Bug 31121 - gprofng does not recognise source in a shared object
Summary: gprofng does not recognise source in a shared object
Status: RESOLVED DUPLICATE of bug 30195
Alias: None
Product: binutils
Classification: Unclassified
Component: gprofng (show other bugs)
Version: 2.40
: P2 normal
Target Milestone: ---
Assignee: Vladimir Mezentsev
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-12-08 08:44 UTC by Robert Jenssen
Modified: 2023-12-21 20:17 UTC (History)
0 users

See Also:
Host:
Target:
Build:
Last reconfirmed: 2023-12-09 00:00:00


Attachments
Output of dwarfdump -ka (18.97 KB, text/plain)
2023-12-09 02:41 UTC, Robert Jenssen
Details
Compressed shared object bin2SD.oct.tar.gz (301.49 KB, application/octet-stream)
2023-12-09 03:24 UTC, Robert Jenssen
Details
Compressed output of objdump -dS bin2SD.oct (21.58 KB, application/octet-stream)
2023-12-09 06:01 UTC, Robert Jenssen
Details
Example of a gdb session with bin2SD (1.44 KB, text/plain)
2023-12-19 07:08 UTC, Robert Jenssen
Details
Compressed bin2SD.oct shared object from test.1.er/archives (301.54 KB, application/octet-stream)
2023-12-20 05:37 UTC, Robert Jenssen
Details
Output of "gprofng display text -calltree test.1.er" (1.27 KB, text/plain)
2023-12-20 05:44 UTC, Robert Jenssen
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Robert Jenssen 2023-12-08 08:44:53 UTC

    
Comment 1 Vladimir Mezentsev 2023-12-08 17:47:59 UTC
Typically gprofng cannot recognize the source if a shared object was built without -g or stripped.

Can you see DWARF:
 dwarfdump YOUR_SHARED_OBJECT
or
 objdump -W YOUR_SHARED_OBJECT
Comment 2 Robert Jenssen 2023-12-09 02:41:56 UTC
Created attachment 15246 [details]
Output of dwarfdump -ka

Attached is the output from:

dwarfdump -ka src/bin2SD.oct > bin2SD.oct.dwarfdump

There are many errors in attr_tag and attr_formclass as well as a few harmless_errors.
Comment 3 Vladimir Mezentsev 2023-12-09 02:52:39 UTC
It looks like gprofng cannot read DWARF.
If you may, could you send me (vladimir.mezentsev@oracle.com) this shared object.
Comment 4 Robert Jenssen 2023-12-09 03:24:57 UTC
Created attachment 15247 [details]
Compressed shared object bin2SD.oct.tar.gz

Attached is a compressed shared object bin2SD.oct.tar.gz. It runs under my build of octave and appears in object_list but the source is not seen:

$ file src/bin2SD.oct
src/bin2SD.oct: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=31ac26cbc516d44c31db6979958596cf16dae070, with debug_info, not stripped

$ gprofng display src -source all -1 src/bin2SD.oct
Annotated source
---------------------------------------
$
Comment 5 Vladimir Mezentsev 2023-12-09 04:11:44 UTC
What function would you like to see ?

As I can see a part of bin2SD.oct was built with -g.
For example:
% gp-display-src -dis Gbin2SD bin2SD.oct 
Annotated disassembly
---------------------------------------
Source file: /home/robj/CHANGES/DesignOfIIRFilters.C1406/src/bin2SD.cc (not found)
Object file: bin2SD.oct
Load Object: bin2SD.oct
   
                <Function: Gbin2SD>
                [ 34]     32c9:  push   %r13
                [ 34]     32cb:  push   %r12
                [ 34]     32cd:  push   %rbp
                [ 34]     32ce:  push   %rbx
                [ 34]     32cf:  sub    $0x58,%rsp
                [ 34]     32d3:  mov    %rdi,%rbx
                [ 34]     32d6:  mov    %esi,%ebp
                [ 34]     32d8:  lea    0x4c(%rsp),%rdx
                [ 34]     32dd:  lea    0x20(%rsp),%rdi
                [ 34]     32e2:  lea    0x1d49(%rip),%rsi        # 0x1d50
                [ 34]     32e9:  call   std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string<std::allocator<char> >(char const*, std::allocator<char> const&) [ 0x3c30, .+0x947]
...


But the other part of bin2SD.oct doesn't have a debug information.
For example:
% gp-display-src -dis 'octave_value::octave_value()' bin2SD.oct 
Annotated disassembly
---------------------------------------
Source file: (unknown)
Object file: bin2SD.oct
Load Object: bin2SD.oct

   
   
   
        <Function: octave_value::octave_value()>
        [?]     3994:  push   %rbx
        [?]     3995:  mov    %rdi,%rbx
        [?]     3998:  call   _ZN12octave_value7nil_repEv@plt [ 0x3160, .-0x838]
        [?]     399d:  mov    %rax,(%rbx)
        [?]     39a0:  lock addq $0x1,0x8(%rax)
        [?]     39a6:  pop    %rbx
        [?]     39a7:  ret



You can see a list of functions:
% gp-display-src -func bin2SD.oct

Functions sorted in lexicographic order

Load Object: <bin2SD.oct>

    Address                     Size        Name

  0x0000000000003020               496      @plt
  0x0000000000003020               496      @plt
  0x0000000000003912                57      dim_vector::dim_vector()
  0x0000000000003912                57      dim_vector::dim_vector()
  0x0000000000003994                20      octave_value::octave_value()
  0x0000000000003994                20      octave_value::octave_value()
  0x00000000000039a8                76      octave_value::~octave_value()
  0x00000000000039a8                76      octave_value::~octave_value()
  0x0000000000003b7c                67      octave_value_list::octave_value_list(octave_value_list&&)
  0x0000000000004000               104      octave_value_list::octave_value_list(long)
  0x0000000000003d7a                69      octave_value_list::octave_value_list()
  0x0000000000003b7c                67      octave_value_list::octave_value_list(octave_value_list&&)
  0x0000000000004000               104      octave_value_list::octave_value_list(long)
  0x0000000000003d7a                69      octave_value_list::octave_value_list()
  0x0000000000003b0e               110      Array<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >::Array(Array<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > > >&&)
...
Comment 6 Robert Jenssen 2023-12-09 06:01:06 UTC
Created attachment 15248 [details]
Compressed output of objdump -dS bin2SD.oct

On my system "objdump -dS bin2SD.oct" shows the source code interleaved with the assembler code starting at:

00000000000032c9 <Gbin2SD>:
#include <math.h>

#include <octave/oct.h>
#include <octave/parse.h>

DEFUN_DLD(bin2SD, args, nargout, "y=bin2SD(x,nbits,ndigits)")
    32c9:       41 55                   push   %r13
    32cb:       41 54                   push   %r12
    32cd:       55                      push   %rbp
.
.
.

See the attached output from objdump.
Comment 7 Vladimir Mezentsev 2023-12-09 08:23:43 UTC
OK. The code looks similar.
I cannot see source because /home/robj/CHANGES/DesignOfIIRFilters.C1406/src/bin2SD.cc is not available.
When you use gprofng, do you see sources for Gbin2SD.
Comment 8 Robert Jenssen 2023-12-09 10:14:10 UTC
I can disassemble octave_value_list::octave_value_list but not bin2SD.
The test.1.er/archive directory contains a copy of liboctinterp.so.11.0.2
but not bin2SD.oct. Does gprofng assume that shared objects have a .so suffix?

$ file bin2SD.oct
bin2SD.oct: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=31ac26cbc516d44c31db6979958596cf16dae070, with debug_info, not stripped
$ gprofng collect app octave -p src --eval "y=bin2SD(48.3,16,3)"
Creating experiment directory test.2.er (Process ID: 1684065) ...
y = 48
$  gprofng display text -functions test.1.er
Functions sorted by metric: Exclusive Total CPU Time

Excl. Total   Incl. Total    Name
CPU           CPU
 sec.      %   sec.      %
0.010 100.00  0.010 100.00   <Total>
0.010 100.00  0.010 100.00   __strlen_avx2
0.      0.    0.010 100.00   FcPatternAdd

$ gp-display-src -func src/bin2SD.oct

Functions sorted in lexicographic order

Load Object: <bin2SD.oct>

    Address                     Size        Name

  0x0000000000003020               496      @plt
  0x00000000000032c9               265      Gbin2SD
  0x00000000000033d2              1343      Fbin2SD(octave_value_list const&, int)
  0x0000000000003912                57      dim_vector::dim_vector()
  0x0000000000003912                57      dim_vector::dim_vector()
  0x000000000000394c                72      dim_vector::operator=(dim_vector&&)
  0x0000000000003994                20      octave_value::octave_value()
  0x0000000000003994                20      octave_value::octave_value()
  0x00000000000039a8                76      octave_value::~octave_value()
  0x00000000000039a8                76      octave_value::~octave_value()
  0x0000000000003a4e                97      octave_value::operator=(octave_value&&)
  0x00000000000039f4                90      octave_value::operator=(octave_value const&)
  0x0000000000004364               110      octave_value_list::elem(long)
  0x0000000000003b7c                67      octave_value_list::octave_value_list(octave_value_list&&)
  0x0000000000004000               104      octave_value_list::octave_value_list(long)
  0x0000000000003d7a                69      octave_value_list::octave_value_list()
  0x0000000000003b7c                67      octave_value_list::octave_value_list(octave_value_list&&)
.
.
.
  0x0000000000003c73                38      void std::_Destroy<octave_value*>(octave_value*, octave_value*)
  0x0000000000003280                64      __do_global_dtors_aux
  0x0000000000003000                32      _init
  0x0000000000003210                48      deregister_tm_clones
  0x00000000000032c0                 9      frame_dummy
  0x0000000000003240                64      register_tm_clones
$ gprofng display text -disasm Gbin2SD test.1.er
Error: No function or file with given name `Gbin2SD' found.
$  gprofng display text -disasm Fbin2SD test.1.er
Error: No function or file with given name `Fbin2SD' found.
$  gprofng display text -disasm bin2SD test.1.er
Error: No function or file with given name `bin2SD' found.
$  gprofng display text -disasm octave_value_list::octave_value_list test.1.er
Default selection "1" made
Source file: (unknown)
Object file: liboctinterp.so.11.0.2 (found as test.1.er/archives/liboctinterp.so.11.0.2_cqz4VOkyeyf)
Load Object: liboctinterp.so.11.0.2 (found as test.1.er/archives/liboctinterp.so.11.0.2_cqz4VOkyeyf)

   Excl. Total   Incl. Total
   CPU           CPU
    sec.      %   sec.      %
                                        <Function: octave_value_list::octave_value_list(octave_value const&) [clone .cold]>
   0.      0.    0.      0.             [?]   2d8c4a:  mov    0x28(%rbx),%rdi
   0.      0.    0.      0.             [?]   2d8c4e:  test   %rdi,%rdi
   0.      0.    0.      0.             [?]   2d8c51:  je     0x7
   0.      0.    0.      0.             [?]   2d8c53:  call   0xfffffffffffc61fd
   0.      0.    0.      0.             [?]   2d8c58:  mov    %rbx,%rdi
   0.      0.    0.      0.             [?]   2d8c5b:  call   0x4e3345
   0.      0.    0.      0.             [?]   2d8c60:  mov    %rbp,%rdi
   0.      0.    0.      0.             [?]   2d8c63:  call   0xfffffffffffca9ed
$ 
$ find . -name liboctinterp.so.11.0.2*
./test.1.er/archives/liboctinterp.so.11.0.2_cqz4VOkyeyf
$  find test.1.er -name *binSD*
$
Comment 9 Vladimir Mezentsev 2023-12-09 18:13:54 UTC
>> Does gprofng assume that shared objects have a .so suffix?

 No.

>> $ gprofng collect app octave -p src --eval "y=bin2SD(48.3,16,3)"
>> Creating experiment directory test.2.er (Process ID: 1684065) ...
>> $  gprofng display text -functions test.1.er

You created an experiment in test.2.er.
But you use test.1.er here.


If you don't use the -o or -O option, gprofng will create a new test.<N>.er.
Comment 10 Vladimir Mezentsev 2023-12-19 04:41:56 UTC
Was the problem that parts of bin2SD.oct do not contain debugging information ?
Or do you think this is a problem in gprofng?
Comment 11 Robert Jenssen 2023-12-19 07:08:43 UTC
Created attachment 15266 [details]
Example of a gdb session with bin2SD

My problem is that gdb can see debugging information in the shared object bin2SD.oct but gprofng does not recognise it. See the attached example of a gdb session. For example, with gprofng:

$ cat .gprofng.rc
addpath src
addpath src/test

$ gprofng collect app  /usr/local/octave-9.0.0/bin/octave --no-gui -p src -p src/test src/test/bin2SD_test.m

$ gprofng display text -source Fbin2SD test.1.er
/usr/bin/gp-display-text: Processed /home/robj/TMP/DesignOfIIRFilters/.gprofng.rc for default settings
Error: Source location not recorded in experiment
$ gprofng display text -functions test.1.er | grep bin2SD
/usr/bin/gp-display-text: Processed /home/robj/TMP/DesignOfIIRFilters/.gprofng.rc for default settings
$
Comment 12 Vladimir Mezentsev 2023-12-20 00:10:44 UTC
> $ gprofng display text -functions test.1.er | grep bin2SD
> /usr/bin/gp-display-text: Processed /home/robj/TMP/DesignOfIIRFilters/.gprofng.rc for default settings
> $

gprofng interrupts your application every 10007 msec and collects the stacks.
We see that there are no “*bin2SD” functions.
This means that gprofng did not collect the stack with Fbin2SD.
It's okay if Fbin2SD is that fast.
But this can become a problem when unwinding the stack.
What is an output of:
  gprofng display text -calltree test.1.er


> $ gprofng display text -source Fbin2SD test.1.er
> /usr/bin/gp-display-text: Processed /home/robj/TMP/DesignOfIIRFilters/.gprofng.rc for default settings
> Error: Source location not recorded in experiment

This means that gprofng found Fbin2SD in src/bin2SD.oct, but cannot read DWARF.
you have attached bin2SD.oct.tar.gz. gprofng can read DWARF in this file.
But it looks like a different file (Perhaps it was rebuilt).
Could you attach test.1.er/archives/bin2SD.oct*.
Comment 13 Robert Jenssen 2023-12-20 05:37:13 UTC
Created attachment 15268 [details]
Compressed bin2SD.oct shared object from test.1.er/archives

Replying to comment #12. bin2SD.oct from test.1.er/archives is attached.

I modified the Octave test script for bin2SD to loop 1000 times.

$ gprofng display text -source Fbin2SD test.1.er
/usr/bin/gp-display-text: Processed /home/robj/TMP/DesignOfIIRFilters/.gprofng.rc for default settings
Error: Source location not recorded in experiment
Comment 14 Robert Jenssen 2023-12-20 05:44:38 UTC
Created attachment 15269 [details]
Output of "gprofng display text -calltree test.1.er"

Replying to comment #12. Note that gprofng sees functions from Octave shared libraries. For example:

$ objdump -T /usr/local/octave-9.0.0/lib/octave/9.0.0/liboctinterp.so | grep clear_functions
0000000000aaa07c g    DF .text	0000000000000019  Base        _ZN6octave11interpreter15clear_functionsEb
0000000000bd69ee g    DF .text	0000000000000044  Base        _ZN6octave12symbol_table15clear_functionsEb
$ grep clear_functions gprofng_calltree.txt 
0.010 100.00                                               +-octave::symbol_table::clear_functions(bool)
$ grep bin2SD gprofng_calltree.txt 
$
Comment 15 Vladimir Mezentsev 2023-12-20 06:09:58 UTC
If you run:

% gp-display-src -dis Fbin2SD test.1.er/archives/bin2SD.oct_IGooCa1n7J2
Annotated disassembly
---------------------------------------
Source file: /home/robj/TMP/DesignOfIIRFilters/src/bin2SD.cc (not found)
Object file: test.1.er/archives/bin2SD.oct_IGooCa1n7J2
Load Object: test.1.er/archives/bin2SD.oct_IGooCa1n7J2
    
                <Function: Fbin2SD(octave_value_list const&, int)>
                [  35]     33d2:  push   %r14
                [  35]     33d4:  push   %r13
                [  35]     33d6:  push   %r12
                [  35]     33d8:  push   %rbp
                [  35]     33d9:  push   %rbx
....


 Do you see a correct name in the "Source file:" field ?
If not, what is in your /home/robj/TMP/DesignOfIIRFilters/.gprofng.rc ?
Comment 16 Robert Jenssen 2023-12-21 03:44:27 UTC
$ dnf list installed binutils-gprofng
Installed Packages
binutils-gprofng.x86_64                   2.40-13.fc39                   @fedora
$ gprofng --version
GNU gprofng binutils version 2.40.00
Copyright (C) 2023 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
$ cat .gprofng.rc
addpath /home/robj/TMP/DesignOfIIRFilters/src
addpath /home/robj/TMP/DesignOfIIRFilters/src/test

$ ls src/bin2SD.cc
src/bin2SD.cc
$ gp-display-src -dis Fbin2SD test.1.er/archives/bin2SD.oct_IGooCa1n7J2
/usr/bin/gp-display-src: Processed /home/robj/TMP/DesignOfIIRFilters/.gprofng.rc for default settings
Annotated disassembly
---------------------------------------
Source file: (unknown)
Object file: test.1.er/archives/bin2SD.oct_IGooCa1n7J2
Load Object: test.1.er/archives/bin2SD.oct_IGooCa1n7J2

   
   
   
        <Function: Fbin2SD(octave_value_list const&, int)>
        [?]     33d2:  push   %r14
        [?]     33d4:  push   %r13
        [?]     33d6:  push   %r12
        [?]     33d8:  push   %rbp
        [?]     33d9:  push   %rbx
        [?]     33da:  sub    $0x110,%rsp
        [?]     33e1:  mov    %rdi,%rbx
        [?]     33e4:  mov    0x8(%rsi),%rax
        [?]     33e8:  sub    (%rsi),%rax
        [?]     33eb:  cmp    $0x18,%rax
        [?]     33ef:  jne    0x149
        [?]     33f5:  mov    %rsi,%r12
        [?]     33f8:  cmpb   $0x0,0x3d09(%rip)        # 0x3d10
.
.
.

I get similar results with and without the rc file.  

BTW "gp-display-src --verbose on" does not work ("Error: invalid option: `--verbose'") and I have not found definitions of "item" or "tag" in the info documentation for gprofng.
Comment 17 Vladimir Mezentsev 2023-12-21 04:21:11 UTC
> $ dnf list installed binutils-gprofng
> Installed Packages
> binutils-gprofng.x86_64                   2.40-13.fc39                   @fedora
> $ gprofng --version
> GNU gprofng binutils version 2.40.00

You use an old version.
I think the problem was fixed in 30195 [display text] Source code location can not be found

I don't use Fedora.
Try to download binutils-gprofng-2.41-17.fc40 from
https://packages.fedoraproject.org/pkgs/binutils/binutils-gprofng/fedora-rawhide.html

Another way is to clone https://sourceware.org/git/binutils-gdb.git,
build and install gprofng.
Comment 18 Robert Jenssen 2023-12-21 05:20:30 UTC
My apologies. I did not find #30195. I will try binutils-2.41 in a VM for fc40-rawhide and wait for release next year.
Comment 19 Vladimir Mezentsev 2023-12-21 20:17:07 UTC
It is a duplicate of 30195.

*** This bug has been marked as a duplicate of bug 30195 ***