Bug 521 - GNU ar on Solaris creates invalid archives in some cases
Summary: GNU ar on Solaris creates invalid archives in some cases
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: binutils (show other bugs)
Version: 2.15
: P2 normal
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-11-06 15:45 UTC by Bruno Haible
Modified: 2009-10-14 02:55 UTC (History)
2 users (show)

See Also:
Host: sparc-sun-solaris2.7
Target: sparc-sun-solaris2.7
Build: sparc-sun-solaris2.7
Last reconfirmed:


Attachments
Output of "gcc -c hello.c" (343 bytes, application/octet-stream)
2004-11-06 15:54 UTC, Bruno Haible
Details
Output of "gcc -c dummy.c" (216 bytes, application/octet-stream)
2004-11-06 15:55 UTC, Bruno Haible
Details
Result of "gnu-ar cru empty.a dummy.o" (283 bytes, application/octet-stream)
2004-11-06 15:56 UTC, Bruno Haible
Details
Result of "/usr/ccs/bin/ar cru empty.a dummy.o" (283 bytes, application/octet-stream)
2004-11-06 15:56 UTC, Bruno Haible
Details
Output of "gcc -c dummy.c" where dummy.c defines a global variable (226 bytes, application/octet-stream)
2004-11-06 15:57 UTC, Bruno Haible
Details
Result of "gnu-ar cru empty.a dummy.o" where dummy.o contains a global variable definition (298 bytes, application/octet-stream)
2004-11-06 15:58 UTC, Bruno Haible
Details
ar (2.19.51.0.2.20090204) / gcc error when bootstrapping gcc-4.3.3 on i386-pc-solaris2.10 (68.00 KB, application/octet-stream)
2009-03-09 11:24 UTC, Niki W. Waibel
Details
produced when bootstrapping gcc-4.3.3 on i386-pc-solaris2.10 ising binutils-2.19.51.0.2.20090204 (2.46 KB, application/octet-stream)
2009-03-09 11:34 UTC, Niki W. Waibel
Details
output of binutils-2.19.50.0.1.20081007 / gcc-4.3.3 bootstrap on i386-pc-solaris2.10 (okay) (109.11 KB, application/octet-stream)
2009-03-09 13:29 UTC, Niki W. Waibel
Details
produced when bootstrapping gcc-4.3.3 on i386-pc-solaris2.10 using binutils-2.19.50.0.1.20081007 (2.53 KB, application/octet-stream)
2009-03-09 13:32 UTC, Niki W. Waibel
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Bruno Haible 2004-11-06 15:45:15 UTC
This is hurting the gnulib project: GNU ar version 2.15, used on Solaris 7 or 
Solaris 9, creates invalid .a files if there are no exported symbols. 
 
Test case: 
 
$ cat > hello.c 
#include <stdio.h> 
int main () { printf("Hello World\n"); return 0; } 
$ gcc -c hello.c 
 
$ gnu-ar --version 
GNU ar 2.15 
Copyright 2004 Free Software Foundation, Inc. 
This program is free software; you may redistribute it under the terms of 
the GNU General Public License.  This program has absolutely no warranty. 
 
$ cat > dummy.c 
typedef int dummy; 
$ gcc -c dummy.c 
$ /bin/rm -f empty.a 
$ gnu-ar cru empty.a dummy.o 
$ /usr/ccs/bin/ld hello.o empty.a -lc -o a.out 
ld: fatal: file empty.a: unknown type, unable to process using elf(3E) libraries 
ld: fatal: File processing errors. No output written to a.out 
$ echo $? 
1 
 
Test case that shows that there is no problem if the system's 'ar' is used: 
 
$ cat > dummy.c 
typedef int dummy; 
$ gcc -c dummy.c 
$ /bin/rm -f empty.a 
$ /usr/ccs/bin/ar cru empty.a dummy.o 
$ /usr/ccs/bin/ld hello.o empty.a -lc -o a.out 
$ echo $? 
0 
 
Test case that shows that there is no problem if there are exported symbols: 
 
$ cat > dummy.c 
int dummy; 
$ gcc -c dummy.c 
$ /bin/rm -f empty.a 
$ gnu-ar cru empty.a dummy.o 
$ /usr/ccs/bin/ld hello.o empty.a -lc -o a.out 
$ echo $? 
0
Comment 1 Bruno Haible 2004-11-06 15:54:27 UTC
Created attachment 259 [details]
Output of "gcc -c hello.c"
Comment 2 Bruno Haible 2004-11-06 15:55:12 UTC
Created attachment 260 [details]
Output of "gcc -c dummy.c"
Comment 3 Bruno Haible 2004-11-06 15:56:00 UTC
Created attachment 261 [details]
Result of "gnu-ar cru empty.a dummy.o"
Comment 4 Bruno Haible 2004-11-06 15:56:49 UTC
Created attachment 262 [details]
Result of "/usr/ccs/bin/ar cru empty.a dummy.o"
Comment 5 Bruno Haible 2004-11-06 15:57:38 UTC
Created attachment 263 [details]
Output of "gcc -c dummy.c" where dummy.c defines a global variable
Comment 6 Bruno Haible 2004-11-06 15:58:19 UTC
Created attachment 264 [details]
Result of "gnu-ar cru empty.a dummy.o" where dummy.o contains a global variable definition
Comment 7 Niki W. Waibel 2009-01-27 15:46:14 UTC
sort of same thing happens on sparc-sun-solaris2.10/binutils-2.19.51.0.1

it is impossible to compile libX11-1.1.92.2 and gcc-4.3.3 using
binutils-2.19.51.0.1. both tools compile fine when using binutils-2.19.50.0.1!

relevant lines when compiling gcc-4.3.3 using binutils-2.19.51.0.1:
===
libtool: link: ar rc .libs/libmath.a  stubs.o signbit.o signbitf.o signbitl.o
libtool: link: ranlib .libs/libmath.a
libtool: link: (cd .libs/libstdc++.lax/libmath.a && ar x
/tmp/gcc-4.3.3-comp/gcc-4.3.3/sparc-sun-solaris2.10/sparcv9/libstdc++-v3/src/../libmath/.libs/libmath.a)
ar:
/tmp/gcc-4.3.3-comp/gcc-4.3.3/sparc-sun-solaris2.10/sparcv9/libstdc++-v3/src/../libmath/.libs/libmath.a
is not a valid archive
===
Comment 8 Nick Clifton 2009-02-18 11:14:49 UTC
Hi Niki,

  Please could you provide a small testcase to reproduce the problem you are
having.  I tried using the sequence of instructions originally described by
Bruno, but they worked.  I also tried a few variations of my own but I could not
create a corrupt archive.

Cheers
  Nick
Comment 9 Niki W. Waibel 2009-03-09 11:24:37 UTC
Created attachment 3801 [details]
ar (2.19.51.0.2.20090204) / gcc error when bootstrapping gcc-4.3.3 on i386-pc-solaris2.10
Comment 10 Niki W. Waibel 2009-03-09 11:29:50 UTC
now i get the same/similar? issue with binutils-2.19.51.0.2.20090204 on
i386-pc-solaris2.10. attached out2.bz2 which includes all output.

i will switch to binutils-2.19.50.0.1, and i bet gcc will bootstrap okay.

nick, i am not an ar/binutils specialist, just a user. maybe you can see in the
output what may be the issue and tell me what i could test.

i will attach
/tmp/gcc-4.3.3-comp/gcc-4.3.3/i386-pc-solaris2.10/libstdc++-v3/src/../libmath/.libs/libmath.a
as well. maybe you can see within that file what's wrong.
Comment 11 Niki W. Waibel 2009-03-09 11:34:36 UTC
Created attachment 3802 [details]
produced when bootstrapping gcc-4.3.3 on i386-pc-solaris2.10 ising binutils-2.19.51.0.2.20090204

last lines are:
===
/bin/bash ../libtool --tag CXX --mode=link
/tmp/gcc-4.3.3-comp/gcc-4.3.3/./gcc/xgcc -shared-libgcc
-B/tmp/gcc-4.3.3-comp/gcc-4.3.3/./gcc -nostdinc++
-L/tmp/gcc-4.3.3-comp/gcc-4.3.3/i386-pc-solaris2.10/libstdc++-v3/src
-L/tmp/gcc-4.3.3-comp/gcc-4.3.3/i386-pc-solaris2.10/libstdc++-v3/src/.libs
-B/misc/i386-pc-solaris2.10/opt/gcc/4.3.3/i386-pc-solaris2.10/bin/
-B/misc/i386-pc-solaris2.10/opt/gcc/4.3.3/i386-pc-solaris2.10/lib/ -isystem
/misc/i386-pc-solaris2.10/opt/gcc/4.3.3/i386-pc-solaris2.10/include -isystem
/misc/i386-pc-solaris2.10/opt/gcc/4.3.3/i386-pc-solaris2.10/sys-include -Wl,-O1
-Wl,-z,relro -Wl,--gc-sections	-fno-implicit-templates -Wall -Wextra
-Wwrite-strings -Wcast-qual  -fdiagnostics-show-location=once 
-ffunction-sections -fdata-sections   -o libstdc++.la -rpath
/misc/i386-pc-solaris2.10/opt/gcc/4.3.3/lib/gcc/i386-pc-solaris2.10/4.3.3
-version-info 6:10:0  -lm  bitmap_allocator.lo pool_allocator.lo
mt_allocator.lo codecvt.lo compatibility.lo complex_io.lo ctype.lo debug.lo
functexcept.lo hash.lo hash_c++0x.lo globals_io.lo hashtable.lo
hashtable_c++0x.lo ios.lo ios_failure.lo ios_init.lo ios_locale.lo limits.lo
list.lo debug_list.lo locale.lo locale_init.lo locale_facets.lo localename.lo
stdexcept.lo strstream.lo tree.lo allocator-inst.lo concept-inst.lo
fstream-inst.lo ext-inst.lo ios-inst.lo iostream-inst.lo istream-inst.lo
istream.lo locale-inst.lo misc-inst.lo ostream-inst.lo sstream-inst.lo
streambuf-inst.lo streambuf.lo string-inst.lo valarray-inst.lo wlocale-inst.lo
wstring-inst.lo atomicity.lo codecvt_members.lo collate_members.lo
ctype_members.lo messages_members.lo monetary_members.lo numeric_members.lo
time_members.lo basic_file.lo c++locale.lo  parallel_list.lo
parallel_settings.lo ../libmath/libmath.la ../libsupc++/libsupc++convenience.la
-lm 
libtool: link: (cd .libs/libstdc++.lax/libmath.a && ar x
/tmp/gcc-4.3.3-comp/gcc-4.3.3/i386-pc-solaris2.10/libstdc++-v3/src/../libmath/.libs/libmath.a)

ar:
/tmp/gcc-4.3.3-comp/gcc-4.3.3/i386-pc-solaris2.10/libstdc++-v3/src/../libmath/.libs/libmath.a
is not a valid archive
make[4]: *** [libstdc++.la] Error 1
===
Comment 12 Niki W. Waibel 2009-03-09 11:51:39 UTC
this looks interesting:
===
nwaibel@amdsol-1:~ $ ar t libmath.a 
stubs.o
signbit.o
signbitf.o
signbitl.o
nwaibel@amdsol-1:~ $ ar x libmath.a 
ar: libmath.a is not a valid archive
nwaibel@amdsol-1:~ $ ar --version
GNU ar (Linux/GNU Binutils) 2.19.51.0.2.20090204
Copyright 2008 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) any later version.
This program has absolutely no warranty.
nwaibel@amdsol-1:~ $ exit
logout
Connection to amdsol-1 closed.
nwaibel@m5000-1:~ $ ar t libmath.a 
stubs.o
signbit.o
signbitf.o
signbitl.o
nwaibel@m5000-1:~ $ ar x libmath.a 
nwaibel@m5000-1:~ $ ar --version
GNU ar (Linux/GNU Binutils) 2.19.50.0.1.20081007
Copyright 2007 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) any later version.
This program has absolutely no warranty.
nwaibel@m5000-1:~ $ /misc/sparc-sun-solaris2.10/opt/binutils/2.19.50.0.1/bin/ar
x libmath.a
nwaibel@m5000-1:~ $ /misc/sparc-sun-solaris2.10/opt/binutils/2.19.51.0.1/bin/ar
--version   
GNU ar (Linux/GNU Binutils) 2.19.51.0.1.20090106
Copyright 2008 Free Software Foundation, Inc.
This program is free software; you may redistribute it under the terms of
the GNU General Public License version 3 or (at your option) any later version.
This program has absolutely no warranty.
===

m5000-1 is sparc-sun-solaris2.10 with binutils-2.19.50.0.1.20081007 (default)
and binutils-2.19.51.0.1.20090106

amdsol-1 is i386-pc-solaris2.10 binutils-2.19.51.0.2.20090204

i am very uncertain if there is a bug when creating or when extracting the
archive. or both ...
Comment 13 Niki W. Waibel 2009-03-09 13:29:10 UTC
Created attachment 3803 [details]
output of binutils-2.19.50.0.1.20081007 / gcc-4.3.3 bootstrap on i386-pc-solaris2.10 (okay)

... as somehow expected.
Comment 14 Niki W. Waibel 2009-03-09 13:32:54 UTC
Created attachment 3804 [details]
produced when bootstrapping gcc-4.3.3 on i386-pc-solaris2.10 using binutils-2.19.50.0.1.20081007

this is quite different from the prev attached libmath.a (by
2.19.51.0.2.20090204), it seems.
Comment 15 Niki W. Waibel 2009-03-09 13:47:44 UTC
strange:
===
nwaibel@amdsol-1:~ $ /misc/i386-pc-solaris2.10/opt/binutils/2.19.51.0.2/bin/ar
-x libmath.a
/misc/i386-pc-solaris2.10/opt/binutils/2.19.51.0.2/bin/ar: libmath.a is not a
valid archive
nwaibel@amdsol-1:~ $ /misc/i386-pc-solaris2.10/opt/binutils/2.19.50.0.1/bin/ar
-x libmath.a
nwaibel@amdsol-1:~ $ rm -rf stubs.o signbit.o signbitf.o signbitl.o
nwaibel@amdsol-1:~ $ /misc/i386-pc-solaris2.10/opt/binutils/2.19.51.0.2/bin/ar
-x libmath.a-okay 
/misc/i386-pc-solaris2.10/opt/binutils/2.19.51.0.2/bin/ar: libmath.a-okay is not
a valid archive
nwaibel@amdsol-1:~ $ /misc/i386-pc-solaris2.10/opt/binutils/2.19.50.0.1/bin/ar
-x libmath.a-okay 
===
Comment 16 Nick Clifton 2009-03-10 15:46:22 UTC
Hi Niki,

  Sorry but I still cannot reproduce the problem.  I checked both versions of
libmath.a that you uploaded and they both responded to the ar program, both with
the 't' command and the 'x' command.

  If you are willing to accept a large email (~270k) I can send you a copy of
the ar binary that I have been using so that you can try it out yourself.

Cheers
  Nick
Comment 17 Niki W. Waibel 2009-03-10 16:10:59 UTC
sure. just send it to my gmx addr given in Cc. i guess your version of ar will work.

you may need to send me your libbfd-2.19.50.0.1.20081007.so lib also ...
===
$ ldd /misc/i386-pc-solaris2.10/opt/binutils/2.19.50.0.1/bin/ar
        libbfd-2.19.50.0.1.20081007.so =>       
/misc/i386-pc-solaris2.10/lib/libbfd-2.19.50.0.1.20081007.so
        libl.so.1 =>     /usr/lib/libl.so.1
        libz.so.1 =>     /misc/i386-pc-solaris2.10/lib/libz.so.1
        libc.so.1 =>     /lib/libc.so.1
        libm.so.2 =>     /lib/libm.so.2
===
Comment 18 Nick Clifton 2009-03-11 15:27:27 UTC
Hi Niki,

  Just one idea - have you tried building a static version of the 'ar' binary
and then testing that ?

Cheers
  Nick
Comment 19 Niki W. Waibel 2009-03-28 00:03:03 UTC
okay, all my issues reported here are fixed with your patch provided in bug#9992.

thanks a lot, nick!

niki
Comment 20 Alan Modra 2009-10-14 02:55:19 UTC
reportedly fixed