I wanted to compile Zig code with BTI enabled. I tried to add CPU feature:
const aarch64_features = std.Target.aarch64.Feature;
var module_target_query: std.Target.Query = .{
.cpu_arch = .aarch64,
.os_tag = .freestanding,
};
module_target_query.cpu_features_add.addFeature(
@intFromEnum(aarch64_features.bti),
);
const obj = b.addObject(.{
.name = "obj",
.root_module = b.createModule(.{
.root_source_file = b.path("main.zig"),
.target = module_target,
.optimize = optimize,
.pic = false,
}),
.use_llvm = true,
});
but it only tells LLVM that CPU supports it, which makes this flag useless.
I have to emit LLVM IR file, manually add “branch-target-enforcement”=“true” to attributes, and compile the IR.
So is there any more convenient way to add BTI enforcement? Can I somehow pass args to LLVM from build? Is it planned to have such arch-specific build options?