]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
rtld: Switch to the standard symbol lookup behavior if LD_DYNAMIC_WEAK is set
authorFangrui Song <i@maskray.me>
Sun, 15 Aug 2021 04:13:33 +0000 (07:13 +0300)
committerKonstantin Belousov <kib@FreeBSD.org>
Mon, 16 Aug 2021 10:55:35 +0000 (13:55 +0300)
commit7da378f9de1a042ec0c81ba7ad39a392540d4721
tree70e0c37d2898172743e74e8747a45f61f2cabac7
parent300e08933e80e9fce02d0d2f7a64e3ad27e4ce8e
rtld: Switch to the standard symbol lookup behavior if LD_DYNAMIC_WEAK is set

The current lookup prefers a strong definition to a STB_WEAK definition
(similar to glibc pre-2.2 behavior) which does not conform to the ELF
specification.

The non-compliant behavior provoked https://reviews.llvm.org/D4418
which was intended to fix -shared-libasan but introduced
new problems (and caused some sanitizer tests (e.g.
test/asan/TestCases/interception_failure_test.cpp) to fail): sanitizer
interceptors are STB_GLOBAL instead of STB_WEAK, so defining a second
STB_GLOBAL interceptor can lead to a multiple definition linker error.
For example, in a -fsanitize={address,memory,...} build, libc functions
like malloc/free/strtol/... cannot be provided by user object files.

See
https://docs.freebsd.org/cgi/getmsg.cgi?fetch=16483939+0+archive/2014/freebsd-current/20140716.freebsd-current
for discussions.

This patch implements the ELF-compliant behavior when LD_DYNAMIC_WEAK is
set. STB_WEAK wrestling in symbol lookups in `Search the dynamic linker
itself` are untouched.

Reviewed by: kib
MFC after: 1 week
Differential revision: https://reviews.freebsd.org/D26352
libexec/rtld-elf/rtld.1
libexec/rtld-elf/rtld.c