Re: -Og bug? (was: [PATCH] libsanitizer demangling using cp-demangle.c)
On Tue, Jan 28, 2014 at 6:36 AM, Thomas Schwinge wrote: > Avoid "'dc' may be uninitialized" warning. > > libiberty/ > * cp-demangle.c (d_demangle_callback): Put __builtin_unreachable > in place, to help the compiler. > > --- libiberty/cp-demangle.c > +++ libiberty/cp-demangle.c > @@ -5824,6 +5824,8 @@ d_demangle_callback (const char *mangled, int options, > NULL); > d_advance (&di, strlen (d_str (&di))); > break; > + default: > + __builtin_unreachable (); You can't call __builtin_unreachable in this code, because libiberty in stage 1 will be compiled by the host compiler and __builtin_unreachable is specific to GCC. This patch is OK if you call abort instead of __builtin_unreachable. Thanks. Ian
-Og bug? (was: [PATCH] libsanitizer demangling using cp-demangle.c)
Hi! This got committed to trunk as r206477; one small nit: On Tue, 10 Dec 2013 12:38:34 +0100, Jakub Jelinek wrote: > * libbacktrace/Makefile.am (libsanitizer_libbacktrace_la_SOURCES): Add > ../../libiberty/cp-demangle.c. Trying to build trunk r207180 with C*FLAGS='-Og -ggdb', a compiler warning in cp-demangle.c (as seen for other instances of cp-demangle.c being built) is promoted to a hard error in the libsanitizer context, due to -Werror usage: libtool: compile: [...]/build/./gcc/xgcc -B[...]/build/./gcc/ -B[...]/install/x86_64-unknown-linux-gnu/bin/ -B[...]/install/x86_64-unknown-linux-gnu/lib/ -isystem [...]/install/x86_64-unknown-linux-gnu/include -isystem [...]/install/x86_64-unknown-linux-gnu/sys-include -DHAVE_CONFIG_H -I. -I../../../../source/libsanitizer/libbacktrace -I.. -I ../../../../source/libsanitizer/../include -I ../../../../source/libsanitizer/../libgcc -I ../../libgcc -I .. -I ../../../../source/libsanitizer -I ../../../../source/libsanitizer/../libbacktrace -W -Wall -Wwrite-strings -Wmissing-format-attribute -Wcast-qual -Werror -Wstrict-prototypes -Wmissing-prototypes -Wold-style-definition -g -O2 -Og -ggdb -MT cp-demangle.lo -MD -MP -MF .deps/cp-demangle.Tpo -c ../../../../source/libsanitizer/libbacktrace/../../libiberty/cp-demangle.c -fPIC -DPIC -o .libs/cp-demangle.o ../../../../source/libsanitizer/libbacktrace/../../libiberty/cp-demangle.c: In function 'd_demangle_callback': ../../../../source/libsanitizer/libbacktrace/../../libiberty/cp-demangle.c:5842:14: error: 'dc' may be used uninitialized in this function [-Werror=maybe-uninitialized] : 0; ^ cc1: all warnings being treated as errors make[4]: *** [cp-demangle.lo] Error 1 make[4]: Leaving directory `[...]/build/x86_64-unknown-linux-gnu/libsanitizer/libbacktrace' GCC fails to track that all the possible values for enum type indeed have been covered, and so dc must have been initialized. As the warning/error does not appear with -O0, is this in fact a -Og bug? If not, solve this by initializing dc to NULL (lame...) ;-), or maybe as follows? Avoid "'dc' may be uninitialized" warning. libiberty/ * cp-demangle.c (d_demangle_callback): Put __builtin_unreachable in place, to help the compiler. --- libiberty/cp-demangle.c +++ libiberty/cp-demangle.c @@ -5824,6 +5824,8 @@ d_demangle_callback (const char *mangled, int options, NULL); d_advance (&di, strlen (d_str (&di))); break; + default: + __builtin_unreachable (); } /* If DMGL_PARAMS is set, then if we didn't consume the entire Grüße, Thomas pgpuBx50ylTWK.pgp Description: PGP signature
Re: [PATCH] libsanitizer demangling using cp-demangle.c
I've landed patches for libbacktrace and cp-demangle support in LLVM. However, they required some changes (e.g. some files LLVM trunk were modified after the last merge). This means that the next merge to GCC (IIUC it won't happen anytime soon before GCC 4.9 release) will not be clean. Sorry for delay. On Fri, Jan 10, 2014 at 7:56 AM, Konstantin Serebryany wrote: > On Thu, Jan 9, 2014 at 5:57 PM, Jakub Jelinek wrote: >> On Thu, Jan 09, 2014 at 05:51:05PM +0400, Konstantin Serebryany wrote: >>> On Tue, Dec 10, 2013 at 3:38 PM, Jakub Jelinek wrote: >>> > On Fri, Dec 06, 2013 at 06:40:52AM -0800, Ian Lance Taylor wrote: >>> >> There was a recent buggy patch to the demangler that added calls to >>> >> malloc and realloc (2013-10-25 Gary Benson ). >>> >> That patch must be fixed or reverted before the 4.9 release. The main >>> >> code in the demangler must not call malloc/realloc. >>> >> >>> >> When that patch is fixed, you can use the cplus_demangle_v3_callback >>> >> function to get a demangler that never calls malloc. >>> > >>> > AFAIK Gary is working on a fix, when that is fixed, with the following >>> > patch libsanitizer (when using libbacktrace for symbolization) will not >>> > use system malloc/realloc/free for the demangling at all. >>> > >>> > Tested on x86_64-linux (-m64/-m32). Note that the changes for the 3 files >>> > unfortunately will need to be applied upstream to compiler-rt, is that >>> > possible? >>> > >>> > 2013-12-10 Jakub Jelinek >>> > >>> > * sanitizer_common/sanitizer_symbolizer_libbacktrace.h >>> > (LibbacktraceSymbolizer::Demangle): New declaration. >>> > * sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc >>> >>> sanitizer_symbolizer_posix_libcdep.cc is the file from upstream. >>> If it gets any change in the GCC variant, I will not be able to do >>> merges from upstream until the same code is applied upstream. >> >> Sure, but we are nearing GCC 4.9 stage3 finish and really need to demangle >> the libbacktrace provided output. Has the compiler-rt situation been >> cleared up? > > I hope it just did (see the fresh Chandler's reply). > > --kcc > >> Haven't seen any follow-ups after Chandler's reversion. >> So, this change is meant to be temporary, with hope that in upstream this >> will be resolved, either with the same patch or something similar. >> >> Jakub -- Alexey Samsonov, MSK
Re: [PATCH] libsanitizer demangling using cp-demangle.c
On Thu, Jan 9, 2014 at 5:57 PM, Jakub Jelinek wrote: > On Thu, Jan 09, 2014 at 05:51:05PM +0400, Konstantin Serebryany wrote: >> On Tue, Dec 10, 2013 at 3:38 PM, Jakub Jelinek wrote: >> > On Fri, Dec 06, 2013 at 06:40:52AM -0800, Ian Lance Taylor wrote: >> >> There was a recent buggy patch to the demangler that added calls to >> >> malloc and realloc (2013-10-25 Gary Benson ). >> >> That patch must be fixed or reverted before the 4.9 release. The main >> >> code in the demangler must not call malloc/realloc. >> >> >> >> When that patch is fixed, you can use the cplus_demangle_v3_callback >> >> function to get a demangler that never calls malloc. >> > >> > AFAIK Gary is working on a fix, when that is fixed, with the following >> > patch libsanitizer (when using libbacktrace for symbolization) will not >> > use system malloc/realloc/free for the demangling at all. >> > >> > Tested on x86_64-linux (-m64/-m32). Note that the changes for the 3 files >> > unfortunately will need to be applied upstream to compiler-rt, is that >> > possible? >> > >> > 2013-12-10 Jakub Jelinek >> > >> > * sanitizer_common/sanitizer_symbolizer_libbacktrace.h >> > (LibbacktraceSymbolizer::Demangle): New declaration. >> > * sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc >> >> sanitizer_symbolizer_posix_libcdep.cc is the file from upstream. >> If it gets any change in the GCC variant, I will not be able to do >> merges from upstream until the same code is applied upstream. > > Sure, but we are nearing GCC 4.9 stage3 finish and really need to demangle > the libbacktrace provided output. Has the compiler-rt situation been > cleared up? I hope it just did (see the fresh Chandler's reply). --kcc > Haven't seen any follow-ups after Chandler's reversion. > So, this change is meant to be temporary, with hope that in upstream this > will be resolved, either with the same patch or something similar. > > Jakub
Re: [PATCH] libsanitizer demangling using cp-demangle.c
On Thu, Jan 09, 2014 at 05:51:05PM +0400, Konstantin Serebryany wrote: > On Tue, Dec 10, 2013 at 3:38 PM, Jakub Jelinek wrote: > > On Fri, Dec 06, 2013 at 06:40:52AM -0800, Ian Lance Taylor wrote: > >> There was a recent buggy patch to the demangler that added calls to > >> malloc and realloc (2013-10-25 Gary Benson ). > >> That patch must be fixed or reverted before the 4.9 release. The main > >> code in the demangler must not call malloc/realloc. > >> > >> When that patch is fixed, you can use the cplus_demangle_v3_callback > >> function to get a demangler that never calls malloc. > > > > AFAIK Gary is working on a fix, when that is fixed, with the following > > patch libsanitizer (when using libbacktrace for symbolization) will not > > use system malloc/realloc/free for the demangling at all. > > > > Tested on x86_64-linux (-m64/-m32). Note that the changes for the 3 files > > unfortunately will need to be applied upstream to compiler-rt, is that > > possible? > > > > 2013-12-10 Jakub Jelinek > > > > * sanitizer_common/sanitizer_symbolizer_libbacktrace.h > > (LibbacktraceSymbolizer::Demangle): New declaration. > > * sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc > > sanitizer_symbolizer_posix_libcdep.cc is the file from upstream. > If it gets any change in the GCC variant, I will not be able to do > merges from upstream until the same code is applied upstream. Sure, but we are nearing GCC 4.9 stage3 finish and really need to demangle the libbacktrace provided output. Has the compiler-rt situation been cleared up? Haven't seen any follow-ups after Chandler's reversion. So, this change is meant to be temporary, with hope that in upstream this will be resolved, either with the same patch or something similar. Jakub
Re: [PATCH] libsanitizer demangling using cp-demangle.c
On Tue, Dec 10, 2013 at 3:38 PM, Jakub Jelinek wrote: > On Fri, Dec 06, 2013 at 06:40:52AM -0800, Ian Lance Taylor wrote: >> There was a recent buggy patch to the demangler that added calls to >> malloc and realloc (2013-10-25 Gary Benson ). >> That patch must be fixed or reverted before the 4.9 release. The main >> code in the demangler must not call malloc/realloc. >> >> When that patch is fixed, you can use the cplus_demangle_v3_callback >> function to get a demangler that never calls malloc. > > AFAIK Gary is working on a fix, when that is fixed, with the following > patch libsanitizer (when using libbacktrace for symbolization) will not > use system malloc/realloc/free for the demangling at all. > > Tested on x86_64-linux (-m64/-m32). Note that the changes for the 3 files > unfortunately will need to be applied upstream to compiler-rt, is that > possible? > > 2013-12-10 Jakub Jelinek > > * sanitizer_common/sanitizer_symbolizer_libbacktrace.h > (LibbacktraceSymbolizer::Demangle): New declaration. > * sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc sanitizer_symbolizer_posix_libcdep.cc is the file from upstream. If it gets any change in the GCC variant, I will not be able to do merges from upstream until the same code is applied upstream. > (POSIXSymbolizer::Demangle): Use libbacktrace_symbolizer_'s Demangle > method if possible. > * sanitizer_common/sanitizer_symbolizer_libbacktrace.cc: Include > "demangle.h" if SANITIZE_CP_DEMANGLE is defined. > (struct CplusV3DemangleData): New type. > (CplusV3DemangleCallback, CplusV3Demangle): New functions. > (SymbolizeCodePCInfoCallback, SymbolizeCodeCallback, > SymbolizeDataCallback): Use CplusV3Demangle. > * sanitizer_common/Makefile.am (AM_CXXFLAGS): Add > -DSANITIZE_CP_DEMANGLE and -I $(top_srcdir)/../include. > * libbacktrace/backtrace-rename.h (cplus_demangle_builtin_types, > cplus_demangle_fill_ctor, cplus_demangle_fill_dtor, > cplus_demangle_fill_extended_operator, cplus_demangle_fill_name, > cplus_demangle_init_info, cplus_demangle_mangled_name, > cplus_demangle_operators, cplus_demangle_print, > cplus_demangle_print_callback, cplus_demangle_type, cplus_demangle_v3, > cplus_demangle_v3_callback, is_gnu_v3_mangled_ctor, > is_gnu_v3_mangled_dtor, java_demangle_v3, java_demangle_v3_callback): > Define. > (__asan_internal_memcmp, __asan_internal_strncmp): New prototypes. > (memcmp, strncmp): Redefine. > * libbacktrace/Makefile.am (libsanitizer_libbacktrace_la_SOURCES): Add > ../../libiberty/cp-demangle.c. > * libbacktrace/bridge.cc (__asan_internal_memcmp, > __asan_internal_strncmp): New functions. > * sanitizer_common/Makefile.in: Regenerated. > * libbacktrace/Makefile.in: Regenerated. > * configure: Regenerated. > * configure.ac: Regenerated. > * config.h.in: Regenerated. > > --- libsanitizer/sanitizer_common/sanitizer_symbolizer_libbacktrace.h.jj > 2013-12-05 12:04:28.0 +0100 > +++ libsanitizer/sanitizer_common/sanitizer_symbolizer_libbacktrace.h > 2013-12-10 11:01:26.777371566 +0100 > @@ -29,6 +29,8 @@ class LibbacktraceSymbolizer { > >bool SymbolizeData(DataInfo *info); > > + const char *Demangle(const char *name); > + > private: >explicit LibbacktraceSymbolizer(void *state) : state_(state) {} > > --- libsanitizer/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc.jj > 2013-12-05 12:04:28.0 +0100 > +++ libsanitizer/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc > 2013-12-10 11:03:02.971876505 +0100 > @@ -513,6 +513,11 @@ class POSIXSymbolizer : public Symbolize > SymbolizerScope sym_scope(this); > if (internal_symbolizer_ != 0) >return internal_symbolizer_->Demangle(name); > +if (libbacktrace_symbolizer_ != 0) { > + const char *demangled = libbacktrace_symbolizer_->Demangle(name); > + if (demangled) > + return demangled; > +} > return DemangleCXXABI(name); >} > > --- libsanitizer/sanitizer_common/sanitizer_symbolizer_libbacktrace.cc.jj > 2013-12-09 14:32:06.0 +0100 > +++ libsanitizer/sanitizer_common/sanitizer_symbolizer_libbacktrace.cc > 2013-12-10 11:48:19.803830291 +0100 > @@ -20,6 +20,10 @@ > # include "backtrace-supported.h" > # if SANITIZER_POSIX && BACKTRACE_SUPPORTED && !BACKTRACE_USES_MALLOC > # include "backtrace.h" > +# if SANITIZER_CP_DEMANGLE > +# undef ARRAY_SIZE > +# include "demangle.h" > +# endif > # else > # define SANITIZER_LIBBACKTRACE 0 > # endif > @@ -31,6 +35,60 @@ namespace __sanitizer { > > namespace { > > +#if SANITIZER_CP_DEMANGLE > +struct CplusV3DemangleData { > + char *buf; > + uptr size, allocated; > +}; > + > +extern "C" { > +static void CplusV3DemangleCallback(const char *s, size_t l, void *vdata) { > + Cp
Re: [PATCH] libsanitizer demangling using cp-demangle.c
Jakub Jelinek a écrit: > > 2013-12-10 Jakub Jelinek > > * sanitizer_common/sanitizer_symbolizer_libbacktrace.h > (LibbacktraceSymbolizer::Demangle): New declaration. > * sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc > (POSIXSymbolizer::Demangle): Use libbacktrace_symbolizer_'s Demangle > method if possible. > * sanitizer_common/sanitizer_symbolizer_libbacktrace.cc: Include > "demangle.h" if SANITIZE_CP_DEMANGLE is defined. > (struct CplusV3DemangleData): New type. > (CplusV3DemangleCallback, CplusV3Demangle): New functions. > (SymbolizeCodePCInfoCallback, SymbolizeCodeCallback, > SymbolizeDataCallback): Use CplusV3Demangle. > * sanitizer_common/Makefile.am (AM_CXXFLAGS): Add > -DSANITIZE_CP_DEMANGLE and -I $(top_srcdir)/../include. > * libbacktrace/backtrace-rename.h (cplus_demangle_builtin_types, > cplus_demangle_fill_ctor, cplus_demangle_fill_dtor, > cplus_demangle_fill_extended_operator, cplus_demangle_fill_name, > cplus_demangle_init_info, cplus_demangle_mangled_name, > cplus_demangle_operators, cplus_demangle_print, > cplus_demangle_print_callback, cplus_demangle_type, cplus_demangle_v3, > cplus_demangle_v3_callback, is_gnu_v3_mangled_ctor, > is_gnu_v3_mangled_dtor, java_demangle_v3, java_demangle_v3_callback): > Define. > (__asan_internal_memcmp, __asan_internal_strncmp): New prototypes. > (memcmp, strncmp): Redefine. > * libbacktrace/Makefile.am (libsanitizer_libbacktrace_la_SOURCES): Add > ../../libiberty/cp-demangle.c. > * libbacktrace/bridge.cc (__asan_internal_memcmp, > __asan_internal_strncmp): New functions. > * sanitizer_common/Makefile.in: Regenerated. > * libbacktrace/Makefile.in: Regenerated. > * configure: Regenerated. > * configure.ac: Regenerated. > * config.h.in: Regenerated. This looks good to me. Thanks. -- Dodji
[PATCH] libsanitizer demangling using cp-demangle.c
On Fri, Dec 06, 2013 at 06:40:52AM -0800, Ian Lance Taylor wrote: > There was a recent buggy patch to the demangler that added calls to > malloc and realloc (2013-10-25 Gary Benson ). > That patch must be fixed or reverted before the 4.9 release. The main > code in the demangler must not call malloc/realloc. > > When that patch is fixed, you can use the cplus_demangle_v3_callback > function to get a demangler that never calls malloc. AFAIK Gary is working on a fix, when that is fixed, with the following patch libsanitizer (when using libbacktrace for symbolization) will not use system malloc/realloc/free for the demangling at all. Tested on x86_64-linux (-m64/-m32). Note that the changes for the 3 files unfortunately will need to be applied upstream to compiler-rt, is that possible? 2013-12-10 Jakub Jelinek * sanitizer_common/sanitizer_symbolizer_libbacktrace.h (LibbacktraceSymbolizer::Demangle): New declaration. * sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc (POSIXSymbolizer::Demangle): Use libbacktrace_symbolizer_'s Demangle method if possible. * sanitizer_common/sanitizer_symbolizer_libbacktrace.cc: Include "demangle.h" if SANITIZE_CP_DEMANGLE is defined. (struct CplusV3DemangleData): New type. (CplusV3DemangleCallback, CplusV3Demangle): New functions. (SymbolizeCodePCInfoCallback, SymbolizeCodeCallback, SymbolizeDataCallback): Use CplusV3Demangle. * sanitizer_common/Makefile.am (AM_CXXFLAGS): Add -DSANITIZE_CP_DEMANGLE and -I $(top_srcdir)/../include. * libbacktrace/backtrace-rename.h (cplus_demangle_builtin_types, cplus_demangle_fill_ctor, cplus_demangle_fill_dtor, cplus_demangle_fill_extended_operator, cplus_demangle_fill_name, cplus_demangle_init_info, cplus_demangle_mangled_name, cplus_demangle_operators, cplus_demangle_print, cplus_demangle_print_callback, cplus_demangle_type, cplus_demangle_v3, cplus_demangle_v3_callback, is_gnu_v3_mangled_ctor, is_gnu_v3_mangled_dtor, java_demangle_v3, java_demangle_v3_callback): Define. (__asan_internal_memcmp, __asan_internal_strncmp): New prototypes. (memcmp, strncmp): Redefine. * libbacktrace/Makefile.am (libsanitizer_libbacktrace_la_SOURCES): Add ../../libiberty/cp-demangle.c. * libbacktrace/bridge.cc (__asan_internal_memcmp, __asan_internal_strncmp): New functions. * sanitizer_common/Makefile.in: Regenerated. * libbacktrace/Makefile.in: Regenerated. * configure: Regenerated. * configure.ac: Regenerated. * config.h.in: Regenerated. --- libsanitizer/sanitizer_common/sanitizer_symbolizer_libbacktrace.h.jj 2013-12-05 12:04:28.0 +0100 +++ libsanitizer/sanitizer_common/sanitizer_symbolizer_libbacktrace.h 2013-12-10 11:01:26.777371566 +0100 @@ -29,6 +29,8 @@ class LibbacktraceSymbolizer { bool SymbolizeData(DataInfo *info); + const char *Demangle(const char *name); + private: explicit LibbacktraceSymbolizer(void *state) : state_(state) {} --- libsanitizer/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc.jj 2013-12-05 12:04:28.0 +0100 +++ libsanitizer/sanitizer_common/sanitizer_symbolizer_posix_libcdep.cc 2013-12-10 11:03:02.971876505 +0100 @@ -513,6 +513,11 @@ class POSIXSymbolizer : public Symbolize SymbolizerScope sym_scope(this); if (internal_symbolizer_ != 0) return internal_symbolizer_->Demangle(name); +if (libbacktrace_symbolizer_ != 0) { + const char *demangled = libbacktrace_symbolizer_->Demangle(name); + if (demangled) + return demangled; +} return DemangleCXXABI(name); } --- libsanitizer/sanitizer_common/sanitizer_symbolizer_libbacktrace.cc.jj 2013-12-09 14:32:06.0 +0100 +++ libsanitizer/sanitizer_common/sanitizer_symbolizer_libbacktrace.cc 2013-12-10 11:48:19.803830291 +0100 @@ -20,6 +20,10 @@ # include "backtrace-supported.h" # if SANITIZER_POSIX && BACKTRACE_SUPPORTED && !BACKTRACE_USES_MALLOC # include "backtrace.h" +# if SANITIZER_CP_DEMANGLE +# undef ARRAY_SIZE +# include "demangle.h" +# endif # else # define SANITIZER_LIBBACKTRACE 0 # endif @@ -31,6 +35,60 @@ namespace __sanitizer { namespace { +#if SANITIZER_CP_DEMANGLE +struct CplusV3DemangleData { + char *buf; + uptr size, allocated; +}; + +extern "C" { +static void CplusV3DemangleCallback(const char *s, size_t l, void *vdata) { + CplusV3DemangleData *data = (CplusV3DemangleData *)vdata; + uptr needed = data->size + l + 1; + if (needed > data->allocated) { +data->allocated *= 2; +if (needed > data->allocated) + data->allocated = needed; +char *buf = (char *)InternalAlloc(data->allocated); +if (data->buf) { + internal_memcpy(buf, data->buf, data->size); + InternalFree(data->buf); +} +data->buf = buf; + } + internal_memcpy(data->bu