1、流行的集成开发环境(IDE),比如Visual Studio等,一般是将编译和链接的过程一步完成,合并在一起的过程称为构建(build)。
2、GCC编译过程:预处理(Prepressing)、编译(Compilation)、汇编(Assembly)和链接(Linking)。
#chapter 3
gcc -c SimpleSection.c
#p62
objdump -h SimpleSection.o
#p64,p65
objdump -s -d SimpleSection.o
objdump -x -s -d SimpleSection.o
#p68
objcopy -I binary -O elf32-i386 -B i386image.jpg image.o
objdump -ht image.o
#p63
size SimpleSection.o
#p69, p84
readelf -h SimpleSection.o
readelf -s SimpleSection.o
#p82
nm SimpleSection.o
#chapter 4
#p101
ld a.o b.o -e main-o ab
#p107
objdump -r a.o
#p119
ar -t libc.a
#p120
gcc -c -fno-builtin hello.c
ar -x libc.a
ld hello.o printf.o
#p121
gcc -static --verbose-fno-builtin hello.c
#p125
gcc -c -fno-builtin TinyHelloWorld.c
ld -static -e nomain-o TinyHelloWorld TinyHelloWorld.o
#p126
./TinyHelloWorld
echo $?
#p128
gcc -c -fno-builtin TinyhelloWorld.c
ld -static -T TinyHelloWorld.lds -oTinyhelloWorld TinyHelloWorld.o
#p132
gcc -o target target.c -lbfd
./target
#chapter 5
#p135, p136
cl /c /ZaSimpleSection.c
dumpbin /AllSimpleSection.obj > SimpleSection.txt
dumpbin SimpleSection.obj /SUMMARY
#chapter 6
#p162
gcc -static Sectionmapping.c -oSectionMapping.elf
#p162, p163
readelf -S SectionMapping.elf
readelf -l SectionMapping.elf
#p166
./SectionMapping.elf &
cat /proc/21963/maps
#p168
./maxMalloc
#p173
./minbash
#chapter 7
#p185
gcc -fPIC-shared -o Lib.so Lib.c
gcc -o Program1 Program1.c ./Lib.so
gcc -o Program2 Program2.c ./Lib.so
#p187
./Program1
cat /proc/3334/maps
kill 3334
#p191
gcc -shared -fPIC -o pic pic.c
objdump -d pic.so
#p195
objdump -h pic.so
objdump -R pic.so
#p197
readelf -d foo.so | grepTEXTREL ::text relocation
#p197
gcc -shared -o module.so module.c
gcc -shared -fPIC -o module.so module.c
#p204
readelf -l Program1 | grep ???????
#p205,p206
readelf -d Lib.so
ldd Program1
#p207
readelf -sDLib.so
readelf -s Lib.so
#p208
readelf -r Lib.so
readelf -S Lib.so
#p213
gcc auxVec.c -o auxVec
./auxVec testAuxVec >auxVec.txt
#p216
gcc -fPIC -shared a1.c -o a1.so
gcc -fPIC -shared a2.c -o a2.so
gcc -fPIC -shared b1.c a1.so -o b1.so
gcc -fPIC -shared b2.c a2.so -o b2.so
#p217
gcc main.c b1.so b2.so -o main -Xlinker -rpath ./
./main &
cat /proc/18117/maps
kill 18117
#p219
/lib/ld-linux.so.2
#p221
ldd /lib/ld-linux.so.2
#p224
objdump -t
objdump -T
#p225-226
gcc -o RunSoSimple RunSoSimple.c -ldl
./RunSoSimple/lib/i386-linux-gnu/libm-2.19.so
readelf -s /lib/i386-linux-gnu/libm-2.19.so | grep sin
#p226
gcc RunSo.c -o RunSo -ldl
./RunSo /lib/i386-linux-gnu/libm-2.19.so sind2.0 d
gcc RunSo.c -o RunSo -ldl -gstabs
gdb -q RunSo
(gdb) disassemble _start
(gdb) disassemble main
(gdb) break main
(gdb) run 1 2 3
(gdb) disassembly main
(gdb) step
(gdb) next
(gdb) quit
Chapter 8
#p234
ls -l /lib/i386-linux-gnu/lib*
#p242
ldconfig -p
#p243
LD_LIBRARY_PATH=/home/user/bin/ls
/lib/ld-linux.so.2-library-path /home/user /bin/ls
#p244
LD_DEBUG=files ./HelloWorld.out
LD_DEBUG=help ./HelloWorld.out
(files,bindings,libs,versions,reloc,symbols,statistics,all,help)
#p245
gcc -shared (-fPIC) -Wl,-soname,my_soname-o library_name source_files library_files
gcc -shared -fPIC -Wl,-soname,libfoo.so.1 -olibfoo.so.1.0.0 libfoo1.c libfoo2.c-lbar1-lbar2
==>
gcc -c -g -Wall-o libfoo1.o libfoo1.c
gcc -c -g -Wall -o libfoo2.o libfoo2.c
ld -shared -soname libfoo.so.1 -o libfoo.so.1.0.0 libfoo1.olibfoo2.o-lbar1-lbar2
#p246
ld -rpath/home/mylib -export-dynamic -o program.outprogram.o -lsomelib
gcc -Wl,-rpath/home/mylib -Wl,-export-dynamic -o program.outprogram.o -lsomelib
#p246
strip libfoo.so
#p247
ldconfig -nshared_library_directory
Chapter 9
#p252
cl /LDd Math.c
#p253
dumpbin /EXPORTSMath.dll
cl /c TestMath.c
link TestMath.obj Math.lib
#p260
link math.obj /DLL/EXPORT:_Add
dumpbin /DIRECTIVESmath.obj
#p262
dumpbin /IMPORTSMath.dll
#p269
link /BASE:0x10010000,0x1000 /DlL bar.obj
editbin /REBASE:BASE=0x10020000 bar.dll
#p270
cl /c Math.c
link /DLL /DEF:Math.edfMath.obj
#p271
editbin /BINDTestMath.exe
dumpbin /IMPORTSTestMath.exe
Chapter 10
#p289
cl foo.c /Zi
dumpbin foo.exe /DISASM> foo.txt
cl foo.c /Zi /Od
dumpbin foo.exe /DISASM> foo.txt
本文:http://blog.csdn.net/rayluoluo4/article/details/39718663