| author | |
| committer | |
| log | da60159d85f2b23e35b62f0626163d798413916f |
| tree | a539ff934e8bb2a472eb3b04797ac4dfa611363a |
| parent | acb91f4b30e6cbb14bb81406ca6ca71241dc3a98 |
3 files changed, 100 insertions(+), 106 deletions(-)
src/link/Dwarf.zig+48-37| ... | @@ -375,12 +375,17 @@ pub const Section = struct { | ... | @@ -375,12 +375,17 @@ pub const Section = struct { |
| 375 | fn resize(sec: *Section, dwarf: *Dwarf, len: u64) UpdateError!void { | 375 | fn resize(sec: *Section, dwarf: *Dwarf, len: u64) UpdateError!void { |
| 376 | if (len <= sec.len) return; | 376 | if (len <= sec.len) return; |
| 377 | if (dwarf.bin_file.cast(.elf)) |elf_file| { | 377 | if (dwarf.bin_file.cast(.elf)) |elf_file| { |
| 378 | const zo = elf_file.zigObjectPtr().?; | ||
| 379 | const atom = zo.symbol(sec.index).atom(elf_file).?; | ||
| 380 | const shndx = atom.output_section_index; | ||
| 378 | if (sec == &dwarf.debug_frame.section) | 381 | if (sec == &dwarf.debug_frame.section) |
| 379 | try elf_file.growAllocSection(sec.index, len) | 382 | try elf_file.growAllocSection(shndx, len) |
| 380 | else | 383 | else |
| 381 | try elf_file.growNonAllocSection(sec.index, len, @intCast(sec.alignment.toByteUnits().?), true); | 384 | try elf_file.growNonAllocSection(shndx, len, @intCast(sec.alignment.toByteUnits().?), true); |
| 382 | const shdr = &elf_file.sections.items(.shdr)[sec.index]; | 385 | const shdr = elf_file.sections.items(.shdr)[shndx]; |
| 383 | sec.off = shdr.sh_offset; | 386 | atom.size = shdr.sh_size; |
| 387 | atom.alignment = InternPool.Alignment.fromNonzeroByteUnits(shdr.sh_addralign); | ||
| 388 | sec.off = shdr.sh_offset + @as(u64, @intCast(atom.value)); | ||
| 384 | sec.len = shdr.sh_size; | 389 | sec.len = shdr.sh_size; |
| 385 | } else if (dwarf.bin_file.cast(.macho)) |macho_file| { | 390 | } else if (dwarf.bin_file.cast(.macho)) |macho_file| { |
| 386 | const header = if (macho_file.d_sym) |*d_sym| header: { | 391 | const header = if (macho_file.d_sym) |*d_sym| header: { |
| ... | @@ -402,7 +407,11 @@ pub const Section = struct { | ... | @@ -402,7 +407,11 @@ pub const Section = struct { |
| 402 | sec.off += len; | 407 | sec.off += len; |
| 403 | sec.len -= len; | 408 | sec.len -= len; |
| 404 | if (dwarf.bin_file.cast(.elf)) |elf_file| { | 409 | if (dwarf.bin_file.cast(.elf)) |elf_file| { |
| 405 | const shdr = &elf_file.sections.items(.shdr)[sec.index]; | 410 | const zo = elf_file.zigObjectPtr().?; |
| 411 | const atom = zo.symbol(sec.index).atom(elf_file).?; | ||
| 412 | const shndx = atom.output_section_index; | ||
| 413 | const shdr = &elf_file.sections.items(.shdr)[shndx]; | ||
| 414 | atom.size = sec.len; | ||
| 406 | shdr.sh_offset = sec.off; | 415 | shdr.sh_offset = sec.off; |
| 407 | shdr.sh_size = sec.len; | 416 | shdr.sh_size = sec.len; |
| 408 | } else if (dwarf.bin_file.cast(.macho)) |macho_file| { | 417 | } else if (dwarf.bin_file.cast(.macho)) |macho_file| { |
| ... | @@ -891,9 +900,11 @@ const Entry = struct { | ... | @@ -891,9 +900,11 @@ const Entry = struct { |
| 891 | if (std.debug.runtime_safety) { | 900 | if (std.debug.runtime_safety) { |
| 892 | log.err("missing {} from {s}", .{ | 901 | log.err("missing {} from {s}", .{ |
| 893 | @as(Entry.Index, @enumFromInt(entry - unit.entries.items.ptr)), | 902 | @as(Entry.Index, @enumFromInt(entry - unit.entries.items.ptr)), |
| 894 | std.mem.sliceTo(if (dwarf.bin_file.cast(.elf)) |elf_file| | 903 | std.mem.sliceTo(if (dwarf.bin_file.cast(.elf)) |elf_file| sh_name: { |
| 895 | elf_file.shstrtab.items[elf_file.sections.items(.shdr)[sec.index].sh_name..] | 904 | const zo = elf_file.zigObjectPtr().?; |
| 896 | else if (dwarf.bin_file.cast(.macho)) |macho_file| | 905 | const shndx = zo.symbol(sec.index).atom(elf_file).?.output_section_index; |
| 906 | break :sh_name elf_file.shstrtab.items[elf_file.sections.items(.shdr)[shndx].sh_name..]; | ||
| 907 | } else if (dwarf.bin_file.cast(.macho)) |macho_file| | ||
| 897 | if (macho_file.d_sym) |*d_sym| | 908 | if (macho_file.d_sym) |*d_sym| |
| 898 | &d_sym.sections.items[sec.index].segname | 909 | &d_sym.sections.items[sec.index].segname |
| 899 | else | 910 | else |
| ... | @@ -961,7 +972,8 @@ const Entry = struct { | ... | @@ -961,7 +972,8 @@ const Entry = struct { |
| 961 | .none, .debug_frame => {}, | 972 | .none, .debug_frame => {}, |
| 962 | .eh_frame => return if (dwarf.bin_file.cast(.elf)) |elf_file| { | 973 | .eh_frame => return if (dwarf.bin_file.cast(.elf)) |elf_file| { |
| 963 | const zo = elf_file.zigObjectPtr().?; | 974 | const zo = elf_file.zigObjectPtr().?; |
| 964 | const entry_addr: i64 = @intCast(entry_off - sec.off + elf_file.shdrs.items[sec.index].sh_addr); | 975 | const shndx = zo.symbol(sec.index).atom(elf_file).?.output_section_index; |
| 976 | const entry_addr: i64 = @intCast(entry_off - sec.off + elf_file.shdrs.items[shndx].sh_addr); | ||
| 965 | for (entry.external_relocs.items) |reloc| { | 977 | for (entry.external_relocs.items) |reloc| { |
| 966 | const symbol = zo.symbol(reloc.target_sym); | 978 | const symbol = zo.symbol(reloc.target_sym); |
| 967 | try dwarf.resolveReloc( | 979 | try dwarf.resolveReloc( |
| ... | @@ -1877,34 +1889,7 @@ pub fn init(lf: *link.File, format: DW.Format) Dwarf { | ... | @@ -1877,34 +1889,7 @@ pub fn init(lf: *link.File, format: DW.Format) Dwarf { |
| 1877 | } | 1889 | } |
| 1878 | 1890 | ||
| 1879 | pub fn reloadSectionMetadata(dwarf: *Dwarf) void { | 1891 | pub fn reloadSectionMetadata(dwarf: *Dwarf) void { |
| 1880 | if (dwarf.bin_file.cast(.elf)) |elf_file| { | 1892 | if (dwarf.bin_file.cast(.macho)) |macho_file| { |
| 1881 | for ([_]*Section{ | ||
| 1882 | &dwarf.debug_abbrev.section, | ||
| 1883 | &dwarf.debug_aranges.section, | ||
| 1884 | &dwarf.debug_frame.section, | ||
| 1885 | &dwarf.debug_info.section, | ||
| 1886 | &dwarf.debug_line.section, | ||
| 1887 | &dwarf.debug_line_str.section, | ||
| 1888 | &dwarf.debug_loclists.section, | ||
| 1889 | &dwarf.debug_rnglists.section, | ||
| 1890 | &dwarf.debug_str.section, | ||
| 1891 | }, [_]u32{ | ||
| 1892 | elf_file.debug_abbrev_section_index.?, | ||
| 1893 | elf_file.debug_aranges_section_index.?, | ||
| 1894 | elf_file.eh_frame_section_index.?, | ||
| 1895 | elf_file.debug_info_section_index.?, | ||
| 1896 | elf_file.debug_line_section_index.?, | ||
| 1897 | elf_file.debug_line_str_section_index.?, | ||
| 1898 | elf_file.debug_loclists_section_index.?, | ||
| 1899 | elf_file.debug_rnglists_section_index.?, | ||
| 1900 | elf_file.debug_str_section_index.?, | ||
| 1901 | }) |sec, section_index| { | ||
| 1902 | const shdr = &elf_file.sections.items(.shdr)[section_index]; | ||
| 1903 | sec.index = section_index; | ||
| 1904 | sec.off = shdr.sh_offset; | ||
| 1905 | sec.len = shdr.sh_size; | ||
| 1906 | } | ||
| 1907 | } else if (dwarf.bin_file.cast(.macho)) |macho_file| { | ||
| 1908 | if (macho_file.d_sym) |*d_sym| { | 1893 | if (macho_file.d_sym) |*d_sym| { |
| 1909 | for ([_]*Section{ | 1894 | for ([_]*Section{ |
| 1910 | &dwarf.debug_abbrev.section, | 1895 | &dwarf.debug_abbrev.section, |
| ... | @@ -1960,6 +1945,32 @@ pub fn reloadSectionMetadata(dwarf: *Dwarf) void { | ... | @@ -1960,6 +1945,32 @@ pub fn reloadSectionMetadata(dwarf: *Dwarf) void { |
| 1960 | } | 1945 | } |
| 1961 | 1946 | ||
| 1962 | pub fn initMetadata(dwarf: *Dwarf) UpdateError!void { | 1947 | pub fn initMetadata(dwarf: *Dwarf) UpdateError!void { |
| 1948 | if (dwarf.bin_file.cast(.elf)) |elf_file| { | ||
| 1949 | const zo = elf_file.zigObjectPtr().?; | ||
| 1950 | for ([_]*Section{ | ||
| 1951 | &dwarf.debug_abbrev.section, | ||
| 1952 | &dwarf.debug_aranges.section, | ||
| 1953 | &dwarf.debug_frame.section, | ||
| 1954 | &dwarf.debug_info.section, | ||
| 1955 | &dwarf.debug_line.section, | ||
| 1956 | &dwarf.debug_line_str.section, | ||
| 1957 | &dwarf.debug_loclists.section, | ||
| 1958 | &dwarf.debug_rnglists.section, | ||
| 1959 | &dwarf.debug_str.section, | ||
| 1960 | }, [_]u32{ | ||
| 1961 | zo.debug_abbrev_index.?, | ||
| 1962 | zo.debug_aranges_index.?, | ||
| 1963 | zo.eh_frame_index.?, | ||
| 1964 | zo.debug_info_index.?, | ||
| 1965 | zo.debug_line_index.?, | ||
| 1966 | zo.debug_line_str_index.?, | ||
| 1967 | zo.debug_loclists_index.?, | ||
| 1968 | zo.debug_rnglists_index.?, | ||
| 1969 | zo.debug_str_index.?, | ||
| 1970 | }) |sec, sym_index| { | ||
| 1971 | sec.index = sym_index; | ||
| 1972 | } | ||
| 1973 | } | ||
| 1963 | dwarf.reloadSectionMetadata(); | 1974 | dwarf.reloadSectionMetadata(); |
| 1964 | 1975 | ||
| 1965 | dwarf.debug_abbrev.section.pad_to_ideal = false; | 1976 | dwarf.debug_abbrev.section.pad_to_ideal = false; |
src/link/Elf.zig+25-36| ... | @@ -114,15 +114,6 @@ rela_plt: std.ArrayListUnmanaged(elf.Elf64_Rela) = .{}, | ... | @@ -114,15 +114,6 @@ rela_plt: std.ArrayListUnmanaged(elf.Elf64_Rela) = .{}, |
| 114 | /// Applies only to a relocatable. | 114 | /// Applies only to a relocatable. |
| 115 | comdat_group_sections: std.ArrayListUnmanaged(ComdatGroupSection) = .{}, | 115 | comdat_group_sections: std.ArrayListUnmanaged(ComdatGroupSection) = .{}, |
| 116 | 116 | ||
| 117 | debug_info_section_index: ?u32 = null, | ||
| 118 | debug_abbrev_section_index: ?u32 = null, | ||
| 119 | debug_str_section_index: ?u32 = null, | ||
| 120 | debug_aranges_section_index: ?u32 = null, | ||
| 121 | debug_line_section_index: ?u32 = null, | ||
| 122 | debug_line_str_section_index: ?u32 = null, | ||
| 123 | debug_loclists_section_index: ?u32 = null, | ||
| 124 | debug_rnglists_section_index: ?u32 = null, | ||
| 125 | |||
| 126 | copy_rel_section_index: ?u32 = null, | 117 | copy_rel_section_index: ?u32 = null, |
| 127 | dynamic_section_index: ?u32 = null, | 118 | dynamic_section_index: ?u32 = null, |
| 128 | dynstrtab_section_index: ?u32 = null, | 119 | dynstrtab_section_index: ?u32 = null, |
| ... | @@ -636,24 +627,31 @@ pub fn growNonAllocSection( | ... | @@ -636,24 +627,31 @@ pub fn growNonAllocSection( |
| 636 | } | 627 | } |
| 637 | 628 | ||
| 638 | pub fn markDirty(self: *Elf, shdr_index: u32) void { | 629 | pub fn markDirty(self: *Elf, shdr_index: u32) void { |
| 639 | const zig_object = self.zigObjectPtr().?; | 630 | if (self.zigObjectPtr()) |zo| { |
| 640 | if (zig_object.dwarf) |_| { | 631 | for ([_]?Symbol.Index{ |
| 641 | if (self.debug_info_section_index.? == shdr_index) { | 632 | zo.debug_info_index, |
| 642 | zig_object.debug_info_section_dirty = true; | 633 | zo.debug_abbrev_index, |
| 643 | } else if (self.debug_abbrev_section_index.? == shdr_index) { | 634 | zo.debug_aranges_index, |
| 644 | zig_object.debug_abbrev_section_dirty = true; | 635 | zo.debug_str_index, |
| 645 | } else if (self.debug_str_section_index.? == shdr_index) { | 636 | zo.debug_line_index, |
| 646 | zig_object.debug_str_section_dirty = true; | 637 | zo.debug_line_str_index, |
| 647 | } else if (self.debug_aranges_section_index.? == shdr_index) { | 638 | zo.debug_loclists_index, |
| 648 | zig_object.debug_aranges_section_dirty = true; | 639 | zo.debug_rnglists_index, |
| 649 | } else if (self.debug_line_section_index.? == shdr_index) { | 640 | }, [_]*bool{ |
| 650 | zig_object.debug_line_section_dirty = true; | 641 | &zo.debug_info_section_dirty, |
| 651 | } else if (self.debug_line_str_section_index.? == shdr_index) { | 642 | &zo.debug_abbrev_section_dirty, |
| 652 | zig_object.debug_line_str_section_dirty = true; | 643 | &zo.debug_aranges_section_dirty, |
| 653 | } else if (self.debug_loclists_section_index.? == shdr_index) { | 644 | &zo.debug_str_section_dirty, |
| 654 | zig_object.debug_loclists_section_dirty = true; | 645 | &zo.debug_line_section_dirty, |
| 655 | } else if (self.debug_rnglists_section_index.? == shdr_index) { | 646 | &zo.debug_line_str_section_dirty, |
| 656 | zig_object.debug_rnglists_section_dirty = true; | 647 | &zo.debug_loclists_section_dirty, |
| 648 | &zo.debug_rnglists_section_dirty, | ||
| 649 | }) |maybe_sym_index, dirty| { | ||
| 650 | const sym_index = maybe_sym_index orelse continue; | ||
| 651 | if (zo.symbol(sym_index).atom(self).?.output_section_index == shdr_index) { | ||
| 652 | dirty.* = true; | ||
| 653 | break; | ||
| 654 | } | ||
| 657 | } | 655 | } |
| 658 | } | 656 | } |
| 659 | } | 657 | } |
| ... | @@ -3473,14 +3471,6 @@ fn resetShdrIndexes(self: *Elf, backlinks: []const u32) void { | ... | @@ -3473,14 +3471,6 @@ fn resetShdrIndexes(self: *Elf, backlinks: []const u32) void { |
| 3473 | &self.copy_rel_section_index, | 3471 | &self.copy_rel_section_index, |
| 3474 | &self.versym_section_index, | 3472 | &self.versym_section_index, |
| 3475 | &self.verneed_section_index, | 3473 | &self.verneed_section_index, |
| 3476 | &self.debug_info_section_index, | ||
| 3477 | &self.debug_abbrev_section_index, | ||
| 3478 | &self.debug_str_section_index, | ||
| 3479 | &self.debug_aranges_section_index, | ||
| 3480 | &self.debug_line_section_index, | ||
| 3481 | &self.debug_line_str_section_index, | ||
| 3482 | &self.debug_loclists_section_index, | ||
| 3483 | &self.debug_rnglists_section_index, | ||
| 3484 | }) |maybe_index| { | 3474 | }) |maybe_index| { |
| 3485 | if (maybe_index.*) |*index| { | 3475 | if (maybe_index.*) |*index| { |
| 3486 | index.* = backlinks[index.*]; | 3476 | index.* = backlinks[index.*]; |
| ... | @@ -3505,7 +3495,6 @@ fn resetShdrIndexes(self: *Elf, backlinks: []const u32) void { | ... | @@ -3505,7 +3495,6 @@ fn resetShdrIndexes(self: *Elf, backlinks: []const u32) void { |
| 3505 | const atom_ptr = zo.atom(atom_index) orelse continue; | 3495 | const atom_ptr = zo.atom(atom_index) orelse continue; |
| 3506 | atom_ptr.output_section_index = backlinks[atom_ptr.output_section_index]; | 3496 | atom_ptr.output_section_index = backlinks[atom_ptr.output_section_index]; |
| 3507 | } | 3497 | } |
| 3508 | if (zo.dwarf) |*dwarf| dwarf.reloadSectionMetadata(); | ||
| 3509 | } | 3498 | } |
| 3510 | 3499 | ||
| 3511 | for (self.comdat_group_sections.items) |*cg| { | 3500 | for (self.comdat_group_sections.items) |*cg| { |
src/link/Elf/ZigObject.zig+27-33| ... | @@ -99,8 +99,8 @@ pub fn init(self: *ZigObject, elf_file: *Elf, options: InitOptions) !void { | ... | @@ -99,8 +99,8 @@ pub fn init(self: *ZigObject, elf_file: *Elf, options: InitOptions) !void { |
| 99 | .dwarf => |v| { | 99 | .dwarf => |v| { |
| 100 | var dwarf = Dwarf.init(&elf_file.base, v); | 100 | var dwarf = Dwarf.init(&elf_file.base, v); |
| 101 | 101 | ||
| 102 | if (elf_file.debug_str_section_index == null) { | 102 | if (self.debug_str_index == null) { |
| 103 | elf_file.debug_str_section_index = try elf_file.addSection(.{ | 103 | const osec = try elf_file.addSection(.{ |
| 104 | .name = try elf_file.insertShString(".debug_str"), | 104 | .name = try elf_file.insertShString(".debug_str"), |
| 105 | .flags = elf.SHF_MERGE | elf.SHF_STRINGS, | 105 | .flags = elf.SHF_MERGE | elf.SHF_STRINGS, |
| 106 | .entsize = 1, | 106 | .entsize = 1, |
| ... | @@ -108,51 +108,51 @@ pub fn init(self: *ZigObject, elf_file: *Elf, options: InitOptions) !void { | ... | @@ -108,51 +108,51 @@ pub fn init(self: *ZigObject, elf_file: *Elf, options: InitOptions) !void { |
| 108 | .addralign = 1, | 108 | .addralign = 1, |
| 109 | }); | 109 | }); |
| 110 | self.debug_str_section_dirty = true; | 110 | self.debug_str_section_dirty = true; |
| 111 | self.debug_str_index = try self.addSectionSymbol(gpa, ".debug_str", .@"1", elf_file.debug_str_section_index.?); | 111 | self.debug_str_index = try self.addSectionSymbol(gpa, ".debug_str", .@"1", osec); |
| 112 | } | 112 | } |
| 113 | 113 | ||
| 114 | if (elf_file.debug_info_section_index == null) { | 114 | if (self.debug_info_index == null) { |
| 115 | elf_file.debug_info_section_index = try elf_file.addSection(.{ | 115 | const osec = try elf_file.addSection(.{ |
| 116 | .name = try elf_file.insertShString(".debug_info"), | 116 | .name = try elf_file.insertShString(".debug_info"), |
| 117 | .type = elf.SHT_PROGBITS, | 117 | .type = elf.SHT_PROGBITS, |
| 118 | .addralign = 1, | 118 | .addralign = 1, |
| 119 | }); | 119 | }); |
| 120 | self.debug_info_section_dirty = true; | 120 | self.debug_info_section_dirty = true; |
| 121 | self.debug_info_index = try self.addSectionSymbol(gpa, ".debug_info", .@"1", elf_file.debug_info_section_index.?); | 121 | self.debug_info_index = try self.addSectionSymbol(gpa, ".debug_info", .@"1", osec); |
| 122 | } | 122 | } |
| 123 | 123 | ||
| 124 | if (elf_file.debug_abbrev_section_index == null) { | 124 | if (self.debug_abbrev_index == null) { |
| 125 | elf_file.debug_abbrev_section_index = try elf_file.addSection(.{ | 125 | const osec = try elf_file.addSection(.{ |
| 126 | .name = try elf_file.insertShString(".debug_abbrev"), | 126 | .name = try elf_file.insertShString(".debug_abbrev"), |
| 127 | .type = elf.SHT_PROGBITS, | 127 | .type = elf.SHT_PROGBITS, |
| 128 | .addralign = 1, | 128 | .addralign = 1, |
| 129 | }); | 129 | }); |
| 130 | self.debug_abbrev_section_dirty = true; | 130 | self.debug_abbrev_section_dirty = true; |
| 131 | self.debug_abbrev_index = try self.addSectionSymbol(gpa, ".debug_abbrev", .@"1", elf_file.debug_abbrev_section_index.?); | 131 | self.debug_abbrev_index = try self.addSectionSymbol(gpa, ".debug_abbrev", .@"1", osec); |
| 132 | } | 132 | } |
| 133 | 133 | ||
| 134 | if (elf_file.debug_aranges_section_index == null) { | 134 | if (self.debug_aranges_index == null) { |
| 135 | elf_file.debug_aranges_section_index = try elf_file.addSection(.{ | 135 | const osec = try elf_file.addSection(.{ |
| 136 | .name = try elf_file.insertShString(".debug_aranges"), | 136 | .name = try elf_file.insertShString(".debug_aranges"), |
| 137 | .type = elf.SHT_PROGBITS, | 137 | .type = elf.SHT_PROGBITS, |
| 138 | .addralign = 16, | 138 | .addralign = 16, |
| 139 | }); | 139 | }); |
| 140 | self.debug_aranges_section_dirty = true; | 140 | self.debug_aranges_section_dirty = true; |
| 141 | self.debug_aranges_index = try self.addSectionSymbol(gpa, ".debug_aranges", .@"16", elf_file.debug_aranges_section_index.?); | 141 | self.debug_aranges_index = try self.addSectionSymbol(gpa, ".debug_aranges", .@"16", osec); |
| 142 | } | 142 | } |
| 143 | 143 | ||
| 144 | if (elf_file.debug_line_section_index == null) { | 144 | if (self.debug_line_index == null) { |
| 145 | elf_file.debug_line_section_index = try elf_file.addSection(.{ | 145 | const osec = try elf_file.addSection(.{ |
| 146 | .name = try elf_file.insertShString(".debug_line"), | 146 | .name = try elf_file.insertShString(".debug_line"), |
| 147 | .type = elf.SHT_PROGBITS, | 147 | .type = elf.SHT_PROGBITS, |
| 148 | .addralign = 1, | 148 | .addralign = 1, |
| 149 | }); | 149 | }); |
| 150 | self.debug_line_section_dirty = true; | 150 | self.debug_line_section_dirty = true; |
| 151 | self.debug_line_index = try self.addSectionSymbol(gpa, ".debug_line", .@"1", elf_file.debug_line_section_index.?); | 151 | self.debug_line_index = try self.addSectionSymbol(gpa, ".debug_line", .@"1", osec); |
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | if (elf_file.debug_line_str_section_index == null) { | 154 | if (self.debug_line_str_index == null) { |
| 155 | elf_file.debug_line_str_section_index = try elf_file.addSection(.{ | 155 | const osec = try elf_file.addSection(.{ |
| 156 | .name = try elf_file.insertShString(".debug_line_str"), | 156 | .name = try elf_file.insertShString(".debug_line_str"), |
| 157 | .flags = elf.SHF_MERGE | elf.SHF_STRINGS, | 157 | .flags = elf.SHF_MERGE | elf.SHF_STRINGS, |
| 158 | .entsize = 1, | 158 | .entsize = 1, |
| ... | @@ -160,31 +160,31 @@ pub fn init(self: *ZigObject, elf_file: *Elf, options: InitOptions) !void { | ... | @@ -160,31 +160,31 @@ pub fn init(self: *ZigObject, elf_file: *Elf, options: InitOptions) !void { |
| 160 | .addralign = 1, | 160 | .addralign = 1, |
| 161 | }); | 161 | }); |
| 162 | self.debug_line_str_section_dirty = true; | 162 | self.debug_line_str_section_dirty = true; |
| 163 | self.debug_line_str_index = try self.addSectionSymbol(gpa, ".debug_line_str", .@"1", elf_file.debug_line_str_section_index.?); | 163 | self.debug_line_str_index = try self.addSectionSymbol(gpa, ".debug_line_str", .@"1", osec); |
| 164 | } | 164 | } |
| 165 | 165 | ||
| 166 | if (elf_file.debug_loclists_section_index == null) { | 166 | if (self.debug_loclists_index == null) { |
| 167 | elf_file.debug_loclists_section_index = try elf_file.addSection(.{ | 167 | const osec = try elf_file.addSection(.{ |
| 168 | .name = try elf_file.insertShString(".debug_loclists"), | 168 | .name = try elf_file.insertShString(".debug_loclists"), |
| 169 | .type = elf.SHT_PROGBITS, | 169 | .type = elf.SHT_PROGBITS, |
| 170 | .addralign = 1, | 170 | .addralign = 1, |
| 171 | }); | 171 | }); |
| 172 | self.debug_loclists_section_dirty = true; | 172 | self.debug_loclists_section_dirty = true; |
| 173 | self.debug_loclists_index = try self.addSectionSymbol(gpa, ".debug_loclists", .@"1", elf_file.debug_loclists_section_index.?); | 173 | self.debug_loclists_index = try self.addSectionSymbol(gpa, ".debug_loclists", .@"1", osec); |
| 174 | } | 174 | } |
| 175 | 175 | ||
| 176 | if (elf_file.debug_rnglists_section_index == null) { | 176 | if (self.debug_rnglists_index == null) { |
| 177 | elf_file.debug_rnglists_section_index = try elf_file.addSection(.{ | 177 | const osec = try elf_file.addSection(.{ |
| 178 | .name = try elf_file.insertShString(".debug_rnglists"), | 178 | .name = try elf_file.insertShString(".debug_rnglists"), |
| 179 | .type = elf.SHT_PROGBITS, | 179 | .type = elf.SHT_PROGBITS, |
| 180 | .addralign = 1, | 180 | .addralign = 1, |
| 181 | }); | 181 | }); |
| 182 | self.debug_rnglists_section_dirty = true; | 182 | self.debug_rnglists_section_dirty = true; |
| 183 | self.debug_rnglists_index = try self.addSectionSymbol(gpa, ".debug_rnglists", .@"1", elf_file.debug_rnglists_section_index.?); | 183 | self.debug_rnglists_index = try self.addSectionSymbol(gpa, ".debug_rnglists", .@"1", osec); |
| 184 | } | 184 | } |
| 185 | 185 | ||
| 186 | if (elf_file.eh_frame_section_index == null) { | 186 | if (self.eh_frame_index == null) { |
| 187 | elf_file.eh_frame_section_index = try elf_file.addSection(.{ | 187 | const osec = try elf_file.addSection(.{ |
| 188 | .name = try elf_file.insertShString(".eh_frame"), | 188 | .name = try elf_file.insertShString(".eh_frame"), |
| 189 | .type = if (elf_file.getTarget().cpu.arch == .x86_64) | 189 | .type = if (elf_file.getTarget().cpu.arch == .x86_64) |
| 190 | elf.SHT_X86_64_UNWIND | 190 | elf.SHT_X86_64_UNWIND |
| ... | @@ -194,7 +194,7 @@ pub fn init(self: *ZigObject, elf_file: *Elf, options: InitOptions) !void { | ... | @@ -194,7 +194,7 @@ pub fn init(self: *ZigObject, elf_file: *Elf, options: InitOptions) !void { |
| 194 | .addralign = ptr_size, | 194 | .addralign = ptr_size, |
| 195 | }); | 195 | }); |
| 196 | self.eh_frame_section_dirty = true; | 196 | self.eh_frame_section_dirty = true; |
| 197 | self.eh_frame_index = try self.addSectionSymbol(gpa, ".eh_frame", Atom.Alignment.fromNonzeroByteUnits(ptr_size), elf_file.eh_frame_section_index.?); | 197 | self.eh_frame_index = try self.addSectionSymbol(gpa, ".eh_frame", Atom.Alignment.fromNonzeroByteUnits(ptr_size), osec); |
| 198 | } | 198 | } |
| 199 | 199 | ||
| 200 | try dwarf.initMetadata(); | 200 | try dwarf.initMetadata(); |
| ... | @@ -328,12 +328,6 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !voi | ... | @@ -328,12 +328,6 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf, tid: Zcu.PerThread.Id) !voi |
| 328 | const sym = self.symbol(sym_index); | 328 | const sym = self.symbol(sym_index); |
| 329 | const atom_ptr = self.atom(sym.ref.index).?; | 329 | const atom_ptr = self.atom(sym.ref.index).?; |
| 330 | if (!atom_ptr.alive) continue; | 330 | if (!atom_ptr.alive) continue; |
| 331 | const shndx = sym.outputShndx(elf_file).?; | ||
| 332 | const shdr = elf_file.sections.items(.shdr)[shndx]; | ||
| 333 | const esym = &self.symtab.items(.elf_sym)[sym.esym_index]; | ||
| 334 | esym.st_size = shdr.sh_size; | ||
| 335 | atom_ptr.size = shdr.sh_size; | ||
| 336 | atom_ptr.alignment = Atom.Alignment.fromNonzeroByteUnits(shdr.sh_addralign); | ||
| 337 | 331 | ||
| 338 | log.debug("parsing relocs in {s}", .{sym.name(elf_file)}); | 332 | log.debug("parsing relocs in {s}", .{sym.name(elf_file)}); |
| 339 | 333 |