HELP with linker script!!!

Nick Clifton nickc@redhat.com
Fri Apr 1 14:05:00 GMT 2005
Hi Vincent,

> Thanks for this informative reply. There is something I am wondering 
> about using the gcc attributes to put variables or functions : how to 
> control the section flags of these new sections?

One way is by pre-declaring the section's name and attributes before 
using it. Like this:

   asm (".section .cached_bss, \"w\",@nobits");
   int foo __attribute__((section (".cached_bss")));

The problem with this approach is that (with GCC 4.1 at least) you will 
get warning messages from the assembler:

   Warning: ignoring changed section type for .cached_bss
   Warning: ignoring changed section attributes for .cached_bss

This is because GCC does not know that the asm() statement has already 
defined the .cached_bss section and so it issues its own .section 
directive.  If you can live with the assembler warning that this method 
will work.

The other way is hackier, but it avoids the warnings:

   int foo __attribute__((section (".cached_bss,\"w\",@nobits#")));

This assumes that the hash character (#) is the start-of-line-comment 
character for the particular instruction set you are using.  If you have 
a look at the assembler emitted by GCC you can see why:

         .section        .cached_bss,"w",@nobits#,"aw",@progbits

The hash stops GAS from interpreting the

   ,"aw",@probits

which gcc has appended to the name of the section...

Cheers
   Nick



More information about the Binutils mailing list