Re: Supporting -export-dynamic on AIX

2006-08-08 Thread Albert Chin
On Sun, Jul 02, 2006 at 10:58:23PM +0900, Peter O'Gorman wrote:
> On Tue, 2006-06-20 at 12:12 -0500, Albert Chin wrote:
> 
> Albert also questioned the documentation:
> 
> >   On some operating systems, a program symbol must be specially
> > declared
> >   in order to be dynamically resolved with the `dlsym' (or equivalent)
> >   function.
> > 
> >  Libtool provides the `-export-dynamic' and `-module' link flags
> >   (*note Link mode::), which do this declaration.  You need to use
> > these
> >   flags if you are linking an application program that dlopens other
> >   modules or a libtool library that will also be dlopened.
> > 
> > Should the last sentence above end with ", respectively"?
> 
> I think this is a documentation bug. -export-dynamic does not imply
> -module, there is a line of code in ltmain that adds dlname to the .la
> file if either -module or -export-dynamic was specified, but this only
> "works" if modules and libraries are otherwise equivalent, so it should
> probably be removed and the documentation adjusted for HEAD, thoughts?
> Either way this patch does not affect that behavior at all.
> 
> Here are patches against branch-1-5 and HEAD, okay (with apropriate
> ChangeLog, of course)?

Another version. Patch against branch-1-5 only. I've reordered where
--export-dynamic occurs so we don't have to worry about the above.

-- 
albert chin ([EMAIL PROTECTED])
Index: libtool.m4
===
RCS file: /cvsroot/libtool/libtool/Attic/libtool.m4,v
retrieving revision 1.314.2.162
diff -u -p -r1.314.2.162 libtool.m4
--- libtool.m4  3 Aug 2006 14:31:47 -   1.314.2.162
+++ libtool.m4  8 Aug 2006 13:16:45 -
@@ -2911,6 +2911,13 @@ case $host_os in
 
   exp_sym_flag='-bexport'
   no_entry_flag='-bnoentry'
+
+  if $NM -V 2>&1 | grep 'GNU' > /dev/null; then
+   _LT_AC_TAGVAR(export_dynamic_symbols_cmds, $1)='$NM -Bpg $objs $libobjs 
$old_deplibs $old_convenience | awk '\''{ if (((\[$]2 == "T") || (\[$]2 == "D") 
|| (\[$]2 == "B")) && ([substr](\[$]3,1,1) != ".")) { print \[$]3 } }'\'' | 
sort -u > $export_symbols'
+  else
+   _LT_AC_TAGVAR(export_dynamic_symbols_cmds, $1)='$NM -BCpg $objs 
$libobjs $old_deplibs $old_convenience | awk '\''{ if (((\[$]2 == "T") || 
(\[$]2 == "D") || (\[$]2 == "B")) && ([substr](\[$]3,1,1) != ".")) { print 
\[$]3 } }'\'' | sort -u > $export_symbols'
+  fi
+  _LT_AC_TAGVAR(export_dynamic_flag_spec, 
$1)="\${wl}$exp_sym_flag:\$export_symbols"
 fi
 
 # When large executables or shared objects are built, AIX ld can
@@ -3974,6 +3981,7 @@ _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=
 _LT_AC_TAGVAR(allow_undefined_flag, $1)=
 _LT_AC_TAGVAR(always_export_symbols, $1)=no
 _LT_AC_TAGVAR(archive_expsym_cmds, $1)=
+_LT_AC_TAGVAR(export_dynamic_symbols_cmds, $1)=
 _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)=
 _LT_AC_TAGVAR(hardcode_direct, $1)=no
 _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)=
@@ -4209,6 +4217,7 @@ if test -f "$ltmain"; then
 _LT_AC_TAGVAR(lt_prog_compiler_pic, $1) \
 _LT_AC_TAGVAR(lt_prog_compiler_static, $1) \
 _LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1) \
+_LT_AC_TAGVAR(export_dynamic_symbols_cmds, $1) \
 _LT_AC_TAGVAR(export_dynamic_flag_spec, $1) \
 _LT_AC_TAGVAR(thread_safe_flag_spec, $1) \
 _LT_AC_TAGVAR(whole_archive_flag_spec, $1) \
@@ -4243,6 +4252,7 @@ if test -f "$ltmain"; then
 _LT_AC_TAGVAR(old_archive_from_new_cmds, $1) | \
 _LT_AC_TAGVAR(archive_cmds, $1) | \
 _LT_AC_TAGVAR(archive_expsym_cmds, $1) | \
+_LT_AC_TAGVAR(export_dynamic_symbols_cmds, $1) | \
 _LT_AC_TAGVAR(module_cmds, $1) | \
 _LT_AC_TAGVAR(module_expsym_cmds, $1) | \
 _LT_AC_TAGVAR(old_archive_from_expsyms_cmds, $1) | \
@@ -4455,6 +4465,7 @@ link_static_flag=$lt_[]_LT_AC_TAGVAR(lt_
 no_builtin_flag=$lt_[]_LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)
 
 # Compiler flag to allow reflexive dlopens.
+export_dynamic_symbols_cmds=$lt_[]_LT_AC_TAGVAR(export_dynamic_symbols_cmds, 
$1)
 export_dynamic_flag_spec=$lt_[]_LT_AC_TAGVAR(export_dynamic_flag_spec, $1)
 
 # Compiler flag to generate shared objects directly from archives.
@@ -5480,6 +5491,7 @@ ifelse([$1],[CXX],[
   _LT_AC_TAGVAR(archive_expsym_cmds, $1)=
   _LT_AC_TAGVAR(old_archive_From_new_cmds, $1)=
   _LT_AC_TAGVAR(old_archive_from_expsyms_cmds, $1)=
+  _LT_AC_TAGVAR(export_dynamic_symbols_cmds, $1)=
   _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)=
   _LT_AC_TAGVAR(whole_archive_flag_spec, $1)=
   _LT_AC_TAGVAR(thread_safe_flag_spec, $1)=
@@ -5788,8 +5800,11 @@ _LT_EOF
# -C means demangle to AIX nm, but means don't demangle with GNU nm
if $NM -V 2>&1 | grep 'GNU' > /dev/null; then
  _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs 
$convenience | awk '\''{ if (((\[$]2 == "T") || (\[$]2 == "D") || (\[$]2 == 
"B")) && ([substr](\[$]3,1,1) != ".")) { print \[$]3 } }'\'' | sort -u > 
$export_symbols'
+ _LT_AC_TAGVAR(export_dyna

Re: How to use --whole-archive ld arg with libtool?

2006-08-08 Thread Reid Spencer
Hi Ralf,

On Mon, 2006-08-07 at 18:07 +0200, Ralf Wildenhues wrote:

> OK.  Here's a stripped-down case that tries to replicate your situation.
> It does not fail for me, and I think it's portable (to non-w32 hosts
> that support dlopen(); I did not use libltdl in this case; and I did
> use one internal detail by referring to lt_cv_dlopen_libs).
> 
> Could you change it in a way so that it exposes the issue you are
> seeing (or show how you can make it fail)?  Thanks.

Okay, I was able to build your stripped-down case.  It produced the
output that you expected (8 and 0).  I tried out our situation, which is
a little different:

1. We don't use automake (we'll ignore that for now)
2. We do use libltdl and I've changed the stripped-down case to reflect
that.
3. We need more than one object in libfoo.la so I created a libfooY.c
4. libfooY.c just contains the Y function from libfoo.c.
5. The diffs for all this are below.

After making my changes, it works. I was expecting to get something
like:

./bar
/proj/libtool/test/.libs/lt-bar: symbol lookup
error: /proj/libtool/test/.libs/barmod.so: undefined symbol: Y

But instead, it just works. So, it seems, that linking all the libraries
into the module doesn't cause duplicate symbols, at least for simple C
programs. Our problem may actually be C++.  I'll look at that before
taking any more of your time.

Thanks for your help!

Reid.

Here' are the diffs if you care to see what I did ..

diff -u test.orig/configure.ac test/configure.ac
--- test.orig/configure.ac  2006-08-07 13:00:03.0 -0700
+++ test/configure.ac   2006-08-07 12:45:22.0 -0700
@@ -1,8 +1,7 @@
-AC_INIT(dup,1,devnull)
+AC_INIT([dup],[1],[devnull])
 AM_INIT_AUTOMAKE(foreign)
 AC_PROG_CC
 AC_LIBTOOL_DLOPEN
 AC_PROG_LIBTOOL
-AC_SUBST([LIBDL], [$lt_cv_dlopen_libs])
 AC_CONFIG_FILES(Makefile)
 AC_OUTPUT

diff -u test.orig/Makefile.am test/Makefile.am
--- test.orig/Makefile.am   2006-08-07 13:00:25.0 -0700
+++ test/Makefile.am2006-08-07 12:57:42.0 -0700
@@ -1,7 +1,7 @@
 lib_LTLIBRARIES = libfoo.la
 bin_PROGRAMS = bar
-bar_LDADD = libfoo.la
-bar_LDADD = libfoo.la $(LIBDL)
+bar_LDADD = libfoo.la -lltdl
+bar_LDFLAGS =
 pkglib_LTLIBRARIES = barmod.la
 barmod_la_LDFLAGS = -module
 barmod_la_LIBADD = libfoo.la


diff -u test.orig/bar.c test/bar.c
--- test.orig/bar.c 2006-08-07 12:59:14.0 -0700
+++ test/bar.c  2006-08-07 12:57:14.0 -0700
@@ -1,28 +1,32 @@
-#include 
+#include 
 #include 
 #include 

 extern int X (void);

+typedef int (*intfunc_t)(void);
+
 int main (int argc, char **argv)
 {
-  void *handle;
-  int (*barmod)(void);
-  char *error;
+  lt_dlhandle handle;
+  intfunc_t barmod;
+  const char *error;
+
+  lt_dlinit();

-  handle = dlopen ("barmod.so", RTLD_LAZY);
+  handle = lt_dlopen ("barmod.so");
   if (!handle) {
-fprintf (stderr, "%s\n", dlerror ());
+fprintf (stderr, "%s\n", lt_dlerror ());
 exit(EXIT_FAILURE);
   }

-  *(void **) (&barmod) = dlsym (handle, "barmod");
-  if ((error = dlerror()) != NULL)  {
+  barmod = (intfunc_t) lt_dlsym (handle, "barmod");
+  if ((error = lt_dlerror()) != NULL)  {
 fprintf (stderr, "%s\n", error);
 exit (EXIT_FAILURE);
   }

   printf ("%d\n", (*barmod) ());
-  dlclose (handle);
+  lt_dlclose (handle);
   return X () - 2;
 }

diff -u test.orig/libfoo.c test/libfoo.c
--- test.orig/libfoo.c  2006-08-07 12:59:14.0 -0700
+++ test/libfoo.c   2006-08-07 12:47:13.0 -0700
@@ -1,2 +1 @@
 int X (void) { return 2; }
-double Y (void) { return 3.14; }

cat test/libfooY.c
double Y (void) { return 3.14; }





___
http://lists.gnu.org/mailman/listinfo/libtool