When linking a program with -Wl,--export-dynamic, no symbols are exported. The problem arises when the executable needs to either dlopen itself, or when it has plugins which are "linked" against it. Both scenarios are not uncommon, particularly with GNOME software. While this does work on Linux, it does not work on Cygwin with --export-dynamic; only --export-all-symbols, an i386PE-specific flag, will accomplish this. I'm attaching a test case; it's a simplified version of the test used in LT_SYS_DLOPEN_SELF (prev. AC_LIBTOOL_DLOPEN_SELF): $ gcc -o test.exe dlopen-self.c && ./test.exe status = 0 $ gcc -Wl,--export-dynamic -o test.exe dlopen-self.c && ./test.exe status = 0 $ gcc -Wl,--export-all-symbols -o test.exe dlopen-self.c && ./test.exe status = 1 Running 'objdump -p test.exe' will also show that the export table is only generated in the last case. I would appreciate your input on this issue.
Created attachment 2826 [details] dlopen-self test case
--export-dynamic is an ELF format option, and --export-all-symbols is the PE equivalent. We could reasonably make --export-dynamic a synonym for PE, I expect.
(In reply to comment #2) > --export-dynamic is an ELF format option, and --export-all-symbols is the PE > equivalent. Dave, thanks for looking at this. The ld texinfo docs say nothing about --export-dynamic being ELF-specific, so if this is indeed the case, that should be made clear. > We could reasonably make --export-dynamic a synonym for PE, I expect. Sounds like a good idea.
(In reply to comment #3) > (In reply to comment #2) > > --export-dynamic is an ELF format option, and --export-all-symbols is the PE > > equivalent. > > Dave, thanks for looking at this. The ld texinfo docs say nothing about > --export-dynamic being ELF-specific, so if this is indeed the case, that should > be made clear. Well it's strongly implied by the wording "When creating a dynamically linked executable ..." that it's not going to apply to platforms that don't support dynamically linked executables. This may also imply that the scope is slightly wider than my assumption of "just Elf", which means the docs maybe are OK as they are. I'm a little (only a little) concerned that if we make it a synonym on PE For --export-all-symbols, it might confuse people into thinking that other linker options related to dynamic objects would also function as expected, but they seem to all be clearly documented as to which platforsm they support. It would certainly be technically correct if libtool chose to use --e-a-s rather than --e-d when linking for a cygwin target, since it's the target-specific equivalent. Why not post an RFC on the binutils list asking if anyone can see a downside of making --e-d a synonym for --e-a-s?
> It would certainly be technically correct if libtool chose to use --e-a-s > rather than --e-d when linking for a cygwin target, since it's the target- > specific equivalent. Good point, changing libtool would cover most, but not all, of the cases. > Why not post an RFC on the binutils list asking if anyone can see a downside > of making --e-d a synonym for --e-a-s? I don't follow the binutils list nowadays.
Hi Guys, I would prefer not to make -export-dynamic a synonym for -export-all-symbols for the reason that Dave mentioned. I would not object to adding code to generate a warning message saying something like: "--export-dynamic is not supported for COFF/PE targets, did you mean --export-all-symbols ?". Cheers Nick
Chuck has pushed the corresponding libtool patch upstream, so this should handle many cases where it would be used. I suppose a warning would be appropriate, as would clarification in the documentation on this flag.
I'm m(In reply to comment #7) > I suppose a warning would be appropriate, as > would clarification in the documentation on this flag. I'm working on a patch to do this right now.
Created attachment 3860 [details] Add warning and docs. This patch adds warnings to both PE and PE+ emulations, (which are the only COFF emulations that implement --export-all-symbols). It also mentions --e-a-s in the --export-dynamic documentation. Tested on cygwin so far, will cross-test to x86_64-mingw later but have to go AFK for a few hours. "make info" worked on the docs, but make html,pdf and dvi are all currently broken for me, for what appear to be unrelated reasons.
(In reply to comment #9) > It also mentions --e-a-s in the --export-dynamic documentation. "PE targets support a similar function to export all symbols from a DLL;" or EXE, which is actually what I'm more concerned about here.
Thanks for proofreading. Revised patch (also contains testcase) about to be posted.
Subject: Bug 6744 CVSROOT: /cvs/src Module name: src Changes by: davek@sourceware.org 2009-04-02 14:42:41 Modified files: ld : ld.texinfo ChangeLog ld/emultempl : pe.em pep.em ld/testsuite/ld-pe: pe.exp ld/testsuite : ChangeLog Added files: ld/testsuite/ld-pe: export_dynamic_warning.d export_dynamic_warning.s Log message: ld/ChangeLog PR ld/6744 * ld.texinfo (--export-dynamic): Mention --export-all-symbols. * emultempl/pe.em (gld_${EMULATION_NAME}_after_parse): Issue warning if --export-dynamic was passed on command-line. * emultempl/pep.em (gld_${EMULATION_NAME}_after_parse): Likewise. ld/testsuite/ChangeLog PR ld/6744 * ld-pe/export_dynamic_warning.d: New test control file. * ld-pe/export_dynamic_warning.s: New test source file. * ld-pe/pe.exp: Also run export_dynamic_warning dump test. Patches: http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/ld.texinfo.diff?cvsroot=src&r1=1.236&r2=1.237 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/ChangeLog.diff?cvsroot=src&r1=1.1956&r2=1.1957 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/emultempl/pe.em.diff?cvsroot=src&r1=1.147&r2=1.148 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/emultempl/pep.em.diff?cvsroot=src&r1=1.24&r2=1.25 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-pe/export_dynamic_warning.d.diff?cvsroot=src&r1=NONE&r2=1.1 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-pe/export_dynamic_warning.s.diff?cvsroot=src&r1=NONE&r2=1.1 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/testsuite/ld-pe/pe.exp.diff?cvsroot=src&r1=1.9&r2=1.10 http://sources.redhat.com/cgi-bin/cvsweb.cgi/src/ld/testsuite/ChangeLog.diff?cvsroot=src&r1=1.1066&r2=1.1067
Closing out old PR.