mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
CLI: add support for -fno-builtin
This commit is contained in:
parent
927e59d053
commit
2ee864ca5e
6 changed files with 52 additions and 4 deletions
|
|
@ -825,6 +825,7 @@ pub const InitOptions = struct {
|
||||||
rdynamic: bool = false,
|
rdynamic: bool = false,
|
||||||
strip: bool = false,
|
strip: bool = false,
|
||||||
function_sections: bool = false,
|
function_sections: bool = false,
|
||||||
|
no_builtin: bool = false,
|
||||||
is_native_os: bool,
|
is_native_os: bool,
|
||||||
is_native_abi: bool,
|
is_native_abi: bool,
|
||||||
time_report: bool = false,
|
time_report: bool = false,
|
||||||
|
|
@ -1351,6 +1352,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
|
||||||
cache.hash.add(omit_frame_pointer);
|
cache.hash.add(omit_frame_pointer);
|
||||||
cache.hash.add(link_mode);
|
cache.hash.add(link_mode);
|
||||||
cache.hash.add(options.function_sections);
|
cache.hash.add(options.function_sections);
|
||||||
|
cache.hash.add(options.no_builtin);
|
||||||
cache.hash.add(strip);
|
cache.hash.add(strip);
|
||||||
cache.hash.add(link_libc);
|
cache.hash.add(link_libc);
|
||||||
cache.hash.add(link_libcpp);
|
cache.hash.add(link_libcpp);
|
||||||
|
|
@ -1682,6 +1684,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
|
||||||
.is_native_os = options.is_native_os,
|
.is_native_os = options.is_native_os,
|
||||||
.is_native_abi = options.is_native_abi,
|
.is_native_abi = options.is_native_abi,
|
||||||
.function_sections = options.function_sections,
|
.function_sections = options.function_sections,
|
||||||
|
.no_builtin = options.no_builtin,
|
||||||
.allow_shlib_undefined = options.linker_allow_shlib_undefined,
|
.allow_shlib_undefined = options.linker_allow_shlib_undefined,
|
||||||
.bind_global_refs_locally = options.linker_bind_global_refs_locally orelse false,
|
.bind_global_refs_locally = options.linker_bind_global_refs_locally orelse false,
|
||||||
.import_memory = options.linker_import_memory orelse false,
|
.import_memory = options.linker_import_memory orelse false,
|
||||||
|
|
@ -3925,6 +3928,10 @@ pub fn addCCArgs(
|
||||||
try argv.append("-ffunction-sections");
|
try argv.append("-ffunction-sections");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (comp.bin_file.options.no_builtin) {
|
||||||
|
try argv.append("-fno-builtin");
|
||||||
|
}
|
||||||
|
|
||||||
if (comp.bin_file.options.link_libcpp) {
|
if (comp.bin_file.options.link_libcpp) {
|
||||||
const libcxx_include_path = try std.fs.path.join(arena, &[_][]const u8{
|
const libcxx_include_path = try std.fs.path.join(arena, &[_][]const u8{
|
||||||
comp.zig_lib_directory.path.?, "libcxx", "include",
|
comp.zig_lib_directory.path.?, "libcxx", "include",
|
||||||
|
|
@ -4997,6 +5004,7 @@ fn buildOutputFromZig(
|
||||||
.optimize_mode = comp.compilerRtOptMode(),
|
.optimize_mode = comp.compilerRtOptMode(),
|
||||||
.link_mode = .Static,
|
.link_mode = .Static,
|
||||||
.function_sections = true,
|
.function_sections = true,
|
||||||
|
.no_builtin = true,
|
||||||
.want_sanitize_c = false,
|
.want_sanitize_c = false,
|
||||||
.want_stack_check = false,
|
.want_stack_check = false,
|
||||||
.want_red_zone = comp.bin_file.options.red_zone,
|
.want_red_zone = comp.bin_file.options.red_zone,
|
||||||
|
|
|
||||||
|
|
@ -2529,7 +2529,14 @@ flagpd1("fborland-extensions"),
|
||||||
flagpd1("fbounds-check"),
|
flagpd1("fbounds-check"),
|
||||||
sepd1("fbracket-depth"),
|
sepd1("fbracket-depth"),
|
||||||
flagpd1("fbranch-count-reg"),
|
flagpd1("fbranch-count-reg"),
|
||||||
flagpd1("fbuiltin"),
|
.{
|
||||||
|
.name = "fbuiltin",
|
||||||
|
.syntax = .flag,
|
||||||
|
.zig_equivalent = .builtin,
|
||||||
|
.pd1 = true,
|
||||||
|
.pd2 = false,
|
||||||
|
.psl = false,
|
||||||
|
},
|
||||||
flagpd1("fbuiltin-module-map"),
|
flagpd1("fbuiltin-module-map"),
|
||||||
flagpd1("fcall-saved-x10"),
|
flagpd1("fcall-saved-x10"),
|
||||||
flagpd1("fcall-saved-x11"),
|
flagpd1("fcall-saved-x11"),
|
||||||
|
|
@ -2925,7 +2932,14 @@ flagpd1("fno-blocks"),
|
||||||
flagpd1("fno-borland-extensions"),
|
flagpd1("fno-borland-extensions"),
|
||||||
flagpd1("fno-bounds-check"),
|
flagpd1("fno-bounds-check"),
|
||||||
flagpd1("fno-branch-count-reg"),
|
flagpd1("fno-branch-count-reg"),
|
||||||
flagpd1("fno-builtin"),
|
.{
|
||||||
|
.name = "fno-builtin",
|
||||||
|
.syntax = .flag,
|
||||||
|
.zig_equivalent = .no_builtin,
|
||||||
|
.pd1 = true,
|
||||||
|
.pd2 = false,
|
||||||
|
.psl = false,
|
||||||
|
},
|
||||||
flagpd1("fno-caller-saves"),
|
flagpd1("fno-caller-saves"),
|
||||||
.{
|
.{
|
||||||
.name = "fno-caret-diagnostics",
|
.name = "fno-caret-diagnostics",
|
||||||
|
|
|
||||||
|
|
@ -2347,7 +2347,9 @@ pub const DeclGen = struct {
|
||||||
if (comp.unwind_tables) {
|
if (comp.unwind_tables) {
|
||||||
dg.addFnAttr(llvm_fn, "uwtable");
|
dg.addFnAttr(llvm_fn, "uwtable");
|
||||||
}
|
}
|
||||||
if (comp.bin_file.options.skip_linker_dependencies) {
|
if (comp.bin_file.options.skip_linker_dependencies or
|
||||||
|
comp.bin_file.options.no_builtin)
|
||||||
|
{
|
||||||
// The intent here is for compiler-rt and libc functions to not generate
|
// The intent here is for compiler-rt and libc functions to not generate
|
||||||
// infinite recursion. For example, if we are compiling the memcpy function,
|
// 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
|
// and llvm detects that the body is equivalent to memcpy, it may replace the
|
||||||
|
|
|
||||||
|
|
@ -108,6 +108,7 @@ pub const Options = struct {
|
||||||
link_libcpp: bool,
|
link_libcpp: bool,
|
||||||
link_libunwind: bool,
|
link_libunwind: bool,
|
||||||
function_sections: bool,
|
function_sections: bool,
|
||||||
|
no_builtin: bool,
|
||||||
eh_frame_hdr: bool,
|
eh_frame_hdr: bool,
|
||||||
emit_relocs: bool,
|
emit_relocs: bool,
|
||||||
rdynamic: bool,
|
rdynamic: bool,
|
||||||
|
|
|
||||||
17
src/main.zig
17
src/main.zig
|
|
@ -381,6 +381,10 @@ const usage_build_generic =
|
||||||
\\ -fno-stage1 Prevent using bootstrap compiler as the codegen backend
|
\\ -fno-stage1 Prevent using bootstrap compiler as the codegen backend
|
||||||
\\ -fsingle-threaded Code assumes there is only one thread
|
\\ -fsingle-threaded Code assumes there is only one thread
|
||||||
\\ -fno-single-threaded Code may not assume there is only one thread
|
\\ -fno-single-threaded Code may not assume there is only one thread
|
||||||
|
\\ -fbuiltin Enable implicit builtin knowledge of functions
|
||||||
|
\\ -fno-builtin Disable implicit builtin knowledge of functions
|
||||||
|
\\ -ffunction-sections Places each function in a separate section
|
||||||
|
\\ -fno-function-sections All functions go into same section
|
||||||
\\ --strip Omit debug symbols
|
\\ --strip Omit debug symbols
|
||||||
\\ -ofmt=[mode] Override target object format
|
\\ -ofmt=[mode] Override target object format
|
||||||
\\ elf Executable and Linking Format
|
\\ elf Executable and Linking Format
|
||||||
|
|
@ -398,7 +402,6 @@ const usage_build_generic =
|
||||||
\\ -D[macro]=[value] Define C [macro] to [value] (1 if [value] omitted)
|
\\ -D[macro]=[value] Define C [macro] to [value] (1 if [value] omitted)
|
||||||
\\ --libc [file] Provide a file which specifies libc paths
|
\\ --libc [file] Provide a file which specifies libc paths
|
||||||
\\ -cflags [flags] -- Set extra flags for the next positional C source files
|
\\ -cflags [flags] -- Set extra flags for the next positional C source files
|
||||||
\\ -ffunction-sections Places each function in a separate section
|
|
||||||
\\
|
\\
|
||||||
\\Link Options:
|
\\Link Options:
|
||||||
\\ -l[lib], --library [lib] Link against system library (only if actually used)
|
\\ -l[lib], --library [lib] Link against system library (only if actually used)
|
||||||
|
|
@ -604,6 +607,7 @@ fn buildOutputType(
|
||||||
var compatibility_version: ?std.builtin.Version = null;
|
var compatibility_version: ?std.builtin.Version = null;
|
||||||
var strip = false;
|
var strip = false;
|
||||||
var function_sections = false;
|
var function_sections = false;
|
||||||
|
var no_builtin = false;
|
||||||
var watch = false;
|
var watch = false;
|
||||||
var debug_compile_errors = false;
|
var debug_compile_errors = false;
|
||||||
var verbose_link = std.process.hasEnvVarConstant("ZIG_VERBOSE_LINK");
|
var verbose_link = std.process.hasEnvVarConstant("ZIG_VERBOSE_LINK");
|
||||||
|
|
@ -1241,6 +1245,12 @@ fn buildOutputType(
|
||||||
single_threaded = false;
|
single_threaded = false;
|
||||||
} else if (mem.eql(u8, arg, "-ffunction-sections")) {
|
} else if (mem.eql(u8, arg, "-ffunction-sections")) {
|
||||||
function_sections = true;
|
function_sections = true;
|
||||||
|
} else if (mem.eql(u8, arg, "-fno-function-sections")) {
|
||||||
|
function_sections = false;
|
||||||
|
} else if (mem.eql(u8, arg, "-fbuiltin")) {
|
||||||
|
no_builtin = false;
|
||||||
|
} else if (mem.eql(u8, arg, "-fno-builtin")) {
|
||||||
|
no_builtin = true;
|
||||||
} else if (mem.eql(u8, arg, "--eh-frame-hdr")) {
|
} else if (mem.eql(u8, arg, "--eh-frame-hdr")) {
|
||||||
link_eh_frame_hdr = true;
|
link_eh_frame_hdr = true;
|
||||||
} else if (mem.eql(u8, arg, "--emit-relocs")) {
|
} else if (mem.eql(u8, arg, "--emit-relocs")) {
|
||||||
|
|
@ -1464,6 +1474,8 @@ fn buildOutputType(
|
||||||
.no_omit_frame_pointer => omit_frame_pointer = false,
|
.no_omit_frame_pointer => omit_frame_pointer = false,
|
||||||
.function_sections => function_sections = true,
|
.function_sections => function_sections = true,
|
||||||
.no_function_sections => function_sections = false,
|
.no_function_sections => function_sections = false,
|
||||||
|
.builtin => no_builtin = false,
|
||||||
|
.no_builtin => no_builtin = true,
|
||||||
.color_diagnostics => color = .on,
|
.color_diagnostics => color = .on,
|
||||||
.no_color_diagnostics => color = .off,
|
.no_color_diagnostics => color = .off,
|
||||||
.stack_check => want_stack_check = true,
|
.stack_check => want_stack_check = true,
|
||||||
|
|
@ -2847,6 +2859,7 @@ fn buildOutputType(
|
||||||
.strip = strip,
|
.strip = strip,
|
||||||
.single_threaded = single_threaded,
|
.single_threaded = single_threaded,
|
||||||
.function_sections = function_sections,
|
.function_sections = function_sections,
|
||||||
|
.no_builtin = no_builtin,
|
||||||
.self_exe_path = self_exe_path,
|
.self_exe_path = self_exe_path,
|
||||||
.thread_pool = &thread_pool,
|
.thread_pool = &thread_pool,
|
||||||
.clang_passthrough_mode = clang_passthrough_mode,
|
.clang_passthrough_mode = clang_passthrough_mode,
|
||||||
|
|
@ -4572,6 +4585,8 @@ pub const ClangArgIterator = struct {
|
||||||
no_omit_frame_pointer,
|
no_omit_frame_pointer,
|
||||||
function_sections,
|
function_sections,
|
||||||
no_function_sections,
|
no_function_sections,
|
||||||
|
builtin,
|
||||||
|
no_builtin,
|
||||||
color_diagnostics,
|
color_diagnostics,
|
||||||
no_color_diagnostics,
|
no_color_diagnostics,
|
||||||
stack_check,
|
stack_check,
|
||||||
|
|
|
||||||
|
|
@ -320,6 +320,14 @@ const known_options = [_]KnownOpt{
|
||||||
.name = "fno-function-sections",
|
.name = "fno-function-sections",
|
||||||
.ident = "no_function_sections",
|
.ident = "no_function_sections",
|
||||||
},
|
},
|
||||||
|
.{
|
||||||
|
.name = "fbuiltin",
|
||||||
|
.ident = "builtin",
|
||||||
|
},
|
||||||
|
.{
|
||||||
|
.name = "fno-builtin",
|
||||||
|
.ident = "no_builtin",
|
||||||
|
},
|
||||||
.{
|
.{
|
||||||
.name = "fcolor-diagnostics",
|
.name = "fcolor-diagnostics",
|
||||||
.ident = "color_diagnostics",
|
.ident = "color_diagnostics",
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue