diff --git a/README.md b/README.md index 8fec6e9f..49c4a3f6 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ -# zld +# emerald -`zld` is a drop-in replacement for your system linker `ld` written in Zig. +`emerald` is a drop-in replacement for your system linker `ld` written in Zig. ## Quick start guide @@ -12,7 +12,7 @@ You will need Zig 0.13.0 in your path. You can download it from [here](https://z $ zig build ``` -This will create the `ld.zld` (Elf), `ld64.zld` (MachO), `link-zld` (Coff) and `wasm-zld` (Wasm) binaries in `zig-out/bin/`. +This will create the `ld.emerald` (Elf), `ld64.emerald` (MachO), `emerald-link.exe` (Coff) and `wasm-emerald` (Wasm) binaries in `zig-out/bin/`. You can then use it like you'd use a standard linker. ``` @@ -32,10 +32,10 @@ $ clang -c hello.c $ zig cc -c hello.c # On macOS -$ ./zig-out/bin/ld64.zld hello.o -o hello +$ ./zig-out/bin/ld64.emerald hello.o -o hello # On Linux -$ ./zig-out/bin/ld.zld hello.o -o hello +$ ./zig-out/bin/ld.emerald hello.o -o hello # Run! $ ./hello diff --git a/build.zig b/build.zig index 02542104..e98bdd29 100644 --- a/build.zig +++ b/build.zig @@ -32,7 +32,7 @@ pub fn build(b: *std.Build) void { }); const exe = b.addExecutable(.{ - .name = "zld", + .name = "emerald", .root_source_file = b.path("src/main.zig"), .target = target, .optimize = mode, @@ -76,10 +76,10 @@ pub fn build(b: *std.Build) void { const install = b.addInstallArtifact(exe, .{}); const symlinks = addSymlinks(b, install, &[_][]const u8{ "ld", - "ld.zld", - "ld64.zld", - "link-zld.exe", - "wasm-zld", + "ld.emerald", + "ld64.emerald", + "emerald-link.exe", + "wasm-emerald", }); symlinks.step.dependOn(&install.step); @@ -90,7 +90,7 @@ pub fn build(b: *std.Build) void { const has_objc_msgsend_stubs = b.option(bool, "has-objc-msgsend-stubs", "Whether the system compiler supports '-fobjc-msgsend-selector-stubs' flag") orelse false; const unit_tests = b.addTest(.{ - .root_source_file = b.path("src/Zld.zig"), + .root_source_file = b.path("src/Ld.zig"), .target = target, .optimize = mode, .use_llvm = use_llvm, diff --git a/build.zig.zon b/build.zig.zon index 3419dc5b..4b85b05d 100644 --- a/build.zig.zon +++ b/build.zig.zon @@ -1,5 +1,5 @@ .{ - .name = "zld", + .name = "emerald", .version = "0.0.3", .dependencies = .{ diff --git a/src/Coff.zig b/src/Coff.zig index 572fdd88..17dd2dff 100644 --- a/src/Coff.zig +++ b/src/Coff.zig @@ -1,4 +1,4 @@ -base: Zld, +base: Ld, options: Options, internal_object_index: ?File.Index = null, @@ -1718,7 +1718,7 @@ const AlternateName = struct { index: Symbol.Index, }; -pub const base_tag = Zld.Tag.coff; +pub const base_tag = Ld.Tag.coff; const build_options = @import("build_options"); const builtin = @import("builtin"); @@ -1741,10 +1741,10 @@ const Coff = @This(); const Dll = @import("Coff/Dll.zig"); const File = @import("Coff/file.zig").File; const InternalObject = @import("Coff/InternalObject.zig"); +const Ld = @import("Ld.zig"); const Object = @import("Coff/Object.zig"); pub const Options = @import("Coff/Options.zig"); const RelocSection = synthetic.RelocSection; const StringTable = @import("StringTable.zig"); const Symbol = @import("Coff/Symbol.zig"); const ThreadPool = std.Thread.Pool; -const Zld = @import("Zld.zig"); diff --git a/src/Coff/Options.zig b/src/Coff/Options.zig index 4fbb10bf..97cd2107 100644 --- a/src/Coff/Options.zig +++ b/src/Coff/Options.zig @@ -1,4 +1,4 @@ -emit: Zld.Emit, +emit: Ld.Emit, cpu_arch: ?std.Target.Cpu.Arch = null, positionals: []const Coff.LinkObject, lib_paths: []const []const u8, @@ -20,7 +20,7 @@ pub fn parse(arena: Allocator, args: []const []const u8, ctx: anytype) !Options }; var verbose = false; - var it = Zld.Options.ArgsIterator{ .args = args }; + var it = Ld.Options.ArgsIterator{ .args = args }; var p = ArgsParser(@TypeOf(it)){ .it = &it }; while (p.hasMore()) { if (p.flag("help")) { @@ -146,7 +146,7 @@ const usage = \\ \\General Options: \\-align:number Alignment value in bytes - \\-debug-log:scope Turn on debugging logs for 'scope' (requires zld compiled with -Dlog) + \\-debug-log:scope Turn on debugging logs for 'scope' (requires linker compiled with -Dlog) \\-defaultlib:name Link a default library \\-filealign:size Section alignment size in bytes, must be power of two \\-help Print this help and exit @@ -156,7 +156,7 @@ const usage = \\-v Print full linker invocation to stderr ; -const cmd = "link-zld.exe"; +const cmd = "link-emerald.exe"; const builtin = @import("builtin"); const io = std.io; @@ -168,4 +168,4 @@ const Allocator = mem.Allocator; const CrossTarget = std.zig.CrossTarget; const Coff = @import("../Coff.zig"); const Options = @This(); -const Zld = @import("../Zld.zig"); +const Ld = @import("../Ld.zig"); diff --git a/src/Elf.zig b/src/Elf.zig index 0751fa14..e7adf9bc 100644 --- a/src/Elf.zig +++ b/src/Elf.zig @@ -1,4 +1,4 @@ -base: Zld, +base: Ld, options: Options, shoff: u64 = 0, @@ -3001,7 +3001,7 @@ pub const null_sym = elf.Elf64_Sym{ .st_size = 0, }; -pub const base_tag = Zld.Tag.elf; +pub const base_tag = Ld.Tag.elf; const std = @import("std"); const build_options = @import("build_options"); @@ -3038,6 +3038,7 @@ const Hash = std.hash.Wyhash; const HashSection = synthetic.HashSection; const InputMergeSection = merge_section.InputMergeSection; const InternalObject = @import("Elf/InternalObject.zig"); +const Ld = @import("Ld.zig"); const LdScript = @import("Elf/LdScript.zig"); const MergeSection = merge_section.MergeSection; const MergeSubsection = merge_section.MergeSubsection; @@ -3051,4 +3052,3 @@ const Symbol = @import("Elf/Symbol.zig"); const ThreadPool = std.Thread.Pool; const Thunk = @import("Elf/Thunk.zig"); const VerneedSection = synthetic.VerneedSection; -const Zld = @import("Zld.zig"); diff --git a/src/Elf/Object.zig b/src/Elf/Object.zig index 6466b8af..dc901727 100644 --- a/src/Elf/Object.zig +++ b/src/Elf/Object.zig @@ -442,8 +442,8 @@ fn filterRelocs( } }; - const f_start = Zld.binarySearch(elf.Elf64_Rela, relocs, Predicate{ .value = start }); - const f_len = Zld.linearSearch(elf.Elf64_Rela, relocs[f_start..], LPredicate{ .value = start + len }); + const f_start = Ld.binarySearch(elf.Elf64_Rela, relocs, Predicate{ .value = start }); + const f_len = Ld.linearSearch(elf.Elf64_Rela, relocs[f_start..], LPredicate{ .value = start + len }); return .{ .start = f_start, .len = f_len }; } @@ -1408,4 +1408,4 @@ const File = @import("file.zig").File; const InputMergeSection = @import("merge_section.zig").InputMergeSection; const StringTable = @import("../StringTable.zig"); const Symbol = @import("Symbol.zig"); -const Zld = @import("../Zld.zig"); +const Ld = @import("../Ld.zig"); diff --git a/src/Elf/Options.zig b/src/Elf/Options.zig index 69f6ca90..2c4336b8 100644 --- a/src/Elf/Options.zig +++ b/src/Elf/Options.zig @@ -1,4 +1,4 @@ -emit: Zld.Emit, +emit: Ld.Emit, shared: bool = false, relocatable: bool = false, positionals: []const Elf.LinkObject, @@ -68,8 +68,8 @@ pub fn parse(arena: Allocator, args: []const []const u8, ctx: anytype) !Options .rpath_list = undefined, }; - var it = Zld.Options.ArgsIterator{ .args = args }; - var p = Zld.ArgParser(@TypeOf(ctx)){ .it = &it, .ctx = ctx }; + var it = Ld.Options.ArgsIterator{ .args = args }; + var p = Ld.ArgParser(@TypeOf(ctx)){ .it = &it, .ctx = ctx }; while (p.hasMore()) { if (p.flag2("help")) { ctx.fatal(usage ++ "\n", .{cmd}); @@ -378,7 +378,7 @@ const usage = \\--build-id=[none,md5,sha1,sha256,uuid,HEXSTRING] \\ Generate build ID \\ --no-build-id - \\--debug-log [value] Turn on debugging logs for [value] (requires zld compiled with -Dlog) + \\--debug-log [value] Turn on debugging logs for [value] (requires linker compiled with -Dlog) \\--dynamic Alias for --Bdynamic \\--dynamic-linker=[value], -I [value] \\ Set the dynamic linker to use @@ -438,12 +438,12 @@ const usage = \\-v, --version Print version \\-V Print version and target information \\ - \\ld.zld: supported target: elf64-x86-64, elf64-littleaarch64, elf64-littleriscv - \\ld.zld: supported emulations: elf64_x86_64, aarch64linux, aarch64elf, elf64lriscv + \\ld.emerald: supported target: elf64-x86-64, elf64-littleaarch64, elf64-littleriscv + \\ld.emerald: supported emulations: elf64_x86_64, aarch64linux, aarch64elf, elf64lriscv ; pub const version = - \\ld.zld 0.0.4 (compatible with GNU ld) + \\ld.emerald 0.0.4 (compatible with GNU ld) ; fn cpuArchToElfEmulation(cpu_arch: std.Target.Cpu.Arch) []const u8 { @@ -483,7 +483,7 @@ fn parseSectionStart(opts: *Options, arena: Allocator, name: []const u8, value: _ = try opts.section_start.put(arena, try arena.dupe(u8, name), start); } -const cmd = "ld.zld"; +const cmd = "ld.emerald"; pub const BuildId = enum { none, @@ -510,4 +510,4 @@ const process = std.process; const Allocator = mem.Allocator; const Elf = @import("../Elf.zig"); const Options = @This(); -const Zld = @import("../Zld.zig"); +const Ld = @import("../Ld.zig"); diff --git a/src/Elf/gc.zig b/src/Elf/gc.zig index 0291190e..81d3cd13 100644 --- a/src/Elf/gc.zig +++ b/src/Elf/gc.zig @@ -149,7 +149,7 @@ pub fn dumpPrunedAtoms(elf_file: *Elf) !void { for (object.atoms_indexes.items) |atom_index| { const atom = object.getAtom(atom_index) orelse continue; if (!atom.flags.alive) - try stderr.print("ld.zld: removing unused section '{s}' in file '{}'\n", .{ + try stderr.print("ld.emerald: removing unused section '{s}' in file '{}'\n", .{ atom.getName(elf_file), atom.getObject(elf_file).fmtPath(), }); diff --git a/src/Zld.zig b/src/Ld.zig similarity index 95% rename from src/Zld.zig rename to src/Ld.zig index a4e3b942..f05dd182 100644 --- a/src/Zld.zig +++ b/src/Ld.zig @@ -204,7 +204,7 @@ pub const ErrorMsg = struct { } }; -pub fn openPath(allocator: Allocator, tag: Tag, options: Options, thread_pool: *ThreadPool) !*Zld { +pub fn openPath(allocator: Allocator, tag: Tag, options: Options, thread_pool: *ThreadPool) !*Ld { return switch (tag) { .macho => &(try MachO.openPath(allocator, options.macho, thread_pool)).base, .elf => &(try Elf.openPath(allocator, options.elf, thread_pool)).base, @@ -213,7 +213,7 @@ pub fn openPath(allocator: Allocator, tag: Tag, options: Options, thread_pool: * }; } -pub fn deinit(base: *Zld) void { +pub fn deinit(base: *Ld) void { base.file.close(); assert(base.warnings.items.len == 0); base.warnings.deinit(base.allocator); @@ -243,7 +243,7 @@ pub fn deinit(base: *Zld) void { } } -pub fn flush(base: *Zld) !void { +pub fn flush(base: *Ld) !void { switch (base.tag) { .elf => try @as(*Elf, @fieldParentPtr("base", base)).flush(), .macho => try @as(*MachO, @fieldParentPtr("base", base)).flush(), @@ -252,12 +252,12 @@ pub fn flush(base: *Zld) !void { } } -pub fn warn(base: *Zld, comptime format: []const u8, args: anytype) void { +pub fn warn(base: *Ld, comptime format: []const u8, args: anytype) void { const warning = base.addWarningWithNotes(0) catch return; warning.addMsg(format, args) catch return; } -pub fn fatal(base: *Zld, comptime format: []const u8, args: anytype) void { +pub fn fatal(base: *Ld, comptime format: []const u8, args: anytype) void { const err = base.addErrorWithNotes(0) catch return; err.addMsg(format, args) catch return; } @@ -285,7 +285,7 @@ pub const ErrorWithNotes = struct { } }; -pub fn addErrorWithNotes(base: *Zld, note_count: usize) !ErrorWithNotes { +pub fn addErrorWithNotes(base: *Ld, note_count: usize) !ErrorWithNotes { base.errors_mutex.lock(); defer base.errors_mutex.unlock(); const err_index = base.errors.items.len; @@ -295,7 +295,7 @@ pub fn addErrorWithNotes(base: *Zld, note_count: usize) !ErrorWithNotes { return .{ .err_index = err_index, .allocator = base.allocator, .errors = base.errors.items }; } -pub fn addWarningWithNotes(base: *Zld, note_count: usize) !ErrorWithNotes { +pub fn addWarningWithNotes(base: *Ld, note_count: usize) !ErrorWithNotes { base.warnings_mutex.lock(); defer base.warnings_mutex.unlock(); const err_index = base.warnings.items.len; @@ -305,7 +305,7 @@ pub fn addWarningWithNotes(base: *Zld, note_count: usize) !ErrorWithNotes { return .{ .err_index = err_index, .allocator = base.allocator, .errors = base.warnings.items }; } -pub fn getAllWarningsAlloc(base: *Zld) !ErrorBundle { +pub fn getAllWarningsAlloc(base: *Ld) !ErrorBundle { var bundle: ErrorBundle.Wip = undefined; try bundle.init(base.allocator); defer bundle.deinit(); @@ -333,7 +333,7 @@ pub fn getAllWarningsAlloc(base: *Zld) !ErrorBundle { return bundle.toOwnedBundle(""); } -pub fn getAllErrorsAlloc(base: *Zld) !ErrorBundle { +pub fn getAllErrorsAlloc(base: *Ld) !ErrorBundle { var bundle: ErrorBundle.Wip = undefined; try bundle.init(base.allocator); defer bundle.deinit(); @@ -403,7 +403,7 @@ fn renderWarningMessageToWriter( } } -pub fn reportErrors(base: *Zld) void { +pub fn reportErrors(base: *Ld) void { var errors = base.getAllErrorsAlloc() catch @panic("OOM"); defer errors.deinit(base.allocator); if (errors.errorMessageCount() > 0) { @@ -411,7 +411,7 @@ pub fn reportErrors(base: *Zld) void { } } -pub fn reportWarnings(base: *Zld) void { +pub fn reportWarnings(base: *Ld) void { var warnings = base.getAllWarningsAlloc() catch @panic("OOM"); defer warnings.deinit(base.allocator); if (warnings.errorMessageCount() > 0) { @@ -451,7 +451,7 @@ pub fn linearSearch(comptime T: type, haystack: []align(1) const T, predicate: a } test { - std.testing.refAllDeclsRecursive(Zld); + std.testing.refAllDeclsRecursive(Ld); } const std = @import("std"); @@ -470,5 +470,5 @@ pub const Wasm = @import("Wasm.zig"); const Allocator = mem.Allocator; const CrossTarget = std.zig.CrossTarget; const ErrorBundle = std.zig.ErrorBundle; +const Ld = @This(); const ThreadPool = std.Thread.Pool; -const Zld = @This(); diff --git a/src/MachO.zig b/src/MachO.zig index 05f7dd80..bf1eb947 100644 --- a/src/MachO.zig +++ b/src/MachO.zig @@ -1,4 +1,4 @@ -base: Zld, +base: Ld, options: Options, dyld_info_cmd: macho.dyld_info_command = .{}, @@ -1279,8 +1279,8 @@ fn reportUndefs(self: *MachO) !void { const addFn = switch (self.options.undefined_treatment) { .dynamic_lookup => unreachable, // handled above .suppress => unreachable, // handled above - .@"error" => &Zld.addErrorWithNotes, - .warn => &Zld.addWarningWithNotes, + .@"error" => &Ld.addErrorWithNotes, + .warn => &Ld.addWarningWithNotes, }; const gpa = self.base.allocator; @@ -3324,7 +3324,7 @@ pub const String = struct { len: u32 = 0, }; -pub const base_tag = Zld.Tag.macho; +pub const base_tag = Ld.Tag.macho; const aarch64 = @import("aarch64.zig"); const assert = std.debug.assert; @@ -3364,6 +3364,7 @@ const GotSection = synthetic.GotSection; const Hash = std.hash.Wyhash; const Indsymtab = synthetic.Indsymtab; const InternalObject = @import("MachO/InternalObject.zig"); +const Ld = @import("Ld.zig"); const MachO = @This(); const Md5 = std.crypto.hash.Md5; const Object = @import("MachO/Object.zig"); @@ -3383,4 +3384,3 @@ const TlvPtrSection = synthetic.TlvPtrSection; const UnwindInfo = @import("MachO/UnwindInfo.zig"); const WaitGroup = std.Thread.WaitGroup; const WeakBind = synthetic.WeakBind; -const Zld = @import("Zld.zig"); diff --git a/src/MachO/CodeSignature.zig b/src/MachO/CodeSignature.zig index ce142b43..54d83d45 100644 --- a/src/MachO/CodeSignature.zig +++ b/src/MachO/CodeSignature.zig @@ -11,7 +11,6 @@ const Allocator = mem.Allocator; const Hasher = @import("hasher.zig").ParallelHasher; const MachO = @import("../MachO.zig"); const Sha256 = std.crypto.hash.sha2.Sha256; -const Zld = @import("../Zld.zig"); const hash_size = Sha256.digest_length; diff --git a/src/MachO/Options.zig b/src/MachO/Options.zig index 5da80f04..9b717210 100644 --- a/src/MachO/Options.zig +++ b/src/MachO/Options.zig @@ -10,7 +10,7 @@ const process = std.process; const Allocator = mem.Allocator; const CrossTarget = std.zig.CrossTarget; const MachO = @import("../MachO.zig"); -const Zld = @import("../Zld.zig"); +const Ld = @import("../Ld.zig"); pub const SearchStrategy = enum { paths_first, @@ -30,7 +30,7 @@ const usage = \\-dead_strip Remove functions and data that are unreachable by the entry point or \\ exported symbols \\-dead_strip_dylibs Remove dylibs that were unreachable by the entry point or exported symbols - \\--debug-log [scope] Turn on debugging logs for [scope] (requires zld compiled with -Dlog) + \\--debug-log [scope] Turn on debugging logs for [scope] (requires linker compiled with -Dlog) \\-dylib Create dynamic library \\-dynamic Perform dynamic linking \\-e [name] Specifies the entry point of main executable @@ -83,17 +83,17 @@ const usage = \\ -weak_library [name] \\-x Do not put non-global symbols in the symbol table \\ - \\ld64.zld: supported targets: macho-x86-64, macho-arm64 - \\ld64.zld: supported emulations: macho_x86_64, macho_arm64 + \\ld64.emerald: supported targets: macho-x86-64, macho-arm64 + \\ld64.emerald: supported emulations: macho_x86_64, macho_arm64 ; const version = - \\ld64.zld 0.0.4 (compatible with Apple ld64) + \\ld64.emerald 0.0.4 (compatible with Apple ld64) ; -const cmd = "ld64.zld"; +const cmd = "ld64.emerald"; -emit: Zld.Emit, +emit: Ld.Emit, dylib: bool = false, relocatable: bool = false, dynamic: bool = false, @@ -151,8 +151,8 @@ pub fn parse(arena: Allocator, args: []const []const u8, ctx: anytype) !Options }; var unknown_options = std.ArrayList(u8).init(arena); - var it = Zld.Options.ArgsIterator{ .args = args }; - var p = Zld.ArgParser(@TypeOf(ctx)){ .it = &it, .ctx = ctx }; + var it = Ld.Options.ArgsIterator{ .args = args }; + var p = Ld.ArgParser(@TypeOf(ctx)){ .it = &it, .ctx = ctx }; while (p.hasMore()) { if (p.flag2("help")) { ctx.fatal(usage ++ "\n", .{cmd}); diff --git a/src/Wasm.zig b/src/Wasm.zig index e34cb939..9613fa5f 100644 --- a/src/Wasm.zig +++ b/src/Wasm.zig @@ -2,10 +2,10 @@ const Wasm = @This(); const std = @import("std"); -const Zld = @import("Zld.zig"); const Atom = @import("Wasm/Atom.zig"); const Object = @import("Wasm/Object.zig"); const Archive = @import("Wasm/Archive.zig"); +const Ld = @import("Ld.zig"); const Symbol = @import("Wasm/Symbol.zig"); const sections = @import("Wasm/sections.zig"); const types = @import("Wasm/types.zig"); @@ -22,7 +22,7 @@ const mem = std.mem; const log = std.log.scoped(.wasm); const gc_loc = std.log.scoped(.@"wasm-garbage-man"); -base: Zld, +base: Ld, /// Configuration of the linker provided by the user options: Options, /// A list with references to objects we link to during `flush()` diff --git a/src/Wasm/Object.zig b/src/Wasm/Object.zig index 8a256ea5..b381ab40 100644 --- a/src/Wasm/Object.zig +++ b/src/Wasm/Object.zig @@ -310,7 +310,7 @@ pub const ParseError = error{ /// Object file contains a feature that is unknown to the linker UnknownFeature, /// The 'elemkind' found in the element section is unsupported. - /// Zld currently only supports funcrefs. + /// Emerald currently only supports funcrefs. UnsupportedElemKind, }; diff --git a/src/Wasm/Options.zig b/src/Wasm/Options.zig index b401851c..6e922101 100644 --- a/src/Wasm/Options.zig +++ b/src/Wasm/Options.zig @@ -3,7 +3,7 @@ const Options = @This(); const std = @import("std"); -const Zld = @import("../Zld.zig"); +const Ld = @import("../Ld.zig"); const Wasm = @import("../Wasm.zig"); const mem = std.mem; @@ -14,7 +14,7 @@ const usage = \\ \\Options: \\-h, --help Print this help and exit - \\--debug-log [scope] Turn on debugging logs for [scope] (requires zld compiled with -Dlog) + \\--debug-log [scope] Turn on debugging logs for [scope] (requires linker compiled with -Dlog) \\-o [path] Output path of the binary \\--entry Name of entry point symbol \\--global-base= Value from where the global data will start @@ -37,7 +37,7 @@ const usage = ; /// Result path of the binary -emit: Zld.Emit, +emit: Ld.Emit, /// List of positionals (paths) of objects and archives /// that may be linked into the final binary positionals: []const []const u8, @@ -88,7 +88,7 @@ exports: []const []const u8, /// atomics and bulk-memory enabled. shared_memory: bool = false, -const cmd = "wasm-zld"; +const cmd = "wasm-emerald"; pub fn parse(arena: Allocator, args: []const []const u8, ctx: anytype) !Options { if (args.len == 0) ctx.fatal(usage, .{cmd}); @@ -114,7 +114,7 @@ pub fn parse(arena: Allocator, args: []const []const u8, ctx: anytype) !Options var exports = std.ArrayList([]const u8).init(arena); var shared_memory: bool = false; - var it = Zld.Options.ArgsIterator{ .args = args }; + var it = Ld.Options.ArgsIterator{ .args = args }; while (it.next()) |arg| { if (mem.eql(u8, arg, "-h") or mem.eql(u8, arg, "--help")) { ctx.fatal(usage, .{cmd}); diff --git a/src/Wasm/Symbol.zig b/src/Wasm/Symbol.zig index c928f615..71217381 100644 --- a/src/Wasm/Symbol.zig +++ b/src/Wasm/Symbol.zig @@ -74,7 +74,7 @@ pub const Flag = enum(u32) { /// Indicates a symbol is TLS WASM_SYM_TLS = 0x100, - /// Zld specific flag. Uses the most significant bit of the flag to annotate whether a symbol is + /// Emerald specific flag. Uses the most significant bit of the flag to annotate whether a symbol is /// alive or not. Dead symbols are allowed to be garbage collected. alive = 0x80000000, }; diff --git a/src/Wasm/emit_wasm.zig b/src/Wasm/emit_wasm.zig index dd13fb4d..e83d5650 100644 --- a/src/Wasm/emit_wasm.zig +++ b/src/Wasm/emit_wasm.zig @@ -589,7 +589,7 @@ fn emitProducerSection(wasm: *const Wasm, bytes: *std.ArrayList(u8)) !void { } else processed_map.deinit(); try processed_map.put(.{ - .value = try wasm.base.allocator.dupe(u8, "Zld"), + .value = try wasm.base.allocator.dupe(u8, "Emerald"), .version = try wasm.base.allocator.dupe(u8, "0.1"), }, {}); @@ -665,7 +665,7 @@ fn emitProducerSection(wasm: *const Wasm, bytes: *std.ArrayList(u8)) !void { } } - // processed-by field (this is never empty as it's always populated by Zld itself) + // processed-by field (this is never empty as it's always populated by Emerald itself) { const processed_by = "processed-by"; try leb.writeULEB128(writer, @as(u32, @intCast(processed_by.len))); @@ -675,7 +675,7 @@ fn emitProducerSection(wasm: *const Wasm, bytes: *std.ArrayList(u8)) !void { // versioned name for (processed_map.keys()) |field| { - try leb.writeULEB128(writer, @as(u32, @intCast(field.value.len))); // len of "Zld" + try leb.writeULEB128(writer, @as(u32, @intCast(field.value.len))); // len of "Emerald" try writer.writeAll(field.value); try leb.writeULEB128(writer, @as(u32, @intCast(field.version.len))); diff --git a/src/main.zig b/src/main.zig index 0f4a57e3..1a3a6439 100644 --- a/src/main.zig +++ b/src/main.zig @@ -6,7 +6,7 @@ const tracy = @import("tracy.zig"); const Allocator = mem.Allocator; const ThreadPool = std.Thread.Pool; -const Zld = @import("Zld.zig"); +const Ld = @import("Ld.zig"); var tracy_alloc = tracy.tracyAllocator(std.heap.c_allocator); @@ -16,12 +16,12 @@ else std.heap.c_allocator; const usage = - \\zld is a generic linker driver. + \\emerald is a generic linker driver. \\Call - \\ ELF: ld.zld - \\ MachO: ld64.zld - \\ COFF: link-zld - \\ Wasm: wasm-zld + \\ ELF: ld.emerald + \\ MachO: ld64.emerald + \\ COFF: emerald-link.exe + \\ Wasm: wasm-emerald ; var log_scopes: std.ArrayList([]const u8) = std.ArrayList([]const u8).init(gpa); @@ -81,20 +81,20 @@ pub fn main() !void { const all_args = try std.process.argsAlloc(arena); const cmd = std.fs.path.basename(all_args[0]); - const tag: Zld.Tag = blk: { + const tag: Ld.Tag = blk: { if (mem.eql(u8, cmd, "ld")) break :blk switch (builtin.target.ofmt) { .elf => .elf, .macho => .macho, .coff => .coff, .wasm => .wasm, else => |other| fatal("unsupported file format '{s}'", .{@tagName(other)}), - } else if (mem.eql(u8, cmd, "ld.zld")) { + } else if (mem.eql(u8, cmd, "ld.emerald")) { break :blk .elf; - } else if (mem.eql(u8, cmd, "ld64.zld")) { + } else if (mem.eql(u8, cmd, "ld64.emerald")) { break :blk .macho; - } else if (mem.eql(u8, cmd, "link-zld.exe")) { + } else if (mem.eql(u8, cmd, "emerald-link.exe")) { break :blk .coff; - } else if (mem.eql(u8, cmd, "wasm-zld")) { + } else if (mem.eql(u8, cmd, "wasm-emerald")) { break :blk .wasm; } else { std.io.getStdOut().writeAll(usage) catch {}; @@ -102,7 +102,7 @@ pub fn main() !void { } }; - const opts = try Zld.Options.parse(arena, tag, all_args[1..], .{ + const opts = try Ld.Options.parse(arena, tag, all_args[1..], .{ .print = print, .fatal = fatal, .log_scopes = &log_scopes, @@ -112,9 +112,9 @@ pub fn main() !void { try thread_pool.init(.{ .allocator = gpa }); defer thread_pool.deinit(); - const zld = try Zld.openPath(gpa, tag, opts, &thread_pool); - defer zld.deinit(); - zld.flush() catch |err| switch (err) { + const ld = try Ld.openPath(gpa, tag, opts, &thread_pool); + defer ld.deinit(); + ld.flush() catch |err| switch (err) { error.FlushFailed, error.InferCpuFailed, error.ParseFailed, @@ -124,15 +124,15 @@ pub fn main() !void { error.ResolveFailed, error.Unimplemented, => { - zld.reportWarnings(); - zld.reportErrors(); + ld.reportWarnings(); + ld.reportErrors(); std.process.exit(1); }, else => |e| { - zld.reportErrors(); + ld.reportErrors(); print("unexpected linker error: {s}\n", .{@errorName(e)}); return e; }, }; - zld.reportWarnings(); + ld.reportWarnings(); } diff --git a/test/coff.zig b/test/coff.zig index 02d1de27..1fb0f14c 100644 --- a/test/coff.zig +++ b/test/coff.zig @@ -4,7 +4,7 @@ pub fn addCoffTests(b: *Build, options: common.Options) *Step { if (builtin.target.ofmt != .coff) return skipTestStep(coff_step); const opts = Options{ - .zld = options.zld, + .ld = options.ld, }; coff_step.dependOn(testHelloDynamic(b, opts)); @@ -39,13 +39,13 @@ fn cl(b: *Build, name: []const u8, opts: Options) SysCmd { fn ld(b: *Build, name: []const u8, opts: Options) SysCmd { const cmd = Run.create(b, "ld"); - cmd.addFileArg(opts.zld); + cmd.addFileArg(opts.ld); const out = cmd.addPrefixedOutputFileArg("/out:", name); return .{ .cmd = cmd, .out = out }; } const Options = struct { - zld: LazyPath, + ld: LazyPath, }; const std = @import("std"); diff --git a/test/elf.zig b/test/elf.zig index 997af5a8..70955f5b 100644 --- a/test/elf.zig +++ b/test/elf.zig @@ -4,7 +4,7 @@ pub fn addElfTests(b: *Build, options: common.Options) *Step { if (builtin.target.ofmt != .elf) return skipTestStep(elf_step); const opts = Options{ - .zld = options.zld, + .ld = options.ld, .is_musl = options.is_musl, .has_zig = options.has_zig, .has_static = options.has_static, @@ -310,7 +310,7 @@ fn testComment(b: *Build, opts: Options) *Step { const check = exe.check(); check.dumpSection(".comment"); - check.checkContains("ld.zld"); + check.checkContains("ld.emerald"); test_step.dependOn(&check.step); return test_step; @@ -3718,7 +3718,7 @@ fn cc(b: *Build, name: []const u8, opts: Options) SysCmd { cmd.addArgs(&.{ opts.cc_override orelse "cc", "-fno-lto" }); cmd.addArg("-o"); const out = cmd.addOutputFileArg(name); - cmd.addPrefixedDirectorySourceArg("-B", opts.zld.dirname()); + cmd.addPrefixedDirectorySourceArg("-B", opts.ld.dirname()); return .{ .cmd = cmd, .out = out }; } @@ -3731,7 +3731,7 @@ fn ar(b: *Build, name: []const u8) SysCmd { fn ld(b: *Build, name: []const u8, opts: Options) SysCmd { const cmd = Run.create(b, "ld"); - cmd.addFileArg(opts.zld); + cmd.addFileArg(opts.ld); cmd.addArg("-o"); const out = cmd.addOutputFileArg(name); return .{ .cmd = cmd, .out = out }; @@ -3745,7 +3745,7 @@ fn zig(b: *Build, name: []const u8, comptime mode: enum { obj, exe, lib }) SysCm } const Options = struct { - zld: LazyPath, + ld: LazyPath, system_compiler: common.SystemCompiler, has_static: bool, has_zig: bool, diff --git a/test/macho.zig b/test/macho.zig index 60b57bbe..90b1fc75 100644 --- a/test/macho.zig +++ b/test/macho.zig @@ -4,7 +4,7 @@ pub fn addMachOTests(b: *Build, options: common.Options) *Step { if (builtin.target.os.tag != .macos) return skipTestStep(macho_step); var opts = Options{ - .zld = options.zld, + .ld = options.ld, .has_zig = options.has_zig, .has_objc_msgsend_stubs = options.has_objc_msgsend_stubs, .macos_sdk = undefined, @@ -4103,7 +4103,7 @@ fn testWeakRef2(b: *Build, opts: Options) *Step { } const Options = struct { - zld: LazyPath, + ld: LazyPath, has_zig: bool, has_objc_msgsend_stubs: bool, macos_sdk: []const u8, @@ -4116,7 +4116,7 @@ fn cc(b: *Build, name: []const u8, opts: Options) SysCmd { cmd.addArgs(&.{ opts.cc_override orelse "cc", "-fno-lto" }); cmd.addArg("-o"); const out = cmd.addOutputFileArg(name); - cmd.addPrefixedDirectorySourceArg("-B", opts.zld.dirname()); + cmd.addPrefixedDirectorySourceArg("-B", opts.ld.dirname()); return .{ .cmd = cmd, .out = out }; } @@ -4143,7 +4143,7 @@ fn lipo(b: *Build, name: []const u8) SysCmd { fn ld(b: *Build, name: []const u8, opts: Options) SysCmd { const cmd = Run.create(b, "ld"); - cmd.addFileArg(opts.zld); + cmd.addFileArg(opts.ld); cmd.addArg("-o"); const out = cmd.addOutputFileArg(name); return .{ .cmd = cmd, .out = out }; diff --git a/test/test.zig b/test/test.zig index 2c04d365..ea2b1b56 100644 --- a/test/test.zig +++ b/test/test.zig @@ -19,9 +19,9 @@ pub fn addTests(b: *Build, comp: *Compile, build_opts: struct { error.InvalidWtf8 => @panic("InvalidWtf8"), error.OutOfMemory => @panic("OOM"), }; - const zld = WriteFile.create(b).addCopyFile(comp.getEmittedBin(), "ld"); + const ld = WriteFile.create(b).addCopyFile(comp.getEmittedBin(), "ld"); const opts: Options = .{ - .zld = zld, + .ld = ld, .system_compiler = system_compiler, .has_static = build_opts.has_static, .has_zig = build_opts.has_zig, @@ -43,7 +43,7 @@ pub const SystemCompiler = enum { }; pub const Options = struct { - zld: LazyPath, + ld: LazyPath, system_compiler: SystemCompiler, has_static: bool = false, has_zig: bool = false,