NetBSD Problem Report #527
From gnats Tue Oct 18 20:01:03 1994
Received: from netbsd4me.jpl.nasa.gov (root@netbsd4me.jpl.nasa.gov [128.149.24.252]) by sun-lamp.cs.berkeley.edu (8.6.9/8.6.9) with ESMTP id UAA04434 for <gnats-bugs@sun-lamp.cs.berkeley.edu>; Tue, 18 Oct 1994 20:01:03 -0700
Message-Id: <199410190301.UAA09276@netbsd4me.jpl.nasa.gov>
Date: Tue, 18 Oct 1994 20:01:32 -0700
From: earle@netbsd4me.jpl.nasa.gov
Reply-To: earle@isolar.Tujunga.CA.US
To: gnats-bugs@sun-lamp.cs.berkeley.edu
Subject: Bug in /usr/src/usr.bin/ar/contents.c on Big-Endian architectures
X-Send-Pr-Version: 3.2
>Number: 527
>Category: bin
>Synopsis: Object modules in archive libraries listed as being of size 0
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: gnats-admin
>State: closed
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Tue Oct 18 20:05:02 +0000 1994
>Closed-Date: Wed Oct 19 06:07:40 +0000 1994
>Last-Modified:
>Originator: Greg Earle
>Release: 1.0_BETA
>Organization:
JPL
>Environment:
System: NetBSD netbsd4me.jpl.nasa.gov 1.0_BETA NetBSD 1.0_BETA (NETBSD4ME) #2: Wed Sep 7 02:56:17 PDT 1994 earle@netbsd4me.jpl.nasa.gov:/usr/src/sys/arch/sparc/compile/NETBSD4ME sparc
>Description:
Running "ar -tv lib[mumble].a" on a Big-Endian architecture machine
yields file sizes for the .o modules that are all "0" length.
This is because the "size" field in the archive library was changed to
be "off_t" sometime back, but the routine that prints out the sizes
of archive members wasn't changed to reflect this. It still uses a
"%8ld" to print the member size, instead of using the "q" quad
qualifier to the "d" in the printf() call. (Aside: the "q" modifier
is not mentioned in the printf(3) man page, either.) I also suggest
that using "%8" in a printf() for an off_t value is also a mistake,
since the off_t implies that the file size could be larger than will
fit in the %8ld format statement.
The bug does not show up on Little-Endian machines because the "%8ld"
argument shows the lower half of the off_t value, given the byte order.
For values less than those which would overspill, the correct size is
still printed on Little-Endian machines.
>How-To-Repeat:
Run "ar -tv /usr/lib/libc.a" on a Big-Endian architecture machine
(such as a SPARC) and watch the fun:
netbsd4me# ar -tv /usr/lib/libc.a | head
rw-r--r-- 0/0 0 Aug 1 12:33 1994 __.SYMDEF
rwxr-xr-x 0/10 0 Jul 29 01:17 1994 truncate.o
rwxr-xr-x 0/10 0 Jul 29 01:17 1994 syscall.o
rwxr-xr-x 0/10 0 Jul 29 01:17 1994 sigreturn.o
rwxr-xr-x 0/10 0 Jul 29 01:17 1994 sigpending.o
rwxr-xr-x 0/10 0 Jul 29 01:17 1994 setlogin.o
rwxr-xr-x 0/10 0 Jul 29 01:17 1994 reboot.o
rwxr-xr-x 0/10 0 Jul 29 01:17 1994 ptrace.o
rwxr-xr-x 0/10 0 Jul 29 01:16 1994 exect.o
rwxr-xr-x 0/10 0 Jul 29 01:16 1994 swab.o
netbsd4me#
With the suggested fix (see below) in place, the results are:
netbsd4me# ./ar -tv /usr/lib/libc.a | head
rw-r--r-- 0/0 18250 Aug 1 12:33 1994 __.SYMDEF
rwxr-xr-x 0/10 209 Jul 29 01:17 1994 truncate.o
rwxr-xr-x 0/10 164 Jul 29 01:17 1994 syscall.o
rwxr-xr-x 0/10 166 Jul 29 01:17 1994 sigreturn.o
rwxr-xr-x 0/10 191 Jul 29 01:17 1994 sigpending.o
rwxr-xr-x 0/10 242 Jul 29 01:17 1994 setlogin.o
rwxr-xr-x 0/10 171 Jul 29 01:17 1994 reboot.o
rwxr-xr-x 0/10 230 Jul 29 01:17 1994 ptrace.o
rwxr-xr-x 0/10 162 Jul 29 01:16 1994 exect.o
rwxr-xr-x 0/10 474 Jul 29 01:16 1994 swab.o
netbsd4me#
>Fix:
Suggest this change to /usr/src/usr.bin/ar/contents.c:
*** contents.c.orig Thu Dec 16 23:04:39 1993
--- contents.c Tue Oct 18 19:52:15 1994
***************
*** 78,80 ****
(void)strmode(chdr.mode, buf);
! (void)printf("%s %6d/%-6d %8ld ",
buf + 1, chdr.uid, chdr.gid, chdr.size);
--- 78,80 ----
(void)strmode(chdr.mode, buf);
! (void)printf("%s %6d/%-6d %16qd ",
buf + 1, chdr.uid, chdr.gid, chdr.size);
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->closed
State-Changed-By: cgd
State-Changed-When: Tue Oct 18 23:07:40 PDT 1994
State-Changed-Why:
fixed in the trunk; will be fixed in -current in a few days.
note that it still prints out with a field width of 8; people who
write .o files bigger than 99M deserve little pity.
>Unformatted:
(Contact us)
$NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026
The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.