Bug 490797

Summary: Ranlib and "ar -s" Can Not Regenerate Index
Product: [Fedora] Fedora Reporter: Qian Cai <qcai>
Component: binutilsAssignee: Nick Clifton <nickc>
Status: CLOSED NOTABUG QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: low Docs Contact:
Priority: low    
Version: rawhideCC: jakub, jan.kratochvil, nickc
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2009-03-27 11:01:38 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Qian Cai 2009-03-18 05:08:50 UTC
Description of problem:
First, we create an archieve file lib.a by including file1.o.
# ar -cr lib.a file1.o

Second, we get lib.a's block size.
# ls -s lib.a
8 lib.a

# nm -s lib.a

Archive index:
main in file1.o

file1.o:
0000000000000000 r .LC0
0000000000000000 T main
                 U puts

Then, we strip its symbols.
# strip lib.a

# ls -s lib.a
8 lib.a

# nm -s lib.a

file1.o:
nm: file1.o: no symbols

Next, use "ar -s" or ranlib to generate symbol index.
# ar -s lib.a

# ls -s lib.a
8 lib.a

# nm -s lib.a
file1.o:
nm: file1.o: no symbols

Version-Release number of selected component (if applicable):
binutils-2.18.50.0.9-8.fc10.i386

How reproducible:
always

Steps to Reproduce:
As the above.
  
Actual results:
No symbol index generated.

Expected results:
Symbol index generated.

Additional info:

Comment 1 Nick Clifton 2009-03-27 11:01:38 UTC
Hi Cai,

  This is the correct behaviour.  Once you have stripped all of the symbols out of the files in the archive (using the "strip lib.a" command) it is no longer possible to regenerate the symbol index.  Basically there are no symbols left in the archive, so it is not possible to create an index based on them.

  If you change the strip command to only remove unneeded symbols then you will be able to create a symbol index.  ie:

  # ar cr lib.a file1.o
  # strip --strip-unneeded lib.a
  # ar s lib.a
  # nm -s lib.a
  Archive index:
  main in file1.o

  file1.o:
  0000000000000000 T main
                   U puts


Cheers
  Nick

Comment 2 Qian Cai 2009-03-27 11:13:09 UTC
Thanks Nick! I'll fix the broken test case instead.

Comment 3 Qian Cai 2009-04-03 02:55:22 UTC
Hi Nick, it is not obvious to me "ar -s" makes any different. Please see the following example,

$ ar cr lib.a file1.o
$ ls -l lib.a
-rw-rw-r-- 1 caiqian caiqian 1018 2009-04-02 10:42 lib.a
$ nm -s lib.a

Archive index:
main in file1.o

file1.o:
00000000 T main
         U puts

$ strip --strip-unneeded lib.a
$ ls -l lib.a
-rw-rw-r-- 1 caiqian caiqian 994 2009-04-02 10:42 lib.a
$ nm -s lib.a

Archive index:
main in file1.o

file1.o:
00000000 T main
         U puts

$ ar -s lib.a
$ ls -l lib.a
-rw-rw-r-- 1 caiqian caiqian 994 2009-04-02 10:43 lib.a
$ nm -s lib.a

Archive index:
main in file1.o

file1.o:
00000000 T main
         U puts


As you can see from the above, the file size and "nm -s" output did not change at all after "ar -s".

Comment 4 Nick Clifton 2009-04-07 09:13:10 UTC
Hi Cai,

> it is not obvious to me "ar -s" makes any different

It doesn't. :-)

It does make a difference on some versions of the ar program, notably those on some Unix and Solaris systems.  These versions of ar do not automatically added a symbol index when the archive is created.  But the binutils ar automatically adds a symbol index when an archive is created.  So the -s option is supported mainly for backwards compatibility with these other versions of ar.

Cheers
  Nick

Comment 5 Qian Cai 2009-04-08 00:28:54 UTC
Thanks a lot, Nick! Those test cases were written a few years back, and I happened to deal with them recently, so I guess they were using the different version of "ar" other than bintuils.