[PATCH] Fix data symbolization with libbacktrace

Alexey Samsonov vonosmas at gmail.com
Mon Dec 15 17:53:51 PST 2014


Submitted as r224308, thanks!

On Mon, Dec 15, 2014 at 11:05 AM, Jakub Jelinek <jakub at redhat.com> wrote:

> Hi!
>
> I've noticed that data symbolization doesn't really work now in GCC.
> The problem is that DataInfo doesn't even have an address field (version
> in compiler-rt), and in GCC version uses info->start, which is a field
> that is supposed to be set by the method, not the address we should
> resolve.
> From the caller we only have module_offset computed, which is relative to
> the start of the library, but libbacktrace actually wants the full address
> instead.
>
> The following patch fixes it.
>
> Testcase:
>
> ts.C:
>
> #include <pthread.h>
>
> int v;
>
> int
> foo (int x)
> {
>   if (x < 99)
>     throw x;
>   v++;
>   return x;
> }
>
> void *
> tf (void *)
> {
>   for (int i = 0; i < 100; i++)
>     try { foo (i); } catch (int) {}
>   return NULL;
> }
>
> int
> do_main ()
> {
>   pthread_t th;
>   if (pthread_create (&th, NULL, tf, NULL))
>     return 0;
>   v++;
>   pthread_join (th, NULL);
>   return 0;
> }
>
> tsm.C:
>
> extern int do_main ();
> int
> main ()
> {
>   return do_main ();
> }
>
> and for both
> $CXX -shared -fpic -o ts.so -g ts.C -fsanitize=thread
> $CXX -o tsm -g tsm.C ./ts.so -fsanitize=thread
> ./tsm
> and:
> $CXX -o ts -g ts.C tsm.C -fsanitize=thread
> ./ts
>
> it should print meaningful
>   Location is global 'v' of size 4 at 0x0000006020e0 (ts+0x0000006020e0)
> or similar line, not
>   Location is global '<null>' of size 0 at 0x0000000000000000
>
> ---
> compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_libbacktrace.h.jj
>  2014-12-15 19:50:53.598624351 +0100
> +++ compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_libbacktrace.h
>       2014-12-15 19:51:24.811097009 +0100
> @@ -35,7 +35,7 @@ class LibbacktraceSymbolizer {
>    SymbolizedStack *SymbolizeCode(uptr addr, const char *module_name,
>                                   uptr module_offset);
>
> -  bool SymbolizeData(DataInfo *info);
> +  bool SymbolizeData(uptr addr, DataInfo *info);
>
>    // May return NULL if demangling failed.
>    static char *Demangle(const char *name, bool always_alloc = false);
> ---
> compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc.jj
>  2014-12-15 19:50:53.605624233 +0100
> +++
> compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc
> 2014-12-15 19:51:24.812096992 +0100
> @@ -596,8 +596,8 @@ class POSIXSymbolizer : public Symbolize
>      // First, try to use libbacktrace symbolizer (if it's available).
>      if (libbacktrace_symbolizer_ != 0) {
>        mu_.CheckLocked();
> -      if (libbacktrace_symbolizer_->SymbolizeData(info))
> -        return true;
> +      if (libbacktrace_symbolizer_->SymbolizeData(addr, info))
> +       return true;
>      }
>      const char *str = SendCommand(true, module_name, module_offset);
>      if (str == 0)
> ---
> compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_libbacktrace.cc.jj
> 2014-12-15 19:50:53.600624317 +0100
> +++ compiler-rt/lib/sanitizer_common/sanitizer_symbolizer_libbacktrace.cc
>      2014-12-15 19:52:23.602103720 +0100
> @@ -173,8 +173,8 @@ SymbolizedStack *LibbacktraceSymbolizer:
>    return data.first;
>  }
>
> -bool LibbacktraceSymbolizer::SymbolizeData(DataInfo *info) {
> -  backtrace_syminfo((backtrace_state *)state_, info->address,
> +bool LibbacktraceSymbolizer::SymbolizeData(uptr addr, DataInfo *info) {
> +  backtrace_syminfo((backtrace_state *)state_, addr,
>                      SymbolizeDataCallback, ErrorCallback, info);
>    return true;
>  }
> @@ -192,7 +192,7 @@ SymbolizedStack *LibbacktraceSymbolizer:
>    return nullptr;
>  }
>
> -bool LibbacktraceSymbolizer::SymbolizeData(DataInfo *info) {
> +bool LibbacktraceSymbolizer::SymbolizeData(uptr addr, DataInfo *info) {
>    return false;
>  }
>
>
>         Jakub
>



-- 
Alexey Samsonov
vonosmas at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20141215/def99d18/attachment.html>


More information about the llvm-commits mailing list