KEMBAR78
binutils: symlink ld.so.conf by cho-m · Pull Request #235571 · Homebrew/homebrew-core · GitHub
Skip to content

Conversation

@cho-m
Copy link
Member

@cho-m cho-m commented Aug 30, 2025

Fixes https://github.com/orgs/Homebrew/discussions/5421. No revision bump as very small number of users impacted. Those that need fix can brew postinstall binutils or brew reinstall binutils.

An alternative fix is adding -rpath-link via cc shim, i.e. change https://github.com/Homebrew/brew/blob/main/Library/Homebrew/shims/super/cc#L374

args << "#{wl}-rpath-link=#{@opt}/#{versioned_glibc_dep}/lib" if versioned_glibc_dep

maybe to

args << if versioned_glibc_dep
  "#{wl}-rpath-link=#{@opt}/#{versioned_glibc_dep}/lib"
else
  "#{wl}-rpath-link=#{@opt}/glibc/lib"
end

Though this does apply it when glibc is installed but not really needed. Would be better to constrain based on whether brew glibc is in dependency tree.


For analysis of issue, looking at ld man page1, the shared libraries' libraries seem to be resolved in order of

  1. -rpath-link
  2. -rpath
  3. export LD_RUN_PATH=... (skip) - only if (1) and (2) are not used which is never in brew
  4. SunOS ... (skip)
  5. export LD_LIBRARY_PATH=... (skip) - usually not used in brew
  6. DT_RUNPATH or DT_RPATH - these don't include glibc
  7. /etc/ld.so.conf - this looks like where we are finding system glibc rather than brew glibc

Binutils does prioritize <prefix>/etc/ld.so.conf over /etc/ld.so.conf at https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=ld/ldelf.c;h=f4f27fc3873440398ff85a403e8b98a834e5697c;hb=HEAD#l946

      tmppath = concat (ld_sysroot, prefix, "/etc/ld.so.conf",
			(const char *) NULL);
      if (!ldelf_parse_ld_so_conf (&info, tmppath))
	{
	  free (tmppath);
	  tmppath = concat (ld_sysroot, "/etc/ld.so.conf",
			    (const char *) NULL);
	  ldelf_parse_ld_so_conf (&info, tmppath);
	}

Footnotes

  1. https://man.archlinux.org/man/ld.1.en#rpath

@cho-m cho-m added in progress Stale bot should stay away maintainer feedback Additional maintainers' opinions may be needed CI-no-bottles Merge without publishing bottles labels Aug 30, 2025
@cho-m cho-m marked this pull request as ready for review August 30, 2025 03:22
@cho-m cho-m added the automerge-skip `brew pr-automerge` will skip this pull request label Aug 30, 2025
Copy link
Member

@ZhongRuoyu ZhongRuoyu left a comment

Choose a reason for hiding this comment

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

I agree that we can handle this in cc shim to cover more scenarios, though this change here looks OK too.

@cho-m
Copy link
Member Author

cho-m commented Sep 1, 2025

cc @Homebrew/core if anyone else is aware of any problematic corner cases. Otherwise will merge sometime today.


I was looking into what happens when user does brew install glibc but seems okay given we always overwrite HOMEBREW_PREFIX/lib/ld.so when brew glibc is installed. So the change here would align with how we expect dynamic linker/loader to behave within Homebrew.

Outside of Homebrew, trying to use brew binutils ld with system libraries while brew glibc is installed could be impacted but this is already caveated in glibc:

By default, Homebrew's linker will not search for the system's libraries. If you
want Homebrew to do so, run:

@Bo98
Copy link
Member

Bo98 commented Sep 1, 2025

It's unfortunate the etc directory is not customisable without a patch - this post install wouldn't be needed if it was.

I'm fine with the approach in general but do have a slight concern that it's sensitive to install order. e.g. if binutils is installed first then it won't trigger this post install if glibc is installed later. It may be worth considering whether this has any place in the global post install instead: https://github.com/Homebrew/brew/blob/main/Library/Homebrew/extend/os/linux/install.rb. (Bonus: it'll also be faster since per-formula post install adds ~1s to pour/install times)

@cho-m
Copy link
Member Author

cho-m commented Sep 1, 2025

I'm fine with the approach in general but do have a slight concern that it's sensitive to install order. e.g. if binutils is installed first then it won't trigger this post install if glibc is installed later. It may be worth considering whether this has any place in the global post install instead: https://github.com/Homebrew/brew/blob/main/Library/Homebrew/extend/os/linux/install.rb. (Bonus: it'll also be faster since per-formula post install adds ~1s to pour/install times)

I was considering a different alternative to add a skip_clean symlink inside bottle. That should allow fallback to /etc/ld.so.conf when glibc is not installed.

@Bo98
Copy link
Member

Bo98 commented Sep 1, 2025

Happy with that if it works!

@cho-m cho-m removed the CI-no-bottles Merge without publishing bottles label Sep 2, 2025
@cho-m cho-m force-pushed the binutils-ld.so.conf branch from 59cb4f7 to b4e93f0 Compare September 2, 2025 21:37
@github-actions github-actions bot removed the automerge-skip `brew pr-automerge` will skip this pull request label Sep 2, 2025
@cho-m cho-m removed in progress Stale bot should stay away maintainer feedback Additional maintainers' opinions may be needed labels Sep 3, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Sep 3, 2025

:shipit: @cho-m has requested bottles to be published to this PR.

Caution

Please do not push to this PR branch before the bottle commits have been pushed, as this results in a state that is difficult to recover from. If you need to resolve a merge conflict, please use a merge commit. Do not force-push to this PR branch.

@github-actions github-actions bot added the CI-published-bottle-commits The commits for the built bottles have been pushed to the PR branch. label Sep 3, 2025
@BrewTestBot BrewTestBot added this pull request to the merge queue Sep 3, 2025
Merged via the queue into main with commit d411f86 Sep 3, 2025
22 checks passed
@BrewTestBot BrewTestBot deleted the binutils-ld.so.conf branch September 3, 2025 13:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CI-published-bottle-commits The commits for the built bottles have been pushed to the PR branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants