Patchwork libgo patch committed: Don't allocate during backtrace

login
register
mail settings
Submitter Ian Taylor
Date Jan. 31, 2013, 4:41 p.m.
Message ID <mcrmwvpuwya.fsf@google.com>
Download mbox | patch
Permalink /patch/217211/
State New
Headers show

Comments

Ian Taylor - Jan. 31, 2013, 4:41 p.m.
The libbacktrace interfaces says that the strings passed to the callback
routine may disappear.  As it happens, in the current implementation
they will not.  The Go backtrace routine needs to hang on to the
strings, and I've discovered that it can't reliably allocate memory,
since it might be called in the middle of an existing memory
allocation.  So at least for now just assume that the backtrace strings
will hang around.  I'll fix this if I can figure out a way to allocate
memory there.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linux-gnu.  Committed to mainline.

Ian

Patch

diff -r 368d10817c19 libgo/runtime/go-callers.c
--- a/libgo/runtime/go-callers.c	Wed Jan 30 14:00:04 2013 -0800
+++ b/libgo/runtime/go-callers.c	Thu Jan 31 08:38:26 2013 -0800
@@ -43,8 +43,14 @@ 
 
   loc = &arg->locbuf[arg->index];
   loc->pc = pc;
-  loc->filename = runtime_gostring ((const byte *) filename);
-  loc->function = runtime_gostring ((const byte *) function);
+
+  /* The libbacktrace library says that these strings might disappear,
+     but with the current implementation they won't.  We can't easily
+     allocate memory here, so for now assume that we can save a
+     pointer to the strings.  */
+  loc->filename = runtime_gostringnocopy ((const byte *) filename);
+  loc->function = runtime_gostringnocopy ((const byte *) function);
+
   loc->lineno = lineno;
   ++arg->index;
   return arg->index >= arg->max;