Patchwork Sparc ASAN

login
register
mail settings
Submitter Konstantin Serebryany
Date Dec. 3, 2012, 6:33 p.m.
Message ID <CAGQ9bdydPvMQL5YKE7VivE7U+25myp4wjmOrc6bDMANtpOSW1Q@mail.gmail.com>
Download mbox | patch
Permalink /patch/203411/
State New
Headers show

Comments

Konstantin Serebryany - Dec. 3, 2012, 6:33 p.m.
On Mon, Dec 3, 2012 at 10:29 PM, David Miller <davem@davemloft.net> wrote:
> From: Konstantin Serebryany <konstantin.s.serebryany@gmail.com>
> Date: Mon, 3 Dec 2012 22:18:56 +0400
>
>> On Mon, Dec 3, 2012 at 10:02 PM, David Miller <davem@davemloft.net> wrote:
>>> The only changes to libsantizier is to put __sparc__ checks where
>>> __powerpc__ checks exist in the unwind code.
>>
>> Like this?
>>
>> ===================================================================
>> --- asan/asan_linux.cc  (revision 169136)
>> +++ asan/asan_linux.cc  (working copy)
>> @@ -158,7 +158,9 @@
>>    stack->trace[0] = pc;
>>    if ((max_s) > 1) {
>>      stack->max_size = max_s;
>> -#if defined(__arm__) || defined(__powerpc__) || defined(__powerpc64__)
>> +#if defined(__arm__) || \
>> +    defined(__powerpc__) || defined(__powerpc64__) || \
>> +    defined(__sparc__)
>>      _Unwind_Backtrace(Unwind_Trace, stack);
>>      // Pop off the two ASAN functions from the backtrace.
>>      stack->PopStackFrames(2);
>
> Yes, that's perfect.
>
> We could also add a __sparc__ block to sanitizer_stacktrace.cc:patch_pc().
> The Sparc PC is actually 8 bytes after the caller's jump.  Sparc has
> a delay slot, the place to return to is 2 instructions after the call/jump,
> and instructions are all 4 bytes long.

Like this?




>
>> We either need to align the redzones by 32 always, or for some platforms.
>> Either is fine for me.
>
> I'm ambivalent as well.
David Miller - Dec. 3, 2012, 6:37 p.m.
From: Konstantin Serebryany <konstantin.s.serebryany@gmail.com>
Date: Mon, 3 Dec 2012 22:33:12 +0400

> On Mon, Dec 3, 2012 at 10:29 PM, David Miller <davem@davemloft.net> wrote:
>> We could also add a __sparc__ block to sanitizer_stacktrace.cc:patch_pc().
>> The Sparc PC is actually 8 bytes after the caller's jump.  Sparc has
>> a delay slot, the place to return to is 2 instructions after the call/jump,
>> and instructions are all 4 bytes long.
> 
> Like this?
> 
> --- sanitizer_common/sanitizer_stacktrace.cc    (revision 169136)
> +++ sanitizer_common/sanitizer_stacktrace.cc    (working copy)
> @@ -36,6 +36,8 @@
>  #if defined(__powerpc__) || defined(__powerpc64__)
>    // PCs are always 4 byte aligned.
>    return pc - 4;
> +#elif defined(__sparc__)
> +  return pc - 8;
>  #else
>    return pc - 1;
>  #endif
> 

Perfect.
Konstantin Serebryany - Dec. 3, 2012, 6:44 p.m.
On Mon, Dec 3, 2012 at 10:37 PM, David Miller <davem@davemloft.net> wrote:
> From: Konstantin Serebryany <konstantin.s.serebryany@gmail.com>
> Date: Mon, 3 Dec 2012 22:33:12 +0400
>
>> On Mon, Dec 3, 2012 at 10:29 PM, David Miller <davem@davemloft.net> wrote:
>>> We could also add a __sparc__ block to sanitizer_stacktrace.cc:patch_pc().
>>> The Sparc PC is actually 8 bytes after the caller's jump.  Sparc has
>>> a delay slot, the place to return to is 2 instructions after the call/jump,
>>> and instructions are all 4 bytes long.
>>
>> Like this?
>>
>> --- sanitizer_common/sanitizer_stacktrace.cc    (revision 169136)
>> +++ sanitizer_common/sanitizer_stacktrace.cc    (working copy)
>> @@ -36,6 +36,8 @@
>>  #if defined(__powerpc__) || defined(__powerpc64__)
>>    // PCs are always 4 byte aligned.
>>    return pc - 4;
>> +#elif defined(__sparc__)
>> +  return pc - 8;
>>  #else
>>    return pc - 1;
>>  #endif
>>
>
> Perfect.

http://llvm.org/viewvc/llvm-project?view=rev&revision=169141
Will reach gcc with the next libsanitizer merge (or feel free to
commit the same patch directly to gcc).

--kcc
David Miller - Dec. 3, 2012, 6:48 p.m.
From: Konstantin Serebryany <konstantin.s.serebryany@gmail.com>
Date: Mon, 3 Dec 2012 22:44:15 +0400

> On Mon, Dec 3, 2012 at 10:37 PM, David Miller <davem@davemloft.net> wrote:
>> From: Konstantin Serebryany <konstantin.s.serebryany@gmail.com>
>> Date: Mon, 3 Dec 2012 22:33:12 +0400
>>
>>> On Mon, Dec 3, 2012 at 10:29 PM, David Miller <davem@davemloft.net> wrote:
>>>> We could also add a __sparc__ block to sanitizer_stacktrace.cc:patch_pc().
>>>> The Sparc PC is actually 8 bytes after the caller's jump.  Sparc has
>>>> a delay slot, the place to return to is 2 instructions after the call/jump,
>>>> and instructions are all 4 bytes long.
>>>
>>> Like this?
>>>
>>> --- sanitizer_common/sanitizer_stacktrace.cc    (revision 169136)
>>> +++ sanitizer_common/sanitizer_stacktrace.cc    (working copy)
>>> @@ -36,6 +36,8 @@
>>>  #if defined(__powerpc__) || defined(__powerpc64__)
>>>    // PCs are always 4 byte aligned.
>>>    return pc - 4;
>>> +#elif defined(__sparc__)
>>> +  return pc - 8;
>>>  #else
>>>    return pc - 1;
>>>  #endif
>>>
>>
>> Perfect.
> 
> http://llvm.org/viewvc/llvm-project?view=rev&revision=169141
> Will reach gcc with the next libsanitizer merge (or feel free to
> commit the same patch directly to gcc).

Thanks for taking care of this.

Patch

--- sanitizer_common/sanitizer_stacktrace.cc    (revision 169136)
+++ sanitizer_common/sanitizer_stacktrace.cc    (working copy)
@@ -36,6 +36,8 @@ 
 #if defined(__powerpc__) || defined(__powerpc64__)
   // PCs are always 4 byte aligned.
   return pc - 4;
+#elif defined(__sparc__)
+  return pc - 8;
 #else
   return pc - 1;
 #endif