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,47 +1,3 @@
1 * audit the CLI options for stage21 * building risc-v musl regression
2 * go ahead and use allocSentinel now that the stage1 bug is fixed
2 * audit the base cache hash3 * 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 {...@@ -347,6 +347,7 @@ pub const InitOptions = struct {
347 rdynamic: bool = false,347 rdynamic: bool = false,
348 strip: bool = false,348 strip: bool = false,
349 single_threaded: bool = false,349 single_threaded: bool = false,
350 function_sections: bool = false,
350 is_native_os: bool,351 is_native_os: bool,
351 time_report: bool = false,352 time_report: bool = false,
352 stack_report: bool = false,353 stack_report: bool = false,
...@@ -355,7 +356,6 @@ pub const InitOptions = struct {...@@ -355,7 +356,6 @@ pub const InitOptions = struct {
355 version_script: ?[]const u8 = null,356 version_script: ?[]const u8 = null,
356 override_soname: ?[]const u8 = null,357 override_soname: ?[]const u8 = null,
357 linker_gc_sections: ?bool = null,358 linker_gc_sections: ?bool = null,
358 function_sections: ?bool = null,
359 linker_allow_shlib_undefined: ?bool = null,359 linker_allow_shlib_undefined: ?bool = null,
360 linker_bind_global_refs_locally: ?bool = null,360 linker_bind_global_refs_locally: ?bool = null,
361 each_lib_rpath: ?bool = null,361 each_lib_rpath: ?bool = null,
...@@ -538,7 +538,6 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {...@@ -538,7 +538,6 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
538 };538 };
539539
540 const single_threaded = options.single_threaded or target_util.isSingleThreaded(options.target);540 const single_threaded = options.single_threaded or target_util.isSingleThreaded(options.target);
541 const function_sections = options.function_sections orelse false;
542541
543 const llvm_cpu_features: ?[*:0]const u8 = if (build_options.have_llvm and use_llvm) blk: {542 const llvm_cpu_features: ?[*:0]const u8 = if (build_options.have_llvm and use_llvm) blk: {
544 var buf = std.ArrayList(u8).init(arena);543 var buf = std.ArrayList(u8).init(arena);
...@@ -589,7 +588,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {...@@ -589,7 +588,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
589 cache.hash.add(pic);588 cache.hash.add(pic);
590 cache.hash.add(stack_check);589 cache.hash.add(stack_check);
591 cache.hash.add(link_mode);590 cache.hash.add(link_mode);
592 cache.hash.add(function_sections);591 cache.hash.add(options.function_sections);
593 cache.hash.add(strip);592 cache.hash.add(strip);
594 cache.hash.add(link_libc);593 cache.hash.add(link_libc);
595 cache.hash.add(options.link_libcpp);594 cache.hash.add(options.link_libcpp);
...@@ -757,7 +756,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {...@@ -757,7 +756,7 @@ pub fn create(gpa: *Allocator, options: InitOptions) !*Compilation {
757 .rpath_list = options.rpath_list,756 .rpath_list = options.rpath_list,
758 .strip = strip,757 .strip = strip,
759 .is_native_os = options.is_native_os,758 .is_native_os = options.is_native_os,
760 .function_sections = options.function_sections orelse false,759 .function_sections = options.function_sections,
761 .allow_shlib_undefined = options.linker_allow_shlib_undefined,760 .allow_shlib_undefined = options.linker_allow_shlib_undefined,
762 .bind_global_refs_locally = options.linker_bind_global_refs_locally orelse false,761 .bind_global_refs_locally = options.linker_bind_global_refs_locally orelse false,
763 .z_nodelete = options.linker_z_nodelete,762 .z_nodelete = options.linker_z_nodelete,
src/main.zig+22-2
...@@ -260,11 +260,13 @@ const usage_build_generic =...@@ -260,11 +260,13 @@ const usage_build_generic =
260 \\ -D[macro]=[value] Define C [macro] to [value] (1 if [value] omitted)260 \\ -D[macro]=[value] Define C [macro] to [value] (1 if [value] omitted)
261 \\ --libc [file] Provide a file which specifies libc paths261 \\ --libc [file] Provide a file which specifies libc paths
262 \\ -cflags [flags] -- Set extra flags for the next positional C source files262 \\ -cflags [flags] -- Set extra flags for the next positional C source files
263 \\ -ffunction-sections Places each function in a separate section
263 \\264 \\
264 \\Link Options:265 \\Link Options:
265 \\ -l[lib], --library [lib] Link against system library266 \\ -l[lib], --library [lib] Link against system library
266 \\ -L[d], --library-directory [d] Add a directory to the library search path267 \\ -L[d], --library-directory [d] Add a directory to the library search path
267 \\ -T[script] Use a custom linker script268 \\ -T[script], --script [script] Use a custom linker script
269 \\ --version-script [path] Provide a version .map file
268 \\ --dynamic-linker [path] Set the dynamic interpreter path (usually ld.so)270 \\ --dynamic-linker [path] Set the dynamic interpreter path (usually ld.so)
269 \\ --each-lib-rpath Add rpath for each used dynamic library271 \\ --each-lib-rpath Add rpath for each used dynamic library
270 \\ --version [ver] Dynamic library semver272 \\ --version [ver] Dynamic library semver
...@@ -273,7 +275,11 @@ const usage_build_generic =...@@ -273,7 +275,11 @@ const usage_build_generic =
273 \\ --eh-frame-hdr Enable C++ exception handling by passing --eh-frame-hdr to linker275 \\ --eh-frame-hdr Enable C++ exception handling by passing --eh-frame-hdr to linker
274 \\ -dynamic Force output to be dynamically linked276 \\ -dynamic Force output to be dynamically linked
275 \\ -static Force output to be statically linked277 \\ -static Force output to be statically linked
278 \\ -Bsymbolic Bind global references locally
276 \\ --subsystem [subsystem] (windows) /SUBSYSTEM:<subsystem> to the linker\n"279 \\ --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
277 \\283 \\
278 \\Test Options:284 \\Test Options:
279 \\ --test-filter [text] Skip tests that do not match filter285 \\ --test-filter [text] Skip tests that do not match filter
...@@ -381,6 +387,7 @@ fn buildOutputType(...@@ -381,6 +387,7 @@ fn buildOutputType(
381 var have_version = false;387 var have_version = false;
382 var strip = false;388 var strip = false;
383 var single_threaded = false;389 var single_threaded = false;
390 var function_sections = false;
384 var watch = false;391 var watch = false;
385 var verbose_link = false;392 var verbose_link = false;
386 var verbose_cc = false;393 var verbose_cc = false;
...@@ -634,7 +641,15 @@ fn buildOutputType(...@@ -634,7 +641,15 @@ fn buildOutputType(
634 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});641 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});
635 i += 1;642 i += 1;
636 try lib_dirs.append(args[i]);643 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")) {
638 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});653 if (i + 1 >= args.len) fatal("expected parameter after {}", .{arg});
639 i += 1;654 i += 1;
640 linker_script = args[i];655 linker_script = args[i];
...@@ -819,6 +834,8 @@ fn buildOutputType(...@@ -819,6 +834,8 @@ fn buildOutputType(
819 strip = true;834 strip = true;
820 } else if (mem.eql(u8, arg, "--single-threaded")) {835 } else if (mem.eql(u8, arg, "--single-threaded")) {
821 single_threaded = true;836 single_threaded = true;
837 } else if (mem.eql(u8, arg, "-ffunction-sections")) {
838 function_sections = true;
822 } else if (mem.eql(u8, arg, "--eh-frame-hdr")) {839 } else if (mem.eql(u8, arg, "--eh-frame-hdr")) {
823 link_eh_frame_hdr = true;840 link_eh_frame_hdr = true;
824 } else if (mem.eql(u8, arg, "-Bsymbolic")) {841 } else if (mem.eql(u8, arg, "-Bsymbolic")) {
...@@ -843,6 +860,8 @@ fn buildOutputType(...@@ -843,6 +860,8 @@ fn buildOutputType(
843 linker_script = arg[2..];860 linker_script = arg[2..];
844 } else if (mem.startsWith(u8, arg, "-L")) {861 } else if (mem.startsWith(u8, arg, "-L")) {
845 try lib_dirs.append(arg[2..]);862 try lib_dirs.append(arg[2..]);
863 } else if (mem.startsWith(u8, arg, "-F")) {
864 try framework_dirs.append(arg[2..]);
846 } else if (mem.startsWith(u8, arg, "-l")) {865 } else if (mem.startsWith(u8, arg, "-l")) {
847 // We don't know whether this library is part of libc or libc++ until we resolve the target.866 // We don't know whether this library is part of libc or libc++ until we resolve the target.
848 // So we simply append to the list for now.867 // So we simply append to the list for now.
...@@ -1555,6 +1574,7 @@ fn buildOutputType(...@@ -1555,6 +1574,7 @@ fn buildOutputType(
1555 .stack_size_override = stack_size_override,1574 .stack_size_override = stack_size_override,
1556 .strip = strip,1575 .strip = strip,
1557 .single_threaded = single_threaded,1576 .single_threaded = single_threaded,
1577 .function_sections = function_sections,
1558 .self_exe_path = self_exe_path,1578 .self_exe_path = self_exe_path,
1559 .rand = &default_prng.random,1579 .rand = &default_prng.random,
1560 .clang_passthrough_mode = arg_mode != .build,1580 .clang_passthrough_mode = arg_mode != .build,