| ... | ... | @@ -3159,36 +3159,38 @@ pub fn initShStrtab(self: *Elf) !void { |
| 3159 | 3159 | fn initSpecialPhdrs(self: *Elf) !void { |
| 3160 | 3160 | comptime assert(max_number_of_special_phdrs == 5); |
| 3161 | 3161 | |
| 3162 | | if (self.interp_section_index != null) { |
| 3162 | if (self.interp_section_index != null and self.phdr_interp_index == null) { |
| 3163 | 3163 | self.phdr_interp_index = try self.addPhdr(.{ |
| 3164 | 3164 | .type = elf.PT_INTERP, |
| 3165 | 3165 | .flags = elf.PF_R, |
| 3166 | 3166 | .@"align" = 1, |
| 3167 | 3167 | }); |
| 3168 | 3168 | } |
| 3169 | | if (self.dynamic_section_index != null) { |
| 3169 | if (self.dynamic_section_index != null and self.phdr_dynamic_index == null) { |
| 3170 | 3170 | self.phdr_dynamic_index = try self.addPhdr(.{ |
| 3171 | 3171 | .type = elf.PT_DYNAMIC, |
| 3172 | 3172 | .flags = elf.PF_R | elf.PF_W, |
| 3173 | 3173 | }); |
| 3174 | 3174 | } |
| 3175 | | if (self.eh_frame_hdr_section_index != null) { |
| 3175 | if (self.eh_frame_hdr_section_index != null and self.phdr_gnu_eh_frame_index == null) { |
| 3176 | 3176 | self.phdr_gnu_eh_frame_index = try self.addPhdr(.{ |
| 3177 | 3177 | .type = elf.PT_GNU_EH_FRAME, |
| 3178 | 3178 | .flags = elf.PF_R, |
| 3179 | 3179 | }); |
| 3180 | 3180 | } |
| 3181 | | self.phdr_gnu_stack_index = try self.addPhdr(.{ |
| 3182 | | .type = elf.PT_GNU_STACK, |
| 3183 | | .flags = elf.PF_W | elf.PF_R, |
| 3184 | | .memsz = self.base.stack_size, |
| 3185 | | .@"align" = 1, |
| 3186 | | }); |
| 3181 | if (self.phdr_gnu_stack_index == null) { |
| 3182 | self.phdr_gnu_stack_index = try self.addPhdr(.{ |
| 3183 | .type = elf.PT_GNU_STACK, |
| 3184 | .flags = elf.PF_W | elf.PF_R, |
| 3185 | .memsz = self.base.stack_size, |
| 3186 | .@"align" = 1, |
| 3187 | }); |
| 3188 | } |
| 3187 | 3189 | |
| 3188 | 3190 | const has_tls = for (self.sections.items(.shdr)) |shdr| { |
| 3189 | 3191 | if (shdr.sh_flags & elf.SHF_TLS != 0) break true; |
| 3190 | 3192 | } else false; |
| 3191 | | if (has_tls) { |
| 3193 | if (has_tls and self.phdr_tls_index == null) { |
| 3192 | 3194 | self.phdr_tls_index = try self.addPhdr(.{ |
| 3193 | 3195 | .type = elf.PT_TLS, |
| 3194 | 3196 | .flags = elf.PF_R, |