* doc/libtool.texi (Dlpreopening): Remove broken documentation of lt_dlsymbol and lt_dlsymlist. Document typedef lt_dlsymlist and symbol lt_preloaded_symbols according to the implementation. * tests/demo/dlmain.c (lt_symlist): Make struct anonymous ... (lt_dlsymlist): ... and typedef to this name. (lt_preloaded_symbols, main): Adjust. * tests/pdemo/longer_file_name_dlmain.c: Likewise.
Signed-off-by: Ralf Wildenhues <ralf.wildenh...@gmx.de> --- Hello, Contrary to popular belief, of these five, A) struct lt_symlist { const char *name; void *address; }; B) struct lt_dlsymlist { const char *name; void *address; }; C) typedef struct { const char *name; void *address; } lt_dlsymlist; D) struct { const char *name; void *address; } OBJECT; E) struct lt_dlsymbol { const char *name; void *address; }; only (C) and (D) name pairwise compatible types, at least in C99 (in C89, things may be different). Thus, when used in different translation units as types for one variable, that constitutes undefined behavior. 'gcc -flto' is smart enough to detect this and warn in some cases. Luckily it doesn't act adversely upon it (yet). The Libtool source code is dumb enough to have used all five of these declarations (we can blissfully ignore the s/void */char */ that was also used for pre-ANSI compilers): Libtool 1.5.26 used (C) with extern const lt_dlsymlist lt_preloaded_symbols[]; in the declaration in ltdl.h, and (D) in the definition in ltmain.in, (with s/OBJECT/lt_preloaded_symbols[] = .../). The 1.5.26 manual documented (B) but then declared @deftypevar {const lt_dlsymlist *} lt_preloaded_symbols which is just plain incompatible to the source code even in C89. The 1.5.26 as well as master 'demo' and 'pdemo' test cases use (A) with extern const struct lt_symlist lt_preloaded_symbols[]; which may have been OK according to C89, but (A) doesn't match the documentation either. ------- Libtool master has more than one symlist (lt_preloaded_symbols is #defined to some other string matching lt_*_LTX_preloaded_symbols). The ltdl.h header uses (C) as declaration, with extern const lt_dlsymlist lt_preloaded_symbols[]; and ltmain.m4sh uses (C) as well, except that the 'const' is omitted on systems which have trouble with relocations in const data or perform relocations at runtime (osf5 the former, cygwin, mingw, cegcc, the latter). This non-const-ness is not reflected in the declaration of lt__PROGRAM__LTX_preloaded_symbols in ltdl.h, nor that of lt_LTDLOPEN_LTX_preloaded_symbols in ltdl.c. In the manual, master uses (E), with @deftypefn {Structure} {struct} lt_dlsymlist @{ @w{const char *...@var{originator +};} @w{const lt_dlsymbol @var{symbols}[];} @} Wow, that's a plain incompatibility with (C) in any C dialect! ------ Thus far the analysis. Question is, how do we fix it. My preference would be to fix the manual and the test cases, since the actual code has been fairly stable. Then it only remains to fix the const-ness in the declaration. In a followup. OK to apply? Thanks, Ralf ChangeLog | 9 +++++++++ doc/libtool.texi | 26 ++++++++++---------------- tests/demo/dlmain.c | 11 ++++++----- tests/pdemo/longer_file_name_dlmain.c | 11 ++++++----- 4 files changed, 31 insertions(+), 26 deletions(-) diff --git a/ChangeLog b/ChangeLog index b324240..c082cee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,14 @@ 2010-04-04 Ralf Wildenhues <ralf.wildenh...@gmx.de> + Fix incompatible struct declarations. + * doc/libtool.texi (Dlpreopening): Remove broken documentation + of lt_dlsymbol and lt_dlsymlist. Document typedef lt_dlsymlist + and symbol lt_preloaded_symbols according to the implementation. + * tests/demo/dlmain.c (lt_symlist): Make struct anonymous ... + (lt_dlsymlist): ... and typedef to this name. + (lt_preloaded_symbols, main): Adjust. + * tests/pdemo/longer_file_name_dlmain.c: Likewise. + Support GCC LTO on GNU/Linux. * NEWS: Update. * libltdl/config/ltmain.m4sh (func_mode_link): Allow through diff --git a/doc/libtool.texi b/doc/libtool.texi index 323bf4e..f73f5a7 100644 --- a/doc/libtool.texi +++ b/doc/libtool.texi @@ -3388,25 +3388,15 @@ you must declare the objects you want your application to dlopen by using the @option{-dlopen} or @option{-dlpreopen} flags when you link your program (@pxref{Link mode}). -...@deftypefn {Structure} {struct} lt_dlsymbol @{ @w{const char *...@var{name};} @w{void *...@var{address};} @} +...@deftp {Data Type} {lt_dlsymlist} typedef struct @ + @{ @w{const char *...@var{name};} @w{void *...@var{address};} @} lt_dlsymlist The @var{name} attribute is a null-terminated character string of the symbol name, such as @code{"fprintf"}. The @var{address} attribute is a generic pointer to the appropriate object, such as @code{&fprintf}. -...@end deftypefn - -...@deftypefn {Structure} {struct} lt_dlsymlist @{ @w{const char *...@var{originator};} @w{const lt_dlsymbol @var{symbols}[];} @} -The @var{originator} attribute is a null-terminated character string, -naming the compilation unit that @var{symbols} were preloaded on -behalf of. This is usually the basename of a library, -...@file{libltdl.la} has a corresponding @var{originator} value of -...@samp{libltdl}; if the @var{symbols} are for the benefit of the -application proper, then @var{originator} is @samp{@@PROGRAM@@}, -though Libtool takes care of that detail if you use -...@samp{ltdl_set_preloaded_symbols}. -...@end deftypefn +...@end deftp -...@deftypevar {const lt_dlsymlist *} lt_preloaded_symbols -An array of @var{lt_symbol} structures, representing all the preloaded +...@deftypevar {const lt_dlsymlist } lt_preloaded_symbols[] +An array of @var{lt_dlsymlist} structures, representing all the preloaded symbols linked into the program proper. For each module @option{-dlpreopen}ed by the Libtool linked program there is an element with the @var{name} of the module and an @var{address} @@ -3414,6 +3404,10 @@ of @code{0}, followed by all symbols exported from this file. For the executable itself the special name @samp{@@PROGRAM@@} is used. The last element of all has a @var{name} and @var{address} of @code{0}. + +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}. @end deftypevar Some compilers may allow identifiers that are not valid in ANSI C, such diff --git a/tests/demo/dlmain.c b/tests/demo/dlmain.c index 0d42d88..c970998 100644 --- a/tests/demo/dlmain.c +++ b/tests/demo/dlmain.c @@ -1,6 +1,7 @@ /* dlmain.c -- hello test program that uses simulated dynamic linking - Copyright (C) 1996-1999, 2004, 2006, 2007 Free Software Foundation, Inc. + Copyright (C) 1996-1999, 2004, 2006, 2007, 2010 Free Software + Foundation, Inc. This file is part of GNU Libtool. @@ -27,18 +28,18 @@ or obtained by writing to the Free Software Foundation, Inc., #define lt_preloaded_symbols lt__PROGRAM__LTX_preloaded_symbols -struct lt_symlist +typedef struct { const char *name; lt_ptr_t address; -}; +} lt_dlsymlist; -extern const struct lt_symlist lt_preloaded_symbols[]; +extern const lt_dlsymlist lt_preloaded_symbols[]; int main () { - const struct lt_symlist *s; + const lt_dlsymlist *s; int (*pfoo)() = 0; int (*phello)() = 0; int *pnothing = 0; diff --git a/tests/pdemo/longer_file_name_dlmain.c b/tests/pdemo/longer_file_name_dlmain.c index fdb5526..ef1e4c5 100644 --- a/tests/pdemo/longer_file_name_dlmain.c +++ b/tests/pdemo/longer_file_name_dlmain.c @@ -1,6 +1,7 @@ /* dlmain.c -- hello test program that uses simulated dynamic linking - Copyright (C) 1996-1999, 2004, 2006, 2007 Free Software Foundation, Inc. + Copyright (C) 1996-1999, 2004, 2006, 2007, 2010 Free Software + Foundation, Inc. This file is part of GNU Libtool. @@ -27,18 +28,18 @@ or obtained by writing to the Free Software Foundation, Inc., #define lt_preloaded_symbols lt__PROGRAM__LTX_preloaded_symbols -struct lt_symlist +typedef struct { const char *name; lt_ptr_t address; -}; +} lt_dlsymlist; -extern const struct lt_symlist lt_preloaded_symbols[]; +extern const lt_dlsymlist lt_preloaded_symbols[]; int main (int argc, char **argv) { - const struct lt_symlist *s; + const lt_dlsymlist *s; int (*pfoo)() = 0; int (*phello)() = 0; int *pnothing = 0; -- 1.7.0.rc1.161.g90487