Skip to content

Commit

Permalink
ubsan: update wording
Browse files Browse the repository at this point in the history
  • Loading branch information
Rexicon226 committed Feb 24, 2025
1 parent 1c465ae commit d3863fe
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 78 deletions.
13 changes: 8 additions & 5 deletions lib/ubsan_rt.zig
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ const Value = extern struct {
) !void {
comptime assert(fmt.len == 0);

// Work around x86_64 backend limitation.
if (builtin.zig_backend == .stage2_x86_64 and builtin.os.tag == .windows) {
try writer.writeAll("(unknown)");
return;
Expand Down Expand Up @@ -646,6 +647,7 @@ fn exportHandler(
handler: anytype,
comptime sym_name: []const u8,
) void {
// Work around x86_64 backend limitation.
const linkage = if (builtin.zig_backend == .stage2_x86_64 and builtin.os.tag == .windows) .internal else .weak;
const N = "__ubsan_handle_" ++ sym_name;
@export(handler, .{ .name = N, .linkage = linkage });
Expand All @@ -656,6 +658,7 @@ fn exportHandlerWithAbort(
abort_handler: anytype,
comptime sym_name: []const u8,
) void {
// Work around x86_64 backend limitation.
const linkage = if (builtin.zig_backend == .stage2_x86_64 and builtin.os.tag == .windows) .internal else .weak;
{
const N = "__ubsan_handle_" ++ sym_name;
Expand Down Expand Up @@ -697,12 +700,12 @@ comptime {
exportHandler(&missingReturn, "missing_return");
}

// these checks are nearly impossible to duplicate in zig, as they rely on nuances
// these checks are nearly impossible to replicate in zig, as they rely on nuances
// in the Itanium C++ ABI.
// exportHelper("dynamic_type_cache_miss", "dynamic-type-cache-miss", true);
// exportHelper("vptr_type_cache", "vptr-type-cache", true);
// exportHandlerWithAbort(&dynamicTypeCacheMiss, &dynamicTypeCacheMissAbort, "dynamic-type-cache-miss");
// exportHandlerWithAbort(&vptrTypeCache, &vptrTypeCacheAbort, "vptr-type-cache");

// we disable -fsanitize=function for reasons explained in src/Compilation.zig
// exportHelper("function-type-mismatch", "function_type_mismatch", true);
// exportHelper("function-type-mismatch-v1", "function_type_mismatch_v1", true);
// exportHandlerWithAbort(&functionTypeMismatch, &functionTypeMismatchAbort, "function-type-mismatch");
// exportHandlerWithAbort(&functionTypeMismatchV1, &functionTypeMismatchV1Abort, "function-type-mismatch-v1");
}
146 changes: 74 additions & 72 deletions test/link/elf.zig
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ fn testCommentString(b: *Build, opts: Options) *Step {
const test_step = addTestStep(b, "comment-string", opts);

const exe = addExecutable(b, opts, .{ .name = "main", .zig_source_bytes =
\\pub fn main() void {}
\\pub fn main() void {}
});

const check = exe.checkObject();
Expand All @@ -490,7 +490,7 @@ fn testCommentStringStaticLib(b: *Build, opts: Options) *Step {
const test_step = addTestStep(b, "comment-string-static-lib", opts);

const lib = addStaticLibrary(b, opts, .{ .name = "lib", .zig_source_bytes =
\\export fn foo() void {}
\\export fn foo() void {}
});

const check = lib.checkObject();
Expand Down Expand Up @@ -861,23 +861,23 @@ fn testEmitRelocatable(b: *Build, opts: Options) *Step {
const test_step = addTestStep(b, "emit-relocatable", opts);

const a_o = addObject(b, opts, .{ .name = "a", .zig_source_bytes =
\\const std = @import("std");
\\extern var bar: i32;
\\export fn foo() i32 {
\\ return bar;
\\}
\\export fn printFoo() void {
\\ std.debug.print("foo={d}\n", .{foo()});
\\}
\\const std = @import("std");
\\extern var bar: i32;
\\export fn foo() i32 {
\\ return bar;
\\}
\\export fn printFoo() void {
\\ std.debug.print("foo={d}\n", .{foo()});
\\}
});
a_o.linkLibC();

const b_o = addObject(b, opts, .{ .name = "b", .c_source_bytes =
\\#include <stdio.h>
\\int bar = 42;
\\void printBar() {
\\ fprintf(stderr, "bar=%d\n", bar);
\\}
\\#include <stdio.h>
\\int bar = 42;
\\void printBar() {
\\ fprintf(stderr, "bar=%d\n", bar);
\\}
});
b_o.linkLibC();

Expand All @@ -886,13 +886,13 @@ fn testEmitRelocatable(b: *Build, opts: Options) *Step {
c_o.addObject(b_o);

const exe = addExecutable(b, opts, .{ .name = "test", .zig_source_bytes =
\\const std = @import("std");
\\extern fn printFoo() void;
\\extern fn printBar() void;
\\pub fn main() void {
\\ printFoo();
\\ printBar();
\\}
\\const std = @import("std");
\\extern fn printFoo() void;
\\extern fn printBar() void;
\\pub fn main() void {
\\ printFoo();
\\ printBar();
\\}
});
exe.addObject(c_o);
exe.linkLibC();
Expand Down Expand Up @@ -1920,8 +1920,8 @@ fn testInitArrayOrder(b: *Build, opts: Options) *Step {
g_o.linkLibC();

const h_o = addObject(b, opts, .{ .name = "h", .c_source_bytes =
\\#include <stdio.h>
\\__attribute__((destructor)) void fini2() { printf("8"); }
\\#include <stdio.h>
\\__attribute__((destructor)) void fini2() { printf("8"); }
});
h_o.linkLibC();

Expand Down Expand Up @@ -2049,7 +2049,8 @@ fn testLargeBss(b: *Build, opts: Options) *Step {
\\}
, &.{});
exe.linkLibC();
// Disabled to work around an ELF linker bug.
// Disabled to work around the ELF linker crashing.
// Can be reproduced on a x86_64-linux host by commenting out the line below.
exe.root_module.sanitize_c = false;

const run = addRunArtifact(exe);
Expand Down Expand Up @@ -2497,23 +2498,23 @@ fn testMergeStrings2(b: *Build, opts: Options) *Step {
const test_step = addTestStep(b, "merge-strings2", opts);

const obj1 = addObject(b, opts, .{ .name = "a", .zig_source_bytes =
\\const std = @import("std");
\\export fn foo() void {
\\ var arr: [5:0]u16 = [_:0]u16{ 1, 2, 3, 4, 5 };
\\ const slice = std.mem.sliceTo(&arr, 3);
\\ std.testing.expectEqualSlices(u16, arr[0..2], slice) catch unreachable;
\\}
\\const std = @import("std");
\\export fn foo() void {
\\ var arr: [5:0]u16 = [_:0]u16{ 1, 2, 3, 4, 5 };
\\ const slice = std.mem.sliceTo(&arr, 3);
\\ std.testing.expectEqualSlices(u16, arr[0..2], slice) catch unreachable;
\\}
});

const obj2 = addObject(b, opts, .{ .name = "b", .zig_source_bytes =
\\const std = @import("std");
\\extern fn foo() void;
\\pub fn main() void {
\\ foo();
\\ var arr: [5:0]u16 = [_:0]u16{ 5, 4, 3, 2, 1 };
\\ const slice = std.mem.sliceTo(&arr, 3);
\\ std.testing.expectEqualSlices(u16, arr[0..2], slice) catch unreachable;
\\}
\\const std = @import("std");
\\extern fn foo() void;
\\pub fn main() void {
\\ foo();
\\ var arr: [5:0]u16 = [_:0]u16{ 5, 4, 3, 2, 1 };
\\ const slice = std.mem.sliceTo(&arr, 3);
\\ std.testing.expectEqualSlices(u16, arr[0..2], slice) catch unreachable;
\\}
});

{
Expand Down Expand Up @@ -2754,17 +2755,17 @@ fn testRelocatableEhFrame(b: *Build, opts: Options) *Step {
});
obj2.linkLibCpp();
const obj3 = addObject(b, opts, .{ .name = "obj3", .cpp_source_bytes =
\\#include <iostream>
\\#include <stdexcept>
\\extern int try_again();
\\int main() {
\\ try {
\\ try_again();
\\ } catch (const std::exception &e) {
\\ std::cout << "exception=" << e.what();
\\ }
\\ return 0;
\\}
\\#include <iostream>
\\#include <stdexcept>
\\extern int try_again();
\\int main() {
\\ try {
\\ try_again();
\\ } catch (const std::exception &e) {
\\ std::cout << "exception=" << e.what();
\\ }
\\ return 0;
\\}
});
obj3.linkLibCpp();

Expand Down Expand Up @@ -2866,15 +2867,15 @@ fn testRelocatableMergeStrings(b: *Build, opts: Options) *Step {
const test_step = addTestStep(b, "relocatable-merge-strings", opts);

const obj1 = addObject(b, opts, .{ .name = "a", .asm_source_bytes =
\\.section .rodata.str1.1,"aMS",@progbits,1
\\val1:
\\.ascii "Hello \0"
\\.section .rodata.str1.1,"aMS",@progbits,1
\\val5:
\\.ascii "World \0"
\\.section .rodata.str1.1,"aMS",@progbits,1
\\val7:
\\.ascii "Hello \0"
\\.section .rodata.str1.1,"aMS",@progbits,1
\\val1:
\\.ascii "Hello \0"
\\.section .rodata.str1.1,"aMS",@progbits,1
\\val5:
\\.ascii "World \0"
\\.section .rodata.str1.1,"aMS",@progbits,1
\\val7:
\\.ascii "Hello \0"
});

const obj2 = addObject(b, opts, .{ .name = "b" });
Expand Down Expand Up @@ -3032,18 +3033,18 @@ fn testThunks(b: *Build, opts: Options) *Step {
const test_step = addTestStep(b, "thunks", opts);

const exe = addExecutable(b, opts, .{ .name = "main", .c_source_bytes =
\\void foo();
\\__attribute__((section(".bar"))) void bar() {
\\ return foo();
\\}
\\__attribute__((section(".foo"))) void foo() {
\\ return bar();
\\}
\\int main() {
\\ foo();
\\ bar();
\\ return 0;
\\}
\\void foo();
\\__attribute__((section(".bar"))) void bar() {
\\ return foo();
\\}
\\__attribute__((section(".foo"))) void foo() {
\\ return bar();
\\}
\\int main() {
\\ foo();
\\ bar();
\\ return 0;
\\}
});

const check = exe.checkObject();
Expand Down Expand Up @@ -3554,7 +3555,8 @@ fn testTlsLargeTbss(b: *Build, opts: Options) *Step {
\\}
, &.{});
exe.linkLibC();
// Disabled to work around an ELF linker bug.
// Disabled to work around the ELF linker crashing.
// Can be reproduced on a x86_64-linux host by commenting out the line below.
exe.root_module.sanitize_c = false;

const run = addRunArtifact(exe);
Expand Down
3 changes: 2 additions & 1 deletion test/link/wasm/export-data/build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ pub fn build(b: *std.Build) void {
}),
});
lib.entry = .disabled;
// Disabling due to self-hosted wasm linker bug.
// Disabled to work around the Wasm linker crashing.
// Can be reproduced by commenting out the line below.
lib.bundle_ubsan_rt = false;
lib.use_lld = false;
lib.root_module.export_symbol_names = &.{ "foo", "bar" };
Expand Down

0 comments on commit d3863fe

Please sign in to comment.