Skip to content

Staticlib rename internal symbols: add COFF support - #160679

Open
cezarbbb wants to merge 1 commit into
rust-lang:mainfrom
cezarbbb:staticlib-rename-coff
Open

Staticlib rename internal symbols: add COFF support#160679
cezarbbb wants to merge 1 commit into
rust-lang:mainfrom
cezarbbb:staticlib-rename-coff

Conversation

@cezarbbb

@cezarbbb cezarbbb commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #156950.

-Zstaticlib-rename-internal-symbols now also works on COFF targets (Windows). Renaming only rewrites symbol names, so unlike hide it needs no visibility concept.

COFF objects keep their string table at the end of the file, so renames append the new names there and patch the 4-byte length prefix plus each symbol's name offset in place. Both regular and bigobj objects are handled; on i686 a leading underscore is stripped when matching against the exported set. The archive format differs (GNU ar on windows-gnu, COFF on windows-msvc) but the members are always COFF objects, so the existing archive code is unchanged.

Supported on ELF, Apple, and COFF targets. -Zstaticlib-hide-internal-symbols remains ELF/Apple-only and still warns on Windows.

A run-make test staticlib-rename-internal-symbols-coff mirrors the existing ELF and Mach-O tests.

r? @bjorn3

@rustbot rustbot added A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Aug 7, 2026
@cezarbbb
cezarbbb force-pushed the staticlib-rename-coff branch from 3a890b2 to 3d2cea7 Compare August 7, 2026 09:25
@rustbot

rustbot commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

This PR was rebased onto a different main commit. Here's a range-diff highlighting what actually changed.

Rebasing is a normal part of keeping PRs up to date, so no action is needed—this note is just to help reviewers.

strip_underscore: bool,
) -> Option<Vec<u8>> {
// COFF has no visibility concept, so hide is a no-op.
let _ = (hide, exported);

@bjorn3 bjorn3 Aug 27, 2026

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.

Maybe assert!(!hide)?

View changes since the review

result[strtab_base..strtab_base + 4].copy_from_slice(&new_len.to_le_bytes());
result.extend_from_slice(&new_strtab);

// Long names are stored as name[0] = 0 and name[4..8] = string table offset.

@bjorn3 bjorn3 Aug 27, 2026

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.

What about name[1..4]? Is that ignored? Perhaps fill that with zeros too?

Edit: According to https://bitsavers.org/pdf/att/unix/System_V_386_Release_3.2/UNIX_System_V_386_Release_3.2_Programmers_Guide_Vol2_1989.pdf page 11-23, the four first bytes all need to be zero for a long symbol name.

View changes since the review

@bjorn3 bjorn3 added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-run-make Area: port run-make Makefiles to rmake.rs S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants