[Core] Allow weak symbols in shared library when linking.

Patch by Rui Ueyama.

llvm-svn: 180209
This commit is contained in:
Michael J. Spencer 2013-04-24 19:00:26 +00:00
parent ef35f3a682
commit 9d70cef481
3 changed files with 23 additions and 11 deletions

View File

@ -315,17 +315,19 @@ bool Resolver::checkUndefines(bool final) {
bool foundUndefines = false;
for (const UndefinedAtom *undefAtom : undefinedAtoms) {
const File &f = undefAtom->file();
bool isAtomUndefined = false;
if (isa<SharedLibraryFile>(f)) {
if (!_targetInfo.allowShlibUndefines()) {
foundUndefines = true;
isAtomUndefined = true;
}
} else if (undefAtom->canBeNull() == UndefinedAtom::canBeNullNever) {
foundUndefines = true;
isAtomUndefined = true;
}
if (isAtomUndefined && _targetInfo.printRemainingUndefines()) {
// Skip over a weak symbol.
if (undefAtom->canBeNull() != UndefinedAtom::canBeNullNever)
continue;
// If this is a library and undefined symbols are allowed on the
// target platform, skip over it.
if (isa<SharedLibraryFile>(f) && _targetInfo.allowShlibUndefines())
continue;
// Seems like this symbol is undefined. Warn that.
foundUndefines = true;
if (_targetInfo.printRemainingUndefines()) {
llvm::errs() << "Undefined Symbol: " << undefAtom->file().path()
<< " : " << undefAtom->name() << "\n";
}

View File

@ -3,6 +3,14 @@
extern int i;
int i = 42;
// Undefined weak function in a dynamic library.
__attribute__((weak)) void weakfoo();
// Regular funtion in a dynamic library.
void foo() {
// Try to call weakfoo so that the reference to weekfoo will be included in
// the resulting .so file.
if (weakfoo)
weakfoo();
puts("Fooo!!");
}

View File

@ -25,3 +25,5 @@ RUN: FileCheck -check-prefix=SHLIB %s < %t2
EXEC: Undefined Symbol: {{[-_A-Za-z0-9.\\/]+}}shared.so-x86-64 : puts
SHLIB: Undefined Symbol: {{[-_A-Za-z0-9.\\/]+}}shared.so-x86-64 : puts
EXEC-NOT: Undefined Symbol: {{[-_A-Za-z0-9.\\/]+}}shared.so-x86-64 : weakfoo
SHLIB-NOT: Undefined Symbol: {{[-_A-Za-z0-9.\\/]+}}shared.so-x86-64 : weakfoo