首页 > 其他 > 详细

Linker scripts之SECTIONS

时间:2015-03-24 22:48:07      阅读:233      评论:0      收藏:0      [点我收藏+]

1  Purpose

  The linker script is used to describe how the sections in the input files should be mapped into the output file, and to control the memory layout of the output file.

 2  Simple example

  The simplest possible linker script has just one command: `SECTIONS‘. Let‘s assume your program consists only of code, initialized data, and uninitialized data. These will be in the `.text‘, `.data‘, and `.bss‘ sections, respectively.

    SECTIONS
    {
        . = 0x10000;
        .text : { *(.text) }
        . = 0x8000000;
        .data : { *(.data) }
        .bss : { *(.bss) }
    }

  The first line sets the value of the special symbol `.‘, which is the location counter. The location counter is then incremented by the size of the output section.

  The second line defines an output section, `.text‘. The expression `*(.text)‘ means all `.text‘ input sections in all input files.

  Since the location counter is `0x10000‘ when the output section `.text‘ is defined, the linker will set the address of the `.text‘ section in the output file to be `0x10000‘.

  The remaining lines define the `.data‘ and `.bss‘ sections in the output file. The linker will place the `.data‘ output section at address `0x8000000‘. After the linker places the `.data‘ output section, the value of the location counter will be `0x8000000‘ plus the size of the `.data‘ output section. The effect is that the linker will place the `.bss‘ output section immediately after the `.data‘ output section in memory.

 3  SECTIONS command

  The SECTIONS command tells the linker how to map input sections into output sections, and how to place the output sections in memory.

The format of the SECTIONS command is:

     SECTIONS
     {
       sections-command
       sections-command
       ...
     }

 

Linker scripts之SECTIONS

原文:http://www.cnblogs.com/mengdie/p/4364042.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!