| ... | ... | @@ -302,21 +302,28 @@ fn initSections(elf_file: *Elf) !void { |
| 302 | 302 | try msec.initOutputSection(elf_file); |
| 303 | 303 | } |
| 304 | 304 | |
| 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 | 308 | if (elf_file.file(index).?.object.cies.items.len > 0) break true; |
| 307 | 309 | } else false; |
| 308 | 310 | if (needs_eh_frame) { |
| 309 | 311 | 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 | }; |
| 320 | 327 | } |
| 321 | 328 | elf_file.eh_frame_rela_section_index = try elf_file.addRelaShdr( |
| 322 | 329 | try elf_file.insertShString(".rela.eh_frame"), |