write/elf: set flags for StandardSection::EhFrame (#877)

This commit is contained in:
Philip Craig
2026-04-10 15:53:20 +10:00
committed by GitHub
parent fbdc2000a4
commit 0a7079ef74
2 changed files with 32 additions and 2 deletions
+3 -1
View File
@@ -119,7 +119,9 @@ impl<'a> Object<'a> {
} else {
SectionKind::ReadOnlyData
},
SectionFlags::None,
SectionFlags::Elf {
sh_flags: u64::from(elf::SHF_ALLOC),
},
),
}
}
+29 -1
View File
@@ -4,7 +4,7 @@ use object::read::{Object, ObjectSection, ObjectSymbol};
use object::{read, write, SectionIndex, SubArchitecture};
use object::{
Architecture, BinaryFormat, Endianness, RelocationEncoding, RelocationFlags, RelocationKind,
SectionKind, SymbolFlags, SymbolKind, SymbolScope, SymbolSection,
SectionFlags, SectionKind, SymbolFlags, SymbolKind, SymbolScope, SymbolSection,
};
mod bss;
@@ -196,6 +196,9 @@ fn elf_x86_64() {
)
.unwrap();
let eh_frame = object.section_id(write::StandardSection::EhFrame);
object.append_section_data(eh_frame, &[1; 30], 4);
let bytes = object.write().unwrap();
let object = read::File::parse(&*bytes).unwrap();
assert_eq!(object.format(), BinaryFormat::Elf);
@@ -211,9 +214,34 @@ fn elf_x86_64() {
assert_eq!(text.kind(), SectionKind::Text);
assert_eq!(text.address(), 0);
assert_eq!(text.size(), 62);
assert_eq!(
text.flags(),
SectionFlags::Elf {
sh_flags: (object::elf::SHF_ALLOC | object::elf::SHF_EXECINSTR).into()
}
);
assert_eq!(&text.data().unwrap()[..30], &[1; 30]);
assert_eq!(&text.data().unwrap()[32..62], &[1; 30]);
let section = sections.next().unwrap();
println!("{:?}", section);
assert_eq!(section.name(), Ok(".rela.text"));
assert_eq!(section.kind(), SectionKind::Metadata);
let section = sections.next().unwrap();
println!("{:?}", section);
assert_eq!(section.name(), Ok(".eh_frame"));
assert_eq!(
section.kind(),
SectionKind::Elf(object::elf::SHT_X86_64_UNWIND)
);
assert_eq!(
section.flags(),
SectionFlags::Elf {
sh_flags: object::elf::SHF_ALLOC.into()
}
);
let mut symbols = object.symbols();
let symbol = symbols.next().unwrap();