Bug 25640 - nm shows symbol as 'U' while showed as 'T'
Summary: nm shows symbol as 'U' while showed as 'T'
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.34
: P2 normal
Target Milestone: 2.35
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-03-06 13:23 UTC by Martin Liška
Modified: 2020-03-25 14:12 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Last reconfirmed:


Attachments
test-case (22.34 KB, application/x-bzip)
2020-03-06 13:23 UTC, Martin Liška
Details
This is a kludge. (645 bytes, patch)
2020-03-06 16:44 UTC, H.J. Lu
Details | Diff
Pass -flto-partition=none to GCC (534 bytes, patch)
2020-03-06 16:54 UTC, H.J. Lu
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Liška 2020-03-06 13:23:52 UTC
Created attachment 12352 [details]
test-case

Using latest release I see:

$ gcc connection.i -O2 -c -flto -c -o x.o
$ nm -B x.o | grep 'U tp_connection_get_type\>'
         U tp_connection_get_type

while previous release 2.33 showed:

$ /home/marxin/Programming/binutils/objdir/binutils/nm-new --plugin /usr/bin/../bin/../lib/bfd-plugins/liblto_plugin.so.0.0.0 x.o

$ /home/marxin/Programming/binutils/objdir/binutils/nm-new --plugin /usr/bin/../bin/../lib/bfd-plugins/liblto_plugin.so.0.0.0 x.o | grep tp_connection_get_type
00000000 T tp_connection_get_type
Comment 1 H.J. Lu 2020-03-06 16:37:46 UTC
LTO generates 2 ltrans.o files from one input IR:

$ nm /tmp/ccXafC5I.ltrans0.ltrans.o | grep tp_connection_get_type
0000000000004570 T tp_connection_get_type
0000000000002250 t tp_connection_get_type_once
$nm /tmp/ccXafC5I.ltrans1.ltrans.o | grep tp_connection_get_type
                 U tp_connection_get_type
 
plugin picked the last one.
Comment 2 Martin Liška 2020-03-06 16:40:56 UTC
Heh. Then we should use -flto-partition=none or one.

Anyway, to be honest, I'm still not fully convinced about the selected approach (of using LTO for nm). There's still a possibility to extend lto plugin to provide information about a symbol whether it's a function of a global variable. That would need plugin extension and GCC change in streaming of LTO call graph section.
Comment 3 H.J. Lu 2020-03-06 16:44:48 UTC
Created attachment 12354 [details]
This is a kludge.
Comment 4 H.J. Lu 2020-03-06 16:54:26 UTC
Created attachment 12355 [details]
Pass -flto-partition=none to GCC
Comment 5 Martin Liška 2020-03-06 17:13:03 UTC
(In reply to H.J. Lu from comment #4)
> Created attachment 12355 [details]
> Pass -flto-partition=none to GCC

This seems right to me.

Anyway, can't we built on something like:
https://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;a=log;h=refs/users/marxin/heads/lto-plugin-symbol-type

There should be extra space at the end of struct ld_plugin_symbol which can make it backward compatible..
Comment 6 H.J. Lu 2020-03-06 17:17:40 UTC
(In reply to Martin Liška from comment #5)
> (In reply to H.J. Lu from comment #4)
> > Created attachment 12355 [details]
> > Pass -flto-partition=none to GCC
> 
> This seems right to me.
> 
> Anyway, can't we built on something like:
> https://gcc.gnu.org/git/gitweb.cgi?p=gcc.git;a=log;h=refs/users/marxin/heads/
> lto-plugin-symbol-type
> 
> There should be extra space at the end of struct ld_plugin_symbol which can
> make it backward compatible..

It sounds a good idea.  Please also add TLS, BSS and DATA.
Comment 7 Martin Liška 2020-03-09 09:08:20 UTC
(In reply to H.J. Lu from comment #4)
> Created attachment 12355 [details]
> Pass -flto-partition=none to GCC

The patch does not work, very likely due to:

lto-wrapper.c:608:

   604          /* Drop arguments that we want to take from the link line.  */
   605          case OPT_flto_:
   606          case OPT_flto:
   607          case OPT_flto_partition_:
   608            continue;
Comment 8 H.J. Lu 2020-03-09 15:34:30 UTC
(In reply to Martin Liška from comment #7)
> (In reply to H.J. Lu from comment #4)
> > Created attachment 12355 [details]
> > Pass -flto-partition=none to GCC
> 
> The patch does not work, very likely due to:
> 
> lto-wrapper.c:608:
> 
>    604          /* Drop arguments that we want to take from the link line. 
> */
>    605          case OPT_flto_:
>    606          case OPT_flto:
>    607          case OPT_flto_partition_:
>    608            continue;

But it works on your testcase.
Comment 9 Martin Liška 2020-03-09 16:19:36 UTC
(In reply to H.J. Lu from comment #8)
> (In reply to Martin Liška from comment #7)
> > (In reply to H.J. Lu from comment #4)
> > > Created attachment 12355 [details]
> > > Pass -flto-partition=none to GCC
> > 
> > The patch does not work, very likely due to:
> > 
> > lto-wrapper.c:608:
> > 
> >    604          /* Drop arguments that we want to take from the link line. 
> > */
> >    605          case OPT_flto_:
> >    606          case OPT_flto:
> >    607          case OPT_flto_partition_:
> >    608            continue;
> 
> But it works on your testcase.

Are you sure? I tried that by adding the patch to package and also locally and it didn't work.
Can you please paste output of:
strace -f -s512 nm -B x.o 2>&1 | grep execv
Comment 10 H.J. Lu 2020-03-09 16:47:36 UTC
(In reply to Martin Liška from comment #9)
> (In reply to H.J. Lu from comment #8)
> > (In reply to Martin Liška from comment #7)
> > > (In reply to H.J. Lu from comment #4)
> > > > Created attachment 12355 [details]
> > > > Pass -flto-partition=none to GCC
> > > 
> > > The patch does not work, very likely due to:
> > > 
> > > lto-wrapper.c:608:
> > > 
> > >    604          /* Drop arguments that we want to take from the link line. 
> > > */
> > >    605          case OPT_flto_:
> > >    606          case OPT_flto:
> > >    607          case OPT_flto_partition_:
> > >    608            continue;
> > 
> > But it works on your testcase.
> 
> Are you sure? I tried that by adding the patch to package and also locally
> and it didn't work.
> Can you please paste output of:
> strace -f -s512 nm -B x.o 2>&1 | grep execv

I was wrong.  I was using different GCC.
Comment 11 Sourceware Commits 2020-03-20 04:01:44 UTC
The master branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=c3a1714ce7806002726a60c0db09371425fe3097

commit c3a1714ce7806002726a60c0db09371425fe3097
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Thu Mar 19 21:00:19 2020 -0700

    plugin: Use LDPT_ADD_SYMBOLS_V2 to get symbol type
    
    Since LTO plugin may generate more than one ltrans.o file from one input
    IR object as LTO wrapper ignores -flto-partition=none:
    
    lto-wrapper.c:608:
    
       604          /* Drop arguments that we want to take from the link line.  */
       605          case OPT_flto_:
       606          case OPT_flto:
       607          case OPT_flto_partition_:
       608            continue;
    
    the LTO wrapper approach is not only slow but also unreliable.  Since
    the LTO plugin API has been extended to add LDPT_ADD_SYMBOLS_V2 with
    symbol type and section kind, we can use LDPT_ADD_SYMBOLS_V2 to get
    symbol type, instead of invoking the LTO wrapper.
    
            PR binutils/25640
            * plugin.c (plugin_list_entry): Add has_symbol_type.
            (add_symbols_v2): New function.
            (bfd_plugin_open_input): Don't invoke LTO wrapper if LTO plugin
            provides symbol type.
            (try_load_plugin): Add LDPT_ADD_SYMBOLS_V2.
            (bfd_plugin_canonicalize_symtab): Use LTO plugin symbol type if
            available.
Comment 12 Sourceware Commits 2020-03-25 14:10:29 UTC
The binutils-2_34-branch branch has been updated by H.J. Lu <hjl@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=64f5c0afcc4683f0003b60d6a5a299beb08f38de

commit 64f5c0afcc4683f0003b60d6a5a299beb08f38de
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Wed Mar 25 06:54:20 2020 -0700

    plugin: Use LDPT_ADD_SYMBOLS_V2 to get symbol type
    
    Since LTO plugin may generate more than one ltrans.o file from one input
    IR object as LTO wrapper ignores -flto-partition=none:
    
    lto-wrapper.c:608:
    
       604          /* Drop arguments that we want to take from the link line.  */
       605          case OPT_flto_:
       606          case OPT_flto:
       607          case OPT_flto_partition_:
       608            continue;
    
    the LTO wrapper approach is not only slow but also unreliable.  Since
    the LTO plugin API has been extended to add LDPT_ADD_SYMBOLS_V2 with
    symbol type and section kind, we can use LDPT_ADD_SYMBOLS_V2 to get
    symbol type, instead of invoking the LTO wrapper.
    
            PR binutils/25640
            * plugin.c (plugin_list_entry): Add has_symbol_type.
            (add_symbols_v2): New function.
            (bfd_plugin_open_input): Don't invoke LTO wrapper if LTO plugin
            provides symbol type.
            (try_load_plugin): Add LDPT_ADD_SYMBOLS_V2.
            (bfd_plugin_canonicalize_symtab): Use LTO plugin symbol type if
            available.
    
    (cherry picked from commit c3a1714ce7806002726a60c0db09371425fe3097)
Comment 13 H.J. Lu 2020-03-25 14:12:09 UTC
Fixed for 2.35 and 2.34 branch.