# Building FreeBSD 8.0 with Clang on amd64 problem



## Rifle (Feb 2, 2011)

I try to build FreeBSD with Clang and get following error


```
#make buildworld
.....
/usr/local/bin/clang -fpic -DPIC -O2 -pipe  -Wtypedef-redefinition -DMAXPAGESIZES=3 
-I/src/include -fPIC -I/src/r217821/lib/libc/include -I/src/r217821/lib/libc/../../include
-I/src/r217821/lib/libc/amd64 -DNLS  -D__DBINTERFACE_PRIVATE 
-I/src/r217821/lib/libc/../../contrib/gdtoa -DINET6 -I/usr/obj/src/r217821/lib/libc 
-I/src/r217821/lib/libc/resolv -D_ACL_PRIVATE -DPOSIX_MISTAKE 
-I/src/r217821/lib/libc/../../contrib/tzcode/stdtime -I/src/r217821/lib/libc/stdtime 
-I/src/r217821/lib/libc/locale -DBROKEN_DES -DPORTMAP -DDES_BUILTIN 
-I/src/r217821/lib/libc/rpc -DYP -DNS_CACHING -DSYMBOL_VERSIONING -std=gnu99 
-fstack-protector -Wsystem-headers -Wall -Wno-format-y2k -Wno-uninitialized 
-Wno-pointer-sign -c /src/r217821/lib/libc/string/wmemset.c -o wmemset.So
clang: warning: argument unused during compilation: '-fpic'
building shared library libc.so.7
/usr/obj/src/r217821/tmp/usr/bin/ld: pselect.So: relocation R_X86_64_32S can not be used when making a shared object; recompile with -fPIC
pselect.So: could not read symbols: Bad value
clang: error: linker command failed with exit code 1 (use -v to see invocation)
*** Error code 1

Stop in /src/r217821/lib/libc.
*** Error code 1
```

src.conf:

```
.if !defined(CC) || ${CC} == "cc"
CC=/usr/local/bin/clang
.endif
.if !defined(CXX) || ${CXX} == "c++"
CXX=/usr/local/bin/clang++
.endif
CFLAGS+=-Wtypedef-redefinition -DMAXPAGESIZES=3 -I/src/include -fPIC
CXXFLAGS+=-D__STDC_LIMIT_MACROS -D__STDC_CONSTANT_MACROS -I/src/include -fPIC
NO_WERROR=
WERROR=
NO_FSCHG=
```

system and clang version:

```
# uname -a
FreeBSD mrt210 8.0-RELEASE FreeBSD 8.0-RELEASE #0: Sat Nov 21 15:02:08 UTC 2009     
root@mason.cse.buffalo.edu:/usr/obj/usr/src/sys/GENERIC  amd64

# clang -v
clang version 2.8 (branches/release_28)
Target: x86_64-unknown-freebsd8.0
Thread model: posix
```

So i think -fPIC option has no effect on Clang.
Has anyone any ideas how to fix this problem?


----------



## Rifle (Feb 2, 2011)

pselect.S compiles with following options:

```
/usr/local/bin/clang -O2 -pipe  -Wtypedef-redefinition -DMAXPAGESIZES=3 -I/src/include -fPIC 
-I/src/r217821/lib/libc/include -I/src/r217821/lib/libc/../../include -I/src/r217821/lib/libc/amd64 
-DNLS  -D__DBINTERFACE_PRIVATE -I/src/r217821/lib/libc/../../contrib/gdtoa -DINET6 
-I/usr/obj/src/r217821/lib/libc -I/src/r217821/lib/libc/resolv -D_ACL_PRIVATE -DPOSIX_MISTAKE 
-I/src/r217821/lib/libc/../../contrib/tzcode/stdtime -I/src/r217821/lib/libc/stdtime 
-I/src/r217821/lib/libc/locale -DBROKEN_DES -DPORTMAP -DDES_BUILTIN -I/src/r217821/lib/libc/rpc -DYP 
-DNS_CACHING -DSYMBOL_VERSIONING -std=gnu99 -fstack-protector -Wsystem-headers -Wall -Wno-format-y2k 
-Wno-uninitialized -Wno-pointer-sign  -c pselect.S
/usr/local/bin/clang -fpic -DPIC -O2 -pipe  -Wtypedef-redefinition -DMAXPAGESIZES=3 -I/src/include -fPIC
-I/src/r217821/lib/libc/include -I/src/r217821/lib/libc/../../include -I/src/r217821/lib/libc/amd64 
-DNLS  -D__DBINTERFACE_PRIVATE -I/src/r217821/lib/libc/../../contrib/gdtoa -DINET6 
-I/usr/obj/src/r217821/lib/libc -I/src/r217821/lib/libc/resolv -D_ACL_PRIVATE -DPOSIX_MISTAKE 
-I/src/r217821/lib/libc/../../contrib/tzcode/stdtime -I/src/r217821/lib/libc/stdtime 
-I/src/r217821/lib/libc/locale -DBROKEN_DES -DPORTMAP -DDES_BUILTIN -I/src/r217821/lib/libc/rpc 
-DYP -DNS_CACHING -DSYMBOL_VERSIONING -std=gnu99 -fstack-protector -Wsystem-headers -Wall 
-Wno-format-y2k -Wno-uninitialized -Wno-pointer-sign  -c pselect.S -o pselect.So
/usr/obj/src/r217821/tmp/usr/bin/ld: pselect.So: relocation R_X86_64_32S can not be used 
when making a shared object; recompile with -fPIC
pselect.So: could not read symbols: Bad value
```


----------



## SirDice (Feb 2, 2011)

If I'm not mistaken this will only work with -CURRENT. 

http://wiki.freebsd.org/BuildingFreeBSDWithClang


----------



## Rifle (Feb 2, 2011)

SirDice said:
			
		

> If I'm not mistaken this will only work with -CURRENT.
> 
> http://wiki.freebsd.org/BuildingFreeBSDWithClang



what does it mean -CURRENT?

I see only "Checkout head (make sure this is r212979 or later):" 
r217821 is the latest revision


----------



## SirDice (Feb 2, 2011)

Rifle said:
			
		

> What does it mean -CURRENT?


Handbook: 24.5 Tracking a Development Branch


----------



## Rifle (Feb 2, 2011)

-CURRENT is 9.0 now?
Sorry for stupid question, but i don't see here folder named current - http://svn.freebsd.org/base
only release and stable
Where can i get current sources and current dist to install?


----------



## Rifle (Feb 2, 2011)

Can I get current sources using svn?
I don't see "current" directory here - http://svn.freebsd.org/base
Or "head" directory is current?


----------



## SirDice (Feb 2, 2011)

If you're asking questions like this you are probably better off sticking with a -RELEASE or -STABLE.


----------



## DutchDaemon (Feb 2, 2011)

Agree. If the terminology confuses you on that basic level, experimenting with compilers may be too early.

Moreover: clang is highly experimental on FreeBSD 9-CURRENT and not even remotely backported (or planned to be backported) to FreeBSD 8-STABLE.


----------



## Rifle (Feb 2, 2011)

Oh, ok, so I need to have FreeBSD 9.0 installed to build it with Clang. 
I didn't noticed this:


> Verify that "/usr/bin/clang -v" produces:
> 
> ```
> FreeBSD clang version 2.8 (branches/release_28 114020) 20100917
> ...


Thanks a lot!
I will try to do it on 9.0 version.


----------



## SirDice (Feb 3, 2011)

Keep in mind that -CURRENT might not even build at times. It may also be quite unstable.

That said, if you want to learn a lot then by all means, go for it.


----------



## xibo (Feb 3, 2011)

Although not officially supported yet, clang can already be used to compile a working FreeBSD-8-STABLE kernel, and for most of the userland. It fails on compiling the system gcc over here.

The relocation of fPIC symbols looks weird to me, i never had that issue with clang or pcc. Are you getting the build directory cleaned before make is run?


----------



## Rifle (Feb 3, 2011)

xibo said:
			
		

> The relocation of fPIC symbols looks weird to me, i never had that issue with clang or pcc. Are you getting the build directory cleaned before make is run?


Yes.
I run 
`rm -rf /usr/obj/*`
and
`make clean`
before each new `make buildworld`


----------

