| ... | ... | @@ -805,6 +805,7 @@ pub const String = enum(u32) { |
| 805 | 805 | @".bss" = 75, |
| 806 | 806 | @".fptable" = 80, |
| 807 | 807 | @".tls" = 89, |
| 808 | @".thunks" = 94, |
| 808 | 809 | _, |
| 809 | 810 | |
| 810 | 811 | pub const Optional = enum(u32) { |
| ... | ... | @@ -821,6 +822,7 @@ pub const String = enum(u32) { |
| 821 | 822 | @".bss" = @intFromEnum(String.@".bss"), |
| 822 | 823 | @".fptable" = @intFromEnum(String.@".fptable"), |
| 823 | 824 | @".tls" = @intFromEnum(String.@".tls"), |
| 825 | @".thunks" = @intFromEnum(String.@".thunks"), |
| 824 | 826 | none = std.math.maxInt(u32), |
| 825 | 827 | _, |
| 826 | 828 | |
| ... | ... | @@ -3401,6 +3403,15 @@ fn objectSectionMapIndex( |
| 3401 | 3403 | }; |
| 3402 | 3404 | } |
| 3403 | 3405 | |
| 3406 | const old_alignment = sym.ni.alignment(&coff.mf); |
| 3407 | if (alignment.compare(.gt, old_alignment)) { |
| 3408 | log.debug("realignObject({s}) {d}->{d}", .{ name.toSlice(coff), old_alignment, alignment }); |
| 3409 | sym.ni.realign(&coff.mf, gpa, alignment, true) catch |err| switch (err) { |
| 3410 | error.Unimplemented => unreachable, |
| 3411 | else => |e| return e, |
| 3412 | }; |
| 3413 | } |
| 3414 | |
| 3404 | 3415 | try coff.verifyParentSectionAttributes( |
| 3405 | 3416 | .object, |
| 3406 | 3417 | sym.section_number.name(coff), |
| ... | ... | @@ -6182,9 +6193,8 @@ fn flushGlobal(coff: *Coff, gmi: Node.GlobalMapIndex) !bool { |
| 6182 | 6193 | const lib_name = import.lib_name.toSlice(coff); |
| 6183 | 6194 | |
| 6184 | 6195 | try coff.nodes.ensureUnusedCapacity(gpa, 4); |
| 6185 | | try coff.symbols.ensureUnusedCapacity(gpa, 1); |
| 6196 | try coff.symbols.ensureUnusedCapacity(gpa, 2); |
| 6186 | 6197 | |
| 6187 | | const sym = si.get(coff); |
| 6188 | 6198 | const target_endian = coff.targetEndian(); |
| 6189 | 6199 | const addr_info = coff.targetAddrInfo(); |
| 6190 | 6200 | const gop = try coff.import_table.entries.getOrPutAdapted( |
| ... | ... | @@ -6328,6 +6338,7 @@ fn flushGlobal(coff: *Coff, gmi: Node.GlobalMapIndex) !bool { |
| 6328 | 6338 | } |
| 6329 | 6339 | } |
| 6330 | 6340 | |
| 6341 | const sym = si.get(coff); |
| 6331 | 6342 | assert(sym.loc_relocs == .none); |
| 6332 | 6343 | const iat_offset: u32 = @intCast(addr_info.size * iat_symbol_gop.value_ptr.*); |
| 6333 | 6344 | switch (import.kind) { |
| ... | ... | @@ -6340,21 +6351,31 @@ fn flushGlobal(coff: *Coff, gmi: Node.GlobalMapIndex) !bool { |
| 6340 | 6351 | (try gop.value_ptr.import_address_table_symbols.addOne(gpa)).* = si; |
| 6341 | 6352 | }, |
| 6342 | 6353 | .thunk => { |
| 6343 | | sym.section_number = Symbol.Index.text.get(coff).section_number; |
| 6344 | 6354 | sym.loc_relocs = @enumFromInt(coff.relocs.items.len); |
| 6355 | |
| 6356 | const target = &comp.root_mod.resolved_target.result; |
| 6357 | const alignment = switch (comp.root_mod.optimize_mode) { |
| 6358 | .Debug, |
| 6359 | .ReleaseSafe, |
| 6360 | .ReleaseFast, |
| 6361 | => target_util.defaultFunctionAlignment(target), |
| 6362 | .ReleaseSmall => target_util.minFunctionAlignment(target), |
| 6363 | }.toStdMem(); |
| 6364 | const parent_si = (try coff.pseudoSectionMapIndex( |
| 6365 | .@".thunks", |
| 6366 | alignment, |
| 6367 | .{ .execute = true, .read = true }, |
| 6368 | )).symbol(coff); |
| 6369 | |
| 6370 | const parent_sym = parent_si.get(coff); |
| 6371 | sym.section_number = parent_sym.section_number; |
| 6372 | |
| 6345 | 6373 | switch (coff.targetLoad(&coff.headerPtr().machine)) { |
| 6346 | 6374 | else => |tag| @panic(@tagName(tag)), |
| 6347 | 6375 | .AMD64 => { |
| 6348 | 6376 | const init = [_]u8{ 0xff, 0x25, 0x00, 0x00, 0x00, 0x00 }; |
| 6349 | | const target = &comp.root_mod.resolved_target.result; |
| 6350 | | const ni = try coff.mf.addLastChildNode(gpa, Symbol.Index.text.node(coff), .{ |
| 6351 | | .alignment = switch (comp.root_mod.optimize_mode) { |
| 6352 | | .Debug, |
| 6353 | | .ReleaseSafe, |
| 6354 | | .ReleaseFast, |
| 6355 | | => target_util.defaultFunctionAlignment(target), |
| 6356 | | .ReleaseSmall => target_util.minFunctionAlignment(target), |
| 6357 | | }.toStdMem(), |
| 6377 | const ni = try coff.mf.addLastChildNode(gpa, parent_sym.ni, .{ |
| 6378 | .alignment = alignment, |
| 6358 | 6379 | .size = init.len, |
| 6359 | 6380 | }); |
| 6360 | 6381 | @memcpy(ni.slice(&coff.mf)[0..init.len], &init); |