Skip to content

Linker-Plugin-LTO encodes wrong OS ABI in the ELF header #73606

@stlankes

Description

@stlankes

I am working on the library operating system RustyHermit. If I enable LTO support, I have to use the Linker-Plugin-LTO, because parts of the kernel are provided as static library. Unfortunately, the final result uses in the ELF file a wrong byte to define the OS ABI. In my case, it encodes the byte of the host operating system.

$ readelf -a target/x86_64-unknown-hermit/release/rusty_demo|less

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:               0x30a730
  Start of program headers:          64 (bytes into file)
  Start of section headers:          1791520 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         7
  Size of section headers:           64 (bytes)
  Number of section headers:         12
  Section header string table index: 10

In our case. the binary should encode that the application is able run standalonen. According to the ELF standard 0xff must be coded. If I disable LTO, the file uses the correct value for the OS ABI.

$ readelf -a target/x86_64-unknown-hermit/debug/rusty_demo|less

ELF Header:
  Magic:   7f 45 4c 46 02 01 01 ff 00 00 00 00 00 00 00 00 
  Class:                             ELF64
  Data:                              2's complement, little endian
  Version:                           1 (current)
  OS/ABI:                            <unknown: ff>
  ABI Version:                       0
  Type:                              EXEC (Executable file)
  Machine:                           Advanced Micro Devices X86-64
  Version:                           0x1
  Entry point address:               0x3c3540
  Start of program headers:          64 (bytes into file)
  Start of section headers:          28120976 (bytes into file)
  Flags:                             0x0
  Size of this header:               64 (bytes)
  Size of program headers:           56 (bytes)
  Number of program headers:         7
  Size of section headers:           64 (bytes)
  Number of section headers:         23
  Section header string table index: 21

Besides this issue, the file is correct. If I change the OS ABI with elfedit, the applicationsruns correctly.

Does anyone have an idea what this might be caused to?

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-linkageArea: linking into static, shared libraries and binariesT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions