ETHW

(Difference between pages)
(Getting started with Teredo)
 
(Using clang with portage)
 
Line 1: Line 1:
= Introduction =
+
==Introduction==
 +
LLVM can be used as an alternative to GNU's compiler, GCC. The main benefit of using LLVM compilers instead of GCC is their lower memory usage, faster compile time and better diagnostics. There are some Benchmarks on the [http://clang.llvm.org/features.html#performance Clang] and [http://www.phoronix.com/scan.php?page=article&item=llvm3_gcc_open64 Phoronix] homepages.
  
[[wikipedia:IPv6|IPv6]] is an redesigned and improved version of the IPv4 protocol, and is intended to start replacing IPv4 in 2011 and beyond as the [[wikipedia:IPv4_address_exhaustion|IPv4 global address space becomes exhausted]]. IPv6 includes a number of improvements over IPv4, including most notably 128-bit addressing, simplified protocol header, integrated IPSec and Multicast implementations, improved discovery, flexibility and router interaction, and improved facilities for auto-configuration. IPv6 also marks the end of [[wikipedia:Network_address_translation|Network Address Translation]] (NAT), which is not recommended or necessary with IPv6. While it's possible to use non-routable addresses with IPv6, this is not a requirement and it is possible for any IPv6 device to have its own globally routable IP address if desired.
+
It may happen that some programs do not compile (like glibc) because they depend on GCC-specific language extensions [http://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html] (this is why the whole BSD code can be compiled with LLVM but some GNU code cannot) or segfault after successful compilation with LLVM (like xorg-server) but after following this guide, the system will still be able to compile packages with gcc. So if something goes wrong, it can be switched back to gcc for the particular package by uncommenting lines in /etc/make.conf and the bug should be reported.
  
== Addressing ==
+
LLVM's C/C++ frontends clang and clang++ version 3.0 are stable enough to be self-hosting [http://blog.llvm.org/2010/02/clang-successfully-self-hosts.html] and compile Boost [http://blog.llvm.org/2010/05/clang-builds-boost.html], Qt [http://labs.qt.nokia.com/2010/10/29/compiling-qt-with-clang/], LibreOffice [http://wiki.documentfoundation.org/Development/Building_LibreOffice_with_Clang], FreeBSD [http://wiki.freebsd.org/BuildingFreeBSDWithClang], some parts of the Linux kernel [http://lwn.net/Articles/411654/] and more.
  
IPv6 addresses consist of 128 bits. The first 64 bits are used for the network and subnet portion of the address, while the remaining 64 bits are used for the host portion of the address. For more information on how to represent IPv6 addresses, please see the Presentation section of the [[wikipedia:IPv6_address|IPv6 address]] page on Wikipedia.  
+
Further, using LLVM 3.0 and up, there is a third way to compile with LLVM: the dragonegg package creates a gcc-plugin, that uses LLVM's optimizers but parses the code and creates binaries with gcc, which means that everything that compiles and works with gcc should work with dragonegg also. This plugin can be enabled by using a single CFLAG. Since LLVM 3.0 the old llvm-gcc package is deprecated and replaced by dragonegg, so it will disappear from portage with llvm version 2.9.
  
=== Network Masks ===
+
==LLVM Frontends==
 +
To be able to compile some sourcecode of a specific language, LLVM needs an appropriate frontend. There are clang, llvm-gcc and dragonegg in portage.
  
IPv6 addresses also have an associated network mask, which is typically written as a trailing "/64" or "/48" at the end of the address, which specifies what bits of the address are used for network and subnet parts. For example, a "/48" mask specifies that addresses use a 48-bit network part, followed by a 16-bit subnet part (allowing for 2^16 subnets), followed by a 64-bit host part (allowing for up to 2<sup>64</sup> hosts for each of the 2<sup>16</sup> subnets to be specified.) In contrast, a "/64" mask specifies that addresses use a 64-bit network part, no subnet part, and a 64-bit host part (allowing up to 2<sup>64</sup> hosts total to be specified.) This means that if you are issued a "/64" set of addresses, you will not be able to define any subnets, but if you are issued a "/48" set of addresses, you will be able to define up to 2<sup>16</sup> subnets.
+
The goal of the Clang project is to create a new C, C++, Objective C and Objective C++ front-end for the LLVM compiler.
  
=== Address Space and Security ===
+
llvm-gcc is a modified version of gcc that compiles C/ObjC programs into native objects, LLVM bitcode or LLVM assembly language, depending upon the options. As written in the previous section, dragonegg replaced llvm-gcc in version 3.0.
  
IPv6 also uses a global, flat address space. IPv6 is designed so that any device that needs to communicate on the Internet is able to have a unique globally-routable address. With IPv6, there is no need for using [[wikipedia:Network_address_translation|Network Address Translation]] (NAT). With IPv4, NAT is often used as a means of protecting systems from being accessed by malicious users. With IPv6, firewalls are typically used instead of NAT for restricting access to systems. With IPv6, it is normal for all machines on your home network to have "globally routable" addresses, the equivalent of a "public IP" in the world of IPv4. It is important to understand that this is the way that IPv6 is intended to be used for the majority of users, and that an IPv6-enabled router will no longer be performing NAT for you.
+
So after installing llvm, clang and dragonegg, you will be able to choose between gcc and llvm whenever you like or use them both at the same time.
  
=== Using IPv6 ===
+
== Install LLVM and its Frontends ==
 
+
Simply emerge the packages on ~arch systems. On arch systems you have to unmask some packages first. dragonegg requires gcc's ''lto'' USE-flag to be set and works with gcc 4.5 and gcc 4.6.
There are several ways to use IPv6 with Funtoo Linux. Here are some possibilities:
+
 
+
* Participating in an existing IPv6 network
+
* Creating a local IPv6 over IPv4 tunnel
+
* Enabling IPv6 on your router, possibly via a tunnel (several ISP uses '''6rd'''...)
+
* Unique Local IPv6 Unicast Addresses (site local)
+
 
+
==== Participating in IPv6 Network ====
+
 
+
The first approach is an option if your Funtoo Linux system happens to be on an IPv6 network, or you desire to set up an IPv6 network. In this case, the Funtoo Linux system simply needs to be configured to participate in this IPv6 network -- and can also participate in an IPv4 network simultaneously. If you will be configuring an IPv6-compatible router, then you will simply configure your Funtoo Linux system to participate in this network.
+
 
+
==== Local IPv6 over IPv4 Tunnel ====
+
 
+
Another approach for using IPv6 is to configure an IPv6 over IPv4 tunnel locally on your Funtoo Linux system, in cooperation with a tunnel provider. This will allow you to use an existing IPv4 network to connect a single Funtoo Linux system to IPv6. It is also possible to configure this system to serve as an IPv6 router.
+
 
+
==== Enabling IPv6 on Your Router ====
+
 
+
If you have a router that is capable of supporting IPv6, then it is possible to configure your router so that an IPv6 network is available, at which point you can simply configure your Funtoo Linux system to participate in it. Note that many popular home/office routers can be configured to use an IPv6 over IPv4 tunnel, which provides a convenient option for home networks or smaller organizations to participate in IPv6. Using this approach, your computer systems behind the router are simply configured to participate in an IPv6 network, and your router handles tunneling the IPv6 traffic back and forth between your tunnel provider. This is typically the most flexible option for exploring IPv6 as it allows you to have multiple computer systems in your home or office to participate in an IPv6 network while your router takes care of everything transparently.
+
 
+
==== Using Unique Local IPv6 Unicast Addresses ====
+
 
+
If you don't have public IPv6 connectivity or you don't wish to open an IPv6 tunnel over an IPv4 network, you can use a mechanism similar to IPv4 private addresses ranges. This mechanism consists of concatenating the prefix FC00::/7 with a globally unique identifier and a subnet identifier to form the upper 64 bits of the IPv6 address. Details of the mechanisms to forge a unique local IPv6 unicast address are documented in [http://tools.ietf.org/html/rfc4193 RFC 4193], however unique local IPv6 unicast addresses are made of the following components:
+
 
+
<pre>
+
      | 7 bits |1|  40 bits  |  16 bits  |          64 bits          |
+
      +--------+-+------------+-----------+----------------------------+
+
      | Prefix |L| Global ID  | Subnet ID |        Interface ID        |
+
      +--------+-+------------+-----------+----------------------------+
+
</pre>
+
 
+
* Prefix (7 bits): always FC00::/7
+
* L (1 bits): must be set to 1 (1 = prefix is locally assigned, 0 is undefined so far and must not be used)
+
* Global ID: A random identifier (see [http://tools.ietf.org/html/rfc4193 RFC 4193] for details about the generation algorithm
+
* Interface ID: Host interface ID as defined in [http://tools.ietf.org/html/rfc3513 RFC 3513]
+
 
+
{{fancynote|Just like with private IPv4 addresses, an IPv6 router must not route a unique local IPv6 unicast address outside the organization local network.}}
+
 
+
= Requirements =
+
 
+
IPv6 requires CONFIG_IPV6 to be enabled in your kernel (either compiled in or as a module). If compiled as a module (e.g. if your kernel was compiled by genkernel), ensure the module is loaded.
+
 
<console>
 
<console>
###i## lsmod | grep ipv6
+
###i## emerge llvm clang dragonegg
 
</console>
 
</console>
 +
Note, that for clang++ the C++ headers search path is hardcoded to the active gcc profile.
 +
If you change the active gcc profile, or update gcc to a new version, you will have to remerge clang to update the search path.
 +
 +
To use dragonegg, run gcc as usual, with an extra command line argument <tt>-fplugin=/usr/lib/llvm/dragonegg.so</tt>
 +
If you change the active gcc profile, or update gcc to a new version, you will have to remerge dragonegg to update the plugin.
  
If this returns nothing, load the module with:
+
After the installation, check which CPUs are supported by using the command
 
<console>
 
<console>
###i## modprobe ipv6
+
###i## llvm-as < /dev/null | llc -mcpu=help
 
</console>
 
</console>
 +
and then add the following lines to <code>/etc/make.conf</code> (uncommenting the lines you need) to enable compilation via LLVM, adapting the march-option according to the previous command:
  
= Commands =
+
in <code>/etc/portage/make.conf</code>:
 +
{{File
 +
|/etc/portage/make.conf|<pre>
 +
# LLVM
 +
#CC="/usr/bin/clang"
 +
#CXX="/usr/bin/clang++"
  
; ping6
+
# llvm-gcc for C++ code and fortran
: IPv6 ping command
+
# llvm-gcc is deprecated and only used with LLVM 2.9
; route -6
+
#CC="/usr/bin/llvm-gcc"
: show IPv6 routes
+
#CXX="/usr/bin/llvm-g++"
; ip -6 neigh show
+
#CPP="/usr/bin/llvm-cpp"
: show all IPv6 neighbors on the local LAN
+
#F77="/usr/bin/llvm-gfortran"
  
= Configuration =
+
# Flags for clang: Insert your arch here instead of k8 and have a look at the manpage of clang for flag descriptions.
 +
# Some gcc flags like -pipe and -pthread also work, though they might be ignored by clang.
 +
#CFLAGS="-march=k8 -O2"
  
== Participating in an Existing IPv6 Network ==
+
# Flags for dragonegg; just use all the gcc flags you like and append -fplugin=/path/to/dragonegg.so
 
+
#CFLAGS="-march=k8 -O2 -fplugin=/usr/lib64/llvm/dragonegg.so"
If your local network already supports IPv6, then you can simply configure Funtoo Linux to participate in this IPv6 network. Here is a sample configuration that might be used to configure an ethernet interface (netif.eth0) to participate in both an IPv4 and IPv6 network:
+
 
+
{{File
+
|/etc/netif.d/netif.eth0|<pre>
+
template="interface"
+
ipaddr="10.0.1.200/24 2001:470:d:c2c:218:51ff:feea:ee21/64"
+
gateway="10.0.1.1"
+
nameservers="10.0.1.1 2001:470:20::2"
+
domain="funtoo.org"
+
multicast="yes"
+
routes="2000::/3 via fe80::daa2:5eff:fe7a:83de dev eth0"
+
 
</pre>}}
 
</pre>}}
  
Above, we use the <tt>interface</tt> template, and specify both an IPv4 and IPv6 address (with network mask) for <tt>ipaddr</tt>. In addition, an IPv4 and IPv6 nameserver is specified. For routing, we use the <tt>gateway</tt> command to specify an IPv4 gateway, while we use the <tt>routes</tt> command to specify a route to our router, which in this case has address <tt>fe80::daa2:5eff:fe7a:83de</tt> and is reachable on device eth0.
+
{{Note}} Have a look at clang's manpages for additional information. If you get errors that your compiler cannot produce code, you should check your flags, e.g. don't use <tt>-O4 -flto -S</tt> or stuff like that; the examples above will work.
  
Note that we specify a route for "2000::/3" rather than "::/0" or "default", and this is a bit unusual. This is to work around a bug in many Linux kernels that prevents the default route from being handled properly. "2000::/3" maps to all routable IP addresses and has the benefit of being compatible with all Linux kernels.
+
== Using clang with portage ==
  
=== Many Addresses and Stateless Autoconfiguration ===
+
Although Gentoo package tree is not designed to be used with compiler other than GCC, clang can be enforced on most of the packages through ''CC'' and ''CXX'' variables.
  
Also note that if we did not specify an IPv6 address in the <tt>ipaddr</tt> variable, then eth0 would still get at least one IPv6 address anyway. First, it would get a link-local address, starting in <tt>fe80::/16</tt>, and it would also automatically use ''stateless autoconfiguration'' to grab an unused IPv6 address from the range used by your IPv6 router. This works similarly to the way a DHCP client works with IPv4, but is built-in to the IPv6 protocol and does not require a DHCP server to function. It works because with IPv6, routers send out ICMP packets to advertise themselves to systems on your network, and your Funtoo Linux system can use this information to automatically grab an unused address. It is important to understand this behavior because it means that by default, your Funtoo Linux system will grab a globally-routable ("public") IPv6 address from your router with no steps necessary on your part and thus may be accessible from the Internet if no firewall is in place. However, in most cases the default IPv6 route must be specified in the <tt>routes</tt> variable for IPv6 to function properly, so this auto-configuration isn't completely automatic at this time.
+
Please note, however, that many of Gentoo packages still don't build with clang and a few don't work correctly after being built. That's why we suggest using <tt>/etc/portage/env</tt> file to enable the use of clang per-package.
  
== Local IPv6 over IPv4 Tunnelling ==
+
In order to do that, first create a new environment override to use in <code>/etc/portage/env/clang</code>:
 +
{{File
 +
|/etc/portage/env/clang|<pre>
 +
CC=clang
 +
CXX=clang++
 +
</pre>}}
  
Tunnelling is the process of encapsulating IPv6 packets within an IPv4 packet so that it can be transmitted over an IPv4 network. This process happens at a local ''tunnel entry point'', which can be a Linux machine or a router, such as an Apple AirPort. The packet then traverses the IPv4 network, until reaches the ''tunnel endpoint'', which ''de-encapsulates'' the packet and places it on an IPv6 network. There are several different types of IPv6 tunnels. There are also several IPv6 tunnel providers that offer free tunnelling services, making it convenient to start using IPv6, even on your home network.
+
Then you can enable use of clang for packages using the [[:/etc/portage/env|/etc/portage/package.env]] file:
 +
|/etc/portage/package.env|<pre>
 +
app-foo/bar clang
 +
app-bar/baz clang
 +
</pre>}}
  
Note that if you want configure an IPv6 over IPv4 tunnel on your router, such as an Apple AirPort, then you will simply need to sign up with one of the tunnel providers and use their instructions to configure your router. At this point, your router will be IPv6 enabled and you can then configure your Funtoo Linux system to participate in an existing IPv6 network using the instructions in the previous section. If this is not an option for you, then it is also possible to set up the IPv6 over IPv4 tunnel directly on your Funtoo Linux system. This means that only your Funtoo Linux system will be able to participate in IPv6, at least to start (later, you could configure your Funtoo Linux system to route IPv6 for other machines on your network) Follow the instructions in this section to set up local tunneling on your Funtoo Linux system.
+
If you want to use clang by default you can and need to specify some core packages. Here is small list of core packages that are currently failing on clang, but not that could be outdated:
 +
{{File
 +
|/etc/portage/env/gcc|<pre>
 +
CC=gcc
 +
CXX=g++
 +
</pre>}}
  
=== Tunnel providers ===
+
in addition, it is recommend to add compiler flags there:
; [http://gogonet.gogo6.com/page/freenet6-tunnelbroker freenet6]
+
{{File
: Supports anonymous tunnels and works behind NAT. You can connect to with your login or as anonymous from anywhere. This can be configured under Funtoo Linux by emerging the '''net-misc/gogoc''' ebuild.
+
|/etc/portage/env/gcc|<pre>
; [http://tunnelbroker.net/ Hurricane Electric]
+
CFLAGS="-O2 -march=native -mtune=native -pipe"
: Configured '''6in4''' tunnel, with support for dynamic IPv4 addresses, and Apple AirPorts can be configured to use this tunnel - see [http://www.nedprod.com/Niall_stuff/addingIPv6toyourhome.html this link]. Also see [http://ipv6.he.net/certification/faq.php ipv6.he.net FAQ] You can setup this tunnel with ifconfig and iproute2, or configure your router to be the tunnel entry point  -- the point at which IPv6 traffic is encapsulated/de-encapsulated.
+
CXXFLAGS="-O2 -march=native -mtune=native -pipe"
; [http://en.wikipedia.org/wiki/Teredo_tunneling Teredo]/[http://www.remlab.net/miredo/ Miredo]
+
LDFLAGS="-Wl,--as-needed"
: [http://tools.ietf.org/html/rfc4380 RFC4380] mandated transition mechanism. Works behind NAT. Assigns one "/128" per host.
+
#You can disable gold link here
 +
#EXTRA_ECONF="--enable-gold=default"
 +
</pre>}}
  
=== Getting Started with gogoc ===
+
And in <code>/etc/portage/package.env</code>:
 
+
{{File
Freenet6 is a free IPv6 access service provided by gogo6 via the [http://en.wikipedia.org/wiki/Tunnel_Setup_Protocol TSP tunnelling protocol].
+
|/etc/portage/package.env|<pre>
<code>gogoc</code> supports any TSP tunnel; perhaps one is provided by your ISP. We will focus on an anonymous tunnel via freenet6.
+
#---------------CORE PACKAGES TO BUILD WITH GCC:
 
+
sys-apps/which gcc
You need ipv6 to be enabled in your kernel as well as the TUN module.
+
sys-fs/reiserfsprogs gcc
 +
sys-libs/ncurses gcc
 +
sys-libs/zlib gcc
 +
sys-apps/busybox gcc
 +
sys-fs/e2fsprogs gcc
 +
sys-devel/binutils gcc
 +
sys-libs/glibc gcc
 +
sys-devel/dragonegg gcc
 +
dev-libs/openssl gcc
 +
sys-boot/grub gcc
 +
#---------------USER PACKAGES TO BUILD WITH GCC:
 +
sys-apps/pacman gcc
 +
www-client/firefox gcc
 +
x11-libs/cairo gcc
 +
media-libs/mesa gcc
 +
</pre>}}
  
You can quickly get started by emerging {{Package|net-misc/gogoc}}, adding <code>gogoc</code> to your startup scripts and starting it.
+
If you have {{Package|app-portage/flaggie}} installed, you can modify <code>/etc/portage/package.env</code> by running the following:
{{Package|net-misc/gogoc}} is currently keyworded unstable (on some architectures, see [https://bugs.gentoo.org/362549 gentoo bug #362549]). If you are running stable Funtoo, you may want to put an entry into your package.keywords/package.accept_keywords file.
+
 
<console>
 
<console>
###i## emerge gogoc
+
###i## flaggie app-foo/bar app-bar/baz +clang
###i## bzcat /usr/share/doc/gogoc-*/gogoc.conf.sample.bz2 >/etc/gogoc/gogoc.conf
+
###i## rc-update add gogoc default
+
###i## /etc/init.d/gogoc start
+
 
</console>
 
</console>
  
{{Note}}By default, <code>gogoc</code> will use an anonymous tunnel. If you wish to authenticate yourself, read and edit <code>/etc/gogoc/gogoc.conf</code>.
+
== Enabling link-time optimizations ==
  
=== Getting started with Teredo ===
+
The ''link-time optimization'' feature defers optimizing the resulting executables to linking phase. This can result in better optimization of packages but is unsupported in Gentoo, and many packages simply fail to build.
  
While this mechanism is officially called Teredo, the implementation of the Teredo service we will be using is called Miredo.
+
When using LTO, clang compiles units into LLVM byte-code rather than machine code. In order to support linking such object files, the [[gold]] linker must be installed and set as the default linker, as it does support plugins.
{{Note}}{{Package|net-misc/miredo}} is currently keyworded unstable. If you are running stable Funtoo, you may want to put an entry into your package.keywords/package.accept_keywords file.}}
+
  
Emerge <tt>net-misc/miredo</tt> and start it up (you can add it to your default runlevel if you wish):
+
Similarly, ''ar'' needs plugin support as well. Sadly, binutils ar doesn't support passing '--plugin'' option before the actual command. Thus, we need to create a wrapper for it:
 +
 
 +
in ''<code>/usr/local/bin/clang-ar</code>'':
 
<console>
 
<console>
###i## emerge net-misc/miredo
+
###i## nano /usr/local/bin/clang-ar
###i## /etc/init.d/miredo start
+
#!/bin/sh
 +
firstarg=${1}
 +
shift
 +
 
 +
exec /usr/bin/ar "${firstarg}" --plugin /usr/lib/llvm/LLVMgold.so "${@}"
 
</console>
 
</console>
  
{{Note}}Miredo requires <code>CONFIG_TUN</code> enabled in your kernel. If it is compiled as a module, ensure the <tt>tun</tt> module is loaded.
+
If that's done, you can create a new environment override profile for LTO-enabled clang:
  
If all goes well, you can check the assignment of an IPv6 address using <tt>/sbin/ip</tt>, for example:
+
in ''<code>/etc/portage/env/clang-lt</code>'':  
 
<console>
 
<console>
###i## /sbin/ip addr show dev teredo
+
CC='clang'
4: teredo: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1280 qdisc pfifo_fast state UNKNOWN qlen 500
+
CXX='clang++'
    link/none
+
CFLAGS="${CFLAGS} -O4"
    inet6 2001:0:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx/32 scope global
+
CXXFLAGS="${CXXFLAGS} -O4"
      valid_lft forever preferred_lft forever
+
LDFLAGS="${LDFLAGS} -O4 -Wl,-plugin,/usr/lib/llvm/LLVMgold.so"
    inet6 fe80::ffff:ffff:ffff/64 scope link
+
AR='/usr/local/bin/clang-ar'
      valid_lft forever preferred_lft forever
+
RANLIB=':'
 +
NM='nm --plugin /usr/lib64/llvm/LLVMgold.so'
 
</console>
 
</console>
  
=== Getting started with Hurricane Electric ===
+
Note that the link-time optimizations were indirectly enabled here via ''-O4''. If you don't want to enable other optimizations enforced by ''-O3'', please use ''-flto'' instead. You need to also pass optimization flags when linking because that's where clang needs them.
{{fancywarning|This section has not been written.}}
+
  
=== Tunnelling 6to4 ===
+
You may also need to adjust the libdir path to plugin. Newer (live) versions of clang add `-plugin` when linking automatically, so `-Wl,-plugin`… is no longer necessary.
  
6to4 is an Internet transition mechanism for migrating from IPv4 to IPv6, a system that allows IPv6 packets to be transmitted over an IPv4 network (generally the IPv4 Internet) without the need to configure explicit tunnels.
+
== Using clang with distcc ==
When using 6to4 your IPv6 golablly addressable IP is generated from you IPv4 IP address.
+
  
The anycast address of 192.88.99.1 has been allocated for the purpose of sending packets to a 6to4 relay router. Note that when converted to a 6to4 IPv6 address with the subnet and hosts fields set to zero this IPv4 address (192.88.99.1) becomes the IPv6 address 2002:c058:6301::.
+
In order to use clang on distcc client, additional symlinks have to be created in ''<code>/usr/lib*/distcc/bin</code>'':
 
+
<console>
To use the funtoo network template method, write the config file for the interface /etc/conf.d/netif.6to4 (which will also handle the converting of your IPv4 address to your IPv6 address). Make sure you change "WAN" to your correct internet facing interface.
+
###i## ln -s /usr/bin/distcc /usr/lib/distcc/bin/clang
<pre>
+
###i## ln -s /usr/bin/distcc /usr/lib/distcc/bin/clang++
template=ipv6-tunnel
+
</console>
WAN="eth0"
+
MTU="1280"
+
ipv4=`ifconfig $WAN | sed -ne 's/[[:space:]]*inet addr:\([0-9.]*\).*/\1/p'`
+
ipv6=`printf "2002:%02x%02x:%02x%02x::1" \`echo $ipv4 | tr "." " "\``
+
remote=192.88.99.1
+
local="$ipv4/24"
+
ipaddr="$ipv6/48"
+
routes="2000::/3 via 2002:c058:6301:: dev $WAN"
+
</pre>
+
 
+
Then create the netif.6to4 symlink and add it to the default runlevel
+
<pre>
+
# ln -s /etc/init.d/netif.tmpl /etc/init.d/netif.6to4
+
# rc-update add netif.6to4 default
+
# /etc/init.d/netif.6to4 start
+
</pre>
+
 
+
You should now be capable of connecting via IPv6
+
<pre>
+
# ping6 ipv6.google.com
+
</pre>
+
 
+
To allow this host to be a router, a modified template is required.
+
/etc/netif.d/ipv6-tunnel
+
<pre>
+
#!/bin/sh
+
 
+
netif_pre_up() {
+
        require local remote
+
        try ip tunnel add $interface mode sit remote $remote local $local ttl 255
+
        try ip addr add $ipaddr dev $interface
+
        try ip addr add $ipaddr4 dev $interface
+
}
+
 
+
netif_post_up() {
+
        try ip route add ::/0 dev $interface
+
}
+
 
+
netif_pre_down() {
+
        ip route del ::/0 dev $interface
+
}
+
 
+
netif_post_down() {
+
        ip tunnel del $interface
+
}
+
</pre>
+
 
+
Then add the following line to /etc/conf.d/netif.6to4
+
<pre>
+
ipaddr4="$ipv4/24"
+
</pre>
+
 
+
After restarting the 6to4 interface radvd can be started
+
<pre>
+
# /etc/init.d/netif.6to4 restart
+
# /etc/init.d/radvd start
+
</pre>
+
 
+
== Optimization ==
+
 
+
=== Prefer IPv4 over IPv6 ===
+
 
+
Generally if your IPv6 connection is through a tunnel, it will be slower than an IPv4 connection. For this reason, if you are using an IPv6 tunnel, it can be best to configure your systems to ''prefer'' IPv4 if an IPv4 version of the site is available, and use IPv6 only when necessary. This way, you will avoid unnecessary encapsulation and de-encapsulation of IPv4 traffic. Here's how to do this for a number of operating systems:
+
 
+
==== Linux ====
+
 
+
Linux will prefer IPv6 if IPv6 support is enabled in the kernel. To prefer IPv4, edit <tt>/etc/gai.conf</tt> and add this line:
+
+
<pre>
+
precedence ::ffff:0:0/96 100
+
</pre>
+
 
+
==== Windows 7, Server 2008, Vista ====
+
 
+
These operating systems prefer IPv6 by default. See [http://msdn.microsoft.com/en-us/library/bb756941.aspx this link]. To prefer IPv4, use the following steps:
+
 
+
# Start <tt>regedit</tt>.
+
# Navigate to <tt>HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\TCPIP6\Parameters</tt>.
+
# Create a new DWORD named <tt>DisabledComponents</tt>. Edit this new DWORD and set it to HEX value of <tt>20</tt> or a DECIMAL value of <tt>32</tt>.
+
# Restart your computer.
+
 
+
== ISPs who currently have IPv6 enabled for residential customers ==
+
 
+
* Canada:
+
** '''Videotron''': Videotron has a [http://support.videotron.com/residential/internet/ipv6/videotron-ipv6 beta-program] for residential customers who want to test IPv6 (no official technical support, it is possible they don't have enabled it in your area so check first before investing in new hardware). Although  at date of writing, a large part of their networks are IPv6, '''you must go through a 6rd tunnel''' because they still need to upgrade some of their equipments and '''your router must support the 6rd protocol''' (this requirement is documented). Videotron sells you a D-Link DIR-825 with a modified firmware however this model has a weird gotcha: it does not support IPv6 firewalling.''' This is not a Videotron specific issue''' (even the genuine firmwares coming  from the manufacturer has no support for IPv6 firewalling as of June 2011). A good alternative to recommend is the CISCO/LinkSYS E4200, more expensive (MSRP ~$180 US/CDN) but has IPv6 firewalling support.  Once the E4200 firmware has been upgraded go in Setup/IPv6 Setup disable "IPv6 - Automatic" (you should then see an IPv6 address in the DUID field) and leave "automatic" for the 6rd configuration. You should be in business and see all of the hosts on your network with an IPv6 stack enabled being assigned a public IPv6 address starting with 2607:f048.
+
** '''Teksavvy'''(?)
+
* France
+
** '''Free'''
+
** '''Nerim'''
+
** '''the French Data Network (FDN)'''
+
* United States:
+
** '''Comcast''' (limited pilot in some areas only)
+
 
+
== Home routers compatible with IPv6 ==
+
  
A few residential routers have support for IPv6 at date of writing and many more home networking devices will have robust IPv6 support in a more or less near futures. The following does not pretend to be exhaustive:
+
{{GLW|src=http://wiki.gentoo.org/wiki/Clang}}
* '''D-Link DIR-825 rev. 1B''' (June 2011): Has IPv6 support out of the box, however for somewhat reason the router has no support for IPv6 firewalling even with teh 2.05N revision of the firmware. Consequence for you is you have to deploy an IPv6 firewall on each of hosts concerned with a public IPv6 connectivity. The canadian ISP Videotron is selling a DIR-825 with a customized firmware as unfortunately, like with the genuine manufacturer firmware, no IPv6 firewalling possible :( .
+
* '''CISCO/LinkSys E4200''' (June 2011): Advertised as being IPv6 compatible with a firmware update (available as of June 14th 2011 -> check for the version tagged 1.0.02 build 13 or later on the manufacturer website). The device supports native IPv6 and IPv6 through a 6rd tunnel (no support for any other tunneling protocol).
+
  
== Resources ==
 
*[http://ipv6.he.net/certification/cert-main.php free ipv6 certification program]
 
*[http://ipv6-test.com/ Test ipv6 (ipv6-test.com)]
 
*[http://test-ipv6.com/ Test ipv6 (test-ipv6.com)]
 
*[http://www.comcast6.net/ Comcast's IPv6 page]
 
*[http://tunnelbroker.net/ Hurricane Electric Tunnel Broker ]
 
*[http://www.gentoo-wiki.info/HOWTO_IPv6 Gentoo Wiki IPv6 ]
 
*[http://www.gentoo.org/doc/en/ipv6.xml Gentoo IPv6 Guide]
 
with Apple airport extreme, etc:
 
*[http://www.tunnelbroker.net/forums/index.php?topic=680.0 tunnelbroker.net forums post - airport config ]
 
*[http://www.nedprod.com/Niall_stuff/addingIPv6toyourhome.html Adding IPv6 Support To Your Home]
 
*[http://www.tunnelbroker.net/forums/index.php?topic=273.0 tunnelbroker.net forums post - Gentoo config (won't work in Funtoo)]
 
Nice Overview over IPv6
 
* [http://www.linux.com/learn/tutorials/428331-ipv6-crash-course-for-linux IPv6 Crash Course for Linux] and page 2 [http://www.linux.com/learn/tutorials/432537:another-ipv6-crash-course-for-linux-real-ipv6-addresses-routing-name-services IPv6 Crash Course for routing name services]
 
* [http://livre.g6.asso.fr/index.php/Accueil IPv6 Théorie et Pratique (in french only)] revised online version of the O'Reilly book published in 2005 by a collective researchers and IT actors.
 
 
[[Category:HOWTO]]
 
[[Category:HOWTO]]
[[Category:Networking]]
 
[[Category:Featured]]
 

Revision as of 14:27, January 28, 2014

Introduction

LLVM can be used as an alternative to GNU's compiler, GCC. The main benefit of using LLVM compilers instead of GCC is their lower memory usage, faster compile time and better diagnostics. There are some Benchmarks on the Clang and Phoronix homepages.

It may happen that some programs do not compile (like glibc) because they depend on GCC-specific language extensions [1] (this is why the whole BSD code can be compiled with LLVM but some GNU code cannot) or segfault after successful compilation with LLVM (like xorg-server) but after following this guide, the system will still be able to compile packages with gcc. So if something goes wrong, it can be switched back to gcc for the particular package by uncommenting lines in /etc/make.conf and the bug should be reported.

LLVM's C/C++ frontends clang and clang++ version 3.0 are stable enough to be self-hosting [2] and compile Boost [3], Qt [4], LibreOffice [5], FreeBSD [6], some parts of the Linux kernel [7] and more.

Further, using LLVM 3.0 and up, there is a third way to compile with LLVM: the dragonegg package creates a gcc-plugin, that uses LLVM's optimizers but parses the code and creates binaries with gcc, which means that everything that compiles and works with gcc should work with dragonegg also. This plugin can be enabled by using a single CFLAG. Since LLVM 3.0 the old llvm-gcc package is deprecated and replaced by dragonegg, so it will disappear from portage with llvm version 2.9.

LLVM Frontends

To be able to compile some sourcecode of a specific language, LLVM needs an appropriate frontend. There are clang, llvm-gcc and dragonegg in portage.

The goal of the Clang project is to create a new C, C++, Objective C and Objective C++ front-end for the LLVM compiler.

llvm-gcc is a modified version of gcc that compiles C/ObjC programs into native objects, LLVM bitcode or LLVM assembly language, depending upon the options. As written in the previous section, dragonegg replaced llvm-gcc in version 3.0.

So after installing llvm, clang and dragonegg, you will be able to choose between gcc and llvm whenever you like or use them both at the same time.

Install LLVM and its Frontends

Simply emerge the packages on ~arch systems. On arch systems you have to unmask some packages first. dragonegg requires gcc's lto USE-flag to be set and works with gcc 4.5 and gcc 4.6.

# emerge llvm clang dragonegg

Note, that for clang++ the C++ headers search path is hardcoded to the active gcc profile. If you change the active gcc profile, or update gcc to a new version, you will have to remerge clang to update the search path.

To use dragonegg, run gcc as usual, with an extra command line argument -fplugin=/usr/lib/llvm/dragonegg.so If you change the active gcc profile, or update gcc to a new version, you will have to remerge dragonegg to update the plugin.

After the installation, check which CPUs are supported by using the command

# llvm-as < /dev/null | llc -mcpu=help

and then add the following lines to /etc/make.conf (uncommenting the lines you need) to enable compilation via LLVM, adapting the march-option according to the previous command:

in /etc/portage/make.conf:

{{{name}}}
{{{body}}}

Note

{{{1}}}

Have a look at clang's manpages for additional information. If you get errors that your compiler cannot produce code, you should check your flags, e.g. don't use -O4 -flto -S or stuff like that; the examples above will work.

Using clang with portage

Although Gentoo package tree is not designed to be used with compiler other than GCC, clang can be enforced on most of the packages through CC and CXX variables.

Please note, however, that many of Gentoo packages still don't build with clang and a few don't work correctly after being built. That's why we suggest using /etc/portage/env file to enable the use of clang per-package.

In order to do that, first create a new environment override to use in /etc/portage/env/clang:

{{{name}}}
{{{body}}}

Then you can enable use of clang for packages using the /etc/portage/package.env file:

|/etc/portage/package.env|
app-foo/bar clang
app-bar/baz clang
}}

If you want to use clang by default you can and need to specify some core packages. Here is small list of core packages that are currently failing on clang, but not that could be outdated:

{{{name}}}
{{{body}}}

in addition, it is recommend to add compiler flags there:

{{{name}}}
{{{body}}}

And in /etc/portage/package.env:

{{{name}}}
{{{body}}}

If you have app-portage/flaggie (package not on wiki - please add) installed, you can modify /etc/portage/package.env by running the following:

# flaggie app-foo/bar app-bar/baz +clang

Enabling link-time optimizations

The link-time optimization feature defers optimizing the resulting executables to linking phase. This can result in better optimization of packages but is unsupported in Gentoo, and many packages simply fail to build.

When using LTO, clang compiles units into LLVM byte-code rather than machine code. In order to support linking such object files, the gold linker must be installed and set as the default linker, as it does support plugins.

Similarly, ar needs plugin support as well. Sadly, binutils ar doesn't support passing '--plugin option before the actual command. Thus, we need to create a wrapper for it:

in /usr/local/bin/clang-ar:

# nano /usr/local/bin/clang-ar
#!/bin/sh
firstarg=${1}
shift

exec /usr/bin/ar "${firstarg}" --plugin /usr/lib/llvm/LLVMgold.so "${@}"

If that's done, you can create a new environment override profile for LTO-enabled clang:

in /etc/portage/env/clang-lt:

CC='clang'
CXX='clang++'
CFLAGS="${CFLAGS} -O4"
CXXFLAGS="${CXXFLAGS} -O4"
LDFLAGS="${LDFLAGS} -O4 -Wl,-plugin,/usr/lib/llvm/LLVMgold.so"
AR='/usr/local/bin/clang-ar'
RANLIB=':'
NM='nm --plugin /usr/lib64/llvm/LLVMgold.so'

Note that the link-time optimizations were indirectly enabled here via -O4. If you don't want to enable other optimizations enforced by -O3, please use -flto instead. You need to also pass optimization flags when linking because that's where clang needs them.

You may also need to adjust the libdir path to plugin. Newer (live) versions of clang add `-plugin` when linking automatically, so `-Wl,-plugin`… is no longer necessary.

Using clang with distcc

In order to use clang on distcc client, additional symlinks have to be created in /usr/lib*/distcc/bin:

# ln -s /usr/bin/distcc /usr/lib/distcc/bin/clang
# ln -s /usr/bin/distcc /usr/lib/distcc/bin/clang++


Creative Commons Attribution-NonCommercial-ShareAlike 3.0 United States

The content of this page is a derivative of a Gentoo Linux Wiki article. You can redistribute and/or modify it under the terms of the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License.

(Original Article)