mirror of
https://github.com/ziglang/zig.git
synced 2024-11-26 23:22:44 +00:00
compilation: pass omit_frame_pointer through to builtin.zig
Renamed dwarf_unwinding -> stack_iterator to better reflect that it's not just DWARF unwinding. Added a test for unwinding with a frame pointer.
This commit is contained in:
parent
7d8b423477
commit
ec96095efd
@ -5288,6 +5288,7 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: Allocator) Alloca
|
|||||||
\\pub const position_independent_executable = {};
|
\\pub const position_independent_executable = {};
|
||||||
\\pub const strip_debug_info = {};
|
\\pub const strip_debug_info = {};
|
||||||
\\pub const code_model = std.builtin.CodeModel.{};
|
\\pub const code_model = std.builtin.CodeModel.{};
|
||||||
|
\\pub const omit_frame_pointer = {};
|
||||||
\\
|
\\
|
||||||
, .{
|
, .{
|
||||||
std.zig.fmtId(@tagName(target.ofmt)),
|
std.zig.fmtId(@tagName(target.ofmt)),
|
||||||
@ -5301,6 +5302,7 @@ pub fn generateBuiltinZigSource(comp: *Compilation, allocator: Allocator) Alloca
|
|||||||
comp.bin_file.options.pie,
|
comp.bin_file.options.pie,
|
||||||
comp.bin_file.options.strip,
|
comp.bin_file.options.strip,
|
||||||
std.zig.fmtId(@tagName(comp.bin_file.options.machine_code_model)),
|
std.zig.fmtId(@tagName(comp.bin_file.options.machine_code_model)),
|
||||||
|
comp.bin_file.options.omit_frame_pointer,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (target.os.tag == .wasi) {
|
if (target.os.tag == .wasi) {
|
||||||
|
@ -510,7 +510,7 @@ pub fn clangAssemblerSupportsMcpuArg(target: std.Target) bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn needUnwindTables(target: std.Target) bool {
|
pub fn needUnwindTables(target: std.Target) bool {
|
||||||
return target.os.tag == .windows or target.ofmt == .macho;
|
return target.os.tag == .windows or target.isDarwin();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn defaultAddressSpace(
|
pub fn defaultAddressSpace(
|
||||||
|
@ -231,8 +231,8 @@ pub const build_cases = [_]BuildCase{
|
|||||||
.import = @import("standalone/zerolength_check/build.zig"),
|
.import = @import("standalone/zerolength_check/build.zig"),
|
||||||
},
|
},
|
||||||
.{
|
.{
|
||||||
.build_root = "test/standalone/dwarf_unwinding",
|
.build_root = "test/standalone/stack_iterator",
|
||||||
.import = @import("standalone/dwarf_unwinding/build.zig"),
|
.import = @import("standalone/stack_iterator/build.zig"),
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -7,10 +7,26 @@ pub fn build(b: *std.Build) void {
|
|||||||
const target = b.standardTargetOptions(.{});
|
const target = b.standardTargetOptions(.{});
|
||||||
const optimize = b.standardOptimizeOption(.{});
|
const optimize = b.standardOptimizeOption(.{});
|
||||||
|
|
||||||
// Test unwinding pure zig code (no libc)
|
// Unwinding pure zig code, with a frame pointer
|
||||||
{
|
{
|
||||||
const exe = b.addExecutable(.{
|
const exe = b.addExecutable(.{
|
||||||
.name = "zig_unwind",
|
.name = "zig_unwind_fp",
|
||||||
|
.root_source_file = .{ .path = "zig_unwind.zig" },
|
||||||
|
.target = target,
|
||||||
|
.optimize = optimize,
|
||||||
|
});
|
||||||
|
|
||||||
|
if (target.isDarwin()) exe.unwind_tables = true;
|
||||||
|
exe.omit_frame_pointer = false;
|
||||||
|
|
||||||
|
const run_cmd = b.addRunArtifact(exe);
|
||||||
|
test_step.dependOn(&run_cmd.step);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unwinding pure zig code, without a frame pointer
|
||||||
|
{
|
||||||
|
const exe = b.addExecutable(.{
|
||||||
|
.name = "zig_unwind_nofp",
|
||||||
.root_source_file = .{ .path = "zig_unwind.zig" },
|
.root_source_file = .{ .path = "zig_unwind.zig" },
|
||||||
.target = target,
|
.target = target,
|
||||||
.optimize = optimize,
|
.optimize = optimize,
|
||||||
@ -23,7 +39,7 @@ pub fn build(b: *std.Build) void {
|
|||||||
test_step.dependOn(&run_cmd.step);
|
test_step.dependOn(&run_cmd.step);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Test unwinding through a C shared library
|
// Unwinding through a C shared library without a frame pointer (libc)
|
||||||
{
|
{
|
||||||
const c_shared_lib = b.addSharedLibrary(.{
|
const c_shared_lib = b.addSharedLibrary(.{
|
||||||
.name = "c_shared_lib",
|
.name = "c_shared_lib",
|
@ -23,24 +23,44 @@ noinline fn frame2(expected: *[4]usize, unwound: *[4]usize) void {
|
|||||||
if (builtin.target.ofmt != .c) {
|
if (builtin.target.ofmt != .c) {
|
||||||
switch (builtin.cpu.arch) {
|
switch (builtin.cpu.arch) {
|
||||||
.x86 => {
|
.x86 => {
|
||||||
asm volatile (
|
if (builtin.omit_frame_pointer) {
|
||||||
\\movl $3, %%ebx
|
asm volatile (
|
||||||
\\movl $1, %%ecx
|
\\movl $3, %%ebx
|
||||||
\\movl $2, %%edx
|
\\movl $1, %%ecx
|
||||||
\\movl $7, %%edi
|
\\movl $2, %%edx
|
||||||
\\movl $6, %%esi
|
\\movl $7, %%edi
|
||||||
\\movl $5, %%ebp
|
\\movl $6, %%esi
|
||||||
::: "ebx", "ecx", "edx", "edi", "esi", "ebp");
|
\\movl $5, %%ebp
|
||||||
|
::: "ebx", "ecx", "edx", "edi", "esi", "ebp");
|
||||||
|
} else {
|
||||||
|
asm volatile (
|
||||||
|
\\movl $3, %%ebx
|
||||||
|
\\movl $1, %%ecx
|
||||||
|
\\movl $2, %%edx
|
||||||
|
\\movl $7, %%edi
|
||||||
|
\\movl $6, %%esi
|
||||||
|
::: "ebx", "ecx", "edx", "edi", "esi");
|
||||||
|
}
|
||||||
},
|
},
|
||||||
.x86_64 => {
|
.x86_64 => {
|
||||||
asm volatile (
|
if (builtin.omit_frame_pointer) {
|
||||||
\\movq $3, %%rbx
|
asm volatile (
|
||||||
\\movq $12, %%r12
|
\\movq $3, %%rbx
|
||||||
\\movq $13, %%r13
|
\\movq $12, %%r12
|
||||||
\\movq $14, %%r14
|
\\movq $13, %%r13
|
||||||
\\movq $15, %%r15
|
\\movq $14, %%r14
|
||||||
\\movq $6, %%rbp
|
\\movq $15, %%r15
|
||||||
::: "rbx", "r12", "r13", "r14", "r15", "rbp");
|
\\movq $6, %%rbp
|
||||||
|
::: "rbx", "r12", "r13", "r14", "r15", "rbp");
|
||||||
|
} else {
|
||||||
|
asm volatile (
|
||||||
|
\\movq $3, %%rbx
|
||||||
|
\\movq $12, %%r12
|
||||||
|
\\movq $13, %%r13
|
||||||
|
\\movq $14, %%r14
|
||||||
|
\\movq $15, %%r15
|
||||||
|
::: "rbx", "r12", "r13", "r14", "r15");
|
||||||
|
}
|
||||||
},
|
},
|
||||||
else => {},
|
else => {},
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user