[lld] 9f8ffaa - [ELF] Replace "symbol '...' has no type" diagnostic with "relocation ... cannot be used against symbol '...'"
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Sun Oct 31 13:12:31 PDT 2021
Author: Fangrui Song
Date: 2021-10-31T13:12:26-07:00
New Revision: 9f8ffaaa0bddcefeec15a3df9858fd50b05fcbae
URL: https://github.com/llvm/llvm-project/commit/9f8ffaaa0bddcefeec15a3df9858fd50b05fcbae
DIFF: https://github.com/llvm/llvm-project/commit/9f8ffaaa0bddcefeec15a3df9858fd50b05fcbae.diff
LOG: [ELF] Replace "symbol '...' has no type" diagnostic with "relocation ... cannot be used against symbol '...'"
The "symbol 'foo' has no type" diagnostic tries to inform that copy
relocation/canonical PLT entry cannot be used, but the diagnostic is often
incorrect and confusing.
Added:
Modified:
lld/ELF/Relocations.cpp
lld/test/ELF/copy-errors.s
lld/test/ELF/tls-weak-undef.s
lld/test/ELF/x86-64-dyn-rel-error.s
Removed:
################################################################################
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 6c8e57a20210..a8f103b3c86a 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -1094,16 +1094,10 @@ static void processRelocAux(InputSectionBase &sec, RelExpr expr, RelType type,
}
}
- if (config->isPic) {
- errorOrWarn("relocation " + toString(type) + " cannot be used against " +
- (sym.getName().empty() ? "local symbol"
- : "symbol '" + toString(sym) + "'") +
- "; recompile with -fPIC" + getLocation(sec, sym, offset));
- return;
- }
-
- errorOrWarn("symbol '" + toString(sym) + "' has no type" +
- getLocation(sec, sym, offset));
+ errorOrWarn("relocation " + toString(type) + " cannot be used against " +
+ (sym.getName().empty() ? "local symbol"
+ : "symbol '" + toString(sym) + "'") +
+ "; recompile with -fPIC" + getLocation(sec, sym, offset));
}
// This function is similar to the `handleTlsRelocation`. MIPS does not
diff --git a/lld/test/ELF/copy-errors.s b/lld/test/ELF/copy-errors.s
index 5b68307ab88b..2c6f00c0e497 100644
--- a/lld/test/ELF/copy-errors.s
+++ b/lld/test/ELF/copy-errors.s
@@ -8,7 +8,7 @@
// CHECK: >>> defined in {{.*}}.so
// CHECK: >>> referenced by {{.*}}.o:(.text+0x1)
-// CHECK: error: symbol 'zed' has no type
+// CHECK: error: relocation R_X86_64_PC32 cannot be used against symbol 'zed'; recompile with -fPIC
// CHECK-NEXT: >>> defined in {{.*}}.so
// CHECK-NEXT: >>> referenced by {{.*}}.o:(.text+0x6)
@@ -16,7 +16,7 @@
// NOINHIBIT: warning: cannot preempt symbol: bar
// NOINHIBIT-NEXT: >>> defined in {{.*}}.so
// NOINHIBIT-NEXT: >>> referenced by {{.*}}.o:(.text+0x1)
-// NOINHIBIT: warning: symbol 'zed' has no type
+// NOINHIBIT: warning: relocation R_X86_64_PC32 cannot be used against symbol 'zed'; recompile with -fPIC
// NOINHIBIT-NEXT: >>> defined in {{.*}}.so
// NOINHIBIT-NEXT: >>> referenced by {{.*}}.o:(.text+0x6)
diff --git a/lld/test/ELF/tls-weak-undef.s b/lld/test/ELF/tls-weak-undef.s
index 19d1337c9fc8..6f0635607a3f 100644
--- a/lld/test/ELF/tls-weak-undef.s
+++ b/lld/test/ELF/tls-weak-undef.s
@@ -23,7 +23,7 @@
# RUN: ld.lld -shared %tdef.o -o %tdef.so
# RUN: not ld.lld %texec.o %tdef.so -o /dev/null 2>&1 | FileCheck --check-prefix=ERROR %s
-# ERROR: symbol 'le' has no type
+# ERROR: error: relocation R_X86_64_TPOFF32 cannot be used against symbol 'le'; recompile with -fPIC
#--- ledef.s
.tbss
diff --git a/lld/test/ELF/x86-64-dyn-rel-error.s b/lld/test/ELF/x86-64-dyn-rel-error.s
index 6093e4dada9a..8f41f1493dde 100644
--- a/lld/test/ELF/x86-64-dyn-rel-error.s
+++ b/lld/test/ELF/x86-64-dyn-rel-error.s
@@ -14,4 +14,4 @@ _start:
// RUN: ld.lld --noinhibit-exec %t.o %t2.so -o /dev/null 2>&1 | FileCheck --check-prefix=WARN %s
// RUN: not ld.lld --export-dynamic --unresolved-symbols=ignore-all %t.o -o /dev/null 2>&1 | FileCheck --check-prefix=WARN %s
-// WARN: symbol 'zed' has no type
+// WARN: relocation R_X86_64_32 cannot be used against symbol 'zed'; recompile with -fPIC
More information about the llvm-commits
mailing list