authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-11-09 11:49:32+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2023-11-09 11:49:32+01:00
log666ac6bf9be68a96d15085c016d123404e256d32
treed303d0695ad43dbc0e4c78e0caf4b09d488353e0
parentf607126614ab249dbf8f965ca0911fda560bc580

elf: track .rela.eh_frame section and emit .eh_frame section symbol


1 files changed, 23 insertions(+), 1 deletions(-)

src/link/Elf.zig+23-1
......@@ -122,6 +122,7 @@ dynamic_section_index: ?u16 = null,
122122dynstrtab_section_index: ?u16 = null,
123123dynsymtab_section_index: ?u16 = null,
124124eh_frame_section_index: ?u16 = null,
125eh_frame_rela_section_index: ?u16 = null,
125126eh_frame_hdr_section_index: ?u16 = null,
126127hash_section_index: ?u16 = null,
127128gnu_hash_section_index: ?u16 = null,
......@@ -3583,7 +3584,7 @@ fn initSectionsObject(self: *Elf) !void {
35833584 .addralign = ptr_size,
35843585 .offset = std.math.maxInt(u64),
35853586 });
3586 // _ = try self.addRelaShdr(".rela.eh_frame", self.eh_frame_section_index.?);
3587 self.eh_frame_rela_section_index = try self.addRelaShdr(".rela.eh_frame", self.eh_frame_section_index.?);
35873588 }
35883589
35893590 try self.initSymtab();
......@@ -3954,6 +3955,7 @@ fn sortShdrs(self: *Elf) !void {
39543955
39553956 for (&[_]*?u16{
39563957 &self.eh_frame_section_index,
3958 &self.eh_frame_rela_section_index,
39573959 &self.eh_frame_hdr_section_index,
39583960 &self.got_section_index,
39593961 &self.symtab_section_index,
......@@ -4769,6 +4771,9 @@ fn updateSymtabSize(self: *Elf) !void {
47694771 for (self.output_sections.keys()) |_| {
47704772 nlocals += 1;
47714773 }
4774 if (self.eh_frame_section_index) |_| {
4775 nlocals += 1;
4776 }
47724777
47734778 for (files.items) |index| {
47744779 const file_ptr = self.file(index).?;
......@@ -5162,9 +5167,26 @@ fn writeSectionSymbols(self: *Elf) void {
51625167 };
51635168 ilocal += 1;
51645169 }
5170
5171 if (self.eh_frame_section_index) |shndx| {
5172 const shdr = self.shdrs.items[shndx];
5173 const out_sym = &self.symtab.items[ilocal];
5174 out_sym.* = .{
5175 .st_name = 0,
5176 .st_value = shdr.sh_addr,
5177 .st_info = elf.STT_SECTION,
5178 .st_shndx = @intCast(shndx),
5179 .st_size = 0,
5180 .st_other = 0,
5181 };
5182 ilocal += 1;
5183 }
51655184}
51665185
51675186pub fn sectionSymbolOutputSymtabIndex(self: Elf, shndx: u32) u32 {
5187 if (self.eh_frame_section_index) |index| {
5188 if (index == shndx) return @intCast(self.output_sections.keys().len + 1);
5189 }
51685190 return @intCast(self.output_sections.getIndex(shndx).? + 1);
51695191}
51705192