mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
std: fix memory bug in getExternalExecutor
Until now, we would pass `candidate: NativeTargetInfo` which creates a copy of the `NativeTargetInfo.DynamicLinker` buffer. We would then return this buffer in `bad_dl: []const u8` which would goes out-of-scope the moment we leave this function frame yielding garbage. To fix this, we just need to remember to pass by const-pointer `candidate: *const NativeTargetInfo`.
This commit is contained in:
parent
e6590fea19
commit
df9462690f
4 changed files with 6 additions and 6 deletions
|
|
@ -679,7 +679,7 @@ fn runCommand(
|
||||||
}
|
}
|
||||||
|
|
||||||
const need_cross_glibc = exe.target.isGnuLibC() and exe.is_linking_libc;
|
const need_cross_glibc = exe.target.isGnuLibC() and exe.is_linking_libc;
|
||||||
switch (b.host.getExternalExecutor(exe.target_info, .{
|
switch (b.host.getExternalExecutor(&exe.target_info, .{
|
||||||
.qemu_fixes_dl = need_cross_glibc and b.glibc_runtimes_dir != null,
|
.qemu_fixes_dl = need_cross_glibc and b.glibc_runtimes_dir != null,
|
||||||
.link_libc = exe.is_linking_libc,
|
.link_libc = exe.is_linking_libc,
|
||||||
})) {
|
})) {
|
||||||
|
|
|
||||||
|
|
@ -1002,7 +1002,7 @@ pub const GetExternalExecutorOptions = struct {
|
||||||
/// of the other target.
|
/// of the other target.
|
||||||
pub fn getExternalExecutor(
|
pub fn getExternalExecutor(
|
||||||
host: NativeTargetInfo,
|
host: NativeTargetInfo,
|
||||||
candidate: NativeTargetInfo,
|
candidate: *const NativeTargetInfo,
|
||||||
options: GetExternalExecutorOptions,
|
options: GetExternalExecutorOptions,
|
||||||
) Executor {
|
) Executor {
|
||||||
const os_match = host.target.os.tag == candidate.target.os.tag;
|
const os_match = host.target.os.tag == candidate.target.os.tag;
|
||||||
|
|
|
||||||
|
|
@ -3667,7 +3667,7 @@ fn buildOutputType(
|
||||||
test_exec_args.items,
|
test_exec_args.items,
|
||||||
self_exe_path.?,
|
self_exe_path.?,
|
||||||
arg_mode,
|
arg_mode,
|
||||||
target_info,
|
&target_info,
|
||||||
&comp_destroyed,
|
&comp_destroyed,
|
||||||
all_args,
|
all_args,
|
||||||
runtime_args_start,
|
runtime_args_start,
|
||||||
|
|
@ -3995,7 +3995,7 @@ fn runOrTest(
|
||||||
test_exec_args: []const ?[]const u8,
|
test_exec_args: []const ?[]const u8,
|
||||||
self_exe_path: []const u8,
|
self_exe_path: []const u8,
|
||||||
arg_mode: ArgMode,
|
arg_mode: ArgMode,
|
||||||
target_info: std.zig.system.NativeTargetInfo,
|
target_info: *const std.zig.system.NativeTargetInfo,
|
||||||
comp_destroyed: *bool,
|
comp_destroyed: *bool,
|
||||||
all_args: []const []const u8,
|
all_args: []const []const u8,
|
||||||
runtime_args_start: ?usize,
|
runtime_args_start: ?usize,
|
||||||
|
|
@ -6256,7 +6256,7 @@ fn parseIntSuffix(arg: []const u8, prefix_len: usize) u64 {
|
||||||
fn warnAboutForeignBinaries(
|
fn warnAboutForeignBinaries(
|
||||||
arena: Allocator,
|
arena: Allocator,
|
||||||
arg_mode: ArgMode,
|
arg_mode: ArgMode,
|
||||||
target_info: std.zig.system.NativeTargetInfo,
|
target_info: *const std.zig.system.NativeTargetInfo,
|
||||||
link_libc: bool,
|
link_libc: bool,
|
||||||
) !void {
|
) !void {
|
||||||
const host_cross_target: std.zig.CrossTarget = .{};
|
const host_cross_target: std.zig.CrossTarget = .{};
|
||||||
|
|
|
||||||
|
|
@ -590,7 +590,7 @@ pub fn lowerToBuildSteps(
|
||||||
const run = if (case.target.ofmt == .c) run_step: {
|
const run = if (case.target.ofmt == .c) run_step: {
|
||||||
const target_info = std.zig.system.NativeTargetInfo.detect(case.target) catch |err|
|
const target_info = std.zig.system.NativeTargetInfo.detect(case.target) catch |err|
|
||||||
std.debug.panic("unable to detect notive host: {s}\n", .{@errorName(err)});
|
std.debug.panic("unable to detect notive host: {s}\n", .{@errorName(err)});
|
||||||
if (host.getExternalExecutor(target_info, .{ .link_libc = true }) != .native) {
|
if (host.getExternalExecutor(&target_info, .{ .link_libc = true }) != .native) {
|
||||||
// We wouldn't be able to run the compiled C code.
|
// We wouldn't be able to run the compiled C code.
|
||||||
break :no_exec;
|
break :no_exec;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue