From 5b79e16a32042c9a5dd08ab7f3f9668865e1b0ae Mon Sep 17 00:00:00 2001 From: Ralf Wildenhues Date: Sun, 4 Apr 2010 10:56:47 +0200 Subject: [PATCH] Uniform const'ness of symlist variable lt_preloaded_symbols. On some systems, lt_preloaded_symbols may not be declared const due to relocation issues. C99 requires qualification to match for compatible declarations, so ensure we declare const'ness in the same way everywhere; link-time optimization may otherwise rightfully complain about inconsistencies. Since ltdl.h may not depend upon config.h, rely on system defines for choosing const'ness. * NEWS: Update. * doc/libtool.texi (Dlpreopening): Document this issue. * libltdl/config/ltmain.m4sh (func_generate_dlsyms): [__WINDOWS__, __CYGWIN__, _WIN32_WCE]: Define LT_DLSYM_CONST according to system defines. Remove old shell cruft. Use LT_DLSYM_CONST for lt_${my_prefix}_LTX_preloaded_symbols. * libltdl/libltdl/lt_system.h (LT_DLSYM_CONST): Likewise, define LT_DLSYM_CONST according to system defines. * tests/demo/foo.h (LT_DLSYM_CONST): Likewise. * tests/pdemo/foo.h (LT_DLSYM_CONST): Likewise. * tests/demo/dlmain.c (lt_dlsymlist): Use LT_DLSYM_CONST. * tests/pdemo/longer_file_name_dlmain.c (lt_dlsymlist): Likewise. * libltdl/m4/libtool.m4 (_LT_CMD_GLOBAL_SYMBOLS): Likewise for configure test code. * libltdl/ltdl.c (preloaded_symbols): Use LT_DLSYM_CONST. * libltdl/ltdl.h (LTDL_SET_PRELOADED_SYMBOLS): Likewise. Signed-off-by: Ralf Wildenhues --- ChangeLog | 28 +++++++++++++++++++++++ NEWS | 3 +++ doc/libtool.texi | 3 +++ libltdl/config/ltmain.m4sh | 33 ++++++++++++--------------- libltdl/libltdl/lt_system.h | 14 +++++++++++- libltdl/ltdl.c | 2 +- libltdl/ltdl.h | 2 +- libltdl/m4/libtool.m4 | 14 +++++++++++- tests/demo/dlmain.c | 2 +- tests/demo/foo.h | 14 +++++++++++- tests/pdemo/foo.h | 14 +++++++++++- tests/pdemo/longer_file_name_dlmain.c | 2 +- 12 files changed, 104 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index 5df42d403..6537ede6a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,31 @@ +2010-08-28 Ralf Wildenhues + + Uniform const'ness of symlist variable lt_preloaded_symbols. + On some systems, lt_preloaded_symbols may not be declared + const due to relocation issues. C99 requires qualification to + match for compatible declarations, so ensure we declare + const'ness in the same way everywhere; link-time optimization + may otherwise rightfully complain about inconsistencies. + Since ltdl.h may not depend upon config.h, rely on system + defines for choosing const'ness. + * NEWS: Update. + * doc/libtool.texi (Dlpreopening): Document this issue. + * libltdl/config/ltmain.m4sh (func_generate_dlsyms): + [__WINDOWS__, __CYGWIN__, _WIN32_WCE]: Define LT_DLSYM_CONST + according to system defines. Remove old shell cruft. Use + LT_DLSYM_CONST for lt_${my_prefix}_LTX_preloaded_symbols. + * libltdl/libltdl/lt_system.h (LT_DLSYM_CONST): Likewise, + define LT_DLSYM_CONST according to system defines. + * tests/demo/foo.h (LT_DLSYM_CONST): Likewise. + * tests/pdemo/foo.h (LT_DLSYM_CONST): Likewise. + * tests/demo/dlmain.c (lt_dlsymlist): Use LT_DLSYM_CONST. + * tests/pdemo/longer_file_name_dlmain.c (lt_dlsymlist): + Likewise. + * libltdl/m4/libtool.m4 (_LT_CMD_GLOBAL_SYMBOLS): Likewise + for configure test code. + * libltdl/ltdl.c (preloaded_symbols): Use LT_DLSYM_CONST. + * libltdl/ltdl.h (LTDL_SET_PRELOADED_SYMBOLS): Likewise. + 2010-08-28 Dave Korn Ensure cwrapper magic string is not optimized away. diff --git a/NEWS b/NEWS index ba7ce0025..688bdca6b 100644 --- a/NEWS +++ b/NEWS @@ -83,6 +83,9 @@ New in 2.2.7b 2010-05-20: git version 2.2.7a, Libtool team: options that begin with '--lt-*' from the argument list before launching (uninstalled) programs. Any '--lt-*' option on the command line not recognized by the wrapper will result in an error. + - The type of the symbol lists variables (lt_*_LTX_preloaded_symbols) has + been fixed in the manual and in a couple of tests to match the actual + implementation. * Changes in supported systems or compilers: diff --git a/doc/libtool.texi b/doc/libtool.texi index be7d3bfa0..a3f1c59e6 100644 --- a/doc/libtool.texi +++ b/doc/libtool.texi @@ -3421,6 +3421,9 @@ The last element of all has a @var{name} and @var{address} of To facilitate inclusion of symbol lists into libraries, @code{lt_preloaded_symbols} is @samp{#define}d to a suitably unique name in @file{ltdl.h}. + +This variable may not be declared @code{const} on some systems due to +relocation issues. @end deftypevar Some compilers may allow identifiers that are not valid in ANSI C, such diff --git a/libltdl/config/ltmain.m4sh b/libltdl/config/ltmain.m4sh index 746718ab8..a7da74ffb 100644 --- a/libltdl/config/ltmain.m4sh +++ b/libltdl/config/ltmain.m4sh @@ -2004,6 +2004,18 @@ extern \"C\" { #pragma GCC diagnostic ignored \"-Wstrict-prototypes\" #endif +/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests. */ +#if defined(__WINDOWS__) || defined(__CYGWIN__) || defined(_WIN32_WCE) +/* DATA imports from DLLs on WIN32 con't be const, because runtime + relocations are performed -- see ld's documentation on pseudo-relocs. */ +# define LT_DLSYM_CONST +#elif defined(__osf__) +/* This system does not cope well with relocations in const data. */ +# define LT_DLSYM_CONST +#else +# define LT_DLSYM_CONST const +#endif + /* External symbol declarations for the compiler. */\ " @@ -2145,26 +2157,9 @@ typedef struct { const char *name; void *address; } lt_dlsymlist; -" - case $host in - *cygwin* | *mingw* | *cegcc* ) - echo >> "$output_objdir/$my_dlsyms" "\ -/* DATA imports from DLLs on WIN32 con't be const, because - runtime relocations are performed -- see ld's documentation - on pseudo-relocs. */" - lt_dlsym_const= ;; - *osf5*) - echo >> "$output_objdir/$my_dlsyms" "\ -/* This system does not cope well with relocations in const data */" - lt_dlsym_const= ;; - *) - lt_dlsym_const=const ;; - esac - - echo >> "$output_objdir/$my_dlsyms" "\ -extern $lt_dlsym_const lt_dlsymlist +extern LT_DLSYM_CONST lt_dlsymlist lt_${my_prefix}_LTX_preloaded_symbols[]; -$lt_dlsym_const lt_dlsymlist +LT_DLSYM_CONST lt_dlsymlist lt_${my_prefix}_LTX_preloaded_symbols[] = {\ { \"$my_originator\", (void *) 0 }," diff --git a/libltdl/libltdl/lt_system.h b/libltdl/libltdl/lt_system.h index dab2ab6b3..a8481d667 100644 --- a/libltdl/libltdl/lt_system.h +++ b/libltdl/libltdl/lt_system.h @@ -1,6 +1,6 @@ /* lt_system.h -- system portability abstraction layer - Copyright (C) 2004, 2007 Free Software Foundation, Inc. + Copyright (C) 2004, 2007, 2010 Free Software Foundation, Inc. Written by Gary V. Vaughan, 2004 NOTE: The canonical source of this file is maintained with the @@ -76,6 +76,18 @@ or obtained by writing to the Free Software Foundation, Inc., # endif #endif +/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests. */ +#if defined(__WINDOWS__) || defined(__CYGWIN__) || defined(_WIN32_WCE) +/* DATA imports from DLLs on WIN32 con't be const, because runtime + relocations are performed -- see ld's documentation on pseudo-relocs. */ +# define LT_DLSYM_CONST +#elif defined(__osf__) +/* This system does not cope well with relocations in const data. */ +# define LT_DLSYM_CONST +#else +# define LT_DLSYM_CONST const +#endif + /* Canonicalise Windows and Cygwin recognition macros. To match the values set by recent Cygwin compilers, make sure that if __CYGWIN__ is defined (after canonicalisation), __WINDOWS__ is NOT! */ diff --git a/libltdl/ltdl.c b/libltdl/ltdl.c index 992584c9c..be1e4c093 100644 --- a/libltdl/ltdl.c +++ b/libltdl/ltdl.c @@ -213,7 +213,7 @@ LT_BEGIN_C_DECLS LT_SCOPE const lt_dlvtable * get_vtable (lt_user_data data); LT_END_C_DECLS #ifdef HAVE_LIBDLLOADER -extern lt_dlsymlist preloaded_symbols[]; +extern LT_DLSYM_CONST lt_dlsymlist preloaded_symbols[]; #endif /* Initialize libltdl. */ diff --git a/libltdl/ltdl.h b/libltdl/ltdl.h index 8b516ad64..5154da1aa 100644 --- a/libltdl/ltdl.h +++ b/libltdl/ltdl.h @@ -103,7 +103,7 @@ LT_SCOPE int lt_dlpreload_open (const char *originator, #define lt_preloaded_symbols lt__PROGRAM__LTX_preloaded_symbols #define LTDL_SET_PRELOADED_SYMBOLS() LT_STMT_START{ \ - extern const lt_dlsymlist lt_preloaded_symbols[]; \ + extern LT_DLSYM_CONST lt_dlsymlist lt_preloaded_symbols[]; \ lt_dlpreload_default(lt_preloaded_symbols); \ }LT_STMT_END diff --git a/libltdl/m4/libtool.m4 b/libltdl/m4/libtool.m4 index 305e2d84c..2f6269107 100644 --- a/libltdl/m4/libtool.m4 +++ b/libltdl/m4/libtool.m4 @@ -3647,6 +3647,18 @@ _LT_EOF if $GREP ' nm_test_var$' "$nlist" >/dev/null; then if $GREP ' nm_test_func$' "$nlist" >/dev/null; then cat <<_LT_EOF > conftest.$ac_ext +/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests. */ +#if defined(__WINDOWS__) || defined(__CYGWIN__) || defined(_WIN32_WCE) +/* DATA imports from DLLs on WIN32 con't be const, because runtime + relocations are performed -- see ld's documentation on pseudo-relocs. */ +# define LT@&t@_DLSYM_CONST +#elif defined(__osf__) +/* This system does not cope well with relocations in const data. */ +# define LT@&t@_DLSYM_CONST +#else +# define LT@&t@_DLSYM_CONST const +#endif + #ifdef __cplusplus extern "C" { #endif @@ -3658,7 +3670,7 @@ _LT_EOF cat <<_LT_EOF >> conftest.$ac_ext /* The mapping between symbol names and symbols. */ -const struct { +LT@&t@_DLSYM_CONST struct { const char *name; void *address; } diff --git a/tests/demo/dlmain.c b/tests/demo/dlmain.c index c970998d4..8c8be09e7 100644 --- a/tests/demo/dlmain.c +++ b/tests/demo/dlmain.c @@ -34,7 +34,7 @@ typedef struct lt_ptr_t address; } lt_dlsymlist; -extern const lt_dlsymlist lt_preloaded_symbols[]; +extern LT_DLSYM_CONST lt_dlsymlist lt_preloaded_symbols[]; int main () diff --git a/tests/demo/foo.h b/tests/demo/foo.h index 287f9c318..838264ea3 100644 --- a/tests/demo/foo.h +++ b/tests/demo/foo.h @@ -1,6 +1,6 @@ /* foo.h -- interface to the libfoo library - Copyright (C) 1996-1999 Free Software Foundation, Inc. + Copyright (C) 1996-1999, 2010 Free Software Foundation, Inc. Written by Gord Matzigkeit, 1996 This file is part of GNU Libtool. @@ -62,6 +62,18 @@ or obtained by writing to the Free Software Foundation, Inc., # define lt_ptr_t char* #endif +/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests. */ +#if defined(__WINDOWS__) || defined(__CYGWIN__) || defined(_WIN32_WCE) +/* DATA imports from DLLs on WIN32 con't be const, because runtime + relocations are performed -- see ld's documentation on pseudo-relocs. */ +# define LT_DLSYM_CONST +#elif defined(__osf__) +/* This system does not cope well with relocations in const data. */ +# define LT_DLSYM_CONST +#else +# define LT_DLSYM_CONST const +#endif + /* Silly constants that the functions return. */ #define HELLO_RET 0xe110 #define FOO_RET 0xf00 diff --git a/tests/pdemo/foo.h b/tests/pdemo/foo.h index f09db19f8..dd4e86d04 100644 --- a/tests/pdemo/foo.h +++ b/tests/pdemo/foo.h @@ -1,6 +1,6 @@ /* foo.h -- interface to the libfoo library - Copyright (C) 1996-1999 Free Software Foundation, Inc. + Copyright (C) 1996-1999, 2010 Free Software Foundation, Inc. Written by Gord Matzigkeit, 1996 This file is part of GNU Libtool. @@ -61,6 +61,18 @@ or obtained by writing to the Free Software Foundation, Inc., # define lt_ptr_t char* #endif +/* Keep this code in sync between libtool.m4, ltmain, lt_system.h, and tests. */ +#if defined(__WINDOWS__) || defined(__CYGWIN__) || defined(_WIN32_WCE) +/* DATA imports from DLLs on WIN32 con't be const, because runtime + relocations are performed -- see ld's documentation on pseudo-relocs. */ +# define LT_DLSYM_CONST +#elif defined(__osf__) +/* This system does not cope well with relocations in const data. */ +# define LT_DLSYM_CONST +#else +# define LT_DLSYM_CONST const +#endif + #ifdef __CYGWIN32__ # ifdef LIBFOO_DLL /* need some (as yet non-existant) automake magic to tell diff --git a/tests/pdemo/longer_file_name_dlmain.c b/tests/pdemo/longer_file_name_dlmain.c index ef1e4c5b4..ad223dcec 100644 --- a/tests/pdemo/longer_file_name_dlmain.c +++ b/tests/pdemo/longer_file_name_dlmain.c @@ -34,7 +34,7 @@ typedef struct lt_ptr_t address; } lt_dlsymlist; -extern const lt_dlsymlist lt_preloaded_symbols[]; +extern LT_DLSYM_CONST lt_dlsymlist lt_preloaded_symbols[]; int main (int argc, char **argv) -- 2.47.2