From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 31309 invoked by alias); 11 Sep 2015 02:48:16 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 31299 invoked by uid 89); 11 Sep 2015 02:48:16 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.9 required=5.0 tests=AWL,BAYES_50,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-qk0-f175.google.com Received: from mail-qk0-f175.google.com (HELO mail-qk0-f175.google.com) (209.85.220.175) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES128-GCM-SHA256 encrypted) ESMTPS; Fri, 11 Sep 2015 02:48:14 +0000 Received: by qkfq186 with SMTP id q186so26950231qkf.1 for ; Thu, 10 Sep 2015 19:48:12 -0700 (PDT) X-Received: by 10.55.201.13 with SMTP id q13mr58623985qki.50.1441939692269; Thu, 10 Sep 2015 19:48:12 -0700 (PDT) Received: from [192.168.0.26] (97-122-175-227.hlrn.qwest.net. [97.122.175.227]) by smtp.gmail.com with ESMTPSA id 186sm7183785qhf.16.2015.09.10.19.48.10 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Sep 2015 19:48:11 -0700 (PDT) Message-ID: <55F240E9.4010304@gmail.com> Date: Fri, 11 Sep 2015 03:19:00 -0000 From: Martin Sebor User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: David Malcolm , gcc-patches@gcc.gnu.org Subject: Re: [PATCH 15/22] Add plugin to recursively dump the source-ranges in a tree References: <1441916913-11547-1-git-send-email-dmalcolm@redhat.com> <1441916913-11547-16-git-send-email-dmalcolm@redhat.com> In-Reply-To: <1441916913-11547-16-git-send-email-dmalcolm@redhat.com> Content-Type: multipart/mixed; boundary="------------030109010404000104020804" X-IsSubscribed: yes X-SW-Source: 2015-09/txt/msg00760.txt.bz2 This is a multi-part message in MIME format. --------------030109010404000104020804 Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit Content-length: 1373 On 09/10/2015 02:28 PM, David Malcolm wrote: > This patch adds a test plugin that recurses down an expression tree, > printing diagnostics showing the ranges of each node in the tree. > > Screenshot: > https://dmalcolm.fedorapeople.org/gcc/2015-09-09/show-trees.html > > This needs a linker hack, since it's the only user of > gcc_rich_location::add_expr > which thus doesn't appear in "cc1" until later patches in the kit > add uses of it; is there a clean way to fix that? ... > + Hack: fails with linker error: > +./diagnostic_plugin_show_trees.so: undefined symbol: _ZN17gcc_rich_location8add_exprEP9tree_node > + since nothing in the tree is using gcc_rich_location::add_expr yet. > + > + I've tried various workarounds (adding DEBUG_FUNCTION to the > + method, taking its address), but can't seem to fix it that way. > + So as a nasty workaround, the following material is copied&pasted > + from gcc-rich-location.c: */ I would expect this to work so long as cc1 is linked with --export-dynamic (or -rdynamic which I think it is), and it does in the attached example. I wonder what's different about the way it's built (I haven't tried to reproduce it with gcc). Martin PS I've only skimmed the patch but besides being in awe at how you managed to structure it and not get lost in the dependencies I really like the output in the snapshots. Very cool! --------------030109010404000104020804 Content-Type: text/x-csrc; name="t.c" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="t.c" Content-length: 1246 /* $ (set -x; fl='-O2 -Wall -flto'; cat t.c && g++ -DFOO=1 -c $fl -o foo.o t.c && g++ -DBAR=1 -c $fl -o bar.o t.c && g++ -DMAIN=1 -c $fl t.c && g++ $fl -Wl,--export-dynamic -ldl foo.o bar.o t.o && g++ -DDSO=1 -fpic $fl -o plugin.so -shared t.c) && LD_LIBRARY_PATH=. ./a.out + fl='-O2 -Wall -flto' + cat t.c */ #include #include struct S { void foo (); int bar (); }; #if FOO void S::foo () { puts (__func__); } #elif BAR int S::bar () { puts (__func__); return 0; } #elif DSO extern "C" { void foobar (S &s) { puts (__func__); s.foo (); } } #elif MAIN int main () { S s; void *dl = dlopen ("plugin.so", RTLD_LAZY); if (!dl) { fprintf (stderr, "dlopen: %s\n", dlerror ()); return 1; } void (*f)(S&) = (void (*)(S&))dlsym (dl, "foobar"); if (!f) { fprintf (stderr, "dlsym: %s\n", dlerror ()); return 1; } f (s); dlclose (dl); return s.bar (); } #endif /* + g++ -DFOO=1 -c -O2 -Wall -flto -o foo.o t.c + g++ -DBAR=1 -c -O2 -Wall -flto -o bar.o t.c + g++ -DMAIN=1 -c -O2 -Wall -flto t.c + g++ -O2 -Wall -flto -Wl,--export-dynamic -ldl foo.o bar.o t.o + g++ -DDSO=1 -fpic -O2 -Wall -flto -o plugin.so -shared t.c foobar foo bar $ */ --------------030109010404000104020804--