mirror of
https://github.com/ziglang/zig.git
synced 2026-02-12 20:37:54 +00:00
elf: pad out file to the required size when init data
We need to pad out the file to the required maximum size equal the final section's offset plus the section's size. We only need to this when populating initial metadata and only when section header was updated.
This commit is contained in:
parent
65c812842d
commit
57357c43e3
@ -922,6 +922,21 @@ pub fn populateMissingMetadata(self: *Elf) !void {
|
||||
}
|
||||
// We are starting with an empty file. The default values are correct, null and empty list.
|
||||
}
|
||||
|
||||
if (self.shdr_table_dirty) {
|
||||
// We need to find out what the max file offset is according to section headers.
|
||||
// Otherwise, we may end up with an ELF binary with file size not matching the final section's
|
||||
// offset + it's filesize.
|
||||
var max_file_offset: u64 = 0;
|
||||
|
||||
for (self.sections.items) |shdr| {
|
||||
if (shdr.sh_offset + shdr.sh_size > max_file_offset) {
|
||||
max_file_offset = shdr.sh_offset + shdr.sh_size;
|
||||
}
|
||||
}
|
||||
|
||||
try self.base.file.?.pwriteAll(&[_]u8{0}, max_file_offset);
|
||||
}
|
||||
}
|
||||
|
||||
pub const abbrev_compile_unit = 1;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user