Bug 98210 - [11 Regression] SHF_GNU_RETAIN breaks gold linker generated binaries
Summary: [11 Regression] SHF_GNU_RETAIN breaks gold linker generated binaries
Status: RESOLVED WONTFIX
Alias: None
Product: gcc
Classification: Unclassified
Component: target (show other bugs)
Version: 11.0
: P1 normal
Target Milestone: 11.0
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-12-09 07:46 UTC by Alan Modra
Modified: 2021-02-19 17:20 UTC (History)
4 users (show)

See Also:
Host:
Target: powerpc64le-linux, x86_64-linux
Build:
Known to work:
Known to fail:
Last reconfirmed: 2020-12-09 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Alan Modra 2020-12-09 07:46:43 UTC
gcc.dg/split-1.exe and other split-stack executables broke recently on powerpc64le-linux, most likely due to git commit 6fbec038f7a7.

I see

  [22] .init_array       INIT_ARRAY      000000001001fda8 00fda8 000008 08 WAo  0   0  8
  [23] .init_array       INIT_ARRAY      000000001001fdb0 00fdb0 000010 00  WA  0   0  8

and in dynamic tags

 0x0000000000000019 (INIT_ARRAY)         0x1001fda8
 0x000000000000001b (INIT_ARRAYSZ)       8 (bytes)
 0x0000000000000019 (INIT_ARRAY)         0x1001fdb0
 0x000000000000001b (INIT_ARRAYSZ)       16 (bytes)

ld.so won't handle multiple tags like this, and symbols __init_array_start and __init_array_end are defined to cover just the first .init_array section.

The same thing happens on x86_64 when using gold, objects like crtbegin.o that have .init_array with "WAR" flags create separate .init_array output sections if being linked with glibc files containing .init_array without the "R" flag.
Comment 1 H.J. Lu 2020-12-09 13:12:00 UTC
Moved.
Comment 2 Alan Modra 2020-12-09 22:53:12 UTC
When the gold patch goes in, gcc should have a configure test such that the combination of gold being the default linker and SHF_GNU_RETAIN support should not be allowed unless gold has the patch.  And even if gold is not the default linker it is required for split-stack go support, so go being compiled also ought to trigger a dependence on gold being recent enough.
Comment 3 H.J. Lu 2020-12-09 23:00:24 UTC
Jozef, SHF_GNU_RETAIN is yours.
Comment 4 Jozef Lawrynowicz 2020-12-15 15:23:47 UTC
Since gold is not built by default, should we just disable SHF_GNU_RETAIN support if gold has been built at all, for Binutils versions without the gold patch.

There's 2 weeks between the GCC "used" implying SHF_GNU_RETAIN patch and gold being fixed, so the real fix if you want SHF_GNU_RETAIN support but are using a Binutils version in this timeframe is to just upgrade. Meanwhile we should just completely turn off SHF_GNU_RETAIN if GCC can spot that a broken gold is available.
Comment 5 H.J. Lu 2020-12-15 15:34:05 UTC
Since gold has been fixed now, you can add a check for broken gold and set
HAVE_GAS_SHF_GNU_RETAIN to 0 for broken gold.
Comment 6 Jozef Lawrynowicz 2020-12-16 18:41:34 UTC
I've posted a patch where the HAVE_GAS_SHF_GNU_RETAIN configure test has been extended to check for SHF_GNU_RETAIN gold support: https://gcc.gnu.org/pipermail/gcc-patches/2020-December/562100.html
Comment 7 Segher Boessenkool 2021-01-29 21:53:39 UTC
This also needs a backport to 10?  Can someone please fill in the
known_to_{work,fail} fields?
Comment 8 Jakub Jelinek 2021-02-19 11:21:52 UTC
Isn't this problem gone with r11-7284-g6347f4a0904fce17eedf5c071be6f3c118680290 ?
I mean, attribute used now means what it used to mean before, and retain attribute is not used in whatever is emitted into .init_array section at least in existing code.  Yes, one might use it in user code, but the answer can be don't do it then.
Comment 9 Jozef Lawrynowicz 2021-02-19 12:40:19 UTC
I believe this PR only relates to the fact that GCC support for SHF_GNU_RETAIN was available before GOLD supported that section flag.

My proposed patch was to turn off GCC support for SHF_GNU_RETAIN if an unsupported GOLD is detected.

I think at this point, the GOLD functionality was only broken for such a narrow period of time in development (not corresponding to a concrete version of Binutils), there's no point adding a configure test to try and catch that now.

(In reply to Jakub Jelinek from comment #8)
> Isn't this problem gone with
> r11-7284-g6347f4a0904fce17eedf5c071be6f3c118680290 ?
> I mean, attribute used now means what it used to mean before, and retain
> attribute is not used in whatever is emitted into .init_array section at
> least in existing code.  Yes, one might use it in user code, but the answer
> can be don't do it then.

And yes, since none of the libraries using the "used" attribute will implicitly create SHF_GNU_RETAIN sections any more, even if you used the Binutils version with broken GOLD, it won't cause any problems.
Comment 10 Jozef Lawrynowicz 2021-02-19 17:20:10 UTC
I think its best to close this as WONTFIX.

GCC will only erroneously enable SHF_GNU_RETAIN support if a Binutils version between:
> commit 99fabbc9739a87ba3433e66792e93b773896790e
> Author: Jozef Lawrynowicz <jozef.l@mittosystems.com>
> Date:   Wed Nov 18 11:51:13 2020 +0000
>
>    Support SHF_GNU_RETAIN ELF section flag

and

> commit ff4bc37d77a0ca7286883a477adcb3aa145fc782
> Author: Cary Coutant <ccoutant@gmail.com>
> Date:   Mon Dec 14 15:46:47 2020 -0800
> 
>     Keep input SHF_GNU_RETAIN sections and strip output SHF_GNU_RETAIN for GNU/FreBSD ELFOSABIs.

is being used. There's no Binutils release in this range.