authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-05 15:21:20-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-05 15:21:20-07:00
log2ee864ca5eb46468e8e0f4237a5532b76b60d715
treea70213c0c4c9f5c861e4c784e5980d6b60fea08d
parent927e59d0532c77e2fb3ead0c9c4f7ead0454785a

CLI: add support for -fno-builtin


6 files changed, 52 insertions(+), 4 deletions(-)

src/Compilation.zig+8
......@@ -825,6 +825,7 @@ pub const InitOptions = struct {
825825 rdynamic: bool = false,
826826 strip: bool = false,
827827 function_sections: bool = false,
828 no_builtin: bool = false,
828829 is_native_os: bool,
829830 is_native_abi: bool,
830831 time_report: bool = false,
......@@ -1351,6 +1352,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
13511352 cache.hash.add(omit_frame_pointer);
13521353 cache.hash.add(link_mode);
13531354 cache.hash.add(options.function_sections);
1355 cache.hash.add(options.no_builtin);
13541356 cache.hash.add(strip);
13551357 cache.hash.add(link_libc);
13561358 cache.hash.add(link_libcpp);
......@@ -1682,6 +1684,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
16821684 .is_native_os = options.is_native_os,
16831685 .is_native_abi = options.is_native_abi,
16841686 .function_sections = options.function_sections,
1687 .no_builtin = options.no_builtin,
16851688 .allow_shlib_undefined = options.linker_allow_shlib_undefined,
16861689 .bind_global_refs_locally = options.linker_bind_global_refs_locally orelse false,
16871690 .import_memory = options.linker_import_memory orelse false,
......@@ -3925,6 +3928,10 @@ pub fn addCCArgs(
39253928 try argv.append("-ffunction-sections");
39263929 }
39273930
3931 if (comp.bin_file.options.no_builtin) {
3932 try argv.append("-fno-builtin");
3933 }
3934
39283935 if (comp.bin_file.options.link_libcpp) {
39293936 const libcxx_include_path = try std.fs.path.join(arena, &[_][]const u8{
39303937 comp.zig_lib_directory.path.?, "libcxx", "include",
......@@ -4997,6 +5004,7 @@ fn buildOutputFromZig(
49975004 .optimize_mode = comp.compilerRtOptMode(),
49985005 .link_mode = .Static,
49995006 .function_sections = true,
5007 .no_builtin = true,
50005008 .want_sanitize_c = false,
50015009 .want_stack_check = false,
50025010 .want_red_zone = comp.bin_file.options.red_zone,
src/clang_options_data.zig+16-2
......@@ -2529,7 +2529,14 @@ flagpd1("fborland-extensions"),
25292529flagpd1("fbounds-check"),
25302530sepd1("fbracket-depth"),
25312531flagpd1("fbranch-count-reg"),
2532flagpd1("fbuiltin"),
2532.{
2533 .name = "fbuiltin",
2534 .syntax = .flag,
2535 .zig_equivalent = .builtin,
2536 .pd1 = true,
2537 .pd2 = false,
2538 .psl = false,
2539},
25332540flagpd1("fbuiltin-module-map"),
25342541flagpd1("fcall-saved-x10"),
25352542flagpd1("fcall-saved-x11"),
......@@ -2925,7 +2932,14 @@ flagpd1("fno-blocks"),
29252932flagpd1("fno-borland-extensions"),
29262933flagpd1("fno-bounds-check"),
29272934flagpd1("fno-branch-count-reg"),
2928flagpd1("fno-builtin"),
2935.{
2936 .name = "fno-builtin",
2937 .syntax = .flag,
2938 .zig_equivalent = .no_builtin,
2939 .pd1 = true,
2940 .pd2 = false,
2941 .psl = false,
2942},
29292943flagpd1("fno-caller-saves"),
29302944.{
29312945 .name = "fno-caret-diagnostics",
src/codegen/llvm.zig+3-1
......@@ -2347,7 +2347,9 @@ pub const DeclGen = struct {
23472347 if (comp.unwind_tables) {
23482348 dg.addFnAttr(llvm_fn, "uwtable");
23492349 }
2350 if (comp.bin_file.options.skip_linker_dependencies) {
2350 if (comp.bin_file.options.skip_linker_dependencies or
2351 comp.bin_file.options.no_builtin)
2352 {
23512353 // The intent here is for compiler-rt and libc functions to not generate
23522354 // infinite recursion. For example, if we are compiling the memcpy function,
23532355 // and llvm detects that the body is equivalent to memcpy, it may replace the
src/link.zig+1
......@@ -108,6 +108,7 @@ pub const Options = struct {
108108 link_libcpp: bool,
109109 link_libunwind: bool,
110110 function_sections: bool,
111 no_builtin: bool,
111112 eh_frame_hdr: bool,
112113 emit_relocs: bool,
113114 rdynamic: bool,
src/main.zig+16-1
......@@ -381,6 +381,10 @@ const usage_build_generic =
381381 \\ -fno-stage1 Prevent using bootstrap compiler as the codegen backend
382382 \\ -fsingle-threaded Code assumes there is only one thread
383383 \\ -fno-single-threaded Code may not assume there is only one thread
384 \\ -fbuiltin Enable implicit builtin knowledge of functions
385 \\ -fno-builtin Disable implicit builtin knowledge of functions
386 \\ -ffunction-sections Places each function in a separate section
387 \\ -fno-function-sections All functions go into same section
384388 \\ --strip Omit debug symbols
385389 \\ -ofmt=[mode] Override target object format
386390 \\ elf Executable and Linking Format
......@@ -398,7 +402,6 @@ const usage_build_generic =
398402 \\ -D[macro]=[value] Define C [macro] to [value] (1 if [value] omitted)
399403 \\ --libc [file] Provide a file which specifies libc paths
400404 \\ -cflags [flags] -- Set extra flags for the next positional C source files
401 \\ -ffunction-sections Places each function in a separate section
402405 \\
403406 \\Link Options:
404407 \\ -l[lib], --library [lib] Link against system library (only if actually used)
......@@ -604,6 +607,7 @@ fn buildOutputType(
604607 var compatibility_version: ?std.builtin.Version = null;
605608 var strip = false;
606609 var function_sections = false;
610 var no_builtin = false;
607611 var watch = false;
608612 var debug_compile_errors = false;
609613 var verbose_link = std.process.hasEnvVarConstant("ZIG_VERBOSE_LINK");
......@@ -1241,6 +1245,12 @@ fn buildOutputType(
12411245 single_threaded = false;
12421246 } else if (mem.eql(u8, arg, "-ffunction-sections")) {
12431247 function_sections = true;
1248 } else if (mem.eql(u8, arg, "-fno-function-sections")) {
1249 function_sections = false;
1250 } else if (mem.eql(u8, arg, "-fbuiltin")) {
1251 no_builtin = false;
1252 } else if (mem.eql(u8, arg, "-fno-builtin")) {
1253 no_builtin = true;
12441254 } else if (mem.eql(u8, arg, "--eh-frame-hdr")) {
12451255 link_eh_frame_hdr = true;
12461256 } else if (mem.eql(u8, arg, "--emit-relocs")) {
......@@ -1464,6 +1474,8 @@ fn buildOutputType(
14641474 .no_omit_frame_pointer => omit_frame_pointer = false,
14651475 .function_sections => function_sections = true,
14661476 .no_function_sections => function_sections = false,
1477 .builtin => no_builtin = false,
1478 .no_builtin => no_builtin = true,
14671479 .color_diagnostics => color = .on,
14681480 .no_color_diagnostics => color = .off,
14691481 .stack_check => want_stack_check = true,
......@@ -2847,6 +2859,7 @@ fn buildOutputType(
28472859 .strip = strip,
28482860 .single_threaded = single_threaded,
28492861 .function_sections = function_sections,
2862 .no_builtin = no_builtin,
28502863 .self_exe_path = self_exe_path,
28512864 .thread_pool = &thread_pool,
28522865 .clang_passthrough_mode = clang_passthrough_mode,
......@@ -4572,6 +4585,8 @@ pub const ClangArgIterator = struct {
45724585 no_omit_frame_pointer,
45734586 function_sections,
45744587 no_function_sections,
4588 builtin,
4589 no_builtin,
45754590 color_diagnostics,
45764591 no_color_diagnostics,
45774592 stack_check,
tools/update_clang_options.zig+8
......@@ -320,6 +320,14 @@ const known_options = [_]KnownOpt{
320320 .name = "fno-function-sections",
321321 .ident = "no_function_sections",
322322 },
323 .{
324 .name = "fbuiltin",
325 .ident = "builtin",
326 },
327 .{
328 .name = "fno-builtin",
329 .ident = "no_builtin",
330 },
323331 .{
324332 .name = "fcolor-diagnostics",
325333 .ident = "color_diagnostics",