[lld] r219415 - [PECOFF] Emit ModuleHandle field in delay-import table.
Rui Ueyama
ruiu at google.com
Thu Oct 9 10:43:02 PDT 2014
Author: ruiu
Date: Thu Oct 9 12:43:01 2014
New Revision: 219415
URL: http://llvm.org/viewvc/llvm-project?rev=219415&view=rev
Log:
[PECOFF] Emit ModuleHandle field in delay-import table.
Previously the field was not set. The field should be pointing to
a placeholder where the DLL delay-loader writes the base address
of a DLL.
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=219415&r1=219414&r2=219415&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.cpp (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.cpp Thu Oct 9 12:43:01 2014
@@ -135,6 +135,11 @@ std::vector<uint8_t> DelayImportDirector
void DelayImportDirectoryAtom::addRelocations(
IdataContext &context, StringRef loadName,
const std::vector<COFFSharedLibraryAtom *> &sharedAtoms) {
+ // "ModuleHandle" field
+ auto *hmodule = new (_alloc) DelayImportHModuleAtom(context);
+ addDir32NBReloc(this, hmodule, context.ctx.getMachineType(),
+ offsetof(delay_import_directory_table_entry, ModuleHandle));
+
// "NameTable" field
std::vector<ImportTableEntryAtom *> nameTable =
createImportTableAtoms(context, sharedAtoms, true, ".didat", _alloc);
@@ -143,11 +148,11 @@ void DelayImportDirectoryAtom::addReloca
offsetof(delay_import_directory_table_entry, DelayImportNameTable));
// "Name" field
- auto *atom = new (_alloc)
+ auto *name = new (_alloc)
COFFStringAtom(context.dummyFile, context.dummyFile.getNextOrdinal(),
".didat", loadName);
- context.file.addAtom(*atom);
- addDir32NBReloc(this, atom, context.ctx.getMachineType(),
+ context.file.addAtom(*name);
+ addDir32NBReloc(this, name, context.ctx.getMachineType(),
offsetof(delay_import_directory_table_entry, Name));
// TODO: emit other fields
}
Modified: lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.h?rev=219415&r1=219414&r2=219415&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.h (original)
+++ lld/trunk/lib/ReaderWriter/PECOFF/IdataPass.h Thu Oct 9 12:43:01 2014
@@ -161,6 +161,20 @@ private:
}
};
+class DelayImportHModuleAtom : public IdataAtom {
+public:
+ explicit DelayImportHModuleAtom(IdataContext &context)
+ : IdataAtom(context, createContent(context.ctx)) {}
+ StringRef customSectionName() const override { return ".data"; }
+ ContentPermissions permissions() const override { return permRW_; }
+ Alignment alignment() const override { return Alignment(3); }
+
+private:
+ std::vector<uint8_t> createContent(const PECOFFLinkingContext &ctx) const {
+ return std::vector<uint8_t>(ctx.is64Bit() ? 8 : 4, 0);
+ }
+};
+
} // namespace idata
class IdataPass : public lld::Pass {
Modified: lld/trunk/test/pecoff/delayimport.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/pecoff/delayimport.test?rev=219415&r1=219414&r2=219415&view=diff
==============================================================================
--- lld/trunk/test/pecoff/delayimport.test (original)
+++ lld/trunk/test/pecoff/delayimport.test Thu Oct 9 12:43:01 2014
@@ -12,9 +12,9 @@
X86: DelayImport {
X86-NEXT: Name: vars.dll
X86-NEXT: Attributes: 0x1
-X86-NEXT: ModuleHandle: 0x0
+X86-NEXT: ModuleHandle: 0x1000
X86-NEXT: ImportAddressTable: 0x0
-X86-NEXT: ImportNameTable: 0x1000
+X86-NEXT: ImportNameTable: 0x2000
X86-NEXT: BoundDelayImportTable: 0x0
X86-NEXT: UnloadDelayImportTable: 0x0
X86-NEXT: Symbol: _name_with_underscore (0)
@@ -25,9 +25,9 @@ X86-NEXT: }
X64: DelayImport {
X64-NEXT: Name: vars64.dll
X64-NEXT: Attributes: 0x1
-X64-NEXT: ModuleHandle: 0x0
+X64-NEXT: ModuleHandle: 0x1000
X64-NEXT: ImportAddressTable: 0x0
-X64-NEXT: ImportNameTable: 0x1000
+X64-NEXT: ImportNameTable: 0x2000
X64-NEXT: BoundDelayImportTable: 0x0
X64-NEXT: UnloadDelayImportTable: 0x0
X64-NEXT: Symbol: _name_with_underscore (0)
More information about the llvm-commits
mailing list