public inbox for ecos-patches@sourceware.org
 help / color / mirror / Atom feed
* redboot fconfig crash with gcc 4.3.2
@ 2009-01-19 22:23 Jose Vasconcellos
  2009-01-20  7:55 ` Gary Thomas
  0 siblings, 1 reply; 4+ messages in thread
From: Jose Vasconcellos @ 2009-01-19 22:23 UTC (permalink / raw)
  To: ecos-patches

Redboot gets an exception when trying to set any IP address with fconfig
when using gcc-4.3.2 on an ixp425 target (armeb). The issue seems to be
an alignment problem as val_ptr contains an odd address; it looks like gcc
is optimizing and trying to do a copy on a word boundary. The removal of
the cast fixes the problem.


--- fconfig.c    2009-01-18 14:34:11.000000000 -0500
+++ fconfig.c.new    2009-01-18 14:35:22.000000000 -0500
@@ -388,7 +388,7 @@
        break;
#ifdef CYGPKG_REDBOOT_NETWORKING
    case CONFIG_IP:
-        memcpy(&hold_ip_val.s_addr, &((in_addr_t *)val_ptr)->s_addr, sizeof(in_addr_t)); 

+        memcpy(&hold_ip_val.s_addr, val_ptr, sizeof(in_addr_t));
        if (!_gethostbyname(line, &new_ip_val)) {
            return CONFIG_BAD;
        }


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: redboot fconfig crash with gcc 4.3.2
  2009-01-19 22:23 redboot fconfig crash with gcc 4.3.2 Jose Vasconcellos
@ 2009-01-20  7:55 ` Gary Thomas
  2009-01-20  9:20   ` Daniel Néri
  2009-01-20 13:19   ` Jose Vasconcellos
  0 siblings, 2 replies; 4+ messages in thread
From: Gary Thomas @ 2009-01-20  7:55 UTC (permalink / raw)
  To: Jose Vasconcellos; +Cc: ecos-patches

Jose Vasconcellos wrote:
> Redboot gets an exception when trying to set any IP address with fconfig
> when using gcc-4.3.2 on an ixp425 target (armeb). The issue seems to be
> an alignment problem as val_ptr contains an odd address; it looks like gcc
> is optimizing and trying to do a copy on a word boundary. The removal of
> the cast fixes the problem.
> 
> 
> --- fconfig.c    2009-01-18 14:34:11.000000000 -0500
> +++ fconfig.c.new    2009-01-18 14:35:22.000000000 -0500
> @@ -388,7 +388,7 @@
>        break;
> #ifdef CYGPKG_REDBOOT_NETWORKING
>    case CONFIG_IP:
> -        memcpy(&hold_ip_val.s_addr, &((in_addr_t *)val_ptr)->s_addr, 
> sizeof(in_addr_t));
> +        memcpy(&hold_ip_val.s_addr, val_ptr, sizeof(in_addr_t));
>        if (!_gethostbyname(line, &new_ip_val)) {
>            return CONFIG_BAD;
>        }
> 

Sounds like a *BUG* in the compiler.  Have you reported it?

This does more than remove the cast :-)  What if the s_addr field is not
at the start of the structure?  I know it hasn't moved in 25+ years, but
I don't like tossing correctness [even if only pedantic] away.

Maybe there's another way to solve this.  Does it happen on arm[el]?

-- 
------------------------------------------------------------
Gary Thomas                 |  Consulting for the
MLB Associates              |    Embedded world
------------------------------------------------------------

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: redboot fconfig crash with gcc 4.3.2
  2009-01-20  7:55 ` Gary Thomas
@ 2009-01-20  9:20   ` Daniel Néri
  2009-01-20 13:19   ` Jose Vasconcellos
  1 sibling, 0 replies; 4+ messages in thread
From: Daniel Néri @ 2009-01-20  9:20 UTC (permalink / raw)
  To: ecos-patches

Gary Thomas <gary@mlbassoc.com> writes:

> Jose Vasconcellos wrote:
>> Redboot gets an exception when trying to set any IP address with fconfig
>> when using gcc-4.3.2 on an ixp425 target (armeb). The issue seems to be
>> an alignment problem as val_ptr contains an odd address; it looks like gcc
>> is optimizing and trying to do a copy on a word boundary. The removal of
>> the cast fixes the problem.
>>
>>
>> --- fconfig.c    2009-01-18 14:34:11.000000000 -0500
>> +++ fconfig.c.new    2009-01-18 14:35:22.000000000 -0500
>> @@ -388,7 +388,7 @@
>>        break;
>> #ifdef CYGPKG_REDBOOT_NETWORKING
>>    case CONFIG_IP:
>> -        memcpy(&hold_ip_val.s_addr, &((in_addr_t
>> *)val_ptr)->s_addr, sizeof(in_addr_t));
>> +        memcpy(&hold_ip_val.s_addr, val_ptr, sizeof(in_addr_t));
>>        if (!_gethostbyname(line, &new_ip_val)) {
>>            return CONFIG_BAD;
>>        }
>>
>
> Sounds like a *BUG* in the compiler.

I don'think so -- standard behaviour is undefined when converting from a
pointer to one type to a pointer to another type that has more stringent
alignment requirements (e.g. from "void *" to "in_addr_t *").


Regards,
-- 
Daniel Néri <daniel.neri@sigicom.com>
Sigicom AB, Stockholm, Sweden

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: redboot fconfig crash with gcc 4.3.2
  2009-01-20  7:55 ` Gary Thomas
  2009-01-20  9:20   ` Daniel Néri
@ 2009-01-20 13:19   ` Jose Vasconcellos
  1 sibling, 0 replies; 4+ messages in thread
From: Jose Vasconcellos @ 2009-01-20 13:19 UTC (permalink / raw)
  To: Gary Thomas; +Cc: ecos-patches

Gary Thomas wrote:
> Jose Vasconcellos wrote:
>> Redboot gets an exception when trying to set any IP address with fconfig
>> when using gcc-4.3.2 on an ixp425 target (armeb). The issue seems to be
>> an alignment problem as val_ptr contains an odd address; it looks 
>> like gcc
>> is optimizing and trying to do a copy on a word boundary. The removal of
>> the cast fixes the problem.
>>
>>
>> --- fconfig.c    2009-01-18 14:34:11.000000000 -0500
>> +++ fconfig.c.new    2009-01-18 14:35:22.000000000 -0500
>> @@ -388,7 +388,7 @@
>>        break;
>> #ifdef CYGPKG_REDBOOT_NETWORKING
>>    case CONFIG_IP:
>> -        memcpy(&hold_ip_val.s_addr, &((in_addr_t *)val_ptr)->s_addr, 
>> sizeof(in_addr_t));
>> +        memcpy(&hold_ip_val.s_addr, val_ptr, sizeof(in_addr_t));
>>        if (!_gethostbyname(line, &new_ip_val)) {
>>            return CONFIG_BAD;
>>        }
>>
>
> Sounds like a *BUG* in the compiler.  Have you reported it?
>
> This does more than remove the cast :-)  What if the s_addr field is not
> at the start of the structure?  I know it hasn't moved in 25+ years, but
> I don't like tossing correctness [even if only pedantic] away.
>
> Maybe there's another way to solve this.  Does it happen on arm[el]?
>
This doesn't look like a compiler bug to me. I suspect that this problem
affects other arm variants but I only have access to an ixp425. The code
is incorrect as val_ptr is pointing to a place in a configuration buffer for
the raw data. Imposing (via a cast) the structure is not the right solution.
Note that a few lines down in the source, the copy in the other direction
does not have such a cast.

Jose

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2009-01-20 13:19 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-19 22:23 redboot fconfig crash with gcc 4.3.2 Jose Vasconcellos
2009-01-20  7:55 ` Gary Thomas
2009-01-20  9:20   ` Daniel Néri
2009-01-20 13:19   ` Jose Vasconcellos

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).