This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
ldlang won't compile with latest gcc
- From: DJ Delorie <dj at redhat dot com>
- To: binutils at sources dot redhat dot com
- Date: Wed, 27 Jul 2005 14:12:42 -0400
- Subject: ldlang won't compile with latest gcc
../../src/ld/ldlang.c:1043: warning: dereferencing type-punned pointer will break strict-aliasing rules
static lang_output_section_statement_type *
lang_output_section_statement_lookup_1 (const char *const name, int constraint)
{
lang_output_section_statement_type *lookup;
. . .
lang_statement_append (&lang_output_section_statement,
(lang_statement_union_type *) lookup,
(lang_statement_union_type **) &lookup->next);
I'm proposing this type of solution, although we could have used a
union to change the type also. Comments?
* ldlang.c (lang_output_section_statement_lookup_1): Don't
cast a unary & address operator, as that breaks GCC's strict
aliasing rules.
Index: ldlang.c
===================================================================
RCS file: /cvs/src/src/ld/ldlang.c,v
retrieving revision 1.192
diff -p -U3 -r1.192 ldlang.c
--- ldlang.c 15 Jul 2005 12:19:13 -0000 1.192
+++ ldlang.c 27 Jul 2005 18:11:05 -0000
@@ -1010,6 +1010,7 @@ static lang_output_section_statement_typ
lang_output_section_statement_lookup_1 (const char *const name, int constraint)
{
lang_output_section_statement_type *lookup;
+ lang_output_section_statement_type **nextp;
lookup = lang_output_section_find_1 (name, constraint);
if (lookup == NULL)
@@ -1038,9 +1039,13 @@ lang_output_section_statement_lookup_1 (
lookup->update_dot_tree = NULL;
lookup->phdrs = NULL;
+ /* GCC's strict aliasing rules prevent us from just casting the
+ address, so we store the pointer in a variable and cast that
+ instead. */
+ nextp = &lookup->next;
lang_statement_append (&lang_output_section_statement,
(lang_statement_union_type *) lookup,
- (lang_statement_union_type **) &lookup->next);
+ (lang_statement_union_type **) nextp);
}
return lookup;
}