This page was last updated on March 13th, 2020(UTC) and it is currently May 30th, 2023(UTC).
That means this page is 3 years, 78 days, 4 hours, 37 minutes and 8 seconds old. Please keep that in mind.

24 - The GNU Compiler Collection GCC is the GNU Compiler Collection. There's alot that's likely to change over the years, so I'm only going to go over that which is absolutely important for most people. I recommend doing more modern research on your own as you get more and more experience. I'll also be covering some of it's backends here.

GCC, while it is actually intended for C, will automatically attempt to use extention (.c, .S, .cpp, .o, etc) and redirect it to the proper programs (gcc, as, g++/gpp, ld, etc). As of right now, the gold standard for C and C++ is, indeed, GCC, no matter how much Microsoft tries to say otherwise. Generally, when you "compile" code, it gets interpreted (and optimized) to assembly or some other intermediary format, then to an "object [.o]" then is sent to LD which then "links" the "objects" together into a final program. Some of these steps, however, can be skipped depending on how you're coding. The advantage of the overall approach is as follows: Assembly output can be further optimized by hand (instead of relying on the compiler to be smarter than the human); object files allow code to be recompiled and updated faster when it doesn't have to look at every single file; and you can actually let the compiler do alot of the work for you.

With GCC, you provide source files (and object files) as arguments and "-o" and then the next argument being a filename to specify what you want the output to be named as. If "-o" is not specified, it will be "a.[extension]" depending on what the output target is (in our case, this'll most likey be "a.exe" for the time being. A "capital o" will also be used for "optimization level." Higher numbers are "faster," but I would recommend restricting yourself to "-Os" and "-Ofast" because the numbers seem to vary per processor or fork. There are other optimization flags as well, but over time the list seems to be constantly growing and OS dependent, so I highly recommend finding a contemporary answer. There also seem to be situations where there are "protections" (like stack protections ["-fstack-protector"]) put in place for security reasons (well, to protect programmers from their own bad decisions), and those could present some slowdowns. I recommend, however, not to turn those off in any program that you release or have running public facing. The output files seem to be a little large, even with all optimization, so I would also suggest running strip as well on some files. As always, though, always look for more modern guides, and beware the uninformed answers.

A special feature of note is the -S flag. It will generate assembly as "[filename w/o extension].s" which, when renamed to "[filename w/o extension].S" will be compilable to a resulting binary. The usefulness of this means we can not only see how languages like C get interpreted, but it also allows us to optimize this by hand. Our main purpose, for now, will be to take advantage of it to study what the automated tools are doing.

Get your own web kitty here!
┬ęCopyright 2010-2023. All rights reserved.