Bug 490797 - Ranlib and "ar -s" Can Not Regenerate Index
Ranlib and "ar -s" Can Not Regenerate Index
Status: CLOSED NOTABUG
Product: Fedora
Classification: Fedora
Component: binutils (Show other bugs)
rawhide
All Linux
low Severity low
: ---
: ---
Assigned To: Nick Clifton
Fedora Extras Quality Assurance
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2009-03-18 01:08 EDT by CAI Qian
Modified: 2009-04-07 20:28 EDT (History)
3 users (show)

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Environment:
Last Closed: 2009-03-27 07:01:38 EDT
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:


Attachments (Terms of Use)

  None (edit)
Description CAI Qian 2009-03-18 01:08:50 EDT
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 07:01:38 EDT
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 CAI Qian 2009-03-27 07:13:09 EDT
Thanks Nick! I'll fix the broken test case instead.
Comment 3 CAI Qian 2009-04-02 22:55:22 EDT
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 05:13:10 EDT
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 CAI Qian 2009-04-07 20:28:54 EDT
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.