authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-11 14:18:56-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2022-07-11 14:18:56-07:00
log2b99182e25e045109b090a794bb06295b09a0eeb
tree4cbb93210359b2b1f7e8359752807c8eb4dcf353
parent1f410b500c8dbe33191a54a4ae02a6fb0febec46

stage2: cleanups to --compress-debug-sections

* make the setting in the linker backend be non-optional; by this time all defaults are supposed to be resolved. * integrate with `zig cc` * change the CLI parsing to match C compiler parsing, allowing `--compress-debug-sections` alone to choose a default encoding of zlib.

6 files changed, 48 insertions(+), 27 deletions(-)

src/Compilation.zig+2-2
...@@ -1688,7 +1688,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {...@@ -1688,7 +1688,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
1688 .no_builtin = options.no_builtin,1688 .no_builtin = options.no_builtin,
1689 .allow_shlib_undefined = options.linker_allow_shlib_undefined,1689 .allow_shlib_undefined = options.linker_allow_shlib_undefined,
1690 .bind_global_refs_locally = options.linker_bind_global_refs_locally orelse false,1690 .bind_global_refs_locally = options.linker_bind_global_refs_locally orelse false,
1691 .compress_debug_sections = options.linker_compress_debug_sections,1691 .compress_debug_sections = options.linker_compress_debug_sections orelse .none,
1692 .import_memory = options.linker_import_memory orelse false,1692 .import_memory = options.linker_import_memory orelse false,
1693 .import_table = options.linker_import_table,1693 .import_table = options.linker_import_table,
1694 .export_table = options.linker_export_table,1694 .export_table = options.linker_export_table,
...@@ -2461,7 +2461,7 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes...@@ -2461,7 +2461,7 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes
2461 man.hash.add(comp.bin_file.options.z_now);2461 man.hash.add(comp.bin_file.options.z_now);
2462 man.hash.add(comp.bin_file.options.z_relro);2462 man.hash.add(comp.bin_file.options.z_relro);
2463 man.hash.add(comp.bin_file.options.hash_style);2463 man.hash.add(comp.bin_file.options.hash_style);
2464 man.hash.addOptional(comp.bin_file.options.compress_debug_sections);2464 man.hash.add(comp.bin_file.options.compress_debug_sections);
2465 man.hash.add(comp.bin_file.options.include_compiler_rt);2465 man.hash.add(comp.bin_file.options.include_compiler_rt);
2466 if (comp.bin_file.options.link_libc) {2466 if (comp.bin_file.options.link_libc) {
2467 man.hash.add(comp.bin_file.options.libc_installation != null);2467 man.hash.add(comp.bin_file.options.libc_installation != null);
src/clang_options_data.zig+18-18
...@@ -2308,7 +2308,7 @@ flagpd1("compiler-options-dump"),...@@ -2308,7 +2308,7 @@ flagpd1("compiler-options-dump"),
2308.{2308.{
2309 .name = "compress-debug-sections",2309 .name = "compress-debug-sections",
2310 .syntax = .flag,2310 .syntax = .flag,
2311 .zig_equivalent = .other,2311 .zig_equivalent = .compress_debug_sections,
2312 .pd1 = true,2312 .pd1 = true,
2313 .pd2 = true,2313 .pd2 = true,
2314 .psl = false,2314 .psl = false,
...@@ -3834,7 +3834,7 @@ m("mavx512cd"),...@@ -3834,7 +3834,7 @@ m("mavx512cd"),
3834m("mavx512dq"),3834m("mavx512dq"),
3835m("mavx512er"),3835m("mavx512er"),
3836m("mavx512f"),3836m("mavx512f"),
3837flagpd1("mavx512fp16"),3837m("mavx512fp16"),
3838m("mavx512ifma"),3838m("mavx512ifma"),
3839m("mavx512pf"),3839m("mavx512pf"),
3840m("mavx512vbmi"),3840m("mavx512vbmi"),
...@@ -3867,7 +3867,7 @@ flagpd1("mconstructor-aliases"),...@@ -3867,7 +3867,7 @@ flagpd1("mconstructor-aliases"),
3867flagpd1("mcpu=?"),3867flagpd1("mcpu=?"),
3868m("mcrbits"),3868m("mcrbits"),
3869m("mcrc"),3869m("mcrc"),
3870flagpd1("mcrc32"),3870m("mcrc32"),
3871m("mcumode"),3871m("mcumode"),
3872m("mcx16"),3872m("mcx16"),
3873sepd1("mdebug-pass"),3873sepd1("mdebug-pass"),
...@@ -3892,8 +3892,8 @@ flagpd1("mfancy-math-387"),...@@ -3892,8 +3892,8 @@ flagpd1("mfancy-math-387"),
3892flagpd1("mfentry"),3892flagpd1("mfentry"),
3893flagpd1("mfix4300"),3893flagpd1("mfix4300"),
3894flagpd1("mfix-and-continue"),3894flagpd1("mfix-and-continue"),
3895flagpd1("mfix-cmse-cve-2021-35465"),3895m("mfix-cmse-cve-2021-35465"),
3896flagpd1("mfix-cortex-a53-835769"),3896m("mfix-cortex-a53-835769"),
3897m("mfloat128"),3897m("mfloat128"),
3898sepd1("mfloat-abi"),3898sepd1("mfloat-abi"),
3899m("mfma"),3899m("mfma"),
...@@ -3913,8 +3913,8 @@ flagpd1("mglobal-merge"),...@@ -3913,8 +3913,8 @@ flagpd1("mglobal-merge"),
3913flagpd1("mgpopt"),3913flagpd1("mgpopt"),
3914m("mhard-float"),3914m("mhard-float"),
3915m("mhvx"),3915m("mhvx"),
3916flagpd1("mhvx-ieee-fp"),3916m("mhvx-ieee-fp"),
3917flagpd1("mhvx-qfloat"),3917m("mhvx-qfloat"),
3918m("mhreset"),3918m("mhreset"),
3919m("mhtm"),3919m("mhtm"),
3920flagpd1("miamcu"),3920flagpd1("miamcu"),
...@@ -4005,7 +4005,7 @@ m("mno-avx512cd"),...@@ -4005,7 +4005,7 @@ m("mno-avx512cd"),
4005m("mno-avx512dq"),4005m("mno-avx512dq"),
4006m("mno-avx512er"),4006m("mno-avx512er"),
4007m("mno-avx512f"),4007m("mno-avx512f"),
4008flagpd1("mno-avx512fp16"),4008m("mno-avx512fp16"),
4009m("mno-avx512ifma"),4009m("mno-avx512ifma"),
4010m("mno-avx512pf"),4010m("mno-avx512pf"),
4011m("mno-avx512vbmi"),4011m("mno-avx512vbmi"),
...@@ -4019,7 +4019,7 @@ flagpd1("mno-backchain"),...@@ -4019,7 +4019,7 @@ flagpd1("mno-backchain"),
4019m("mno-bmi"),4019m("mno-bmi"),
4020m("mno-bmi2"),4020m("mno-bmi2"),
4021flagpd1("mno-branch-likely"),4021flagpd1("mno-branch-likely"),
4022flagpd1("mno-bti-at-return-twice"),4022m("mno-bti-at-return-twice"),
4023m("mno-bulk-memory"),4023m("mno-bulk-memory"),
4024flagpd1("mno-check-zero-division"),4024flagpd1("mno-check-zero-division"),
4025m("mno-cldemote"),4025m("mno-cldemote"),
...@@ -4032,7 +4032,7 @@ flagpd1("mno-constant-cfstrings"),...@@ -4032,7 +4032,7 @@ flagpd1("mno-constant-cfstrings"),
4032flagpd1("mno-constructor-aliases"),4032flagpd1("mno-constructor-aliases"),
4033m("mno-crbits"),4033m("mno-crbits"),
4034m("mno-crc"),4034m("mno-crc"),
4035flagpd1("mno-crc32"),4035m("mno-crc32"),
4036m("mno-cumode"),4036m("mno-cumode"),
4037m("mno-cx16"),4037m("mno-cx16"),
4038m("mno-dsp"),4038m("mno-dsp"),
...@@ -4044,8 +4044,8 @@ flagpd1("mnoexecstack"),...@@ -4044,8 +4044,8 @@ flagpd1("mnoexecstack"),
4044m("mno-execute-only"),4044m("mno-execute-only"),
4045flagpd1("mno-extern-sdata"),4045flagpd1("mno-extern-sdata"),
4046m("mno-f16c"),4046m("mno-f16c"),
4047flagpd1("mno-fix-cmse-cve-2021-35465"),4047m("mno-fix-cmse-cve-2021-35465"),
4048flagpd1("mno-fix-cortex-a53-835769"),4048m("mno-fix-cortex-a53-835769"),
4049m("mno-float128"),4049m("mno-float128"),
4050m("mno-fma"),4050m("mno-fma"),
4051m("mno-fma4"),4051m("mno-fma4"),
...@@ -4058,8 +4058,8 @@ m("mno-ginv"),...@@ -4058,8 +4058,8 @@ m("mno-ginv"),
4058flagpd1("mno-global-merge"),4058flagpd1("mno-global-merge"),
4059flagpd1("mno-gpopt"),4059flagpd1("mno-gpopt"),
4060m("mno-hvx"),4060m("mno-hvx"),
4061flagpd1("mno-hvx-ieee-fp"),4061m("mno-hvx-ieee-fp"),
4062flagpd1("mno-hvx-qfloat"),4062m("mno-hvx-qfloat"),
4063m("mno-hreset"),4063m("mno-hreset"),
4064m("mno-htm"),4064m("mno-htm"),
4065flagpd1("mno-iamcu"),4065flagpd1("mno-iamcu"),
...@@ -4137,7 +4137,7 @@ m("mno-reference-types"),...@@ -4137,7 +4137,7 @@ m("mno-reference-types"),
4137m("mno-relax"),4137m("mno-relax"),
4138flagpd1("mno-relax-all"),4138flagpd1("mno-relax-all"),
4139flagpd1("mno-relax-pic-calls"),4139flagpd1("mno-relax-pic-calls"),
4140flagpd1("mno-relaxed-simd"),4140m("mno-relaxed-simd"),
4141flagpd1("mno-restrict-it"),4141flagpd1("mno-restrict-it"),
4142m("mno-retpoline"),4142m("mno-retpoline"),
4143m("mno-retpoline-external-thunk"),4143m("mno-retpoline-external-thunk"),
...@@ -4259,7 +4259,7 @@ flagpd1("mrelax-pic-calls"),...@@ -4259,7 +4259,7 @@ flagpd1("mrelax-pic-calls"),
4259 .pd2 = true,4259 .pd2 = true,
4260 .psl = false,4260 .psl = false,
4261},4261},
4262flagpd1("mrelaxed-simd"),4262m("mrelaxed-simd"),
4263sepd1("mrelocation-model"),4263sepd1("mrelocation-model"),
4264flagpd1("mrestrict-it"),4264flagpd1("mrestrict-it"),
4265m("mretpoline"),4265m("mretpoline"),
...@@ -4323,7 +4323,7 @@ m("mv66"),...@@ -4323,7 +4323,7 @@ m("mv66"),
4323m("mv67"),4323m("mv67"),
4324flagpd1("mv67t"),4324flagpd1("mv67t"),
4325m("mv68"),4325m("mv68"),
4326flagpd1("mv69"),4326m("mv69"),
4327m("mvaes"),4327m("mvaes"),
4328m("mvirt"),4328m("mvirt"),
4329m("mvpclmulqdq"),4329m("mvpclmulqdq"),
...@@ -5087,7 +5087,7 @@ joinpd1("msign-return-address-key="),...@@ -5087,7 +5087,7 @@ joinpd1("msign-return-address-key="),
5087.{5087.{
5088 .name = "compress-debug-sections=",5088 .name = "compress-debug-sections=",
5089 .syntax = .joined,5089 .syntax = .joined,
5090 .zig_equivalent = .other,5090 .zig_equivalent = .compress_debug_sections,
5091 .pd1 = true,5091 .pd1 = true,
5092 .pd2 = true,5092 .pd2 = true,
5093 .psl = false,5093 .psl = false,
src/link.zig+1-1
...@@ -123,7 +123,7 @@ pub const Options = struct {...@@ -123,7 +123,7 @@ pub const Options = struct {
123 nxcompat: bool,123 nxcompat: bool,
124 dynamicbase: bool,124 dynamicbase: bool,
125 linker_optimization: u8,125 linker_optimization: u8,
126 compress_debug_sections: ?CompressDebugSections,126 compress_debug_sections: CompressDebugSections,
127 bind_global_refs_locally: bool,127 bind_global_refs_locally: bool,
128 import_memory: bool,128 import_memory: bool,
129 import_table: bool,129 import_table: bool,
src/link/Elf.zig+4-4
...@@ -1351,7 +1351,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v...@@ -1351,7 +1351,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
1351 link.hashAddSystemLibs(&man.hash, self.base.options.system_libs);1351 link.hashAddSystemLibs(&man.hash, self.base.options.system_libs);
1352 man.hash.add(allow_shlib_undefined);1352 man.hash.add(allow_shlib_undefined);
1353 man.hash.add(self.base.options.bind_global_refs_locally);1353 man.hash.add(self.base.options.bind_global_refs_locally);
1354 man.hash.addOptional(self.base.options.compress_debug_sections);1354 man.hash.add(self.base.options.compress_debug_sections);
1355 man.hash.add(self.base.options.tsan);1355 man.hash.add(self.base.options.tsan);
1356 man.hash.addOptionalBytes(self.base.options.sysroot);1356 man.hash.addOptionalBytes(self.base.options.sysroot);
1357 man.hash.add(self.base.options.linker_optimization);1357 man.hash.add(self.base.options.linker_optimization);
...@@ -1755,9 +1755,9 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v...@@ -1755,9 +1755,9 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
1755 try argv.append("--allow-shlib-undefined");1755 try argv.append("--allow-shlib-undefined");
1756 }1756 }
17571757
1758 if (self.base.options.compress_debug_sections) |how| {1758 switch (self.base.options.compress_debug_sections) {
1759 const arg = try std.fmt.allocPrint(arena, "--compress-debug-sections={s}", .{@tagName(how)});1759 .none => {},
1760 try argv.append(arg);1760 .zlib => try argv.append("--compress-debug-sections=zlib"),
1761 }1761 }
17621762
1763 if (self.base.options.bind_global_refs_locally) {1763 if (self.base.options.bind_global_refs_locally) {
src/main.zig+15-2
...@@ -443,8 +443,9 @@ const usage_build_generic =...@@ -443,8 +443,9 @@ const usage_build_generic =
443 \\ -dynamic Force output to be dynamically linked443 \\ -dynamic Force output to be dynamically linked
444 \\ -static Force output to be statically linked444 \\ -static Force output to be statically linked
445 \\ -Bsymbolic Bind global references locally445 \\ -Bsymbolic Bind global references locally
446 \\ --compress-debug-sections= Compress DWARF debug sections446 \\ --compress-debug-sections=[e] Debug section compression settings
447 \\ none|zlib447 \\ none No compression
448 \\ zlib Compression with deflate/inflate
448 \\ --subsystem [subsystem] (Windows) /SUBSYSTEM:<subsystem> to the linker449 \\ --subsystem [subsystem] (Windows) /SUBSYSTEM:<subsystem> to the linker
449 \\ --stack [size] Override default stack size450 \\ --stack [size] Override default stack size
450 \\ --image-base [addr] Set base address for executable image451 \\ --image-base [addr] Set base address for executable image
...@@ -946,6 +947,8 @@ fn buildOutputType(...@@ -946,6 +947,8 @@ fn buildOutputType(
946 linker_compress_debug_sections = std.meta.stringToEnum(link.CompressDebugSections, param) orelse {947 linker_compress_debug_sections = std.meta.stringToEnum(link.CompressDebugSections, param) orelse {
947 fatal("expected --compress-debug-sections=[none|zlib], found '{s}'", .{param});948 fatal("expected --compress-debug-sections=[none|zlib], found '{s}'", .{param});
948 };949 };
950 } else if (mem.eql(u8, arg, "--compress-debug-sections")) {
951 linker_compress_debug_sections = link.CompressDebugSections.zlib;
949 } else if (mem.eql(u8, arg, "-pagezero_size")) {952 } else if (mem.eql(u8, arg, "-pagezero_size")) {
950 const next_arg = args_iter.next() orelse {953 const next_arg = args_iter.next() orelse {
951 fatal("expected parameter after {s}", .{arg});954 fatal("expected parameter after {s}", .{arg});
...@@ -1648,6 +1651,15 @@ fn buildOutputType(...@@ -1648,6 +1651,15 @@ fn buildOutputType(
1648 .weak_library => try system_libs.put(it.only_arg, .{ .weak = true }),1651 .weak_library => try system_libs.put(it.only_arg, .{ .weak = true }),
1649 .weak_framework => try frameworks.put(gpa, it.only_arg, .{ .weak = true }),1652 .weak_framework => try frameworks.put(gpa, it.only_arg, .{ .weak = true }),
1650 .headerpad_max_install_names => headerpad_max_install_names = true,1653 .headerpad_max_install_names => headerpad_max_install_names = true,
1654 .compress_debug_sections => {
1655 if (it.only_arg.len == 0) {
1656 linker_compress_debug_sections = .zlib;
1657 } else {
1658 linker_compress_debug_sections = std.meta.stringToEnum(link.CompressDebugSections, it.only_arg) orelse {
1659 fatal("expected [none|zlib] after --compress-debug-sections, found '{s}'", .{it.only_arg});
1660 };
1661 }
1662 },
1651 }1663 }
1652 }1664 }
1653 // Parse linker args.1665 // Parse linker args.
...@@ -4617,6 +4629,7 @@ pub const ClangArgIterator = struct {...@@ -4617,6 +4629,7 @@ pub const ClangArgIterator = struct {
4617 weak_library,4629 weak_library,
4618 weak_framework,4630 weak_framework,
4619 headerpad_max_install_names,4631 headerpad_max_install_names,
4632 compress_debug_sections,
4620 };4633 };
46214634
4622 const Args = struct {4635 const Args = struct {
tools/update_clang_options.zig+8
...@@ -460,6 +460,14 @@ const known_options = [_]KnownOpt{...@@ -460,6 +460,14 @@ const known_options = [_]KnownOpt{
460 .name = "headerpad_max_install_names",460 .name = "headerpad_max_install_names",
461 .ident = "headerpad_max_install_names",461 .ident = "headerpad_max_install_names",
462 },462 },
463 .{
464 .name = "compress-debug-sections",
465 .ident = "compress_debug_sections",
466 },
467 .{
468 .name = "compress-debug-sections=",
469 .ident = "compress_debug_sections",
470 },
463};471};
464472
465const blacklisted_options = [_][]const u8{};473const blacklisted_options = [_][]const u8{};