Skip to content
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

NetBSD-8.0: build-time failures using g++ as C-compiler #17381

Closed
jkeenan opened this issue Dec 20, 2019 · 8 comments
Closed

NetBSD-8.0: build-time failures using g++ as C-compiler #17381

jkeenan opened this issue Dec 20, 2019 · 8 comments

Comments

@jkeenan
Copy link
Contributor

jkeenan commented Dec 20, 2019

Today I ran a smoke-test of Perl 5 blead in a NetBSD-8.0 VM using g++ as the C-compiler. make failed to complete. To the best of my recollection, I have never previously tested perl on this platform with that C-compiler. However, until June of this year Carlos Guevara was testing on NetBSD-8.0 and consistently got build-time failures with g++ (g++ (nb2 20180327) 5.5.0). But he upgraded that VM to NetBSD-8.1 in June and on that version of the OS compiling perl with g++ no longer displayed build-time failures.

If we had been testing on NetBSD, say, in 2015 when g++-5.5.0 became available, we would have discovered that this build-time failure goes back a year earlier. Bisection with this invocation:

perl Porting/bisect.pl \
-Dcc=g++ \
--test-build \
--start=v5.21.6 \
--end=v5.21.7

... points to this commit:

6d59e610a3f269be73ffea56a90d1cd7dc8bf2fd is the first bad commit
commit 6d59e610a3f269be73ffea56a90d1cd7dc8bf2fd
Author: Lukas Mai <l.mai@web.de>
Date:   Sat Nov 29 12:17:05 2014 +0100
Commit:     Father Chrysostomos <sprout@cpan.org>
CommitDate: Sat Nov 29 06:11:08 2014 -0800

    define and use STATIC_ASSERT_STMT for compile-time invariants

 op.c     |  2 +-
 perl.h   | 26 +++++++++++++++++++++++++-
 pp.c     |  2 +-
 pp_hot.c |  2 +-
 pp_sys.c |  6 +++---
 sv.c     |  8 ++++----
 toke.c   |  2 +-
 7 files changed, 36 insertions(+), 12 deletions(-)

At the breaking commit (commit 6d59e61), make fails with this output:

$ zcat make.netbsd.g++.6d59e610a3.output.txt.gz
echo @`sh  cflags "optimize='-O'" perlmini.o`  -DPERL_IS_MINIPERL -DPERL_EXTERNAL_GLOB perlmini.c
@g++ -c -DPERL_CORE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/pkg/include -ansi -O -Wall -Werror=declaration-after-statement -Wextra -Wwrite-strings -DPERL_IS_MINIPERL -DPERL_EXTERNAL_GLOB perlmini.c
echo @`sh  cflags "optimize='-O'" opmini.o`  -DPERL_IS_MINIPERL -DPERL_EXTERNAL_GLOB opmini.c
@g++ -c -DPERL_CORE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/pkg/include -ansi -O -Wall -Werror=declaration-after-statement -Wextra -Wwrite-strings -DPERL_IS_MINIPERL -DPERL_EXTERNAL_GLOB opmini.c
g++ -c -DPERL_CORE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/pkg/include -ansi -O -Wall -Werror=declaration-after-statement -Wextra -Wwrite-strings miniperlmain.c
g++ -c -DPERL_CORE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/pkg/include -ansi -O -Wall -Werror=declaration-after-statement -Wextra -Wwrite-strings gv.c
g++ -c -DPERL_CORE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/pkg/include -ansi -O -Wall -Werror=declaration-after-statement -Wextra -Wwrite-strings toke.c
In file included from toke.c:40:0:
toke.c: In function 'void Perl_lex_start(SV*, PerlIOl**, U32)':
perl.h:3508:63: error: '_Static_assert' was not declared in this scope
 #  define STATIC_ASSERT_GLOBAL(COND) static_assert(COND, #COND)
                                                               ^
perl.h:3524:44: note: in expansion of macro 'STATIC_ASSERT_GLOBAL'
 #define STATIC_ASSERT_STMT(COND)      do { STATIC_ASSERT_GLOBAL(COND); } while (0)
                                            ^
toke.c:733:5: note: in expansion of macro 'STATIC_ASSERT_STMT'
     STATIC_ASSERT_STMT(FITS_IN_8_BITS(LEX_IGNORE_UTF8_HINTS|LEX_EVALBYTES
     ^
*** Error code 1

Stop.
make: stopped in /home/jkeenan/gitwork/perl

At HEAD (commit 4357af6), make fails with this output:

$ zcat make.netbsd.g++.4357af6ce6.output.txt.gz
echo @`sh  cflags "optimize='-O'" opmini.o`  -DPERL_IS_MINIPERL -DPERL_EXTERNAL_GLOB opmini.c
@g++ -c -DPERL_CORE -fwrapv -fno-strict-aliasing -pipe -fstack-protector-strong -I/usr/pkg/include -D_FORTIFY_SOURCE=2 -O -Wall -DPERL_IS_MINIPERL -DPERL_EXTERNAL_GLOB opmini.c
In file included from op.c:163:0:
op.c: In function 'void S_maybe_multiconcat(OP*)':
perl.h:3645:61: error: '_Static_assert' was not declared in this scope
 #  define STATIC_ASSERT_DECL(COND) static_assert(COND, #COND)
                                                             ^
perl.h:3661:52: note: in expansion of macro 'STATIC_ASSERT_DECL'
 #define STATIC_ASSERT_STMT(COND)      STMT_START { STATIC_ASSERT_DECL(COND); } STMT_END
                                                    ^
op.c:3019:5: note: in expansion of macro 'STATIC_ASSERT_STMT'
     STATIC_ASSERT_STMT(   STRUCT_OFFSET(BINOP,    op_last)
     ^
perl.h:3645:61: error: '_Static_assert' was not declared in this scope
 #  define STATIC_ASSERT_DECL(COND) static_assert(COND, #COND)
                                                             ^
perl.h:3661:52: note: in expansion of macro 'STATIC_ASSERT_DECL'
 #define STATIC_ASSERT_STMT(COND)      STMT_START { STATIC_ASSERT_DECL(COND); } STMT_END
                                                    ^
op.c:3021:5: note: in expansion of macro 'STATIC_ASSERT_STMT'
     STATIC_ASSERT_STMT(   STRUCT_OFFSET(LISTOP,   op_last)
     ^
op.c: In function 'OP* S_pmtrans(OP*, OP*, OP*)':
perl.h:3645:61: error: '_Static_assert' was not declared in this scope
 #  define STATIC_ASSERT_DECL(COND) static_assert(COND, #COND)
                                                             ^
op.c:7782:13: note: in expansion of macro 'STATIC_ASSERT_DECL'
             STATIC_ASSERT_DECL(TR_SPECIAL_HANDLING == TR_DELETE);
             ^
op.c: In function 'void Perl_rpeep(OP*)':
perl.h:3645:61: error: '_Static_assert' was not declared in this scope
 #  define STATIC_ASSERT_DECL(COND) static_assert(COND, #COND)
                                                             ^
perl.h:3661:52: note: in expansion of macro 'STATIC_ASSERT_DECL'
 #define STATIC_ASSERT_STMT(COND)      STMT_START { STATIC_ASSERT_DECL(COND); } STMT_END
                                                    ^
op.c:16980:21: note: in expansion of macro 'STATIC_ASSERT_STMT'
                     STATIC_ASSERT_STMT(sizeof(OP) <= sizeof(BINOP));
                     ^
*** Error code 1

Stop.
make: stopped in /home/jkeenan/gitwork/perl

The default C-compiler on NetBSD-8.0 is gcc-5.5.0. I have no idea what importance g++ has on NetBSD, nor do I know why these build-time failures seem to be OS-version-specific. But if anyone can spot the flaw, it would help make our coding more precise.

Thank you very much.
Jim Keenan

@cpansprout @cguevara

@krytarowski
Copy link

Perl is wrong attempting to use C11 static_assert() without at least -std=c11. Clang defines _Static_assert() for pre-c11 as an extension, while GCC does not do it.

The proper solution is to stop trying to use a compiler extension without compiler support.

@krytarowski
Copy link

krytarowski commented Dec 21, 2019

Nonetheless... we added a fallback in newer headers for pre-c11 code for static_assert() that does not depend on C11.

@khwilliamson
Copy link
Contributor

There is this in perl.h:
#if (defined(static_assert) || (defined(__cplusplus) && __cplusplus >= 201103L)) && (!defined(__IBMC__) || __IBMC__ >= 1210) /* static_assert is a macro defined in <assert.h> in C11 or a compiler builtin in C++11. But IBM XL C V11 does not support _Static_assert, no matter what <assert.h> says. */
It the conditions aren't met, it uses a fallback definition for static_assert.

What could perl do to cause it to use the fallback on already existing netbsd versions?

@krytarowski
Copy link

Today probably it would be easier to do nothing and wait for NetBSD-9.0.

@khwilliamson
Copy link
Contributor

khwilliamson commented Dec 22, 2019 via email

@krytarowski
Copy link

krytarowski commented Dec 22, 2019

Replace the check of unconditional defined(static_assert) to defined(static_assert) && (defined(_ISOC11_SOURCE) || (__STDC_VERSION__ - 0) >= 201101L)

khwilliamson added a commit that referenced this issue Dec 26, 2019
As discussed in the ticket, static assertions aren't always enabled
here.  The solution is to use our already-existing fallback to emulate
static assertions in more instances as suggested in the ticket.
jkeenan pushed a commit that referenced this issue Dec 26, 2019
As discussed in the ticket, static assertions aren't always enabled
here.  The solution is to use our already-existing fallback to emulate
static assertions in more instances as suggested in the ticket.
@jkeenan
Copy link
Contributor Author

jkeenan commented Dec 26, 2019

This should be fixed as of the following commit to blead:

commit f223d81ede2b28c83c8c4b31793166137f1fcdf1 (HEAD -> blead, origin/blead, origin/HEAD)
Author:     Karl Williamson <khw@cpan.org>
AuthorDate: Sat Dec 21 20:51:38 2019
Commit:     James E Keenan <jkeenan@cpan.org>
CommitDate: Thu Dec 26 16:21:14 2019

    PATCH: GH #17381 netbsd static assert failure
    
    As discussed in the ticket, static assertions aren't always enabled
    here.  The solution is to use our already-existing fallback to emulate
    static assertions in more instances as suggested in the ticket.

Will close once re-smoked.

Thank you very much.
Jim Keenan

@jkeenan jkeenan self-assigned this Dec 26, 2019
@jkeenan
Copy link
Contributor Author

jkeenan commented Jan 2, 2020

make is completing and the only tests that are failing are those that often fail on our testing VM due to its capacity constraints. Closing.

@jkeenan jkeenan closed this as completed Jan 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants