- cat
- rm
- wget
- xz
- cpio
- bash
- awk
NOTE: Always double-check every single command, do not copy-paste them. However, the listed commands below might work perfectly on you system (which was the intention), but we cannot guarantee all commands match with your system.
- Create an empty folder, and cd into it
Code: Select all
$ mkdir threos $ cd threos
- Download the script from http://threos.io/files/sdk_dl.sh
(note: we added the -O sdk_dl.sh to the wget, this is done to overwrite the previous script instead of making new files every time)Code: Select all
$ wget http://threos.io/files/sdk_dl.sh -O sdk_dl.sh
- If you want, you can adjust the variables at the beginning of the shell script. In case you do not modify anything, the script will make a new directory named prefix, and downloads/extracts data into it.
The default script will download packages belong to the x86_64 architecture.
WARNING! The script will remove that directory. - After check the content of the downloaded script, add executable right:
Code: Select all
$ chmod +x sdk_dl.sh
- Execute the script (this will take a while):
Code: Select all
$ ./sdk_dl.sh
- Missing packages will be printed to the standard output, and the script exits with non-zero exit code.
- cd prefix
- export MYROOT=$PWD
- cd usr/src/examples
- compile with your native gcc
Command line to build a statically linked version:
Code: Select all
$ gcc -ffreestanding -nostdlib --no-builtin -m64 -mcmodel=large -fno-stack-protector -static-libgcc -Wl,-q,-x -I$MYROOT/usr/include -L$MYROOT/usr/lib -L$MYROOT/lib -fPIE $MYROOT/usr/lib/Scrt1.o hello1.c -lc -ldevlib -lkrnlext
Explanation:Code: Select all
$ gcc -ffreestanding -nostdlib --no-builtin -m64 -mcmodel=large -fno-stack-protector -static-libgcc -Wl,-q,-x -I$MYROOT/usr/include -L$MYROOT/usr/lib -L$MYROOT/lib -static $MYROOT/usr/lib/crt0.o hello1.c -lc -ldevlib -lkrnlext
- Compile to bare machine: -ffreestanding -nostdlib --no-builtin
- Use the large memory model (selecting the proper memory model really matters in statically linked programs, PIEs are good as are): -m64 -mcmodel=large
- Disable the stack protector, it links against symbols in the glibc: -fno-stack-protector
- Link libgcc statically (this is mandatory even for PIEs), otherwise the program will be linked to the libraries installed with your gcc (which ABI does not match): -static-libgcc
- Ask the linker to keep some info for us (really matters for statically linked programs): -Wl,-q,-x
- Statically programs that will be loaded with devman shall include -Wl,-N
- Build the target environment (include and library search directories): -I$MYROOT/usr/include -L$MYROOT/usr/lib -L$MYROOT/lib
- Specify output executable mode: -fPIE (NOTE: statically linked programs shall use -static)
- Select the CRT to use: $MYROOT/usr/lib/Scrt1.o (NOTE: statically linked programs shall use $MYROOT/usr/lib/crt0.o)
- Specify sources/objects: hello1.c (in our case)
- Specify libraries to link with: -lc -ldevlib -lkrnlext (there are probably always mandatory, additional libraries may be required)
Code: Select all
LIBS = -lc -ldevlib -lkrnlext
CFLAGS_DYNAMIC = -ffreestanding -nostdlib --no-builtin -m64 -mcmodel=large -fno-stack-protector -I$MYROOT/usr/include -fPIC
LDFLAGS_DYNAMIC = -ffreestanding -nostdlib --no-builtin -m64 -static-libgcc -fPIE $MYROOT/usr/lib/Scrt1.o -L$MYROOT/usr/lib -L$MYROOT/lib -Wl,-q,-x
CFLAGS_STATIC = -ffreestanding -nostdlib --no-builtin -m64 -mcmodel=large -fno-stack-protector -I$MYROOT/usr/include -static
LDFLAGS_STATIC = -ffreestanding -nostdlib --no-builtin -m64 -static-libgcc -static $MYROOT/usr/lib/crt0.o -L$MYROOT/usr/lib -L$MYROOT/lib -Wl,-q,-x,-N