Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
107 changes: 1 addition & 106 deletions lib/std/c.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1841,110 +1841,6 @@ pub const PROT = switch (native_os) {
else => void,
};

pub const REG = switch (native_os) {
.linux => linux.REG,
.emscripten => emscripten.REG,
.freebsd => switch (builtin.cpu.arch) {
.aarch64 => struct {
pub const FP = 29;
pub const SP = 31;
pub const PC = 32;
},
.arm => struct {
pub const FP = 11;
pub const SP = 13;
pub const PC = 15;
},
.x86_64 => struct {
pub const RBP = 12;
pub const RIP = 21;
pub const RSP = 24;
},
else => struct {},
},
.solaris, .illumos => struct {
pub const R15 = 0;
pub const R14 = 1;
pub const R13 = 2;
pub const R12 = 3;
pub const R11 = 4;
pub const R10 = 5;
pub const R9 = 6;
pub const R8 = 7;
pub const RDI = 8;
pub const RSI = 9;
pub const RBP = 10;
pub const RBX = 11;
pub const RDX = 12;
pub const RCX = 13;
pub const RAX = 14;
pub const RIP = 17;
pub const RSP = 20;
},
.netbsd => switch (builtin.cpu.arch) {
.aarch64, .aarch64_be => struct {
pub const FP = 29;
pub const SP = 31;
pub const PC = 32;
},
.arm, .armeb => struct {
pub const FP = 11;
pub const SP = 13;
pub const PC = 15;
},
.x86 => struct {
pub const GS = 0;
pub const FS = 1;
pub const ES = 2;
pub const DS = 3;
pub const EDI = 4;
pub const ESI = 5;
pub const EBP = 6;
pub const ESP = 7;
pub const EBX = 8;
pub const EDX = 9;
pub const ECX = 10;
pub const EAX = 11;
pub const TRAPNO = 12;
pub const ERR = 13;
pub const EIP = 14;
pub const CS = 15;
pub const EFL = 16;
pub const UESP = 17;
pub const SS = 18;
},
.x86_64 => struct {
pub const RDI = 0;
pub const RSI = 1;
pub const RDX = 2;
pub const RCX = 3;
pub const R8 = 4;
pub const R9 = 5;
pub const R10 = 6;
pub const R11 = 7;
pub const R12 = 8;
pub const R13 = 9;
pub const R14 = 10;
pub const R15 = 11;
pub const RBP = 12;
pub const RBX = 13;
pub const RAX = 14;
pub const GS = 15;
pub const FS = 16;
pub const ES = 17;
pub const DS = 18;
pub const TRAPNO = 19;
pub const ERR = 20;
pub const RIP = 21;
pub const CS = 22;
pub const RFLAGS = 23;
pub const RSP = 24;
pub const SS = 25;
},
else => struct {},
},
else => struct {},
};
pub const RLIM = switch (native_os) {
.linux => linux.RLIM,
.emscripten => emscripten.RLIM,
Expand Down Expand Up @@ -4553,7 +4449,7 @@ pub const rusage = switch (native_os) {
pub const siginfo_t = switch (native_os) {
.linux => linux.siginfo_t,
.emscripten => emscripten.siginfo_t,
.macos, .ios, .tvos, .watchos, .visionos => extern struct {
.driverkit, .macos, .ios, .tvos, .watchos, .visionos => extern struct {
signo: c_int,
errno: c_int,
code: c_int,
Expand Down Expand Up @@ -11084,7 +10980,6 @@ pub const SETUSTACK = solaris.GETUSTACK;
pub const SFD = solaris.SFD;
pub const ctid_t = solaris.ctid_t;
pub const file_obj = solaris.file_obj;
pub const fpregset_t = solaris.fpregset_t;
pub const id_t = solaris.id_t;
pub const lif_ifinfo_req = solaris.lif_ifinfo_req;
pub const lif_nd_req = solaris.lif_nd_req;
Expand Down
23 changes: 0 additions & 23 deletions lib/std/c/solaris.zig
Original file line number Diff line number Diff line change
Expand Up @@ -31,29 +31,6 @@ pub const poolid_t = id_t;
pub const zoneid_t = id_t;
pub const ctid_t = id_t;

pub const fpregset_t = extern union {
regs: [130]u32,
chip_state: extern struct {
cw: u16,
sw: u16,
fctw: u8,
__fx_rsvd: u8,
fop: u16,
rip: u64,
rdp: u64,
mxcsr: u32,
mxcsr_mask: u32,
st: [8]extern union {
fpr_16: [5]u16,
__fpr_pad: u128,
},
xmm: [16]u128,
__fx_ign2: [6]u128,
status: u32,
xstatus: u32,
},
};

pub const GETCONTEXT = 0;
pub const SETCONTEXT = 1;
pub const GETUSTACK = 2;
Expand Down
55 changes: 42 additions & 13 deletions lib/std/debug.zig
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ pub const SelfInfo = if (@hasDecl(root, "debug") and @hasDecl(root.debug, "SelfI
root.debug.SelfInfo
else switch (std.Target.ObjectFormat.default(native_os, native_arch)) {
.coff => if (native_os == .windows) @import("debug/SelfInfo/Windows.zig") else void,
.elf => @import("debug/SelfInfo/Elf.zig"),
.elf => switch (native_os) {
.freestanding, .other => void,
else => @import("debug/SelfInfo/Elf.zig"),
},
.macho => @import("debug/SelfInfo/MachO.zig"),
.goff, .plan9, .spirv, .wasm, .xcoff => void,
.c, .hex, .raw => unreachable,
Expand Down Expand Up @@ -985,15 +988,15 @@ const StackIterator = union(enum) {
// On RISC-V the frame pointer points to the top of the saved register
// area, on pretty much every other architecture it points to the stack
// slot where the previous frame pointer is saved.
if (native_arch.isRISCV()) break :off -2 * @sizeOf(usize);
if (native_arch.isLoongArch() or native_arch.isRISCV()) break :off -2 * @sizeOf(usize);
// On SPARC the previous frame pointer is stored at 14 slots past %fp+BIAS.
if (native_arch.isSPARC()) break :off 14 * @sizeOf(usize);
break :off 0;
};

/// Offset of the saved return address wrt the frame pointer.
const ra_offset = off: {
if (native_arch.isRISCV()) break :off -1 * @sizeOf(usize);
if (native_arch.isLoongArch() or native_arch.isRISCV()) break :off -1 * @sizeOf(usize);
if (native_arch.isSPARC()) break :off 15 * @sizeOf(usize);
if (native_arch.isPowerPC64()) break :off 2 * @sizeOf(usize);
// On s390x, r14 is the link register and we need to grab it from its customary slot in the
Expand Down Expand Up @@ -1312,15 +1315,26 @@ fn getDebugInfoAllocator() Allocator {

/// Whether or not the current target can print useful debug information when a segfault occurs.
pub const have_segfault_handling_support = switch (native_os) {
.haiku,
.linux,
.macos,
.serenity,

.dragonfly,
.freebsd,
.netbsd,
.solaris,
.openbsd,

.driverkit,
.ios,
.macos,
.tvos,
.visionos,
.watchos,

.illumos,
.solaris,

.windows,
.freebsd,
.openbsd,
.serenity,
=> true,

else => false,
Expand Down Expand Up @@ -1403,11 +1417,26 @@ fn handleSegfaultPosix(sig: i32, info: *const posix.siginfo_t, ctx_ptr: ?*anyopa
}
}
const addr: usize = switch (native_os) {
.linux => @intFromPtr(info.fields.sigfault.addr),
.freebsd, .macos, .serenity => @intFromPtr(info.addr),
.netbsd => @intFromPtr(info.info.reason.fault.addr),
.openbsd => @intFromPtr(info.data.fault.addr),
.solaris, .illumos => @intFromPtr(info.reason.fault.addr),
.serenity,
.dragonfly,
.freebsd,
.driverkit,
.ios,
.macos,
.tvos,
.visionos,
.watchos,
=> @intFromPtr(info.addr),
.linux,
=> @intFromPtr(info.fields.sigfault.addr),
.netbsd,
=> @intFromPtr(info.info.reason.fault.addr),
.haiku,
.openbsd,
=> @intFromPtr(info.data.fault.addr),
.illumos,
.solaris,
=> @intFromPtr(info.reason.fault.addr),
else => comptime unreachable,
};
const name = switch (sig) {
Expand Down
50 changes: 41 additions & 9 deletions lib/std/debug/SelfInfo/Elf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ pub const can_unwind: bool = s: {
// Notably, we are yet to support unwinding on ARM. There, unwinding is not done through
// `.eh_frame`, but instead with the `.ARM.exidx` section, which has a different format.
const archs: []const std.Target.Cpu.Arch = switch (builtin.target.os.tag) {
// Not supported yet: arm, m68k, sparc64
.haiku => &.{
.aarch64,
.powerpc,
.riscv64,
.x86,
.x86_64,
},
// Not supported yet: arc, arm/armeb/thumb/thumbeb, csky, m68k, or1k, sparc/sparc64, xtensa
.linux => &.{
.aarch64,
.aarch64_be,
Expand All @@ -113,31 +122,54 @@ pub const can_unwind: bool = s: {
.x86,
.x86_64,
},
.netbsd => &.{
.serenity => &.{
.aarch64,
.aarch64_be,
.x86,
.x86_64,
.riscv64,
},
.freebsd => &.{

.dragonfly => &.{
.x86_64,
},
// Not supported yet: arm
.freebsd => &.{
.aarch64,
.powerpc64,
.powerpc64le,
.riscv64,
.x86_64,
},
.openbsd => &.{
// Not supported yet: arm/armeb, m68k, mips64/mips64el, sparc/sparc64
.netbsd => &.{
.aarch64,
.aarch64_be,
.mips,
.mipsel,
.powerpc,
.x86,
.x86_64,
},
.solaris => &.{
// Not supported yet: arm, sparc64
.openbsd => &.{
.aarch64,
.mips64,
.mips64el,
.powerpc,
.powerpc64,
.riscv64,
.x86,
.x86_64,
},

.illumos => &.{
.x86,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Illumos and Solaris haven't supported x86 for a while now. You can run old binaries but it's discouraged to create new ones.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know Solaris hasn't, but illumos seems to still support userspace 32-bit applications? http://www.tribblix.org/32bit.html

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It only matters how you define can_unwind:

  1. Does this arch-os-abi combo support unwinding?
  2. Does the Zig compiler emit code for this combo?

If 2 doesn't matter then you may as well add x86 to Solaris as well. It seems like it doesn't since sparc64-solaris isn't there.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sparc64-solaris is just a to-do along with sparc64-linux and others; I'll do a later pull request that adds full SPARC unwinding to all of std.debug (unless @mlugg beats me to it?).

In general, I'm going off test/llvm_targets.zig for what targets are relevant here. That file in turn boils down to which targets are still supported by the developers/vendor of the OS. If a target is missing here, it's probably because it's missing in test/llvm_targets.zig, while a @compileError represents work to be done.

That said, I'm not sure I entirely understand point 2; the Zig compiler should in theory be able to emit code for x86-solaris, sparc-solaris, sparc64-solaris, etc. It's just that if a target is effectively dead and no one cares about it, we're not going to bother maintaining code paths for it.

.x86_64,
},
.serenity => &.{
// Not supported yet: sparc64
.solaris => &.{
.x86_64,
.aarch64,
.riscv64,
},

else => unreachable,
};
for (archs) |a| {
Expand Down
Loading