| author | |
| committer | |
| log | 53c3757c007bc48e5db1b933b0713df099499d2c |
| tree | 1d1544f7aff60e0c55dae0d2e5740066b9a68f07 |
| parent | 00787885f4f99a92d85b496ff9e03993d69b1cf6 |
5 files changed, 109 insertions(+), 91 deletions(-)
src/link/Elf.zig+51-32| ... | ... | @@ -836,14 +836,20 @@ pub fn populateMissingMetadata(self: *Elf) !void { |
| 836 | 836 | } }); |
| 837 | 837 | self.zig_module_index = index; |
| 838 | 838 | const zig_module = self.file(index).?.zig_module; |
| 839 | const sym_index = try zig_module.addLocal(self); | |
| 840 | const sym = self.symbol(sym_index); | |
| 841 | const esym = zig_module.sourceSymbol(sym_index, self); | |
| 839 | ||
| 842 | 840 | const name_off = try self.strtab.insert(gpa, std.fs.path.stem(module.main_pkg.root_src_path)); |
| 843 | sym.name_offset = name_off; | |
| 841 | const symbol_index = try self.addSymbol(); | |
| 842 | try zig_module.local_symbols.append(gpa, symbol_index); | |
| 843 | const symbol_ptr = self.symbol(symbol_index); | |
| 844 | symbol_ptr.file_index = zig_module.index; | |
| 845 | symbol_ptr.name_offset = name_off; | |
| 846 | ||
| 847 | const esym_index = try zig_module.addLocalEsym(gpa); | |
| 848 | const esym = &zig_module.local_esyms.items[esym_index]; | |
| 844 | 849 | esym.st_name = name_off; |
| 845 | 850 | esym.st_info |= elf.STT_FILE; |
| 846 | 851 | esym.st_shndx = elf.SHN_ABS; |
| 852 | symbol_ptr.esym_index = esym_index; | |
| 847 | 853 | } |
| 848 | 854 | } |
| 849 | 855 | } |
| ... | ... | @@ -2194,7 +2200,7 @@ pub fn getOrCreateMetadataForLazySymbol(self: *Elf, sym: link.File.LazySymbol) ! |
| 2194 | 2200 | }; |
| 2195 | 2201 | const zig_module = self.file(self.zig_module_index.?).?.zig_module; |
| 2196 | 2202 | switch (metadata.state.*) { |
| 2197 | .unused => metadata.symbol_index.* = try zig_module.createAtom(switch (sym.kind) { | |
| 2203 | .unused => metadata.symbol_index.* = try zig_module.addAtom(switch (sym.kind) { | |
| 2198 | 2204 | .code => self.text_section_index.?, |
| 2199 | 2205 | .const_data => self.rodata_section_index.?, |
| 2200 | 2206 | }, self), |
| ... | ... | @@ -2213,7 +2219,7 @@ pub fn getOrCreateMetadataForDecl(self: *Elf, decl_index: Module.Decl.Index) !Sy |
| 2213 | 2219 | if (!gop.found_existing) { |
| 2214 | 2220 | const zig_module = self.file(self.zig_module_index.?).?.zig_module; |
| 2215 | 2221 | gop.value_ptr.* = .{ |
| 2216 | .symbol_index = try zig_module.createAtom(self.getDeclShdrIndex(decl_index), self), | |
| 2222 | .symbol_index = try zig_module.addAtom(self.getDeclShdrIndex(decl_index), self), | |
| 2217 | 2223 | .exports = .{}, |
| 2218 | 2224 | }; |
| 2219 | 2225 | } |
| ... | ... | @@ -2264,7 +2270,7 @@ fn updateDeclCode( |
| 2264 | 2270 | const required_alignment = decl.getAlignment(mod); |
| 2265 | 2271 | |
| 2266 | 2272 | const sym = self.symbol(sym_index); |
| 2267 | const esym = zig_module.sourceSymbol(sym_index, self); | |
| 2273 | const esym = &zig_module.local_esyms.items[sym.esym_index]; | |
| 2268 | 2274 | const atom_ptr = sym.atom(self).?; |
| 2269 | 2275 | const shdr_index = sym.output_section_index; |
| 2270 | 2276 | |
| ... | ... | @@ -2521,7 +2527,7 @@ fn updateLazySymbol(self: *Elf, sym: link.File.LazySymbol, symbol_index: Symbol. |
| 2521 | 2527 | const local_sym = self.symbol(symbol_index); |
| 2522 | 2528 | const phdr_index = self.phdr_to_shdr_table.get(local_sym.output_section_index).?; |
| 2523 | 2529 | local_sym.name_offset = name_str_index; |
| 2524 | const local_esym = zig_module.sourceSymbol(symbol_index, self); | |
| 2530 | const local_esym = &zig_module.local_esyms.items[local_sym.esym_index]; | |
| 2525 | 2531 | local_esym.st_name = name_str_index; |
| 2526 | 2532 | local_esym.st_info |= elf.STT_OBJECT; |
| 2527 | 2533 | local_esym.st_size = code.len; |
| ... | ... | @@ -2575,7 +2581,7 @@ pub fn lowerUnnamedConst(self: *Elf, typed_value: TypedValue, decl_index: Module |
| 2575 | 2581 | const name = self.strtab.get(name_str_index).?; |
| 2576 | 2582 | |
| 2577 | 2583 | const zig_module = self.file(self.zig_module_index.?).?.zig_module; |
| 2578 | const sym_index = try zig_module.createAtom(self.rodata_section_index.?, self); | |
| 2584 | const sym_index = try zig_module.addAtom(self.rodata_section_index.?, self); | |
| 2579 | 2585 | |
| 2580 | 2586 | const res = try codegen.generateSymbol(&self.base, decl.srcLoc(mod), typed_value, &code_buffer, .{ |
| 2581 | 2587 | .none = {}, |
| ... | ... | @@ -2597,7 +2603,7 @@ pub fn lowerUnnamedConst(self: *Elf, typed_value: TypedValue, decl_index: Module |
| 2597 | 2603 | const phdr_index = self.phdr_to_shdr_table.get(shdr_index).?; |
| 2598 | 2604 | const local_sym = self.symbol(sym_index); |
| 2599 | 2605 | local_sym.name_offset = name_str_index; |
| 2600 | const local_esym = zig_module.sourceSymbol(sym_index, self); | |
| 2606 | const local_esym = &zig_module.local_esyms.items[local_sym.esym_index]; | |
| 2601 | 2607 | local_esym.st_name = name_str_index; |
| 2602 | 2608 | local_esym.st_info |= elf.STT_OBJECT; |
| 2603 | 2609 | local_esym.st_size = code.len; |
| ... | ... | @@ -2642,10 +2648,11 @@ pub fn updateDeclExports( |
| 2642 | 2648 | |
| 2643 | 2649 | const gpa = self.base.allocator; |
| 2644 | 2650 | |
| 2651 | const zig_module = self.file(self.zig_module_index.?).?.zig_module; | |
| 2645 | 2652 | const decl = mod.declPtr(decl_index); |
| 2646 | 2653 | const decl_sym_index = try self.getOrCreateMetadataForDecl(decl_index); |
| 2647 | 2654 | const decl_sym = self.symbol(decl_sym_index); |
| 2648 | const decl_esym = decl_sym.sourceSymbol(self); | |
| 2655 | const decl_esym = zig_module.local_esyms.items[decl_sym.esym_index]; | |
| 2649 | 2656 | const decl_metadata = self.decls.getPtr(decl_index).?; |
| 2650 | 2657 | |
| 2651 | 2658 | for (exports) |exp| { |
| ... | ... | @@ -2681,21 +2688,21 @@ pub fn updateDeclExports( |
| 2681 | 2688 | }; |
| 2682 | 2689 | const stt_bits: u8 = @as(u4, @truncate(decl_esym.st_info)); |
| 2683 | 2690 | |
| 2684 | const zig_module = self.file(self.zig_module_index.?).?.zig_module; | |
| 2685 | 2691 | const sym_index = if (decl_metadata.@"export"(self, exp_name)) |exp_index| exp_index.* else blk: { |
| 2686 | const sym_index = try zig_module.addGlobal(exp_name, self); | |
| 2692 | const sym_index = try zig_module.addGlobalEsym(gpa); | |
| 2693 | _ = try zig_module.global_symbols.addOne(gpa); | |
| 2687 | 2694 | try decl_metadata.exports.append(gpa, sym_index); |
| 2688 | 2695 | break :blk sym_index; |
| 2689 | 2696 | }; |
| 2690 | const sym = self.symbol(sym_index); | |
| 2691 | sym.flags.@"export" = true; | |
| 2692 | sym.value = decl_sym.value; | |
| 2693 | sym.atom_index = decl_sym.atom_index; | |
| 2694 | sym.output_section_index = decl_sym.output_section_index; | |
| 2695 | const esym = zig_module.sourceSymbol(sym_index, self); | |
| 2696 | esym.* = decl_esym; | |
| 2697 | const name_off = try self.strtab.insert(gpa, exp_name); | |
| 2698 | const esym = &zig_module.global_esyms.items[sym_index]; | |
| 2699 | esym.st_value = decl_sym.value; | |
| 2700 | esym.st_shndx = decl_sym.output_section_index; | |
| 2697 | 2701 | esym.st_info = (stb_bits << 4) | stt_bits; |
| 2698 | _ = self.unresolved.swapRemove(sym_index); | |
| 2702 | esym.st_name = name_off; | |
| 2703 | ||
| 2704 | const gop = try self.getOrPutGlobal(name_off); | |
| 2705 | zig_module.global_symbols.items[sym_index] = gop.index; | |
| 2699 | 2706 | } |
| 2700 | 2707 | } |
| 2701 | 2708 | |
| ... | ... | @@ -2722,20 +2729,20 @@ pub fn deleteDeclExport( |
| 2722 | 2729 | ) void { |
| 2723 | 2730 | if (self.llvm_object) |_| return; |
| 2724 | 2731 | const metadata = self.decls.getPtr(decl_index) orelse return; |
| 2725 | const gpa = self.base.allocator; | |
| 2726 | 2732 | const mod = self.base.options.module.?; |
| 2727 | 2733 | const zig_module = self.file(self.zig_module_index.?).?.zig_module; |
| 2728 | 2734 | const exp_name = mod.intern_pool.stringToSlice(name); |
| 2729 | const sym_index = metadata.@"export"(self, exp_name) orelse return; | |
| 2735 | const esym_index = metadata.@"export"(self, exp_name) orelse return; | |
| 2730 | 2736 | log.debug("deleting export '{s}'", .{exp_name}); |
| 2731 | const sym = self.symbol(sym_index.*); | |
| 2732 | const esym = zig_module.sourceSymbol(sym_index.*, self); | |
| 2733 | assert(self.resolver.fetchSwapRemove(sym.name_offset) != null); // TODO don't delete it if it's not dominant | |
| 2734 | sym.* = .{}; | |
| 2735 | // TODO free list for esym! | |
| 2737 | const esym = &zig_module.global_esyms.items[esym_index.*]; | |
| 2738 | _ = zig_module.globals_lookup.remove(esym.st_name); | |
| 2739 | const sym_index = self.resolver.get(esym.st_name).?; | |
| 2740 | const sym = self.symbol(sym_index); | |
| 2741 | if (sym.file_index == zig_module.index) { | |
| 2742 | _ = self.resolver.swapRemove(esym.st_name); | |
| 2743 | sym.* = .{}; | |
| 2744 | } | |
| 2736 | 2745 | esym.* = null_sym; |
| 2737 | self.symbols_free_list.append(gpa, sym_index.*) catch {}; | |
| 2738 | sym_index.* = 0; | |
| 2739 | 2746 | } |
| 2740 | 2747 | |
| 2741 | 2748 | fn addLinkerDefinedSymbols(self: *Elf) !void { |
| ... | ... | @@ -3468,8 +3475,18 @@ pub fn globalByName(self: *Elf, name: []const u8) ?Symbol.Index { |
| 3468 | 3475 | |
| 3469 | 3476 | pub fn getGlobalSymbol(self: *Elf, name: []const u8, lib_name: ?[]const u8) !u32 { |
| 3470 | 3477 | _ = lib_name; |
| 3478 | const gpa = self.base.allocator; | |
| 3479 | const off = try self.strtab.insert(gpa, name); | |
| 3480 | const gop = try self.getOrPutGlobal(off); | |
| 3471 | 3481 | const zig_module = self.file(self.zig_module_index.?).?.zig_module; |
| 3472 | return zig_module.addGlobal(name, self); | |
| 3482 | const lookup_gop = try zig_module.globals_lookup.getOrPut(gpa, off); | |
| 3483 | if (!lookup_gop.found_existing) { | |
| 3484 | const esym_index = try zig_module.addGlobalEsym(gpa); | |
| 3485 | const esym = &zig_module.global_esyms.items[esym_index]; | |
| 3486 | esym.st_name = off; | |
| 3487 | lookup_gop.value_ptr.* = esym_index; | |
| 3488 | } | |
| 3489 | return gop.index; | |
| 3473 | 3490 | } |
| 3474 | 3491 | |
| 3475 | 3492 | const GetOrCreateComdatGroupOwnerResult = struct { |
| ... | ... | @@ -3753,8 +3770,10 @@ const DeclMetadata = struct { |
| 3753 | 3770 | exports: std.ArrayListUnmanaged(Symbol.Index) = .{}, |
| 3754 | 3771 | |
| 3755 | 3772 | fn @"export"(m: DeclMetadata, elf_file: *Elf, name: []const u8) ?*u32 { |
| 3773 | const zig_module = elf_file.file(elf_file.zig_module_index.?).?.zig_module; | |
| 3756 | 3774 | for (m.exports.items) |*exp| { |
| 3757 | if (mem.eql(u8, name, elf_file.symbol(exp.*).name(elf_file))) return exp; | |
| 3775 | const exp_name = elf_file.strtab.getAssumeExists(zig_module.global_esyms.items[exp.*].st_name); | |
| 3776 | if (mem.eql(u8, name, exp_name)) return exp; | |
| 3758 | 3777 | } |
| 3759 | 3778 | return null; |
| 3760 | 3779 | } |
src/link/Elf/Object.zig+2-2| ... | ... | @@ -8,9 +8,9 @@ shdrs: std.ArrayListUnmanaged(elf.Elf64_Shdr) = .{}, |
| 8 | 8 | strings: StringTable(.object_strings) = .{}, |
| 9 | 9 | symtab: []align(1) const elf.Elf64_Sym = &[0]elf.Elf64_Sym{}, |
| 10 | 10 | strtab: []const u8 = &[0]u8{}, |
| 11 | first_global: ?u32 = null, | |
| 11 | first_global: ?Symbol.Index = null, | |
| 12 | 12 | |
| 13 | symbols: std.ArrayListUnmanaged(u32) = .{}, | |
| 13 | symbols: std.ArrayListUnmanaged(Symbol.Index) = .{}, | |
| 14 | 14 | atoms: std.ArrayListUnmanaged(Atom.Index) = .{}, |
| 15 | 15 | comdat_groups: std.ArrayListUnmanaged(Elf.ComdatGroup.Index) = .{}, |
| 16 | 16 |
src/link/Elf/Symbol.zig+11-4| ... | ... | @@ -69,9 +69,13 @@ pub fn file(symbol: Symbol, elf_file: *Elf) ?File { |
| 69 | 69 | pub fn sourceSymbol(symbol: Symbol, elf_file: *Elf) elf.Elf64_Sym { |
| 70 | 70 | const file_ptr = symbol.file(elf_file).?; |
| 71 | 71 | switch (file_ptr) { |
| 72 | .zig_module => return file_ptr.zig_module.sourceSymbol(symbol.index, elf_file).*, | |
| 73 | .linker_defined => return file_ptr.linker_defined.symtab.items[symbol.esym_index], | |
| 74 | .object => return file_ptr.object.symtab[symbol.esym_index], | |
| 72 | .zig_module => |x| { | |
| 73 | const is_global = x.globals_lookup.contains(symbol.name_offset); | |
| 74 | if (is_global) return x.global_esyms.items[symbol.esym_index]; | |
| 75 | return x.local_esyms.items[symbol.esym_index]; | |
| 76 | }, | |
| 77 | .linker_defined => |x| return x.symtab.items[symbol.esym_index], | |
| 78 | .object => |x| return x.symtab[symbol.esym_index], | |
| 75 | 79 | } |
| 76 | 80 | } |
| 77 | 81 | |
| ... | ... | @@ -164,7 +168,10 @@ pub fn setExtra(symbol: Symbol, extras: Extra, elf_file: *Elf) void { |
| 164 | 168 | } |
| 165 | 169 | |
| 166 | 170 | pub fn setOutputSym(symbol: Symbol, elf_file: *Elf, out: *elf.Elf64_Sym) void { |
| 167 | const file_ptr = symbol.file(elf_file).?; | |
| 171 | const file_ptr = symbol.file(elf_file) orelse { | |
| 172 | out.* = Elf.null_sym; | |
| 173 | return; | |
| 174 | }; | |
| 168 | 175 | const s_sym = symbol.sourceSymbol(elf_file); |
| 169 | 176 | const st_type = symbol.type(elf_file); |
| 170 | 177 | const st_bind: u8 = blk: { |
src/link/Elf/ZigModule.zig+45-52| ... | ... | @@ -2,11 +2,11 @@ |
| 2 | 2 | path: []const u8, |
| 3 | 3 | index: File.Index, |
| 4 | 4 | |
| 5 | elf_local_symbols: std.ArrayListUnmanaged(elf.Elf64_Sym) = .{}, | |
| 6 | local_symbols: std.AutoArrayHashMapUnmanaged(Symbol.Index, void) = .{}, | |
| 7 | ||
| 8 | elf_global_symbols: std.ArrayListUnmanaged(elf.Elf64_Sym) = .{}, | |
| 9 | global_symbols: std.AutoArrayHashMapUnmanaged(Symbol.Index, void) = .{}, | |
| 5 | local_esyms: std.ArrayListUnmanaged(elf.Elf64_Sym) = .{}, | |
| 6 | global_esyms: std.ArrayListUnmanaged(elf.Elf64_Sym) = .{}, | |
| 7 | local_symbols: std.ArrayListUnmanaged(Symbol.Index) = .{}, | |
| 8 | global_symbols: std.ArrayListUnmanaged(Symbol.Index) = .{}, | |
| 9 | globals_lookup: std.AutoHashMapUnmanaged(u32, Symbol.Index) = .{}, | |
| 10 | 10 | |
| 11 | 11 | atoms: std.AutoArrayHashMapUnmanaged(Atom.Index, void) = .{}, |
| 12 | 12 | relocs: std.ArrayListUnmanaged(std.ArrayListUnmanaged(elf.Elf64_Rela)) = .{}, |
| ... | ... | @@ -14,10 +14,11 @@ relocs: std.ArrayListUnmanaged(std.ArrayListUnmanaged(elf.Elf64_Rela)) = .{}, |
| 14 | 14 | output_symtab_size: Elf.SymtabSize = .{}, |
| 15 | 15 | |
| 16 | 16 | pub fn deinit(self: *ZigModule, allocator: Allocator) void { |
| 17 | self.elf_local_symbols.deinit(allocator); | |
| 17 | self.local_esyms.deinit(allocator); | |
| 18 | self.global_esyms.deinit(allocator); | |
| 18 | 19 | self.local_symbols.deinit(allocator); |
| 19 | self.elf_global_symbols.deinit(allocator); | |
| 20 | 20 | self.global_symbols.deinit(allocator); |
| 21 | self.globals_lookup.deinit(allocator); | |
| 21 | 22 | self.atoms.deinit(allocator); |
| 22 | 23 | for (self.relocs.items) |*list| { |
| 23 | 24 | list.deinit(allocator); |
| ... | ... | @@ -25,58 +26,57 @@ pub fn deinit(self: *ZigModule, allocator: Allocator) void { |
| 25 | 26 | self.relocs.deinit(allocator); |
| 26 | 27 | } |
| 27 | 28 | |
| 28 | pub fn createAtom(self: *ZigModule, output_section_index: u16, elf_file: *Elf) !Symbol.Index { | |
| 29 | pub fn addLocalEsym(self: *ZigModule, allocator: Allocator) !Symbol.Index { | |
| 30 | try self.local_esyms.ensureUnusedCapacity(allocator, 1); | |
| 31 | const index = @as(Symbol.Index, @intCast(self.local_esyms.items.len)); | |
| 32 | const esym = self.local_esyms.addOneAssumeCapacity(); | |
| 33 | esym.* = Elf.null_sym; | |
| 34 | esym.st_info = elf.STB_LOCAL << 4; | |
| 35 | return index; | |
| 36 | } | |
| 37 | ||
| 38 | pub fn addGlobalEsym(self: *ZigModule, allocator: Allocator) !Symbol.Index { | |
| 39 | try self.global_esyms.ensureUnusedCapacity(allocator, 1); | |
| 40 | const index = @as(Symbol.Index, @intCast(self.global_esyms.items.len)); | |
| 41 | const esym = self.global_esyms.addOneAssumeCapacity(); | |
| 42 | esym.* = Elf.null_sym; | |
| 43 | esym.st_info = elf.STB_GLOBAL << 4; | |
| 44 | return index; | |
| 45 | } | |
| 46 | ||
| 47 | pub fn addAtom(self: *ZigModule, output_section_index: u16, elf_file: *Elf) !Symbol.Index { | |
| 29 | 48 | const gpa = elf_file.base.allocator; |
| 49 | ||
| 30 | 50 | const atom_index = try elf_file.addAtom(); |
| 31 | const symbol_index = try self.addLocal(elf_file); | |
| 51 | try self.atoms.putNoClobber(gpa, atom_index, {}); | |
| 32 | 52 | const atom_ptr = elf_file.atom(atom_index).?; |
| 33 | 53 | atom_ptr.file_index = self.index; |
| 34 | 54 | atom_ptr.output_section_index = output_section_index; |
| 55 | ||
| 56 | const symbol_index = try elf_file.addSymbol(); | |
| 57 | try self.local_symbols.append(gpa, symbol_index); | |
| 35 | 58 | const symbol_ptr = elf_file.symbol(symbol_index); |
| 59 | symbol_ptr.file_index = self.index; | |
| 36 | 60 | symbol_ptr.atom_index = atom_index; |
| 37 | 61 | symbol_ptr.output_section_index = output_section_index; |
| 38 | const local_esym = self.sourceSymbol(symbol_ptr.index, elf_file); | |
| 39 | local_esym.st_shndx = output_section_index; | |
| 62 | ||
| 63 | const esym_index = try self.addLocalEsym(gpa); | |
| 64 | const esym = &self.local_esyms.items[esym_index]; | |
| 65 | esym.st_shndx = output_section_index; | |
| 66 | symbol_ptr.esym_index = esym_index; | |
| 67 | ||
| 40 | 68 | const relocs_index = @as(Atom.Index, @intCast(self.relocs.items.len)); |
| 41 | 69 | const relocs = try self.relocs.addOne(gpa); |
| 42 | 70 | relocs.* = .{}; |
| 43 | 71 | atom_ptr.relocs_section_index = relocs_index; |
| 44 | try self.atoms.putNoClobber(gpa, atom_index, {}); | |
| 45 | return symbol_index; | |
| 46 | } | |
| 47 | 72 | |
| 48 | pub fn addLocal(self: *ZigModule, elf_file: *Elf) !Symbol.Index { | |
| 49 | const gpa = elf_file.base.allocator; | |
| 50 | const symbol_index = try elf_file.addSymbol(); | |
| 51 | const symbol_ptr = elf_file.symbol(symbol_index); | |
| 52 | symbol_ptr.file_index = self.index; | |
| 53 | symbol_ptr.esym_index = @as(Symbol.Index, @intCast(self.elf_local_symbols.items.len)); | |
| 54 | const local_esym = try self.elf_local_symbols.addOne(gpa); | |
| 55 | local_esym.* = Elf.null_sym; | |
| 56 | local_esym.st_info = elf.STB_LOCAL << 4; | |
| 57 | try self.local_symbols.putNoClobber(gpa, symbol_index, {}); | |
| 58 | 73 | return symbol_index; |
| 59 | 74 | } |
| 60 | 75 | |
| 61 | pub fn addGlobal(self: *ZigModule, name: []const u8, elf_file: *Elf) !Symbol.Index { | |
| 62 | const gpa = elf_file.base.allocator; | |
| 63 | try self.elf_global_symbols.ensureUnusedCapacity(gpa, 1); | |
| 64 | try self.global_symbols.ensureUnusedCapacity(gpa, 1); | |
| 65 | const off = try elf_file.strtab.insert(gpa, name); | |
| 66 | const esym_index = @as(Symbol.Index, @intCast(self.elf_global_symbols.items.len)); | |
| 67 | const esym = self.elf_global_symbols.addOneAssumeCapacity(); | |
| 68 | esym.* = Elf.null_sym; | |
| 69 | esym.st_name = off; | |
| 70 | esym.st_info = elf.STB_GLOBAL << 4; | |
| 71 | const gop = try elf_file.getOrPutGlobal(off); | |
| 72 | if (!gop.found_existing) { | |
| 73 | try elf_file.unresolved.putNoClobber(gpa, gop.index, {}); | |
| 74 | } | |
| 75 | const sym = elf_file.symbol(gop.index); | |
| 76 | sym.file_index = self.index; | |
| 77 | sym.esym_index = esym_index; | |
| 78 | self.global_symbols.putAssumeCapacityNoClobber(gop.index, {}); | |
| 79 | return gop.index; | |
| 76 | pub fn resolveSymbols(self: *ZigModule, elf_file: *Elf) void { | |
| 77 | _ = self; | |
| 78 | _ = elf_file; | |
| 79 | @panic("TODO"); | |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | 82 | pub fn updateSymtabSize(self: *ZigModule, elf_file: *Elf) void { |
| ... | ... | @@ -133,19 +133,12 @@ pub fn writeSymtab(self: *ZigModule, elf_file: *Elf, ctx: anytype) void { |
| 133 | 133 | } |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | pub fn sourceSymbol(self: *ZigModule, symbol_index: Symbol.Index, elf_file: *Elf) *elf.Elf64_Sym { | |
| 137 | const sym = elf_file.symbol(symbol_index); | |
| 138 | if (self.local_symbols.get(symbol_index)) |_| return &self.elf_local_symbols.items[sym.esym_index]; | |
| 139 | assert(self.global_symbols.get(symbol_index) != null); | |
| 140 | return &self.elf_global_symbols.items[sym.esym_index]; | |
| 141 | } | |
| 142 | ||
| 143 | 136 | pub fn locals(self: *ZigModule) []const Symbol.Index { |
| 144 | return self.local_symbols.keys(); | |
| 137 | return self.local_symbols.items; | |
| 145 | 138 | } |
| 146 | 139 | |
| 147 | 140 | pub fn globals(self: *ZigModule) []const Symbol.Index { |
| 148 | return self.global_symbols.keys(); | |
| 141 | return self.global_symbols.items; | |
| 149 | 142 | } |
| 150 | 143 | |
| 151 | 144 | pub fn asFile(self: *ZigModule) File { |
src/link/Elf/file.zig-1| ... | ... | @@ -32,7 +32,6 @@ pub const File = union(enum) { |
| 32 | 32 | |
| 33 | 33 | pub fn resolveSymbols(file: File, elf_file: *Elf) void { |
| 34 | 34 | switch (file) { |
| 35 | .zig_module => unreachable, // handled separately | |
| 36 | 35 | inline else => |x| x.resolveSymbols(elf_file), |
| 37 | 36 | } |
| 38 | 37 | } |