Skip to content

Commit

Permalink
druntime + phobos updated to v2.109.1
Browse files Browse the repository at this point in the history
  • Loading branch information
kassane committed Jul 10, 2024
1 parent d236fb3 commit 3352ea4
Show file tree
Hide file tree
Showing 8 changed files with 160 additions and 101 deletions.
51 changes: 30 additions & 21 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ pub fn build(b: *std.Build) !void {

fn buildRuntime(b: *std.Build, options: buildOptions) !void {
const source = switch (options.target.result.os.tag) {
.windows => runtime_src ++ &[_][]const u8{"druntime/src/ldc/eh_msvc.d"},
.windows => runtime_src ++ &[_][]const u8{
"druntime/src/ldc/eh_msvc.d",
"druntime/src/ldc/msvc.c",
},
else => runtime_src,
};

Expand All @@ -43,15 +46,8 @@ fn buildRuntime(b: *std.Build, options: buildOptions) !void {
.target = options.target,
.optimize = options.optimize,
});
complementary.addIncludePath(b.path("druntime/src")); // importc.h
complementary.addAssemblyFile(b.path("druntime/src/core/threadasm.S"));
complementary.addAssemblyFile(b.path("druntime/src/ldc/eh_asm.S"));
if (options.target.result.abi == .msvc) {
complementary.addCSourceFile(.{
.file = b.path("druntime/src/ldc/msvc.c"),
});
complementary.linkLibC();
}
if (options.target.result.cpu.arch.isAARCH64()) {
complementary.addCSourceFile(.{
.file = b.path("druntime/src/ldc/arm_unwind.c"),
Expand All @@ -72,22 +68,24 @@ fn buildRuntime(b: *std.Build, options: buildOptions) !void {
};

const tagLabel = switch (options.optimize) {
.Debug => "debug",
else => "release",
.Debug => "-debug",
else => "",
};
const linkMode = switch (options.linkage) {
.static => "static",
.dynamic => "shared",
.static => "-static",
.dynamic => "-shared",
};
try buildD(b, .{
.name = b.fmt("druntime-ldc-{s}-{s}", .{ linkMode, tagLabel }),
.name = b.fmt("druntime-ldc{s}{s}", .{
tagLabel,
linkMode,
}),
.kind = .lib,
.linkage = options.linkage,
.target = options.target,
.optimize = options.optimize,
.sources = source,
.dflags = &.{
"-Idruntime/src",
"-w",
"-de",
"-preview=dip1000",
Expand All @@ -97,6 +95,12 @@ fn buildRuntime(b: *std.Build, options: buildOptions) !void {
"-defaultlib=",
"-debuglib=",
},
.importPaths = &.{
"druntime/src",
},
.cIncludePaths = &.{
"druntime/src", // importc header
},
.versions = versions_config,
.artifact = complementary,
.use_zigcc = true,
Expand All @@ -111,23 +115,24 @@ fn buildD(b: *std.Build, options: ldc2.DCompileStep) !void {

fn buildPhobos(b: *std.Build, options: buildOptions) !void {
const tagLabel = switch (options.optimize) {
.Debug => "debug",
else => "release",
.Debug => "-debug",
else => "",
};
const linkMode = switch (options.linkage) {
.static => "static",
.dynamic => "shared",
.static => "-static",
.dynamic => "-shared",
};
try buildD(b, .{
.name = b.fmt("phobos2-ldc-{s}-{s}", .{ linkMode, tagLabel }),
.name = b.fmt("phobos2-ldc{s}{s}", .{
tagLabel,
linkMode,
}),
.kind = .lib,
.linkage = options.linkage,
.target = options.target,
.optimize = options.optimize,
.sources = std_src,
.dflags = &.{
"-Iphobos",
"-Idruntime/src",
"-w",
"-conf=",
"-defaultlib=",
Expand All @@ -138,6 +143,10 @@ fn buildPhobos(b: *std.Build, options: buildOptions) !void {
"-preview=fieldwise",
"-lowmem",
},
.importPaths = &.{
"phobos",
"druntime/src",
},
.artifact = buildZlib(b, .{
.target = options.target,
.optimize = options.optimize,
Expand Down
4 changes: 2 additions & 2 deletions build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
.version = "1.109.0",
.dependencies = .{
.abs = .{
.url = "git+https://github.com/kassane/anotherBuildStep#b6eee7061021b491f2a31b40ff1fc7c24efc606e",
.hash = "122097056a0f4ed6804c89c145063a120b1687ea316de8a427f6c9ed173acd9b7b2f",
.url = "git+https://github.com/kassane/anotherBuildStep#449e179e966ba95b8a2308a9982cde490b57b3d3",
.hash = "12209e13ee461f2636956b46c663b17305a990338d02a8a70182043ff3a3a7a11356",
},
},
.paths = .{""},
Expand Down
54 changes: 28 additions & 26 deletions druntime/src/core/internal/backtrace/libunwind.d
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,15 @@
*/
module core.internal.backtrace.libunwind;

version (DRuntime_Use_Libunwind) : // Libunwind supports Windows as well, but we currently use a different
version (DRuntime_Use_Libunwind):

// Libunwind supports Windows as well, but we currently use a different
// mechanism for Windows, so the bindings haven't been brought in yet.
version (Posix) : import core.stdc.inttypes;
version (Posix):

import core.stdc.inttypes;

extern (C):
extern(C):
@nogc:
nothrow:

Expand All @@ -56,21 +60,21 @@ struct unw_cursor_t
///
struct unw_proc_info_t
{
unw_word_t start_ip; /* start address of function */
unw_word_t end_ip; /* address after end of function */
unw_word_t lsda; /* address of language specific data area, */
unw_word_t start_ip; /* start address of function */
unw_word_t end_ip; /* address after end of function */
unw_word_t lsda; /* address of language specific data area, */
/* or zero if not used */
unw_word_t handler; /* personality routine, or zero if not used */
unw_word_t gp; /* not used */
unw_word_t flags; /* not used */
uint format; /* compact unwind encoding, or zero if none */
uint unwind_info_size; /* size of DWARF unwind info, or zero if none */
unw_word_t handler; /* personality routine, or zero if not used */
unw_word_t gp; /* not used */
unw_word_t flags; /* not used */
uint format; /* compact unwind encoding, or zero if none */
uint unwind_info_size; /* size of DWARF unwind info, or zero if none */
// Note: It's a `void*` with LLVM and a `unw_word_t` with upstream
unw_word_t unwind_info; /* address of DWARF unwind info, or zero */
unw_word_t unwind_info; /* address of DWARF unwind info, or zero */
// Note: upstream might not have this member at all, or it might be a single
// byte, however we never pass an array of this type, so this is safe to
// just use the bigger (LLVM's) value.
unw_word_t extra; /* mach_header of mach-o image containing func */
unw_word_t extra; /* mach_header of mach-o image containing func */
}

/// Initialize the context at the current call site
Expand Down Expand Up @@ -113,12 +117,10 @@ else version (X86_64)
version (Win64)
{
enum _LIBUNWIND_CONTEXT_SIZE = 54;
// # ifdef __SEH__
// # define _LIBUNWIND_CURSOR_SIZE 204
// # ifdef __SEH__
// # define _LIBUNWIND_CURSOR_SIZE 204
enum _LIBUNWIND_CURSOR_SIZE = 66;
}
else
{
} else {
enum _LIBUNWIND_CONTEXT_SIZE = 21;
enum _LIBUNWIND_CURSOR_SIZE = 33;
}
Expand All @@ -136,18 +138,18 @@ else version (PPC)
else version (AArch64)
{
enum _LIBUNWIND_CONTEXT_SIZE = 66;
// # if defined(__SEH__)
// # define _LIBUNWIND_CURSOR_SIZE 164
// # if defined(__SEH__)
// # define _LIBUNWIND_CURSOR_SIZE 164
enum _LIBUNWIND_CURSOR_SIZE = 78;
}
else version (ARM)
{
// # if defined(__SEH__)
// # define _LIBUNWIND_CONTEXT_SIZE 42
// # define _LIBUNWIND_CURSOR_SIZE 80
// # elif defined(__ARM_WMMX)
// # define _LIBUNWIND_CONTEXT_SIZE 61
// # define _LIBUNWIND_CURSOR_SIZE 68
// # if defined(__SEH__)
// # define _LIBUNWIND_CONTEXT_SIZE 42
// # define _LIBUNWIND_CURSOR_SIZE 80
// # elif defined(__ARM_WMMX)
// # define _LIBUNWIND_CONTEXT_SIZE 61
// # define _LIBUNWIND_CURSOR_SIZE 68
enum _LIBUNWIND_CONTEXT_SIZE = 42;
enum _LIBUNWIND_CURSOR_SIZE = 49;
}
Expand Down
43 changes: 17 additions & 26 deletions druntime/src/core/internal/backtrace/unwind.d
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ version (LDC) // simplify runtime function forward declaration
else
void _Unwind_Resume(_Unwind_Exception* exception_object);
_Unwind_Reason_Code _Unwind_Resume_or_Rethrow(_Unwind_Exception* exception_object);
_Unwind_Reason_Code _Unwind_Backtrace(_Unwind_Trace_Fn, void*);
_Unwind_Reason_Code _Unwind_Backtrace(_Unwind_Trace_Fn, void*) nothrow;

version (ARM_EABI_UNWINDER)
{
Expand All @@ -160,46 +160,37 @@ version (ARM_EABI_UNWINDER)
// On ARM, these are macros resp. not visible (static inline). To avoid
// an unmaintainable amount of dependencies on implementation details,
// just use a C shim (in ldc/arm_unwind.c).
_Unwind_Word _d_eh_GetGR(_Unwind_Context* context, int index);
_Unwind_Word _d_eh_GetGR(_Unwind_Context* context, int index) nothrow;
alias _Unwind_GetGR = _d_eh_GetGR;

void _d_eh_SetGR(_Unwind_Context* context, int index, _Unwind_Word new_value);
void _d_eh_SetGR(_Unwind_Context* context, int index, _Unwind_Word new_value) nothrow;
alias _Unwind_SetGR = _d_eh_SetGR;

_Unwind_Ptr _d_eh_GetIP(_Unwind_Context* context);
_Unwind_Ptr _d_eh_GetIP(_Unwind_Context* context) nothrow;
alias _Unwind_GetIP = _d_eh_GetIP;

_Unwind_Ptr _d_eh_GetIPInfo(_Unwind_Context* context, int*);
_Unwind_Ptr _d_eh_GetIPInfo(_Unwind_Context* context, int*) nothrow;
alias _Unwind_GetIPInfo = _d_eh_GetIPInfo;

void _d_eh_SetIP(_Unwind_Context* context, _Unwind_Ptr new_value);
void _d_eh_SetIP(_Unwind_Context* context, _Unwind_Ptr new_value) nothrow;
alias _Unwind_SetIP = _d_eh_SetIP;
}
else
{
_Unwind_Word _Unwind_GetGR(_Unwind_Context* context, int index);
void _Unwind_SetGR(_Unwind_Context* context, int index, _Unwind_Word new_value);
_Unwind_Ptr _Unwind_GetIP(_Unwind_Context* context);
_Unwind_Ptr _Unwind_GetIPInfo(_Unwind_Context* context, int*);
void _Unwind_SetIP(_Unwind_Context* context, _Unwind_Ptr new_value);
_Unwind_Word _Unwind_GetGR(_Unwind_Context* context, int index) nothrow;
void _Unwind_SetGR(_Unwind_Context* context, int index, _Unwind_Word new_value) nothrow;
_Unwind_Ptr _Unwind_GetIP(_Unwind_Context* context) nothrow;
_Unwind_Ptr _Unwind_GetIPInfo(_Unwind_Context* context, int*) nothrow;
void _Unwind_SetIP(_Unwind_Context* context, _Unwind_Ptr new_value) nothrow;
}
_Unwind_Word _Unwind_GetCFA(_Unwind_Context*);
_Unwind_Word _Unwind_GetBSP(_Unwind_Context*);
void* _Unwind_GetLanguageSpecificData(_Unwind_Context*);
_Unwind_Ptr _Unwind_GetRegionStart(_Unwind_Context* context);
void* _Unwind_FindEnclosingFunction(void* pc);
_Unwind_Word _Unwind_GetCFA(_Unwind_Context*) nothrow;
_Unwind_Word _Unwind_GetBSP(_Unwind_Context*) nothrow;
void* _Unwind_GetLanguageSpecificData(_Unwind_Context*) nothrow;
_Unwind_Ptr _Unwind_GetRegionStart(_Unwind_Context* context) nothrow;
void* _Unwind_FindEnclosingFunction(void* pc) nothrow;

version (X68_64)
version (X86_64)
{
_Unwind_Ptr _Unwind_GetDataRelBase(_Unwind_Context* context)
{
return _Unwind_GetGR(context, 1);
}

_Unwind_Ptr _Unwind_GetTextRelBase(_Unwind_Context* context)
{
assert(0);
}
}
else
{
Expand Down
39 changes: 14 additions & 25 deletions druntime/src/core/runtime.d
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,17 @@ else version (TVOS)
else version (WatchOS)
version = Darwin;

version(LDC) version (Darwin)
{
// Use our own backtrace() based on _Unwind_Backtrace(), as the former (from
// execinfo) doesn't seem to handle missing frame pointers too well.
version = DefineBacktrace_using_UnwindBacktrace;
}

version (DRuntime_Use_Libunwind)
{
import core.internal.backtrace.libunwind;
version = DefineBacktrace_using_UnwindBacktrace;

// This shouldn't be necessary but ensure that code doesn't get mixed
// It does however prevent the unittest SEGV handler to be installed,
// which is desireable as it uses backtrace directly.
Expand Down Expand Up @@ -670,24 +678,11 @@ extern (C) UnitTestResult runModuleUnitTests()
return results;
}

version (LDC) version (Darwin)
version (DefineBacktrace_using_UnwindBacktrace)
{
nothrow:

extern (C)
{
enum _URC_NO_REASON = 0;
enum _URC_END_OF_STACK = 5;
import core.internal.backtrace.unwind;

alias _Unwind_Context_Ptr = void*;
alias _Unwind_Trace_Fn = int function(_Unwind_Context_Ptr, void*);
int _Unwind_Backtrace(_Unwind_Trace_Fn, void*);
ptrdiff_t _Unwind_GetIP(_Unwind_Context_Ptr context);
}

// Use our own backtrce() based on _Unwind_Backtrace(), as the former (from
// execinfo) doesn't seem to handle missing frame pointers too well.
private int backtrace(void** buffer, int maxSize)
private int backtrace(void** buffer, int maxSize) nothrow
{
if (maxSize < 0) return 0;

Expand All @@ -698,7 +693,7 @@ version (LDC) version (Darwin)
int entriesWritten = 0;
}

static extern(C) int handler(_Unwind_Context_Ptr context, void* statePtr)
static extern(C) int handler(_Unwind_Context* context, void* statePtr)
{
auto state = cast(State*)statePtr;
if (state.entriesWritten >= state.maxSize) return _URC_END_OF_STACK;
Expand Down Expand Up @@ -819,14 +814,8 @@ void defaultTraceDeallocator(Throwable.TraceInfo info) nothrow
free(cast(void *)obj);
}

version (DRuntime_Use_Libunwind)
{
import core.internal.backtrace.handler;

alias DefaultTraceInfo = LibunwindHandler;
}
/// Default implementation for most POSIX systems
else version (Posix) private class DefaultTraceInfo : Throwable.TraceInfo
version (Posix) private class DefaultTraceInfo : Throwable.TraceInfo
{
import core.demangle;
import core.stdc.stdlib : free;
Expand Down
Loading

0 comments on commit 3352ea4

Please sign in to comment.