diff --git a/lld/ELF/Target.cpp b/lld/ELF/Target.cpp index 65fb0324e3cd..0cf8de91accd 100644 --- a/lld/ELF/Target.cpp +++ b/lld/ELF/Target.cpp @@ -85,6 +85,7 @@ public: void writePltZero(uint8_t *Buf) const override; void writePlt(uint8_t *Buf, uint64_t GotEntryAddr, uint64_t PltEntryAddr, int32_t Index, unsigned RelOff) const override; + bool isRelRelative(uint32_t Type) const override; bool needsCopyRelImpl(uint32_t Type) const override; bool needsDynRelative(uint32_t Type) const override; bool needsGot(uint32_t Type, SymbolBody &S) const override; @@ -396,6 +397,17 @@ X86TargetInfo::X86TargetInfo() { PltZeroSize = 16; } +bool X86TargetInfo::isRelRelative(uint32_t Type) const { + switch (Type) { + default: + return false; + case R_386_PC32: + case R_386_PLT32: + case R_386_TLS_LDO_32: + return true; + } +} + void X86TargetInfo::writeGotPltHeader(uint8_t *Buf) const { write32le(Buf, Out::Dynamic->getVA()); } diff --git a/lld/test/ELF/i386-relative.s b/lld/test/ELF/i386-relative.s new file mode 100644 index 000000000000..b829d1d3daed --- /dev/null +++ b/lld/test/ELF/i386-relative.s @@ -0,0 +1,13 @@ +// REQUIRES: x86 +// RUN: llvm-mc -filetype=obj -triple=i386-pc-linux %s -o %t.o +// RUN: ld.lld -shared %t.o -o %t.so +// RUN: llvm-readobj -r %t.so | FileCheck %s + +// CHECK: Relocations [ +// CHECK-NEXT: Section ({{.*}}) .rel.dyn { +// CHECK-NEXT: R_386_RELATIVE - 0x0 +// CHECK-NEXT: } +// CHECK-NEXT: ] + +foo: + .long foo