aboutsummaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig54
1 files changed, 48 insertions, 6 deletions
diff --git a/src/main.zig b/src/main.zig
index f634c259ff..a0cdfb36b6 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -20,7 +20,7 @@ const LibCInstallation = @import("libc_installation.zig").LibCInstallation;
const wasi_libc = @import("wasi_libc.zig");
const translate_c = @import("translate_c.zig");
const clang = @import("clang.zig");
-const Cache = @import("Cache.zig");
+const Cache = std.Build.Cache;
const target_util = @import("target.zig");
const ThreadPool = @import("ThreadPool.zig");
const crash_report = @import("crash_report.zig");
@@ -432,6 +432,8 @@ const usage_build_generic =
\\ -fno-Clang Prevent using Clang as the C/C++ compilation backend
\\ -freference-trace[=num] How many lines of reference trace should be shown per compile error
\\ -fno-reference-trace Disable reference trace
+ \\ -ferror-tracing Enable error tracing in ReleaseFast mode
+ \\ -fno-error-tracing Disable error tracing in Debug and ReleaseSafe mode
\\ -fsingle-threaded Code assumes there is only one thread
\\ -fno-single-threaded Code may not assume there is only one thread
\\ -fbuiltin Enable implicit builtin knowledge of functions
@@ -490,6 +492,7 @@ const usage_build_generic =
\\ nodelete Indicate that the object cannot be deleted from a process
\\ notext Permit read-only relocations in read-only segments
\\ defs Force a fatal error if any undefined symbols remain
+ \\ undefs Reverse of -z defs
\\ origin Indicate that the object must have its origin processed
\\ nocopyreloc Disable the creation of copy relocations
\\ now (default) Force all relocations to be processed on load
@@ -506,6 +509,7 @@ const usage_build_generic =
\\ zlib Compression with deflate/inflate
\\ --gc-sections Force removal of functions and data that are unreachable by the entry point or exported symbols
\\ --no-gc-sections Don't force removal of unreachable functions and data
+ \\ --sort-section=[value] Sort wildcard section patterns by 'name' or 'alignment'
\\ --subsystem [subsystem] (Windows) /SUBSYSTEM:<subsystem> to the linker
\\ --stack [size] Override default stack size
\\ --image-base [addr] Set base address for executable image
@@ -728,6 +732,7 @@ fn buildOutputType(
var linker_script: ?[]const u8 = null;
var version_script: ?[]const u8 = null;
var disable_c_depfile = false;
+ var linker_sort_section: ?link.SortSection = null;
var linker_gc_sections: ?bool = null;
var linker_compress_debug_sections: ?link.CompressDebugSections = null;
var linker_allow_shlib_undefined: ?bool = null;
@@ -797,6 +802,7 @@ fn buildOutputType(
var headerpad_max_install_names: bool = false;
var dead_strip_dylibs: bool = false;
var reference_trace: ?u32 = null;
+ var error_tracing: ?bool = null;
var pdb_out_path: ?[]const u8 = null;
// e.g. -m3dnow or -mno-outline-atomics. They correspond to std.Target llvm cpu feature names.
@@ -1218,6 +1224,10 @@ fn buildOutputType(
};
} else if (mem.eql(u8, arg, "-fno-reference-trace")) {
reference_trace = null;
+ } else if (mem.eql(u8, arg, "-ferror-tracing")) {
+ error_tracing = true;
+ } else if (mem.eql(u8, arg, "-fno-error-tracing")) {
+ error_tracing = false;
} else if (mem.eql(u8, arg, "-rdynamic")) {
rdynamic = true;
} else if (mem.eql(u8, arg, "-fsoname")) {
@@ -1326,6 +1336,8 @@ fn buildOutputType(
linker_z_notext = true;
} else if (mem.eql(u8, z_arg, "defs")) {
linker_z_defs = true;
+ } else if (mem.eql(u8, z_arg, "undefs")) {
+ linker_z_defs = false;
} else if (mem.eql(u8, z_arg, "origin")) {
linker_z_origin = true;
} else if (mem.eql(u8, z_arg, "nocopyreloc")) {
@@ -1343,7 +1355,7 @@ fn buildOutputType(
} else if (mem.startsWith(u8, z_arg, "max-page-size=")) {
linker_z_max_page_size = parseIntSuffix(z_arg, "max-page-size=".len);
} else {
- warn("unsupported linker extension flag: -z {s}", .{z_arg});
+ fatal("unsupported linker extension flag: -z {s}", .{z_arg});
}
} else if (mem.eql(u8, arg, "--import-memory")) {
linker_import_memory = true;
@@ -1607,6 +1619,10 @@ fn buildOutputType(
build_id = true;
warn("ignoring build-id style argument: '{s}'", .{value});
continue;
+ } else if (mem.eql(u8, key, "--sort-common")) {
+ // this ignores --sort=common=<anything>; ignoring plain --sort-common
+ // is done below.
+ continue;
}
try linker_args.append(key);
try linker_args.append(value);
@@ -1619,6 +1635,9 @@ fn buildOutputType(
needed = true;
} else if (mem.eql(u8, linker_arg, "-no-pie")) {
want_pie = false;
+ } else if (mem.eql(u8, linker_arg, "--sort-common")) {
+ // from ld.lld(1): --sort-common is ignored for GNU compatibility,
+ // this ignores plain --sort-common
} else if (mem.eql(u8, linker_arg, "--whole-archive") or
mem.eql(u8, linker_arg, "-whole-archive"))
{
@@ -1872,6 +1891,8 @@ fn buildOutputType(
linker_gc_sections = true;
} else if (mem.eql(u8, arg, "-dead_strip_dylibs")) {
dead_strip_dylibs = true;
+ } else if (mem.eql(u8, arg, "--no-undefined")) {
+ linker_z_defs = true;
} else if (mem.eql(u8, arg, "--gc-sections")) {
linker_gc_sections = true;
} else if (mem.eql(u8, arg, "--no-gc-sections")) {
@@ -1882,6 +1903,15 @@ fn buildOutputType(
linker_print_icf_sections = true;
} else if (mem.eql(u8, arg, "--print-map")) {
linker_print_map = true;
+ } else if (mem.eql(u8, arg, "--sort-section")) {
+ i += 1;
+ if (i >= linker_args.items.len) {
+ fatal("expected linker arg after '{s}'", .{arg});
+ }
+ const arg1 = linker_args.items[i];
+ linker_sort_section = std.meta.stringToEnum(link.SortSection, arg1) orelse {
+ fatal("expected [name|alignment] after --sort-section, found '{s}'", .{arg1});
+ };
} else if (mem.eql(u8, arg, "--allow-shlib-undefined") or
mem.eql(u8, arg, "-allow-shlib-undefined"))
{
@@ -1937,6 +1967,8 @@ fn buildOutputType(
linker_z_notext = true;
} else if (mem.eql(u8, z_arg, "defs")) {
linker_z_defs = true;
+ } else if (mem.eql(u8, z_arg, "undefs")) {
+ linker_z_defs = false;
} else if (mem.eql(u8, z_arg, "origin")) {
linker_z_origin = true;
} else if (mem.eql(u8, z_arg, "nocopyreloc")) {
@@ -1961,7 +1993,7 @@ fn buildOutputType(
} else if (mem.startsWith(u8, z_arg, "max-page-size=")) {
linker_z_max_page_size = parseIntSuffix(z_arg, "max-page-size=".len);
} else {
- warn("unsupported linker extension flag: -z {s}", .{z_arg});
+ fatal("unsupported linker extension flag: -z {s}", .{z_arg});
}
} else if (mem.eql(u8, arg, "--major-image-version")) {
i += 1;
@@ -2023,6 +2055,14 @@ fn buildOutputType(
// This option does not do anything.
} else if (mem.eql(u8, arg, "--export-all-symbols")) {
rdynamic = true;
+ } else if (mem.eql(u8, arg, "--color-diagnostics") or
+ mem.eql(u8, arg, "--color-diagnostics=always"))
+ {
+ color = .on;
+ } else if (mem.eql(u8, arg, "--no-color-diagnostics") or
+ mem.eql(u8, arg, "--color-diagnostics=never"))
+ {
+ color = .off;
} else if (mem.eql(u8, arg, "-s") or mem.eql(u8, arg, "--strip-all") or
mem.eql(u8, arg, "-S") or mem.eql(u8, arg, "--strip-debug"))
{
@@ -2186,7 +2226,7 @@ fn buildOutputType(
have_version = true;
} else {
- warn("unsupported linker arg: {s}", .{arg});
+ fatal("unsupported linker arg: {s}", .{arg});
}
}
@@ -3056,6 +3096,7 @@ fn buildOutputType(
.version_script = version_script,
.disable_c_depfile = disable_c_depfile,
.soname = resolved_soname,
+ .linker_sort_section = linker_sort_section,
.linker_gc_sections = linker_gc_sections,
.linker_allow_shlib_undefined = linker_allow_shlib_undefined,
.linker_bind_global_refs_locally = linker_bind_global_refs_locally,
@@ -3136,6 +3177,7 @@ fn buildOutputType(
.headerpad_max_install_names = headerpad_max_install_names,
.dead_strip_dylibs = dead_strip_dylibs,
.reference_trace = reference_trace,
+ .error_tracing = error_tracing,
.pdb_out_path = pdb_out_path,
}) catch |err| switch (err) {
error.LibCUnavailable => {
@@ -3607,7 +3649,7 @@ fn cmdTranslateC(comp: *Compilation, arena: Allocator, enable_cache: bool) !void
defer if (enable_cache) man.deinit();
man.hash.add(@as(u16, 0xb945)); // Random number to distinguish translate-c from compiling C objects
- man.hashCSource(c_source_file) catch |err| {
+ Compilation.cache_helpers.hashCSource(&man, c_source_file) catch |err| {
fatal("unable to process '{s}': {s}", .{ c_source_file.src_path, @errorName(err) });
};
@@ -4523,7 +4565,7 @@ fn fmtPathDir(
if (is_dir and (mem.eql(u8, entry.name, "zig-cache") or mem.eql(u8, entry.name, "zig-out"))) continue;
- if (is_dir or entry.kind == .File and mem.endsWith(u8, entry.name, ".zig")) {
+ if (is_dir or entry.kind == .File and (mem.endsWith(u8, entry.name, ".zig") or mem.endsWith(u8, entry.name, ".zon"))) {
const full_path = try fs.path.join(fmt.gpa, &[_][]const u8{ file_path, entry.name });
defer fmt.gpa.free(full_path);