authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-09-24 10:56:48+02:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2024-09-25 17:54:50+02:00
logdb3db1150e48cf506593489dff93adda9e1111fe
treed528b81913591daf74bd7630982afe67d665a5f6
parent62c282ba4699bd00d0cb74b3253bac7a925eae68

elf: do not re-create special program headers if already created


1 files changed, 12 insertions(+), 10 deletions(-)

src/link/Elf.zig+12-10
......@@ -3159,36 +3159,38 @@ pub fn initShStrtab(self: *Elf) !void {
31593159fn initSpecialPhdrs(self: *Elf) !void {
31603160 comptime assert(max_number_of_special_phdrs == 5);
31613161
3162 if (self.interp_section_index != null) {
3162 if (self.interp_section_index != null and self.phdr_interp_index == null) {
31633163 self.phdr_interp_index = try self.addPhdr(.{
31643164 .type = elf.PT_INTERP,
31653165 .flags = elf.PF_R,
31663166 .@"align" = 1,
31673167 });
31683168 }
3169 if (self.dynamic_section_index != null) {
3169 if (self.dynamic_section_index != null and self.phdr_dynamic_index == null) {
31703170 self.phdr_dynamic_index = try self.addPhdr(.{
31713171 .type = elf.PT_DYNAMIC,
31723172 .flags = elf.PF_R | elf.PF_W,
31733173 });
31743174 }
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) {
31763176 self.phdr_gnu_eh_frame_index = try self.addPhdr(.{
31773177 .type = elf.PT_GNU_EH_FRAME,
31783178 .flags = elf.PF_R,
31793179 });
31803180 }
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 }
31873189
31883190 const has_tls = for (self.sections.items(.shdr)) |shdr| {
31893191 if (shdr.sh_flags & elf.SHF_TLS != 0) break true;
31903192 } else false;
3191 if (has_tls) {
3193 if (has_tls and self.phdr_tls_index == null) {
31923194 self.phdr_tls_index = try self.addPhdr(.{
31933195 .type = elf.PT_TLS,
31943196 .flags = elf.PF_R,