Hardening

This is an old revision of Hardening, edited by Dbannon at . The current revision is 144378.

This article applies to Linux only.

See also: Multiplatform Programming Guide

Hardening - PIE or PIC - applies to Linux may, or may not have some relevance to Windows.

Overview

For our purpose here, "hardening" means making your binary harder to hack while running. Key is PIE, Position Independent Executable. FPC supports PIE with a couple of options on most platforms. Some environments require it and it makes good sense, especially in a server application. Its suggested that PIE Hardening increases the size of an executable and slows it down marginally.

Most projects only require the following extra FPC command line switches -

-Cg -k-pie -znow

However, there are some corner cases -

Example

Following is an example test file -

program Test;
{$linklib c}
begin
  writeln('test');
end.

Compile with this -

fpc  -Cg  -k-pie  -k-znow  test.pas

And examine the result -

$> file test [enter]
test: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.4.0, stripped

See Also