Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

macho: implement -r mode #95

Merged
merged 42 commits into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
6ca25c7
macho: recognise -r flag and error as unimplemented
kubkon Dec 26, 2023
1473324
macho: forgot to commit relocatable.zig
kubkon Dec 28, 2023
6b4f895
macho: init output sections in relocatable mode
kubkon Dec 28, 2023
33d20d0
macho: calculate alloc section sizes
kubkon Dec 28, 2023
6a9208b
macho: calculate __compact_unwind and __eh_frame sizes
kubkon Dec 31, 2023
987a478
macho: allocate sections for object file
kubkon Dec 31, 2023
e9f632b
macho: allocate segment in relocatable mode
kubkon Dec 31, 2023
edaacf8
macho: allocate atoms in relocatable mode
kubkon Jan 1, 2024
35d5f02
macho: write __compact_unwind and __eh_frame
kubkon Jan 1, 2024
55473fd
macho: move calc of next __LINKEDIT offset outside of each func
kubkon Jan 1, 2024
97eaf22
macho: write well-formed relocatable object file
kubkon Jan 1, 2024
9f2ad6e
macho: preserve exports in relocatable mode
kubkon Jan 1, 2024
5c4a931
macho: unconditionally emit ALL local symbols in -r mode
kubkon Jan 1, 2024
5299045
macho: actually emit __compact_unwind section
kubkon Jan 1, 2024
606772d
macho: set data-in-code cmd to next available file offset
kubkon Jan 2, 2024
9bf929f
macho: calc number of relocations for each section
kubkon Jan 2, 2024
72b570a
macho: allocate reloffs when allocating sections
kubkon Jan 3, 2024
a8691e7
macho: emit relocs for atoms
kubkon Jan 3, 2024
406f4c1
macho: addend for unsigned needs to be written to code buffer
kubkon Jan 3, 2024
cb1f179
macho: emit __compact_unwind relocs
kubkon Jan 3, 2024
27f1aa2
macho: create atoms for __DWARF, input __compact_unwind and __eh_fram…
kubkon Jan 3, 2024
5161cff
macho: skip null unwind recs synthesis in -r; fix relocs in -r; test
kubkon Jan 3, 2024
535f932
macho: write atom relocs for x86_64 arch
kubkon Jan 3, 2024
16e5ccc
macho: write relocated __eh_frame records; fix writing into invalid L…
kubkon Jan 3, 2024
4a2fb86
macho: fix writing local relocs (non-externs)
kubkon Jan 3, 2024
e1337f1
macho: do not emit stabs in -r mode
kubkon Jan 4, 2024
a22df16
macho: error out on unhandled input stab symbols
kubkon Jan 4, 2024
7681146
macho: fix file mode in -r mode
kubkon Jan 4, 2024
9037d58
macho: emit __DWARF in -r mode (incomplete)
kubkon Jan 4, 2024
63454c1
macho: partially revert: emit __DWARF in -r mode (incomplete)
kubkon Jan 4, 2024
811e3f3
macho: write out stabs in -r mode; skip them when linking image
kubkon Jan 4, 2024
ab50dcb
macho: copy over symbol stabs from input object files
kubkon Jan 4, 2024
cf35be7
macho: fix applying __eh_frame records after -r
kubkon Jan 4, 2024
d9410be
macho: fix generating valid debug info in -r mode
kubkon Jan 5, 2024
fe08a6b
macho: flag an error when parsing __DWARF fails
kubkon Jan 5, 2024
d917206
macho: almost update to latest zig changes
kubkon Jan 6, 2024
197c4bb
macho: fix dylib test
kubkon Jan 6, 2024
a2a719c
macho: fix entry in dylib test
kubkon Jan 6, 2024
9dd651d
macho: fix fat dylib test
kubkon Jan 6, 2024
e3dacf8
macho: fix link order test
kubkon Jan 6, 2024
004a609
macho: fix tls test
kubkon Jan 6, 2024
832770e
elf: update to latest Zig build api
kubkon Jan 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const tests = @import("test/test.zig");

const Allocator = std.mem.Allocator;

pub fn build(b: *std.Build.Builder) void {
pub fn build(b: *std.Build) void {
const target = b.standardTargetOptions(.{});
const mode = b.standardOptimizeOption(.{});

Expand All @@ -27,12 +27,12 @@ pub fn build(b: *std.Build.Builder) void {
.target = target,
.optimize = mode,
});
exe.addModule("yaml", yaml.module("yaml"));
exe.addModule("dis_x86_64", dis_x86_64.module("dis_x86_64"));
exe.root_module.addImport("yaml", yaml.module("yaml"));
exe.root_module.addImport("dis_x86_64", dis_x86_64.module("dis_x86_64"));
exe.linkLibC();

const exe_opts = b.addOptions();
exe.addOptions("build_options", exe_opts);
exe.root_module.addOptions("build_options", exe_opts);
exe_opts.addOption(bool, "enable_logging", enable_logging);
exe_opts.addOption(bool, "enable_tracy", enable_tracy != null);

Expand All @@ -43,17 +43,17 @@ pub fn build(b: *std.Build.Builder) void {
) catch unreachable;

// On mingw, we need to opt into windows 7+ to get some features required by tracy.
const tracy_c_flags: []const []const u8 = if (target.isWindows() and target.getAbi() == .gnu)
const tracy_c_flags: []const []const u8 = if (target.result.os.tag == .windows and target.result.abi == .gnu)
&[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined", "-D_WIN32_WINNT=0x601" }
else
&[_][]const u8{ "-DTRACY_ENABLE=1", "-fno-sanitize=undefined" };

exe.addIncludePath(.{ .cwd_relative = tracy_path });
exe.addCSourceFile(.{ .file = .{ .cwd_relative = client_cpp }, .flags = tracy_c_flags });
exe.linkSystemLibraryName("c++");
exe.strip = false;
exe.root_module.linkSystemLibrary("c++", .{ .use_pkg_config = .no });
exe.root_module.strip = false;

if (target.isWindows()) {
if (target.result.os.tag == .windows) {
exe.linkSystemLibrary("dbghelp");
exe.linkSystemLibrary("ws2_32");
}
Expand All @@ -78,11 +78,11 @@ pub fn build(b: *std.Build.Builder) void {
.optimize = mode,
});
const unit_tests_opts = b.addOptions();
unit_tests.addOptions("build_options", unit_tests_opts);
unit_tests.root_module.addOptions("build_options", unit_tests_opts);
unit_tests_opts.addOption(bool, "enable_logging", enable_logging);
unit_tests_opts.addOption(bool, "enable_tracy", enable_tracy != null);
unit_tests.addModule("yaml", yaml.module("yaml"));
unit_tests.addModule("dis_x86_64", dis_x86_64.module("dis_x86_64"));
unit_tests.root_module.addImport("yaml", yaml.module("yaml"));
unit_tests.root_module.addImport("dis_x86_64", dis_x86_64.module("dis_x86_64"));
unit_tests.linkLibC();

const test_step = b.step("test", "Run tests");
Expand All @@ -96,8 +96,8 @@ pub fn build(b: *std.Build.Builder) void {
}

fn addSymlinks(
builder: *std.Build.Builder,
install: *std.Build.InstallArtifactStep,
builder: *std.Build,
install: *std.Build.Step.InstallArtifact,
names: []const []const u8,
) *CreateSymlinksStep {
const step = CreateSymlinksStep.create(builder, install, names);
Expand All @@ -109,13 +109,13 @@ const CreateSymlinksStep = struct {
pub const base_id = .custom;

step: std.Build.Step,
builder: *std.Build.Builder,
install: *std.Build.InstallArtifactStep,
builder: *std.Build,
install: *std.Build.Step.InstallArtifact,
targets: []const []const u8,

pub fn create(
builder: *std.Build.Builder,
install: *std.Build.InstallArtifactStep,
builder: *std.Build,
install: *std.Build.Step.InstallArtifact,
targets: []const []const u8,
) *CreateSymlinksStep {
const self = builder.allocator.create(CreateSymlinksStep) catch unreachable;
Expand All @@ -135,7 +135,7 @@ const CreateSymlinksStep = struct {

fn make(step: *std.Build.Step, prog_node: *std.Progress.Node) anyerror!void {
const self = @fieldParentPtr(CreateSymlinksStep, "step", step);
const install_path = self.install.artifact.getOutputSource().getPath(self.builder);
const install_path = self.install.artifact.getEmittedBin().getPath(self.builder);
const rel_source = fs.path.basename(install_path);

var node = prog_node.start("creating symlinks", self.targets.len);
Expand Down
8 changes: 4 additions & 4 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

.dependencies = .{
.@"zig-yaml" = .{
.url = "https://github.com/kubkon/zig-yaml/archive/1ed4925bed911b73a189526a6ad82bd8c5c2079a.tar.gz",
.hash = "1220f56d186377820d7ad62ee03987acdd53bc24da83e8f6dff571bc7343f789f69a",
.url = "https://github.com/kubkon/zig-yaml/archive/953bf8e9a10386eb3756d3fc722df634d0d634a9.tar.gz",
.hash = "1220b174728272a3e4b38c27a37bd76e9749fad1668c24538cd8110353e87306360b",
},
.@"zig-dis-x86_64" = .{
.url = "https://github.com/kubkon/zig-dis-x86_64/archive/a9155631990aa6d56fa06fddef304cabb94a0681.tar.gz",
.hash = "1220a4d63ba372f6b5a0fc262f863572dc119727b469f6ccf527ad91790e353bb0f0",
.url = "https://github.com/kubkon/zig-dis-x86_64/archive/752655a8feca210880abb8f1be5acad8e7f4961a.tar.gz",
.hash = "1220591498890a10351d6cadc52cf07a594baeabd7eef7fe3e7a7f43960a3398edea",
},
},

Expand Down
Loading