authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-04-08 22:09:49+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-04-08 22:09:49+02:00
log84a0110464eba4d5e3669647395e1a4ea7648683
tree0b048ea62c7d70ac8be16ca5bb15acdea2592fd2
parent9875ab4ee823b4cbf93fed826eeb03900b2046ff

link/elf: handle symbols to begin/end of .eh_frame section


1 files changed, 24 insertions(+), 0 deletions(-)

src/link/Elf/Symbol.zig+24
...@@ -105,6 +105,29 @@ pub fn address(symbol: Symbol, opts: struct { plt: bool = true }, elf_file: *Elf...@@ -105,6 +105,29 @@ pub fn address(symbol: Symbol, opts: struct { plt: bool = true }, elf_file: *Elf
105 return symbol.pltAddress(elf_file);105 return symbol.pltAddress(elf_file);
106 }106 }
107 if (symbol.atom(elf_file)) |atom_ptr| {107 if (symbol.atom(elf_file)) |atom_ptr| {
108 if (!atom_ptr.flags.alive) {
109 if (mem.eql(u8, atom_ptr.name(elf_file), ".eh_frame")) {
110 const sym_name = symbol.name(elf_file);
111 if (mem.startsWith(u8, sym_name, "__EH_FRAME_BEGIN__") or
112 mem.startsWith(u8, sym_name, "__EH_FRAME_LIST__") or
113 mem.startsWith(u8, sym_name, ".eh_frame_seg") or
114 symbol.elfSym(elf_file).st_type() == elf.STT_SECTION)
115 {
116 return elf_file.shdrs.items[elf_file.eh_frame_section_index.?].sh_addr;
117 }
118
119 if (mem.startsWith(u8, sym_name, "__FRAME_END__") or
120 mem.startsWith(u8, sym_name, "__EH_FRAME_LIST_END__"))
121 {
122 const shdr = elf_file.shdrs.items[elf_file.eh_frame_section_index.?];
123 return shdr.sh_addr + shdr.sh_size;
124 }
125
126 // TODO I think we potentially should error here
127 }
128
129 return 0;
130 }
108 return atom_ptr.address(elf_file) + symbol.value;131 return atom_ptr.address(elf_file) + symbol.value;
109 }132 }
110 return symbol.value;133 return symbol.value;
...@@ -432,6 +455,7 @@ pub const Index = u32;...@@ -432,6 +455,7 @@ pub const Index = u32;
432455
433const assert = std.debug.assert;456const assert = std.debug.assert;
434const elf = std.elf;457const elf = std.elf;
458const mem = std.mem;
435const std = @import("std");459const std = @import("std");
436const synthetic_sections = @import("synthetic_sections.zig");460const synthetic_sections = @import("synthetic_sections.zig");
437461