Skip to content

Fix getting output type from linker scripts that use AS_NEEDED#1546

Open
jwakely wants to merge 1 commit intorui314:mainfrom
jwakely:linker-script-group-as-needed
Open

Fix getting output type from linker scripts that use AS_NEEDED#1546
jwakely wants to merge 1 commit intorui314:mainfrom
jwakely:linker-script-group-as-needed

Conversation

@jwakely
Copy link

@jwakely jwakely commented Jan 21, 2026

Make Script<E>::get_script_output_type support AS_NEEDED inside an INPUT or GROUP group, so that the libatomic_asneeded.so linker script used by GCC 16 works.

Fixes #1545

@jwakely jwakely force-pushed the linker-script-group-as-needed branch 2 times, most recently from ff1916d to df7b143 Compare January 21, 2026 11:44
@jwakely jwakely changed the title Fix getting output type from linker scripts using AS_NEEDED Fix getting output type from linker scripts that use AS_NEEDED Jan 21, 2026
if (tok.size() >= 3 && (tok[0] == "INPUT" || tok[0] == "GROUP") &&
tok[1] == "(")
tok[1] == "(") {
if (tok[2] == "AS_NEEDED" && tok[3] == "(")

Choose a reason for hiding this comment

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

I think we should check that there are enough tokens after AS_NEEDED, i.e. tok.size() >= 5

Copy link
Author

Choose a reason for hiding this comment

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

Done

@jwakely jwakely force-pushed the linker-script-group-as-needed branch from df7b143 to aed588b Compare February 12, 2026 13:46
if (tok.size() >= 3 && (tok[0] == "INPUT" || tok[0] == "GROUP") &&
tok[1] == "(")
tok[1] == "(") {
if (tok[2] == "AS_NEEDED" && tok[3] == "(" && tok.size() >= 5)

Choose a reason for hiding this comment

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

Suggested change
if (tok[2] == "AS_NEEDED" && tok[3] == "(" && tok.size() >= 5)
if (tok[2] == "AS_NEEDED" && tok.size() >= 5 && tok[3] == "(")

Only tok.size() >= 3 is checked above, so tok[3] would be OOB. changing order of this check fixes this.

Copy link
Author

Choose a reason for hiding this comment

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

Oops, thanks. Done.

Make Script<E>::get_script_output_type support AS_NEEDED inside an INPUT
or GROUP group, so that the libatomic_asneeded.so linker script used by
GCC 16 works.

Fixes rui314#1545

Signed-off-by: Jonathan Wakely <jwakely@redhat.com>
@jwakely jwakely force-pushed the linker-script-group-as-needed branch from aed588b to e0a6f8e Compare March 1, 2026 14:38
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.

[gcc-16 regression] Linker scripts starting with INPUT(AS_NEEDED(...)) do not work

3 participants