Some gcc options have multiple representations.
For example, --warn-unused-macros can get the same result as -Wunused-macros.
But I checked the gcc website 3.8 Options to Request or Suppress Warnings.
There is only a description of -Wunused-macros.
How does gcc lead the two options to the same result?
Thank you !!!
For example, --warn-unused-macros can get the same result as -Wunused-macros.
Mmh, indeed it appears to be an undocumented alternative way to specify -W... parameters (it is not even reported by gcc --help=warnings). However I only did a quick search, so it may be documented somewhere (maybe someone else may point to the documentation if they found it).
Also, if I execute gcc --warn-long-long2, GCC will correctly tell me that I may have misspelled the --warn-long-long option (a.k.a. -Wlong-long). So, suggestions correctly work for this alternate naming.
How does gcc lead the two options to the same result?
The two options lead to the same result simply because GCC treats them as the same option with different names. Many softwares have several names for the same option. I'm not sure what your doubt/question is about this.
Do you want to know specifically how GCC parse command line options internally?
Related
One pass run by the compiler when optimising in gcc is falign-loops.
Although a vague description is provided here: https://www.intel.com/content/www/us/en/develop/documentation/cpp-compiler-developer-guide-and-reference/top/compiler-reference/compiler-options/compiler-option-details/data-options/falign-loops-qalign-loops.html
It is listed as one of the optimisations occurring with the -O2 flag here:
https://gcc.gnu.org/onlinedocs/gcc/Optimize-Options.html
I have been unable to actually see it work in action with any piece of code I have tried using compiler explorer. Does anyone know how the flag functions and perhaps have some explicit examples?
Thanks
I recently got my hands dirty with assembly and c code and found the gcc option -Xassembler -Xpreprocessor. i searched online for simple examples and the values these gcc options take, but couldn't find.
help appreciated.
thank you
-Xassembler: It passes an option to the assembler as a compilation option, such as specific options regarding architecture (which most probably GCC couldn't recognize). It is similar to -Wa (however the way to pass arguments change). For the completeness sake, I am used to see -Wa instead of -Xassembler, I guess backward compatibility explains why there are two similar options.
An example for -Xassembler (ARM arch): -Xassembler -mthumb to assemble for Thumb architectures (or -Wa,-mthumb).
-Xpreprocessor: It passes an option to the preprocessor, as before, it is useful to pass options that GCC doesn't recognize. It is similar to -Wp (and the way to pass arguments change).
An example for -Xpreprocessor: -Xpreprocessor -M (or -Wp,-M) in order to
output a rule suitable for make describing the dependencies of the main source file
I am looking for a way to get a list of all the function and variable names for a set of c source files. I know that gcc breaks down those elements when compiling and linking so is there a way to piggyback that process? Or any other tool that could do the same thing?
EDIT: It's mostly because I am curious, I have been playing with things like make auto dependency and graphing include trees and would like to be able to get more stats on the source files. And it seems like something that would already exist but i haven't found any options or flags for it.
If you are only interested by names of global functions and variables, you might (assuming you are on Linux) use the nm or objdump utilities on the ELF binary executable or object files.
Otherwise, you might customize the GCC compiler (assuming you have a recent version, e.g. 5.3 or 6 at least) thru plugins. You could code them directly in C++, or you might consider using GCC MELT, a Lisp-like domain specific language to customize GCC. Perhaps even the findgimple mode of GCC MELT might be enough....
If you consider extending GCC, be aware that you'll need to spend a significant time (perhaps months) understanding its internal representations (notably Generic Trees & Gimple) in details. The links and slides on GCC MELT documentation page might be useful.
Your main issue is that you probably need to understand most of the details about GCC internal representations, and that takes time!
Also, the details of GCC internals are slightly changing from one version of GCC to the next one.
You could also consider (instead of working inside GCC) using the Clang/LLVM framework (but learning that is also a lot of time). Maybe you might also look into Frama-C or Coccinnelle.
Another approach might be to compile with debug info and parse DWARF information.
PS. My point is that your problem is probably much more difficult than what you believe. Parsing C is not that simple ... You might spend months or even years working on that... And details could be target-processor & system & compiler specific...
I just started building some code with the intel c compiler -- icc. Our configure script likes to add the -ffast-math flag and maybe a couple others which seem to be GCC specific. Invoking icc with -ffast-math produces the following warning which I would like to silence:
icc: command line warning #10006: ignoring unknown option '-ffast-math'
As far as I see it, there are 2 ways it could be silenced (But I'd love to see other solutions). First, I could turn that warning into an error which would tell configure that -ffast-math isn't a valid option. I would hope that when configure tries to add that to the commandline, it would then see it isn't able to and decide that maybe adding it was a bad idea after all ... The second option (which I don't think is quite as clean) is to just tell icc to silence that kind of warning ...
Responding to the comments, here's the relevant portion of configure.ac:
# add -ffast-math etc if possible
AX_CHECK_COMPILER_FLAGS([-ffast-math],
[CFLAGS="$CFLAGS -ffast-math"
])
AX_CHECK_COMPILER_FLAGS([-mtune=native -march=native],
[CFLAGS="$CFLAGS -mtune=native -march=native"
])
That m4 macro appears to have been taken from here
I suppose that fixing that to be smarter would be the "holy-grail" -- But as icc returns a successful exit status even when -ffast-math is passed (or -mtune=native etc.), I don't really think that there is too much that can be done there (feel free to prove me wrong). that said, I don't want to hard-code checks for intel into the configure script.... That seems overly messy.
In reference to my earlier question here, I found out a possilbe bug in GCC 4.4.3 when it did not support following pragmas in the source code for optimization (although it says 4.4.x onwards it does!)
#pragma GCC optimize ("O3")
__attribute__((optimize("O3")))
Tried both above options but both gave compile time errors in the compiler itself(See the error message snapshot posted in the link mentioned above)
Now are there any further options for me to enable different optimization levels for different functions in my C code?
From the online docs:
Numbers are assumed to be an optimization level. Strings that begin with O are assumed to be an optimization option, while other options are assumed to be used with a -f prefix.
So, if you want the equivalent of the command line -O3 you should probably use the just the number 3 instead of "O3".
I agree that this is a bug and should not generate an ICE, consider reporting it along with a small test case to the GCC guys.
Now are there any further options for me to enable different optimization levels for different functions
in my C code?
Your remaining option is to place the functions in their own .c file and compile that .c file with the optimization flag you want.