Skip to content

Commit dbe19c2

Browse files
committed
symcheck: Update to object 0.40
The biggest thing here is a change from integers to newtypes for most flags. Link: https://github.com/gimli-rs/object/blob/400e64fbcb03fddb4b1ae8aef1868976ab999acc/CHANGELOG.md#0400
1 parent bb61639 commit dbe19c2

3 files changed

Lines changed: 21 additions & 15 deletions

File tree

Cargo.lock

Lines changed: 6 additions & 6 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
@@ -54,7 +54,7 @@ libm-test = { path = "libm-test", default-features = false }
5454
libtest-mimic = "0.8.1"
5555
musl-math-sys = { path = "crates/musl-math-sys" }
5656
no-panic = "0.1.36"
57-
object = { version = "0.39.0", features = ["wasm"] }
57+
object = { version = "0.40.0", features = ["wasm"] }
5858
panic-handler = { path = "crates/panic-handler" }
5959
paste = "1.0.15"
6060
pretty_assertions = "1.4.1"

crates/symcheck/src/main.rs

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use std::process::{Command, Stdio, exit};
1313
use std::sync::LazyLock;
1414
use std::{env, fmt, fs};
1515

16+
use object::elf::{ProgramFlags, ProgramType};
1617
use object::read::archive::ArchiveFile;
1718
use object::read::pe::ImageOptionalHeader;
1819
use object::{
@@ -697,10 +698,10 @@ fn elf_os<Elf: read::elf::FileHeader>(f: &read::elf::ElfFile<Elf>) -> Os {
697698
/// Get the OS from a mach file, or `Unknown` if not specified.
698699
fn mach_os<Mach: read::macho::MachHeader>(f: &read::macho::MachOFile<Mach>) -> Os {
699700
// Note that this only returns something on `.rmeta` objects, not `.o`s.
700-
let Ok(Some(build)) = f.build_version() else {
701+
let Ok(Some((build_cmd, build_tool))) = f.build_version() else {
701702
return Os::Unknown;
702703
};
703-
let platform = build.platform.get(f.endian());
704+
let platform = build_cmd.platform.get(f.endian());
704705

705706
match platform {
706707
macho::PLATFORM_UNKNOWN => Os::Unknown,
@@ -709,7 +710,7 @@ fn mach_os<Mach: read::macho::MachHeader>(f: &read::macho::MachOFile<Mach>) -> O
709710
macho::PLATFORM_TVOS | macho::PLATFORM_TVOSSIMULATOR => Os::TvOs,
710711
macho::PLATFORM_VISIONOS | macho::PLATFORM_VISIONOSSIMULATOR => Os::VisionOs,
711712
macho::PLATFORM_WATCHOS | macho::PLATFORM_WATCHOSSIMULATOR => Os::WatchOs,
712-
_ => panic!("unrecognized Mach-O platform {platform} ({build:?})"),
713+
_ => panic!("unrecognized Mach-O platform {platform} ({build_cmd:?} {build_tool:?})"),
713714
}
714715
}
715716

@@ -808,7 +809,8 @@ fn check_elf_exe_stack(obj: &ObjFile) -> Result<(), ExeStack> {
808809
// Check for PT_GNU_STACK marked executable
809810
let mut is_obj_exe = false;
810811
let mut found_gnu_stack = false;
811-
let mut check_ph = |p_type: U32<Endianness>, p_flags: U32<Endianness>| {
812+
let mut check_ph = |p_type: U32<Endianness, ProgramType>,
813+
p_flags: U32<Endianness, ProgramFlags>| {
812814
let ty = p_type.get(end);
813815
let flags = p_flags.get(end);
814816

@@ -821,7 +823,7 @@ fn check_elf_exe_stack(obj: &ObjFile) -> Result<(), ExeStack> {
821823
if ty == elf::PT_GNU_STACK {
822824
assert!(!found_gnu_stack, "multiple PT_GNU_STACK sections");
823825
found_gnu_stack = true;
824-
if flags & elf::PF_X != 0 {
826+
if flags.contains(elf::PF_X) {
825827
return Err(ExeStack::ExePtGnuStack);
826828
}
827829
}
@@ -852,11 +854,15 @@ fn check_elf_exe_stack(obj: &ObjFile) -> Result<(), ExeStack> {
852854
let mut gnu_stack_exe = None;
853855
let mut has_exe_sections = false;
854856
for sec in obj.sections() {
855-
let SectionFlags::Elf { sh_flags } = sec.flags() else {
857+
let SectionFlags::Elf {
858+
sh_type: _,
859+
sh_flags,
860+
} = sec.flags()
861+
else {
856862
unreachable!("only elf files are being checked");
857863
};
858864

859-
let is_sec_exe = sh_flags & u64::from(elf::SHF_EXECINSTR) != 0;
865+
let is_sec_exe = sh_flags.contains(elf::SHF_EXECINSTR);
860866

861867
// If the magic section is present, its exe bit tells us whether or not the object
862868
// file requires an executable stack.
@@ -891,7 +897,7 @@ fn check_elf_exe_stack(obj: &ObjFile) -> Result<(), ExeStack> {
891897
match obj.architecture() {
892898
// PPC64 doesn't set `.note.GNU-stack` since GNU nested functions don't need a trampoline,
893899
// <https://gcc.gnu.org/bugzilla/show_bug.cgi?id=21098>. This only applies to ELFv1.
894-
Architecture::PowerPc64 if e_flags & elf::EF_PPC64_ABI != 2 => Ok(()),
900+
Architecture::PowerPc64 if e_flags.0 & elf::EF_PPC64_ABI != 2 => Ok(()),
895901

896902
_ => Err(ExeStack::MissingGnuStackSec),
897903
}

0 commit comments

Comments
 (0)