From 7fe8f5c785897cacf3abcacfee1a7d10455f0054 Mon Sep 17 00:00:00 2001 From: "Gary V. Vaughan" Date: Mon, 21 Dec 1998 13:04:14 +0000 Subject: [PATCH] misc win32 cleanups --- ChangeLog | 36 ++++++++++++++++++++++++++++++++++++ demo/dlmain.c | 32 ++++++++++++++++++++++++-------- demo/foo.c | 5 ++++- demo/foo.h | 25 +++++++++++++++++++++++-- demo/hello.c | 3 +++ libltdl/configure.in | 22 +++++++++------------- libtool.m4 | 16 +++++++--------- ltconfig.in | 12 ++++++------ ltmain.in | 28 ++++++++++++++-------------- 9 files changed, 126 insertions(+), 53 deletions(-) diff --git a/ChangeLog b/ChangeLog index 3cff6ec0b..d3f9583e8 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,39 @@ +1998-12-21 Gary V. Vaughan + + * libtool.m4 (AM_SYS_NM_PARSE): apparently __ptr_t is predefined + on some systems - use lt_ptr_t instead. + * ltconfig.in: ditto. + * ltmain.in: ditto. + + * libtool.m4 (AM_SYS_SYMBOL_UNDERSCORE): use an AC_SUBST to pass + the result of this into the compile rather than AC_DEFINE which + breaks when building with older versions of autoconf. + * ltconfig.in (symxfrm): Don't put the leading underscore back + with the global_symbol_pipe. + * demo/dlmain.c (main): No need to specialcase underscores in + dld_preloaded_symbols - it is fixed by symxfrm above! + * libltdl/configure.in: use AM_SYS_SYMBOL_UNDERSCORE from + libtool.m4 rather than reincent the wheel here =)O| + + * ltmain.in: Fix deplibs methods to not rely on a.out (cygwin + uses a.exe!). + + * libltdl/configure.in: Cleanups - fix header comment and emacs + local-vars. + + * demo/dlmain.c (win32_force_data_import_address): a nasty hack + to force the address of imported data symbols into + dld_preloaded_symbols on win32, which does data imports + differently to function imports (sheesh!). This functionality + needs to be moved into the dld_preloaded_symbols generation code. + demo/helldl with static linking is broken on win32 by this change, + probably until after libtool-1.3 =(O| + * demo/foo.h: make sure __CYGWIN32__ is always defined on cygwin32 + systems. Use the correct __declspec macro for lib exports/imports + on cygwin32. + * demo/foo.c, demo/hello.c: Make sure we tell foo.h that these + sources are inside libfoo, and want to export symbols. + 1998-12-20 Thomas Tanner * autogen: configure demo, depdemo, libltdl and mdemo diff --git a/demo/dlmain.c b/demo/dlmain.c index 1374aa49e..c328e4044 100644 --- a/demo/dlmain.c +++ b/demo/dlmain.c @@ -29,6 +29,25 @@ struct dld_symlist extern struct dld_symlist dld_preloaded_symbols[]; +#ifdef __CYGWIN32__ +int +win32_force_data_import_address __P((void)) +{ + struct dld_symlist *s; + + s = dld_preloaded_symbols; + while (s->name) + { + if (!strcmp ("nothing", s->name)) + s->address = ¬hing; + s++; + } + + return 0; +} +#endif + + int main (argc, argv) int argc; @@ -41,20 +60,17 @@ main (argc, argv) printf ("Welcome to *modular* GNU Hell!\n"); +#ifdef __CYGWIN32__ + /* runtime table initialisation */ + (void) win32_force_data_import_address(); +#endif + /* Look up the symbols we require for this demonstration. */ s = dld_preloaded_symbols; while (s->name) { if (s->address) { char *name = s->name; -#ifdef WITH_SYMBOL_UNDERSCORE - if (*name != '_') - { - fprintf(stderr, "ERROR: configure detected leading underscores incorrectly.\n"); - exit(1); - } - name++; -#endif printf ("found symbol: %s\n", name); if (!strcmp ("hello", name)) phello = s->address; diff --git a/demo/foo.c b/demo/foo.c index 0a8c318ab..d700b5755 100644 --- a/demo/foo.c +++ b/demo/foo.c @@ -18,12 +18,15 @@ along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ +#define _LIBFOO_COMPILATION_ #include "foo.h" +#undef _LIBFOO_COMPILATION + #include #include /* Give a global variable definition. */ -int nothing; +int nothing = FOO_RET; int foo () diff --git a/demo/foo.h b/demo/foo.h index 2a17a0ae3..b450605c4 100644 --- a/demo/foo.h +++ b/demo/foo.h @@ -22,6 +22,16 @@ USA. */ #ifndef _FOO_H_ #define _FOO_H_ 1 +/* At some point, cygwin will stop defining __CYGWIN32__, but b19 and + * earlier do not define __CYGWIN__. This snippit allows us to check + * for __CYGWIN32__ reliably for both old and (probable) future releases. + */ +#ifdef __CYGWIN__ +# ifndef __CYGWIN32__ +# define __CYGWIN32__ +# endif +#endif + /* __BEGIN_DECLS should be used at the beginning of your declarations, so that C++ compilers don't mangle their names. Use __END_DECLS at the end of C declarations. */ @@ -39,21 +49,32 @@ USA. */ that don't understand ANSI C prototypes still work, and ANSI C compilers can issue warnings about type mismatches. */ #undef __P -#if defined (__STDC__) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(WIN32) || defined(__cplusplus) +#if defined (__STDC__) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(__CYGWIN32__) || defined(__cplusplus) # define __P(protos) protos #else # define __P(protos) () #endif +#ifdef __CYGWIN32__ +# ifdef _LIBFOO_COMPILATION_ +# define EXTERN __declspec(dllexport) +# else +# define EXTERN extern __declspec(dllimport) +# endif +#else +# define EXTERN extern +#endif + /* Silly constants that the functions return. */ #define HELLO_RET 0xe110 #define FOO_RET 0xf00 + /* Declarations. Note the wonderful use of the above macros. */ __BEGIN_DECLS int foo __P((void)); int hello __P((void)); -extern int nothing; +EXTERN int nothing; __END_DECLS #endif /* !_FOO_H_ */ diff --git a/demo/hello.c b/demo/hello.c index b82bfe5ae..c20cb75f1 100644 --- a/demo/hello.c +++ b/demo/hello.c @@ -18,7 +18,10 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ /* Written by Gordon Matzigkeit */ +#define _LIBFOO_COMPILATION #include "foo.h" +#undef _LIBFOO_COMPILATION + #include int diff --git a/libltdl/configure.in b/libltdl/configure.in index a1dfbb911..02a47097a 100644 --- a/libltdl/configure.in +++ b/libltdl/configure.in @@ -1,4 +1,5 @@ -dnl Initialize the hell package. +dnl Process this file with autoconf to create configure. +dnl Initialize the ltdl package. AC_INIT(ltdl.c) AM_INIT_AUTOMAKE(libltdl,1.0) @@ -32,18 +33,8 @@ AC_CHECK_FUNCS(dlopen, AC_DEFINE(HAVE_LIBDL), ) AC_SUBST(LIBADD_DL) -AC_CACHE_CHECK([for underscore before symbols], libltdl_cv_uscore, [ - echo "main(){int i=1;} fnord(){int i=23; int ltuae=42;}" > conftest.c - ${CC} -c conftest.c > /dev/null - if (nm conftest.$ac_objext | grep _fnord) > /dev/null; then - libltdl_cv_uscore=yes - else - libltdl_cv_uscore=no - fi - rm -f conftest* -]) - -if test x"$libltdl_cv_uscore" = xyes; then +AM_SYS_SYMBOL_UNDERSCORE +if test x"$USE_SYMBOL_UNDERSCORE" = xyes; then if test x"$ac_cv_func_dlopen" = xyes || test x"$ac_cv_lib_dl_dlopen" = xyes ; then AC_CACHE_CHECK([whether we have to add an underscore for dlsym], @@ -67,3 +58,8 @@ fi dnl Output the makefile AC_OUTPUT(Makefile) + +# Local Variables: +# mode:shell-script +# sh-indentation:2 +# End: diff --git a/libtool.m4 b/libtool.m4 index 80265f12c..42c48ecb3 100644 --- a/libtool.m4 +++ b/libtool.m4 @@ -428,9 +428,9 @@ EOF cat <> conftest.c #if defined (__STDC__) && __STDC__ -# define __ptr_t void * +# define lt_ptr_t void * #else -# define __ptr_t char * +# define lt_ptr_t char * #endif /* The number of symbols in dld_preloaded_symbols, -1 if unsorted. */ @@ -439,16 +439,16 @@ int dld_preloaded_symbol_count = $ac_count; /* The mapping between symbol names and symbols. */ struct { char *name; - __ptr_t address; + lt_ptr_t address; } changequote(,)dnl dld_preloaded_symbols[] = changequote([,])dnl { EOF - sed 's/^\(.*\) \(.*\)$/ {"\1", (__ptr_t) \&\2},/' < "$ac_nlist" >> conftest.c + sed 's/^\(.*\) \(.*\)$/ {"\1", (lt_ptr_t) \&\2},/' < "$ac_nlist" >> conftest.c cat <<\EOF >> conftest.c - {0, (__ptr_t) 0} + {0, (lt_ptr_t) 0} }; #ifdef __cplusplus @@ -537,8 +537,6 @@ fi rm -rf conftest* ]) AC_MSG_RESULT($ac_cv_sys_symbol_underscore) -if test x$ac_cv_sys_symbol_underscore = xyes; then - AC_DEFINE(WITH_SYMBOL_UNDERSCORE,1, - [define if compiled symbols have a leading underscore]) -fi +USE_SYMBOL_UNDERSCORE=${ac_cv_sys_symbol_underscore=no} +AC_SUBST(USE_SYMBOL_UNDERSCORE)dnl ]) diff --git a/ltconfig.in b/ltconfig.in index 19db0e5be..21be389ca 100755 --- a/ltconfig.in +++ b/ltconfig.in @@ -1382,7 +1382,6 @@ aix*) ;; sunos* | cygwin32* | mingw32*) sympat='_\([_A-Za-z][_A-Za-z0-9]*\)' - symxfrm='_\1 \1' ;; irix*) # Cannot use undefined symbols on IRIX because inlined functions mess us up. @@ -1455,9 +1454,9 @@ EOF cat <> conftest.c #if defined (__STDC__) && __STDC__ -# define __ptr_t void * +# define lt_ptr_t void * #else -# define __ptr_t char * +# define lt_ptr_t char * #endif /* The number of symbols in dld_preloaded_symbols, -1 if unsorted. */ @@ -1466,14 +1465,14 @@ int dld_preloaded_symbol_count = $count; /* The mapping between symbol names and symbols. */ struct { char *name; - __ptr_t address; + lt_ptr_t address; } dld_preloaded_symbols[] = { EOF - sed 's/^\(.*\) \(.*\)$/ {"\1", (__ptr_t) \&\2},/' < "$nlist" >> conftest.c + sed 's/^\(.*\) \(.*\)$/ {"\1", (lt_ptr_t) \&\2},/' < "$nlist" >> conftest.c cat <<\EOF >> conftest.c - {0, (__ptr_t) 0} + {0, (lt_ptr_t) 0} }; #ifdef __cplusplus @@ -1606,6 +1605,7 @@ cygwin32* | mingw32*) dynamic_linker='Win32 ld.exe' libname_spec='$name' need_lib_prefix=no + # FIXME: first we should search . and the directory the executable is in shlibpath_var=PATH ;; diff --git a/ltmain.in b/ltmain.in index 2b80b72e7..732473b0b 100644 --- a/ltmain.in +++ b/ltmain.in @@ -1399,10 +1399,10 @@ compiler." cat > conftest.c <> "$output_objdir/$dlsyms" "\ - {\"${output}\", (__ptr_t) 0}," - sed 's/^\(.*\)/ {"\1", (__ptr_t) \&\1},/' < "$export_symbols" >> "$output_objdir/$dlsyms" + {\"${output}\", (lt_ptr_t) 0}," + sed 's/^\(.*\)/ {"\1", (lt_ptr_t) \&\1},/' < "$export_symbols" >> "$output_objdir/$dlsyms" fi for arg in $dlprefiles; do name=`echo "$arg" | sed -e 's%^.*/%%'` echo >> "$output_objdir/$dlsyms" "\ - {\"$name\", (__ptr_t) 0}," + {\"$name\", (lt_ptr_t) 0}," eval "$NM $arg | $global_symbol_pipe > '$nlist'" if test -f "$nlist"; then - sed 's/^\(.*\) \(.*\)$/ {"\1", (__ptr_t) \&\2},/' < "$nlist" >> "$output_objdir/$dlsyms" + sed 's/^\(.*\) \(.*\)$/ {"\1", (lt_ptr_t) \&\2},/' < "$nlist" >> "$output_objdir/$dlsyms" else echo '/* NONE */' >> "$output_objdir/$dlsyms" fi done $echo >> "$output_objdir/$dlsyms" "\ - {0, (__ptr_t) 0} + {0, (lt_ptr_t) 0} }; #ifdef __cplusplus -- 2.47.2