public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: The Cygwin Mailing List <cygwin@cygwin.com>
Subject: Re: environ: fix link error on 64-bit Cygwin
Date: Wed, 31 Jan 2018 13:53:00 -0000	[thread overview]
Message-ID: <0d2666a8-1037-fc9c-a17f-72cc59e9d977@redhat.com> (raw)
In-Reply-To: <36131639.liFsmjX0ip@omega>


[-- Attachment #1.1: Type: text/plain, Size: 2659 bytes --]

Forwarding from the gnulib list; is this something we should fix in
cygwin proper?

On 01/31/2018 04:42 AM, Bruno Haible wrote:
> On 64-bit Cygwin, a libunistring build fails like this:
> 
> $ /bin/sh ../libtool  --tag=CC --preserve-dup-deps  --mode=link x86_64-pc-cygwin-gcc  -g -O2  -L/usr/local/cygwin64/lib -Wl,--disable-auto-import -o test-environ.exe test-environ.o libtests.a ../lib/libunistring.la libtests.a
> libtool: link: x86_64-pc-cygwin-gcc -g -O2 -Wl,--disable-auto-import -o .libs/test-environ.exe test-environ.o  -L/usr/local/cygwin64/lib libtests.a ../lib/.libs/libunistring.dll.a -liconv libtests.a -L/usr/local/cygwin64/lib
> test-environ.o:test-environ.c:(.rdata$.refptr.environ[.refptr.environ]+0x0): undefined reference to `environ'
> collect2: error: ld returned 1 exit status
> 
> This fixes it.
> 
> 
> 2018-01-31  Bruno Haible  <bruno@clisp.org>
> 
> 	environ: Fix link error on 64-bit Cygwin.
> 	* lib/unistd.in.h (environ): On Cygwin, redeclare with the
> 	__declspec(dllimport) attribute.
> 	* doc/posix-functions/environ.texi: Mention the Cygwin problem.
> 
> diff --git a/doc/posix-functions/environ.texi b/doc/posix-functions/environ.texi
> index 34ac25a..a6c0095 100644
> --- a/doc/posix-functions/environ.texi
> +++ b/doc/posix-functions/environ.texi
> @@ -24,6 +24,9 @@ shared libraries on Mac OS X 10.5.  Here is a workaround: Instead, one can use
>  #define environ (*_NSGetEnviron())
>  @end smallexample
>  This works at all versions of Mac OS X.
> +@item
> +On Cygwin in 64-bit mode, references to this variable cause a link error when
> +the option @code{-Wl,--disable-auto-import} is in use.
>  @end itemize
>  
>  Portability problems not fixed by Gnulib:
> diff --git a/lib/unistd.in.h b/lib/unistd.in.h
> index 6802e3b..4ef0ffa 100644
> --- a/lib/unistd.in.h
> +++ b/lib/unistd.in.h
> @@ -400,6 +400,13 @@ _GL_WARN_ON_USE (dup3, "dup3 is unportable - "
>  
>  
>  #if @GNULIB_ENVIRON@
> +# if defined __CYGWIN__
> +/* The 'environ' variable is defined in a DLL. Therefore its declaration needs
> +   the '__declspec(dllimport)' attribute, but the system's <unistd.h> lacks it.
> +   This leads to a link error on 64-bit Cygwin when the option
> +   -Wl,--disable-auto-import is in use.  */
> +_GL_EXTERN_C __declspec(dllimport) char **environ;
> +# endif
>  # if !@HAVE_DECL_ENVIRON@
>  /* Set of environment variables and values.  An array of strings of the form
>     "VARIABLE=VALUE", terminated with a NULL.  */
> 
> 
> 

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3266
Virtualization:  qemu.org | libvirt.org


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 619 bytes --]

       reply	other threads:[~2018-01-31 13:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <36131639.liFsmjX0ip@omega>
2018-01-31 13:53 ` Eric Blake [this message]
2018-01-31 14:40   ` Corinna Vinschen
2018-02-26 21:28     ` Ken Brown
2018-02-27 10:38       ` Corinna Vinschen
2018-02-27 14:10       ` cyg Simple

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0d2666a8-1037-fc9c-a17f-72cc59e9d977@redhat.com \
    --to=eblake@redhat.com \
    --cc=cygwin@cygwin.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).