为 cortex M4 编译时冲突 CPU 架构 1/13

Conflicting CPU architectures 1/13 when compiling for cortex M4

我曾经用 arm-none-eabi-gcc/arm-none-eabi-g++ 编译我的微控制器代码,一切正常。我在 Mac 上使用自制的 Cask gcc-arm-embedded。昨天我更新了它,现在当我为 Cortex M4 架构编译时,我在 link 阶段收到每个目标文件的这些错误消息(用 M3 编译得很好):

/usr/local/Caskroom/gcc-arm-embedded/6-2017-q1-update/gcc-arm-none-eabi-6-2017-q1-update/bin/../lib/gcc/arm-none-eabi/6.3.1/../../../../arm-none-eabi/bin/ld: error: anobjectfile.o: Conflicting CPU architectures 1/13
/usr/local/Caskroom/gcc-arm-embedded/6-2017-q1-update/gcc-arm-none-eabi-6-2017-q1-update/bin/../lib/gcc/arm-none-eabi/6.3.1/../../../../arm-none-eabi/bin/ld: failed to merge target specific data of file example.o

查看内容时一切正常:

$ arm-none-eabi-readelf -A example.o
Attribute Section: aeabi
File Attributes
  Tag_CPU_name: "Cortex-M4"
  Tag_CPU_arch: v7E-M
  Tag_CPU_arch_profile: Microcontroller
  Tag_THUMB_ISA_use: Thumb-2
  Tag_FP_arch: VFPv4-D16
  Tag_ABI_PCS_wchar_t: 2
  Tag_ABI_FP_denormal: Needed
  Tag_ABI_FP_exceptions: Needed
  Tag_ABI_FP_number_model: IEEE 754
  Tag_ABI_align_needed: 8-byte
  Tag_ABI_align_preserved: 8-byte, except leaf SP
  Tag_ABI_enum_size: small
  Tag_ABI_HardFP_use: SP only
  Tag_ABI_VFP_args: VFP registers
  Tag_ABI_optimization_goals: Aggressive Size
  Tag_CPU_unaligned_access: v6

这里是编译C文件的命令行:

arm-none-eabi-gcc -ffunction-sections -Wall -Werror -I… -std=c99 -DBOARD_DISCOVERY_F429 
  -DPORT_CPU=stm32f429 -DPORT_CPU_FAMILY=arm -DPORT_CPU_FAMILY_SUBFAMILY=CM4F 
  -DPORT_CPU_FLAVOR=stm32f4xx -g -Os -DNDEBUG -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 
  -mfloat-abi=hard -fno-math-errno -mtune=cortex-m4 -D__thumb2__=1 -march=armv7e-m -mthumb 
  -DUSE_STDPERIPH_DRIVER -DSTM32F429_439xx -mapcs-frame -mno-sched-prolog -fshort-wchar 
  -D__LITTLE_ENDIAN -ffunction-sections -fdata-sections -fno-builtin-malloc 
  -fno-builtin-realloc -fno-builtin-free -fno-strict-aliasing -DTARGET_LITTLE_ENDIAN 
  -DHSE_VALUE=8000000 -DPLL_M=8 -g -c -o example.o example.c

对于 C++ 文件:

arm-none-eabi-g++ -ffunction-sections -Wall -Werror -I… -fno-exceptions -fno-rtti 
  -std=c++11 -DBOARD_DISCOVERY_F429 -DPORT_CPU=stm32f429 -DPORT_CPU_FAMILY=arm 
  -DPORT_CPU_FAMILY_SUBFAMILY=CM4F -DPORT_CPU_FLAVOR=stm32f4xx -g -Os -DNDEBUG 
  -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fno-math-errno -mtune=cortex-m4 
  -D__thumb2__=1 -march=armv7e-m -mthumb -DUSE_STDPERIPH_DRIVER -DSTM32F429_439xx 
  -mapcs-frame -mno-sched-prolog -fshort-wchar -D__LITTLE_ENDIAN -ffunction-sections 
  -fdata-sections -fno-builtin-malloc -fno-builtin-realloc -fno-builtin-free 
  -fno-strict-aliasing -DTARGET_LITTLE_ENDIAN -DHSE_VALUE=8000000 -DPLL_M=8 -g -c 
  -o example.o example.cpp

和 link:

arm-none-eabi-gcc -Wl,--gc-sections -Wl,-Map=executable.map -o executable.elf executable.o 
  file1.o file2.o … -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -fno-math-errno 
  -mtune=cortex-m4 -march=armv7e-m -mthumb -Wl,--no-wchar-size-warning -g 
  -T…/stm32f40x.ld -specs=…/specs -Wl,--start-group …/lib1.a …/lib2.a …  -Wl,--end-group

查看多库:

$ arm-none-eabi-gcc -print-multi-lib
.;
thumb;@mthumb
hard;@mfloat-abi=hard
thumb/v6-m;@mthumb@march=armv6s-m
thumb/v7-m;@mthumb@march=armv7-m
thumb/v7e-m;@mthumb@march=armv7e-m
thumb/v7-ar;@mthumb@march=armv7
thumb/v8-m.base;@mthumb@march=armv8-m.base
thumb/v8-m.main;@mthumb@march=armv8-m.main
thumb/v7e-m/fpv4-sp/softfp;@mthumb@march=armv7e-m@mfpu=fpv4-sp-d16@mfloat-abi=softfp
thumb/v7e-m/fpv4-sp/hard;@mthumb@march=armv7e-m@mfpu=fpv4-sp-d16@mfloat-abi=hard
thumb/v7e-m/fpv5-sp/softfp;@mthumb@march=armv7e-m@mfpu=fpv5-sp-d16@mfloat-abi=softfp
thumb/v7e-m/fpv5-sp/hard;@mthumb@march=armv7e-m@mfpu=fpv5-sp-d16@mfloat-abi=hard
thumb/v7e-m/fpv5/softfp;@mthumb@march=armv7e-m@mfpu=fpv5-d16@mfloat-abi=softfp
thumb/v7e-m/fpv5/hard;@mthumb@march=armv7e-m@mfpu=fpv5-d16@mfloat-abi=hard
thumb/v7-ar/fpv3/softfp;@mthumb@march=armv7@mfpu=vfpv3-d16@mfloat-abi=softfp
thumb/v7-ar/fpv3/hard;@mthumb@march=armv7@mfpu=vfpv3-d16@mfloat-abi=hard
thumb/v8-m.main/fpv5-sp/softfp;@mthumb@march=armv8-m.main@mfpu=fpv5-sp-d16@mfloat-abi=softfp
thumb/v8-m.main/fpv5-sp/hard;@mthumb@march=armv8-m.main@mfpu=fpv5-sp-d16@mfloat-abi=hard
thumb/v8-m.main/fpv5/softfp;@mthumb@march=armv8-m.main@mfpu=fpv5-d16@mfloat-abi=softfp
thumb/v8-m.main/fpv5/hard;@mthumb@march=armv8-m.main@mfpu=fpv5-d16@mfloat-abi=hard

有符合我参数的配置:

thumb/v7e-m/fpv4-sp/hard;@mthumb@march=armv7e-m@mfpu=fpv4-sp-d16@mfloat-abi=hard

有人知道我的配置有什么问题吗?

一位同事发现了这个问题。由于某些原因,我们需要更改编译器规范。为此,我们将其添加到 link 命令行:-specs=…/specs

我们使用以下命令生成了规格文件arm-none-eabi-gcc -c foo.c -dumpspecs

问题是新版本的编译器有新的规格,所以我们不得不重新生成它们,这解决了问题。