Ticket #251 (Open)Tue Sep 21 22:25:38 UTC 2010
Enabling the -g switch causes cc (v. 5.65) to produce different code
Reported by: | Jeffrey Lee (213) | Severity: | Enhancement |
Part: | RISC OS: C/C++ toolchain | Release: | |
Milestone: | Status | Open |
Details by Jeffrey Lee (213):
Using the -g switch when compiling seemingly any C file causes CC to produce different code, even though the -g switch is only meant to result in the generation of debug metadata. For a simple example, try compiling the Dhrystone or CModule examples that are supplied with the C/C++ tools. First compile them with the default settings and make a copy of the binary. Then compile again, but this time with -g added to CCflags in the makefile. The resulting binaries will be different to the originals, even though the -d option wasn’t passed to the linker. Examination of the binaries suggests that using -g has a significant effect on the behaviour of the code generator.
For a more ‘real-world’ example, this problem was first observed when compiling the MUSBDriver module with the -g switch. I suspect a good test for whether the issue is fixed or not would be to compile one or more full ROM images with and without -g being specified in the base CC alias that gets set up in the Library.Tools.APCS-32 script.
Changelog:
Modified by Sprow (202) Sun, October 01 2017 - 21:18:11 GMT
In the Acorn C/C++ manual (page 102, in my PDF copy) it says
“Any function that is declared with inline at the top-level before (or in) its definition will be inlined when used subsequently in that translation unit. Inlining does not occur if the -g or -Ospace options have been selected.”
and similarly in the CC notes in the ChangeLogs directory for the DDE it says
“Scheduling is also disabled if debugging is enabled with -g.”
GCC’s online docs say
“Generate debugging information. This information is stored in the object file and copied from there to the final executable file by the linker, where it can be read by the debugger. You must use the -g switch if you plan on using the debugger.”
All of which make me think this isn’t a bug, simply that Acorn chose to do something different with their -g. Might it might be a useful enhancement to change to the rest of the world?
Modified by Jeffrey Lee (213) Sun, November 12 2017 - 21:41:39 GMT
- Severity changed from Normal to Enhancement
Yes, making the -g switch more orthogonal with other compilers would certainly be useful. And if that can’t be done, improving the documentation would be nice – looking at DDE 28, the Debug option information on page 24 of the manual (which is referred to from the -g switch entry on page 49) only talks about it adding debugging tables to the output, not that it affects other aspects of code generation. To have to search through the rest of the manual (and the changelogs) to find the full details isn’t ideal.
When I looked at the ASDTF spec a while ago, I noted that it’s only really designed for use with compilers where the ordering of lines in the source file corresponds to the ordering of instructions in the compiled output. So it wouldn’t surprise me if the side-effects that -g has on code generation are actually born out of the limitations of ASDTF.