QQ登录

只需一步,快速开始

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 3886|回复: 0

可以使用C++特性的链接脚本的设置,大家瞧瞧

[复制链接]
发表于 2006-10-8 22:03:56 | 显示全部楼层 |阅读模式
我根据现成的链接脚本配合我的板子修改了新的链接脚本,经测试可以使用C/C++的库和C++的特性。然后我分析了一下脚本中各个段的作用,不知对不对,大家提点意见!
使用我经过修改的脚本文件加以说明:

OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm",
              "elf32-littlearm")
//输出的文件格式:大端模式(elf32-bigarm);小端模式(elf32-littlearm)
OUTPUT_ARCH(arm)
//输出的CPU构架(arm)
ENTRY(_start_start)
//程序的入口

SECTIONS
{
  . = 0x00000000;

  __text_start = .;
  .text      :                //代码段
  {
*(.vectors)
//中断section,这是我加的
*(.text)
*(.text.*)
//文本section
*(.stub)
//调试程序时插入的代码section(就是存放调试用的桩(stub)用的段;这个我不太确定?)
*(.gnu.linkonce.t*)
//linkonce段用来消除C++的重复代码,这样编译出来的程序会比较小。linkonce.t是代码段
*(.glue_7t) *(.glue_7)
//链接动态链接库时使用的胶合(glue)代码段
  } =0

  .init          :        
  {
    KEEP (*(.init))
  } =0
        //程序启动时执行的代码,对于C是不需要这个的,但对于具有初始函数的全局数据的C++语言来说是必须的

  .ctors   :
  {
    /* gcc uses crtbegin.o to find the start of
        the constructors, so we make sure it is
       first.  Because this is a wildcard, it
       doesn't matter if the user does not
       actually link against crtbegin.o; the
       linker won't look for a file to match a
       wildcard.  The wildcard also means that it
       doesn't matter which directory crtbegin.o
       is in.  */
/*    KEEP (*crtbegin.o(.ctors))*/
    /* We don't want to include the .ctor section from
       from the crtend.o file until after the sorted ctors.
       The .ctor section from the crtend file contains the
       end of ctors marker and it must be last */
/*    KEEP (*(EXCLUDE_FILE (*crtend.o ) .ctors))*/
/*    KEEP (*(SORT(.ctors.*)))*/
    KEEP (*(.ctors))
    KEEP (*(.ctor))
  }
        //给C++的构造函数使用的section

   .dtors         :
  {
/*    KEEP (*crtbegin.o(.dtors))*/
/*    KEEP (*(EXCLUDE_FILE (*crtend.o ) .dtors))*/
/*    KEEP (*(SORT(.dtors.*)))*/
    KEEP (*(.dtors))
    KEEP (*(.dtor))
  }
        //给C++的析构函数使用的section
  __text_end = .;
  _etext = .;
  PROVIDE (etext = .);

  .fini      :
  {
    KEEP (*(.fini))
  } =0
        //同init段。程序终结时执行的代码。C不是必须的;而C++是必须的

  __rodata_start = .;
  .rodata   : { *(.rodata) *(.rodata.*) *(.gnu.linkonce.r*) }
  .rodata1   : { *(.rodata1) }
        //只读数据区
  __rodata_end = .;
  
  . = 0x0c000000;
       
  __data_start = .;
  . = ALIGN(4);
  .data :                //以初始化的数据段
  AT(__rodata_end)                //我对数据段进行了重定位
  {       
            *(.data)
            *(.data.*)
                //可读写数据区
            *(.gnu.linkonce.d*)
                // linkonce段用来消除C++的重复代码。linkonce.d是数据段
        SORT(CONSTRUCTORS)                //这个是什么不知道????不敢删掉

        *(.data1)
/*        KEEP (*(.eh_frame)) */
        *(.gcc_except_table)                //gcc的中断向量表段,如果自定义向量表的话可以不用
  
        *(.sdata)
        *(.sdata.*)
        *(.gnu.linkonce.s.*)
        //小数据区,有些平台上会用到。到底是哪些平台那????
  }
  __data_end = .;
  _edata = .;
  PROVIDE (edata = .);

  . = ALIGN(4);
  __bss_start = __data_end;
  __bss_start__ = __data_end;
  .sbss      :                //未初始化数据段,包括小的bss和公共块,在哪些平台上用到哪??
  {
    *(.sbss)
    *(.sbss.*)
    *(.scommon)
  }
  .bss       :               
//未初始化数据段,包括bss和公共块。其中common段对于C语言来说足够了,但对于C++来说还是不够的
  {
   *(.bss)
   *(.bss.*)
   *(COMMON)
   /* Align here to ensure that the .bss section occupies space up to
      _end.  Align after .bss to ensure correct alignment even if the
      .bss section disappears because there are no input sections.  */
   . = ALIGN(32 / ;
  }
  . = ALIGN(32 / ;
  _bss_end__ = . ; __bss_end__ = . ; __end__ = . ;
  PROVIDE (end = .);
  __bss_end = .;

        //以下是stack和heap的设置,对于不同MCU设置都会有所不同,我使用的是s3c44b0,此处省去。

        //存放一些调试信息
  /* Stabs debugging sections.  */
  .stab 0 : { *(.stab) }
  .stabstr 0 : { *(.stabstr) }
  .stab.excl 0 : { *(.stab.excl) }
  .stab.exclstr 0 : { *(.stab.exclstr) }
  .stab.index 0 : { *(.stab.index) }
  .stab.indexstr 0 : { *(.stab.indexstr) }
  .comment 0 : { *(.comment) }

  _end = .;
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则

GMT+8, 2024-3-29 20:42 , Processed in 0.057577 second(s), 15 queries .

© 2021 Powered by Discuz! X3.5.

快速回复 返回顶部 返回列表