Commit Graph

92 Commits

Author SHA1 Message Date
Conrad Meyer
9c1fa7a429 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
2019-05-27 17:33:20 +00:00
John Baldwin
c1bba4445c Parse MIPS relocations to unbreak kldxref on MIPS.
Parse the R_MIPS_32 and R_MIPS_64 relocations.  Both Elf_Rel and
Elf_Rela relocations are handled since O32 MIPS uses Elf_Rel while N64
uses Elf_Rela.  Note that R_MIPS_32 is only handled for 32-bit mips
and R_MIPS_64 for 64-bit.  N32 is untested.

Reviewed by:	imp
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D19870
2019-04-24 23:35:10 +00:00
Leandro Lupori
7e4520854c Fix kldxref on PowerPC64
When using kldxref on kernel modules built with clang8 + lld8,
kldxref would be unable to find the modules metadata information,
because PowerPC64 was using the ef_nop.c implementation of
ef_reloc().

When GNU LD was used, it was also relocating the metadata section of
the .ko file. LLD does not do this, but only generate dynamic
relocations for it. With minor changes, ef_powerpc.c can now work
for PowerPC64 too.

Reviewed by:	emaste
Differential Revision:	https://reviews.freebsd.org/D19370
2019-02-27 13:24:42 +00:00
Ed Maste
b6274d1775 kldxref: use appropriate Elf_Off type for offsets
Submitted by:	Mitchell Horne <mhorne063@gmail.com>
Reviewed by:	kib
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D13957
2018-11-09 15:02:53 +00:00
John Baldwin
1bcac4ba99 Add support for relocations in RISC-V kernel modules to kldxref.
Reviewed by:	br, markj
Approved by:	re (gjb)
Sponsored by:	DARPA
Differential Revision:	https://reviews.freebsd.org/D17415
2018-10-08 19:15:58 +00:00
Warner Losh
517a1827f7 Relax syntax requirements of source string
The original spec for the strings describing the PNP info didn't allow
spaces. Several times now people have broken the install by including
them. Relax the syntax to allow them after the ; which is where
people's muscle memory tends to put them.

Approved by: re@ (gjb)
2018-09-26 19:41:06 +00:00
Warner Losh
ee150a3376 Use EF_SEG_READ_STRING instead of EF_SEG_READ when reading strings.
Normally, we can get away with just reading the 1k buffer for the
string, since the placement of the data is generally no where near the
end of the file. However, it's possible that the string is within the
last 1k of the file, in which case the read will fail, and we'll not
produce the proper records needed for devmatch to work. By reading
using EF_SEG_READ_STRING, we automatically work around these problems
while still retaining safety.

This fix a problem with devmatch where we wouldn't load certain
modules (like ums). This didn't always happen (my tree didn't exhibit
it, while nathan's did because his optimization options were more
agressive).

Reported by: nathanw@
2018-07-15 05:29:39 +00:00
Warner Losh
a35ddacab7 Fixup minor nits in the PNP_INFO protocol.
Sponsored by: Netflix
2018-02-17 06:57:03 +00:00
John Baldwin
66f8917bea Adjust format string to fix build. 2018-01-18 00:24:05 +00:00
John Baldwin
449af04fc9 Tidy some whitespace. 2018-01-18 00:23:11 +00:00
Ed Maste
559d4a5216 kldxref: additional sytle(9) cleanup
Reported by:	kib (via comments in D13957)
Sponsored by:	The FreeBSD Foundation
2018-01-17 20:43:30 +00:00
Ed Maste
e2d0802c6b kldxref: improve style(9)
Address style issues including some previously raised in D13923.

- Use designated initializers for structs
- Always use bracketed return style
- No initialization in declarations
- Align function prototype names
- Remove old commented code/unused includes

Submitted by:	Mitchell Horne <mhorne063@gmail.com>
Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D13943
2018-01-17 19:59:43 +00:00
Ed Maste
da67e6e62c kldxref: handle modules with md_cval at the end of allocated sections
Attempting to retrieve an md_cval string from a kernel module with
kldxref would throw a offset error for modules created using lld, since
this value would be placed at the end of all allocated sections.

Add an ef_read_seg_string method to the ef interface, to allow reading
strings of varying size without attempting to read beyond the segment's
bounds.

PR:		224875
Submitted by:	Mitchell Horne <mhorne063@gmail.com>
Reviewed by:	cem, kib
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D13923
2018-01-16 18:20:12 +00:00
Ed Maste
f68e716ffe kldxref: correct function names in warning messages
Sponsored by:	The FreeBSD Foundation
2018-01-02 21:31:54 +00:00
Pedro F. Giffuni
1de7b4b805 various: general adoption of SPDX licensing ID tags.
Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

No functional change intended.
2017-11-27 15:37:16 +00:00
Pedro F. Giffuni
df57947f08 spdx: initial adoption of licensing ID tags.
The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.

Special thanks to Wind River for providing access to "The Duke of
Highlander" tool: an older (2014) run over FreeBSD tree was useful as a
starting point.

Initially, only tag files that use BSD 4-Clause "Original" license.

RelNotes:	yes
Differential Revision:	https://reviews.freebsd.org/D13133
2017-11-18 14:26:50 +00:00
Bryan Drewery
ea825d0274 DIRDEPS_BUILD: Update dependencies.
Sponsored by:	Dell EMC Isilon
2017-10-31 00:07:04 +00:00
Ed Maste
b6c03f2122 kldxref: bump MAXSEGS to 3
ld.bfd generates two PT_LOAD segments, but certain linkers or linker
configurations generate three PT_LOAD segments (one additional for
RELRO).

PR:		216975
Reported by:	Shawn Webb
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
2017-02-10 19:17:10 +00:00
Ed Maste
d65b2f7ed6 kldxref: s/sections/segments/ in warning message
The message refers to program header segments, not sections.

PR:		216975
2017-02-10 19:11:33 +00:00
Marcelo Araujo
bf6911cd08 Use roundup2() from sys/param.h. 2016-08-23 13:43:43 +00:00
Marcelo Araujo
1dcace5ba0 Use NULL instead of 0 for pointers.
MFC after:	2 weeks.
2016-05-16 01:12:56 +00:00
Andrew Turner
f5e45e53f9 Add support for relocating AArch64 modules to kldxref. This fixes an error
message where it fails to read the module as the unrelocated addresses
are zero.

Sponsored by:	ABT Systems Ltd
2016-01-13 21:34:15 +00:00
Warner Losh
493b2041d6 Augment kldxref to find the new MODULE_PNP_INFO records now in
modules, simplify them into a more normal form and write them to
linker.hints.

Differential Review: https://reviews.freebsd.org/D3461
2015-12-11 05:27:55 +00:00
Ed Maste
113a1a2139 Add debug file extension to kldxref(8) after r288176
After r288176 kernel debug files have the extension .debug.  They also
moved to /usr/lib/debug/boot/kernel by default so in the normal case
kldxref does not encounter them.  A src.conf(5) setting may be used to
continue installing them in /boot/kernel though, so have kldxref skip
.debug files in addition to .symbols files.

Reported by:	fabient
Sponsored by:	The FreeBSD Foundation
2015-10-02 13:16:06 +00:00
Simon J. Gerraty
ccfb965433 Add META_MODE support.
Off by default, build behaves normally.
WITH_META_MODE we get auto objdir creation, the ability to
start build from anywhere in the tree.

Still need to add real targets under targets/ to build packages.

Differential Revision:       D2796
Reviewed by: brooks imp
2015-06-13 19:20:56 +00:00
Simon J. Gerraty
44d314f704 dirdeps.mk now sets DEP_RELDIR 2015-06-08 23:35:17 +00:00
Simon J. Gerraty
98e0ffaefb Merge sync of head 2015-05-27 01:19:58 +00:00
Warner Losh
b03747e983 Reserve and ignore the a new module metadata type MDT_PNP_INFO for
associating an optional PNP hint table with this module. In the
future, when these are added, these changes will silently ignore the
new type they would otherwise warn about. It will always be safe to
ignore this data. Get this into the builds today for some future
proofing.

MFC After: 3 days
2015-01-15 00:46:30 +00:00
Warner Losh
e808299c02 Bump the largest record we can cope with from 1k to 8k. Other users of
the hints file don't have any real limits, and longer records will
need to be written shortly.
2014-12-19 18:45:52 +00:00
Warner Losh
8bc65725c7 Remove -fno-strict-alias, as it is no longer needed. 2014-12-18 16:57:19 +00:00
Simon J. Gerraty
ee7b0571c2 Merge head from 7/28 2014-08-19 06:50:54 +00:00
Baptiste Daroussin
01c2b8ac0d use .Mt to mark up email addresses consistently (part2)
PR:		191174
Submitted by:	Franco Fichtner  <franco@lastsummer.de>
2014-06-20 09:57:27 +00:00
Simon J. Gerraty
fae50821ae Updated dependencies 2014-05-16 14:09:51 +00:00
Simon J. Gerraty
76b28ad6ab Updated dependencies 2014-05-10 05:16:28 +00:00
Simon J. Gerraty
cc3f4b9965 Merge from head 2014-05-08 23:54:15 +00:00
Ed Maste
2bd7b9e5cc kldxref: Clean up error reporting
Omit "too many sections" warnings if the ELF file is not dynamically
linked (and is therefore skipped anyway), and otherwise output it only
once.  An errant core file would previously cause kldxref to output a
number of warnings.

Also introduce a MAXSEGS #define and replace literal 2 with it, to make
comparisons clear.

Reviewed by:	kib
Sponsored by:	The FreeBSD Foundation
2014-04-30 18:11:53 +00:00
Simon J. Gerraty
3b8f084595 Merge head 2014-04-28 07:50:45 +00:00
Jilles Tjoelker
5d452cea64 kldxref: Add static keyword to the new function only used in the same file.
The WARNS level is not such that the omission broke the build.

Reported by:	mdf
2013-10-16 20:04:06 +00:00
Simon J. Gerraty
3caf0790a8 Merge head@256284 2013-10-13 02:35:19 +00:00
Jilles Tjoelker
6d9cb20bd7 kldxref: Do not depend on the directory order.
Sort the filenames to get a consistent result between machines of the same
architecture.

Also, sort FTS_D entries after other entries so kldxref -R works properly in
the uncommon case that a directory contains both subdirectories and modules.
Previously, this may have happened to work, depending on the order of files
in the directory.

PR:		bin/182098
Submitted by:	Derek Schrock (original version)
Tested by:	Derek Schrock
Approved by:	re (delphij)
MFC after:	1 week
2013-10-04 21:25:55 +00:00
Simon J. Gerraty
d1d0158641 Merge from head 2013-09-05 20:18:59 +00:00
Xin LI
c84739b210 Use calloc().
MFC after:	2 weeks
2013-06-05 21:56:29 +00:00
Xin LI
ac8e13960d Remove unneeded reference to link.h (sys/link_elf.h).
MFC after:	2 weeks
2013-06-05 21:55:20 +00:00
Simon J. Gerraty
7cf3a1c6b2 Updated dependencies 2013-03-11 17:21:52 +00:00
Simon J. Gerraty
f5f7c05209 Updated dependencies 2013-02-16 01:23:54 +00:00
Simon J. Gerraty
23090366f7 Sync from head 2012-11-04 02:52:03 +00:00
Tim Kientzle
5db4d6779f Clarify a warning message. 2012-10-29 03:31:22 +00:00
Marcel Moolenaar
7750ad47a9 Sync FreeBSD's bmake branch with Juniper's internal bmake branch.
Requested by: Simon Gerraty <sjg@juniper.net>
2012-08-22 19:25:57 +00:00
Eitan Adler
7e22d9ed96 Remove variables which are initialized but never used thereafter reported by gcc46 warning
Approved by:	cperciva
MFC After:	3 days
2012-06-19 06:10:34 +00:00
Ulrich Spörlein
f76b319989 Reencode files to UTF-8. Drop CP1252 em-dash. 2011-12-30 00:59:08 +00:00