Skip to content

Commit 2b13c7a

Browse files
bjorn3alexcrichton
authored andcommitted
Use the new section/symbol_flags_mut helpers in cranelift-object (bytecodealliance#11425)
* Use the new section/symbol_flags_mut helpers in cranelift-object This ensures that the correct default flags are used. * Add vets --------- Co-authored-by: Alex Crichton <[email protected]>
1 parent 22b4939 commit 2b13c7a

File tree

4 files changed

+28
-48
lines changed

4 files changed

+28
-48
lines changed

Cargo.lock

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ json-from-wast = "0.236.0"
347347
arbitrary = "1.4.0"
348348
mutatis = "0.3.2"
349349
cc = "1.0"
350-
object = { version = "0.37.0", default-features = false, features = ['read_core', 'elf'] }
350+
object = { version = "0.37.3", default-features = false, features = ['read_core', 'elf'] }
351351
gimli = { version = "0.32.0", default-features = false, features = ['read'] }
352352
addr2line = { version = "0.25.0", default-features = false }
353353
anyhow = { version = "1.0.93", default-features = false }

cranelift/object/src/backend.rs

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -454,41 +454,15 @@ impl Module for ObjectModule {
454454

455455
if used {
456456
match self.object.format() {
457-
object::BinaryFormat::Elf => {
458-
let section = self.object.section_mut(section);
459-
match &mut section.flags {
460-
SectionFlags::None => {
461-
// Explicitly specify default flags as SectionFlags::Elf overwrites them
462-
let sh_flags = if decl.tls {
463-
elf::SHF_ALLOC | elf::SHF_WRITE | elf::SHF_TLS
464-
} else if decl.writable || !relocs.is_empty() {
465-
elf::SHF_ALLOC | elf::SHF_WRITE
466-
} else {
467-
elf::SHF_ALLOC
468-
};
469-
section.flags = SectionFlags::Elf {
470-
sh_flags: u64::from(sh_flags | elf::SHF_GNU_RETAIN),
471-
}
472-
}
473-
SectionFlags::Elf { sh_flags } => {
474-
*sh_flags |= u64::from(elf::SHF_GNU_RETAIN)
475-
}
476-
_ => unreachable!(),
477-
}
478-
}
457+
object::BinaryFormat::Elf => match self.object.section_flags_mut(section) {
458+
SectionFlags::Elf { sh_flags } => *sh_flags |= u64::from(elf::SHF_GNU_RETAIN),
459+
_ => unreachable!(),
460+
},
479461
object::BinaryFormat::Coff => {}
480-
object::BinaryFormat::MachO => {
481-
let symbol = self.object.symbol_mut(symbol);
482-
assert!(matches!(symbol.flags, SymbolFlags::None));
483-
let n_desc = if decl.linkage == Linkage::Preemptible {
484-
object::macho::N_WEAK_DEF
485-
} else {
486-
0
487-
};
488-
symbol.flags = SymbolFlags::MachO {
489-
n_desc: n_desc | object::macho::N_NO_DEAD_STRIP,
490-
}
491-
}
462+
object::BinaryFormat::MachO => match self.object.symbol_flags_mut(symbol) {
463+
SymbolFlags::MachO { n_desc } => *n_desc |= object::macho::N_NO_DEAD_STRIP,
464+
_ => unreachable!(),
465+
},
492466
_ => unreachable!(),
493467
}
494468
}

supply-chain/audits.toml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2909,6 +2909,12 @@ criteria = "safe-to-deploy"
29092909
delta = "0.36.5 -> 0.37.1"
29102910
notes = "New object file formats, new formatting, new other minor changes, no new `unsafe`."
29112911

2912+
[[audits.object]]
2913+
who = "Alex Crichton <[email protected]>"
2914+
criteria = "safe-to-deploy"
2915+
delta = "0.37.1 -> 0.37.3"
2916+
notes = "Lots of new support for new object features, no new unsafe or anything suspicious."
2917+
29122918
[[audits.once_cell]]
29132919
who = "Chris Fallin <[email protected]>"
29142920
criteria = "safe-to-deploy"

0 commit comments

Comments
 (0)