Header

  1. View current page

    kkamagui의 프로그래밍 작업실

Profile_image?t=1221830958&type=big
온갖 자료가 난무하는 kkamagui의 Springnote~!!!
22

02 링커 스크립트(Linker Script)

02 링커 스크립트(Linker Script) (작성중)

원문 : http://kkamagui.springnote.com/pages/420104

 

들어가기 전에...

 

1.시작하면서...

 GCC의 링커(Linker)인 LD는 다양한 옵션을 가지고 있다. LD에 대한 자세한 내용은 http://sourceware.org/binutils/docs/ld/index.html 에서 찾아볼 수 있다.

 

 

여기 자세한 내용 넣기

 

  1. The Location Counter
    The special linker variable dot `.' always contains the current output location counter. Since the . always refers to a location in an output section, it must always appear in an expression within a SECTIONS command. The . symbol may appear anywhere that an ordinary symbol is allowed in an expression, but its assignments have a side effect. Assigning a value to the . symbol will cause the location counter to be moved. This may be used to create holes in the output section. The location counter may never be moved backwards.

     

  2. SECTIONS
    {
      output :
      {
      file1(.text)
      . = . + 1000;
      file2(.text)
      . += 1000;
      file3(.text)
      } = 0x1234;
    }

 

  1. Optional Section Attributes
    Here is the full syntax of a section definition, including all the optional portions:
  2. SECTIONS {
    ...
    secname start BLOCK(align) (NOLOAD) : AT ( ldadr )
      { contents } >region :phdr =fill...
    }
  3. secname and contents are required. See section Section Definitions, and section Section Placement, for details on contents. The remaining elements---start, BLOCK(align), (NOLOAD), AT ( ldadr ), >region, :phdr, and =fill---are all optional.
  4. start
    You can force the output section to be loaded at a specified address by specifying start immediately following the section name. start can be represented as any expression. The following example generates section output at location 0x40000000:
    SECTIONS {
      ...
      output 0x40000000: {
        ...
        }
      ...
    }
  5. BLOCK(align)
    You can include BLOCK() specification to advance the location counter . prior to the beginning of the section, so that the section will begin at the specified alignment. align is an expression.
    (NOLOAD)
    The `(NOLOAD)' directive will mark a section to not be loaded at run time. The linker will process the section normally, but will mark it so that a program loader will not load it into memory. For example, in the script sample below, the ROM section is addressed at memory location `0' and does not need to be loaded when the program is run. The contents of the ROM section will appear in the linker output file as usual.
    SECTIONS {
      ROM  0  (NOLOAD)  : { ... }
      ...
    }
  6. AT ( ldadr )
    The expression ldadr that follows the AT keyword specifies the load address of the section. The default (if you do not use the AT keyword) is to make the load address the same as the relocation address. This feature is designed to make it easy to build a ROM image. For example, this SECTIONS definition creates two output sections: one called `.text', which starts at 0x1000, and one called `.mdata', which is loaded at the end of the `.text' section even though its relocation address is 0x2000. The symbol _data is defined with the value 0x2000:
    SECTIONS
      {
      .text 0x1000 : { *(.text) _etext = . ; }
      .mdata 0x2000 :
        AT ( ADDR(.text) + SIZEOF ( .text ) )
        { _data = . ; *(.data); _edata = . ;  }
      .bss 0x3000 :
        { _bstart = . ;  *(.bss) *(COMMON) ; _bend = . ;}
    }
  7. The run-time initialization code (for C programs, usually crt0) for use with a ROM generated this way has to include something like the following, to copy the initialized data from the ROM image to its runtime address:
    char *src = _etext;
    char *dst = _data;
  8. /* ROM has data at end of text; copy it. */
    while (dst < _edata) {
      *dst++ = *src++;
    }
  9. /* Zero bss */
    for (dst = _bstart; dst< _bend; dst++)
      *dst = 0;
  10. >region
    Assign this section to a previously defined region of memory. See section Memory Layout.
    :phdr
    Assign this section to a segment described by a program header. See section ELF Program Headers. If a section is assigned to one or more segments, then all subsequent allocated sections will be assigned to those segments as well, unless they use an explicitly :phdr modifier. To prevent a section from being assigned to a segment when it would normally default to one, use :NONE.
    =fill
    Including =fill in a section definition specifies the initial fill value for that section. You may use any expression to specify fill. Any unallocated holes in the current output section when written to the output file will be filled with the two least significant bytes of the value, repeated as necessary. You can also change the fill value with a FILL statement in the contents of a section definition.
  11.  

History

Last edited on 07/12/2008 12:15 by kkamagui

Comments (0)

You must log in to leave a comment. Please sign in.