Subject: 'ar cru' rejecting empty object list on darwin11

From: David Fang <[email-masked]>
Date: Sat, 13 Oct 2012 12:34:51 -0400 (EDT)

Hi,
 	I'm getting an error with libtool --mode=link on darwin11 (OS X 
10.7.5), using xcode command-line tools 4.5.1 (October 2012).  An 'ar cru' 
command fails because it expects a non-empty object list.

The brief:
[fangism-pro:hackt-0.1.4-devel-20121012/darwin-build/src] fang% make -j1
All header tests passed.
make  all-recursive
Making all in util/test
make  all-am
make[3]: Nothing to be done for `all-am'.
Making all in .
/bin/sh ../libtool  --tag=CXX   --mode=link clang++ -pipe -ansi 
-pedantic-errors -Wold-style-cast -Woverloaded-virtual -W -Wextra -Wall 
-Wundef -Wshadow -Wno-unused-parameter -Wpointer-arith -Wcast-qual 
-Wcast-align -Wconversion -Werror -g -O2 -Wno-error=sign-conversion 
-Wno-error=unused-function -Wno-error=conversion -Qunused-arguments 
-L/sw/lib   -L/sw/lib -o libhacktexec.la  main/force_load.lo 
main/program_registry.lo main/parse_test.lo main/flatten.lo main/haco.lo 
main/create.lo main/cflat.lo main/prsobjdemo.lo main/prsim-main.lo 
main/dump_persistent_table.lo main/objdump.lo main/shell.lo 
main/version.lo main/chpsim.lo main/hacknet.lo    libhacktprsim.la 
libhacktchpsim.la libhacknet.la
libtool: link: rm -fr  .libs/libhacktexec.a .libs/libhacktexec.la
libtool: link: ar cru .libs/libhacktexec.a main/.libs/force_load.o 
main/.libs/program_registry.o main/.libs/parse_test.o main/.libs/flatten.o 
main/.libs/haco.o main/.libs/create.o main/.libs/cflat.o 
main/.libs/prsobjdemo.o main/.libs/prsim-main.o 
main/.libs/dump_persistent_table.o main/.libs/objdump.o main/.libs/shell.o 
main/.libs/version.o main/.libs/chpsim.o main/.libs/hacknet.o
libtool: link: ranlib .libs/libhacktexec.a
libtool: link: ( cd ".libs" && rm -f "libhacktexec.la" && ln -s 
"../libhacktexec.la" "libhacktexec.la" )
/bin/sh ../libtool  --tag=CC   --mode=link clang -pipe -ansi 
-pedantic-errors -Wmissing-prototypes -Wstrict-prototypes 
-Wbad-function-cast -Wnested-externs -W -Wextra -Wall -Wundef -Wshadow 
-Wno-unused-parameter -Wpointer-arith -Wcast-qual -Wcast-align 
-Wconversion -Werror -g -O2 -Qunused-arguments -module -L/sw/lib -o 
hackt-guile.la -rpath /sw/lib/hackt  libhacktguile.la
libtool: link: warning: `/sw/lib/libgmp.la' seems to be moved
libtool: link: warning: `/sw/lib/libgmp.la' seems to be moved
libtool: link: warning: library `/sw/lib/libgmp.la' was moved.
libtool: link: rm -fr  .libs/hackt-guile.0.so .libs/hackt-guile.so
libtool: link: clang -Wl,-undefined -Wl,dynamic_lookup -o 
.libs/hackt-guile.0.so -bundle   -L/sw/lib ./.libs/libhacktguile.dylib 
/sw/src/fink.build/hackt-0.1.4-devel-20121012-1/hackt-0.1.4-devel-20121012/darwin-build/src/.libs/libhacktlib.dylib 
/sw/src/fink.build/hackt-0.1.4-devel-20121012-1/hackt-0.1.4-devel-20121012/darwin-build/src/.libs/libhacktparsers.dylib 
/sw/src/fink.build/hackt-0.1.4-devel-20121012-1/hackt-0.1.4-devel-20121012/darwin-build/src/.libs/libhacktast.dylib 
/sw/src/fink.build/hackt-0.1.4-devel-20121012-1/hackt-0.1.4-devel-20121012/darwin-build/src/.libs/libfangutil.dylib 
-lreadline -lncurses 
/sw/src/fink.build/hackt-0.1.4-devel-20121012-1/hackt-0.1.4-devel-20121012/darwin-build/src/.libs/libguileutil.dylib 
/sw/lib/libguile.dylib /sw/lib/libgmp.dylib -lm /sw/lib/libltdl.dylib  -O2 
-Wl,-dylib_file 
-Wl,/sw/lib/hackt/libhacktlib.0.dylib:/sw/src/fink.build/hackt-0.1.4-devel-20121012-1/hackt-0.1.4-devel-20121012/darwin-build/src/.libs/libhacktlib.dylib 
-Wl,-dylib_file 
-Wl,/sw/lib/hackt/libhacktparsers.0.dylib:/sw/src/fink.build/hackt-0.1.4-devel-20121012-1/hackt-0.1.4-devel-20121012/darwin-build/src/.libs/libhacktparsers.dylib 
-Wl,-dylib_file 
-Wl,/sw/lib/hackt/libhacktast.0.dylib:/sw/src/fink.build/hackt-0.1.4-devel-20121012-1/hackt-0.1.4-devel-20121012/darwin-build/src/.libs/libhacktast.dylib 
-Wl,-dylib_file 
-Wl,/sw/lib/hackt/libfangutil.0.dylib:/sw/src/fink.build/hackt-0.1.4-devel-20121012-1/hackt-0.1.4-devel-20121012/darwin-build/src/.libs/libfangutil.dylib 
-Wl,-dylib_file 
-Wl,/sw/lib/hackt/libguileutil.0.dylib:/sw/src/fink.build/hackt-0.1.4-devel-20121012-1/hackt-0.1.4-devel-20121012/darwin-build/src/.libs/libguileutil.dylib 
-Wl,-dylib_file 
-Wl,/sw/lib/hackt/libhacktparsers.0.dylib:/sw/src/fink.build/hackt-0.1.4-devel-20121012-1/hackt-0.1.4-devel-20121012/darwin-build/src/.libs/libhacktparsers.dylib 
-Wl,-dylib_file 
-Wl,/sw/lib/hackt/libhacktast.0.dylib:/sw/src/fink.build/hackt-0.1.4-devel-20121012-1/hackt-0.1.4-devel-20121012/darwin-build/src/.libs/libhacktast.dylib 
-Wl,-dylib_file 
-Wl,/sw/lib/hackt/libfangutil.0.dylib:/sw/src/fink.build/hackt-0.1.4-devel-20121012-1/hackt-0.1.4-devel-20121012/darwin-build/src/.libs/libfangutil.dylib 
-Wl,-dylib_file 
-Wl,/sw/lib/hackt/libhacktast.0.dylib:/sw/src/fink.build/hackt-0.1.4-devel-20121012-1/hackt-0.1.4-devel-20121012/darwin-build/src/.libs/libhacktast.dylib 
-Wl,-dylib_file 
-Wl,/sw/lib/hackt/libfangutil.0.dylib:/sw/src/fink.build/hackt-0.1.4-devel-20121012-1/hackt-0.1.4-devel-20121012/darwin-build/src/.libs/libfangutil.dylib 
-Wl,-dylib_file 
-Wl,/sw/lib/hackt/libfangutil.0.dylib:/sw/src/fink.build/hackt-0.1.4-devel-20121012-1/hackt-0.1.4-devel-20121012/darwin-build/src/.libs/libfangutil.dylib
libtool: link: (cd ".libs" && rm -f "hackt-guile.so" && ln -s 
"hackt-guile.0.so" "hackt-guile.so")
libtool: link: ar cru .libs/hackt-guile.a
ar: no archive members specified
usage:  ar -d [-TLsv] archive file ...
 	ar -m [-TLsv] archive file ...
 	ar -m [-abiTLsv] position archive file ...
 	ar -p [-TLsv] archive [file ...]
 	ar -q [-cTLsv] archive file ...
 	ar -r [-cuTLsv] archive file ...
 	ar -r [-abciuTLsv] position archive file ...
 	ar -t [-TLsv] archive [file ...]
 	ar -x [-ouTLsv] archive [file ...]
make[2]: *** [hackt-guile.la] Error 1
make[1]: *** [all-recursive] Error 1
make: *** [all] Error 2

With --debug added to the libtool command, the tail of the output shows:
+ func_to_tool_file .libs/hackt-guile.a func_convert_file_msys_to_w32
+ set -x
+ case ,$2, in
+ func_convert_file_noop .libs/hackt-guile.a
+ func_to_host_file_result=.libs/hackt-guile.a
+ func_to_tool_file_result=.libs/hackt-guile.a
+ tool_oldlib=.libs/hackt-guile.a
+ eval 'cmds="$AR' '$AR_FLAGS' '$oldlib$oldobjs~$RANLIB' '$tool_oldlib"'
++ cmds='ar cru .libs/hackt-guile.a ~ranlib .libs/hackt-guile.a'
+ func_len ' ar cru .libs/hackt-guile.a ~ranlib .libs/hackt-guile.a'
+ func_len_result=55
+ len=55
+ test 55 -lt 196608
+ cmds='$AR $AR_FLAGS $oldlib$oldobjs~$RANLIB $tool_oldlib'
+ func_execute_cmds '$AR $AR_FLAGS $oldlib$oldobjs~$RANLIB $tool_oldlib' 
'exit $?'
+ set -x
+ save_ifs='
'
+ IFS='~'
+ for cmd in '$1'
+ IFS='
'
+ eval 'cmd="$AR' '$AR_FLAGS' '$oldlib$oldobjs"'
++ cmd='ar cru .libs/hackt-guile.a '
+ func_show_eval 'ar cru .libs/hackt-guile.a ' 'exit $?'
+ my_cmd='ar cru .libs/hackt-guile.a '
+ my_fail_exp='exit $?'
+ false
+ func_quote_for_expand 'ar cru .libs/hackt-guile.a '
+ case $1 in
+ my_arg='ar cru .libs/hackt-guile.a '
+ case $my_arg in
+ my_arg='"ar cru .libs/hackt-guile.a "'
+ func_quote_for_expand_result='"ar cru .libs/hackt-guile.a "'
+ eval 'func_echo "ar cru .libs/hackt-guile.a "'
++ func_echo 'ar cru .libs/hackt-guile.a '
++ echo 'libtool: link: ar cru .libs/hackt-guile.a '
libtool: link: ar cru .libs/hackt-guile.a
+ false
+ eval 'ar cru .libs/hackt-guile.a '
++ ar cru .libs/hackt-guile.a
ar: no archive members specified
usage:  ar -d [-TLsv] archive file ...
 	ar -m [-TLsv] archive file ...
 	ar -m [-abiTLsv] position archive file ...
 	ar -p [-TLsv] archive [file ...]
 	ar -q [-cTLsv] archive file ...
 	ar -r [-cuTLsv] archive file ...
 	ar -r [-abciuTLsv] position archive file ...
 	ar -t [-TLsv] archive [file ...]
 	ar -x [-ouTLsv] archive [file ...]
+ my_status=1
+ test 1 -eq 0
+ eval '(exit 1); exit $?'
++ exit 1
++ exit 1

from Makefile.am (relevant lines):
pkglib_LTLIBRARIES += libhacktguile.la
pkglib_LTLIBRARIES += hackt-guile.la
hackt_guile_la_SOURCES =
hackt_guile_la_LDFLAGS = -module
hackt_guile_la_LIBADD = libhacktguile.la

libhacktguile_la_SOURCES = \
         guile/libhackt-wrap.cc \
         guile/libhackt-wrap.h \
 	...
libhacktguile_la_CPPFLAGS = $(GUILE_CPPFLAGS) -DWITH_MAIN
libhacktguile_la_CXXFLAGS = $(AM_CXXFLAGS) $(GUILE_WARN_FLAGS) \
         -Wno-old-style-cast -Werror
libhacktguile_la_LIBADD = libhacktlib.la libguileutil.la

hackt-guile.la is a loadable module with no additional sources,
just a library dependency on libhacktguile.la.

To get this far I had to apply a workaround patch to the 
configure-generated libtool script for issue 12156 (tr):
http://debbugs.gnu.org/cgi/bugreport.cgi?bug=12156

Does anything in the debug trace look wrong?
Is ar supposed to be called if the archive member list is empty?
If not, is there a suitable patch or workaround?

Fang

-- 
David Fang
http://www.csl.cornell.edu/~fang/