X-Recipient: archive-cygwin AT delorie DOT com DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:references:in-reply-to:subject:date :message-id:mime-version:content-type; q=dns; s=default; b=L8KBu uyd8X3AdLBFObXgIB0BMkuHt3VfBLfElO1R6Ym4NdlDiKNsNXJAKuCRVmw1oTzrc Obs/U27UXDLTn6QpCoGLkqPGTfQ9Rlupt36gWH0bkYI93sRUmKruP8Kb7P3cPv4x 1e+v/7DlkKwXf+wniuDKMuuuICqeXDZDr5RrTg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:references:in-reply-to:subject:date :message-id:mime-version:content-type; s=default; bh=Ho0ehNCkOFe U2FHjCfLDNiTx/kY=; b=iWHmB4VNPnqWgGwQTLXc0YY0dXDK3MTG6/GUHRDttgv tsTmYaXGvqaRlT0CTnL/I24QnVWgs7DfqNoFIwMPF2pR1sLR2EqSUyvS52zTYltW Qig0lipFzhPwntKBQAgY8M4G5lU1BkKoTO6Ia3xMkvAaptoVvB5t4KmPEVojv3Rg = Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Id: <cygwin.cygwin.com> List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com> List-Archive: <http://sourceware.org/ml/cygwin/> List-Post: <mailto:cygwin AT cygwin DOT com> List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs> Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com X-Spam-SWARE-Status: No, score=-1.5 required=5.0 tests=AWL,BAYES_50,KHOP_RCVD_UNTRUST,KHOP_THREADED,MIME_QP_LONG_LINE,RCVD_IN_HOSTKARMA_W,RCVD_IN_HOSTKARMA_WL,RDNS_NONE,SPF_HELO_PASS autolearn=no version=3.3.1 From: Fedin Pavel <p DOT fedin AT samsung DOT com> To: "'Andrew Schulman'" <schulman DOT andrew AT epamail DOT epa DOT gov>, cygwin AT cygwin DOT com References: <000001ce7e08$2b866830$82933890$%fedin AT samsung DOT com> <u4ett8due4p6h9ku1iumscvulp0g688tgk AT 4ax DOT com> <4q4ut8had25hqmo8b0752i8asuv6ism2qh AT 4ax DOT com> <002901ce7f0a$9da99420$d8fcbc60$%fedin AT samsung DOT com> <tq50u89pa1s7us0cff5rnu8k5ocumac510 AT 4ax DOT com> In-reply-to: <tq50u89pa1s7us0cff5rnu8k5ocumac510@4ax.com> Subject: [PATCH] Fix optional variables in libargp Date: Wed, 17 Jul 2013 10:32:18 +0400 Message-id: <002601ce82b7$63229580$2967c080$%fedin@samsung.com> MIME-version: 1.0 Content-type: multipart/mixed; boundary="----=_NextPart_000_0027_01CE82D8.EA343580" X-Virus-Found: No ------=_NextPart_000_0027_01CE82D8.EA343580 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Hello! > Okay, well I agree that this sounds like a good solution. For now you > have a workaround, and I'll be glad to consider a patch if you submit > one. Please take it. This is my experimental implementation which appears to be simpler than i suggested. Some details: this implementation adds explicit dllexport attribute to these 4 variables. This allows to look them up using GetProcAddress(). The dllexport attribute has to be added explicitly because when compiling an .exe file (without -shared switch) gcc does not mark externals as exportable by default. When building a .dll, all external symbols are marked as exportable by default, *UNLESS* we have at least one explicit dllexport specification, hence i surrounded this with #ifndef DLL_EXPORT, this definition is introduced by libtool when building a shared library. This implementation would not work in the following corner cases: a) .exe file uses some foo.dll library, which defines these variables and uses libargp - symbols are picked up only from .exe file itself. b) Building that foo.dll manually without DLL_EXPORT definition can get broken - the compiler will see dllexport attribute, and it will override the default behavior to make all externs exportable. I believe these cases are quite unusual so it's OK. Getting rid of these limitations would need more complex implementation with more changes. I have tested the implementation on x86-64 with RedHat's Prelink utility, and it works quite fine. i386 should work too, but please retest, just in case. Additionally, i added the second #ifdef _WIN32 in order to make the same thing working also for MinGW target. Kind regards, Pavel Fedin Expert Engineer Samsung Electronics Research center Russia ------=_NextPart_000_0027_01CE82D8.EA343580 Content-Type: application/octet-stream; name="libargp-20110921-fix-optional-variables.diff" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="libargp-20110921-fix-optional-variables.diff" diff -ru src/libargp-20110921.orig/gllib/argp.h src/libargp-20110921/gllib/= argp.h=0A= --- src/libargp-20110921.orig/gllib/argp.h 2011-09-23 03:31:26.000000000 +0= 500=0A= +++ src/libargp-20110921/gllib/argp.h 2013-07-15 12:03:51.616647900 +0500= =0A= @@ -64,6 +64,18 @@=0A= typedef int error_t;=0A= # define __error_t_defined=0A= #endif=0A= +=0A= +#ifndef DLL_EXPORT=0A= +#ifdef __CYGWIN__=0A= +#define __dllexport __declspec(dllexport)=0A= +#endif=0A= +#ifdef _WIN32=0A= +#define __dllexport __declspec(dllexport)=0A= +#endif=0A= +#endif=0A= +#ifndef __dllexport=0A= +#define __dllexport=0A= +#endif=0A= =0C=0A= #ifdef __cplusplus=0A= extern "C" {=0A= @@ -441,14 +453,14 @@=0A= option --version is added (unless the ARGP_NO_HELP flag is used), which= =0A= will print this string followed by a newline and exit (unless the=0A= ARGP_NO_EXIT flag is used). Overridden by ARGP_PROGRAM_VERSION_HOOK. = */=0A= -extern const char *argp_program_version;=0A= +__dllexport extern const char *argp_program_version;=0A= =20=0A= /* If defined or set by the user program to a non-zero value, then a defau= lt=0A= option --version is added (unless the ARGP_NO_HELP flag is used), which= =0A= calls this function with a stream to print the version to and a pointer= to=0A= the current parsing state, and then exits (unless the ARGP_NO_EXIT flag= is=0A= used). This variable takes precedent over ARGP_PROGRAM_VERSION. */=0A= -extern void (*argp_program_version_hook) (FILE *__restrict __stream,=0A= +__dllexport extern void (*argp_program_version_hook) (FILE *__restrict __s= tream,=0A= struct argp_state *__restrict=0A= __state);=0A= =20=0A= @@ -457,12 +469,12 @@=0A= argp_help if the ARGP_HELP_BUG_ADDR flag is set (as it is by various=0A= standard help messages), embedded in a sentence that says something like= =0A= `Report bugs to ADDR.'. */=0A= -extern const char *argp_program_bug_address;=0A= +__dllexport extern const char *argp_program_bug_address;=0A= =20=0A= /* The exit status that argp will use when exiting due to a parsing error.= =0A= If not defined or set by the user program, this defaults to EX_USAGE fr= om=0A= <sysexits.h>. */=0A= -extern error_t argp_err_exit_status;=0A= +__dllexport extern error_t argp_err_exit_status;=0A= =0C=0A= /* Flags for argp_help. */=0A= #define ARGP_HELP_USAGE 0x01 /* a Usage: message. */=0A= diff -ru src/libargp-20110921.orig/gllib/argp-parse.c src/libargp-20110921/= gllib/argp-parse.c=0A= --- src/libargp-20110921.orig/gllib/argp-parse.c 2011-09-23 03:31:26.000000= 000 +0500=0A= +++ src/libargp-20110921/gllib/argp-parse.c 2013-07-15 11:39:49.690236100 += 0500=0A= @@ -64,6 +64,42 @@=0A= /* EZ alias for ARGP_ERR_UNKNOWN. */=0A= #define EBADKEY ARGP_ERR_UNKNOWN=0A= =0C=0A= +/* Windows does not support things like weak symbols, neither it will merg= e two=0A= + external symbols. In order to make our optional variables working, we h= ave=0A= + to do this trick. What we do here is looking up respective variables in= =0A= + main .exe file and patching our versions with correct pointers=0A= + Note that the whole thing relies on these variables being declared with= =0A= + __declspec(dllexport). */=0A= +#ifdef DLL_EXPORT=0A= +=0A= +#include <windows.h>=0A= +=0A= +#ifdef __i386__=0A= +#define PREFIX "_"=0A= +#else=0A= +#define PREFIX=0A= +#endif=0A= +=0A= +#define PatchPtr(var) \=0A= + p =3D (void **)GetProcAddress(NULL, PREFIX #var ); \=0A= + if (p) var =3D *p;=0A= +=0A= +#define PatchInt(var) \=0A= + i =3D (int *)GetProcAddress(NULL, PREFIX #var ); \=0A= + if (i) var =3D *i;=0A= +=0A= +static void __attribute__((constructor)) patch_vars(void)=0A= +{=0A= + void **p;=0A= + int *i;=0A= +=0A= + PatchPtr(argp_program_version);=0A= + PatchPtr(argp_program_version_hook);=0A= + PatchPtr(argp_program_bug_address);=0A= + PatchInt(argp_err_exit_status);=0A= +}=0A= +#endif=0A= +=0A= /* Default options. */=0A= =20=0A= /* When argp is given the --HANG switch, _ARGP_HANG is set and argp will s= leep=0A= ------=_NextPart_000_0027_01CE82D8.EA343580 Content-Type: text/plain; charset=us-ascii -- Problem reports: http://cygwin.com/problems.html FAQ: http://cygwin.com/faq/ Documentation: http://cygwin.com/docs.html Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple ------=_NextPart_000_0027_01CE82D8.EA343580--