runtime_loader: treat weak symbols as strong symbols definitions.
http://www.sourceware.org/ml/libc-hacker/2000-06/msg00029.html Change-Id: I15bf1f48dda32942e2a93610d62dabe0cabdc9a1 Reviewed-on: https://review.haiku-os.org/c/1191 Reviewed-by: Adrien Destugues <pulkomandy@gmail.com> Reviewed-by: Jérôme Duval <jerome.duval@gmail.com>
This commit is contained in:
parent
471e44c962
commit
888652929c
@ -377,15 +377,8 @@ find_undefined_symbol_global(image_t* rootImage, image_t* image,
|
||||
&& (otherImage->flags
|
||||
& (RTLD_GLOBAL | RFLAG_USE_FOR_RESOLVING)) != 0)) {
|
||||
if (elf_sym* symbol = find_symbol(otherImage, lookupInfo)) {
|
||||
if (symbol->Bind() != STB_WEAK) {
|
||||
*_foundInImage = otherImage;
|
||||
return symbol;
|
||||
}
|
||||
|
||||
if (candidateSymbol == NULL) {
|
||||
candidateSymbol = symbol;
|
||||
candidateImage = otherImage;
|
||||
}
|
||||
*_foundInImage = otherImage;
|
||||
return symbol;
|
||||
}
|
||||
}
|
||||
otherImage = otherImage->next;
|
||||
|
46
src/tests/system/runtime_loader/test_suite/load_resolve_weak1
Executable file
46
src/tests/system/runtime_loader/test_suite/load_resolve_weak1
Executable file
@ -0,0 +1,46 @@
|
||||
#!/bin/sh
|
||||
|
||||
# program
|
||||
# <- liba.so
|
||||
#
|
||||
# Expected: Weak symbol in liba.so resolves to symbol in program,
|
||||
# not to symbol in liba.so.
|
||||
|
||||
|
||||
. ./test_setup
|
||||
|
||||
|
||||
# create liba.so
|
||||
cat > liba.c << EOI
|
||||
int __attribute__((weak)) c() { return 2; }
|
||||
int __attribute__((weak)) a() { return c(); }
|
||||
int (*a_p)() = &c;
|
||||
int b() { return (*a_p)(); }
|
||||
EOI
|
||||
|
||||
# build
|
||||
compile_lib -o liba.so liba.c
|
||||
|
||||
# create program
|
||||
cat > program.c << EOI
|
||||
extern int a();
|
||||
extern int b();
|
||||
|
||||
int c()
|
||||
{
|
||||
return 4;
|
||||
}
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
return a() + b();
|
||||
}
|
||||
EOI
|
||||
|
||||
# build
|
||||
compile_program -o program program.c ./liba.so
|
||||
|
||||
# run
|
||||
test_run_ok ./program 8
|
||||
|
48
src/tests/system/runtime_loader/test_suite/load_resolve_weak2
Executable file
48
src/tests/system/runtime_loader/test_suite/load_resolve_weak2
Executable file
@ -0,0 +1,48 @@
|
||||
#!/bin/sh
|
||||
|
||||
# program
|
||||
# <- liba.so
|
||||
# <- libb.so
|
||||
# <- libb.so
|
||||
# Expected: symbol in program resolves to weak alias in liba.so,
|
||||
# not to symbol in libb.so.
|
||||
|
||||
|
||||
. ./test_setup
|
||||
|
||||
|
||||
# create libb.so
|
||||
cat > libb.c << EOI
|
||||
int a() { return 4; }
|
||||
EOI
|
||||
|
||||
# build
|
||||
compile_lib -o libb.so libb.c
|
||||
|
||||
|
||||
# create liba.so
|
||||
cat > liba.c << EOI
|
||||
int __a() { return 2; }
|
||||
int a() __attribute__((weak, alias("__a")));
|
||||
EOI
|
||||
|
||||
# build
|
||||
compile_lib -o liba.so liba.c ./libb.so
|
||||
|
||||
# create program
|
||||
cat > program.c << EOI
|
||||
extern int a();
|
||||
|
||||
int
|
||||
main()
|
||||
{
|
||||
return a();
|
||||
}
|
||||
EOI
|
||||
|
||||
# build
|
||||
compile_program -o program program.c ./liba.so ./libb.so
|
||||
|
||||
# run
|
||||
test_run_ok ./program 2
|
||||
|
Loading…
Reference in New Issue
Block a user