[Barrelfish-users] How to compile Barrelfish using gcc-4.4

Timothy Roscoe troscoe at inf.ethz.ch
Sun Sep 26 08:46:55 MEST 2010


Dear Joey, 

Many thanks for this.  Internally, we hit this problem as well moving
to gcc 4.4 a while back.  There are also a few more lurking problems
involving bitfield layout as well...

We're hoping to do another public release in a few weeks or so, which
will build under gcc 4.4 - we'll announce it on this list as soon as
it is ready.  After that, we're hoping to post bug fixes rather more
often than we have recently :-)

Best regards,

 -- Timothy Roscoe


At Thu, 23 Sep 2010 16:26:37 -0700, Joey Trebbien <jtrebbien at gmail.com> wrote:
> Attached is a patch to allow Barrelfish to compile under gcc 4.4.
> 
> I added the -Wno-error=uninitialized option to the cOptFlags variable
> in hake/Config.hs.template to prevent this warning:
> 
>     ../lib/barrelfish/arch/x86_64/syscalls.c: In function ‘cap_invoke_sysret’:
>     ../lib/barrelfish/arch/x86_64/syscalls.c:96: error: ‘cap’ is used
> uninitialized in this function
>     ../lib/barrelfish/arch/x86_64/syscalls.c:35: note: ‘cap’ was declared here
> 
> from stopping the build.
> 
> Second, I fixed two errors such as the following:
> 
>     ../usr/drivers/e1000/e1000n_server.c: In function ‘get_mac_addr’:
>     ../usr/drivers/e1000/e1000n_server.c:196: error: dereferencing
> type-punned pointer will break strict-aliasing rules
> 
> The file e1000n_server.c contained:
> 
>     static void get_mac_addr(struct ether_service_response *cc)
>     {
>         uint8_t hwaddr[6];
>         ethernet_get_mac_address(hwaddr);
> 
>         cc->f->get_mac_address_response(cc, *(uint64_t *)hwaddr);   //
> <--- line 196
>     }
> 
> The problem was that the code tried to force an uint64_t to be located
> at the same location as the uint8_t array hwaddr.  gcc (with the
> -fstrict-aliasing option, enabled automatically in this case with -O2)
> assumes for optimization purposes that objects of different types do
> not have the same location.  See:
> 
>     http://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html#index-freorder_002dfunctions-810
>     http://bytes.com/topic/c/answers/672233-dereferencing-type-punned-pointer-will-break-strict-aliasing-rules
> 
> The way to deal with this situation is to use unions:
> 
>     static void get_mac_addr(struct ether_service_response *cc)
>     {
>         union {
>             uint8_t hwaddr[6];
>             uint64_t hw;
>         } u;
>         ethernet_get_mac_address(u.hwaddr);
> 
>         cc->f->get_mac_address_response(cc, u.hw);
>     }
> 
> I also fixed the #APP and #NO_APP error by adding another sed filter
> in tools/asmoffsets/Hakefile.
> 
> 
> Joey Trebbien


More information about the Barrelfish-users mailing list