Project

General

Profile

Actions

Bug #14659

closed

strip can lose its identity

Added by Andy Fiddaman 4 months ago. Updated 3 months ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
cmd - userland programs
Start date:
Due date:
% Done:

100%

Estimated time:
Difficulty:
Medium
Tags:
Gerrit CR:

Description

When attempting to remove debugging information from a particular rust binary using strip -x, an error is generated. GNU strip does not have any problem.

strip: diffr.orig: Warning: Cannot delete section (.debug_gdb_scripts)
                from a segment.
diffr.orig: WARNING: strip: Cannot manipulate file.

There's nothing particularly odd about the binary's sections except that there are rather a lot of them

% elfdump -cC diffr.orig | grep 'Section Header'
Section Header[1]:  sh_name: .interp
Section Header[2]:  sh_name: .eh_frame_hdr
Section Header[3]:  sh_name: .eh_frame
Section Header[4]:  sh_name: .hash
Section Header[5]:  sh_name: .SUNW_ldynsym
Section Header[6]:  sh_name: .dynsym
Section Header[7]:  sh_name: .dynstr
Section Header[8]:  sh_name: .SUNW_version
Section Header[9]:  sh_name: .SUNW_versym
Section Header[10]:  sh_name: .SUNW_dynsymsort
Section Header[11]:  sh_name: .SUNW_reloc
Section Header[12]:  sh_name: .rela.plt
Section Header[13]:  sh_name: .plt
Section Header[14]:  sh_name: .text
Section Header[15]:  sh_name: .init
Section Header[16]:  sh_name: .fini
Section Header[17]:  sh_name: .rodata
Section Header[18]:  sh_name: .gcc_except_table._ZN4core3ptr46drop_in_place$LT$termcolor..StandardStream$GT$17h9537d9ac9f0e5a1fE
Section Header[19]:  sh_name: .gcc_except_table._ZN4core3ptr56drop_in_place$LT$clap..args..arg_matches..ArgMatches$GT$17h2aae54c23a905e96E
Section Header[20]:  sh_name: .gcc_except_table._ZN4core3ptr80drop_in_place$LT$alloc..boxed..Box$LT$clap..args..subcommand..SubCommand$GT$$GT$17h231c0d96eb920020E
Section Header[21]:  sh_name: .gcc_except_table._ZN4core3ptr81drop_in_place$LT$core..result..Result$LT$$LP$$RP$$C$std..io..error..Error$GT$$GT$17h9e60d6f70efa73b9E
Section Header[22]:  sh_name: .gcc_except_table._ZN5diffr4main17h40bf08de95b73112E
Section Header[23]:  sh_name: .gcc_except_table._ZN5diffr9ExecStats11report_into28_$u7b$$u7b$closure$u7d$$u7d$17h88e42c3119309c15E
Section Header[24]:  sh_name: .gcc_except_table._ZN5diffr10HunkBuffer18process_with_stats17h681823125bcc705dE
Section Header[25]:  sh_name: .debug_gdb_scripts
Section Header[26]:  sh_name: .gcc_except_table._ZN4core3ptr42drop_in_place$LT$std..io..error..Error$GT$17he7b17f3c1f1371d0E.llvm.13730893840837908257
...
Section Header[784]:  sh_name: .gcc_except_table._ZN4core9panicking15panic_no_unwind17h2b2afbf7d5714b40E
Section Header[785]:  sh_name: .got
Section Header[786]:  sh_name: .dynamic
Section Header[787]:  sh_name: .fini_array
Section Header[788]:  sh_name: .init_array
Section Header[789]:  sh_name: .data
Section Header[790]:  sh_name: .tm_clone_table
Section Header[791]:  sh_name: .data.rel.ro
Section Header[792]:  sh_name: .bss
Section Header[793]:  sh_name: .symtab
Section Header[794]:  sh_name: .strtab
Section Header[795]:  sh_name: .comment
Section Header[796]:  sh_name: .debug_loc
Section Header[797]:  sh_name: .debug_abbrev
Section Header[798]:  sh_name: .debug_info
Section Header[799]:  sh_name: .debug_aranges
Section Header[800]:  sh_name: .debug_ranges
Section Header[801]:  sh_name: .debug_str
Section Header[802]:  sh_name: .debug_pubnames
Section Header[803]:  sh_name: .debug_pubtypes
Section Header[804]:  sh_name: .note.GNU-stack
Section Header[805]:  sh_name: .debug_line
Section Header[806]:  sh_name: .shstrtab

From inspecting the code around where this error is produced, it should never happen if the command being invoked is strip, which is a bit odd.

Looking further, it seems that it is checking whether the command is strip by inspecting a bit in the section header instead of the command information.

Actions #1

Updated by Electric Monk 4 months ago

  • Gerrit CR set to 2128
Actions #2

Updated by Andy Fiddaman 4 months ago

  • Description updated (diff)
  • Gerrit CR deleted (2128)
Actions #3

Updated by Andy Fiddaman 4 months ago

  • Gerrit CR set to 2128
Actions #4

Updated by Andy Fiddaman 4 months ago

  • Subject changed from strip fails on rust binary to strip can lose its identity
Actions #5

Updated by Andy Fiddaman 3 months ago

I tested this by replacing the strip binary on a system and then running a full omnios build, core and extra, which exercised it, and also by explicitly testing that it was now possible to strip a binary that it couldn't before.

For some sample files in the build, I compared the ELF section headers in the resulting binary with the old to check that it was still removing the same things.

Actions #6

Updated by Rich Lowe 3 months ago

You should also check that it doesn't actually remove that section that's part of a segment, and that mcs is still ok.
(I think I actually checked this when I reviewed it, but I didn't save the details).

Actions #7

Updated by Andy Fiddaman 3 months ago

I've confirmed that the .debug_gdb_scripts section is still there after the new strip has done its thing:

% /tmp/new/strip diffr
% echo $?
0
% elfdump -c -N .debug_gdb_scripts diffr

Section Header[25]:  sh_name: .debug_gdb_scripts
    sh_addr:      0x67b714            sh_flags:   [ SHF_ALLOC SHF_MERGE SHF_STRINGS ]
    sh_size:      0x23                sh_type:    [ SHT_PROGBITS ]
    sh_offset:    0x27b714            sh_entsize: 0x1 (35 entries)
    sh_link:      0                   sh_info:    0
    sh_addralign: 0x1

and a wsdiff on the original and stripped binary shows that the expected sections have been removed:

ELF sections found in /tmp/old/diffr but not in /tmp/new/diffr

.debug_abbrev   .debug_aranges  .debug_info     .debug_line     .debug_loc
.debug_pubnames .debug_pubtypes .debug_ranges   .debug_str      .strtab .symtab

and that mcs still seems okay with a few manual invocations and a full gate build with this patch, which will exercise it a lot more, and the comment sections seem fine:

% mcs -p $ROOT/usr/bin/strip
strip:

@(#)illumos gate-ig_14659_striprust-e08d9f2a10 May 2022
Actions #8

Updated by Andy Fiddaman 3 months ago

A wsdiff of a full gate build with this patch is clean, modulo the expected changes due to a change in git commit hash, and the mcs and strip binaries:

% wsdiff -uvVr out proto/root_i386-nd proto.new/root_i386-nd
usr/bin/amd64/strip
usr/bin/amd64/mcs
usr/bin/strip
usr/bin/mcs
usr/sbin/iasl
usr/sbin/acpixtract
usr/sbin/acpidump
etc/versions/build
etc/motd
platform/i86xpv/kernel/amd64/unix
platform/i86pc/kernel/amd64/unix
Actions #9

Updated by Electric Monk 3 months ago

  • Status changed from In Progress to Closed
  • % Done changed from 0 to 100

git commit 56b75c05d0c84c701fbb1eb2a572b0ecee66f012

commit  56b75c05d0c84c701fbb1eb2a572b0ecee66f012
Author: Andy Fiddaman <omnios@citrus-it.co.uk>
Date:   2022-05-16T12:16:38.000Z

    14659 strip can lose its identity
    Reviewed by: Rich Lowe <richlowe@richlowe.net>
    Reviewed by: Michael Zeller <mike@mikezeller.net>
    Reviewed by: Toomas Soome <tsoome@me.com>
    Approved by: Robert Mustacchi <rm@fingolfin.org>

Actions

Also available in: Atom PDF