Re: [PATCH] Put -lasan always very early on the ld command line (PR sanitizer/55374)

2013-02-05 Thread Jakub Jelinek
On Tue, Feb 05, 2013 at 09:37:29AM +0100, Eric Botcazou wrote:
> Tested on x86_64-suse-linux, OK for the mainline?
> 
> 
> 2013-02-05  Eric Botcazou  
> 
>   PR sanitizer/55374
>   * config/gnu-user.h (LIBASAN_EARLY_SPEC): Add missing guard.

Yes, thanks.

> Index: config/gnu-user.h
> ===
> --- config/gnu-user.h (revision 195694)
> +++ config/gnu-user.h (working copy)
> @@ -102,10 +102,12 @@ see the files COPYING3 and COPYING.RUNTI
> it for -shared link, the executable should be compiled with 
> -static-libasan
> in that case, and for executable link link with --{,no-}whole-archive 
> around
> it to force everything into the executable.  */
> +#if defined(HAVE_LD_STATIC_DYNAMIC)
>  #undef LIBASAN_EARLY_SPEC
>  #define LIBASAN_EARLY_SPEC "%{static-libasan:%{!shared:" \
>LD_STATIC_OPTION " --whole-archive -lasan --no-whole-archive " \
>LD_DYNAMIC_OPTION "}}%{!static-libasan:-lasan}"
> +#endif
>  
>  /* Additional libraries needed by -static-libasan.  */
>  #undef STATIC_LIBASAN_LIBS

Jakub


Re: [PATCH] Put -lasan always very early on the ld command line (PR sanitizer/55374)

2013-02-05 Thread Eric Botcazou
> 2013-01-22  Jakub Jelinek  
> 
>   PR sanitizer/55374
>   * gcc.c (LIBASAN_SPEC): Define just to ADD_STATIC_LIBASAN_LIBS if
>   LIBASAN_EARLY_SPEC is defined.
>   (LIBASAN_EARLY_SPEC): Define to empty string if not already defined.
>   (LINK_COMMAND_SPEC): Add LIBASAN_EARLY_SPEC for -fsanitize=address,
>   before %o.
>   * config/gnu-user.h (LIBASAN_EARLY_SPEC): Define.

This has introduced a syntax error for gcc.c when you're building a quick 
cross-compiler.  Fixed by the attached patchlet.

Tested on x86_64-suse-linux, OK for the mainline?


2013-02-05  Eric Botcazou  

PR sanitizer/55374
* config/gnu-user.h (LIBASAN_EARLY_SPEC): Add missing guard.


-- 
Eric BotcazouIndex: config/gnu-user.h
===
--- config/gnu-user.h	(revision 195694)
+++ config/gnu-user.h	(working copy)
@@ -102,10 +102,12 @@ see the files COPYING3 and COPYING.RUNTI
it for -shared link, the executable should be compiled with -static-libasan
in that case, and for executable link link with --{,no-}whole-archive around
it to force everything into the executable.  */
+#if defined(HAVE_LD_STATIC_DYNAMIC)
 #undef LIBASAN_EARLY_SPEC
 #define LIBASAN_EARLY_SPEC "%{static-libasan:%{!shared:" \
   LD_STATIC_OPTION " --whole-archive -lasan --no-whole-archive " \
   LD_DYNAMIC_OPTION "}}%{!static-libasan:-lasan}"
+#endif
 
 /* Additional libraries needed by -static-libasan.  */
 #undef STATIC_LIBASAN_LIBS

Re: [PATCH] Put -lasan always very early on the ld command line (PR sanitizer/55374)

2013-01-30 Thread Jakub Jelinek
On Wed, Jan 30, 2013 at 04:04:55PM +0100, Dodji Seketeli wrote:
> As an aside, I am curious why about ...
> 
> > --- gcc/testsuite/g++.dg/asan/deep-stack-uaf-1.C.jj 2012-12-14 
> > 16:24:38.0 +0100
> > +++ gcc/testsuite/g++.dg/asan/deep-stack-uaf-1.C2013-01-22 
> > 16:43:03.337091101 +0100
> > @@ -27,7 +27,7 @@ struct DeepFree<0> {
> >  };
> >  
> >  int main() {
> > -  char *x = new char[10];
> > +  char *x = (char*)malloc(10);
> >// deep_free(x);
> >DeepFree<200>::free(x);
> >return x[5];
> 
> ... why/how this is falling when -lasan comes before -lstdc++?

libasan has added recently support for operator new and operator new[]
checking, which checks that there is not a mismatch between the way
how object is allocated (malloc/calloc/realloc vs. operator new vs. operator
new[]) and how it is deallocated (free vs. delete vs. delete[]).  The
deep-stack-uaf-1.C testcase has been violating this (new char[10]
allocation, free (x) deallocation) and has been changed upstream
when those changes landed into libasan.  When -lstdc++ came first,
the -lasan operator new interceptor wasn't called (because libstdc++'s
operator new was earlier in search scope) and thus it appeared as calling
malloc and doing free to -lasan.

Jakub


Re: [PATCH] Put -lasan always very early on the ld command line (PR sanitizer/55374)

2013-01-30 Thread Dodji Seketeli
Jakub Jelinek  writes:


> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
>
> 2013-01-22  Jakub Jelinek  
>
>   PR sanitizer/55374
>   * gcc.c (LIBASAN_SPEC): Define just to ADD_STATIC_LIBASAN_LIBS if
>   LIBASAN_EARLY_SPEC is defined.
>   (LIBASAN_EARLY_SPEC): Define to empty string if not already defined.
>   (LINK_COMMAND_SPEC): Add LIBASAN_EARLY_SPEC for -fsanitize=address,
>   before %o.
>   * config/gnu-user.h (LIBASAN_EARLY_SPEC): Define.
>
>   * g++.dg/asan/large-func-test-1.C: Allow both _Zna[jm] in addition
>   to _Znw[jm] in the backtrace.  Allow _Zna[jm] to be the first frame
>   printed in backtrace.
>   * g++.dg/asan/deep-stack-uaf-1.C: Use malloc instead of operator new
>   to avoid errors about mismatched allocation vs. deallocation.

This looks okay for me.  Sorry for the delay.

As an aside, I am curious why about ...

> --- gcc/testsuite/g++.dg/asan/deep-stack-uaf-1.C.jj   2012-12-14 
> 16:24:38.0 +0100
> +++ gcc/testsuite/g++.dg/asan/deep-stack-uaf-1.C  2013-01-22 
> 16:43:03.337091101 +0100
> @@ -27,7 +27,7 @@ struct DeepFree<0> {
>  };
>  
>  int main() {
> -  char *x = new char[10];
> +  char *x = (char*)malloc(10);
>// deep_free(x);
>DeepFree<200>::free(x);
>return x[5];

... why/how this is falling when -lasan comes before -lstdc++?

-- 
Dodji


Re: [PATCH] Put -lasan always very early on the ld command line (PR sanitizer/55374)

2013-01-30 Thread Jason Merrill

Looks good to me.  OK if nobody else responds today.

Jason