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