| ... | @@ -180,16 +180,16 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf) !void { | ... | @@ -180,16 +180,16 @@ pub fn flushModule(self: *ZigObject, elf_file: *Elf) !void { |
| 180 | } | 180 | } |
| 181 | | 181 | |
| 182 | if (self.debug_info_header_dirty) { | 182 | if (self.debug_info_header_dirty) { |
| 183 | const text_phdr = &elf_file.phdrs.items[elf_file.phdr_zig_load_re_index.?]; | 183 | const text_shdr = elf_file.shdrs.items[elf_file.zig_text_section_index.?]; |
| 184 | const low_pc = text_phdr.p_vaddr; | 184 | const low_pc = text_shdr.sh_addr; |
| 185 | const high_pc = text_phdr.p_vaddr + text_phdr.p_memsz; | 185 | const high_pc = text_shdr.sh_addr + text_shdr.sh_size; |
| 186 | try dw.writeDbgInfoHeader(elf_file.base.options.module.?, low_pc, high_pc); | 186 | try dw.writeDbgInfoHeader(elf_file.base.options.module.?, low_pc, high_pc); |
| 187 | self.debug_info_header_dirty = false; | 187 | self.debug_info_header_dirty = false; |
| 188 | } | 188 | } |
| 189 | | 189 | |
| 190 | if (self.debug_aranges_section_dirty) { | 190 | if (self.debug_aranges_section_dirty) { |
| 191 | const text_phdr = &elf_file.phdrs.items[elf_file.phdr_zig_load_re_index.?]; | 191 | const text_shdr = elf_file.shdrs.items[elf_file.zig_text_section_index.?]; |
| 192 | try dw.writeDbgAranges(text_phdr.p_vaddr, text_phdr.p_memsz); | 192 | try dw.writeDbgAranges(text_shdr.sh_addr, text_shdr.sh_size); |
| 193 | self.debug_aranges_section_dirty = false; | 193 | self.debug_aranges_section_dirty = false; |
| 194 | } | 194 | } |
| 195 | | 195 | |
| ... | @@ -731,9 +731,7 @@ fn updateDeclCode( | ... | @@ -731,9 +731,7 @@ fn updateDeclCode( |
| 731 | | 731 | |
| 732 | const shdr = elf_file.shdrs.items[shdr_index]; | 732 | const shdr = elf_file.shdrs.items[shdr_index]; |
| 733 | if (shdr.sh_type != elf.SHT_NOBITS) { | 733 | if (shdr.sh_type != elf.SHT_NOBITS) { |
| 734 | const phdr_index = elf_file.phdr_to_shdr_table.get(shdr_index).?; | 734 | const file_offset = shdr.sh_offset + sym.value - shdr.sh_addr; |
| 735 | const section_offset = sym.value - elf_file.phdrs.items[phdr_index].p_vaddr; | | |
| 736 | const file_offset = shdr.sh_offset + section_offset; | | |
| 737 | try elf_file.base.file.?.pwriteAll(code, file_offset); | 735 | try elf_file.base.file.?.pwriteAll(code, file_offset); |
| 738 | } | 736 | } |
| 739 | } | 737 | } |
| ... | @@ -940,7 +938,6 @@ fn updateLazySymbol( | ... | @@ -940,7 +938,6 @@ fn updateLazySymbol( |
| 940 | .const_data => elf_file.zig_data_rel_ro_section_index.?, | 938 | .const_data => elf_file.zig_data_rel_ro_section_index.?, |
| 941 | }; | 939 | }; |
| 942 | const local_sym = elf_file.symbol(symbol_index); | 940 | const local_sym = elf_file.symbol(symbol_index); |
| 943 | const phdr_index = elf_file.phdr_to_shdr_table.get(output_section_index).?; | | |
| 944 | local_sym.name_offset = name_str_index; | 941 | local_sym.name_offset = name_str_index; |
| 945 | local_sym.output_section_index = output_section_index; | 942 | local_sym.output_section_index = output_section_index; |
| 946 | const local_esym = &self.local_esyms.items(.elf_sym)[local_sym.esym_index]; | 943 | const local_esym = &self.local_esyms.items(.elf_sym)[local_sym.esym_index]; |
| ... | @@ -963,8 +960,8 @@ fn updateLazySymbol( | ... | @@ -963,8 +960,8 @@ fn updateLazySymbol( |
| 963 | const gop = try local_sym.getOrCreateZigGotEntry(symbol_index, elf_file); | 960 | const gop = try local_sym.getOrCreateZigGotEntry(symbol_index, elf_file); |
| 964 | try elf_file.zig_got.writeOne(elf_file, gop.index); | 961 | try elf_file.zig_got.writeOne(elf_file, gop.index); |
| 965 | | 962 | |
| 966 | const section_offset = atom_ptr.value - elf_file.phdrs.items[phdr_index].p_vaddr; | 963 | const shdr = elf_file.shdrs.items[output_section_index]; |
| 967 | const file_offset = elf_file.shdrs.items[output_section_index].sh_offset + section_offset; | 964 | const file_offset = shdr.sh_offset + atom_ptr.value - shdr.sh_addr; |
| 968 | try elf_file.base.file.?.pwriteAll(code, file_offset); | 965 | try elf_file.base.file.?.pwriteAll(code, file_offset); |
| 969 | } | 966 | } |
| 970 | | 967 | |
| ... | @@ -1038,7 +1035,6 @@ fn lowerConst( | ... | @@ -1038,7 +1035,6 @@ fn lowerConst( |
| 1038 | .fail => |em| return .{ .fail = em }, | 1035 | .fail => |em| return .{ .fail = em }, |
| 1039 | }; | 1036 | }; |
| 1040 | | 1037 | |
| 1041 | const phdr_index = elf_file.phdr_to_shdr_table.get(output_section_index).?; | | |
| 1042 | const local_sym = elf_file.symbol(sym_index); | 1038 | const local_sym = elf_file.symbol(sym_index); |
| 1043 | const name_str_index = try self.insertString(gpa, name); | 1039 | const name_str_index = try self.insertString(gpa, name); |
| 1044 | local_sym.name_offset = name_str_index; | 1040 | local_sym.name_offset = name_str_index; |
| ... | @@ -1061,8 +1057,8 @@ fn lowerConst( | ... | @@ -1061,8 +1057,8 @@ fn lowerConst( |
| 1061 | local_sym.value = atom_ptr.value; | 1057 | local_sym.value = atom_ptr.value; |
| 1062 | local_esym.st_value = atom_ptr.value; | 1058 | local_esym.st_value = atom_ptr.value; |
| 1063 | | 1059 | |
| 1064 | const section_offset = atom_ptr.value - elf_file.phdrs.items[phdr_index].p_vaddr; | 1060 | const shdr = elf_file.shdrs.items[output_section_index]; |
| 1065 | const file_offset = elf_file.shdrs.items[output_section_index].sh_offset + section_offset; | 1061 | const file_offset = shdr.sh_offset + atom_ptr.value - shdr.sh_addr; |
| 1066 | try elf_file.base.file.?.pwriteAll(code, file_offset); | 1062 | try elf_file.base.file.?.pwriteAll(code, file_offset); |
| 1067 | | 1063 | |
| 1068 | return .{ .ok = sym_index }; | 1064 | return .{ .ok = sym_index }; |