COFF: Set non-1 alignment to common chunks.
I don't know what the right thing to do here, but at least 1 does
not seem like a correct value. If we do not align common chunks at
all, a small program which calls puts() from global dtors crashes
mysteriously in a kernel32's function.
I believe the crash was caused by symbols overlapping each other,
and my guess is that alignment has something to do with that, but
I am not 100% sure. Needs investigating.
llvm-svn: 239280
diff --git a/lld/COFF/Chunks.cpp b/lld/COFF/Chunks.cpp
index e485936..ecd5b41 100644
--- a/lld/COFF/Chunks.cpp
+++ b/lld/COFF/Chunks.cpp
@@ -151,6 +151,13 @@
return SectionRef(Ref, File->getCOFFObj());
}
+CommonChunk::CommonChunk(const COFFSymbolRef S) : Sym(S) {
+ // Alignment is a section attribute, but common symbols don't
+ // belong to any section. How do we know common data alignments?
+ // Needs investigating. For now, we set a large number as an alignment.
+ Align = 16;
+}
+
uint32_t CommonChunk::getPermissions() const {
return IMAGE_SCN_CNT_UNINITIALIZED_DATA | IMAGE_SCN_MEM_READ |
IMAGE_SCN_MEM_WRITE;
diff --git a/lld/COFF/Chunks.h b/lld/COFF/Chunks.h
index 8ed700d..ed6b0ad 100644
--- a/lld/COFF/Chunks.h
+++ b/lld/COFF/Chunks.h
@@ -145,7 +145,7 @@
// A chunk for common symbols. Common chunks don't have actual data.
class CommonChunk : public Chunk {
public:
- CommonChunk(const COFFSymbolRef S) : Sym(S) {}
+ CommonChunk(const COFFSymbolRef Sym);
size_t getSize() const override { return Sym.getValue(); }
bool hasData() const override { return false; }
uint32_t getPermissions() const override;