newaetech / chipwhisperer

ChipWhisperer - the complete open-source toolchain for side-channel power analysis and glitching attacks
http://chipwhisperer.com
Other
1.05k stars 275 forks source link

Failure building for CWLITEARM target: multiple definition of _exit, _close, _lseek #483

Open marcoh00 opened 2 months ago

marcoh00 commented 2 months ago

Hello,

I was trying to build simpleserial w/ TinyAES for the CWLITEARM but wasn't successful at first. While this seems to work in our lab using Debian 12 with gcc-12.2, it does not work on my laptop using openSUSE with gcc 13.2.1:

% LC_ALL=C make PLATFORM=CWLITEARM CRYPTO_TARGET=TINYAES128C VERBOSE=TRUE
Building for platform CWLITEARM with CRYPTO_TARGET=TINYAES128C
SS_VER set to SS_VER_1_1
SS_VER set to SS_VER_1_1
Blank crypto options, building for AES128
Building for platform CWLITEARM with CRYPTO_TARGET=TINYAES128C
SS_VER set to SS_VER_1_1
SS_VER set to SS_VER_1_1
Blank crypto options, building for AES128
mkdir -p .dep
Building for platform CWLITEARM with CRYPTO_TARGET=TINYAES128C
SS_VER set to SS_VER_1_1
SS_VER set to SS_VER_1_1
Blank crypto options, building for AES128
.
Welcome to another exciting ChipWhisperer target build!!
arm-none-eabi-gcc (SUSE Linux) 13.2.1 20240206 [revision 67ac78caf31f7cb3202177e6428a46d829b70f23]
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

.
Compiling:
    arm-none-eabi-gcc -c -mcpu=cortex-m4 -I. -DNO_EXTRA_OPTS -mthumb -mfloat-abi=soft -fmessage-length=0 -ffunction-sections -gdwarf-2 -DSS_VER=SS_VER_1_1 -DSTM32F303xC -DSTM32F3 -DSTM32 -DDEBUG -DHAL_TYPE=HAL_stm32f3 -DPLATFORM=CWLITEARM -DSS_VER=SS_VER_1_1 -DTINYAES128C -DF_CPU=7372800UL -DSS_VER_2_0=2 -DSS_VER_2_1=3 -DSS_VER_1_1=1 -DSS_VER_1_0=0 -Os -funsigned-char -funsigned-bitfields -fshort-enums -Wall -Wstrict-prototypes -I.././simpleserial/ -I.././hal -I.././hal/stm32f3 -I.././hal/stm32f3/CMSIS -I.././hal/stm32f3/CMSIS/core -I.././hal/stm32f3/CMSIS/device -I.././hal/stm32f4/Legacy -I.././simpleserial/ -I.././crypto/ -I.././crypto/tiny-AES128-C -std=gnu99 -Wno-discarded-qualifiers -Wno-unused-function -Wno-unused-variable -Wno-strict-prototypes -Wno-missing-prototypes -Wno-pointer-sign -Wno-unused-value -Wno-implicit-function-declaration  -Wa,-adhlns=objdir-CWLITEARM/simpleserial-aes.lst -MMD -MP -MF .dep/simpleserial-aes.o.d simpleserial-aes.c -o objdir-CWLITEARM/simpleserial-aes.o ...Done!

.
Compiling:
    arm-none-eabi-gcc -c -mcpu=cortex-m4 -I. -DNO_EXTRA_OPTS -mthumb -mfloat-abi=soft -fmessage-length=0 -ffunction-sections -gdwarf-2 -DSS_VER=SS_VER_1_1 -DSTM32F303xC -DSTM32F3 -DSTM32 -DDEBUG -DHAL_TYPE=HAL_stm32f3 -DPLATFORM=CWLITEARM -DSS_VER=SS_VER_1_1 -DTINYAES128C -DF_CPU=7372800UL -DSS_VER_2_0=2 -DSS_VER_2_1=3 -DSS_VER_1_1=1 -DSS_VER_1_0=0 -Os -funsigned-char -funsigned-bitfields -fshort-enums -Wall -Wstrict-prototypes -I.././simpleserial/ -I.././hal -I.././hal/stm32f3 -I.././hal/stm32f3/CMSIS -I.././hal/stm32f3/CMSIS/core -I.././hal/stm32f3/CMSIS/device -I.././hal/stm32f4/Legacy -I.././simpleserial/ -I.././crypto/ -I.././crypto/tiny-AES128-C -std=gnu99 -Wno-discarded-qualifiers -Wno-unused-function -Wno-unused-variable -Wno-strict-prototypes -Wno-missing-prototypes -Wno-pointer-sign -Wno-unused-value -Wno-implicit-function-declaration  -Wa,-adhlns=objdir-CWLITEARM/simpleserial.lst -MMD -MP -MF .dep/simpleserial.o.d .././simpleserial/simpleserial.c -o objdir-CWLITEARM/simpleserial.o ...Done!

.
Compiling:
    arm-none-eabi-gcc -c -mcpu=cortex-m4 -I. -DNO_EXTRA_OPTS -mthumb -mfloat-abi=soft -fmessage-length=0 -ffunction-sections -gdwarf-2 -DSS_VER=SS_VER_1_1 -DSTM32F303xC -DSTM32F3 -DSTM32 -DDEBUG -DHAL_TYPE=HAL_stm32f3 -DPLATFORM=CWLITEARM -DSS_VER=SS_VER_1_1 -DTINYAES128C -DF_CPU=7372800UL -DSS_VER_2_0=2 -DSS_VER_2_1=3 -DSS_VER_1_1=1 -DSS_VER_1_0=0 -Os -funsigned-char -funsigned-bitfields -fshort-enums -Wall -Wstrict-prototypes -I.././simpleserial/ -I.././hal -I.././hal/stm32f3 -I.././hal/stm32f3/CMSIS -I.././hal/stm32f3/CMSIS/core -I.././hal/stm32f3/CMSIS/device -I.././hal/stm32f4/Legacy -I.././simpleserial/ -I.././crypto/ -I.././crypto/tiny-AES128-C -std=gnu99 -Wno-discarded-qualifiers -Wno-unused-function -Wno-unused-variable -Wno-strict-prototypes -Wno-missing-prototypes -Wno-pointer-sign -Wno-unused-value -Wno-implicit-function-declaration  -Wa,-adhlns=objdir-CWLITEARM/stm32f3_hal.lst -MMD -MP -MF .dep/stm32f3_hal.o.d .././hal/stm32f3/stm32f3_hal.c -o objdir-CWLITEARM/stm32f3_hal.o ...Done!

.
Compiling:
    arm-none-eabi-gcc -c -mcpu=cortex-m4 -I. -DNO_EXTRA_OPTS -mthumb -mfloat-abi=soft -fmessage-length=0 -ffunction-sections -gdwarf-2 -DSS_VER=SS_VER_1_1 -DSTM32F303xC -DSTM32F3 -DSTM32 -DDEBUG -DHAL_TYPE=HAL_stm32f3 -DPLATFORM=CWLITEARM -DSS_VER=SS_VER_1_1 -DTINYAES128C -DF_CPU=7372800UL -DSS_VER_2_0=2 -DSS_VER_2_1=3 -DSS_VER_1_1=1 -DSS_VER_1_0=0 -Os -funsigned-char -funsigned-bitfields -fshort-enums -Wall -Wstrict-prototypes -I.././simpleserial/ -I.././hal -I.././hal/stm32f3 -I.././hal/stm32f3/CMSIS -I.././hal/stm32f3/CMSIS/core -I.././hal/stm32f3/CMSIS/device -I.././hal/stm32f4/Legacy -I.././simpleserial/ -I.././crypto/ -I.././crypto/tiny-AES128-C -std=gnu99 -Wno-discarded-qualifiers -Wno-unused-function -Wno-unused-variable -Wno-strict-prototypes -Wno-missing-prototypes -Wno-pointer-sign -Wno-unused-value -Wno-implicit-function-declaration  -Wa,-adhlns=objdir-CWLITEARM/stm32f3_hal_lowlevel.lst -MMD -MP -MF .dep/stm32f3_hal_lowlevel.o.d .././hal/stm32f3/stm32f3_hal_lowlevel.c -o objdir-CWLITEARM/stm32f3_hal_lowlevel.o ...Done!

.
Compiling:
    arm-none-eabi-gcc -c -mcpu=cortex-m4 -I. -DNO_EXTRA_OPTS -mthumb -mfloat-abi=soft -fmessage-length=0 -ffunction-sections -gdwarf-2 -DSS_VER=SS_VER_1_1 -DSTM32F303xC -DSTM32F3 -DSTM32 -DDEBUG -DHAL_TYPE=HAL_stm32f3 -DPLATFORM=CWLITEARM -DSS_VER=SS_VER_1_1 -DTINYAES128C -DF_CPU=7372800UL -DSS_VER_2_0=2 -DSS_VER_2_1=3 -DSS_VER_1_1=1 -DSS_VER_1_0=0 -Os -funsigned-char -funsigned-bitfields -fshort-enums -Wall -Wstrict-prototypes -I.././simpleserial/ -I.././hal -I.././hal/stm32f3 -I.././hal/stm32f3/CMSIS -I.././hal/stm32f3/CMSIS/core -I.././hal/stm32f3/CMSIS/device -I.././hal/stm32f4/Legacy -I.././simpleserial/ -I.././crypto/ -I.././crypto/tiny-AES128-C -std=gnu99 -Wno-discarded-qualifiers -Wno-unused-function -Wno-unused-variable -Wno-strict-prototypes -Wno-missing-prototypes -Wno-pointer-sign -Wno-unused-value -Wno-implicit-function-declaration  -Wa,-adhlns=objdir-CWLITEARM/stm32f3_sysmem.lst -MMD -MP -MF .dep/stm32f3_sysmem.o.d .././hal/stm32f3/stm32f3_sysmem.c -o objdir-CWLITEARM/stm32f3_sysmem.o ...Done!

.
Compiling:
    arm-none-eabi-gcc -c -mcpu=cortex-m4 -I. -DNO_EXTRA_OPTS -mthumb -mfloat-abi=soft -fmessage-length=0 -ffunction-sections -gdwarf-2 -DSS_VER=SS_VER_1_1 -DSTM32F303xC -DSTM32F3 -DSTM32 -DDEBUG -DHAL_TYPE=HAL_stm32f3 -DPLATFORM=CWLITEARM -DSS_VER=SS_VER_1_1 -DTINYAES128C -DF_CPU=7372800UL -DSS_VER_2_0=2 -DSS_VER_2_1=3 -DSS_VER_1_1=1 -DSS_VER_1_0=0 -Os -funsigned-char -funsigned-bitfields -fshort-enums -Wall -Wstrict-prototypes -I.././simpleserial/ -I.././hal -I.././hal/stm32f3 -I.././hal/stm32f3/CMSIS -I.././hal/stm32f3/CMSIS/core -I.././hal/stm32f3/CMSIS/device -I.././hal/stm32f4/Legacy -I.././simpleserial/ -I.././crypto/ -I.././crypto/tiny-AES128-C -std=gnu99 -Wno-discarded-qualifiers -Wno-unused-function -Wno-unused-variable -Wno-strict-prototypes -Wno-missing-prototypes -Wno-pointer-sign -Wno-unused-value -Wno-implicit-function-declaration  -Wa,-adhlns=objdir-CWLITEARM/aes.lst -MMD -MP -MF .dep/aes.o.d .././crypto/tiny-AES128-C/aes.c -o objdir-CWLITEARM/aes.o ...Done!

.
Compiling:
    arm-none-eabi-gcc -c -mcpu=cortex-m4 -I. -DNO_EXTRA_OPTS -mthumb -mfloat-abi=soft -fmessage-length=0 -ffunction-sections -gdwarf-2 -DSS_VER=SS_VER_1_1 -DSTM32F303xC -DSTM32F3 -DSTM32 -DDEBUG -DHAL_TYPE=HAL_stm32f3 -DPLATFORM=CWLITEARM -DSS_VER=SS_VER_1_1 -DTINYAES128C -DF_CPU=7372800UL -DSS_VER_2_0=2 -DSS_VER_2_1=3 -DSS_VER_1_1=1 -DSS_VER_1_0=0 -Os -funsigned-char -funsigned-bitfields -fshort-enums -Wall -Wstrict-prototypes -I.././simpleserial/ -I.././hal -I.././hal/stm32f3 -I.././hal/stm32f3/CMSIS -I.././hal/stm32f3/CMSIS/core -I.././hal/stm32f3/CMSIS/device -I.././hal/stm32f4/Legacy -I.././simpleserial/ -I.././crypto/ -I.././crypto/tiny-AES128-C -std=gnu99 -Wno-discarded-qualifiers -Wno-unused-function -Wno-unused-variable -Wno-strict-prototypes -Wno-missing-prototypes -Wno-pointer-sign -Wno-unused-value -Wno-implicit-function-declaration  -Wa,-adhlns=objdir-CWLITEARM/aes-independant.lst -MMD -MP -MF .dep/aes-independant.o.d .././crypto/aes-independant.c -o objdir-CWLITEARM/aes-independant.o ...Done!

.
Assembling: .././hal/stm32f3/stm32f3_startup.S
arm-none-eabi-gcc -c -mcpu=cortex-m4 -I. -x assembler-with-cpp -mthumb -mfloat-abi=soft -fmessage-length=0 -ffunction-sections -DF_CPU=7372800 -Wa,-gstabs,-adhlns=objdir-CWLITEARM/stm32f3_startup.lst -I.././simpleserial/ -I.././hal -I.././hal/stm32f3 -I.././hal/stm32f3/CMSIS -I.././hal/stm32f3/CMSIS/core -I.././hal/stm32f3/CMSIS/device -I.././hal/stm32f4/Legacy -I.././simpleserial/ -I.././crypto/ -I.././crypto/tiny-AES128-C .././hal/stm32f3/stm32f3_startup.S -o objdir-CWLITEARM/stm32f3_startup.o
.
LINKING:
    arm-none-eabi-gcc simpleserial-aes-CWLITEARM.elf w/ opts -mcpu=cortex-m4 -I. -DNO_EXTRA_OPTS -mthumb -mfloat-abi=soft -fmessage-length=0 -ffunction-sections -gdwarf-2 -DSS_VER=SS_VER_1_1 -DSTM32F303xC -DSTM32F3 -DSTM32 -DDEBUG -DHAL_TYPE=HAL_stm32f3 -DPLATFORM=CWLITEARM -DSS_VER=SS_VER_1_1 -DTINYAES128C -DF_CPU=7372800UL -DSS_VER_2_0=2 -DSS_VER_2_1=3 -DSS_VER_1_1=1 -DSS_VER_1_0=0 -Os -funsigned-char -funsigned-bitfields -fshort-enums -Wall -Wstrict-prototypes -I.././simpleserial/ -I.././hal -I.././hal/stm32f3 -I.././hal/stm32f3/CMSIS -I.././hal/stm32f3/CMSIS/core -I.././hal/stm32f3/CMSIS/device -I.././hal/stm32f4/Legacy -I.././simpleserial/ -I.././crypto/ -I.././crypto/tiny-AES128-C -std=gnu99 -Wno-discarded-qualifiers -Wno-unused-function -Wno-unused-variable -Wno-strict-prototypes -Wno-missing-prototypes -Wno-pointer-sign -Wno-unused-value -Wno-implicit-function-declaration  -Wa,-adhlns=objdir-CWLITEARM/simpleserial-aes.o -MMD -MP -MF .dep/simpleserial-aes-CWLITEARM.elf.d --specs=nano.specs --specs=nosys.specs -T .././hal/stm32f3/LinkerScript.ld -Wl,--gc-sections -lm -Wl,-Map=simpleserial-aes-CWLITEARM.map,--cref   -lm   ... objdir-CWLITEARM/simpleserial-aes.o objdir-CWLITEARM/simpleserial.o objdir-CWLITEARM/stm32f3_hal.o objdir-CWLITEARM/stm32f3_hal_lowlevel.o objdir-CWLITEARM/stm32f3_sysmem.o objdir-CWLITEARM/aes.o objdir-CWLITEARM/aes-independant.o objdir-CWLITEARM/stm32f3_startup.o/usr/lib64/gcc/arm-none-eabi/13/ld: /usr/lib64/gcc/arm-none-eabi/13/../../../../arm-none-eabi/lib/thumb/v7e-m/nofp/libg_nano.a(libc_a-closer.o): in function `_close_r':
/home/abuild/rpmbuild/BUILD/newlib-4.3.0.20230120/build-nano-dir/arm-none-eabi/thumb/v7e-m/nofp/newlib/../../../../../../newlib/libc/reent/closer.c:47:(.text+0xc): warning: _close is not implemented and will always fail
/usr/lib64/gcc/arm-none-eabi/13/ld: /usr/lib64/gcc/arm-none-eabi/13/../../../../arm-none-eabi/lib/thumb/v7e-m/nofp/libg_nano.a(libc_a-closer.o): note: the message above does not take linker garbage collection into account
/usr/lib64/gcc/arm-none-eabi/13/ld: /usr/lib64/gcc/arm-none-eabi/13/../../../../arm-none-eabi/lib/thumb/v7e-m/nofp/libg_nano.a(libc_a-lseekr.o): in function `_lseek_r':
/home/abuild/rpmbuild/BUILD/newlib-4.3.0.20230120/build-nano-dir/arm-none-eabi/thumb/v7e-m/nofp/newlib/../../../../../../newlib/libc/reent/lseekr.c:49:(.text+0x10): warning: _lseek is not implemented and will always fail
/usr/lib64/gcc/arm-none-eabi/13/ld: /usr/lib64/gcc/arm-none-eabi/13/../../../../arm-none-eabi/lib/thumb/v7e-m/nofp/libg_nano.a(libc_a-lseekr.o): note: the message above does not take linker garbage collection into account
/usr/lib64/gcc/arm-none-eabi/13/ld: /usr/lib64/gcc/arm-none-eabi/13/../../../../arm-none-eabi/lib/thumb/v7e-m/nofp/libg_nano.a(libc_a-readr.o): in function `_read_r':
/home/abuild/rpmbuild/BUILD/newlib-4.3.0.20230120/build-nano-dir/arm-none-eabi/thumb/v7e-m/nofp/newlib/../../../../../../newlib/libc/reent/readr.c:49:(.text+0x10): warning: _read is not implemented and will always fail
/usr/lib64/gcc/arm-none-eabi/13/ld: /usr/lib64/gcc/arm-none-eabi/13/../../../../arm-none-eabi/lib/thumb/v7e-m/nofp/libg_nano.a(libc_a-readr.o): note: the message above does not take linker garbage collection into account
/usr/lib64/gcc/arm-none-eabi/13/ld: /usr/lib64/gcc/arm-none-eabi/13/../../../../arm-none-eabi/lib/thumb/v7e-m/nofp/libg_nano.a(libc_a-writer.o): in function `_write_r':
/home/abuild/rpmbuild/BUILD/newlib-4.3.0.20230120/build-nano-dir/arm-none-eabi/thumb/v7e-m/nofp/newlib/../../../../../../newlib/libc/reent/writer.c:49:(.text+0x10): warning: _write is not implemented and will always fail
/usr/lib64/gcc/arm-none-eabi/13/ld: /usr/lib64/gcc/arm-none-eabi/13/../../../../arm-none-eabi/lib/thumb/v7e-m/nofp/libg_nano.a(libc_a-writer.o): note: the message above does not take linker garbage collection into account
/usr/lib64/gcc/arm-none-eabi/13/ld: /usr/lib64/gcc/arm-none-eabi/13/../../../../arm-none-eabi/lib/thumb/v7e-m/nofp/libc.a(libc_a-syscalls.o): in function `_lseek':
/home/abuild/rpmbuild/BUILD/newlib-4.3.0.20230120/build-regular-dir/arm-none-eabi/thumb/v7e-m/nofp/newlib/../../../../../../newlib/libc/sys/arm/syscalls.c:310: multiple definition of `_lseek'; /usr/lib64/gcc/arm-none-eabi/13/../../../../arm-none-eabi/lib/thumb/v7e-m/nofp/libnosys.a(lseek.o):/home/abuild/rpmbuild/BUILD/newlib-4.3.0.20230120/build-regular-dir/arm-none-eabi/thumb/v7e-m/nofp/libgloss/../../../../../../libgloss/libnosys/lseek.c:18: first defined here
/usr/lib64/gcc/arm-none-eabi/13/ld: /usr/lib64/gcc/arm-none-eabi/13/../../../../arm-none-eabi/lib/thumb/v7e-m/nofp/libc.a(libc_a-syscalls.o): in function `_close':
/home/abuild/rpmbuild/BUILD/newlib-4.3.0.20230120/build-regular-dir/arm-none-eabi/thumb/v7e-m/nofp/newlib/../../../../../../newlib/libc/sys/arm/syscalls.c:443: multiple definition of `_close'; /usr/lib64/gcc/arm-none-eabi/13/../../../../arm-none-eabi/lib/thumb/v7e-m/nofp/libnosys.a(close.o):/home/abuild/rpmbuild/BUILD/newlib-4.3.0.20230120/build-regular-dir/arm-none-eabi/thumb/v7e-m/nofp/libgloss/../../../../../../libgloss/libnosys/close.c:16: first defined here
/usr/lib64/gcc/arm-none-eabi/13/ld: /usr/lib64/gcc/arm-none-eabi/13/../../../../arm-none-eabi/lib/thumb/v7e-m/nofp/libc.a(libc_a-syscalls.o): in function `_exit':
/home/abuild/rpmbuild/BUILD/newlib-4.3.0.20230120/build-regular-dir/arm-none-eabi/thumb/v7e-m/nofp/newlib/../../../../../../newlib/libc/sys/arm/syscalls.c:494: multiple definition of `_exit'; /usr/lib64/gcc/arm-none-eabi/13/../../../../arm-none-eabi/lib/thumb/v7e-m/nofp/libnosys.a(_exit.o):/home/abuild/rpmbuild/BUILD/newlib-4.3.0.20230120/build-regular-dir/arm-none-eabi/thumb/v7e-m/nofp/libgloss/../../../../../../libgloss/libnosys/_exit.c:16: first defined here
/usr/lib64/gcc/arm-none-eabi/13/ld: warning: simpleserial-aes-CWLITEARM.elf has a LOAD segment with RWX permissions
collect2: error: ld returned 1 exit status
make[1]: *** [.././Makefile.inc:498: simpleserial-aes-CWLITEARM.elf] Error 1
make: *** [.././Makefile.inc:350: all] Error 2

It does seem to work, when I remove --specs=nano.specs or --specs=nosys.specs (or both) from LDFLAGS in hal/stm32f3/Makefile.stm32f3. However, in I am not exactly sure what the consequences for the built artifact are. Is any of them unneeded? If yes, what was the reason for adding both specs and should any of them be removed?

colinoflynn commented 2 months ago

tldr; if it builds it works(tm)!

The nano.specs/nosys.specs was required for I think some of the builds, I know we had it on/off (I'll have to let @alex-dewar chime in as I forget exactly when/why now... IIRC for the F0 but been a while). If the build succeeds without that present then it should be fine, this may be changes in newlib?

We don't actually need any of those stubs (hence the warning about them doing nothing), it's just some of the examples pull in the standard library so you need them for linking purposes. The multiple definition presumably means they ended up in one of the libraries where we didn't have them before, so your build now succeeds without us explicitly adding those stubs.