aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2020-09-29 00:50:20 -0700
committerAndrew Kelley <andrew@ziglang.org>2020-09-29 00:50:20 -0700
commitd3a99c7bd5396f2e458d844368ce2743934e43e2 (patch)
treeaf7d6aef6498a84d0d8ae779a2efecd2efff0ad6 /src
parentcfbcb4116017a27a403f8be11a32f25f6c1c8671 (diff)
downloadzig-d3a99c7bd5396f2e458d844368ce2743934e43e2.tar.gz
zig-d3a99c7bd5396f2e458d844368ce2743934e43e2.zip
add CLI options for darwin frameworks and -ffunction-sections
and add missing usage help text
Diffstat (limited to 'src')
-rw-r--r--src/Compilation.zig7
-rw-r--r--src/main.zig24
2 files changed, 25 insertions, 6 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig
index aa6ab94415..1cd0d6c099 100644
--- a/src/Compilation.zig
+++ b/src/Compilation.zig
@@ -347,6 +347,7 @@ pub const InitOptions = struct {
rdynamic: bool = false,
strip: bool = false,
single_threaded: bool = false,
+ function_sections: bool = false,
is_native_os: bool,
time_report: bool = false,
stack_report: bool = false,
@@ -355,7 +356,6 @@ pub const InitOptions = struct {
version_script: ?[]const u8 = null,
override_soname: ?[]const u8 = null,
linker_gc_sections: ?bool = null,
- function_sections: ?bool = null,
linker_allow_shlib_undefined: ?bool = null,
linker_bind_global_refs_locally: ?bool = null,
each_lib_rpath: ?bool = null,
@@ -538,7 +538,6 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
};
const single_threaded = options.single_threaded or target_util.isSingleThreaded(options.target);
- const function_sections = options.function_sections orelse false;
const llvm_cpu_features: ?[*:0]const u8 = if (build_options.have_llvm and use_llvm) blk: {
var buf = std.ArrayList(u8).init(arena);
@@ -589,7 +588,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
cache.hash.add(pic);
cache.hash.add(stack_check);
cache.hash.add(link_mode);
- cache.hash.add(function_sections);
+ cache.hash.add(options.function_sections);
cache.hash.add(strip);
cache.hash.add(link_libc);
cache.hash.add(options.link_libcpp);
@@ -757,7 +756,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
.rpath_list = options.rpath_list,
.strip = strip,
.is_native_os = options.is_native_os,
- .function_sections = options.function_sections orelse false,
+ .function_sections = options.function_sections,
.allow_shlib_undefined = options.linker_allow_shlib_undefined,
.bind_global_refs_locally = options.linker_bind_global_refs_locally orelse false,
.z_nodelete = options.linker_z_nodelete,
diff --git a/src/main.zig b/src/main.zig
index 80e92a73b0..de2f38bffb 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -260,11 +260,13 @@ const usage_build_generic =
\\ -D[macro]=[value] Define C [macro] to [value] (1 if [value] omitted)
\\ --libc [file] Provide a file which specifies libc paths
\\ -cflags [flags] -- Set extra flags for the next positional C source files
+ \\ -ffunction-sections Places each function in a separate section
\\
\\Link Options:
\\ -l[lib], --library [lib] Link against system library
\\ -L[d], --library-directory [d] Add a directory to the library search path
- \\ -T[script] Use a custom linker script
+ \\ -T[script], --script [script] Use a custom linker script
+ \\ --version-script [path] Provide a version .map file
\\ --dynamic-linker [path] Set the dynamic interpreter path (usually ld.so)
\\ --each-lib-rpath Add rpath for each used dynamic library
\\ --version [ver] Dynamic library semver
@@ -273,7 +275,11 @@ const usage_build_generic =
\\ --eh-frame-hdr Enable C++ exception handling by passing --eh-frame-hdr to linker
\\ -dynamic Force output to be dynamically linked
\\ -static Force output to be statically linked
+ \\ -Bsymbolic Bind global references locally
\\ --subsystem [subsystem] (windows) /SUBSYSTEM:<subsystem> to the linker\n"
+ \\ --stack [size] Override default stack size
+ \\ -framework [name] (darwin) link against framework
+ \\ -F[dir] (darwin) add search path for frameworks
\\
\\Test Options:
\\ --test-filter [text] Skip tests that do not match filter
@@ -381,6 +387,7 @@ fn buildOutputType(
var have_version = false;
var strip = false;
var single_threaded = false;
+ var function_sections = false;
var watch = false;
var verbose_link = false;
var verbose_cc = false;
@@ -634,7 +641,15 @@ fn buildOutputType(
if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});
i += 1;
try lib_dirs.append(args[i]);
- } else if (mem.eql(u8, arg, "-T")) {
+ } else if (mem.eql(u8, arg, "-F")) {
+ if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});
+ i += 1;
+ try framework_dirs.append(args[i]);
+ } else if (mem.eql(u8, arg, "-framework")) {
+ if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});
+ i += 1;
+ try frameworks.append(args[i]);
+ } else if (mem.eql(u8, arg, "-T") or mem.eql(u8, arg, "--script")) {
if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});
i += 1;
linker_script = args[i];
@@ -819,6 +834,8 @@ fn buildOutputType(
strip = true;
} else if (mem.eql(u8, arg, "--single-threaded")) {
single_threaded = true;
+ } else if (mem.eql(u8, arg, "-ffunction-sections")) {
+ function_sections = true;
} else if (mem.eql(u8, arg, "--eh-frame-hdr")) {
link_eh_frame_hdr = true;
} else if (mem.eql(u8, arg, "-Bsymbolic")) {
@@ -843,6 +860,8 @@ fn buildOutputType(
linker_script = arg[2..];
} else if (mem.startsWith(u8, arg, "-L")) {
try lib_dirs.append(arg[2..]);
+ } else if (mem.startsWith(u8, arg, "-F")) {
+ try framework_dirs.append(arg[2..]);
} else if (mem.startsWith(u8, arg, "-l")) {
// We don't know whether this library is part of libc or libc++ until we resolve the target.
// So we simply append to the list for now.
@@ -1555,6 +1574,7 @@ fn buildOutputType(
.stack_size_override = stack_size_override,
.strip = strip,
.single_threaded = single_threaded,
+ .function_sections = function_sections,
.self_exe_path = self_exe_path,
.rand = &default_prng.random,
.clang_passthrough_mode = arg_mode != .build,