| ... | @@ -57,6 +57,7 @@ phdrs: ProgramHeaderList = .empty, | ... | @@ -57,6 +57,7 @@ phdrs: ProgramHeaderList = .empty, |
| 57 | | 57 | |
| 58 | /// Special program headers. | 58 | /// Special program headers. |
| 59 | phdr_indexes: ProgramHeaderIndexes = .{}, | 59 | phdr_indexes: ProgramHeaderIndexes = .{}, |
| | 60 | section_indexes: SectionIndexes = .{}, |
| 60 | | 61 | |
| 61 | page_size: u32, | 62 | page_size: u32, |
| 62 | default_sym_version: elf.Elf64_Versym, | 63 | default_sym_version: elf.Elf64_Versym, |
| ... | @@ -99,29 +100,6 @@ rela_plt: std.ArrayListUnmanaged(elf.Elf64_Rela) = .empty, | ... | @@ -99,29 +100,6 @@ rela_plt: std.ArrayListUnmanaged(elf.Elf64_Rela) = .empty, |
| 99 | /// Applies only to a relocatable. | 100 | /// Applies only to a relocatable. |
| 100 | comdat_group_sections: std.ArrayListUnmanaged(ComdatGroupSection) = .empty, | 101 | comdat_group_sections: std.ArrayListUnmanaged(ComdatGroupSection) = .empty, |
| 101 | | 102 | |
| 102 | copy_rel_section_index: ?u32 = null, | | |
| 103 | dynamic_section_index: ?u32 = null, | | |
| 104 | dynstrtab_section_index: ?u32 = null, | | |
| 105 | dynsymtab_section_index: ?u32 = null, | | |
| 106 | eh_frame_section_index: ?u32 = null, | | |
| 107 | eh_frame_rela_section_index: ?u32 = null, | | |
| 108 | eh_frame_hdr_section_index: ?u32 = null, | | |
| 109 | hash_section_index: ?u32 = null, | | |
| 110 | gnu_hash_section_index: ?u32 = null, | | |
| 111 | got_section_index: ?u32 = null, | | |
| 112 | got_plt_section_index: ?u32 = null, | | |
| 113 | interp_section_index: ?u32 = null, | | |
| 114 | plt_section_index: ?u32 = null, | | |
| 115 | plt_got_section_index: ?u32 = null, | | |
| 116 | rela_dyn_section_index: ?u32 = null, | | |
| 117 | rela_plt_section_index: ?u32 = null, | | |
| 118 | versym_section_index: ?u32 = null, | | |
| 119 | verneed_section_index: ?u32 = null, | | |
| 120 | | | |
| 121 | shstrtab_section_index: ?u32 = null, | | |
| 122 | strtab_section_index: ?u32 = null, | | |
| 123 | symtab_section_index: ?u32 = null, | | |
| 124 | | | |
| 125 | resolver: SymbolResolver = .{}, | 103 | resolver: SymbolResolver = .{}, |
| 126 | | 104 | |
| 127 | has_text_reloc: bool = false, | 105 | has_text_reloc: bool = false, |
| ... | @@ -136,6 +114,31 @@ comment_merge_section_index: ?MergeSection.Index = null, | ... | @@ -136,6 +114,31 @@ comment_merge_section_index: ?MergeSection.Index = null, |
| 136 | | 114 | |
| 137 | first_eflags: ?elf.Elf64_Word = null, | 115 | first_eflags: ?elf.Elf64_Word = null, |
| 138 | | 116 | |
| | 117 | const SectionIndexes = struct { |
| | 118 | copy_rel: ?u32 = null, |
| | 119 | dynamic: ?u32 = null, |
| | 120 | dynstrtab: ?u32 = null, |
| | 121 | dynsymtab: ?u32 = null, |
| | 122 | eh_frame: ?u32 = null, |
| | 123 | eh_frame_rela: ?u32 = null, |
| | 124 | eh_frame_hdr: ?u32 = null, |
| | 125 | hash: ?u32 = null, |
| | 126 | gnu_hash: ?u32 = null, |
| | 127 | got: ?u32 = null, |
| | 128 | got_plt: ?u32 = null, |
| | 129 | interp: ?u32 = null, |
| | 130 | plt: ?u32 = null, |
| | 131 | plt_got: ?u32 = null, |
| | 132 | rela_dyn: ?u32 = null, |
| | 133 | rela_plt: ?u32 = null, |
| | 134 | versym: ?u32 = null, |
| | 135 | verneed: ?u32 = null, |
| | 136 | |
| | 137 | shstrtab: ?u32 = null, |
| | 138 | strtab: ?u32 = null, |
| | 139 | symtab: ?u32 = null, |
| | 140 | }; |
| | 141 | |
| 139 | const ProgramHeaderList = std.ArrayListUnmanaged(elf.Elf64_Phdr); | 142 | const ProgramHeaderList = std.ArrayListUnmanaged(elf.Elf64_Phdr); |
| 140 | | 143 | |
| 141 | const OptionalProgramHeaderIndex = enum(u16) { | 144 | const OptionalProgramHeaderIndex = enum(u16) { |
| ... | @@ -2670,7 +2673,7 @@ pub fn writeElfHeader(self: *Elf) !void { | ... | @@ -2670,7 +2673,7 @@ pub fn writeElfHeader(self: *Elf) !void { |
| 2670 | mem.writeInt(u16, hdr_buf[index..][0..2], e_shnum, endian); | 2673 | mem.writeInt(u16, hdr_buf[index..][0..2], e_shnum, endian); |
| 2671 | index += 2; | 2674 | index += 2; |
| 2672 | | 2675 | |
| 2673 | mem.writeInt(u16, hdr_buf[index..][0..2], @intCast(self.shstrtab_section_index.?), endian); | 2676 | mem.writeInt(u16, hdr_buf[index..][0..2], @intCast(self.section_indexes.shstrtab.?), endian); |
| 2674 | index += 2; | 2677 | index += 2; |
| 2675 | | 2678 | |
| 2676 | assert(index == e_ehsize); | 2679 | assert(index == e_ehsize); |
| ... | @@ -2888,8 +2891,8 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -2888,8 +2891,8 @@ fn initSyntheticSections(self: *Elf) !void { |
| 2888 | } else false; | 2891 | } else false; |
| 2889 | }; | 2892 | }; |
| 2890 | if (needs_eh_frame) { | 2893 | if (needs_eh_frame) { |
| 2891 | if (self.eh_frame_section_index == null) { | 2894 | if (self.section_indexes.eh_frame == null) { |
| 2892 | self.eh_frame_section_index = self.sectionByName(".eh_frame") orelse try self.addSection(.{ | 2895 | self.section_indexes.eh_frame = self.sectionByName(".eh_frame") orelse try self.addSection(.{ |
| 2893 | .name = try self.insertShString(".eh_frame"), | 2896 | .name = try self.insertShString(".eh_frame"), |
| 2894 | .type = if (target.cpu.arch == .x86_64) | 2897 | .type = if (target.cpu.arch == .x86_64) |
| 2895 | elf.SHT_X86_64_UNWIND | 2898 | elf.SHT_X86_64_UNWIND |
| ... | @@ -2899,8 +2902,8 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -2899,8 +2902,8 @@ fn initSyntheticSections(self: *Elf) !void { |
| 2899 | .addralign = ptr_size, | 2902 | .addralign = ptr_size, |
| 2900 | }); | 2903 | }); |
| 2901 | } | 2904 | } |
| 2902 | if (comp.link_eh_frame_hdr and self.eh_frame_hdr_section_index == null) { | 2905 | if (comp.link_eh_frame_hdr and self.section_indexes.eh_frame_hdr == null) { |
| 2903 | self.eh_frame_hdr_section_index = try self.addSection(.{ | 2906 | self.section_indexes.eh_frame_hdr = try self.addSection(.{ |
| 2904 | .name = try self.insertShString(".eh_frame_hdr"), | 2907 | .name = try self.insertShString(".eh_frame_hdr"), |
| 2905 | .type = elf.SHT_PROGBITS, | 2908 | .type = elf.SHT_PROGBITS, |
| 2906 | .flags = elf.SHF_ALLOC, | 2909 | .flags = elf.SHF_ALLOC, |
| ... | @@ -2909,8 +2912,8 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -2909,8 +2912,8 @@ fn initSyntheticSections(self: *Elf) !void { |
| 2909 | } | 2912 | } |
| 2910 | } | 2913 | } |
| 2911 | | 2914 | |
| 2912 | if (self.got.entries.items.len > 0 and self.got_section_index == null) { | 2915 | if (self.got.entries.items.len > 0 and self.section_indexes.got == null) { |
| 2913 | self.got_section_index = try self.addSection(.{ | 2916 | self.section_indexes.got = try self.addSection(.{ |
| 2914 | .name = try self.insertShString(".got"), | 2917 | .name = try self.insertShString(".got"), |
| 2915 | .type = elf.SHT_PROGBITS, | 2918 | .type = elf.SHT_PROGBITS, |
| 2916 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, | 2919 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, |
| ... | @@ -2918,8 +2921,8 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -2918,8 +2921,8 @@ fn initSyntheticSections(self: *Elf) !void { |
| 2918 | }); | 2921 | }); |
| 2919 | } | 2922 | } |
| 2920 | | 2923 | |
| 2921 | if (self.got_plt_section_index == null) { | 2924 | if (self.section_indexes.got_plt == null) { |
| 2922 | self.got_plt_section_index = try self.addSection(.{ | 2925 | self.section_indexes.got_plt = try self.addSection(.{ |
| 2923 | .name = try self.insertShString(".got.plt"), | 2926 | .name = try self.insertShString(".got.plt"), |
| 2924 | .type = elf.SHT_PROGBITS, | 2927 | .type = elf.SHT_PROGBITS, |
| 2925 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, | 2928 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, |
| ... | @@ -2938,8 +2941,8 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -2938,8 +2941,8 @@ fn initSyntheticSections(self: *Elf) !void { |
| 2938 | } | 2941 | } |
| 2939 | break :blk false; | 2942 | break :blk false; |
| 2940 | }; | 2943 | }; |
| 2941 | if (needs_rela_dyn and self.rela_dyn_section_index == null) { | 2944 | if (needs_rela_dyn and self.section_indexes.rela_dyn == null) { |
| 2942 | self.rela_dyn_section_index = try self.addSection(.{ | 2945 | self.section_indexes.rela_dyn = try self.addSection(.{ |
| 2943 | .name = try self.insertShString(".rela.dyn"), | 2946 | .name = try self.insertShString(".rela.dyn"), |
| 2944 | .type = elf.SHT_RELA, | 2947 | .type = elf.SHT_RELA, |
| 2945 | .flags = elf.SHF_ALLOC, | 2948 | .flags = elf.SHF_ALLOC, |
| ... | @@ -2949,16 +2952,16 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -2949,16 +2952,16 @@ fn initSyntheticSections(self: *Elf) !void { |
| 2949 | } | 2952 | } |
| 2950 | | 2953 | |
| 2951 | if (self.plt.symbols.items.len > 0) { | 2954 | if (self.plt.symbols.items.len > 0) { |
| 2952 | if (self.plt_section_index == null) { | 2955 | if (self.section_indexes.plt == null) { |
| 2953 | self.plt_section_index = try self.addSection(.{ | 2956 | self.section_indexes.plt = try self.addSection(.{ |
| 2954 | .name = try self.insertShString(".plt"), | 2957 | .name = try self.insertShString(".plt"), |
| 2955 | .type = elf.SHT_PROGBITS, | 2958 | .type = elf.SHT_PROGBITS, |
| 2956 | .flags = elf.SHF_ALLOC | elf.SHF_EXECINSTR, | 2959 | .flags = elf.SHF_ALLOC | elf.SHF_EXECINSTR, |
| 2957 | .addralign = 16, | 2960 | .addralign = 16, |
| 2958 | }); | 2961 | }); |
| 2959 | } | 2962 | } |
| 2960 | if (self.rela_plt_section_index == null) { | 2963 | if (self.section_indexes.rela_plt == null) { |
| 2961 | self.rela_plt_section_index = try self.addSection(.{ | 2964 | self.section_indexes.rela_plt = try self.addSection(.{ |
| 2962 | .name = try self.insertShString(".rela.plt"), | 2965 | .name = try self.insertShString(".rela.plt"), |
| 2963 | .type = elf.SHT_RELA, | 2966 | .type = elf.SHT_RELA, |
| 2964 | .flags = elf.SHF_ALLOC, | 2967 | .flags = elf.SHF_ALLOC, |
| ... | @@ -2968,8 +2971,8 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -2968,8 +2971,8 @@ fn initSyntheticSections(self: *Elf) !void { |
| 2968 | } | 2971 | } |
| 2969 | } | 2972 | } |
| 2970 | | 2973 | |
| 2971 | if (self.plt_got.symbols.items.len > 0 and self.plt_got_section_index == null) { | 2974 | if (self.plt_got.symbols.items.len > 0 and self.section_indexes.plt_got == null) { |
| 2972 | self.plt_got_section_index = try self.addSection(.{ | 2975 | self.section_indexes.plt_got = try self.addSection(.{ |
| 2973 | .name = try self.insertShString(".plt.got"), | 2976 | .name = try self.insertShString(".plt.got"), |
| 2974 | .type = elf.SHT_PROGBITS, | 2977 | .type = elf.SHT_PROGBITS, |
| 2975 | .flags = elf.SHF_ALLOC | elf.SHF_EXECINSTR, | 2978 | .flags = elf.SHF_ALLOC | elf.SHF_EXECINSTR, |
| ... | @@ -2977,8 +2980,8 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -2977,8 +2980,8 @@ fn initSyntheticSections(self: *Elf) !void { |
| 2977 | }); | 2980 | }); |
| 2978 | } | 2981 | } |
| 2979 | | 2982 | |
| 2980 | if (self.copy_rel.symbols.items.len > 0 and self.copy_rel_section_index == null) { | 2983 | if (self.copy_rel.symbols.items.len > 0 and self.section_indexes.copy_rel == null) { |
| 2981 | self.copy_rel_section_index = try self.addSection(.{ | 2984 | self.section_indexes.copy_rel = try self.addSection(.{ |
| 2982 | .name = try self.insertShString(".copyrel"), | 2985 | .name = try self.insertShString(".copyrel"), |
| 2983 | .type = elf.SHT_NOBITS, | 2986 | .type = elf.SHT_NOBITS, |
| 2984 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, | 2987 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, |
| ... | @@ -2994,8 +2997,8 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -2994,8 +2997,8 @@ fn initSyntheticSections(self: *Elf) !void { |
| 2994 | if (self.base.isStatic() and !comp.config.pie) break :blk false; | 2997 | if (self.base.isStatic() and !comp.config.pie) break :blk false; |
| 2995 | break :blk target.dynamic_linker.get() != null; | 2998 | break :blk target.dynamic_linker.get() != null; |
| 2996 | }; | 2999 | }; |
| 2997 | if (needs_interp and self.interp_section_index == null) { | 3000 | if (needs_interp and self.section_indexes.interp == null) { |
| 2998 | self.interp_section_index = try self.addSection(.{ | 3001 | self.section_indexes.interp = try self.addSection(.{ |
| 2999 | .name = try self.insertShString(".interp"), | 3002 | .name = try self.insertShString(".interp"), |
| 3000 | .type = elf.SHT_PROGBITS, | 3003 | .type = elf.SHT_PROGBITS, |
| 3001 | .flags = elf.SHF_ALLOC, | 3004 | .flags = elf.SHF_ALLOC, |
| ... | @@ -3004,8 +3007,8 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -3004,8 +3007,8 @@ fn initSyntheticSections(self: *Elf) !void { |
| 3004 | } | 3007 | } |
| 3005 | | 3008 | |
| 3006 | if (self.isEffectivelyDynLib() or self.shared_objects.items.len > 0 or comp.config.pie) { | 3009 | if (self.isEffectivelyDynLib() or self.shared_objects.items.len > 0 or comp.config.pie) { |
| 3007 | if (self.dynstrtab_section_index == null) { | 3010 | if (self.section_indexes.dynstrtab == null) { |
| 3008 | self.dynstrtab_section_index = try self.addSection(.{ | 3011 | self.section_indexes.dynstrtab = try self.addSection(.{ |
| 3009 | .name = try self.insertShString(".dynstr"), | 3012 | .name = try self.insertShString(".dynstr"), |
| 3010 | .flags = elf.SHF_ALLOC, | 3013 | .flags = elf.SHF_ALLOC, |
| 3011 | .type = elf.SHT_STRTAB, | 3014 | .type = elf.SHT_STRTAB, |
| ... | @@ -3013,8 +3016,8 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -3013,8 +3016,8 @@ fn initSyntheticSections(self: *Elf) !void { |
| 3013 | .addralign = 1, | 3016 | .addralign = 1, |
| 3014 | }); | 3017 | }); |
| 3015 | } | 3018 | } |
| 3016 | if (self.dynamic_section_index == null) { | 3019 | if (self.section_indexes.dynamic == null) { |
| 3017 | self.dynamic_section_index = try self.addSection(.{ | 3020 | self.section_indexes.dynamic = try self.addSection(.{ |
| 3018 | .name = try self.insertShString(".dynamic"), | 3021 | .name = try self.insertShString(".dynamic"), |
| 3019 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, | 3022 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, |
| 3020 | .type = elf.SHT_DYNAMIC, | 3023 | .type = elf.SHT_DYNAMIC, |
| ... | @@ -3022,8 +3025,8 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -3022,8 +3025,8 @@ fn initSyntheticSections(self: *Elf) !void { |
| 3022 | .addralign = @alignOf(elf.Elf64_Dyn), | 3025 | .addralign = @alignOf(elf.Elf64_Dyn), |
| 3023 | }); | 3026 | }); |
| 3024 | } | 3027 | } |
| 3025 | if (self.dynsymtab_section_index == null) { | 3028 | if (self.section_indexes.dynsymtab == null) { |
| 3026 | self.dynsymtab_section_index = try self.addSection(.{ | 3029 | self.section_indexes.dynsymtab = try self.addSection(.{ |
| 3027 | .name = try self.insertShString(".dynsym"), | 3030 | .name = try self.insertShString(".dynsym"), |
| 3028 | .flags = elf.SHF_ALLOC, | 3031 | .flags = elf.SHF_ALLOC, |
| 3029 | .type = elf.SHT_DYNSYM, | 3032 | .type = elf.SHT_DYNSYM, |
| ... | @@ -3032,8 +3035,8 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -3032,8 +3035,8 @@ fn initSyntheticSections(self: *Elf) !void { |
| 3032 | .info = 1, | 3035 | .info = 1, |
| 3033 | }); | 3036 | }); |
| 3034 | } | 3037 | } |
| 3035 | if (self.hash_section_index == null) { | 3038 | if (self.section_indexes.hash == null) { |
| 3036 | self.hash_section_index = try self.addSection(.{ | 3039 | self.section_indexes.hash = try self.addSection(.{ |
| 3037 | .name = try self.insertShString(".hash"), | 3040 | .name = try self.insertShString(".hash"), |
| 3038 | .flags = elf.SHF_ALLOC, | 3041 | .flags = elf.SHF_ALLOC, |
| 3039 | .type = elf.SHT_HASH, | 3042 | .type = elf.SHT_HASH, |
| ... | @@ -3041,8 +3044,8 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -3041,8 +3044,8 @@ fn initSyntheticSections(self: *Elf) !void { |
| 3041 | .entsize = 4, | 3044 | .entsize = 4, |
| 3042 | }); | 3045 | }); |
| 3043 | } | 3046 | } |
| 3044 | if (self.gnu_hash_section_index == null) { | 3047 | if (self.section_indexes.gnu_hash == null) { |
| 3045 | self.gnu_hash_section_index = try self.addSection(.{ | 3048 | self.section_indexes.gnu_hash = try self.addSection(.{ |
| 3046 | .name = try self.insertShString(".gnu.hash"), | 3049 | .name = try self.insertShString(".gnu.hash"), |
| 3047 | .flags = elf.SHF_ALLOC, | 3050 | .flags = elf.SHF_ALLOC, |
| 3048 | .type = elf.SHT_GNU_HASH, | 3051 | .type = elf.SHT_GNU_HASH, |
| ... | @@ -3055,8 +3058,8 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -3055,8 +3058,8 @@ fn initSyntheticSections(self: *Elf) !void { |
| 3055 | if (sym.flags.import and sym.version_index & elf.VERSYM_VERSION > elf.VER_NDX_GLOBAL) break true; | 3058 | if (sym.flags.import and sym.version_index & elf.VERSYM_VERSION > elf.VER_NDX_GLOBAL) break true; |
| 3056 | } else false; | 3059 | } else false; |
| 3057 | if (needs_versions) { | 3060 | if (needs_versions) { |
| 3058 | if (self.versym_section_index == null) { | 3061 | if (self.section_indexes.versym == null) { |
| 3059 | self.versym_section_index = try self.addSection(.{ | 3062 | self.section_indexes.versym = try self.addSection(.{ |
| 3060 | .name = try self.insertShString(".gnu.version"), | 3063 | .name = try self.insertShString(".gnu.version"), |
| 3061 | .flags = elf.SHF_ALLOC, | 3064 | .flags = elf.SHF_ALLOC, |
| 3062 | .type = elf.SHT_GNU_VERSYM, | 3065 | .type = elf.SHT_GNU_VERSYM, |
| ... | @@ -3064,8 +3067,8 @@ fn initSyntheticSections(self: *Elf) !void { | ... | @@ -3064,8 +3067,8 @@ fn initSyntheticSections(self: *Elf) !void { |
| 3064 | .entsize = @sizeOf(elf.Elf64_Versym), | 3067 | .entsize = @sizeOf(elf.Elf64_Versym), |
| 3065 | }); | 3068 | }); |
| 3066 | } | 3069 | } |
| 3067 | if (self.verneed_section_index == null) { | 3070 | if (self.section_indexes.verneed == null) { |
| 3068 | self.verneed_section_index = try self.addSection(.{ | 3071 | self.section_indexes.verneed = try self.addSection(.{ |
| 3069 | .name = try self.insertShString(".gnu.version_r"), | 3072 | .name = try self.insertShString(".gnu.version_r"), |
| 3070 | .flags = elf.SHF_ALLOC, | 3073 | .flags = elf.SHF_ALLOC, |
| 3071 | .type = elf.SHT_GNU_VERNEED, | 3074 | .type = elf.SHT_GNU_VERNEED, |
| ... | @@ -3084,16 +3087,16 @@ pub fn initSymtab(self: *Elf) !void { | ... | @@ -3084,16 +3087,16 @@ pub fn initSymtab(self: *Elf) !void { |
| 3084 | .p32 => true, | 3087 | .p32 => true, |
| 3085 | .p64 => false, | 3088 | .p64 => false, |
| 3086 | }; | 3089 | }; |
| 3087 | if (self.symtab_section_index == null) { | 3090 | if (self.section_indexes.symtab == null) { |
| 3088 | self.symtab_section_index = try self.addSection(.{ | 3091 | self.section_indexes.symtab = try self.addSection(.{ |
| 3089 | .name = try self.insertShString(".symtab"), | 3092 | .name = try self.insertShString(".symtab"), |
| 3090 | .type = elf.SHT_SYMTAB, | 3093 | .type = elf.SHT_SYMTAB, |
| 3091 | .addralign = if (small_ptr) @alignOf(elf.Elf32_Sym) else @alignOf(elf.Elf64_Sym), | 3094 | .addralign = if (small_ptr) @alignOf(elf.Elf32_Sym) else @alignOf(elf.Elf64_Sym), |
| 3092 | .entsize = if (small_ptr) @sizeOf(elf.Elf32_Sym) else @sizeOf(elf.Elf64_Sym), | 3095 | .entsize = if (small_ptr) @sizeOf(elf.Elf32_Sym) else @sizeOf(elf.Elf64_Sym), |
| 3093 | }); | 3096 | }); |
| 3094 | } | 3097 | } |
| 3095 | if (self.strtab_section_index == null) { | 3098 | if (self.section_indexes.strtab == null) { |
| 3096 | self.strtab_section_index = try self.addSection(.{ | 3099 | self.section_indexes.strtab = try self.addSection(.{ |
| 3097 | .name = try self.insertShString(".strtab"), | 3100 | .name = try self.insertShString(".strtab"), |
| 3098 | .type = elf.SHT_STRTAB, | 3101 | .type = elf.SHT_STRTAB, |
| 3099 | .entsize = 1, | 3102 | .entsize = 1, |
| ... | @@ -3103,8 +3106,8 @@ pub fn initSymtab(self: *Elf) !void { | ... | @@ -3103,8 +3106,8 @@ pub fn initSymtab(self: *Elf) !void { |
| 3103 | } | 3106 | } |
| 3104 | | 3107 | |
| 3105 | pub fn initShStrtab(self: *Elf) !void { | 3108 | pub fn initShStrtab(self: *Elf) !void { |
| 3106 | if (self.shstrtab_section_index == null) { | 3109 | if (self.section_indexes.shstrtab == null) { |
| 3107 | self.shstrtab_section_index = try self.addSection(.{ | 3110 | self.section_indexes.shstrtab = try self.addSection(.{ |
| 3108 | .name = try self.insertShString(".shstrtab"), | 3111 | .name = try self.insertShString(".shstrtab"), |
| 3109 | .type = elf.SHT_STRTAB, | 3112 | .type = elf.SHT_STRTAB, |
| 3110 | .entsize = 1, | 3113 | .entsize = 1, |
| ... | @@ -3116,20 +3119,20 @@ pub fn initShStrtab(self: *Elf) !void { | ... | @@ -3116,20 +3119,20 @@ pub fn initShStrtab(self: *Elf) !void { |
| 3116 | fn initSpecialPhdrs(self: *Elf) !void { | 3119 | fn initSpecialPhdrs(self: *Elf) !void { |
| 3117 | comptime assert(max_number_of_special_phdrs == 5); | 3120 | comptime assert(max_number_of_special_phdrs == 5); |
| 3118 | | 3121 | |
| 3119 | if (self.interp_section_index != null and self.phdr_indexes.interp == .none) { | 3122 | if (self.section_indexes.interp != null and self.phdr_indexes.interp == .none) { |
| 3120 | self.phdr_indexes.interp = (try self.addPhdr(.{ | 3123 | self.phdr_indexes.interp = (try self.addPhdr(.{ |
| 3121 | .type = elf.PT_INTERP, | 3124 | .type = elf.PT_INTERP, |
| 3122 | .flags = elf.PF_R, | 3125 | .flags = elf.PF_R, |
| 3123 | .@"align" = 1, | 3126 | .@"align" = 1, |
| 3124 | })).toOptional(); | 3127 | })).toOptional(); |
| 3125 | } | 3128 | } |
| 3126 | if (self.dynamic_section_index != null and self.phdr_indexes.dynamic == .none) { | 3129 | if (self.section_indexes.dynamic != null and self.phdr_indexes.dynamic == .none) { |
| 3127 | self.phdr_indexes.dynamic = (try self.addPhdr(.{ | 3130 | self.phdr_indexes.dynamic = (try self.addPhdr(.{ |
| 3128 | .type = elf.PT_DYNAMIC, | 3131 | .type = elf.PT_DYNAMIC, |
| 3129 | .flags = elf.PF_R | elf.PF_W, | 3132 | .flags = elf.PF_R | elf.PF_W, |
| 3130 | })).toOptional(); | 3133 | })).toOptional(); |
| 3131 | } | 3134 | } |
| 3132 | if (self.eh_frame_hdr_section_index != null and self.phdr_indexes.gnu_eh_frame == .none) { | 3135 | if (self.section_indexes.eh_frame_hdr != null and self.phdr_indexes.gnu_eh_frame == .none) { |
| 3133 | self.phdr_indexes.gnu_eh_frame = (try self.addPhdr(.{ | 3136 | self.phdr_indexes.gnu_eh_frame = (try self.addPhdr(.{ |
| 3134 | .type = elf.PT_GNU_EH_FRAME, | 3137 | .type = elf.PT_GNU_EH_FRAME, |
| 3135 | .flags = elf.PF_R, | 3138 | .flags = elf.PF_R, |
| ... | @@ -3237,7 +3240,7 @@ fn sortInitFini(self: *Elf) !void { | ... | @@ -3237,7 +3240,7 @@ fn sortInitFini(self: *Elf) !void { |
| 3237 | } | 3240 | } |
| 3238 | | 3241 | |
| 3239 | fn setDynamicSection(self: *Elf, rpaths: []const []const u8) !void { | 3242 | fn setDynamicSection(self: *Elf, rpaths: []const []const u8) !void { |
| 3240 | if (self.dynamic_section_index == null) return; | 3243 | if (self.section_indexes.dynamic == null) return; |
| 3241 | | 3244 | |
| 3242 | for (self.shared_objects.items) |index| { | 3245 | for (self.shared_objects.items) |index| { |
| 3243 | const shared_object = self.file(index).?.shared_object; | 3246 | const shared_object = self.file(index).?.shared_object; |
| ... | @@ -3255,13 +3258,13 @@ fn setDynamicSection(self: *Elf, rpaths: []const []const u8) !void { | ... | @@ -3255,13 +3258,13 @@ fn setDynamicSection(self: *Elf, rpaths: []const []const u8) !void { |
| 3255 | } | 3258 | } |
| 3256 | | 3259 | |
| 3257 | fn sortDynamicSymtab(self: *Elf) void { | 3260 | fn sortDynamicSymtab(self: *Elf) void { |
| 3258 | if (self.gnu_hash_section_index == null) return; | 3261 | if (self.section_indexes.gnu_hash == null) return; |
| 3259 | self.dynsym.sort(self); | 3262 | self.dynsym.sort(self); |
| 3260 | } | 3263 | } |
| 3261 | | 3264 | |
| 3262 | fn setVersionSymtab(self: *Elf) !void { | 3265 | fn setVersionSymtab(self: *Elf) !void { |
| 3263 | const gpa = self.base.comp.gpa; | 3266 | const gpa = self.base.comp.gpa; |
| 3264 | if (self.versym_section_index == null) return; | 3267 | if (self.section_indexes.versym == null) return; |
| 3265 | try self.versym.resize(gpa, self.dynsym.count()); | 3268 | try self.versym.resize(gpa, self.dynsym.count()); |
| 3266 | self.versym.items[0] = elf.VER_NDX_LOCAL; | 3269 | self.versym.items[0] = elf.VER_NDX_LOCAL; |
| 3267 | for (self.dynsym.entries.items, 1..) |entry, i| { | 3270 | for (self.dynsym.entries.items, 1..) |entry, i| { |
| ... | @@ -3269,7 +3272,7 @@ fn setVersionSymtab(self: *Elf) !void { | ... | @@ -3269,7 +3272,7 @@ fn setVersionSymtab(self: *Elf) !void { |
| 3269 | self.versym.items[i] = sym.version_index; | 3272 | self.versym.items[i] = sym.version_index; |
| 3270 | } | 3273 | } |
| 3271 | | 3274 | |
| 3272 | if (self.verneed_section_index) |shndx| { | 3275 | if (self.section_indexes.verneed) |shndx| { |
| 3273 | try self.verneed.generate(self); | 3276 | try self.verneed.generate(self); |
| 3274 | const shdr = &self.sections.items(.shdr)[shndx]; | 3277 | const shdr = &self.sections.items(.shdr)[shndx]; |
| 3275 | shdr.sh_info = @as(u32, @intCast(self.verneed.verneed.items.len)); | 3278 | shdr.sh_info = @as(u32, @intCast(self.verneed.verneed.items.len)); |
| ... | @@ -3277,10 +3280,10 @@ fn setVersionSymtab(self: *Elf) !void { | ... | @@ -3277,10 +3280,10 @@ fn setVersionSymtab(self: *Elf) !void { |
| 3277 | } | 3280 | } |
| 3278 | | 3281 | |
| 3279 | fn setHashSections(self: *Elf) !void { | 3282 | fn setHashSections(self: *Elf) !void { |
| 3280 | if (self.hash_section_index != null) { | 3283 | if (self.section_indexes.hash != null) { |
| 3281 | try self.hash.generate(self); | 3284 | try self.hash.generate(self); |
| 3282 | } | 3285 | } |
| 3283 | if (self.gnu_hash_section_index != null) { | 3286 | if (self.section_indexes.gnu_hash != null) { |
| 3284 | try self.gnu_hash.calcSize(self); | 3287 | try self.gnu_hash.calcSize(self); |
| 3285 | } | 3288 | } |
| 3286 | } | 3289 | } |
| ... | @@ -3420,47 +3423,22 @@ pub fn sortShdrs(self: *Elf) !void { | ... | @@ -3420,47 +3423,22 @@ pub fn sortShdrs(self: *Elf) !void { |
| 3420 | | 3423 | |
| 3421 | const backlinks = try gpa.alloc(u32, entries.items.len); | 3424 | const backlinks = try gpa.alloc(u32, entries.items.len); |
| 3422 | defer gpa.free(backlinks); | 3425 | defer gpa.free(backlinks); |
| 3423 | for (entries.items, 0..) |entry, i| { | 3426 | { |
| 3424 | backlinks[entry.shndx] = @intCast(i); | 3427 | var slice = self.sections.toOwnedSlice(); |
| 3425 | } | 3428 | defer slice.deinit(gpa); |
| 3426 | | 3429 | try self.sections.resize(gpa, slice.len); |
| 3427 | var slice = self.sections.toOwnedSlice(); | 3430 | |
| 3428 | defer slice.deinit(gpa); | 3431 | for (entries.items, 0..) |entry, i| { |
| 3429 | | 3432 | backlinks[entry.shndx] = @intCast(i); |
| 3430 | try self.sections.ensureTotalCapacity(gpa, slice.len); | 3433 | self.sections.set(i, slice.get(entry.shndx)); |
| 3431 | for (entries.items) |sorted| { | 3434 | } |
| 3432 | self.sections.appendAssumeCapacity(slice.get(sorted.shndx)); | 3435 | } |
| 3433 | } | 3436 | |
| 3434 | | 3437 | const special_indexes = &self.section_indexes; |
| 3435 | self.resetShdrIndexes(backlinks); | 3438 | |
| 3436 | } | 3439 | inline for (@typeInfo(SectionIndexes).@"struct".fields) |field| { |
| 3437 | | 3440 | if (@field(special_indexes, field.name)) |special_index| { |
| 3438 | fn resetShdrIndexes(self: *Elf, backlinks: []const u32) void { | 3441 | @field(special_indexes, field.name) = backlinks[special_index]; |
| 3439 | for (&[_]*?u32{ | | |
| 3440 | &self.eh_frame_section_index, | | |
| 3441 | &self.eh_frame_rela_section_index, | | |
| 3442 | &self.eh_frame_hdr_section_index, | | |
| 3443 | &self.got_section_index, | | |
| 3444 | &self.symtab_section_index, | | |
| 3445 | &self.strtab_section_index, | | |
| 3446 | &self.shstrtab_section_index, | | |
| 3447 | &self.interp_section_index, | | |
| 3448 | &self.dynamic_section_index, | | |
| 3449 | &self.dynsymtab_section_index, | | |
| 3450 | &self.dynstrtab_section_index, | | |
| 3451 | &self.hash_section_index, | | |
| 3452 | &self.gnu_hash_section_index, | | |
| 3453 | &self.plt_section_index, | | |
| 3454 | &self.got_plt_section_index, | | |
| 3455 | &self.plt_got_section_index, | | |
| 3456 | &self.rela_dyn_section_index, | | |
| 3457 | &self.rela_plt_section_index, | | |
| 3458 | &self.copy_rel_section_index, | | |
| 3459 | &self.versym_section_index, | | |
| 3460 | &self.verneed_section_index, | | |
| 3461 | }) |maybe_index| { | | |
| 3462 | if (maybe_index.*) |*index| { | | |
| 3463 | index.* = backlinks[index.*]; | | |
| 3464 | } | 3442 | } |
| 3465 | } | 3443 | } |
| 3466 | | 3444 | |
| ... | @@ -3478,7 +3456,7 @@ fn resetShdrIndexes(self: *Elf, backlinks: []const u32) void { | ... | @@ -3478,7 +3456,7 @@ fn resetShdrIndexes(self: *Elf, backlinks: []const u32) void { |
| 3478 | // FIXME:JK we should spin up .symtab potentially earlier, or set all non-dynamic RELA sections | 3456 | // FIXME:JK we should spin up .symtab potentially earlier, or set all non-dynamic RELA sections |
| 3479 | // to point at symtab | 3457 | // to point at symtab |
| 3480 | // shdr.sh_link = backlinks[shdr.sh_link]; | 3458 | // shdr.sh_link = backlinks[shdr.sh_link]; |
| 3481 | shdr.sh_link = self.symtab_section_index.?; | 3459 | shdr.sh_link = self.section_indexes.symtab.?; |
| 3482 | shdr.sh_info = backlinks[shdr.sh_info]; | 3460 | shdr.sh_info = backlinks[shdr.sh_info]; |
| 3483 | } | 3461 | } |
| 3484 | } | 3462 | } |
| ... | @@ -3489,56 +3467,56 @@ fn resetShdrIndexes(self: *Elf, backlinks: []const u32) void { | ... | @@ -3489,56 +3467,56 @@ fn resetShdrIndexes(self: *Elf, backlinks: []const u32) void { |
| 3489 | cg.shndx = backlinks[cg.shndx]; | 3467 | cg.shndx = backlinks[cg.shndx]; |
| 3490 | } | 3468 | } |
| 3491 | | 3469 | |
| 3492 | if (self.symtab_section_index) |index| { | 3470 | if (self.section_indexes.symtab) |index| { |
| 3493 | const shdr = &slice.items(.shdr)[index]; | 3471 | const shdr = &slice.items(.shdr)[index]; |
| 3494 | shdr.sh_link = self.strtab_section_index.?; | 3472 | shdr.sh_link = self.section_indexes.strtab.?; |
| 3495 | } | 3473 | } |
| 3496 | | 3474 | |
| 3497 | if (self.dynamic_section_index) |index| { | 3475 | if (self.section_indexes.dynamic) |index| { |
| 3498 | const shdr = &slice.items(.shdr)[index]; | 3476 | const shdr = &slice.items(.shdr)[index]; |
| 3499 | shdr.sh_link = self.dynstrtab_section_index.?; | 3477 | shdr.sh_link = self.section_indexes.dynstrtab.?; |
| 3500 | } | 3478 | } |
| 3501 | | 3479 | |
| 3502 | if (self.dynsymtab_section_index) |index| { | 3480 | if (self.section_indexes.dynsymtab) |index| { |
| 3503 | const shdr = &slice.items(.shdr)[index]; | 3481 | const shdr = &slice.items(.shdr)[index]; |
| 3504 | shdr.sh_link = self.dynstrtab_section_index.?; | 3482 | shdr.sh_link = self.section_indexes.dynstrtab.?; |
| 3505 | } | 3483 | } |
| 3506 | | 3484 | |
| 3507 | if (self.hash_section_index) |index| { | 3485 | if (self.section_indexes.hash) |index| { |
| 3508 | const shdr = &slice.items(.shdr)[index]; | 3486 | const shdr = &slice.items(.shdr)[index]; |
| 3509 | shdr.sh_link = self.dynsymtab_section_index.?; | 3487 | shdr.sh_link = self.section_indexes.dynsymtab.?; |
| 3510 | } | 3488 | } |
| 3511 | | 3489 | |
| 3512 | if (self.gnu_hash_section_index) |index| { | 3490 | if (self.section_indexes.gnu_hash) |index| { |
| 3513 | const shdr = &slice.items(.shdr)[index]; | 3491 | const shdr = &slice.items(.shdr)[index]; |
| 3514 | shdr.sh_link = self.dynsymtab_section_index.?; | 3492 | shdr.sh_link = self.section_indexes.dynsymtab.?; |
| 3515 | } | 3493 | } |
| 3516 | | 3494 | |
| 3517 | if (self.versym_section_index) |index| { | 3495 | if (self.section_indexes.versym) |index| { |
| 3518 | const shdr = &slice.items(.shdr)[index]; | 3496 | const shdr = &slice.items(.shdr)[index]; |
| 3519 | shdr.sh_link = self.dynsymtab_section_index.?; | 3497 | shdr.sh_link = self.section_indexes.dynsymtab.?; |
| 3520 | } | 3498 | } |
| 3521 | | 3499 | |
| 3522 | if (self.verneed_section_index) |index| { | 3500 | if (self.section_indexes.verneed) |index| { |
| 3523 | const shdr = &slice.items(.shdr)[index]; | 3501 | const shdr = &slice.items(.shdr)[index]; |
| 3524 | shdr.sh_link = self.dynstrtab_section_index.?; | 3502 | shdr.sh_link = self.section_indexes.dynstrtab.?; |
| 3525 | } | 3503 | } |
| 3526 | | 3504 | |
| 3527 | if (self.rela_dyn_section_index) |index| { | 3505 | if (self.section_indexes.rela_dyn) |index| { |
| 3528 | const shdr = &slice.items(.shdr)[index]; | 3506 | const shdr = &slice.items(.shdr)[index]; |
| 3529 | shdr.sh_link = self.dynsymtab_section_index orelse 0; | 3507 | shdr.sh_link = self.section_indexes.dynsymtab orelse 0; |
| 3530 | } | 3508 | } |
| 3531 | | 3509 | |
| 3532 | if (self.rela_plt_section_index) |index| { | 3510 | if (self.section_indexes.rela_plt) |index| { |
| 3533 | const shdr = &slice.items(.shdr)[index]; | 3511 | const shdr = &slice.items(.shdr)[index]; |
| 3534 | shdr.sh_link = self.dynsymtab_section_index.?; | 3512 | shdr.sh_link = self.section_indexes.dynsymtab.?; |
| 3535 | shdr.sh_info = self.plt_section_index.?; | 3513 | shdr.sh_info = self.section_indexes.plt.?; |
| 3536 | } | 3514 | } |
| 3537 | | 3515 | |
| 3538 | if (self.eh_frame_rela_section_index) |index| { | 3516 | if (self.section_indexes.eh_frame_rela) |index| { |
| 3539 | const shdr = &slice.items(.shdr)[index]; | 3517 | const shdr = &slice.items(.shdr)[index]; |
| 3540 | shdr.sh_link = self.symtab_section_index.?; | 3518 | shdr.sh_link = self.section_indexes.symtab.?; |
| 3541 | shdr.sh_info = self.eh_frame_section_index.?; | 3519 | shdr.sh_info = self.section_indexes.eh_frame.?; |
| 3542 | } | 3520 | } |
| 3543 | } | 3521 | } |
| 3544 | | 3522 | |
| ... | @@ -3572,31 +3550,31 @@ fn updateSectionSizes(self: *Elf) !void { | ... | @@ -3572,31 +3550,31 @@ fn updateSectionSizes(self: *Elf) !void { |
| 3572 | } | 3550 | } |
| 3573 | | 3551 | |
| 3574 | const shdrs = slice.items(.shdr); | 3552 | const shdrs = slice.items(.shdr); |
| 3575 | if (self.eh_frame_section_index) |index| { | 3553 | if (self.section_indexes.eh_frame) |index| { |
| 3576 | shdrs[index].sh_size = try eh_frame.calcEhFrameSize(self); | 3554 | shdrs[index].sh_size = try eh_frame.calcEhFrameSize(self); |
| 3577 | } | 3555 | } |
| 3578 | | 3556 | |
| 3579 | if (self.eh_frame_hdr_section_index) |index| { | 3557 | if (self.section_indexes.eh_frame_hdr) |index| { |
| 3580 | shdrs[index].sh_size = eh_frame.calcEhFrameHdrSize(self); | 3558 | shdrs[index].sh_size = eh_frame.calcEhFrameHdrSize(self); |
| 3581 | } | 3559 | } |
| 3582 | | 3560 | |
| 3583 | if (self.got_section_index) |index| { | 3561 | if (self.section_indexes.got) |index| { |
| 3584 | shdrs[index].sh_size = self.got.size(self); | 3562 | shdrs[index].sh_size = self.got.size(self); |
| 3585 | } | 3563 | } |
| 3586 | | 3564 | |
| 3587 | if (self.plt_section_index) |index| { | 3565 | if (self.section_indexes.plt) |index| { |
| 3588 | shdrs[index].sh_size = self.plt.size(self); | 3566 | shdrs[index].sh_size = self.plt.size(self); |
| 3589 | } | 3567 | } |
| 3590 | | 3568 | |
| 3591 | if (self.got_plt_section_index) |index| { | 3569 | if (self.section_indexes.got_plt) |index| { |
| 3592 | shdrs[index].sh_size = self.got_plt.size(self); | 3570 | shdrs[index].sh_size = self.got_plt.size(self); |
| 3593 | } | 3571 | } |
| 3594 | | 3572 | |
| 3595 | if (self.plt_got_section_index) |index| { | 3573 | if (self.section_indexes.plt_got) |index| { |
| 3596 | shdrs[index].sh_size = self.plt_got.size(self); | 3574 | shdrs[index].sh_size = self.plt_got.size(self); |
| 3597 | } | 3575 | } |
| 3598 | | 3576 | |
| 3599 | if (self.rela_dyn_section_index) |shndx| { | 3577 | if (self.section_indexes.rela_dyn) |shndx| { |
| 3600 | var num = self.got.numRela(self) + self.copy_rel.numRela(); | 3578 | var num = self.got.numRela(self) + self.copy_rel.numRela(); |
| 3601 | if (self.zigObjectPtr()) |zig_object| { | 3579 | if (self.zigObjectPtr()) |zig_object| { |
| 3602 | num += zig_object.num_dynrelocs; | 3580 | num += zig_object.num_dynrelocs; |
| ... | @@ -3607,43 +3585,43 @@ fn updateSectionSizes(self: *Elf) !void { | ... | @@ -3607,43 +3585,43 @@ fn updateSectionSizes(self: *Elf) !void { |
| 3607 | shdrs[shndx].sh_size = num * @sizeOf(elf.Elf64_Rela); | 3585 | shdrs[shndx].sh_size = num * @sizeOf(elf.Elf64_Rela); |
| 3608 | } | 3586 | } |
| 3609 | | 3587 | |
| 3610 | if (self.rela_plt_section_index) |index| { | 3588 | if (self.section_indexes.rela_plt) |index| { |
| 3611 | shdrs[index].sh_size = self.plt.numRela() * @sizeOf(elf.Elf64_Rela); | 3589 | shdrs[index].sh_size = self.plt.numRela() * @sizeOf(elf.Elf64_Rela); |
| 3612 | } | 3590 | } |
| 3613 | | 3591 | |
| 3614 | if (self.copy_rel_section_index) |index| { | 3592 | if (self.section_indexes.copy_rel) |index| { |
| 3615 | try self.copy_rel.updateSectionSize(index, self); | 3593 | try self.copy_rel.updateSectionSize(index, self); |
| 3616 | } | 3594 | } |
| 3617 | | 3595 | |
| 3618 | if (self.interp_section_index) |index| { | 3596 | if (self.section_indexes.interp) |index| { |
| 3619 | shdrs[index].sh_size = self.getTarget().dynamic_linker.get().?.len + 1; | 3597 | shdrs[index].sh_size = self.getTarget().dynamic_linker.get().?.len + 1; |
| 3620 | } | 3598 | } |
| 3621 | | 3599 | |
| 3622 | if (self.hash_section_index) |index| { | 3600 | if (self.section_indexes.hash) |index| { |
| 3623 | shdrs[index].sh_size = self.hash.size(); | 3601 | shdrs[index].sh_size = self.hash.size(); |
| 3624 | } | 3602 | } |
| 3625 | | 3603 | |
| 3626 | if (self.gnu_hash_section_index) |index| { | 3604 | if (self.section_indexes.gnu_hash) |index| { |
| 3627 | shdrs[index].sh_size = self.gnu_hash.size(); | 3605 | shdrs[index].sh_size = self.gnu_hash.size(); |
| 3628 | } | 3606 | } |
| 3629 | | 3607 | |
| 3630 | if (self.dynamic_section_index) |index| { | 3608 | if (self.section_indexes.dynamic) |index| { |
| 3631 | shdrs[index].sh_size = self.dynamic.size(self); | 3609 | shdrs[index].sh_size = self.dynamic.size(self); |
| 3632 | } | 3610 | } |
| 3633 | | 3611 | |
| 3634 | if (self.dynsymtab_section_index) |index| { | 3612 | if (self.section_indexes.dynsymtab) |index| { |
| 3635 | shdrs[index].sh_size = self.dynsym.size(); | 3613 | shdrs[index].sh_size = self.dynsym.size(); |
| 3636 | } | 3614 | } |
| 3637 | | 3615 | |
| 3638 | if (self.dynstrtab_section_index) |index| { | 3616 | if (self.section_indexes.dynstrtab) |index| { |
| 3639 | shdrs[index].sh_size = self.dynstrtab.items.len; | 3617 | shdrs[index].sh_size = self.dynstrtab.items.len; |
| 3640 | } | 3618 | } |
| 3641 | | 3619 | |
| 3642 | if (self.versym_section_index) |index| { | 3620 | if (self.section_indexes.versym) |index| { |
| 3643 | shdrs[index].sh_size = self.versym.items.len * @sizeOf(elf.Elf64_Versym); | 3621 | shdrs[index].sh_size = self.versym.items.len * @sizeOf(elf.Elf64_Versym); |
| 3644 | } | 3622 | } |
| 3645 | | 3623 | |
| 3646 | if (self.verneed_section_index) |index| { | 3624 | if (self.section_indexes.verneed) |index| { |
| 3647 | shdrs[index].sh_size = self.verneed.size(); | 3625 | shdrs[index].sh_size = self.verneed.size(); |
| 3648 | } | 3626 | } |
| 3649 | | 3627 | |
| ... | @@ -3653,7 +3631,7 @@ fn updateSectionSizes(self: *Elf) !void { | ... | @@ -3653,7 +3631,7 @@ fn updateSectionSizes(self: *Elf) !void { |
| 3653 | | 3631 | |
| 3654 | // FIXME:JK this is very much obsolete, remove! | 3632 | // FIXME:JK this is very much obsolete, remove! |
| 3655 | pub fn updateShStrtabSize(self: *Elf) void { | 3633 | pub fn updateShStrtabSize(self: *Elf) void { |
| 3656 | if (self.shstrtab_section_index) |index| { | 3634 | if (self.section_indexes.shstrtab) |index| { |
| 3657 | self.sections.items(.shdr)[index].sh_size = self.shstrtab.items.len; | 3635 | self.sections.items(.shdr)[index].sh_size = self.shstrtab.items.len; |
| 3658 | } | 3636 | } |
| 3659 | } | 3637 | } |
| ... | @@ -3936,9 +3914,9 @@ fn allocateSpecialPhdrs(self: *Elf) void { | ... | @@ -3936,9 +3914,9 @@ fn allocateSpecialPhdrs(self: *Elf) void { |
| 3936 | const slice = self.sections.slice(); | 3914 | const slice = self.sections.slice(); |
| 3937 | | 3915 | |
| 3938 | for (&[_]struct { OptionalProgramHeaderIndex, ?u32 }{ | 3916 | for (&[_]struct { OptionalProgramHeaderIndex, ?u32 }{ |
| 3939 | .{ self.phdr_indexes.interp, self.interp_section_index }, | 3917 | .{ self.phdr_indexes.interp, self.section_indexes.interp }, |
| 3940 | .{ self.phdr_indexes.dynamic, self.dynamic_section_index }, | 3918 | .{ self.phdr_indexes.dynamic, self.section_indexes.dynamic }, |
| 3941 | .{ self.phdr_indexes.gnu_eh_frame, self.eh_frame_hdr_section_index }, | 3919 | .{ self.phdr_indexes.gnu_eh_frame, self.section_indexes.eh_frame_hdr }, |
| 3942 | }) |pair| { | 3920 | }) |pair| { |
| 3943 | if (pair[0].int()) |index| { | 3921 | if (pair[0].int()) |index| { |
| 3944 | const shdr = slice.items(.shdr)[pair[1].?]; | 3922 | const shdr = slice.items(.shdr)[pair[1].?]; |
| ... | @@ -4075,7 +4053,7 @@ pub fn updateSymtabSize(self: *Elf) !void { | ... | @@ -4075,7 +4053,7 @@ pub fn updateSymtabSize(self: *Elf) !void { |
| 4075 | strsize += ctx.strsize; | 4053 | strsize += ctx.strsize; |
| 4076 | } | 4054 | } |
| 4077 | | 4055 | |
| 4078 | if (self.got_section_index) |_| { | 4056 | if (self.section_indexes.got) |_| { |
| 4079 | self.got.output_symtab_ctx.reset(); | 4057 | self.got.output_symtab_ctx.reset(); |
| 4080 | self.got.output_symtab_ctx.ilocal = nlocals; | 4058 | self.got.output_symtab_ctx.ilocal = nlocals; |
| 4081 | self.got.updateSymtabSize(self); | 4059 | self.got.updateSymtabSize(self); |
| ... | @@ -4083,7 +4061,7 @@ pub fn updateSymtabSize(self: *Elf) !void { | ... | @@ -4083,7 +4061,7 @@ pub fn updateSymtabSize(self: *Elf) !void { |
| 4083 | strsize += self.got.output_symtab_ctx.strsize; | 4061 | strsize += self.got.output_symtab_ctx.strsize; |
| 4084 | } | 4062 | } |
| 4085 | | 4063 | |
| 4086 | if (self.plt_section_index) |_| { | 4064 | if (self.section_indexes.plt) |_| { |
| 4087 | self.plt.output_symtab_ctx.reset(); | 4065 | self.plt.output_symtab_ctx.reset(); |
| 4088 | self.plt.output_symtab_ctx.ilocal = nlocals; | 4066 | self.plt.output_symtab_ctx.ilocal = nlocals; |
| 4089 | self.plt.updateSymtabSize(self); | 4067 | self.plt.updateSymtabSize(self); |
| ... | @@ -4091,7 +4069,7 @@ pub fn updateSymtabSize(self: *Elf) !void { | ... | @@ -4091,7 +4069,7 @@ pub fn updateSymtabSize(self: *Elf) !void { |
| 4091 | strsize += self.plt.output_symtab_ctx.strsize; | 4069 | strsize += self.plt.output_symtab_ctx.strsize; |
| 4092 | } | 4070 | } |
| 4093 | | 4071 | |
| 4094 | if (self.plt_got_section_index) |_| { | 4072 | if (self.section_indexes.plt_got) |_| { |
| 4095 | self.plt_got.output_symtab_ctx.reset(); | 4073 | self.plt_got.output_symtab_ctx.reset(); |
| 4096 | self.plt_got.output_symtab_ctx.ilocal = nlocals; | 4074 | self.plt_got.output_symtab_ctx.ilocal = nlocals; |
| 4097 | self.plt_got.updateSymtabSize(self); | 4075 | self.plt_got.updateSymtabSize(self); |
| ... | @@ -4108,9 +4086,9 @@ pub fn updateSymtabSize(self: *Elf) !void { | ... | @@ -4108,9 +4086,9 @@ pub fn updateSymtabSize(self: *Elf) !void { |
| 4108 | } | 4086 | } |
| 4109 | | 4087 | |
| 4110 | const slice = self.sections.slice(); | 4088 | const slice = self.sections.slice(); |
| 4111 | const symtab_shdr = &slice.items(.shdr)[self.symtab_section_index.?]; | 4089 | const symtab_shdr = &slice.items(.shdr)[self.section_indexes.symtab.?]; |
| 4112 | symtab_shdr.sh_info = nlocals; | 4090 | symtab_shdr.sh_info = nlocals; |
| 4113 | symtab_shdr.sh_link = self.strtab_section_index.?; | 4091 | symtab_shdr.sh_link = self.section_indexes.strtab.?; |
| 4114 | | 4092 | |
| 4115 | const sym_size: u64 = switch (self.ptr_width) { | 4093 | const sym_size: u64 = switch (self.ptr_width) { |
| 4116 | .p32 => @sizeOf(elf.Elf32_Sym), | 4094 | .p32 => @sizeOf(elf.Elf32_Sym), |
| ... | @@ -4119,7 +4097,7 @@ pub fn updateSymtabSize(self: *Elf) !void { | ... | @@ -4119,7 +4097,7 @@ pub fn updateSymtabSize(self: *Elf) !void { |
| 4119 | const needed_size = (nlocals + nglobals) * sym_size; | 4097 | const needed_size = (nlocals + nglobals) * sym_size; |
| 4120 | symtab_shdr.sh_size = needed_size; | 4098 | symtab_shdr.sh_size = needed_size; |
| 4121 | | 4099 | |
| 4122 | const strtab = &slice.items(.shdr)[self.strtab_section_index.?]; | 4100 | const strtab = &slice.items(.shdr)[self.section_indexes.strtab.?]; |
| 4123 | strtab.sh_size = strsize + 1; | 4101 | strtab.sh_size = strsize + 1; |
| 4124 | } | 4102 | } |
| 4125 | | 4103 | |
| ... | @@ -4127,7 +4105,7 @@ fn writeSyntheticSections(self: *Elf) !void { | ... | @@ -4127,7 +4105,7 @@ fn writeSyntheticSections(self: *Elf) !void { |
| 4127 | const gpa = self.base.comp.gpa; | 4105 | const gpa = self.base.comp.gpa; |
| 4128 | const slice = self.sections.slice(); | 4106 | const slice = self.sections.slice(); |
| 4129 | | 4107 | |
| 4130 | if (self.interp_section_index) |shndx| { | 4108 | if (self.section_indexes.interp) |shndx| { |
| 4131 | var buffer: [256]u8 = undefined; | 4109 | var buffer: [256]u8 = undefined; |
| 4132 | const interp = self.getTarget().dynamic_linker.get().?; | 4110 | const interp = self.getTarget().dynamic_linker.get().?; |
| 4133 | @memcpy(buffer[0..interp.len], interp); | 4111 | @memcpy(buffer[0..interp.len], interp); |
| ... | @@ -4138,12 +4116,12 @@ fn writeSyntheticSections(self: *Elf) !void { | ... | @@ -4138,12 +4116,12 @@ fn writeSyntheticSections(self: *Elf) !void { |
| 4138 | try self.base.file.?.pwriteAll(contents, shdr.sh_offset); | 4116 | try self.base.file.?.pwriteAll(contents, shdr.sh_offset); |
| 4139 | } | 4117 | } |
| 4140 | | 4118 | |
| 4141 | if (self.hash_section_index) |shndx| { | 4119 | if (self.section_indexes.hash) |shndx| { |
| 4142 | const shdr = slice.items(.shdr)[shndx]; | 4120 | const shdr = slice.items(.shdr)[shndx]; |
| 4143 | try self.base.file.?.pwriteAll(self.hash.buffer.items, shdr.sh_offset); | 4121 | try self.base.file.?.pwriteAll(self.hash.buffer.items, shdr.sh_offset); |
| 4144 | } | 4122 | } |
| 4145 | | 4123 | |
| 4146 | if (self.gnu_hash_section_index) |shndx| { | 4124 | if (self.section_indexes.gnu_hash) |shndx| { |
| 4147 | const shdr = slice.items(.shdr)[shndx]; | 4125 | const shdr = slice.items(.shdr)[shndx]; |
| 4148 | var buffer = try std.ArrayList(u8).initCapacity(gpa, self.gnu_hash.size()); | 4126 | var buffer = try std.ArrayList(u8).initCapacity(gpa, self.gnu_hash.size()); |
| 4149 | defer buffer.deinit(); | 4127 | defer buffer.deinit(); |
| ... | @@ -4151,12 +4129,12 @@ fn writeSyntheticSections(self: *Elf) !void { | ... | @@ -4151,12 +4129,12 @@ fn writeSyntheticSections(self: *Elf) !void { |
| 4151 | try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset); | 4129 | try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset); |
| 4152 | } | 4130 | } |
| 4153 | | 4131 | |
| 4154 | if (self.versym_section_index) |shndx| { | 4132 | if (self.section_indexes.versym) |shndx| { |
| 4155 | const shdr = slice.items(.shdr)[shndx]; | 4133 | const shdr = slice.items(.shdr)[shndx]; |
| 4156 | try self.base.file.?.pwriteAll(mem.sliceAsBytes(self.versym.items), shdr.sh_offset); | 4134 | try self.base.file.?.pwriteAll(mem.sliceAsBytes(self.versym.items), shdr.sh_offset); |
| 4157 | } | 4135 | } |
| 4158 | | 4136 | |
| 4159 | if (self.verneed_section_index) |shndx| { | 4137 | if (self.section_indexes.verneed) |shndx| { |
| 4160 | const shdr = slice.items(.shdr)[shndx]; | 4138 | const shdr = slice.items(.shdr)[shndx]; |
| 4161 | var buffer = try std.ArrayList(u8).initCapacity(gpa, self.verneed.size()); | 4139 | var buffer = try std.ArrayList(u8).initCapacity(gpa, self.verneed.size()); |
| 4162 | defer buffer.deinit(); | 4140 | defer buffer.deinit(); |
| ... | @@ -4164,7 +4142,7 @@ fn writeSyntheticSections(self: *Elf) !void { | ... | @@ -4164,7 +4142,7 @@ fn writeSyntheticSections(self: *Elf) !void { |
| 4164 | try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset); | 4142 | try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset); |
| 4165 | } | 4143 | } |
| 4166 | | 4144 | |
| 4167 | if (self.dynamic_section_index) |shndx| { | 4145 | if (self.section_indexes.dynamic) |shndx| { |
| 4168 | const shdr = slice.items(.shdr)[shndx]; | 4146 | const shdr = slice.items(.shdr)[shndx]; |
| 4169 | var buffer = try std.ArrayList(u8).initCapacity(gpa, self.dynamic.size(self)); | 4147 | var buffer = try std.ArrayList(u8).initCapacity(gpa, self.dynamic.size(self)); |
| 4170 | defer buffer.deinit(); | 4148 | defer buffer.deinit(); |
| ... | @@ -4172,7 +4150,7 @@ fn writeSyntheticSections(self: *Elf) !void { | ... | @@ -4172,7 +4150,7 @@ fn writeSyntheticSections(self: *Elf) !void { |
| 4172 | try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset); | 4150 | try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset); |
| 4173 | } | 4151 | } |
| 4174 | | 4152 | |
| 4175 | if (self.dynsymtab_section_index) |shndx| { | 4153 | if (self.section_indexes.dynsymtab) |shndx| { |
| 4176 | const shdr = slice.items(.shdr)[shndx]; | 4154 | const shdr = slice.items(.shdr)[shndx]; |
| 4177 | var buffer = try std.ArrayList(u8).initCapacity(gpa, self.dynsym.size()); | 4155 | var buffer = try std.ArrayList(u8).initCapacity(gpa, self.dynsym.size()); |
| 4178 | defer buffer.deinit(); | 4156 | defer buffer.deinit(); |
| ... | @@ -4180,12 +4158,12 @@ fn writeSyntheticSections(self: *Elf) !void { | ... | @@ -4180,12 +4158,12 @@ fn writeSyntheticSections(self: *Elf) !void { |
| 4180 | try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset); | 4158 | try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset); |
| 4181 | } | 4159 | } |
| 4182 | | 4160 | |
| 4183 | if (self.dynstrtab_section_index) |shndx| { | 4161 | if (self.section_indexes.dynstrtab) |shndx| { |
| 4184 | const shdr = slice.items(.shdr)[shndx]; | 4162 | const shdr = slice.items(.shdr)[shndx]; |
| 4185 | try self.base.file.?.pwriteAll(self.dynstrtab.items, shdr.sh_offset); | 4163 | try self.base.file.?.pwriteAll(self.dynstrtab.items, shdr.sh_offset); |
| 4186 | } | 4164 | } |
| 4187 | | 4165 | |
| 4188 | if (self.eh_frame_section_index) |shndx| { | 4166 | if (self.section_indexes.eh_frame) |shndx| { |
| 4189 | const existing_size = existing_size: { | 4167 | const existing_size = existing_size: { |
| 4190 | const zo = self.zigObjectPtr() orelse break :existing_size 0; | 4168 | const zo = self.zigObjectPtr() orelse break :existing_size 0; |
| 4191 | const sym = zo.symbol(zo.eh_frame_index orelse break :existing_size 0); | 4169 | const sym = zo.symbol(zo.eh_frame_index orelse break :existing_size 0); |
| ... | @@ -4200,7 +4178,7 @@ fn writeSyntheticSections(self: *Elf) !void { | ... | @@ -4200,7 +4178,7 @@ fn writeSyntheticSections(self: *Elf) !void { |
| 4200 | try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset + existing_size); | 4178 | try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset + existing_size); |
| 4201 | } | 4179 | } |
| 4202 | | 4180 | |
| 4203 | if (self.eh_frame_hdr_section_index) |shndx| { | 4181 | if (self.section_indexes.eh_frame_hdr) |shndx| { |
| 4204 | const shdr = slice.items(.shdr)[shndx]; | 4182 | const shdr = slice.items(.shdr)[shndx]; |
| 4205 | const sh_size = math.cast(usize, shdr.sh_size) orelse return error.Overflow; | 4183 | const sh_size = math.cast(usize, shdr.sh_size) orelse return error.Overflow; |
| 4206 | var buffer = try std.ArrayList(u8).initCapacity(gpa, sh_size); | 4184 | var buffer = try std.ArrayList(u8).initCapacity(gpa, sh_size); |
| ... | @@ -4209,7 +4187,7 @@ fn writeSyntheticSections(self: *Elf) !void { | ... | @@ -4209,7 +4187,7 @@ fn writeSyntheticSections(self: *Elf) !void { |
| 4209 | try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset); | 4187 | try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset); |
| 4210 | } | 4188 | } |
| 4211 | | 4189 | |
| 4212 | if (self.got_section_index) |index| { | 4190 | if (self.section_indexes.got) |index| { |
| 4213 | const shdr = slice.items(.shdr)[index]; | 4191 | const shdr = slice.items(.shdr)[index]; |
| 4214 | var buffer = try std.ArrayList(u8).initCapacity(gpa, self.got.size(self)); | 4192 | var buffer = try std.ArrayList(u8).initCapacity(gpa, self.got.size(self)); |
| 4215 | defer buffer.deinit(); | 4193 | defer buffer.deinit(); |
| ... | @@ -4217,7 +4195,7 @@ fn writeSyntheticSections(self: *Elf) !void { | ... | @@ -4217,7 +4195,7 @@ fn writeSyntheticSections(self: *Elf) !void { |
| 4217 | try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset); | 4195 | try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset); |
| 4218 | } | 4196 | } |
| 4219 | | 4197 | |
| 4220 | if (self.rela_dyn_section_index) |shndx| { | 4198 | if (self.section_indexes.rela_dyn) |shndx| { |
| 4221 | const shdr = slice.items(.shdr)[shndx]; | 4199 | const shdr = slice.items(.shdr)[shndx]; |
| 4222 | try self.got.addRela(self); | 4200 | try self.got.addRela(self); |
| 4223 | try self.copy_rel.addRela(self); | 4201 | try self.copy_rel.addRela(self); |
| ... | @@ -4225,7 +4203,7 @@ fn writeSyntheticSections(self: *Elf) !void { | ... | @@ -4225,7 +4203,7 @@ fn writeSyntheticSections(self: *Elf) !void { |
| 4225 | try self.base.file.?.pwriteAll(mem.sliceAsBytes(self.rela_dyn.items), shdr.sh_offset); | 4203 | try self.base.file.?.pwriteAll(mem.sliceAsBytes(self.rela_dyn.items), shdr.sh_offset); |
| 4226 | } | 4204 | } |
| 4227 | | 4205 | |
| 4228 | if (self.plt_section_index) |shndx| { | 4206 | if (self.section_indexes.plt) |shndx| { |
| 4229 | const shdr = slice.items(.shdr)[shndx]; | 4207 | const shdr = slice.items(.shdr)[shndx]; |
| 4230 | var buffer = try std.ArrayList(u8).initCapacity(gpa, self.plt.size(self)); | 4208 | var buffer = try std.ArrayList(u8).initCapacity(gpa, self.plt.size(self)); |
| 4231 | defer buffer.deinit(); | 4209 | defer buffer.deinit(); |
| ... | @@ -4233,7 +4211,7 @@ fn writeSyntheticSections(self: *Elf) !void { | ... | @@ -4233,7 +4211,7 @@ fn writeSyntheticSections(self: *Elf) !void { |
| 4233 | try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset); | 4211 | try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset); |
| 4234 | } | 4212 | } |
| 4235 | | 4213 | |
| 4236 | if (self.got_plt_section_index) |shndx| { | 4214 | if (self.section_indexes.got_plt) |shndx| { |
| 4237 | const shdr = slice.items(.shdr)[shndx]; | 4215 | const shdr = slice.items(.shdr)[shndx]; |
| 4238 | var buffer = try std.ArrayList(u8).initCapacity(gpa, self.got_plt.size(self)); | 4216 | var buffer = try std.ArrayList(u8).initCapacity(gpa, self.got_plt.size(self)); |
| 4239 | defer buffer.deinit(); | 4217 | defer buffer.deinit(); |
| ... | @@ -4241,7 +4219,7 @@ fn writeSyntheticSections(self: *Elf) !void { | ... | @@ -4241,7 +4219,7 @@ fn writeSyntheticSections(self: *Elf) !void { |
| 4241 | try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset); | 4219 | try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset); |
| 4242 | } | 4220 | } |
| 4243 | | 4221 | |
| 4244 | if (self.plt_got_section_index) |shndx| { | 4222 | if (self.section_indexes.plt_got) |shndx| { |
| 4245 | const shdr = slice.items(.shdr)[shndx]; | 4223 | const shdr = slice.items(.shdr)[shndx]; |
| 4246 | var buffer = try std.ArrayList(u8).initCapacity(gpa, self.plt_got.size(self)); | 4224 | var buffer = try std.ArrayList(u8).initCapacity(gpa, self.plt_got.size(self)); |
| 4247 | defer buffer.deinit(); | 4225 | defer buffer.deinit(); |
| ... | @@ -4249,7 +4227,7 @@ fn writeSyntheticSections(self: *Elf) !void { | ... | @@ -4249,7 +4227,7 @@ fn writeSyntheticSections(self: *Elf) !void { |
| 4249 | try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset); | 4227 | try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset); |
| 4250 | } | 4228 | } |
| 4251 | | 4229 | |
| 4252 | if (self.rela_plt_section_index) |shndx| { | 4230 | if (self.section_indexes.rela_plt) |shndx| { |
| 4253 | const shdr = slice.items(.shdr)[shndx]; | 4231 | const shdr = slice.items(.shdr)[shndx]; |
| 4254 | try self.plt.addRela(self); | 4232 | try self.plt.addRela(self); |
| 4255 | try self.base.file.?.pwriteAll(mem.sliceAsBytes(self.rela_plt.items), shdr.sh_offset); | 4233 | try self.base.file.?.pwriteAll(mem.sliceAsBytes(self.rela_plt.items), shdr.sh_offset); |
| ... | @@ -4261,7 +4239,7 @@ fn writeSyntheticSections(self: *Elf) !void { | ... | @@ -4261,7 +4239,7 @@ fn writeSyntheticSections(self: *Elf) !void { |
| 4261 | | 4239 | |
| 4262 | // FIXME:JK again, why is this needed? | 4240 | // FIXME:JK again, why is this needed? |
| 4263 | pub fn writeShStrtab(self: *Elf) !void { | 4241 | pub fn writeShStrtab(self: *Elf) !void { |
| 4264 | if (self.shstrtab_section_index) |index| { | 4242 | if (self.section_indexes.shstrtab) |index| { |
| 4265 | const shdr = self.sections.items(.shdr)[index]; | 4243 | const shdr = self.sections.items(.shdr)[index]; |
| 4266 | log.debug("writing .shstrtab from 0x{x} to 0x{x}", .{ shdr.sh_offset, shdr.sh_offset + shdr.sh_size }); | 4244 | log.debug("writing .shstrtab from 0x{x} to 0x{x}", .{ shdr.sh_offset, shdr.sh_offset + shdr.sh_size }); |
| 4267 | try self.base.file.?.pwriteAll(self.shstrtab.items, shdr.sh_offset); | 4245 | try self.base.file.?.pwriteAll(self.shstrtab.items, shdr.sh_offset); |
| ... | @@ -4271,8 +4249,8 @@ pub fn writeShStrtab(self: *Elf) !void { | ... | @@ -4271,8 +4249,8 @@ pub fn writeShStrtab(self: *Elf) !void { |
| 4271 | pub fn writeSymtab(self: *Elf) !void { | 4249 | pub fn writeSymtab(self: *Elf) !void { |
| 4272 | const gpa = self.base.comp.gpa; | 4250 | const gpa = self.base.comp.gpa; |
| 4273 | const slice = self.sections.slice(); | 4251 | const slice = self.sections.slice(); |
| 4274 | const symtab_shdr = slice.items(.shdr)[self.symtab_section_index.?]; | 4252 | const symtab_shdr = slice.items(.shdr)[self.section_indexes.symtab.?]; |
| 4275 | const strtab_shdr = slice.items(.shdr)[self.strtab_section_index.?]; | 4253 | const strtab_shdr = slice.items(.shdr)[self.section_indexes.strtab.?]; |
| 4276 | const sym_size: u64 = switch (self.ptr_width) { | 4254 | const sym_size: u64 = switch (self.ptr_width) { |
| 4277 | .p32 => @sizeOf(elf.Elf32_Sym), | 4255 | .p32 => @sizeOf(elf.Elf32_Sym), |
| 4278 | .p64 => @sizeOf(elf.Elf64_Sym), | 4256 | .p64 => @sizeOf(elf.Elf64_Sym), |
| ... | @@ -4330,15 +4308,15 @@ pub fn writeSymtab(self: *Elf) !void { | ... | @@ -4330,15 +4308,15 @@ pub fn writeSymtab(self: *Elf) !void { |
| 4330 | obj.asFile().writeSymtab(self); | 4308 | obj.asFile().writeSymtab(self); |
| 4331 | } | 4309 | } |
| 4332 | | 4310 | |
| 4333 | if (self.got_section_index) |_| { | 4311 | if (self.section_indexes.got) |_| { |
| 4334 | self.got.writeSymtab(self); | 4312 | self.got.writeSymtab(self); |
| 4335 | } | 4313 | } |
| 4336 | | 4314 | |
| 4337 | if (self.plt_section_index) |_| { | 4315 | if (self.section_indexes.plt) |_| { |
| 4338 | self.plt.writeSymtab(self); | 4316 | self.plt.writeSymtab(self); |
| 4339 | } | 4317 | } |
| 4340 | | 4318 | |
| 4341 | if (self.plt_got_section_index) |_| { | 4319 | if (self.section_indexes.plt_got) |_| { |
| 4342 | self.plt_got.writeSymtab(self); | 4320 | self.plt_got.writeSymtab(self); |
| 4343 | } | 4321 | } |
| 4344 | | 4322 | |
| ... | @@ -4778,9 +4756,9 @@ pub fn mergeSection(self: *Elf, index: MergeSection.Index) *MergeSection { | ... | @@ -4778,9 +4756,9 @@ pub fn mergeSection(self: *Elf, index: MergeSection.Index) *MergeSection { |
| 4778 | | 4756 | |
| 4779 | pub fn gotAddress(self: *Elf) i64 { | 4757 | pub fn gotAddress(self: *Elf) i64 { |
| 4780 | const shndx = blk: { | 4758 | const shndx = blk: { |
| 4781 | if (self.getTarget().cpu.arch == .x86_64 and self.got_plt_section_index != null) | 4759 | if (self.getTarget().cpu.arch == .x86_64 and self.section_indexes.got_plt != null) |
| 4782 | break :blk self.got_plt_section_index.?; | 4760 | break :blk self.section_indexes.got_plt.?; |
| 4783 | break :blk if (self.got_section_index) |shndx| shndx else null; | 4761 | break :blk if (self.section_indexes.got) |shndx| shndx else null; |
| 4784 | }; | 4762 | }; |
| 4785 | return if (shndx) |index| @intCast(self.sections.items(.shdr)[index].sh_addr) else 0; | 4763 | return if (shndx) |index| @intCast(self.sections.items(.shdr)[index].sh_addr) else 0; |
| 4786 | } | 4764 | } |