Bug 2052801 - Backport TYPE=SHT_NOTE patch to binutils and use it for the .note.package section
Summary: Backport TYPE=SHT_NOTE patch to binutils and use it for the .note.package sec...
Keywords:
Status: CLOSED RAWHIDE
Alias: None
Product: Fedora
Classification: Fedora
Component: binutils
Version: rawhide
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: ---
Assignee: Nick Clifton
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2022-02-10 04:47 UTC by Fangrui Song
Modified: 2024-01-19 15:05 UTC (History)
9 users (show)

Fixed In Version: binutils-2.38-2.fc37
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
Environment:
Last Closed: 2024-01-19 15:05:29 UTC
Type: Bug
Embargoed:


Attachments (Terms of Use)

Description Fangrui Song 2022-02-10 04:47:44 UTC
Description of problem:
For https://fedoraproject.org/wiki/Changes/Package_information_on_ELF_objects , https://github.com/systemd/package-notes/blob/main/generate-package-notes.py
uses a linker script like

```
SECTIONS {
    .note.package (READONLY) : ALIGN(4) {
        BYTE(0x04) BYTE(0x00) BYTE(0x00) BYTE(0x00) /* Length of Owner including NUL */
        ...
    }
} INSERT AFTER .note.gnu.build-id;
```

to add a note section to a linked image.
This makes use of a GNU ld behavior that a `.note` section automatically gets the SHT_NOTE type.
Unfortunately this goes against ELF spirits
(gold and ld.lld assign SHT_PROGBITS instead of SHT_NOTE to the output section, and it'd be hard to make ld.lld accept the ".note*" == SHT_NOTE idea)
In ELF, attributes are identified as well known integers. The magic section prefix ".note" is contrary to this.
(See how http://www.linker-aliens.org/blogs/ali/entry/elf_section_compression/ replaced ".zdebug" with a section flag).

One suggestion is to add new syntax for specifying the output section type
(pending patch attached in https://sourceware.org/pipermail/binutils/2022-February/119600.html)

    .note.package (TYPE=SHT_NOTE) : ALIGN(4) {

Since the upstream binutils 2.38 does not support TYPE=, the Fedora package may need to backport this feature.

(Ideally when the output section contains an input section of a different type, ld should report a type mismatch error to prevent misuse, but I do not know how to implement this in ld ...)


About `READONLY`: it appears to be unneeded since GNU ld 2.36
(https://sourceware.org/bugzilla/show_bug.cgi?id=26378#c11) and is recommended
to be removed (https://sourceware.org/pipermail/binutils/2022-February/119627.html).

Version-Release number of selected component (if applicable):
2.38

Comment 1 Fangrui Song 2022-02-17 02:47:58 UTC
There is a related issue: -dT probably should not be used (https://bugzilla.redhat.com/show_bug.cgi?id=2055458).

Comment 2 Nick Clifton 2022-02-17 09:14:48 UTC
Fixed in binutils-2.38-2.fc37


Note You need to log in before you can comment on or make changes to this bug.