| ... | @@ -922,6 +922,21 @@ pub fn populateMissingMetadata(self: *Elf) !void { | ... | @@ -922,6 +922,21 @@ pub fn populateMissingMetadata(self: *Elf) !void { |
| 922 | } | 922 | } |
| 923 | // We are starting with an empty file. The default values are correct, null and empty list. | 923 | // We are starting with an empty file. The default values are correct, null and empty list. |
| 924 | } | 924 | } |
| | 925 | |
| | 926 | if (self.shdr_table_dirty) { |
| | 927 | // We need to find out what the max file offset is according to section headers. |
| | 928 | // Otherwise, we may end up with an ELF binary with file size not matching the final section's |
| | 929 | // offset + it's filesize. |
| | 930 | var max_file_offset: u64 = 0; |
| | 931 | |
| | 932 | for (self.sections.items) |shdr| { |
| | 933 | if (shdr.sh_offset + shdr.sh_size > max_file_offset) { |
| | 934 | max_file_offset = shdr.sh_offset + shdr.sh_size; |
| | 935 | } |
| | 936 | } |
| | 937 | |
| | 938 | try self.base.file.?.pwriteAll(&[_]u8{0}, max_file_offset); |
| | 939 | } |
| 925 | } | 940 | } |
| 926 | | 941 | |
| 927 | pub const abbrev_compile_unit = 1; | 942 | pub const abbrev_compile_unit = 1; |