forked from OSchip/llvm-project
Fix a crash bug in --start-lib.
Previously, Lazy symbols were created for undefined symbols even though such symbols cannot be resolved by loading object files. This patch fixes that bug. llvm-svn: 265847
This commit is contained in:
parent
e25b65bdb7
commit
1f492893ac
|
@ -594,7 +594,8 @@ template <class ELFT> std::vector<StringRef> LazyObjectFile::getElfSymbols() {
|
|||
StringRef StringTable = check(Obj.getStringTableForSymtab(Sec));
|
||||
std::vector<StringRef> V;
|
||||
for (const Elf_Sym &Sym : Syms.slice(FirstNonLocal))
|
||||
V.push_back(check(Sym.getName(StringTable)));
|
||||
if (Sym.st_shndx != SHN_UNDEF)
|
||||
V.push_back(check(Sym.getName(StringTable)));
|
||||
return V;
|
||||
}
|
||||
return {};
|
||||
|
@ -608,6 +609,8 @@ std::vector<StringRef> LazyObjectFile::getBitcodeSymbols() {
|
|||
for (const BasicSymbolRef &Sym : Obj->symbols()) {
|
||||
if (BitcodeFile::shouldSkip(Sym))
|
||||
continue;
|
||||
if (Sym.getFlags() == BasicSymbolRef::SF_Undefined)
|
||||
continue;
|
||||
SmallString<64> Name;
|
||||
raw_svector_ostream OS(Name);
|
||||
Sym.printName(OS);
|
||||
|
@ -616,7 +619,7 @@ std::vector<StringRef> LazyObjectFile::getBitcodeSymbols() {
|
|||
return V;
|
||||
}
|
||||
|
||||
// Returns a vector of globally-visible symbol names.
|
||||
// Returns a vector of globally-visible defined symbol names.
|
||||
std::vector<StringRef> LazyObjectFile::getSymbols() {
|
||||
if (isBitcode(this->MB))
|
||||
return getBitcodeSymbols();
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
.globl foo
|
||||
foo:
|
||||
call bar
|
|
@ -0,0 +1,2 @@
|
|||
.globl bar
|
||||
bar:
|
|
@ -2,15 +2,24 @@
|
|||
|
||||
// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t1.o
|
||||
// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \
|
||||
// RUN: %p/Inputs/whole-archive.s -o %t2.o
|
||||
// RUN: %p/Inputs/start-lib1.s -o %t2.o
|
||||
// RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux \
|
||||
// RUN: %p/Inputs/start-lib2.s -o %t3.o
|
||||
|
||||
// RUN: ld.lld -o %t3 %t1.o %t2.o
|
||||
// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=ADDED %s
|
||||
// ADDED: Name: _bar
|
||||
// RUN: ld.lld -o %t3 %t1.o %t2.o %t3.o
|
||||
// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=TEST1 %s
|
||||
// TEST1: Name: bar
|
||||
// TEST1: Name: foo
|
||||
|
||||
// RUN: ld.lld -o %t3 %t1.o --start-lib %t2.o
|
||||
// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=LIB %s
|
||||
// LIB-NOT: Name: _bar
|
||||
// RUN: ld.lld -o %t3 %t1.o -u bar --start-lib %t2.o %t3.o
|
||||
// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=TEST2 %s
|
||||
// TEST2: Name: bar
|
||||
// TEST2-NOT: Name: foo
|
||||
|
||||
// RUN: ld.lld -o %t3 %t1.o --start-lib %t2.o %t3.o
|
||||
// RUN: llvm-readobj --symbols %t3 | FileCheck --check-prefix=TEST3 %s
|
||||
// TEST3-NOT: Name: bar
|
||||
// TEST3-NOT: Name: foo
|
||||
|
||||
.globl _start
|
||||
_start:
|
||||
|
|
Loading…
Reference in New Issue