Skip to content

Commit

Permalink
llvm: Use no-builtins attribute instead of nobuiltin.
Browse files Browse the repository at this point in the history
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: #21842
  • Loading branch information
alexrp committed Nov 3, 2024
1 parent 3054486 commit aba7853
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/codegen/llvm.zig
Original file line number Diff line number Diff line change
Expand Up @@ -3242,13 +3242,16 @@ 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) {
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);
Expand All @@ -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`,
Expand Down

0 comments on commit aba7853

Please sign in to comment.