[lld] r221853 - [PECOFF] Fix delay-import address table contents.

Rui Ueyama ruiu at google.com
Wed Nov 12 18:58:36 PST 2014


Author: ruiu
Date: Wed Nov 12 20:58:36 2014
New Revision: 221853

URL: http://llvm.org/viewvc/llvm-project?rev=221853&view=rev
Log:
[PECOFF] Fix delay-import address table contents.

Each entry in the delay-import address table had a wrong alignment
requirement if 32 bit. As a result it got wrong delay-import table.

Because llvm-readobj doesn't print out that field, we don't have a
test for that. I'll submit a test that would catch this bug after
improving llvm-readobj.

Modified:
    lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.cpp
    lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.h
    lld/trunk/test/pecoff/delayimport.test

Modified: lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.cpp?rev=221853&r1=221852&r2=221853&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.cpp Wed Nov 12 20:58:36 2014
@@ -185,7 +185,10 @@ void DelayImportDirectoryAtom::addReloca
   for (int i = 0, e = sharedAtoms.size(); i < e; ++i) {
     const DefinedAtom *loader = new (_alloc) DelayLoaderAtom(
         context, addrTable[i], this, delayLoadHelper);
-    addDir64Reloc(addrTable[i], loader, context.ctx.getMachineType(), 0);
+    if (context.ctx.is64Bit())
+      addDir64Reloc(addrTable[i], loader, context.ctx.getMachineType(), 0);
+    else
+      addDir32NBReloc(addrTable[i], loader, context.ctx.getMachineType(), 0);
   }
 }
 

Modified: lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.h?rev=221853&r1=221852&r2=221853&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.h (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.h Wed Nov 12 20:58:36 2014
@@ -162,15 +162,18 @@ private:
 class DelayImportAddressAtom : public IdataAtom {
 public:
   explicit DelayImportAddressAtom(IdataContext &context)
-      : IdataAtom(context, createContent(context.ctx)) {}
+      : IdataAtom(context, createContent(context.ctx)),
+        _align(Alignment(context.ctx.is64Bit() ? 3 : 2)) {}
   StringRef customSectionName() const override { return ".data"; }
   ContentPermissions permissions() const override { return permRW_; }
-  Alignment alignment() const override { return Alignment(3); }
+  Alignment alignment() const override { return _align; }
 
 private:
   std::vector<uint8_t> createContent(const PECOFFLinkingContext &ctx) const {
     return std::vector<uint8_t>(ctx.is64Bit() ? 8 : 4, 0);
   }
+
+  Alignment _align;
 };
 
 // DelayLoaderAtom contains a wrapper function for __delayLoadHelper2.

Modified: lld/trunk/test/pecoff/delayimport.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/delayimport.test?rev=221853&r1=221852&r2=221853&view=diff
==============================================================================
--- lld/trunk/test/pecoff/delayimport.test (original)
+++ lld/trunk/test/pecoff/delayimport.test Wed Nov 12 20:58:36 2014
@@ -13,7 +13,7 @@ X86:      DelayImport {
 X86-NEXT:   Name: vars.dll
 X86-NEXT:   Attributes: 0x1
 X86-NEXT:   ModuleHandle: 0x1000
-X86-NEXT:   ImportAddressTable: 0x1008
+X86-NEXT:   ImportAddressTable: 0x1004
 X86-NEXT:   ImportNameTable: 0x2000
 X86-NEXT:   BoundDelayImportTable: 0x0
 X86-NEXT:   UnloadDelayImportTable: 0x0





More information about the llvm-commits mailing list