gcc
Cheatsheet
Most useful commands (especially for me:)
Create position independent code( -fPIC)
gcc -c -fPIC file.cUse compile line macros (-Dmacro)
gcc -DMACRO file.cConvert warnings to errors (-Werror)
gcc -Werror file.cGcc options through a file using @option usefull if you use many options. Example file:
-Werroe -Wallgcc file.c @file_contains_optionsStrip the content
gcc -s file.c -o fileAdd debugging information
gcc -g file.c -o fileGenerate Makefile
gcc -MM file.cSpecify architecture
gcc -m32 file.cWithout rbp register
gcc -fomit-frame-pointer file.cGet pretty assembly output
gcc file.c -S -masm=intel -fverbose-asm -o file.SGet compiling stages
Get pre-processed output from file.c -> file.i
gcc -E file.cCompilation from file.i -> file.s
gcc -S file.i -o file.SAssembly
gcc -c file.S -o file.oLinking
gcc file.o -o fileGet all intermediate files using (-save-temps)
gcc -save-temps file.cLinking with shared libraries (-l)
gcc file.c -o file -lCPPFILEProduce only compiled code
gcc -c file.cThis enables all the warnings about constructions that some users consider questionable. Compile every program with this flag.
gcc -Wall file.cInclude source code in asm output:
gcc test.c -o test -Wa,-adhln=test.s -g -fverbose-asm -masm=intelSpecial commands
Disable stack protection. Usefull when you learn buffer overflow.
gcc -fno-stack-protectionUse fpu registers. Usefull when you learn x87 FPU Coproccesor commands
gcc -mno-ssePrint (on standard error output) the commands executed to run the stages of compilation. Also print the version number of the compiler driver program and of the preprocessor and the compiler proper. Can get information about where include files was searched.
gcc -v file.cDon't produce a position independent executable. There is problem when compiling some programs.
gcc -no-pie file.cDebian switched to PIC/PIE binaries in 64-bits mode & GCC in your case is trying to link your object as PIC
For more details see https://stackoverflow.com/questions/48071280/nasm-symbol-printf-causes-overflow-in-r-x86-64-pc32-relocation
Do not search the standard system directories for header files. Only the directories explicitly specified with flags.
gcc -nostdincCreate simple static library http://www.yolinux.com/TUTORIALS/LibraryArchives-StaticAndDynamic.html
gcc -c hello.c -o hello.o
ar -cvq libhello.a hello.o
gcc -o res main.c libhello.aPrint the full absolute name of the library
gcc -print-file-name=libc.so
output: /usr/lib/gcc/x86_64-linux-gnu/7/../../../x86_64-linux-gnu/libc.soCompiler Level
https://gcc.gnu.org/onlinedocs/gcc/Developer-Options.html
dump AST info
gcc -fdump-tree-all hello.c最后更新于