aboutsummaryrefslogtreecommitdiff
path: root/src/codegen
diff options
context:
space:
mode:
authorAlex Rønne Petersen <alex@alexrp.com>2024-11-03 14:37:42 +0100
committerAlex Rønne Petersen <alex@alexrp.com>2024-11-04 14:17:57 +0100
commitbd8ef0036d8d380a753bb88d426f58c059c97f61 (patch)
tree4240e95673506e4b51fb255b6fd5c769e48a34a3 /src/codegen
parent4a3611f7d6837da6a27df22e631838fd60819768 (diff)
downloadzig-bd8ef0036d8d380a753bb88d426f58c059c97f61.tar.gz
zig-bd8ef0036d8d380a753bb88d426f58c059c97f61.zip
llvm: Use no-builtins attribute instead of nobuiltin.
The former prevents recognizing code patterns and turning them into libcalls, which is what we want for compiler-rt. The latter is meant to be used on call sites to prevent them from being turned into intrinsics. Context: https://github.com/ziglang/zig/issues/21833
Diffstat (limited to 'src/codegen')
-rw-r--r--src/codegen/llvm.zig15
1 files changed, 6 insertions, 9 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
index b709403256..7e503ce6ae 100644
--- a/src/codegen/llvm.zig
+++ b/src/codegen/llvm.zig
@@ -3242,19 +3242,22 @@ pub const Object = struct {
if (owner_mod.unwind_tables) {
try attributes.addFnAttr(.{ .uwtable = Builder.Attribute.UwTable.default }, &o.builder);
}
- if (comp.skip_linker_dependencies or comp.no_builtin) {
+ const target = owner_mod.resolved_target.result;
+ if (comp.skip_linker_dependencies or comp.no_builtin or target.cpu.arch.isBpf()) {
// The intent here is for compiler-rt and libc functions to not generate
// infinite recursion. For example, if we are compiling the memcpy function,
// and llvm detects that the body is equivalent to memcpy, it may replace the
// body of memcpy with a call to memcpy, which would then cause a stack
// overflow instead of performing memcpy.
- try attributes.addFnAttr(.nobuiltin, &o.builder);
+ try attributes.addFnAttr(.{ .string = .{
+ .kind = try o.builder.string("no-builtins"),
+ .value = .empty,
+ } }, &o.builder);
}
if (owner_mod.optimize_mode == .ReleaseSmall) {
try attributes.addFnAttr(.minsize, &o.builder);
try attributes.addFnAttr(.optsize, &o.builder);
}
- const target = owner_mod.resolved_target.result;
if (target.cpu.model.llvm_name) |s| {
try attributes.addFnAttr(.{ .string = .{
.kind = try o.builder.string("target-cpu"),
@@ -3267,12 +3270,6 @@ pub const Object = struct {
.value = try o.builder.string(std.mem.span(s)),
} }, &o.builder);
}
- if (target.cpu.arch.isBpf()) {
- try attributes.addFnAttr(.{ .string = .{
- .kind = try o.builder.string("no-builtins"),
- .value = .empty,
- } }, &o.builder);
- }
if (target.floatAbi() == .soft) {
// `use-soft-float` means "use software routines for floating point computations". In
// other words, it configures how LLVM lowers basic float instructions like `fcmp`,