Skip to content

fix(x86_64): only relax when the section holds the rewritten bytes - #3069

Closed
deepakshirkem wants to merge 1 commit into
wild-linker:mainfrom
deepakshirkem:fix/x86-relaxation-truncated
Closed

deepakshirkem wants to merge 1 commit into
wild-linker:mainfrom
deepakshirkem:fix/x86-relaxation-truncated

Conversation

@deepakshirkem

Copy link
Copy Markdown
Member

The x86-64 relaxation recognisers check the bytes they need to identify an instruction sequence, but five relaxations then rewrite more than that: TlsLdToLocalExec, TlsLdToLocalExec64, TlsLdToLocalExecNoPlt, SkipTlsDescCall and JmpIndirectToRelative. On a section cut short after the recognised bytes, apply wrote past its end and panicked.

Each of those recognisers now declines the relaxation unless the section holds everything apply writes. The relocation is then handled without relaxation: the TLSLD sequences link, and the other two now give the existing errors for a static TLSDESC call and a relocation outside its section. GNU ld rejects all five.

This checks the span in each affected recogniser. A more general alternative would be for every RelaxationKind to report the span it rewrites, checked in one place; happy to do that instead if you prefer.

Fixes #2995

The relaxation recognisers check the bytes needed to identify an
instruction sequence, but five relaxations rewrite more than that. On a
truncated section, applying them panicked. Decline the relaxation unless
the section holds everything it rewrites.
@deepakshirkem
deepakshirkem marked this pull request as ready for review November 23, 2026 19:18

@marxin marxin left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm against the change as it introduced unnecessary complexity. The linked issue is a product of artificially constructed object files and a normal toolchain does not produce such a garbage. Ending with a linker panic seems like a reasonable outcome for such an input.

Note, in general, one can produce an infinite number of invalid object files where we'll certainly crash and such issues should be categorized as very low priority.

@marxin marxin closed this Nov 24, 2026
@deepakshirkem
deepakshirkem deleted the fix/x86-relaxation-truncated branch November 24, 2026 16:45
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.

Five x86-64 relaxation rewrites panic on truncated instruction spans

2 participants