-
Notifications
You must be signed in to change notification settings - Fork 7.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Weird IllegalInstruction errors (need to add -Werror=return-type) (IDFGH-6602) #8244
Comments
Update: changing optimization level in sdkconfig to debug without optimization -O0 fixes the issue. |
I do believe there are some problems with -O0 in esp-idf. #7835 |
I haven't stumbled upon problems with -O0 yet, but I'm not using nvs for now. But I will watch out for that issue, and report it, if I will be able to reproduce it. |
Hi @eldendiss, thank you for reporting this issue! (I wasn't able to reproduce the issue based on the snippets in the issue description, unfortunately. I get the following compiled code after trying the code snippets in the issue description:
while in the ELF file you have attached it looks like this:
) |
Hi, yes I'm working on it right now |
Thank you very much @eldendiss, I was able to reproduce this. I found that your function is declared as returning This behavior of GCC was noted some time ago in esp8266/Arduino project, see esp8266/Arduino#8165. According to GCC manual, in C++ code omitting the return statement is undefined behavior:
GCC manual also notes:
So you would get a warning from GCC about this, if it was not for this line in your project CMakeLists.txt line:
which disables all the compiler warnings :( So the moral of this issue is to not disable the compiler warnings, since they can save quite some time debugging weird issues! Please note that this behavior is not unique to Xtensa architecture or to Espressif's cross-compiler toolchain. Here is an example of the same thing happening with GCC for ARM: https://godbolt.org/z/j5fvx9n1a |
Yes, sorry I totally missed that :) I also missed -w compiler flag was set. Mb, but maybe it will help someone with similar issue in the future. Anyway thank you again for your help. |
This is a good suggestion. I agree we should add I'll keep the issue open to track this. |
Okay, I should have read more attentively.
ESP-IDF already compiles all the code with The issue in this case was that |
Yes sure, it is indeed an user error. I just disabled warnings globally because when I was debugging I had full log of missing initializer warnings. Maybe just a suggestion, to add this somewhere in docs, so users should look for problems with their code in addition to HW problems (when I searched for IllegalInstruction it pointed me in the direction of HW problem with SPI, or PSU voltage drops). When I found out that HW is not the reason for crashing, I began to suspect an idf/compiler bug. Fixing it with disabled optimization made me just more sure of it being a bug. |
We have this section in the docs about troubleshooting IllegalInstruction exception, I will add a paragraph there to mention the situation you have encountered. |
In C++ code it is considered to be undefined behavior to exit a non-void function without returning a value. Normally this is detected by the compiler, but users could disable relevant warnings. Add a note about this possibility. See #8244 for context.
In C++ code it is considered to be undefined behavior to exit a non-void function without returning a value. Normally this is detected by the compiler, but users could disable relevant warnings. Add a note about this possibility. See espressif#8244 for context.
In C++ code it is considered to be undefined behavior to exit a non-void function without returning a value. Normally this is detected by the compiler, but users could disable relevant warnings. Add a note about this possibility. See espressif#8244 for context.
Environment
Problem Description
My application is calling function declared and defined in separate component. This should take care of i2c communication with GPIO expanders. However i always get some weird errors when calling two specific functions.
I tried:
Expected Behavior
Call the function and run the code obviously.
Actual Behavior
Calling function from main task results in Core panic Illegalnstruction with nothing insightful in register dump (last address executed is the address of called function - exception decoder points this to the line of code where function is defined. When i comment out everything in function, so it just returns without doing anything, i get LoadProhibited error, again with nothing insightful being reported by register dump - it reports last executed command as a class initializer, which is not even called in that function.
If I comment out that initializer, it again proceeds with error IllegalInstruction
Code to reproduce this issue
adc-api.h
adc-api.cpp
Debug Logs
Other items if possible
sdkconfig-elf-coredump.zip
The text was updated successfully, but these errors were encountered: