Homebrew / brew

🍺 The missing package manager for macOS (or Linux)
https://brew.sh
BSD 2-Clause "Simplified" License
41.13k stars 9.65k forks source link

Changing the DYLIB ID of bundled Java runtime breaks all dylibs #12777

Closed aalmiray closed 2 years ago

aalmiray commented 2 years ago

brew config output

HOMEBREW_VERSION: 3.3.11-103-g768b172
ORIGIN: https://github.com/Homebrew/brew
HEAD: 768b172393339b4654107dc6a840a2cd08dc64b9
Last commit: 2 days ago
Core tap ORIGIN: https://github.com/Homebrew/homebrew-core
Core tap HEAD: bdc3ee9820351c4bc71f678239a491a29a41e3b1
Core tap last commit: 32 minutes ago
Core tap branch: master
HOMEBREW_PREFIX: /usr/local
HOMEBREW_CASK_OPTS: []
HOMEBREW_CORE_GIT_REMOTE: https://github.com/Homebrew/homebrew-core
HOMEBREW_DISPLAY: /private/tmp/com.apple.launchd.VpyjeHrqCk/org.macosforge.xquartz:0
HOMEBREW_MAKE_JOBS: 12
Homebrew Ruby: 2.6.8 => /usr/local/Homebrew/Library/Homebrew/vendor/portable-ruby/2.6.8/bin/ruby
CPU: dodeca-core 64-bit kabylake
Clang: 13.0.0 build 1300
Git: 2.31.1 => /usr/local/bin/git
Curl: 7.64.1 => /usr/bin/curl
macOS: 11.6.2-x86_64
CLT: 13.2.0.0.1.1638488800
Xcode: 13.2.1

brew doctor output

Warning: Calling bottle :unneeded is deprecated! There is no replacement.
Please report this issue to the gitea/tap tap (not Homebrew/brew or Homebrew/core):
  /usr/local/Homebrew/Library/Taps/gitea/homebrew-tap/gitea.rb:40

Uninstalling /usr/local/Cellar/jreleaser/1.0.0-M1... (228 files, 79.8MB)
aalmiray2:local aalmiray$ brew doctor
Warning: Calling bottle :unneeded is deprecated! There is no replacement.
Please report this issue to the gitea/tap tap (not Homebrew/brew or Homebrew/core):
  /usr/local/Homebrew/Library/Taps/gitea/homebrew-tap/gitea.rb:40

Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: Some installed formulae are deprecated or disabled.
You should find replacements for the following formulae:
  ilmbase

Warning: Unbrewed dylibs were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected dylibs:
  /usr/local/lib/libndi.3.dylib
  /usr/local/lib/libndi.4.dylib

Warning: Unbrewed static libraries were found in /usr/local/lib.
If you didn't put them there on purpose they could cause problems when
building Homebrew formulae, and may need to be deleted.

Unexpected static libraries:
  /usr/local/lib/libsopfli.a

Warning: You have unlinked kegs in your Cellar.
Leaving kegs unlinked can lead to build-trouble and cause formulae that depend on
those kegs to fail to run properly once built. Run `brew link` on these:
  unbound
  imagemagick
  gnupg
  python@3.9

Verification

What were you trying to do (and why)?

This issue is similar to https://github.com/Homebrew/brew/issues/9526

Verified on my local environment, reported by @ApfelSaucell at https://github.com/jreleaser/jreleaser/issues/675

JReleaser's formula bundles a Java Runtime (built with Java's jlink). This results in a minimum Java runtime that may be used to launch the app without an external dependency to a Java formula. Java runtimes include dylib files whose ids are relocated upon install but shouldn't.

What happened (include all command output)?

$ brew install jreleaser/tap/jreleaser
$ jreleaser -V
Killed: 9

What did you expect to happen?

JReleaser's version should appear on the console, such as

$ jreleaser -V
------------------------------------------------------------
jreleaser 1.0.0-M1
------------------------------------------------------------
Build time:   2022-01-22 09:38:55Z
Revision:     2489915b925abc10a1f0c4cf2afa2fae75f031ba
------------------------------------------------------------

Step-by-step reproduction instructions (by running brew commands)

$  HOMEBREW_VERBOSE=1 HOMEBREW_DEBUG=1 brew install jreleaser/tap/jreleaser
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::TapLoader): loading /usr/local/Homebrew/Library/Taps/jreleaser/homebrew-tap/Formula/jreleaser.rb
==> Downloading https://github.com/jreleaser/jreleaser/releases/download/v1.0.0-M1/jreleaser-standalone-1.0.0-M1-osx-x86_64.zip
/usr/local/Homebrew/Library/Homebrew/shims/shared/curl --disable --cookie /dev/null --globoff --show-error --user-agent Homebrew/3.3.11-103-g768b172\ \(Macintosh\;\ Intel\ Mac\ OS\ X\ 11.6.2\)\ curl/7.64.1 --header Accept-Language:\ en --retry 3 --location --silent --head --request GET https://github.com/jreleaser/jreleaser/releases/download/v1.0.0-M1/jreleaser-standalone-1.0.0-M1-osx-x86_64.zip
Already downloaded: /Users/aalmiray/Library/Caches/Homebrew/downloads/95b8fc13c00ccb025cfe60b16f9150961cd2e3f7130651cab8556cb5d81a4247--jreleaser-standalone-1.0.0-M1-osx-x86_64.zip
==> Verifying checksum for '95b8fc13c00ccb025cfe60b16f9150961cd2e3f7130651cab8556cb5d81a4247--jreleaser-standalone-1.0.0-M1-osx-x86_64.zip'
==> Installing jreleaser from jreleaser/tap
/usr/local/Homebrew/Library/Homebrew/shims/shared/git --version
ln -s ../Cellar/jreleaser/1.0.0-M1/bin/jreleaser jreleaser
==> Changing dylib ID of /usr/local/Cellar/jreleaser/1.0.0-M1/libexec/lib/libawt.dylib
  from @rpath/libawt.dylib
    to /usr/local/opt/jreleaser/libexec/lib/libawt.dylib
==> Changing dylib ID of /usr/local/Cellar/jreleaser/1.0.0-M1/libexec/lib/libawt_lwawt.dylib
  from @rpath/libawt_lwawt.dylib
    to /usr/local/opt/jreleaser/libexec/lib/libawt_lwawt.dylib
==> Changing dylib ID of /usr/local/Cellar/jreleaser/1.0.0-M1/libexec/lib/libextnet.dylib
  from @rpath/libextnet.dylib
    to /usr/local/opt/jreleaser/libexec/lib/libextnet.dylib
==> Changing dylib ID of /usr/local/Cellar/jreleaser/1.0.0-M1/libexec/lib/libfontmanager.dylib
  from @rpath/libfontmanager.dylib
    to /usr/local/opt/jreleaser/libexec/lib/libfontmanager.dylib
==> Changing dylib ID of /usr/local/Cellar/jreleaser/1.0.0-M1/libexec/lib/libfreetype.dylib
  from @rpath/libfreetype.dylib
    to /usr/local/opt/jreleaser/libexec/lib/libfreetype.dylib
==> Changing dylib ID of /usr/local/Cellar/jreleaser/1.0.0-M1/libexec/lib/libj2gss.dylib
  from @rpath/libj2gss.dylib
    to /usr/local/opt/jreleaser/libexec/lib/libj2gss.dylib
==> Changing dylib ID of /usr/local/Cellar/jreleaser/1.0.0-M1/libexec/lib/libj2pkcs11.dylib
  from @rpath/libj2pkcs11.dylib
    to /usr/local/opt/jreleaser/libexec/lib/libj2pkcs11.dylib
==> Changing dylib ID of /usr/local/Cellar/jreleaser/1.0.0-M1/libexec/lib/libjaas.dylib
  from @rpath/libjaas.dylib
    to /usr/local/opt/jreleaser/libexec/lib/libjaas.dylib
==> Changing dylib ID of /usr/local/Cellar/jreleaser/1.0.0-M1/libexec/lib/libjava.dylib
  from @rpath/libjava.dylib
    to /usr/local/opt/jreleaser/libexec/lib/libjava.dylib
==> Changing dylib ID of /usr/local/Cellar/jreleaser/1.0.0-M1/libexec/lib/libjavajpeg.dylib
  from @rpath/libjavajpeg.dylib
    to /usr/local/opt/jreleaser/libexec/lib/libjavajpeg.dylib
==> Changing dylib ID of /usr/local/Cellar/jreleaser/1.0.0-M1/libexec/lib/libjawt.dylib
  from @rpath/libjawt.dylib
    to /usr/local/opt/jreleaser/libexec/lib/libjawt.dylib
==> Changing dylib ID of /usr/local/Cellar/jreleaser/1.0.0-M1/libexec/lib/libjimage.dylib
  from @rpath/libjimage.dylib
    to /usr/local/opt/jreleaser/libexec/lib/libjimage.dylib
==> Changing dylib ID of /usr/local/Cellar/jreleaser/1.0.0-M1/libexec/lib/libjli.dylib
  from @rpath/libjli.dylib
    to /usr/local/opt/jreleaser/libexec/lib/libjli.dylib
==> Changing dylib ID of /usr/local/Cellar/jreleaser/1.0.0-M1/libexec/lib/libjsig.dylib
  from @rpath/libjsig.dylib
    to /usr/local/opt/jreleaser/libexec/lib/libjsig.dylib
==> Changing dylib ID of /usr/local/Cellar/jreleaser/1.0.0-M1/libexec/lib/libjsound.dylib
  from @rpath/libjsound.dylib
    to /usr/local/opt/jreleaser/libexec/lib/libjsound.dylib
==> Changing dylib ID of /usr/local/Cellar/jreleaser/1.0.0-M1/libexec/lib/liblcms.dylib
  from @rpath/liblcms.dylib
    to /usr/local/opt/jreleaser/libexec/lib/liblcms.dylib
==> Changing dylib ID of /usr/local/Cellar/jreleaser/1.0.0-M1/libexec/lib/libmanagement.dylib
  from @rpath/libmanagement.dylib
    to /usr/local/opt/jreleaser/libexec/lib/libmanagement.dylib
==> Changing dylib ID of /usr/local/Cellar/jreleaser/1.0.0-M1/libexec/lib/libmlib_image.dylib
  from @rpath/libmlib_image.dylib
    to /usr/local/opt/jreleaser/libexec/lib/libmlib_image.dylib
==> Changing dylib ID of /usr/local/Cellar/jreleaser/1.0.0-M1/libexec/lib/libnet.dylib
  from @rpath/libnet.dylib
    to /usr/local/opt/jreleaser/libexec/lib/libnet.dylib
==> Changing dylib ID of /usr/local/Cellar/jreleaser/1.0.0-M1/libexec/lib/libnio.dylib
  from @rpath/libnio.dylib
    to /usr/local/opt/jreleaser/libexec/lib/libnio.dylib
==> Changing dylib ID of /usr/local/Cellar/jreleaser/1.0.0-M1/libexec/lib/libosx.dylib
  from @rpath/libosx.dylib
    to /usr/local/opt/jreleaser/libexec/lib/libosx.dylib
==> Changing dylib ID of /usr/local/Cellar/jreleaser/1.0.0-M1/libexec/lib/libosxapp.dylib
  from @rpath/libosxapp.dylib
    to /usr/local/opt/jreleaser/libexec/lib/libosxapp.dylib
==> Changing dylib ID of /usr/local/Cellar/jreleaser/1.0.0-M1/libexec/lib/libosxkrb5.dylib
  from @rpath/libosxkrb5.dylib
    to /usr/local/opt/jreleaser/libexec/lib/libosxkrb5.dylib
==> Changing dylib ID of /usr/local/Cellar/jreleaser/1.0.0-M1/libexec/lib/libosxsecurity.dylib
  from @rpath/libosxsecurity.dylib
    to /usr/local/opt/jreleaser/libexec/lib/libosxsecurity.dylib
==> Changing dylib ID of /usr/local/Cellar/jreleaser/1.0.0-M1/libexec/lib/libosxui.dylib
  from @rpath/libosxui.dylib
    to /usr/local/opt/jreleaser/libexec/lib/libosxui.dylib
==> Changing dylib ID of /usr/local/Cellar/jreleaser/1.0.0-M1/libexec/lib/libprefs.dylib
  from @rpath/libprefs.dylib
    to /usr/local/opt/jreleaser/libexec/lib/libprefs.dylib
==> Changing dylib ID of /usr/local/Cellar/jreleaser/1.0.0-M1/libexec/lib/librmi.dylib
  from @rpath/librmi.dylib
    to /usr/local/opt/jreleaser/libexec/lib/librmi.dylib
==> Changing dylib ID of /usr/local/Cellar/jreleaser/1.0.0-M1/libexec/lib/libsplashscreen.dylib
  from @rpath/libsplashscreen.dylib
    to /usr/local/opt/jreleaser/libexec/lib/libsplashscreen.dylib
==> Changing dylib ID of /usr/local/Cellar/jreleaser/1.0.0-M1/libexec/lib/libverify.dylib
  from @rpath/libverify.dylib
    to /usr/local/opt/jreleaser/libexec/lib/libverify.dylib
==> Changing dylib ID of /usr/local/Cellar/jreleaser/1.0.0-M1/libexec/lib/libzip.dylib
  from @rpath/libzip.dylib
    to /usr/local/opt/jreleaser/libexec/lib/libzip.dylib
==> Changing dylib ID of /usr/local/Cellar/jreleaser/1.0.0-M1/libexec/lib/server/libjsig.dylib
  from @rpath/libjsig.dylib
    to /usr/local/opt/jreleaser/libexec/lib/server/libjsig.dylib
==> Changing dylib ID of /usr/local/Cellar/jreleaser/1.0.0-M1/libexec/lib/server/libjvm.dylib
  from @rpath/libjvm.dylib
    to /usr/local/opt/jreleaser/libexec/lib/server/libjvm.dylib
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FromPathLoader): loading /usr/local/opt/jreleaser/.brew/jreleaser.rb
🍺  /usr/local/Cellar/jreleaser/1.0.0-M1: 228 files, 79.8MB, built in 5 seconds
==> Running `brew cleanup jreleaser`...
aalmiray commented 2 years ago

If there's an option to skip relocating dylib files then I'd very much like to know how to apply it to a formula. TIA.

Bo98 commented 2 years ago

We could perhaps skip @rpath IDs, though the effect it may have on the formulae we ship would need careful testing and in practice doesn't have much benefits given everything Homebrew installs lies under one prefix.

With that said, the change itself shouldn't break anything on its own - unless there's non-adhoc codesigning bundles involved? It'll be useful to know more about exactly what the issue is here - a crash report will say if it's a codesigning issue.

We haven't had this issue occur with Homebrew's build of OpenJDK.

aalmiray commented 2 years ago

FWIW the bundled JR and the application (jreleaser) are not codesigned at all.

If skipping relocation is deemed hazardous then perhaps adding a flag to enabled it explicitly plus a warning message would be preferable instead of automatically skipping relocation of @rpath IDS that is, make it a conscious decision for the formula writer (use of the flag or env var) that's passed on to consumers (warning message).

aalmiray commented 2 years ago

re: OpenJDK. I suppose because the formula is built from keg? ID relocation still takes place

$ HOMEBREW_VERBOSE=1 HOMEBREW_DEBUG=1 brew install openjdk
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FormulaLoader): loading /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/openjdk.rb
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FormulaLoader): loading /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/autoconf.rb
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FormulaLoader): loading /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core/Formula/m4.rb
==> Downloading https://ghcr.io/v2/homebrew/core/openjdk/manifests/17.0.1_1
/usr/local/Homebrew/Library/Homebrew/shims/shared/curl --disable --cookie /dev/null --globoff --show-error --user-agent Homebrew/3.3.11-103-g768b172\ \(Macintosh\;\ Intel\ Mac\ OS\ X\ 11.6.2\)\ curl/7.64.1 --header Accept-Language:\ en --retry 3 --header Accept:\ application/vnd.oci.image.index.v1\+json --header Authorization:\ Bearer\ QQ== --location --silent --head --request GET https://ghcr.io/v2/homebrew/core/openjdk/manifests/17.0.1_1
Already downloaded: /Users/aalmiray/Library/Caches/Homebrew/downloads/3b1b62cfad844ff54529068a2fb6ce6454afcb241b5052fc130c7d1fecfb9b33--openjdk-17.0.1_1.bottle_manifest.json
==> Downloading https://ghcr.io/v2/homebrew/core/openjdk/blobs/sha256:75ee17c1331022fa8bf1e63f00fe903f23fe31d3a09021117d46b5f6ed1e26e1
/usr/local/Homebrew/Library/Homebrew/shims/shared/curl --disable --cookie /dev/null --globoff --show-error --user-agent Homebrew/3.3.11-103-g768b172\ \(Macintosh\;\ Intel\ Mac\ OS\ X\ 11.6.2\)\ curl/7.64.1 --header Accept-Language:\ en --retry 3 --header Authorization:\ Bearer\ QQ== --location --silent --head --request GET https://ghcr.io/v2/homebrew/core/openjdk/blobs/sha256:75ee17c1331022fa8bf1e63f00fe903f23fe31d3a09021117d46b5f6ed1e26e1
Already downloaded: /Users/aalmiray/Library/Caches/Homebrew/downloads/bdb0a9271915e9c16093867de598df9d7561fb674784c66599d7f2d6a3b81cc1--openjdk--17.0.1_1.big_sur.bottle.tar.gz
==> Verifying checksum for 'bdb0a9271915e9c16093867de598df9d7561fb674784c66599d7f2d6a3b81cc1--openjdk--17.0.1_1.big_sur.bottle.tar.gz'
/usr/local/Homebrew/Library/Homebrew/shims/shared/git --version
==> Pouring openjdk--17.0.1_1.big_sur.bottle.tar.gz
tar --extract --no-same-owner --file /Users/aalmiray/Library/Caches/Homebrew/downloads/bdb0a9271915e9c16093867de598df9d7561fb674784c66599d7f2d6a3b81cc1--openjdk--17.0.1_1.big_sur.bottle.tar.gz --directory /private/tmp/d20220123-13309-15v3n10
cp -pR /private/tmp/d20220123-13309-15v3n10/openjdk/. /usr/local/Cellar/openjdk
chmod -Rf +w /private/tmp/d20220123-13309-15v3n10
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libattach.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libattach.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libattach.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libawt.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libawt.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libawt.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libawt_lwawt.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libawt_lwawt.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libawt_lwawt.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libdt_socket.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libdt_socket.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libdt_socket.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libextnet.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libextnet.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libextnet.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libfontmanager.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libfontmanager.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libfontmanager.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libfreetype.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libfreetype.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libfreetype.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libinstrument.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libinstrument.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libinstrument.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libj2gss.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libj2gss.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libj2gss.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libj2pcsc.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libj2pcsc.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libj2pcsc.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libj2pkcs11.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libj2pkcs11.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libj2pkcs11.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libjaas.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libjaas.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libjaas.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libjava.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libjava.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libjava.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libjavajpeg.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libjavajpeg.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libjavajpeg.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libjawt.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libjawt.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libjawt.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libjdwp.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libjdwp.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libjdwp.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libjimage.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libjimage.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libjimage.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libjli.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libjli.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libjli.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libjsig.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libjsig.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libjsig.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libjsound.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libjsound.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libjsound.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/liblcms.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/liblcms.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/liblcms.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libmanagement.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libmanagement.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libmanagement.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libmanagement_agent.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libmanagement_agent.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libmanagement_agent.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libmanagement_ext.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libmanagement_ext.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libmanagement_ext.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libmlib_image.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libmlib_image.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libmlib_image.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libnet.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libnet.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libnet.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libnio.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libnio.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libnio.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libosx.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libosx.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libosx.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libosxapp.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libosxapp.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libosxapp.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libosxkrb5.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libosxkrb5.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libosxkrb5.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libosxsecurity.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libosxsecurity.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libosxsecurity.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libosxui.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libosxui.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libosxui.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libprefs.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libprefs.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libprefs.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/librmi.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/librmi.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/librmi.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libsaproc.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libsaproc.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libsaproc.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libsplashscreen.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libsplashscreen.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libsplashscreen.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libsyslookup.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libsyslookup.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libsyslookup.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libverify.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libverify.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libverify.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/libzip.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libzip.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/libzip.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/server/libjsig.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/server/libjsig.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/server/libjsig.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/Home/lib/server/libjvm.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/server/libjvm.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/Home/lib/server/libjvm.dylib
==> Changing dylib ID of /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/MacOS/libjli.dylib
  from @@HOMEBREW_PREFIX@@/opt/openjdk/libexec/openjdk.jdk/Contents/MacOS/libjli.dylib
    to /usr/local/opt/openjdk/libexec/openjdk.jdk/Contents/MacOS/libjli.dylib
/usr/local/Homebrew/Library/Homebrew/brew.rb (Formulary::FromPathLoader): loading /usr/local/opt/openjdk/.brew/openjdk.rb
==> Caveats
For the system Java wrappers to find this JDK, symlink it with
  sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk

openjdk is keg-only, which means it was not symlinked into /usr/local,
because macOS provides similar software and installing this software in
parallel can cause all kinds of trouble.

If you need to have openjdk first in your PATH, run:
  echo 'export PATH="/usr/local/opt/openjdk/bin:$PATH"' >> /Users/aalmiray/.bash_profile

For compilers to find openjdk you may need to set:
  export CPPFLAGS="-I/usr/local/opt/openjdk/include"

==> Summary
🍺  /usr/local/Cellar/openjdk/17.0.1_1: 639 files, 305.2MB
==> Running `brew cleanup openjdk`...
carlocab commented 2 years ago

Do you pass -headerpad_max_install_names to the linker when building your Java runtime?

We could perhaps skip @rpath IDs, though the effect it may have on the formulae we ship would need careful testing and in practice doesn't have much benefits given everything Homebrew installs lies under one prefix.

This was tried previously and broke some things, and was reverted afterward. It can be fixed with -rpath flags, but I'm pretty sure this will leave many users confused about why they need these flags now but didn't use to.

As a workaround, you can carry around something like this in post_install to undo relocation:

https://github.com/Homebrew/homebrew-core/commit/458380086f90b4ebc90f0d5d40b0d7e1fad06657

aalmiray commented 2 years ago

Do you pass -headerpad_max_install_names to the linker when building your Java runtime?

I think that's not an option you can call from jlink

$ jlink -h
Usage: jlink <options> --module-path <modulepath> --add-modules <module>[,<module>...]
Possible options include:
      --add-modules <mod>[,<mod>...]    Root modules to resolve
      --bind-services                   Link in service provider modules and
                                        their dependences
  -c, --compress=<0|1|2>                Enable compression of resources:
                                          Level 0: No compression
                                          Level 1: Constant string sharing
                                          Level 2: ZIP
      --disable-plugin <pluginname>     Disable the plugin mentioned
      --endian <little|big>             Byte order of generated jimage
                                        (default:native)
  -h, --help, -?                        Print this help message
      --ignore-signing-information      Suppress a fatal error when signed
                                        modular JARs are linked in the image.
                                        The signature related files of the
                                        signed modular JARs are not copied to
                                        the runtime image.
      --launcher <name>=<module>[/<mainclass>]
                                        Add a launcher command of the given
                                        name for the module and the main class
                                        if specified  
      --limit-modules <mod>[,<mod>...]  Limit the universe of observable
                                        modules
      --list-plugins                    List available plugins
  -p, --module-path <path>              Module path
      --no-header-files                 Exclude include header files
      --no-man-pages                    Exclude man pages
      --output <path>                   Location of output path
      --post-process-path <imagefile>   Post process an existing image
      --resources-last-sorter <name>    The last plugin allowed to sort
                                        resources
      --save-opts <filename>            Save jlink options in the given file
  -G, --strip-debug                     Strip debug information
      --suggest-providers [<name>,...]  Suggest providers that implement the
                                        given service types from the module path
  -v, --verbose                         Enable verbose tracing
      --version                         Version information
      @<filename>                       Read options from file

As a workaround, you can carry around something like this in post_install to undo relocation:

Homebrew/homebrew-core@4583800

Yes, this is what I thought would be needed. I wasn't sure what piece of code was required to make it work, thanks for the link.

carlocab commented 2 years ago

Do you pass -headerpad_max_install_names to the linker when building your Java runtime?

I think that's not an option you can call from jlink

It is an option consumed by ld.

     -headerpad_max_install_names
             Automatically adds space for future expansion of load commands such that all paths could expand to MAXPATHLEN.  Only
             useful if intend to run install_name_tool to alter the load commands later.
aalmiray commented 2 years ago

How would you use that flag then? Do I have to set it on the formula itself? I've not had the need t use ld before so I have no idea how yo hook it up.

aalmiray commented 2 years ago

FWIW the post_install snippet fixes the problem. Thanks!