| author | |
| committer | |
| log | d6f43a1eac6d8d0405b870a46f202d71957b5ba4 |
| tree | 0bfdd47e5600b7e4430c167d8c30b073c4da8604 |
| parent | a96b6ad83f4385dd47112084baeeb24e7e9356fa |
Due to a deficiency in LLD, we need to special-case BPF to a simple
file copy when generating relocatables. Normally, we would expect
`lld -r` to work. However, because LLD wants to resolve BPF relocations
which it shouldn't, it fails before even generating the relocatable.
Co-authored-by: Matthew Knight <mattnite@protonmail.com>3 files changed, 16 insertions(+), 4 deletions(-)
lib/std/target.zig+11| ... | ... | @@ -895,6 +895,13 @@ pub const Target = struct { |
| 895 | 895 | }; |
| 896 | 896 | } |
| 897 | 897 | |
| 898 | pub fn isBpf(arch: Arch) bool { | |
| 899 | return switch (arch) { | |
| 900 | .bpfel, .bpfeb => true, | |
| 901 | else => false, | |
| 902 | }; | |
| 903 | } | |
| 904 | ||
| 898 | 905 | pub fn parseCpuModel(arch: Arch, cpu_name: []const u8) !*const Cpu.Model { |
| 899 | 906 | for (arch.allCpuModels()) |cpu| { |
| 900 | 907 | if (mem.eql(u8, cpu_name, cpu.name)) { |
| ... | ... | @@ -1421,6 +1428,10 @@ pub const Target = struct { |
| 1421 | 1428 | return self.os.tag.isBSD(); |
| 1422 | 1429 | } |
| 1423 | 1430 | |
| 1431 | pub fn isBpfFreestanding(self: Target) bool { | |
| 1432 | return self.cpu.arch.isBpf() and self.os.tag == .freestanding; | |
| 1433 | } | |
| 1434 | ||
| 1424 | 1435 | pub fn isGnuLibC_os_tag_abi(os_tag: Os.Tag, abi: Abi) bool { |
| 1425 | 1436 | return os_tag == .linux and abi.isGnu(); |
| 1426 | 1437 | } |
src/link.zig-3| ... | ... | @@ -532,9 +532,6 @@ pub const File = struct { |
| 532 | 532 | return; |
| 533 | 533 | } |
| 534 | 534 | |
| 535 | if (base.options.output_mode == .Obj) | |
| 536 | return; | |
| 537 | ||
| 538 | 535 | const use_lld = build_options.have_llvm and base.options.use_lld; |
| 539 | 536 | if (use_lld and base.options.output_mode == .Lib and base.options.link_mode == .Static) { |
| 540 | 537 | return base.linkAsArchive(comp); |
src/link/Elf.zig+5-1| ... | ... | @@ -1381,7 +1381,11 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void { |
| 1381 | 1381 | } |
| 1382 | 1382 | |
| 1383 | 1383 | const full_out_path = try directory.join(arena, &[_][]const u8{self.base.options.emit.?.sub_path}); |
| 1384 | if (self.base.options.output_mode == .Obj and self.base.options.lto) { | |
| 1384 | ||
| 1385 | // Due to a deficiency in LLD, we need to special-case BPF to a simple file copy when generating | |
| 1386 | // relocatables. Normally, we would expect `lld -r` to work. However, because LLD wants to resolve | |
| 1387 | // BPF relocations which it shouldn't, it fails before even generating the relocatable. | |
| 1388 | if (self.base.options.output_mode == .Obj and (self.base.options.lto or target.isBpfFreestanding())) { | |
| 1385 | 1389 | // In this case we must do a simple file copy |
| 1386 | 1390 | // here. TODO: think carefully about how we can avoid this redundant operation when doing |
| 1387 | 1391 | // build-obj. See also the corresponding TODO in linkAsArchive. |