Page MenuHomeFreeBSD

lib/csu: Ensure that ELF notes are retained with -Wl,--gc-sections
Needs RevisionPublic

Authored by arichardson on Jun 20 2022, 9:36 PM.
Tags
None
Referenced Files
Unknown Object (File)
Sep 13 2025, 12:31 AM
Unknown Object (File)
Sep 11 2025, 12:50 AM
Unknown Object (File)
Aug 30 2025, 9:22 PM
Unknown Object (File)
Aug 7 2025, 9:10 PM
Unknown Object (File)
Jul 26 2025, 8:45 PM
Unknown Object (File)
Jul 26 2025, 8:11 PM
Unknown Object (File)
Jul 26 2025, 3:19 AM
Unknown Object (File)
Jul 12 2025, 1:40 AM
Subscribers

Details

Reviewers
jrtc27
jhb
Summary

This requires a rather recent clang (https://reviews.llvm.org/D95730),
so I'm not sure if we can commit this as-is now.

Test Plan

previously building a binary with -static and -Wl,--gc-sections on
would not have the FreeBSD ABI note, and on some architectures (e.g. aarch64)
this would result in the kernel ELF loader rejecting the file with:
ELF binary type "0" not known.
This patch is based on CheriBSD (first patch submitted from my Morello board), but I will update to drop the non-upstream parts if this is considered the correct approach to work around this problem.

Diff Detail

Repository
rS FreeBSD src repository - subversion
Lint
Lint Passed
Unit
No Test Coverage
Build Status
Buildable 46043
Build 42932: arc lint + arc unit

Event Timeline

jrtc27 requested changes to this revision.Jun 20 2022, 9:38 PM

This was considered but not done as it requires the linker to support SHF_RETAIN. The best option is to move the note to just crti and have a dummy crti for CHERI downstream rather than omit it

This revision now requires changes to proceed.Jun 20 2022, 9:38 PM

This was considered but not done as it requires the linker to support SHF_RETAIN. The best option is to move the note to just crti and have a dummy crti for CHERI downstream rather than omit it

Makes sense, it is I was concerned about. How about downstream though, we don't have the old linker constraint there.

I think binutils allows (or allowed) SHF_GNU_RETAIN only with ELFOSABI_GNU or ELFOSABI_FREEBSD, and if we have that then this change is less important.