From ec4540d8a62cfef017173ce7309adcb9beca4e53 Mon Sep 17 00:00:00 2001 From: Fangrui Song Date: Mon, 19 Aug 2019 15:52:29 +0000 Subject: [PATCH] [ELF] Simplify processRelocAux and allow a corner-case error After D66007/r369262, if the control flow reaches `if (sym.isUndefined())`, we know: * The relocation is not a link-time constant => symbol is preemptable => Undefined or SharedSymbol * Not an undef weak. * -no-pie. * The symbol type is neither STT_OBJECT nor STT_FUNC. ld.lld --export-dynamic --unresolved-symbols=ignore-all %t.o can satisfy these conditions. Delete the isUndefined() test so that we error `symbol '...' has no type`, because we don't know the type to make the decision to create copy relocation/canonical PLT. llvm-svn: 369271 --- lld/ELF/Relocations.cpp | 4 ---- lld/test/ELF/x86-64-dyn-rel-error.s | 3 ++- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp index 9a11acf..f142154 100644 --- a/lld/ELF/Relocations.cpp +++ b/lld/ELF/Relocations.cpp @@ -1077,10 +1077,6 @@ static void processRelocAux(InputSectionBase &sec, RelExpr expr, RelType type, return; } - // If the symbol is undefined we already reported any relevant errors. - if (sym.isUndefined()) - return; - errorOrWarn("symbol '" + toString(sym) + "' has no type" + getLocation(sec, sym, offset)); } diff --git a/lld/test/ELF/x86-64-dyn-rel-error.s b/lld/test/ELF/x86-64-dyn-rel-error.s index 7753a4d..1c715db 100644 --- a/lld/test/ELF/x86-64-dyn-rel-error.s +++ b/lld/test/ELF/x86-64-dyn-rel-error.s @@ -11,6 +11,7 @@ _start: // CHECK: relocation R_X86_64_32 cannot be used against symbol zed; recompile with -fPIC -// RUN: ld.lld --noinhibit-exec %t.o %t2.so -o %t 2>&1 | FileCheck --check-prefix=WARN %s +// 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 -- 2.7.4