aboutsummaryrefslogtreecommitdiff
path: root/src/link.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2022-08-29 14:10:59 -0700
committerAndrew Kelley <andrew@ziglang.org>2022-08-29 14:10:59 -0700
commitde7270028d2b70ceea74c43be943b1b788c797a6 (patch)
tree0d9b545a2a9d36c86b79178f797adf5ebcd40d17 /src/link.zig
parent7c9a8ecc2aca7f925e59d282540ef8e2d1ae211e (diff)
parente69973beddcd8a42dbc7ebcfb96187e5a6f61b61 (diff)
downloadzig-de7270028d2b70ceea74c43be943b1b788c797a6.tar.gz
zig-de7270028d2b70ceea74c43be943b1b788c797a6.zip
Merge remote-tracking branch 'origin/master' into llvm15
Diffstat (limited to 'src/link.zig')
-rw-r--r--src/link.zig34
1 files changed, 23 insertions, 11 deletions
diff --git a/src/link.zig b/src/link.zig
index ec8e95a626..7f5f1ebc4b 100644
--- a/src/link.zig
+++ b/src/link.zig
@@ -72,7 +72,6 @@ pub const Options = struct {
target: std.Target,
output_mode: std.builtin.OutputMode,
link_mode: std.builtin.LinkMode,
- object_format: std.Target.ObjectFormat,
optimize_mode: std.builtin.Mode,
machine_code_model: std.builtin.CodeModel,
root_name: [:0]const u8,
@@ -91,6 +90,9 @@ pub const Options = struct {
entry: ?[]const u8,
stack_size_override: ?u64,
image_base_override: ?u64,
+ /// 0 means no stack protector
+ /// other value means stack protector with that buffer size.
+ stack_protector: u32,
cache_mode: CacheMode,
include_compiler_rt: bool,
/// Set to `true` to omit debug info.
@@ -173,6 +175,12 @@ pub const Options = struct {
lib_dirs: []const []const u8,
rpath_list: []const []const u8,
+ /// List of symbols forced as undefined in the symbol table
+ /// thus forcing their resolution by the linker.
+ /// Corresponds to `-u <symbol>` for ELF and `/include:<symbol>` for COFF/PE.
+ /// TODO add handling for MachO.
+ force_undefined_symbols: std.StringArrayHashMapUnmanaged(void),
+
version: ?std.builtin.Version,
compatibility_version: ?std.builtin.Version,
libc_installation: ?*const LibCInstallation,
@@ -273,13 +281,13 @@ pub const File = struct {
/// rewriting it. A malicious file is detected as incremental link failure
/// and does not cause Illegal Behavior. This operation is not atomic.
pub fn openPath(allocator: Allocator, options: Options) !*File {
- if (options.object_format == .macho) {
+ if (options.target.ofmt == .macho) {
return &(try MachO.openPath(allocator, options)).base;
}
- const use_stage1 = build_options.is_stage1 and options.use_stage1;
+ const use_stage1 = build_options.have_stage1 and options.use_stage1;
if (use_stage1 or options.emit == null) {
- return switch (options.object_format) {
+ return switch (options.target.ofmt) {
.coff => &(try Coff.createEmpty(allocator, options)).base,
.elf => &(try Elf.createEmpty(allocator, options)).base,
.macho => unreachable,
@@ -299,7 +307,7 @@ pub const File = struct {
if (options.module == null) {
// No point in opening a file, we would not write anything to it.
// Initialize with empty.
- return switch (options.object_format) {
+ return switch (options.target.ofmt) {
.coff => &(try Coff.createEmpty(allocator, options)).base,
.elf => &(try Elf.createEmpty(allocator, options)).base,
.macho => unreachable,
@@ -316,12 +324,12 @@ pub const File = struct {
// Open a temporary object file, not the final output file because we
// want to link with LLD.
break :blk try std.fmt.allocPrint(allocator, "{s}{s}", .{
- emit.sub_path, options.object_format.fileExt(options.target.cpu.arch),
+ emit.sub_path, options.target.ofmt.fileExt(options.target.cpu.arch),
});
} else emit.sub_path;
errdefer if (use_lld) allocator.free(sub_path);
- const file: *File = switch (options.object_format) {
+ const file: *File = switch (options.target.ofmt) {
.coff => &(try Coff.openPath(allocator, sub_path, options)).base,
.elf => &(try Elf.openPath(allocator, sub_path, options)).base,
.macho => unreachable,
@@ -421,7 +429,7 @@ pub const File = struct {
NoSpaceLeft,
Unseekable,
PermissionDenied,
- FileBusy,
+ SwapFile,
SystemResources,
OperationAborted,
BrokenPipe,
@@ -438,6 +446,7 @@ pub const File = struct {
EmitFail,
NameTooLong,
CurrentWorkingDirectoryUnlinked,
+ LockViolation,
};
/// Called from within the CodeGen to lower a local variable instantion as an unnamed
@@ -774,12 +783,15 @@ pub const File = struct {
error.FileNotFound => {},
else => |e| return e,
}
- try std.fs.rename(
+ std.fs.rename(
cache_directory.handle,
tmp_dir_sub_path,
cache_directory.handle,
o_sub_path,
- );
+ ) catch |err| switch (err) {
+ error.AccessDenied => unreachable, // We are most likely trying to move a dir with open handles to its resources
+ else => |e| return e,
+ };
break;
} else {
std.fs.rename(
@@ -814,7 +826,7 @@ pub const File = struct {
// If there is no Zig code to compile, then we should skip flushing the output file
// because it will not be part of the linker line anyway.
const module_obj_path: ?[]const u8 = if (base.options.module) |module| blk: {
- const use_stage1 = build_options.is_stage1 and base.options.use_stage1;
+ const use_stage1 = build_options.have_stage1 and base.options.use_stage1;
if (use_stage1) {
const obj_basename = try std.zig.binNameAlloc(arena, .{
.root_name = base.options.root_name,