Bug 2162495
Summary: | eu-addr2line -i option to display inlined functions doesn't work with LTO (-flto) and Dwarf5 | ||||||
---|---|---|---|---|---|---|---|
Product: | Red Hat Enterprise Linux 8 | Reporter: | Vikramsingh Patil <vikpatil> | ||||
Component: | elfutils | Assignee: | Mark Wielaard <mjw> | ||||
elfutils sub component: | system-version | QA Contact: | Martin Cermak <mcermak> | ||||
Status: | CLOSED ERRATA | Docs Contact: | Petr Hybl <phybl> | ||||
Severity: | medium | ||||||
Priority: | unspecified | CC: | casantos, fweimer, gfialova, lkuprova, mcermak, mjw, phybl, tminor, wcohen | ||||
Version: | 8.6 | Keywords: | Triaged | ||||
Target Milestone: | rc | ||||||
Target Release: | --- | ||||||
Hardware: | All | ||||||
OS: | Linux | ||||||
Whiteboard: | |||||||
Fixed In Version: | elfutils-0.189-1.el8 | Doc Type: | Bug Fix | ||||
Doc Text: |
.`eu-addr2line -i` now correctly handles code compiled with GCC link-time optimization
Previously, the `dwarf_getscopes` function from the `libdw` library included in `elfutils` was unable to find an abstract origin definition of a function that was compiled with GCC link-time optimization. Consequently, when you used the `-i` argument in the `eu-addr2line` command, `eu-addr2line` was unable to show inline functions for code compiled with `gcc -flto`. With this update, the `libdw dwarf_getscopes` function looks in the correct compile unit for the inlined scope, and `eu-addr2line -i` works as expected.
|
Story Points: | --- | ||||
Clone Of: | |||||||
: | 2182059 (view as bug list) | Environment: | |||||
Last Closed: | 2023-11-14 15:47:35 UTC | Type: | Bug | ||||
Regression: | --- | Mount Type: | --- | ||||
Documentation: | --- | CRM: | |||||
Verified Versions: | Category: | --- | |||||
oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |||||
Cloudforms Team: | --- | Target Upstream Version: | |||||
Embargoed: | |||||||
Bug Depends On: | |||||||
Bug Blocks: | 2182059 | ||||||
Attachments: |
|
This is indeed an issue with eu-addr2line -i, also in upstream. It doesn't seem to rely on the DWARF version with both gcc -O2 -flto -gdwarf-4 and -gdwarf-5 you don't actually get inlined subroutines. It seems to be caused by including the -C flag: -C, --demangle[=ARG] Show demangled symbols (ARG is always ignored) Without it: $ eu-addr2line -fi -e a.out 0x0000000000401055 FunctionToInline1 inlined at /tmp/repro_inlines/sample.c:34:5 in main /tmp/repro_inlines/sample.c:6:5 FunctionToInline2 /tmp/repro_inlines/sample.c:34:5 FunctionToInline3 /tmp/repro_inlines/sample.c:39:5 FunctionToInline4 /tmp/repro_inlines/sample.c:43:5 FunctionToInline5 /tmp/repro_inlines/sample.c:47:5 FunctionToInline6 /tmp/repro_inlines/sample.c:51:5 main /tmp/repro_inlines/sample.c:57:5 I'll investigate, it shouldn't matter whether or not we are demangling the symbols, but apparently it does. Note that as a workaround you can probably use binutils addr2line which seems to work correctly with -fCi (at least upstream, and tested against binutils version 2.38) (In reply to Mark Wielaard from comment #1) > It seems to be caused by including the -C flag: > -C, --demangle[=ARG] Show demangled symbols (ARG is always ignored) > > Without it: > > $ eu-addr2line -fi -e a.out 0x0000000000401055 > FunctionToInline1 inlined at /tmp/repro_inlines/sample.c:34:5 in main > /tmp/repro_inlines/sample.c:6:5 > FunctionToInline2 > /tmp/repro_inlines/sample.c:34:5 > FunctionToInline3 > /tmp/repro_inlines/sample.c:39:5 > FunctionToInline4 > /tmp/repro_inlines/sample.c:43:5 > FunctionToInline5 > /tmp/repro_inlines/sample.c:47:5 > FunctionToInline6 > /tmp/repro_inlines/sample.c:51:5 > main > /tmp/repro_inlines/sample.c:57:5 > > I'll investigate, it shouldn't matter whether or not we are demangling the > symbols, but apparently it does. This is really an embarrassing bug. The problem is that -C takes an argument (which is always ignored). The code simply treats anything as an argument, so if you use eu-readelf -fCi ... it takes that 'i' as argument to -C and ignores it. So you don't get -i inlines... The workaround is putting -C last (-fiC): $ eu-addr2line -fiC -e a.out 0x0000000000401052 FunctionToInline1 inlined at /tmp/repro_inlines/sample.c:34:5 in main /tmp/repro_inlines/sample.c:6:5 FunctionToInline2 /tmp/repro_inlines/sample.c:34:5 FunctionToInline3 /tmp/repro_inlines/sample.c:39:5 FunctionToInline4 /tmp/repro_inlines/sample.c:43:5 FunctionToInline5 /tmp/repro_inlines/sample.c:47:5 FunctionToInline6 /tmp/repro_inlines/sample.c:51:5 main /tmp/repro_inlines/sample.c:57:5 The customer(In reply to Mark Wielaard from comment #2) > (In reply to Mark Wielaard from comment #1) > > It seems to be caused by including the -C flag: > > -C, --demangle[=ARG] Show demangled symbols (ARG is always ignored) > > > > Without it: > > > > $ eu-addr2line -fi -e a.out 0x0000000000401055 > > FunctionToInline1 inlined at /tmp/repro_inlines/sample.c:34:5 in main > > /tmp/repro_inlines/sample.c:6:5 > > FunctionToInline2 > > /tmp/repro_inlines/sample.c:34:5 > > FunctionToInline3 > > /tmp/repro_inlines/sample.c:39:5 > > FunctionToInline4 > > /tmp/repro_inlines/sample.c:43:5 > > FunctionToInline5 > > /tmp/repro_inlines/sample.c:47:5 > > FunctionToInline6 > > /tmp/repro_inlines/sample.c:51:5 > > main > > /tmp/repro_inlines/sample.c:57:5 > > > > I'll investigate, it shouldn't matter whether or not we are demangling the > > symbols, but apparently it does. > > This is really an embarrassing bug. The problem is that -C takes an argument > (which is always ignored). > The code simply treats anything as an argument, so if you use eu-readelf > -fCi ... it takes that 'i' as argument to -C and ignores it. > So you don't get -i inlines... > > The workaround is putting -C last (-fiC): > > $ eu-addr2line -fiC -e a.out 0x0000000000401052 > FunctionToInline1 inlined at /tmp/repro_inlines/sample.c:34:5 in main > /tmp/repro_inlines/sample.c:6:5 > FunctionToInline2 > /tmp/repro_inlines/sample.c:34:5 > FunctionToInline3 > /tmp/repro_inlines/sample.c:39:5 > FunctionToInline4 > /tmp/repro_inlines/sample.c:43:5 > FunctionToInline5 > /tmp/repro_inlines/sample.c:47:5 > FunctionToInline6 > /tmp/repro_inlines/sample.c:51:5 > main > /tmp/repro_inlines/sample.c:57:5 The customer for whom we opened the bugs replied that the workaround does not work and I confirmed it: $ rpm -q gcc-toolset-11 gcc-toolset-11-11.1-1.el8.x86_64 $ rpm -qf /bin/eu-addr2line elfutils-0.187-4.el8.x86_64 $ scl enable gcc-toolset-11 'gcc -O2 -flto -gdwarf-5 -g sample.c' $ scl enable gcc-toolset-11 'eu-addr2line -fiC -e a.out 0x0000000000401052' main /work/XXXXXXXX/repro_inlines/sample.c:6:5 $ /bin/eu-addr2line -fiC -e a.out 0x0000000000401052 main /work/XXXXXXXX/repro_inlines/sample.c:6:5 (In reply to Carlos Santos from comment #3) > The customer for whom we opened the bugs replied that the workaround does > not work and I confirmed it: > > $ rpm -q gcc-toolset-11 > gcc-toolset-11-11.1-1.el8.x86_64 > > $ rpm -qf /bin/eu-addr2line > elfutils-0.187-4.el8.x86_64 > > $ scl enable gcc-toolset-11 'gcc -O2 -flto -gdwarf-5 -g sample.c' > > $ scl enable gcc-toolset-11 'eu-addr2line -fiC -e a.out 0x0000000000401052' > main > /work/XXXXXXXX/repro_inlines/sample.c:6:5 > > $ /bin/eu-addr2line -fiC -e a.out 0x0000000000401052 You are right. I apparently hadn't tested with the -flto option, thinking that wasn't it. Sorry. If you do use -flto then it really doesn't work with or without -C or placing it last. I go and try to figure out what goes wrong when the binary is produced with -flto. Upstream acts the same, so it isn't a RHEL specific bug. So there are two issues: 1) The demangle option -C prevents -i to work when used before it. So -Ci won't show inlines, but -iC does. Submitted an upstream patch to fix that: https://patchwork.sourceware.org/project/elfutils/patch/20230123091128.687801-1-mark@klomp.org/ 2) The -i inlines option doesn't work when using -flto. This has now easy workaround. The issue is that with -flto the abstract origin of an inlined subroutine is in a separate "compile unit", which confused the libdw dwarf_getscopes function. Patch to fix that submitted upstream: https://patchwork.sourceware.org/project/elfutils/patch/20230123091520.688326-1-mark@klomp.org/ Since the problem described in this bug report should be resolved in a recent advisory, it has been closed with a resolution of ERRATA. For information on the advisory (elfutils bug fix and enhancement update), and where to find the updated files, follow the link below. If the solution does not work for you, open a new bug report. https://access.redhat.com/errata/RHBA-2023:7089 |
Created attachment 1939208 [details] reproducer code Description of problem: eu-addr2line -i option to display inlined functions doesn't work with LTO (-flto) and Dwarf5 Version-Release number of selected component (if applicable): elfutils-0.187-4.el8.x86_64 gcc-toolset-11-elfutils-0.185-5.el8.x86_64 How reproducible: every time Steps to Reproduce: 1.From repro.sh found in repro_inlines.tgz scl enable gcc-toolset-11 'gcc -O2 -flto -gdwarf-5 -g sample.c' 2.scl enable gcc-toolset-11 'eu-addr2line -fCi -e a.out 0x401055' Actual results: "main /mnt/data/RTVs/testIK8/elfutils/repro_inlines/sample.c:6:5" Expected results: # "FunctionToInline1 # /mnt/data/repro_inlines/sample.c:6 # FunctionToInline2 # /mnt/data/repro_inlines/sample.c:34 # FunctionToInline3 # /mnt/data/repro_inlines/sample.c:39 # FunctionToInline4 # /mnt/data/elfutils/repro_inlines/sample.c:43 # FunctionToInline5 # /mnt/data/repro_inlines/sample.c:47 # FunctionToInline6 # /mnt/data/repro_inlines/sample.c:51 # main # /mnt/data/repro_inlines/sample.c:57 # " Additional info: