HomeFreeBSD

rtld: Switch to the standard symbol lookup behavior if LD_DYNAMIC_WEAK is set

Description

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

Details

Provenance
fbsd-phab_maskray.meAuthored on Aug 15 2021, 4:13 AM
kibCommitted on Aug 16 2021, 10:55 AM
Reviewer
kib
Differential Revision
D26352: rtld: Switch to the standard symbol lookup behavior if LD_DYNAMIC_WEAK=0
Parents
rG300e08933e80: libc tls: use TLS_DTV_OFFSET defined by rtld.h
Branches
Unknown
Tags
Unknown