HomeFreeBSD

kldxref(8): Sort MDT_MODULE info first in linker.hints output

Description

kldxref(8): Sort MDT_MODULE info first in linker.hints output

MDT_MODULE info is required to be ordered before any other MDT metadata for
a given kld because it serves as an implicit record boundary between
distinct klds for linker.hints consumers. kldxref(8) has previously relied
on the assumption that MDT_MODULE was ordered relative to other module
metadata in kld objects by source code ordering.

However, C does not require implementations to emit file scope objects in
any particular order, and it seems that GCC 6.4.0 and/or binutils 2.32 ld
may reorder emitted objects with respect to source code ordering.

So: just take two passes over a given .ko's module metadata, scanning for
the MDT_MODULE on the first pass and the other metadata on subsequent
passes. It's not super expensive and not exactly a performance-critical
piece of code. This ensures MDT_MODULE is always ordered before
MDT_PNP_INFO and other MDTs, regardless of compiler/linker movement. As a
fringe benefit, it removes the requirement that care be taken to always
order MODULE_PNP_INFO after DRIVER_MODULE in source code.

Reviewed by: emaste, imp
Differential Revision: https://reviews.freebsd.org/D20405

(cherry picked from commit 9c1fa7a429145b298a012cb7b752c82a1e0b1184)

Details

Provenance
cemAuthored on May 27 2019, 5:33 PM
markjCommitted on Jan 23 2021, 4:01 PM
Reviewer
emaste
Differential Revision
D20405: kldxref(8): Sort MDT_MODULE info first in linker.hints output
Parents
rG4493b69d4aa4: Unify Intel CODEC naming.
Branches
Unknown
Tags
Unknown