Hardening - PIE or PIC
Overview
For our purpose here, "hardening" means making your binary harder to hack with running. Key is PIE (add wikipedia link here), 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 -
- Lazarus application will probably already have the "-Cg" in its compile line.
- Small, command line applications that would generate a pure static linked binary will compile fine but not run. ("No such file or directory"). The difficulty is that FPC does not bother to imbed instructions about portable linking in such a binary because its appears unnecessary. The solution is to add "{$linklib c}" without the inverted commas to your source, by requesting LibC be linked, it forces a