Sign in Join
Wiki copytemporary

hardening

Hardening - PIE or PIC - applies to Linux. PIE Hardening applies also to Windows, and its probably useful on Windows. The same FPC command line switches apply on 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 -

bash
-Cg -k-pie -znow

However, there are some corner cases -

Example

Following is an example test file -

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

Compile with this -

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

And examine the result -

bash
$> 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


From the Free Pascal wiki, page "hardening", as it stood on 2021-12-08 after a change by Alextp, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.

Revision 3, last changed by WikiArchive .

Talk about this page

Nobody has opened a bench for this page yet. Sign in to open one.