[lld] r287915 - [ELF] Refactor getDynRel to print error location
Eugene Leviant via llvm-commits
llvm-commits at lists.llvm.org
Fri Nov 25 00:56:38 PST 2016
Author: evgeny777
Date: Fri Nov 25 02:56:36 2016
New Revision: 287915
URL: http://llvm.org/viewvc/llvm-project?rev=287915&view=rev
Log:
[ELF] Refactor getDynRel to print error location
Differential revision: https://reviews.llvm.org/D27055
Modified:
lld/trunk/ELF/Relocations.cpp
lld/trunk/ELF/Target.cpp
lld/trunk/ELF/Target.h
lld/trunk/test/ELF/aarch64-fpic-abs16.s
lld/trunk/test/ELF/aarch64-fpic-prel16.s
lld/trunk/test/ELF/aarch64-fpic-prel32.s
lld/trunk/test/ELF/aarch64-fpic-prel64.s
lld/trunk/test/ELF/x86-64-dyn-rel-error.s
lld/trunk/test/ELF/x86-64-dyn-rel-error2.s
lld/trunk/test/ELF/x86-64-reloc-32-fpic.s
lld/trunk/test/ELF/x86-64-reloc-pc32-fpic.s
Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=287915&r1=287914&r2=287915&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Fri Nov 25 02:56:36 2016
@@ -711,7 +711,11 @@ static void scanRelocs(InputSectionBase<
} else {
// We don't know anything about the finaly symbol. Just ask the dynamic
// linker to handle the relocation for us.
+ if (!Target->isPicRel(Type))
+ error(getLocation(C, Offset) + ": relocation " + toString(Type) +
+ " cannot be used against shared object; recompile with -fPIC.");
AddDyn({Target->getDynRel(Type), &C, Offset, false, &Body, Addend});
+
// MIPS ABI turns using of GOT and dynamic relocations inside out.
// While regular ABI uses dynamic relocations to fill up GOT entries
// MIPS ABI requires dynamic linker to fills up GOT entries using
Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=287915&r1=287914&r2=287915&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Fri Nov 25 02:56:36 2016
@@ -75,11 +75,6 @@ template <unsigned N> static void checkA
error("improper alignment for relocation " + toString(Type));
}
-static void errorDynRel(uint32_t Type) {
- error("relocation " + toString(Type) +
- " cannot be used against shared object; recompile with -fPIC.");
-}
-
namespace {
class X86TargetInfo final : public TargetInfo {
public:
@@ -109,7 +104,7 @@ template <class ELFT> class X86_64Target
public:
X86_64TargetInfo();
RelExpr getRelExpr(uint32_t Type, const SymbolBody &S) const override;
- uint32_t getDynRel(uint32_t Type) const override;
+ bool isPicRel(uint32_t Type) const override;
bool isTlsLocalDynamicRel(uint32_t Type) const override;
bool isTlsGlobalDynamicRel(uint32_t Type) const override;
bool isTlsInitialExecRel(uint32_t Type) const override;
@@ -153,7 +148,7 @@ class AArch64TargetInfo final : public T
public:
AArch64TargetInfo();
RelExpr getRelExpr(uint32_t Type, const SymbolBody &S) const override;
- uint32_t getDynRel(uint32_t Type) const override;
+ bool isPicRel(uint32_t Type) const override;
bool isTlsInitialExecRel(uint32_t Type) const override;
void writeGotPlt(uint8_t *Buf, const SymbolBody &S) const override;
void writePltHeader(uint8_t *Buf) const override;
@@ -179,6 +174,7 @@ class ARMTargetInfo final : public Targe
public:
ARMTargetInfo();
RelExpr getRelExpr(uint32_t Type, const SymbolBody &S) const override;
+ bool isPicRel(uint32_t Type) const override;
uint32_t getDynRel(uint32_t Type) const override;
uint64_t getImplicitAddend(const uint8_t *Buf, uint32_t Type) const override;
bool isTlsLocalDynamicRel(uint32_t Type) const override;
@@ -198,6 +194,7 @@ public:
MipsTargetInfo();
RelExpr getRelExpr(uint32_t Type, const SymbolBody &S) const override;
uint64_t getImplicitAddend(const uint8_t *Buf, uint32_t Type) const override;
+ bool isPicRel(uint32_t Type) const override;
uint32_t getDynRel(uint32_t Type) const override;
bool isTlsLocalDynamicRel(uint32_t Type) const override;
bool isTlsGlobalDynamicRel(uint32_t Type) const override;
@@ -640,10 +637,8 @@ void X86_64TargetInfo<ELFT>::writePlt(ui
}
template <class ELFT>
-uint32_t X86_64TargetInfo<ELFT>::getDynRel(uint32_t Type) const {
- if (Type == R_X86_64_PC32 || Type == R_X86_64_32)
- errorDynRel(Type);
- return Type;
+bool X86_64TargetInfo<ELFT>::isPicRel(uint32_t Type) const {
+ return Type != R_X86_64_PC32 && Type != R_X86_64_32;
}
template <class ELFT>
@@ -1249,12 +1244,8 @@ bool AArch64TargetInfo::isTlsInitialExec
Type == R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC;
}
-uint32_t AArch64TargetInfo::getDynRel(uint32_t Type) const {
- if (Type == R_AARCH64_ABS32 || Type == R_AARCH64_ABS64)
- return Type;
- // Keep it going with a dummy value so that we can find more reloc errors.
- errorDynRel(Type);
- return R_AARCH64_ABS32;
+bool AArch64TargetInfo::isPicRel(uint32_t Type) const {
+ return Type == R_AARCH64_ABS32 || Type == R_AARCH64_ABS64;
}
void AArch64TargetInfo::writeGotPlt(uint8_t *Buf, const SymbolBody &) const {
@@ -1609,13 +1600,17 @@ RelExpr ARMTargetInfo::getRelExpr(uint32
}
}
+bool ARMTargetInfo::isPicRel(uint32_t Type) const {
+ return (Type == R_ARM_TARGET1 && !Config->Target1Rel) ||
+ (Type == R_ARM_ABS32);
+}
+
uint32_t ARMTargetInfo::getDynRel(uint32_t Type) const {
if (Type == R_ARM_TARGET1 && !Config->Target1Rel)
return R_ARM_ABS32;
if (Type == R_ARM_ABS32)
return Type;
// Keep it going with a dummy value so that we can find more reloc errors.
- errorDynRel(Type);
return R_ARM_ABS32;
}
@@ -1979,13 +1974,13 @@ RelExpr MipsTargetInfo<ELFT>::getRelExpr
}
}
+template <class ELFT> bool MipsTargetInfo<ELFT>::isPicRel(uint32_t Type) const {
+ return Type == R_MIPS_32 || Type == R_MIPS_64;
+}
+
template <class ELFT>
uint32_t MipsTargetInfo<ELFT>::getDynRel(uint32_t Type) const {
- if (Type == R_MIPS_32 || Type == R_MIPS_64)
- return RelativeRel;
- // Keep it going with a dummy value so that we can find more reloc errors.
- errorDynRel(Type);
- return R_MIPS_32;
+ return RelativeRel;
}
template <class ELFT>
Modified: lld/trunk/ELF/Target.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.h?rev=287915&r1=287914&r2=287915&view=diff
==============================================================================
--- lld/trunk/ELF/Target.h (original)
+++ lld/trunk/ELF/Target.h Fri Nov 25 02:56:36 2016
@@ -26,6 +26,7 @@ public:
virtual bool isTlsInitialExecRel(uint32_t Type) const;
virtual bool isTlsLocalDynamicRel(uint32_t Type) const;
virtual bool isTlsGlobalDynamicRel(uint32_t Type) const;
+ virtual bool isPicRel(uint32_t Type) const { return true; }
virtual uint32_t getDynRel(uint32_t Type) const { return Type; }
virtual void writeGotPltHeader(uint8_t *Buf) const {}
virtual void writeGotPlt(uint8_t *Buf, const SymbolBody &S) const {};
Modified: lld/trunk/test/ELF/aarch64-fpic-abs16.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/aarch64-fpic-abs16.s?rev=287915&r1=287914&r2=287915&view=diff
==============================================================================
--- lld/trunk/test/ELF/aarch64-fpic-abs16.s (original)
+++ lld/trunk/test/ELF/aarch64-fpic-abs16.s Fri Nov 25 02:56:36 2016
@@ -1,7 +1,7 @@
// REQUIRES: aarch64
// RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t.o
// RUN: not ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s
-// CHECK: relocation R_AARCH64_ABS16 cannot be used against shared object; recompile with -fPIC.
+// CHECK: {{.*}}:(.data+0x0): relocation R_AARCH64_ABS16 cannot be used against shared object; recompile with -fPIC.
.data
.hword foo
Modified: lld/trunk/test/ELF/aarch64-fpic-prel16.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/aarch64-fpic-prel16.s?rev=287915&r1=287914&r2=287915&view=diff
==============================================================================
--- lld/trunk/test/ELF/aarch64-fpic-prel16.s (original)
+++ lld/trunk/test/ELF/aarch64-fpic-prel16.s Fri Nov 25 02:56:36 2016
@@ -1,7 +1,7 @@
// REQUIRES: aarch64
// RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t.o
// RUN: not ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s
-// CHECK: relocation R_AARCH64_PREL16 cannot be used against shared object; recompile with -fPIC.
+// CHECK: {{.*}}:(.data+0x0): relocation R_AARCH64_PREL16 cannot be used against shared object; recompile with -fPIC.
.data
.hword foo - .
Modified: lld/trunk/test/ELF/aarch64-fpic-prel32.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/aarch64-fpic-prel32.s?rev=287915&r1=287914&r2=287915&view=diff
==============================================================================
--- lld/trunk/test/ELF/aarch64-fpic-prel32.s (original)
+++ lld/trunk/test/ELF/aarch64-fpic-prel32.s Fri Nov 25 02:56:36 2016
@@ -1,7 +1,7 @@
// REQUIRES: aarch64
// RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t.o
// RUN: not ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s
-// CHECK: relocation R_AARCH64_PREL32 cannot be used against shared object; recompile with -fPIC.
+// CHECK: {{.*}}:(.data+0x0): relocation R_AARCH64_PREL32 cannot be used against shared object; recompile with -fPIC.
.data
.word foo - .
Modified: lld/trunk/test/ELF/aarch64-fpic-prel64.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/aarch64-fpic-prel64.s?rev=287915&r1=287914&r2=287915&view=diff
==============================================================================
--- lld/trunk/test/ELF/aarch64-fpic-prel64.s (original)
+++ lld/trunk/test/ELF/aarch64-fpic-prel64.s Fri Nov 25 02:56:36 2016
@@ -1,7 +1,7 @@
// REQUIRES: aarch64
// RUN: llvm-mc -filetype=obj -triple=aarch64-none-freebsd %s -o %t.o
// RUN: not ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s
-// CHECK: relocation R_AARCH64_PREL64 cannot be used against shared object; recompile with -fPIC.
+// CHECK: {{.*}}:(.data+0x0): relocation R_AARCH64_PREL64 cannot be used against shared object; recompile with -fPIC.
.data
.xword foo - .
Modified: lld/trunk/test/ELF/x86-64-dyn-rel-error.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/x86-64-dyn-rel-error.s?rev=287915&r1=287914&r2=287915&view=diff
==============================================================================
--- lld/trunk/test/ELF/x86-64-dyn-rel-error.s (original)
+++ lld/trunk/test/ELF/x86-64-dyn-rel-error.s Fri Nov 25 02:56:36 2016
@@ -9,4 +9,4 @@ _start:
.data
.long bar
-// CHECK: R_X86_64_32 cannot be used against shared object; recompile with -fPIC.
+// CHECK: {{.*}}:(.data+0x0): relocation R_X86_64_32 cannot be used against shared object; recompile with -fPIC.
Modified: lld/trunk/test/ELF/x86-64-dyn-rel-error2.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/x86-64-dyn-rel-error2.s?rev=287915&r1=287914&r2=287915&view=diff
==============================================================================
--- lld/trunk/test/ELF/x86-64-dyn-rel-error2.s (original)
+++ lld/trunk/test/ELF/x86-64-dyn-rel-error2.s Fri Nov 25 02:56:36 2016
@@ -9,4 +9,4 @@ _start:
.data
.long bar - .
-// CHECK: R_X86_64_PC32 cannot be used against shared object; recompile with -fPIC.
+// CHECK: {{.*}}:(.data+0x0): relocation R_X86_64_PC32 cannot be used against shared object; recompile with -fPIC.
Modified: lld/trunk/test/ELF/x86-64-reloc-32-fpic.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/x86-64-reloc-32-fpic.s?rev=287915&r1=287914&r2=287915&view=diff
==============================================================================
--- lld/trunk/test/ELF/x86-64-reloc-32-fpic.s (original)
+++ lld/trunk/test/ELF/x86-64-reloc-32-fpic.s Fri Nov 25 02:56:36 2016
@@ -1,7 +1,7 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
# RUN: not ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s
-# CHECK: relocation R_X86_64_32 cannot be used against shared object; recompile with -fPIC.
+# CHECK: {{.*}}:(.data+0x0): relocation R_X86_64_32 cannot be used against shared object; recompile with -fPIC.
.data
.long _shared
Modified: lld/trunk/test/ELF/x86-64-reloc-pc32-fpic.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/x86-64-reloc-pc32-fpic.s?rev=287915&r1=287914&r2=287915&view=diff
==============================================================================
--- lld/trunk/test/ELF/x86-64-reloc-pc32-fpic.s (original)
+++ lld/trunk/test/ELF/x86-64-reloc-pc32-fpic.s Fri Nov 25 02:56:36 2016
@@ -1,7 +1,7 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
# RUN: not ld.lld -shared %t.o -o %t.so 2>&1 | FileCheck %s
-# CHECK: relocation R_X86_64_PC32 cannot be used against shared object; recompile with -fPIC.
+# CHECK: {{.*}}:(.data+0x1): relocation R_X86_64_PC32 cannot be used against shared object; recompile with -fPIC.
.data
call _shared
More information about the llvm-commits
mailing list