public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* Aligning .text segments
@ 2014-12-10  0:12 K Jski
  2014-12-23  8:46 ` Nicholas Clifton
  0 siblings, 1 reply; 3+ messages in thread
From: K Jski @ 2014-12-10  0:12 UTC (permalink / raw)
  To: Binutils

this is like a stack overflow question but I need help:
I am trying to align functions for multiple binary files on different
ISAs configuring GOLD with a linker script
(i.e. I have a program with functions foo with size= 0xc9,bar
size=0x18, and a main. Assume .text addr starts at 0x400000000
suppose the original layout of the file is

foo at 0x40000010
bar at 0x400000c9
main in at  0x40000400

so I just would want the following to happen
foo to be aligned at 0x40000050
bar to be aligned at 0x40000100
main stays at 0x40000400

I have an attempt at a linker script (I never worked on linkers in my
life) that I feed gold as an arg "myscript.x". (source below) what
happens when gold produces a binary is that it creates another .text
section and inserts them at the designated addresses. running the
program results in "Killed"

myscript.x

SECTIONS{
             .text:
            {
               . = ALIGN(0x50);
               *(.text.foo)
                . = ALIGN(0x50);
                *(.text.bar)
             }
}


(I have tried to use INSERT AFTER .text after the sections declaration
but then it gives a unexpected STRING fatal error)

Sincerely,

C Jelesnianski

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

* Re: Aligning .text segments
  2014-12-10  0:12 Aligning .text segments K Jski
@ 2014-12-23  8:46 ` Nicholas Clifton
  2014-12-23 18:36   ` Cary Coutant
  0 siblings, 1 reply; 3+ messages in thread
From: Nicholas Clifton @ 2014-12-23  8:46 UTC (permalink / raw)
  To: K Jski, Binutils

Hi K Jski,

> foo at 0x40000010
> bar at 0x400000c9
> main in at  0x40000400
>
> so I just would want the following to happen
> foo to be aligned at 0x40000050
> bar to be aligned at 0x40000100
> main stays at 0x40000400
>
> I have an attempt at a linker script (I never worked on linkers in my
> life) that I feed gold as an arg "myscript.x". (source below) what
> happens when gold produces a binary is that it creates another .text
> section and inserts them at the designated addresses.

So, are you saying that the functions get aligned as you wanted, but 
that the program itself does not run ?

> myscript.x
>
> SECTIONS{
>               .text:
>              {
>                 . = ALIGN(0x50);
>                 *(.text.foo)
>                  . = ALIGN(0x50);
>                  *(.text.bar)
>               }
> }

That script should work, assuming that you compiled your code with the 
-ffunction-sections command line option enabled, although you are 
missing the catch-all line to catch the other text sections (eg the one 
containing main):

                .text:
               {
                  . = ALIGN(0x50);
                  *(.text.foo)
                   . = ALIGN(0x50);
                   *(.text.bar)
		  . = ALIGN(0x50);
		  *(.text .text.*)
                }

Also - this script is just a fragment - a full script would also need to 
specify the locations of other sections like .data, .bss and so on. 
Your best bet is to take the linker's builtin default script (shown when 
you run "gold --verbose") and modify that to suit your needs.

Cheers
   Nick

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

* Re: Aligning .text segments
  2014-12-23  8:46 ` Nicholas Clifton
@ 2014-12-23 18:36   ` Cary Coutant
  0 siblings, 0 replies; 3+ messages in thread
From: Cary Coutant @ 2014-12-23 18:36 UTC (permalink / raw)
  To: Nicholas Clifton; +Cc: K Jski, Binutils

> Also - this script is just a fragment - a full script would also need to
> specify the locations of other sections like .data, .bss and so on. Your
> best bet is to take the linker's builtin default script (shown when you run
> "gold --verbose") and modify that to suit your needs.

Gold doesn't use a default linker script, so gold --verbose won't
help. In gold, linker scripts are really meant for full-on embedded
applications where you really want full control over the placement of
everything, and you're responsible for making sure the script handles
all the various input sections that the linker might see. It's
possible that you could print BFD ld's default linker script and use
that with gold, but it seems like an extremely heavy-weight solution.

To set the alignment for individual functions, I think you'd be better
off using __attribute__ ((aligned (n))) in the source code.

-cary

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

end of thread, other threads:[~2014-12-23 18:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-12-10  0:12 Aligning .text segments K Jski
2014-12-23  8:46 ` Nicholas Clifton
2014-12-23 18:36   ` Cary Coutant

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