View Issue Details

IDProjectCategoryView StatusLast Update
0036506FPCCompilerpublic2020-01-05 18:24
ReporterAlfred Assigned ToFlorian  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionno change required 
PlatformAny 
Product Version3.3.1 
Summary0036506: Linking failure when cross-building a library for Linux.
DescriptionAs already reported on the mailing list, cross-building a library fails during the linking stage due to the dynamic linker not found.

Looking at t_linux.pas, this code is the culprit:
  if (isdll) then
  begin
        Add('INPUT(');
        Add(sysrootpath+info.DynamicLinker); <----- gives file not found
        Add(')');
  end;
 
I have asked fpcupdeluxe users to test if the code below works for them:
  if FileExists(sysrootpath+info.DynamicLinker,false) then
    Add(sysrootpath+info.DynamicLinker)
  else
    Add(ExtractFileName(info.DynamicLinker));

With this code-change, linking succeeds and the binaries (libraries) still work on the target system
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget-
Attached Files

Activities

Alfred

2020-01-03 08:57

reporter  

fpcpatch_linux_linker.patch (623 bytes)   
Index: compiler/systems/t_linux.pas
===================================================================
--- compiler/systems/t_linux.pas	(revision 43706)
+++ compiler/systems/t_linux.pas	(working copy)
@@ -569,7 +569,10 @@
       if (isdll) then
        begin
          Add('INPUT(');
-         Add(sysrootpath+info.DynamicLinker);
+         if FileExists(sysrootpath+info.DynamicLinker,false) then
+           Add(sysrootpath+info.DynamicLinker)
+         else
+           Add(ExtractFileName(info.DynamicLinker));
          Add(')');
        end;
       linksToSharedLibFiles := not SharedLibFiles.Empty;
fpcpatch_linux_linker.patch (623 bytes)   
fpcpatch_linux_linker_fixes_3_2.patch (623 bytes)   
Index: compiler/systems/t_linux.pas
===================================================================
--- compiler/systems/t_linux.pas	(revision 43712)
+++ compiler/systems/t_linux.pas	(working copy)
@@ -550,7 +550,10 @@
       if (isdll) then
        begin
          Add('INPUT(');
-         Add(sysrootpath+info.DynamicLinker);
+         if FileExists(sysrootpath+info.DynamicLinker,false) then
+           Add(sysrootpath+info.DynamicLinker)
+         else
+           Add(ExtractFileName(info.DynamicLinker));
          Add(')');
        end;
       linksToSharedLibFiles := not SharedLibFiles.Empty;

Marco van de Voort

2020-01-03 09:57

manager   ~0120190

Last edited: 2020-01-03 09:57

View 3 revisions

Simply copy the dynamiclinker. To crosslink to linux, relevant libraries (dyn linker inclusive) must be present on the host system

I don't see the need to implement and support a possible fragile workaround for that.

Alfred

2020-01-03 10:27

reporter   ~0120192

Well.

info.DynamicLinker is hardcoded to something like /lib64/ld-linux-x86-64.so.2 when compiling for Linux x64.
This is an absolute path. And will not be found when cross-compiling from Windows towards Linux.
The trick used by many is to set the sysroot path towards the library directory, add a lib64 directory inside this library directory, and add the dynamic linker.

Setting this sysroot path resulted in non working binaries until recently fixed.

All other libraries are linked by using a relative path. So, why not this one ?

Florian

2020-01-03 11:49

administrator   ~0120195

> All other libraries are linked by using a relative path. So, why not this one ?

Experience shows that fiddeling with the dyn. linker is prone to break.

Setting a sysroot path with an existing dyn. linker is the only proper solution and not a trick.

Alfred

2020-01-03 12:36

reporter   ~0120196

The sole reason for this report were requests from fpcupdeluxe users that asked me to include the sysroot option to allow cross-buiding libs. As this resulted in non-working binaries (at that moment, issues are fixed meanwhile), I asked these users to try other methods, including the one proposed in this report. Users reported success with the proposed changes.

However, I will happily accept the fact that setting sysroot must be the way to go.
Bug-report can be closed.

Issue History

Date Modified Username Field Change
2020-01-03 08:57 Alfred New Issue
2020-01-03 08:57 Alfred File Added: fpcpatch_linux_linker.patch
2020-01-03 08:57 Alfred File Added: fpcpatch_linux_linker_fixes_3_2.patch
2020-01-03 09:57 Marco van de Voort Note Added: 0120190
2020-01-03 09:57 Marco van de Voort Note Edited: 0120190 View Revisions
2020-01-03 09:57 Marco van de Voort Note Edited: 0120190 View Revisions
2020-01-03 10:27 Alfred Note Added: 0120192
2020-01-03 11:49 Florian Note Added: 0120195
2020-01-03 12:36 Alfred Note Added: 0120196
2020-01-05 18:24 Florian Assigned To => Florian
2020-01-05 18:24 Florian Status new => resolved
2020-01-05 18:24 Florian Resolution open => no change required
2020-01-05 18:24 Florian FPCTarget => -