Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dllist() returns no items on FreeBSD #50846

Closed
ararslan opened this issue Aug 8, 2023 · 6 comments · Fixed by #51114
Closed

dllist() returns no items on FreeBSD #50846

ararslan opened this issue Aug 8, 2023 · 6 comments · Fixed by #51114
Assignees
Labels
system:freebsd Affects only FreeBSD upstream The issue is with an upstream dependency, e.g. LLVM

Comments

@ararslan
Copy link
Member

ararslan commented Aug 8, 2023

With Julia 1.9.2 on FreeBSD 13.2, dllist() returns 42 entries. With 1.10.0-beta1 and master, it incorrectly returns 0 entries. The libdl and binaryplatform tests are failing for this reason. This is a regression introduced by #50162. Specifically, reordering the sources for symbol lookup to put the exe last caused this; the sanitizer parts of that PR are unrelated.

@ararslan ararslan added regression Regression in behavior compared to a previous version system:freebsd Affects only FreeBSD labels Aug 8, 2023
@staticfloat
Copy link
Member

staticfloat commented Aug 9, 2023

Just to make sure we're not barking up the wrong tree, have you tried manually reverting that change (reordering the if statements) and verifying that dllist() then works? I ask because dllist() doesn't seem to touch jl_dlfind.

@ararslan
Copy link
Member Author

ararslan commented Aug 9, 2023

Yes, that's how I was able to determine that it was the reordering that caused the breakage. dllist doesn't use jl_dlfind directly but it does use ccall which uses jl_dlfind when dlsym doesn't find what it's looking for in libjulia-internal.

@topolarity
Copy link
Member

It seems that dl_iterate_phdr is an overloaded weak symbol on FreeBSD:

$ readelf -sW /lib/libc.so.7 | grep dl_iterate_phdr
   840: 0000000000094fe0   199 FUNC    WEAK   DEFAULT   13 dl_iterate_phdr@@FBSD_1.0 (2)
$ readelf -sW /libexec/ld-elf.so.1 | grep dl_iterate_phdr
    10: 000000000000cfa0   748 FUNC  GLOBAL   DEFAULT   12 dl_iterate_phdr@@FBSD_1.0 (2)

Compare to Linux:

$ readelf -sW /lib/x86_64-linux-gnu/libc.so.6 | grep dl_iterate_phdr
  1138: 0000000000174d30   532 FUNC    WEAK   DEFAULT   15 dl_iterate_phdr@@GLIBC_2.2.5
$ readelf -sW /lib64/ld-linux-x86-64.so.2 | grep dl_iterate_phdr
(nothing)

After #50162, we end up resolving to the dl_iterate_phdr function provided by libc.so.7 rather than ld-elf.so.1 (which is the dynamic linker on FreeBSD).

@ararslan
Copy link
Member Author

ararslan commented Aug 9, 2023

In your PR, you noted

During bootstrapping, many internal symbols (e.g. jl_fl_parse) are found in the global EXE namespace leading to an ambiguous lookup in Julia-in-Julia scenarios.

Can you elaborate on what that scenario is and how the prior ordering caused issues? The simplest "solution" to this issue is to add an #ifdef and preserve the previous order for lookups on FreeBSD while retaining the current order elsewhere, but that's not a particularly good solution since it sounds like the PR fixed something that could cause an actual problem, which presumably would also apply to FreeBSD. I don't actually understand what that problem is though.

@vtjnash
Copy link
Member

vtjnash commented Aug 30, 2023

Turned out to be an upstream bug (https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=272992), now fixed. Found by @topolarity

@vtjnash vtjnash closed this as completed Aug 30, 2023
@vtjnash vtjnash added upstream The issue is with an upstream dependency, e.g. LLVM and removed regression Regression in behavior compared to a previous version labels Aug 30, 2023
@topolarity
Copy link
Member

I still want to merge a small fix for this on our side, since that fix is not available in any stable FreeBSD release yet

@topolarity topolarity reopened this Aug 30, 2023
DilumAluthge pushed a commit that referenced this issue Aug 31, 2023
ELF doesn't handle WEAK symbols dynamically the way it handles them
statically.

Looking up overloaded WEAK symbols via a library-specific handle will
often give you the empty stub (in `libc.so.7` in this case) instead of
the strong implementation elsewhere (`ld-elf.so.1` here).

Even after the [upstream
fix](https://cgit.freebsd.org/src/commit/?id=21a52f99440c9bec7679f3b0c5c9d888901c3694),
`dlsym`, `dladdr` and a ton of other symbols still have stubs with no
trampoline in FreeBSD's libc:

https://cgit.freebsd.org/src/tree/lib/libc/gen/dlfcn.c?id=21a52f99440c9bec7679f3b0c5c9d888901c3694
Thankfully `dl_iterate_phdr` appears to be the only function that we
directly `ccall` from Julia's Libdl so we can leave this fix incomplete
for now.

Resolves #50846.
KristofferC pushed a commit that referenced this issue Sep 15, 2023
ELF doesn't handle WEAK symbols dynamically the way it handles them
statically.

Looking up overloaded WEAK symbols via a library-specific handle will
often give you the empty stub (in `libc.so.7` in this case) instead of
the strong implementation elsewhere (`ld-elf.so.1` here).

Even after the [upstream
fix](https://cgit.freebsd.org/src/commit/?id=21a52f99440c9bec7679f3b0c5c9d888901c3694),
`dlsym`, `dladdr` and a ton of other symbols still have stubs with no
trampoline in FreeBSD's libc:

https://cgit.freebsd.org/src/tree/lib/libc/gen/dlfcn.c?id=21a52f99440c9bec7679f3b0c5c9d888901c3694
Thankfully `dl_iterate_phdr` appears to be the only function that we
directly `ccall` from Julia's Libdl so we can leave this fix incomplete
for now.

Resolves #50846.

(cherry picked from commit c659011)
nalimilan pushed a commit that referenced this issue Nov 5, 2023
ELF doesn't handle WEAK symbols dynamically the way it handles them
statically.

Looking up overloaded WEAK symbols via a library-specific handle will
often give you the empty stub (in `libc.so.7` in this case) instead of
the strong implementation elsewhere (`ld-elf.so.1` here).

Even after the [upstream
fix](https://cgit.freebsd.org/src/commit/?id=21a52f99440c9bec7679f3b0c5c9d888901c3694),
`dlsym`, `dladdr` and a ton of other symbols still have stubs with no
trampoline in FreeBSD's libc:

https://cgit.freebsd.org/src/tree/lib/libc/gen/dlfcn.c?id=21a52f99440c9bec7679f3b0c5c9d888901c3694
Thankfully `dl_iterate_phdr` appears to be the only function that we
directly `ccall` from Julia's Libdl so we can leave this fix incomplete
for now.

Resolves #50846.

(cherry picked from commit c659011)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
system:freebsd Affects only FreeBSD upstream The issue is with an upstream dependency, e.g. LLVM
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants