This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

[参考译文] MSP430F249:MSP430 gcc 标准库大小

Guru**** 2536610 points
Other Parts Discussed in Thread: MSP430F249

请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1057179/msp430f249-msp430-gcc-standard-library-size

器件型号:MSP430F249

您好!

我正在尝试将一个旧的旧旧项目从 IAR 移植到 GCC。 我已经成功了、但即使在 IAR 中、代码大小也存在问题-我们的闪存几乎已满。 但是对于 gcc、我必须禁用部分应用程序才能完成链接。 主要原因可能是库函数的大小。

这些来自 IAR。 总尺寸约为1650。

352 FUNC    GLOBAL DEFAULT  ABS _Add32f
 304 FUNC    GLOBAL DEFAULT  ABS _Div32f
 272 FUNC    GLOBAL DEFAULT  ABS _Mul32f
 126 FUNC    GLOBAL DEFAULT  ABS _Cast32uto32f
  50 FUNC    GLOBAL DEFAULT  ABS _Cast32fto32s
  28 FUNC    GLOBAL DEFAULT  ABS _make_new_mem_hole
  16 FUNC    GLOBAL DEFAULT  ABS __data16_memzero
   4 FUNC    GLOBAL DEFAULT  ABS __data16_memcpy
   4 FUNC    GLOBAL DEFAULT  ABS _Sub32f
   4 FUNC    GLOBAL DEFAULT  ABS __program_start
   2 FUNC    GLOBAL DEFAULT  ABS __exit
   0 FUNC    GLOBAL DEFAULT  ABS _exit
   0 FUNC    GLOBAL DEFAULT  ABS _STACK_SIZE
   0 FUNC    GLOBAL DEFAULT  ABS _HEAP_SIZE
   0 FUNC    GLOBAL DEFAULT  ABS _SYS_RAM_END
   0 FUNC    GLOBAL DEFAULT  ABS _APP_RAM_START
   0 FUNC    GLOBAL DEFAULT  ABS _USER_EE_END
   0 FUNC    GLOBAL DEFAULT  ABS _APP_INTERN_START
  86 FUNC    GLOBAL DEFAULT  ABS ?FLT_GE
  82 FUNC    GLOBAL DEFAULT  ABS ?FLT_LT
  76 FUNC    GLOBAL DEFAULT  ABS ?FLT_Extract
  48 FUNC    GLOBAL DEFAULT  ABS ?DivMod16s
  46 FUNC    GLOBAL DEFAULT  ABS ?Mul16to32u
  46 FUNC    GLOBAL DEFAULT  ABS ?Mul16
  24 FUNC    GLOBAL DEFAULT  ABS ?DivMod16u
  16 FUNC    GLOBAL DEFAULT  ABS ?cstart_init_copy
  12 FUNC    GLOBAL DEFAULT  ABS ?ShiftRight16s
  12 FUNC    GLOBAL DEFAULT  ABS ?cstart_init_zero
   8 FUNC    GLOBAL DEFAULT  ABS ?Epilogue3
   8 FUNC    GLOBAL DEFAULT  ABS ?cstart_call_main
   4 FUNC    GLOBAL DEFAULT  ABS ?Mul8
   4 FUNC    GLOBAL DEFAULT  ABS ?cstart_begin
   2 FUNC    GLOBAL DEFAULT  ABS ?Epilogue6
   2 FUNC    GLOBAL DEFAULT  ABS ?Epilogue5
   2 FUNC    GLOBAL DEFAULT  ABS ?Epilogue4
   2 FUNC    GLOBAL DEFAULT  ABS ?C_EXIT
   0 FUNC    GLOBAL DEFAULT  ABS ?cstart_end   

对于 gcc、它们有9000多个。

1398 FUNC    LOCAL  DEFAULT   74 _fpadd_parts
1308 FUNC    GLOBAL HIDDEN    74 __mspabi_mpyd
 650 FUNC    GLOBAL HIDDEN    74 __pack_d
 606 FUNC    GLOBAL HIDDEN    74 __mspabi_mpyf
 568 FUNC    LOCAL  DEFAULT   74 _fpadd_parts
 374 FUNC    GLOBAL HIDDEN    74 __unpack_d
 368 FUNC    GLOBAL HIDDEN    74 __pack_f
 334 FUNC    GLOBAL HIDDEN    74 __mspabi_divf
 258 FUNC    GLOBAL DEFAULT   74 _malloc_r
 254 FUNC    GLOBAL DEFAULT   74 _free_r
 252 FUNC    GLOBAL HIDDEN    74 __unpack_f
 234 FUNC    GLOBAL HIDDEN    74 __fpcmp_parts_d
 180 FUNC    GLOBAL HIDDEN    74 __fpcmp_parts_f
 166 FUNC    GLOBAL HIDDEN    74 __mspabi_fixdli
 148 FUNC    GLOBAL HIDDEN    74 __mspabi_fltulf
 146 FUNC    GLOBAL HIDDEN    74 __mspabi_fixfli
 112 FUNC    GLOBAL HIDDEN    74 __gedf2
 108 FUNC    GLOBAL HIDDEN    74 __mspabi_cvtdf
 106 FUNC    GLOBAL HIDDEN    74 __mspabi_subd
 104 FUNC    GLOBAL HIDDEN    74 __mspabi_fltuld
 104 FUNC    GLOBAL DEFAULT   74 _raise_r
 102 FUNC    GLOBAL HIDDEN    74 __mspabi_addd
  92 FUNC    GLOBAL HIDDEN    74 __mspabi_fixdul
  92 FUNC    GLOBAL HIDDEN    74 __mspabi_cvtfd
  90 FUNC    GLOBAL DEFAULT   74 _realloc_r
  84 FUNC    GLOBAL HIDDEN    74 __gesf2
  84 FUNC    GLOBAL HIDDEN    74 __gtsf2
  82 FUNC    GLOBAL HIDDEN    74 __ltsf2
  82 FUNC    GLOBAL HIDDEN    74 __mspabi_subf
  78 FUNC    GLOBAL HIDDEN    74 __mspabi_addf
  76 FUNC    GLOBAL HIDDEN    74 __clzsi2
  62 FUNC    GLOBAL HIDDEN    74 __fixunssfsi
  58 FUNC    GLOBAL HIDDEN    74 __make_fp
  52 FUNC    GLOBAL HIDDEN    74 __make_dp
  48 FUNC    GLOBAL HIDDEN    74 __mspabi_divi
  48 FUNC    GLOBAL DEFAULT   74 _sbrk
  44 FUNC    GLOBAL DEFAULT   74 __crt0_run_smi_location_init_array
  36 FUNC    GLOBAL DEFAULT   74 _kill_r
  34 FUNC    GLOBAL DEFAULT   74 _sbrk_r
  24 FUNC    GLOBAL DEFAULT   74 __umulhisi2
  20 FUNC    GLOBAL DEFAULT   74 __crt0_movedata
  20 FUNC    GLOBAL DEFAULT   74 __mulhi2
  20 FUNC    GLOBAL DEFAULT   74 _malloc_usable_size_r
  14 FUNC    GLOBAL DEFAULT   74 __crt0_init_bss
   8 FUNC    GLOBAL HIDDEN    74 __mspabi_divu
   8 FUNC    GLOBAL HIDDEN    74 __mspabi_remu
   6 FUNC    GLOBAL DEFAULT   74 __crt0_call_main
   6 FUNC    GLOBAL DEFAULT   74 _getpid_r
   6 FUNC    GLOBAL DEFAULT   74 __errno
   4 FUNC    WEAK   DEFAULT   74 _exit
   4 FUNC    GLOBAL DEFAULT   74 __crt0_start
   0 FUNC    GLOBAL DEFAULT   74 __mspabi_mpyi
   0 FUNC    GLOBAL DEFAULT   74 __mspabi_mpyul_hw
   0 FUNC    GLOBAL DEFAULT   74 __mspabi_mpyul
   0 FUNC    GLOBAL DEFAULT   74 __mspabi_mpyi_hw

是否有任何简单的解决方案? 我猜至少部分函数是浮点支持、但快速测试显示、即使我从应用程序中删除了所有浮点值、它们也是链接的。

BR
1月

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    [引用 userid="83373" URL"~/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1057179/msp430f249-msp430-gcc-standard-library-size "]是否有任何简单的解决方案?

    GCC 输出显示 了使用 double 的函数、例如_mspabi_fltuld。

    使用 MSP430-gcc-9.3.0.31时、浮点为32位、双精度为64位。

    您的代码是否需要执行32位或64位浮点计算?

    《IAR C/C++编译器用户指南 》指出、IAR 有一个选项可以设置 double 大小、IAR 编译器项目可能有--double=32来帮助减小大小:

    在 C 语言中、非后缀的浮点常量隐式为双精度、这会导致计算提升使用双精度。 例如、以下代码是在 CCS 11中使用 MSP430-gcc-9.3.0.31为 MSP430F249创建的示例

    #include <msp430.h> 
    
    
    /**
     * main.c
     */
    int main(void)
    {
    	WDTCTL = WDTPW | WDTHOLD;	// stop watchdog timer
    	
    	volatile unsigned int input = 23456;
    
    	return input * 1.2345;
    }

    它产生了一个大小如下的程序:

    $ size MSP430F249_GCC_floating_point.out 
       text	   data	    bss	    dec	    hex	filename
       3092	      0	      4	   3096	    c18	MSP430F249_GCC_floating_point.out

    链接器映射文件显示 调用了_mspabi_fltuld、该文件会将 unsigned int 转换为 double。

    减小大小的一种方法是修改代码、将'f'后缀添加到浮点常量中、使常量显式浮动。 例如:

    	return input * 1.2345f;

    为了避免必须更改源代码、另一个选项是在 CCS 工程选项中启用-fsingle-precision-constant 选项:

    进行任一更改都会将示例程序的大小缩减为:

    $ size MSP430F249_GCC_floating_point.out 
       text	   data	    bss	    dec	    hex	filename
       1926	      0	      4	   1930	    78a	MSP430F249_GCC_floating_point.out

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    [引用 userid="83373" URL"~/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1057179/msp430f249-msp430-gcc-standard-library-size。]我猜至少部分函数是浮点支持、但快速测试显示、即使我从应用程序中删除了所有浮点值、这些函数也是链接的。

    在您的 GCC 程序中,malloc()也显示为链接,对于 IAR 程序则不显示。

    您的程序是否执行动态内存分配?

    如果不是,可能值得了解为什么使用 GCC 时会链接 malloc()。 GCC 生成的链接器映射文件具有一个"包含归档成员以满足文件(符号)的引用"部分、可用于查找导致 malloc()链接的原因。

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    切斯特、您好!

    感谢您的详细回答。 他们都对我帮助很大。 我 还没有意识到浮点支持也可能由于常量计算而链接。  尽管在原始 IAR SW 中使用了 malloc、但有关 malloc 的注释也是相关的。 在我的列表中,我只包含了以_或?开头的函数 malloc 在这里实现为正常函数。 我很可能可以轻松地消除它。

    BR
    1月

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    [引用 userid="83373" URL"~/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1057179/msp430f249-msp430-gcc-standard-library-size/3910984 #3910984"]我 尚未意识到也可能由于常量计算而链接浮点支持。

    视情况而定。 我有时使用浮点数、但请注意使用显式转换为整数类型。 然后、编译器可以在编译时执行浮点计算、并在目标代码中保留整数常量。 例如、将一个人类可读的常量转换为 MSP430的定点值。

    如果代码大小是一个问题、请确保将--gC-sections 选项传递给链接器。 一些库对象中有多个函数、有时并非所有函数都被使用。