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

binutils: support custom ld #33580

Closed
wants to merge 1 commit into from

Conversation

dtzWill
Copy link
Member

@dtzWill dtzWill commented Jan 7, 2018

Motivation for this change

Currently the default linker is always "bfd", this introduces a config option for specifying a different default linker.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

default:

$ nix run -f . stdenv.cc  -c ld --version
GNU ld (GNU Binutils) 2.28.1
Copyright (C) 2017 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.

gold:

$ nix run -f . stdenv.cc --arg config '{ defaultLd = "gold"; }' -c ld --version
GNU gold (GNU Binutils 2.28.1) 1.14
Copyright (C) 2017 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) a later version.
This program has absolutely no warranty.

Additionally, modifying the cc-wrapper test to include -Wl,-v shows this successfully controls the linker used during compilation.

@dtzWill
Copy link
Member Author

dtzWill commented Jan 8, 2018

release-small using gold has only 4 additional failures! 😁

  • mono (via libgdiplus)
libtool: link: gcc -g -O2 -pthread -o .libs/testgdi testgdi.o  ../src/.libs/libgdiplus.so -lpthread /nix/store/86k0fajpxc4jzg0lzsif0xzc0s7fi6cs-fontconfig-2.12.1-lib/lib/libfontconfig.so -pthread -Wl,-rpath -Wl,/nix/store/63nyakkv0m4r1fw85wdqy7mv52yjywgf-libgdiplus-2.10.9/lib -Wl,-rpath -Wl,/nix/store/86k0fajpxc4jzg0lzsif0xzc0s7fi6cs-fontconfig-2.12.1-lib/lib
testgdi.c:46: error: undefined reference to 'XClearWindow'
testgdi.c:72: error: undefined reference to 'g_utf8_to_utf16'
testgdi.c:77: error: undefined reference to 'g_free'
testgdi.c:83: error: undefined reference to 'g_utf8_to_utf16'
testgdi.c:88: error: undefined reference to 'g_free'
testgdi.c:94: error: undefined reference to 'g_utf8_to_utf16'
testgdi.c:99: error: undefined reference to 'g_free'
testgdi.c:105: error: undefined reference to 'g_utf8_to_utf16'
testgdi.c:110: error: undefined reference to 'g_free'
testgdi.c:120: error: undefined reference to 'g_print'
testgdi.c:118: error: undefined reference to 'g_print'
testgdi.c:109: error: undefined reference to 'g_print'
testgdi.c:107: error: undefined reference to 'g_print'
testgdi.c:134: error: undefined reference to 'XOpenDisplay'
testgdi.c:165: error: undefined reference to 'XCreateSimpleWindow'
testgdi.c:169: error: undefined reference to 'XStringToKeysym'
testgdi.c:169: error: undefined reference to 'XKeysymToKeycode'
testgdi.c:171: error: undefined reference to 'XSelectInput'
testgdi.c:176: error: undefined reference to 'XMapWindow'
testgdi.c:191: error: undefined reference to 'XNextEvent'
testgdi.c:182: error: undefined reference to 'XDestroyWindow'
testgdi.c:149: error: undefined reference to 'XCloseDisplay'
collect2: error: ld returned 1 exit status
make[2]: *** [Makefile:310: testgdi] Error 1
make[2]: Leaving directory '/build/libgdiplus-2.10.9/tests'
make[1]: *** [Makefile:374: all-recursive] Error 1
make[1]: Leaving directory '/build/libgdiplus-2.10.9'
make: *** [Makefile:279: all] Error 2
builder for '/nix/store/lxnxgvk35byg82mb6myg027xvk2a394z-libgdiplus-2.10.9.drv' failed with exit code 2
  • grub:
checking if C symbols get an underscore after compilation... no
checking whether objcopy works for absolute addresses... configure: error: gcc cannot link at address 7C00
builder for '/nix/store/54v24qaxipwwin07av5aqpaws17gsn11-grub-0.97-patch-1.12.drv' failed with exit code 1
  • mysql
/nix/store/p33cbv59w9sxyj8a7q0gg7ikaprbbcyq-binutils-2.28.1/bin/ld: error: mariadbclient.def:1:9: invalid use of VERSION in input file
/nix/store/p33cbv59w9sxyj8a7q0gg7ikaprbbcyq-binutils-2.28.1/bin/ld: error: mariadbclient.def:254:9: invalid use of VERSION in input file
collect2: error: ld returned 1 exit status
make[2]: *** [libmariadb/libmariadb/CMakeFiles/libmariadb.dir/build.make:138: libmariadb/libmariadb/libmariadb.so.3] Error 1
make[1]: *** [CMakeFiles/Makefile2:1614: libmariadb/libmariadb/CMakeFiles/libmariadb.dir/all] Error 2
  • ssmtp
gcc -o ssmtp ssmtp.o arpadate.o base64.o xgethostname.o -lnsl  -lssl -DSTDC_HEADERS=1 -DHAVE_LIMITS_H=1 -DHAVE_STRINGS_H=1 -DHAVE_SYSLOG_H=1 -DHAVE_UNISTD_H=1 -DHAVE_LIBNSL=1 -DRETSIGTYPE=void -DHAVE_VPRINTF=1 -DHAVE_GETHOSTNAME=1 -DHAVE_SOCKET=1 -DHAVE_STRDUP=1 -DHAVE_STRSTR=1 -DREWRITE_DOMAIN=1 -DHAVE_SSL=1  -DSSMTPCONFDIR=\"/etc/ssmtp\" -DCONFIGURATION_FILE=\"/etc/ssmtp/ssmtp.conf\" -DREVALIASES_FILE=\"/etc/ssmtp/revaliases\"  -g -O2 -Wall
ssmtp.c:1284: error: undefined reference to 'X509_free'
collect2: error: ld returned 1 exit status
make: *** [Makefile:81: ssmtp] Error 1

@dtzWill
Copy link
Member Author

dtzWill commented Jan 8, 2018

Actually, perhaps this isn't the best way to do this:

  • bintools seems a more natural place to select the linker, and implementing this there leaves open future options such as lld.

  • config seems wrong place for this? This describes how things are built less than the contents of what is built (config seems mostly for expressing things like overrides, enabling/disabling optional features, selecting between implementations like openssl vs libressl). Selecting linker is more akin to selecting compiler (gcc/clang/...) which is already partially done by selecting platform as part of localSystem/crossSystem (for Darwin). Also config is an annoying place for settings one might want to control as part of a Hydra job :).


Future settings that are a bit distinct from linker/CC:

  • libgcc vs compiler-rt
  • libstdc++ vs libc++
  • glibc vs musl vs uclibc

(libc selection is already somewhat supported as part of localSystem/crossSystem)

@dtzWill
Copy link
Member Author

dtzWill commented Jan 9, 2018

Closing since it's not a priority and if it's needed we can revive/discuss.

@dtzWill dtzWill closed this Jan 9, 2018
@orivej
Copy link
Contributor

orivej commented Jan 10, 2018

@Ericson2314 made some provisions very recently to make the linker configurable in the stdenv (but I have not confirmed that it works).

@Ericson2314
Copy link
Member

I think overriding the wrapper to select the default would be the easiest/cheapest.

@Ericson2314
Copy link
Member

Also, the original motivation of this I believe was https://sourceware.org/bugzilla/show_bug.cgi?id=16177; we can just solve directly with @bgamari's rebase of the patch: https://sourceware.org/bugzilla/attachment.cgi?id=10727

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

Successfully merging this pull request may close these issues.

None yet

5 participants