This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

section attribute of compound literals


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 };

This would be useful for instances like:

struct chacha20poly1305_testvec {
    const u8 *key, *nonce, *assoc, *input, *result;
    size_t nlen, alen, ilen;
};
static const struct chacha20poly1305_testvec
chacha20poly1305_enc_vectors[] __stuffdata = { {
    .key    = (u8[]){ 0x1c, 0x92, 0x40, 0xa5, 0xeb, 0x55, 0xd3, 0x8a,
                      0xf3, 0x33, 0x88, 0x86, 0x04, 0xf6, 0xb5, 0xf0,
                      0x47, 0x39, 0x17, 0xc1, 0x40, 0x2b, 0x80, 0x09,
                      0x9d, 0xca, 0x5c, 0xbc, 0x20, 0x70, 0x75, 0xc0 },
    .nonce  = (u8[]){ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 },
    .nlen   = 8,
    .assoc  = (u8[]){ 0xf3, 0x33, 0x88, 0x86, 0x00, 0x00, 0x00, 0x00,
                      0x00, 0x00, 0x4e, 0x91 },
    .alen   = 12,
    .input  = (u8[]){ 0x49, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x65, 0x74,
                      0x2d, 0x44, 0x72, 0x61, 0x66, 0x74, 0x73, 0x20,
...


I wish that instead of (u8[]) I could write (u8[] __stuffdata), but
this doesn't work. As a consequence, the data winds up in the wrong
section.

Is this a gcc limitation, or is there some wild syntax that would make
this possible?

Thanks,
Jason


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]