Browse Source

* initialize linklibc earlier (in InitSysInitUnitName); this is necessary,
because the sysinit unit name depends on whether libc is linked or not.
Helper function ModulesLinkToLibc copied from t_linux.pas

git-svn-id: trunk@41698 -

nickysn 6 years ago
parent
commit
525eff2927
1 changed files with 29 additions and 5 deletions
  1. 29 5
      compiler/systems/t_bsd.pas

+ 29 - 5
compiler/systems/t_bsd.pas

@@ -76,6 +76,27 @@ implementation
     end;
     end;
 
 
 
 
+function ModulesLinkToLibc:boolean;
+var
+  hp: tmodule;
+begin
+  { This is called very early, ImportLibraryList is not yet merged into linkothersharedlibs.
+    The former contains library names qualified with prefix and suffix (coming from
+    "external 'c' name 'foo' declarations), the latter contains raw names (from "$linklib c"
+    directives). }
+  hp:=tmodule(loaded_units.first);
+  while assigned(hp) do
+    begin
+      result:=Assigned(hp.ImportLibraryList.find(target_info.sharedClibprefix+'c'+target_info.sharedClibext));
+      if result then break;
+      result:=hp.linkothersharedlibs.find(target_info.sharedClibprefix+'c'+target_info.sharedClibext);
+      if result then break;
+      result:=hp.linkothersharedlibs.find('c');
+      if result then break;
+      hp:=tmodule(hp.next);
+    end;
+end;
+
 
 
 {*****************************************************************************
 {*****************************************************************************
                              TIMPORTLIBDARWIN
                              TIMPORTLIBDARWIN
@@ -235,9 +256,15 @@ End;
 procedure TLinkerBSD.InitSysInitUnitName;
 procedure TLinkerBSD.InitSysInitUnitName;
 begin
 begin
   if target_info.system in systems_darwin then
   if target_info.system in systems_darwin then
-    SysInitUnit:='sysinit'
+    begin
+      { for darwin: always link dynamically against libc }
+      linklibc := true;
+      SysInitUnit:='sysinit';
+    end
   else
   else
-    inherited InitSysInitUnitName;
+    begin
+      linklibc:=ModulesLinkToLibc;
+    end;
 end;
 end;
 
 
 
 
@@ -425,7 +452,6 @@ begin
           gprtobj:='gprt0';
           gprtobj:='gprt0';
         end;
         end;
       linkdynamic:=not(SharedLibFiles.empty);
       linkdynamic:=not(SharedLibFiles.empty);
-      linklibc:=(SharedLibFiles.Find('c')<>nil);
       // this one is a bit complex.
       // this one is a bit complex.
       // Only reorder for now if -XL or -XO params are given
       // Only reorder for now if -XL or -XO params are given
       // or when -Xf.
       // or when -Xf.
@@ -450,8 +476,6 @@ begin
     end
     end
   else
   else
     begin
     begin
-      { for darwin: always link dynamically against libc }
-      linklibc := true;
 {$ifdef MACOSX104ORHIGHER}
 {$ifdef MACOSX104ORHIGHER}
       { not sure what this is for, but gcc always links against it }
       { not sure what this is for, but gcc always links against it }
       if not(cs_profile in current_settings.moduleswitches) then
       if not(cs_profile in current_settings.moduleswitches) then