[lld] r238562 - COFF: Fill imort table HintName field.
Rui Ueyama
ruiu at google.com
Fri May 29 08:45:36 PDT 2015
Author: ruiu
Date: Fri May 29 10:45:35 2015
New Revision: 238562
URL: http://llvm.org/viewvc/llvm-project?rev=238562&view=rev
Log:
COFF: Fill imort table HintName field.
Currently we set the field to zero, but as per the spec, we should
set numbers we read from import library files. The loader uses the
values as starting offsets for binary search when looking up imported
symbols from DLL.
Modified:
lld/trunk/COFF/Chunks.cpp
lld/trunk/COFF/Chunks.h
lld/trunk/COFF/InputFiles.cpp
lld/trunk/COFF/Symbols.h
lld/trunk/test/COFF/imports.test
Modified: lld/trunk/COFF/Chunks.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Chunks.cpp?rev=238562&r1=238561&r2=238562&view=diff
==============================================================================
--- lld/trunk/COFF/Chunks.cpp (original)
+++ lld/trunk/COFF/Chunks.cpp Fri May 29 10:45:35 2015
@@ -172,11 +172,11 @@ void ImportThunkChunk::applyRelocations(
write32le(Buf + FileOff + 2, Operand);
}
-HintNameChunk::HintNameChunk(StringRef N)
- : Name(N), Size(RoundUpToAlignment(Name.size() + 4, 2)) {}
+HintNameChunk::HintNameChunk(StringRef N, uint16_t H)
+ : Name(N), Hint(H), Size(RoundUpToAlignment(Name.size() + 4, 2)) {}
void HintNameChunk::writeTo(uint8_t *Buf) {
- // The first two bytes is Hint/Name field.
+ write16le(Buf + FileOff, Hint);
memcpy(Buf + FileOff + 2, Name.data(), Name.size());
}
@@ -196,7 +196,8 @@ ImportTable::ImportTable(StringRef N,
DLLName = new StringChunk(N);
DirTab = new DirectoryChunk(DLLName);
for (DefinedImportData *S : Symbols)
- HintNameTables.push_back(new HintNameChunk(S->getExportName()));
+ HintNameTables.push_back(
+ new HintNameChunk(S->getExportName(), S->getOrdinal()));
for (HintNameChunk *H : HintNameTables) {
LookupTables.push_back(new LookupChunk(H));
Modified: lld/trunk/COFF/Chunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Chunks.h?rev=238562&r1=238561&r2=238562&view=diff
==============================================================================
--- lld/trunk/COFF/Chunks.h (original)
+++ lld/trunk/COFF/Chunks.h Fri May 29 10:45:35 2015
@@ -194,12 +194,13 @@ private:
// A chunk for the import descriptor table.
class HintNameChunk : public Chunk {
public:
- explicit HintNameChunk(StringRef Name);
+ HintNameChunk(StringRef Name, uint16_t Hint);
size_t getSize() const override { return Size; }
void writeTo(uint8_t *Buf) override;
private:
StringRef Name;
+ uint16_t Hint;
size_t Size;
};
Modified: lld/trunk/COFF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/InputFiles.cpp?rev=238562&r1=238561&r2=238562&view=diff
==============================================================================
--- lld/trunk/COFF/InputFiles.cpp (original)
+++ lld/trunk/COFF/InputFiles.cpp Fri May 29 10:45:35 2015
@@ -232,7 +232,7 @@ std::error_code ImportFile::parse() {
StringRef Name = StringAlloc.save(StringRef(Buf + sizeof(*Hdr)));
StringRef ImpName = StringAlloc.save(Twine("__imp_") + Name);
StringRef DLLName(Buf + sizeof(coff_import_header) + Name.size() + 1);
- auto *ImpSym = new (Alloc) DefinedImportData(DLLName, ImpName, Name);
+ auto *ImpSym = new (Alloc) DefinedImportData(DLLName, ImpName, Name, Hdr);
SymbolBodies.push_back(ImpSym);
// If type is function, we need to create a thunk which jump to an
Modified: lld/trunk/COFF/Symbols.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Symbols.h?rev=238562&r1=238561&r2=238562&view=diff
==============================================================================
--- lld/trunk/COFF/Symbols.h (original)
+++ lld/trunk/COFF/Symbols.h Fri May 29 10:45:35 2015
@@ -24,6 +24,7 @@ namespace coff {
using llvm::object::Archive;
using llvm::object::COFFSymbolRef;
+using llvm::object::coff_import_header;
class ArchiveFile;
class InputFile;
@@ -158,9 +159,10 @@ private:
// table in an output. The former has "__imp_" prefix.
class DefinedImportData : public Defined {
public:
- DefinedImportData(StringRef D, StringRef ImportName, StringRef ExportName)
+ DefinedImportData(StringRef D, StringRef ImportName, StringRef ExportName,
+ const coff_import_header *H)
: Defined(DefinedImportDataKind, ImportName), DLLName(D),
- ExpName(ExportName) {}
+ ExpName(ExportName), Hdr(H) {}
static bool classof(const SymbolBody *S) {
return S->kind() == DefinedImportDataKind;
@@ -171,10 +173,12 @@ public:
StringRef getDLLName() { return DLLName; }
StringRef getExportName() { return ExpName; }
void setLocation(Chunk *AddressTable) { Location = AddressTable; }
+ uint16_t getOrdinal() { return Hdr->OrdinalHint; }
private:
StringRef DLLName;
StringRef ExpName;
+ const coff_import_header *Hdr;
Chunk *Location = nullptr;
};
Modified: lld/trunk/test/COFF/imports.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/imports.test?rev=238562&r1=238561&r2=238562&view=diff
==============================================================================
--- lld/trunk/test/COFF/imports.test (original)
+++ lld/trunk/test/COFF/imports.test Fri May 29 10:45:35 2015
@@ -23,5 +23,5 @@ IMPORT-NEXT: Name: std64.dll
IMPORT-NEXT: ImportLookupTableRVA: 0x3028
IMPORT-NEXT: ImportAddressTableRVA: 0x3040
IMPORT-NEXT: Symbol: ExitProcess (0)
-IMPORT-NEXT: Symbol: MessageBoxA (0)
+IMPORT-NEXT: Symbol: MessageBoxA (1)
IMPORT-NEXT: }
More information about the llvm-commits
mailing list