Skip to content

fix: make three more x86_64 relaxations reqired for static binaries#1654

Merged
mati865 merged 14 commits into
wild-linker:mainfrom
mati865:push-yzpzklutotwv
Mar 8, 2026
Merged

fix: make three more x86_64 relaxations reqired for static binaries#1654
mati865 merged 14 commits into
wild-linker:mainfrom
mati865:push-yzpzklutotwv

Conversation

@mati865

@mati865 mati865 commented Mar 6, 2026

Copy link
Copy Markdown
Member

This change fixes linking of C++ hello world with -static -Wl,--no-relax and addresses one of linker-diff's errors about missing relaxation.

Wild still applies too many relaxations as shown in linker-diff output, but disabling some of them results in broken binaries, so I gave up on touching that. Also, in the output there are not yet implemented endbr64 relaxations.

@davidlattimore davidlattimore left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the fix. Would it be possible to add a test? The static no-relax combination seems like it would be pretty straightforward

mati865 added 3 commits March 7, 2026 19:45
Otherwise, linking C++ hello world with `-static -Wl,--no-relax` fails
with undefined references to `__tls_get_addr`.
This matches GNU ld behaviour according to linker-diff when linking C++
hello world with `-static -Wl,--no-relax`.
@mati865 mati865 force-pushed the push-yzpzklutotwv branch from 176ba40 to b5d4a23 Compare March 7, 2026 18:46
@mati865 mati865 force-pushed the push-yzpzklutotwv branch from 7194e6e to c1363cb Compare March 7, 2026 18:54
@mati865

mati865 commented Mar 7, 2026

Copy link
Copy Markdown
Member Author

My changes fixed the issue on Arch Linux, but all other test runners still hit it:

wild: error: Undefined symbol __tls_get_addr, referenced by 
    /usr/lib/gcc/x86_64-linux-gnu/15/libstdc++.a @ eh_globals.o

Welp, at least I didn't regress anything, although failing to link is a bar set pretty low.

@mati865 mati865 changed the title fix: make two x86_64 relaxations reqired for static binaries fix: make three x86_64 relaxations reqired for static binaries Mar 7, 2026
@mati865 mati865 changed the title fix: make three x86_64 relaxations reqired for static binaries fix: make three more x86_64 relaxations reqired for static binaries Mar 7, 2026
@mati865 mati865 requested a review from davidlattimore March 7, 2026 20:08
@mati865

mati865 commented Mar 7, 2026

Copy link
Copy Markdown
Member Author

Quite a bumpy ride but added test that now passes the CI.

@davidlattimore davidlattimore left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the test. A couple of minor comments, but fine to submit as-is if you prefer

Comment thread wild/tests/sources/cpp-integration.cc Outdated
//#LinkArgs:-no-pie -Wl,-z,now
//#EnableLinker:lld

//#Config:static:default

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps call the config "static-no-relax" to better capture what we're testing?

//#LinkerDriver:g++
//#LinkArgs:-static -Wl,-z,now,-no-relax
//#DiffIgnore:rel.extra-got-plt-got
//#DiffIgnore:init_array

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think any of these ignores are things that we should look at in future? If so, perhaps add a TODO. The init_array diff especially stands out to me

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought init_array diff is a known defect, I get it even when linking dynamic executables with linker-diff enabled. For example, when linking Release profile (without debug info) Clang.
FWIW, this is the diff from this test:

    wild: /home/mateusz/Projects/wild/wild/tests/build/cpp-integration.cc/static-no-relax-host/cpp-integration.cc.wild
    ld: /home/mateusz/Projects/wild/wild/tests/build/cpp-integration.cc/static-no-relax-host/cpp-integration.cc.ld
    init_array
      ┌──────────────────────────────────────┬──────────────────────────────────────┐
      │ wild                                 │ ld                                   │
      ├──────────────────────────────────────┼──────────────────────────────────────┤
      │ _GLOBAL__sub_I.00090_globals_io.cc   │ _GLOBAL__sub_I.00090_globals_io.cc   │
      │ frame_dummy                          │ frame_dummy                          │
      │ _GLOBAL__sub_I_eh_alloc.cc           │ _GLOBAL__sub_I_cxx11_wlocale_inst.cc │
      │ _GLOBAL__sub_I_cxx11_locale_inst.cc  │ _GLOBAL__sub_I_locale_inst.cc        │
      │ _GLOBAL__sub_I_cxx11_wlocale_inst.cc │ _GLOBAL__sub_I_wlocale_inst.cc       │
      │ _GLOBAL__sub_I_locale_inst.cc        │ _GLOBAL__sub_I_eh_alloc.cc           │
      │ _GLOBAL__sub_I_wlocale_inst.cc       │ _GLOBAL__sub_I_cxx11_locale_inst.cc  │
      │ _IO_stdfiles_init                    │ _IO_stdfiles_init                    │
      └──────────────────────────────────────┴──────────────────────────────────────┘

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was a known issue, but I thought it was fixed in #588, but it sounds like there might be more to do.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For some reason I thought it wasn't supposed to be a full fix.

@mati865 mati865 merged commit f317af0 into wild-linker:main Mar 8, 2026
21 checks passed
@mati865 mati865 deleted the push-yzpzklutotwv branch March 8, 2026 23:09
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