diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2024-10-10 00:41:58 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2024-10-10 14:21:52 -0700 |
| commit | 14c8e270bb47c4e10ee3392661d4c62ab5c2f89d (patch) | |
| tree | c74fe79e74d3fc6bff7dd61f372153906e29e040 /src/main.zig | |
| parent | 58349b2c8ebc57718bbfbf939c30b586d5c85466 (diff) | |
| download | zig-14c8e270bb47c4e10ee3392661d4c62ab5c2f89d.tar.gz zig-14c8e270bb47c4e10ee3392661d4c62ab5c2f89d.zip | |
link: fix false positive crtbegin/crtend detection
Embrace the Path abstraction, doing more operations based on directory
handles rather than absolute file paths. Most of the diff noise here
comes from this one.
Fix sorting of crtbegin/crtend atoms. Previously it would look at all
path components for those strings.
Make the C runtime path detection partially a pure function, and move
some logic to glibc.zig where it belongs.
Diffstat (limited to 'src/main.zig')
| -rw-r--r-- | src/main.zig | 47 |
1 files changed, 24 insertions, 23 deletions
diff --git a/src/main.zig b/src/main.zig index 940e88e2cf..4e29611d9c 100644 --- a/src/main.zig +++ b/src/main.zig @@ -13,6 +13,12 @@ const warn = std.log.warn; const ThreadPool = std.Thread.Pool; const cleanExit = std.process.cleanExit; const native_os = builtin.os.tag; +const Cache = std.Build.Cache; +const Path = std.Build.Cache.Path; +const EnvVar = std.zig.EnvVar; +const LibCInstallation = std.zig.LibCInstallation; +const AstGen = std.zig.AstGen; +const Server = std.zig.Server; const tracy = @import("tracy.zig"); const Compilation = @import("Compilation.zig"); @@ -20,16 +26,11 @@ const link = @import("link.zig"); const Package = @import("Package.zig"); const build_options = @import("build_options"); const introspect = @import("introspect.zig"); -const EnvVar = std.zig.EnvVar; -const LibCInstallation = std.zig.LibCInstallation; const wasi_libc = @import("wasi_libc.zig"); -const Cache = std.Build.Cache; const target_util = @import("target.zig"); const crash_report = @import("crash_report.zig"); const Zcu = @import("Zcu.zig"); -const AstGen = std.zig.AstGen; const mingw = @import("mingw.zig"); -const Server = std.zig.Server; const dev = @import("dev.zig"); pub const std_options = .{ @@ -1724,14 +1725,14 @@ fn buildOutputType( } } else switch (file_ext orelse Compilation.classifyFileExt(arg)) { .shared_library => { - try create_module.link_objects.append(arena, .{ .path = arg }); + try create_module.link_objects.append(arena, .{ .path = Path.initCwd(arg) }); create_module.opts.any_dyn_libs = true; }, .object, .static_library => { - try create_module.link_objects.append(arena, .{ .path = arg }); + try create_module.link_objects.append(arena, .{ .path = Path.initCwd(arg) }); }, .res => { - try create_module.link_objects.append(arena, .{ .path = arg }); + try create_module.link_objects.append(arena, .{ .path = Path.initCwd(arg) }); contains_res_file = true; }, .manifest => { @@ -1845,20 +1846,20 @@ fn buildOutputType( }, .shared_library => { try create_module.link_objects.append(arena, .{ - .path = it.only_arg, + .path = Path.initCwd(it.only_arg), .must_link = must_link, }); create_module.opts.any_dyn_libs = true; }, .unknown, .object, .static_library => { try create_module.link_objects.append(arena, .{ - .path = it.only_arg, + .path = Path.initCwd(it.only_arg), .must_link = must_link, }); }, .res => { try create_module.link_objects.append(arena, .{ - .path = it.only_arg, + .path = Path.initCwd(it.only_arg), .must_link = must_link, }); contains_res_file = true; @@ -1894,7 +1895,7 @@ fn buildOutputType( // binary: no extra rpaths and DSO filename exactly // as provided. Hello, Go. try create_module.link_objects.append(arena, .{ - .path = it.only_arg, + .path = Path.initCwd(it.only_arg), .must_link = must_link, .loption = true, }); @@ -2532,7 +2533,7 @@ fn buildOutputType( install_name = linker_args_it.nextOrFatal(); } else if (mem.eql(u8, arg, "-force_load")) { try create_module.link_objects.append(arena, .{ - .path = linker_args_it.nextOrFatal(), + .path = Path.initCwd(linker_args_it.nextOrFatal()), .must_link = true, }); } else if (mem.eql(u8, arg, "-hash-style") or @@ -2707,7 +2708,7 @@ fn buildOutputType( break :b create_module.c_source_files.items[0].src_path; if (create_module.link_objects.items.len >= 1) - break :b create_module.link_objects.items[0].path; + break :b create_module.link_objects.items[0].path.sub_path; if (emit_bin == .yes) break :b emit_bin.yes; @@ -2963,7 +2964,7 @@ fn buildOutputType( framework_dir_path, framework_name, )) { - const path = try arena.dupe(u8, test_path.items); + const path = Path.initCwd(try arena.dupe(u8, test_path.items)); try resolved_frameworks.append(.{ .needed = info.needed, .weak = info.weak, @@ -3635,7 +3636,7 @@ const CreateModule = struct { name: []const u8, lib: Compilation.SystemLib, }), - wasi_emulated_libs: std.ArrayListUnmanaged(wasi_libc.CRTFile), + wasi_emulated_libs: std.ArrayListUnmanaged(wasi_libc.CrtFile), c_source_files: std.ArrayListUnmanaged(Compilation.CSourceFile), rc_source_files: std.ArrayListUnmanaged(Compilation.RcSourceFile), @@ -3808,7 +3809,7 @@ fn createModule( } if (target.os.tag == .wasi) { - if (wasi_libc.getEmulatedLibCRTFile(lib_name)) |crt_file| { + if (wasi_libc.getEmulatedLibCrtFile(lib_name)) |crt_file| { try create_module.wasi_emulated_libs.append(arena, crt_file); continue; } @@ -3929,7 +3930,7 @@ fn createModule( target, info.preferred_mode, )) { - const path = try arena.dupe(u8, test_path.items); + const path = Path.initCwd(try arena.dupe(u8, test_path.items)); switch (info.preferred_mode) { .static => try create_module.link_objects.append(arena, .{ .path = path }), .dynamic => try create_module.resolved_system_libs.append(arena, .{ @@ -3963,7 +3964,7 @@ fn createModule( target, info.fallbackMode(), )) { - const path = try arena.dupe(u8, test_path.items); + const path = Path.initCwd(try arena.dupe(u8, test_path.items)); switch (info.fallbackMode()) { .static => try create_module.link_objects.append(arena, .{ .path = path }), .dynamic => try create_module.resolved_system_libs.append(arena, .{ @@ -3997,7 +3998,7 @@ fn createModule( target, info.preferred_mode, )) { - const path = try arena.dupe(u8, test_path.items); + const path = Path.initCwd(try arena.dupe(u8, test_path.items)); switch (info.preferred_mode) { .static => try create_module.link_objects.append(arena, .{ .path = path }), .dynamic => try create_module.resolved_system_libs.append(arena, .{ @@ -4021,7 +4022,7 @@ fn createModule( target, info.fallbackMode(), )) { - const path = try arena.dupe(u8, test_path.items); + const path = Path.initCwd(try arena.dupe(u8, test_path.items)); switch (info.fallbackMode()) { .static => try create_module.link_objects.append(arena, .{ .path = path }), .dynamic => try create_module.resolved_system_libs.append(arena, .{ @@ -6163,7 +6164,7 @@ fn cmdAstCheck( } file.mod = try Package.Module.createLimited(arena, .{ - .root = Cache.Path.cwd(), + .root = Path.cwd(), .root_src_path = file.sub_file_path, .fully_qualified_name = "root", }); @@ -6523,7 +6524,7 @@ fn cmdChangelist( }; file.mod = try Package.Module.createLimited(arena, .{ - .root = Cache.Path.cwd(), + .root = Path.cwd(), .root_src_path = file.sub_file_path, .fully_qualified_name = "root", }); |
