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

ld: set --enable-new-dtags by default #2255

Merged
merged 1 commit into from
Mar 18, 2018
Merged

Conversation

bukzor
Copy link
Contributor

@bukzor bukzor commented Mar 18, 2018

The --enable-new-dtags option to ld causes it to emit a RUNPATH rather than RPATH entry in the elf header. Because the Android linker supports RUNPATH but not RPATH, this means many things can now Just Work. This should (eventually) eliminate the need to set LD_LIBRARY_PATH.

Prior art:

This became the default for Linux in 2013 but I think termux isn't getting it because it reports "Android" instead of "Linux"? Or maybe the way it works changed since then. Regardless, Debian has been using RUNPATH by default since December 2016. Their newest configuration uses the newer configuration option seen in this patch. The suse and gentoo maintainers said they did the same in 2004 and 2005, respectively. So it seems well battle-tested, to me.

For the curious:
This came up because I'm working on getting Homebrew working under Termux.

The --enable-new-dtags option to ld causes it to emit a RUNPATH rather than RPATH entry in the elf header. Because the Android linker supports RUNPATH but not RPATH, this means many things can now Just Work. This should (eventually) eliminate the need to set LD_LIBRARY_PATH.

Prior art:

This [became the default for Linux in 2013](https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=commitdiff;h=822b8bf) but I think termux isn't getting it because it reports "Android" instead of "Linux"? Or maybe the way it works changed since then. Regardless, [Debian has been using RUNPATH by default since December 2016.](https://sources.debian.org/src/binutils/2.27.90.20161231-1/debian/patches/ld-new-dtags-by-default.diff/?hl=27#L27) Their [newest configuration](https://sources.debian.org/src/binutils/2.30-7/debian/rules/#L362) uses the newer configuration option seen in this patch. The [suse and gentoo](https://web.archive.org/web/20160101182307/http://comments.gmane.org/gmane.comp.gnu.binutils/57379) maintainers said they did the same in 2004 and 2005, respectively. So it seems well battle-tested, to me.

For the curious:
This came up because I'm working on [getting Homebrew working under Termux](Linuxbrew/brew#621).
@fornwall
Copy link
Member

fornwall commented Mar 18, 2018

Thanks - the updated package is now available at version 2.30-1 as an update!

This came up because I'm working on getting Homebrew working under Termux.

Interesting! Let us know how it goes (I guess #2071 is the best location to post progress)!

@sjackman
Copy link

RPATH is the default on Ubuntu 16.04 (Xenial Xerus).

❯❯❯ echo 'int main() { return 0; }' >hello.c
❯❯❯ gcc -Wl,-rpath=/foo -o hello hello.c
❯❯❯ readelf -d hello | egrep 'RPATH|RUNPATH'
 0x000000000000000f (RPATH)              Library rpath: [/foo]
❯❯❯ gcc -Wl,-rpath=/foo -Wl,--enable-new-dtags -o hello hello.c
❯❯❯ readelf -d hello | egrep 'RPATH|RUNPATH'
 0x000000000000001d (RUNPATH)            Library runpath: [/foo]

@bukzor
Copy link
Contributor Author

bukzor commented Mar 18, 2018

I believe the change happened in binutils 2.27. For comparison:

$ echo 'int main() { return 0; }' >hello.c
$ gcc -Wl,-rpath=/foo -o hello hello.c
$ readelf -d hello | egrep 'RPATH|RUNPATH'
 0x000000000000001d (RUNPATH)            Library runpath: [/foo]

$ gcc -Wl,-rpath=/foo -Wl,--enable-new-dtags -o hello hello.c
$ readelf -d hello | egrep 'RPATH|RUNPATH'
 0x000000000000001d (RUNPATH)            Library runpath: [/foo]

$ dpkg -l binutils
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name           Version      Architecture Description
+++-==============-============-============-=================================
ii  binutils       2.29.1-4ubun amd64        GNU assembler, linker and binary 

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 17.10
Release:	17.10
Codename:	artful

@bukzor
Copy link
Contributor Author

bukzor commented Mar 18, 2018

@fornwall I'm most interested to see if this eases my pain when clang is compiled using this.
Is there some reasonable way for me to try that myself? Perhaps a wiki page somewhere?

@sjackman
Copy link

Good to know!

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