-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Why -g is included in the compilation sequence? #2998
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
Comments
I'm a bit confused. You say adding -g fixes a compilation issue, but also that -g is always included already. Those seem contradictory to me? Posting verbose compilation output, preferable for both the working and failing cases would be useful. Posting the failing sketch code (preferable with as much code as possible removed) would also be useful. |
Sorry, perhaps I should have been clearer. I am using the avr-gcc tools and utilities (like avrude, avr-gcc, etc.) to upload to an Arduino board without using the Java-based Arduino software. When I do this, I have never included -g, and it worked fine without -g, until I updated to version 1.6.3. Now, the compilation will "fail" when -g is omitted. Interestingly enough, it still produces the elf output. I noticed that the Arduino Java software includes the -g option always when compiling and I was wondering why this is, and if there is a reason that debugging is turned on for the compilation sequence. To reproduce the issue inside the Arduino Java software, open up Now, open up the Arduino Java software and try to compile just about any sketch (including a blank one as I have done so below), and it will fail due to a linker issue. The sketch I tried compiling below is as follows:
This is the output from the Arduino software
When I look at the linker output by passing --verbose as an option to the linker in the last elf compilation command, it turns out that for some reason the linker doesn't find certain .o files in libc.a. The linker output below is when I added --verbose to the linker options (via -Wl,--verbose).
Now, when I include -g when compiling, this is the verbose linker output
You will notice in the latter case, the linker finds the following files:
|
I think that this problem is related to/explained by #5539 Is that correct? Is the -g option used so all necessary information is included in the elf? |
Looking at the compiler output, this could very well be a compiler bug (given that the linker exits without any error message). @anonymouse64, is this problem still occuring for you with the most recent version? I think we might have upgraded the compiler version since then. As for the issue you link to, that might indeed solve this issue, if the compiler is somehow confused by having debugging symbols in the object files without -g being passed to the linker. As for why -g is passed in the first place, that allows using an (external) debugger, or disassembling the binary and dumping the related source code in between (though I've seen that LTO messes up the correctness of the debugging symbols in some places). |
The -g debub symbols also allows the compiler to show more meaningful error messages. Or at least they did in earlier compiler versions. That's the reason Arduino has always used -g while compiling. |
Yes, I have confirmed that it now works with the updated toolchain in Arduino 1.8.1. |
Hello,
I am wondering why the Arduino software always compiles with the -g (debugging in native output) option.
Background:
I am using the version of avr-gcc (and other tools) included in the Arduino software release, and before 1.6.3, I didn't have any problem compiling without -g, but now I get a linker returning 255 or 5 (or other random numbers sometimes) error. Including -g with Arduino 1.6.3 causes it to compile fine. When I switch to using 1.6.1 or 1.6.0 (I haven't tried 1.6.2), the issue doesn't appear. Strangely it seems as though including the -g option causes the linker to find files it should have found anyways. I can post more details (including verbose compilation output) if necessary. (I am using Windows 8.1 for reference)
I realize my specific issue is likely with avr-gcc and related tools itself, but it raised my curiosity as to why -g is always included when compiling on Arduino.
Thanks,
Ian
The text was updated successfully, but these errors were encountered: