BUG: /lib/lists.c.. Don`t use -O2 . Use -O1

Uwe Kleine-König uwe+bird at kleine-koenig.org
Mon Jan 21 17:31:25 CET 2013


Hello,

On 01/10/2013 03:47 PM, Maksim Tamarsky wrote:
> I found that my trouble exists when compiling with -O2 option.
> In that case inline functions rem_node and add_head will merged into
> function (/nest/iface.c ifa_recalc_primary) and then will badly
> optimized by compiler, because the implicit use of pointers to the same
> data. If we call external function(like printf) between rem_node and
> add_head trouble gone away in any case.
Do you wanna say that adding a printf between rem_node and add_head
makes bird run fine? I analysed the code generated for ARM with -O2 (see
thread "bird6 1.3.7 hangs on start on a Raspberry Pi") and I cannot see
anything wrong with the assembler code.

On the other hand, casting a pointer to the head member of a struct list
to a node * is definitely broken. (This is done in add_head().)
I'm pretty sure this code's behavior is undefined and so should be fixed.
And I consider this to be more likely the cause of the bad behaviour
that you, Fritz and Eric are seeing.

Martin Mares already suggested an alternative implementation for
doubly-linked lists. Another alternative is include/linux/lists.h from
the Linux kernel. I guess an upside of the latter is that it is known to
be working on several architectures. (But note I didn't even look at
Martin's suggestion and so cannot really say how well it is tested.)

Best regards
Uwe



More information about the Bird-users mailing list