summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFangrui Song <maskray@google.com>2019-05-20 11:25:55 +0000
committerFangrui Song <maskray@google.com>2019-05-20 11:25:55 +0000
commit7c7425483ae621c5f197e999c0b49a8cdd5c5ace (patch)
treee09f7310314e007bb84e33611496e3ee77dd95b9
parent95805bc425b264805a472232a75ed2ffe58aceda (diff)
downloadbcm5719-llvm-7c7425483ae621c5f197e999c0b49a8cdd5c5ace.tar.gz
bcm5719-llvm-7c7425483ae621c5f197e999c0b49a8cdd5c5ace.zip
[ELF] Error on relocations to local undefined symbols
For a reference to a local symbol, ld.bfd and gold error if the symbol is defined in a discarded section but accept it if the symbol is undefined. This inconsistent behavior seems unnecessary for us (it probably makes sense for them as they differentiate local/global symbols, the error would mean more code). Weaken the condition to getSymbol(Config->IsMips64EL) == 0 to catch such errors. The symbol index can be 0 (e.g. R_*_NONE R_ARM_V4BX) and we shouldn't error on them. Reviewed By: ruiu Differential Revision: https://reviews.llvm.org/D61563 llvm-svn: 361144
-rw-r--r--lld/ELF/Relocations.cpp10
-rw-r--r--lld/test/ELF/local-undefined-symbol.s8
2 files changed, 9 insertions, 9 deletions
diff --git a/lld/ELF/Relocations.cpp b/lld/ELF/Relocations.cpp
index 74b46174dbf..fbdeb4f346b 100644
--- a/lld/ELF/Relocations.cpp
+++ b/lld/ELF/Relocations.cpp
@@ -675,7 +675,7 @@ static int64_t computeAddend(const RelTy &Rel, const RelTy *End,
// Returns true if this function printed out an error message.
static bool maybeReportUndefined(Symbol &Sym, InputSectionBase &Sec,
uint64_t Offset) {
- if (Sym.isLocal() || !Sym.isUndefined() || Sym.isWeak())
+ if (!Sym.isUndefined() || Sym.isWeak())
return false;
bool CanBeExternal =
@@ -1012,7 +1012,8 @@ template <class ELFT, class RelTy>
static void scanReloc(InputSectionBase &Sec, OffsetGetter &GetOffset, RelTy *&I,
RelTy *End) {
const RelTy &Rel = *I;
- Symbol &Sym = Sec.getFile<ELFT>()->getRelocTargetSym(Rel);
+ uint32_t SymIndex = Rel.getSymbol(Config->IsMips64EL);
+ Symbol &Sym = Sec.getFile<ELFT>()->getSymbol(SymIndex);
RelType Type;
// Deal with MIPS oddity.
@@ -1028,8 +1029,9 @@ static void scanReloc(InputSectionBase &Sec, OffsetGetter &GetOffset, RelTy *&I,
if (Offset == uint64_t(-1))
return;
- // Skip if the target symbol is an erroneous undefined symbol.
- if (maybeReportUndefined(Sym, Sec, Rel.r_offset))
+ // Error if the target symbol is undefined. Symbol index 0 may be used by
+ // marker relocations, e.g. R_*_NONE and R_ARM_V4BX. Don't error on them.
+ if (SymIndex != 0 && maybeReportUndefined(Sym, Sec, Rel.r_offset))
return;
const uint8_t *RelocatedAddr = Sec.data().begin() + Rel.r_offset;
diff --git a/lld/test/ELF/local-undefined-symbol.s b/lld/test/ELF/local-undefined-symbol.s
index bff8c8bc1dc..c2ab207359b 100644
--- a/lld/test/ELF/local-undefined-symbol.s
+++ b/lld/test/ELF/local-undefined-symbol.s
@@ -1,10 +1,8 @@
# REQUIRES: x86
-# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
-# RUN: ld.lld %t -o %t1
-# RUN: llvm-readobj --symbols %t1 | FileCheck %s
+# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
+# RUN: not ld.lld %t.o -o %t 2>&1 | FileCheck %s
-# CHECK: Symbols [
-# CHECK-NOT: Name: foo
+# CHECK: error: undefined symbol: foo
.global _start
_start:
OpenPOWER on IntegriCloud