Skip to content

Commit 3fd1d69

Browse files
committed
[ELF] relocateNonAlloc: clean up workaround code
relocateNonAlloc is costly for .debug_* section relocating. We don't want to burn CPU cycles on other targets' workarounds. Remove a temporary workaround for Linux objtool after a proper fix https://git.kernel.org/linus/b8ec60e1186cdcfce41e7db4c827cb107e459002 Move the R_386_GOTPC workaround for GCC<8 beside the R_PC workaround.
1 parent 7030aab commit 3fd1d69

File tree

3 files changed

+13
-19
lines changed

3 files changed

+13
-19
lines changed

lld/ELF/InputSection.cpp

Lines changed: 9 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -910,16 +910,8 @@ void InputSection::relocateNonAlloc(uint8_t *buf, ArrayRef<RelTy> rels) {
910910

911911
for (size_t i = 0, relsSize = rels.size(); i != relsSize; ++i) {
912912
const RelTy &rel = rels[i];
913-
RelType type = rel.getType(config->isMips64EL);
914-
915-
// GCC 8.0 or earlier have a bug that they emit R_386_GOTPC relocations
916-
// against _GLOBAL_OFFSET_TABLE_ for .debug_info. The bug has been fixed
917-
// in 2017 (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82630), but we
918-
// need to keep this bug-compatible code for a while.
919-
if (emachine == EM_386 && type == R_386_GOTPC)
920-
continue;
921-
922-
uint64_t offset = rel.r_offset;
913+
const RelType type = rel.getType(config->isMips64EL);
914+
const uint64_t offset = rel.r_offset;
923915
uint8_t *bufLoc = buf + offset;
924916
int64_t addend = getAddend<ELFT>(rel);
925917
if (!RelTy::IsRela)
@@ -1016,8 +1008,8 @@ void InputSection::relocateNonAlloc(uint8_t *buf, ArrayRef<RelTy> rels) {
10161008
std::string msg = getLocation(offset) + ": has non-ABS relocation " +
10171009
toString(type) + " against symbol '" + toString(sym) +
10181010
"'";
1019-
if (expr != R_PC) {
1020-
error(msg);
1011+
if (expr != R_PC && !(emachine == EM_386 && type == R_386_GOTPC)) {
1012+
errorOrWarn(msg);
10211013
return;
10221014
}
10231015

@@ -1029,11 +1021,11 @@ void InputSection::relocateNonAlloc(uint8_t *buf, ArrayRef<RelTy> rels) {
10291021
// address 0. For bug-compatibility, we accept them with warnings. We
10301022
// know Steel Bank Common Lisp as of 2018 have this bug.
10311023
//
1032-
// RELA -r stopped earlier and does not get the warning. Suppress the
1033-
// warning for REL -r as well
1034-
// (https://github.com/ClangBuiltLinux/linux/issues/1937).
1035-
if (RelTy::IsRela || !config->relocatable)
1036-
warn(msg);
1024+
// GCC 8.0 or earlier have a bug that they emit R_386_GOTPC relocations
1025+
// against _GLOBAL_OFFSET_TABLE_ for .debug_info. The bug has been fixed in
1026+
// 2017 (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82630), but we need to
1027+
// keep this bug-compatible code for a while.
1028+
warn(msg);
10371029
target.relocateNoSym(
10381030
bufLoc, type,
10391031
SignExtend64<bits>(sym.getVA(addend - offset - outSecOff)));

lld/test/ELF/i386-debug-noabs.test

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# REQUIRES: x86
22

33
# RUN: yaml2obj %s -o %t.o
4-
# RUN: ld.lld %t.o -o /dev/null --entry 0 --fatal-warnings
4+
# RUN: ld.lld %t.o -o /dev/null --entry 0 2>&1 | FileCheck %s
5+
# CHECK: warning: {{.*}}:(.debug_info+0x41f): has non-ABS relocation R_386_GOTPC against symbol '_GLOBAL_OFFSET_TABLE_'
56

67
## This is for https://bugs.llvm.org//show_bug.cgi?id=34852. GCC 8.0 or
78
## earlier have a bug which creates non-absolute R_386_GOTPC relocations

lld/test/ELF/non-abs-reloc.s

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
// DISASM-NEXT: 6: call{{.}} 0x5
1616

1717
/// There is currently no error for -r. See also https://github.com/ClangBuiltLinux/linux/issues/1937
18-
// RUN: ld.lld -T lds -r a.o -o /dev/null --fatal-warnings
18+
// RUN: ld.lld -T lds -r a.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=REL-R --implicit-check-not=warning:
19+
// REL-R: warning: {{.*}}:(.nonalloc1+0xa): has non-ABS relocation R_386_PC32 against symbol ''
1920

2021
// RUN: llvm-mc -filetype=obj -triple=x86_64 asm -o b.o
2122
// RUN: ld.lld -T lds b.o -o b 2>&1 | FileCheck %s --check-prefix=CHECK2 --implicit-check-not=warning:

0 commit comments

Comments
 (0)