Skip to content

Commit 9f8ffaa

Browse files
committed
[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.
1 parent 03a4f1f commit 9f8ffaa

File tree

4 files changed

+8
-14
lines changed

4 files changed

+8
-14
lines changed

lld/ELF/Relocations.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,16 +1094,10 @@ static void processRelocAux(InputSectionBase &sec, RelExpr expr, RelType type,
10941094
}
10951095
}
10961096

1097-
if (config->isPic) {
1098-
errorOrWarn("relocation " + toString(type) + " cannot be used against " +
1099-
(sym.getName().empty() ? "local symbol"
1100-
: "symbol '" + toString(sym) + "'") +
1101-
"; recompile with -fPIC" + getLocation(sec, sym, offset));
1102-
return;
1103-
}
1104-
1105-
errorOrWarn("symbol '" + toString(sym) + "' has no type" +
1106-
getLocation(sec, sym, offset));
1097+
errorOrWarn("relocation " + toString(type) + " cannot be used against " +
1098+
(sym.getName().empty() ? "local symbol"
1099+
: "symbol '" + toString(sym) + "'") +
1100+
"; recompile with -fPIC" + getLocation(sec, sym, offset));
11071101
}
11081102

11091103
// This function is similar to the `handleTlsRelocation`. MIPS does not

lld/test/ELF/copy-errors.s

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88
// CHECK: >>> defined in {{.*}}.so
99
// CHECK: >>> referenced by {{.*}}.o:(.text+0x1)
1010

11-
// CHECK: error: symbol 'zed' has no type
11+
// CHECK: error: relocation R_X86_64_PC32 cannot be used against symbol 'zed'; recompile with -fPIC
1212
// CHECK-NEXT: >>> defined in {{.*}}.so
1313
// CHECK-NEXT: >>> referenced by {{.*}}.o:(.text+0x6)
1414

1515
// RUN: ld.lld --noinhibit-exec %t.o %t2.so -o %t 2>&1 | FileCheck %s --check-prefix=NOINHIBIT
1616
// NOINHIBIT: warning: cannot preempt symbol: bar
1717
// NOINHIBIT-NEXT: >>> defined in {{.*}}.so
1818
// NOINHIBIT-NEXT: >>> referenced by {{.*}}.o:(.text+0x1)
19-
// NOINHIBIT: warning: symbol 'zed' has no type
19+
// NOINHIBIT: warning: relocation R_X86_64_PC32 cannot be used against symbol 'zed'; recompile with -fPIC
2020
// NOINHIBIT-NEXT: >>> defined in {{.*}}.so
2121
// NOINHIBIT-NEXT: >>> referenced by {{.*}}.o:(.text+0x6)
2222

lld/test/ELF/tls-weak-undef.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# RUN: ld.lld -shared %tdef.o -o %tdef.so
2424
# RUN: not ld.lld %texec.o %tdef.so -o /dev/null 2>&1 | FileCheck --check-prefix=ERROR %s
2525

26-
# ERROR: symbol 'le' has no type
26+
# ERROR: error: relocation R_X86_64_TPOFF32 cannot be used against symbol 'le'; recompile with -fPIC
2727

2828
#--- ledef.s
2929
.tbss

lld/test/ELF/x86-64-dyn-rel-error.s

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ _start:
1414
// RUN: ld.lld --noinhibit-exec %t.o %t2.so -o /dev/null 2>&1 | FileCheck --check-prefix=WARN %s
1515
// RUN: not ld.lld --export-dynamic --unresolved-symbols=ignore-all %t.o -o /dev/null 2>&1 | FileCheck --check-prefix=WARN %s
1616

17-
// WARN: symbol 'zed' has no type
17+
// WARN: relocation R_X86_64_32 cannot be used against symbol 'zed'; recompile with -fPIC

0 commit comments

Comments
 (0)