Skip to content

TLS program header is not correctly generated for zero-initialized tls variables#1788

Draft
ostylk wants to merge 2 commits intowild-linker:mainfrom
ostylk:fix/tls
Draft

TLS program header is not correctly generated for zero-initialized tls variables#1788
ostylk wants to merge 2 commits intowild-linker:mainfrom
ostylk:fix/tls

Conversation

@ostylk
Copy link
Copy Markdown
Contributor

@ostylk ostylk commented Apr 1, 2026

I noticed the tls-common test failed on my machine depending on which environment and versions of compilers I used. It seems like the TLS program header is generated incorrectly for zero initialized tls variables.

E.g. in the tls-common we have a variable tvar that is in .tbss. However, the TLS program header is filesz=4,memsz=4 which doesn't zero-initialize it but loads bytes from the elf binary. It just so happens that all CIs and your local setup contained zeros in the binary at the exact place for this to nevertheless work. The correct TLS program header would be filesz=0,memsz=4.

So this pull request does/will do two things:

  • Implement program header assertions in testing so this bug actually errors out deterministically. Now a test can contain //#ExpectProgramHeader:PT_TLS filesz=0,memsz=4 and it will only accept if a program header with at least these properties exists.
  • Fix the actual bug.

This is a draft because the test option still needs documentation and I haven't found the bug yet and holidays are starting. So I'll complete it at a later time.

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.

1 participant