I hope I choosed a convenient subforum - if not, please let me know.
Versions: - Lazarus 2.0.6 with FPC 3.0.4 (on Linux installed by fpcupdeluxe with 32-bit cross-compile)
- OS: Linux Ubuntu 18.04 (64-bit) & Windows 7 (32-bit)
Problem1 + Question1:I saw that when I compile a program on Windows, that unused procedures and functions were excluded from the executable, while when compiling the same program on Linux, unused procs were
not excluded from the executable. To test this, I reduced my bigger program to this:
unit unit1;
{$mode objfpc}{$H+}
interface
procedure test1;
procedure test2;
implementation
procedure test1;
begin
writeln('This_is_a_test1');
end;
procedure test2;
begin
writeln('This_is_a_test2');
end;
end.
program demo1;
{$mode objfpc}{$H+}
uses unit1;
procedure test3;
begin
writeln('This_is_a_test3');
end;
begin
{$IFDEF CPU32}
writeln('32-bit');
{$ELSE}
writeln('64-bit');
{$ENDIF}
test1;
end.
For this test I used FPC directly
without Lazarus:
- on Windows => unused procs were excluded (only 32 bit tested)
- on Linux => unused procs were
not excluded (32-bit and 64-bit tested)
I tested this by searching the executable for "This_is_a_test". One match = "This_is_a_test1" means, unused procs were excluded. 3 matches = "This_is_a_test1" .. "This_is_a_test3" mean, they were not excluded.
After spending a lot of time I found out, that this is called "smartlinking" and that compiler options -CX and -XX are involved and that this part in fpc.cfg
#ifdef cpui8086
-CX
-XX
#endifon Windows obviously worked, while on Linux this did not work.
After adding -CX and -XX in fpc.cfg for Linux => unused procs were excluded (32-bit and 64-bit).
Problem1 is now solved by this, but I want to ask:
Question1: Why does "#ifdef cpui8086" work on Windows and not on Linux (on the same computer, with the same CPU)? Does anyone know a documentation about the definition of "cpui8086" (and the other possible conditionals) in fpc.cfg?
Problem2 + Question2:First I thought, my problem was solved. But when I compiled my program
via Lazarus, I saw:
- on Windows => unused procs were excluded (only 32 bit tested)
- on Linux (compile as 32-bit) => unused procs were excluded
- on Linux (compile as 64-bit) => unused procs were
not excluded
After spending again more time I found out, that Lazarus sets compiler options -g and -gl which mean:
-g = Generate debug information (default format for target)
-gl = Use line info unit (show more info with backtraces)
And when you compile a 32-bit program with -g and/or -gl => unused procs are excluded.
And when you compile a 64-bit program with -g and/or -gl => unused procs are
not excluded.
Question2:Why are unused procs not excluded with compiler options -g and/or -gl on 64-bit, while they are excluded on 32-bit? Is this "impossible"? What must I do, that unused procs are excluded with compiler options -g and/or -gl on 64-bit too? (I'm not familiar with the linker and still a beginner on Linux).
For me it is important, that if a program crashes, that I see as much debug infos as possible. Therefore I will never compile "release versions" with reduced debug infos. But I want to exclude all unused procs (on 32-bit and on 64-bit). Is that possible and how?
I attached my little demo program and the used fpc.cfg. Thanks a lot in advance for your help.