Skip to content

build: defer libwhich lookup in symlink_system_library#61243

Merged
IanButterworth merged 2 commits intomasterfrom
mh/macos-libwhich-crash
Mar 6, 2026
Merged

build: defer libwhich lookup in symlink_system_library#61243
IanButterworth merged 2 commits intomasterfrom
mh/macos-libwhich-crash

Conversation

@fingolfin
Copy link
Copy Markdown
Member

@fingolfin fingolfin commented Mar 5, 2026

Run libwhich -p inside the symlink recipe shell instead of
using $(shell ...) in a recursively expanded make variable.

This keeps evaluation timing explicit and avoids unpredictable
expansion behavior from recursive $(shell ...).

The lookup still happens only when the symlink target is built,
so default builds and clean targets do not trigger unnecessary
probes.

This fixes in particular annoying segfaults in libwhich on macOS when
it tries to inspect libcrypto or libssl. Since USE_SYSTEM_OPENSSL=0
by default, the failed lookups don't matter but they look scary and
if CrashReporter is active, can be also rather annoying.

Resolves #57670

Co-authored-by: Codex codex@openai.com

Switch `libname_$2` and `libpath_$2` in `base/Makefile` from immediate
(`:=`) to recursive (`=`) assignment in `symlink_system_library`.

This avoids running `libwhich -p` while parsing the makefile. With
immediate expansion, these probes are executed unconditionally, even
when the corresponding `USE_SYSTEM_*` setting is disabled. On macOS,
probing some names can abort in `libwhich` and pollute normal `make`,
`make clean`, or `make cleanall` output.

By deferring expansion to recipe execution, lookups happen only when
the symlink target is actually needed.

This fixes in particular annoying segfaults in libwhich on macOS when
it tries to inspect libcrypto or libssl. Since USE_SYSTEM_OPENSSL=0
by default, the failed lookups don't matter but they look scary and
if CrashReporter is active, can be also rather annoying.

Resolves #57670

Co-authored-by: Codex <codex@openai.com>
@fingolfin fingolfin added building Build system, or building Julia or its dependencies backport 1.13 Change should be backported to release-1.13 backport 1.12 Change should be backported to release-1.12 labels Mar 5, 2026
base/Makefile Outdated
libname_$2 := $$(notdir $(call versioned_libname,$2,$3))
libpath_$2 := $$(shell $$(call spawn,$$(LIBWHICH)) -p $$(libname_$2) 2>/dev/null)
libname_$2 = $$(notdir $(call versioned_libname,$2,$3))
libpath_$2 = $$(shell $$(call spawn,$$(LIBWHICH)) -p $$(libname_$2) 2>/dev/null)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$(shell inside a recursive expansion is an antipattern, because the expansion point becomes unpredictable. My suggestion would be a simply-expanded $(eval inside the target definition. See e.g. https://stackoverflow.com/questions/1909188/define-make-variable-at-rule-execution-time

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I might be wrong about when $(eval runs. In that case these could be made shell variables. My point is to avoid the $(shell) in the recursive expansion.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind, just double checked, $(eval is fine.

Copy link
Copy Markdown
Member

@Keno Keno Mar 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although in this case may need to be $$(eval of course.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, I (or rather Codex 😂) rewrote it with a different approach which I hope addresses your concern (at least it does seem sensible to me)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, codex did the In that case these could be made shell variables suggestion I made above, which works fine.

@fingolfin fingolfin force-pushed the mh/macos-libwhich-crash branch from 894fdaf to 4610f79 Compare March 6, 2026 14:52
Run `libwhich -p` inside the symlink recipe shell instead of
using `$(shell ...)` in a recursively expanded make variable.

This keeps evaluation timing explicit and avoids unpredictable
expansion behavior from recursive `$(shell ...)`.

The lookup still happens only when the symlink target is built,
so default builds and clean targets do not trigger unnecessary
probes.

This fixes in particular annoying segfaults in libwhich on macOS when
it tries to inspect libcrypto or libssl. Since USE_SYSTEM_OPENSSL=0
by default, the failed lookups don't matter but they look scary and
if CrashReporter is active, can be also rather annoying.

Resolves #57670

Co-authored-by: Codex <codex@openai.com>
@fingolfin fingolfin force-pushed the mh/macos-libwhich-crash branch from 4610f79 to 1c6dec4 Compare March 6, 2026 14:52
@fingolfin fingolfin added the merge me PR is reviewed. Merge when all tests are passing label Mar 6, 2026
@IanButterworth IanButterworth merged commit 18827b7 into master Mar 6, 2026
9 of 10 checks passed
@IanButterworth IanButterworth deleted the mh/macos-libwhich-crash branch March 6, 2026 19:59
@DilumAluthge DilumAluthge removed the merge me PR is reviewed. Merge when all tests are passing label Mar 6, 2026
KristofferC pushed a commit that referenced this pull request Mar 9, 2026
Co-authored-by: Codex <codex@openai.com>
(cherry picked from commit 18827b7)
KristofferC pushed a commit that referenced this pull request Mar 12, 2026
Co-authored-by: Codex <codex@openai.com>
(cherry picked from commit 18827b7)
@KristofferC KristofferC removed the backport 1.13 Change should be backported to release-1.13 label Mar 13, 2026
@KristofferC KristofferC removed the backport 1.12 Change should be backported to release-1.12 label Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

building Build system, or building Julia or its dependencies

Projects

None yet

Development

Successfully merging this pull request may close these issues.

libwhich segfaults when building on macOS

5 participants