Skip to content

Commit 0ff0fbd

Browse files
committed
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: ziglang#21833
1 parent 3054486 commit 0ff0fbd

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

src/codegen/llvm.zig

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3242,19 +3242,22 @@ pub const Object = struct {
32423242
if (owner_mod.unwind_tables) {
32433243
try attributes.addFnAttr(.{ .uwtable = Builder.Attribute.UwTable.default }, &o.builder);
32443244
}
3245-
if (comp.skip_linker_dependencies or comp.no_builtin) {
3245+
const target = owner_mod.resolved_target.result;
3246+
if (comp.skip_linker_dependencies or comp.no_builtin or target.cpu.arch.isBpf()) {
32463247
// The intent here is for compiler-rt and libc functions to not generate
32473248
// infinite recursion. For example, if we are compiling the memcpy function,
32483249
// and llvm detects that the body is equivalent to memcpy, it may replace the
32493250
// body of memcpy with a call to memcpy, which would then cause a stack
32503251
// overflow instead of performing memcpy.
3251-
try attributes.addFnAttr(.nobuiltin, &o.builder);
3252+
try attributes.addFnAttr(.{ .string = .{
3253+
.kind = try o.builder.string("no-builtins"),
3254+
.value = .empty,
3255+
} }, &o.builder);
32523256
}
32533257
if (owner_mod.optimize_mode == .ReleaseSmall) {
32543258
try attributes.addFnAttr(.minsize, &o.builder);
32553259
try attributes.addFnAttr(.optsize, &o.builder);
32563260
}
3257-
const target = owner_mod.resolved_target.result;
32583261
if (target.cpu.model.llvm_name) |s| {
32593262
try attributes.addFnAttr(.{ .string = .{
32603263
.kind = try o.builder.string("target-cpu"),
@@ -3267,12 +3270,6 @@ pub const Object = struct {
32673270
.value = try o.builder.string(std.mem.span(s)),
32683271
} }, &o.builder);
32693272
}
3270-
if (target.cpu.arch.isBpf()) {
3271-
try attributes.addFnAttr(.{ .string = .{
3272-
.kind = try o.builder.string("no-builtins"),
3273-
.value = .empty,
3274-
} }, &o.builder);
3275-
}
32763273
if (target.floatAbi() == .soft) {
32773274
// `use-soft-float` means "use software routines for floating point computations". In
32783275
// other words, it configures how LLVM lowers basic float instructions like `fcmp`,

0 commit comments

Comments
 (0)