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.

[参考译文] TM4C129XNCZAD:静态库会导致整体大小大于没有静态库的原始代码

Guru**** 2391175 points


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

https://e2e.ti.com/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1111795/tm4c129xnczad-static-library-cause-the-overall-size-to-be-larger-than-the-original-code-without-static-library

器件型号:TM4C129XNCZAD

您好!

我正在使用:

CCS           :版本:9.3.0.00012

XDCTool       :xdctools_3_32_01_22_core

ARM 编译器  :ti-cgt-arm_18.12.5.LTS

TIRTOS        :tirtos_tivac_2_16_01_14

我有一个代码尝试在静态库中将其部分分离、但我感到惊讶的是、在这样做之后、所有代码都增加了8K。

经过一些调查后、我发现库中实现的一些函数没有被主代码调用、链接器将其包含在代码中、而并非所有代码都位于一个项目中。

是否有办法让链接器忽略库中未使用的函数以节省代码空间?

谢谢、

穆罕默德

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

    请考虑使用链接时优化。  要了解相关信息、 请在 TI ARM 编译器手册中搜索 标题为 链接时优化的子章节。  请注意在构建库、主应用程序源文件和链接时必须如何使用--opt_level=4。

    谢谢、此致、

    乔治

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    [引用 userid="173560" URL"~/support/microcontrollers/arm-based-microcontrollers-group/arm-based-microcontrollers/f/arm-based-microcontrollers-forum/1111795/tm4c129xnczad-static-library-cause-the-over-size-to-max-be-maer-the-real-the-real-the-the-the-the-the-the-the-the-the-the-the-the-ree-the-the-the-the-the-the-the-the-the-ree-the-the-the-the-

    虽然 George 建议使用链接时优化、但另一种可能是将-gen_func_subsections 设置为 on (对于  ti-cgt-arm_18.12.5.LTS、默认设置为 off)。 这位于 CCS Project Properties -> CCS Build -> ARM Compiler -> Advanced Options -> Runtime Model Options 下:

    使用 -gen_func_subsections=on 意味着每个函数都放置在其自己的子段中、这允许链接器删除一个源文件(编译单元)中的未使用函数。

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

    谢谢您 George、但我无法在主项目中使用此级别的优化、因为我害怕由于此级别的优化而在代码中引入错误、还有其他替代方法吗?

    穆罕默德   

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

    实际上、此选项处于打开状态、它不会删除不需要的函数

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。
    [引用 userid="173560" URL"~/support/microcontrollers/arm-based microcontrollers-group/arm -based-microcontrollers/f/arm based-microcontrollers-forum/1111795/tm4c129xnczad-static-library-cause-the-over-size-te-be-be-max-be-max-the-origine-ine-regule-ine-regule-quality/quote-ine-regule-regule-regulse-se-ine-regulse-se-ine-se-size-ce-ce-ine-ine-ine-

    您能否确认构建静态库的工程中是否也启用了该选项?

    您是否还能够从不需要的函数未被删除的构建中发布链接器.map 文件?