| ... | @@ -371,7 +371,7 @@ pub fn createEmpty( | ... | @@ -371,7 +371,7 @@ pub fn createEmpty( |
| 371 | try self.shstrtab.append(gpa, 0); | 371 | try self.shstrtab.append(gpa, 0); |
| 372 | try self.strtab.append(gpa, 0); | 372 | try self.strtab.append(gpa, 0); |
| 373 | // There must always be a null shdr in index 0 | 373 | // There must always be a null shdr in index 0 |
| 374 | _ = try self.addSection(.{ .name = "" }); | 374 | _ = try self.addSection(.{}); |
| 375 | // Append null symbol in output symtab | 375 | // Append null symbol in output symtab |
| 376 | try self.symtab.append(gpa, null_sym); | 376 | try self.symtab.append(gpa, null_sym); |
| 377 | | 377 | |
| ... | @@ -716,7 +716,7 @@ pub fn initMetadata(self: *Elf, options: InitMetadataOptions) !void { | ... | @@ -716,7 +716,7 @@ pub fn initMetadata(self: *Elf, options: InitMetadataOptions) !void { |
| 716 | | 716 | |
| 717 | if (self.zig_text_section_index == null) { | 717 | if (self.zig_text_section_index == null) { |
| 718 | self.zig_text_section_index = try self.addSection(.{ | 718 | self.zig_text_section_index = try self.addSection(.{ |
| 719 | .name = ".text.zig", | 719 | .name = try self.insertShString(".text.zig"), |
| 720 | .type = elf.SHT_PROGBITS, | 720 | .type = elf.SHT_PROGBITS, |
| 721 | .flags = elf.SHF_ALLOC | elf.SHF_EXECINSTR, | 721 | .flags = elf.SHF_ALLOC | elf.SHF_EXECINSTR, |
| 722 | .addralign = 1, | 722 | .addralign = 1, |
| ... | @@ -725,7 +725,7 @@ pub fn initMetadata(self: *Elf, options: InitMetadataOptions) !void { | ... | @@ -725,7 +725,7 @@ pub fn initMetadata(self: *Elf, options: InitMetadataOptions) !void { |
| 725 | const shdr = &self.shdrs.items[self.zig_text_section_index.?]; | 725 | const shdr = &self.shdrs.items[self.zig_text_section_index.?]; |
| 726 | fillSection(self, shdr, options.program_code_size_hint, self.phdr_zig_load_re_index); | 726 | fillSection(self, shdr, options.program_code_size_hint, self.phdr_zig_load_re_index); |
| 727 | if (self.base.isRelocatable()) { | 727 | if (self.base.isRelocatable()) { |
| 728 | const rela_shndx = try self.addRelaShdr(".rela.text.zig", self.zig_text_section_index.?); | 728 | const rela_shndx = try self.addRelaShdr(try self.insertShString(".rela.text.zig"), self.zig_text_section_index.?); |
| 729 | try self.output_rela_sections.putNoClobber(gpa, self.zig_text_section_index.?, .{ | 729 | try self.output_rela_sections.putNoClobber(gpa, self.zig_text_section_index.?, .{ |
| 730 | .shndx = rela_shndx, | 730 | .shndx = rela_shndx, |
| 731 | }); | 731 | }); |
| ... | @@ -742,7 +742,7 @@ pub fn initMetadata(self: *Elf, options: InitMetadataOptions) !void { | ... | @@ -742,7 +742,7 @@ pub fn initMetadata(self: *Elf, options: InitMetadataOptions) !void { |
| 742 | | 742 | |
| 743 | if (self.zig_got_section_index == null and !self.base.isRelocatable()) { | 743 | if (self.zig_got_section_index == null and !self.base.isRelocatable()) { |
| 744 | self.zig_got_section_index = try self.addSection(.{ | 744 | self.zig_got_section_index = try self.addSection(.{ |
| 745 | .name = ".got.zig", | 745 | .name = try self.insertShString(".got.zig"), |
| 746 | .type = elf.SHT_PROGBITS, | 746 | .type = elf.SHT_PROGBITS, |
| 747 | .addralign = ptr_size, | 747 | .addralign = ptr_size, |
| 748 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, | 748 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, |
| ... | @@ -763,7 +763,7 @@ pub fn initMetadata(self: *Elf, options: InitMetadataOptions) !void { | ... | @@ -763,7 +763,7 @@ pub fn initMetadata(self: *Elf, options: InitMetadataOptions) !void { |
| 763 | | 763 | |
| 764 | if (self.zig_data_rel_ro_section_index == null) { | 764 | if (self.zig_data_rel_ro_section_index == null) { |
| 765 | self.zig_data_rel_ro_section_index = try self.addSection(.{ | 765 | self.zig_data_rel_ro_section_index = try self.addSection(.{ |
| 766 | .name = ".data.rel.ro.zig", | 766 | .name = try self.insertShString(".data.rel.ro.zig"), |
| 767 | .type = elf.SHT_PROGBITS, | 767 | .type = elf.SHT_PROGBITS, |
| 768 | .addralign = 1, | 768 | .addralign = 1, |
| 769 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, | 769 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, |
| ... | @@ -773,7 +773,7 @@ pub fn initMetadata(self: *Elf, options: InitMetadataOptions) !void { | ... | @@ -773,7 +773,7 @@ pub fn initMetadata(self: *Elf, options: InitMetadataOptions) !void { |
| 773 | fillSection(self, shdr, 1024, self.phdr_zig_load_ro_index); | 773 | fillSection(self, shdr, 1024, self.phdr_zig_load_ro_index); |
| 774 | if (self.base.isRelocatable()) { | 774 | if (self.base.isRelocatable()) { |
| 775 | const rela_shndx = try self.addRelaShdr( | 775 | const rela_shndx = try self.addRelaShdr( |
| 776 | ".rela.data.rel.ro.zig", | 776 | try self.insertShString(".rela.data.rel.ro.zig"), |
| 777 | self.zig_data_rel_ro_section_index.?, | 777 | self.zig_data_rel_ro_section_index.?, |
| 778 | ); | 778 | ); |
| 779 | try self.output_rela_sections.putNoClobber(gpa, self.zig_data_rel_ro_section_index.?, .{ | 779 | try self.output_rela_sections.putNoClobber(gpa, self.zig_data_rel_ro_section_index.?, .{ |
| ... | @@ -792,7 +792,7 @@ pub fn initMetadata(self: *Elf, options: InitMetadataOptions) !void { | ... | @@ -792,7 +792,7 @@ pub fn initMetadata(self: *Elf, options: InitMetadataOptions) !void { |
| 792 | | 792 | |
| 793 | if (self.zig_data_section_index == null) { | 793 | if (self.zig_data_section_index == null) { |
| 794 | self.zig_data_section_index = try self.addSection(.{ | 794 | self.zig_data_section_index = try self.addSection(.{ |
| 795 | .name = ".data.zig", | 795 | .name = try self.insertShString(".data.zig"), |
| 796 | .type = elf.SHT_PROGBITS, | 796 | .type = elf.SHT_PROGBITS, |
| 797 | .addralign = ptr_size, | 797 | .addralign = ptr_size, |
| 798 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, | 798 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, |
| ... | @@ -802,7 +802,7 @@ pub fn initMetadata(self: *Elf, options: InitMetadataOptions) !void { | ... | @@ -802,7 +802,7 @@ pub fn initMetadata(self: *Elf, options: InitMetadataOptions) !void { |
| 802 | fillSection(self, shdr, 1024, self.phdr_zig_load_rw_index); | 802 | fillSection(self, shdr, 1024, self.phdr_zig_load_rw_index); |
| 803 | if (self.base.isRelocatable()) { | 803 | if (self.base.isRelocatable()) { |
| 804 | const rela_shndx = try self.addRelaShdr( | 804 | const rela_shndx = try self.addRelaShdr( |
| 805 | ".rela.data.zig", | 805 | try self.insertShString(".rela.data.zig"), |
| 806 | self.zig_data_section_index.?, | 806 | self.zig_data_section_index.?, |
| 807 | ); | 807 | ); |
| 808 | try self.output_rela_sections.putNoClobber(gpa, self.zig_data_section_index.?, .{ | 808 | try self.output_rela_sections.putNoClobber(gpa, self.zig_data_section_index.?, .{ |
| ... | @@ -821,7 +821,7 @@ pub fn initMetadata(self: *Elf, options: InitMetadataOptions) !void { | ... | @@ -821,7 +821,7 @@ pub fn initMetadata(self: *Elf, options: InitMetadataOptions) !void { |
| 821 | | 821 | |
| 822 | if (self.zig_bss_section_index == null) { | 822 | if (self.zig_bss_section_index == null) { |
| 823 | self.zig_bss_section_index = try self.addSection(.{ | 823 | self.zig_bss_section_index = try self.addSection(.{ |
| 824 | .name = ".bss.zig", | 824 | .name = try self.insertShString(".bss.zig"), |
| 825 | .type = elf.SHT_NOBITS, | 825 | .type = elf.SHT_NOBITS, |
| 826 | .addralign = ptr_size, | 826 | .addralign = ptr_size, |
| 827 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, | 827 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, |
| ... | @@ -845,7 +845,7 @@ pub fn initMetadata(self: *Elf, options: InitMetadataOptions) !void { | ... | @@ -845,7 +845,7 @@ pub fn initMetadata(self: *Elf, options: InitMetadataOptions) !void { |
| 845 | assert(dw.strtab.buffer.items.len == 0); | 845 | assert(dw.strtab.buffer.items.len == 0); |
| 846 | try dw.strtab.buffer.append(gpa, 0); | 846 | try dw.strtab.buffer.append(gpa, 0); |
| 847 | self.debug_str_section_index = try self.addSection(.{ | 847 | self.debug_str_section_index = try self.addSection(.{ |
| 848 | .name = ".debug_str", | 848 | .name = try self.insertShString(".debug_str"), |
| 849 | .flags = elf.SHF_MERGE | elf.SHF_STRINGS, | 849 | .flags = elf.SHF_MERGE | elf.SHF_STRINGS, |
| 850 | .entsize = 1, | 850 | .entsize = 1, |
| 851 | .type = elf.SHT_PROGBITS, | 851 | .type = elf.SHT_PROGBITS, |
| ... | @@ -863,7 +863,7 @@ pub fn initMetadata(self: *Elf, options: InitMetadataOptions) !void { | ... | @@ -863,7 +863,7 @@ pub fn initMetadata(self: *Elf, options: InitMetadataOptions) !void { |
| 863 | | 863 | |
| 864 | if (self.debug_info_section_index == null) { | 864 | if (self.debug_info_section_index == null) { |
| 865 | self.debug_info_section_index = try self.addSection(.{ | 865 | self.debug_info_section_index = try self.addSection(.{ |
| 866 | .name = ".debug_info", | 866 | .name = try self.insertShString(".debug_info"), |
| 867 | .type = elf.SHT_PROGBITS, | 867 | .type = elf.SHT_PROGBITS, |
| 868 | .addralign = 1, | 868 | .addralign = 1, |
| 869 | .offset = std.math.maxInt(u64), | 869 | .offset = std.math.maxInt(u64), |
| ... | @@ -879,7 +879,7 @@ pub fn initMetadata(self: *Elf, options: InitMetadataOptions) !void { | ... | @@ -879,7 +879,7 @@ pub fn initMetadata(self: *Elf, options: InitMetadataOptions) !void { |
| 879 | | 879 | |
| 880 | if (self.debug_abbrev_section_index == null) { | 880 | if (self.debug_abbrev_section_index == null) { |
| 881 | self.debug_abbrev_section_index = try self.addSection(.{ | 881 | self.debug_abbrev_section_index = try self.addSection(.{ |
| 882 | .name = ".debug_abbrev", | 882 | .name = try self.insertShString(".debug_abbrev"), |
| 883 | .type = elf.SHT_PROGBITS, | 883 | .type = elf.SHT_PROGBITS, |
| 884 | .addralign = 1, | 884 | .addralign = 1, |
| 885 | .offset = std.math.maxInt(u64), | 885 | .offset = std.math.maxInt(u64), |
| ... | @@ -895,7 +895,7 @@ pub fn initMetadata(self: *Elf, options: InitMetadataOptions) !void { | ... | @@ -895,7 +895,7 @@ pub fn initMetadata(self: *Elf, options: InitMetadataOptions) !void { |
| 895 | | 895 | |
| 896 | if (self.debug_aranges_section_index == null) { | 896 | if (self.debug_aranges_section_index == null) { |
| 897 | self.debug_aranges_section_index = try self.addSection(.{ | 897 | self.debug_aranges_section_index = try self.addSection(.{ |
| 898 | .name = ".debug_aranges", | 898 | .name = try self.insertShString(".debug_aranges"), |
| 899 | .type = elf.SHT_PROGBITS, | 899 | .type = elf.SHT_PROGBITS, |
| 900 | .addralign = 16, | 900 | .addralign = 16, |
| 901 | .offset = std.math.maxInt(u64), | 901 | .offset = std.math.maxInt(u64), |
| ... | @@ -911,7 +911,7 @@ pub fn initMetadata(self: *Elf, options: InitMetadataOptions) !void { | ... | @@ -911,7 +911,7 @@ pub fn initMetadata(self: *Elf, options: InitMetadataOptions) !void { |
| 911 | | 911 | |
| 912 | if (self.debug_line_section_index == null) { | 912 | if (self.debug_line_section_index == null) { |
| 913 | self.debug_line_section_index = try self.addSection(.{ | 913 | self.debug_line_section_index = try self.addSection(.{ |
| 914 | .name = ".debug_line", | 914 | .name = try self.insertShString(".debug_line"), |
| 915 | .type = elf.SHT_PROGBITS, | 915 | .type = elf.SHT_PROGBITS, |
| 916 | .addralign = 1, | 916 | .addralign = 1, |
| 917 | .offset = std.math.maxInt(u64), | 917 | .offset = std.math.maxInt(u64), |
| ... | @@ -3390,7 +3390,7 @@ pub fn initMergeSections(self: *Elf) !void { | ... | @@ -3390,7 +3390,7 @@ pub fn initMergeSections(self: *Elf) !void { |
| 3390 | if (msec.finalized_subsections.items.len == 0) continue; | 3390 | if (msec.finalized_subsections.items.len == 0) continue; |
| 3391 | const name = msec.name(self); | 3391 | const name = msec.name(self); |
| 3392 | const shndx = self.sectionByName(name) orelse try self.addSection(.{ | 3392 | const shndx = self.sectionByName(name) orelse try self.addSection(.{ |
| 3393 | .name = name, | 3393 | .name = msec.name_offset, |
| 3394 | .type = msec.type, | 3394 | .type = msec.type, |
| 3395 | .flags = msec.flags, | 3395 | .flags = msec.flags, |
| 3396 | }); | 3396 | }); |
| ... | @@ -3416,7 +3416,7 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -3416,7 +3416,7 @@ fn initSyntheticSections(self: *Elf) !void { |
| 3416 | } else false; | 3416 | } else false; |
| 3417 | if (needs_eh_frame) { | 3417 | if (needs_eh_frame) { |
| 3418 | self.eh_frame_section_index = try self.addSection(.{ | 3418 | self.eh_frame_section_index = try self.addSection(.{ |
| 3419 | .name = ".eh_frame", | 3419 | .name = try self.insertShString(".eh_frame"), |
| 3420 | .type = elf.SHT_PROGBITS, | 3420 | .type = elf.SHT_PROGBITS, |
| 3421 | .flags = elf.SHF_ALLOC, | 3421 | .flags = elf.SHF_ALLOC, |
| 3422 | .addralign = ptr_size, | 3422 | .addralign = ptr_size, |
| ... | @@ -3425,7 +3425,7 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -3425,7 +3425,7 @@ fn initSyntheticSections(self: *Elf) !void { |
| 3425 | | 3425 | |
| 3426 | if (comp.link_eh_frame_hdr) { | 3426 | if (comp.link_eh_frame_hdr) { |
| 3427 | self.eh_frame_hdr_section_index = try self.addSection(.{ | 3427 | self.eh_frame_hdr_section_index = try self.addSection(.{ |
| 3428 | .name = ".eh_frame_hdr", | 3428 | .name = try self.insertShString(".eh_frame_hdr"), |
| 3429 | .type = elf.SHT_PROGBITS, | 3429 | .type = elf.SHT_PROGBITS, |
| 3430 | .flags = elf.SHF_ALLOC, | 3430 | .flags = elf.SHF_ALLOC, |
| 3431 | .addralign = 4, | 3431 | .addralign = 4, |
| ... | @@ -3436,7 +3436,7 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -3436,7 +3436,7 @@ fn initSyntheticSections(self: *Elf) !void { |
| 3436 | | 3436 | |
| 3437 | if (self.got.entries.items.len > 0) { | 3437 | if (self.got.entries.items.len > 0) { |
| 3438 | self.got_section_index = try self.addSection(.{ | 3438 | self.got_section_index = try self.addSection(.{ |
| 3439 | .name = ".got", | 3439 | .name = try self.insertShString(".got"), |
| 3440 | .type = elf.SHT_PROGBITS, | 3440 | .type = elf.SHT_PROGBITS, |
| 3441 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, | 3441 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, |
| 3442 | .addralign = ptr_size, | 3442 | .addralign = ptr_size, |
| ... | @@ -3445,7 +3445,7 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -3445,7 +3445,7 @@ fn initSyntheticSections(self: *Elf) !void { |
| 3445 | } | 3445 | } |
| 3446 | | 3446 | |
| 3447 | self.got_plt_section_index = try self.addSection(.{ | 3447 | self.got_plt_section_index = try self.addSection(.{ |
| 3448 | .name = ".got.plt", | 3448 | .name = try self.insertShString(".got.plt"), |
| 3449 | .type = elf.SHT_PROGBITS, | 3449 | .type = elf.SHT_PROGBITS, |
| 3450 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, | 3450 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, |
| 3451 | .addralign = @alignOf(u64), | 3451 | .addralign = @alignOf(u64), |
| ... | @@ -3465,7 +3465,7 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -3465,7 +3465,7 @@ fn initSyntheticSections(self: *Elf) !void { |
| 3465 | }; | 3465 | }; |
| 3466 | if (needs_rela_dyn) { | 3466 | if (needs_rela_dyn) { |
| 3467 | self.rela_dyn_section_index = try self.addSection(.{ | 3467 | self.rela_dyn_section_index = try self.addSection(.{ |
| 3468 | .name = ".rela.dyn", | 3468 | .name = try self.insertShString(".rela.dyn"), |
| 3469 | .type = elf.SHT_RELA, | 3469 | .type = elf.SHT_RELA, |
| 3470 | .flags = elf.SHF_ALLOC, | 3470 | .flags = elf.SHF_ALLOC, |
| 3471 | .addralign = @alignOf(elf.Elf64_Rela), | 3471 | .addralign = @alignOf(elf.Elf64_Rela), |
| ... | @@ -3476,14 +3476,14 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -3476,14 +3476,14 @@ fn initSyntheticSections(self: *Elf) !void { |
| 3476 | | 3476 | |
| 3477 | if (self.plt.symbols.items.len > 0) { | 3477 | if (self.plt.symbols.items.len > 0) { |
| 3478 | self.plt_section_index = try self.addSection(.{ | 3478 | self.plt_section_index = try self.addSection(.{ |
| 3479 | .name = ".plt", | 3479 | .name = try self.insertShString(".plt"), |
| 3480 | .type = elf.SHT_PROGBITS, | 3480 | .type = elf.SHT_PROGBITS, |
| 3481 | .flags = elf.SHF_ALLOC | elf.SHF_EXECINSTR, | 3481 | .flags = elf.SHF_ALLOC | elf.SHF_EXECINSTR, |
| 3482 | .addralign = 16, | 3482 | .addralign = 16, |
| 3483 | .offset = std.math.maxInt(u64), | 3483 | .offset = std.math.maxInt(u64), |
| 3484 | }); | 3484 | }); |
| 3485 | self.rela_plt_section_index = try self.addSection(.{ | 3485 | self.rela_plt_section_index = try self.addSection(.{ |
| 3486 | .name = ".rela.plt", | 3486 | .name = try self.insertShString(".rela.plt"), |
| 3487 | .type = elf.SHT_RELA, | 3487 | .type = elf.SHT_RELA, |
| 3488 | .flags = elf.SHF_ALLOC, | 3488 | .flags = elf.SHF_ALLOC, |
| 3489 | .addralign = @alignOf(elf.Elf64_Rela), | 3489 | .addralign = @alignOf(elf.Elf64_Rela), |
| ... | @@ -3494,7 +3494,7 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -3494,7 +3494,7 @@ fn initSyntheticSections(self: *Elf) !void { |
| 3494 | | 3494 | |
| 3495 | if (self.plt_got.symbols.items.len > 0) { | 3495 | if (self.plt_got.symbols.items.len > 0) { |
| 3496 | self.plt_got_section_index = try self.addSection(.{ | 3496 | self.plt_got_section_index = try self.addSection(.{ |
| 3497 | .name = ".plt.got", | 3497 | .name = try self.insertShString(".plt.got"), |
| 3498 | .type = elf.SHT_PROGBITS, | 3498 | .type = elf.SHT_PROGBITS, |
| 3499 | .flags = elf.SHF_ALLOC | elf.SHF_EXECINSTR, | 3499 | .flags = elf.SHF_ALLOC | elf.SHF_EXECINSTR, |
| 3500 | .addralign = 16, | 3500 | .addralign = 16, |
| ... | @@ -3504,7 +3504,7 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -3504,7 +3504,7 @@ fn initSyntheticSections(self: *Elf) !void { |
| 3504 | | 3504 | |
| 3505 | if (self.copy_rel.symbols.items.len > 0) { | 3505 | if (self.copy_rel.symbols.items.len > 0) { |
| 3506 | self.copy_rel_section_index = try self.addSection(.{ | 3506 | self.copy_rel_section_index = try self.addSection(.{ |
| 3507 | .name = ".copyrel", | 3507 | .name = try self.insertShString(".copyrel"), |
| 3508 | .type = elf.SHT_NOBITS, | 3508 | .type = elf.SHT_NOBITS, |
| 3509 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, | 3509 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, |
| 3510 | .offset = std.math.maxInt(u64), | 3510 | .offset = std.math.maxInt(u64), |
| ... | @@ -3522,7 +3522,7 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -3522,7 +3522,7 @@ fn initSyntheticSections(self: *Elf) !void { |
| 3522 | }; | 3522 | }; |
| 3523 | if (needs_interp) { | 3523 | if (needs_interp) { |
| 3524 | self.interp_section_index = try self.addSection(.{ | 3524 | self.interp_section_index = try self.addSection(.{ |
| 3525 | .name = ".interp", | 3525 | .name = try self.insertShString(".interp"), |
| 3526 | .type = elf.SHT_PROGBITS, | 3526 | .type = elf.SHT_PROGBITS, |
| 3527 | .flags = elf.SHF_ALLOC, | 3527 | .flags = elf.SHF_ALLOC, |
| 3528 | .addralign = 1, | 3528 | .addralign = 1, |
| ... | @@ -3532,7 +3532,7 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -3532,7 +3532,7 @@ fn initSyntheticSections(self: *Elf) !void { |
| 3532 | | 3532 | |
| 3533 | if (self.isEffectivelyDynLib() or self.shared_objects.items.len > 0 or comp.config.pie) { | 3533 | if (self.isEffectivelyDynLib() or self.shared_objects.items.len > 0 or comp.config.pie) { |
| 3534 | self.dynstrtab_section_index = try self.addSection(.{ | 3534 | self.dynstrtab_section_index = try self.addSection(.{ |
| 3535 | .name = ".dynstr", | 3535 | .name = try self.insertShString(".dynstr"), |
| 3536 | .flags = elf.SHF_ALLOC, | 3536 | .flags = elf.SHF_ALLOC, |
| 3537 | .type = elf.SHT_STRTAB, | 3537 | .type = elf.SHT_STRTAB, |
| 3538 | .entsize = 1, | 3538 | .entsize = 1, |
| ... | @@ -3540,7 +3540,7 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -3540,7 +3540,7 @@ fn initSyntheticSections(self: *Elf) !void { |
| 3540 | .offset = std.math.maxInt(u64), | 3540 | .offset = std.math.maxInt(u64), |
| 3541 | }); | 3541 | }); |
| 3542 | self.dynamic_section_index = try self.addSection(.{ | 3542 | self.dynamic_section_index = try self.addSection(.{ |
| 3543 | .name = ".dynamic", | 3543 | .name = try self.insertShString(".dynamic"), |
| 3544 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, | 3544 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, |
| 3545 | .type = elf.SHT_DYNAMIC, | 3545 | .type = elf.SHT_DYNAMIC, |
| 3546 | .entsize = @sizeOf(elf.Elf64_Dyn), | 3546 | .entsize = @sizeOf(elf.Elf64_Dyn), |
| ... | @@ -3548,7 +3548,7 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -3548,7 +3548,7 @@ fn initSyntheticSections(self: *Elf) !void { |
| 3548 | .offset = std.math.maxInt(u64), | 3548 | .offset = std.math.maxInt(u64), |
| 3549 | }); | 3549 | }); |
| 3550 | self.dynsymtab_section_index = try self.addSection(.{ | 3550 | self.dynsymtab_section_index = try self.addSection(.{ |
| 3551 | .name = ".dynsym", | 3551 | .name = try self.insertShString(".dynsym"), |
| 3552 | .flags = elf.SHF_ALLOC, | 3552 | .flags = elf.SHF_ALLOC, |
| 3553 | .type = elf.SHT_DYNSYM, | 3553 | .type = elf.SHT_DYNSYM, |
| 3554 | .addralign = @alignOf(elf.Elf64_Sym), | 3554 | .addralign = @alignOf(elf.Elf64_Sym), |
| ... | @@ -3557,7 +3557,7 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -3557,7 +3557,7 @@ fn initSyntheticSections(self: *Elf) !void { |
| 3557 | .offset = std.math.maxInt(u64), | 3557 | .offset = std.math.maxInt(u64), |
| 3558 | }); | 3558 | }); |
| 3559 | self.hash_section_index = try self.addSection(.{ | 3559 | self.hash_section_index = try self.addSection(.{ |
| 3560 | .name = ".hash", | 3560 | .name = try self.insertShString(".hash"), |
| 3561 | .flags = elf.SHF_ALLOC, | 3561 | .flags = elf.SHF_ALLOC, |
| 3562 | .type = elf.SHT_HASH, | 3562 | .type = elf.SHT_HASH, |
| 3563 | .addralign = 4, | 3563 | .addralign = 4, |
| ... | @@ -3565,7 +3565,7 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -3565,7 +3565,7 @@ fn initSyntheticSections(self: *Elf) !void { |
| 3565 | .offset = std.math.maxInt(u64), | 3565 | .offset = std.math.maxInt(u64), |
| 3566 | }); | 3566 | }); |
| 3567 | self.gnu_hash_section_index = try self.addSection(.{ | 3567 | self.gnu_hash_section_index = try self.addSection(.{ |
| 3568 | .name = ".gnu.hash", | 3568 | .name = try self.insertShString(".gnu.hash"), |
| 3569 | .flags = elf.SHF_ALLOC, | 3569 | .flags = elf.SHF_ALLOC, |
| 3570 | .type = elf.SHT_GNU_HASH, | 3570 | .type = elf.SHT_GNU_HASH, |
| 3571 | .addralign = 8, | 3571 | .addralign = 8, |
| ... | @@ -3578,7 +3578,7 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -3578,7 +3578,7 @@ fn initSyntheticSections(self: *Elf) !void { |
| 3578 | } else false; | 3578 | } else false; |
| 3579 | if (needs_versions) { | 3579 | if (needs_versions) { |
| 3580 | self.versym_section_index = try self.addSection(.{ | 3580 | self.versym_section_index = try self.addSection(.{ |
| 3581 | .name = ".gnu.version", | 3581 | .name = try self.insertShString(".gnu.version"), |
| 3582 | .flags = elf.SHF_ALLOC, | 3582 | .flags = elf.SHF_ALLOC, |
| 3583 | .type = elf.SHT_GNU_VERSYM, | 3583 | .type = elf.SHT_GNU_VERSYM, |
| 3584 | .addralign = @alignOf(elf.Elf64_Versym), | 3584 | .addralign = @alignOf(elf.Elf64_Versym), |
| ... | @@ -3586,7 +3586,7 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -3586,7 +3586,7 @@ fn initSyntheticSections(self: *Elf) !void { |
| 3586 | .offset = std.math.maxInt(u64), | 3586 | .offset = std.math.maxInt(u64), |
| 3587 | }); | 3587 | }); |
| 3588 | self.verneed_section_index = try self.addSection(.{ | 3588 | self.verneed_section_index = try self.addSection(.{ |
| 3589 | .name = ".gnu.version_r", | 3589 | .name = try self.insertShString(".gnu.version_r"), |
| 3590 | .flags = elf.SHF_ALLOC, | 3590 | .flags = elf.SHF_ALLOC, |
| 3591 | .type = elf.SHT_GNU_VERNEED, | 3591 | .type = elf.SHT_GNU_VERNEED, |
| 3592 | .addralign = @alignOf(elf.Elf64_Verneed), | 3592 | .addralign = @alignOf(elf.Elf64_Verneed), |
| ... | @@ -3606,7 +3606,7 @@ pub fn initSymtab(self: *Elf) !void { | ... | @@ -3606,7 +3606,7 @@ pub fn initSymtab(self: *Elf) !void { |
| 3606 | }; | 3606 | }; |
| 3607 | if (self.symtab_section_index == null) { | 3607 | if (self.symtab_section_index == null) { |
| 3608 | self.symtab_section_index = try self.addSection(.{ | 3608 | self.symtab_section_index = try self.addSection(.{ |
| 3609 | .name = ".symtab", | 3609 | .name = try self.insertShString(".symtab"), |
| 3610 | .type = elf.SHT_SYMTAB, | 3610 | .type = elf.SHT_SYMTAB, |
| 3611 | .addralign = if (small_ptr) @alignOf(elf.Elf32_Sym) else @alignOf(elf.Elf64_Sym), | 3611 | .addralign = if (small_ptr) @alignOf(elf.Elf32_Sym) else @alignOf(elf.Elf64_Sym), |
| 3612 | .entsize = if (small_ptr) @sizeOf(elf.Elf32_Sym) else @sizeOf(elf.Elf64_Sym), | 3612 | .entsize = if (small_ptr) @sizeOf(elf.Elf32_Sym) else @sizeOf(elf.Elf64_Sym), |
| ... | @@ -3615,7 +3615,7 @@ pub fn initSymtab(self: *Elf) !void { | ... | @@ -3615,7 +3615,7 @@ pub fn initSymtab(self: *Elf) !void { |
| 3615 | } | 3615 | } |
| 3616 | if (self.strtab_section_index == null) { | 3616 | if (self.strtab_section_index == null) { |
| 3617 | self.strtab_section_index = try self.addSection(.{ | 3617 | self.strtab_section_index = try self.addSection(.{ |
| 3618 | .name = ".strtab", | 3618 | .name = try self.insertShString(".strtab"), |
| 3619 | .type = elf.SHT_STRTAB, | 3619 | .type = elf.SHT_STRTAB, |
| 3620 | .entsize = 1, | 3620 | .entsize = 1, |
| 3621 | .addralign = 1, | 3621 | .addralign = 1, |
| ... | @@ -3627,7 +3627,7 @@ pub fn initSymtab(self: *Elf) !void { | ... | @@ -3627,7 +3627,7 @@ pub fn initSymtab(self: *Elf) !void { |
| 3627 | pub fn initShStrtab(self: *Elf) !void { | 3627 | pub fn initShStrtab(self: *Elf) !void { |
| 3628 | if (self.shstrtab_section_index == null) { | 3628 | if (self.shstrtab_section_index == null) { |
| 3629 | self.shstrtab_section_index = try self.addSection(.{ | 3629 | self.shstrtab_section_index = try self.addSection(.{ |
| 3630 | .name = ".shstrtab", | 3630 | .name = try self.insertShString(".shstrtab"), |
| 3631 | .type = elf.SHT_STRTAB, | 3631 | .type = elf.SHT_STRTAB, |
| 3632 | .entsize = 1, | 3632 | .entsize = 1, |
| 3633 | .addralign = 1, | 3633 | .addralign = 1, |
| ... | @@ -5428,7 +5428,7 @@ fn addPhdr(self: *Elf, opts: struct { | ... | @@ -5428,7 +5428,7 @@ fn addPhdr(self: *Elf, opts: struct { |
| 5428 | return index; | 5428 | return index; |
| 5429 | } | 5429 | } |
| 5430 | | 5430 | |
| 5431 | pub fn addRelaShdr(self: *Elf, name: [:0]const u8, shndx: u32) !u32 { | 5431 | pub fn addRelaShdr(self: *Elf, name: u32, shndx: u32) !u32 { |
| 5432 | const entsize: u64 = switch (self.ptr_width) { | 5432 | const entsize: u64 = switch (self.ptr_width) { |
| 5433 | .p32 => @sizeOf(elf.Elf32_Rela), | 5433 | .p32 => @sizeOf(elf.Elf32_Rela), |
| 5434 | .p64 => @sizeOf(elf.Elf64_Rela), | 5434 | .p64 => @sizeOf(elf.Elf64_Rela), |
| ... | @@ -5449,7 +5449,7 @@ pub fn addRelaShdr(self: *Elf, name: [:0]const u8, shndx: u32) !u32 { | ... | @@ -5449,7 +5449,7 @@ pub fn addRelaShdr(self: *Elf, name: [:0]const u8, shndx: u32) !u32 { |
| 5449 | } | 5449 | } |
| 5450 | | 5450 | |
| 5451 | pub const AddSectionOpts = struct { | 5451 | pub const AddSectionOpts = struct { |
| 5452 | name: [:0]const u8, | 5452 | name: u32 = 0, |
| 5453 | type: u32 = elf.SHT_NULL, | 5453 | type: u32 = elf.SHT_NULL, |
| 5454 | flags: u64 = 0, | 5454 | flags: u64 = 0, |
| 5455 | link: u32 = 0, | 5455 | link: u32 = 0, |
| ... | @@ -5464,7 +5464,7 @@ pub fn addSection(self: *Elf, opts: AddSectionOpts) !u32 { | ... | @@ -5464,7 +5464,7 @@ pub fn addSection(self: *Elf, opts: AddSectionOpts) !u32 { |
| 5464 | const index = @as(u32, @intCast(self.shdrs.items.len)); | 5464 | const index = @as(u32, @intCast(self.shdrs.items.len)); |
| 5465 | const shdr = try self.shdrs.addOne(gpa); | 5465 | const shdr = try self.shdrs.addOne(gpa); |
| 5466 | shdr.* = .{ | 5466 | shdr.* = .{ |
| 5467 | .sh_name = try self.insertShString(opts.name), | 5467 | .sh_name = opts.name, |
| 5468 | .sh_type = opts.type, | 5468 | .sh_type = opts.type, |
| 5469 | .sh_flags = opts.flags, | 5469 | .sh_flags = opts.flags, |
| 5470 | .sh_addr = 0, | 5470 | .sh_addr = 0, |
| ... | @@ -5709,7 +5709,7 @@ pub fn zigObjectPtr(self: *Elf) ?*ZigObject { | ... | @@ -5709,7 +5709,7 @@ pub fn zigObjectPtr(self: *Elf) ?*ZigObject { |
| 5709 | return self.file(index).?.zig_object; | 5709 | return self.file(index).?.zig_object; |
| 5710 | } | 5710 | } |
| 5711 | | 5711 | |
| 5712 | pub fn getOrCreateMergeSection(self: *Elf, name: []const u8, flags: u64, @"type": u32) !MergeSection.Index { | 5712 | pub fn getOrCreateMergeSection(self: *Elf, name: [:0]const u8, flags: u64, @"type": u32) !MergeSection.Index { |
| 5713 | const gpa = self.base.comp.gpa; | 5713 | const gpa = self.base.comp.gpa; |
| 5714 | const out_name = name: { | 5714 | const out_name = name: { |
| 5715 | if (self.base.isRelocatable()) break :name name; | 5715 | if (self.base.isRelocatable()) break :name name; |
| ... | @@ -5717,11 +5717,11 @@ pub fn getOrCreateMergeSection(self: *Elf, name: []const u8, flags: u64, @"type" | ... | @@ -5717,11 +5717,11 @@ pub fn getOrCreateMergeSection(self: *Elf, name: []const u8, flags: u64, @"type" |
| 5717 | break :name if (flags & elf.SHF_STRINGS != 0) ".rodata.str" else ".rodata.cst"; | 5717 | break :name if (flags & elf.SHF_STRINGS != 0) ".rodata.str" else ".rodata.cst"; |
| 5718 | break :name name; | 5718 | break :name name; |
| 5719 | }; | 5719 | }; |
| 5720 | const out_off = try self.strings.insert(gpa, out_name); | | |
| 5721 | const out_flags = flags & ~@as(u64, elf.SHF_COMPRESSED | elf.SHF_GROUP); | | |
| 5722 | for (self.merge_sections.items, 0..) |msec, index| { | 5720 | for (self.merge_sections.items, 0..) |msec, index| { |
| 5723 | if (msec.name_offset == out_off) return @intCast(index); | 5721 | if (mem.eql(u8, msec.name(self), out_name)) return @intCast(index); |
| 5724 | } | 5722 | } |
| | 5723 | const out_off = try self.insertShString(out_name); |
| | 5724 | const out_flags = flags & ~@as(u64, elf.SHF_COMPRESSED | elf.SHF_GROUP); |
| 5725 | const index = @as(MergeSection.Index, @intCast(self.merge_sections.items.len)); | 5725 | const index = @as(MergeSection.Index, @intCast(self.merge_sections.items.len)); |
| 5726 | const msec = try self.merge_sections.addOne(gpa); | 5726 | const msec = try self.merge_sections.addOne(gpa); |
| 5727 | msec.* = .{ | 5727 | msec.* = .{ |