This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: libsanitizer merge from upstream r191666
- From: Konstantin Serebryany <konstantin dot s dot serebryany at gmail dot com>
- To: Jakub Jelinek <jakub at redhat dot com>
- Cc: GCC Patches <gcc-patches at gcc dot gnu dot org>, Dodji Seketeli <dodji at redhat dot com>, Dmitry Vyukov <dvyukov at google dot com>
- Date: Tue, 29 Oct 2013 17:15:24 -0700
- Subject: Re: libsanitizer merge from upstream r191666
- Authentication-results: sourceware.org; auth=none
- References: <CAGQ9bdzrx07_OfvCcxm_uFUt3MRhg1gwqdHvmK_9kHDmz1vPVw at mail dot gmail dot com> <CAGQ9bdxj-DmEaoo0mOWfSVXsrhVShWj3onHZRxiwt97Vq6J45w at mail dot gmail dot com> <20131029121355 dot GY30970 at tucnak dot zalov dot cz> <CAGQ9bdw+VW=yF+vaqE_0GkyHUChL_vp3cABZf-FuNYoHo3g=eg at mail dot gmail dot com> <CAGQ9bdzHaBmaTnnX3=npLngK+8K1P2EWWMX-GmOLz0S1vWcHVA at mail dot gmail dot com>
Actually, I guessed the flags:
% ../gcc-inst/bin/g++ -g -fsanitize=address -static-libasan -O2 -flto
-fno-use-linker-plugin -flto-partition=none
../gcc/gcc/testsuite/c-c++-common/asan/stack-overflow-1.c; ./a.out
2>&1
/tmp/ccgSw6NI.lto.o: In function `main':
../gcc/gcc/testsuite/c-c++-common/asan/stack-overflow-1.c:13:
undefined reference to `.LASANPC0.2585'
collect2: error: ld returned 1 exit status
Looks like this patch is not friendly to -flto
--kcc
On Tue, Oct 29, 2013 at 4:54 PM, Konstantin Serebryany
<konstantin.s.serebryany@gmail.com> wrote:
> Jakub,
>
> Your patch seems to do what it should:
>
> % ../gcc-inst/bin/g++ -gdwarf-2 -fsanitize=address -static-libasan
> ../gcc/gcc/testsuite/c-c++-common/asan/stack-overflow-1.c && ./a.out
> ...
> Address 0x7fffb8ec95ca is located in stack of thread T0 at offset 42 in frame
> #0 0x44bd73 in main
> ../gcc/gcc/testsuite/c-c++-common/asan/stack-overflow-1.c:13
>
> But now when I run the tests I get this:
>
> FAIL: c-c++-common/asan/clone-test-1.c -O2 -flto
> -fno-use-linker-plugin -flto-partition=none (test for excess errors)
> FAIL: c-c++-common/asan/clone-test-1.c -O2 -flto -fuse-linker-plugin
> -fno-fat-lto-objects (test for excess errors)
> FAIL: c-c++-common/asan/memcmp-1.c -O2 -flto -fno-use-linker-plugin
> -flto-partition=none (test for excess errors)
> FAIL: c-c++-common/asan/memcmp-1.c -O2 -flto -fuse-linker-plugin
> -fno-fat-lto-objects (test for excess errors)
> FAIL: c-c++-common/asan/stack-overflow-1.c -O2 -flto
> -fno-use-linker-plugin -flto-partition=none (test for excess errors)
> FAIL: c-c++-common/asan/stack-overflow-1.c -O2 -flto
> -fuse-linker-plugin -fno-fat-lto-objects (test for excess errors)
> FAIL: c-c++-common/asan/swapcontext-test-1.c -O2 -flto
> -fno-use-linker-plugin -flto-partition=none (test for excess errors)
> FAIL: c-c++-common/asan/swapcontext-test-1.c -O2 -flto
> -fuse-linker-plugin -fno-fat-lto-objects (test for excess errors)
> FAIL: g++.dg/asan/deep-thread-stack-1.C -O2 -flto
> -fno-use-linker-plugin -flto-partition=none (test for excess errors)
> FAIL: g++.dg/asan/deep-thread-stack-1.C -O2 -flto -fuse-linker-plugin
> -fno-fat-lto-objects (test for excess errors)
>
> W/o your change they pass.
> Could you please remind me how to debug this (i.e. how to run the
> exact test commands manually)?
>
> Thanks!
> --kcc
>
> On Tue, Oct 29, 2013 at 6:49 AM, Konstantin Serebryany
> <konstantin.s.serebryany@gmail.com> wrote:
>> Thanks!
>> (At this time I will be slow with response due to travel)
>>
>> --kcc
>>
>>
>> On Tue, Oct 29, 2013 at 5:13 AM, Jakub Jelinek <jakub@redhat.com> wrote:
>>>
>>> > On Wed, Oct 2, 2013 at 12:51 PM, Konstantin Serebryany
>>> > > 2013-10-XX Kostya Serebryany <kcc@google.com>
>>> > >
>>> > > * g++.dg/asan/asan_test.cc: Update the test
>>> > > to match the fresh asan run-time.
>>> > > * c-c++-common/asan/stack-overflow-1.c: Ditto.
>>> > >
>>> > > =========== gcc/ChangeLog
>>> > >
>>> > > 2013-10-XX Kostya Serebryany <kcc@google.com>
>>> > >
>>> > > * asan.c: Update to match the changed asan API.
>>> > > (asan_emit_stack_protection): update the string stored in the
>>> > > stack red zone to match new API. Store the PC of the current
>>> > > function in the red zone.
>>> > > (asan_global_struct): update the __asan_global definition to
>>> > > match
>>> > > the new API.
>>> > > (asan_add_global): Ditto.
>>> > > * sanitizer.def: rename __asan_init_v1 to __asan_init_v3
>>>
>>> The "Update to match the changed asan API." should either be
>>> dropped, or come on a line before the * asan.c
>>> (asan_emit_stack_protection):
>>> line. All descriptions should start with capital letters, end with ., two
>>> spaces after . if followed by another sentence.
>>>
>>> Besides that, here is (completely untested) attempt to give you
>>> the pc of the first instruction of the function and two minor changes
>>> (pp_string (something, "") is useless and in two spots I've noticed
>>> you didn't add space before ( in function call).
>>>
>>> Finally, if the new libasan is ABI incompatible with the old one, which
>>> seems it is, then libsanitizer/asan/libtool-version (and perhaps also
>>> libsanitizer/tsan/libtool-version, haven't looked if that one is ABI
>>> compatible or not) needs to be bumped (to 1:0:0 ?).
>>>
>>> --- gcc/asan.c.jj 2013-10-29 11:58:30.000000000 +0100
>>> +++ gcc/asan.c 2013-10-29 13:04:07.709667677 +0100
>>> @@ -921,6 +921,15 @@ asan_clear_shadow (rtx shadow_mem, HOST_
>>> add_int_reg_note (jump, REG_BR_PROB, REG_BR_PROB_BASE * 80 / 100);
>>> }
>>>
>>> +void
>>> +asan_function_start (void)
>>> +{
>>> + section *fnsec = function_section (current_function_decl);
>>> + switch_to_section (fnsec);
>>> + ASM_OUTPUT_DEBUG_LABEL (asm_out_file, "LASANPC",
>>> + current_function_funcdef_no);
>>> +}
>>> +
>>> /* Insert code to protect stack vars. The prologue sequence should be
>>> emitted
>>> directly, epilogue sequence returned. BASE is the register holding
>>> the
>>> stack base, against which OFFSETS array offsets are relative to,
>>> OFFSETS
>>> @@ -936,12 +945,13 @@ asan_emit_stack_protection (rtx base, HO
>>> int length)
>>> {
>>> rtx shadow_base, shadow_mem, ret, mem;
>>> + char buf[30];
>>> unsigned char shadow_bytes[4];
>>> HOST_WIDE_INT base_offset = offsets[length - 1], offset, prev_offset;
>>> HOST_WIDE_INT last_offset, last_size;
>>> int l;
>>> unsigned char cur_shadow_byte = ASAN_STACK_MAGIC_LEFT;
>>> - tree str_cst;
>>> + tree str_cst, decl;
>>>
>>> if (shadow_ptr_types[0] == NULL_TREE)
>>> asan_init_shadow_ptr_types ();
>>> @@ -949,7 +959,6 @@ asan_emit_stack_protection (rtx base, HO
>>> /* First of all, prepare the description string. */
>>> pretty_printer asan_pp;
>>>
>>> - pp_string (&asan_pp, "");
>>> pp_decimal_int (&asan_pp, length / 2 - 1);
>>> pp_space (&asan_pp);
>>> for (l = length - 2; l; l -= 2)
>>> @@ -980,7 +989,17 @@ asan_emit_stack_protection (rtx base, HO
>>> mem = adjust_address (mem, VOIDmode, GET_MODE_SIZE (ptr_mode));
>>> emit_move_insn (mem, expand_normal (str_cst));
>>> mem = adjust_address (mem, VOIDmode, GET_MODE_SIZE (ptr_mode));
>>> - emit_move_insn (mem, expand_normal (str_cst)); // FIXME: should be
>>> cur_pc.
>>> + ASM_GENERATE_INTERNAL_LABEL (buf, "LASANPC",
>>> current_function_funcdef_no);
>>> + decl = build_decl (DECL_SOURCE_LOCATION (current_function_decl),
>>> + VAR_DECL, get_identifier (buf), char_type_node);
>>> + TREE_ADDRESSABLE (decl) = 1;
>>> + TREE_READONLY (decl) = 1;
>>> + DECL_ARTIFICIAL (decl) = 1;
>>> + DECL_IGNORED_P (decl) = 1;
>>> + TREE_STATIC (decl) = 1;
>>> + TREE_PUBLIC (decl) = 0;
>>> + TREE_USED (decl) = 1;
>>> + emit_move_insn (mem, expand_normal (build_fold_addr_expr (decl)));
>>> shadow_base = expand_binop (Pmode, lshr_optab, base,
>>> GEN_INT (ASAN_SHADOW_SHIFT),
>>> NULL_RTX, 1, OPTAB_DIRECT);
>>> @@ -1979,8 +1998,8 @@ asan_add_global (tree decl, tree type, v
>>> pp_string (&asan_pp, "<unknown>");
>>> str_cst = asan_pp_string (&asan_pp);
>>>
>>> - pp_string(&module_name_pp, main_input_filename);
>>> - module_name_cst = asan_pp_string(&module_name_pp);
>>> + pp_string (&module_name_pp, main_input_filename);
>>> + module_name_cst = asan_pp_string (&module_name_pp);
>>>
>>> if (asan_needs_local_alias (decl))
>>> {
>>> --- gcc/asan.h.jj 2013-01-11 09:02:50.000000000 +0100
>>> +++ gcc/asan.h 2013-10-29 12:37:54.190798947 +0100
>>> @@ -21,6 +21,7 @@ along with GCC; see the file COPYING3.
>>> #ifndef TREE_ASAN
>>> #define TREE_ASAN
>>>
>>> +extern void asan_function_start (void);
>>> extern void asan_finish_file (void);
>>> extern rtx asan_emit_stack_protection (rtx, HOST_WIDE_INT *, tree *,
>>> int);
>>> extern bool asan_protect_global (tree);
>>> --- gcc/final.c.jj 2013-10-23 14:43:12.000000000 +0200
>>> +++ gcc/final.c 2013-10-29 12:49:33.609176613 +0100
>>> @@ -78,6 +78,7 @@ along with GCC; see the file COPYING3.
>>> #include "cfgloop.h"
>>> #include "params.h"
>>> #include "tree-pretty-print.h" /* for dump_function_header */
>>> +#include "asan.h"
>>>
>>> #ifdef XCOFF_DEBUGGING_INFO
>>> #include "xcoffout.h" /* Needed for external data
>>> @@ -1738,6 +1739,9 @@ final_start_function (rtx first, FILE *f
>>>
>>> high_block_linenum = high_function_linenum = last_linenum;
>>>
>>> + if (flag_sanitize & SANITIZE_ADDRESS)
>>> + asan_function_start ();
>>> +
>>> if (!DECL_IGNORED_P (current_function_decl))
>>> debug_hooks->begin_prologue (last_linenum, last_filename);
>>>
>>>
>>>
>>> Jakub
>>
>>