authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-09-03 14:45:59+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-09-04 13:34:26+02:00
log5cdad186fe1cb83c6d79642433bfbe330436914a
tree1faa27605eff1543d40902ec53d64c4e3674c7fb
parent88e0d49febf5839654e4a5f3dc02ad6b2a82e242

elf: do not create .eh_frame section if ZigObject already did so in relocatable mode


1 files changed, 18 insertions(+), 11 deletions(-)

src/link/Elf/relocatable.zig+18-11
...@@ -302,21 +302,28 @@ fn initSections(elf_file: *Elf) !void {...@@ -302,21 +302,28 @@ fn initSections(elf_file: *Elf) !void {
302 try msec.initOutputSection(elf_file);302 try msec.initOutputSection(elf_file);
303 }303 }
304304
305 const needs_eh_frame = for (elf_file.objects.items) |index| {305 const needs_eh_frame = if (elf_file.zigObjectPtr()) |zo|
306 zo.eh_frame_index != null
307 else for (elf_file.objects.items) |index| {
306 if (elf_file.file(index).?.object.cies.items.len > 0) break true;308 if (elf_file.file(index).?.object.cies.items.len > 0) break true;
307 } else false;309 } else false;
308 if (needs_eh_frame) {310 if (needs_eh_frame) {
309 if (elf_file.eh_frame_section_index == null) {311 if (elf_file.eh_frame_section_index == null) {
310 elf_file.eh_frame_section_index = try elf_file.addSection(.{312 elf_file.eh_frame_section_index = blk: {
311 .name = try elf_file.insertShString(".eh_frame"),313 if (elf_file.zigObjectPtr()) |zo| {
312 .type = if (elf_file.getTarget().cpu.arch == .x86_64)314 if (zo.eh_frame_index) |idx| break :blk zo.symbol(idx).atom(elf_file).?.output_section_index;
313 elf.SHT_X86_64_UNWIND315 }
314 else316 break :blk try elf_file.addSection(.{
315 elf.SHT_PROGBITS,317 .name = try elf_file.insertShString(".eh_frame"),
316 .flags = elf.SHF_ALLOC,318 .type = if (elf_file.getTarget().cpu.arch == .x86_64)
317 .addralign = elf_file.ptrWidthBytes(),319 elf.SHT_X86_64_UNWIND
318 .offset = std.math.maxInt(u64),320 else
319 });321 elf.SHT_PROGBITS,
322 .flags = elf.SHF_ALLOC,
323 .addralign = elf_file.ptrWidthBytes(),
324 .offset = std.math.maxInt(u64),
325 });
326 };
320 }327 }
321 elf_file.eh_frame_rela_section_index = try elf_file.addRelaShdr(328 elf_file.eh_frame_rela_section_index = try elf_file.addRelaShdr(
322 try elf_file.insertShString(".rela.eh_frame"),329 try elf_file.insertShString(".rela.eh_frame"),