https://sourceware.org/bugzilla/show_bug.cgi?id=33232

            Bug ID: 33232
           Summary: strip fails to recognize/check binary architecture
           Product: binutils
           Version: 2.45
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: binutils
          Assignee: unassigned at sourceware dot org
          Reporter: udo at hypervisor dot org
  Target Milestone: ---

Up to and including binutils-2.44, the strip utility, when applied to a binary
of a different architecture, stated

strip: Unable to recognise the format of the input file `foo'

and it did not touch that binary.

Starting with binutils 2.45, that check seems to be gone or broken and a binary
of a different architecture is instead rendered unusable.

readelf -h foo
ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           Advanced Micro Devices X86-64
  Version:                           0x1
  Entry point address:               0x404740
  Start of program headers:          64 (bytes into file)
  Start of section headers:          7121848 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         14
  Size of section headers:           64 (bytes)
  Number of section headers:         39
  Section header string table index: 38

./aarch64-linux-strip foo

readelf -h foo
ELF Header:
  Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - System V
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           None
  Version:                           0x1
  Entry point address:               0x404740
  Start of program headers:          64 (bytes into file)
  Start of section headers:          1339720 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         14
  Size of section headers:           64 (bytes)
  Number of section headers:         29
  Section header string table index: 28

Note that the machine field in the ELF header has been erased and the binary is
now unusable:

-bash: ./foo: cannot execute binary file: Exec format error

This can be reproduced as follows:

../binutils-2.45/configure --prefix=/opt/foo --with-sysroot
--target=aarch64-linux --disable-multilib

which builds binutils on x86_64 (host) for aarch64 (target). When
./aarch64-linux-strip (an x86_64 binary) is applied to itself, it gets broken.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

Reply via email to