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

Failed to compile in FreeBSD 10.3 i386 #1

Open
dram opened this issue Jun 7, 2016 · 2 comments
Open

Failed to compile in FreeBSD 10.3 i386 #1

dram opened this issue Jun 7, 2016 · 2 comments

Comments

@dram
Copy link
Contributor

dram commented Jun 7, 2016

Compile ack default branch in FreeBSD 10.3 i386 failed with following error:

CPP /tmp/ack-build/obj/i86/mach/proto/as/comm2.y.m
INSTALL /tmp/ack-build/obj/plat/pc86//preprocessed-comm2.y
YACC /tmp/ack-build/obj/plat/pc86//y.tab.c
yacc: 1 shift/reduce conflict.
CC /tmp/ack-build/obj/i86//tmp/ack-build/obj/plat/pc86//y.tab.o
/tmp/ack-build/obj/plat/pc86//preprocessed-comm2.y:96:3: error: conflicting types for '__mbstate_t'
 } __mbstate_t;
   ^
In file included from /usr/local/lib/gcc48/gcc/i386-portbld-freebsd10.1/4.8.5/include-fixed/stdlib.h:47:0,
                 from /tmp/ack-build/obj/plat/pc86//preprocessed-comm2.y:2:
/usr/include/sys/_types.h:113:3: note: previous declaration of '__mbstate_t' was here
 } __mbstate_t;
   ^
plat/pc86/build.mk:29: recipe for target '/tmp/ack-build/obj/i86//tmp/ack-build/obj/plat/pc86//y.tab.o' failed
gmake: *** [/tmp/ack-build/obj/i86//tmp/ack-build/obj/plat/pc86//y.tab.o] Error 1
@kernigh
Copy link
Contributor

kernigh commented Jan 16, 2017

I don't get this error, but I find a similar problem with OpenBSD 6.0 amd64. The C compiler sees two copies of <machine/_types.h>.

This happens because we run cpp twice. We run cpp before yacc, and then cc runs cpp as usual when compiling y.tab.c from yacc. The source file mach/proto/as/comm2.y has #define _include #include. Any #include happens in the first cpp, but _include happens in the second cpp.

Now comm2.y does #include "comm0.h", and mach/proto/as/comm0.h does #include <stdint.h> and #include "out.h", and h/out.h has another #include <stdint.h>. So the first cpp enters <stdint.h>. But comm0.h also does _include <stdlib.h>. So the second cpp enters <stdlib.h>. In OpenBSD, both <stdint.h> and <stdlib.h> include <machine/_types.h>. So both the first cpp and the second cpp enter <machine/_types.h>.

The file obj/plat/linuxppc/as/yacc/yaccinput/comm2.y is the output of the first cpp. I can see that all typedefs from <machine/_types.h> and <stdint.h> have been copied to the yacc input. The #include <stdlib.h> is also in the yacc input. The files obj/plat/linuxppc/as/yacc/y.tab.[ch] are the yacc output. Again, I see both the typedefs and the #include in y.tab.c. So when we compile y.tab.c, the compiler sees two copies of <machine/_types.h>: one copy in y.tab.c and one included from <stdlib.h>.

OpenBSD declares __mbstate_t in <sys/_types.h>, but luckily for me, <stdint.h> never includes <sys/_types.h>, so I never get the error of two __mbstate_t declarations.

kernigh added a commit to kernigh/ack that referenced this issue Jan 17, 2017
See issue davidgiven#1 (davidgiven#1).  The file
mach/proto/as/comm2.y goes through cpp twice.  The _include macro,
defined in comm2.y and used in comm0.h, delays the inclusion of system
header files.  The inclusion of <stdint.h> wasn't delayed.  This
caused multiple inclusions of <sys/_types.h> in FreeBSD and
<machine/_types.h> in OpenBSD.

Use _include to delay <stdint.h>.  Also use _include for "arch.h" and
"out.h", because h/out.h includes <stdint.h> and h/arch.h might
include it in the future.

Sort the system includes in comm0.h by moving them up to be with
<stdint.h>.  Must include <stdint.h> before "mach0.c", because
mach/powerpc/as/mach0.c needs it.  Must include "mach0.c" before
checking ASLD.
@dram
Copy link
Contributor Author

dram commented Jan 19, 2017

With the fix in #44, compliation in FreeBSD can proceed further, but still failed with following error:

plat/linux68k/include+pkg
lang/b/lib+lib_linux68k/init
opt2: error on line 0: wrong input file
/tmp/ack-build/staging/bin/ack: /tmp/ack-build/staging/lib/ack/em_opt2 died with signal 6
*** Error code 1

kernigh added a commit to kernigh/ack that referenced this issue Jan 31, 2017
We should not include a system header file here, because
mach/proto/as/comm2.y goes through cpp twice.  The include can cause
problems like davidgiven#1

Remove this include #<stdbool.h> and leave a comment pointing to the
includes in comm0.h.  Change the few instances of bool, false, true,
to int, 0, 1.
kernigh added a commit to kernigh/ack that referenced this issue Oct 30, 2017
@dram reported a build failure in FreeBSD at
davidgiven#1 (comment)

Linux manual for getopt(3) says:
> If the first character of optstring is '-', then each nonoption
> argv-element is handled as if it were the argument of an option with
> character code 1....
>
> The use of '+' and '-' in optstring is a GNU extension.

GNU/Linux and OpenBSD handle '-' in this special way, but FreeBSD
seems not to.  If '-' is not special, then em_ego can't find its input
file, so the build must fail.  This commit stops using '-' in both
em_b and em_ego, but doesn't change mcg.

Also fix em_ego -O3 to not act like -O4.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants