From 745482e3e45820aade9ab71f7362a9a2de4c4aa0 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Thu, 20 Feb 2020 13:08:26 -0700 Subject: [PATCH] vfasl: repairs for fcallables A 0 relocation is used by fcallable code as a recognizable cookie, and its relocations must be preserved. original commit: 38fb3fdf75cf6540d6bd2568f015af6272d22995 --- c/vfasl.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/c/vfasl.c b/c/vfasl.c index 02e2291bbf..ac7e79f581 100644 --- a/c/vfasl.c +++ b/c/vfasl.c @@ -1410,7 +1410,8 @@ static uptr sweep_code_object(vfasl_info *vfi, ptr co) { } else if (IMMEDIATE(obj)) { /* as-is */ if (Sfixnump(obj)) - S_error("vfasl", "unexpected fixnum in relocation"); + if (obj != FIX(0)) /* allow 0 for fcallable cookie */ + S_error("vfasl", "unexpected fixnum in relocation"); } else { obj = vfasl_relocate_help(vfi, obj); obj = (ptr)ptr_diff(obj, vfi->base_addr); @@ -1432,7 +1433,8 @@ static void relink_code(ptr co, ptr sym_base, ptr *vspaces, uptr *vspace_offsets t = CODERELOC(co); t = ptr_add(vspaces[vspace_reloc], (uptr)t - vspace_offsets[vspace_reloc]); - if (to_static && !S_G.retain_static_relocation) + if (to_static && !S_G.retain_static_relocation + && ((CODETYPE(co) & (code_flag_template << code_flags_offset)) == 0)) CODERELOC(co) = (ptr)0; else { CODERELOC(co) = t; @@ -1474,6 +1476,8 @@ static void relink_code(ptr co, ptr sym_base, ptr *vspaces, uptr *vspace_offsets obj = TYPE(ptr_add(sym_base, symbol_pos_to_offset(pos)), type_symbol); if ((val = SYMVAL(obj)) != sunbound) obj = val; + } else if (obj == FIX(0)) { + /* leave as-is */ } else { S_error_abort("vfasl: bad relocation tag"); }