diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2024-09-03 13:28:01 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2024-09-04 13:34:26 +0200 |
| commit | 2ef3e30e2d04f16510d0953e6d266a97bcb4eb49 (patch) | |
| tree | 2d4fd8e6fd36449939b254f99408370b3884cc86 /src/link/Elf/Object.zig | |
| parent | 5cb51c10debd3e9542e35e22648bca2a8b59259e (diff) | |
| download | zig-2ef3e30e2d04f16510d0953e6d266a97bcb4eb49.tar.gz zig-2ef3e30e2d04f16510d0953e6d266a97bcb4eb49.zip | |
elf: emit relocs for self-hosted generated .eh_frame section
Diffstat (limited to 'src/link/Elf/Object.zig')
| -rw-r--r-- | src/link/Elf/Object.zig | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/src/link/Elf/Object.zig b/src/link/Elf/Object.zig index 92c8c1e23f..a72ac697dd 100644 --- a/src/link/Elf/Object.zig +++ b/src/link/Elf/Object.zig @@ -391,15 +391,24 @@ fn parseEhFrame(self: *Object, allocator: Allocator, handle: std.fs.File, shndx: .input_section_index = shndx, .file_index = self.index, }), - .fde => try self.fdes.append(allocator, .{ - .offset = data_start + rec.offset, - .size = rec.size, - .cie_index = undefined, - .rel_index = rel_start + @as(u32, @intCast(rel_range.start)), - .rel_num = @as(u32, @intCast(rel_range.len)), - .input_section_index = shndx, - .file_index = self.index, - }), + .fde => { + if (rel_range.len == 0) { + // No relocs for an FDE means we cannot associate this FDE to an Atom + // so we skip it. According to mold source code + // (https://github.com/rui314/mold/blob/a3e69502b0eaf1126d6093e8ea5e6fdb95219811/src/input-files.cc#L525-L528) + // this can happen for object files built with -r flag by the linker. + continue; + } + try self.fdes.append(allocator, .{ + .offset = data_start + rec.offset, + .size = rec.size, + .cie_index = undefined, + .rel_index = rel_start + @as(u32, @intCast(rel_range.start)), + .rel_num = @as(u32, @intCast(rel_range.len)), + .input_section_index = shndx, + .file_index = self.index, + }); + }, } } @@ -1106,6 +1115,7 @@ pub fn addAtomsToRelaSections(self: *Object, elf_file: *Elf) !void { for (self.atoms_indexes.items) |atom_index| { const atom_ptr = self.atom(atom_index) orelse continue; if (!atom_ptr.alive) continue; + if (atom_ptr.output_section_index == elf_file.eh_frame_section_index) continue; const shndx = blk: { const shndx = atom_ptr.relocsShndx() orelse continue; const shdr = self.shdrs.items[shndx]; |
