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

[SR-1625] gold linker requires LD_LIBRARY_PATH, whereas bfd did not. Why? #385

Closed
modocache mannequin opened this issue May 26, 2016 · 8 comments
Closed

[SR-1625] gold linker requires LD_LIBRARY_PATH, whereas bfd did not. Why? #385

modocache mannequin opened this issue May 26, 2016 · 8 comments
Assignees

Comments

@modocache
Copy link
Mannequin

modocache mannequin commented May 26, 2016

Previous ID SR-1625
Radar None
Original Reporter @modocache
Type Bug
Status Resolved
Resolution Done
Additional Detail from JIRA
Votes 0
Component/s XCTest
Labels Bug
Assignee @ddunbar
Priority Medium

md5: 8834d6092b4b0cde78eaeff0ec184aa4

relates to:

  • SR-1631 swift-integration-tests failing, unable to find libFoundation.so

Issue Description:

See discussion in #118 For some reason, apple/swift#2609 required an extra LD_LIBRARY_PATH to be specified when running the XCTest test suite. Why is that? And can we do this in a "nicer" way?

@ddunbar
Copy link
Member

ddunbar commented May 26, 2016

@compnerd can you explain why this is required? I wouldn't have expected the Swift change to change behavior for clients?

@compnerd
Copy link
Collaborator

I wouldn't expect that to change either. Interestingly enough, I can't seem to get the binary to run with BFD nor gold unless the LD_LIBRARY_PATH is set.

It seems that we are not setting the RPATH for libXCTest.so which is why it fails.

x86_64-pc-linux-gnu-readelf -Wd /Users/compnerd/Source/swift/build/Ninja-ReleaseAssert/xctest-linux-x86_64/libXCTest.so | grep RUNPATH
0x000000000000001d (RUNPATH) Library runpath: [/Users/compnerd/Source/swift/build/Ninja-ReleaseAssert/swift-linux-x86_64/lib/swift/linux]

Adding it seems to make it work.

x86_64-pc-linux-gnu-readelf -Wd /Users/compnerd/Source/swift/build/Ninja-ReleaseAssert/xctest-linux-x86_64/libXCTest.so | grep RUNPATH
0x000000000000001d (RUNPATH) Library runpath: [/Users/compnerd/Source/swift/build/Ninja-ReleaseAssert/swift-linux-x86_64/lib/swift/linux:/Users/compnerd/Source/swift/build/Ninja-ReleaseAssert/foundation-linux-x86_64/Foundation]

Now, the thing is that Foundation.so is probably going to somewhere in the system root, so adding the DT_RUNPATH for the build environment doesn't really make much sense.

@ddunbar
Copy link
Member

ddunbar commented May 27, 2016

When installed, libFoundation.so will be adjacent to libXCTest.so in the distributed toolchain (`lib/linux`) so we could use rpaths...

@compnerd
Copy link
Collaborator

Hmm, adding `$ORIGIN` to the rpath by default sounds safe and would fix it. A quick test (with adding `$ORIGIN` and symlinking libFoundation.so) does indeed work for me.

@compnerd
Copy link
Collaborator

BTW, running a clean build after the changes with the LD_LIBRARY_PATH change reverted, the tests do seem to pass. Could this just be an oddity of the two linkers producing slightly different results confusing the loader?

@ddunbar
Copy link
Member

ddunbar commented May 31, 2016

Nope.

I believe the problem here, which I tracked down in SR-1631, is that gold defaults to embedding DT_RUNPATH into the library instead of DT_RPATH. I am not very familiar with dynamic library search mechanisms on Linux though, so I don't yet have a complete picture of how this breaks things.

@ddunbar
Copy link
Member

ddunbar commented May 31, 2016

Taking this. I fixed SR-1631, but I think the right fix here is to move to a toolchain based build process, at which point this workaround can maybe go away.

@finagolfin
Copy link
Contributor

Finally removed this hack in #338

@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@shahmishal shahmishal transferred this issue from apple/swift May 9, 2022
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants