Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20140620225114.GP23102@port70.net>
Date: Sat, 21 Jun 2014 00:51:14 +0200
From: Szabolcs Nagy <nsz@...t70.net>
To: musl@...ts.openwall.com
Subject: Re: Re: broken gcc optimization for facilitynames

* Cl?ment Vasseur <clement.vasseur@...il.com> [2014-06-20 22:09:17 +0000]:
> 
> I made some progress towards a standalone test case. Here it is:
> 
> struct s1 { int v; };
> struct s2 { int v; };
> 
> #define a ((struct s2 *)(struct s1 []){{ 42 }})
> 
> int main(void)
> {
> 	for (int i = 0; a[i].v; i++)
> 		if (a[i].v)
> 			return a[i].v;
> }
> 
> I also found out which optimization flag causes the broken output, it's
> -fstrict-aliasing. I guess the issue here is whether casting `struct s1
> []` to `struct s2 *` violates the strict aliasing rules or not. Indeed,
> compiling with -Wstrict-aliasing=1 shows a warning at this location.
> 
> Can someone pinpoint the exact location in the ISO C spec where there is
> an explanation about the aliasing rules with this kind of pointer
> compatibility?

http://port70.net/~nsz/c/c11/n1570.html#6.5p7

different structs are not compatible types and
object with s1 effective type is accessed through
an expression with s2 type

(if a union of s1 and s2 were used then it would
be ok, because of the "common initial sequence"
rule, or if the first member of s1 had type s2,
because aggregate member can be aliased that way)

so yes this is an aliasing violation and syslog.h
should be fixed

Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.