Sch*_*mpf 5 c enums gcc arm ld
我正在为 ARM 设备(无操作系统)编写裸机应用程序。我需要 32 位枚举,所以我用-fno-short-enums编译器标志编译了应用程序。如果没有这个标志,我会得到变量枚举(并且通过向0xFFFFFFFF每个枚举添加附加值来强制大小不是一种选择)。
现在我收到每个对象的以下链接器警告:
c:/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/6.2.1/../../../../arm-none-eabi/bin/ld.exe: warning: ./src/test.o uses 32-bit enums yet the output is to use variable-size enums; use of enum values across objects may fail
Run Code Online (Sandbox Code Playgroud)
这只是一个警告,没有错误。但这究竟是什么意思?如何指定“输出”?
我尝试使用上述标志重新编译 newlib 以确保所有对象使用相同的枚举大小,但我仍然收到警告。有什么我错过了吗?
过了一会儿我就开始工作了。我用这个标志重建了整个工具链,包括编译器。这是我所做的:
从https://developer.arm.com/open-source/gnu-toolchain/gnu-rm/downloads获取工具链源代码
将 3 行添加到构建脚本的某些部分build-toolchain.sh:
saveenv
saveenvvar CFLAGS_FOR_TARGET '-fno-short-enums'
[...build commands...]
restoreenv
Run Code Online (Sandbox Code Playgroud)
修改部分:
Task [III-1] /$HOST_NATIVE/gcc-first/Task [III-2] /$HOST_NATIVE/newlib/Task [III-4] /$HOST_NATIVE/gcc-final/Task [IV-3] /$HOST_MINGW/gcc-final/我跳过了建设newlib-nano和gcc-size-libstdcxx。
运行修改后的脚本build-prerequisites.sh并build-toolchain.sh构建一切。
之后,编译器使用大型枚举模式,并且链接器对我的对象很好。但现在,我收到了 newlib 的某些对象的相反警告(lib_a-mbtowc_r.o、lib_a-svfiprintf.o、lib_a-svfprintf.o和lib_a-vfprintf.o)lib_a-vfiprintf.o:
c:/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/6.2.1/../../../../arm-none-eabi/bin/ld.exe: warning: c:/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/6.2.1/../../../../arm-none-eabi/lib\libc.a(lib_a-mbtowc_r.o) uses variable-size enums yet the output is to use 32-bit enums; use of enum values across objects may fail
Run Code Online (Sandbox Code Playgroud)
我查看了这些对象的 makefile,遗憾的是它们被明确设置为可变大小枚举。唯一的“解决方案”是添加一个链接器标志来静音此警告:
-Xlinker -no-enum-size-warning
Run Code Online (Sandbox Code Playgroud)
就是这样。