Re: [PATCH 3/3] [asan] Instrument built-in memory access function calls

2012-10-29 Thread Hans-Peter Nilsson
On Wed, 24 Oct 2012, Dodji Seketeli wrote: > Jakub Jelinek writes: > > On Tue, Oct 23, 2012 at 03:11:29PM +0200, Dodji Seketeli wrote: > > > * asan.c (insert_if_then_before_iter) > > > (instrument_mem_region_access) > > > (maybe_instrument_builtin_call, maybe_instrument_call): New static > >

Re: [PATCH 3/3] [asan] Instrument built-in memory access function calls

2012-10-26 Thread Jakub Jelinek
On Fri, Oct 26, 2012 at 12:13:16PM +0200, Dodji Seketeli wrote: > * asan.c (insert_if_then_before_iter, instrument_mem_region_access, > (instrument_strlen_call, maybe_instrument_builtin_call, > (maybe_instrument_call): New static functions. > (create_cond_insert_point): Rena

Re: [PATCH 3/3] [asan] Instrument built-in memory access function calls

2012-10-26 Thread Dodji Seketeli
Jakub Jelinek writes: >> + location_t location = gimple_location (call); > > I'd call the var just loc, that is far more commonly used and shorter. Done. > >> + /* If we initially had an instruction like: >> + >> + int n = strlen (str) >> + >> + we now want to instrument the access to

Re: [PATCH 3/3] [asan] Instrument built-in memory access function calls

2012-10-25 Thread Jakub Jelinek
On Fri, Oct 26, 2012 at 12:23:41AM +0200, Dodji Seketeli wrote: > +/* Instrument the strlen builtin call pointed to by ITER. > + > + This function instruments the access to the first byte of the > + argument, right before the call. After the call it instruments the > + access to the last byt

Re: [PATCH 3/3] [asan] Instrument built-in memory access function calls

2012-10-25 Thread Dodji Seketeli
Jakub Jelinek writes: >> +instrument_derefs (iter, dest, location, is_store); > > BUILTIN_ATOMIC_LOAD* are just loads and so should clear is_store. Done. > >> + if (len != NULL_TREE) >> +{ >> + is_store = (dest != NULL_TREE); >> + >> + if (source0 != NULL_TREE) >> +instru

Re: [PATCH 3/3] [asan] Instrument built-in memory access function calls

2012-10-25 Thread Jakub Jelinek
On Thu, Oct 25, 2012 at 11:32:58PM +0200, Dodji Seketeli wrote: > + tree source0 = NULL_TREE, source1 = NULL_TREE, > +dest = NULL_TREE, len = NULL_TREE; > + bool is_store = true; ... nothing sets is_store here. ... > + > + instrument_derefs (iter, dest, location, is_store); BUILTIN_ATOMI

Re: [PATCH 3/3] [asan] Instrument built-in memory access function calls

2012-10-25 Thread Dodji Seketeli
Jakub Jelinek writes: > case BUILT_IN_ATOMIC_ALWAYS_LOCK_FREE: > case BUILT_IN_ATOMIC_IS_LOCK_FREE: > I think don't touch the memory at all (or not necessarily), > and IMHO you don't want to handle the BUILT_IN_*_N variants either, > those are just FE builtins that are lowered to the corr

Re: [PATCH 3/3] [asan] Instrument built-in memory access function calls

2012-10-24 Thread Jakub Jelinek
On Wed, Oct 24, 2012 at 05:11:23PM +0200, Dodji Seketeli wrote: > If I write exactly what you wrote here, I am getting an error for e.g: > > void > bar () > { > char bar[1] = {0}; > int n = 0; > > __builtin_memset (bar, 0, n); > } I see, the problem is that buil

Re: [PATCH 3/3] [asan] Instrument built-in memory access function calls

2012-10-24 Thread Dodji Seketeli
Jakub Jelinek writes: > On Wed, Oct 24, 2012 at 05:16:26PM +0200, Dodji Seketeli wrote: >> Jakub Jelinek writes: >> >> >> For 'strlen', can the memory check be done at the end of the string >> >> using the returned length? >> > >> > Guess strlen is commonly expanded inline, so it would be worth

Re: [PATCH 3/3] [asan] Instrument built-in memory access function calls

2012-10-24 Thread Jakub Jelinek
On Wed, Oct 24, 2012 at 05:16:26PM +0200, Dodji Seketeli wrote: > Jakub Jelinek writes: > > >> For 'strlen', can the memory check be done at the end of the string > >> using the returned length? > > > > Guess strlen is commonly expanded inline, so it would be worthwhile to check > > the shadow me

Re: [PATCH 3/3] [asan] Instrument built-in memory access function calls

2012-10-24 Thread Dodji Seketeli
Jakub Jelinek writes: >> For 'strlen', can the memory check be done at the end of the string >> using the returned length? > > Guess strlen is commonly expanded inline, so it would be worthwhile to check > the shadow memory after the call (well, we could check the first byte > before the call and

Re: [PATCH 3/3] [asan] Instrument built-in memory access function calls

2012-10-24 Thread Dodji Seketeli
Jakub Jelinek writes: > On Tue, Oct 23, 2012 at 03:11:29PM +0200, Dodji Seketeli wrote: >> + /* (src, n) style memops. */ >> +case BUILT_IN_STRNDUP: >> + source0 = gimple_call_arg (call, 0); >> + len = gimple_call_arg (call, 1); >> + break; > > I think you can't instrumen

Re: [PATCH 3/3] [asan] Instrument built-in memory access function calls

2012-10-23 Thread Xinliang David Li
On Tue, Oct 23, 2012 at 8:58 AM, Jakub Jelinek wrote: > On Tue, Oct 23, 2012 at 08:47:48AM -0700, Xinliang David Li wrote: >> > + /* The builtin below cannot be safely instrumented as their >> > + length parameter is just a mere limit. >> > + >> >> Why can't the following be instrumen

Re: [PATCH 3/3] [asan] Instrument built-in memory access function calls

2012-10-23 Thread Jakub Jelinek
On Tue, Oct 23, 2012 at 03:11:29PM +0200, Dodji Seketeli wrote: > + /* (src, n) style memops. */ > +case BUILT_IN_STRNDUP: > + source0 = gimple_call_arg (call, 0); > + len = gimple_call_arg (call, 1); > + break; I think you can't instrument strndup either, the length is ju

Re: [PATCH 3/3] [asan] Instrument built-in memory access function calls

2012-10-23 Thread Jakub Jelinek
On Tue, Oct 23, 2012 at 08:47:48AM -0700, Xinliang David Li wrote: > > + /* The builtin below cannot be safely instrumented as their > > + length parameter is just a mere limit. > > + > > Why can't the following be instrumented? The length is min (n, strlen (str)). Because that would

Re: [PATCH 3/3] [asan] Instrument built-in memory access function calls

2012-10-23 Thread Xinliang David Li
On Tue, Oct 23, 2012 at 6:11 AM, Dodji Seketeli wrote: > This patch instruments many memory access patterns through builtins. > > Basically, for a call like: > > __builtin_memset (from, 0, n_bytes); > > the patch would only instrument the accesses at the beginning and at > the end of the memo

Re: [PATCH 3/3] [asan] Instrument built-in memory access function calls

2012-10-23 Thread Jakub Jelinek
On Tue, Oct 23, 2012 at 03:11:29PM +0200, Dodji Seketeli wrote: > * asan.c (insert_if_then_before_iter) > (instrument_mem_region_access) > (maybe_instrument_builtin_call, maybe_instrument_call): New static Why not just write it: * asan.c (insert_if_then_before_iter, instr

[PATCH 3/3] [asan] Instrument built-in memory access function calls

2012-10-23 Thread Dodji Seketeli
This patch instruments many memory access patterns through builtins. Basically, for a call like: __builtin_memset (from, 0, n_bytes); the patch would only instrument the accesses at the beginning and at the end of the memory region [from, from + n_bytes]. This is the strategy used by the l