[x86_64] Compiling with gcc on Threos

Forum for developers, compiling on Threos, etc.
Post Reply
aron
Posts: 79
Joined: Tue Dec 05, 2017 11:06 am

[x86_64] Compiling with gcc on Threos

Post by aron » Thu Apr 26, 2018 2:28 pm

Once you installed the gcc package, you will be able to compile C sources files with gcc:

Code: Select all

# pkman -Syu gcc
The following examples can be done in the /usr/src/examples directory (from the examples package).

To compile hello1.c into a PIE (Position-Independent Executable, uses GOT/PLT and dynamically links to the libc, and other libraries):

Code: Select all

$ gcc hello1.c
To compile a static executable (does not use dynamic libraries):

Code: Select all

$ gcc -mcmodel=large -static -fno-pie -fno-pic -Wl,-Nqx,--start-group,-ldevlib,-lkrnlext hello1.c

aron
Posts: 79
Joined: Tue Dec 05, 2017 11:06 am

Re: [x86_64] Compiling with gcc on Threos

Post by aron » Wed May 23, 2018 2:03 pm

Starting from gcc-4.7.2-7, the default mode is dynamically linked PIE (as it was before). However, the -static is a synonym to -static-pie (or -static -pie). Also, the -static switch includes the -ldevlib -lkrnlext flags.

In order to build a static non-PIE program, use -static -no-pie. For example:

Code: Select all

$ gcc -mcmodel=large -static -fno-pie -fno-pic -Wl,-Nqx hello1.c

Post Reply