# clang unable to compile world.



## Deleted member 35650 (Nov 9, 2012)

Hi,

I'm running a freebsd with branch stable/9.
I want to switch from gcc to clang, and I edited my make.conf as following : 

```
â•°â”€âž¤ cat /etc/make.conf                                                                                                                                            }1 â†µ
WITHOUT_BLUETOOTH="YES"
WITHOUT_FLOPPY="YES"  
WITHOUT_USB="YES"  
WITHOUT_WIRELESS="YES"  
WITHOUT_ZFS="YES"
CFLAGS=-O2 -pipe -march=native
WITHOUT_X11=yes
COPTFLAGS=-O2 -pipe -march=native
KERNCONF=DRAGONBORN GENERIC
USER!=/usr/bin/whoami

.if !defined(NO_CLANG)
CC=clang
CXX=clang++
CPP=clang-cpp
.endif
.if ${USER} == root
.if !defined(NO_CCACHE)
CC:=${CC:C,^cc,/usr/local/libexec/ccache/world/cc,1}
CXX:=${CXX:C,^c\+\+,/usr/local/libexec/ccache/world/c++,1}
CC:=${CC:C,^clang,/usr/local/libexec/ccache/world/clang,1}
CXX:=${CXX:C,^clang\+\+,/usr/local/libexec/ccache/world/clang++,1}
CCACHE_DIR:=/var/tmp/ccache
CCACHE_LOGFILE=:/var/log/ccache.log
.endif
.endif
.if ${CC:T} == "clang"
CFLAGS+=        -Qunused-arguments
COPTFLAGS=      -Qunsued-arguments
.endif
# added by use.perl 2012-10-22 00:50:29
PERL_VERSION=5.14.2                                                                                                                                               
WITH_PKGNG=yes
```

The problem is ... Compilation crash. I'm doing make buildworld buildkernel on /usr/src


```
/usr/local/libexec/ccache/world/clang  -O2 -pipe -march=native -Qunused-arguments  -I/usr/src/lib/libelf -I/usr/src/lib/libelf/../../sys -DLIBELF_TEST_HOOKS -std=gnu99
 -Qunused-arguments -fstack-protector -Wsystem-headers -Werror -Wall -Wno-format-y2k -W -Wno-unused-parameter -Wstrict-prototypes -Wmissing-prototypes -Wpointer-arith 
-Wreturn-type -Wcast-qual -Wwrite-strings -Wswitch -Wshadow -Wunused-parameter -Wcast-align -Wchar-subscripts -Winline -Wnested-externs -Wredundant-decls -Wold-style-d
efinition -Wno-pointer-sign -Wno-empty-body -Wno-string-plus-int -c /usr/src/lib/libelf/elf_strptr.c -o elf_strptr.o
In file included from /usr/src/lib/libelf/elf_scn.c:1:
/usr/src/lib/libelf/elf_scn.c:198:41: error: equality comparison with extraneous parentheses [-Werror,-Wparentheses-equality]
 if (((&e->e_u.e_elf.e_scn)->stqh_first == ((void *)0))) {
                                        ^~
                                        =
1 error generated.
*** [elf_scn.So] Error code 1
2 errors
*** [all] Error code 2
1 error
*** [lib__L] Error code 2
1 error
*** [libraries] Error code 2
1 error
*** [_libraries] Error code 2
1 error
*** [buildworld] Error code 2
1 error
â•­â”€<root@Dragonborn>-</usr/src>-<14:07:13>-â—‡
```

Please tell me if you need more file from my system. Thanks. (I don't have a src.conf)


----------



## kpa (Nov 9, 2012)

Disable ccache for world and kernel when using clang(1) to compile them.


----------



## Deleted member 35650 (Nov 9, 2012)

kpa said:
			
		

> Disable ccache for world and kernel when using clang(1) to compile them.



Well, I will do this. But, Do I have to disable ccache for testing, or forever ? Because ccache is very usefull, on my computer.


----------



## SirDice (Nov 9, 2012)

Cubox said:
			
		

> ```
> WITHOUT_BLUETOOTH="YES"
> WITHOUT_FLOPPY="YES"
> WITHOUT_USB="YES"
> ...


These should go in src.conf(5).



> ```
> CFLAGS=-O2 -pipe -march=native
> COPTFLAGS=-O2 -pipe -march=native
> ```


Remove these, and any other CFLAGS or COPTFLAGS.


----------



## Deleted member 35650 (Nov 9, 2012)

SirDice said:
			
		

> These should go in src.conf(5).
> 
> 
> Remove these, and any other CFLAGS or COPTFLAGS.



Well, thanks for the answer, I moved things in src.conf.

I don't understand why I have to remove these flags, I really want to use -pipe and -O2 when it's possible. (and -march=native, I just figured that CPUTYPE is ignored on worldbuilding.)
It's possible to have more information about why I need to remove these flags ?


----------



## kpa (Nov 9, 2012)

The system sources are already tuned and optimized to the maximum and some parts are such that they require handcrafted CFLAGS to avoid compiler bugs and other quirks. If you forcibly override CFLAGS you might break something in subtle ways that don't prevent the code from compiling but results in a non working system.


----------



## SirDice (Nov 9, 2012)

Or produce weird compilation errors, like the ones you have now.


----------



## Deleted member 35650 (Nov 9, 2012)

Okey. I understand more. I don't understand about ccache, do I have to remove it for the same reasons ?


----------



## Deleted member 35650 (Nov 9, 2012)

(I want to apologies for possible misunderstandings, I'm not native speaker.)


----------



## Deleted member 35650 (Nov 11, 2012)

```
===> sys/boot/i386/boot2 (all)
objcopy -S -O binary boot1.out boot1
dd if=/dev/zero of=boot2.ldr bs=512 count=1
1+0 records in
1+0 records out
512 bytes transferred in 0.000097 secs (5276373 bytes/sec)
/usr/local/libexec/ccache/world/clang -Os  -fno-guess-branch-probability  -fomit-frame-pointer  -fno-unit-at-a-time  -mno-align-long-strings  -mrtd  -mregparm=3  -DUSE
_XREAD  -DUFS1_AND_UFS2  -DFLAGS=0x80  -DSIOPRT=0x3f8  -DSIOFMT=0x3  -DSIOSPD=9600  -I/usr/src/sys/boot/i386/boot2/../../common  -I/usr/src/sys/boot/i386/boot2/../btx/
lib -I.  -Wall -Waggregate-return -Wbad-function-cast -Wcast-align  -Wmissing-declarations -Wmissing-prototypes -Wnested-externs  -Wpointer-arith -Wshadow -Wstrict-pro
totypes -Wwrite-strings  -Winline --param max-inline-insns-single=100  -mstack-alignment=8 -mllvm -inline-threshold=3 -mllvm -enable-load-pre=false -mllvm -simplifycfg
-dup-ret -ffreestanding -mpreferred-stack-boundary=2  -mno-mmx -mno-3dnow -mno-sse -mno-sse2 -mno-sse3 -msoft-float -m32 -march=i386 -std=gnu99 -Qunused-arguments    -
S -o boot2.s.tmp /usr/src/sys/boot/i386/boot2/boot2.c
clang: warning: the clang compiler does not support '-fno-unit-at-a-time'
In file included from /usr/src/sys/boot/i386/boot2/boot2.c:170:
/usr/src/sys/boot/i386/boot2/../../common/ufsread.c:233:17: warning: cast from 'char *' to 'struct ufs1_dinode *' increases required alignment from 1 to 4
      [-Wcast-align]
                        memcpy(&dp1, (struct ufs1_dinode *)blkbuf + n,
                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/src/sys/boot/i386/boot2/../../common/ufsread.c:236:17: warning: cast from 'char *' to 'struct ufs2_dinode *' increases required alignment from 1 to 4
      [-Wcast-align]
                        memcpy(&dp2, (struct ufs2_dinode *)blkbuf + n,
                                     ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/src/sys/boot/i386/boot2/boot2.c:222:1: warning: no previous prototype for function 'main' [-Wmissing-prototypes]
main(void)
^
/usr/src/sys/boot/i386/boot2/boot2.c:353:4: warning: cast from 'caddr_t' (aka 'char *') to 'Elf32_Word *' (aka 'unsigned int *') increases required alignment from 1 to
      4 [-Wcast-align]
                *(Elf32_Word *)p = es[i].sh_size;
                 ^~~~~~~~~~~~~~~
/usr/src/sys/boot/i386/boot2/boot2.c:619:8: warning: cast from 'caddr_t' (aka 'char *') to 'uint32_t *' (aka 'unsigned int *') increases required alignment from 1 to 4
      [-Wcast-align]
        t1 = *(uint32_t *)PTOV(0x46c);
              ^~~~~~~~~~~~~~~~~~~~~~~
5 warnings generated.
sed -e '/align/d' -e '/nop/d' < boot2.s.tmp > boot2.s
rm -f boot2.s.tmp
/usr/local/libexec/ccache/world/clang  -m32 -c boot2.s
/usr/local/libexec/ccache/world/clang -Os  -fno-guess-branch-probability  -fomit-frame-pointer  -fno-unit-at-a-time  -mno-align-long-strings  -mrtd  -mregparm=3  -DUSE
_XREAD  -DUFS1_AND_UFS2  -DFLAGS=0x80  -DSIOPRT=0x3f8  -DSIOFMT=0x3  -DSIOSPD=9600  -I/usr/src/sys/boot/i386/boot2/../../common  -I/usr/src/sys/boot/i386/boot2/../btx/
lib -I.  -Wall -Waggregate-return -Wbad-function-cast -Wcast-align  -Wmissing-declarations -Wmissing-prototypes -Wnested-externs  -Wpointer-arith -Wshadow -Wstrict-pro
totypes -Wwrite-strings  -Winline --param max-inline-insns-single=100  -mstack-alignment=8 -mllvm -inline-threshold=3 -mllvm -enable-load-pre=false -mllvm -simplifycfg
-dup-ret -ffreestanding -mpreferred-stack-boundary=2  -mno-mmx -mno-3dnow -mno-sse -mno-sse2 -mno-sse3 -msoft-float -m32 -march=i386 -std=gnu99 -Qunused-arguments     
-m32 -c /usr/src/sys/boot/i386/boot2/sio.S
clang: warning: the clang compiler does not support '-fno-unit-at-a-time'
ld -static -N --gc-sections -nostdlib -m elf_i386_fbsd -Ttext 0x2000 -o boot2.out /usr/obj/usr/src/sys/boot/i386/boot2/../btx/lib/crt0.o boot2.o sio.o
objcopy -S -O binary boot2.out boot2.bin
btxld -v -E 0x2000 -f bin -b /usr/obj/usr/src/sys/boot/i386/boot2/../btx/btx/btx -l boot2.ldr  -o boot2.ld -P 1 boot2.bin
kernel: ver=1.02 size=690 load=9000 entry=9010 map=16M pgctl=1:1
client: fmt=bin size=1575 text=0 data=0 bss=0 entry=0
output: fmt=bin size=1e05 text=200 data=1c05 org=0 entry=0
-5 bytes available
*** [boot2] Error code 1

Stop in /usr/src/sys/boot/i386/boot2.
*** [all] Error code 1

Stop in /usr/src/sys/boot/i386.
*** [all] Error code 1

Stop in /usr/src/sys/boot.
*** [all] Error code 1

Stop in /usr/src/sys.
*** [sys.all__D] Error code 1

Stop in /usr/src.
*** [everything] Error code 1

Stop in /usr/src.
*** [buildworld] Error code 1

Stop in /usr/src.
â•­â”€<root@Dragonborn>-</usr/src>-<22:47:52>-â—‡
â•°â”€âž¤                                                                                                                                                               }1 â†µ
```
Still crashing ! I don't use ccache and those useless cflags now. Where is the problem ?


----------



## xibo (Nov 11, 2012)

There's a thread on this issue on the stable mailing list ( here).

A workaround for now is to define WITHOUT_BOOT in src.conf(5).

EDIT:
btw, the compiler being called

```
/usr/local/libexec/ccache/world/clang
```
sounds like you're using ccache though


----------



## Deleted member 35650 (Nov 11, 2012)

xibo said:
			
		

> There's a thread on this issue on the stable mailing list ( here).
> 
> A workaround for now is to define WITHOUT_BOOT in src.conf(5).
> 
> ...



Thanks for your answer. I followed the thread and applied (by hand) the patch posted.
I have setuped WITH_CLANG_AS_CC=true on my src.conf for this world build, (not related to thread, but I still ask, if you know.) Is this option a good choice? (I did not used WITHOUT_GCC=true)
The log shows ccache, because it was an old log, I tryed after with NO_CCACHE.

Thanks  Thread marked as solved.


----------



## xibo (Nov 12, 2012)

WITH_CLANG_IS_CC will cause world/kernel and most ports(7) to be build with clang(1) without the need to set CC/CXX/CPP in make.conf(5). Defining WITHOUG_GCC might cause trouble at this time, e.g. devel/boost-libs cannot be built by ports-mgmt/portmaster any more and needs to get explicitly setCXX=c++ to the make(1) call in order to build (g++(1) is hardcoded somewhere), while other ports(7) might not compile at all when using clang(1).


----------



## kpa (Nov 12, 2012)

My experience is that devel/ccache causes problems when compiling world and with clang(1) because of some extra warnings the compiler produces that are counted as errors. That's why I recommended turning devel/ccache off for world and kernel.

Remember to not run make delete-old if you compile the world with WITHOUT_BOOT=1, you might delete /boot/loader if you do


----------



## xibo (Nov 12, 2012)

It doesn't remove /boot/loader, I did that just 3 days ago 

boot2 seems to have been fixed now though, see r242907.


----------



## kpa (Nov 12, 2012)

Damn, I was at r242903 when I started compilation... time to update again and start over.


----------



## Deleted member 35650 (Nov 12, 2012)

kpa said:
			
		

> My experience is that devel/ccache causes problems when compiling world and with clang(1) because of some extra warnings the compiler produces that are counted as errors. That's why I recommended turning devel/ccache off for world and kernel.



Yeah, I figured how to remove the problems with ccache. Just disable werrors for world and kernel build. (add this : NO_WERROR= WERROR= to /etc/src.conf)

I'm building ... Will see in a few houres if this damn world will build with clang


----------



## Deleted member 35650 (Nov 12, 2012)

xibo said:
			
		

> WITH_CLANG_IS_CC will cause world/kernel and most ports(7) to be build with clang(1) without the need to set CC/CXX/CPP in make.conf(5). Defining WITHOUG_GCC might cause trouble at this time, e.g. devel/boost-libs cannot be built by ports-mgmt/portmaster any more and needs to get explicitly setCXX=c++ to the make(1) call in order to build (g++(1) is hardcoded somewhere), while other ports(7) might not compile at all when using clang(1).



Thanks for this explanation. I will just set clang as cc (but keeping gcc).


----------

