Bug 30699 - objcopy: '--only-keep-debug for ELF relocatables' test fails
Summary: objcopy: '--only-keep-debug for ELF relocatables' test fails
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.41
: P2 normal
Target Milestone: ---
Assignee: Nick Clifton
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-07-30 18:08 UTC by Sam James
Modified: 2023-12-20 02:37 UTC (History)
1 user (show)

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


Attachments
binutils.log.xz (91.11 KB, application/x-xz)
2023-07-30 18:08 UTC, Sam James
Details
testprog.o (8.91 KB, application/x-object)
2023-08-01 06:27 UTC, Sam James
Details
Proposed patch (478 bytes, patch)
2023-08-01 11:28 UTC, Nick Clifton
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Sam James 2023-07-30 18:08:41 UTC
Created attachment 15022 [details]
binutils.log.xz

The '--only-keep-debug for ELF relocatables' binutils/objcopy test fails for me with binutils-2.41.

```
$ grep -rsin ^FAIL /var/tmp/portage/sys-devel/binutils-2.41/temp/build.log
12755:FAIL: tmpdir/gp-collect-app_F
12819:FAIL: --only-keep-debug for ELF relocatables
13115:FAIL: Run pr23169b
```
Comment 1 Sam James 2023-07-30 18:10:52 UTC Comment hidden (obsolete)
Comment 2 Sam James 2023-07-30 18:11:31 UTC Comment hidden (obsolete)
Comment 3 Nick Clifton 2023-07-31 15:52:51 UTC
Hi Sam,

  The test appears to be failing because it thinks that the .debug_macro sections,
  and their associated .rela.debug_macro sections do not contain debug information
  and as a result, should not appear (with contents) in a file that has been 
  stripped of everything but debugging:

    Expected SHT_NOBITS type for .debug_macro
    Expected SHT_NOBITS type for .rela.debug_macro
    FAIL: --only-keep-debug for ELF relocatables

  The reason that the test thinks that these sections do not contain debug info
  is because they are part of a section group.  The test code runs readelf over
  the before-being-stripped version of the file and looks for any section with
  either the ALLOC or GROUP flags set.  Any such section found is added to a 
  list of non-debug sections:

	if { $type != "NOTE" && [regexp {[AG]} $flag] } {
	    lappend non_debug_sections $name

  But two of the .debug_macro sections are part of a group: 

  [14] .debug_macro      PROGBITS  0000000000000000 00070f 00001a 00      0   0  1
  [15] .rela.debug_macro RELA      0000000000000000 001ed8 000048 18   I 29  14  8
  [16] .debug_macro      PROGBITS  0000000000000000 000730 000038 00  GC  0   0  8
  [17] .rela.debug_macro RELA      0000000000000000 001f20 0028f8 18  IG 29  16  8
  [18] .debug_macro      PROGBITS  0000000000000000 000768 000028 00   G  0   0  1
  [19] .rela.debug_macro RELA      0000000000000000 004818 000090 18  IG 29  18  8

  (I assume that this is normal behaviour for gcc when it is creating .debug_macro
  sections).

  So I think that the logic in proc keep_debug_symbols_for_elf_relocatable 
  in binutils/testsuite/binutils-all/objcopy.exp needs to be updated.

  Would it be possible for you to upload a copy of the unstriped version of
  testprog.o that is triggering these results ?  The version of gcc that I
  am using does not generate .debug_macro sections, so I cannot test any changes
  that I make using my own compiler.

Cheers
  Nick
Comment 4 Sam James 2023-08-01 06:27:10 UTC
Created attachment 15029 [details]
testprog.o

Hi Nick,

I've attached testprog.o, let me know if you need anything else.

It may or may not be to do with building with -ggdb3, but I can't reproduce it yet when running `runtest` manually (but I'm not super familiar with dejagnu yet, I usually just run `make check).

$ file /var/tmp/portage/sys-devel/binutils-2.41/work/build/binutils/tmpdir/testprog.o
/var/tmp/portage/sys-devel/binutils-2.41/work/build/binutils/tmpdir/testprog.o: ELF 64-bit LSB relocatable, x86-64, version 1 (SYSV), with debug_info, not stripped
Comment 5 Nick Clifton 2023-08-01 11:28:53 UTC
Created attachment 15030 [details]
Proposed patch

Hi Sam,

  Please could you try out this patch and let me know if it works for you ?

Cheers
  Nick
Comment 6 Sam James 2023-08-01 13:18:23 UTC
That works for me, thanks Nick!

$ grep -rsin -- ": --only-keep-debug for ELF relocatables" /var/tmp/portage/sys-devel/binutils-2.41/work/build/binutils/binutils.log
6516:PASS: --only-keep-debug for ELF relocatables
Comment 7 Sourceware Commits 2023-08-01 13:40:17 UTC
The master branch has been updated by Nick Clifton <nickc@sourceware.org>:

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

commit b99a9693430a9f04165b1b868f890b622bb1b46c
Author: Nick Clifton <nickc@redhat.com>
Date:   Tue Aug 1 14:37:04 2023 +0100

    Fix "--only-keep-debug for ELF relocatables" binutils test for compilers which add .debug_macro sections to object files.
    
      PR 30699
      * binutils/testsuite/binutils-all/objcopy.exp (keep_debug_symbols_for_elf_relocatable): Do not add sections containing the string "debug_" to the list of non-debug sections.
Comment 8 Nick Clifton 2023-08-01 13:40:46 UTC
Fixed.
Comment 9 Sourceware Commits 2023-12-20 02:37:55 UTC
The binutils-2_41-branch branch has been updated by Sam James <sjames@sourceware.org>:

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

commit 83d5e7b750556c9c7389a888bf1e3bfc33622b58
Author: Nick Clifton <nickc@redhat.com>
Date:   Tue Aug 1 14:37:04 2023 +0100

    Fix "--only-keep-debug for ELF relocatables" binutils test for compilers which add .debug_macro sections to object files.
    
      PR 30699
      * binutils/testsuite/binutils-all/objcopy.exp (keep_debug_symbols_for_elf_relocatable): Do not add sections containing the string "debug_" to the list of non-debug sections.
    
    (cherry picked from commit b99a9693430a9f04165b1b868f890b622bb1b46c)