diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-05-23 21:51:10 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-05-23 21:51:10 -0700 |
| commit | 55811d8dac9109aa6357639908fb4f6c479480f9 (patch) | |
| tree | 668f796e1c6feeb6972f178c4a9c1333c594cdce /src | |
| parent | 609207801a570508e58d9e02b6ce551fbf1dca30 (diff) | |
| download | zig-55811d8dac9109aa6357639908fb4f6c479480f9.tar.gz zig-55811d8dac9109aa6357639908fb4f6c479480f9.zip | |
stage2: introduce clangAssemblerSupportsMcpuArg
Clang has a completely inconsistent CLI for its integrated assembler for
each target architecture. For x86_64, for example, it does not accept
an -mcpu parameter, and emits "warning: unused parameter". However, for
ARM, -mcpu is needed in order to properly lower assembly to machine code
instructions (see new standalone test case provided thanks to @g-w1).
This is a compromise between
b8f85a805bf61ae11d6ee2bd6d8356fbc98ee3ba and
afb9f695b1bdbf81185e7d55d5783bcbab880989.
Diffstat (limited to 'src')
| -rw-r--r-- | src/Compilation.zig | 42 | ||||
| -rw-r--r-- | src/target.zig | 9 |
2 files changed, 36 insertions, 15 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index 405066331f..023a54ca8d 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -2943,26 +2943,38 @@ pub fn addCCArgs( try argv.append("-fPIC"); } }, - .shared_library, .assembly, .ll, .bc, .unknown, .static_library, .object, .zig => {}, + .shared_library, .ll, .bc, .unknown, .static_library, .object, .zig => {}, + .assembly => { + // The Clang assembler does not accept the list of CPU features like the + // compiler frontend does. Therefore we must hard-code the -m flags for + // all CPU features here. + switch (target.cpu.arch) { + .riscv32, .riscv64 => { + if (std.Target.riscv.featureSetHas(target.cpu.features, .relax)) { + try argv.append("-mrelax"); + } else { + try argv.append("-mno-relax"); + } + }, + else => { + // TODO + }, + } + if (target_util.clangAssemblerSupportsMcpuArg(target)) { + if (target.cpu.model.llvm_name) |llvm_name| { + try argv.append(try std.fmt.allocPrint(arena, "-mcpu={s}", .{llvm_name})); + } + } + }, } if (out_dep_path) |p| { try argv.appendSlice(&[_][]const u8{ "-MD", "-MV", "-MF", p }); } - // Argh, why doesn't the assembler accept the list of CPU features?! - // I don't see a way to do this other than hard coding everything. - switch (target.cpu.arch) { - .riscv32, .riscv64 => { - if (std.Target.riscv.featureSetHas(target.cpu.features, .relax)) { - try argv.append("-mrelax"); - } else { - try argv.append("-mno-relax"); - } - }, - else => { - // TODO - }, - } + // We never want clang to invoke the system assembler for anything. So we would want + // this option always enabled. However, it only matters for some targets. To avoid + // "unused parameter" warnings, and to keep CLI spam to a minimum, we only put this + // flag on the command line if it is necessary. if (target_util.clangMightShellOutForAssembly(target)) { try argv.append("-integrated-as"); } diff --git a/src/target.zig b/src/target.zig index e077d9629c..b4e6123819 100644 --- a/src/target.zig +++ b/src/target.zig @@ -389,3 +389,12 @@ pub fn clangMightShellOutForAssembly(target: std.Target) bool { // when targeting a non-BSD OS. return target.cpu.arch.isSPARC(); } + +/// Each backend architecture in Clang has a different codepath which may or may not +/// support an -mcpu flag. +pub fn clangAssemblerSupportsMcpuArg(target: std.Target) bool { + return switch (target.cpu.arch) { + .arm, .armeb, .thumb, .thumbeb => true, + else => false, + }; +} |
