[newlib-cygwin] Move definition of wsadata into wsock_init

Corinna Vinschen corinna@sourceware.org
Wed Mar 9 21:55:00 GMT 2016


commit 264b5e137e20d0a8062497f8555759eb8bf8cc02
Author: Corinna Vinschen <corinna@vinschen.de>
Date:   Wed Mar 9 22:55:28 2016 +0100

    Move definition of wsadata into wsock_init
    The problem this patch fixes showed up after updating to gcc-5.3.0.  The
    cuplrit is a change in gcc when emitting section attributes.  It only
    shows up when building without optimization.  Effect in Cygwin: ws2_32
    functions failed to load.
    In the original code the definition of "NO_COPY wsadata" was preceeding
    an __asm__ block (the definition of the _wsock_init wrapper), while the
    definition of "NO_COPY here" immediately follows the same assembler
    block.  When gcc-5.3.0 emits assembler code for the wsadata definition,
    it emits the .data_cygwin_nocopy section attribute.
    Next it emits the assembler output for the __asm_ block, entirely ignoring
    its content.  The __asm__ block adds a .text section definition.
    Eventually gcc emits assembler code for the here definition.  However,
    apparently gcc still "knows" that it just emitted the .data_cygwin_nocopy
    section attribute and so doesn't redefine it.  Remember the __asm__?  It
    changed the section to .text.
    So with gcc-4.9.3 we got:
        .section .data_cygwin_nocopy,"w"
      __asm__ block:
        .section .data_cygwin_nocopy,"w"
    With gcc 5.3.0 we now get:
        .section .data_cygwin_nocopy,"w"
      __asm__ block:
    So "here" is now in the .text segment which is read-only.  Hilarity ensues.
    Signed-off-by: Corinna Vinschen <corinna@vinschen.de>

 winsup/cygwin/autoload.cc | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/autoload.cc b/winsup/cygwin/autoload.cc
index bc13e07..422e2c98 100644
--- a/winsup/cygwin/autoload.cc
+++ b/winsup/cygwin/autoload.cc
@@ -480,7 +480,6 @@ std_dll_init ()
 /* Initialization function for winsock stuff. */
 #ifdef __x86_64__
 /* See above comment preceeding std_dll_init. */
@@ -493,6 +492,10 @@ __attribute__ ((used, noinline)) static two_addr_t
 wsock_init ()
+  /* CV 2016-03-09: Moved wsadata into wsock_init to workaround a problem
+     with the NO_COPY definition of wsadata and here starting with gcc-5.3.0.
+     See the git log for a description. */
+  static WSADATA NO_COPY wsadata;
   static LONG NO_COPY here = -1L;
 #ifndef __x86_64__
   struct func_info *func = (struct func_info *) __builtin_return_address (0);

More information about the Cygwin-cvs mailing list