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 {
302302 try msec.initOutputSection(elf_file);
303303 }
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| {
306308 if (elf_file.file(index).?.object.cies.items.len > 0) break true;
307309 } else false;
308310 if (needs_eh_frame) {
309311 if (elf_file.eh_frame_section_index == null) {
310 elf_file.eh_frame_section_index = try elf_file.addSection(.{
311 .name = try elf_file.insertShString(".eh_frame"),
312 .type = if (elf_file.getTarget().cpu.arch == .x86_64)
313 elf.SHT_X86_64_UNWIND
314 else
315 elf.SHT_PROGBITS,
316 .flags = elf.SHF_ALLOC,
317 .addralign = elf_file.ptrWidthBytes(),
318 .offset = std.math.maxInt(u64),
319 });
312 elf_file.eh_frame_section_index = blk: {
313 if (elf_file.zigObjectPtr()) |zo| {
314 if (zo.eh_frame_index) |idx| break :blk zo.symbol(idx).atom(elf_file).?.output_section_index;
315 }
316 break :blk try elf_file.addSection(.{
317 .name = try elf_file.insertShString(".eh_frame"),
318 .type = if (elf_file.getTarget().cpu.arch == .x86_64)
319 elf.SHT_X86_64_UNWIND
320 else
321 elf.SHT_PROGBITS,
322 .flags = elf.SHF_ALLOC,
323 .addralign = elf_file.ptrWidthBytes(),
324 .offset = std.math.maxInt(u64),
325 });
326 };
320327 }
321328 elf_file.eh_frame_rela_section_index = try elf_file.addRelaShdr(
322329 try elf_file.insertShString(".rela.eh_frame"),