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.
This commit is contained in:
Andrew Kelley 2022-07-11 14:18:56 -07:00
parent 1f410b500c
commit 2b99182e25
6 changed files with 48 additions and 27 deletions

View File

@ -1688,7 +1688,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation {
.no_builtin = options.no_builtin, .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,
.compress_debug_sections = options.linker_compress_debug_sections, .compress_debug_sections = options.linker_compress_debug_sections orelse .none,
.import_memory = options.linker_import_memory orelse false, .import_memory = options.linker_import_memory orelse false,
.import_table = options.linker_import_table, .import_table = options.linker_import_table,
.export_table = options.linker_export_table, .export_table = options.linker_export_table,
@ -2461,7 +2461,7 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes
man.hash.add(comp.bin_file.options.z_now); man.hash.add(comp.bin_file.options.z_now);
man.hash.add(comp.bin_file.options.z_relro); man.hash.add(comp.bin_file.options.z_relro);
man.hash.add(comp.bin_file.options.hash_style); man.hash.add(comp.bin_file.options.hash_style);
man.hash.addOptional(comp.bin_file.options.compress_debug_sections); man.hash.add(comp.bin_file.options.compress_debug_sections);
man.hash.add(comp.bin_file.options.include_compiler_rt); man.hash.add(comp.bin_file.options.include_compiler_rt);
if (comp.bin_file.options.link_libc) { if (comp.bin_file.options.link_libc) {
man.hash.add(comp.bin_file.options.libc_installation != null); man.hash.add(comp.bin_file.options.libc_installation != null);

View File

@ -2308,7 +2308,7 @@ flagpd1("compiler-options-dump"),
.{ .{
.name = "compress-debug-sections", .name = "compress-debug-sections",
.syntax = .flag, .syntax = .flag,
.zig_equivalent = .other, .zig_equivalent = .compress_debug_sections,
.pd1 = true, .pd1 = true,
.pd2 = true, .pd2 = true,
.psl = false, .psl = false,
@ -3834,7 +3834,7 @@ m("mavx512cd"),
m("mavx512dq"), m("mavx512dq"),
m("mavx512er"), m("mavx512er"),
m("mavx512f"), m("mavx512f"),
flagpd1("mavx512fp16"), m("mavx512fp16"),
m("mavx512ifma"), m("mavx512ifma"),
m("mavx512pf"), m("mavx512pf"),
m("mavx512vbmi"), m("mavx512vbmi"),
@ -3867,7 +3867,7 @@ flagpd1("mconstructor-aliases"),
flagpd1("mcpu=?"), flagpd1("mcpu=?"),
m("mcrbits"), m("mcrbits"),
m("mcrc"), m("mcrc"),
flagpd1("mcrc32"), m("mcrc32"),
m("mcumode"), m("mcumode"),
m("mcx16"), m("mcx16"),
sepd1("mdebug-pass"), sepd1("mdebug-pass"),
@ -3892,8 +3892,8 @@ flagpd1("mfancy-math-387"),
flagpd1("mfentry"), flagpd1("mfentry"),
flagpd1("mfix4300"), flagpd1("mfix4300"),
flagpd1("mfix-and-continue"), flagpd1("mfix-and-continue"),
flagpd1("mfix-cmse-cve-2021-35465"), m("mfix-cmse-cve-2021-35465"),
flagpd1("mfix-cortex-a53-835769"), m("mfix-cortex-a53-835769"),
m("mfloat128"), m("mfloat128"),
sepd1("mfloat-abi"), sepd1("mfloat-abi"),
m("mfma"), m("mfma"),
@ -3913,8 +3913,8 @@ flagpd1("mglobal-merge"),
flagpd1("mgpopt"), flagpd1("mgpopt"),
m("mhard-float"), m("mhard-float"),
m("mhvx"), m("mhvx"),
flagpd1("mhvx-ieee-fp"), m("mhvx-ieee-fp"),
flagpd1("mhvx-qfloat"), m("mhvx-qfloat"),
m("mhreset"), m("mhreset"),
m("mhtm"), m("mhtm"),
flagpd1("miamcu"), flagpd1("miamcu"),
@ -4005,7 +4005,7 @@ m("mno-avx512cd"),
m("mno-avx512dq"), m("mno-avx512dq"),
m("mno-avx512er"), m("mno-avx512er"),
m("mno-avx512f"), m("mno-avx512f"),
flagpd1("mno-avx512fp16"), m("mno-avx512fp16"),
m("mno-avx512ifma"), m("mno-avx512ifma"),
m("mno-avx512pf"), m("mno-avx512pf"),
m("mno-avx512vbmi"), m("mno-avx512vbmi"),
@ -4019,7 +4019,7 @@ flagpd1("mno-backchain"),
m("mno-bmi"), m("mno-bmi"),
m("mno-bmi2"), m("mno-bmi2"),
flagpd1("mno-branch-likely"), flagpd1("mno-branch-likely"),
flagpd1("mno-bti-at-return-twice"), m("mno-bti-at-return-twice"),
m("mno-bulk-memory"), m("mno-bulk-memory"),
flagpd1("mno-check-zero-division"), flagpd1("mno-check-zero-division"),
m("mno-cldemote"), m("mno-cldemote"),
@ -4032,7 +4032,7 @@ flagpd1("mno-constant-cfstrings"),
flagpd1("mno-constructor-aliases"), flagpd1("mno-constructor-aliases"),
m("mno-crbits"), m("mno-crbits"),
m("mno-crc"), m("mno-crc"),
flagpd1("mno-crc32"), m("mno-crc32"),
m("mno-cumode"), m("mno-cumode"),
m("mno-cx16"), m("mno-cx16"),
m("mno-dsp"), m("mno-dsp"),
@ -4044,8 +4044,8 @@ flagpd1("mnoexecstack"),
m("mno-execute-only"), m("mno-execute-only"),
flagpd1("mno-extern-sdata"), flagpd1("mno-extern-sdata"),
m("mno-f16c"), m("mno-f16c"),
flagpd1("mno-fix-cmse-cve-2021-35465"), m("mno-fix-cmse-cve-2021-35465"),
flagpd1("mno-fix-cortex-a53-835769"), m("mno-fix-cortex-a53-835769"),
m("mno-float128"), m("mno-float128"),
m("mno-fma"), m("mno-fma"),
m("mno-fma4"), m("mno-fma4"),
@ -4058,8 +4058,8 @@ m("mno-ginv"),
flagpd1("mno-global-merge"), flagpd1("mno-global-merge"),
flagpd1("mno-gpopt"), flagpd1("mno-gpopt"),
m("mno-hvx"), m("mno-hvx"),
flagpd1("mno-hvx-ieee-fp"), m("mno-hvx-ieee-fp"),
flagpd1("mno-hvx-qfloat"), m("mno-hvx-qfloat"),
m("mno-hreset"), m("mno-hreset"),
m("mno-htm"), m("mno-htm"),
flagpd1("mno-iamcu"), flagpd1("mno-iamcu"),
@ -4137,7 +4137,7 @@ m("mno-reference-types"),
m("mno-relax"), m("mno-relax"),
flagpd1("mno-relax-all"), flagpd1("mno-relax-all"),
flagpd1("mno-relax-pic-calls"), flagpd1("mno-relax-pic-calls"),
flagpd1("mno-relaxed-simd"), m("mno-relaxed-simd"),
flagpd1("mno-restrict-it"), flagpd1("mno-restrict-it"),
m("mno-retpoline"), m("mno-retpoline"),
m("mno-retpoline-external-thunk"), m("mno-retpoline-external-thunk"),
@ -4259,7 +4259,7 @@ flagpd1("mrelax-pic-calls"),
.pd2 = true, .pd2 = true,
.psl = false, .psl = false,
}, },
flagpd1("mrelaxed-simd"), m("mrelaxed-simd"),
sepd1("mrelocation-model"), sepd1("mrelocation-model"),
flagpd1("mrestrict-it"), flagpd1("mrestrict-it"),
m("mretpoline"), m("mretpoline"),
@ -4323,7 +4323,7 @@ m("mv66"),
m("mv67"), m("mv67"),
flagpd1("mv67t"), flagpd1("mv67t"),
m("mv68"), m("mv68"),
flagpd1("mv69"), m("mv69"),
m("mvaes"), m("mvaes"),
m("mvirt"), m("mvirt"),
m("mvpclmulqdq"), m("mvpclmulqdq"),
@ -5087,7 +5087,7 @@ joinpd1("msign-return-address-key="),
.{ .{
.name = "compress-debug-sections=", .name = "compress-debug-sections=",
.syntax = .joined, .syntax = .joined,
.zig_equivalent = .other, .zig_equivalent = .compress_debug_sections,
.pd1 = true, .pd1 = true,
.pd2 = true, .pd2 = true,
.psl = false, .psl = false,

View File

@ -123,7 +123,7 @@ pub const Options = struct {
nxcompat: bool, nxcompat: bool,
dynamicbase: bool, dynamicbase: bool,
linker_optimization: u8, linker_optimization: u8,
compress_debug_sections: ?CompressDebugSections, compress_debug_sections: CompressDebugSections,
bind_global_refs_locally: bool, bind_global_refs_locally: bool,
import_memory: bool, import_memory: bool,
import_table: bool, import_table: bool,

View File

@ -1351,7 +1351,7 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
link.hashAddSystemLibs(&man.hash, self.base.options.system_libs); link.hashAddSystemLibs(&man.hash, self.base.options.system_libs);
man.hash.add(allow_shlib_undefined); man.hash.add(allow_shlib_undefined);
man.hash.add(self.base.options.bind_global_refs_locally); man.hash.add(self.base.options.bind_global_refs_locally);
man.hash.addOptional(self.base.options.compress_debug_sections); man.hash.add(self.base.options.compress_debug_sections);
man.hash.add(self.base.options.tsan); man.hash.add(self.base.options.tsan);
man.hash.addOptionalBytes(self.base.options.sysroot); man.hash.addOptionalBytes(self.base.options.sysroot);
man.hash.add(self.base.options.linker_optimization); man.hash.add(self.base.options.linker_optimization);
@ -1755,9 +1755,9 @@ fn linkWithLLD(self: *Elf, comp: *Compilation, prog_node: *std.Progress.Node) !v
try argv.append("--allow-shlib-undefined"); try argv.append("--allow-shlib-undefined");
} }
if (self.base.options.compress_debug_sections) |how| { switch (self.base.options.compress_debug_sections) {
const arg = try std.fmt.allocPrint(arena, "--compress-debug-sections={s}", .{@tagName(how)}); .none => {},
try argv.append(arg); .zlib => try argv.append("--compress-debug-sections=zlib"),
} }
if (self.base.options.bind_global_refs_locally) { if (self.base.options.bind_global_refs_locally) {

View File

@ -443,8 +443,9 @@ const usage_build_generic =
\\ -dynamic Force output to be dynamically linked \\ -dynamic Force output to be dynamically linked
\\ -static Force output to be statically linked \\ -static Force output to be statically linked
\\ -Bsymbolic Bind global references locally \\ -Bsymbolic Bind global references locally
\\ --compress-debug-sections= Compress DWARF debug sections \\ --compress-debug-sections=[e] Debug section compression settings
\\ none|zlib \\ none No compression
\\ zlib Compression with deflate/inflate
\\ --subsystem [subsystem] (Windows) /SUBSYSTEM:<subsystem> to the linker \\ --subsystem [subsystem] (Windows) /SUBSYSTEM:<subsystem> to the linker
\\ --stack [size] Override default stack size \\ --stack [size] Override default stack size
\\ --image-base [addr] Set base address for executable image \\ --image-base [addr] Set base address for executable image
@ -946,6 +947,8 @@ fn buildOutputType(
linker_compress_debug_sections = std.meta.stringToEnum(link.CompressDebugSections, param) orelse { linker_compress_debug_sections = std.meta.stringToEnum(link.CompressDebugSections, param) orelse {
fatal("expected --compress-debug-sections=[none|zlib], found '{s}'", .{param}); fatal("expected --compress-debug-sections=[none|zlib], found '{s}'", .{param});
}; };
} else if (mem.eql(u8, arg, "--compress-debug-sections")) {
linker_compress_debug_sections = link.CompressDebugSections.zlib;
} else if (mem.eql(u8, arg, "-pagezero_size")) { } else if (mem.eql(u8, arg, "-pagezero_size")) {
const next_arg = args_iter.next() orelse { const next_arg = args_iter.next() orelse {
fatal("expected parameter after {s}", .{arg}); fatal("expected parameter after {s}", .{arg});
@ -1648,6 +1651,15 @@ fn buildOutputType(
.weak_library => try system_libs.put(it.only_arg, .{ .weak = true }), .weak_library => try system_libs.put(it.only_arg, .{ .weak = true }),
.weak_framework => try frameworks.put(gpa, it.only_arg, .{ .weak = true }), .weak_framework => try frameworks.put(gpa, it.only_arg, .{ .weak = true }),
.headerpad_max_install_names => headerpad_max_install_names = true, .headerpad_max_install_names => headerpad_max_install_names = true,
.compress_debug_sections => {
if (it.only_arg.len == 0) {
linker_compress_debug_sections = .zlib;
} else {
linker_compress_debug_sections = std.meta.stringToEnum(link.CompressDebugSections, it.only_arg) orelse {
fatal("expected [none|zlib] after --compress-debug-sections, found '{s}'", .{it.only_arg});
};
}
},
} }
} }
// Parse linker args. // Parse linker args.
@ -4617,6 +4629,7 @@ pub const ClangArgIterator = struct {
weak_library, weak_library,
weak_framework, weak_framework,
headerpad_max_install_names, headerpad_max_install_names,
compress_debug_sections,
}; };
const Args = struct { const Args = struct {

View File

@ -460,6 +460,14 @@ const known_options = [_]KnownOpt{
.name = "headerpad_max_install_names", .name = "headerpad_max_install_names",
.ident = "headerpad_max_install_names", .ident = "headerpad_max_install_names",
}, },
.{
.name = "compress-debug-sections",
.ident = "compress_debug_sections",
},
.{
.name = "compress-debug-sections=",
.ident = "compress_debug_sections",
},
}; };
const blacklisted_options = [_][]const u8{}; const blacklisted_options = [_][]const u8{};