| ... | ... | @@ -1,3 +1,5 @@ |
| 1 | pub const Atom = @import("Elf/Atom.zig"); |
| 2 | |
| 1 | 3 | base: link.File, |
| 2 | 4 | rpath_table: std.StringArrayHashMapUnmanaged(void), |
| 3 | 5 | image_base: u64, |
| ... | ... | @@ -53,26 +55,11 @@ shdr_table_offset: ?u64 = null, |
| 53 | 55 | |
| 54 | 56 | /// Stored in native-endian format, depending on target endianness needs to be bswapped on read/write. |
| 55 | 57 | /// Same order as in the file. |
| 56 | | phdrs: std.ArrayListUnmanaged(elf.Elf64_Phdr) = .empty, |
| 57 | | |
| 58 | | /// Special program headers |
| 59 | | /// PT_PHDR |
| 60 | | phdr_table_index: ?u16 = null, |
| 61 | | /// PT_LOAD for PHDR table |
| 62 | | /// We add this special load segment to ensure the EHDR and PHDR table are always |
| 63 | | /// loaded into memory. |
| 64 | | phdr_table_load_index: ?u16 = null, |
| 65 | | /// PT_INTERP |
| 66 | | phdr_interp_index: ?u16 = null, |
| 67 | | /// PT_DYNAMIC |
| 68 | | phdr_dynamic_index: ?u16 = null, |
| 69 | | /// PT_GNU_EH_FRAME |
| 70 | | phdr_gnu_eh_frame_index: ?u16 = null, |
| 71 | | /// PT_GNU_STACK |
| 72 | | phdr_gnu_stack_index: ?u16 = null, |
| 73 | | /// PT_TLS |
| 74 | | /// TODO I think ELF permits multiple TLS segments but for now, assume one per file. |
| 75 | | phdr_tls_index: ?u16 = null, |
| 58 | phdrs: ProgramHeaderList = .empty, |
| 59 | |
| 60 | /// Special program headers. |
| 61 | phdr_indexes: ProgramHeaderIndexes = .{}, |
| 62 | section_indexes: SectionIndexes = .{}, |
| 76 | 63 | |
| 77 | 64 | page_size: u32, |
| 78 | 65 | default_sym_version: elf.Elf64_Versym, |
| ... | ... | @@ -115,29 +102,6 @@ rela_plt: std.ArrayListUnmanaged(elf.Elf64_Rela) = .empty, |
| 115 | 102 | /// Applies only to a relocatable. |
| 116 | 103 | comdat_group_sections: std.ArrayListUnmanaged(ComdatGroupSection) = .empty, |
| 117 | 104 | |
| 118 | | copy_rel_section_index: ?u32 = null, |
| 119 | | dynamic_section_index: ?u32 = null, |
| 120 | | dynstrtab_section_index: ?u32 = null, |
| 121 | | dynsymtab_section_index: ?u32 = null, |
| 122 | | eh_frame_section_index: ?u32 = null, |
| 123 | | eh_frame_rela_section_index: ?u32 = null, |
| 124 | | eh_frame_hdr_section_index: ?u32 = null, |
| 125 | | hash_section_index: ?u32 = null, |
| 126 | | gnu_hash_section_index: ?u32 = null, |
| 127 | | got_section_index: ?u32 = null, |
| 128 | | got_plt_section_index: ?u32 = null, |
| 129 | | interp_section_index: ?u32 = null, |
| 130 | | plt_section_index: ?u32 = null, |
| 131 | | plt_got_section_index: ?u32 = null, |
| 132 | | rela_dyn_section_index: ?u32 = null, |
| 133 | | rela_plt_section_index: ?u32 = null, |
| 134 | | versym_section_index: ?u32 = null, |
| 135 | | verneed_section_index: ?u32 = null, |
| 136 | | |
| 137 | | shstrtab_section_index: ?u32 = null, |
| 138 | | strtab_section_index: ?u32 = null, |
| 139 | | symtab_section_index: ?u32 = null, |
| 140 | | |
| 141 | 105 | resolver: SymbolResolver = .{}, |
| 142 | 106 | |
| 143 | 107 | has_text_reloc: bool = false, |
| ... | ... | @@ -147,11 +111,87 @@ num_ifunc_dynrelocs: usize = 0, |
| 147 | 111 | thunks: std.ArrayListUnmanaged(Thunk) = .empty, |
| 148 | 112 | |
| 149 | 113 | /// List of output merge sections with deduped contents. |
| 150 | | merge_sections: std.ArrayListUnmanaged(MergeSection) = .empty, |
| 151 | | comment_merge_section_index: ?MergeSection.Index = null, |
| 114 | merge_sections: std.ArrayListUnmanaged(Merge.Section) = .empty, |
| 115 | comment_merge_section_index: ?Merge.Section.Index = null, |
| 152 | 116 | |
| 153 | 117 | first_eflags: ?elf.Elf64_Word = null, |
| 154 | 118 | |
| 119 | const SectionIndexes = struct { |
| 120 | copy_rel: ?u32 = null, |
| 121 | dynamic: ?u32 = null, |
| 122 | dynstrtab: ?u32 = null, |
| 123 | dynsymtab: ?u32 = null, |
| 124 | eh_frame: ?u32 = null, |
| 125 | eh_frame_rela: ?u32 = null, |
| 126 | eh_frame_hdr: ?u32 = null, |
| 127 | hash: ?u32 = null, |
| 128 | gnu_hash: ?u32 = null, |
| 129 | got: ?u32 = null, |
| 130 | got_plt: ?u32 = null, |
| 131 | interp: ?u32 = null, |
| 132 | plt: ?u32 = null, |
| 133 | plt_got: ?u32 = null, |
| 134 | rela_dyn: ?u32 = null, |
| 135 | rela_plt: ?u32 = null, |
| 136 | versym: ?u32 = null, |
| 137 | verneed: ?u32 = null, |
| 138 | |
| 139 | shstrtab: ?u32 = null, |
| 140 | strtab: ?u32 = null, |
| 141 | symtab: ?u32 = null, |
| 142 | }; |
| 143 | |
| 144 | const ProgramHeaderList = std.ArrayListUnmanaged(elf.Elf64_Phdr); |
| 145 | |
| 146 | const OptionalProgramHeaderIndex = enum(u16) { |
| 147 | none = std.math.maxInt(u16), |
| 148 | _, |
| 149 | |
| 150 | fn unwrap(i: OptionalProgramHeaderIndex) ?ProgramHeaderIndex { |
| 151 | if (i == .none) return null; |
| 152 | return @enumFromInt(@intFromEnum(i)); |
| 153 | } |
| 154 | |
| 155 | fn int(i: OptionalProgramHeaderIndex) ?u16 { |
| 156 | if (i == .none) return null; |
| 157 | return @intFromEnum(i); |
| 158 | } |
| 159 | }; |
| 160 | |
| 161 | const ProgramHeaderIndex = enum(u16) { |
| 162 | _, |
| 163 | |
| 164 | fn toOptional(i: ProgramHeaderIndex) OptionalProgramHeaderIndex { |
| 165 | const result: OptionalProgramHeaderIndex = @enumFromInt(@intFromEnum(i)); |
| 166 | assert(result != .none); |
| 167 | return result; |
| 168 | } |
| 169 | |
| 170 | fn int(i: ProgramHeaderIndex) u16 { |
| 171 | return @intFromEnum(i); |
| 172 | } |
| 173 | }; |
| 174 | |
| 175 | const ProgramHeaderIndexes = struct { |
| 176 | /// PT_PHDR |
| 177 | table: OptionalProgramHeaderIndex = .none, |
| 178 | /// PT_LOAD for PHDR table |
| 179 | /// We add this special load segment to ensure the EHDR and PHDR table are always |
| 180 | /// loaded into memory. |
| 181 | table_load: OptionalProgramHeaderIndex = .none, |
| 182 | /// PT_INTERP |
| 183 | interp: OptionalProgramHeaderIndex = .none, |
| 184 | /// PT_DYNAMIC |
| 185 | dynamic: OptionalProgramHeaderIndex = .none, |
| 186 | /// PT_GNU_EH_FRAME |
| 187 | gnu_eh_frame: OptionalProgramHeaderIndex = .none, |
| 188 | /// PT_GNU_STACK |
| 189 | gnu_stack: OptionalProgramHeaderIndex = .none, |
| 190 | /// PT_TLS |
| 191 | /// TODO I think ELF permits multiple TLS segments but for now, assume one per file. |
| 192 | tls: OptionalProgramHeaderIndex = .none, |
| 193 | }; |
| 194 | |
| 155 | 195 | /// When allocating, the ideal_capacity is calculated by |
| 156 | 196 | /// actual_capacity + (actual_capacity / ideal_factor) |
| 157 | 197 | const ideal_factor = 3; |
| ... | ... | @@ -358,7 +398,7 @@ pub fn createEmpty( |
| 358 | 398 | }; |
| 359 | 399 | const max_nphdrs = comptime getMaxNumberOfPhdrs(); |
| 360 | 400 | const reserved: u64 = mem.alignForward(u64, padToIdeal(max_nphdrs * phsize), self.page_size); |
| 361 | | self.phdr_table_index = try self.addPhdr(.{ |
| 401 | self.phdr_indexes.table = (try self.addPhdr(.{ |
| 362 | 402 | .type = elf.PT_PHDR, |
| 363 | 403 | .flags = elf.PF_R, |
| 364 | 404 | .@"align" = p_align, |
| ... | ... | @@ -366,8 +406,8 @@ pub fn createEmpty( |
| 366 | 406 | .offset = ehsize, |
| 367 | 407 | .filesz = reserved, |
| 368 | 408 | .memsz = reserved, |
| 369 | | }); |
| 370 | | self.phdr_table_load_index = try self.addPhdr(.{ |
| 409 | })).toOptional(); |
| 410 | self.phdr_indexes.table_load = (try self.addPhdr(.{ |
| 371 | 411 | .type = elf.PT_LOAD, |
| 372 | 412 | .flags = elf.PF_R, |
| 373 | 413 | .@"align" = self.page_size, |
| ... | ... | @@ -375,7 +415,7 @@ pub fn createEmpty( |
| 375 | 415 | .offset = 0, |
| 376 | 416 | .filesz = reserved + ehsize, |
| 377 | 417 | .memsz = reserved + ehsize, |
| 378 | | }); |
| 418 | })).toOptional(); |
| 379 | 419 | } |
| 380 | 420 | |
| 381 | 421 | if (opt_zcu) |zcu| { |
| ... | ... | @@ -952,7 +992,16 @@ pub fn flushModule(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_nod |
| 952 | 992 | // Generate and emit synthetic sections. |
| 953 | 993 | try self.initSyntheticSections(); |
| 954 | 994 | try self.initSpecialPhdrs(); |
| 955 | | try self.sortShdrs(); |
| 995 | try sortShdrs( |
| 996 | gpa, |
| 997 | &self.section_indexes, |
| 998 | &self.sections, |
| 999 | self.shstrtab.items, |
| 1000 | self.merge_sections.items, |
| 1001 | self.comdat_group_sections.items, |
| 1002 | self.zigObjectPtr(), |
| 1003 | self.files, |
| 1004 | ); |
| 956 | 1005 | |
| 957 | 1006 | try self.setDynamicSection(self.rpath_table.keys()); |
| 958 | 1007 | self.sortDynamicSymtab(); |
| ... | ... | @@ -966,7 +1015,7 @@ pub fn flushModule(self: *Elf, arena: Allocator, tid: Zcu.PerThread.Id, prog_nod |
| 966 | 1015 | try self.addLoadPhdrs(); |
| 967 | 1016 | try self.allocatePhdrTable(); |
| 968 | 1017 | try self.allocateAllocSections(); |
| 969 | | try self.sortPhdrs(); |
| 1018 | try sortPhdrs(gpa, &self.phdrs, &self.phdr_indexes, self.sections.items(.phndx)); |
| 970 | 1019 | try self.allocateNonAllocSections(); |
| 971 | 1020 | self.allocateSpecialPhdrs(); |
| 972 | 1021 | if (self.linkerDefinedPtr()) |obj| { |
| ... | ... | @@ -2461,7 +2510,7 @@ fn writePhdrTable(self: *Elf) !void { |
| 2461 | 2510 | const gpa = self.base.comp.gpa; |
| 2462 | 2511 | const target_endian = self.getTarget().cpu.arch.endian(); |
| 2463 | 2512 | const foreign_endian = target_endian != builtin.cpu.arch.endian(); |
| 2464 | | const phdr_table = &self.phdrs.items[self.phdr_table_index.?]; |
| 2513 | const phdr_table = &self.phdrs.items[self.phdr_indexes.table.int().?]; |
| 2465 | 2514 | |
| 2466 | 2515 | log.debug("writing program headers from 0x{x} to 0x{x}", .{ |
| 2467 | 2516 | phdr_table.p_offset, |
| ... | ... | @@ -2573,18 +2622,18 @@ pub fn writeElfHeader(self: *Elf) !void { |
| 2573 | 2622 | const entry_sym = obj.entrySymbol(self) orelse break :blk 0; |
| 2574 | 2623 | break :blk @intCast(entry_sym.address(.{}, self)); |
| 2575 | 2624 | } else 0; |
| 2576 | | const phdr_table_offset = if (self.phdr_table_index) |phndx| self.phdrs.items[phndx].p_offset else 0; |
| 2625 | const phdr_table_offset = if (self.phdr_indexes.table.int()) |phndx| self.phdrs.items[phndx].p_offset else 0; |
| 2577 | 2626 | switch (self.ptr_width) { |
| 2578 | 2627 | .p32 => { |
| 2579 | | mem.writeInt(u32, hdr_buf[index..][0..4], @as(u32, @intCast(e_entry)), endian); |
| 2628 | mem.writeInt(u32, hdr_buf[index..][0..4], @intCast(e_entry), endian); |
| 2580 | 2629 | index += 4; |
| 2581 | 2630 | |
| 2582 | 2631 | // e_phoff |
| 2583 | | mem.writeInt(u32, hdr_buf[index..][0..4], @as(u32, @intCast(phdr_table_offset)), endian); |
| 2632 | mem.writeInt(u32, hdr_buf[index..][0..4], @intCast(phdr_table_offset), endian); |
| 2584 | 2633 | index += 4; |
| 2585 | 2634 | |
| 2586 | 2635 | // e_shoff |
| 2587 | | mem.writeInt(u32, hdr_buf[index..][0..4], @as(u32, @intCast(self.shdr_table_offset.?)), endian); |
| 2636 | mem.writeInt(u32, hdr_buf[index..][0..4], @intCast(self.shdr_table_offset.?), endian); |
| 2588 | 2637 | index += 4; |
| 2589 | 2638 | }, |
| 2590 | 2639 | .p64 => { |
| ... | ... | @@ -2631,11 +2680,11 @@ pub fn writeElfHeader(self: *Elf) !void { |
| 2631 | 2680 | mem.writeInt(u16, hdr_buf[index..][0..2], e_shentsize, endian); |
| 2632 | 2681 | index += 2; |
| 2633 | 2682 | |
| 2634 | | const e_shnum = @as(u16, @intCast(self.sections.items(.shdr).len)); |
| 2683 | const e_shnum: u16 = @intCast(self.sections.items(.shdr).len); |
| 2635 | 2684 | mem.writeInt(u16, hdr_buf[index..][0..2], e_shnum, endian); |
| 2636 | 2685 | index += 2; |
| 2637 | 2686 | |
| 2638 | | mem.writeInt(u16, hdr_buf[index..][0..2], @intCast(self.shstrtab_section_index.?), endian); |
| 2687 | mem.writeInt(u16, hdr_buf[index..][0..2], @intCast(self.section_indexes.shstrtab.?), endian); |
| 2639 | 2688 | index += 2; |
| 2640 | 2689 | |
| 2641 | 2690 | assert(index == e_ehsize); |
| ... | ... | @@ -2853,8 +2902,8 @@ fn initSyntheticSections(self: *Elf) !void { |
| 2853 | 2902 | } else false; |
| 2854 | 2903 | }; |
| 2855 | 2904 | if (needs_eh_frame) { |
| 2856 | | if (self.eh_frame_section_index == null) { |
| 2857 | | self.eh_frame_section_index = self.sectionByName(".eh_frame") orelse try self.addSection(.{ |
| 2905 | if (self.section_indexes.eh_frame == null) { |
| 2906 | self.section_indexes.eh_frame = self.sectionByName(".eh_frame") orelse try self.addSection(.{ |
| 2858 | 2907 | .name = try self.insertShString(".eh_frame"), |
| 2859 | 2908 | .type = if (target.cpu.arch == .x86_64) |
| 2860 | 2909 | elf.SHT_X86_64_UNWIND |
| ... | ... | @@ -2864,8 +2913,8 @@ fn initSyntheticSections(self: *Elf) !void { |
| 2864 | 2913 | .addralign = ptr_size, |
| 2865 | 2914 | }); |
| 2866 | 2915 | } |
| 2867 | | if (comp.link_eh_frame_hdr and self.eh_frame_hdr_section_index == null) { |
| 2868 | | self.eh_frame_hdr_section_index = try self.addSection(.{ |
| 2916 | if (comp.link_eh_frame_hdr and self.section_indexes.eh_frame_hdr == null) { |
| 2917 | self.section_indexes.eh_frame_hdr = try self.addSection(.{ |
| 2869 | 2918 | .name = try self.insertShString(".eh_frame_hdr"), |
| 2870 | 2919 | .type = elf.SHT_PROGBITS, |
| 2871 | 2920 | .flags = elf.SHF_ALLOC, |
| ... | ... | @@ -2874,8 +2923,8 @@ fn initSyntheticSections(self: *Elf) !void { |
| 2874 | 2923 | } |
| 2875 | 2924 | } |
| 2876 | 2925 | |
| 2877 | | if (self.got.entries.items.len > 0 and self.got_section_index == null) { |
| 2878 | | self.got_section_index = try self.addSection(.{ |
| 2926 | if (self.got.entries.items.len > 0 and self.section_indexes.got == null) { |
| 2927 | self.section_indexes.got = try self.addSection(.{ |
| 2879 | 2928 | .name = try self.insertShString(".got"), |
| 2880 | 2929 | .type = elf.SHT_PROGBITS, |
| 2881 | 2930 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, |
| ... | ... | @@ -2883,8 +2932,8 @@ fn initSyntheticSections(self: *Elf) !void { |
| 2883 | 2932 | }); |
| 2884 | 2933 | } |
| 2885 | 2934 | |
| 2886 | | if (self.got_plt_section_index == null) { |
| 2887 | | self.got_plt_section_index = try self.addSection(.{ |
| 2935 | if (self.section_indexes.got_plt == null) { |
| 2936 | self.section_indexes.got_plt = try self.addSection(.{ |
| 2888 | 2937 | .name = try self.insertShString(".got.plt"), |
| 2889 | 2938 | .type = elf.SHT_PROGBITS, |
| 2890 | 2939 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, |
| ... | ... | @@ -2903,8 +2952,8 @@ fn initSyntheticSections(self: *Elf) !void { |
| 2903 | 2952 | } |
| 2904 | 2953 | break :blk false; |
| 2905 | 2954 | }; |
| 2906 | | if (needs_rela_dyn and self.rela_dyn_section_index == null) { |
| 2907 | | self.rela_dyn_section_index = try self.addSection(.{ |
| 2955 | if (needs_rela_dyn and self.section_indexes.rela_dyn == null) { |
| 2956 | self.section_indexes.rela_dyn = try self.addSection(.{ |
| 2908 | 2957 | .name = try self.insertShString(".rela.dyn"), |
| 2909 | 2958 | .type = elf.SHT_RELA, |
| 2910 | 2959 | .flags = elf.SHF_ALLOC, |
| ... | ... | @@ -2914,16 +2963,16 @@ fn initSyntheticSections(self: *Elf) !void { |
| 2914 | 2963 | } |
| 2915 | 2964 | |
| 2916 | 2965 | if (self.plt.symbols.items.len > 0) { |
| 2917 | | if (self.plt_section_index == null) { |
| 2918 | | self.plt_section_index = try self.addSection(.{ |
| 2966 | if (self.section_indexes.plt == null) { |
| 2967 | self.section_indexes.plt = try self.addSection(.{ |
| 2919 | 2968 | .name = try self.insertShString(".plt"), |
| 2920 | 2969 | .type = elf.SHT_PROGBITS, |
| 2921 | 2970 | .flags = elf.SHF_ALLOC | elf.SHF_EXECINSTR, |
| 2922 | 2971 | .addralign = 16, |
| 2923 | 2972 | }); |
| 2924 | 2973 | } |
| 2925 | | if (self.rela_plt_section_index == null) { |
| 2926 | | self.rela_plt_section_index = try self.addSection(.{ |
| 2974 | if (self.section_indexes.rela_plt == null) { |
| 2975 | self.section_indexes.rela_plt = try self.addSection(.{ |
| 2927 | 2976 | .name = try self.insertShString(".rela.plt"), |
| 2928 | 2977 | .type = elf.SHT_RELA, |
| 2929 | 2978 | .flags = elf.SHF_ALLOC, |
| ... | ... | @@ -2933,8 +2982,8 @@ fn initSyntheticSections(self: *Elf) !void { |
| 2933 | 2982 | } |
| 2934 | 2983 | } |
| 2935 | 2984 | |
| 2936 | | if (self.plt_got.symbols.items.len > 0 and self.plt_got_section_index == null) { |
| 2937 | | self.plt_got_section_index = try self.addSection(.{ |
| 2985 | if (self.plt_got.symbols.items.len > 0 and self.section_indexes.plt_got == null) { |
| 2986 | self.section_indexes.plt_got = try self.addSection(.{ |
| 2938 | 2987 | .name = try self.insertShString(".plt.got"), |
| 2939 | 2988 | .type = elf.SHT_PROGBITS, |
| 2940 | 2989 | .flags = elf.SHF_ALLOC | elf.SHF_EXECINSTR, |
| ... | ... | @@ -2942,8 +2991,8 @@ fn initSyntheticSections(self: *Elf) !void { |
| 2942 | 2991 | }); |
| 2943 | 2992 | } |
| 2944 | 2993 | |
| 2945 | | if (self.copy_rel.symbols.items.len > 0 and self.copy_rel_section_index == null) { |
| 2946 | | self.copy_rel_section_index = try self.addSection(.{ |
| 2994 | if (self.copy_rel.symbols.items.len > 0 and self.section_indexes.copy_rel == null) { |
| 2995 | self.section_indexes.copy_rel = try self.addSection(.{ |
| 2947 | 2996 | .name = try self.insertShString(".copyrel"), |
| 2948 | 2997 | .type = elf.SHT_NOBITS, |
| 2949 | 2998 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, |
| ... | ... | @@ -2959,8 +3008,8 @@ fn initSyntheticSections(self: *Elf) !void { |
| 2959 | 3008 | if (self.base.isStatic() and !comp.config.pie) break :blk false; |
| 2960 | 3009 | break :blk target.dynamic_linker.get() != null; |
| 2961 | 3010 | }; |
| 2962 | | if (needs_interp and self.interp_section_index == null) { |
| 2963 | | self.interp_section_index = try self.addSection(.{ |
| 3011 | if (needs_interp and self.section_indexes.interp == null) { |
| 3012 | self.section_indexes.interp = try self.addSection(.{ |
| 2964 | 3013 | .name = try self.insertShString(".interp"), |
| 2965 | 3014 | .type = elf.SHT_PROGBITS, |
| 2966 | 3015 | .flags = elf.SHF_ALLOC, |
| ... | ... | @@ -2969,8 +3018,8 @@ fn initSyntheticSections(self: *Elf) !void { |
| 2969 | 3018 | } |
| 2970 | 3019 | |
| 2971 | 3020 | if (self.isEffectivelyDynLib() or self.shared_objects.items.len > 0 or comp.config.pie) { |
| 2972 | | if (self.dynstrtab_section_index == null) { |
| 2973 | | self.dynstrtab_section_index = try self.addSection(.{ |
| 3021 | if (self.section_indexes.dynstrtab == null) { |
| 3022 | self.section_indexes.dynstrtab = try self.addSection(.{ |
| 2974 | 3023 | .name = try self.insertShString(".dynstr"), |
| 2975 | 3024 | .flags = elf.SHF_ALLOC, |
| 2976 | 3025 | .type = elf.SHT_STRTAB, |
| ... | ... | @@ -2978,8 +3027,8 @@ fn initSyntheticSections(self: *Elf) !void { |
| 2978 | 3027 | .addralign = 1, |
| 2979 | 3028 | }); |
| 2980 | 3029 | } |
| 2981 | | if (self.dynamic_section_index == null) { |
| 2982 | | self.dynamic_section_index = try self.addSection(.{ |
| 3030 | if (self.section_indexes.dynamic == null) { |
| 3031 | self.section_indexes.dynamic = try self.addSection(.{ |
| 2983 | 3032 | .name = try self.insertShString(".dynamic"), |
| 2984 | 3033 | .flags = elf.SHF_ALLOC | elf.SHF_WRITE, |
| 2985 | 3034 | .type = elf.SHT_DYNAMIC, |
| ... | ... | @@ -2987,8 +3036,8 @@ fn initSyntheticSections(self: *Elf) !void { |
| 2987 | 3036 | .addralign = @alignOf(elf.Elf64_Dyn), |
| 2988 | 3037 | }); |
| 2989 | 3038 | } |
| 2990 | | if (self.dynsymtab_section_index == null) { |
| 2991 | | self.dynsymtab_section_index = try self.addSection(.{ |
| 3039 | if (self.section_indexes.dynsymtab == null) { |
| 3040 | self.section_indexes.dynsymtab = try self.addSection(.{ |
| 2992 | 3041 | .name = try self.insertShString(".dynsym"), |
| 2993 | 3042 | .flags = elf.SHF_ALLOC, |
| 2994 | 3043 | .type = elf.SHT_DYNSYM, |
| ... | ... | @@ -2997,8 +3046,8 @@ fn initSyntheticSections(self: *Elf) !void { |
| 2997 | 3046 | .info = 1, |
| 2998 | 3047 | }); |
| 2999 | 3048 | } |
| 3000 | | if (self.hash_section_index == null) { |
| 3001 | | self.hash_section_index = try self.addSection(.{ |
| 3049 | if (self.section_indexes.hash == null) { |
| 3050 | self.section_indexes.hash = try self.addSection(.{ |
| 3002 | 3051 | .name = try self.insertShString(".hash"), |
| 3003 | 3052 | .flags = elf.SHF_ALLOC, |
| 3004 | 3053 | .type = elf.SHT_HASH, |
| ... | ... | @@ -3006,8 +3055,8 @@ fn initSyntheticSections(self: *Elf) !void { |
| 3006 | 3055 | .entsize = 4, |
| 3007 | 3056 | }); |
| 3008 | 3057 | } |
| 3009 | | if (self.gnu_hash_section_index == null) { |
| 3010 | | self.gnu_hash_section_index = try self.addSection(.{ |
| 3058 | if (self.section_indexes.gnu_hash == null) { |
| 3059 | self.section_indexes.gnu_hash = try self.addSection(.{ |
| 3011 | 3060 | .name = try self.insertShString(".gnu.hash"), |
| 3012 | 3061 | .flags = elf.SHF_ALLOC, |
| 3013 | 3062 | .type = elf.SHT_GNU_HASH, |
| ... | ... | @@ -3020,8 +3069,8 @@ fn initSyntheticSections(self: *Elf) !void { |
| 3020 | 3069 | if (sym.flags.import and sym.version_index & elf.VERSYM_VERSION > elf.VER_NDX_GLOBAL) break true; |
| 3021 | 3070 | } else false; |
| 3022 | 3071 | if (needs_versions) { |
| 3023 | | if (self.versym_section_index == null) { |
| 3024 | | self.versym_section_index = try self.addSection(.{ |
| 3072 | if (self.section_indexes.versym == null) { |
| 3073 | self.section_indexes.versym = try self.addSection(.{ |
| 3025 | 3074 | .name = try self.insertShString(".gnu.version"), |
| 3026 | 3075 | .flags = elf.SHF_ALLOC, |
| 3027 | 3076 | .type = elf.SHT_GNU_VERSYM, |
| ... | ... | @@ -3029,8 +3078,8 @@ fn initSyntheticSections(self: *Elf) !void { |
| 3029 | 3078 | .entsize = @sizeOf(elf.Elf64_Versym), |
| 3030 | 3079 | }); |
| 3031 | 3080 | } |
| 3032 | | if (self.verneed_section_index == null) { |
| 3033 | | self.verneed_section_index = try self.addSection(.{ |
| 3081 | if (self.section_indexes.verneed == null) { |
| 3082 | self.section_indexes.verneed = try self.addSection(.{ |
| 3034 | 3083 | .name = try self.insertShString(".gnu.version_r"), |
| 3035 | 3084 | .flags = elf.SHF_ALLOC, |
| 3036 | 3085 | .type = elf.SHT_GNU_VERNEED, |
| ... | ... | @@ -3049,16 +3098,16 @@ pub fn initSymtab(self: *Elf) !void { |
| 3049 | 3098 | .p32 => true, |
| 3050 | 3099 | .p64 => false, |
| 3051 | 3100 | }; |
| 3052 | | if (self.symtab_section_index == null) { |
| 3053 | | self.symtab_section_index = try self.addSection(.{ |
| 3101 | if (self.section_indexes.symtab == null) { |
| 3102 | self.section_indexes.symtab = try self.addSection(.{ |
| 3054 | 3103 | .name = try self.insertShString(".symtab"), |
| 3055 | 3104 | .type = elf.SHT_SYMTAB, |
| 3056 | 3105 | .addralign = if (small_ptr) @alignOf(elf.Elf32_Sym) else @alignOf(elf.Elf64_Sym), |
| 3057 | 3106 | .entsize = if (small_ptr) @sizeOf(elf.Elf32_Sym) else @sizeOf(elf.Elf64_Sym), |
| 3058 | 3107 | }); |
| 3059 | 3108 | } |
| 3060 | | if (self.strtab_section_index == null) { |
| 3061 | | self.strtab_section_index = try self.addSection(.{ |
| 3109 | if (self.section_indexes.strtab == null) { |
| 3110 | self.section_indexes.strtab = try self.addSection(.{ |
| 3062 | 3111 | .name = try self.insertShString(".strtab"), |
| 3063 | 3112 | .type = elf.SHT_STRTAB, |
| 3064 | 3113 | .entsize = 1, |
| ... | ... | @@ -3068,8 +3117,8 @@ pub fn initSymtab(self: *Elf) !void { |
| 3068 | 3117 | } |
| 3069 | 3118 | |
| 3070 | 3119 | pub fn initShStrtab(self: *Elf) !void { |
| 3071 | | if (self.shstrtab_section_index == null) { |
| 3072 | | self.shstrtab_section_index = try self.addSection(.{ |
| 3120 | if (self.section_indexes.shstrtab == null) { |
| 3121 | self.section_indexes.shstrtab = try self.addSection(.{ |
| 3073 | 3122 | .name = try self.insertShString(".shstrtab"), |
| 3074 | 3123 | .type = elf.SHT_STRTAB, |
| 3075 | 3124 | .entsize = 1, |
| ... | ... | @@ -3081,43 +3130,43 @@ pub fn initShStrtab(self: *Elf) !void { |
| 3081 | 3130 | fn initSpecialPhdrs(self: *Elf) !void { |
| 3082 | 3131 | comptime assert(max_number_of_special_phdrs == 5); |
| 3083 | 3132 | |
| 3084 | | if (self.interp_section_index != null and self.phdr_interp_index == null) { |
| 3085 | | self.phdr_interp_index = try self.addPhdr(.{ |
| 3133 | if (self.section_indexes.interp != null and self.phdr_indexes.interp == .none) { |
| 3134 | self.phdr_indexes.interp = (try self.addPhdr(.{ |
| 3086 | 3135 | .type = elf.PT_INTERP, |
| 3087 | 3136 | .flags = elf.PF_R, |
| 3088 | 3137 | .@"align" = 1, |
| 3089 | | }); |
| 3138 | })).toOptional(); |
| 3090 | 3139 | } |
| 3091 | | if (self.dynamic_section_index != null and self.phdr_dynamic_index == null) { |
| 3092 | | self.phdr_dynamic_index = try self.addPhdr(.{ |
| 3140 | if (self.section_indexes.dynamic != null and self.phdr_indexes.dynamic == .none) { |
| 3141 | self.phdr_indexes.dynamic = (try self.addPhdr(.{ |
| 3093 | 3142 | .type = elf.PT_DYNAMIC, |
| 3094 | 3143 | .flags = elf.PF_R | elf.PF_W, |
| 3095 | | }); |
| 3144 | })).toOptional(); |
| 3096 | 3145 | } |
| 3097 | | if (self.eh_frame_hdr_section_index != null and self.phdr_gnu_eh_frame_index == null) { |
| 3098 | | self.phdr_gnu_eh_frame_index = try self.addPhdr(.{ |
| 3146 | if (self.section_indexes.eh_frame_hdr != null and self.phdr_indexes.gnu_eh_frame == .none) { |
| 3147 | self.phdr_indexes.gnu_eh_frame = (try self.addPhdr(.{ |
| 3099 | 3148 | .type = elf.PT_GNU_EH_FRAME, |
| 3100 | 3149 | .flags = elf.PF_R, |
| 3101 | | }); |
| 3150 | })).toOptional(); |
| 3102 | 3151 | } |
| 3103 | | if (self.phdr_gnu_stack_index == null) { |
| 3104 | | self.phdr_gnu_stack_index = try self.addPhdr(.{ |
| 3152 | if (self.phdr_indexes.gnu_stack == .none) { |
| 3153 | self.phdr_indexes.gnu_stack = (try self.addPhdr(.{ |
| 3105 | 3154 | .type = elf.PT_GNU_STACK, |
| 3106 | 3155 | .flags = elf.PF_W | elf.PF_R, |
| 3107 | 3156 | .memsz = self.base.stack_size, |
| 3108 | 3157 | .@"align" = 1, |
| 3109 | | }); |
| 3158 | })).toOptional(); |
| 3110 | 3159 | } |
| 3111 | 3160 | |
| 3112 | 3161 | const has_tls = for (self.sections.items(.shdr)) |shdr| { |
| 3113 | 3162 | if (shdr.sh_flags & elf.SHF_TLS != 0) break true; |
| 3114 | 3163 | } else false; |
| 3115 | | if (has_tls and self.phdr_tls_index == null) { |
| 3116 | | self.phdr_tls_index = try self.addPhdr(.{ |
| 3164 | if (has_tls and self.phdr_indexes.tls == .none) { |
| 3165 | self.phdr_indexes.tls = (try self.addPhdr(.{ |
| 3117 | 3166 | .type = elf.PT_TLS, |
| 3118 | 3167 | .flags = elf.PF_R, |
| 3119 | 3168 | .@"align" = 1, |
| 3120 | | }); |
| 3169 | })).toOptional(); |
| 3121 | 3170 | } |
| 3122 | 3171 | } |
| 3123 | 3172 | |
| ... | ... | @@ -3202,7 +3251,7 @@ fn sortInitFini(self: *Elf) !void { |
| 3202 | 3251 | } |
| 3203 | 3252 | |
| 3204 | 3253 | fn setDynamicSection(self: *Elf, rpaths: []const []const u8) !void { |
| 3205 | | if (self.dynamic_section_index == null) return; |
| 3254 | if (self.section_indexes.dynamic == null) return; |
| 3206 | 3255 | |
| 3207 | 3256 | for (self.shared_objects.items) |index| { |
| 3208 | 3257 | const shared_object = self.file(index).?.shared_object; |
| ... | ... | @@ -3220,13 +3269,13 @@ fn setDynamicSection(self: *Elf, rpaths: []const []const u8) !void { |
| 3220 | 3269 | } |
| 3221 | 3270 | |
| 3222 | 3271 | fn sortDynamicSymtab(self: *Elf) void { |
| 3223 | | if (self.gnu_hash_section_index == null) return; |
| 3272 | if (self.section_indexes.gnu_hash == null) return; |
| 3224 | 3273 | self.dynsym.sort(self); |
| 3225 | 3274 | } |
| 3226 | 3275 | |
| 3227 | 3276 | fn setVersionSymtab(self: *Elf) !void { |
| 3228 | 3277 | const gpa = self.base.comp.gpa; |
| 3229 | | if (self.versym_section_index == null) return; |
| 3278 | if (self.section_indexes.versym == null) return; |
| 3230 | 3279 | try self.versym.resize(gpa, self.dynsym.count()); |
| 3231 | 3280 | self.versym.items[0] = elf.VER_NDX_LOCAL; |
| 3232 | 3281 | for (self.dynsym.entries.items, 1..) |entry, i| { |
| ... | ... | @@ -3234,7 +3283,7 @@ fn setVersionSymtab(self: *Elf) !void { |
| 3234 | 3283 | self.versym.items[i] = sym.version_index; |
| 3235 | 3284 | } |
| 3236 | 3285 | |
| 3237 | | if (self.verneed_section_index) |shndx| { |
| 3286 | if (self.section_indexes.verneed) |shndx| { |
| 3238 | 3287 | try self.verneed.generate(self); |
| 3239 | 3288 | const shdr = &self.sections.items(.shdr)[shndx]; |
| 3240 | 3289 | shdr.sh_info = @as(u32, @intCast(self.verneed.verneed.items.len)); |
| ... | ... | @@ -3242,34 +3291,39 @@ fn setVersionSymtab(self: *Elf) !void { |
| 3242 | 3291 | } |
| 3243 | 3292 | |
| 3244 | 3293 | fn setHashSections(self: *Elf) !void { |
| 3245 | | if (self.hash_section_index != null) { |
| 3294 | if (self.section_indexes.hash != null) { |
| 3246 | 3295 | try self.hash.generate(self); |
| 3247 | 3296 | } |
| 3248 | | if (self.gnu_hash_section_index != null) { |
| 3297 | if (self.section_indexes.gnu_hash != null) { |
| 3249 | 3298 | try self.gnu_hash.calcSize(self); |
| 3250 | 3299 | } |
| 3251 | 3300 | } |
| 3252 | 3301 | |
| 3253 | 3302 | fn phdrRank(phdr: elf.Elf64_Phdr) u8 { |
| 3254 | | switch (phdr.p_type) { |
| 3255 | | elf.PT_NULL => return 0, |
| 3256 | | elf.PT_PHDR => return 1, |
| 3257 | | elf.PT_INTERP => return 2, |
| 3258 | | elf.PT_LOAD => return 3, |
| 3259 | | elf.PT_DYNAMIC, elf.PT_TLS => return 4, |
| 3260 | | elf.PT_GNU_EH_FRAME => return 5, |
| 3261 | | elf.PT_GNU_STACK => return 6, |
| 3262 | | else => return 7, |
| 3263 | | } |
| 3303 | return switch (phdr.p_type) { |
| 3304 | elf.PT_NULL => 0, |
| 3305 | elf.PT_PHDR => 1, |
| 3306 | elf.PT_INTERP => 2, |
| 3307 | elf.PT_LOAD => 3, |
| 3308 | elf.PT_DYNAMIC, elf.PT_TLS => 4, |
| 3309 | elf.PT_GNU_EH_FRAME => 5, |
| 3310 | elf.PT_GNU_STACK => 6, |
| 3311 | else => 7, |
| 3312 | }; |
| 3264 | 3313 | } |
| 3265 | 3314 | |
| 3266 | | fn sortPhdrs(self: *Elf) error{OutOfMemory}!void { |
| 3315 | fn sortPhdrs( |
| 3316 | gpa: Allocator, |
| 3317 | phdrs: *ProgramHeaderList, |
| 3318 | special_indexes: *ProgramHeaderIndexes, |
| 3319 | section_indexes: []OptionalProgramHeaderIndex, |
| 3320 | ) error{OutOfMemory}!void { |
| 3267 | 3321 | const Entry = struct { |
| 3268 | 3322 | phndx: u16, |
| 3269 | 3323 | |
| 3270 | | pub fn lessThan(elf_file: *Elf, lhs: @This(), rhs: @This()) bool { |
| 3271 | | const lhs_phdr = elf_file.phdrs.items[lhs.phndx]; |
| 3272 | | const rhs_phdr = elf_file.phdrs.items[rhs.phndx]; |
| 3324 | pub fn lessThan(program_headers: []const elf.Elf64_Phdr, lhs: @This(), rhs: @This()) bool { |
| 3325 | const lhs_phdr = program_headers[lhs.phndx]; |
| 3326 | const rhs_phdr = program_headers[rhs.phndx]; |
| 3273 | 3327 | const lhs_rank = phdrRank(lhs_phdr); |
| 3274 | 3328 | const rhs_rank = phdrRank(rhs_phdr); |
| 3275 | 3329 | if (lhs_rank == rhs_rank) return lhs_phdr.p_vaddr < rhs_phdr.p_vaddr; |
| ... | ... | @@ -3277,52 +3331,41 @@ fn sortPhdrs(self: *Elf) error{OutOfMemory}!void { |
| 3277 | 3331 | } |
| 3278 | 3332 | }; |
| 3279 | 3333 | |
| 3280 | | const gpa = self.base.comp.gpa; |
| 3281 | | var entries = try std.ArrayList(Entry).initCapacity(gpa, self.phdrs.items.len); |
| 3282 | | defer entries.deinit(); |
| 3283 | | for (0..self.phdrs.items.len) |phndx| { |
| 3284 | | entries.appendAssumeCapacity(.{ .phndx = @as(u16, @intCast(phndx)) }); |
| 3334 | const entries = try gpa.alloc(Entry, phdrs.items.len); |
| 3335 | defer gpa.free(entries); |
| 3336 | for (entries, 0..) |*entry, phndx| { |
| 3337 | entry.* = .{ .phndx = @intCast(phndx) }; |
| 3285 | 3338 | } |
| 3286 | 3339 | |
| 3287 | | mem.sort(Entry, entries.items, self, Entry.lessThan); |
| 3340 | // The `@as` here works around a bug in the C backend. |
| 3341 | mem.sort(Entry, entries, @as([]const elf.Elf64_Phdr, phdrs.items), Entry.lessThan); |
| 3288 | 3342 | |
| 3289 | | const backlinks = try gpa.alloc(u16, entries.items.len); |
| 3343 | const backlinks = try gpa.alloc(u16, entries.len); |
| 3290 | 3344 | defer gpa.free(backlinks); |
| 3291 | | for (entries.items, 0..) |entry, i| { |
| 3292 | | backlinks[entry.phndx] = @as(u16, @intCast(i)); |
| 3293 | | } |
| 3294 | | |
| 3295 | | const slice = try self.phdrs.toOwnedSlice(gpa); |
| 3345 | const slice = try phdrs.toOwnedSlice(gpa); |
| 3296 | 3346 | defer gpa.free(slice); |
| 3347 | try phdrs.resize(gpa, slice.len); |
| 3297 | 3348 | |
| 3298 | | try self.phdrs.ensureTotalCapacityPrecise(gpa, slice.len); |
| 3299 | | for (entries.items) |sorted| { |
| 3300 | | self.phdrs.appendAssumeCapacity(slice[sorted.phndx]); |
| 3349 | for (entries, phdrs.items, 0..) |entry, *phdr, i| { |
| 3350 | backlinks[entry.phndx] = @intCast(i); |
| 3351 | phdr.* = slice[entry.phndx]; |
| 3301 | 3352 | } |
| 3302 | 3353 | |
| 3303 | | for (&[_]*?u16{ |
| 3304 | | &self.phdr_table_index, |
| 3305 | | &self.phdr_table_load_index, |
| 3306 | | &self.phdr_interp_index, |
| 3307 | | &self.phdr_dynamic_index, |
| 3308 | | &self.phdr_gnu_eh_frame_index, |
| 3309 | | &self.phdr_tls_index, |
| 3310 | | }) |maybe_index| { |
| 3311 | | if (maybe_index.*) |*index| { |
| 3312 | | index.* = backlinks[index.*]; |
| 3354 | inline for (@typeInfo(ProgramHeaderIndexes).@"struct".fields) |field| { |
| 3355 | if (@field(special_indexes, field.name).int()) |special_index| { |
| 3356 | @field(special_indexes, field.name) = @enumFromInt(backlinks[special_index]); |
| 3313 | 3357 | } |
| 3314 | 3358 | } |
| 3315 | 3359 | |
| 3316 | | for (self.sections.items(.phndx)) |*maybe_phndx| { |
| 3317 | | if (maybe_phndx.*) |*index| { |
| 3318 | | index.* = backlinks[index.*]; |
| 3360 | for (section_indexes) |*opt_phndx| { |
| 3361 | if (opt_phndx.int()) |index| { |
| 3362 | opt_phndx.* = @enumFromInt(backlinks[index]); |
| 3319 | 3363 | } |
| 3320 | 3364 | } |
| 3321 | 3365 | } |
| 3322 | 3366 | |
| 3323 | | fn shdrRank(self: *Elf, shndx: u32) u8 { |
| 3324 | | const shdr = self.sections.items(.shdr)[shndx]; |
| 3325 | | const name = self.getShString(shdr.sh_name); |
| 3367 | fn shdrRank(shdr: elf.Elf64_Shdr, shstrtab: []const u8) u8 { |
| 3368 | const name = shString(shstrtab, shdr.sh_name); |
| 3326 | 3369 | const flags = shdr.sh_flags; |
| 3327 | 3370 | |
| 3328 | 3371 | switch (shdr.sh_type) { |
| ... | ... | @@ -3371,145 +3414,138 @@ fn shdrRank(self: *Elf, shndx: u32) u8 { |
| 3371 | 3414 | } |
| 3372 | 3415 | } |
| 3373 | 3416 | |
| 3374 | | pub fn sortShdrs(self: *Elf) !void { |
| 3417 | pub fn sortShdrs( |
| 3418 | gpa: Allocator, |
| 3419 | section_indexes: *SectionIndexes, |
| 3420 | sections: *std.MultiArrayList(Section), |
| 3421 | shstrtab: []const u8, |
| 3422 | merge_sections: []Merge.Section, |
| 3423 | comdat_group_sections: []ComdatGroupSection, |
| 3424 | zig_object_ptr: ?*ZigObject, |
| 3425 | files: std.MultiArrayList(File.Entry), |
| 3426 | ) !void { |
| 3375 | 3427 | const Entry = struct { |
| 3376 | 3428 | shndx: u32, |
| 3377 | 3429 | |
| 3378 | | pub fn lessThan(elf_file: *Elf, lhs: @This(), rhs: @This()) bool { |
| 3379 | | return elf_file.shdrRank(lhs.shndx) < elf_file.shdrRank(rhs.shndx); |
| 3430 | const Context = struct { |
| 3431 | shdrs: []const elf.Elf64_Shdr, |
| 3432 | shstrtab: []const u8, |
| 3433 | }; |
| 3434 | |
| 3435 | pub fn lessThan(ctx: Context, lhs: @This(), rhs: @This()) bool { |
| 3436 | return shdrRank(ctx.shdrs[lhs.shndx], ctx.shstrtab) < |
| 3437 | shdrRank(ctx.shdrs[rhs.shndx], ctx.shstrtab); |
| 3380 | 3438 | } |
| 3381 | 3439 | }; |
| 3382 | 3440 | |
| 3383 | | const gpa = self.base.comp.gpa; |
| 3384 | | var entries = try std.ArrayList(Entry).initCapacity(gpa, self.sections.items(.shdr).len); |
| 3385 | | defer entries.deinit(); |
| 3386 | | for (0..self.sections.items(.shdr).len) |shndx| { |
| 3387 | | entries.appendAssumeCapacity(.{ .shndx = @intCast(shndx) }); |
| 3441 | const shdrs = sections.items(.shdr); |
| 3442 | |
| 3443 | const entries = try gpa.alloc(Entry, shdrs.len); |
| 3444 | defer gpa.free(entries); |
| 3445 | for (entries, 0..shdrs.len) |*entry, shndx| { |
| 3446 | entry.* = .{ .shndx = @intCast(shndx) }; |
| 3388 | 3447 | } |
| 3389 | 3448 | |
| 3390 | | mem.sort(Entry, entries.items, self, Entry.lessThan); |
| 3449 | const sort_context: Entry.Context = .{ |
| 3450 | .shdrs = shdrs, |
| 3451 | .shstrtab = shstrtab, |
| 3452 | }; |
| 3453 | mem.sort(Entry, entries, sort_context, Entry.lessThan); |
| 3391 | 3454 | |
| 3392 | | const backlinks = try gpa.alloc(u32, entries.items.len); |
| 3455 | const backlinks = try gpa.alloc(u32, entries.len); |
| 3393 | 3456 | defer gpa.free(backlinks); |
| 3394 | | for (entries.items, 0..) |entry, i| { |
| 3395 | | backlinks[entry.shndx] = @intCast(i); |
| 3396 | | } |
| 3397 | | |
| 3398 | | var slice = self.sections.toOwnedSlice(); |
| 3399 | | defer slice.deinit(gpa); |
| 3400 | | |
| 3401 | | try self.sections.ensureTotalCapacity(gpa, slice.len); |
| 3402 | | for (entries.items) |sorted| { |
| 3403 | | self.sections.appendAssumeCapacity(slice.get(sorted.shndx)); |
| 3404 | | } |
| 3405 | | |
| 3406 | | self.resetShdrIndexes(backlinks); |
| 3407 | | } |
| 3408 | | |
| 3409 | | fn resetShdrIndexes(self: *Elf, backlinks: []const u32) void { |
| 3410 | | for (&[_]*?u32{ |
| 3411 | | &self.eh_frame_section_index, |
| 3412 | | &self.eh_frame_rela_section_index, |
| 3413 | | &self.eh_frame_hdr_section_index, |
| 3414 | | &self.got_section_index, |
| 3415 | | &self.symtab_section_index, |
| 3416 | | &self.strtab_section_index, |
| 3417 | | &self.shstrtab_section_index, |
| 3418 | | &self.interp_section_index, |
| 3419 | | &self.dynamic_section_index, |
| 3420 | | &self.dynsymtab_section_index, |
| 3421 | | &self.dynstrtab_section_index, |
| 3422 | | &self.hash_section_index, |
| 3423 | | &self.gnu_hash_section_index, |
| 3424 | | &self.plt_section_index, |
| 3425 | | &self.got_plt_section_index, |
| 3426 | | &self.plt_got_section_index, |
| 3427 | | &self.rela_dyn_section_index, |
| 3428 | | &self.rela_plt_section_index, |
| 3429 | | &self.copy_rel_section_index, |
| 3430 | | &self.versym_section_index, |
| 3431 | | &self.verneed_section_index, |
| 3432 | | }) |maybe_index| { |
| 3433 | | if (maybe_index.*) |*index| { |
| 3434 | | index.* = backlinks[index.*]; |
| 3457 | { |
| 3458 | var slice = sections.toOwnedSlice(); |
| 3459 | defer slice.deinit(gpa); |
| 3460 | try sections.resize(gpa, slice.len); |
| 3461 | |
| 3462 | for (entries, 0..) |entry, i| { |
| 3463 | backlinks[entry.shndx] = @intCast(i); |
| 3464 | sections.set(i, slice.get(entry.shndx)); |
| 3435 | 3465 | } |
| 3436 | 3466 | } |
| 3437 | 3467 | |
| 3438 | | for (self.merge_sections.items) |*msec| { |
| 3468 | inline for (@typeInfo(SectionIndexes).@"struct".fields) |field| { |
| 3469 | if (@field(section_indexes, field.name)) |special_index| { |
| 3470 | @field(section_indexes, field.name) = backlinks[special_index]; |
| 3471 | } |
| 3472 | } |
| 3473 | |
| 3474 | for (merge_sections) |*msec| { |
| 3439 | 3475 | msec.output_section_index = backlinks[msec.output_section_index]; |
| 3440 | 3476 | } |
| 3441 | 3477 | |
| 3442 | | const slice = self.sections.slice(); |
| 3478 | const slice = sections.slice(); |
| 3443 | 3479 | for (slice.items(.shdr), slice.items(.atom_list_2)) |*shdr, *atom_list| { |
| 3444 | 3480 | atom_list.output_section_index = backlinks[atom_list.output_section_index]; |
| 3445 | 3481 | for (atom_list.atoms.keys()) |ref| { |
| 3446 | | self.atom(ref).?.output_section_index = atom_list.output_section_index; |
| 3482 | fileLookup(files, ref.file).?.atom(ref.index).?.output_section_index = atom_list.output_section_index; |
| 3447 | 3483 | } |
| 3448 | 3484 | if (shdr.sh_type == elf.SHT_RELA) { |
| 3449 | 3485 | // FIXME:JK we should spin up .symtab potentially earlier, or set all non-dynamic RELA sections |
| 3450 | 3486 | // to point at symtab |
| 3451 | 3487 | // shdr.sh_link = backlinks[shdr.sh_link]; |
| 3452 | | shdr.sh_link = self.symtab_section_index.?; |
| 3488 | shdr.sh_link = section_indexes.symtab.?; |
| 3453 | 3489 | shdr.sh_info = backlinks[shdr.sh_info]; |
| 3454 | 3490 | } |
| 3455 | 3491 | } |
| 3456 | 3492 | |
| 3457 | | if (self.zigObjectPtr()) |zo| zo.resetShdrIndexes(backlinks); |
| 3493 | if (zig_object_ptr) |zo| zo.resetShdrIndexes(backlinks); |
| 3458 | 3494 | |
| 3459 | | for (self.comdat_group_sections.items) |*cg| { |
| 3495 | for (comdat_group_sections) |*cg| { |
| 3460 | 3496 | cg.shndx = backlinks[cg.shndx]; |
| 3461 | 3497 | } |
| 3462 | 3498 | |
| 3463 | | if (self.symtab_section_index) |index| { |
| 3499 | if (section_indexes.symtab) |index| { |
| 3464 | 3500 | const shdr = &slice.items(.shdr)[index]; |
| 3465 | | shdr.sh_link = self.strtab_section_index.?; |
| 3501 | shdr.sh_link = section_indexes.strtab.?; |
| 3466 | 3502 | } |
| 3467 | 3503 | |
| 3468 | | if (self.dynamic_section_index) |index| { |
| 3504 | if (section_indexes.dynamic) |index| { |
| 3469 | 3505 | const shdr = &slice.items(.shdr)[index]; |
| 3470 | | shdr.sh_link = self.dynstrtab_section_index.?; |
| 3506 | shdr.sh_link = section_indexes.dynstrtab.?; |
| 3471 | 3507 | } |
| 3472 | 3508 | |
| 3473 | | if (self.dynsymtab_section_index) |index| { |
| 3509 | if (section_indexes.dynsymtab) |index| { |
| 3474 | 3510 | const shdr = &slice.items(.shdr)[index]; |
| 3475 | | shdr.sh_link = self.dynstrtab_section_index.?; |
| 3511 | shdr.sh_link = section_indexes.dynstrtab.?; |
| 3476 | 3512 | } |
| 3477 | 3513 | |
| 3478 | | if (self.hash_section_index) |index| { |
| 3514 | if (section_indexes.hash) |index| { |
| 3479 | 3515 | const shdr = &slice.items(.shdr)[index]; |
| 3480 | | shdr.sh_link = self.dynsymtab_section_index.?; |
| 3516 | shdr.sh_link = section_indexes.dynsymtab.?; |
| 3481 | 3517 | } |
| 3482 | 3518 | |
| 3483 | | if (self.gnu_hash_section_index) |index| { |
| 3519 | if (section_indexes.gnu_hash) |index| { |
| 3484 | 3520 | const shdr = &slice.items(.shdr)[index]; |
| 3485 | | shdr.sh_link = self.dynsymtab_section_index.?; |
| 3521 | shdr.sh_link = section_indexes.dynsymtab.?; |
| 3486 | 3522 | } |
| 3487 | 3523 | |
| 3488 | | if (self.versym_section_index) |index| { |
| 3524 | if (section_indexes.versym) |index| { |
| 3489 | 3525 | const shdr = &slice.items(.shdr)[index]; |
| 3490 | | shdr.sh_link = self.dynsymtab_section_index.?; |
| 3526 | shdr.sh_link = section_indexes.dynsymtab.?; |
| 3491 | 3527 | } |
| 3492 | 3528 | |
| 3493 | | if (self.verneed_section_index) |index| { |
| 3529 | if (section_indexes.verneed) |index| { |
| 3494 | 3530 | const shdr = &slice.items(.shdr)[index]; |
| 3495 | | shdr.sh_link = self.dynstrtab_section_index.?; |
| 3531 | shdr.sh_link = section_indexes.dynstrtab.?; |
| 3496 | 3532 | } |
| 3497 | 3533 | |
| 3498 | | if (self.rela_dyn_section_index) |index| { |
| 3534 | if (section_indexes.rela_dyn) |index| { |
| 3499 | 3535 | const shdr = &slice.items(.shdr)[index]; |
| 3500 | | shdr.sh_link = self.dynsymtab_section_index orelse 0; |
| 3536 | shdr.sh_link = section_indexes.dynsymtab orelse 0; |
| 3501 | 3537 | } |
| 3502 | 3538 | |
| 3503 | | if (self.rela_plt_section_index) |index| { |
| 3539 | if (section_indexes.rela_plt) |index| { |
| 3504 | 3540 | const shdr = &slice.items(.shdr)[index]; |
| 3505 | | shdr.sh_link = self.dynsymtab_section_index.?; |
| 3506 | | shdr.sh_info = self.plt_section_index.?; |
| 3541 | shdr.sh_link = section_indexes.dynsymtab.?; |
| 3542 | shdr.sh_info = section_indexes.plt.?; |
| 3507 | 3543 | } |
| 3508 | 3544 | |
| 3509 | | if (self.eh_frame_rela_section_index) |index| { |
| 3545 | if (section_indexes.eh_frame_rela) |index| { |
| 3510 | 3546 | const shdr = &slice.items(.shdr)[index]; |
| 3511 | | shdr.sh_link = self.symtab_section_index.?; |
| 3512 | | shdr.sh_info = self.eh_frame_section_index.?; |
| 3547 | shdr.sh_link = section_indexes.symtab.?; |
| 3548 | shdr.sh_info = section_indexes.eh_frame.?; |
| 3513 | 3549 | } |
| 3514 | 3550 | } |
| 3515 | 3551 | |
| ... | ... | @@ -3543,31 +3579,31 @@ fn updateSectionSizes(self: *Elf) !void { |
| 3543 | 3579 | } |
| 3544 | 3580 | |
| 3545 | 3581 | const shdrs = slice.items(.shdr); |
| 3546 | | if (self.eh_frame_section_index) |index| { |
| 3582 | if (self.section_indexes.eh_frame) |index| { |
| 3547 | 3583 | shdrs[index].sh_size = try eh_frame.calcEhFrameSize(self); |
| 3548 | 3584 | } |
| 3549 | 3585 | |
| 3550 | | if (self.eh_frame_hdr_section_index) |index| { |
| 3586 | if (self.section_indexes.eh_frame_hdr) |index| { |
| 3551 | 3587 | shdrs[index].sh_size = eh_frame.calcEhFrameHdrSize(self); |
| 3552 | 3588 | } |
| 3553 | 3589 | |
| 3554 | | if (self.got_section_index) |index| { |
| 3590 | if (self.section_indexes.got) |index| { |
| 3555 | 3591 | shdrs[index].sh_size = self.got.size(self); |
| 3556 | 3592 | } |
| 3557 | 3593 | |
| 3558 | | if (self.plt_section_index) |index| { |
| 3594 | if (self.section_indexes.plt) |index| { |
| 3559 | 3595 | shdrs[index].sh_size = self.plt.size(self); |
| 3560 | 3596 | } |
| 3561 | 3597 | |
| 3562 | | if (self.got_plt_section_index) |index| { |
| 3598 | if (self.section_indexes.got_plt) |index| { |
| 3563 | 3599 | shdrs[index].sh_size = self.got_plt.size(self); |
| 3564 | 3600 | } |
| 3565 | 3601 | |
| 3566 | | if (self.plt_got_section_index) |index| { |
| 3602 | if (self.section_indexes.plt_got) |index| { |
| 3567 | 3603 | shdrs[index].sh_size = self.plt_got.size(self); |
| 3568 | 3604 | } |
| 3569 | 3605 | |
| 3570 | | if (self.rela_dyn_section_index) |shndx| { |
| 3606 | if (self.section_indexes.rela_dyn) |shndx| { |
| 3571 | 3607 | var num = self.got.numRela(self) + self.copy_rel.numRela(); |
| 3572 | 3608 | if (self.zigObjectPtr()) |zig_object| { |
| 3573 | 3609 | num += zig_object.num_dynrelocs; |
| ... | ... | @@ -3578,43 +3614,43 @@ fn updateSectionSizes(self: *Elf) !void { |
| 3578 | 3614 | shdrs[shndx].sh_size = num * @sizeOf(elf.Elf64_Rela); |
| 3579 | 3615 | } |
| 3580 | 3616 | |
| 3581 | | if (self.rela_plt_section_index) |index| { |
| 3617 | if (self.section_indexes.rela_plt) |index| { |
| 3582 | 3618 | shdrs[index].sh_size = self.plt.numRela() * @sizeOf(elf.Elf64_Rela); |
| 3583 | 3619 | } |
| 3584 | 3620 | |
| 3585 | | if (self.copy_rel_section_index) |index| { |
| 3621 | if (self.section_indexes.copy_rel) |index| { |
| 3586 | 3622 | try self.copy_rel.updateSectionSize(index, self); |
| 3587 | 3623 | } |
| 3588 | 3624 | |
| 3589 | | if (self.interp_section_index) |index| { |
| 3625 | if (self.section_indexes.interp) |index| { |
| 3590 | 3626 | shdrs[index].sh_size = self.getTarget().dynamic_linker.get().?.len + 1; |
| 3591 | 3627 | } |
| 3592 | 3628 | |
| 3593 | | if (self.hash_section_index) |index| { |
| 3629 | if (self.section_indexes.hash) |index| { |
| 3594 | 3630 | shdrs[index].sh_size = self.hash.size(); |
| 3595 | 3631 | } |
| 3596 | 3632 | |
| 3597 | | if (self.gnu_hash_section_index) |index| { |
| 3633 | if (self.section_indexes.gnu_hash) |index| { |
| 3598 | 3634 | shdrs[index].sh_size = self.gnu_hash.size(); |
| 3599 | 3635 | } |
| 3600 | 3636 | |
| 3601 | | if (self.dynamic_section_index) |index| { |
| 3637 | if (self.section_indexes.dynamic) |index| { |
| 3602 | 3638 | shdrs[index].sh_size = self.dynamic.size(self); |
| 3603 | 3639 | } |
| 3604 | 3640 | |
| 3605 | | if (self.dynsymtab_section_index) |index| { |
| 3641 | if (self.section_indexes.dynsymtab) |index| { |
| 3606 | 3642 | shdrs[index].sh_size = self.dynsym.size(); |
| 3607 | 3643 | } |
| 3608 | 3644 | |
| 3609 | | if (self.dynstrtab_section_index) |index| { |
| 3645 | if (self.section_indexes.dynstrtab) |index| { |
| 3610 | 3646 | shdrs[index].sh_size = self.dynstrtab.items.len; |
| 3611 | 3647 | } |
| 3612 | 3648 | |
| 3613 | | if (self.versym_section_index) |index| { |
| 3649 | if (self.section_indexes.versym) |index| { |
| 3614 | 3650 | shdrs[index].sh_size = self.versym.items.len * @sizeOf(elf.Elf64_Versym); |
| 3615 | 3651 | } |
| 3616 | 3652 | |
| 3617 | | if (self.verneed_section_index) |index| { |
| 3653 | if (self.section_indexes.verneed) |index| { |
| 3618 | 3654 | shdrs[index].sh_size = self.verneed.size(); |
| 3619 | 3655 | } |
| 3620 | 3656 | |
| ... | ... | @@ -3624,7 +3660,7 @@ fn updateSectionSizes(self: *Elf) !void { |
| 3624 | 3660 | |
| 3625 | 3661 | // FIXME:JK this is very much obsolete, remove! |
| 3626 | 3662 | pub fn updateShStrtabSize(self: *Elf) void { |
| 3627 | | if (self.shstrtab_section_index) |index| { |
| 3663 | if (self.section_indexes.shstrtab) |index| { |
| 3628 | 3664 | self.sections.items(.shdr)[index].sh_size = self.shstrtab.items.len; |
| 3629 | 3665 | } |
| 3630 | 3666 | } |
| ... | ... | @@ -3656,7 +3692,7 @@ fn addLoadPhdrs(self: *Elf) error{OutOfMemory}!void { |
| 3656 | 3692 | if (shdr.sh_type == elf.SHT_NULL) continue; |
| 3657 | 3693 | if (shdr.sh_flags & elf.SHF_ALLOC == 0) continue; |
| 3658 | 3694 | const flags = shdrToPhdrFlags(shdr.sh_flags); |
| 3659 | | if (self.getPhdr(.{ .flags = flags, .type = elf.PT_LOAD }) == null) { |
| 3695 | if (self.getPhdr(.{ .flags = flags, .type = elf.PT_LOAD }) == .none) { |
| 3660 | 3696 | _ = try self.addPhdr(.{ .flags = flags, .type = elf.PT_LOAD }); |
| 3661 | 3697 | } |
| 3662 | 3698 | } |
| ... | ... | @@ -3664,8 +3700,8 @@ fn addLoadPhdrs(self: *Elf) error{OutOfMemory}!void { |
| 3664 | 3700 | |
| 3665 | 3701 | /// Allocates PHDR table in virtual memory and in file. |
| 3666 | 3702 | fn allocatePhdrTable(self: *Elf) error{OutOfMemory}!void { |
| 3667 | | const phdr_table = &self.phdrs.items[self.phdr_table_index.?]; |
| 3668 | | const phdr_table_load = &self.phdrs.items[self.phdr_table_load_index.?]; |
| 3703 | const phdr_table = &self.phdrs.items[self.phdr_indexes.table.int().?]; |
| 3704 | const phdr_table_load = &self.phdrs.items[self.phdr_indexes.table_load.int().?]; |
| 3669 | 3705 | |
| 3670 | 3706 | const ehsize: u64 = switch (self.ptr_width) { |
| 3671 | 3707 | .p32 => @sizeOf(elf.Elf32_Ehdr), |
| ... | ... | @@ -3757,7 +3793,7 @@ pub fn allocateAllocSections(self: *Elf) !void { |
| 3757 | 3793 | // When allocating we first find the largest required alignment |
| 3758 | 3794 | // of any section that is contained in a cover and use it to align |
| 3759 | 3795 | // the start address of the segement (and first section). |
| 3760 | | const phdr_table = &self.phdrs.items[self.phdr_table_load_index.?]; |
| 3796 | const phdr_table = &self.phdrs.items[self.phdr_indexes.table_load.int().?]; |
| 3761 | 3797 | var addr = phdr_table.p_vaddr + phdr_table.p_memsz; |
| 3762 | 3798 | |
| 3763 | 3799 | for (covers) |cover| { |
| ... | ... | @@ -3817,8 +3853,8 @@ pub fn allocateAllocSections(self: *Elf) !void { |
| 3817 | 3853 | } |
| 3818 | 3854 | |
| 3819 | 3855 | const first = slice.items(.shdr)[cover.items[0]]; |
| 3820 | | const phndx = self.getPhdr(.{ .type = elf.PT_LOAD, .flags = shdrToPhdrFlags(first.sh_flags) }).?; |
| 3821 | | const phdr = &self.phdrs.items[phndx]; |
| 3856 | const phndx = self.getPhdr(.{ .type = elf.PT_LOAD, .flags = shdrToPhdrFlags(first.sh_flags) }).unwrap().?; |
| 3857 | const phdr = &self.phdrs.items[phndx.int()]; |
| 3822 | 3858 | const allocated_size = self.allocatedSize(phdr.p_offset); |
| 3823 | 3859 | if (filesz > allocated_size) { |
| 3824 | 3860 | const old_offset = phdr.p_offset; |
| ... | ... | @@ -3830,7 +3866,7 @@ pub fn allocateAllocSections(self: *Elf) !void { |
| 3830 | 3866 | |
| 3831 | 3867 | for (cover.items) |shndx| { |
| 3832 | 3868 | const shdr = &slice.items(.shdr)[shndx]; |
| 3833 | | slice.items(.phndx)[shndx] = phndx; |
| 3869 | slice.items(.phndx)[shndx] = phndx.toOptional(); |
| 3834 | 3870 | if (shdr.sh_type == elf.SHT_NOBITS) { |
| 3835 | 3871 | shdr.sh_offset = 0; |
| 3836 | 3872 | continue; |
| ... | ... | @@ -3906,12 +3942,12 @@ pub fn allocateNonAllocSections(self: *Elf) !void { |
| 3906 | 3942 | fn allocateSpecialPhdrs(self: *Elf) void { |
| 3907 | 3943 | const slice = self.sections.slice(); |
| 3908 | 3944 | |
| 3909 | | for (&[_]struct { ?u16, ?u32 }{ |
| 3910 | | .{ self.phdr_interp_index, self.interp_section_index }, |
| 3911 | | .{ self.phdr_dynamic_index, self.dynamic_section_index }, |
| 3912 | | .{ self.phdr_gnu_eh_frame_index, self.eh_frame_hdr_section_index }, |
| 3945 | for (&[_]struct { OptionalProgramHeaderIndex, ?u32 }{ |
| 3946 | .{ self.phdr_indexes.interp, self.section_indexes.interp }, |
| 3947 | .{ self.phdr_indexes.dynamic, self.section_indexes.dynamic }, |
| 3948 | .{ self.phdr_indexes.gnu_eh_frame, self.section_indexes.eh_frame_hdr }, |
| 3913 | 3949 | }) |pair| { |
| 3914 | | if (pair[0]) |index| { |
| 3950 | if (pair[0].int()) |index| { |
| 3915 | 3951 | const shdr = slice.items(.shdr)[pair[1].?]; |
| 3916 | 3952 | const phdr = &self.phdrs.items[index]; |
| 3917 | 3953 | phdr.p_align = shdr.sh_addralign; |
| ... | ... | @@ -3926,7 +3962,7 @@ fn allocateSpecialPhdrs(self: *Elf) void { |
| 3926 | 3962 | // Set the TLS segment boundaries. |
| 3927 | 3963 | // We assume TLS sections are laid out contiguously and that there is |
| 3928 | 3964 | // a single TLS segment. |
| 3929 | | if (self.phdr_tls_index) |index| { |
| 3965 | if (self.phdr_indexes.tls.int()) |index| { |
| 3930 | 3966 | const shdrs = slice.items(.shdr); |
| 3931 | 3967 | const phdr = &self.phdrs.items[index]; |
| 3932 | 3968 | var shndx: u32 = 0; |
| ... | ... | @@ -4046,7 +4082,7 @@ pub fn updateSymtabSize(self: *Elf) !void { |
| 4046 | 4082 | strsize += ctx.strsize; |
| 4047 | 4083 | } |
| 4048 | 4084 | |
| 4049 | | if (self.got_section_index) |_| { |
| 4085 | if (self.section_indexes.got) |_| { |
| 4050 | 4086 | self.got.output_symtab_ctx.reset(); |
| 4051 | 4087 | self.got.output_symtab_ctx.ilocal = nlocals; |
| 4052 | 4088 | self.got.updateSymtabSize(self); |
| ... | ... | @@ -4054,7 +4090,7 @@ pub fn updateSymtabSize(self: *Elf) !void { |
| 4054 | 4090 | strsize += self.got.output_symtab_ctx.strsize; |
| 4055 | 4091 | } |
| 4056 | 4092 | |
| 4057 | | if (self.plt_section_index) |_| { |
| 4093 | if (self.section_indexes.plt) |_| { |
| 4058 | 4094 | self.plt.output_symtab_ctx.reset(); |
| 4059 | 4095 | self.plt.output_symtab_ctx.ilocal = nlocals; |
| 4060 | 4096 | self.plt.updateSymtabSize(self); |
| ... | ... | @@ -4062,7 +4098,7 @@ pub fn updateSymtabSize(self: *Elf) !void { |
| 4062 | 4098 | strsize += self.plt.output_symtab_ctx.strsize; |
| 4063 | 4099 | } |
| 4064 | 4100 | |
| 4065 | | if (self.plt_got_section_index) |_| { |
| 4101 | if (self.section_indexes.plt_got) |_| { |
| 4066 | 4102 | self.plt_got.output_symtab_ctx.reset(); |
| 4067 | 4103 | self.plt_got.output_symtab_ctx.ilocal = nlocals; |
| 4068 | 4104 | self.plt_got.updateSymtabSize(self); |
| ... | ... | @@ -4079,9 +4115,9 @@ pub fn updateSymtabSize(self: *Elf) !void { |
| 4079 | 4115 | } |
| 4080 | 4116 | |
| 4081 | 4117 | const slice = self.sections.slice(); |
| 4082 | | const symtab_shdr = &slice.items(.shdr)[self.symtab_section_index.?]; |
| 4118 | const symtab_shdr = &slice.items(.shdr)[self.section_indexes.symtab.?]; |
| 4083 | 4119 | symtab_shdr.sh_info = nlocals; |
| 4084 | | symtab_shdr.sh_link = self.strtab_section_index.?; |
| 4120 | symtab_shdr.sh_link = self.section_indexes.strtab.?; |
| 4085 | 4121 | |
| 4086 | 4122 | const sym_size: u64 = switch (self.ptr_width) { |
| 4087 | 4123 | .p32 => @sizeOf(elf.Elf32_Sym), |
| ... | ... | @@ -4090,7 +4126,7 @@ pub fn updateSymtabSize(self: *Elf) !void { |
| 4090 | 4126 | const needed_size = (nlocals + nglobals) * sym_size; |
| 4091 | 4127 | symtab_shdr.sh_size = needed_size; |
| 4092 | 4128 | |
| 4093 | | const strtab = &slice.items(.shdr)[self.strtab_section_index.?]; |
| 4129 | const strtab = &slice.items(.shdr)[self.section_indexes.strtab.?]; |
| 4094 | 4130 | strtab.sh_size = strsize + 1; |
| 4095 | 4131 | } |
| 4096 | 4132 | |
| ... | ... | @@ -4098,7 +4134,7 @@ fn writeSyntheticSections(self: *Elf) !void { |
| 4098 | 4134 | const gpa = self.base.comp.gpa; |
| 4099 | 4135 | const slice = self.sections.slice(); |
| 4100 | 4136 | |
| 4101 | | if (self.interp_section_index) |shndx| { |
| 4137 | if (self.section_indexes.interp) |shndx| { |
| 4102 | 4138 | var buffer: [256]u8 = undefined; |
| 4103 | 4139 | const interp = self.getTarget().dynamic_linker.get().?; |
| 4104 | 4140 | @memcpy(buffer[0..interp.len], interp); |
| ... | ... | @@ -4109,12 +4145,12 @@ fn writeSyntheticSections(self: *Elf) !void { |
| 4109 | 4145 | try self.base.file.?.pwriteAll(contents, shdr.sh_offset); |
| 4110 | 4146 | } |
| 4111 | 4147 | |
| 4112 | | if (self.hash_section_index) |shndx| { |
| 4148 | if (self.section_indexes.hash) |shndx| { |
| 4113 | 4149 | const shdr = slice.items(.shdr)[shndx]; |
| 4114 | 4150 | try self.base.file.?.pwriteAll(self.hash.buffer.items, shdr.sh_offset); |
| 4115 | 4151 | } |
| 4116 | 4152 | |
| 4117 | | if (self.gnu_hash_section_index) |shndx| { |
| 4153 | if (self.section_indexes.gnu_hash) |shndx| { |
| 4118 | 4154 | const shdr = slice.items(.shdr)[shndx]; |
| 4119 | 4155 | var buffer = try std.ArrayList(u8).initCapacity(gpa, self.gnu_hash.size()); |
| 4120 | 4156 | defer buffer.deinit(); |
| ... | ... | @@ -4122,12 +4158,12 @@ fn writeSyntheticSections(self: *Elf) !void { |
| 4122 | 4158 | try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset); |
| 4123 | 4159 | } |
| 4124 | 4160 | |
| 4125 | | if (self.versym_section_index) |shndx| { |
| 4161 | if (self.section_indexes.versym) |shndx| { |
| 4126 | 4162 | const shdr = slice.items(.shdr)[shndx]; |
| 4127 | 4163 | try self.base.file.?.pwriteAll(mem.sliceAsBytes(self.versym.items), shdr.sh_offset); |
| 4128 | 4164 | } |
| 4129 | 4165 | |
| 4130 | | if (self.verneed_section_index) |shndx| { |
| 4166 | if (self.section_indexes.verneed) |shndx| { |
| 4131 | 4167 | const shdr = slice.items(.shdr)[shndx]; |
| 4132 | 4168 | var buffer = try std.ArrayList(u8).initCapacity(gpa, self.verneed.size()); |
| 4133 | 4169 | defer buffer.deinit(); |
| ... | ... | @@ -4135,7 +4171,7 @@ fn writeSyntheticSections(self: *Elf) !void { |
| 4135 | 4171 | try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset); |
| 4136 | 4172 | } |
| 4137 | 4173 | |
| 4138 | | if (self.dynamic_section_index) |shndx| { |
| 4174 | if (self.section_indexes.dynamic) |shndx| { |
| 4139 | 4175 | const shdr = slice.items(.shdr)[shndx]; |
| 4140 | 4176 | var buffer = try std.ArrayList(u8).initCapacity(gpa, self.dynamic.size(self)); |
| 4141 | 4177 | defer buffer.deinit(); |
| ... | ... | @@ -4143,7 +4179,7 @@ fn writeSyntheticSections(self: *Elf) !void { |
| 4143 | 4179 | try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset); |
| 4144 | 4180 | } |
| 4145 | 4181 | |
| 4146 | | if (self.dynsymtab_section_index) |shndx| { |
| 4182 | if (self.section_indexes.dynsymtab) |shndx| { |
| 4147 | 4183 | const shdr = slice.items(.shdr)[shndx]; |
| 4148 | 4184 | var buffer = try std.ArrayList(u8).initCapacity(gpa, self.dynsym.size()); |
| 4149 | 4185 | defer buffer.deinit(); |
| ... | ... | @@ -4151,12 +4187,12 @@ fn writeSyntheticSections(self: *Elf) !void { |
| 4151 | 4187 | try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset); |
| 4152 | 4188 | } |
| 4153 | 4189 | |
| 4154 | | if (self.dynstrtab_section_index) |shndx| { |
| 4190 | if (self.section_indexes.dynstrtab) |shndx| { |
| 4155 | 4191 | const shdr = slice.items(.shdr)[shndx]; |
| 4156 | 4192 | try self.base.file.?.pwriteAll(self.dynstrtab.items, shdr.sh_offset); |
| 4157 | 4193 | } |
| 4158 | 4194 | |
| 4159 | | if (self.eh_frame_section_index) |shndx| { |
| 4195 | if (self.section_indexes.eh_frame) |shndx| { |
| 4160 | 4196 | const existing_size = existing_size: { |
| 4161 | 4197 | const zo = self.zigObjectPtr() orelse break :existing_size 0; |
| 4162 | 4198 | const sym = zo.symbol(zo.eh_frame_index orelse break :existing_size 0); |
| ... | ... | @@ -4171,7 +4207,7 @@ fn writeSyntheticSections(self: *Elf) !void { |
| 4171 | 4207 | try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset + existing_size); |
| 4172 | 4208 | } |
| 4173 | 4209 | |
| 4174 | | if (self.eh_frame_hdr_section_index) |shndx| { |
| 4210 | if (self.section_indexes.eh_frame_hdr) |shndx| { |
| 4175 | 4211 | const shdr = slice.items(.shdr)[shndx]; |
| 4176 | 4212 | const sh_size = math.cast(usize, shdr.sh_size) orelse return error.Overflow; |
| 4177 | 4213 | var buffer = try std.ArrayList(u8).initCapacity(gpa, sh_size); |
| ... | ... | @@ -4180,7 +4216,7 @@ fn writeSyntheticSections(self: *Elf) !void { |
| 4180 | 4216 | try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset); |
| 4181 | 4217 | } |
| 4182 | 4218 | |
| 4183 | | if (self.got_section_index) |index| { |
| 4219 | if (self.section_indexes.got) |index| { |
| 4184 | 4220 | const shdr = slice.items(.shdr)[index]; |
| 4185 | 4221 | var buffer = try std.ArrayList(u8).initCapacity(gpa, self.got.size(self)); |
| 4186 | 4222 | defer buffer.deinit(); |
| ... | ... | @@ -4188,7 +4224,7 @@ fn writeSyntheticSections(self: *Elf) !void { |
| 4188 | 4224 | try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset); |
| 4189 | 4225 | } |
| 4190 | 4226 | |
| 4191 | | if (self.rela_dyn_section_index) |shndx| { |
| 4227 | if (self.section_indexes.rela_dyn) |shndx| { |
| 4192 | 4228 | const shdr = slice.items(.shdr)[shndx]; |
| 4193 | 4229 | try self.got.addRela(self); |
| 4194 | 4230 | try self.copy_rel.addRela(self); |
| ... | ... | @@ -4196,7 +4232,7 @@ fn writeSyntheticSections(self: *Elf) !void { |
| 4196 | 4232 | try self.base.file.?.pwriteAll(mem.sliceAsBytes(self.rela_dyn.items), shdr.sh_offset); |
| 4197 | 4233 | } |
| 4198 | 4234 | |
| 4199 | | if (self.plt_section_index) |shndx| { |
| 4235 | if (self.section_indexes.plt) |shndx| { |
| 4200 | 4236 | const shdr = slice.items(.shdr)[shndx]; |
| 4201 | 4237 | var buffer = try std.ArrayList(u8).initCapacity(gpa, self.plt.size(self)); |
| 4202 | 4238 | defer buffer.deinit(); |
| ... | ... | @@ -4204,7 +4240,7 @@ fn writeSyntheticSections(self: *Elf) !void { |
| 4204 | 4240 | try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset); |
| 4205 | 4241 | } |
| 4206 | 4242 | |
| 4207 | | if (self.got_plt_section_index) |shndx| { |
| 4243 | if (self.section_indexes.got_plt) |shndx| { |
| 4208 | 4244 | const shdr = slice.items(.shdr)[shndx]; |
| 4209 | 4245 | var buffer = try std.ArrayList(u8).initCapacity(gpa, self.got_plt.size(self)); |
| 4210 | 4246 | defer buffer.deinit(); |
| ... | ... | @@ -4212,7 +4248,7 @@ fn writeSyntheticSections(self: *Elf) !void { |
| 4212 | 4248 | try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset); |
| 4213 | 4249 | } |
| 4214 | 4250 | |
| 4215 | | if (self.plt_got_section_index) |shndx| { |
| 4251 | if (self.section_indexes.plt_got) |shndx| { |
| 4216 | 4252 | const shdr = slice.items(.shdr)[shndx]; |
| 4217 | 4253 | var buffer = try std.ArrayList(u8).initCapacity(gpa, self.plt_got.size(self)); |
| 4218 | 4254 | defer buffer.deinit(); |
| ... | ... | @@ -4220,7 +4256,7 @@ fn writeSyntheticSections(self: *Elf) !void { |
| 4220 | 4256 | try self.base.file.?.pwriteAll(buffer.items, shdr.sh_offset); |
| 4221 | 4257 | } |
| 4222 | 4258 | |
| 4223 | | if (self.rela_plt_section_index) |shndx| { |
| 4259 | if (self.section_indexes.rela_plt) |shndx| { |
| 4224 | 4260 | const shdr = slice.items(.shdr)[shndx]; |
| 4225 | 4261 | try self.plt.addRela(self); |
| 4226 | 4262 | try self.base.file.?.pwriteAll(mem.sliceAsBytes(self.rela_plt.items), shdr.sh_offset); |
| ... | ... | @@ -4232,7 +4268,7 @@ fn writeSyntheticSections(self: *Elf) !void { |
| 4232 | 4268 | |
| 4233 | 4269 | // FIXME:JK again, why is this needed? |
| 4234 | 4270 | pub fn writeShStrtab(self: *Elf) !void { |
| 4235 | | if (self.shstrtab_section_index) |index| { |
| 4271 | if (self.section_indexes.shstrtab) |index| { |
| 4236 | 4272 | const shdr = self.sections.items(.shdr)[index]; |
| 4237 | 4273 | log.debug("writing .shstrtab from 0x{x} to 0x{x}", .{ shdr.sh_offset, shdr.sh_offset + shdr.sh_size }); |
| 4238 | 4274 | try self.base.file.?.pwriteAll(self.shstrtab.items, shdr.sh_offset); |
| ... | ... | @@ -4242,8 +4278,8 @@ pub fn writeShStrtab(self: *Elf) !void { |
| 4242 | 4278 | pub fn writeSymtab(self: *Elf) !void { |
| 4243 | 4279 | const gpa = self.base.comp.gpa; |
| 4244 | 4280 | const slice = self.sections.slice(); |
| 4245 | | const symtab_shdr = slice.items(.shdr)[self.symtab_section_index.?]; |
| 4246 | | const strtab_shdr = slice.items(.shdr)[self.strtab_section_index.?]; |
| 4281 | const symtab_shdr = slice.items(.shdr)[self.section_indexes.symtab.?]; |
| 4282 | const strtab_shdr = slice.items(.shdr)[self.section_indexes.strtab.?]; |
| 4247 | 4283 | const sym_size: u64 = switch (self.ptr_width) { |
| 4248 | 4284 | .p32 => @sizeOf(elf.Elf32_Sym), |
| 4249 | 4285 | .p64 => @sizeOf(elf.Elf64_Sym), |
| ... | ... | @@ -4301,15 +4337,15 @@ pub fn writeSymtab(self: *Elf) !void { |
| 4301 | 4337 | obj.asFile().writeSymtab(self); |
| 4302 | 4338 | } |
| 4303 | 4339 | |
| 4304 | | if (self.got_section_index) |_| { |
| 4340 | if (self.section_indexes.got) |_| { |
| 4305 | 4341 | self.got.writeSymtab(self); |
| 4306 | 4342 | } |
| 4307 | 4343 | |
| 4308 | | if (self.plt_section_index) |_| { |
| 4344 | if (self.section_indexes.plt) |_| { |
| 4309 | 4345 | self.plt.writeSymtab(self); |
| 4310 | 4346 | } |
| 4311 | 4347 | |
| 4312 | | if (self.plt_got_section_index) |_| { |
| 4348 | if (self.section_indexes.plt_got) |_| { |
| 4313 | 4349 | self.plt_got.writeSymtab(self); |
| 4314 | 4350 | } |
| 4315 | 4351 | |
| ... | ... | @@ -4482,14 +4518,15 @@ pub fn isEffectivelyDynLib(self: Elf) bool { |
| 4482 | 4518 | fn getPhdr(self: *Elf, opts: struct { |
| 4483 | 4519 | type: u32 = 0, |
| 4484 | 4520 | flags: u32 = 0, |
| 4485 | | }) ?u16 { |
| 4521 | }) OptionalProgramHeaderIndex { |
| 4486 | 4522 | for (self.phdrs.items, 0..) |phdr, phndx| { |
| 4487 | | if (self.phdr_table_load_index) |index| { |
| 4523 | if (self.phdr_indexes.table_load.int()) |index| { |
| 4488 | 4524 | if (phndx == index) continue; |
| 4489 | 4525 | } |
| 4490 | | if (phdr.p_type == opts.type and phdr.p_flags == opts.flags) return @intCast(phndx); |
| 4526 | if (phdr.p_type == opts.type and phdr.p_flags == opts.flags) |
| 4527 | return @enumFromInt(phndx); |
| 4491 | 4528 | } |
| 4492 | | return null; |
| 4529 | return .none; |
| 4493 | 4530 | } |
| 4494 | 4531 | |
| 4495 | 4532 | fn addPhdr(self: *Elf, opts: struct { |
| ... | ... | @@ -4500,9 +4537,9 @@ fn addPhdr(self: *Elf, opts: struct { |
| 4500 | 4537 | addr: u64 = 0, |
| 4501 | 4538 | filesz: u64 = 0, |
| 4502 | 4539 | memsz: u64 = 0, |
| 4503 | | }) error{OutOfMemory}!u16 { |
| 4540 | }) error{OutOfMemory}!ProgramHeaderIndex { |
| 4504 | 4541 | const gpa = self.base.comp.gpa; |
| 4505 | | const index = @as(u16, @intCast(self.phdrs.items.len)); |
| 4542 | const index: ProgramHeaderIndex = @enumFromInt(self.phdrs.items.len); |
| 4506 | 4543 | try self.phdrs.append(gpa, .{ |
| 4507 | 4544 | .p_type = opts.type, |
| 4508 | 4545 | .p_flags = opts.flags, |
| ... | ... | @@ -4667,13 +4704,17 @@ pub fn thunk(self: *Elf, index: Thunk.Index) *Thunk { |
| 4667 | 4704 | } |
| 4668 | 4705 | |
| 4669 | 4706 | pub fn file(self: *Elf, index: File.Index) ?File { |
| 4670 | | const tag = self.files.items(.tags)[index]; |
| 4707 | return fileLookup(self.files, index); |
| 4708 | } |
| 4709 | |
| 4710 | fn fileLookup(files: std.MultiArrayList(File.Entry), index: File.Index) ?File { |
| 4711 | const tag = files.items(.tags)[index]; |
| 4671 | 4712 | return switch (tag) { |
| 4672 | 4713 | .null => null, |
| 4673 | | .linker_defined => .{ .linker_defined = &self.files.items(.data)[index].linker_defined }, |
| 4674 | | .zig_object => .{ .zig_object = &self.files.items(.data)[index].zig_object }, |
| 4675 | | .object => .{ .object = &self.files.items(.data)[index].object }, |
| 4676 | | .shared_object => .{ .shared_object = &self.files.items(.data)[index].shared_object }, |
| 4714 | .linker_defined => .{ .linker_defined = &files.items(.data)[index].linker_defined }, |
| 4715 | .zig_object => .{ .zig_object = &files.items(.data)[index].zig_object }, |
| 4716 | .object => .{ .object = &files.items(.data)[index].object }, |
| 4717 | .shared_object => .{ .shared_object = &files.items(.data)[index].shared_object }, |
| 4677 | 4718 | }; |
| 4678 | 4719 | } |
| 4679 | 4720 | |
| ... | ... | @@ -4718,7 +4759,7 @@ pub fn linkerDefinedPtr(self: *Elf) ?*LinkerDefined { |
| 4718 | 4759 | return self.file(index).?.linker_defined; |
| 4719 | 4760 | } |
| 4720 | 4761 | |
| 4721 | | pub fn getOrCreateMergeSection(self: *Elf, name: [:0]const u8, flags: u64, @"type": u32) !MergeSection.Index { |
| 4762 | pub fn getOrCreateMergeSection(self: *Elf, name: [:0]const u8, flags: u64, @"type": u32) !Merge.Section.Index { |
| 4722 | 4763 | const gpa = self.base.comp.gpa; |
| 4723 | 4764 | const out_name = name: { |
| 4724 | 4765 | if (self.base.isRelocatable()) break :name name; |
| ... | ... | @@ -4731,7 +4772,7 @@ pub fn getOrCreateMergeSection(self: *Elf, name: [:0]const u8, flags: u64, @"typ |
| 4731 | 4772 | } |
| 4732 | 4773 | const out_off = try self.insertShString(out_name); |
| 4733 | 4774 | const out_flags = flags & ~@as(u64, elf.SHF_COMPRESSED | elf.SHF_GROUP); |
| 4734 | | const index = @as(MergeSection.Index, @intCast(self.merge_sections.items.len)); |
| 4775 | const index: Merge.Section.Index = @intCast(self.merge_sections.items.len); |
| 4735 | 4776 | const msec = try self.merge_sections.addOne(gpa); |
| 4736 | 4777 | msec.* = .{ |
| 4737 | 4778 | .name_offset = out_off, |
| ... | ... | @@ -4741,22 +4782,22 @@ pub fn getOrCreateMergeSection(self: *Elf, name: [:0]const u8, flags: u64, @"typ |
| 4741 | 4782 | return index; |
| 4742 | 4783 | } |
| 4743 | 4784 | |
| 4744 | | pub fn mergeSection(self: *Elf, index: MergeSection.Index) *MergeSection { |
| 4785 | pub fn mergeSection(self: *Elf, index: Merge.Section.Index) *Merge.Section { |
| 4745 | 4786 | assert(index < self.merge_sections.items.len); |
| 4746 | 4787 | return &self.merge_sections.items[index]; |
| 4747 | 4788 | } |
| 4748 | 4789 | |
| 4749 | 4790 | pub fn gotAddress(self: *Elf) i64 { |
| 4750 | 4791 | const shndx = blk: { |
| 4751 | | if (self.getTarget().cpu.arch == .x86_64 and self.got_plt_section_index != null) |
| 4752 | | break :blk self.got_plt_section_index.?; |
| 4753 | | break :blk if (self.got_section_index) |shndx| shndx else null; |
| 4792 | if (self.getTarget().cpu.arch == .x86_64 and self.section_indexes.got_plt != null) |
| 4793 | break :blk self.section_indexes.got_plt.?; |
| 4794 | break :blk if (self.section_indexes.got) |shndx| shndx else null; |
| 4754 | 4795 | }; |
| 4755 | 4796 | return if (shndx) |index| @intCast(self.sections.items(.shdr)[index].sh_addr) else 0; |
| 4756 | 4797 | } |
| 4757 | 4798 | |
| 4758 | 4799 | pub fn tpAddress(self: *Elf) i64 { |
| 4759 | | const index = self.phdr_tls_index orelse return 0; |
| 4800 | const index = self.phdr_indexes.tls.int() orelse return 0; |
| 4760 | 4801 | const phdr = self.phdrs.items[index]; |
| 4761 | 4802 | const addr = switch (self.getTarget().cpu.arch) { |
| 4762 | 4803 | .x86_64 => mem.alignForward(u64, phdr.p_vaddr + phdr.p_memsz, phdr.p_align), |
| ... | ... | @@ -4768,20 +4809,27 @@ pub fn tpAddress(self: *Elf) i64 { |
| 4768 | 4809 | } |
| 4769 | 4810 | |
| 4770 | 4811 | pub fn dtpAddress(self: *Elf) i64 { |
| 4771 | | const index = self.phdr_tls_index orelse return 0; |
| 4812 | const index = self.phdr_indexes.tls.int() orelse return 0; |
| 4772 | 4813 | const phdr = self.phdrs.items[index]; |
| 4773 | 4814 | return @intCast(phdr.p_vaddr); |
| 4774 | 4815 | } |
| 4775 | 4816 | |
| 4776 | 4817 | pub fn tlsAddress(self: *Elf) i64 { |
| 4777 | | const index = self.phdr_tls_index orelse return 0; |
| 4818 | const index = self.phdr_indexes.tls.int() orelse return 0; |
| 4778 | 4819 | const phdr = self.phdrs.items[index]; |
| 4779 | 4820 | return @intCast(phdr.p_vaddr); |
| 4780 | 4821 | } |
| 4781 | 4822 | |
| 4782 | 4823 | pub fn getShString(self: Elf, off: u32) [:0]const u8 { |
| 4783 | | assert(off < self.shstrtab.items.len); |
| 4784 | | return mem.sliceTo(@as([*:0]const u8, @ptrCast(self.shstrtab.items.ptr + off)), 0); |
| 4824 | return shString(self.shstrtab.items, off); |
| 4825 | } |
| 4826 | |
| 4827 | fn shString( |
| 4828 | shstrtab: []const u8, |
| 4829 | off: u32, |
| 4830 | ) [:0]const u8 { |
| 4831 | const slice = shstrtab[off..]; |
| 4832 | return slice[0..std.mem.indexOfScalar(u8, slice, 0).? :0]; |
| 4785 | 4833 | } |
| 4786 | 4834 | |
| 4787 | 4835 | pub fn insertShString(self: *Elf, name: [:0]const u8) error{OutOfMemory}!u32 { |
| ... | ... | @@ -5393,7 +5441,7 @@ const Section = struct { |
| 5393 | 5441 | shdr: elf.Elf64_Shdr, |
| 5394 | 5442 | |
| 5395 | 5443 | /// Assigned program header index if any. |
| 5396 | | phndx: ?u32 = null, |
| 5444 | phndx: OptionalProgramHeaderIndex = .none, |
| 5397 | 5445 | |
| 5398 | 5446 | /// List of atoms contributing to this section. |
| 5399 | 5447 | /// TODO currently this is only used for relocations tracking in relocatable mode |
| ... | ... | @@ -5533,6 +5581,9 @@ const relocs_log = std.log.scoped(.link_relocs); |
| 5533 | 5581 | const state_log = std.log.scoped(.link_state); |
| 5534 | 5582 | const math = std.math; |
| 5535 | 5583 | const mem = std.mem; |
| 5584 | const Allocator = std.mem.Allocator; |
| 5585 | const Cache = std.Build.Cache; |
| 5586 | const Hash = std.hash.Wyhash; |
| 5536 | 5587 | |
| 5537 | 5588 | const codegen = @import("../codegen.zig"); |
| 5538 | 5589 | const dev = @import("../dev.zig"); |
| ... | ... | @@ -5540,7 +5591,6 @@ const eh_frame = @import("Elf/eh_frame.zig"); |
| 5540 | 5591 | const gc = @import("Elf/gc.zig"); |
| 5541 | 5592 | const glibc = @import("../glibc.zig"); |
| 5542 | 5593 | const link = @import("../link.zig"); |
| 5543 | | const merge_section = @import("Elf/merge_section.zig"); |
| 5544 | 5594 | const musl = @import("../musl.zig"); |
| 5545 | 5595 | const relocatable = @import("Elf/relocatable.zig"); |
| 5546 | 5596 | const relocation = @import("Elf/relocation.zig"); |
| ... | ... | @@ -5548,12 +5598,10 @@ const target_util = @import("../target.zig"); |
| 5548 | 5598 | const trace = @import("../tracy.zig").trace; |
| 5549 | 5599 | const synthetic_sections = @import("Elf/synthetic_sections.zig"); |
| 5550 | 5600 | |
| 5601 | const Merge = @import("Elf/Merge.zig"); |
| 5551 | 5602 | const Air = @import("../Air.zig"); |
| 5552 | | const Allocator = std.mem.Allocator; |
| 5553 | 5603 | const Archive = @import("Elf/Archive.zig"); |
| 5554 | | pub const Atom = @import("Elf/Atom.zig"); |
| 5555 | 5604 | const AtomList = @import("Elf/AtomList.zig"); |
| 5556 | | const Cache = std.Build.Cache; |
| 5557 | 5605 | const Path = Cache.Path; |
| 5558 | 5606 | const Compilation = @import("../Compilation.zig"); |
| 5559 | 5607 | const ComdatGroupSection = synthetic_sections.ComdatGroupSection; |
| ... | ... | @@ -5566,15 +5614,11 @@ const File = @import("Elf/file.zig").File; |
| 5566 | 5614 | const GnuHashSection = synthetic_sections.GnuHashSection; |
| 5567 | 5615 | const GotSection = synthetic_sections.GotSection; |
| 5568 | 5616 | const GotPltSection = synthetic_sections.GotPltSection; |
| 5569 | | const Hash = std.hash.Wyhash; |
| 5570 | 5617 | const HashSection = synthetic_sections.HashSection; |
| 5571 | | const InputMergeSection = merge_section.InputMergeSection; |
| 5572 | 5618 | const LdScript = @import("Elf/LdScript.zig"); |
| 5573 | 5619 | const LinkerDefined = @import("Elf/LinkerDefined.zig"); |
| 5574 | 5620 | const Liveness = @import("../Liveness.zig"); |
| 5575 | 5621 | const LlvmObject = @import("../codegen/llvm.zig").Object; |
| 5576 | | const MergeSection = merge_section.MergeSection; |
| 5577 | | const MergeSubsection = merge_section.MergeSubsection; |
| 5578 | 5622 | const Zcu = @import("../Zcu.zig"); |
| 5579 | 5623 | const Object = @import("Elf/Object.zig"); |
| 5580 | 5624 | const InternPool = @import("../InternPool.zig"); |