| ... | ... | @@ -3572,8 +3572,10 @@ fn updateSectionSizes(self: *Elf) !void { |
| 3572 | 3572 | if (self.requiresThunks() and shdr.sh_flags & elf.SHF_EXECINSTR != 0) continue; |
| 3573 | 3573 | if (self.zigObjectPtr()) |zo| blk: { |
| 3574 | 3574 | const sym_index = for ([_]?Symbol.Index{ |
| 3575 | | zo.data_index, |
| 3575 | zo.text_index, |
| 3576 | zo.rodata_index, |
| 3576 | 3577 | zo.data_relro_index, |
| 3578 | zo.data_index, |
| 3577 | 3579 | zo.bss_index, |
| 3578 | 3580 | }) |maybe_idx| { |
| 3579 | 3581 | if (maybe_idx) |idx| break idx; |
| ... | ... | @@ -3913,8 +3915,10 @@ pub fn allocateAllocSections(self: *Elf) !void { |
| 3913 | 3915 | |
| 3914 | 3916 | if (self.zigObjectPtr()) |zo| blk: { |
| 3915 | 3917 | const existing_size = for ([_]?Symbol.Index{ |
| 3916 | | zo.data_index, |
| 3918 | zo.text_index, |
| 3919 | zo.rodata_index, |
| 3917 | 3920 | zo.data_relro_index, |
| 3921 | zo.data_index, |
| 3918 | 3922 | zo.eh_frame_index, |
| 3919 | 3923 | }) |maybe_sym_index| { |
| 3920 | 3924 | const sect_sym_index = maybe_sym_index orelse continue; |
| ... | ... | @@ -3954,27 +3958,27 @@ pub fn allocateNonAllocSections(self: *Elf) !void { |
| 3954 | 3958 | shdr.sh_size = 0; |
| 3955 | 3959 | const new_offset = try self.findFreeSpace(needed_size, shdr.sh_addralign); |
| 3956 | 3960 | |
| 3957 | | if (self.isDebugSection(@intCast(shndx))) { |
| 3961 | if (self.zigObjectPtr()) |zo| blk: { |
| 3962 | const existing_size = for ([_]?Symbol.Index{ |
| 3963 | zo.debug_info_index, |
| 3964 | zo.debug_abbrev_index, |
| 3965 | zo.debug_aranges_index, |
| 3966 | zo.debug_str_index, |
| 3967 | zo.debug_line_index, |
| 3968 | zo.debug_line_str_index, |
| 3969 | zo.debug_loclists_index, |
| 3970 | zo.debug_rnglists_index, |
| 3971 | }) |maybe_sym_index| { |
| 3972 | const sym_index = maybe_sym_index orelse continue; |
| 3973 | const sym = zo.symbol(sym_index); |
| 3974 | const atom_ptr = sym.atom(self).?; |
| 3975 | if (atom_ptr.output_section_index == shndx) break atom_ptr.size; |
| 3976 | } else break :blk; |
| 3958 | 3977 | log.debug("moving {s} from 0x{x} to 0x{x}", .{ |
| 3959 | 3978 | self.getShString(shdr.sh_name), |
| 3960 | 3979 | shdr.sh_offset, |
| 3961 | 3980 | new_offset, |
| 3962 | 3981 | }); |
| 3963 | | const zo = self.zigObjectPtr().?; |
| 3964 | | const existing_size = for ([_]Symbol.Index{ |
| 3965 | | zo.debug_info_index.?, |
| 3966 | | zo.debug_abbrev_index.?, |
| 3967 | | zo.debug_aranges_index.?, |
| 3968 | | zo.debug_str_index.?, |
| 3969 | | zo.debug_line_index.?, |
| 3970 | | zo.debug_line_str_index.?, |
| 3971 | | zo.debug_loclists_index.?, |
| 3972 | | zo.debug_rnglists_index.?, |
| 3973 | | }) |sym_index| { |
| 3974 | | const sym = zo.symbol(sym_index); |
| 3975 | | const atom_ptr = sym.atom(self).?; |
| 3976 | | if (atom_ptr.output_section_index == shndx) break atom_ptr.size; |
| 3977 | | } else 0; |
| 3978 | 3982 | const amt = try self.base.file.?.copyRangeAll( |
| 3979 | 3983 | shdr.sh_offset, |
| 3980 | 3984 | self.base.file.?, |
| ... | ... | @@ -4068,35 +4072,28 @@ fn writeAtoms(self: *Elf) !void { |
| 4068 | 4072 | log.debug("writing atoms in '{s}' section", .{self.getShString(shdr.sh_name)}); |
| 4069 | 4073 | |
| 4070 | 4074 | // TODO really, really handle debug section separately |
| 4071 | | const base_offset = if (self.isDebugSection(@intCast(shndx))) base_offset: { |
| 4072 | | const zo = self.zigObjectPtr().?; |
| 4073 | | for ([_]Symbol.Index{ |
| 4074 | | zo.debug_info_index.?, |
| 4075 | | zo.debug_abbrev_index.?, |
| 4076 | | zo.debug_aranges_index.?, |
| 4077 | | zo.debug_str_index.?, |
| 4078 | | zo.debug_line_index.?, |
| 4079 | | zo.debug_line_str_index.?, |
| 4080 | | zo.debug_loclists_index.?, |
| 4081 | | zo.debug_rnglists_index.?, |
| 4082 | | }) |sym_index| { |
| 4075 | const base_offset = if (self.zigObjectPtr()) |zo| base_offset: { |
| 4076 | for ([_]?Symbol.Index{ |
| 4077 | zo.text_index, |
| 4078 | zo.rodata_index, |
| 4079 | zo.data_relro_index, |
| 4080 | zo.data_index, |
| 4081 | zo.eh_frame_index, |
| 4082 | zo.debug_info_index, |
| 4083 | zo.debug_abbrev_index, |
| 4084 | zo.debug_aranges_index, |
| 4085 | zo.debug_str_index, |
| 4086 | zo.debug_line_index, |
| 4087 | zo.debug_line_str_index, |
| 4088 | zo.debug_loclists_index, |
| 4089 | zo.debug_rnglists_index, |
| 4090 | }) |maybe_sym_index| { |
| 4091 | const sym_index = maybe_sym_index orelse continue; |
| 4083 | 4092 | const sym = zo.symbol(sym_index); |
| 4084 | 4093 | const atom_ptr = sym.atom(self).?; |
| 4085 | 4094 | if (atom_ptr.output_section_index == shndx) break :base_offset atom_ptr.size; |
| 4086 | 4095 | } |
| 4087 | 4096 | break :base_offset 0; |
| 4088 | | } else if (self.zigObjectPtr()) |zo| base_offset: { |
| 4089 | | const sym_index = for ([_]?Symbol.Index{ |
| 4090 | | zo.data_index, |
| 4091 | | zo.data_relro_index, |
| 4092 | | zo.eh_frame_index, |
| 4093 | | }) |maybe_idx| { |
| 4094 | | if (maybe_idx) |idx| break idx; |
| 4095 | | } else break :base_offset 0; |
| 4096 | | const sym = zo.symbol(sym_index); |
| 4097 | | const atom_ptr = sym.atom(self).?; |
| 4098 | | if (atom_ptr.output_section_index == @as(u32, @intCast(shndx))) break :base_offset atom_ptr.size; |
| 4099 | | break :base_offset 0; |
| 4100 | 4097 | } else 0; |
| 4101 | 4098 | const sh_offset = shdr.sh_offset + base_offset; |
| 4102 | 4099 | const sh_size = math.cast(usize, shdr.sh_size - base_offset) orelse return error.Overflow; |
| ... | ... | @@ -4799,22 +4796,6 @@ pub fn isEffectivelyDynLib(self: Elf) bool { |
| 4799 | 4796 | }; |
| 4800 | 4797 | } |
| 4801 | 4798 | |
| 4802 | | pub fn isDebugSection(self: Elf, shndx: u32) bool { |
| 4803 | | inline for (&[_]?u32{ |
| 4804 | | self.debug_info_section_index, |
| 4805 | | self.debug_abbrev_section_index, |
| 4806 | | self.debug_str_section_index, |
| 4807 | | self.debug_aranges_section_index, |
| 4808 | | self.debug_line_section_index, |
| 4809 | | self.debug_line_str_section_index, |
| 4810 | | self.debug_loclists_section_index, |
| 4811 | | self.debug_rnglists_section_index, |
| 4812 | | }) |index| { |
| 4813 | | if (index == shndx) return true; |
| 4814 | | } |
| 4815 | | return false; |
| 4816 | | } |
| 4817 | | |
| 4818 | 4799 | pub fn addPhdr(self: *Elf, opts: struct { |
| 4819 | 4800 | type: u32 = 0, |
| 4820 | 4801 | flags: u32 = 0, |