diff options
| author | Jakub Konka <kubkon@jakubkonka.com> | 2023-04-01 11:51:05 +0200 |
|---|---|---|
| committer | Jakub Konka <kubkon@jakubkonka.com> | 2023-04-01 14:22:44 +0200 |
| commit | a88c0b4d089d286e36351cf476c8d982fb730541 (patch) | |
| tree | a4d985e8a6bd7f7b36b66f24e21e1ff53ff5303a /src/Compilation.zig | |
| parent | 2dd178443abcbd91a923c64a4fd066caef974a82 (diff) | |
| download | zig-a88c0b4d089d286e36351cf476c8d982fb730541.tar.gz zig-a88c0b4d089d286e36351cf476c8d982fb730541.zip | |
link: handle -u flag in all linkers
Also clean up parsing of linker args - reuse `ArgsIterator`.
In MachO, ensure we add every symbol marked with `-u` as undefined
before proceeding with symbol resolution. Additionally, ensure those
symbols are never garbage collected.
MachO entry_in_dylib test: pass `-u _my_main` when linking executable
so that it is not incorrectly garbage collected by the linker.
Diffstat (limited to 'src/Compilation.zig')
| -rw-r--r-- | src/Compilation.zig | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/Compilation.zig b/src/Compilation.zig index 2c9b4e4063..2fdb2ae4ba 100644 --- a/src/Compilation.zig +++ b/src/Compilation.zig @@ -602,6 +602,7 @@ pub const InitOptions = struct { parent_compilation_link_libc: bool = false, hash_style: link.HashStyle = .both, entry: ?[]const u8 = null, + force_undefined_symbols: std.StringArrayHashMapUnmanaged(void) = .{}, stack_size_override: ?u64 = null, image_base_override: ?u64 = null, self_exe_path: ?[]const u8 = null, @@ -1523,7 +1524,7 @@ pub fn create(gpa: Allocator, options: InitOptions) !*Compilation { .headerpad_size = options.headerpad_size, .headerpad_max_install_names = options.headerpad_max_install_names, .dead_strip_dylibs = options.dead_strip_dylibs, - .force_undefined_symbols = .{}, + .force_undefined_symbols = options.force_undefined_symbols, .pdb_source_path = options.pdb_source_path, .pdb_out_path = options.pdb_out_path, }); @@ -2186,7 +2187,7 @@ fn prepareWholeEmitSubPath(arena: Allocator, opt_emit: ?EmitLoc) error{OutOfMemo /// to remind the programmer to update multiple related pieces of code that /// are in different locations. Bump this number when adding or deleting /// anything from the link cache manifest. -pub const link_hash_implementation_version = 7; +pub const link_hash_implementation_version = 8; fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifest) !void { const gpa = comp.gpa; @@ -2196,7 +2197,7 @@ fn addNonIncrementalStuffToCacheManifest(comp: *Compilation, man: *Cache.Manifes defer arena_allocator.deinit(); const arena = arena_allocator.allocator(); - comptime assert(link_hash_implementation_version == 7); + comptime assert(link_hash_implementation_version == 8); if (comp.bin_file.options.module) |mod| { const main_zig_file = try mod.main_pkg.root_src_directory.join(arena, &[_][]const u8{ |
