This is the mail archive of the binutils@sourceware.org mailing list for the binutils 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: what does AT do in a linker scripts ?


On 2016年07月13日 16:49, Erik Christiansen wrote:
On 13.07.16 16:16, Yubin Ruan wrote:
Hi,
I am reading some C code and some linker scripts for `ld`.
I find something really hard to understand:

     .text : AT(0x100000) {
         *(.text .stub .text.* .gnu.linkonce.t.*)
     }

I understand what the `.text` and the wild char * do, but what does
the `AT` after the colon do ?
Need help.

It specifies the LMA, i.e. the address at which the output section is to
be loaded, e.g. into ROM. (As opposed to the VMA, the address at which
the output section has been linked/located to run.)

And also, why is there no man page describing the syntax of linker scripts ?

That is annoying, and has been for a very long time, but we need to use
the documentation provided:

# apt-get install binutils-doc
$ info ld

It's described in section: "3.6.8.2 Output Section LMA"

Erik

Thanks for replying. Those infos you provided are really helpful.

May I ask another related question:

There are some linker script like this:

    SECTIONS
    {
        . = 0X80100000;
        .text : AT(0x100000) {
            *(.text .stub .text.* .gnu.linkonce.t.*)
        }

      ... blah blah ...
    }

Now 0x8010000 is a VMA, and 0x100000 is a LMA.
Can I treat the LMA the same as the physical address in a ELF program header ? A typical ELF declaration would be something like this:

typedef struct
{
  Elf32_Word    p_type;                 /* Segment type */
  Elf32_Off     p_offset;               /* Segment file offset */
  Elf32_Addr    p_vaddr;                /* Segment virtual address */
  Elf32_Addr    p_paddr;                /* Segment physical address */
  Elf32_Word    p_filesz;               /* Segment size in file */
  Elf32_Word    p_memsz;                /* Segment size in memory */
  Elf32_Word    p_flags;                /* Segment flags */
  Elf32_Word    p_align;                /* Segment alignment */
} Elf32_Phdr;

Is LMA just **p_paddr** in a program header?
My understanding is, when the linker link all the object files together and then output a executable file of ELF format, those LMA declare in the linker script would be the **p_paddr** in the executable file, so the loader can correspondingly put that program on the physical address as declared by **p_paddr**. Is that correct? Please correct me if you may. I'm reading some low level code and is not really familiar with those low level stuff.

Thanks in advance!
Ruan.


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