Skip to content

Allow marking data objects as used for the linker #11206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2025

Conversation

bjorn3
Copy link
Contributor

@bjorn3 bjorn3 commented Jul 9, 2025

Fixes #10758

@bjorn3 bjorn3 requested a review from a team as a code owner July 9, 2025 10:26
@bjorn3 bjorn3 requested review from abrown and removed request for a team July 9, 2025 10:26
_ => unreachable!(),
}
}
object::BinaryFormat::Coff => {},
Copy link
Contributor Author

@bjorn3 bjorn3 Jul 9, 2025

Choose a reason for hiding this comment

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

I couldn't find what flag is necessary for Windows (if any).

@bjorn3
Copy link
Contributor Author

bjorn3 commented Jul 9, 2025

Also could this get a backport to the branch for the next Cranelift release. rust-lang/rust#140525 has removed a workaround for #[used] previously defaulting to #[used(compiler)] rather than #[used(linker)], so without the Cranelift changes, .init_array support in cg_clif is broken with lld.

@github-actions github-actions bot added cranelift Issues related to the Cranelift code generator cranelift:module labels Jul 9, 2025
Copy link
Member

@abrown abrown left a comment

Choose a reason for hiding this comment

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

I'm no expert here but this seems reasonable.

@abrown abrown added this pull request to the merge queue Jul 10, 2025
Merged via the queue into bytecodealliance:main with commit 9c3d102 Jul 10, 2025
42 checks passed
@bjorn3 bjorn3 deleted the used_data_object branch July 10, 2025 17:40
match &mut section.flags {
SectionFlags::None => {
section.flags = SectionFlags::Elf {
sh_flags: object::elf::SHF_GNU_RETAIN.into(),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should have also included elf::SHF_ALLOC | elf::SHF_WRITE (or elf::SHF_ALLOC only when the data object is neither writable nor contains relocations).

let symbol = self.object.symbol_mut(symbol);
assert!(matches!(symbol.flags, SymbolFlags::None));
symbol.flags = SymbolFlags::MachO {
n_desc: object::macho::N_NO_DEAD_STRIP,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

And I think this is missing N_WEAK_REF/N_WEAK_DEF for weak symbols.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cranelift:module cranelift Issues related to the Cranelift code generator
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cranelift-object: Support marking data object as used
2 participants