authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-29 00:50:20-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2020-09-29 00:50:20-07:00
logd3a99c7bd5396f2e458d844368ce2743934e43e2
treeaf7d6aef6498a84d0d8ae779a2efecd2efff0ad6
parentcfbcb4116017a27a403f8be11a32f25f6c1c8671

add CLI options for darwin frameworks and -ffunction-sections

and add missing usage help text

3 files changed, 27 insertions(+), 52 deletions(-)

BRANCH_TODO+2-46
......@@ -1,47 +1,3 @@
1 * audit the CLI options for stage2
1 * building risc-v musl regression
2 * go ahead and use allocSentinel now that the stage1 bug is fixed
23 * audit the base cache hash
3 * try building some software with zig cc to make sure it didn't regress
4
5 * On operating systems that support it, do an execve for `zig test` and `zig run` rather than child process.
6 * implement proper parsing of clang stderr/stdout and exposing compile errors with the Compilation API
7 * implement proper parsing of LLD stderr/stdout and exposing compile errors with the Compilation API
8 * support cross compiling stage2 with `zig build`
9 * implement proper compile errors for failing to build glibc crt files and shared libs
10 * implement -fno-emit-bin
11 * improve the stage2 tests to support testing with LLVM extensions enabled
12 * implement emit-h in stage2
13 * multi-thread building C objects
14 * implement serialization/deserialization of incremental compilation metadata
15 * incremental compilation - implement detection of which source files changed
16 * improve the cache hash logic for c objects with respect to extra flags and file parameters
17 * LLVM codegen backend: put a sub-arch in the triple in some cases
18 * implement an LLVM backend for stage2
19 * implement outputting dynamic libraries in self-hosted linker
20 * implement outputting static libraries (archive files) in self-hosted linker
21 * support linking against object files in self-hosted linker
22 * avoid invoking lld when it's just 1 object file (the `zig cc -c` case)
23 * `zig fmt --check` should output to stdout not stderr.
24 * main.zig: If there was an argsAllocZ we could avoid this allocation
25 * improve robustness of response file parsing
26 * there are a couple panic("TODO") in clang options parsing
27 * std.testing needs improvement to support exposing directory path for its tmp dir (look for "bogus")
28 * integrate target features into building assembly code
29 * libc_installation.zig: make it look for msvc only if msvc abi is chosen
30 * switch the default C ABI for windows to be mingw-w64
31 - make it .obj instead of .o always for coff
32 * change glibc log errors to normal exposed compile errors
33 * improve Directory.join to only use 1 allocation in a clean way.
34 * tracy builds with lc++
35 * some kind of "zig identifier escape" function rather than unconditionally using @"" syntax
36 in builtin.zig
37 * rename std.builtin.Mode to std.builtin.OptimizeMode
38 * implement `zig run` and `zig test` when combined with `--watch`
39 * close the --pkg-begin --pkg-end Package directory handles
40 * make std.Progress support multithreaded
41 * update musl.zig static data to use native path separator in static data rather than replacing '/' at runtime
42 * linking hello world with LLD, lld is silently calling exit(1) instead of reporting ok=false. when run standalone the error message is: ld.lld: error: section [index 3] has a sh_offset (0x57000) + sh_size (0x68) that is greater than the file size (0x57060)
43 * submit PR to godbolt and update the CLI options (see changes to test/cli.zig)
44 * make proposal about log levels
45 * proposal for changing fs Z/W functions to be native paths and have a way to do native path string literals
46 * proposal for block { break x; }
47 * generally look for the "TODO surface this as a real compile error message" and fix all that stuff
src/Compilation.zig+3-4
......@@ -347,6 +347,7 @@ pub const InitOptions = struct {
347347 rdynamic: bool = false,
348348 strip: bool = false,
349349 single_threaded: bool = false,
350 function_sections: bool = false,
350351 is_native_os: bool,
351352 time_report: bool = false,
352353 stack_report: bool = false,
......@@ -355,7 +356,6 @@ pub const InitOptions = struct {
355356 version_script: ?[]const u8 = null,
356357 override_soname: ?[]const u8 = null,
357358 linker_gc_sections: ?bool = null,
358 function_sections: ?bool = null,
359359 linker_allow_shlib_undefined: ?bool = null,
360360 linker_bind_global_refs_locally: ?bool = null,
361361 each_lib_rpath: ?bool = null,
......@@ -538,7 +538,6 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
538538 };
539539
540540 const single_threaded = options.single_threaded or target_util.isSingleThreaded(options.target);
541 const function_sections = options.function_sections orelse false;
542541
543542 const llvm_cpu_features: ?[*:0]const u8 = if (build_options.have_llvm and use_llvm) blk: {
544543 var buf = std.ArrayList(u8).init(arena);
......@@ -589,7 +588,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
589588 cache.hash.add(pic);
590589 cache.hash.add(stack_check);
591590 cache.hash.add(link_mode);
592 cache.hash.add(function_sections);
591 cache.hash.add(options.function_sections);
593592 cache.hash.add(strip);
594593 cache.hash.add(link_libc);
595594 cache.hash.add(options.link_libcpp);
......@@ -757,7 +756,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
757756 .rpath_list = options.rpath_list,
758757 .strip = strip,
759758 .is_native_os = options.is_native_os,
760 .function_sections = options.function_sections orelse false,
759 .function_sections = options.function_sections,
761760 .allow_shlib_undefined = options.linker_allow_shlib_undefined,
762761 .bind_global_refs_locally = options.linker_bind_global_refs_locally orelse false,
763762 .z_nodelete = options.linker_z_nodelete,
src/main.zig+22-2
......@@ -260,11 +260,13 @@ const usage_build_generic =
260260 \\ -D[macro]=[value] Define C [macro] to [value] (1 if [value] omitted)
261261 \\ --libc [file] Provide a file which specifies libc paths
262262 \\ -cflags [flags] -- Set extra flags for the next positional C source files
263 \\ -ffunction-sections Places each function in a separate section
263264 \\
264265 \\Link Options:
265266 \\ -l[lib], --library [lib] Link against system library
266267 \\ -L[d], --library-directory [d] Add a directory to the library search path
267 \\ -T[script] Use a custom linker script
268 \\ -T[script], --script [script] Use a custom linker script
269 \\ --version-script [path] Provide a version .map file
268270 \\ --dynamic-linker [path] Set the dynamic interpreter path (usually ld.so)
269271 \\ --each-lib-rpath Add rpath for each used dynamic library
270272 \\ --version [ver] Dynamic library semver
......@@ -273,7 +275,11 @@ const usage_build_generic =
273275 \\ --eh-frame-hdr Enable C++ exception handling by passing --eh-frame-hdr to linker
274276 \\ -dynamic Force output to be dynamically linked
275277 \\ -static Force output to be statically linked
278 \\ -Bsymbolic Bind global references locally
276279 \\ --subsystem [subsystem] (windows) /SUBSYSTEM:<subsystem> to the linker\n"
280 \\ --stack [size] Override default stack size
281 \\ -framework [name] (darwin) link against framework
282 \\ -F[dir] (darwin) add search path for frameworks
277283 \\
278284 \\Test Options:
279285 \\ --test-filter [text] Skip tests that do not match filter
......@@ -381,6 +387,7 @@ fn buildOutputType(
381387 var have_version = false;
382388 var strip = false;
383389 var single_threaded = false;
390 var function_sections = false;
384391 var watch = false;
385392 var verbose_link = false;
386393 var verbose_cc = false;
......@@ -634,7 +641,15 @@ fn buildOutputType(
634641 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});
635642 i += 1;
636643 try lib_dirs.append(args[i]);
637 } else if (mem.eql(u8, arg, "-T")) {
644 } else if (mem.eql(u8, arg, "-F")) {
645 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});
646 i += 1;
647 try framework_dirs.append(args[i]);
648 } else if (mem.eql(u8, arg, "-framework")) {
649 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});
650 i += 1;
651 try frameworks.append(args[i]);
652 } else if (mem.eql(u8, arg, "-T") or mem.eql(u8, arg, "--script")) {
638653 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});
639654 i += 1;
640655 linker_script = args[i];
......@@ -819,6 +834,8 @@ fn buildOutputType(
819834 strip = true;
820835 } else if (mem.eql(u8, arg, "--single-threaded")) {
821836 single_threaded = true;
837 } else if (mem.eql(u8, arg, "-ffunction-sections")) {
838 function_sections = true;
822839 } else if (mem.eql(u8, arg, "--eh-frame-hdr")) {
823840 link_eh_frame_hdr = true;
824841 } else if (mem.eql(u8, arg, "-Bsymbolic")) {
......@@ -843,6 +860,8 @@ fn buildOutputType(
843860 linker_script = arg[2..];
844861 } else if (mem.startsWith(u8, arg, "-L")) {
845862 try lib_dirs.append(arg[2..]);
863 } else if (mem.startsWith(u8, arg, "-F")) {
864 try framework_dirs.append(arg[2..]);
846865 } else if (mem.startsWith(u8, arg, "-l")) {
847866 // We don't know whether this library is part of libc or libc++ until we resolve the target.
848867 // So we simply append to the list for now.
......@@ -1555,6 +1574,7 @@ fn buildOutputType(
15551574 .stack_size_override = stack_size_override,
15561575 .strip = strip,
15571576 .single_threaded = single_threaded,
1577 .function_sections = function_sections,
15581578 .self_exe_path = self_exe_path,
15591579 .rand = &default_prng.random,
15601580 .clang_passthrough_mode = arg_mode != .build,