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

Joey Trebbien jtrebbien at gmail.com
Fri Sep 24 01:26:37 MEST 2010


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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: barrelfish-gcc4.4.patch
Type: text/x-patch
Size: 4546 bytes
Desc: not available
Url : https://lists.inf.ethz.ch/pipermail/barrelfish-users/attachments/20100923/fd96beac/barrelfish-gcc4.4.bin


More information about the Barrelfish-users mailing list