Closed deejgregor closed 1 year ago
There aren't really too many details to understand on our side, since the full build configuration is shown in the formula:
If the issue is the RPATH configuration, then that seems to be something inherited from the upstream defaults, since we don't pass any related flags. We can adjust it to something more appropriate, but we need to know what the correct way to pass it to the build is.
Could you try rebuilding openjdk
with this patch and see if it helps?
diff --git a/Formula/openjdk.rb b/Formula/openjdk.rb
index b04e356a6de..7a82f21c9b6 100644
--- a/Formula/openjdk.rb
+++ b/Formula/openjdk.rb
@@ -89,7 +89,7 @@ class Openjdk < Formula
args += if OS.mac?
%W[
--enable-dtrace
- --with-extra-ldflags=-headerpad_max_install_names
+ --with-extra-ldflags=-headerpad_max_install_names\ -Wl,-rpath,#{loader_path}/server
--with-sysroot=#{MacOS.sdk_path}
]
else
Could you try rebuilding
openjdk
with this patch and see if it helps?
Yup! I'll give it a whirl on both @11 and current. Give me a little bit of time. This one won't be quick. ;-)
Oops, before you do that, there's a typo in my patch.
Edit: Try that.
Actually, use this one, I always forget how these %W
arrays work:
diff --git a/Formula/openjdk.rb b/Formula/openjdk.rb
index b04e356a6de..7e36210a8be 100644
--- a/Formula/openjdk.rb
+++ b/Formula/openjdk.rb
@@ -89,7 +89,6 @@ class Openjdk < Formula
args += if OS.mac?
%W[
--enable-dtrace
- --with-extra-ldflags=-headerpad_max_install_names
--with-sysroot=#{MacOS.sdk_path}
]
else
@@ -99,6 +98,7 @@ class Openjdk < Formula
--with-fontconfig=#{HOMEBREW_PREFIX}
]
end
+ args << "--with-extra-ldflags=-headerpad_max_install_names -Wl,-rpath,#{loader_path}/server"
chmod 0755, "configure"
system "./configure", *args
Actually, use this one
The updated patch using args << ...
works great! I applied this to both openjdk.rb and openjdk@11.rb and it fixed the problem with both. (openjdk@11 is the important one for me because our app currently only works on 11).
Great; thanks for testing it. The patch as is isn't quite suitable to apply to the formula directly (we don't want -headpad_max_install_names
on Linux), but I'm glad we've zeroed in on the right fix.
I'll look into opening a PR to fix it in a few days, but please feel free to beat me to it.
Oh, one more thing. Can you tell me the output of
otool -l "$(brew --prefix openjdk)/libexec/openjdk.jdk/Contents/Home/lib/libjava.dylib" | grep -A2 LC_RPATH
please? After you've applied the build fix above, I mean.
I'm working on a PR. I'll take care of all of the openjdk versions that are affected that I am able to compile (11, 17, current; not sure about 8 at this point). I should have that worked up by tomorrow.
Does this seem like a decent way to go so that -headpad_max_install_names
isn't set on Linux? There's a little bit of duplication, but it's pretty straightforward (and the original form you showed me worked just fine).
--- Formula/openjdk.rb
+++ Formula/openjdk.rb
@@ -89,7 +89,7 @@ class Openjdk < Formula
args += if OS.mac?
%W[
--enable-dtrace
- --with-extra-ldflags=-headerpad_max_install_names
+ --with-extra-ldflags=-headerpad_max_install_names\ -Wl,-rpath,#{loader_path}/server
--with-sysroot=#{MacOS.sdk_path}
]
else
@@ -97,6 +97,7 @@ class Openjdk < Formula
--with-x=#{HOMEBREW_PREFIX}
--with-cups=#{HOMEBREW_PREFIX}
--with-fontconfig=#{HOMEBREW_PREFIX}
+ --with-extra-ldflags=-Wl,-rpath,#{loader_path}/server"
]
end
$ otool -l "$(brew --prefix openjdk)/libexec/openjdk.jdk/Contents/Home/lib/libjava.dylib" | grep -A2 LC_RPATH
cmd LC_RPATH
cmdsize 32
path @loader_path/server (offset 12)
--
cmd LC_RPATH
cmdsize 32
path @loader_path/. (offset 12)
$ otool -l "$(brew --prefix openjdk\@11)/libexec/openjdk.jdk/Contents/Home/lib/libjava.dylib" | grep -A2 LC_RPATH
cmd LC_RPATH
cmdsize 32
path @loader_path/server (offset 12)
--
cmd LC_RPATH
cmdsize 32
path @loader_path/. (offset 12)
Note: this was the one that was causing me problems.
$ otool -l "$(brew --prefix openjdk\@11)/libexec/openjdk.jdk/Contents/Home/lib/libmanagement.dylib" | grep -A2 LC_RPATH
cmd LC_RPATH
cmdsize 32
path @loader_path/server (offset 12)
--
cmd LC_RPATH
cmdsize 32
path @loader_path/. (offset 12)
$
$ otool -l "$(brew --prefix openjdk\@17)/libexec/openjdk.jdk/Contents/Home/lib/libjava.dylib" | grep -A2 LC_RPATH
cmd LC_RPATH
cmdsize 32
path @loader_path/. (offset 12)
@carlocab I opened a PR over at #111255 and I think it's ready to go, but I have one question mentioned in https://github.com/Homebrew/homebrew-core/pull/111255#issuecomment-1252862341:
Question: I'm not sure if this needs a new revision as mentioned here: https://github.com/Homebrew/homebrew-core/blob/HEAD/CONTRIBUTING.md#to-contribute-a-fix-to-the-foo-formula
Closed in #111255.
brew gist-logs <formula>
link ORbrew config
ANDbrew doctor
outputbrew config
brew doctor
Verification
brew update
and am still able to reproduce my issue.brew doctor
and that did not fix my problem.What were you trying to do (and why)?
Use the pyroscope java agent with opennms for continuous profiling to debug application issues. This loads the async-profiler and its .so to get profiling information out of the JVM. I have the same problem when I try to load
async-profiler
directly. I'm doing this on an M1 Mac using Homebrew OpenJDK.I have a simple reproducer,
ManagementTest
and all of the details I'll share will be from there.If I load either the pyroscope agent or the async-profiler into Homebrew-built OpenJDK 11.0.16.1 or 18.0.2.1, I get this failure:
What happened (include all command output)?
(note that I had to hit ctrl-C to terminate the JVM when loading the pyroscope agent)
If you run with
DYLD_PRINT_APIS=1
(see this page for details), you get to see the detailed error is thatlibmanagement.dylib
fails to loadlibjvm.dylib
:Library not loaded: '@rpath/libjvm.dylib'
. Note thatlibjvm.dylib
is inlib/server
, not directly inlib
:Details:
What did you expect to happen?
The application starts up properly with the agent setup.
It does if I use a patched copy of async-profiler with the patch in this issue: https://github.com/jvm-profiling-tools/async-profiler/issues/647 (see more information the reproduction section).
See also: https://github.com/Homebrew/homebrew-core/issues/66953
Step-by-step reproduction instructions (by running
brew
commands)If I apply this workaround from #647: Patch rpath for Homebrew JDK to
async-profiler
, things work fine. Pyroscope also works fine if I apply the same patch to their patched version of async-profiler and rebuild their.jar
with updated versions of the.so
and its.sha1
file:(note: this example was hacked up from my notes/history, so it might not be 100% correct)
I'm unfortunately not familiar enough with the details of Homebrew builds and the JDK build infrastructure to easily dig into what could be tweaked in https://github.com/iMichka/homebrew-core/blob/master/Formula/openjdk@11.rb to fix this.