This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: Minor feature for ld
- From: Ian Lance Taylor <ian at airs dot com>
- To: Pete Gonzalez <pgonzalez at bluel dot com>
- Cc: binutils at sources dot redhat dot com
- Date: 03 Sep 2002 09:03:19 -0700
- Subject: Re: Minor feature for ld
- References: <5.1.0.14.2.20020903113750.01bd63f0@emmet.jeffsys.net>
Pete Gonzalez <pgonzalez@bluel.com> writes:
> I think the linker should support segments whose address is a
> function of the segment name. It would allow definitions like
> this in GCC:
>
> __attribute__((section("/0x123456/"))) int IOPort;
>
> In the above example, the linker would locate the variable at
> the given address, so these two statements would be equivalent:
>
> IOPort = x;
> *(int *)0x123456 = x;
>
> Really this feature belongs in the compiler, but sections are
> the closest C/C++ compilers come to letting you control the
> address of variables. Everything else is handled by the linker,
> so that seems like the simplest place to fix. (If not, maybe
> I should be pestering the GCC people.)
It's easy enough to do this in C by doing
int* IOPort = (int*) 0x123456;
*IOPort = x;
In most uses you will want volatile, as in
volatile int* IOPort = (int*) 0x123456;
What's the advantage of doing it in a linker section?
Ian