HomeFreeBSD

kernel: Fix defining of .init_array and .fini_array sections

Description

kernel: Fix defining of .init_array and .fini_array sections

These input sections can have decimal numbers as the priority suffix.
Clang emits the '%u' form, while SORT is an alias for SORT_BY_NAME,
hence will result in wrong order of constructors / destructors in
output sections. Fix by using the correct sorting command
SORT_BY_INIT_PRIORITY instead [1].

The functions referenced by section .fini_array is in the normal order,
but been executed in the reverse order. The order is same with
.init_array section.

Currently these sections are not used, there should be no functional
change.

Note: As for the .ctors and .dtors sections, both Clang and GCC emit
the priority suffix in the form of '%05u', so there is no semantic
difference between SORT_BY_NAME and SORT_BY_INIT_PRIORITY for those
sections [2].

This fix is extracted from a bigger patch [3] of hselasky, with
additional fix for .fini_array section.

  1. https://sourceware.org/binutils/docs/ld/Input-Section-Wildcards.html
  2. https://reviews.llvm.org/D91187
  3. https://reviews.freebsd.org/D40467

Reviewed by: imp (previous version)
Obtained from: hselasky
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D45194

Details

Provenance
zleiAuthored on Mon, Sep 2, 4:26 AM
Reviewer
imp
Differential Revision
D40467: ld(1): Correctly define .init_array and .fini_array for all platforms.
Parents
rG0578fe492284: pf: rework pf_icmp_state_lookup() failure mode
Branches
Unknown
Tags
Unknown