From 80fcd5470e0ca193d6b5ec7a919c125011b637b7 Mon Sep 17 00:00:00 2001 From: Santeri Hannula Date: Fri, 5 Jul 2024 17:54:19 +0300 Subject: [PATCH 01/39] 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/39] 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/39] 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/39] 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/39] 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/39] 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/39] 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/39] 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/39] 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/39] 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/39] 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/39] 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/39] 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/39] 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/39] 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/39] 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/39] 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/39] 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 2e9a5d60c6cadab45f1aa252df5ab89441a03aa0 Mon Sep 17 00:00:00 2001 From: Sigilante <57601680+sigilante@users.noreply.github.com> Date: Fri, 26 Jul 2024 11:41:25 -0500 Subject: [PATCH 19/39] Add debugging instructions --- CONTRIBUTING.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 96d1076c88..e2738b8d0c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -153,3 +153,21 @@ jump to definition, cross-references, hovering, symbol renaming, etc.): ```console bazel run //bazel:refresh_compile_commands ``` + +### Debugging + +Prefer GDB for interactive debugging. You need to compile with the symbol table: + +```bash +bazel build :urbit --compilation_mode=dbg +gdb --args ./bazel-bin/pkg/vere/urbit zod +``` + +In GDB, set the following, and any breakpoints (e.g. `break u3m_bail`): + +```gdb +set follow-fork-mode child +handle SIGSEGV nostop noprint +``` + +Then run the Urbit program as usual with `r`. From e5fa962ee079d03782489dcad43dced53ecb8cfe Mon Sep 17 00:00:00 2001 From: pkova Date: Sat, 27 Jul 2024 21:30:08 +0300 Subject: [PATCH 20/39] 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 21/39] 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 8c638594b14296c4dce3db4adbb1a3de27a148e9 Mon Sep 17 00:00:00 2001 From: Quodss Date: Wed, 31 Jul 2024 05:59:20 +0200 Subject: [PATCH 22/39] aor jet registration causes segfault --- bazel/common_settings.bzl | 4 ++-- pkg/noun/jets/q.h | 1 + pkg/noun/jets/tree.c | 3 +++ pkg/noun/jets/w.h | 1 + 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/bazel/common_settings.bzl b/bazel/common_settings.bzl index 68a2232cd1..6a61de1292 100644 --- a/bazel/common_settings.bzl +++ b/bazel/common_settings.bzl @@ -14,7 +14,7 @@ string_flag = rule( def vere_library(copts = [], linkopts = [], **kwargs): native.cc_library( copts = copts + select({ - "//:debug": ["-O0", "-g3", "-DC3DBG", "-fdebug-compilation-dir=."], + "//:debug": ["-O0", "-g3", "-DC3DBG"], "//conditions:default": ["-O3"] }) + select({ "//:lto": ['-flto'], @@ -39,7 +39,7 @@ def vere_library(copts = [], linkopts = [], **kwargs): def vere_binary(copts = [], linkopts = [], **kwargs): native.cc_binary( copts = copts + select({ - "//:debug": ["-O0", "-g3", "-DC3DBG", "-fdebug-compilation-dir=."], + "//:debug": ["-O0", "-g3", "-DC3DBG"], "//conditions:default": ["-O3"] }) + select({ "//:lto": ['-flto'], diff --git a/pkg/noun/jets/q.h b/pkg/noun/jets/q.h index fd7c5981fb..b4fe7cd73e 100644 --- a/pkg/noun/jets/q.h +++ b/pkg/noun/jets/q.h @@ -48,6 +48,7 @@ /** Tier 3. **/ + u3_noun u3qc_aor(u3_atom, u3_atom); u3_noun u3qc_bex(u3_atom); u3_noun u3qc_xeb(u3_atom); u3_noun u3qc_can(u3_atom, u3_noun); diff --git a/pkg/noun/jets/tree.c b/pkg/noun/jets/tree.c index e40fe03846..bf06268b5b 100644 --- a/pkg/noun/jets/tree.c +++ b/pkg/noun/jets/tree.c @@ -2463,6 +2463,8 @@ static u3j_core _138_two__by_d[] = static u3j_harm _138_two_mate_a[] = {{".2", u3wb_mate, c3y}, {}}; +static u3j_harm _138_two_aor_a[] = {{".2", u3wc_aor, c3y}, {}}; + static u3j_core _138_two_d[] = { { "tri", 3, 0, _138_tri_d, no_hashes, _140_tri_ho }, @@ -2489,6 +2491,7 @@ static u3j_core _138_two_d[] = { "welp", 7, _140_two_welp_a, 0, no_hashes }, { "zing", 7, _140_two_zing_a, 0, no_hashes }, + { "aor", 7, _138_two_aor_a, 0, no_hashes }, { "bex", 7, _140_two_bex_a, 0, no_hashes }, { "cat", 7, _140_two_cat_a, 0, no_hashes }, { "can", 7, _140_two_can_a, 0, no_hashes }, diff --git a/pkg/noun/jets/w.h b/pkg/noun/jets/w.h index 34716971bd..275740cd97 100644 --- a/pkg/noun/jets/w.h +++ b/pkg/noun/jets/w.h @@ -50,6 +50,7 @@ /** Tier 3. **/ + u3_noun u3wc_aor(u3_noun); u3_noun u3wc_bex(u3_noun); u3_noun u3wc_xeb(u3_noun); u3_noun u3wc_can(u3_noun); From 76d83269672b21274ea470f6bb2959b04c1c8e28 Mon Sep 17 00:00:00 2001 From: Quodss Date: Wed, 31 Jul 2024 06:01:20 +0200 Subject: [PATCH 23/39] aor jet --- pkg/noun/jets/c/aor.c | 83 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 pkg/noun/jets/c/aor.c diff --git a/pkg/noun/jets/c/aor.c b/pkg/noun/jets/c/aor.c new file mode 100644 index 0000000000..29fd78960d --- /dev/null +++ b/pkg/noun/jets/c/aor.c @@ -0,0 +1,83 @@ +/// @file + +#include "jets/q.h" +#include "jets/w.h" + +#include "noun.h" + + + static u3_atom + _aor_tramp(u3_noun a, + u3_noun b) + { + if ( c3y == u3r_sing(a, b) ) { + return c3y; + } + else { + if ( c3y == u3ud(a) ) { + if ( c3y == u3ud(b) ) { + c3_w len_a, len_b, i = 0; + c3_y *a_bytes = u3r_bytes_all(&len_a, a); + c3_y *b_bytes = u3r_bytes_all(&len_b, b); + while ( (i < len_a) && (i < len_b) ) { + c3_y a_slice=a_bytes[i], b_slice=b_bytes[i]; + if (a_slice != b_slice) { + return u3qa_lth(a_slice, b_slice); + } + i++; + } + return u3m_bail(c3__fail); + } + else { + return c3y; + } + } + else { + if ( c3y == u3ud(b) ) { + return c3n; + } + else { + if ( c3y == u3r_sing(u3h(a), u3h(b)) ) { + return 3; + } + else { + return 2; + } + } + } + } + } + + u3_noun + u3qc_aor(u3_noun a, + u3_noun b) + { + u3_noun out = 4; + while ( 1 ) { + out = _aor_tramp(a, b); + if (out == 2) { + a = u3h(a); + b = u3h(b); + } + else if (out == 3) { + a = u3t(a); + b = u3t(b); + } + else { + return out; + } + } + } + + u3_noun + u3wc_aor(u3_noun cor) + { + u3_noun a, b; + + if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) ) { + return u3m_bail(c3__exit); + } else { + return u3qc_aor(a, b); + } + } + From 1a66d26a9240dad4cd21aa5fe124aea5222e332c Mon Sep 17 00:00:00 2001 From: Quodss Date: Wed, 31 Jul 2024 06:23:56 +0200 Subject: [PATCH 24/39] aor don't copy --- pkg/noun/jets/c/aor.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/pkg/noun/jets/c/aor.c b/pkg/noun/jets/c/aor.c index 29fd78960d..ea35290617 100644 --- a/pkg/noun/jets/c/aor.c +++ b/pkg/noun/jets/c/aor.c @@ -16,15 +16,25 @@ else { if ( c3y == u3ud(a) ) { if ( c3y == u3ud(b) ) { - c3_w len_a, len_b, i = 0; - c3_y *a_bytes = u3r_bytes_all(&len_a, a); - c3_y *b_bytes = u3r_bytes_all(&len_b, b); - while ( (i < len_a) && (i < len_b) ) { - c3_y a_slice=a_bytes[i], b_slice=b_bytes[i]; - if (a_slice != b_slice) { - return u3qa_lth(a_slice, b_slice); - } - i++; + u3a_atom* a_u = u3a_to_ptr(a); + u3a_atom* b_u = u3a_to_ptr(b); + c3_w len_w_a, len_w_b, i_w = 0; + c3_w *a_words = a_u->buf_w; + c3_w *b_words = b_u->buf_w; + while ( (i_w < len_w_a) && (i_w < len_w_b) ) { + c3_w a_w = a_words[i_w], b_w = b_words[i_w]; + c3_y a_y = a_w & 0xFF, b_y = b_w & 0xFF; + if (a_y != b_y) return u3qa_lth(a_y, b_y); + a_y = a_w & 0xFF00; + b_y = b_w & 0xFF00; + if (a_y != b_y) return u3qa_lth(a_y, b_y); + a_y = a_w & 0xFF0000; + b_y = b_w & 0xFF0000; + if (a_y != b_y) return u3qa_lth(a_y, b_y); + a_y = a_w & 0xFF000000; + b_y = b_w & 0xFF000000; + if (a_y != b_y) return u3qa_lth(a_y, b_y); + i_w++; } return u3m_bail(c3__fail); } From 3f862f86cb855ef57b15cdd5a22e67548545cf02 Mon Sep 17 00:00:00 2001 From: Quodss Date: Wed, 31 Jul 2024 06:26:04 +0200 Subject: [PATCH 25/39] len_w --- pkg/noun/jets/c/aor.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/noun/jets/c/aor.c b/pkg/noun/jets/c/aor.c index ea35290617..47e07f62c4 100644 --- a/pkg/noun/jets/c/aor.c +++ b/pkg/noun/jets/c/aor.c @@ -18,7 +18,8 @@ if ( c3y == u3ud(b) ) { u3a_atom* a_u = u3a_to_ptr(a); u3a_atom* b_u = u3a_to_ptr(b); - c3_w len_w_a, len_w_b, i_w = 0; + c3_w len_w_a = a_u->len_w, len_w_b = b_u->len_w; + c3_w i_w = 0; c3_w *a_words = a_u->buf_w; c3_w *b_words = b_u->buf_w; while ( (i_w < len_w_a) && (i_w < len_w_b) ) { From 2638bc35cb32c7d519d6f15583c87ba87f228ee9 Mon Sep 17 00:00:00 2001 From: Quodss Date: Wed, 31 Jul 2024 06:34:25 +0200 Subject: [PATCH 26/39] inline lth --- pkg/noun/jets/c/aor.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pkg/noun/jets/c/aor.c b/pkg/noun/jets/c/aor.c index 47e07f62c4..12688f3681 100644 --- a/pkg/noun/jets/c/aor.c +++ b/pkg/noun/jets/c/aor.c @@ -25,16 +25,20 @@ while ( (i_w < len_w_a) && (i_w < len_w_b) ) { c3_w a_w = a_words[i_w], b_w = b_words[i_w]; c3_y a_y = a_w & 0xFF, b_y = b_w & 0xFF; - if (a_y != b_y) return u3qa_lth(a_y, b_y); + if (a_y != b_y) return __(a_y < b_y); + a_y = a_w & 0xFF00; b_y = b_w & 0xFF00; - if (a_y != b_y) return u3qa_lth(a_y, b_y); + if (a_y != b_y) return __(a_y < b_y); + a_y = a_w & 0xFF0000; b_y = b_w & 0xFF0000; - if (a_y != b_y) return u3qa_lth(a_y, b_y); + if (a_y != b_y) return __(a_y < b_y); + a_y = a_w & 0xFF000000; b_y = b_w & 0xFF000000; - if (a_y != b_y) return u3qa_lth(a_y, b_y); + if (a_y != b_y) return __(a_y < b_y); + i_w++; } return u3m_bail(c3__fail); From f7fc53c1a0050b0e875da35ce95daf88068f8073 Mon Sep 17 00:00:00 2001 From: Quodss Date: Wed, 31 Jul 2024 10:02:09 +0200 Subject: [PATCH 27/39] rollback to copy --- pkg/noun/jets/c/aor.c | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/pkg/noun/jets/c/aor.c b/pkg/noun/jets/c/aor.c index 12688f3681..0ee6f6b0f5 100644 --- a/pkg/noun/jets/c/aor.c +++ b/pkg/noun/jets/c/aor.c @@ -16,30 +16,17 @@ else { if ( c3y == u3ud(a) ) { if ( c3y == u3ud(b) ) { - u3a_atom* a_u = u3a_to_ptr(a); - u3a_atom* b_u = u3a_to_ptr(b); - c3_w len_w_a = a_u->len_w, len_w_b = b_u->len_w; - c3_w i_w = 0; - c3_w *a_words = a_u->buf_w; - c3_w *b_words = b_u->buf_w; - while ( (i_w < len_w_a) && (i_w < len_w_b) ) { - c3_w a_w = a_words[i_w], b_w = b_words[i_w]; - c3_y a_y = a_w & 0xFF, b_y = b_w & 0xFF; - if (a_y != b_y) return __(a_y < b_y); - - a_y = a_w & 0xFF00; - b_y = b_w & 0xFF00; - if (a_y != b_y) return __(a_y < b_y); - - a_y = a_w & 0xFF0000; - b_y = b_w & 0xFF0000; - if (a_y != b_y) return __(a_y < b_y); - - a_y = a_w & 0xFF000000; - b_y = b_w & 0xFF000000; - if (a_y != b_y) return __(a_y < b_y); - - i_w++; + c3_w len_a, len_b, i = 0; + c3_y *a_bytes = u3r_bytes_all(&len_a, a); + c3_y *b_bytes = u3r_bytes_all(&len_b, b); + while ( (i < len_a) && (i < len_b) ) { + c3_y a_slice=a_bytes[i], b_slice=b_bytes[i]; + u3m_p("a_slice", a_slice); + u3m_p("b_slice", b_slice); + if (a_slice != b_slice) { + return __(a_slice < b_slice); + } + i++; } return u3m_bail(c3__fail); } @@ -79,6 +66,7 @@ b = u3t(b); } else { + u3m_p("out", out); return out; } } @@ -87,6 +75,7 @@ u3_noun u3wc_aor(u3_noun cor) { + // return u3_none; u3_noun a, b; if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) ) { From 2be5296db5044d3b888820d5df8007baf7b558c0 Mon Sep 17 00:00:00 2001 From: Quodss Date: Wed, 31 Jul 2024 12:47:16 +0200 Subject: [PATCH 28/39] jet fix no copy --- pkg/noun/jets/c/aor.c | 51 +++++++++++++++++++++++++++++++------------ 1 file changed, 37 insertions(+), 14 deletions(-) diff --git a/pkg/noun/jets/c/aor.c b/pkg/noun/jets/c/aor.c index 0ee6f6b0f5..8514e78319 100644 --- a/pkg/noun/jets/c/aor.c +++ b/pkg/noun/jets/c/aor.c @@ -16,19 +16,44 @@ else { if ( c3y == u3ud(a) ) { if ( c3y == u3ud(b) ) { - c3_w len_a, len_b, i = 0; - c3_y *a_bytes = u3r_bytes_all(&len_a, a); - c3_y *b_bytes = u3r_bytes_all(&len_b, b); - while ( (i < len_a) && (i < len_b) ) { - c3_y a_slice=a_bytes[i], b_slice=b_bytes[i]; - u3m_p("a_slice", a_slice); - u3m_p("b_slice", b_slice); - if (a_slice != b_slice) { - return __(a_slice < b_slice); + c3_w len_a_w, len_b_w, i_w = 0; + c3_w *a_words, *b_words; + c3_w a_w, b_w; + if ( c3y == u3a_is_cat(a) ) { + len_a_w = 1; + a_words = &a; + } + else { + u3a_atom* a_u = u3a_to_ptr(a); + len_a_w = (a_u->len_w); + a_words = a_u->buf_w; + } + if ( c3y == u3a_is_cat(b) ) { + len_b_w = 1; + b_words = &b; + } + else { + u3a_atom* b_u = u3a_to_ptr(b); + len_b_w = (b_u->len_w); + b_words = b_u->buf_w; + } + while ( (i_w < len_a_w) && (i_w < len_b_w) ) { + c3_y a_y, b_y; + a_w = a_words[i_w]; + b_w = b_words[i_w]; + for (c3_w j = 0; j < 4; j++) { + a_y = a_w % (1 << 8); + b_y = b_w % (1 << 8); + if ( a_y != b_y ) return __(a_y < b_y); + a_w = a_w >> 8; + b_w = b_w >> 8; } - i++; + i_w++; + } + if ( len_a_w == len_b_w) { + return u3m_bail(c3__fail); // impossible: nonequal atoms with equal payloads } - return u3m_bail(c3__fail); + return __(len_a_w < len_b_w); } else { return c3y; @@ -54,7 +79,7 @@ u3qc_aor(u3_noun a, u3_noun b) { - u3_noun out = 4; + u3_noun out; while ( 1 ) { out = _aor_tramp(a, b); if (out == 2) { @@ -66,7 +91,6 @@ b = u3t(b); } else { - u3m_p("out", out); return out; } } @@ -75,7 +99,6 @@ u3_noun u3wc_aor(u3_noun cor) { - // return u3_none; u3_noun a, b; if ( c3n == u3r_mean(cor, u3x_sam_2, &a, u3x_sam_3, &b, 0) ) { From 0c9d7682a65356ca1acee9e45b23899a2c679cb8 Mon Sep 17 00:00:00 2001 From: Quodss Date: Wed, 31 Jul 2024 12:48:57 +0200 Subject: [PATCH 29/39] restore common settings --- bazel/common_settings.bzl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bazel/common_settings.bzl b/bazel/common_settings.bzl index 6a61de1292..68a2232cd1 100644 --- a/bazel/common_settings.bzl +++ b/bazel/common_settings.bzl @@ -14,7 +14,7 @@ string_flag = rule( def vere_library(copts = [], linkopts = [], **kwargs): native.cc_library( copts = copts + select({ - "//:debug": ["-O0", "-g3", "-DC3DBG"], + "//:debug": ["-O0", "-g3", "-DC3DBG", "-fdebug-compilation-dir=."], "//conditions:default": ["-O3"] }) + select({ "//:lto": ['-flto'], @@ -39,7 +39,7 @@ def vere_library(copts = [], linkopts = [], **kwargs): def vere_binary(copts = [], linkopts = [], **kwargs): native.cc_binary( copts = copts + select({ - "//:debug": ["-O0", "-g3", "-DC3DBG"], + "//:debug": ["-O0", "-g3", "-DC3DBG", "-fdebug-compilation-dir=."], "//conditions:default": ["-O3"] }) + select({ "//:lto": ['-flto'], From 663a54af3d3639a05d242cf2104950f640cffd3b Mon Sep 17 00:00:00 2001 From: Quodss Date: Wed, 31 Jul 2024 16:36:03 +0200 Subject: [PATCH 30/39] optimizations --- pkg/noun/jets/c/aor.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/pkg/noun/jets/c/aor.c b/pkg/noun/jets/c/aor.c index 8514e78319..d19a7864e4 100644 --- a/pkg/noun/jets/c/aor.c +++ b/pkg/noun/jets/c/aor.c @@ -16,9 +16,9 @@ else { if ( c3y == u3ud(a) ) { if ( c3y == u3ud(b) ) { - c3_w len_a_w, len_b_w, i_w = 0; + c3_w len_a_w, len_b_w; c3_w *a_words, *b_words; - c3_w a_w, b_w; + c3_y a_y, b_y; if ( c3y == u3a_is_cat(a) ) { len_a_w = 1; a_words = &a; @@ -37,21 +37,13 @@ len_b_w = (b_u->len_w); b_words = b_u->buf_w; } - while ( (i_w < len_a_w) && (i_w < len_b_w) ) { - c3_y a_y, b_y; - a_w = a_words[i_w]; - b_w = b_words[i_w]; + c3_w len_min = c3_min(len_a_w, len_b_w); + for (c3_w i_w = 0; i_w < len_min; i_w++) { for (c3_w j = 0; j < 4; j++) { - a_y = a_w % (1 << 8); - b_y = b_w % (1 << 8); + a_y = (a_words[i_w] >> (8*j)) & 0xFF; + b_y = (b_words[i_w] >> (8*j)) & 0xFF; if ( a_y != b_y ) return __(a_y < b_y); - a_w = a_w >> 8; - b_w = b_w >> 8; } - i_w++; - } - if ( len_a_w == len_b_w) { - return u3m_bail(c3__fail); // impossible: nonequal atoms with equal payloads } return __(len_a_w < len_b_w); } From cb13d69c5bb634e71aaa27a6264b8e91046ca1f0 Mon Sep 17 00:00:00 2001 From: Quodss Date: Wed, 31 Jul 2024 17:09:30 +0200 Subject: [PATCH 31/39] remove helping function --- pkg/noun/jets/c/aor.c | 119 ++++++++++++++++++------------------------ 1 file changed, 51 insertions(+), 68 deletions(-) diff --git a/pkg/noun/jets/c/aor.c b/pkg/noun/jets/c/aor.c index d19a7864e4..0feb0bd9d0 100644 --- a/pkg/noun/jets/c/aor.c +++ b/pkg/noun/jets/c/aor.c @@ -6,87 +6,70 @@ #include "noun.h" - static u3_atom - _aor_tramp(u3_noun a, - u3_noun b) + u3_noun + u3qc_aor(u3_noun a, + u3_noun b) { - if ( c3y == u3r_sing(a, b) ) { - return c3y; - } - else { - if ( c3y == u3ud(a) ) { - if ( c3y == u3ud(b) ) { - c3_w len_a_w, len_b_w; - c3_w *a_words, *b_words; - c3_y a_y, b_y; - if ( c3y == u3a_is_cat(a) ) { - len_a_w = 1; - a_words = &a; - } - else { - u3a_atom* a_u = u3a_to_ptr(a); - len_a_w = (a_u->len_w); - a_words = a_u->buf_w; - } - if ( c3y == u3a_is_cat(b) ) { - len_b_w = 1; - b_words = &b; + while ( 1 ) { + if ( c3y == u3r_sing(a, b) ) { + return c3y; + } + else { + if ( c3y == u3ud(a) ) { + if ( c3y == u3ud(b) ) { + c3_w len_a_w, len_b_w; + c3_w *a_words, *b_words; + c3_y a_y, b_y; + if ( c3y == u3a_is_cat(a) ) { + len_a_w = 1; + a_words = &a; + } + else { + u3a_atom* a_u = u3a_to_ptr(a); + len_a_w = (a_u->len_w); + a_words = a_u->buf_w; + } + if ( c3y == u3a_is_cat(b) ) { + len_b_w = 1; + b_words = &b; + } + else { + u3a_atom* b_u = u3a_to_ptr(b); + len_b_w = (b_u->len_w); + b_words = b_u->buf_w; + } + c3_w len_min = c3_min(len_a_w, len_b_w); + for (c3_w i_w = 0; i_w < len_min; i_w++) { + for (c3_w j = 0; j < 4; j++) { + a_y = (a_words[i_w] >> (8*j)) & 0xFF; + b_y = (b_words[i_w] >> (8*j)) & 0xFF; + if ( a_y != b_y ) return __(a_y < b_y); + } + } + return __(len_a_w < len_b_w); } else { - u3a_atom* b_u = u3a_to_ptr(b); - len_b_w = (b_u->len_w); - b_words = b_u->buf_w; - } - c3_w len_min = c3_min(len_a_w, len_b_w); - for (c3_w i_w = 0; i_w < len_min; i_w++) { - for (c3_w j = 0; j < 4; j++) { - a_y = (a_words[i_w] >> (8*j)) & 0xFF; - b_y = (b_words[i_w] >> (8*j)) & 0xFF; - if ( a_y != b_y ) return __(a_y < b_y); - } + return c3y; } - return __(len_a_w < len_b_w); - } - else { - return c3y; - } - } - else { - if ( c3y == u3ud(b) ) { - return c3n; } else { - if ( c3y == u3r_sing(u3h(a), u3h(b)) ) { - return 3; + if ( c3y == u3ud(b) ) { + return c3n; } else { - return 2; + if ( c3y == u3r_sing(u3h(a), u3h(b)) ) { + a = u3t(a); + b = u3t(b); + } + else { + a = u3h(a); + b = u3h(b); + } } } } } } - - u3_noun - u3qc_aor(u3_noun a, - u3_noun b) - { - u3_noun out; - while ( 1 ) { - out = _aor_tramp(a, b); - if (out == 2) { - a = u3h(a); - b = u3h(b); - } - else if (out == 3) { - a = u3t(a); - b = u3t(b); - } - else { - return out; - } - } - } u3_noun u3wc_aor(u3_noun cor) From f54e67120a71c81e34ce88eac8a43be54e6cc6a1 Mon Sep 17 00:00:00 2001 From: Quodss Date: Wed, 31 Jul 2024 18:13:04 +0200 Subject: [PATCH 32/39] refactor to follow hoon flow --- pkg/noun/jets/c/aor.c | 82 +++++++++++++++++++------------------------ 1 file changed, 36 insertions(+), 46 deletions(-) diff --git a/pkg/noun/jets/c/aor.c b/pkg/noun/jets/c/aor.c index 0feb0bd9d0..9125ea2e85 100644 --- a/pkg/noun/jets/c/aor.c +++ b/pkg/noun/jets/c/aor.c @@ -11,61 +11,51 @@ u3_noun b) { while ( 1 ) { - if ( c3y == u3r_sing(a, b) ) { - return c3y; + if ( c3y == u3r_sing(a, b) ) return c3y; + if ( c3n == u3ud(a) ) { + if ( c3y == u3ud(b) ) return c3n; + if ( c3y == u3r_sing(u3h(a), u3h(b)) ) { + a = u3t(a); + b = u3t(b); + } + else { + a = u3h(a); + b = u3h(b); + } } else { - if ( c3y == u3ud(a) ) { - if ( c3y == u3ud(b) ) { - c3_w len_a_w, len_b_w; - c3_w *a_words, *b_words; - c3_y a_y, b_y; - if ( c3y == u3a_is_cat(a) ) { - len_a_w = 1; - a_words = &a; - } - else { - u3a_atom* a_u = u3a_to_ptr(a); - len_a_w = (a_u->len_w); - a_words = a_u->buf_w; - } - if ( c3y == u3a_is_cat(b) ) { - len_b_w = 1; - b_words = &b; - } - else { - u3a_atom* b_u = u3a_to_ptr(b); - len_b_w = (b_u->len_w); - b_words = b_u->buf_w; - } - c3_w len_min = c3_min(len_a_w, len_b_w); - for (c3_w i_w = 0; i_w < len_min; i_w++) { - for (c3_w j = 0; j < 4; j++) { - a_y = (a_words[i_w] >> (8*j)) & 0xFF; - b_y = (b_words[i_w] >> (8*j)) & 0xFF; - if ( a_y != b_y ) return __(a_y < b_y); - } - } - return __(len_a_w < len_b_w); + if ( c3n == u3ud(b) ) return c3y; + { + c3_w len_a_w, len_b_w; + c3_w *a_words, *b_words; + c3_y a_y, b_y; + if ( c3y == u3a_is_cat(a) ) { + len_a_w = 1; + a_words = &a; } else { - return c3y; + u3a_atom* a_u = u3a_to_ptr(a); + len_a_w = a_u->len_w; + a_words = a_u->buf_w; } - } - else { - if ( c3y == u3ud(b) ) { - return c3n; + if ( c3y == u3a_is_cat(b) ) { + len_b_w = 1; + b_words = &b; } else { - if ( c3y == u3r_sing(u3h(a), u3h(b)) ) { - a = u3t(a); - b = u3t(b); - } - else { - a = u3h(a); - b = u3h(b); + u3a_atom* b_u = u3a_to_ptr(b); + len_b_w = b_u->len_w; + b_words = b_u->buf_w; + } + c3_w len_min = c3_min(len_a_w, len_b_w); + for (c3_w i_w = 0; i_w < len_min; i_w++) { + for (c3_w j = 0; j < 4; j++) { + a_y = (a_words[i_w] >> (8*j)) & 0xFF; + b_y = (b_words[i_w] >> (8*j)) & 0xFF; + if ( a_y != b_y ) return __(a_y < b_y); } } + return __(len_a_w < len_b_w); } } } From f04a8bcfdf02f5e735b39155d163cff1e9272d84 Mon Sep 17 00:00:00 2001 From: Quodss Date: Wed, 31 Jul 2024 20:30:01 +0200 Subject: [PATCH 33/39] little endian optimization --- pkg/noun/jets/c/aor.c | 59 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/pkg/noun/jets/c/aor.c b/pkg/noun/jets/c/aor.c index 9125ea2e85..5d6b705879 100644 --- a/pkg/noun/jets/c/aor.c +++ b/pkg/noun/jets/c/aor.c @@ -4,7 +4,64 @@ #include "jets/w.h" #include "noun.h" +#include "portable.h" +#if defined(c3_endian) && defined(c3_endian_little) && (c3_endian == c3_endian_little) + + u3_noun + u3qc_aor(u3_noun a, + u3_noun b) + { + while ( 1 ) { + if ( c3y == u3r_sing(a, b) ) return c3y; + if ( c3n == u3ud(a) ) { + if ( c3y == u3ud(b) ) return c3n; + if ( c3y == u3r_sing(u3h(a), u3h(b)) ) { + a = u3t(a); + b = u3t(b); + } + else { + a = u3h(a); + b = u3h(b); + } + } + else { + if ( c3n == u3ud(b) ) return c3y; + { + c3_w len_a_y, len_b_y; + c3_y *a_bytes, *b_bytes; + c3_y a_y, b_y; + if ( c3y == u3a_is_cat(a) ) { + len_a_y = 4; + a_bytes = (c3_y*)&a; + } + else { + u3a_atom* a_u = u3a_to_ptr(a); + len_a_y = (a_u->len_w)*4; + a_bytes = (c3_y*)(a_u->buf_w); + } + if ( c3y == u3a_is_cat(b) ) { + len_b_y = 4; + b_bytes = (c3_y*)&b; + } + else { + u3a_atom* b_u = u3a_to_ptr(b); + len_b_y = (b_u->len_w)*4; + b_bytes = (c3_y*)(b_u->buf_w); + } + c3_w len_min = c3_min(len_a_y, len_b_y); + for (c3_w i_y = 0; i_y < len_min; i_y++) { + a_y = a_bytes[i_y]; + b_y = b_bytes[i_y]; + if ( a_y != b_y ) return __(a_y < b_y); + } + return __(len_a_y < len_b_y); + } + } + } + } + +#else u3_noun u3qc_aor(u3_noun a, @@ -60,6 +117,8 @@ } } } + +#endif u3_noun u3wc_aor(u3_noun cor) From 3ddba6af6157421daad401cba496cede4f11d9cd Mon Sep 17 00:00:00 2001 From: Quodss Date: Mon, 5 Aug 2024 19:27:42 +0200 Subject: [PATCH 34/39] length fix, remove dead code --- pkg/noun/jets/c/aor.c | 69 ++----------------------------------------- 1 file changed, 2 insertions(+), 67 deletions(-) diff --git a/pkg/noun/jets/c/aor.c b/pkg/noun/jets/c/aor.c index 5d6b705879..d19d1858cf 100644 --- a/pkg/noun/jets/c/aor.c +++ b/pkg/noun/jets/c/aor.c @@ -4,9 +4,6 @@ #include "jets/w.h" #include "noun.h" -#include "portable.h" - -#if defined(c3_endian) && defined(c3_endian_little) && (c3_endian == c3_endian_little) u3_noun u3qc_aor(u3_noun a, @@ -28,25 +25,22 @@ else { if ( c3n == u3ud(b) ) return c3y; { - c3_w len_a_y, len_b_y; + c3_w len_a_y = u3r_met(3, a); + c3_w len_b_y = u3r_met(3, b);; c3_y *a_bytes, *b_bytes; c3_y a_y, b_y; if ( c3y == u3a_is_cat(a) ) { - len_a_y = 4; a_bytes = (c3_y*)&a; } else { u3a_atom* a_u = u3a_to_ptr(a); - len_a_y = (a_u->len_w)*4; a_bytes = (c3_y*)(a_u->buf_w); } if ( c3y == u3a_is_cat(b) ) { - len_b_y = 4; b_bytes = (c3_y*)&b; } else { u3a_atom* b_u = u3a_to_ptr(b); - len_b_y = (b_u->len_w)*4; b_bytes = (c3_y*)(b_u->buf_w); } c3_w len_min = c3_min(len_a_y, len_b_y); @@ -60,65 +54,6 @@ } } } - -#else - - u3_noun - u3qc_aor(u3_noun a, - u3_noun b) - { - while ( 1 ) { - if ( c3y == u3r_sing(a, b) ) return c3y; - if ( c3n == u3ud(a) ) { - if ( c3y == u3ud(b) ) return c3n; - if ( c3y == u3r_sing(u3h(a), u3h(b)) ) { - a = u3t(a); - b = u3t(b); - } - else { - a = u3h(a); - b = u3h(b); - } - } - else { - if ( c3n == u3ud(b) ) return c3y; - { - c3_w len_a_w, len_b_w; - c3_w *a_words, *b_words; - c3_y a_y, b_y; - if ( c3y == u3a_is_cat(a) ) { - len_a_w = 1; - a_words = &a; - } - else { - u3a_atom* a_u = u3a_to_ptr(a); - len_a_w = a_u->len_w; - a_words = a_u->buf_w; - } - if ( c3y == u3a_is_cat(b) ) { - len_b_w = 1; - b_words = &b; - } - else { - u3a_atom* b_u = u3a_to_ptr(b); - len_b_w = b_u->len_w; - b_words = b_u->buf_w; - } - c3_w len_min = c3_min(len_a_w, len_b_w); - for (c3_w i_w = 0; i_w < len_min; i_w++) { - for (c3_w j = 0; j < 4; j++) { - a_y = (a_words[i_w] >> (8*j)) & 0xFF; - b_y = (b_words[i_w] >> (8*j)) & 0xFF; - if ( a_y != b_y ) return __(a_y < b_y); - } - } - return __(len_a_w < len_b_w); - } - } - } - } - -#endif u3_noun u3wc_aor(u3_noun cor) From d24221754cb1a04802024c38130762dbf0bed3f1 Mon Sep 17 00:00:00 2001 From: Quodss Date: Mon, 5 Aug 2024 19:55:52 +0200 Subject: [PATCH 35/39] naming conventions --- pkg/noun/jets/c/aor.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/pkg/noun/jets/c/aor.c b/pkg/noun/jets/c/aor.c index d19d1858cf..248661e777 100644 --- a/pkg/noun/jets/c/aor.c +++ b/pkg/noun/jets/c/aor.c @@ -25,31 +25,31 @@ else { if ( c3n == u3ud(b) ) return c3y; { - c3_w len_a_y = u3r_met(3, a); - c3_w len_b_y = u3r_met(3, b);; - c3_y *a_bytes, *b_bytes; - c3_y a_y, b_y; + c3_w len_a_w = u3r_met(3, a); + c3_w len_b_w = u3r_met(3, b);; + c3_y *buf_a_y, *buf_b_y; + c3_y cut_a_y, cut_b_y; if ( c3y == u3a_is_cat(a) ) { - a_bytes = (c3_y*)&a; + buf_a_y = (c3_y*)&a; } else { u3a_atom* a_u = u3a_to_ptr(a); - a_bytes = (c3_y*)(a_u->buf_w); + buf_a_y = (c3_y*)(a_u->buf_w); } if ( c3y == u3a_is_cat(b) ) { - b_bytes = (c3_y*)&b; + buf_b_y = (c3_y*)&b; } else { u3a_atom* b_u = u3a_to_ptr(b); - b_bytes = (c3_y*)(b_u->buf_w); + buf_b_y = (c3_y*)(b_u->buf_w); } - c3_w len_min = c3_min(len_a_y, len_b_y); - for (c3_w i_y = 0; i_y < len_min; i_y++) { - a_y = a_bytes[i_y]; - b_y = b_bytes[i_y]; - if ( a_y != b_y ) return __(a_y < b_y); + c3_w len_min_w = c3_min(len_a_w, len_b_w); + for (c3_w i_w = 0; i_w < len_min_w; i_w++) { + cut_a_y = buf_a_y[i_w]; + cut_b_y = buf_b_y[i_w]; + if ( cut_a_y != cut_b_y ) return __(cut_a_y < cut_b_y); } - return __(len_a_y < len_b_y); + return __(len_a_w < len_b_w); } } } From b5d53e2d5a92e0aeb964fad167e514ce478063a8 Mon Sep 17 00:00:00 2001 From: pkova Date: Mon, 16 Sep 2024 14:56:36 +0300 Subject: [PATCH 36/39] 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 37/39] 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 38/39] 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 39/39] 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 {