简体   繁体   English

使用GCC ARM Embedded进行编译时,代码大小加倍?

[英]Code size is doubled when compiling with GCC ARM Embedded?

I've just ported a STM32 microcontroller project from Keil uVision (using Keil ARM Compiler) to CooCox CoIDE (using GCC ARM Embedded compiler). 我刚刚将Keil uVision(使用Keil ARM编译器)的STM32微控制器项目移植到CooCox CoIDE(使用GCC ARM嵌入式编译器)。

Problem is, the code size is the double size when compiled in CoIDE with GCC compared to Keil uVision. 问题是,与Keil uVision相比,使用GCC在CoIDE中编译时,代码大小是双倍大小。

How can this be? 怎么会这样? What can I do? 我能做什么?

Code size in Keil: 54632b (.text) Code size in CoIDE: 100844b (.text) Keil中的代码大小:54632b(。text)CoIDE中的代码大小:100844b(.text)

GCC compiler flags: GCC编译器标志:

arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -g2 -Wl,-Map=project.map -Os 
-Wl,--gc-sections -Wl,-TC:\arm-gcc-link.ld -g -o project.elf -L -lm

I am suspecting CoIDE and GCC to compile a lot of functions and files, that are present in the project, though aren't used (yet). 我怀疑CoIDE和GCC编译了很多函数和文件,这些函数和文件存在于项目中,但尚未使用。 Is it possible that it compiles whole files even if I only use 1 function out of 20 in there? 它是否有可能编译整个文件,即使我只使用20中的1个函数? (even though I have -Os).. (即使我有-Os)..

Hard to say which files are really compiled/linked in your final binary from the information you give. 很难说你的最终二进制文件中的哪些文件是真正编译/链接的。 I suppose it takes all the C files it finds on your project if you did not explicitly specified which one to compile or if you don't use your own Makefile. 我想如果你没有明确指定要编译哪一个或者你没有使用自己的Makefile,那么它会占用你在项目中找到的所有C文件。

But from the compiler options you give, the linker flag --gc-sections won't do much garbage if you don't have the following compiler flags: -ffunction-sections -fdata-sections . 但是,根据您提供的编译器选项,如果您没有以下编译器标志,则链接器标志--gc-sections将不会产生太多垃圾: -ffunction-sections -fdata-sections Try to add those options to strip all unused functions and data at link time. 尝试添加这些选项以在链接时删除所有未使用的函数和数据。

Since the question was tagged with C++, I wonder if you would like to disable exceptions and RTTI. 由于问题是用C ++标记的,我想知道您是否要禁用异常和RTTI。 Those take quite a bit of code. 那些需要相当多的代码。 Add -fno-exceptions -fno-rtti to linker flags. -fno-exceptions -fno-rtti添加到链接器标志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM