Created attachment 246617 [details] Minimal reproducer Consider the attached example, with a build.sh to build it: libutil provides get_value, set_value -- it's built into both libutil.so and libutil2.so, two separate libraries with purposefully conflicting symbols libfoo provides print_value (which calls get_value) and links against libutil2 app links against libutil and dlopens $ORIGIN/libfoo.so with RTLD_DEEPBIND and calls set_value(5) to get a different value for get_value() On Linux, this prints: % ./app application value 5 library value: 10 On FreeBSD: $ ./app application value 5 library value: 5 So under glibc, symbol_lookup from the dlopened image prefers symbols from the same chain of objects that were loaded at that dlopen time, not just the same image.
https://reviews.freebsd.org/D42841 Could you, please, convert the reproducer into a test case?
(In reply to Konstantin Belousov from comment #1) Thanks! Yes, I will go ahead and turn this into a proper test-case.
I created https://reviews.freebsd.org/D42843 and threw it on the same stack for discoverability.
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=9daf6cd0f46416d9c6eb0411ea6042cd42b8a9bc commit 9daf6cd0f46416d9c6eb0411ea6042cd42b8a9bc Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2023-11-29 18:30:59 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2023-11-30 19:34:36 +0000 RTLD_DEEPBIND: make lookup not just symbolic, but walk all refobj' DAGs before starting the walk over the global list. Effectively we visit needed objects first as well, instead of just the object itself. This seems to better match the semantic offered by the glibc flag. Reported by: kevans PR: 275393 Reviewed by: kevans Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential revision: https://reviews.freebsd.org/D42841 libexec/rtld-elf/rtld.c | 8 ++++++-- libexec/rtld-elf/rtld.h | 1 + 2 files changed, 7 insertions(+), 2 deletions(-)
A commit in branch main references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=d9c543b6b0cabea6e6679d70b4e701018e7eab80 commit d9c543b6b0cabea6e6679d70b4e701018e7eab80 Author: Kyle Evans <kevans@FreeBSD.org> AuthorDate: 2023-12-01 01:26:09 +0000 Commit: Kyle Evans <kevans@FreeBSD.org> CommitDate: 2023-12-01 01:26:09 +0000 rtld: add a test for RTLD_DEEPBIND This tests that with RTLD_DEEPBIND, symbols are looked up in all of the object's needed objects before the global object. PR: 275393 Reviewed by: kib Sponsored by: NetApp, Inc. Sponsored by: Klara, Inc. Differential Revision: https://reviews.freebsd.org/D42843 etc/mtree/BSD.tests.dist | 2 + libexec/rtld-elf/tests/Makefile | 5 +- libexec/rtld-elf/tests/Makefile.inc (new) | 3 + libexec/rtld-elf/tests/libdeep/Makefile (new) | 15 +++++ libexec/rtld-elf/tests/libdeep/libdeep.c (new) | 28 ++++++++++ libexec/rtld-elf/tests/libval/Makefile (new) | 10 ++++ libexec/rtld-elf/tests/libval/libval.c (new) | 26 +++++++++ libexec/rtld-elf/tests/libval2/Makefile (new) | 8 +++ .../rtld-elf/tests/rtld_deepbind/Makefile (new) | 10 ++++ .../tests/rtld_deepbind/rtld_deepbind.c (new) | 65 ++++++++++++++++++++++ libexec/rtld-elf/tests/target/Makefile | 2 +- 11 files changed, 172 insertions(+), 2 deletions(-)
A commit in branch stable/14 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=8d0740e8b9dd05513ef23e2dee7194f32551df13 commit 8d0740e8b9dd05513ef23e2dee7194f32551df13 Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2023-11-29 18:30:59 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2023-12-07 00:27:19 +0000 RTLD_DEEPBIND: make lookup not just symbolic, but walk all refobj' DAGs PR: 275393 (cherry picked from commit 9daf6cd0f46416d9c6eb0411ea6042cd42b8a9bc) libexec/rtld-elf/rtld.c | 8 ++++++-- libexec/rtld-elf/rtld.h | 1 + 2 files changed, 7 insertions(+), 2 deletions(-)
A commit in branch stable/13 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=07fa8d431c0ea291a0e4b79a0bb81707d0b119e6 commit 07fa8d431c0ea291a0e4b79a0bb81707d0b119e6 Author: Konstantin Belousov <kib@FreeBSD.org> AuthorDate: 2023-11-29 18:30:59 +0000 Commit: Konstantin Belousov <kib@FreeBSD.org> CommitDate: 2023-12-07 00:27:34 +0000 RTLD_DEEPBIND: make lookup not just symbolic, but walk all refobj' DAGs PR: 275393 (cherry picked from commit 9daf6cd0f46416d9c6eb0411ea6042cd42b8a9bc) libexec/rtld-elf/rtld.c | 8 ++++++-- libexec/rtld-elf/rtld.h | 1 + 2 files changed, 7 insertions(+), 2 deletions(-)
A commit in branch stable/14 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=2ef9079ece5a97aba7a288040fea805d8599a6f4 commit 2ef9079ece5a97aba7a288040fea805d8599a6f4 Author: Kyle Evans <kevans@FreeBSD.org> AuthorDate: 2023-12-01 01:26:09 +0000 Commit: Kyle Evans <kevans@FreeBSD.org> CommitDate: 2023-12-15 00:58:36 +0000 rtld: add a test for RTLD_DEEPBIND This tests that with RTLD_DEEPBIND, symbols are looked up in all of the object's needed objects before the global object. PR: 275393 Reviewed by: kib Sponsored by: NetApp, Inc. Sponsored by: Klara, Inc. (cherry picked from commit d9c543b6b0cabea6e6679d70b4e701018e7eab80) etc/mtree/BSD.tests.dist | 2 + libexec/rtld-elf/tests/Makefile | 5 +- libexec/rtld-elf/tests/Makefile.inc (new) | 3 + libexec/rtld-elf/tests/libdeep/Makefile (new) | 15 +++++ libexec/rtld-elf/tests/libdeep/libdeep.c (new) | 28 ++++++++++ libexec/rtld-elf/tests/libval/Makefile (new) | 10 ++++ libexec/rtld-elf/tests/libval/libval.c (new) | 26 +++++++++ libexec/rtld-elf/tests/libval2/Makefile (new) | 8 +++ .../rtld-elf/tests/rtld_deepbind/Makefile (new) | 10 ++++ .../tests/rtld_deepbind/rtld_deepbind.c (new) | 65 ++++++++++++++++++++++ libexec/rtld-elf/tests/target/Makefile | 2 +- 11 files changed, 172 insertions(+), 2 deletions(-)
A commit in branch stable/13 references this bug: URL: https://cgit.FreeBSD.org/src/commit/?id=9986fd59d855234cbb999b2a4099ad3cd094aa49 commit 9986fd59d855234cbb999b2a4099ad3cd094aa49 Author: Kyle Evans <kevans@FreeBSD.org> AuthorDate: 2023-12-01 01:26:09 +0000 Commit: Kyle Evans <kevans@FreeBSD.org> CommitDate: 2023-12-15 16:56:59 +0000 rtld: add a test for RTLD_DEEPBIND This tests that with RTLD_DEEPBIND, symbols are looked up in all of the object's needed objects before the global object. ATF_REQUIRE_INTEQ was added after stable/13 branched, so we shim it out here. PR: 275393 Reviewed by: kib Sponsored by: NetApp, Inc. Sponsored by: Klara, Inc. (cherry picked from commit d9c543b6b0cabea6e6679d70b4e701018e7eab80) etc/mtree/BSD.tests.dist | 2 + libexec/rtld-elf/tests/Makefile | 5 +- libexec/rtld-elf/tests/Makefile.inc (new) | 3 + libexec/rtld-elf/tests/libdeep/Makefile (new) | 15 +++++ libexec/rtld-elf/tests/libdeep/libdeep.c (new) | 28 +++++++++ libexec/rtld-elf/tests/libval/Makefile (new) | 10 +++ libexec/rtld-elf/tests/libval/libval.c (new) | 26 ++++++++ libexec/rtld-elf/tests/libval2/Makefile (new) | 8 +++ .../rtld-elf/tests/rtld_deepbind/Makefile (new) | 10 +++ .../tests/rtld_deepbind/rtld_deepbind.c (new) | 72 ++++++++++++++++++++++ libexec/rtld-elf/tests/target/Makefile | 2 +- 11 files changed, 179 insertions(+), 2 deletions(-)
Thanks!