Bug 27155 - objcopy --only-keep-debug should strip .debug_info symbols
Summary: objcopy --only-keep-debug should strip .debug_info symbols
Status: RESOLVED INVALID
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.35
: P2 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-01-07 15:30 UTC by Martin Liska
Modified: 2022-06-22 06:29 UTC (History)
1 user (show)

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


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Liska 2021-01-07 15:30:15 UTC
Let's consider the following example:

$ cat foo.c
int foo(void)
{
  return 123;
}

$ gcc foo.c -O2 -g -flto -shared -o libfoo.so

Note that LTO uses artificial debug info symbols for early LTO debug info.

$ readelf -s --wide libfoo.so | grep foo.c
    60: 0000000000000067     0 NOTYPE  LOCAL  DEFAULT   25 foo.c.cf7807ca

as seen the symbol lives in .debug_info section:

$ readelf -S --wide libfoo.so | grep 25
  [25] .debug_info       PROGBITS        0000000000000000 003130 0000ba 00      0   0  1

Now let's create a separated debug info and strip the original library:

$ objcopy --only-keep-debug  libfoo.so debug.so
$ strip --strip-debug libfoo.so

$ readelf -s --wide debug.so | grep foo.c
    60: 0000000000000067     0 NOTYPE  LOCAL  DEFAULT   25 foo.c.cf7807ca

and now we have problem as the original libfoo.so section index 25 points to something different:

$ readelf -S --wide libfoo.so | grep '\[25\]'
  [25] .strtab           STRTAB          0000000000000000 003498 000154 00      0   0  1

My suggestion would be to strip such symbols. Perf is unhappy about such symbols as one can easily get out of sections
in the original ELF file.

Original bug report:
https://bugzilla.suse.com/show_bug.cgi?id=1180610

@Mark: Can you please help me with that?
Comment 1 Martin Liska 2021-01-11 13:20:44 UTC
It's invalid as perf should look at .debug_info in a separate ELF as the section has PROGBITS == 1.