aboutsummaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
authorMotiejus Jakštys <motiejus@jakstys.lt>2022-06-14 14:41:47 +0300
committerAndrew Kelley <andrew@ziglang.org>2022-07-11 13:55:29 -0700
commit1f410b500c8dbe33191a54a4ae02a6fb0febec46 (patch)
tree7948dd086ed915e1dbd2d94a32e314ea6bb9af10 /src/main.zig
parentade9bd9287fcdd730a7562811d0e50a6899a6cf2 (diff)
downloadzig-1f410b500c8dbe33191a54a4ae02a6fb0febec46.tar.gz
zig-1f410b500c8dbe33191a54a4ae02a6fb0febec46.zip
ELF: understand -Wl,--compress-debug-sections
This argument is both a compiler and a linker flag. The linker flag was not understood; now it is. Go likes to use it as a linker flag. Tested with sqlite3. The size difference is significant, and I confirmed gdb understands both binaries. zlib: 3.66MB ------------ CC="zig cc" CFLAGS="-Wl,--compress-debug-sections=zlib -O2" ./configure --disable-tcl make FILE SIZE VM SIZE -------------- -------------- 39.1% 1.43Mi 88.4% 1.43Mi .text 19.6% 734Ki 0.0% 0 .debug_info 16.4% 613Ki 0.0% 0 .debug_loc 13.1% 492Ki 0.0% 0 .debug_line 4.2% 157Ki 9.5% 157Ki .rodata 2.3% 87.6Ki 0.0% 0 .debug_ranges 1.5% 56.2Ki 0.0% 0 .symtab 1.1% 40.2Ki 0.0% 0 .strtab 1.0% 38.2Ki 0.0% 0 .debug_str 0.7% 26.2Ki 0.0% 0 .debug_frame 0.4% 15.3Ki 0.9% 15.3Ki .data 0.1% 4.71Ki 0.3% 4.71Ki .dynsym 0.1% 3.65Ki 0.2% 3.26Ki [16 Others] 0.1% 2.55Ki 0.2% 2.55Ki .rela.plt 0.1% 2.12Ki 0.0% 0 [ELF Section Headers] 0.0% 0 0.1% 2.02Ki .bss 0.0% 1.84Ki 0.1% 1.84Ki .dynstr 0.0% 1.72Ki 0.1% 1.72Ki .plt 0.0% 1.58Ki 0.1% 1.58Ki .hash 0.0% 1.17Ki 0.0% 0 .debug_abbrev 0.0% 1.01Ki 0.1% 1.01Ki .rela.dyn 100.0% 3.66Mi 100.0% 1.62Mi TOTAL none: 8.56MB ------------ CC="zig cc" CFLAGS="-O2" ./configure --disable-tcl make FILE SIZE VM SIZE -------------- -------------- 41.1% 3.52Mi 0.0% 0 .debug_loc 18.5% 1.59Mi 0.0% 0 .debug_info 16.7% 1.43Mi 88.4% 1.43Mi .text 11.8% 1.01Mi 0.0% 0 .debug_line 5.9% 515Ki 0.0% 0 .debug_ranges 1.8% 157Ki 9.5% 157Ki .rodata 1.3% 118Ki 0.0% 0 .debug_frame 1.3% 110Ki 0.0% 0 .debug_str 0.6% 56.2Ki 0.0% 0 .symtab 0.5% 40.2Ki 0.0% 0 .strtab 0.2% 15.3Ki 0.9% 15.3Ki .data 0.1% 4.71Ki 0.3% 4.71Ki .dynsym 0.0% 3.64Ki 0.2% 3.26Ki [16 Others] 0.0% 2.98Ki 0.0% 0 .debug_abbrev 0.0% 2.55Ki 0.2% 2.55Ki .rela.plt 0.0% 2.12Ki 0.0% 0 [ELF Section Headers] 0.0% 0 0.1% 2.02Ki .bss 0.0% 1.84Ki 0.1% 1.84Ki .dynstr 0.0% 1.72Ki 0.1% 1.72Ki .plt 0.0% 1.58Ki 0.1% 1.58Ki .hash 0.0% 1.01Ki 0.1% 1.01Ki .rela.dyn 100.0% 8.56Mi 100.0% 1.62Mi TOTAL
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/main.zig b/src/main.zig
index 4fe048bb93..c23aa3111a 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -443,6 +443,8 @@ const usage_build_generic =
\\ -dynamic Force output to be dynamically linked
\\ -static Force output to be statically linked
\\ -Bsymbolic Bind global references locally
+ \\ --compress-debug-sections= Compress DWARF debug sections
+ \\ none|zlib
\\ --subsystem [subsystem] (Windows) /SUBSYSTEM:<subsystem> to the linker
\\ --stack [size] Override default stack size
\\ --image-base [addr] Set base address for executable image
@@ -657,6 +659,7 @@ fn buildOutputType(
var version_script: ?[]const u8 = null;
var disable_c_depfile = false;
var linker_gc_sections: ?bool = null;
+ var linker_compress_debug_sections: ?link.CompressDebugSections = null;
var linker_allow_shlib_undefined: ?bool = null;
var linker_bind_global_refs_locally: ?bool = null;
var linker_import_memory: ?bool = null;
@@ -938,6 +941,11 @@ fn buildOutputType(
install_name = args_iter.next() orelse {
fatal("expected parameter after {s}", .{arg});
};
+ } else if (mem.startsWith(u8, arg, "--compress-debug-sections=")) {
+ const param = arg["--compress-debug-sections=".len..];
+ linker_compress_debug_sections = std.meta.stringToEnum(link.CompressDebugSections, param) orelse {
+ fatal("expected --compress-debug-sections=[none|zlib], found '{s}'", .{param});
+ };
} else if (mem.eql(u8, arg, "-pagezero_size")) {
const next_arg = args_iter.next() orelse {
fatal("expected parameter after {s}", .{arg});
@@ -1776,6 +1784,15 @@ fn buildOutputType(
linker_global_base = parseIntSuffix(arg, "--global-base=".len);
} else if (mem.startsWith(u8, arg, "--export=")) {
try linker_export_symbol_names.append(arg["--export=".len..]);
+ } else if (mem.eql(u8, arg, "--compress-debug-sections")) {
+ i += 1;
+ if (i >= linker_args.items.len) {
+ fatal("expected linker arg after '{s}'", .{arg});
+ }
+ const arg1 = linker_args.items[i];
+ linker_compress_debug_sections = std.meta.stringToEnum(link.CompressDebugSections, arg1) orelse {
+ fatal("expected [none|zlib] after --compress-debug-sections, found '{s}'", .{arg1});
+ };
} else if (mem.eql(u8, arg, "-z")) {
i += 1;
if (i >= linker_args.items.len) {
@@ -2849,6 +2866,7 @@ fn buildOutputType(
.linker_nxcompat = linker_nxcompat,
.linker_dynamicbase = linker_dynamicbase,
.linker_optimization = linker_optimization,
+ .linker_compress_debug_sections = linker_compress_debug_sections,
.major_subsystem_version = major_subsystem_version,
.minor_subsystem_version = minor_subsystem_version,
.link_eh_frame_hdr = link_eh_frame_hdr,