[lld] r295936 - [ELF] Ignore R_*_NONE relocs when relocating non-alloc sections
Petr Hosek via llvm-commits
llvm-commits at lists.llvm.org
Wed Feb 22 22:22:28 PST 2017
Author: phosek
Date: Thu Feb 23 00:22:28 2017
New Revision: 295936
URL: http://llvm.org/viewvc/llvm-project?rev=295936&view=rev
Log:
[ELF] Ignore R_*_NONE relocs when relocating non-alloc sections
We shouldn't report an error for R_*_NONE relocs since we're emitting
them when writing relocations to discarded sections.
Differential Revision: https://reviews.llvm.org/D30279
Added:
lld/trunk/test/ELF/Inputs/relocatable-non-alloc.s
lld/trunk/test/ELF/relocatable-non-alloc.s
Modified:
lld/trunk/ELF/InputSection.cpp
lld/trunk/ELF/Relocations.cpp
lld/trunk/ELF/Relocations.h
lld/trunk/ELF/Target.cpp
Modified: lld/trunk/ELF/InputSection.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputSection.cpp?rev=295936&r1=295935&r2=295936&view=diff
==============================================================================
--- lld/trunk/ELF/InputSection.cpp (original)
+++ lld/trunk/ELF/InputSection.cpp Thu Feb 23 00:22:28 2017
@@ -308,6 +308,7 @@ getRelocTargetVA(uint32_t Type, int64_t
const SymbolBody &Body, RelExpr Expr) {
switch (Expr) {
case R_HINT:
+ case R_NONE:
case R_TLSDESC_CALL:
llvm_unreachable("cannot relocate hint relocs");
case R_TLSLD:
@@ -459,7 +460,10 @@ void InputSection<ELFT>::relocateNonAllo
Addend += Target->getImplicitAddend(BufLoc, Type);
SymbolBody &Sym = this->getFile<ELFT>()->getRelocTargetSym(Rel);
- if (Target->getRelExpr(Type, Sym) != R_ABS) {
+ RelExpr Expr = Target->getRelExpr(Type, Sym);
+ if (Expr == R_NONE)
+ continue;
+ if (Expr != R_ABS) {
error(this->getLocation<ELFT>(Offset) + ": has non-ABS reloc");
return;
}
Modified: lld/trunk/ELF/Relocations.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.cpp?rev=295936&r1=295935&r2=295936&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.cpp (original)
+++ lld/trunk/ELF/Relocations.cpp Thu Feb 23 00:22:28 2017
@@ -694,6 +694,11 @@ static void scanRelocs(InputSectionBase
reportUndefined<ELFT>(Body, C, RI.r_offset);
RelExpr Expr = Target->getRelExpr(Type, Body);
+
+ // Ignore "hint" relocations because they are only markers for relaxation.
+ if (isRelExprOneOf<R_HINT, R_NONE>(Expr))
+ continue;
+
bool Preemptible = isPreemptible(Body, Type);
Expr = adjustExpr(*File, Body, IsWrite, Expr, Type, Buf + RI.r_offset, C,
RI.r_offset);
@@ -732,9 +737,7 @@ static void scanRelocs(InputSectionBase
continue;
}
- // Ignore "hint" and TLS Descriptor call relocation because they are
- // only markers for relaxation.
- if (isRelExprOneOf<R_HINT, R_TLSDESC_CALL>(Expr))
+ if (Expr == R_TLSDESC_CALL)
continue;
if (needsPlt(Expr) ||
Modified: lld/trunk/ELF/Relocations.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Relocations.h?rev=295936&r1=295935&r2=295936&view=diff
==============================================================================
--- lld/trunk/ELF/Relocations.h (original)
+++ lld/trunk/ELF/Relocations.h Thu Feb 23 00:22:28 2017
@@ -42,6 +42,7 @@ enum RelExpr {
R_MIPS_TLSGD,
R_MIPS_TLSLD,
R_NEG_TLS,
+ R_NONE,
R_PAGE_PC,
R_PC,
R_PLT,
Modified: lld/trunk/ELF/Target.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Target.cpp?rev=295936&r1=295935&r2=295936&view=diff
==============================================================================
--- lld/trunk/ELF/Target.cpp (original)
+++ lld/trunk/ELF/Target.cpp Thu Feb 23 00:22:28 2017
@@ -389,7 +389,7 @@ RelExpr X86TargetInfo::getRelExpr(uint32
case R_386_TLS_LE_32:
return R_NEG_TLS;
case R_386_NONE:
- return R_HINT;
+ return R_NONE;
default:
error(toString(S.File) + ": unknown relocation type: " + toString(Type));
return R_HINT;
@@ -684,7 +684,7 @@ RelExpr X86_64TargetInfo<ELFT>::getRelEx
case R_X86_64_GOTTPOFF:
return R_GOT_PC;
case R_X86_64_NONE:
- return R_HINT;
+ return R_NONE;
default:
error(toString(S.File) + ": unknown relocation type: " + toString(Type));
return R_HINT;
@@ -1715,7 +1715,7 @@ RelExpr ARMTargetInfo::getRelExpr(uint32
case R_ARM_THM_MOVT_PREL:
return R_PC;
case R_ARM_NONE:
- return R_HINT;
+ return R_NONE;
case R_ARM_TLS_LE32:
return R_TLS;
}
Added: lld/trunk/test/ELF/Inputs/relocatable-non-alloc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/Inputs/relocatable-non-alloc.s?rev=295936&view=auto
==============================================================================
--- lld/trunk/test/ELF/Inputs/relocatable-non-alloc.s (added)
+++ lld/trunk/test/ELF/Inputs/relocatable-non-alloc.s Thu Feb 23 00:22:28 2017
@@ -0,0 +1,6 @@
+.section .text.foo,"axG", at progbits,foo,comdat,unique,0
+foo:
+ nop
+
+.section .debug_info
+.long .text.foo
Added: lld/trunk/test/ELF/relocatable-non-alloc.s
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/ELF/relocatable-non-alloc.s?rev=295936&view=auto
==============================================================================
--- lld/trunk/test/ELF/relocatable-non-alloc.s (added)
+++ lld/trunk/test/ELF/relocatable-non-alloc.s Thu Feb 23 00:22:28 2017
@@ -0,0 +1,10 @@
+# REQUIRES: x86
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %S/Inputs/relocatable-non-alloc.s -o %t2.o
+# RUN: ld.lld %t2.o %t2.o -r -o %t3.o
+# RUN: ld.lld %t1.o %t3.o -o %t.o | FileCheck -allow-empty %s
+
+# CHECK-NOT: has non-ABS reloc
+
+.globl _start
+_start:
More information about the llvm-commits
mailing list