section attribute of compound literals
Jim Wilson
jimw@sifive.com
Thu Sep 13 20:39:00 GMT 2018
On 09/10/2018 10:46 PM, Jason A. Donenfeld wrote:
> Hello,
>
> I'd like to have a compound literal exist inside a certain linker
> section. However, it doesn't appear to work as I'd like:
>
> #define __stuffdata __attribute__((__section__("stuff")))
> const u8 works[] __stuffdata = { 0x1, 0x2, 0x3, 0x4 };
> const u8 *breaks = (const u8[] __stuffdata){ 0x1, 0x2, 0x3, 0x4 };
Attribute section applies to symbols not to types, so you can't use it
in a cast. In order to access data in another section, we need an
address for it, and symbols have an address, but types do not. The
compound literal could have an address, but we don't have a way to
attach attributes to compound literals.
Since your testcase already has a symbol in the right section, you could
just use that to initialize breaks.
const u8 *breaks = works;
This means defining a bunch of extra symbols, but is a potential
solution to your problem.
Jim
More information about the Gcc
mailing list