Aliasing bug in FICL (may break loader with gcc>4.4)

From: Julian Stecklina <jsteckli_at_os.inf.tu-dresden.de>
Date: Mon, 15 Feb 2010 19:15:08 +0100
Hello,

while porting FICL, I noticed an aliasing bug which manifests (at least)
with gcc 4.4.2 and 4.4.3 when strict-aliasing is enabled. The root cause is

#define LVALUEtoCELL(v) (*(CELL *)&v)

in sys/boot/ficl/ficl.h. CELL is a union:

typedef union _cell
{
    FICL_INT i;
    FICL_UNS u;
[...]
    void *p;
    void (*fn)(void);
} CELL;

If you compile the attached C file with gcc-4.4.3 and -O3, all stores to
i are optimized out and the result is bogus. A ficl built with this gcc
is inoperable.

Giving the union the may_alias attribute works around this, but is GCC
specific (patch is attached). Just using ((CELL)v) does not work without
casting all over the place or extending the union.

Regards, Julian
-- 
"Actually I made up the term 'object-oriented', and I can tell you I
did not have C++ in mind." - Alan Kay (OOPSLA 1997 Keynote)

Received on Mon Feb 15 2010 - 17:15:14 UTC

This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:40:00 UTC