diff --git a/src/system/runtime_loader/elf_symbol_lookup.cpp b/src/system/runtime_loader/elf_symbol_lookup.cpp index 9bb78e195e..d271abf65e 100644 --- a/src/system/runtime_loader/elf_symbol_lookup.cpp +++ b/src/system/runtime_loader/elf_symbol_lookup.cpp @@ -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; diff --git a/src/tests/system/runtime_loader/test_suite/load_resolve_weak1 b/src/tests/system/runtime_loader/test_suite/load_resolve_weak1 new file mode 100755 index 0000000000..bb153e4b7d --- /dev/null +++ b/src/tests/system/runtime_loader/test_suite/load_resolve_weak1 @@ -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 + diff --git a/src/tests/system/runtime_loader/test_suite/load_resolve_weak2 b/src/tests/system/runtime_loader/test_suite/load_resolve_weak2 new file mode 100755 index 0000000000..00b87cacfb --- /dev/null +++ b/src/tests/system/runtime_loader/test_suite/load_resolve_weak2 @@ -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 +