| ... | ... | @@ -674,13 +674,14 @@ fn mirCallExtern(emit: *Emit, inst: Mir.Inst.Index) !void { |
| 674 | 674 | assert(emit.mir.instructions.items(.tag)[inst] == .call_extern); |
| 675 | 675 | const relocation = emit.mir.instructions.items(.data)[inst].relocation; |
| 676 | 676 | |
| 677 | const offset = blk: { |
| 678 | const offset = @intCast(u32, emit.code.items.len); |
| 679 | // bl |
| 680 | try emit.writeInstruction(Instruction.bl(0)); |
| 681 | break :blk offset; |
| 682 | }; |
| 683 | |
| 677 | 684 | if (emit.bin_file.cast(link.File.MachO)) |macho_file| { |
| 678 | | const offset = blk: { |
| 679 | | const offset = @intCast(u32, emit.code.items.len); |
| 680 | | // bl |
| 681 | | try emit.writeInstruction(Instruction.bl(0)); |
| 682 | | break :blk offset; |
| 683 | | }; |
| 684 | 685 | // Add relocation to the decl. |
| 685 | 686 | const atom = macho_file.getAtomForSymbol(.{ .sym_index = relocation.atom_index, .file = null }).?; |
| 686 | 687 | const target = macho_file.getGlobalByIndex(relocation.sym_index); |
| ... | ... | @@ -692,8 +693,20 @@ fn mirCallExtern(emit: *Emit, inst: Mir.Inst.Index) !void { |
| 692 | 693 | .pcrel = true, |
| 693 | 694 | .length = 2, |
| 694 | 695 | }); |
| 696 | } else if (emit.bin_file.cast(link.File.Coff)) |coff_file| { |
| 697 | // Add relocation to the decl. |
| 698 | const atom = coff_file.getAtomForSymbol(.{ .sym_index = relocation.atom_index, .file = null }).?; |
| 699 | const target = coff_file.getGlobalByIndex(relocation.sym_index); |
| 700 | try atom.addRelocation(coff_file, .{ |
| 701 | .@"type" = .branch_26, |
| 702 | .target = target, |
| 703 | .offset = offset, |
| 704 | .addend = 0, |
| 705 | .pcrel = true, |
| 706 | .length = 2, |
| 707 | }); |
| 695 | 708 | } else { |
| 696 | | return emit.fail("Implement call_extern for linking backends != MachO", .{}); |
| 709 | return emit.fail("Implement call_extern for linking backends != {{ COFF, MachO }}", .{}); |
| 697 | 710 | } |
| 698 | 711 | } |
| 699 | 712 | |
| ... | ... | @@ -926,6 +939,40 @@ fn mirLoadMemoryPie(emit: *Emit, inst: Mir.Inst.Index) !void { |
| 926 | 939 | else => unreachable, |
| 927 | 940 | }, |
| 928 | 941 | }); |
| 942 | } else if (emit.bin_file.cast(link.File.Coff)) |coff_file| { |
| 943 | const atom = coff_file.getAtomForSymbol(.{ .sym_index = data.atom_index, .file = null }).?; |
| 944 | try atom.addRelocation(coff_file, .{ |
| 945 | .target = .{ .sym_index = data.sym_index, .file = null }, |
| 946 | .offset = offset, |
| 947 | .addend = 0, |
| 948 | .pcrel = true, |
| 949 | .length = 2, |
| 950 | .@"type" = switch (tag) { |
| 951 | .load_memory_got, |
| 952 | .load_memory_ptr_got, |
| 953 | => .got_page, |
| 954 | .load_memory_direct, |
| 955 | .load_memory_ptr_direct, |
| 956 | => .page, |
| 957 | else => unreachable, |
| 958 | }, |
| 959 | }); |
| 960 | try atom.addRelocation(coff_file, .{ |
| 961 | .target = .{ .sym_index = data.sym_index, .file = null }, |
| 962 | .offset = offset + 4, |
| 963 | .addend = 0, |
| 964 | .pcrel = false, |
| 965 | .length = 2, |
| 966 | .@"type" = switch (tag) { |
| 967 | .load_memory_got, |
| 968 | .load_memory_ptr_got, |
| 969 | => .got_pageoff, |
| 970 | .load_memory_direct, |
| 971 | .load_memory_ptr_direct, |
| 972 | => .pageoff, |
| 973 | else => unreachable, |
| 974 | }, |
| 975 | }); |
| 929 | 976 | } else { |
| 930 | 977 | return emit.fail("TODO implement load_memory for PIE GOT indirection on this platform", .{}); |
| 931 | 978 | } |