authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-11-05 14:29:44+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-11-05 14:43:02+01:00
logb57819118ddf287a135b4c2fb7182615b402fbc2
tree6b55bd9b957750e542bec14373e3ba27aef94b5a
parent56b416662aa89196d5b974632dcd927d26b5d12c
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

Compilation: Move no_builtin to Package.Module.

This option, by its very nature, needs to be attached to a module. If it isn't, the code in a module could break at random when compiled into an application that doesn't have this option set. After this change, skip_linker_dependencies no longer implies no_builtin in the LLVM backend.

8 files changed, 65 insertions(+), 40 deletions(-)

src/Compilation.zig+13-9
...@@ -89,7 +89,6 @@ windows_libs: std.StringArrayHashMapUnmanaged(void),...@@ -89,7 +89,6 @@ windows_libs: std.StringArrayHashMapUnmanaged(void),
89version: ?std.SemanticVersion,89version: ?std.SemanticVersion,
90libc_installation: ?*const LibCInstallation,90libc_installation: ?*const LibCInstallation,
91skip_linker_dependencies: bool,91skip_linker_dependencies: bool,
92no_builtin: bool,
93function_sections: bool,92function_sections: bool,
94data_sections: bool,93data_sections: bool,
95link_eh_frame_hdr: bool,94link_eh_frame_hdr: bool,
...@@ -852,6 +851,7 @@ pub const cache_helpers = struct {...@@ -852,6 +851,7 @@ pub const cache_helpers = struct {
852 hh.add(mod.fuzz);851 hh.add(mod.fuzz);
853 hh.add(mod.unwind_tables);852 hh.add(mod.unwind_tables);
854 hh.add(mod.structured_cfg);853 hh.add(mod.structured_cfg);
854 hh.add(mod.no_builtin);
855 hh.addListOfBytes(mod.cc_argv);855 hh.addListOfBytes(mod.cc_argv);
856 }856 }
857857
...@@ -1057,7 +1057,6 @@ pub const CreateOptions = struct {...@@ -1057,7 +1057,6 @@ pub const CreateOptions = struct {
1057 want_lto: ?bool = null,1057 want_lto: ?bool = null,
1058 function_sections: bool = false,1058 function_sections: bool = false,
1059 data_sections: bool = false,1059 data_sections: bool = false,
1060 no_builtin: bool = false,
1061 time_report: bool = false,1060 time_report: bool = false,
1062 stack_report: bool = false,1061 stack_report: bool = false,
1063 link_eh_frame_hdr: bool = false,1062 link_eh_frame_hdr: bool = false,
...@@ -1353,7 +1352,6 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil...@@ -1353,7 +1352,6 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
1353 cache.hash.add(options.config.link_mode);1352 cache.hash.add(options.config.link_mode);
1354 cache.hash.add(options.function_sections);1353 cache.hash.add(options.function_sections);
1355 cache.hash.add(options.data_sections);1354 cache.hash.add(options.data_sections);
1356 cache.hash.add(options.no_builtin);
1357 cache.hash.add(link_libc);1355 cache.hash.add(link_libc);
1358 cache.hash.add(options.config.link_libcpp);1356 cache.hash.add(options.config.link_libcpp);
1359 cache.hash.add(options.config.link_libunwind);1357 cache.hash.add(options.config.link_libunwind);
...@@ -1490,7 +1488,6 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil...@@ -1490,7 +1488,6 @@ pub fn create(gpa: Allocator, arena: Allocator, options: CreateOptions) !*Compil
1490 .framework_dirs = options.framework_dirs,1488 .framework_dirs = options.framework_dirs,
1491 .llvm_opt_bisect_limit = options.llvm_opt_bisect_limit,1489 .llvm_opt_bisect_limit = options.llvm_opt_bisect_limit,
1492 .skip_linker_dependencies = options.skip_linker_dependencies,1490 .skip_linker_dependencies = options.skip_linker_dependencies,
1493 .no_builtin = options.no_builtin,
1494 .job_queued_update_builtin_zig = have_zcu,1491 .job_queued_update_builtin_zig = have_zcu,
1495 .function_sections = options.function_sections,1492 .function_sections = options.function_sections,
1496 .data_sections = options.data_sections,1493 .data_sections = options.data_sections,
...@@ -5261,7 +5258,7 @@ pub fn addCCArgs(...@@ -5261,7 +5258,7 @@ pub fn addCCArgs(
5261 try argv.append("-fdata-sections");5258 try argv.append("-fdata-sections");
5262 }5259 }
52635260
5264 if (comp.no_builtin) {5261 if (mod.no_builtin) {
5265 try argv.append("-fno-builtin");5262 try argv.append("-fno-builtin");
5266 }5263 }
52675264
...@@ -6189,6 +6186,7 @@ fn buildOutputFromZig(...@@ -6189,6 +6186,7 @@ fn buildOutputFromZig(
6189 .pic = comp.root_mod.pic,6186 .pic = comp.root_mod.pic,
6190 .optimize_mode = optimize_mode,6187 .optimize_mode = optimize_mode,
6191 .structured_cfg = comp.root_mod.structured_cfg,6188 .structured_cfg = comp.root_mod.structured_cfg,
6189 .no_builtin = true,
6192 .code_model = comp.root_mod.code_model,6190 .code_model = comp.root_mod.code_model,
6193 },6191 },
6194 .global = config,6192 .global = config,
...@@ -6237,7 +6235,6 @@ fn buildOutputFromZig(...@@ -6237,7 +6235,6 @@ fn buildOutputFromZig(
6237 },6235 },
6238 .function_sections = true,6236 .function_sections = true,
6239 .data_sections = true,6237 .data_sections = true,
6240 .no_builtin = true,
6241 .emit_h = null,6238 .emit_h = null,
6242 .verbose_cc = comp.verbose_cc,6239 .verbose_cc = comp.verbose_cc,
6243 .verbose_link = comp.verbose_link,6240 .verbose_link = comp.verbose_link,
...@@ -6262,16 +6259,21 @@ fn buildOutputFromZig(...@@ -6262,16 +6259,21 @@ fn buildOutputFromZig(
6262 comp.queueLinkTaskMode(crt_file.full_object_path, output_mode);6259 comp.queueLinkTaskMode(crt_file.full_object_path, output_mode);
6263}6260}
62646261
6262pub const CrtFileOptions = struct {
6263 pic: ?bool = null,
6264 no_builtin: ?bool = null,
6265};
6266
6265pub fn build_crt_file(6267pub fn build_crt_file(
6266 comp: *Compilation,6268 comp: *Compilation,
6267 root_name: []const u8,6269 root_name: []const u8,
6268 output_mode: std.builtin.OutputMode,6270 output_mode: std.builtin.OutputMode,
6269 pic: ?bool,
6270 misc_task_tag: MiscTask,6271 misc_task_tag: MiscTask,
6271 prog_node: std.Progress.Node,6272 prog_node: std.Progress.Node,
6272 /// These elements have to get mutated to add the owner module after it is6273 /// These elements have to get mutated to add the owner module after it is
6273 /// created within this function.6274 /// created within this function.
6274 c_source_files: []CSourceFile,6275 c_source_files: []CSourceFile,
6276 options: CrtFileOptions,
6275) !void {6277) !void {
6276 const tracy_trace = trace(@src());6278 const tracy_trace = trace(@src());
6277 defer tracy_trace.end();6279 defer tracy_trace.end();
...@@ -6319,10 +6321,12 @@ pub fn build_crt_file(...@@ -6319,10 +6321,12 @@ pub fn build_crt_file(
6319 .omit_frame_pointer = comp.root_mod.omit_frame_pointer,6321 .omit_frame_pointer = comp.root_mod.omit_frame_pointer,
6320 .valgrind = false,6322 .valgrind = false,
6321 .unwind_tables = false,6323 .unwind_tables = false,
6322 // Some CRT objects (rcrt1.o, Scrt1.o) are opinionated about PIC.6324 // Some CRT objects (e.g. musl's rcrt1.o and Scrt1.o) are opinionated about PIC.
6323 .pic = pic orelse comp.root_mod.pic,6325 .pic = options.pic orelse comp.root_mod.pic,
6324 .optimize_mode = comp.compilerRtOptMode(),6326 .optimize_mode = comp.compilerRtOptMode(),
6325 .structured_cfg = comp.root_mod.structured_cfg,6327 .structured_cfg = comp.root_mod.structured_cfg,
6328 // Some libcs (e.g. musl) are opinionated about -fno-builtin.
6329 .no_builtin = options.no_builtin orelse comp.root_mod.no_builtin,
6326 },6330 },
6327 .global = config,6331 .global = config,
6328 .cc_argv = &.{},6332 .cc_argv = &.{},
src/Package/Module.zig+12
...@@ -31,6 +31,7 @@ unwind_tables: bool,...@@ -31,6 +31,7 @@ unwind_tables: bool,
31cc_argv: []const []const u8,31cc_argv: []const []const u8,
32/// (SPIR-V) whether to generate a structured control flow graph or not32/// (SPIR-V) whether to generate a structured control flow graph or not
33structured_cfg: bool,33structured_cfg: bool,
34no_builtin: bool,
3435
35/// If the module is an `@import("builtin")` module, this is the `File` that36/// If the module is an `@import("builtin")` module, this is the `File` that
36/// is preallocated for it. Otherwise this field is null.37/// is preallocated for it. Otherwise this field is null.
...@@ -95,6 +96,7 @@ pub const CreateOptions = struct {...@@ -95,6 +96,7 @@ pub const CreateOptions = struct {
95 sanitize_thread: ?bool = null,96 sanitize_thread: ?bool = null,
96 fuzz: ?bool = null,97 fuzz: ?bool = null,
97 structured_cfg: ?bool = null,98 structured_cfg: ?bool = null,
99 no_builtin: ?bool = null,
98 };100 };
99};101};
100102
...@@ -298,6 +300,13 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {...@@ -298,6 +300,13 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {
298 };300 };
299 };301 };
300302
303 const no_builtin = b: {
304 if (options.inherited.no_builtin) |x| break :b x;
305 if (options.parent) |p| break :b p.no_builtin;
306
307 break :b target.cpu.arch.isBpf();
308 };
309
301 const llvm_cpu_features: ?[*:0]const u8 = b: {310 const llvm_cpu_features: ?[*:0]const u8 = b: {
302 if (resolved_target.llvm_cpu_features) |x| break :b x;311 if (resolved_target.llvm_cpu_features) |x| break :b x;
303 if (!options.global.use_llvm) break :b null;312 if (!options.global.use_llvm) break :b null;
...@@ -350,6 +359,7 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {...@@ -350,6 +359,7 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {
350 .unwind_tables = unwind_tables,359 .unwind_tables = unwind_tables,
351 .cc_argv = options.cc_argv,360 .cc_argv = options.cc_argv,
352 .structured_cfg = structured_cfg,361 .structured_cfg = structured_cfg,
362 .no_builtin = no_builtin,
353 .builtin_file = null,363 .builtin_file = null,
354 };364 };
355365
...@@ -442,6 +452,7 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {...@@ -442,6 +452,7 @@ pub fn create(arena: Allocator, options: CreateOptions) !*Package.Module {
442 .unwind_tables = unwind_tables,452 .unwind_tables = unwind_tables,
443 .cc_argv = &.{},453 .cc_argv = &.{},
444 .structured_cfg = structured_cfg,454 .structured_cfg = structured_cfg,
455 .no_builtin = no_builtin,
445 .builtin_file = new_file,456 .builtin_file = new_file,
446 };457 };
447 new_file.* = .{458 new_file.* = .{
...@@ -502,6 +513,7 @@ pub fn createLimited(gpa: Allocator, options: LimitedOptions) Allocator.Error!*P...@@ -502,6 +513,7 @@ pub fn createLimited(gpa: Allocator, options: LimitedOptions) Allocator.Error!*P
502 .unwind_tables = undefined,513 .unwind_tables = undefined,
503 .cc_argv = undefined,514 .cc_argv = undefined,
504 .structured_cfg = undefined,515 .structured_cfg = undefined,
516 .no_builtin = undefined,
505 .builtin_file = null,517 .builtin_file = null,
506 };518 };
507 return mod;519 return mod;
src/codegen/llvm.zig+2-4
...@@ -3222,8 +3222,6 @@ pub const Object = struct {...@@ -3222,8 +3222,6 @@ pub const Object = struct {
3222 owner_mod: *Package.Module,3222 owner_mod: *Package.Module,
3223 omit_frame_pointer: bool,3223 omit_frame_pointer: bool,
3224 ) Allocator.Error!void {3224 ) Allocator.Error!void {
3225 const comp = o.pt.zcu.comp;
3226
3227 if (!owner_mod.red_zone) {3225 if (!owner_mod.red_zone) {
3228 try attributes.addFnAttr(.noredzone, &o.builder);3226 try attributes.addFnAttr(.noredzone, &o.builder);
3229 }3227 }
...@@ -3242,8 +3240,7 @@ pub const Object = struct {...@@ -3242,8 +3240,7 @@ pub const Object = struct {
3242 if (owner_mod.unwind_tables) {3240 if (owner_mod.unwind_tables) {
3243 try attributes.addFnAttr(.{ .uwtable = Builder.Attribute.UwTable.default }, &o.builder);3241 try attributes.addFnAttr(.{ .uwtable = Builder.Attribute.UwTable.default }, &o.builder);
3244 }3242 }
3245 const target = owner_mod.resolved_target.result;3243 if (owner_mod.no_builtin) {
3246 if (comp.skip_linker_dependencies or comp.no_builtin or target.cpu.arch.isBpf()) {
3247 // The intent here is for compiler-rt and libc functions to not generate3244 // The intent here is for compiler-rt and libc functions to not generate
3248 // infinite recursion. For example, if we are compiling the memcpy function,3245 // infinite recursion. For example, if we are compiling the memcpy function,
3249 // and llvm detects that the body is equivalent to memcpy, it may replace the3246 // and llvm detects that the body is equivalent to memcpy, it may replace the
...@@ -3258,6 +3255,7 @@ pub const Object = struct {...@@ -3258,6 +3255,7 @@ pub const Object = struct {
3258 try attributes.addFnAttr(.minsize, &o.builder);3255 try attributes.addFnAttr(.minsize, &o.builder);
3259 try attributes.addFnAttr(.optsize, &o.builder);3256 try attributes.addFnAttr(.optsize, &o.builder);
3260 }3257 }
3258 const target = owner_mod.resolved_target.result;
3261 if (target.cpu.model.llvm_name) |s| {3259 if (target.cpu.model.llvm_name) |s| {
3262 try attributes.addFnAttr(.{ .string = .{3260 try attributes.addFnAttr(.{ .string = .{
3263 .kind = try o.builder.string("target-cpu"),3261 .kind = try o.builder.string("target-cpu"),
src/glibc.zig+4-4
...@@ -221,7 +221,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre...@@ -221,7 +221,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
221 .owner = comp.root_mod,221 .owner = comp.root_mod,
222 },222 },
223 };223 };
224 return comp.build_crt_file("crti", .Obj, null, .@"glibc crti.o", prog_node, &files);224 return comp.build_crt_file("crti", .Obj, .@"glibc crti.o", prog_node, &files, .{});
225 },225 },
226 .crtn_o => {226 .crtn_o => {
227 var args = std.ArrayList([]const u8).init(arena);227 var args = std.ArrayList([]const u8).init(arena);
...@@ -242,7 +242,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre...@@ -242,7 +242,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
242 .owner = undefined,242 .owner = undefined,
243 },243 },
244 };244 };
245 return comp.build_crt_file("crtn", .Obj, null, .@"glibc crtn.o", prog_node, &files);245 return comp.build_crt_file("crtn", .Obj, .@"glibc crtn.o", prog_node, &files, .{});
246 },246 },
247 .scrt1_o => {247 .scrt1_o => {
248 const start_o: Compilation.CSourceFile = blk: {248 const start_o: Compilation.CSourceFile = blk: {
...@@ -295,7 +295,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre...@@ -295,7 +295,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
295 };295 };
296 var files = [_]Compilation.CSourceFile{ start_o, abi_note_o, init_o };296 var files = [_]Compilation.CSourceFile{ start_o, abi_note_o, init_o };
297 const basename = if (comp.config.output_mode == .Exe and !comp.config.pie) "crt1" else "Scrt1";297 const basename = if (comp.config.output_mode == .Exe and !comp.config.pie) "crt1" else "Scrt1";
298 return comp.build_crt_file(basename, .Obj, null, .@"glibc Scrt1.o", prog_node, &files);298 return comp.build_crt_file(basename, .Obj, .@"glibc Scrt1.o", prog_node, &files, .{});
299 },299 },
300 .libc_nonshared_a => {300 .libc_nonshared_a => {
301 const s = path.sep_str;301 const s = path.sep_str;
...@@ -413,7 +413,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre...@@ -413,7 +413,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
413 files_index += 1;413 files_index += 1;
414 }414 }
415 const files = files_buf[0..files_index];415 const files = files_buf[0..files_index];
416 return comp.build_crt_file("c_nonshared", .Lib, null, .@"glibc libc_nonshared.a", prog_node, files);416 return comp.build_crt_file("c_nonshared", .Lib, .@"glibc libc_nonshared.a", prog_node, files, .{});
417 },417 },
418 }418 }
419}419}
src/main.zig+4-6
...@@ -810,7 +810,6 @@ fn buildOutputType(...@@ -810,7 +810,6 @@ fn buildOutputType(
810 var compatibility_version: ?std.SemanticVersion = null;810 var compatibility_version: ?std.SemanticVersion = null;
811 var function_sections = false;811 var function_sections = false;
812 var data_sections = false;812 var data_sections = false;
813 var no_builtin = false;
814 var listen: Listen = .none;813 var listen: Listen = .none;
815 var debug_compile_errors = false;814 var debug_compile_errors = false;
816 var verbose_link = (native_os != .wasi or builtin.link_libc) and815 var verbose_link = (native_os != .wasi or builtin.link_libc) and
...@@ -1550,9 +1549,9 @@ fn buildOutputType(...@@ -1550,9 +1549,9 @@ fn buildOutputType(
1550 } else if (mem.eql(u8, arg, "-fno-data-sections")) {1549 } else if (mem.eql(u8, arg, "-fno-data-sections")) {
1551 data_sections = false;1550 data_sections = false;
1552 } else if (mem.eql(u8, arg, "-fbuiltin")) {1551 } else if (mem.eql(u8, arg, "-fbuiltin")) {
1553 no_builtin = false;1552 mod_opts.no_builtin = false;
1554 } else if (mem.eql(u8, arg, "-fno-builtin")) {1553 } else if (mem.eql(u8, arg, "-fno-builtin")) {
1555 no_builtin = true;1554 mod_opts.no_builtin = true;
1556 } else if (mem.startsWith(u8, arg, "-fopt-bisect-limit=")) {1555 } else if (mem.startsWith(u8, arg, "-fopt-bisect-limit=")) {
1557 const next_arg = arg["-fopt-bisect-limit=".len..];1556 const next_arg = arg["-fopt-bisect-limit=".len..];
1558 llvm_opt_bisect_limit = std.fmt.parseInt(c_int, next_arg, 0) catch |err|1557 llvm_opt_bisect_limit = std.fmt.parseInt(c_int, next_arg, 0) catch |err|
...@@ -1963,8 +1962,8 @@ fn buildOutputType(...@@ -1963,8 +1962,8 @@ fn buildOutputType(
1963 .no_function_sections => function_sections = false,1962 .no_function_sections => function_sections = false,
1964 .data_sections => data_sections = true,1963 .data_sections => data_sections = true,
1965 .no_data_sections => data_sections = false,1964 .no_data_sections => data_sections = false,
1966 .builtin => no_builtin = false,1965 .builtin => mod_opts.no_builtin = false,
1967 .no_builtin => no_builtin = true,1966 .no_builtin => mod_opts.no_builtin = true,
1968 .color_diagnostics => color = .on,1967 .color_diagnostics => color = .on,
1969 .no_color_diagnostics => color = .off,1968 .no_color_diagnostics => color = .off,
1970 .stack_check => mod_opts.stack_check = true,1969 .stack_check => mod_opts.stack_check = true,
...@@ -3468,7 +3467,6 @@ fn buildOutputType(...@@ -3468,7 +3467,6 @@ fn buildOutputType(
3468 .image_base = image_base,3467 .image_base = image_base,
3469 .function_sections = function_sections,3468 .function_sections = function_sections,
3470 .data_sections = data_sections,3469 .data_sections = data_sections,
3471 .no_builtin = no_builtin,
3472 .clang_passthrough_mode = clang_passthrough_mode,3470 .clang_passthrough_mode = clang_passthrough_mode,
3473 .clang_preprocessor_mode = clang_preprocessor_mode,3471 .clang_preprocessor_mode = clang_preprocessor_mode,
3474 .version = optional_version,3472 .version = optional_version,
src/mingw.zig+3-3
...@@ -41,7 +41,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre...@@ -41,7 +41,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
41 .owner = undefined,41 .owner = undefined,
42 },42 },
43 };43 };
44 return comp.build_crt_file("crt2", .Obj, null, .@"mingw-w64 crt2.o", prog_node, &files);44 return comp.build_crt_file("crt2", .Obj, .@"mingw-w64 crt2.o", prog_node, &files, .{});
45 },45 },
4646
47 .dllcrt2_o => {47 .dllcrt2_o => {
...@@ -56,7 +56,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre...@@ -56,7 +56,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
56 .owner = undefined,56 .owner = undefined,
57 },57 },
58 };58 };
59 return comp.build_crt_file("dllcrt2", .Obj, null, .@"mingw-w64 dllcrt2.o", prog_node, &files);59 return comp.build_crt_file("dllcrt2", .Obj, .@"mingw-w64 dllcrt2.o", prog_node, &files, .{});
60 },60 },
6161
62 .mingw32_lib => {62 .mingw32_lib => {
...@@ -118,7 +118,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre...@@ -118,7 +118,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
118 } else {118 } else {
119 @panic("unsupported arch");119 @panic("unsupported arch");
120 }120 }
121 return comp.build_crt_file("mingw32", .Lib, null, .@"mingw-w64 mingw32.lib", prog_node, c_source_files.items);121 return comp.build_crt_file("mingw32", .Lib, .@"mingw-w64 mingw32.lib", prog_node, c_source_files.items, .{});
122 },122 },
123 }123 }
124}124}
src/musl.zig+20-7
...@@ -38,7 +38,9 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro...@@ -38,7 +38,9 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
38 .owner = undefined,38 .owner = undefined,
39 },39 },
40 };40 };
41 return comp.build_crt_file("crti", .Obj, null, .@"musl crti.o", prog_node, &files);41 return comp.build_crt_file("crti", .Obj, .@"musl crti.o", prog_node, &files, .{
42 .no_builtin = true,
43 });
42 },44 },
43 .crtn_o => {45 .crtn_o => {
44 var args = std.ArrayList([]const u8).init(arena);46 var args = std.ArrayList([]const u8).init(arena);
...@@ -50,7 +52,9 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro...@@ -50,7 +52,9 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
50 .owner = undefined,52 .owner = undefined,
51 },53 },
52 };54 };
53 return comp.build_crt_file("crtn", .Obj, null, .@"musl crtn.o", prog_node, &files);55 return comp.build_crt_file("crtn", .Obj, .@"musl crtn.o", prog_node, &files, .{
56 .no_builtin = true,
57 });
54 },58 },
55 .crt1_o => {59 .crt1_o => {
56 var args = std.ArrayList([]const u8).init(arena);60 var args = std.ArrayList([]const u8).init(arena);
...@@ -68,7 +72,9 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro...@@ -68,7 +72,9 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
68 .owner = undefined,72 .owner = undefined,
69 },73 },
70 };74 };
71 return comp.build_crt_file("crt1", .Obj, null, .@"musl crt1.o", prog_node, &files);75 return comp.build_crt_file("crt1", .Obj, .@"musl crt1.o", prog_node, &files, .{
76 .no_builtin = true,
77 });
72 },78 },
73 .rcrt1_o => {79 .rcrt1_o => {
74 var args = std.ArrayList([]const u8).init(arena);80 var args = std.ArrayList([]const u8).init(arena);
...@@ -86,7 +92,10 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro...@@ -86,7 +92,10 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
86 .owner = undefined,92 .owner = undefined,
87 },93 },
88 };94 };
89 return comp.build_crt_file("rcrt1", .Obj, true, .@"musl rcrt1.o", prog_node, &files);95 return comp.build_crt_file("rcrt1", .Obj, .@"musl rcrt1.o", prog_node, &files, .{
96 .pic = true,
97 .no_builtin = true,
98 });
90 },99 },
91 .scrt1_o => {100 .scrt1_o => {
92 var args = std.ArrayList([]const u8).init(arena);101 var args = std.ArrayList([]const u8).init(arena);
...@@ -104,7 +113,10 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro...@@ -104,7 +113,10 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
104 .owner = undefined,113 .owner = undefined,
105 },114 },
106 };115 };
107 return comp.build_crt_file("Scrt1", .Obj, true, .@"musl Scrt1.o", prog_node, &files);116 return comp.build_crt_file("Scrt1", .Obj, .@"musl Scrt1.o", prog_node, &files, .{
117 .pic = true,
118 .no_builtin = true,
119 });
108 },120 },
109 .libc_a => {121 .libc_a => {
110 // When there is a src/<arch>/foo.* then it should substitute for src/foo.*122 // When there is a src/<arch>/foo.* then it should substitute for src/foo.*
...@@ -197,7 +209,9 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro...@@ -197,7 +209,9 @@ pub fn buildCrtFile(comp: *Compilation, in_crt_file: CrtFile, prog_node: std.Pro
197 .owner = undefined,209 .owner = undefined,
198 };210 };
199 }211 }
200 return comp.build_crt_file("c", .Lib, null, .@"musl libc.a", prog_node, c_source_files.items);212 return comp.build_crt_file("c", .Lib, .@"musl libc.a", prog_node, c_source_files.items, .{
213 .no_builtin = true,
214 });
201 },215 },
202 .libc_so => {216 .libc_so => {
203 const optimize_mode = comp.compilerRtOptMode();217 const optimize_mode = comp.compilerRtOptMode();
...@@ -410,7 +424,6 @@ fn addCcArgs(...@@ -410,7 +424,6 @@ fn addCcArgs(
410 try args.appendSlice(&[_][]const u8{424 try args.appendSlice(&[_][]const u8{
411 "-std=c99",425 "-std=c99",
412 "-ffreestanding",426 "-ffreestanding",
413 "-fno-builtin",
414 "-fexcess-precision=standard",427 "-fexcess-precision=standard",
415 "-frounding-math",428 "-frounding-math",
416 "-ffp-contract=off",429 "-ffp-contract=off",
src/wasi_libc.zig+7-7
...@@ -81,7 +81,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre...@@ -81,7 +81,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
81 .owner = undefined,81 .owner = undefined,
82 },82 },
83 };83 };
84 return comp.build_crt_file("crt1-reactor", .Obj, null, .@"wasi crt1-reactor.o", prog_node, &files);84 return comp.build_crt_file("crt1-reactor", .Obj, .@"wasi crt1-reactor.o", prog_node, &files, .{});
85 },85 },
86 .crt1_command_o => {86 .crt1_command_o => {
87 var args = std.ArrayList([]const u8).init(arena);87 var args = std.ArrayList([]const u8).init(arena);
...@@ -96,7 +96,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre...@@ -96,7 +96,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
96 .owner = undefined,96 .owner = undefined,
97 },97 },
98 };98 };
99 return comp.build_crt_file("crt1-command", .Obj, null, .@"wasi crt1-command.o", prog_node, &files);99 return comp.build_crt_file("crt1-command", .Obj, .@"wasi crt1-command.o", prog_node, &files, .{});
100 },100 },
101 .libc_a => {101 .libc_a => {
102 var libc_sources = std.ArrayList(Compilation.CSourceFile).init(arena);102 var libc_sources = std.ArrayList(Compilation.CSourceFile).init(arena);
...@@ -150,7 +150,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre...@@ -150,7 +150,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
150 }150 }
151 }151 }
152152
153 try comp.build_crt_file("c", .Lib, null, .@"wasi libc.a", prog_node, libc_sources.items);153 try comp.build_crt_file("c", .Lib, .@"wasi libc.a", prog_node, libc_sources.items, .{});
154 },154 },
155 .libwasi_emulated_process_clocks_a => {155 .libwasi_emulated_process_clocks_a => {
156 var args = std.ArrayList([]const u8).init(arena);156 var args = std.ArrayList([]const u8).init(arena);
...@@ -167,7 +167,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre...@@ -167,7 +167,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
167 .owner = undefined,167 .owner = undefined,
168 });168 });
169 }169 }
170 try comp.build_crt_file("wasi-emulated-process-clocks", .Lib, null, .@"libwasi-emulated-process-clocks.a", prog_node, emu_clocks_sources.items);170 try comp.build_crt_file("wasi-emulated-process-clocks", .Lib, .@"libwasi-emulated-process-clocks.a", prog_node, emu_clocks_sources.items, .{});
171 },171 },
172 .libwasi_emulated_getpid_a => {172 .libwasi_emulated_getpid_a => {
173 var args = std.ArrayList([]const u8).init(arena);173 var args = std.ArrayList([]const u8).init(arena);
...@@ -184,7 +184,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre...@@ -184,7 +184,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
184 .owner = undefined,184 .owner = undefined,
185 });185 });
186 }186 }
187 try comp.build_crt_file("wasi-emulated-getpid", .Lib, null, .@"libwasi-emulated-getpid.a", prog_node, emu_getpid_sources.items);187 try comp.build_crt_file("wasi-emulated-getpid", .Lib, .@"libwasi-emulated-getpid.a", prog_node, emu_getpid_sources.items, .{});
188 },188 },
189 .libwasi_emulated_mman_a => {189 .libwasi_emulated_mman_a => {
190 var args = std.ArrayList([]const u8).init(arena);190 var args = std.ArrayList([]const u8).init(arena);
...@@ -201,7 +201,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre...@@ -201,7 +201,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
201 .owner = undefined,201 .owner = undefined,
202 });202 });
203 }203 }
204 try comp.build_crt_file("wasi-emulated-mman", .Lib, null, .@"libwasi-emulated-mman.a", prog_node, emu_mman_sources.items);204 try comp.build_crt_file("wasi-emulated-mman", .Lib, .@"libwasi-emulated-mman.a", prog_node, emu_mman_sources.items, .{});
205 },205 },
206 .libwasi_emulated_signal_a => {206 .libwasi_emulated_signal_a => {
207 var emu_signal_sources = std.ArrayList(Compilation.CSourceFile).init(arena);207 var emu_signal_sources = std.ArrayList(Compilation.CSourceFile).init(arena);
...@@ -238,7 +238,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre...@@ -238,7 +238,7 @@ pub fn buildCrtFile(comp: *Compilation, crt_file: CrtFile, prog_node: std.Progre
238 }238 }
239 }239 }
240240
241 try comp.build_crt_file("wasi-emulated-signal", .Lib, null, .@"libwasi-emulated-signal.a", prog_node, emu_signal_sources.items);241 try comp.build_crt_file("wasi-emulated-signal", .Lib, .@"libwasi-emulated-signal.a", prog_node, emu_signal_sources.items, .{});
242 },242 },
243 }243 }
244}244}