[ELF] Replace "symbol '...' has no type" diagnostic with "relocation ... cannot be...
authorFangrui Song <i@maskray.me>
Sun, 31 Oct 2021 20:12:26 +0000 (13:12 -0700)
committerFangrui Song <i@maskray.me>
Sun, 31 Oct 2021 20:12:26 +0000 (13:12 -0700)
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.

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

index 6c8e57a..a8f103b 100644 (file)
@@ -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
index 5b68307..2c6f00c 100644 (file)
@@ -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)
 
index 19d1337..6f06356 100644 (file)
@@ -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
index 6093e4d..8f41f14 100644 (file)
@@ -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