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

shims/super/cc: unset LD_LIBRARY_PATH #18162

Merged
merged 3 commits into from
Aug 25, 2024
Merged

shims/super/cc: unset LD_LIBRARY_PATH #18162

merged 3 commits into from
Aug 25, 2024

Conversation

ZhongRuoyu
Copy link
Member

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

A local ruby build failed while building extensions, with:

*** Following extensions are not compiled:
-test-/file:
  Could not be configured. It will not be installed.
  /tmp/ruby-20240824-893184-ehcnsa/ruby-3.3.4/lib/mkmf.rb:480: The compiler failed to generate an executable file.
  You have to install development tools first.
  Check ext/-test-/file/mkmf.log for more details.
-test-/symbol:
  Could not be configured. It will not be installed.
  /tmp/ruby-20240824-893184-ehcnsa/ruby-3.3.4/lib/mkmf.rb:480: The compiler failed to generate an executable file.
  You have to install development tools first.
  Check ext/-test-/symbol/mkmf.log for more details.
[...]

mkmf.log indicated that the compiler shim failed to load pathname:

LD_LIBRARY_PATH=.:../../.. "gcc-13 -o conftest -I../../../.ext/include/aarch64-linux -I../../.././include -I../../.././ext/-test-/file -I/home/linuxbrew/.linuxbrew/opt/libyaml/include -I/home/linuxbrew/.linuxbrew/opt/openssl@3/include    -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdiv-by-zero -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wold-style-definition -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable -Wmisleading-indentation -Wundef  -fPIC conftest.c  -L. -L../../.. -L/home/linuxbrew/.linuxbrew/opt/libyaml/lib -Wl,-rpath,/home/linuxbrew/.linuxbrew/opt/libyaml/lib -L/home/linuxbrew/.linuxbrew/opt/openssl@3/lib -Wl,-rpath,/home/linuxbrew/.linuxbrew/opt/openssl@3/lib -L. -fstack-protector-strong -L/home/linuxbrew/.linuxbrew/opt/libyaml/lib  -Wl,-rpath,/home/linuxbrew/.linuxbrew/opt/libyaml/lib -L/home/linuxbrew/.linuxbrew/opt/openssl@3/lib  -Wl,-rpath,/home/linuxbrew/.linuxbrew/opt/openssl@3/lib -rdynamic -Wl,-export-dynamic -Wl,--no-as-needed     -Wl,-rpath,/home/linuxbrew/.linuxbrew/Cellar/ruby/3.3.4/lib -L/home/linuxbrew/.linuxbrew/Cellar/ruby/3.3.4/lib -lruby-static -lz -lrt -lrt -ldl -lcrypt -lm -lpthread   -lm -lpthread  -lc"
/home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/shims/linux/super/gcc-13:12:in `require': cannot load such file -- pathname (LoadError)
  from /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/shims/linux/super/gcc-13:12:in `<main>'

I believe this was due to ../../.. in LD_LIBRARY_PATH containing libruby.so, causing the Ruby script to load the being-built Ruby library instead of the system/portable one.

A local `ruby` build failed while building extensions, with:

    *** Following extensions are not compiled:
    -test-/file:
      Could not be configured. It will not be installed.
      /tmp/ruby-20240824-893184-ehcnsa/ruby-3.3.4/lib/mkmf.rb:480: The compiler failed to generate an executable file.
      You have to install development tools first.
      Check ext/-test-/file/mkmf.log for more details.
    -test-/symbol:
      Could not be configured. It will not be installed.
      /tmp/ruby-20240824-893184-ehcnsa/ruby-3.3.4/lib/mkmf.rb:480: The compiler failed to generate an executable file.
      You have to install development tools first.
      Check ext/-test-/symbol/mkmf.log for more details.
    [...]

`mkmf.log` indicated that the compiler shim failed to load `pathname`:

    LD_LIBRARY_PATH=.:../../.. "gcc-13 -o conftest -I../../../.ext/include/aarch64-linux -I../../.././include -I../../.././ext/-test-/file -I/home/linuxbrew/.linuxbrew/opt/libyaml/include -I/home/linuxbrew/.linuxbrew/opt/openssl@3/include    -O3 -fno-fast-math -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wdiv-by-zero -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wpointer-arith -Wwrite-strings -Wold-style-definition -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable -Wmisleading-indentation -Wundef  -fPIC conftest.c  -L. -L../../.. -L/home/linuxbrew/.linuxbrew/opt/libyaml/lib -Wl,-rpath,/home/linuxbrew/.linuxbrew/opt/libyaml/lib -L/home/linuxbrew/.linuxbrew/opt/openssl@3/lib -Wl,-rpath,/home/linuxbrew/.linuxbrew/opt/openssl@3/lib -L. -fstack-protector-strong -L/home/linuxbrew/.linuxbrew/opt/libyaml/lib  -Wl,-rpath,/home/linuxbrew/.linuxbrew/opt/libyaml/lib -L/home/linuxbrew/.linuxbrew/opt/openssl@3/lib  -Wl,-rpath,/home/linuxbrew/.linuxbrew/opt/openssl@3/lib -rdynamic -Wl,-export-dynamic -Wl,--no-as-needed     -Wl,-rpath,/home/linuxbrew/.linuxbrew/Cellar/ruby/3.3.4/lib -L/home/linuxbrew/.linuxbrew/Cellar/ruby/3.3.4/lib -lruby-static -lz -lrt -lrt -ldl -lcrypt -lm -lpthread   -lm -lpthread  -lc"
    /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/shims/linux/super/gcc-13:12:in `require': cannot load such file -- pathname (LoadError)
      from /home/linuxbrew/.linuxbrew/Homebrew/Library/Homebrew/shims/linux/super/gcc-13:12:in `<main>'

I believe this was due to `../../..` in `LD_LIBRARY_PATH` containing
`libruby.so`, causing the Ruby script to load the being-built Ruby
library instead of the system/portable one.
@ZhongRuoyu ZhongRuoyu requested a review from Bo98 August 25, 2024 15:53
@Bo98
Copy link
Member

Bo98 commented Aug 25, 2024

Where does the LD_LIBRARY_PATH come from if we have env filtering?

@Bo98
Copy link
Member

Bo98 commented Aug 25, 2024

Oh right I think I understand now - misread the part that it's how our compiler shim executing Ruby that fails.

@ZhongRuoyu
Copy link
Member Author

It comes from the Ruby build itself, somehow. The gcc-13 shim (which I believe does not have environment filtering) was invoked with LD_LIBRARY_PATH=.:../../...

@Bo98
Copy link
Member

Bo98 commented Aug 25, 2024

Does GNU ld use LD_LIBRARY_PATH itself at all? I wonder if we need to save this env and then re-apply it before invoking the real compiler/linker?

This could be used by the linker [^1] so let's preserve it before
invoking the compiler/linker.

[^1]: https://sourceware.org/binutils/docs/ld/Options.html
@ZhongRuoyu
Copy link
Member Author

Ah it does seem so: https://sourceware.org/binutils/docs/ld/Options.html

-rpath-link=dir

When additional shared libraries are required, the linker will search directories in the order listed below in order to find them. ...

...
5. For a native linker, search the contents of the environment variable LD_LIBRARY_PATH.

So preserving the variable makes sense. I've pushed an update.

Library/Homebrew/shims/super/cc Outdated Show resolved Hide resolved
@Bo98 Bo98 enabled auto-merge August 25, 2024 16:51
@Bo98 Bo98 merged commit 17e3bee into master Aug 25, 2024
24 checks passed
@Bo98 Bo98 deleted the cc-LD_LIBRARY_PATH branch August 25, 2024 16:55
@MikeMcQuaid
Copy link
Member

Thanks @ZhongRuoyu, good catch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants