[Midnightbsd-cvs] src [10729] sync
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sat Jun 9 17:59:22 EDT 2018
Revision: 10729
http://svnweb.midnightbsd.org/src/?rev=10729
Author: laffer1
Date: 2018-06-09 17:59:22 -0400 (Sat, 09 Jun 2018)
Log Message:
-----------
sync
Modified Paths:
--------------
trunk/usr.sbin/kldxref/Makefile
trunk/usr.sbin/kldxref/ef.c
trunk/usr.sbin/kldxref/ef.h
trunk/usr.sbin/kldxref/ef_amd64.c
trunk/usr.sbin/kldxref/ef_i386.c
trunk/usr.sbin/kldxref/ef_nop.c
trunk/usr.sbin/kldxref/ef_obj.c
trunk/usr.sbin/kldxref/ef_sparc64.c
trunk/usr.sbin/kldxref/fileformat
trunk/usr.sbin/kldxref/kldxref.8
trunk/usr.sbin/kldxref/kldxref.c
Added Paths:
-----------
trunk/usr.sbin/kldxref/ef_powerpc.c
Property Changed:
----------------
trunk/usr.sbin/kldxref/fileformat
trunk/usr.sbin/kldxref/kldxref.8
Modified: trunk/usr.sbin/kldxref/Makefile
===================================================================
--- trunk/usr.sbin/kldxref/Makefile 2018-06-09 21:57:54 UTC (rev 10728)
+++ trunk/usr.sbin/kldxref/Makefile 2018-06-09 21:59:22 UTC (rev 10729)
@@ -1,14 +1,14 @@
-# $FreeBSD: src/usr.sbin/kldxref/Makefile,v 1.10 2006/08/04 21:29:39 marcel Exp $
+# $MidnightBSD$
+# $FreeBSD: stable/10/usr.sbin/kldxref/Makefile 211934 2010-08-28 15:03:11Z nwhitehorn $
PROG= kldxref
MAN= kldxref.8
SRCS= kldxref.c ef.c ef_obj.c
+WARNS?= 2
CFLAGS+=-fno-strict-aliasing
-WARNS?= 2
-
-.if exists(ef_${MACHINE_CPUARCH}.c)
+.if exists(ef_${MACHINE_CPUARCH}.c) && ${MACHINE_ARCH} != "powerpc64"
SRCS+= ef_${MACHINE_CPUARCH}.c
.else
SRCS+= ef_nop.c
Modified: trunk/usr.sbin/kldxref/ef.c
===================================================================
--- trunk/usr.sbin/kldxref/ef.c 2018-06-09 21:57:54 UTC (rev 10728)
+++ trunk/usr.sbin/kldxref/ef.c 2018-06-09 21:59:22 UTC (rev 10729)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*
* Copyright (c) 2000, Boris Popov
* All rights reserved.
@@ -29,7 +30,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD: src/usr.sbin/kldxref/ef.c,v 1.9 2005/12/18 04:52:37 marcel Exp $
+ * $FreeBSD: stable/10/usr.sbin/kldxref/ef.c 313848 2017-02-17 00:49:01Z emaste $
*/
#include <sys/param.h>
@@ -42,12 +43,12 @@
#include <fcntl.h>
#include <machine/elf.h>
#define FREEBSD_ELF
-#include <link.h>
#include <err.h>
#include "ef.h"
+#define MAXSEGS 3
struct ef_file {
char* ef_name;
struct elf_file *ef_efile;
@@ -69,7 +70,7 @@
Elf_Off ef_symoff;
Elf_Sym* ef_symtab;
int ef_nsegs;
- Elf_Phdr * ef_segs[2];
+ Elf_Phdr * ef_segs[MAXSEGS];
int ef_verbose;
Elf_Rel * ef_rel; /* relocation table */
int ef_relsz; /* number of entries */
@@ -532,7 +533,7 @@
int error;
int phlen, res;
int nsegs;
- Elf_Phdr *phdr, *phdyn, *phphdr, *phlimit;
+ Elf_Phdr *phdr, *phdyn, *phlimit;
if (filename == NULL)
return EFTYPE;
@@ -576,21 +577,16 @@
phlimit = phdr + hdr->e_phnum;
nsegs = 0;
phdyn = NULL;
- phphdr = NULL;
while (phdr < phlimit) {
if (verbose > 1)
ef_print_phdr(phdr);
switch (phdr->p_type) {
case PT_LOAD:
- if (nsegs == 2) {
- warnx("%s: too many sections",
- filename);
- break;
- }
- ef->ef_segs[nsegs++] = phdr;
+ if (nsegs < MAXSEGS)
+ ef->ef_segs[nsegs] = phdr;
+ nsegs++;
break;
case PT_PHDR:
- phphdr = phdr;
break;
case PT_DYNAMIC:
phdyn = phdr;
@@ -600,11 +596,15 @@
}
if (verbose > 1)
printf("\n");
- ef->ef_nsegs = nsegs;
if (phdyn == NULL) {
- warnx("file isn't dynamically-linked");
+ warnx("Skipping %s: not dynamically-linked",
+ filename);
break;
+ } else if (nsegs > MAXSEGS) {
+ warnx("%s: too many segments", filename);
+ break;
}
+ ef->ef_nsegs = nsegs;
if (ef_read_entry(ef, phdyn->p_offset,
phdyn->p_filesz, (void**)&ef->ef_dyn) != 0) {
printf("ef_read_entry failed\n");
Modified: trunk/usr.sbin/kldxref/ef.h
===================================================================
--- trunk/usr.sbin/kldxref/ef.h 2018-06-09 21:57:54 UTC (rev 10728)
+++ trunk/usr.sbin/kldxref/ef.h 2018-06-09 21:59:22 UTC (rev 10729)
@@ -1,4 +1,5 @@
-/* $FreeBSD: src/usr.sbin/kldxref/ef.h,v 1.6 2005/12/18 04:52:37 marcel Exp $ */
+/* $MidnightBSD$ */
+/* $FreeBSD: stable/10/usr.sbin/kldxref/ef.h 153504 2005-12-18 04:52:37Z marcel $ */
#ifndef _EF_H_
#define _EF_H_
Modified: trunk/usr.sbin/kldxref/ef_amd64.c
===================================================================
--- trunk/usr.sbin/kldxref/ef_amd64.c 2018-06-09 21:57:54 UTC (rev 10728)
+++ trunk/usr.sbin/kldxref/ef_amd64.c 2018-06-09 21:59:22 UTC (rev 10729)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2003 Jake Burkholder.
* Copyright 1996-1998 John D. Polstra.
@@ -24,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD: src/usr.sbin/kldxref/ef_amd64.c,v 1.3 2005/12/18 04:52:37 marcel Exp $
+ * $FreeBSD: stable/10/usr.sbin/kldxref/ef_amd64.c 251439 2013-06-05 21:55:20Z delphij $
*/
#include <sys/types.h>
@@ -32,7 +33,6 @@
#include <err.h>
#include <errno.h>
-#include <string.h>
#include "ef.h"
Modified: trunk/usr.sbin/kldxref/ef_i386.c
===================================================================
--- trunk/usr.sbin/kldxref/ef_i386.c 2018-06-09 21:57:54 UTC (rev 10728)
+++ trunk/usr.sbin/kldxref/ef_i386.c 2018-06-09 21:59:22 UTC (rev 10729)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2003 Jake Burkholder.
* Copyright 1996-1998 John D. Polstra.
@@ -24,7 +25,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD: src/usr.sbin/kldxref/ef_i386.c,v 1.3 2005/12/18 04:52:37 marcel Exp $
+ * $FreeBSD: stable/10/usr.sbin/kldxref/ef_i386.c 251439 2013-06-05 21:55:20Z delphij $
*/
#include <sys/types.h>
@@ -32,7 +33,6 @@
#include <err.h>
#include <errno.h>
-#include <string.h>
#include "ef.h"
@@ -43,12 +43,13 @@
*/
int
ef_reloc(struct elf_file *ef, const void *reldata, int reltype, Elf_Off relbase,
- Elf_Off dataoff, size_t len, void *dest)
+ Elf_Off dataoff, size_t len, void *_dest)
{
Elf_Addr *where, addr, addend;
Elf_Size rtype, symidx;
const Elf_Rel *rel;
const Elf_Rela *rela;
+ char *dest = _dest;
switch (reltype) {
case EF_RELOC_REL:
Modified: trunk/usr.sbin/kldxref/ef_nop.c
===================================================================
--- trunk/usr.sbin/kldxref/ef_nop.c 2018-06-09 21:57:54 UTC (rev 10728)
+++ trunk/usr.sbin/kldxref/ef_nop.c 2018-06-09 21:59:22 UTC (rev 10729)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2003 Jake Burkholder.
* All rights reserved.
@@ -23,7 +24,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD: src/usr.sbin/kldxref/ef_nop.c,v 1.3 2004/08/28 19:31:10 iedowse Exp $
+ * $FreeBSD: stable/10/usr.sbin/kldxref/ef_nop.c 134450 2004-08-28 19:31:10Z iedowse $
*/
#include <sys/types.h>
Modified: trunk/usr.sbin/kldxref/ef_obj.c
===================================================================
--- trunk/usr.sbin/kldxref/ef_obj.c 2018-06-09 21:57:54 UTC (rev 10728)
+++ trunk/usr.sbin/kldxref/ef_obj.c 2018-06-09 21:59:22 UTC (rev 10729)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*
* Copyright (c) 2000, Boris Popov
* Copyright (c) 1998-2000 Doug Rabson
@@ -31,7 +32,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD: src/usr.sbin/kldxref/ef_obj.c,v 1.5 2006/01/12 08:01:38 jasone Exp $
+ * $FreeBSD: stable/10/usr.sbin/kldxref/ef_obj.c 251440 2013-06-05 21:56:29Z delphij $
*/
#include <sys/param.h>
@@ -44,7 +45,6 @@
#include <fcntl.h>
#include <machine/elf.h>
#define FREEBSD_ELF
-#include <link.h>
#include <err.h>
@@ -133,7 +133,7 @@
};
static int
-ef_obj_get_type(elf_file_t ef)
+ef_obj_get_type(elf_file_t __unused ef)
{
return (EFT_KLD);
@@ -180,7 +180,7 @@
{
const Elf_Sym *sym;
- if (symidx >= ef->ddbsymcnt)
+ if (symidx >= (size_t) ef->ddbsymcnt)
return (0);
sym = ef->ddbsymtab + symidx;
@@ -344,7 +344,7 @@
if ((fd = open(filename, O_RDONLY)) == -1)
return errno;
- ef = malloc(sizeof(*ef));
+ ef = calloc(1, sizeof(*ef));
if (ef == NULL) {
close(fd);
return (ENOMEM);
@@ -353,7 +353,6 @@
efile->ef_ef = ef;
efile->ef_ops = &ef_obj_file_ops;
- bzero(ef, sizeof(*ef));
ef->ef_verbose = verbose;
ef->ef_fd = fd;
ef->ef_name = strdup(filename);
Added: trunk/usr.sbin/kldxref/ef_powerpc.c
===================================================================
--- trunk/usr.sbin/kldxref/ef_powerpc.c (rev 0)
+++ trunk/usr.sbin/kldxref/ef_powerpc.c 2018-06-09 21:59:22 UTC (rev 10729)
@@ -0,0 +1,75 @@
+/* $MidnightBSD$ */
+/*-
+ * Copyright (c) 2005 Peter Grehan.
+ * Copyright 1996-1998 John D. Polstra.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * $FreeBSD: stable/10/usr.sbin/kldxref/ef_powerpc.c 153504 2005-12-18 04:52:37Z marcel $
+ */
+
+#include <sys/types.h>
+#include <machine/elf.h>
+
+#include <err.h>
+#include <errno.h>
+#include <string.h>
+
+#include "ef.h"
+
+#include <stdio.h>
+
+/*
+ * Apply relocations to the values obtained from the file. `relbase' is the
+ * target relocation address of the section, and `dataoff/len' is the region
+ * that is to be relocated, and has been copied to *dest
+ */
+int
+ef_reloc(struct elf_file *ef, const void *reldata, int reltype, Elf_Off relbase,
+ Elf_Off dataoff, size_t len, void *dest)
+{
+ Elf_Addr *where, addend;
+ Elf_Size rtype, symidx;
+ const Elf_Rela *rela;
+
+ if (reltype != EF_RELOC_RELA)
+ return (EINVAL);
+
+ rela = (const Elf_Rela *)reldata;
+ where = (Elf_Addr *) ((Elf_Off)dest - dataoff + rela->r_offset);
+ addend = rela->r_addend;
+ rtype = ELF_R_TYPE(rela->r_info);
+ symidx = ELF_R_SYM(rela->r_info);
+
+ if ((char *)where < (char *)dest || (char *)where >= (char *)dest + len)
+ return (0);
+
+ switch(rtype) {
+ case R_PPC_RELATIVE: /* word32 B + A */
+ *where = relbase + addend;
+ break;
+ default:
+ warnx("unhandled relocation type %d", rtype);
+ }
+ return (0);
+}
Property changes on: trunk/usr.sbin/kldxref/ef_powerpc.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Modified: trunk/usr.sbin/kldxref/ef_sparc64.c
===================================================================
--- trunk/usr.sbin/kldxref/ef_sparc64.c 2018-06-09 21:57:54 UTC (rev 10728)
+++ trunk/usr.sbin/kldxref/ef_sparc64.c 2018-06-09 21:59:22 UTC (rev 10729)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*-
* Copyright (c) 2003 Jake Burkholder.
* All rights reserved.
@@ -23,7 +24,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD: src/usr.sbin/kldxref/ef_sparc64.c,v 1.5 2005/12/18 04:52:37 marcel Exp $
+ * $FreeBSD: stable/10/usr.sbin/kldxref/ef_sparc64.c 153504 2005-12-18 04:52:37Z marcel $
*/
#include <sys/types.h>
Modified: trunk/usr.sbin/kldxref/fileformat
===================================================================
--- trunk/usr.sbin/kldxref/fileformat 2018-06-09 21:57:54 UTC (rev 10728)
+++ trunk/usr.sbin/kldxref/fileformat 2018-06-09 21:59:22 UTC (rev 10729)
@@ -1,8 +1,12 @@
-$FreeBSD: src/usr.sbin/kldxref/fileformat,v 1.1 2001/09/11 01:13:15 peter Exp $
- linker.hints file consists from the one or more records. First record of
-file is special and determines its version:
+$FreeBSD: stable/10/usr.sbin/kldxref/fileformat 186824 2009-01-06 14:10:30Z luigi $
+$MidnightBSD$
+linker.hints file consists from the one or more records,
+and is processed by sys/kern/kern_linker.c::linker_hints_lookup()
+
+First record of file is special and determines its version:
+
int version;
All subsequent records have following format:
@@ -16,13 +20,13 @@
'data' determines its type:
struct data {
- int type; /* type of data. currently MTD_* values */
+ int type; /* type of data. currently MDT_* values */
};
The rest of record depends on the type.
struct string {
- int length; /* length of string */
+ uint8_t length; /* length of string */
char val[]; /* string itself (no terminating zero) */
};
@@ -29,12 +33,15 @@
struct data_mdt_version {
int type = MDT_VERSION;
struct string modname;
+ /* padding */
int version;
struct string kldname;
+ /* padding */
};
struct data_mdt_module {
- int type = MDT_VERSION;
+ int type = MDT_MODULE;
struct string modname;
struct string kldname;
+ /* padding */
};
Property changes on: trunk/usr.sbin/kldxref/fileformat
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.sbin/kldxref/kldxref.8
===================================================================
--- trunk/usr.sbin/kldxref/kldxref.8 2018-06-09 21:57:54 UTC (rev 10728)
+++ trunk/usr.sbin/kldxref/kldxref.8 2018-06-09 21:59:22 UTC (rev 10729)
@@ -1,6 +1,7 @@
+.\" $MidnightBSD$
.\"-
.\" Copyright (c) 2001 Boris Popov
-.\" Copyright (c) 2001 Dag-Erling Co\xEFdan Sm\xF8rgrav
+.\" Copyright (c) 2001 Dag-Erling Coïdan Smørgrav
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
@@ -24,7 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" $FreeBSD: src/usr.sbin/kldxref/kldxref.8,v 1.8 2004/06/01 09:34:04 ru Exp $
+.\" $FreeBSD: stable/10/usr.sbin/kldxref/kldxref.8 228976 2011-12-30 00:59:08Z uqs $
.\"
.Dd October 9, 2001
.Dt KLDXREF 8
Property changes on: trunk/usr.sbin/kldxref/kldxref.8
___________________________________________________________________
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Modified: trunk/usr.sbin/kldxref/kldxref.c
===================================================================
--- trunk/usr.sbin/kldxref/kldxref.c 2018-06-09 21:57:54 UTC (rev 10728)
+++ trunk/usr.sbin/kldxref/kldxref.c 2018-06-09 21:59:22 UTC (rev 10729)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
/*
* Copyright (c) 2000, Boris Popov
* All rights reserved.
@@ -29,7 +30,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD: src/usr.sbin/kldxref/kldxref.c,v 1.14 2006/08/05 18:22:11 imp Exp $
+ * $FreeBSD: stable/10/usr.sbin/kldxref/kldxref.c 298494 2016-04-22 21:43:44Z emaste $
*/
#include <sys/types.h>
@@ -42,7 +43,6 @@
#include <sys/stat.h>
#include <sys/module.h>
#define FREEBSD_ELF
-#include <link.h>
#include <err.h>
#include <fts.h>
#include <string.h>
@@ -54,41 +54,23 @@
#include "ef.h"
-#define MAXRECSIZE 1024
+#define MAXRECSIZE 8192
#define check(val) if ((error = (val)) != 0) break
-#ifndef min
-#define min(a,b) (((a)<(b)) ? (a) : (b))
-#endif
+static int dflag; /* do not create a hint file, only write on stdout */
+static int verbose;
-struct mod_info {
- char* mi_name;
- int mi_ver;
- SLIST_ENTRY(mod_info) mi_next;
-};
+static FILE *fxref; /* current hints file */
-#ifdef notnow
-struct kld_info {
- char* k_filename;
- SLIST_HEAD(mod_list_head, mod_info) k_modules;
- SLIST_ENTRY(kld_info) k_next;
-};
-
-SLIST_HEAD(kld_list_head, kld_info) kldlist;
-#endif
-
-static int dflag, verbose;
-
-FILE *fxref;
-
static const char *xref_file = "linker.hints";
+/*
+ * A record is stored in the static buffer recbuf before going to disk.
+ */
static char recbuf[MAXRECSIZE];
-static int recpos, reccnt;
+static int recpos; /* current write position */
+static int reccnt; /* total record written to this file so far */
-FILE *maketempfile(char *, const char *);
-static void usage(void);
-
static void
intalign(void)
{
@@ -105,7 +87,7 @@
static int
record_end(void)
{
- if (dflag || recpos == 0)
+ if (recpos == 0)
return 0;
reccnt++;
intalign();
@@ -123,6 +105,9 @@
return 0;
}
+/*
+ * An int is stored in host order and aligned
+ */
static int
record_int(int val)
{
@@ -130,21 +115,21 @@
return record_buf(&val, sizeof(val));
}
+/*
+ * A string is stored as 1-byte length plus data, no padding
+ */
static int
-record_byte(u_char val)
-{
- return record_buf(&val, sizeof(val));
-}
-
-static int
record_string(const char *str)
{
- int len = strlen(str);
- int error;
-
+ int len, error;
+ u_char val;
+
if (dflag)
return 0;
- error = record_byte(len);
+ val = len = strlen(str);
+ if (len > 255)
+ errx(1, "string %s too long", str);
+ error = record_buf(&val, sizeof(val));
if (error)
return error;
return record_buf(str, len);
@@ -170,22 +155,28 @@
break;
case MDT_VERSION:
check(EF_SEG_READ(ef, data, sizeof(mdv), &mdv));
- record_int(MDT_VERSION);
- record_string(cval);
- record_int(mdv.mv_version);
- record_string(kldname);
- if (!dflag)
- break;
- printf(" interface %s.%d\n", cval, mdv.mv_version);
+ if (dflag) {
+ printf(" interface %s.%d\n", cval, mdv.mv_version);
+ } else {
+ record_int(MDT_VERSION);
+ record_string(cval);
+ record_int(mdv.mv_version);
+ record_string(kldname);
+ }
break;
case MDT_MODULE:
- record_int(MDT_MODULE);
- record_string(cval);
- record_string(kldname);
- if (!dflag)
- break;
- printf(" module %s\n", cval);
+ if (dflag) {
+ printf(" module %s\n", cval);
+ } else {
+ record_int(MDT_MODULE);
+ record_string(cval);
+ record_string(kldname);
+ }
break;
+ case MDT_PNP_INFO:
+ if (dflag) {
+ printf(" pnp info for bus %s\n", cval);
+ }
default:
warnx("unknown metadata record %d in file %s", md->md_type, kldname);
}
@@ -199,8 +190,6 @@
{
struct mod_metadata md;
struct elf_file ef;
-/* struct kld_info *kip;
- struct mod_info *mip;*/
void **p, **orgp;
int error, eftype, nmlen;
long start, finish, entries;
@@ -224,8 +213,9 @@
}
if (!dflag) {
cp = strrchr(kldname, '.');
- nmlen = cp ? min(MAXMODNAME, cp - kldname) :
- min(MAXMODNAME, strlen(kldname));
+ nmlen = (cp != NULL) ? cp - kldname : (int)strlen(kldname);
+ if (nmlen > MAXMODNAME)
+ nmlen = MAXMODNAME;
strlcpy(kldmodname, kldname, nmlen);
/* fprintf(fxref, "%s:%s:%d\n", kldmodname, kldname, 0);*/
}
@@ -252,25 +242,53 @@
return error;
}
-FILE *
+/*
+ * Create a temp file in directory root, make sure we don't
+ * overflow the buffer for the destination name
+ */
+static FILE *
maketempfile(char *dest, const char *root)
{
char *p;
- int fd;
+ int n, fd;
- strlcpy(dest, root, MAXPATHLEN);
+ p = strrchr(root, '/');
+ n = p != NULL ? p - root + 1 : 0;
+ if (snprintf(dest, MAXPATHLEN, "%.*slhint.XXXXXX", n, root) >=
+ MAXPATHLEN) {
+ errno = ENAMETOOLONG;
+ return NULL;
+ }
- if ((p = strrchr(dest, '/')) != 0)
- p++;
- else
- p = dest;
- strcpy(p, "lhint.XXXXXX");
fd = mkstemp(dest);
- return ((fd == -1) ? NULL : fdopen(fd, "w+"));
+ if (fd < 0)
+ return NULL;
+ fchmod(fd, 0644); /* nothing secret in the file */
+ return fdopen(fd, "w+");
}
static char xrefname[MAXPATHLEN], tempname[MAXPATHLEN];
+static void
+usage(void)
+{
+
+ fprintf(stderr, "%s\n",
+ "usage: kldxref [-Rdv] [-f hintsfile] path ..."
+ );
+ exit(1);
+}
+
+static int
+compare(const FTSENT *const *a, const FTSENT *const *b)
+{
+ if ((*a)->fts_info == FTS_D && (*b)->fts_info != FTS_D)
+ return 1;
+ if ((*a)->fts_info != FTS_D && (*b)->fts_info == FTS_D)
+ return -1;
+ return strcmp((*a)->fts_name, (*b)->fts_name);
+}
+
int
main(int argc, char *argv[])
{
@@ -280,20 +298,19 @@
struct stat sb;
fts_options = FTS_PHYSICAL;
-/* SLIST_INIT(&kldlist);*/
while ((opt = getopt(argc, argv, "Rdf:v")) != -1) {
switch (opt) {
- case 'd':
+ case 'd': /* no hint file, only print on stdout */
dflag = 1;
break;
- case 'f':
+ case 'f': /* use this name instead of linker.hints */
xref_file = optarg;
break;
case 'v':
verbose++;
break;
- case 'R':
+ case 'R': /* recurse on directories */
fts_options |= FTS_COMFOLLOW;
break;
default:
@@ -313,18 +330,20 @@
err(1, "%s", argv[0]);
}
- ftsp = fts_open(argv, fts_options, 0);
+ ftsp = fts_open(argv, fts_options, compare);
if (ftsp == NULL)
exit(1);
for (;;) {
p = fts_read(ftsp);
- if ((p == NULL || p->fts_info == FTS_D) && !dflag && fxref) {
+ if ((p == NULL || p->fts_info == FTS_D) && fxref) {
+ /* close and rename the current hint file */
fclose(fxref);
fxref = NULL;
if (reccnt) {
rename(tempname, xrefname);
} else {
+ /* didn't find any entry, ignore this file */
unlink(tempname);
unlink(xrefname);
}
@@ -331,7 +350,8 @@
}
if (p == NULL)
break;
- if (p && p->fts_info == FTS_D && !dflag) {
+ if (p->fts_info == FTS_D && !dflag) {
+ /* visiting a new directory, create a new hint file */
snprintf(xrefname, sizeof(xrefname), "%s/%s",
ftsp->fts_path, xref_file);
fxref = maketempfile(tempname, ftsp->fts_path);
@@ -341,8 +361,12 @@
fwrite(&ival, sizeof(ival), 1, fxref);
reccnt = 0;
}
+ /* skip non-files and separate debug files */
if (p->fts_info != FTS_F)
continue;
+ if (p->fts_namelen >= 6 &&
+ strcmp(p->fts_name + p->fts_namelen - 6, ".debug") == 0)
+ continue;
if (p->fts_namelen >= 8 &&
strcmp(p->fts_name + p->fts_namelen - 8, ".symbols") == 0)
continue;
@@ -351,13 +375,3 @@
fts_close(ftsp);
return 0;
}
-
-static void
-usage(void)
-{
-
- fprintf(stderr, "%s\n",
- "usage: kldxref [-Rdv] [-f hintsfile] path ..."
- );
- exit(1);
-}
More information about the Midnightbsd-cvs
mailing list