This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Allocate a variable in a known physical location
- From: Ian Lance Taylor <iant at google dot com>
- To: isuru herath <isuru81 at yahoo dot com>
- Cc: gcc-help at gcc dot gnu dot org
- Date: Mon, 31 Jan 2011 11:21:23 -0800
- Subject: Re: Allocate a variable in a known physical location
- References: <693708.27710.qm@web56001.mail.re3.yahoo.com>
isuru herath <isuru81@yahoo.com> writes:
> I need to allocate a variable in a known physical location, let's say I need
> to allocate void *p in location 0x10001000. I was using mmap to to do this,
> but in that manner I can only allocate p[0], p[1]...p[n] in that physical
> address range. Therefore when I access p[i], accesses to p results in
> outside {0x10001000, 0x10001000+offset} and p[i] results as an access in
> the range I am interested in.
I don't understand the last sentence there.
> I was wondering is there a was for me to force
> to allocate variable p in that address range or I am looking for something
> totally unrealistic. Because of the nature of my research I can use any
> optimization(-O2, O3).
If you don't want to use mmap, the simplest way to put a variable at a
specific location is to put it in a specific section using __attribute__
((section ("..."))) and then put that section at a specific address
using a linker script.
Ian