| ... | @@ -647,15 +647,12 @@ pub const SymbolTable = struct { | ... | @@ -647,15 +647,12 @@ pub const SymbolTable = struct { |
| 647 | }; | 647 | }; |
| 648 | | 648 | |
| 649 | pub const SymbolName = union(enum) { | 649 | pub const SymbolName = union(enum) { |
| 650 | short: []const u8, | 650 | short: [8]u8, |
| 651 | long: StringIndex, | 651 | long: StringIndex, |
| 652 | | 652 | |
| 653 | pub fn store(name: SymbolName, coff: *const Coff, field: *[8]u8) void { | 653 | pub fn store(name: SymbolName, coff: *const Coff, field: *[8]u8) void { |
| 654 | switch (name) { | 654 | switch (name) { |
| 655 | .short => |s| { | 655 | .short => |s| field.* = s, |
| 656 | @memcpy(field[0..s.len], s); | | |
| 657 | @memset(field[s.len..], 0); | | |
| 658 | }, | | |
| 659 | .long => |l| { | 656 | .long => |l| { |
| 660 | @memset(field[0..4], 0); | 657 | @memset(field[0..4], 0); |
| 661 | std.mem.writePackedInt(u32, field[4..], 0, @backingInt(l), coff.targetEndian()); | 658 | std.mem.writePackedInt(u32, field[4..], 0, @backingInt(l), coff.targetEndian()); |
| ... | @@ -2728,29 +2725,42 @@ fn getString(coff: *Coff, string: []const u8) String.Optional { | ... | @@ -2728,29 +2725,42 @@ fn getString(coff: *Coff, string: []const u8) String.Optional { |
| 2728 | return .none; | 2725 | return .none; |
| 2729 | } | 2726 | } |
| 2730 | | 2727 | |
| 2731 | /// If the name does not fit in the symbol header, adds it to the symbol table string table. | 2728 | /// If the name does not fit within inline storage, adds it to the symbol table string table. |
| 2732 | /// If the caller knows this name already has a String associated with it, they can avoid | 2729 | fn getOrPutSymbolName(coff: *Coff, name: union(enum) { |
| 2733 | /// a redundant call to `getOrPutString` by specifying `opt_string`. | 2730 | slice: []const u8, |
| 2734 | /// The lifetime of the return value matches that of `name`. | 2731 | string: String, |
| 2735 | fn getOrPutSymbolName(coff: *Coff, name: []const u8, opt_string: ?String) !SymbolTable.SymbolName { | 2732 | }) !SymbolTable.SymbolName { |
| 2736 | assert(!coff.isImage()); | 2733 | assert(!coff.isImage()); |
| 2737 | const gpa = coff.base.comp.gpa; | 2734 | const gpa = coff.base.comp.gpa; |
| | 2735 | const slice = switch (name) { |
| | 2736 | .slice => |s| s, |
| | 2737 | .string => |s| s.toSlice(coff), |
| | 2738 | }; |
| | 2739 | |
| | 2740 | if (slice.len > header_name_max_len) { |
| | 2741 | const string = switch (name) { |
| | 2742 | .slice => |s| try coff.getOrPutString(s), |
| | 2743 | .string => |s| s, |
| | 2744 | }; |
| 2738 | | 2745 | |
| 2739 | return if (name.len > header_name_max_len) name: { | | |
| 2740 | const string = opt_string orelse try coff.getOrPutString(name); | | |
| 2741 | const string_gop = try coff.symbol_table.strings.getOrPut(gpa, string); | 2746 | const string_gop = try coff.symbol_table.strings.getOrPut(gpa, string); |
| 2742 | if (!string_gop.found_existing) { | 2747 | if (!string_gop.found_existing) { |
| 2743 | const string_index = coff.symbol_table.strings_ni.location(&coff.mf).resolve(&coff.mf)[1]; | 2748 | const string_index = coff.symbol_table.strings_ni.location(&coff.mf).resolve(&coff.mf)[1]; |
| 2744 | string_gop.value_ptr.* = @fromBackingInt(@intCast(string_index)); | 2749 | string_gop.value_ptr.* = @fromBackingInt(@intCast(string_index)); |
| 2745 | | 2750 | |
| 2746 | try coff.symbol_table.strings_ni.resizeLeaf(gpa, &coff.mf, string_index + name.len + 1); | 2751 | try coff.symbol_table.strings_ni.resizeLeaf(gpa, &coff.mf, string_index + slice.len + 1); |
| 2747 | const slice = coff.symbol_table.strings_ni.slice(&coff.mf); | 2752 | const storage = coff.symbol_table.strings_ni.slice(&coff.mf); |
| 2748 | @memcpy(slice[@intCast(string_index)..][0..name.len], name); | 2753 | @memcpy(storage[@intCast(string_index)..][0..slice.len], slice); |
| 2749 | slice[@intCast(string_index + name.len)] = 0; | 2754 | storage[@intCast(string_index + slice.len)] = 0; |
| 2750 | } | 2755 | } |
| 2751 | | 2756 | |
| 2752 | break :name .{ .long = string_gop.value_ptr.* }; | 2757 | return .{ .long = string_gop.value_ptr.* }; |
| 2753 | } else .{ .short = name }; | 2758 | } else { |
| | 2759 | var symbol_name: SymbolTable.SymbolName = .{ .short = undefined }; |
| | 2760 | @memcpy(symbol_name.short[0..slice.len], slice); |
| | 2761 | @memset(symbol_name.short[slice.len..], 0); |
| | 2762 | return symbol_name; |
| | 2763 | } |
| 2754 | } | 2764 | } |
| 2755 | | 2765 | |
| 2756 | /// `len` does not include null terminators | 2766 | /// `len` does not include null terminators |
| ... | @@ -2862,7 +2872,7 @@ pub fn globalSymbol(coff: *Coff, opts: struct { | ... | @@ -2862,7 +2872,7 @@ pub fn globalSymbol(coff: *Coff, opts: struct { |
| 2862 | break :lib_name .lib_c; | 2872 | break :lib_name .lib_c; |
| 2863 | } | 2873 | } |
| 2864 | | 2874 | |
| 2865 | try coff.ensureManyUnusedStringCapacity(2, opts.name.len + lib_name.len); | 2875 | try coff.ensureManyUnusedStringCapacity(2, opts.name.len + lib_name.len + 2); |
| 2866 | break :lib_name .{ .explicit = coff.getOrPutStringAssumeCapacity(lib_name) }; | 2876 | break :lib_name .{ .explicit = coff.getOrPutStringAssumeCapacity(lib_name) }; |
| 2867 | } else .any; | 2877 | } else .any; |
| 2868 | | 2878 | |
| ... | @@ -3146,7 +3156,7 @@ fn ensureMemberSymbol(coff: *Coff, mi: Member.Index, name: String) !void { | ... | @@ -3146,7 +3156,7 @@ fn ensureMemberSymbol(coff: *Coff, mi: Member.Index, name: String) !void { |
| 3146 | coff.targetStore(coff.secondLinkerMemberNumSymbolsPtr(), @backingInt(mfli) + 1); | 3156 | coff.targetStore(coff.secondLinkerMemberNumSymbolsPtr(), @backingInt(mfli) + 1); |
| 3147 | if (!needs_sort) { | 3157 | if (!needs_sort) { |
| 3148 | @memmove(slice[new_header_size..][0..coff.lib_string_len], slice[old_header_size..][0..coff.lib_string_len]); | 3158 | @memmove(slice[new_header_size..][0..coff.lib_string_len], slice[old_header_size..][0..coff.lib_string_len]); |
| 3149 | @memcpy(slice[new_header_size + coff.lib_string_len ..][0..name_slice.len], name_slice[0..name_slice.len]); | 3159 | @memcpy(slice[new_header_size + coff.lib_string_len ..][0..name_slice.len], name_slice); |
| 3150 | slice[new_header_size + coff.lib_string_len + name_slice.len] = 0; | 3160 | slice[new_header_size + coff.lib_string_len + name_slice.len] = 0; |
| 3151 | } else if (!old_needs_sort) { | 3161 | } else if (!old_needs_sort) { |
| 3152 | // The entire string table is rebuilt in flushMember after sorting | 3162 | // The entire string table is rebuilt in flushMember after sorting |
| ... | @@ -3175,9 +3185,8 @@ fn flushSymbolTableEntry(coff: *Coff, index: u32) !void { | ... | @@ -3175,9 +3185,8 @@ fn flushSymbolTableEntry(coff: *Coff, index: u32) !void { |
| 3175 | const entry = coff.symbolTableEntryPtr(sti.*) orelse entry: { | 3185 | const entry = coff.symbolTableEntryPtr(sti.*) orelse entry: { |
| 3176 | const symbol_name, const num_aux_symbols: u8, const complex_type: std.coff.ComplexType = | 3186 | const symbol_name, const num_aux_symbols: u8, const complex_type: std.coff.ComplexType = |
| 3177 | if (sym.gmi != .none) blk: { | 3187 | if (sym.gmi != .none) blk: { |
| 3178 | const name = sym.gmi.name(coff); | | |
| 3179 | break :blk .{ | 3188 | break :blk .{ |
| 3180 | try coff.getOrPutSymbolName(name.toSlice(coff), name), | 3189 | try coff.getOrPutSymbolName(.{ .string = sym.gmi.name(coff) }), |
| 3181 | @intFromBool(sym.flags.weak_external_strat != .none), | 3190 | @intFromBool(sym.flags.weak_external_strat != .none), |
| 3182 | if (Symbol.Index.text.get(coff).section_number == sym.section_number) | 3191 | if (Symbol.Index.text.get(coff).section_number == sym.section_number) |
| 3183 | .FUNCTION | 3192 | .FUNCTION |
| ... | @@ -3186,7 +3195,7 @@ fn flushSymbolTableEntry(coff: *Coff, index: u32) !void { | ... | @@ -3186,7 +3195,7 @@ fn flushSymbolTableEntry(coff: *Coff, index: u32) !void { |
| 3186 | }; | 3195 | }; |
| 3187 | } else blk: switch (coff.getNode(sym.ni.unwrap().?)) { | 3196 | } else blk: switch (coff.getNode(sym.ni.unwrap().?)) { |
| 3188 | .image_section => .{ | 3197 | .image_section => .{ |
| 3189 | try coff.getOrPutSymbolName(&sym.section_number.header(coff).name, null), | 3198 | try coff.getOrPutSymbolName(.{ .slice = &sym.section_number.header(coff).name }), |
| 3190 | 1, | 3199 | 1, |
| 3191 | .NULL, | 3200 | .NULL, |
| 3192 | }, | 3201 | }, |
| ... | @@ -3195,7 +3204,7 @@ fn flushSymbolTableEntry(coff: *Coff, index: u32) !void { | ... | @@ -3195,7 +3204,7 @@ fn flushSymbolTableEntry(coff: *Coff, index: u32) !void { |
| 3195 | const ip = &zcu.intern_pool; | 3204 | const ip = &zcu.intern_pool; |
| 3196 | const nav = ip.getNav(nmi.navIndex(coff)); | 3205 | const nav = ip.getNav(nmi.navIndex(coff)); |
| 3197 | break :blk .{ | 3206 | break :blk .{ |
| 3198 | try coff.getOrPutSymbolName(nav.fqn.toSlice(ip), null), | 3207 | try coff.getOrPutSymbolName(.{ .slice = nav.fqn.toSlice(ip) }), |
| 3199 | 0, | 3208 | 0, |
| 3200 | if (ip.isFunctionType(nav.resolved.?.type)) .FUNCTION else .NULL, | 3209 | if (ip.isFunctionType(nav.resolved.?.type)) .FUNCTION else .NULL, |
| 3201 | }; | 3210 | }; |
| ... | @@ -3204,7 +3213,7 @@ fn flushSymbolTableEntry(coff: *Coff, index: u32) !void { | ... | @@ -3204,7 +3213,7 @@ fn flushSymbolTableEntry(coff: *Coff, index: u32) !void { |
| 3204 | var name_buf: [std.fmt.count("__anon_{d}", .{std.math.maxInt(u32)})]u8 = undefined; | 3213 | var name_buf: [std.fmt.count("__anon_{d}", .{std.math.maxInt(u32)})]u8 = undefined; |
| 3205 | const name = std.mem.print(&name_buf, "__anon_{d}", .{umi}) catch unreachable; | 3214 | const name = std.mem.print(&name_buf, "__anon_{d}", .{umi}) catch unreachable; |
| 3206 | break :blk .{ | 3215 | break :blk .{ |
| 3207 | try coff.getOrPutSymbolName(name, null), | 3216 | try coff.getOrPutSymbolName(.{ .slice = name }), |
| 3208 | 0, | 3217 | 0, |
| 3209 | .NULL, | 3218 | .NULL, |
| 3210 | }; | 3219 | }; |
| ... | @@ -3218,9 +3227,8 @@ fn flushSymbolTableEntry(coff: *Coff, index: u32) !void { | ... | @@ -3218,9 +3227,8 @@ fn flushSymbolTableEntry(coff: *Coff, index: u32) !void { |
| 3218 | lazy_sym.kind, mi, | 3227 | lazy_sym.kind, mi, |
| 3219 | }) catch unreachable; | 3228 | }) catch unreachable; |
| 3220 | | 3229 | |
| 3221 | const string = try coff.getOrPutString(name); | | |
| 3222 | break :blk .{ | 3230 | break :blk .{ |
| 3223 | try coff.getOrPutSymbolName(string.toSlice(coff), string), | 3231 | try coff.getOrPutSymbolName(.{ .slice = name }), |
| 3224 | 0, | 3232 | 0, |
| 3225 | if (tag == .lazy_code) .FUNCTION else .NULL, | 3233 | if (tag == .lazy_code) .FUNCTION else .NULL, |
| 3226 | }; | 3234 | }; |
| ... | @@ -3451,8 +3459,8 @@ fn addSection(coff: *Coff, name: String, flags: std.coff.SectionHeader.Flags) !S | ... | @@ -3451,8 +3459,8 @@ fn addSection(coff: *Coff, name: String, flags: std.coff.SectionHeader.Flags) !S |
| 3451 | if (coff.targetEndian() != native_endian) | 3459 | if (coff.targetEndian() != native_endian) |
| 3452 | std.mem.byteSwapAllFields(std.coff.SectionHeader, section); | 3460 | std.mem.byteSwapAllFields(std.coff.SectionHeader, section); |
| 3453 | | 3461 | |
| 3454 | const name_slice = name.toSlice(coff); | | |
| 3455 | if (coff.isImage()) { | 3462 | if (coff.isImage()) { |
| | 3463 | const name_slice = name.toSlice(coff); |
| 3456 | @memcpy(section.name[0..name_slice.len], name_slice); | 3464 | @memcpy(section.name[0..name_slice.len], name_slice); |
| 3457 | @memset(section.name[name_slice.len..], 0); | 3465 | @memset(section.name[name_slice.len..], 0); |
| 3458 | switch (coff.optionalHeaderPtr()) { | 3466 | switch (coff.optionalHeaderPtr()) { |
| ... | @@ -3462,7 +3470,7 @@ fn addSection(coff: *Coff, name: String, flags: std.coff.SectionHeader.Flags) !S | ... | @@ -3462,7 +3470,7 @@ fn addSection(coff: *Coff, name: String, flags: std.coff.SectionHeader.Flags) !S |
| 3462 | ), | 3470 | ), |
| 3463 | } | 3471 | } |
| 3464 | } else { | 3472 | } else { |
| 3465 | (try coff.getOrPutSymbolName(name_slice, name)).store(coff, &section.name); | 3473 | (try coff.getOrPutSymbolName(.{ .string = name })).store(coff, &section.name); |
| 3466 | try coff.pendingSymbolTableEntry(si); | 3474 | try coff.pendingSymbolTableEntry(si); |
| 3467 | } | 3475 | } |
| 3468 | | 3476 | |
| ... | @@ -3585,12 +3593,21 @@ fn objectSectionMapIndex( | ... | @@ -3585,12 +3593,21 @@ fn objectSectionMapIndex( |
| 3585 | const object_section_gop = try coff.object_section_table.getOrPut(gpa, name); | 3593 | const object_section_gop = try coff.object_section_table.getOrPut(gpa, name); |
| 3586 | const osmi: Node.ObjectSectionMapIndex = @fromBackingInt(@intCast(object_section_gop.index)); | 3594 | const osmi: Node.ObjectSectionMapIndex = @fromBackingInt(@intCast(object_section_gop.index)); |
| 3587 | const sym = if (!object_section_gop.found_existing) sym: { | 3595 | const sym = if (!object_section_gop.found_existing) sym: { |
| 3588 | const name_slice = name.toSlice(coff); | 3596 | const name_slice, const parent_name = blk: { |
| 3589 | const parent_name_slice = coff.objectSectionParentName(name_slice); | 3597 | var name_slice = name.toSlice(coff); |
| 3590 | const parent_name = if (parent_name_slice.len < name_slice.len) parent_name: { | 3598 | const parent_name_slice = coff.objectSectionParentName(name_slice); |
| 3591 | try coff.ensureUnusedStringCapacity(parent_name_slice.len); | 3599 | const parent_name = if (parent_name_slice.len < name_slice.len) parent_name: { |
| 3592 | break :parent_name coff.getOrPutStringAssumeCapacity(name.toSlice(coff)[0..parent_name_slice.len]); | 3600 | try coff.ensureUnusedStringCapacity(parent_name_slice.len); |
| 3593 | } else name; | 3601 | name_slice = name.toSlice(coff); |
| | 3602 | break :parent_name coff.getOrPutStringAssumeCapacity(name_slice[0..parent_name_slice.len]); |
| | 3603 | } else name; |
| | 3604 | |
| | 3605 | break :blk .{ name_slice, parent_name }; |
| | 3606 | }; |
| | 3607 | |
| | 3608 | coff.string_bytes.lockPointers(); |
| | 3609 | defer coff.string_bytes.unlockPointers(); |
| | 3610 | |
| 3594 | const parent = (try coff.pseudoSectionMapIndex(parent_name, alignment, attributes)).symbol(coff); | 3611 | const parent = (try coff.pseudoSectionMapIndex(parent_name, alignment, attributes)).symbol(coff); |
| 3595 | try coff.nodes.ensureUnusedCapacity(gpa, 1); | 3612 | try coff.nodes.ensureUnusedCapacity(gpa, 1); |
| 3596 | try coff.symbols.ensureUnusedCapacity(gpa, 1); | 3613 | try coff.symbols.ensureUnusedCapacity(gpa, 1); |
| ... | @@ -5998,12 +6015,12 @@ fn resolve(coff: *Coff, tid: Zcu.PerThread.Id) !bool { | ... | @@ -5998,12 +6015,12 @@ fn resolve(coff: *Coff, tid: Zcu.PerThread.Id) !bool { |
| 5998 | break :task; | 6015 | break :task; |
| 5999 | } | 6016 | } |
| 6000 | if (coff.pending_input) |pending_iami| { | 6017 | if (coff.pending_input) |pending_iami| { |
| 6001 | const name_slice = pending_iami.member(coff).name.toSlice(coff); | | |
| 6002 | const sub_prog_node = coff.input_prog_node.start( | 6018 | const sub_prog_node = coff.input_prog_node.start( |
| 6003 | name_slice, | 6019 | pending_iami.member(coff).name.toSlice(coff), |
| 6004 | 0, | 6020 | 0, |
| 6005 | ); | 6021 | ); |
| 6006 | defer sub_prog_node.end(); | 6022 | defer sub_prog_node.end(); |
| | 6023 | |
| 6007 | coff.pending_input = null; | 6024 | coff.pending_input = null; |
| 6008 | coff.flushInputMember(pending_iami) catch |err| switch (err) { | 6025 | coff.flushInputMember(pending_iami) catch |err| switch (err) { |
| 6009 | error.OutOfMemory => return error.OutOfMemory, | 6026 | error.OutOfMemory => return error.OutOfMemory, |
| ... | @@ -6011,7 +6028,7 @@ fn resolve(coff: *Coff, tid: Zcu.PerThread.Id) !bool { | ... | @@ -6011,7 +6028,7 @@ fn resolve(coff: *Coff, tid: Zcu.PerThread.Id) !bool { |
| 6011 | "linker failed to load archive member '{f}{f}': {t}", | 6028 | "linker failed to load archive member '{f}{f}': {t}", |
| 6012 | .{ | 6029 | .{ |
| 6013 | pending_iami.member(coff).iai.path(coff), | 6030 | pending_iami.member(coff).iai.path(coff), |
| 6014 | fmtMemberNameString(name_slice), | 6031 | fmtMemberNameString(pending_iami.member(coff).name.toSlice(coff)), |
| 6015 | e, | 6032 | e, |
| 6016 | }, | 6033 | }, |
| 6017 | ), | 6034 | ), |
| ... | @@ -6357,16 +6374,18 @@ fn flushGlobal(coff: *Coff, gmi: Node.GlobalMapIndex) !bool { | ... | @@ -6357,16 +6374,18 @@ fn flushGlobal(coff: *Coff, gmi: Node.GlobalMapIndex) !bool { |
| 6357 | | 6374 | |
| 6358 | const import: Import = import: { | 6375 | const import: Import = import: { |
| 6359 | const sym = si.get(coff); | 6376 | const sym = si.get(coff); |
| 6360 | const name_slice = name.toSlice(coff); | 6377 | const imp_match, const name_len = blk: { |
| 6361 | const imp_match = std.mem.startsWith(u8, name_slice, imp_prefix); | 6378 | const name_slice = name.toSlice(coff); |
| | 6379 | break :blk .{ std.mem.startsWith(u8, name_slice, imp_prefix), name_slice.len }; |
| | 6380 | }; |
| 6362 | | 6381 | |
| 6363 | // Globals may have the __imp_ prefix already if they are undef externals from another input. | 6382 | // Globals may have the __imp_ prefix already if they are undef externals from another input. |
| 6364 | assert(sym.flags.dll_storage_class != .dllexport); | 6383 | assert(sym.flags.dll_storage_class != .dllexport); |
| 6365 | const search_name, const is_imp = if (imp_match or sym.flags.dll_storage_class != .dllimport) | 6384 | const search_name, const is_imp = if (imp_match or sym.flags.dll_storage_class != .dllimport) |
| 6366 | .{ name, imp_match } | 6385 | .{ name, imp_match } |
| 6367 | else name: { | 6386 | else name: { |
| 6368 | try coff.ensureUnusedStringCapacity(imp_prefix.len + name_slice.len); | 6387 | try coff.ensureUnusedStringCapacity(imp_prefix.len + name_len); |
| 6369 | const imp_name = try gpa.print(imp_prefix ++ "{s}", .{name_slice}); | 6388 | const imp_name = try gpa.print(imp_prefix ++ "{s}", .{name.toSlice(coff)}); |
| 6370 | defer gpa.free(imp_name); | 6389 | defer gpa.free(imp_name); |
| 6371 | break :name .{ coff.getOrPutStringAssumeCapacity(imp_name), true }; | 6390 | break :name .{ coff.getOrPutStringAssumeCapacity(imp_name), true }; |
| 6372 | }; | 6391 | }; |
| ... | @@ -6429,6 +6448,7 @@ fn flushGlobal(coff: *Coff, gmi: Node.GlobalMapIndex) !bool { | ... | @@ -6429,6 +6448,7 @@ fn flushGlobal(coff: *Coff, gmi: Node.GlobalMapIndex) !bool { |
| 6429 | .NAME_UNDECORATE, | 6448 | .NAME_UNDECORATE, |
| 6430 | => |tag| { | 6449 | => |tag| { |
| 6431 | const symbol_name: []const u8 = import.symbol_name.toSlice(coff); | 6450 | const symbol_name: []const u8 = import.symbol_name.toSlice(coff); |
| | 6451 | const name_slice = name.toSlice(coff); |
| 6432 | const end_match = std.mem.endsWith(u8, name_slice, symbol_name); | 6452 | const end_match = std.mem.endsWith(u8, name_slice, symbol_name); |
| 6433 | const len_delta = name_slice.len -% symbol_name.len; | 6453 | const len_delta = name_slice.len -% symbol_name.len; |
| 6434 | if (!end_match or | 6454 | if (!end_match or |
| ... | @@ -6520,10 +6540,10 @@ fn flushGlobal(coff: *Coff, gmi: Node.GlobalMapIndex) !bool { | ... | @@ -6520,10 +6540,10 @@ fn flushGlobal(coff: *Coff, gmi: Node.GlobalMapIndex) !bool { |
| 6520 | | 6540 | |
| 6521 | const target_endian = coff.targetEndian(); | 6541 | const target_endian = coff.targetEndian(); |
| 6522 | const addr_info = coff.targetAddrInfo(); | 6542 | const addr_info = coff.targetAddrInfo(); |
| 6523 | const lib_name = import.lib_name.toSlice(coff); | 6543 | const lib_name_slice = import.lib_name.toSlice(coff); |
| 6524 | const gop = try coff.import_table.entries.getOrPutAdapted( | 6544 | const gop = try coff.import_table.entries.getOrPutAdapted( |
| 6525 | gpa, | 6545 | gpa, |
| 6526 | lib_name, | 6546 | lib_name_slice, |
| 6527 | ImportTable.Adapter{ .coff = coff }, | 6547 | ImportTable.Adapter{ .coff = coff }, |
| 6528 | ); | 6548 | ); |
| 6529 | const import_hint_name_align: Alignment = .@"2"; | 6549 | const import_hint_name_align: Alignment = .@"2"; |
| ... | @@ -6535,7 +6555,7 @@ fn flushGlobal(coff: *Coff, gmi: Node.GlobalMapIndex) !bool { | ... | @@ -6535,7 +6555,7 @@ fn flushGlobal(coff: *Coff, gmi: Node.GlobalMapIndex) !bool { |
| 6535 | @sizeOf(std.coff.ImportDirectoryEntry) * (gop.index + 2), | 6555 | @sizeOf(std.coff.ImportDirectoryEntry) * (gop.index + 2), |
| 6536 | ); | 6556 | ); |
| 6537 | const import_hint_name_table_len = | 6557 | const import_hint_name_table_len = |
| 6538 | import_hint_name_align.forward(lib_name.len + ".dll".len + 1); | 6558 | import_hint_name_align.forward(lib_name_slice.len + ".dll".len + 1); |
| 6539 | const idata_section_ni = coff.import_table.ni.parent(&coff.mf).unwrap().?; | 6559 | const idata_section_ni = coff.import_table.ni.parent(&coff.mf).unwrap().?; |
| 6540 | const import_lookup_table_ni = try idata_section_ni.addFloatingChild(gpa, &coff.mf, .{ | 6560 | const import_lookup_table_ni = try idata_section_ni.addFloatingChild(gpa, &coff.mf, .{ |
| 6541 | .size = addr_info.size * 2, | 6561 | .size = addr_info.size * 2, |
| ... | @@ -6570,9 +6590,9 @@ fn flushGlobal(coff: *Coff, gmi: Node.GlobalMapIndex) !bool { | ... | @@ -6570,9 +6590,9 @@ fn flushGlobal(coff: *Coff, gmi: Node.GlobalMapIndex) !bool { |
| 6570 | .hint_name_len = @intCast(import_hint_name_table_len), | 6590 | .hint_name_len = @intCast(import_hint_name_table_len), |
| 6571 | }; | 6591 | }; |
| 6572 | const import_hint_name_slice = import_hint_name_table_ni.slice(&coff.mf); | 6592 | const import_hint_name_slice = import_hint_name_table_ni.slice(&coff.mf); |
| 6573 | @memcpy(import_hint_name_slice[0..lib_name.len], lib_name); | 6593 | @memcpy(import_hint_name_slice[0..lib_name_slice.len], lib_name_slice); |
| 6574 | @memcpy(import_hint_name_slice[lib_name.len..][0..".dll".len], ".dll"); | 6594 | @memcpy(import_hint_name_slice[lib_name_slice.len..][0..".dll".len], ".dll"); |
| 6575 | @memset(import_hint_name_slice[lib_name.len + ".dll".len ..], 0); | 6595 | @memset(import_hint_name_slice[lib_name_slice.len + ".dll".len ..], 0); |
| 6576 | coff.nodes.appendAssumeCapacity(.{ .import_lookup_table = @fromBackingInt(@intCast(gop.index)) }); | 6596 | coff.nodes.appendAssumeCapacity(.{ .import_lookup_table = @fromBackingInt(@intCast(gop.index)) }); |
| 6577 | coff.nodes.appendAssumeCapacity(.{ .import_address_table = @fromBackingInt(@intCast(gop.index)) }); | 6597 | coff.nodes.appendAssumeCapacity(.{ .import_address_table = @fromBackingInt(@intCast(gop.index)) }); |
| 6578 | coff.nodes.appendAssumeCapacity(.{ .import_hint_name_table = @fromBackingInt(@intCast(gop.index)) }); | 6598 | coff.nodes.appendAssumeCapacity(.{ .import_hint_name_table = @fromBackingInt(@intCast(gop.index)) }); |
| ... | @@ -6597,7 +6617,7 @@ fn flushGlobal(coff: *Coff, gmi: Node.GlobalMapIndex) !bool { | ... | @@ -6597,7 +6617,7 @@ fn flushGlobal(coff: *Coff, gmi: Node.GlobalMapIndex) !bool { |
| 6597 | | 6617 | |
| 6598 | log.debug( | 6618 | log.debug( |
| 6599 | "flushGlobalImport({s}, {?s}, {d}, {s})", | 6619 | "flushGlobalImport({s}, {?s}, {d}, {s})", |
| 6600 | .{ name.toSlice(coff), import.name.toSlice(coff), import.ordinal_hint, lib_name }, | 6620 | .{ name.toSlice(coff), import.name.toSlice(coff), import.ordinal_hint, lib_name_slice }, |
| 6601 | ); | 6621 | ); |
| 6602 | | 6622 | |
| 6603 | const iat_symbol_gop = try coff.import_table.iat_symbol_indices.getOrPut(gpa, .{ | 6623 | const iat_symbol_gop = try coff.import_table.iat_symbol_indices.getOrPut(gpa, .{ |