Bug 32892 - source line level information not available with "-g -O2"
Summary: source line level information not available with "-g -O2"
Status: ASSIGNED
Alias: None
Product: binutils
Classification: Unclassified
Component: gprofng (show other bugs)
Version: 2.44
: P2 normal
Target Milestone: ---
Assignee: Vladimir Mezentsev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2025-04-20 12:39 UTC by Bruno Haible
Modified: 2025-04-21 12:01 UTC (History)
1 user (show)

See Also:
Host: x86_64-linux-gnu
Target:
Build:
Last reconfirmed: 2025-04-21 00:00:00
Project(s) to access:
ssh public key:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Bruno Haible 2025-04-20 12:39:19 UTC
The documentation of gprofng https://sourceware.org/binutils/docs/gprofng.html#Main-Features says: "This tool works with unmodified production level executables. There is no need to recompile the code, but if the ‘-g’ option has been used when building the application, source line level information is available."

So, it sounds like binaries built with the options '-g -O2' should be usable with source line level information.

This is true for valgrind (see https://gitlab.com/ghwiki/gnow-how/-/wikis/Profiling/with_sampling ), but not for gprofng.

How to reproduce:
1. wget https://ftp.gnu.org/gnu/gperf/gperf-3.3.tar.gz
2. tar xfz gperf-3.3.tar.gz
3. cd gperf-3.3
4. export CC=gcc; export CXX=g++; unset CFLAGS; unset CXXFLAGS; export CPPFLAGS=-Wall
5. ./configure
6. make
Observe that the C++ source code gets compiler with "g++ -g -O2".
7. cd src
8. gp-collect-app -o test.1.er -p on -S on ./gperf -m 10 ../tests/5000.gperf > /dev/null
9. gprofng-display-text test.1.er
(gprofng-display-text) lines
...
13.259  91.63  14.210  98.20   <Function: Search::find_asso_values(), instructions without line numbers>
...
(gprofng-display-text) source search.cc

Expected:
Lines search.cc 1396..1402 are highlighted as CPU-intensive.

Actual:
Lines search.cc 1396..1402 are not marked in any way.

This is on Linux/x86_64, with g++ 13.3.0.