This is the mail archive of the gcc-help@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]

Re: How to place code in a different section than .text


Hi ,

> Hi,
>
> I'd like to place a part of my Code, let us say the content of one
> C-File in a different section than .text.

You have two independent options .

1. If you are using GCC you can use the
__attribute__((section("section_name")) GNU extension to put your code and
data into different sections. This gives you flexibility within a
compilation unit a.k.a 1 C source file about which part of the code goes
into which section etc.

2. If you use the GNU ld , what you need is a linker script that puts the
object code generated for the 1 C file that you want put into different
sections.

You can get the default linker script used by ld --verbose on your platform .

In that just create  a new dummy section like the following.

.text_mine           :
  {
    myfile.o(.text)
  } =0x90909090

Where myfile.o contains the text that needs to be put into a separate
section.

The same can be applied to the data. Please note that 0x90909090 is the
encoding for the nop instruction on the i386 which should be the fill
value used for padding for alignment issues.

For more information on this do info ld and search for linker scripts,
there are tons of examples out there.

HTH

cheers
Ramana






---
Ramana Radhakrishnan
GNU Tools
codito ergo sum (www.codito.com)





> Also I like to have a special location for the .data and .bss.






>
> Ok, on a embedded target I can specify the sections in the linker
> script, e.g.
>
> .new_text
> .new_data
> .new_bss
>
> But how does it work for compilation, which option did I have to use to
> tell the compiler that he should mark the output for different location.
>
> I will also have the rest of my code in a
> .text
> .data
> .bss
>
> Does anybody has an idea?
>
> Best regards,
>
> Norbert
>


----
Ramana Radhakrishnan
Codito Technologies


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