Why ar doesn't call ranlib on Mac?

Alexy Khrabrov deliverable at gmail.com
Sun Mar 8 23:01:53 PDT 2009


Peter --

On Wed, Mar 4, 2009 at 10:18 AM, Peter O'Gorman <peter at pogma.com> wrote:
> Alexy Khrabrov wrote:
>> In building various Linux things from source on Mac, I've run into the
>> "archive has no table of contents" problem several times.  The fix is
>> invariably to go and stick ranlib after each ar.
>
> What version of Mac OS X/Xcode are you using? ar, since Mac OS X 10.4
> does ranlib the archive. I filed a bug at the time asking for the -S
> flag to turn off this behavior to speed up creating an archive
> incrementally.
>
> http://www.opensource.apple.com/darwinsource/10.5.6/cctools-667.3/ar/ar.c

In fact, I checked and see that ranlib is not being run!

Way to check: get

http://www.opensource.apple.com/darwinsource/tarballs/apsl/cctools-667.3.tar.gz

-- and patch it like,

		case 's':
		  (void)fprintf(stderr, "Alexy wants to run ranlib with -s\n");
			options |= AR_S;
			break;
...

	if(fcall != 0){
	    retval = (*fcall)(argv);
	    if(retval != EXIT_SUCCESS ||
          ((options & AR_S) != AR_S && // NB (0)
          /* ((((options & AR_S) != AR_S) && !run_ranlib) && */ // NB (1)
	        (get_unix_standard_mode() == FALSE ||
		 archive_opened_for_writing == 0)))
     (void)fprintf(stderr, "exiting with code %d, run_ranlib==%d\n",
retval, run_ranlib); // NB
		exit(retval);
	}

	/*
	 * The default is to run ranlib(1) for UNIX conformance.  But if the -S
	 * option is specified by the user we don't run it.
	 */
	if(run_ranlib){
    (void)fprintf(stderr, "Alexy wants to run ranlib\n"); // NB
...

-- where NB mark the additions.  Now if you run, in the same directory,

make # creates ar.NEW -- not universal and so is only about 31 K in
size vs 63 K for /usr/bin/ar

/s/src/apple/cctools/cctools-667.3/ar ./ar.NEW crs test.a *.o && echo
"exit code $?"
Alexy wants to run ranlib with -s
Alexy got his with to run ranlib
ranlib: file: test.a(vers.o) has no symbols
exit code 0

/s/src/apple/cctools/cctools-667.3/ar ./ar.NEW cr test.a *.o && echo
"exit code $?"
exiting with code 0, run_ranlib==1
exit code 0

-- notice ranlib section governed by run_ranlib is not being run!

Replacing the line NB (0) with line NB (1) does the trick -- in order
to check exiting, we're checking AR_S only, not ranlib...
After doing so both cases become:

/s/src/apple/cctools/cctools-667.3/ar ./ar.NEW cr test.a *.o && echo
"exit code $?"
Alexy got his with to run ranlib
ranlib: file: test.a(vers.o) has no symbols
exit code 0

Makes sense?  The extra parentheses around the chained &&'s can be removed.
Cheers,
Alexy


More information about the macports-users mailing list