authorgravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-11-26 10:54:16+01:00
committergravatar for kubkon@jakubkonka.comJakub Konka <kubkon@jakubkonka.com> 2021-11-26 10:54:16+01:00
loga2c546fea30de2caf1efb454d327e70270c07338
tree0bfdd47e5600b7e4430c167d8c30b073c4da8604
parentda7baf7daec175f63e336082d4bcada9ccf4d55c
parentd6f43a1eac6d8d0405b870a46f202d71957b5ba4

Merge branch 'mattnite-build-obj-no-link'


3 files changed, 17 insertions(+), 1 deletions(-)

lib/std/target.zig+11
......@@ -895,6 +895,13 @@ pub const Target = struct {
895895 };
896896 }
897897
898 pub fn isBpf(arch: Arch) bool {
899 return switch (arch) {
900 .bpfel, .bpfeb => true,
901 else => false,
902 };
903 }
904
898905 pub fn parseCpuModel(arch: Arch, cpu_name: []const u8) !*const Cpu.Model {
899906 for (arch.allCpuModels()) |cpu| {
900907 if (mem.eql(u8, cpu_name, cpu.name)) {
......@@ -1421,6 +1428,10 @@ pub const Target = struct {
14211428 return self.os.tag.isBSD();
14221429 }
14231430
1431 pub fn isBpfFreestanding(self: Target) bool {
1432 return self.cpu.arch.isBpf() and self.os.tag == .freestanding;
1433 }
1434
14241435 pub fn isGnuLibC_os_tag_abi(os_tag: Os.Tag, abi: Abi) bool {
14251436 return os_tag == .linux and abi.isGnu();
14261437 }
src/link.zig+1
......@@ -531,6 +531,7 @@ pub const File = struct {
531531 try fs.cwd().copyFile(cached_pp_file_path, fs.cwd(), full_out_path, .{});
532532 return;
533533 }
534
534535 const use_lld = build_options.have_llvm and base.options.use_lld;
535536 if (use_lld and base.options.output_mode == .Lib and base.options.link_mode == .Static) {
536537 return base.linkAsArchive(comp);
src/link/Elf.zig+5-1
......@@ -1381,7 +1381,11 @@ fn linkWithLLD(self: *Elf, comp: *Compilation) !void {
13811381 }
13821382
13831383 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())) {
13851389 // In this case we must do a simple file copy
13861390 // here. TODO: think carefully about how we can avoid this redundant operation when doing
13871391 // build-obj. See also the corresponding TODO in linkAsArchive.