Re: [arm-gnu] how to locate a const struct in memory (ld question)
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [arm-gnu] how to locate a const struct in memory (ld question)



On Saturday 08 May 2010 07:20:23 Daniel Jacobowitz wrote:
> On Fri, May 07, 2010 at 03:17:13PM -0400, Andrew Kohlsmith (mailing lists 
account) wrote:
> > Is there a way to specify a specific location for a specific object, or
> > perhaps should I be declaring the structure differently so that I can get
> > a section out of it for ld to put at a specific location?
>
> Look up __attribute__((section)) in the GCC manual to do this.
>
> > Finally, right now the bootloader and the application are built at the
> > same time, so the linker is resolving bl_funcs for the application's
> > extern declaration. Do I use the linker PROVIDE() function to do this
> > when the bootloader is removed from the image?

Please **don't** use special attributes etc. That makes very unportable code 
and can break from version to version of gcc.

It is way cleaner to do this sort of thing using the linker/locator.

If you really, really, must use gcc then put all those specials in a separate 
file (ie. not mixed through your code).

The way I'd tackle this is through a double indirection.

In C, build a table that looks like:

struct func_table table{
	func_a,
	func_b,
	func_c,
}

Then use the linker/locator to store a pointer to the table in a special 
location

Then to dereference the code

struct func_table *table_ptr = *((struct func_table **) ADDR_OF_POINTER);

Now have local wrapper functions

int func_a(int x)
{
	return table_ptr->func_a(x);
}