]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/commit
kldxref(8): Sort MDT_MODULE info first in linker.hints output
authorcem <cem@FreeBSD.org>
Mon, 27 May 2019 17:33:20 +0000 (17:33 +0000)
committercem <cem@FreeBSD.org>
Mon, 27 May 2019 17:33:20 +0000 (17:33 +0000)
commit156c41aa9beda23f95a135611f102f9889f74294
tree8e4662c22d479ee7ff9f96c9cc038340aa5d2112
parentf5100e0445e628b94031d6a64cd976f0162790ac
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
usr.sbin/kldxref/kldxref.c