From owner-svn-src-head@FreeBSD.ORG Tue Sep 6 10:21:34 2011 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 226ED106564A; Tue, 6 Sep 2011 10:21:34 +0000 (UTC) (envelope-from kib@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 07AE78FC14; Tue, 6 Sep 2011 10:21:34 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id p86ALXnQ078725; Tue, 6 Sep 2011 10:21:33 GMT (envelope-from kib@svn.freebsd.org) Received: (from kib@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id p86ALXBF078723; Tue, 6 Sep 2011 10:21:33 GMT (envelope-from kib@svn.freebsd.org) Message-Id: <201109061021.p86ALXBF078723@svn.freebsd.org> From: Konstantin Belousov Date: Tue, 6 Sep 2011 10:21:33 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r225417 - head/libexec/rtld-elf X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 06 Sep 2011 10:21:34 -0000 Author: kib Date: Tue Sep 6 10:21:33 2011 New Revision: 225417 URL: http://svn.freebsd.org/changeset/base/225417 Log: Do not use the function pointers for the internal operation of rtld_printf() functions. The _rtld_error() function might be called early during the rtld bootstrap, in which case function pointers are not yet functional on ia64 due to required relocations not yet performed. Reported, reviewed and tested by: marcel Approved by: re (bz) Modified: head/libexec/rtld-elf/rtld_printf.c Modified: head/libexec/rtld-elf/rtld_printf.c ============================================================================== --- head/libexec/rtld-elf/rtld_printf.c Tue Sep 6 10:19:01 2011 (r225416) +++ head/libexec/rtld-elf/rtld_printf.c Tue Sep 6 10:21:33 2011 (r225417) @@ -46,7 +46,11 @@ #define MAXNBUF (sizeof(intmax_t) * NBBY + 1) +#define PRINT_METHOD_SNPRINTF 1 +#define PRINT_METHOD_WRITE 2 + struct snprintf_arg { + int method; char *str; char *buf; size_t remain; @@ -55,16 +59,6 @@ struct snprintf_arg { }; static void -snprintf_func(int ch, struct snprintf_arg *const info) -{ - - if (info->remain >= 2) { - *info->str++ = ch; - info->remain--; - } -} - -static void printf_out(struct snprintf_arg *info) { @@ -76,14 +70,24 @@ printf_out(struct snprintf_arg *info) } static void -printf_func(int ch, struct snprintf_arg *const info) +snprintf_func(int ch, struct snprintf_arg *const info) { - if (info->remain > 0) { - *info->str++ = ch; - info->remain--; - } else - printf_out(info); + switch (info->method) { + case PRINT_METHOD_SNPRINTF: + if (info->remain >= 2) { + *info->str++ = ch; + info->remain--; + } + break; + case PRINT_METHOD_WRITE: + if (info->remain > 0) { + *info->str++ = ch; + info->remain--; + } else + printf_out(info); + break; + } } static char const hex2ascii_data[] = "0123456789abcdefghijklmnopqrstuvwxyz"; @@ -113,10 +117,9 @@ ksprintn(char *nbuf, uintmax_t num, int } static int -kvprintf(char const *fmt, void (*func)(int c, struct snprintf_arg *const arg), - struct snprintf_arg *arg, int radix, va_list ap) +kvprintf(char const *fmt, struct snprintf_arg *arg, int radix, va_list ap) { -#define PCHAR(c) func((c), arg) +#define PCHAR(c) snprintf_func((c), arg) char nbuf[MAXNBUF]; const char *p, *percent, *q; u_char *up; @@ -429,10 +432,11 @@ rtld_vsnprintf(char *buf, size_t bufsize struct snprintf_arg info; int retval; + info.method = PRINT_METHOD_SNPRINTF; info.buf = info.str = buf; info.buf_total = info.remain = bufsize; info.fd = -1; - retval = kvprintf(fmt, snprintf_func, &info, 10, ap); + retval = kvprintf(fmt, &info, 10, ap); if (info.remain >= 1) *info.str++ = '\0'; return (retval); @@ -445,10 +449,11 @@ rtld_vfdprintf(int fd, const char *fmt, struct snprintf_arg info; int retval; + info.method = PRINT_METHOD_WRITE; info.buf = info.str = buf; info.buf_total = info.remain = sizeof(buf); info.fd = fd; - retval = kvprintf(fmt, printf_func, &info, 10, ap); + retval = kvprintf(fmt, &info, 10, ap); printf_out(&info); return (retval); }