When there is no definition for a weak undef STT_FUNC symbol, the function's address should resolve to absolute zero, not some random address. In Bug 15435 gold was changed to accept weak undefs with STV_HIDDEN, however when no definition is present it seems to resolve to some garbage address [1], instead of zero. This is easily reproducible with the sample from the same bug. --- extern void undefined () __attribute__((visibility("hidden"))) __attribute__((weak)); int main () { if (&undefined != 0) return 1; return 0; } --- $ gcc main.c -fuse-ld=bfd && ./a.out; echo $? 0 $ gcc main.c -fuse-ld=gold && ./a.out; echo $? 1 $ gcc main.c -fuse-ld=lld && ./a.out; echo $? 0 $ gcc main.c -fuse-ld=mold && ./a.out; echo $? 0 [1]: https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/29986#note_2516917
A patch is posted at https://sourceware.org/pipermail/binutils/2024-August/136394.html
Here is the v2 patch: https://sourceware.org/pipermail/binutils/2024-August/136395.html
The master branch has been updated by H.J. Lu <hjl@sourceware.org>: https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=229ecf80f35c64145678e537daf54358d16107e3 commit 229ecf80f35c64145678e537daf54358d16107e3 Author: H.J. Lu <hjl.tools@gmail.com> Date: Wed Aug 21 08:06:41 2024 -0700 gold: Always resolve non-default weak undefined to 0 Non-default weak undefined symbols in executable and shared library are always resolved to 0 at runtime and don't need dynamic relocation. Tested on i686, x86-64, powerpc64le and aarch64. PR gold/32071 * symtab.cc (Symbol::final_value_is_known): Always resolve non-default weak undefined symbol in executable and shared library to 0 at runtime. * symtab.h (Symbol::needs_dynamic_reloc): Return false for non-default weak undefined symbol in executable and shared library. * testsuite/Makefile.am: Add weak_undef_test_3 and weak_undef_test_4 tests. * testsuite/Makefile.in: Regenerated. * testsuite/weak_undef_lib_4.c: New file. * testsuite/weak_undef_test_3.c: Likewise. * testsuite/weak_undef_test_4.c: Likewise. Signed-off-by: H.J. Lu <hjl.tools@gmail.com>
Fixed for 2.44.
Thanks for fixing.