cpq / mdk

A bare metal SDK for the ESP32 & ESP32C3
MIT License
188 stars 26 forks source link

error: dereferencing type-punned pointer will break strict-aliasing rules #6

Closed adumont closed 2 years ago

adumont commented 2 years ago

I've exported the variables:

$ export MDK=/home/adumont/esp32c3/mdk
$ export PATH=$PATH:$MDK/tools
$ export TOOLCHAIN=riscv32-esp-elf
$ export ARCH=ESP32C3
$ export PORT=/dev/ttyUSB0
$ export PATH=$PATH:/home/adumont/.espressif/tools/riscv32-esp-elf/1.24.0.123_64eb9ff-8.4.0/riscv32-esp-elf/bin/

When I run the command to make the blinky example, I get an error when making esputil. Do you know how I could fix it?

$ make -C examples/blinky clean build flash monitor
make: Entering directory '/home/adumont/esp32c3/mdk/examples/blinky'
riscv32-esp-elf-gcc -W -Wall -Wextra -Werror -Wundef -Wshadow -Wdouble-promotion -fno-common -Wconversion -Os -g3 -ffunction-sections -fdata-sections -march=rv32imc -mabi=ilp32 -I. -I/home/adumont/esp32c3/mdk/src -DESP32C3   -c main.c -o build/main.o
riscv32-esp-elf-gcc -W -Wall -Wextra -Werror -Wundef -Wshadow -Wdouble-promotion -fno-common -Wconversion -Os -g3 -ffunction-sections -fdata-sections -march=rv32imc -mabi=ilp32 -I. -I/home/adumont/esp32c3/mdk/src -DESP32C3   -c /home/adumont/esp32c3/mdk/src/boot/boot_ESP32C3.s -o build//home/adumont/esp32c3/mdk/src/boot/boot_ESP32C3.o
riscv32-esp-elf-gcc -W -Wall -Wextra -Werror -Wundef -Wshadow -Wdouble-promotion -fno-common -Wconversion -Os -g3 -ffunction-sections -fdata-sections -march=rv32imc -mabi=ilp32 -I. -I/home/adumont/esp32c3/mdk/src -DESP32C3   -c /home/adumont/esp32c3/mdk/src/init.c -o build//home/adumont/esp32c3/mdk/src/init.o
riscv32-esp-elf-gcc -W -Wall -Wextra -Werror -Wundef -Wshadow -Wdouble-promotion -fno-common -Wconversion -Os -g3 -ffunction-sections -fdata-sections -march=rv32imc -mabi=ilp32 -I. -I/home/adumont/esp32c3/mdk/src -DESP32C3   -c /home/adumont/esp32c3/mdk/src/uart.c -o build//home/adumont/esp32c3/mdk/src/uart.o
riscv32-esp-elf-gcc -W -Wall -Wextra -Werror -Wundef -Wshadow -Wdouble-promotion -fno-common -Wconversion -Os -g3 -ffunction-sections -fdata-sections -march=rv32imc -mabi=ilp32 -I. -I/home/adumont/esp32c3/mdk/src -DESP32C3   -c /home/adumont/esp32c3/mdk/src/log.c -o build//home/adumont/esp32c3/mdk/src/log.o
riscv32-esp-elf-gcc -W -Wall -Wextra -Werror -Wundef -Wshadow -Wdouble-promotion -fno-common -Wconversion -Os -g3 -ffunction-sections -fdata-sections -march=rv32imc -mabi=ilp32 -I. -I/home/adumont/esp32c3/mdk/src -DESP32C3   -c /home/adumont/esp32c3/mdk/src/spi.c -o build//home/adumont/esp32c3/mdk/src/spi.o
riscv32-esp-elf-gcc -W -Wall -Wextra -Werror -Wundef -Wshadow -Wdouble-promotion -fno-common -Wconversion -Os -g3 -ffunction-sections -fdata-sections -march=rv32imc -mabi=ilp32 -I. -I/home/adumont/esp32c3/mdk/src -DESP32C3   -c /home/adumont/esp32c3/mdk/src/tcpip.c -o build//home/adumont/esp32c3/mdk/src/tcpip.o
riscv32-esp-elf-gcc -W -Wall -Wextra -Werror -Wundef -Wshadow -Wdouble-promotion -fno-common -Wconversion -Os -g3 -ffunction-sections -fdata-sections -march=rv32imc -mabi=ilp32 -I. -I/home/adumont/esp32c3/mdk/src -DESP32C3   -c /home/adumont/esp32c3/mdk/src/malloc.c -o build//home/adumont/esp32c3/mdk/src/malloc.o
riscv32-esp-elf-gcc -Xlinker ./build/main.o ./build//home/adumont/esp32c3/mdk/src/boot/boot_ESP32C3.o ./build//home/adumont/esp32c3/mdk/src/init.o ./build//home/adumont/esp32c3/mdk/src/uart.o ./build//home/adumont/esp32c3/mdk/src/log.o ./build//home/adumont/esp32c3/mdk/src/spi.o ./build//home/adumont/esp32c3/mdk/src/tcpip.o ./build//home/adumont/esp32c3/mdk/src/malloc.o -march=rv32imc -mabi=ilp32 -T/home/adumont/esp32c3/mdk/make/ESP32C3.ld -nostdlib -nostartfiles -Wl,--gc-sections  -o build/firmware.elf
riscv32-esp-elf-size build/firmware.elf
   text    data     bss     dec     hex filename
   1040     192   32784   34016    84e0 build/firmware.elf
make -C /home/adumont/esp32c3/mdk/tools esputil
make[1]: Entering directory '/home/adumont/esp32c3/mdk/tools'
cc -W -Wall -Wextra -Werror -Wundef -Wshadow -Wdouble-promotion -Os esputil.c -o ./esputil
esputil.c: In function ‘flash’:
esputil.c:581:7: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
       *(uint32_t *) &buf[0] = n;      // Populate initial bytes - size
       ^
esputil.c:582:7: error: dereferencing type-punned pointer will break strict-aliasing rules [-Werror=strict-aliasing]
       *(uint32_t *) &buf[4] = seq++;  // And sequence numner
       ^
cc1: all warnings being treated as errors
Makefile:11: recipe for target 'esputil' failed
make[1]: *** [esputil] Error 1
make[1]: Leaving directory '/home/adumont/esp32c3/mdk/tools'
../../make/build.mk:40: recipe for target '/home/adumont/esp32c3/mdk/tools/esputil' failed
make: *** [/home/adumont/esp32c3/mdk/tools/esputil] Error 2
make: Leaving directory '/home/adumont/esp32c3/mdk/examples/blinky'

riscv32-esp-elf-gcc -v:

$ /home/adumont/.espressif/tools/riscv32-esp-elf/1.24.0.123_64eb9ff-8.4.0/riscv32-esp-elf/bin/riscv32-esp-elf-gcc -v
Using built-in specs.
COLLECT_GCC=/home/adumont/.espressif/tools/riscv32-esp-elf/1.24.0.123_64eb9ff-8.4.0/riscv32-esp-elf/bin/riscv32-esp-elf-gcc
COLLECT_LTO_WRAPPER=/home/adumont/.espressif/tools/riscv32-esp-elf/1.24.0.123_64eb9ff-8.4.0/riscv32-esp-elf/bin/../libexec/gcc/riscv32-esp-elf/8.4.0/lto-wrapper
Target: riscv32-esp-elf
Configured with: /builds/idf/crosstool-NG/.build/riscv32-esp-elf/src/gcc/configure --build=x86_64-build_pc-linux-gnu --host=x86_64-build_pc-linux-gnu --target=riscv32-esp-elf --prefix=/builds/idf/crosstool-NG/builds/riscv32-esp-elf --with-local-prefix=/builds/idf/crosstool-NG/builds/riscv32-esp-elf/riscv32-esp-elf --with-headers=/builds/idf/crosstool-NG/builds/riscv32-esp-elf/riscv32-esp-elf/include --with-newlib --enable-threads=no --disable-shared --with-arch=rv32imc --with-abi=ilp32 --with-pkgversion='crosstool-NG 1.24.0.123_64eb9ff' --disable-__cxa_atexit --enable-cxx-flags=-ffunction-sections --disable-libgomp --disable-libmudflap --disable-libmpx --disable-libssp --disable-libquadmath --disable-libquadmath-support --with-gmp=/builds/idf/crosstool-NG/.build/riscv32-esp-elf/buildtools --with-mpfr=/builds/idf/crosstool-NG/.build/riscv32-esp-elf/buildtools --with-mpc=/builds/idf/crosstool-NG/.build/riscv32-esp-elf/buildtools --with-isl=/builds/idf/crosstool-NG/.build/riscv32-esp-elf/buildtools --enable-lto --enable-target-optspace --without-long-double-128 --disable-nls --enable-multiarch --enable-languages=c,c++ --disable-libstdcxx-verbose --enable-threads=posix --enable-gcov-custom-rtio --enable-libstdcxx-time=yes
Thread model: posix
gcc version 8.4.0 (crosstool-NG 1.24.0.123_64eb9ff) 
cpq commented 2 years ago

Pushed https://github.com/cpq/mdk/commit/c106e5e6a8c176332d101cb8e51a453123e9fb64

Please pull and retry.

adumont commented 2 years ago

That fixed it, thanks!