[lld] 3fd1d69 - [ELF] relocateNonAlloc: clean up workaround code
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 7 12:43:44 PST 2023
Author: Fangrui Song
Date: 2023-12-07T12:43:40-08:00
New Revision: 3fd1d6953d12e2fba6b5efae0a725500c963ce3a
URL: https://github.com/llvm/llvm-project/commit/3fd1d6953d12e2fba6b5efae0a725500c963ce3a
DIFF: https://github.com/llvm/llvm-project/commit/3fd1d6953d12e2fba6b5efae0a725500c963ce3a.diff
LOG: [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.
Added:
Modified:
lld/ELF/InputSection.cpp
lld/test/ELF/i386-debug-noabs.test
lld/test/ELF/non-abs-reloc.s
Removed:
################################################################################
diff --git a/lld/ELF/InputSection.cpp b/lld/ELF/InputSection.cpp
index 2c06bb594158c..81468a20dfb54 100644
--- a/lld/ELF/InputSection.cpp
+++ b/lld/ELF/InputSection.cpp
@@ -910,16 +910,8 @@ void InputSection::relocateNonAlloc(uint8_t *buf, ArrayRef<RelTy> rels) {
for (size_t i = 0, relsSize = rels.size(); i != relsSize; ++i) {
const RelTy &rel = rels[i];
- RelType type = rel.getType(config->isMips64EL);
-
- // GCC 8.0 or earlier have a bug that they emit R_386_GOTPC relocations
- // against _GLOBAL_OFFSET_TABLE_ for .debug_info. The bug has been fixed
- // in 2017 (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82630), but we
- // need to keep this bug-compatible code for a while.
- if (emachine == EM_386 && type == R_386_GOTPC)
- continue;
-
- uint64_t offset = rel.r_offset;
+ const RelType type = rel.getType(config->isMips64EL);
+ const uint64_t offset = rel.r_offset;
uint8_t *bufLoc = buf + offset;
int64_t addend = getAddend<ELFT>(rel);
if (!RelTy::IsRela)
@@ -1016,8 +1008,8 @@ void InputSection::relocateNonAlloc(uint8_t *buf, ArrayRef<RelTy> rels) {
std::string msg = getLocation(offset) + ": has non-ABS relocation " +
toString(type) + " against symbol '" + toString(sym) +
"'";
- if (expr != R_PC) {
- error(msg);
+ if (expr != R_PC && !(emachine == EM_386 && type == R_386_GOTPC)) {
+ errorOrWarn(msg);
return;
}
@@ -1029,11 +1021,11 @@ void InputSection::relocateNonAlloc(uint8_t *buf, ArrayRef<RelTy> rels) {
// address 0. For bug-compatibility, we accept them with warnings. We
// know Steel Bank Common Lisp as of 2018 have this bug.
//
- // RELA -r stopped earlier and does not get the warning. Suppress the
- // warning for REL -r as well
- // (https://github.com/ClangBuiltLinux/linux/issues/1937).
- if (RelTy::IsRela || !config->relocatable)
- warn(msg);
+ // GCC 8.0 or earlier have a bug that they emit R_386_GOTPC relocations
+ // against _GLOBAL_OFFSET_TABLE_ for .debug_info. The bug has been fixed in
+ // 2017 (https://gcc.gnu.org/bugzilla/show_bug.cgi?id=82630), but we need to
+ // keep this bug-compatible code for a while.
+ warn(msg);
target.relocateNoSym(
bufLoc, type,
SignExtend64<bits>(sym.getVA(addend - offset - outSecOff)));
diff --git a/lld/test/ELF/i386-debug-noabs.test b/lld/test/ELF/i386-debug-noabs.test
index 486cc8d9fbed8..02ef238dd1485 100644
--- a/lld/test/ELF/i386-debug-noabs.test
+++ b/lld/test/ELF/i386-debug-noabs.test
@@ -1,7 +1,8 @@
# REQUIRES: x86
# RUN: yaml2obj %s -o %t.o
-# RUN: ld.lld %t.o -o /dev/null --entry 0 --fatal-warnings
+# RUN: ld.lld %t.o -o /dev/null --entry 0 2>&1 | FileCheck %s
+# CHECK: warning: {{.*}}:(.debug_info+0x41f): has non-ABS relocation R_386_GOTPC against symbol '_GLOBAL_OFFSET_TABLE_'
## This is for https://bugs.llvm.org//show_bug.cgi?id=34852. GCC 8.0 or
## earlier have a bug which creates non-absolute R_386_GOTPC relocations
diff --git a/lld/test/ELF/non-abs-reloc.s b/lld/test/ELF/non-abs-reloc.s
index 04f583ab25347..42b5f8fec1c43 100644
--- a/lld/test/ELF/non-abs-reloc.s
+++ b/lld/test/ELF/non-abs-reloc.s
@@ -15,7 +15,8 @@
// DISASM-NEXT: 6: call{{.}} 0x5
/// There is currently no error for -r. See also https://github.com/ClangBuiltLinux/linux/issues/1937
-// RUN: ld.lld -T lds -r a.o -o /dev/null --fatal-warnings
+// RUN: ld.lld -T lds -r a.o -o /dev/null 2>&1 | FileCheck %s --check-prefix=REL-R --implicit-check-not=warning:
+// REL-R: warning: {{.*}}:(.nonalloc1+0xa): has non-ABS relocation R_386_PC32 against symbol ''
// RUN: llvm-mc -filetype=obj -triple=x86_64 asm -o b.o
// RUN: ld.lld -T lds b.o -o b 2>&1 | FileCheck %s --check-prefix=CHECK2 --implicit-check-not=warning:
More information about the llvm-commits
mailing list