From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from csb.redhat.com (gnu.wildebeest.org [45.83.234.184]) by sourceware.org (Postfix) with ESMTPS id 9C1823858D32 for ; Mon, 23 Jan 2023 09:15:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9C1823858D32 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=klomp.org Received: by csb.redhat.com (Postfix, from userid 10916) id D6C84CF45F; Mon, 23 Jan 2023 10:15:22 +0100 (CET) From: Mark Wielaard To: elfutils-devel@sourceware.org Cc: Mark Wielaard Subject: [PATCH] libdw: Search for abstract origin in the correct CU Date: Mon, 23 Jan 2023 10:15:20 +0100 Message-Id: <20230123091520.688326-1-mark@klomp.org> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3038.1 required=5.0 tests=BAYES_00,GIT_PATCH_0,JMQ_SPF_NEUTRAL,KAM_DMARC_STATUS,SPF_HELO_NONE,SPF_PASS,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: With gcc -flto the abstract origin of an inlined subroutine could be in a different CU. dwarf_getscopes might return an empty scope if it cannot find the abstract origin scope. So make sure to search in the We also tried to add the origin match in pc_record directly in the current inlined scope. This always failed, causing to do a needless traversal, followed by the full CU scan in dwarf_getscopes. Just always stop the pc_record search and then do the CU origin_match in dwarf_getscopes. Signed-off-by: Mark Wielaard --- libdw/ChangeLog | 6 +++++ libdw/dwarf_getscopes.c | 18 ++++++++------ tests/ChangeLog | 6 +++++ tests/Makefile.am | 1 + tests/run-addr2line-i-test.sh | 43 +++++++++++++++++++++++++++++++++ tests/testfile-inlines-lto.bz2 | Bin 0 -> 2838 bytes 6 files changed, 66 insertions(+), 8 deletions(-) create mode 100755 tests/testfile-inlines-lto.bz2 diff --git a/libdw/ChangeLog b/libdw/ChangeLog index 4c7af94e..71e96c88 100644 --- a/libdw/ChangeLog +++ b/libdw/ChangeLog @@ -1,3 +1,9 @@ +2023-01-22 Mark Wielaard + + * dwarf_getscopes.c (pc_record): Return nscopes when done. + (dwarf_getscopes): Call __libdw_visit_scopes with + inlined_origin CU. + 2022-12-20 Mark Wielaard * Makefile.am (AM_CPPFLAGS): Add -I$(srcdir)/../libebl. diff --git a/libdw/dwarf_getscopes.c b/libdw/dwarf_getscopes.c index 5662eecf..833f1ac5 100644 --- a/libdw/dwarf_getscopes.c +++ b/libdw/dwarf_getscopes.c @@ -1,5 +1,6 @@ /* Return scope DIEs containing PC address. Copyright (C) 2005, 2007, 2015 Red Hat, Inc. + Copyright (C) 2023 Mark J. Wielaard This file is part of elfutils. This file is free software; you can redistribute it and/or modify @@ -173,12 +174,8 @@ pc_record (unsigned int depth, struct Dwarf_Die_Chain *die, void *arg) /* Not there yet. */ return 0; - /* Now we are in a scope that contains the concrete inlined instance. - Search it for the inline function's abstract definition. - If we don't find it, return to search the containing scope. - If we do find it, the nonzero return value will bail us out - of the postorder traversal. */ - return __libdw_visit_scopes (depth, die, NULL, &origin_match, NULL, a); + /* This is the innermost inline scope, we are done here. */ + return a->nscopes; } @@ -193,8 +190,13 @@ dwarf_getscopes (Dwarf_Die *cudie, Dwarf_Addr pc, Dwarf_Die **scopes) int result = __libdw_visit_scopes (0, &cu, NULL, &pc_match, &pc_record, &a); - if (result == 0 && a.scopes != NULL) - result = __libdw_visit_scopes (0, &cu, NULL, &origin_match, NULL, &a); + if (result >= 0 && a.scopes != NULL && a.inlined > 0) + { + /* We like the find the inline function's abstract definition + scope, but that might be in a different CU. */ + cu.die = CUDIE (a.inlined_origin.cu); + result = __libdw_visit_scopes (0, &cu, NULL, &origin_match, NULL, &a); + } if (result > 0) *scopes = a.scopes; diff --git a/tests/ChangeLog b/tests/ChangeLog index 66807856..ba7c1c93 100644 --- a/tests/ChangeLog +++ b/tests/ChangeLog @@ -1,3 +1,9 @@ +2023-01-22 Mark Wielaard + + * testfile-inlines-lto.bz2: New testfile. + * run-addr2line-i-test.sh: Add new lto inlines test. + * Makefile.am (EXTRA_DIST): Add testfile-inlines-lto.bz2. + 2023-01-19 Mark Wielaard * run-debuginfod-query-retry.sh: Use libdebuginfod.so.1 instead diff --git a/tests/Makefile.am b/tests/Makefile.am index 71b19601..393ce7b1 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -426,6 +426,7 @@ EXTRA_DIST = run-arextract.sh run-arsymtest.sh run-ar.sh \ testfilenolines.bz2 test-core-lib.so.bz2 test-core.core.bz2 \ test-core.exec.bz2 run-addr2line-test.sh \ run-addr2line-i-test.sh testfile-inlines.bz2 \ + testfile-inlines-lto.bz2 \ run-addr2line-i-lex-test.sh testfile-lex-inlines.bz2 \ run-addr2line-i-demangle-test.sh run-addr2line-alt-debugpath.sh \ testfileppc32.bz2 testfileppc64.bz2 \ diff --git a/tests/run-addr2line-i-test.sh b/tests/run-addr2line-i-test.sh index d08f3cba..4f63e487 100755 --- a/tests/run-addr2line-i-test.sh +++ b/tests/run-addr2line-i-test.sh @@ -220,4 +220,47 @@ testrun_compare ${abs_top_builddir}/src/addr2line --pretty-print -a -f -i -e tes (inlined by) _Z2fuv at /tmp/x.cpp:33 EOF +# == x.cpp == +# g++ x.cpp -g -fPIC -olibx.so -shared -O0 -flto +# +# __attribute__((always_inline)) inline +# int foobar(int i) +# { +# return i + 1; +# } +# +# __attribute__((always_inline)) inline +# int fubar(int i) +# { +# return i + 1; +# } +# +# __attribute__((always_inline)) inline +# int bar(int i) +# { +# return fubar(i++); +# } +# +# __attribute__((always_inline)) inline +# int foo(int i) +# { +# return foobar(i++); +# } +# +# int fu(int i) +# { +# return foo(i++) + bar(i++); +# } + +testfiles testfile-inlines-lto + +testrun_compare ${abs_top_builddir}/src/addr2line --pretty -fiC -e testfile-inlines-lto 0x1118 0x1137 <<\EOF +foobar(int) at /tmp/x.cpp:4:14 + (inlined by) foo(int) at /tmp/x.cpp:22:16 + (inlined by) fu(int) at /tmp/x.cpp:27:13 +fubar(int) at /tmp/x.cpp:10:14 + (inlined by) bar(int) at /tmp/x.cpp:16:15 + (inlined by) fu(int) at /tmp/x.cpp:27:24 +EOF + exit 0 diff --git a/tests/testfile-inlines-lto.bz2 b/tests/testfile-inlines-lto.bz2 new file mode 100755 index 0000000000000000000000000000000000000000..7e2e2bfd481a1d56f8a396a39726c3d21c984620 GIT binary patch literal 2838 zcmV+x3+ePiT4*^jL0KkKS*V|nQveFr|NsC0|Nr;@|NsC0{{H{}-}>)sb*9*BL-~C} zbZ~xc|9{{KpL5=Jc+s%-JF{#}+-~*^uDU(!b?t8+xJe=i1PVNvO|(YUG}@a})5xHD zhqRh%Y2_PJ)Owl$>TFZg^)fWk00SnPXk_w@8Udu#8Y+Gx zRNj-++EZ$NspUOG)CP?hLqIYB007WvGyn!b$N``L000000j7Y^28aPtd8hyhpfLag zL7)Rb00E$Bp^yy#00000(?da^00001rhzGA!Wrho&~9-wG601W^EpbZdY(CMKEy(V?IQ zgA+{+0B8UJ01OjAXwcBfkP@0gO$mU3rjuxs#WdPAGB%-;AZ;d$LFxbi116aROo5;c z4FCp!02%-Rpa24HuD~A02{EXtGvA{gtjaHwSgo#?Ye?9-MS_Tcyp^5hYW4+E;bnY!4dniDRpu{AN^C@zH%!X1yaUlzhAhL2KA%J@Y_}2i!HyH#fp)x9u z5y{0dgi>Qjh@p-ui5?p1tqS&&h>Gyf6w1V=zpd>c->za)tu1`4pFcA#62i%_j^r@J zrBRR?R$Gnnw^16LfCjG989E9Tl7hS<2@{WyWilX9N?d#K!^_5^IIvnDolzlBiWDsR ztE;;;sM%c&nS@wVM!z6WFzHirdQhXk-ecH}66Dko$y$oDB83NH{+jwLTv;unl?p+*OfwtQa7bpv0dt5qNWi~N#=RQqnmJy};oQ8M0o2{6e644IQLF@!6INei`Pf}w*Y zl1d~p5GT`cAXy_JW7;_cEPzBz1f~WyDA*v80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