forked from gimli-rs/object
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
write/elf: Fix writing of aligned empty sections (gimli-rs#540)
This was previously causing an assertion failure because the alignment padding was not written to the buffer if the section was empty, which caused subsequent sections to be placed at the wrong offsets.
- Loading branch information
Showing
2 changed files
with
26 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#![cfg(feature = "write")] | ||
|
||
use object::{ | ||
write::{Object, StreamingBuffer}, | ||
Architecture, BinaryFormat, Endianness, SectionKind, | ||
}; | ||
|
||
#[test] | ||
fn aligned_sections() { | ||
let mut object = Object::new(BinaryFormat::Elf, Architecture::X86_64, Endianness::Little); | ||
|
||
let text_section_id = object.add_section(vec![], b".text".to_vec(), SectionKind::Text); | ||
let text_section = object.section_mut(text_section_id); | ||
text_section.set_data(&[][..], 4096); | ||
|
||
let data_section_id = object.add_section(vec![], b".data".to_vec(), SectionKind::Data); | ||
let data_section = object.section_mut(data_section_id); | ||
data_section.set_data(&b"1234"[..], 16); | ||
|
||
let mut buffer = StreamingBuffer::new(vec![]); | ||
object.emit(&mut buffer).unwrap(); | ||
buffer.result().unwrap(); | ||
} |