This is the mail archive of the mailing list for the binutils project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] Silence ld auto-import warnings for pe-i386.

   Hi all,

  PE linkers implement a feature for automatic import of symbols exported from
DLLs, which is widely used on Win32 platforms (Cygwin, MinGW) in the absence
of full support for symbol versioning scripts (from which import DEF files
could be generated) and in light of the fact that an awful lot of DLLs out
there don't have the exported symbols correctly annotated with dllimport
attributes in their associated header files.

  There are two aspects to this behaviour: ld generates a lot of import stubs
with load-time relocs pointing at them, and (since relocs can't be applied by
the loader against a read-only section) it selects an alternative linker
script that outputs all .rdata sections into .data so they can be fixed up at
runtime by the native windows dynamic loader without SEGVs.

  This feature can be enabled or disabled by supplying a command-line option,
but, for historical reasons[*], it has evolved so that the default behaviour
if no option is supplied is to automtically generate the required import stubs
and relocs.  However, in this case, it does not know that it will be
auto-importing until it starts reading the input BFDs, by which time it is
already too late to select the alternative linker script.  This will work OK
as long as none of the auto-imported symbols are referenced from within the
.rdata section, but any const data items referencing auto-imported symbols
will end up in .rdata and blow up at runtime.  In order to warn the user that
this switch-on-as-needed mode isn't guaranteed to work, ld currently issues
the following warning:

  einfo (_("%P: warning: auto-importing has been activated without
--enable-auto-import specified on the command line.\n\
This should work unless it involves constant data structures referencing
symbols from auto-imported DLLs.\n"));

  As Cygwin is switching to shared libgcc after having statically linked it
until now, these once-rare warnings are now becoming increasingly common, and
although still generally over-cautious, the situation where failures can occur
is becoming a more and more real problem.

  Accordingly after much discussion on the cygwin-apps list we've decided that
the best thing to do for now is to take the minor performance impact that may
arise from less sharing of R/O data pages between images of the same
executable in different processes, and just turn the feature fully on by
default.  Other PE targets may want to do likewise.  (Our longer-term plan is
to resolve the problem by using Kai's v2. runtime pseudo-relocs, which can
obviate the need to make .rdata writable).

  The attached patch enables auto-import fully by default, conditioned on
testing $target in the emultempl script when generating the emulation .c file.

  Tested natively on i686-pc-cygwin with no regressions and by inspecting
generted ei386pe.c and by manually running a link command with before and
after linkers and observing no warning.  Cross tests running from
i686-pc-linux-gnu to {arm-epoc-pe, arm-wince-pe, i386-pc-netbsdpe, i386-pc-pe,
i586-pc-interix, i586-unknown-beospe, i686-pc-cygwin, i686-pc-mingw32,
mcore-unknown-pe, powerpcle-unknown-pe, sh-unknown-pe, thumb-epoc-pe,
x86_64-pc-freebsd, x86_64-pc-linux-gnu, x86_64-pc-mingw32}.

  Assuming all clear, OK for HEAD?


	* emultempl/pe.em (gld_${EMULATION_NAME}_before_parse):  Set
	default state of auto-import flag based on $target.


[*]  - See PR linker/4844 for development.
[**] - See

Index: ld/emultempl/pe.em
RCS file: /cvs/src/src/ld/emultempl/pe.em,v
retrieving revision 1.144
diff -p -u -r1.144 pe.em
--- ld/emultempl/pe.em	18 Feb 2009 18:23:07 -0000	1.144
+++ ld/emultempl/pe.em	26 Feb 2009 13:27:09 -0000
@@ -145,7 +145,21 @@ gld_${EMULATION_NAME}_before_parse (void
   config.dynamic_link = TRUE;
   config.has_shared = 1;
-  link_info.pei386_auto_import = -1;
+# Cygwin no longer wants these noisy warnings.  Other PE
+# targets might like to consider adding themselves here.
+case ${target} in
+  *-*-cygwin*)
+    default_auto_import=1
+    ;;
+  *)
+    default_auto_import=-1
+    ;;
+fragment <<EOF
+  link_info.pei386_auto_import = ${default_auto_import};
   link_info.pei386_runtime_pseudo_reloc = 1; /* Use by default version 1.  */

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]