Skip to content

[35.0.0] Fix section/symbol flags when setting the used flag #11231

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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions cranelift/object/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use object::write::{
};
use object::{
RelocationEncoding, RelocationFlags, RelocationKind, SectionFlags, SectionKind, SymbolFlags,
SymbolKind, SymbolScope,
SymbolKind, SymbolScope, elf,
};
use std::collections::HashMap;
use std::collections::hash_map::Entry;
Expand Down Expand Up @@ -458,12 +458,20 @@ impl Module for ObjectModule {
let section = self.object.section_mut(section);
match &mut section.flags {
SectionFlags::None => {
// Explicitly specify default flags as SectionFlags::Elf overwrites them
let sh_flags = if decl.tls {
elf::SHF_ALLOC | elf::SHF_WRITE | elf::SHF_TLS
} else if decl.writable || !relocs.is_empty() {
elf::SHF_ALLOC | elf::SHF_WRITE
} else {
elf::SHF_ALLOC
};
section.flags = SectionFlags::Elf {
sh_flags: object::elf::SHF_GNU_RETAIN.into(),
sh_flags: u64::from(sh_flags | elf::SHF_GNU_RETAIN),
}
}
SectionFlags::Elf { sh_flags } => {
*sh_flags |= u64::from(object::elf::SHF_GNU_RETAIN)
*sh_flags |= u64::from(elf::SHF_GNU_RETAIN)
}
_ => unreachable!(),
}
Expand All @@ -472,8 +480,13 @@ impl Module for ObjectModule {
object::BinaryFormat::MachO => {
let symbol = self.object.symbol_mut(symbol);
assert!(matches!(symbol.flags, SymbolFlags::None));
let n_desc = if decl.linkage == Linkage::Preemptible {
object::macho::N_WEAK_DEF
} else {
0
};
symbol.flags = SymbolFlags::MachO {
n_desc: object::macho::N_NO_DEAD_STRIP,
n_desc: n_desc | object::macho::N_NO_DEAD_STRIP,
}
}
_ => unreachable!(),
Expand Down
Loading