* looking for non-loaded, non-writable, non-allocated elf segment
@ 2002-01-02 23:20 Andrew Brown
2002-01-03 0:19 ` Philippe GIACINTI
0 siblings, 1 reply; 2+ messages in thread
From: Andrew Brown @ 2002-01-02 23:20 UTC (permalink / raw)
To: gcc-help
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."
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: looking for non-loaded, non-writable, non-allocated elf segment
2002-01-02 23:20 looking for non-loaded, non-writable, non-allocated elf segment Andrew Brown
@ 2002-01-03 0:19 ` Philippe GIACINTI
0 siblings, 0 replies; 2+ messages in thread
From: Philippe GIACINTI @ 2002-01-03 0:19 UTC (permalink / raw)
To: Andrew Brown; +Cc: gcc-help
on January 3 2002 Andrew Brown <atatat@atatdot.net> wrote:
> 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:
>
>
> ...
>
>
> 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"?
>
Hello,
I already faced this kind of problem, and, after looking at the code, it
seems there is no elegant way to achieve your goal (the `a,@progbits'
is actually hardcoded somewhere ...).
To solve my problem, I used a dirty workaround: I forced the definition
of the section with inline assembly before letting the compiler define
it...
For example, I have this kind of code (I want a section without content):
__asm__(".section my_section,\"aw\",@nobits\n");
static int my_variable __attribute__ ((section ("my_section")));
The assembler issues a warning because of the redefinition of the
section, but ignores the second definition (i.e: generated by the
compiler ...).
Just my 0,02 Euro...
Best regards.
--
Philippe Giacinti - Alcatel Business Systems
mailto:Philippe.Giacinti@sxb.bsf.alcatel.fr
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2002-01-03 8:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-02 23:20 looking for non-loaded, non-writable, non-allocated elf segment Andrew Brown
2002-01-03 0:19 ` Philippe GIACINTI
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).