This is a forward of https://bugs.gentoo.org/788901 bug by Petr Šabata. Petr uses LDFLAGS+=-Wl,--relax system-wide. glibc (and ghc) occasionally use `ld -r` for partial linking (and apply $LDFLAGS for it). binutils does not allow such a mix: $ touch a.c $ LANG=C h gcc -Wl,--relax -r a.c -o a /usr/lib/gcc/x86_64-pc-linux-gnu/12.0.0/../../../../x86_64-pc-linux-gnu/bin/ld: --relax and -r may not be used together collect2: error: ld returned 1 exit status Our options are to: 1. Filter out -Wl,--relax flag downstream and don't pass it to glibc 2. Tweak glibc to pass -Wl,--no-relax in `ld -r` contexts I wonder if binutils could ignore -Wl,--relax altogether for partial linking. Thank you!
Created attachment 13462 [details] Proposed patch Hi Sergei How about this patch ? It allows the link to complete, but it still issues a (non-error) message saying "disabling relaxation; it will not work with -r". Cheers Nick
(In reply to Nick Clifton from comment #1) > Created attachment 13462 [details] > Proposed patch > > Hi Sergei > > How about this patch ? It allows the link to complete, but it still > issues a (non-error) message saying "disabling relaxation; it will > not work with -r". Tried both on a small example and on glibc. Works great here. Thank you, Nick!
Unfortunately I have discovered a problem with the patch: The PowerPC target does allow -r and --relax to be combined. So it is not correct to just globally disable the combination. (There may be other architectures that also allow it, but the PowerPC is the only that has tests in the linker testsuite to make sure that it works). So now I am wondering if the linker is the correct place to resolve this problem. If a build system is triggering error messages from the linker, then shouldn't that system be corrected ?