forked from OSchip/llvm-project
[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). Catch such errors. Symbol index 0 may be used by marker relocations, e.g. R_*_NONE R_ARM_V4BX. Don't error on them. The difference from D61563 (which caused msan failure) is we don't call Sym.computeBinding() on local symbols - VersionId is uninitialized. llvm-svn: 361213
This commit is contained in:
parent
67510fac36
commit
547e3e930c
|
|
@ -675,11 +675,11 @@ static int64_t computeAddend(const RelTy &Rel, const RelTy *End,
|
||||||
// Returns true if this function printed out an error message.
|
// Returns true if this function printed out an error message.
|
||||||
static bool maybeReportUndefined(Symbol &Sym, InputSectionBase &Sec,
|
static bool maybeReportUndefined(Symbol &Sym, InputSectionBase &Sec,
|
||||||
uint64_t Offset) {
|
uint64_t Offset) {
|
||||||
if (Sym.isLocal() || !Sym.isUndefined() || Sym.isWeak())
|
if (!Sym.isUndefined() || Sym.isWeak())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
bool CanBeExternal =
|
bool CanBeExternal = !Sym.isLocal() && Sym.computeBinding() != STB_LOCAL &&
|
||||||
Sym.computeBinding() != STB_LOCAL && Sym.Visibility == STV_DEFAULT;
|
Sym.Visibility == STV_DEFAULT;
|
||||||
if (Config->UnresolvedSymbols == UnresolvedPolicy::Ignore && CanBeExternal)
|
if (Config->UnresolvedSymbols == UnresolvedPolicy::Ignore && CanBeExternal)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
@ -1012,7 +1012,8 @@ template <class ELFT, class RelTy>
|
||||||
static void scanReloc(InputSectionBase &Sec, OffsetGetter &GetOffset, RelTy *&I,
|
static void scanReloc(InputSectionBase &Sec, OffsetGetter &GetOffset, RelTy *&I,
|
||||||
RelTy *End) {
|
RelTy *End) {
|
||||||
const RelTy &Rel = *I;
|
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;
|
RelType Type;
|
||||||
|
|
||||||
// Deal with MIPS oddity.
|
// Deal with MIPS oddity.
|
||||||
|
|
@ -1028,8 +1029,9 @@ static void scanReloc(InputSectionBase &Sec, OffsetGetter &GetOffset, RelTy *&I,
|
||||||
if (Offset == uint64_t(-1))
|
if (Offset == uint64_t(-1))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Skip if the target symbol is an erroneous undefined symbol.
|
// Error if the target symbol is undefined. Symbol index 0 may be used by
|
||||||
if (maybeReportUndefined(Sym, Sec, Rel.r_offset))
|
// 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;
|
return;
|
||||||
|
|
||||||
const uint8_t *RelocatedAddr = Sec.data().begin() + Rel.r_offset;
|
const uint8_t *RelocatedAddr = Sec.data().begin() + Rel.r_offset;
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,8 @@
|
||||||
# REQUIRES: x86
|
# REQUIRES: x86
|
||||||
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t
|
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
|
||||||
# RUN: ld.lld %t -o %t1
|
# RUN: not ld.lld %t.o -o %t 2>&1 | FileCheck %s
|
||||||
# RUN: llvm-readobj --symbols %t1 | FileCheck %s
|
|
||||||
|
|
||||||
# CHECK: Symbols [
|
# CHECK: error: undefined symbol: foo
|
||||||
# CHECK-NOT: Name: foo
|
|
||||||
|
|
||||||
.global _start
|
.global _start
|
||||||
_start:
|
_start:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue