Bug 27091 - executable is incorrectly marked as ELFOSABI_GNU
Summary: executable is incorrectly marked as ELFOSABI_GNU
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: ld (show other bugs)
Version: 2.36
: P2 normal
Target Milestone: 2.36
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-12-17 14:09 UTC by H.J. Lu
Modified: 2020-12-18 12:42 UTC (History)
0 users

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 H.J. Lu 2020-12-17 14:09:48 UTC
[hjl@gnu-cfl-2 retain-2]$ cat x.s
	.type _start,"function"
	.section .text,"axR",%progbits
	.global _start
_start:
	.nop
[hjl@gnu-cfl-2 retain-2]$ make
./as   -o x.o x.s
./ld  -e _start -o x x.o
readelf -h x
ELF Header:
  Magic:   7f 45 4c 46 02 01 01 03 00 00 00 00 00 00 00 00 
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            UNIX - GNU
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           Advanced Micro Devices X86-64
  Version:                           0x1
  Entry point address:               0x401000
  Start of program headers:          64 (bytes into file)
  Start of section headers:          4352 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         4
  Size of section headers:           64 (bytes)
  Number of section headers:         6
  Section header string table index: 5
[hjl@gnu-cfl-2 retain-2]$ 

Since SHF_GNU_RETAIN has no impact on shared object and executable,
they shouldn't be marked with ELFOSABI_GNU.
Comment 1 Andreas Schwab 2020-12-17 14:41:11 UTC
SHF_GNU_RETAIN is in the OS-specific range, the marking is required to properly recognize it.
Comment 2 H.J. Lu 2020-12-17 14:43:17 UTC
(In reply to Andreas Schwab from comment #1)
> SHF_GNU_RETAIN is in the OS-specific range, the marking is required to
> properly recognize it.

SHF_GNU_RETAIN does nothing on shared object and executable.  Linker
doesn't even mark it on shared object and executable.
Comment 3 Andreas Schwab 2020-12-17 15:06:51 UTC
That is irrelevant.  Without the marking the bit has no defined meaning.
Comment 4 Sourceware Commits 2020-12-18 12:28:17 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=04f8967487515179cc6dfc7c828f77eeb75c08d3

commit 04f8967487515179cc6dfc7c828f77eeb75c08d3
Author: H.J. Lu <hjl.tools@gmail.com>
Date:   Fri Dec 18 04:24:26 2020 -0800

    elf: Copy elf_gnu_osabi_retain only for relocatable link
    
    Copy elf_gnu_osabi_retain from input only for relocatable link since
    SHF_GNU_RETAIN has no impact on non-relocatable outputs.
    
    bfd/
    
            PR ld/27091
            * elflink.c (elf_link_input_bfd): Copy elf_gnu_osabi_retain
            from input only for relocatable link.
    
    ld/
    
            PR ld/27091
            * testsuite/ld-elf/retain7.s: New file.
            * testsuite/ld-elf/retain7a.d: Likewise.
            * testsuite/ld-elf/retain7b.d: Likewise.
Comment 5 H.J. Lu 2020-12-18 12:42:00 UTC
Fixed.