Bug 27837 - Consider allowing mix of -r / --relax by ignoring --relax.
Summary: Consider allowing mix of -r / --relax by ignoring --relax.
Status: ASSIGNED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.36
: P2 normal
Target Milestone: ---
Assignee: Nick Clifton
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-05-09 22:13 UTC by Sergei Trofimovich
Modified: 2022-06-22 06:31 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed: 2021-05-19 00:00:00


Attachments
Proposed patch (386 bytes, patch)
2021-05-19 12:32 UTC, Nick Clifton
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sergei Trofimovich 2021-05-09 22:13:06 UTC
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!
Comment 1 Nick Clifton 2021-05-19 12:32:39 UTC
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
Comment 2 Sergei Trofimovich 2021-05-20 22:55:53 UTC
(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!
Comment 3 Nick Clifton 2021-05-21 09:55:46 UTC
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 ?