Hi, Well, Mac OS X 10.6 has been released, and its linker now has support for an option similar to --whole-archive. -force_load libfoo.a will load all members of libfoo.a into the output. -force_load <lib> can be given multiple times on the command line.
This patch (and a test case that checks that gdb can find the debugging symbols) makes libtool use this new option. Ok? 2009-09-06 Peter O'Gorman <pe...@pogma.com> Use darwin's -force_load flag if available for whole_archive_flag_spec * libltdl/m4/libtool.m4 (_LT_REQUIRED_DARWIN_CHECKS): Check for -force_load and use it if there. * tests/darwin.at: Add a simple test. Peter -- Peter O'Gorman http://pogma.com
>From b1b56b0c0678d4c4e7b25c155d53145ca579effc Mon Sep 17 00:00:00 2001 From: Peter O'Gorman <pe...@pogma.com> Date: Sun, 6 Sep 2009 09:59:19 -0500 Subject: [PATCH] Use darwin's -force_load flag if available for whole_archive_flag_spec libltdl/m4/libtool.m4 (_LT_REQUIRED_DARWIN_CHECKS): Check for -force_load and use it if there. tests/darwin.at: Add a simple test. --- libltdl/m4/libtool.m4 | 31 ++++++++++++++++++++++++++- tests/darwin.at | 53 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 82 insertions(+), 2 deletions(-) diff --git a/libltdl/m4/libtool.m4 b/libltdl/m4/libtool.m4 index b081f7b..48f7993 100644 --- a/libltdl/m4/libtool.m4 +++ b/libltdl/m4/libtool.m4 @@ -971,6 +971,29 @@ m4_defun_once([_LT_REQUIRED_DARWIN_CHECKS],[ [lt_cv_ld_exported_symbols_list=no]) LDFLAGS="$save_LDFLAGS" ]) + AC_CACHE_CHECK([for -force_load linker flag],[lt_cv_ld_force_load], + [lt_cv_ld_force_load=no + cat > conftest.c << _LT_EOF +int forced_loaded() { return 2;} +_LT_EOF + echo "$LTCC $LTCFLAGS -c -o conftest.o conftest.c" >&AS_MESSAGE_LOG_FD + $LTCC $LTCFLAGS -c -o conftest.o conftest.c 2>&AS_MESSAGE_LOG_FD + echo "$AR cru libconftest.a conftest.o" >&AS_MESSAGE_LOG_FD + $AR cru libconftest.a conftest.o 2>&AS_MESSAGE_LOG_FD + cat > conftest.c << _LT_EOF +int main() { return 0;} +_LT_EOF + echo "$LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a" >&AS_MESSAGE_LOG_FD + $LTCC $LTCFLAGS $LDFLAGS -o conftest conftest.c -Wl,-force_load,./libconftest.a 2>conftest.err + _lt_result=$? + if test -f conftest && test ! -s conftest.err && test $_lt_result = 0 && $GREP forced_load conftest 2>&1 >/dev/null; then + lt_cv_ld_force_load=yes + else + cat conftest.err >&AS_MESSAGE_LOG_FD + fi + rm -f conftest.err conftest.a conftest conftest.c + rm -rf conftest.dSYM + ]) case $host_os in rhapsody* | darwin1.[[012]]) _lt_dar_allow_undefined='${wl}-undefined ${wl}suppress' ;; @@ -998,7 +1021,7 @@ m4_defun_once([_LT_REQUIRED_DARWIN_CHECKS],[ else _lt_dar_export_syms='~$NMEDIT -s $output_objdir/${libname}-symbols.expsym ${lib}' fi - if test "$DSYMUTIL" != ":"; then + if test "$DSYMUTIL" != ":" && test "$lt_cv_ld_force_load" = "no"; then _lt_dsymutil='~$DSYMUTIL $lib || :' else _lt_dsymutil= @@ -1018,7 +1041,11 @@ m4_defun([_LT_DARWIN_LINKER_FEATURES], _LT_TAGVAR(hardcode_direct, $1)=no _LT_TAGVAR(hardcode_automatic, $1)=yes _LT_TAGVAR(hardcode_shlibpath_var, $1)=unsupported - _LT_TAGVAR(whole_archive_flag_spec, $1)='' + if test "$lt_cv_ld_force_load" = "yes"; then + _LT_TAGVAR(whole_archive_flag_spec, $1)='`for conv in $convenience\"\"; do test -n \"$conv\" && new_convenience=\"$new_convenience ${wl}-force_load,$conv\"; done; func_echo_all \"$new_convenience\"`' + else + _LT_TAGVAR(whole_archive_flag_spec, $1)='' + fi _LT_TAGVAR(link_all_deplibs, $1)=yes _LT_TAGVAR(allow_undefined_flag, $1)="$_lt_dar_allow_undefined" case $cc_basename in diff --git a/tests/darwin.at b/tests/darwin.at index 8884fd2..fe442f7 100644 --- a/tests/darwin.at +++ b/tests/darwin.at @@ -148,3 +148,56 @@ AT_CHECK([$LIBTOOL --dry-run --mode=link $CC $CFLAGS $LDFLAGS ]dnl AT_CHECK([grep stamp $lockfile], [], [ignore]) AT_CLEANUP + +AT_SETUP([darwin gdb debug information]) + +AT_DATA([foo.c], [[ +int foo (void) { return 0; } +]]) + +AT_DATA([bar.c], [[ +extern int foo (void); +int bar (void) { return foo (); } +]]) + +AT_DATA([main.c], [[ +extern int bar(void); + +int main() { return bar();} +]]) + +AT_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c bar.c], + [], [ignore], [ignore]) +AT_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c foo.c], + [], [ignore], [ignore]) +AT_CHECK([$LIBTOOL --mode=compile $CC $CPPFLAGS $CFLAGS -c main.c], + [], [ignore], [ignore]) + +AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS -o libfoo.la foo.lo], + [], [ignore], [ignore]) + +AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS ]dnl + [ -o libbar.la bar.lo -rpath /foo libfoo.la ], + [], [ignore], [ignore]) + +AT_CHECK([$LIBTOOL --mode=link $CC $CFLAGS $LDFLAGS ]dnl + [ -o main main.lo libbar.la],[], [ignore], [ignore]) +AT_CHECK([echo quit | $LIBTOOL --mode=execute gdb main 2>err1], + [ignore], [ignore], [ignore]) + +AT_CHECK([grep 'Could not find object file' err1],[1],[ignore],[ignore]) + +AT_XFAIL_IF([ +case `$LIBTOOL --config | grep whole_archive_flag_spec=` in +*-force_load*) false ;; +*) : ;; +esac ]) + +# Remove any dSYM bundle +rm -rf .libs/*.dSYM + +AT_CHECK([echo quit | $LIBTOOL --mode=execute gdb main 2>err2], + [ignore], [ignore], [ignore]) +AT_CHECK([grep 'Could not find object file' err2],[1],[ignore],[ignore]) + +AT_CLEANUP -- 1.6.0.6