[PATCH] D60039: Fix the bug of garbage collection of siod.

LuoYuanke via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Mar 30 18:36:14 PDT 2019


LuoYuanke created this revision.
LuoYuanke added reviewers: craig.topper, annita.zhang, wxiao3, smaslov.
Herald added subscribers: llvm-commits, jdoerfert.
Herald added a project: LLVM.

In the siod gc, it depends on setjmp(...) to get the value of callee saved register value, and traverse those register to get the possible local object pointer. Also it traverse current stack to get the possible local object pointer. For setjmp(...) on X86-64, the rbp register (callee saved register) is NOT saved in the setjmp buffer, so object  that pointed by rbp is NOT considered as local object variable and its memory is collected as garbage. This patch is to use getcontext(...) to get more register value of current context and traverse those register to protect object from garbage collection.

This bug is not easy to expose, because usually rbp has been saved in stack when do garbage collection, so the object pointer can be scanned from stack. However when compiler do some optimization on register allocation or licm, the rbp live in gc_mark_and_sweep(...) and rbp is pointing to an object. In such situation, siod failed to run test.scm because object is collected as garbage unexpectedly.


Repository:
  rT test-suite

https://reviews.llvm.org/D60039

Files:
  MultiSource/Applications/siod/slib.c


Index: MultiSource/Applications/siod/slib.c
===================================================================
--- MultiSource/Applications/siod/slib.c
+++ MultiSource/Applications/siod/slib.c
@@ -129,7 +129,7 @@
 struct user_type_hooks *user_types = NULL;
 long user_tc_next = tc_user_min;
 struct gc_protected *protected_registers = NULL;
-jmp_buf save_regs_gc_mark;
+ucontext_t ucontext;
 double gc_rt;
 long gc_cells_collected;
 char *user_ch_readm = "";
@@ -1266,9 +1266,9 @@
    {heap->type = tc_free_cell;
     heap->gc_mark = 0;
     ++heap;}
- setjmp(save_regs_gc_mark);
- mark_locations((LISP *) save_regs_gc_mark,
-		(LISP *) (((char *) save_regs_gc_mark) + sizeof(save_regs_gc_mark)));
+ getcontext(&ucontext);
+ mark_locations((LISP *) &ucontext.uc_mcontext,
+                (LISP *) (((char *) &ucontext.uc_mcontext) + sizeof(mcontext_t)));
  mark_protected_registers();
  mark_locations((LISP *) stack_start_ptr,
 		(LISP *) &stack_end);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60039.192996.patch
Type: text/x-patch
Size: 955 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190331/088c22c1/attachment.bin>


More information about the llvm-commits mailing list