Bug 490797 - Ranlib and "ar -s" Can Not Regenerate Index
Summary: Ranlib and "ar -s" Can Not Regenerate Index
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Fedora
Classification: Fedora
Component: binutils
Version: rawhide
Hardware: All
OS: Linux
low
low
Target Milestone: ---
Assignee: Nick Clifton
QA Contact: Fedora Extras Quality Assurance
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2009-03-18 05:08 UTC by Qian Cai
Modified: 2009-04-08 00:28 UTC (History)
3 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2009-03-27 11:01:38 UTC
Type: ---
Embargoed:


Attachments (Terms of Use)

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.


Note You need to log in before you can comment on or make changes to this bug.