From 80fcd5470e0ca193d6b5ec7a919c125011b637b7 Mon Sep 17 00:00:00 2001 From: Santeri Hannula Date: Fri, 5 Jul 2024 17:54:19 +0300 Subject: [PATCH 01/24] deps: add libbacktrace --- WORKSPACE.bazel | 9 +++++++ bazel/third_party/libbacktrace/BUILD.bazel | 0 .../libbacktrace/libbacktrace.BUILD | 25 +++++++++++++++++++ pkg/noun/BUILD.bazel | 1 + 4 files changed, 35 insertions(+) create mode 100644 bazel/third_party/libbacktrace/BUILD.bazel create mode 100644 bazel/third_party/libbacktrace/libbacktrace.BUILD diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel index 6661562bee..7105c55ac9 100644 --- a/WORKSPACE.bazel +++ b/WORKSPACE.bazel @@ -233,6 +233,15 @@ versioned_http_file( version = "255fb1ca8206072f1d09425f0db61ecfe7ff5b17", ) +versioned_http_archive( + name = "libbacktrace", + build_file = "//bazel/third_party/libbacktrace:libbacktrace.BUILD", + sha256 = "609c17352ec38eaf5ff6618fcbfb38cd8fa0e94a15a0d9aa259df514bbf47fcd", + url = "https://github.com/ianlancetaylor/libbacktrace/archive/{version}.tar.gz", + strip_prefix = "libbacktrace-{version}", + version = "4ead348bb45f753121ca0bd44170ff8352d4c514", +) + versioned_http_archive( name = "lmdb", build_file = "//bazel/third_party/lmdb:lmdb.BUILD", diff --git a/bazel/third_party/libbacktrace/BUILD.bazel b/bazel/third_party/libbacktrace/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bazel/third_party/libbacktrace/libbacktrace.BUILD b/bazel/third_party/libbacktrace/libbacktrace.BUILD new file mode 100644 index 0000000000..ecb9ed9036 --- /dev/null +++ b/bazel/third_party/libbacktrace/libbacktrace.BUILD @@ -0,0 +1,25 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +filegroup( + name = "all", + srcs = glob(["**"]), +) + +configure_make( + name = "libbacktrace", + args = [ + ] + select({ + "@platforms//os:macos": ["--jobs=`sysctl -n hw.logicalcpu`"], + "//conditions:default": ["--jobs=`nproc`"], + }), + configure_options = [ + ] + select({ + "@//:linux_aarch64": ["--host=aarch64-linux-musl"], + "@//:linux_x86_64": ["--host=x86_64-linux-musl"], + "//conditions:default": [], + }), + copts = ["-O3"], + lib_source = ":all", + out_static_libs = ["libbacktrace.a"], + visibility = ["//visibility:public"], +) diff --git a/pkg/noun/BUILD.bazel b/pkg/noun/BUILD.bazel index a6b8de6d7a..ea43cd7006 100644 --- a/pkg/noun/BUILD.bazel +++ b/pkg/noun/BUILD.bazel @@ -34,6 +34,7 @@ vere_library( "//pkg/ent", "//pkg/ur", "@gmp", + "@libbacktrace", "@murmur3", "@openssl", "@pdjson", From c154fd17e697ae23c03625c12b43b9a5bb1ce810 Mon Sep 17 00:00:00 2001 From: Santeri Hannula Date: Wed, 10 Jul 2024 18:50:50 +0300 Subject: [PATCH 02/24] build: include debug symbols on all platforms --- bazel/common_settings.bzl | 17 ++--------------- 1 file changed, 2 insertions(+), 15 deletions(-) diff --git a/bazel/common_settings.bzl b/bazel/common_settings.bzl index 68a2232cd1..c4bcfcfa35 100644 --- a/bazel/common_settings.bzl +++ b/bazel/common_settings.bzl @@ -15,18 +15,10 @@ def vere_library(copts = [], linkopts = [], **kwargs): native.cc_library( copts = copts + select({ "//:debug": ["-O0", "-g3", "-DC3DBG", "-fdebug-compilation-dir=."], - "//conditions:default": ["-O3"] + "//conditions:default": ["-O3", "-g"] }) + select({ "//:lto": ['-flto'], - "//:thinlto": ['-flto=thin'], "//conditions:default": [] - }) + select({ - # Don't include source level debug info on macOS. See - # https://github.com/urbit/urbit/issues/5561 and - # https://github.com/urbit/vere/issues/131. - "//:debug": [], - "@platforms//os:linux": ["-g"], - "//conditions:default": [], }), linkopts = linkopts + ['-g'] + select({ "//:lto": ['-flto'], @@ -40,15 +32,10 @@ def vere_binary(copts = [], linkopts = [], **kwargs): native.cc_binary( copts = copts + select({ "//:debug": ["-O0", "-g3", "-DC3DBG", "-fdebug-compilation-dir=."], - "//conditions:default": ["-O3"] + "//conditions:default": ["-O3", "-g"] }) + select({ "//:lto": ['-flto'], - "//:thinlto": ['-flto=thin'], "//conditions:default": [] - }) + select({ - "//:debug": [], - "@platforms//os:linux": ["-g"], - "//conditions:default": [], }), linkopts = linkopts + ['-g'] + select({ "//:lto": ['-flto'], From 0abc468678225f1395e4a68cea5e242af1880fab Mon Sep 17 00:00:00 2001 From: Santeri Hannula Date: Thu, 11 Jul 2024 13:47:40 +0300 Subject: [PATCH 03/24] manage: print stacktrace in sigsegv signal handler --- pkg/noun/BUILD.bazel | 1 + pkg/noun/manage.c | 100 +++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 98 insertions(+), 3 deletions(-) diff --git a/pkg/noun/BUILD.bazel b/pkg/noun/BUILD.bazel index ea43cd7006..9b5347dfcf 100644 --- a/pkg/noun/BUILD.bazel +++ b/pkg/noun/BUILD.bazel @@ -41,6 +41,7 @@ vere_library( "@sigsegv", "@softfloat", "@urcrypt", + "@whereami", ] + select({ "@platforms//os:macos": ["//pkg/noun/platform/darwin"], "@platforms//os:linux": ["//pkg/noun/platform/linux"], diff --git a/pkg/noun/manage.c b/pkg/noun/manage.c index 71d673e357..07fa7024cb 100644 --- a/pkg/noun/manage.c +++ b/pkg/noun/manage.c @@ -6,10 +6,12 @@ #include #include +#include #include #include #include "allocate.h" +#include "backtrace.h" #include "events.h" #include "hashtable.h" #include "imprison.h" @@ -24,6 +26,7 @@ #include "trace.h" #include "urcrypt.h" #include "vortex.h" +#include "whereami.h" #include "xtract.h" // XX stack-overflow recovery should be gated by -a @@ -1770,8 +1773,63 @@ _cm_limits(void) # endif } +struct bt_cb_data { + c3_y count; + c3_y fail; +}; + +void +err_cb(void* data, const char* msg, int errnum) +{ + struct bt_cb_data* bdata = (struct bt_cb_data *)data; + bdata->count++; + + if ( bdata->count <= 1 ) { + /* u3l_log("Backtrace error %d: %s", errnum, msg); */ + bdata->fail = 1; + } +} + +int +bt_cb(void* data, + uintptr_t pc, + const char* filename, + int lineno, + const char* function) +{ + struct bt_cb_data* bdata = (struct bt_cb_data *)data; + bdata->count++; + + if ( bdata->count <= 100 ) { + if ( filename != NULL ) { + u3l_log("%s:%d %s", filename, lineno, function); + } + return 0; + } + else { + return 1; + } +} + +/* _main_self_path(): get binary self-path. + */ +c3_y +_main_self_path(c3_c *pat_c) +{ + c3_i len_i = 0; + c3_i pat_i; + + if ( 0 < (len_i = wai_getExecutablePath(NULL, 0, &pat_i)) ) { + wai_getExecutablePath(pat_c, len_i, &pat_i); + pat_c[len_i] = 0; + return 0; + } + + return 1; +} + /* u3m_fault(): handle a memory event with libsigsegv protocol. -*/ + */ c3_i u3m_fault(void* adr_v, c3_i ser_i) { @@ -1786,8 +1844,44 @@ u3m_fault(void* adr_v, c3_i ser_i) // this could be avoided by registering the loom bounds in libsigsegv // else if ( (adr_w < u3_Loom) || (adr_w >= (u3_Loom + u3C.wor_i)) ) { - fprintf(stderr, "loom: external fault: %p (%p : %p)\r\n\r\n", - adr_w, u3_Loom, u3_Loom + u3C.wor_i); + u3l_log("loom: external fault: %p (%p : %p)\r\n", + adr_w, u3_Loom, u3_Loom + u3C.wor_i); + + u3l_log("Stacktrace (%d):", ser_i); + + void* bt_state; + c3_i ret_i; + struct bt_cb_data data = { 0, 0 }; + + c3_c* self_path_c[4096] = {0}; + if ( _main_self_path((c3_c*)self_path_c) == 0 ) { + bt_state = backtrace_create_state((const c3_c*)self_path_c, 0, err_cb, 0); + ret_i = backtrace_full(bt_state, 0, bt_cb, err_cb, &data); + if (data.fail == 0) u3l_log(""); + } + else { + data.fail = 1; + } + + if ( data.fail == 1 ) { + void* array[100]; + c3_c** strings; + size_t size = backtrace(array, 100); + + strings = backtrace_symbols(array, size); + + if ( strings == NULL ) { + u3l_log("Backtrace failed"); + } + else { + for ( c3_i i = 0; i < size; i++ ) + u3l_log("%s", strings[i]); + u3l_log(""); + } + + free(strings); + } + u3_assert(0); return 0; } From 5f8b2259cbeed63aecbc4e99bf4a20902a738044 Mon Sep 17 00:00:00 2001 From: Santeri Hannula Date: Thu, 11 Jul 2024 14:27:47 +0300 Subject: [PATCH 04/24] manage: prettify stacktrace --- pkg/noun/manage.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/pkg/noun/manage.c b/pkg/noun/manage.c index 07fa7024cb..2ccd00b9bb 100644 --- a/pkg/noun/manage.c +++ b/pkg/noun/manage.c @@ -1802,7 +1802,9 @@ bt_cb(void* data, if ( bdata->count <= 100 ) { if ( filename != NULL ) { - u3l_log("%s:%d %s", filename, lineno, function); + c3_c* loc[128]; + snprintf((c3_c *)loc, 128, "%s:%d", filename, lineno); + u3l_log("%-3d %-35s %s", bdata->count - 1, function, (c3_c *)loc); } return 0; } From f05d5aa1f6fdc77c8e947b4a908331237018eaf5 Mon Sep 17 00:00:00 2001 From: Santeri Hannula Date: Thu, 11 Jul 2024 14:43:53 +0300 Subject: [PATCH 05/24] manage: print libbacktrace frames even when symbols were not found --- pkg/noun/manage.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pkg/noun/manage.c b/pkg/noun/manage.c index 2ccd00b9bb..9b14250d77 100644 --- a/pkg/noun/manage.c +++ b/pkg/noun/manage.c @@ -1801,11 +1801,9 @@ bt_cb(void* data, bdata->count++; if ( bdata->count <= 100 ) { - if ( filename != NULL ) { - c3_c* loc[128]; - snprintf((c3_c *)loc, 128, "%s:%d", filename, lineno); - u3l_log("%-3d %-35s %s", bdata->count - 1, function, (c3_c *)loc); - } + c3_c* loc[128]; + snprintf((c3_c *)loc, 128, "%s:%d", filename, lineno); + u3l_log("%-3d %-35s %s", bdata->count - 1, function, (c3_c *)loc); return 0; } else { From 0054a1297dc17fc358ca661ba9b45df754f2f24e Mon Sep 17 00:00:00 2001 From: Santeri Hannula Date: Fri, 12 Jul 2024 14:02:59 +0300 Subject: [PATCH 06/24] deps: add libexecinfo for linux --- WORKSPACE.bazel | 9 +++++++++ bazel/third_party/libexecinfo/BUILD.bazel | 0 bazel/third_party/libexecinfo/libexecinfo.BUILD | 14 ++++++++++++++ pkg/noun/BUILD.bazel | 5 ++++- 4 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 bazel/third_party/libexecinfo/BUILD.bazel create mode 100644 bazel/third_party/libexecinfo/libexecinfo.BUILD diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel index 7105c55ac9..39d081bcfa 100644 --- a/WORKSPACE.bazel +++ b/WORKSPACE.bazel @@ -242,6 +242,15 @@ versioned_http_archive( version = "4ead348bb45f753121ca0bd44170ff8352d4c514", ) +versioned_http_archive( + name = "libexecinfo", + build_file = "//bazel/third_party/libexecinfo:libexecinfo.BUILD", + sha256 = "3f00073eac3322551e96d66a00ae46796bdb22f7ce13d3ad0fe1313fc57cd72c", + url = "https://github.com/resslinux/libexecinfo/archive/{version}.tar.gz", + strip_prefix = "libexecinfo-{version}", + version = "115624ccf81e731c2fa732595acf6547555f03be", +) + versioned_http_archive( name = "lmdb", build_file = "//bazel/third_party/lmdb:lmdb.BUILD", diff --git a/bazel/third_party/libexecinfo/BUILD.bazel b/bazel/third_party/libexecinfo/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bazel/third_party/libexecinfo/libexecinfo.BUILD b/bazel/third_party/libexecinfo/libexecinfo.BUILD new file mode 100644 index 0000000000..3c7a3d5dbb --- /dev/null +++ b/bazel/third_party/libexecinfo/libexecinfo.BUILD @@ -0,0 +1,14 @@ +cc_library( + name = "libexecinfo", + srcs = [ + "execinfo.c", + "stacktraverse.c", + ], + hdrs = [ + "execinfo.h", + "stacktraverse.h", + ], + copts = ["-O3 -g"], + includes = ["."], + visibility = ["//visibility:public"], +) diff --git a/pkg/noun/BUILD.bazel b/pkg/noun/BUILD.bazel index 9b5347dfcf..f56c1a3ee6 100644 --- a/pkg/noun/BUILD.bazel +++ b/pkg/noun/BUILD.bazel @@ -44,7 +44,10 @@ vere_library( "@whereami", ] + select({ "@platforms//os:macos": ["//pkg/noun/platform/darwin"], - "@platforms//os:linux": ["//pkg/noun/platform/linux"], + "@platforms//os:linux": [ + "//pkg/noun/platform/linux", + "@libexecinfo", + ], "//conditions:default": [], }), ) From e0c2a329c9876f6f7c84ff1fb6974fcfede8319b Mon Sep 17 00:00:00 2001 From: Santeri Hannula Date: Thu, 18 Jul 2024 17:07:29 +0300 Subject: [PATCH 07/24] deps: add libunwind for linux --- WORKSPACE.bazel | 9 ++++++++ bazel/third_party/libunwind/BUILD.bazel | 0 bazel/third_party/libunwind/libunwind.BUILD | 25 +++++++++++++++++++++ pkg/noun/BUILD.bazel | 1 + 4 files changed, 35 insertions(+) create mode 100644 bazel/third_party/libunwind/BUILD.bazel create mode 100644 bazel/third_party/libunwind/libunwind.BUILD diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel index 39d081bcfa..1d1f79dced 100644 --- a/WORKSPACE.bazel +++ b/WORKSPACE.bazel @@ -251,6 +251,15 @@ versioned_http_archive( version = "115624ccf81e731c2fa732595acf6547555f03be", ) +versioned_http_archive( + name = "libunwind", + build_file = "//bazel/third_party/libunwind:libunwind.BUILD", + sha256 = "ddf0e32dd5fafe5283198d37e4bf9decf7ba1770b6e7e006c33e6df79e6a6157", + url = "https://github.com/libunwind/libunwind/releases/download/v1.8.1/libunwind-1.8.1.tar.gz", + strip_prefix = "libunwind-{version}", + version = "1.8.1", +) + versioned_http_archive( name = "lmdb", build_file = "//bazel/third_party/lmdb:lmdb.BUILD", diff --git a/bazel/third_party/libunwind/BUILD.bazel b/bazel/third_party/libunwind/BUILD.bazel new file mode 100644 index 0000000000..e69de29bb2 diff --git a/bazel/third_party/libunwind/libunwind.BUILD b/bazel/third_party/libunwind/libunwind.BUILD new file mode 100644 index 0000000000..3934b8f8b3 --- /dev/null +++ b/bazel/third_party/libunwind/libunwind.BUILD @@ -0,0 +1,25 @@ +load("@rules_foreign_cc//foreign_cc:defs.bzl", "configure_make") + +filegroup( + name = "all", + srcs = glob(["**"]), +) + +configure_make( + name = "libunwind", + args = select({ + "@platforms//os:macos": ["--jobs=`sysctl -n hw.logicalcpu`"], + "//conditions:default": ["--jobs=`nproc`"], + }), + configure_options = [ + "--enable-debug-frame", + ] + select({ + "@//:linux_aarch64": ["--host=aarch64-linux-musl"], + "@//:linux_x86_64": ["--host=x86_64-linux-musl"], + "//conditions:default": [], + }), + copts = ["-O3 -g"], + lib_source = ":all", + out_static_libs = ["libunwind.a"], + visibility = ["//visibility:public"], +) diff --git a/pkg/noun/BUILD.bazel b/pkg/noun/BUILD.bazel index f56c1a3ee6..859f894a49 100644 --- a/pkg/noun/BUILD.bazel +++ b/pkg/noun/BUILD.bazel @@ -47,6 +47,7 @@ vere_library( "@platforms//os:linux": [ "//pkg/noun/platform/linux", "@libexecinfo", + "@libunwind", ], "//conditions:default": [], }), From 94001b5dd48289d2025e61993e5df784abf4af6b Mon Sep 17 00:00:00 2001 From: Santeri Hannula Date: Thu, 18 Jul 2024 17:10:56 +0300 Subject: [PATCH 08/24] build: include frame pointers --- bazel/common_settings.bzl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/bazel/common_settings.bzl b/bazel/common_settings.bzl index c4bcfcfa35..9ec74beda5 100644 --- a/bazel/common_settings.bzl +++ b/bazel/common_settings.bzl @@ -13,7 +13,9 @@ string_flag = rule( def vere_library(copts = [], linkopts = [], **kwargs): native.cc_library( - copts = copts + select({ + copts = copts + [ + "-fno-omit-frame-pointer", + ] + select({ "//:debug": ["-O0", "-g3", "-DC3DBG", "-fdebug-compilation-dir=."], "//conditions:default": ["-O3", "-g"] }) + select({ @@ -30,7 +32,9 @@ def vere_library(copts = [], linkopts = [], **kwargs): def vere_binary(copts = [], linkopts = [], **kwargs): native.cc_binary( - copts = copts + select({ + copts = copts + [ + "-fno-omit-frame-pointer", + ] + select({ "//:debug": ["-O0", "-g3", "-DC3DBG", "-fdebug-compilation-dir=."], "//conditions:default": ["-O3", "-g"] }) + select({ From 5eeb0f72d9146396fdc062ca93f50726aa0014f7 Mon Sep 17 00:00:00 2001 From: Santeri Hannula Date: Thu, 18 Jul 2024 17:12:21 +0300 Subject: [PATCH 09/24] manage: unwind backtrace frames with libunwind on linux --- pkg/noun/manage.c | 73 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 62 insertions(+), 11 deletions(-) diff --git a/pkg/noun/manage.c b/pkg/noun/manage.c index 9b14250d77..0af39f717c 100644 --- a/pkg/noun/manage.c +++ b/pkg/noun/manage.c @@ -6,9 +6,15 @@ #include #include +#if defined(U3_OS_osx) #include +#endif #include #include +#if defined(U3_OS_linux) +#define UNW_LOCAL_ONLY +#include +#endif #include "allocate.h" #include "backtrace.h" @@ -1774,8 +1780,9 @@ _cm_limits(void) } struct bt_cb_data { - c3_y count; - c3_y fail; + c3_y count; + c3_y fail; + c3_c* pn_c; }; void @@ -1802,19 +1809,32 @@ bt_cb(void* data, if ( bdata->count <= 100 ) { c3_c* loc[128]; - snprintf((c3_c *)loc, 128, "%s:%d", filename, lineno); - u3l_log("%-3d %-35s %s", bdata->count - 1, function, (c3_c *)loc); + if (filename != 0) + snprintf((c3_c *)loc, 128, "%s:%d", filename, lineno); + else + snprintf((c3_c *)loc, 128, "-"); + + c3_c* fn_c; + if (function != 0 || bdata->pn_c != 0) + fn_c = function != 0 ? function : bdata->pn_c; + else + fn_c = "-"; + + u3l_log("%-3d %-35s %s", bdata->count - 1, fn_c , (c3_c *)loc); + + bdata->pn_c = 0; return 0; } else { + bdata->pn_c = 0; return 1; } } -/* _main_self_path(): get binary self-path. +/* _self_path(): get binary self-path. */ c3_y -_main_self_path(c3_c *pat_c) +_self_path(c3_c *pat_c) { c3_i len_i = 0; c3_i pat_i; @@ -1847,14 +1867,15 @@ u3m_fault(void* adr_v, c3_i ser_i) u3l_log("loom: external fault: %p (%p : %p)\r\n", adr_w, u3_Loom, u3_Loom + u3C.wor_i); - u3l_log("Stacktrace (%d):", ser_i); - void* bt_state; c3_i ret_i; - struct bt_cb_data data = { 0, 0 }; - + struct bt_cb_data data = { 0, 0, 0 }; c3_c* self_path_c[4096] = {0}; - if ( _main_self_path((c3_c*)self_path_c) == 0 ) { + +#if defined(U3_OS_osx) + u3l_log("Stacktrace:"); + + if ( _self_path((c3_c*)self_path_c) == 0 ) { bt_state = backtrace_create_state((const c3_c*)self_path_c, 0, err_cb, 0); ret_i = backtrace_full(bt_state, 0, bt_cb, err_cb, &data); if (data.fail == 0) u3l_log(""); @@ -1881,6 +1902,36 @@ u3m_fault(void* adr_v, c3_i ser_i) free(strings); } +#elif defined(U3_OS_linux) + u3l_log("Stacktrace:"); + + if ( _self_path((c3_c*)self_path_c) == 0 ) { + bt_state = backtrace_create_state((const c3_c*)self_path_c, 0, err_cb, 0); + + unw_context_t context; + unw_cursor_t cursor; + unw_getcontext(&context); + unw_init_local(&cursor, &context); + unw_word_t pc, sp; + + c3_c* pn_c[1024] = {0}; + c3_w offp_w = 0; + + do { + unw_get_reg(&cursor, UNW_REG_IP, &pc); + unw_get_reg(&cursor, UNW_REG_SP, &sp); + if ( 0 == unw_get_proc_name(&cursor, pn_c, 1024, &offp_w) ) + data.pn_c = pn_c; + ret_i = backtrace_pcinfo(bt_state, pc - 1, bt_cb, err_cb, &data); + } while (unw_step(&cursor) > 0); + + if ( (data.count > 0) ) u3l_log(""); + } + else { + data.fail = 1; + u3l_log("Backtrace failed"); + } +#endif u3_assert(0); return 0; From 743987c0724f46da9d77d7a049993401f9b96eda Mon Sep 17 00:00:00 2001 From: Santeri Hannula Date: Thu, 18 Jul 2024 17:17:53 +0300 Subject: [PATCH 10/24] deps: remove redundant libexecinfo --- WORKSPACE.bazel | 9 --------- bazel/third_party/libexecinfo/BUILD.bazel | 0 bazel/third_party/libexecinfo/libexecinfo.BUILD | 14 -------------- pkg/noun/BUILD.bazel | 1 - 4 files changed, 24 deletions(-) delete mode 100644 bazel/third_party/libexecinfo/BUILD.bazel delete mode 100644 bazel/third_party/libexecinfo/libexecinfo.BUILD diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel index 1d1f79dced..e12aa50f5d 100644 --- a/WORKSPACE.bazel +++ b/WORKSPACE.bazel @@ -242,15 +242,6 @@ versioned_http_archive( version = "4ead348bb45f753121ca0bd44170ff8352d4c514", ) -versioned_http_archive( - name = "libexecinfo", - build_file = "//bazel/third_party/libexecinfo:libexecinfo.BUILD", - sha256 = "3f00073eac3322551e96d66a00ae46796bdb22f7ce13d3ad0fe1313fc57cd72c", - url = "https://github.com/resslinux/libexecinfo/archive/{version}.tar.gz", - strip_prefix = "libexecinfo-{version}", - version = "115624ccf81e731c2fa732595acf6547555f03be", -) - versioned_http_archive( name = "libunwind", build_file = "//bazel/third_party/libunwind:libunwind.BUILD", diff --git a/bazel/third_party/libexecinfo/BUILD.bazel b/bazel/third_party/libexecinfo/BUILD.bazel deleted file mode 100644 index e69de29bb2..0000000000 diff --git a/bazel/third_party/libexecinfo/libexecinfo.BUILD b/bazel/third_party/libexecinfo/libexecinfo.BUILD deleted file mode 100644 index 3c7a3d5dbb..0000000000 --- a/bazel/third_party/libexecinfo/libexecinfo.BUILD +++ /dev/null @@ -1,14 +0,0 @@ -cc_library( - name = "libexecinfo", - srcs = [ - "execinfo.c", - "stacktraverse.c", - ], - hdrs = [ - "execinfo.h", - "stacktraverse.h", - ], - copts = ["-O3 -g"], - includes = ["."], - visibility = ["//visibility:public"], -) diff --git a/pkg/noun/BUILD.bazel b/pkg/noun/BUILD.bazel index 859f894a49..1be5825990 100644 --- a/pkg/noun/BUILD.bazel +++ b/pkg/noun/BUILD.bazel @@ -46,7 +46,6 @@ vere_library( "@platforms//os:macos": ["//pkg/noun/platform/darwin"], "@platforms//os:linux": [ "//pkg/noun/platform/linux", - "@libexecinfo", "@libunwind", ], "//conditions:default": [], From 2d6bbe2bf50ece7e4767b8fb92d78f07fee6feae Mon Sep 17 00:00:00 2001 From: Santeri Hannula Date: Mon, 22 Jul 2024 16:36:34 +0300 Subject: [PATCH 11/24] bazel: upgrade gcc and musl in linux toolchain --- BUILD.bazel | 4 ++-- bazel/toolchain/BUILD.bazel | 4 ++++ pkg/vere/king.c | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/BUILD.bazel b/BUILD.bazel index 3569ed78a2..730fe0ec81 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -84,8 +84,8 @@ string_flag( # Version flag for gcc. string_flag( name = "gcc_version", - # musl-cross-make uses `gcc-9.4.0` by default. - build_setting_default = "9.4.0", + # musl-cross-make uses `gcc-11.4.0` by default. + build_setting_default = "11.4.0", visibility = ["//visibility:public"], ) diff --git a/bazel/toolchain/BUILD.bazel b/bazel/toolchain/BUILD.bazel index aaed5de087..9cf9447963 100644 --- a/bazel/toolchain/BUILD.bazel +++ b/bazel/toolchain/BUILD.bazel @@ -349,6 +349,8 @@ genrule( echo ' tar -xf {}.tar.gz' >> $@ echo ' archive=musl-cross-make-{}' >> $@ echo ' echo OUTPUT=$$aarch64_linux_musl_install > $$archive/config.mak' >> $@ + echo ' echo GCC_VER=11.4.0 >> $$archive/config.mak' >> $@ + echo ' echo MUSL_VER=1.2.5 >> $$archive/config.mak' >> $@ echo ' TARGET=aarch64-linux-musl make -s -C$$archive -j`nproc`' >> $@ echo ' sudo TARGET=aarch64-linux-musl make -s -C$$archive -j`nproc` install' >> $@ echo ' sudo chown --recursive $$USER $$aarch64_linux_musl_install' >> $@ @@ -382,6 +384,8 @@ genrule( echo ' tar -xf {}.tar.gz' >> $@ echo ' archive=musl-cross-make-{}' >> $@ echo ' echo OUTPUT=$$x86_64_linux_musl_install > $$archive/config.mak' >> $@ + echo ' echo GCC_VER=11.4.0 >> $$archive/config.mak' >> $@ + echo ' echo MUSL_VER=1.2.5 >> $$archive/config.mak' >> $@ echo ' TARGET=x86_64-linux-musl make -s -C$$archive -j`nproc`' >> $@ echo ' sudo TARGET=x86_64-linux-musl make -s -C$$archive -j`nproc` install' >> $@ echo ' sudo chown --recursive $$USER $$x86_64_linux_musl_install' >> $@ diff --git a/pkg/vere/king.c b/pkg/vere/king.c index 915ce7262f..bd619564b2 100644 --- a/pkg/vere/king.c +++ b/pkg/vere/king.c @@ -1437,7 +1437,7 @@ _king_copy_file(c3_c* src_c, c3_c* dst_c) do { // XX fallback on any errors? // - if ( 0 > (sen_i = sendfile64(dst_i, src_i, &off_i, len_i)) ) { + if ( 0 > (sen_i = sendfile(dst_i, src_i, &off_i, len_i)) ) { err_i = errno; ret_i = -1; goto done3; From 34c936998a7aef74211f3f63dcfa9ff8e7bcd9bd Mon Sep 17 00:00:00 2001 From: Santeri Hannula Date: Mon, 22 Jul 2024 16:37:06 +0300 Subject: [PATCH 12/24] build: upgrade musl-cross-make and quick fix libunwind for arm linux --- bazel/toolchain/BUILD.bazel | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bazel/toolchain/BUILD.bazel b/bazel/toolchain/BUILD.bazel index 9cf9447963..38fa379197 100644 --- a/bazel/toolchain/BUILD.bazel +++ b/bazel/toolchain/BUILD.bazel @@ -335,9 +335,9 @@ toolchain( # so introduces a circular dependency during Bazel C/C++ toolchain resolution. # musl-cross-make builds musl-libc-compatible gcc toolchains from source. -_musl_cross_make_version = "fe915821b652a7fa37b34a596f47d8e20bc72338" +_musl_cross_make_version = "99f2cbc7e230f72bde3394be3ebd50497cb53e89" -_musl_cross_make_archive = "https://github.com/richfelker/musl-cross-make/archive/{}.tar.gz".format(_musl_cross_make_version) +_musl_cross_make_archive = "https://github.com/ripperi/musl-cross-make/archive/{}.tar.gz".format(_musl_cross_make_version) genrule( name = "install-aarch64-linux-musl-gcc", From f34d5aa3bfb0fdbc8e1de6d603b0b1b188d3737f Mon Sep 17 00:00:00 2001 From: Santeri Hannula Date: Tue, 23 Jul 2024 14:12:31 +0300 Subject: [PATCH 13/24] manage: try to resolve symbols with dladdr as a fallback --- pkg/noun/manage.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pkg/noun/manage.c b/pkg/noun/manage.c index 0af39f717c..4a9ca52a36 100644 --- a/pkg/noun/manage.c +++ b/pkg/noun/manage.c @@ -5,6 +5,7 @@ #include "pkg/noun/v3/manage.h" #include +#include #include #if defined(U3_OS_osx) #include @@ -1807,20 +1808,29 @@ bt_cb(void* data, struct bt_cb_data* bdata = (struct bt_cb_data *)data; bdata->count++; + Dl_info info = {}; + c3_c* fname_c = {0}; + + if ( dladdr((void *)pc, &info) ) { + for ( c3_w i_w = 0; info.dli_fname[i_w] != 0; i_w++ ) + if ( info.dli_fname[i_w] == '/' ) + fname_c = &info.dli_fname[i_w + 1]; + } + if ( bdata->count <= 100 ) { c3_c* loc[128]; if (filename != 0) snprintf((c3_c *)loc, 128, "%s:%d", filename, lineno); else - snprintf((c3_c *)loc, 128, "-"); + snprintf((c3_c *)loc, 128, fname_c != 0 ? fname_c : "-"); c3_c* fn_c; if (function != 0 || bdata->pn_c != 0) fn_c = function != 0 ? function : bdata->pn_c; else - fn_c = "-"; + fn_c = info.dli_sname != 0 ? info.dli_sname : "-"; - u3l_log("%-3d %-35s %s", bdata->count - 1, fn_c , (c3_c *)loc); + u3l_log("%-3d %-35s %s", bdata->count - 1, fn_c, (c3_c *)loc); bdata->pn_c = 0; return 0; From 742f14dd5981a29d99eeb2d52b258b37bd8716a0 Mon Sep 17 00:00:00 2001 From: Santeri Hannula Date: Wed, 24 Jul 2024 16:57:50 +0300 Subject: [PATCH 14/24] manage: move stacktrace printing under `u3m_bail` --- pkg/noun/manage.c | 300 ++++++++++++++++++++++++---------------------- 1 file changed, 154 insertions(+), 146 deletions(-) diff --git a/pkg/noun/manage.c b/pkg/noun/manage.c index 4a9ca52a36..91a1cdb421 100644 --- a/pkg/noun/manage.c +++ b/pkg/noun/manage.c @@ -738,6 +738,156 @@ u3m_dump(void) } #endif +struct bt_cb_data { + c3_y count; + c3_y fail; + c3_c* pn_c; +}; + +static void +err_cb(void* data, const char* msg, int errnum) +{ + struct bt_cb_data* bdata = (struct bt_cb_data *)data; + bdata->count++; + + if ( bdata->count <= 1 ) { + /* u3l_log("Backtrace error %d: %s", errnum, msg); */ + bdata->fail = 1; + } +} + +static int +bt_cb(void* data, + uintptr_t pc, + const char* filename, + int lineno, + const char* function) +{ + struct bt_cb_data* bdata = (struct bt_cb_data *)data; + bdata->count++; + + Dl_info info = {}; + c3_c* fname_c = {0}; + + if ( dladdr((void *)pc, &info) ) { + for ( c3_w i_w = 0; info.dli_fname[i_w] != 0; i_w++ ) + if ( info.dli_fname[i_w] == '/' ) + fname_c = &info.dli_fname[i_w + 1]; + } + + if ( bdata->count <= 100 ) { + c3_c* loc[128]; + if (filename != 0) + snprintf((c3_c *)loc, 128, "%s:%d", filename, lineno); + else + snprintf((c3_c *)loc, 128, fname_c != 0 ? fname_c : "-"); + + c3_c* fn_c; + if (function != 0 || bdata->pn_c != 0) + fn_c = function != 0 ? function : bdata->pn_c; + else + fn_c = info.dli_sname != 0 ? info.dli_sname : "-"; + + u3l_log("%-3d %-35s %s", bdata->count - 1, fn_c, (c3_c *)loc); + + bdata->pn_c = 0; + return 0; + } + else { + bdata->pn_c = 0; + return 1; + } +} + +/* _self_path(): get binary self-path. + */ +static c3_y +_self_path(c3_c *pat_c) +{ + c3_i len_i = 0; + c3_i pat_i; + + if ( 0 < (len_i = wai_getExecutablePath(NULL, 0, &pat_i)) ) { + wai_getExecutablePath(pat_c, len_i, &pat_i); + pat_c[len_i] = 0; + return 0; + } + + return 1; +} + +void +u3m_stacktrace() +{ + void* bt_state; + c3_i ret_i; + struct bt_cb_data data = { 0, 0, 0 }; + c3_c* self_path_c[4096] = {0}; + +#if defined(U3_OS_osx) + u3l_log("Stacktrace:"); + + if ( _self_path((c3_c*)self_path_c) == 0 ) { + bt_state = backtrace_create_state((const c3_c*)self_path_c, 0, err_cb, 0); + ret_i = backtrace_full(bt_state, 0, bt_cb, err_cb, &data); + if (data.fail == 0) u3l_log(""); + } + else { + data.fail = 1; + } + + if ( data.fail == 1 ) { + void* array[100]; + c3_c** strings; + size_t size = backtrace(array, 100); + + strings = backtrace_symbols(array, size); + + if ( strings == NULL ) { + u3l_log("Backtrace failed"); + } + else { + for ( c3_i i = 0; i < size; i++ ) + u3l_log("%s", strings[i]); + u3l_log(""); + } + + free(strings); + } +#elif defined(U3_OS_linux) + /* TODO: Fix unwind not getting past signal trampoline on linux aarch64 + */ + u3l_log("Stacktrace:"); + + if ( _self_path((c3_c*)self_path_c) == 0 ) { + bt_state = backtrace_create_state((const c3_c*)self_path_c, 0, err_cb, 0); + + unw_context_t context; + unw_cursor_t cursor; + unw_getcontext(&context); + unw_init_local(&cursor, &context); + unw_word_t pc, sp; + + c3_c* pn_c[1024] = {0}; + c3_w offp_w = 0; + + do { + unw_get_reg(&cursor, UNW_REG_IP, &pc); + unw_get_reg(&cursor, UNW_REG_SP, &sp); + if ( 0 == unw_get_proc_name(&cursor, pn_c, 1024, &offp_w) ) + data.pn_c = pn_c; + ret_i = backtrace_pcinfo(bt_state, pc - 1, bt_cb, err_cb, &data); + } while (unw_step(&cursor) > 0); + + if ( (data.count > 0) ) u3l_log(""); + } + else { + data.fail = 1; + u3l_log("Backtrace failed"); + } +#endif +} + /* u3m_bail(): bail out. Does not return. ** ** Bail motes: @@ -790,7 +940,8 @@ u3m_bail(u3_noun how) if ( &(u3H->rod_u) == u3R ) { // XX set exit code // - fprintf(stderr, "home: bailing out\r\n"); + u3l_log("home: bailing out\r\n"); + u3m_stacktrace(); abort(); } @@ -801,7 +952,8 @@ u3m_bail(u3_noun how) case c3__oops: { // XX set exit code // - fprintf(stderr, "bailing out\r\n"); + u3l_log("bailing out\r\n"); + u3m_stacktrace(); abort(); } } @@ -1780,84 +1932,6 @@ _cm_limits(void) # endif } -struct bt_cb_data { - c3_y count; - c3_y fail; - c3_c* pn_c; -}; - -void -err_cb(void* data, const char* msg, int errnum) -{ - struct bt_cb_data* bdata = (struct bt_cb_data *)data; - bdata->count++; - - if ( bdata->count <= 1 ) { - /* u3l_log("Backtrace error %d: %s", errnum, msg); */ - bdata->fail = 1; - } -} - -int -bt_cb(void* data, - uintptr_t pc, - const char* filename, - int lineno, - const char* function) -{ - struct bt_cb_data* bdata = (struct bt_cb_data *)data; - bdata->count++; - - Dl_info info = {}; - c3_c* fname_c = {0}; - - if ( dladdr((void *)pc, &info) ) { - for ( c3_w i_w = 0; info.dli_fname[i_w] != 0; i_w++ ) - if ( info.dli_fname[i_w] == '/' ) - fname_c = &info.dli_fname[i_w + 1]; - } - - if ( bdata->count <= 100 ) { - c3_c* loc[128]; - if (filename != 0) - snprintf((c3_c *)loc, 128, "%s:%d", filename, lineno); - else - snprintf((c3_c *)loc, 128, fname_c != 0 ? fname_c : "-"); - - c3_c* fn_c; - if (function != 0 || bdata->pn_c != 0) - fn_c = function != 0 ? function : bdata->pn_c; - else - fn_c = info.dli_sname != 0 ? info.dli_sname : "-"; - - u3l_log("%-3d %-35s %s", bdata->count - 1, fn_c, (c3_c *)loc); - - bdata->pn_c = 0; - return 0; - } - else { - bdata->pn_c = 0; - return 1; - } -} - -/* _self_path(): get binary self-path. - */ -c3_y -_self_path(c3_c *pat_c) -{ - c3_i len_i = 0; - c3_i pat_i; - - if ( 0 < (len_i = wai_getExecutablePath(NULL, 0, &pat_i)) ) { - wai_getExecutablePath(pat_c, len_i, &pat_i); - pat_c[len_i] = 0; - return 0; - } - - return 1; -} - /* u3m_fault(): handle a memory event with libsigsegv protocol. */ c3_i @@ -1877,72 +1951,6 @@ u3m_fault(void* adr_v, c3_i ser_i) u3l_log("loom: external fault: %p (%p : %p)\r\n", adr_w, u3_Loom, u3_Loom + u3C.wor_i); - void* bt_state; - c3_i ret_i; - struct bt_cb_data data = { 0, 0, 0 }; - c3_c* self_path_c[4096] = {0}; - -#if defined(U3_OS_osx) - u3l_log("Stacktrace:"); - - if ( _self_path((c3_c*)self_path_c) == 0 ) { - bt_state = backtrace_create_state((const c3_c*)self_path_c, 0, err_cb, 0); - ret_i = backtrace_full(bt_state, 0, bt_cb, err_cb, &data); - if (data.fail == 0) u3l_log(""); - } - else { - data.fail = 1; - } - - if ( data.fail == 1 ) { - void* array[100]; - c3_c** strings; - size_t size = backtrace(array, 100); - - strings = backtrace_symbols(array, size); - - if ( strings == NULL ) { - u3l_log("Backtrace failed"); - } - else { - for ( c3_i i = 0; i < size; i++ ) - u3l_log("%s", strings[i]); - u3l_log(""); - } - - free(strings); - } -#elif defined(U3_OS_linux) - u3l_log("Stacktrace:"); - - if ( _self_path((c3_c*)self_path_c) == 0 ) { - bt_state = backtrace_create_state((const c3_c*)self_path_c, 0, err_cb, 0); - - unw_context_t context; - unw_cursor_t cursor; - unw_getcontext(&context); - unw_init_local(&cursor, &context); - unw_word_t pc, sp; - - c3_c* pn_c[1024] = {0}; - c3_w offp_w = 0; - - do { - unw_get_reg(&cursor, UNW_REG_IP, &pc); - unw_get_reg(&cursor, UNW_REG_SP, &sp); - if ( 0 == unw_get_proc_name(&cursor, pn_c, 1024, &offp_w) ) - data.pn_c = pn_c; - ret_i = backtrace_pcinfo(bt_state, pc - 1, bt_cb, err_cb, &data); - } while (unw_step(&cursor) > 0); - - if ( (data.count > 0) ) u3l_log(""); - } - else { - data.fail = 1; - u3l_log("Backtrace failed"); - } -#endif - u3_assert(0); return 0; } From c5908518adebcecb3caae349e627b9bae5a65d00 Mon Sep 17 00:00:00 2001 From: Pyry Kovanen Date: Wed, 24 Jul 2024 19:43:43 +0300 Subject: [PATCH 15/24] actions: rebuild toolchain cache for toolchain upgrade --- .github/workflows/shared.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/shared.yml b/.github/workflows/shared.yml index aee47884a5..ddfb757a5c 100644 --- a/.github/workflows/shared.yml +++ b/.github/workflows/shared.yml @@ -64,7 +64,7 @@ jobs: - name: Set up build cache uses: actions/cache@v3 with: - key: ${{ matrix.target }}-cache + key: ${{ matrix.target }}-cache-1 path: | # # Cache bazel path on Linux. ~/.cache/bazel/_bazel_$(whoami) From 1b4c2eb3c3a0f18b25dd64beefb3a4fbb090f47b Mon Sep 17 00:00:00 2001 From: Santeri Hannula Date: Thu, 25 Jul 2024 13:42:18 +0300 Subject: [PATCH 16/24] build: add `configure_options` to libexpat build --- bazel/third_party/expat/expat.BUILD | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/bazel/third_party/expat/expat.BUILD b/bazel/third_party/expat/expat.BUILD index 030f81ed78..1c0a6bc36d 100644 --- a/bazel/third_party/expat/expat.BUILD +++ b/bazel/third_party/expat/expat.BUILD @@ -11,6 +11,12 @@ configure_make( "@platforms//os:macos": ["--jobs=`sysctl -n hw.logicalcpu`"], "//conditions:default": ["--jobs=`nproc`"], }), + configure_options = [ + ] + select({ + "@//:linux_aarch64": ["--host=aarch64-linux-musl"], + "@//:linux_x86_64": ["--host=x86_64-linux-musl"], + "//conditions:default": [], + }), copts = ["-O3"], lib_source = ":all", out_static_libs = ["libexpat.a"], From d01d1d4407855eb63f9b069dfe61e81a30ec479c Mon Sep 17 00:00:00 2001 From: Santeri Hannula Date: Thu, 25 Jul 2024 15:11:27 +0300 Subject: [PATCH 17/24] actions: set swap on linux --- .github/workflows/shared.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/.github/workflows/shared.yml b/.github/workflows/shared.yml index ddfb757a5c..56cbf34fbf 100644 --- a/.github/workflows/shared.yml +++ b/.github/workflows/shared.yml @@ -56,6 +56,33 @@ jobs: # - uses: actions/checkout@v3 + - name: Set swap space + if: ${{ matrix.target == 'linux-x86_64' || matrix.target == 'linux-aarch64'}} + run: | + echo "Memory and swap:" + free -h + echo + swapon --show + echo + + export SWAP_FILE=$(swapon --show=NAME | tail -n 1) + if test -z "${SWAP_FILE}"; then + export SWAP_FILE=/swapfile + else + sudo swapoff -a + sudo rm "${SWAP_FILE}" + fi + sudo fallocate -l 10G "${SWAP_FILE}" + sudo chmod 600 "${SWAP_FILE}" + sudo mkswap "${SWAP_FILE}" + sudo swapon "${SWAP_FILE}" + + echo "Memory and swap:" + free -h + echo + swapon --show + echo + - name: chown /usr/local if: ${{ matrix.target == 'linux-x86_64' || matrix.target == 'linux-aarch64'}} run: | From cc17895e82458b1c576a290a4cc81ecf28cfecfa Mon Sep 17 00:00:00 2001 From: Santeri Hannula Date: Thu, 25 Jul 2024 16:53:51 +0300 Subject: [PATCH 18/24] build: decrease liburcrypt optimization level --- bazel/third_party/urcrypt/urcrypt.BUILD | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bazel/third_party/urcrypt/urcrypt.BUILD b/bazel/third_party/urcrypt/urcrypt.BUILD index 973830447d..c41d78f5b0 100644 --- a/bazel/third_party/urcrypt/urcrypt.BUILD +++ b/bazel/third_party/urcrypt/urcrypt.BUILD @@ -15,7 +15,7 @@ configure_make( copts = [ "-Wall", "-g", - "-O3", + "-O2", ], deps = [ "@aes_siv", From e5fa962ee079d03782489dcad43dced53ecb8cfe Mon Sep 17 00:00:00 2001 From: pkova Date: Sat, 27 Jul 2024 21:30:08 +0300 Subject: [PATCH 19/24] bazel: bump openssl --- WORKSPACE.bazel | 6 +++--- bazel/third_party/openssl/openssl.BUILD | 4 +++- pkg/noun/manage.c | 20 ++++++++++++-------- 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel index e12aa50f5d..06e60e04c3 100644 --- a/WORKSPACE.bazel +++ b/WORKSPACE.bazel @@ -280,10 +280,10 @@ versioned_http_archive( versioned_http_archive( name = "openssl", build_file = "//bazel/third_party/openssl:openssl.BUILD", - sha256 = "cf3098950cb4d853ad95c0841f1f9c6d3dc102dccfcacd521d93925208b76ac8", + sha256 = "777cd596284c883375a2a7a11bf5d2786fc5413255efab20c50d6ffe6d020b7e", strip_prefix = "openssl-{version}", - url = "https://github.com/openssl/openssl/releases/download/OpenSSL_1_1_1w/openssl-{version}.tar.gz", - version = "1.1.1w", + url = "https://github.com/openssl/openssl/releases/download/openssl-{version}/openssl-{version}.tar.gz", + version = "3.3.1", ) versioned_http_archive( diff --git a/bazel/third_party/openssl/openssl.BUILD b/bazel/third_party/openssl/openssl.BUILD index bb521c4a98..942efe3814 100644 --- a/bazel/third_party/openssl/openssl.BUILD +++ b/bazel/third_party/openssl/openssl.BUILD @@ -17,6 +17,8 @@ configure_make( }), configure_options = [ "no-shared", + "no-threads", + "-static", ] + select({ "@//:linux_aarch64": [ "linux-aarch64", @@ -29,7 +31,7 @@ configure_make( ], "//conditions:default": [], }), - copts = ["-O3"], + copts = ["-O0", "-g"], lib_source = ":all", out_static_libs = [ "libssl.a", diff --git a/pkg/noun/manage.c b/pkg/noun/manage.c index 91a1cdb421..fcaa590515 100644 --- a/pkg/noun/manage.c +++ b/pkg/noun/manage.c @@ -2121,21 +2121,23 @@ _cm_signals(void) */ static void* _cm_malloc_ssl(size_t len_i -#if OPENSSL_VERSION_NUMBER >= 0x10100000L +/* #if OPENSSL_VERSION_NUMBER >= 0x10100000L */ , const char* file, int line -#endif +/* #endif */ ) { - return u3a_malloc(len_i); + void* ret = u3a_malloc(len_i); + u3l_log("alloc %p", ret); + return ret; } /* _cm_realloc_ssl(): openssl-shaped realloc. */ static void* _cm_realloc_ssl(void* lag_v, size_t len_i -#if OPENSSL_VERSION_NUMBER >= 0x10100000L +/* #if OPENSSL_VERSION_NUMBER >= 0x10100000L */ , const char* file, int line -#endif +/* #endif */ ) { return u3a_realloc(lag_v, len_i); @@ -2145,12 +2147,14 @@ _cm_realloc_ssl(void* lag_v, size_t len_i */ static void _cm_free_ssl(void* tox_v -#if OPENSSL_VERSION_NUMBER >= 0x10100000L +/* #if OPENSSL_VERSION_NUMBER >= 0x10100000L */ , const char* file, int line -#endif +/* #endif */ ) { - return u3a_free(tox_v); + u3l_log("free %p", tox_v); + u3a_free(tox_v); + return; } extern void u3je_secp_init(void); From a068cbde6875ac6796e431ef02baee348fb7a4ba Mon Sep 17 00:00:00 2001 From: Santeri Hannula Date: Tue, 30 Jul 2024 15:04:24 +0300 Subject: [PATCH 20/24] manage: use `fprintf` instead of `u3l_log` for stacktrace --- pkg/noun/manage.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/pkg/noun/manage.c b/pkg/noun/manage.c index 91a1cdb421..059d7d7e7e 100644 --- a/pkg/noun/manage.c +++ b/pkg/noun/manage.c @@ -788,7 +788,7 @@ bt_cb(void* data, else fn_c = info.dli_sname != 0 ? info.dli_sname : "-"; - u3l_log("%-3d %-35s %s", bdata->count - 1, fn_c, (c3_c *)loc); + fprintf(stderr, "%-3d %-35s %s\r\n", bdata->count - 1, fn_c, (c3_c *)loc); bdata->pn_c = 0; return 0; @@ -825,7 +825,7 @@ u3m_stacktrace() c3_c* self_path_c[4096] = {0}; #if defined(U3_OS_osx) - u3l_log("Stacktrace:"); + fprintf(stderr, "Stacktrace:\r\n"); if ( _self_path((c3_c*)self_path_c) == 0 ) { bt_state = backtrace_create_state((const c3_c*)self_path_c, 0, err_cb, 0); @@ -844,11 +844,11 @@ u3m_stacktrace() strings = backtrace_symbols(array, size); if ( strings == NULL ) { - u3l_log("Backtrace failed"); + fprintf(stderr, "Backtrace failed\r\n"); } else { for ( c3_i i = 0; i < size; i++ ) - u3l_log("%s", strings[i]); + fprintf(stderr, "%s\r\n", strings[i]); u3l_log(""); } @@ -857,7 +857,7 @@ u3m_stacktrace() #elif defined(U3_OS_linux) /* TODO: Fix unwind not getting past signal trampoline on linux aarch64 */ - u3l_log("Stacktrace:"); + fprintf(stderr, "Stacktrace:\r\n"); if ( _self_path((c3_c*)self_path_c) == 0 ) { bt_state = backtrace_create_state((const c3_c*)self_path_c, 0, err_cb, 0); @@ -883,7 +883,7 @@ u3m_stacktrace() } else { data.fail = 1; - u3l_log("Backtrace failed"); + fprintf(stderr, "Backtrace failed\r\n"); } #endif } @@ -940,7 +940,7 @@ u3m_bail(u3_noun how) if ( &(u3H->rod_u) == u3R ) { // XX set exit code // - u3l_log("home: bailing out\r\n"); + fprintf(stderr, "home: bailing out\r\n\r\n"); u3m_stacktrace(); abort(); } @@ -952,7 +952,7 @@ u3m_bail(u3_noun how) case c3__oops: { // XX set exit code // - u3l_log("bailing out\r\n"); + fprintf(stderr, "bailing out\r\n\r\n"); u3m_stacktrace(); abort(); } @@ -1948,7 +1948,7 @@ u3m_fault(void* adr_v, c3_i ser_i) // this could be avoided by registering the loom bounds in libsigsegv // else if ( (adr_w < u3_Loom) || (adr_w >= (u3_Loom + u3C.wor_i)) ) { - u3l_log("loom: external fault: %p (%p : %p)\r\n", + fprintf(stderr, "loom: external fault: %p (%p : %p)\r\n\r\n", adr_w, u3_Loom, u3_Loom + u3C.wor_i); u3_assert(0); From b5d53e2d5a92e0aeb964fad167e514ce478063a8 Mon Sep 17 00:00:00 2001 From: pkova Date: Mon, 16 Sep 2024 14:56:36 +0300 Subject: [PATCH 21/24] manage: also print stacktrace on external fault --- pkg/noun/manage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/noun/manage.c b/pkg/noun/manage.c index b26de2ef22..34578b730e 100644 --- a/pkg/noun/manage.c +++ b/pkg/noun/manage.c @@ -1950,7 +1950,7 @@ u3m_fault(void* adr_v, c3_i ser_i) else if ( (adr_w < u3_Loom) || (adr_w >= (u3_Loom + u3C.wor_i)) ) { fprintf(stderr, "loom: external fault: %p (%p : %p)\r\n\r\n", adr_w, u3_Loom, u3_Loom + u3C.wor_i); - + u3m_stacktrace(); u3_assert(0); return 0; } From d8fba622d67626730a7f9e236958bf2e1d1b1b4a Mon Sep 17 00:00:00 2001 From: pkova Date: Mon, 16 Sep 2024 15:04:44 +0300 Subject: [PATCH 22/24] manage: general cleanup of the stacktrace code --- pkg/noun/manage.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/pkg/noun/manage.c b/pkg/noun/manage.c index 34578b730e..a45b036039 100644 --- a/pkg/noun/manage.c +++ b/pkg/noun/manage.c @@ -771,22 +771,27 @@ bt_cb(void* data, if ( dladdr((void *)pc, &info) ) { for ( c3_w i_w = 0; info.dli_fname[i_w] != 0; i_w++ ) - if ( info.dli_fname[i_w] == '/' ) - fname_c = &info.dli_fname[i_w + 1]; + if ( info.dli_fname[i_w] == '/' ) { + fname_c = (c3_c*)&info.dli_fname[i_w + 1]; + } } if ( bdata->count <= 100 ) { c3_c* loc[128]; - if (filename != 0) - snprintf((c3_c *)loc, 128, "%s:%d", filename, lineno); - else - snprintf((c3_c *)loc, 128, fname_c != 0 ? fname_c : "-"); + if (filename != 0) { + snprintf((c3_c*)loc, 128, "%s:%d", filename, lineno); + } + else { + snprintf((c3_c*)loc, 128, "%s", fname_c != 0 ? fname_c : "-"); + } c3_c* fn_c; - if (function != 0 || bdata->pn_c != 0) - fn_c = function != 0 ? function : bdata->pn_c; - else - fn_c = info.dli_sname != 0 ? info.dli_sname : "-"; + if (function != 0 || bdata->pn_c != 0) { + fn_c = (c3_c*)(function != 0 ? function : bdata->pn_c); + } + else { + fn_c = (c3_c*)(info.dli_sname != 0 ? info.dli_sname : "-"); + } fprintf(stderr, "%-3d %-35s %s\r\n", bdata->count - 1, fn_c, (c3_c *)loc); @@ -847,8 +852,9 @@ u3m_stacktrace() fprintf(stderr, "Backtrace failed\r\n"); } else { - for ( c3_i i = 0; i < size; i++ ) + for ( c3_i i = 0; i < size; i++ ) { fprintf(stderr, "%s\r\n", strings[i]); + } u3l_log(""); } @@ -879,7 +885,9 @@ u3m_stacktrace() ret_i = backtrace_pcinfo(bt_state, pc - 1, bt_cb, err_cb, &data); } while (unw_step(&cursor) > 0); - if ( (data.count > 0) ) u3l_log(""); + if ( (data.count > 0) ) { + u3l_log(""); + } } else { data.fail = 1; From 62e4cc20bf04a0274a12c96d1a9472c8096b6491 Mon Sep 17 00:00:00 2001 From: pkova Date: Mon, 16 Sep 2024 15:21:26 +0300 Subject: [PATCH 23/24] Revert "bazel: bump openssl" This reverts commit e5fa962ee079d03782489dcad43dced53ecb8cfe. --- WORKSPACE.bazel | 6 +++--- bazel/third_party/openssl/openssl.BUILD | 4 +--- pkg/noun/manage.c | 20 ++++++++------------ 3 files changed, 12 insertions(+), 18 deletions(-) diff --git a/WORKSPACE.bazel b/WORKSPACE.bazel index 06e60e04c3..e12aa50f5d 100644 --- a/WORKSPACE.bazel +++ b/WORKSPACE.bazel @@ -280,10 +280,10 @@ versioned_http_archive( versioned_http_archive( name = "openssl", build_file = "//bazel/third_party/openssl:openssl.BUILD", - sha256 = "777cd596284c883375a2a7a11bf5d2786fc5413255efab20c50d6ffe6d020b7e", + sha256 = "cf3098950cb4d853ad95c0841f1f9c6d3dc102dccfcacd521d93925208b76ac8", strip_prefix = "openssl-{version}", - url = "https://github.com/openssl/openssl/releases/download/openssl-{version}/openssl-{version}.tar.gz", - version = "3.3.1", + url = "https://github.com/openssl/openssl/releases/download/OpenSSL_1_1_1w/openssl-{version}.tar.gz", + version = "1.1.1w", ) versioned_http_archive( diff --git a/bazel/third_party/openssl/openssl.BUILD b/bazel/third_party/openssl/openssl.BUILD index 942efe3814..bb521c4a98 100644 --- a/bazel/third_party/openssl/openssl.BUILD +++ b/bazel/third_party/openssl/openssl.BUILD @@ -17,8 +17,6 @@ configure_make( }), configure_options = [ "no-shared", - "no-threads", - "-static", ] + select({ "@//:linux_aarch64": [ "linux-aarch64", @@ -31,7 +29,7 @@ configure_make( ], "//conditions:default": [], }), - copts = ["-O0", "-g"], + copts = ["-O3"], lib_source = ":all", out_static_libs = [ "libssl.a", diff --git a/pkg/noun/manage.c b/pkg/noun/manage.c index a45b036039..2147eb2b6e 100644 --- a/pkg/noun/manage.c +++ b/pkg/noun/manage.c @@ -2129,23 +2129,21 @@ _cm_signals(void) */ static void* _cm_malloc_ssl(size_t len_i -/* #if OPENSSL_VERSION_NUMBER >= 0x10100000L */ +#if OPENSSL_VERSION_NUMBER >= 0x10100000L , const char* file, int line -/* #endif */ +#endif ) { - void* ret = u3a_malloc(len_i); - u3l_log("alloc %p", ret); - return ret; + return u3a_malloc(len_i); } /* _cm_realloc_ssl(): openssl-shaped realloc. */ static void* _cm_realloc_ssl(void* lag_v, size_t len_i -/* #if OPENSSL_VERSION_NUMBER >= 0x10100000L */ +#if OPENSSL_VERSION_NUMBER >= 0x10100000L , const char* file, int line -/* #endif */ +#endif ) { return u3a_realloc(lag_v, len_i); @@ -2155,14 +2153,12 @@ _cm_realloc_ssl(void* lag_v, size_t len_i */ static void _cm_free_ssl(void* tox_v -/* #if OPENSSL_VERSION_NUMBER >= 0x10100000L */ +#if OPENSSL_VERSION_NUMBER >= 0x10100000L , const char* file, int line -/* #endif */ +#endif ) { - u3l_log("free %p", tox_v); - u3a_free(tox_v); - return; + return u3a_free(tox_v); } extern void u3je_secp_init(void); From df8e34e3e8b60f3693e1747c15c7db9a93b03031 Mon Sep 17 00:00:00 2001 From: pkova Date: Mon, 16 Sep 2024 15:23:07 +0300 Subject: [PATCH 24/24] manage: fix error check in backtrace codepath --- pkg/noun/manage.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/noun/manage.c b/pkg/noun/manage.c index 2147eb2b6e..cb6c901d27 100644 --- a/pkg/noun/manage.c +++ b/pkg/noun/manage.c @@ -848,7 +848,7 @@ u3m_stacktrace() strings = backtrace_symbols(array, size); - if ( strings == NULL ) { + if ( strings[0] == NULL ) { fprintf(stderr, "Backtrace failed\r\n"); } else {