From 33fb2cb11b7d2454bd2d97fe95c11ed38679327b Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Wed, 15 Jul 2015 00:25:38 +0000 Subject: [PATCH] COFF: Fix base relocations for __imp_ symbols on x86. Because thunks for dllimported symbols contain absolute addresses on x86, they need to be relocated at load-time. This bug was a cause of crashes in DLL initialization routines. llvm-svn: 242259 --- lld/COFF/Chunks.cpp | 6 ++++++ lld/COFF/Chunks.h | 1 + lld/test/COFF/hello32.test | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lld/COFF/Chunks.cpp b/lld/COFF/Chunks.cpp index 873d2a7..86f6e84 100644 --- a/lld/COFF/Chunks.cpp +++ b/lld/COFF/Chunks.cpp @@ -252,6 +252,12 @@ ImportThunkChunk::ImportThunkChunk(Defined *S) : ImpSymbol(S) { Align = 16; } +void ImportThunkChunk::getBaserels(std::vector *Res, + Defined *ImageBase) { + if (!Config->is64()) + Res->push_back(getRVA() + 2); +} + void ImportThunkChunk::writeTo(uint8_t *Buf) { memcpy(Buf + FileOff, ImportThunkData, sizeof(ImportThunkData)); // The first two bytes is a JMP instruction. Fill its operand. diff --git a/lld/COFF/Chunks.h b/lld/COFF/Chunks.h index b9b533f..c75f379 100644 --- a/lld/COFF/Chunks.h +++ b/lld/COFF/Chunks.h @@ -234,6 +234,7 @@ class ImportThunkChunk : public Chunk { public: explicit ImportThunkChunk(Defined *ImpSymbol); size_t getSize() const override { return sizeof(ImportThunkData); } + void getBaserels(std::vector *Res, Defined *ImageBase) override; void writeTo(uint8_t *Buf) override; private: diff --git a/lld/test/COFF/hello32.test b/lld/test/COFF/hello32.test index 916a7c3..130bb0b 100644 --- a/lld/test/COFF/hello32.test +++ b/lld/test/COFF/hello32.test @@ -64,7 +64,7 @@ HEADER-NEXT: ExceptionTableSize: 0x0 HEADER-NEXT: CertificateTableRVA: 0x0 HEADER-NEXT: CertificateTableSize: 0x0 HEADER-NEXT: BaseRelocationTableRVA: 0x4000 -HEADER-NEXT: BaseRelocationTableSize: 0xC +HEADER-NEXT: BaseRelocationTableSize: 0x10 HEADER-NEXT: DebugRVA: 0x0 HEADER-NEXT: DebugSize: 0x0 HEADER-NEXT: ArchitectureRVA: 0x0 -- 2.7.4