1
1
mirror of https://github.com/NixOS/mobile-nixos.git synced 2024-12-16 11:43:21 +03:00

mruby: Add patch to strip store paths in debug info

This fixes backtraces in stage-1!
This commit is contained in:
Samuel Dionne-Riel 2021-02-16 18:22:12 -05:00
parent cc591aef6d
commit 056fc26e2d
2 changed files with 66 additions and 12 deletions

View File

@ -0,0 +1,58 @@
From 6dab6fb118ece6c47e0407d4a7aa80e842b3747d Mon Sep 17 00:00:00 2001
From: Samuel Dionne-Riel <samuel@dionne-riel.com>
Date: Mon, 15 Feb 2021 23:18:06 -0500
Subject: [PATCH] [mobile-nixos] Strip store path hashes when saving debug
information
This is required for breaking the dependency on the source files, as
`nuke-refs` break the irep otherwise.
This patch could be applied strictly to an `mrbc` used to compile for
the initrd, rather than always.
---
src/debug.c | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/src/debug.c b/src/debug.c
index b44c7d10..022d32bb 100644
--- a/src/debug.c
+++ b/src/debug.c
@@ -3,6 +3,8 @@
#include <mruby/irep.h>
#include <mruby/debug.h>
+#define NIX_STORE "/nix/store/"
+
static mrb_irep_debug_info_file*
get_file(mrb_irep_debug_info *info, uint32_t pc)
{
@@ -130,6 +132,7 @@ mrb_debug_info_append_file(mrb_state *mrb, mrb_irep_debug_info *d,
uint32_t file_pc_count;
size_t fn_len;
uint32_t i;
+ char *obfuscated_filename;
if (!d) return NULL;
if (start_pos == end_pos) return NULL;
@@ -156,7 +159,17 @@ mrb_debug_info_append_file(mrb_state *mrb, mrb_irep_debug_info *d,
d->pc_count = end_pos;
fn_len = strlen(filename);
- f->filename_sym = mrb_intern(mrb, filename, fn_len);
+ obfuscated_filename = strdup(filename);
+
+ // filename starts with the string to obfuscate?
+ if (strstr(obfuscated_filename, NIX_STORE) == obfuscated_filename) {
+ // Transforms:
+ // /nix/store/00000bgcw03vv7m7407w22brc0g638dw-source
+ // Into:
+ // /nix/store/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-source
+ strncpy(obfuscated_filename, NIX_STORE "eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee", 32 + strlen(NIX_STORE));
+ }
+ f->filename_sym = mrb_intern(mrb, obfuscated_filename, fn_len);
f->line_type = select_line_type(lines + start_pos, end_pos - start_pos);
f->lines.ptr = NULL;
--
2.29.2

View File

@ -34,10 +34,12 @@ in
, additionalBuildConfig ? ""
# Adds `enable_debug`.
, debug ? false
# Adds `-g` to mrbc wrapper.
, mrbWithDebug ? true
# Prepends defaults to `gems` and `gemBoxes`.
, useDefaults ? true
# Strips store path hashes in debug information
# `nuke-ref` will break the irep of compiled mruby.
# Stripping the hashes is *required* with nuke-ref.
, stripStorePathHashes ? debug
}:
let
@ -46,6 +48,7 @@ let
concatStringsSep
isDerivation
mapAttrsToList
optional
optionals
optionalString
;
@ -178,7 +181,9 @@ let
./0001-HACK-Ensures-a-host-less-build-can-be-made.patch
./0001-Nixpkgs-dump-linker-flags-for-re-use.patch
./bison-36-compat.patch
];
]
++ optional stripStorePathHashes ./0001-mobile-nixos-Strip-store-path-hashes-when-saving-deb.patch
;
postPatch = ''
substituteInPlace include/mrbconf.h \
@ -220,15 +225,6 @@ let
cp -R include $out
mkdir -p $out/nix-support
cp mruby_linker_flags.sh $out/nix-support/
# Wrap `mrbc` with -g conditional to the debug flag.
mkdir -p $out/libexec/
mv $out/bin/mrbc $out/libexec/mrbc
cat > $out/bin/mrbc <<EOF
#!${runtimeShell}
exec $out/libexec/mrbc ${optionalString mrbWithDebug "-g"} "\''${@}"
EOF
chmod +x $out/bin/mrbc
runHook postInstall
'';