C++ Frontend and combining files

Mike Stump mrs@apple.com
Wed Oct 4 01:41:00 GMT 2006


On Oct 3, 2006, at 5:43 PM, Brendon Costa wrote:
> I think I could insert my data into the .s file into a particular
> section. I am not sure if I should create my own named section

I'd recommend .comment probably.  If you want to productize it, add  
your own, and put it into your linker script.

> If I place it into the .data section then would it then be possible to
> have conflicts with code symbols?

Only if you add a symbol that can have conflicts with code symbols,  
see the language spec for which symbols you can and cannot use.  __foo 
$bar is safe for example to use. printf generally isn't.

> I am also not yet sure how I would extract this data from the  
> objects (Using libbfd somehow I will have to look further into it).

man objcopy, man objdump

   objdump --section=.comment --full-contents a.out

for example.

> What would be the best directive to use to insert binary data into the
> section?

If you have a word

   .word 0

see the assembler manual for other possibilities.

   .string "Hello world\n\0"

might also work, if you have strings.  Also, you can ask the compiler  
how to output data by using the -S flag.

> Also does using ar/ld on resulting .o files filter out any sections  
> they don't know about?

as no.  ld -r, no.  Final link, probably.  --print-map for example  
might tell you some of the information you might need.  Look at the  
default linker script.  I can use use emacs /usr/bin/ld to view mine  
for example.  :-)

You can google("ld options dump liinker script") and find out that ld  
--verbose is an easier way to figure out the default linker script for  
GNU ld.

> Or do they always just include sections into the resulting archive/ 
> executable even if the sections are non-standard containing meta- 
> data that they don't understand?

.comment is standard on my platform.



More information about the Gcc mailing list