[lld] r348000 - Do not assume .idata is zero-initialized.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 30 08:34:57 PST 2018


Author: ruiu
Date: Fri Nov 30 08:34:56 2018
New Revision: 348000

URL: http://llvm.org/viewvc/llvm-project?rev=348000&view=rev
Log:
Do not assume .idata is zero-initialized.

We initialize .text section with 0xcc (INT3 instruction), so we need to
explicitly write data even if it is zero if it can be in a .text section.
If you specify /merge:.rdata=.text, .rdata (which contains .idata) is put
to .text, so we need to do this.

Fixes https://bugs.llvm.org/show_bug.cgi?id=39826

Differential Revision: https://reviews.llvm.org/D55098

Modified:
    lld/trunk/COFF/Chunks.cpp
    lld/trunk/COFF/DLL.cpp
    lld/trunk/test/COFF/export.test

Modified: lld/trunk/COFF/Chunks.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Chunks.cpp?rev=348000&r1=347999&r2=348000&view=diff
==============================================================================
--- lld/trunk/COFF/Chunks.cpp (original)
+++ lld/trunk/COFF/Chunks.cpp Fri Nov 30 08:34:56 2018
@@ -619,6 +619,7 @@ uint32_t CommonChunk::getOutputCharacter
 
 void StringChunk::writeTo(uint8_t *Buf) const {
   memcpy(Buf + OutputSectionOff, Str.data(), Str.size());
+  Buf[OutputSectionOff + Str.size()] = '\0';
 }
 
 ImportThunkChunkX64::ImportThunkChunkX64(Defined *S) : ImpSymbol(S) {

Modified: lld/trunk/COFF/DLL.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/DLL.cpp?rev=348000&r1=347999&r2=348000&view=diff
==============================================================================
--- lld/trunk/COFF/DLL.cpp (original)
+++ lld/trunk/COFF/DLL.cpp Fri Nov 30 08:34:56 2018
@@ -416,6 +416,8 @@ public:
   size_t getSize() const override { return Size * 4; }
 
   void writeTo(uint8_t *Buf) const override {
+    memset(Buf + OutputSectionOff, 0, getSize());
+
     for (const Export &E : Config->Exports) {
       uint8_t *P = Buf + OutputSectionOff + E.Ordinal * 4;
       uint32_t Bit = 0;

Modified: lld/trunk/test/COFF/export.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/export.test?rev=348000&r1=347999&r2=348000&view=diff
==============================================================================
--- lld/trunk/test/COFF/export.test (original)
+++ lld/trunk/test/COFF/export.test Fri Nov 30 08:34:56 2018
@@ -97,3 +97,12 @@ FORWARDER:  Ordinal      RVA  Name
 FORWARDER:        0        0
 FORWARDER:        1   0x1010  exportfn
 FORWARDER:        2           foo (forwarded to kernel32.foobar)
+
+# RUN: lld-link /out:%t.dll /dll %t.obj /merge:.rdata=.text /export:exportfn1 /export:exportfn2
+# RUN: llvm-objdump -p %t.dll | FileCheck -check-prefix=MERGE -match-full-lines %s
+
+MERGE:      DLL name: export.test.tmp.dll
+MERGE:      Ordinal      RVA  Name
+MERGE-NEXT:       0        0
+MERGE-NEXT:       1   0x1008  exportfn1
+MERGE-NEXT:       2   0x1010  exportfn2




More information about the llvm-commits mailing list