[lld] r239280 - COFF: Set non-1 alignment to common chunks.

Rui Ueyama ruiu at google.com
Sun Jun 7 20:17:07 PDT 2015


Author: ruiu
Date: Sun Jun  7 22:17:07 2015
New Revision: 239280

URL: http://llvm.org/viewvc/llvm-project?rev=239280&view=rev
Log:
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.

Modified:
    lld/trunk/COFF/Chunks.cpp
    lld/trunk/COFF/Chunks.h

Modified: lld/trunk/COFF/Chunks.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Chunks.cpp?rev=239280&r1=239279&r2=239280&view=diff
==============================================================================
--- lld/trunk/COFF/Chunks.cpp (original)
+++ lld/trunk/COFF/Chunks.cpp Sun Jun  7 22:17:07 2015
@@ -151,6 +151,13 @@ SectionRef SectionChunk::getSectionRef()
   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;

Modified: lld/trunk/COFF/Chunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Chunks.h?rev=239280&r1=239279&r2=239280&view=diff
==============================================================================
--- lld/trunk/COFF/Chunks.h (original)
+++ lld/trunk/COFF/Chunks.h Sun Jun  7 22:17:07 2015
@@ -145,7 +145,7 @@ private:
 // 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;





More information about the llvm-commits mailing list