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

rpath being set incorrectly #48

Open
twmarshall opened this issue May 14, 2018 · 1 comment
Open

rpath being set incorrectly #48

twmarshall opened this issue May 14, 2018 · 1 comment

Comments

@twmarshall
Copy link
Contributor

When setting LDFLAGS in init-compiler, we do the escaping of "$ORIGIN" in rpath incorrectly - if you look at the output of a build you'll see rpath being set to something of the form 'RIGIN/../lib', when it should be '$ORIGIN/../lib'

I played around with it for awhile and unfortunately was not able to come up with an escaping that seems to actually work.

One possible solution would be to use a tool like chrpath or patchelf to update the rpath after everything is done, as I've done here: https://github.com/twmarshall/native-toolchain/tree/rpath, but this adds a dependency on a non-standard package, which isn't ideal.

@timarmstrong
Copy link
Contributor

I went down a similar rabbit hole a while ago while looking into something else. IIRC one of CMake or autotools handles escaping differently so there's no way to specify $ORIGIN that works for all projects. The hacky solution I came up with was to just include both versions in every RPATH. That way you get a working rpath and a bogus one.

-  # Upgrade rpath variable to catch current library location and possible future location
+  # Add rpath to all binaries we produce that points to the ../lib/ subdirectory relative
+  # to the output binaries or libraries. Need to include versions with both $ORIGIN and
+  # $$ORIGIN to work around autotools and CMake projects inconsistently escaping LDFLAGS
+  # values. We always get the expected "$ORIGIN/" rpaths in produced binaries, but we also
+  # get a bad rpath in each binary: either starting with "$$ORIGIN/" or "RIGIN/". The bad
+  # rpaths are ignored by the linker and are harmless.
   if [[ "$OSTYPE" == "darwin"* ]]; then
-    FULL_RPATH="-Wl,-rpath,$BUILD_DIR/gcc-$GCC_VERSION/lib,-rpath,'\$ORIGIN/../lib'"
+    FULL_RPATH="-Wl,-rpath,'\$ORIGIN/../lib',-rpath,'\$\$ORIGIN/../lib'"
   else
-    FULL_RPATH="-Wl,-rpath,$BUILD_DIR/gcc-$GCC_VERSION/lib64,-rpath,'\$ORIGIN/../lib64'"
+    FULL_RPATH="-Wl,-rpath,'\$ORIGIN/../lib64',-rpath,'\$\$ORIGIN/../lib64'"
   fi
-  FULL_RPATH="${FULL_RPATH},-rpath,'\$ORIGIN/../lib'"
+  FULL_RPATH="${FULL_RPATH},-rpath,'\$ORIGIN/../lib',-rpath,'\$\$ORIGIN/../lib'"

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

No branches or pull requests

2 participants