All of lore.kernel.org
 help / color / mirror / Atom feed
From: Albert ARIBAUD <albert.u.boot@aribaud.net>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH] avr32: fix relocation address calculation
Date: Fri, 10 May 2013 19:15:46 +0200	[thread overview]
Message-ID: <20130510191546.464c2892@lilith> (raw)
In-Reply-To: <1A284989-3691-4A1C-B79C-6BE55B50357A@prograde.net>

Hi Michael,

On Fri, 10 May 2013 13:02:57 -0400, Michael Cashwell
<mboards@prograde.net> wrote:

> On May 10, 2013, at 11:09 AM, Albert ARIBAUD <albert.u.boot@aribaud.net> wrote:
> 
> > The compiler considers the name/symbol to be value, not the address of the
> > corresponding object... at least most of the time: as you indicate, when
> > the symbol denotes a C array, then the C compiler understand the symbol as
> > the address of the array.
> 
> I ran into a case one on Codewarrior Mac PPC tools where there was a subtle
> different here. In an existing body of code there was originally a global
> char[] defined with a matching extern char[] declared in a header.
> 
> At some point the definition was changed to char* because the size of the
> array grew and we wanted it out of the global section. I traced an obscure
> crash to some assembly code that had worked when the definition was char[]
> but needed an extra level of indirection when it was char *.

Well, of course it did! char* is a pointer to char, with syntactic
facilities to use it as a pointer to char array, but char* is not an
array. The value of a pointer to char is a (probably 32-bit) address,
and you need to dereferenc it to get a char.

> During that debugging I found that the declaration had not been changed to
> char * but the C compiler hadn't cared. It handled the mixed forms just fine
> despite the clear difference in the code.

Well, the compiler would not care that one C module would know the
symbol as char* and another one would know it as char[], since the
compiler treats compilation units completely independently. You would
end up using the same address space area for two different objects: an
array of chars, overlapped with a (probably 32-bit) pointer to char.

Where I worked up until recently, we had a 'coding rule' that required
us to always #include a module's .h file (its public interface) from
within its .c file (its implementation) if only to make sure the
compiler saw both the declarations and the definitions in a single
compilation unit, and would thus bark at us for screwing up between
declaration and definition.

> I surmised it was some subtle issue around PPC's handling of global data
> (or the Codewarrior PPC ABI) but still don't really know.

This has nothing to do with PPC or CW; this is just C working as
designed.

> -Mike

Amicalement,
-- 
Albert.

  reply	other threads:[~2013-05-10 17:15 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-08  9:25 [U-Boot] [PATCH] avr32: fix relocation address calculation Andreas Bießmann
2013-05-10  9:24 ` Albert ARIBAUD
2013-05-10 10:57   ` Andreas Bießmann
2013-05-10 15:09     ` Albert ARIBAUD
2013-05-10 17:02       ` Michael Cashwell
2013-05-10 17:15         ` Albert ARIBAUD [this message]
2013-05-13  8:35       ` Andreas Bießmann
2013-05-13 11:34         ` Albert ARIBAUD
2013-05-13 11:43   ` Albert ARIBAUD
2013-05-13  8:38 ` [U-Boot] " Andreas Bießmann
2013-05-13  8:42   ` Andreas Bießmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20130510191546.464c2892@lilith \
    --to=albert.u.boot@aribaud.net \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.