Zig Version
0.9.1, on ArtixLinux x64, normal kernel, and hardened.
Steps to Reproduce
build.zig:
const std = @import("std");
pub fn build(b: *std.build.Builder) void {
const target = b.standardTargetOptions(.{});
const mode = b.standardReleaseOptions();
const exe = b.addExecutable("zigample", "src/main.zig");
exe.setTarget(target);
exe.setBuildMode(mode);
exe.linkSystemLibrary("GL");
exe.linkLibC();
exe.install();
const run_cmd = exe.run();
run_cmd.step.dependOn(b.getInstallStep());
if (b.args) |args| {
run_cmd.addArgs(args);
}
const run_step = b.step("run", "Run the app");
run_step.dependOn(&run_cmd.step);
}
main.zig:
const std = @import("std");
pub fn main() !void {
var testVar = "hello";
var general_purpose_allocator = std.heap.GeneralPurposeAllocator(.{}){};
const alloc = general_purpose_allocator.allocator();
var gameMap = try alloc.alloc(u8, testVar.len);
std.mem.copy(u8, gameMap, testVar);
const debug_info = std.debug.getSelfDebugInfo() catch unreachable;
const module = debug_info.getModuleForAddress(@returnAddress());
std.log.warn("hello {}", .{module});
//const builtin = @import("builtin");
//std.log.warn("hello {}", .{builtin.position_independent_executable});
std.debug.dumpCurrentStackTrace(@returnAddress());
_ = general_purpose_allocator.deinit();
}
Command to compile:
However, this works:
zig build-exe -lX11 -lGL src/main.zig
but this does not:
zig build-exe -lc -GL src/main
Appears to be happening when linking multiple/both libraries?
Expected Behavior
A bunch of gibberish for the first print, then:
/usr/lib/zig/std/start.zig:561:37: 0x22513a in std.start.callMain (main)
const result = root.main() catch |err| {
^
/usr/lib/zig/std/start.zig:495:12: 0x206497 in std.start.callMainWithArgs (main)
return @call(.{ .modifier = .always_inline }, callMain, .{});
^
/usr/lib/zig/std/start.zig:409:17: 0x205594 in std.start.posixCallMainAndExit (main)
std.os.exit(@call(.{ .modifier = .always_inline }, callMainWithArgs, .{ argc, argv, envp }));
^
/usr/lib/zig/std/start.zig:322:5: 0x2053a1 in std.start._start (main)
@call(.{ .modifier = .never_inline }, posixCallMainAndExit, .{});
^
error(gpa): memory address 0x7f64405b6000 leaked:
/data/sisyphus/proj/zigample/src/main.zig:9:34: 0x22b8c6 in main (main)
var gameMap = try alloc.alloc(u8, testVar.len);
^
/usr/lib/zig/std/start.zig:561:37: 0x22513a in std.start.callMain (main)
const result = root.main() catch |err| {
^
/usr/lib/zig/std/start.zig:495:12: 0x206497 in std.start.callMainWithArgs (main)
return @call(.{ .modifier = .always_inline }, callMain, .{});
^
/usr/lib/zig/std/start.zig:409:17: 0x205594 in std.start.posixCallMainAndExit (main)
std.os.exit(@call(.{ .modifier = .always_inline }, callMainWithArgs, .{ argc, argv, envp }));
Actual Behavior
warning: hello error.InvalidDebugInfo
???:?:?: 0x22afe7 in ??? (???)
???:?:?: 0x206bf7 in ??? (???)
???:?:?: 0x2069a2 in ??? (???)
error(gpa): memory address 0x7fa8a9429000 leaked:
???:?:?: 0x205e76 in ??? (???)
???:?:?: 0x22afe7 in ??? (???)
???:?:?: 0x206bf7 in ??? (???)
???:?:?: 0x2069a2 in ??? (???)
Zig Version
0.9.1, on ArtixLinux x64, normal kernel, and hardened.
Steps to Reproduce
build.zig:
main.zig:
Command to compile:
However, this works:
but this does not:
Appears to be happening when linking multiple/both libraries?
Expected Behavior
A bunch of gibberish for the first print, then:
Actual Behavior