Skip to content

Commit

Permalink
Merge pull request #8282 from kubkon/zld
Browse files Browse the repository at this point in the history
macho: upstream zld linker
  • Loading branch information
kubkon committed Mar 18, 2021
2 parents b54514d + f3b4f79 commit 17c066e
Show file tree
Hide file tree
Showing 10 changed files with 3,794 additions and 306 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Expand Up @@ -564,7 +564,14 @@ set(ZIG_STAGE2_SOURCES
"${CMAKE_SOURCE_DIR}/src/link/Coff.zig"
"${CMAKE_SOURCE_DIR}/src/link/Elf.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/Archive.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/CodeSignature.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/DebugSymbols.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/Object.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/Trie.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/Zld.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/bind.zig"
"${CMAKE_SOURCE_DIR}/src/link/MachO/commands.zig"
"${CMAKE_SOURCE_DIR}/src/link/Wasm.zig"
"${CMAKE_SOURCE_DIR}/src/link/C/zig.h"
"${CMAKE_SOURCE_DIR}/src/link/msdos-stub.bin"
Expand Down
18 changes: 0 additions & 18 deletions lib/std/debug.zig
Expand Up @@ -250,24 +250,6 @@ pub fn panicExtra(trace: ?*const builtin.StackTrace, first_trace_addr: ?usize, c
resetSegfaultHandler();
}

if (comptime std.Target.current.isDarwin() and std.Target.current.cpu.arch == .aarch64)
nosuspend {
// As a workaround for not having threadlocal variable support in LLD for this target,
// we have a simpler panic implementation that does not use threadlocal variables.
// TODO https://github.com/ziglang/zig/issues/7527
const stderr = io.getStdErr().writer();
if (@atomicRmw(u8, &panicking, .Add, 1, .SeqCst) == 0) {
stderr.print("panic: " ++ format ++ "\n", args) catch os.abort();
if (trace) |t| {
dumpStackTrace(t.*);
}
dumpCurrentStackTrace(first_trace_addr);
} else {
stderr.print("Panicked during a panic. Aborting.\n", .{}) catch os.abort();
}
os.abort();
};

nosuspend switch (panic_stage) {
0 => {
panic_stage = 1;
Expand Down
32 changes: 32 additions & 0 deletions lib/std/macho.zig
Expand Up @@ -1227,6 +1227,24 @@ pub const S_ATTR_EXT_RELOC = 0x200;
/// section has local relocation entries
pub const S_ATTR_LOC_RELOC = 0x100;

/// template of initial values for TLVs
pub const S_THREAD_LOCAL_REGULAR = 0x11;

/// template of initial values for TLVs
pub const S_THREAD_LOCAL_ZEROFILL = 0x12;

/// TLV descriptors
pub const S_THREAD_LOCAL_VARIABLES = 0x13;

/// pointers to TLV descriptors
pub const S_THREAD_LOCAL_VARIABLE_POINTERS = 0x14;

/// functions to call to initialize TLV values
pub const S_THREAD_LOCAL_INIT_FUNCTION_POINTERS = 0x15;

/// 32-bit offsets to initializers
pub const S_INIT_FUNC_OFFSETS = 0x16;

pub const cpu_type_t = integer_t;
pub const cpu_subtype_t = integer_t;
pub const integer_t = c_int;
Expand Down Expand Up @@ -1597,3 +1615,17 @@ pub const GenericBlob = extern struct {
/// Total length of blob
length: u32,
};

/// The LC_DATA_IN_CODE load commands uses a linkedit_data_command
/// to point to an array of data_in_code_entry entries. Each entry
/// describes a range of data in a code section.
pub const data_in_code_entry = extern struct {
/// From mach_header to start of data range.
offset: u32,

/// Number of bytes in data range.
length: u16,

/// A DICE_KIND value.
kind: u16,
};
5 changes: 4 additions & 1 deletion src/codegen/aarch64.zig
Expand Up @@ -221,7 +221,8 @@ pub const Instruction = union(enum) {
offset: u12,
opc: u2,
op1: u2,
fixed: u4 = 0b111_0,
v: u1,
fixed: u3 = 0b111,
size: u2,
},
LoadStorePairOfRegisters: packed struct {
Expand Down Expand Up @@ -505,6 +506,7 @@ pub const Instruction = union(enum) {
.offset = offset.toU12(),
.opc = opc,
.op1 = op1,
.v = 0,
.size = 0b10,
},
};
Expand All @@ -517,6 +519,7 @@ pub const Instruction = union(enum) {
.offset = offset.toU12(),
.opc = opc,
.op1 = op1,
.v = 0,
.size = 0b11,
},
};
Expand Down

0 comments on commit 17c066e

Please sign in to comment.