C/C++
ldd : list library
LD_LIBRARY_PATH = "List all dynamic library"
https://scrapbox.io/files/66d0452060f13c001c823ab3.png
Static gives smaller docker
https://scrapbox.io/files/66d045c19faba4001cf23673.png
C
header in /usr/include like stdio.h
Header only have prototype of function
ldd Display linked libraries
code:minimal.c
int main(){
return 0;
}
Any program need to have a return int to give information on how the process terminated.
code:with_exit.c
int main() {
exit(0); // return error, but doesn't clean memory stack e.g
}
gcc -o test -DMONDEFINE=1 test.c
code:with_exit.c
int main(){
return MONDEFINE; // return error, but doesn't clean memory stack e.g
}
Some Assembly
code:some_asm.c
int geteax() {
__asm__("mov eax,42;");
}
int main(){
return geteax();
}
gcc -o out -masm=intel out.c
xxd > dump binary
clang vs gcc , different implementation, clang faster at compile time .
clan -m32 -g -o output input.c
32 bits , debug symbol
code:.sh
lldb
b main
r
s # step
p sizeof(i) # size of variable i
p &i # adress of i
p i # val of i
x/4b &i # Examine adress : 4 byte at i adress
0x00 0x04 0x00 0x00 << 1024 = 0x400
Initialisation of variable not guaranteeted to be Zeroed
When a process get created, we got some part of memory allocated.
little endian
C++
g++
-g : Ajoute info de debug
-Wall : Tous les warnings
Header
#include <stdio.h> -> #include <cstdio>
Retirer .h et ajouter c*
Namespace
using namespace std; Jamais car peut clash les noms de fonctions
io
cout /cin from iostream
fprinf(stdout, "Hello World!\n");
ou
std::cout << "Hello world!" << std::endl;