Page 1 of 1

[x86_64] Compiling with gcc on Threos

Posted: Thu Apr 26, 2018 2:28 pm
by aron
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

Re: [x86_64] Compiling with gcc on Threos

Posted: Wed May 23, 2018 2:03 pm
by aron
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

Re: [x86_64] Compiling with gcc on Threos

Posted: Mon Mar 04, 2019 3:02 pm
by aron
The most recent gcc package (version 8.2.0-4) has much better default flags, so the common cases shall compile/link without any problem.