public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* How to place code in a different section than .text
@ 2005-01-20 13:11 Labermeier Norbert
  2005-01-20 18:37 ` Ramana Radhakrishnan
  0 siblings, 1 reply; 2+ messages in thread
From: Labermeier Norbert @ 2005-01-20 13:11 UTC (permalink / raw)
  To: gcc-help

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. 
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

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: How to place code in a different section than .text
  2005-01-20 13:11 How to place code in a different section than .text Labermeier Norbert
@ 2005-01-20 18:37 ` Ramana Radhakrishnan
  0 siblings, 0 replies; 2+ messages in thread
From: Ramana Radhakrishnan @ 2005-01-20 18:37 UTC (permalink / raw)
  To: Labermeier Norbert; +Cc: gcc-help


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

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2005-01-20 18:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-20 13:11 How to place code in a different section than .text Labermeier Norbert
2005-01-20 18:37 ` Ramana Radhakrishnan

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).