Module Name: src Committed By: joerg Date: Thu Dec 16 22:52:32 UTC 2010
Modified Files: src/lib/libc/gen: errlist.awk src/libexec/ld.elf_so: Makefile xprintf.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.3 -r1.4 src/lib/libc/gen/errlist.awk cvs rdiff -u -r1.100 -r1.101 src/libexec/ld.elf_so/Makefile cvs rdiff -u -r1.20 -r1.21 src/libexec/ld.elf_so/xprintf.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libc/gen/errlist.awk diff -u src/lib/libc/gen/errlist.awk:1.3 src/lib/libc/gen/errlist.awk:1.4 --- src/lib/libc/gen/errlist.awk:1.3 Sun Dec 12 22:34:44 2010 +++ src/lib/libc/gen/errlist.awk Thu Dec 16 22:52:32 2010 @@ -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); + } + } } Index: src/libexec/ld.elf_so/Makefile diff -u src/libexec/ld.elf_so/Makefile:1.100 src/libexec/ld.elf_so/Makefile:1.101 --- src/libexec/ld.elf_so/Makefile:1.100 Thu Dec 16 22:47:27 2010 +++ src/libexec/ld.elf_so/Makefile Thu Dec 16 22:52:32 2010 @@ -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 Index: src/libexec/ld.elf_so/xprintf.c diff -u src/libexec/ld.elf_so/xprintf.c:1.20 src/libexec/ld.elf_so/xprintf.c:1.21 --- src/libexec/ld.elf_so/xprintf.c:1.20 Tue May 19 20:44:52 2009 +++ src/libexec/ld.elf_so/xprintf.c Thu Dec 16 22:52:32 2010 @@ -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 <m...@3am-software.com> @@ -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