Discuss here different C compiler set ups, and compiling executables for the ESP8266

User avatar
By jcmvbkbc
#19771 Hello.

For the brave souls willing to test binutils-2.25, gcc-5.1 and gdb-7.9.1 built by the crosstool-NG-1.21.0 there's a new branch lx106-g++-1.21.0 in the crosstool-NG repository: https://github.com/jcmvbkbc/crosstool-N ... g++-1.21.0

The build steps are the same, just check out another branch:
Code: Select allgit clone -b lx106-g++-1.21.0 git://github.com/jcmvbkbc/crosstool-NG.git
cd crosstool-NG
./bootstrap && ./configure --prefix=`pwd` && make && make install
./ct-ng xtensa-lx106-elf
./ct-ng build
User avatar
By cal
#19823 Moin,

I was rather suprised by the following:

Code: Select allint main(char** argv) {
   *((char*) 0) = 'x';
}


compiled with gcc-5.1

Code: Select allxtensa-lx106-elf-gcc -Os --save-temps -c -o null-access2.o null-access2.c


resulted in
Code: Select all.file   "null-access2.c"
   .global   abort
   .section   .text.startup,"ax",@progbits
   .literal_position
   .align   4
   .global   main
   .type   main, @function
main:
   addi   sp, sp, -16
   s32i.n   a0, sp, 12
   movi.n   a2, 0
   memw
   s8i   a2, a2, 0
   call0   abort
   .size   main, .-main
   .ident   "GCC: (crosstool-NG 1.21.0) 5.1.0"


My code was replaced with a direct call to abort.

Original code was some deeply nested ((void*)(0)) in some define.
Do I have to provide a dummy abort symbol to avoid the whole family of sbrk, malloc, etc?
Is there some magic switch available?
Do I miss something?

Cal
User avatar
By jcmvbkbc
#19826
cal wrote:My code was replaced with a direct call to abort.

Followed by, actually.

cal wrote:Do I have to provide a dummy abort symbol to avoid the whole family of sbrk, malloc, etc?
Is there some magic switch available?

Interesting. This is clearly an undefined behaviour and that's where gcc would emit trap, and according to the chapter 2.1 here in case it's not implemented a call to abort will be emitted. So yes, we either need a dummy implementation of abort() or we need to implement trap pattern in the gcc. Surprisingly I haven't found any switch to turn it off.
I'll add a patch with the trap pattern implementation.

Thanks for your report!