Skip to content

Commit

Permalink
Revert "build: add build opts for enabling sanitizers"
Browse files Browse the repository at this point in the history
This reverts commit b044efa.
  • Loading branch information
pkova committed Nov 14, 2024
1 parent ad4bc28 commit 3c4249a
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 107 deletions.
22 changes: 0 additions & 22 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,6 @@ pro hand -p true -s false -n false SIGBUS
pro hand -p true -s false -n false SIGSEGV
```

### Sanitizers

Musl does not have proper sanitizer support, so until we support native (GNU) linux builds, these are limited to mac only.

In order to use address sanitizer (`-Dasan`) and undefined behavior sanitizer (`-Dubsan`), you need to have version 18 of llvm installed on your machine. You also have to build natively, since cross-compilation is not supported.

macOS:
```terminal
brew install llvm@18
```

<!-- linux: -->
<!-- ```terminal -->
<!-- apt-get install llvm-18 clang-18 -->
<!-- ``` -->

## Build

Once you install `zig`, you're ready to build:
Expand Down Expand Up @@ -89,12 +73,6 @@ Supported values:
Provide additional compiler flags. These propagate to all build artifacts and
dependencies.

#### `-Dasan`
Enable address sanitizer. Only supported in native macos builds. Requires llvm 18, see [prerequisites](#sanitizers).

#### `-Dubsan`
Enable undefined behavior sanitizer. Only supported in native macos builds. Requires llvm 18, see [prerequisites](#sanitizers).

<!-- ## LSP Integration -->

<!-- ```console -->
Expand Down
81 changes: 1 addition & 80 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ const std = @import("std");

const VERSION = "3.2";

// TODO: x86_64-linux-gnu & aarch64-linux-gnu
const targets: []const std.Target.Query = &.{
.{ .cpu_arch = .aarch64, .os_tag = .macos, .abi = null },
.{ .cpu_arch = .x86_64, .os_tag = .macos, .abi = null },
Expand All @@ -20,8 +19,6 @@ const BuildCfg = struct {
mem_dbg: bool = false,
c3dbg: bool = false,
snapshot_validation: bool = false,
ubsan: bool = false,
asan: bool = false,
};

pub fn build(b: *std.Build) !void {
Expand Down Expand Up @@ -88,26 +85,6 @@ pub fn build(b: *std.Build) !void {
"Binary name (Default: urbit)",
) orelse "urbit";

// Sanitizers are not properly supported in musl => mac only

const asan = if (target.query.isNative() and target.result.isDarwin())
b.option(
bool,
"asan",
"Enable address sanitizer (native only, requires llvm@18)",
) orelse false
else
false;

const ubsan = if (target.query.isNative() and target.result.isDarwin())
b.option(
bool,
"ubsan",
"Enable undefined behavior sanitizer (native only, requires llvm@18)",
) orelse false
else
false;

// Parse short git rev
//
var file = try std.fs.cwd().openFile(".git/logs/HEAD", .{});
Expand Down Expand Up @@ -141,8 +118,6 @@ pub fn build(b: *std.Build) !void {
.mem_dbg = mem_dbg,
.c3dbg = c3dbg,
.snapshot_validation = snapshot_validation,
.asan = asan,
.ubsan = ubsan,
.include_test_steps = !all,
};

Expand Down Expand Up @@ -181,38 +156,12 @@ fn build_single(

try global_flags.appendSlice(cfg.flags);
try global_flags.appendSlice(&.{
"-fno-sanitize=all",
"-g",
"-Wall",
"-Werror",
});

if (!cfg.asan and !cfg.ubsan)
try global_flags.appendSlice(&.{
"-fno-sanitize=all",
});

if (cfg.asan and !cfg.ubsan)
try global_flags.appendSlice(&.{
"-Wno-deprecated",
"-fsanitize=address",
"-fno-sanitize=undefined",
"-fno-sanitize-trap=undefined",
});

if (!cfg.asan and cfg.ubsan)
try global_flags.appendSlice(&.{
"-fsanitize=undefined",
"-fno-sanitize-trap=undefined",
});

if (cfg.asan and cfg.ubsan)
try global_flags.appendSlice(&.{
"-Wno-deprecated",
"-fsanitize=address",
"-fsanitize=undefined",
"-fno-sanitize-trap=undefined",
});

//
// CFLAGS for Urbit Libs and Binaries
//
Expand Down Expand Up @@ -935,34 +884,6 @@ fn build_single(

urbit.linkLibC();

if (t.isDarwin()) {
// Requires llvm@18 homebrew installation
if (cfg.asan or cfg.ubsan)
urbit.addLibraryPath(.{
.cwd_relative = "/opt/homebrew/opt/llvm/lib/clang/18/lib/darwin",
});
if (cfg.asan) urbit.linkSystemLibrary("clang_rt.asan_osx_dynamic");
if (cfg.ubsan) urbit.linkSystemLibrary("clang_rt.ubsan_osx_dynamic");
}

if (t.os.tag == .linux) {
// Requires llvm-18 and clang-18 installation
if (cfg.asan or cfg.ubsan)
urbit.addLibraryPath(.{
.cwd_relative = "/usr/lib/clang/18/lib/linux",
});
if (t.cpu.arch == .x86_64) {
if (cfg.asan) urbit.linkSystemLibrary("clang_rt.asan-x86_64");
if (cfg.ubsan)
urbit.linkSystemLibrary("clang_rt.ubsan_standalone-x86_64");
}
if (t.cpu.arch == .aarch64) {
if (cfg.asan) urbit.linkSystemLibrary("clang_rt.asan-aarch64");
if (cfg.ubsan)
urbit.linkSystemLibrary("clang_rt.ubsan_standalone-aarch64");
}
}

urbit.linkLibrary(vere);
urbit.linkLibrary(pkg_noun);
urbit.linkLibrary(pkg_c3);
Expand Down
6 changes: 1 addition & 5 deletions pkg/c3/portable.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,7 @@
# define U3_OS_LoomBits 30
# elif defined(U3_OS_osx)
# ifdef __LP64__
# ifdef ASAN_ENABLED
# define U3_OS_LoomBase 0x728000000000
# else
# define U3_OS_LoomBase 0x28000000000
# endif
# define U3_OS_LoomBase 0x28000000000
# else
# define U3_OS_LoomBase 0x4000000
# endif
Expand Down

0 comments on commit 3c4249a

Please sign in to comment.