This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
looking for non-loaded, non-writable, non-allocated elf segment
- From: Andrew Brown <atatat at atatdot dot net>
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 3 Jan 2002 02:20:36 -0500
- Subject: looking for non-loaded, non-writable, non-allocated elf segment
what i'm trying to do is embed some configuration data that describes
my program in the actual binary itself so that i have less "things" i
need to keep track of. what seemed best to me was to stuff the data
into a non-loadable, non-allocated, and also read-only (although i
supposed that's moot if it's not loaded or allocated) elf segment via,
eg:
static const char config[]
#ifdef __ELF__
__attribute__((section(".netbsd.config")))
#endif /* __ELF__ */
__attribute__((__unused__)) = "...";
running objdump on my binary shows at this point shows me this:
% objdump -h netbsd
...
Sections:
Idx Name Size VMA LMA File off Algn
...
6 .netbsd.config 0000b140 00000000 00000000 002bca40 2**5
CONTENTS, ALLOC, LOAD, READONLY, DATA
which isn't exactly what i was looking for. after a little random
poking around, i happened upon this syntax:
__attribute__((section(".netbsd.config#")))
which changes the attributes of the given section to "CONTENTS,
READONLY" which is exactly what i was looking for, however, after
skimming through gas to see if that's the "correct" behavior, i have
reached the conclusion that it might perhaps be a happy bug. that
__attribute__() turns into this "assembly":
#NO_APP
.section .netbsd.config#,"a",@progbits
.align 32
.type config,@object
.size config,45068
config:
.ascii "..."
so it seems that the ,"a",@progbits piece of the .section is just
being ignored. it seems, however, that since i'm toying with this
idea on an i386 platform, this "just works" because the # is the
comment character, which isn't exactly portable, nor is it an actual
feature.
what i'm looking for is a way to specify that a given section is not
to be loaded or allocated, which is also what i get if i remove the
"a" from the ,"a", sequence on the .section line. is there a way to
specify this with some other __attribute__ flags or carefully crafted
section names? in a way that's likely to "remain functional"?
--
|-----< "CODE WARRIOR" >-----|
codewarrior@daemon.org * "ah! i see you have the internet
twofsonet@graffiti.com (Andrew Brown) that goes *ping*!"
andrew@crossbar.com * "information is power -- share the wealth."