Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Replace use of errlist with a single concatenated version an...
details: https://anonhg.NetBSD.org/src/rev/597a4c96d739
branches: trunk
changeset: 759806:597a4c96d739
user: joerg <joerg%NetBSD.org@localhost>
date: Thu Dec 16 22:52:32 2010 +0000
description:
Replace use of errlist with a single concatenated version and an offset
array. This requires less storage and avoids one runtime relocation per
errno value.
diffstat:
lib/libc/gen/errlist.awk | 39 +++++++++++++++++++++++++++++++++------
libexec/ld.elf_so/Makefile | 12 ++++++++++--
libexec/ld.elf_so/xprintf.c | 10 ++++++----
3 files changed, 49 insertions(+), 12 deletions(-)
diffs (139 lines):
diff -r b101e2f73f0e -r 597a4c96d739 lib/libc/gen/errlist.awk
--- a/lib/libc/gen/errlist.awk Thu Dec 16 22:47:27 2010 +0000
+++ b/lib/libc/gen/errlist.awk Thu Dec 16 22:52:32 2010 +0000
@@ -1,5 +1,5 @@
#! /usr/bin/awk -f
-# $NetBSD: errlist.awk,v 1.3 2010/12/12 22:34:44 joerg Exp $
+# $NetBSD: errlist.awk,v 1.4 2010/12/16 22:52:32 joerg Exp $
#
# Copyright (c) 2010 The NetBSD Foundation, Inc.
# All rights reserved.
@@ -37,6 +37,8 @@
#
function tabs(desc) {
l = length(desc) + 3;
+ if (concat)
+ l++
if (l < 16)
return "\t\t\t\t";
else if (l < 24)
@@ -50,14 +52,25 @@
}
function perror(name, number, desc)
{
- printf("\t\"%s\",%s/* %d - %s */\n", desc, tabs(desc), number, name);
+ if (!concat) {
+ printf("\t\"%s\",%s/* %d - %s */\n", desc, tabs(desc), number, name);
+ } else {
+ offsets[number] = offset;
+ offset += length(desc) + 1;
+ printf("\t\"%s\\0\"%s/* %d - %s */\n", desc, tabs(desc), number, name);
+ }
}
BEGIN {
printf("/* Automatically generated file; do not edit */\n");
printf("#include <sys/cdefs.h>\n");
- printf("__RCSID(\"$NetBSD: errlist.awk,v 1.3 2010/12/12 22:34:44 joerg Exp $\");\n");
+ printf("__RCSID(\"$NetBSD: errlist.awk,v 1.4 2010/12/16 22:52:32 joerg Exp $\");\n");
printf("#include <errno.h>\n");
- printf("static const char *const errlist[] = {\n");
+ if (!concat) {
+ printf("static const char *const errlist[] = {\n");
+ } else {
+ printf("static const char concat_errlist[] = {\n");
+ offset = 0;
+ }
perror("ENOERROR", 0, "Undefined error: 0");
errno = 1;
}
@@ -81,6 +94,20 @@
}
END {
printf("};\n\n");
- printf("const int sys_nerr = sizeof(errlist) / sizeof(errlist[0]);\n");
- printf("const char * const *sys_errlist = errlist;\n");
+ if (!concat) {
+ printf("const int sys_nerr = sizeof(errlist) / sizeof(errlist[0]);\n");
+ printf("const char * const *sys_errlist = errlist;\n");
+ } else {
+ printf("static const int concat_nerr = %d;\n", errno);
+ printf("static const unsigned short concat_offset[] = {\n");
+ offsets[errno++] = offset;
+ for (j = 0; j < errno; j++) {
+ printf("\t%d,\n", offsets[j]);
+ }
+ printf("};\n");
+ if (offset > 65535) {
+ printf("Total errlist size doesn't fit into 16bit\n") > "/dev/stderr";
+ exit(1);
+ }
+ }
}
diff -r b101e2f73f0e -r 597a4c96d739 libexec/ld.elf_so/Makefile
--- a/libexec/ld.elf_so/Makefile Thu Dec 16 22:47:27 2010 +0000
+++ b/libexec/ld.elf_so/Makefile Thu Dec 16 22:52:32 2010 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.100 2010/12/16 22:47:27 joerg Exp $
+# $NetBSD: Makefile,v 1.101 2010/12/16 22:52:32 joerg Exp $
#
# NOTE: when changing ld.so, ensure that ldd still compiles.
#
@@ -69,10 +69,18 @@
.PATH.c: ${NETBSDSRCDIR}/lib/libc/stdlib
SRCS+= exit.c
+errlist_concat.h: ${NETBSDSRCDIR}/lib/libc/gen/errlist.awk ${NETBSDSRCDIR}/sys/sys/errno.h
+ ${TOOL_AWK} -v concat=1 -f ${.ALLSRC} > ${.TARGET}.tmp && \
+ mv -f ${.TARGET}.tmp ${.TARGET}
+
+xprintf.c: errlist_concat.h
+
+CLEANFILES+= errlist_concat.h
+
BINDIR= ${SHLINKINSTALLDIR}
CPPFLAGS+= -DLIBDIR=\"${LIBDIR}\" -D_PATH_RTLD=\"${BINDIR}/${PROG}\"
-CPPFLAGS+= -I${.CURDIR}
+CPPFLAGS+= -I${.CURDIR} -I.
CPPFLAGS+= -DRTLD_LOADER
CPPFLAGS+= -D_RTLD_SOURCE
CPPFLAGS+= -DCOMBRELOC
diff -r b101e2f73f0e -r 597a4c96d739 libexec/ld.elf_so/xprintf.c
--- a/libexec/ld.elf_so/xprintf.c Thu Dec 16 22:47:27 2010 +0000
+++ b/libexec/ld.elf_so/xprintf.c Thu Dec 16 22:52:32 2010 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: xprintf.c,v 1.20 2009/05/19 20:44:52 christos Exp $ */
+/* $NetBSD: xprintf.c,v 1.21 2010/12/16 22:52:32 joerg Exp $ */
/*
* Copyright 1996 Matt Thomas <matt%3am-software.com@localhost>
@@ -29,7 +29,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: xprintf.c,v 1.20 2009/05/19 20:44:52 christos Exp $");
+__RCSID("$NetBSD: xprintf.c,v 1.21 2010/12/16 22:52:32 joerg Exp $");
#endif /* not lint */
#include <string.h>
@@ -243,16 +243,18 @@
va_end(ap);
}
+#include "errlist_concat.h"
+
const char *
xstrerror(int error)
{
- if (error >= sys_nerr || error < 0) {
+ if (error >= concat_nerr || error < 0) {
static char buf[128];
xsnprintf(buf, sizeof(buf), "Unknown error: %d", error);
return buf;
}
- return sys_errlist[error];
+ return concat_errlist + concat_offset[error];
}
void
Home |
Main Index |
Thread Index |
Old Index