From c851ccc3bd38b0887615f9b39950d07ffc66da0a Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Fri, 10 Jul 2015 04:30:54 +0000 Subject: [PATCH] COFF: Fix locally-imported symbol's base relocations. Base relocations are RVA and not VA, so we shouldn't add ImageBase. llvm-svn: 241883 --- lld/COFF/Chunks.cpp | 2 +- lld/test/COFF/locally-imported.test | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/lld/COFF/Chunks.cpp b/lld/COFF/Chunks.cpp index 0c4e99acdd73..873d2a7be0d5 100644 --- a/lld/COFF/Chunks.cpp +++ b/lld/COFF/Chunks.cpp @@ -263,7 +263,7 @@ void ImportThunkChunk::writeTo(uint8_t *Buf) { void LocalImportChunk::getBaserels(std::vector *Res, Defined *ImageBase) { - Res->push_back(getRVA() + Config->ImageBase); + Res->push_back(getRVA()); } size_t LocalImportChunk::getSize() const { diff --git a/lld/test/COFF/locally-imported.test b/lld/test/COFF/locally-imported.test index 7f985536e7ab..406a4a66eed0 100644 --- a/lld/test/COFF/locally-imported.test +++ b/lld/test/COFF/locally-imported.test @@ -1,13 +1,24 @@ # RUN: yaml2obj < %s > %t.obj # RUN: lld -flavor link2 /out:%t.exe /entry:main %t.obj # RUN: llvm-objdump -s %t.exe | FileCheck %s +# RUN: llvm-readobj -coff-basereloc %t.exe | FileCheck -check-prefix=BASEREL %s # CHECK: Contents of section .text: # CHECK-NEXT: 1000 00200000 - # CHECK: Contents of section .rdata: # CHECK-NEXT: 2000 04100040 01000000 +# BASEREL: BaseReloc [ +# BASEREL-NEXT: Entry { +# BASEREL-NEXT: Type: DIR64 +# BASEREL-NEXT: Address: 0x2000 +# BASEREL-NEXT: } +# BASEREL-NEXT: Entry { +# BASEREL-NEXT: Type: ABSOLUTE +# BASEREL-NEXT: Address: 0x2000 +# BASEREL-NEXT: } +# BASEREL-NEXT: ] + --- header: Machine: IMAGE_FILE_MACHINE_AMD64