On 07/14/2017 03:42 PM, Michael Matz wrote: > Hi, > > On Thu, 13 Jul 2017, Martin Liška wrote: > >> Hopefully following patch will fix that. I returned to the first version >> and saved/restored static_chain register before/after >> __asan_stack_malloc. > > It should also work if you emit the parm_birth_note after the static chain > is set up (not before it), but before you store into the > nonlocal_goto_save_area. With that you don't need to worry about > clobbering the incoming static chain with the asan setup.
Unfortunately it does not work. First asan_emit_stack_protection is executed, which creates: #0 0x00000000009850f4 in expand_used_vars () at ../../gcc/cfgexpand.c:2233 #1 0x0000000000992ab7 in (anonymous namespace)::pass_expand::execute (this=0x28c02f0, fun=0x2aaaac1b60b0) at ../../gcc/cfgexpand.c:6232 #2 0x0000000000e0d3a8 in execute_one_pass (pass=0x28c02f0) at ../../gcc/passes.c:2492 which does all the stack preparation (including the problematic call to __asan_stack_malloc_N). Note that this code still should be placed before parm_birth_note as we cant's say that params are ready before a fake stack is prepared. Then we generate code that loads the implicit chain argument: (gdb) p debug_rtx_list(get_insns(), 100) (note 1 0 37 NOTE_INSN_DELETED) (note 37 1 38 NOTE_INSN_FUNCTION_BEG) (insn 38 37 39 (set (reg/f:DI 94 [ CHAIN.1 ]) (reg:DI 39 r10 [ CHAIN.1 ])) "/home/marxin/Programming/gcc/gcc/testsuite/gcc.dg/asan/pr81186.c":9 -1 (nil)) (insn 39 38 0 (set (mem/c:DI (plus:DI (reg/f:DI 82 virtual-stack-vars) (const_int -584 [0xfffffffffffffdb8])) [0 S8 A64]) (reg:DI 39 r10 [ CHAIN.1 ])) "/home/marxin/Programming/gcc/gcc/testsuite/gcc.dg/asan/pr81186.c":9 -1 (nil)) Which is problematic as using virtual-stack-vars which should point to fake stack done by AddressSanitizer in __asan_stack_malloc_N. That said both parts (ASAN fake stack init and CHAIN load from implicit argument) are before parm birth actions that should be aware each other. Thus my previous patch preserves the r10 register on x86_64. Thanks, Martin > > Can you test that? It would better reflect the intent of this note (the > static chain being an implicit parameter, but the nonlocal_goto_save_area > setup not being such). > > > Ciao, > Michael. >