[lld] r242259 - COFF: Fix base relocations for __imp_ symbols on x86.
Rui Ueyama
ruiu at google.com
Tue Jul 14 17:25:38 PDT 2015
Author: ruiu
Date: Tue Jul 14 19:25:38 2015
New Revision: 242259
URL: http://llvm.org/viewvc/llvm-project?rev=242259&view=rev
Log:
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.
Modified:
lld/trunk/COFF/Chunks.cpp
lld/trunk/COFF/Chunks.h
lld/trunk/test/COFF/hello32.test
Modified: lld/trunk/COFF/Chunks.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Chunks.cpp?rev=242259&r1=242258&r2=242259&view=diff
==============================================================================
--- lld/trunk/COFF/Chunks.cpp (original)
+++ lld/trunk/COFF/Chunks.cpp Tue Jul 14 19:25:38 2015
@@ -252,6 +252,12 @@ ImportThunkChunk::ImportThunkChunk(Defin
Align = 16;
}
+void ImportThunkChunk::getBaserels(std::vector<uint32_t> *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.
Modified: lld/trunk/COFF/Chunks.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/COFF/Chunks.h?rev=242259&r1=242258&r2=242259&view=diff
==============================================================================
--- lld/trunk/COFF/Chunks.h (original)
+++ lld/trunk/COFF/Chunks.h Tue Jul 14 19:25:38 2015
@@ -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<uint32_t> *Res, Defined *ImageBase) override;
void writeTo(uint8_t *Buf) override;
private:
Modified: lld/trunk/test/COFF/hello32.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/COFF/hello32.test?rev=242259&r1=242258&r2=242259&view=diff
==============================================================================
--- lld/trunk/test/COFF/hello32.test (original)
+++ lld/trunk/test/COFF/hello32.test Tue Jul 14 19:25:38 2015
@@ -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
More information about the llvm-commits
mailing list