-
Notifications
You must be signed in to change notification settings - Fork 159
Fix error: ‘environ’ was declared ‘extern’ and later ‘static’ [-fpermissive] #289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
What compiler is this? Wondering why we don't see this on any other platform.... |
I think this #if defined (__UNIX__)
# if defined (__UTYPE_OSX)
#include <crt_externs.h>
#define environ (*_NSGetEnviron ())
# else
extern char **environ; // should be declared as a part of unistd.h, but fail in some targets in Travis
// declare it explicitly
# endif
#endif |
It's a matter of libc. On alpine, it is musl instead gblic and in unistd.h we have:
musl seems to rely on On glibc environment,
On my glibc machine, the unistd.h contains:
You can reproduce the failing compilation like this:
Then inside running container:
I pushed a new fix that compiles both on alpine with musl and ubuntu with glibc. It uses Thibault |
I think We want a So apparently the problem is that musl doesn't #if __MUSL
# define _GNU_SOURCE
#endif at the top of this file. The problem is that musl doesn't
That StackOverflow question has an interesting comment: "... consider checking for GNU_SOURCE but NOT _GLIBC (or _GLIB_MINOR, or __GNU_LIBRARY)...." That doesn't seem correct, but it might be close. EDIT: No, that's obviously wrong.... Ugh. Maybe this? #if !defined(_GLIBC) && !defined(__USE_GNU) /* detect musl */
# define _GNU_SOURCE
#endif Maybe need to add some conditions there for BSD and Mac? EDIT: Ugh, I think I'm just completely confused and need something to eat... Sorry. |
I don't know 🤭 I had the feeling that _GNU_SOURCE was more "standard" between various libc: glibc = both __USE_GNU and _GNU_SOURCE (in features.h if _GNU_SOURCE implies __USE_GNU) But honestly I repeat, I don't know 😁 I leave you the final word to decide 👍 |
Well, I think it should be clear by now that I don't know either. :) As near as I can tell, nothing in the gearmand build apparatus Everything I've read online says that |
I think this is wrong. In gearman, _GNU_SOURCE (and GNU extensions in general) seems to be set by configure "on systems that have them." It appears in m4/extensions.m4 (but this "undef is not defined" is weird) then later in the gear_config.in (same weird logic) in the release tarball then later in the gear_config.h after the So I think it is set "when it's possible" and I just checked with musl and it is also well set.
EDIT: it appears that on MacOS, the configure also sets _GNU_SOURCE, I tested in a github action see the logs. EDIT: on my side I used -fpermissive and it seems to fix some CPANTesters reports running on alpine Thibault |
I edited several times the previous message, sorry for that, as we agreed both, this problem and fix not cristal clear for us 😆 |
I tested some variation on mac os github actions: ✔️ Vanilla 1.1.19.1: ✔️ No ifndef (but keep ❌ ifndef _GNU_SOURCE: ❌ No ifndef and no environ declaration: Means:
Then #ifndef __USE_GNU will impact both musl and macOS which is bad ❌ My fix is wrong for mac os and current ifndef is wrong for musl. The tarball used :
The github actions: I hope this will help the debates 😄 Maybe I can try also |
Back again, replacing See Mac OS build here from this github action using this modified gearman 1.1.19.1 I updated the PR, I remind you the original error was to redefine with static instead extern. I'm not sure what other kind of impact it could have. If you have better idea or simply prefer another solution, I let you decide, no problem 😄 |
Thank you for extensive testing! You rock, @thibaultduponchelle. :) Could you test something like this on macOS? #if defined(__APPLE__) && __APPLE__
# include <crt_externs.h>
# define environ (*_NSGetEnviron ())
#elif !defined(_GNU_SOURCE)
extern char **environ= NULL;
#endif There’s also FreeBSD. I don’t think we officially support FreeBSD, but I know we’ve made some efforts in that arena to get it to compile at least. Not expecting you to test this on FreeBSD, but it might be worth researching how FreeBSD defines environ in EDIT: Hmmm, I don't see any mention of |
Oh, I knew it was wrong, but I just couldn’t find where it happened. Thanks for giving me some clarity. :)
Ok, that’s good to know! |
✔️ Your code snippet compiles OK on Mac OS, Ubuntu and Alpine 🕺 See github ci build using this tarball Concerning freebsd, I don't know, but I think you could add a freebsd ci with cirrus-ci. And IMHO you can as well add a mac os in your travis for non-reg purposes. Seems like we have a fix, right ? 😃 |
Wait @p-alik thank you for approval but this PR still not contains the final fix, will add it right now |
…issive] Some libc do not set internal __USE_GNU and are not apple.
Thank you, @thibaultduponchelle, for seeing it through and doing so much testing. Cheers! |
Can somebody check and make sure the libgearman produced by this is ABI
compatible with 1.1.19.1?
I worry that we may need to bump soname if we have changed this variable's
declaration.
…On Fri, Jul 24, 2020, 8:46 AM Ed Sabol ***@***.***> wrote:
Merged #289 <#289> into master.
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#289 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AADS6YCHJMUVTVTMT6YKON3R5GUENANCNFSM4PCRBXTQ>
.
|
Hi, Clint. Is libtest code in libgearman.so? I assumed libtest was only used in the test suite. This variable declaration has changed on macOS and other non-glibc platforms, like FreeBSD and alpine. |
Hello,
I'm not sure about this fix.
In the CPANTesters I noticed this error :
From http://www.cpantesters.org/cpan/report/003e64ec-ca05-11ea-9066-e374b0ba08e8 (it is on an alpine Linux)
From the git blame it was added for OSX. I have tested with and without #ifdef on my machine but I have not tested on OSX...
Best regards.
Thibault