Browse Source

+ Support library grouping in internal linker script, use it to load C libraries.

git-svn-id: trunk@22962 -
sergei 12 years ago
parent
commit
49501413e1
2 changed files with 29 additions and 4 deletions
  1. 27 3
      compiler/link.pas
  2. 2 1
      compiler/systems/t_linux.pas

+ 27 - 3
compiler/link.pas

@@ -99,6 +99,8 @@ interface
          FGroupStack : TFPObjectList;
          FGroupStack : TFPObjectList;
          procedure Load_ReadObject(const para:TCmdStr);
          procedure Load_ReadObject(const para:TCmdStr);
          procedure Load_ReadStaticLibrary(const para:TCmdStr);
          procedure Load_ReadStaticLibrary(const para:TCmdStr);
+         procedure Load_Group;
+         procedure Load_EndGroup;
          procedure ParseScript_Handle;
          procedure ParseScript_Handle;
          procedure ParseScript_PostCheck;
          procedure ParseScript_PostCheck;
          procedure ParseScript_Load;
          procedure ParseScript_Load;
@@ -1055,6 +1057,22 @@ Implementation
       end;
       end;
 
 
 
 
+    procedure TInternalLinker.Load_Group;
+      var
+        group: TStaticLibrary;
+      begin
+        group:=TStaticLibrary.create_group;
+        TFPObjectList(FGroupStack.Last).Add(group);
+        FGroupStack.Add(group.GroupMembers);
+      end;
+
+
+    procedure TInternalLinker.Load_EndGroup;
+      begin
+        FGroupStack.Delete(FGroupStack.Count-1);
+      end;
+
+
     procedure TInternalLinker.ParseScript_Handle;
     procedure TInternalLinker.ParseScript_Handle;
       var
       var
         s, para, keyword : String;
         s, para, keyword : String;
@@ -1093,7 +1111,9 @@ Implementation
                (keyword<>'EXESECTION') and
                (keyword<>'EXESECTION') and
                (keyword<>'ENDEXESECTION') and
                (keyword<>'ENDEXESECTION') and
                (keyword<>'OBJSECTION') and
                (keyword<>'OBJSECTION') and
-               (keyword<>'HEADER')
+               (keyword<>'HEADER') and
+               (keyword<>'GROUP') and
+               (keyword<>'ENDGROUP')
                then
                then
               Comment(V_Warning,'Unknown keyword "'+keyword+'" in "'+hp.str
               Comment(V_Warning,'Unknown keyword "'+keyword+'" in "'+hp.str
                 +'" internal linker script');
                 +'" internal linker script');
@@ -1179,6 +1199,10 @@ Implementation
               UseStabs:=true
               UseStabs:=true
             else if keyword='READSTATICLIBRARY' then
             else if keyword='READSTATICLIBRARY' then
               Load_ReadStaticLibrary(para)
               Load_ReadStaticLibrary(para)
+            else if keyword='GROUP' then
+              Load_Group
+            else if keyword='ENDGROUP' then
+              Load_EndGroup
             else
             else
               handled:=false;
               handled:=false;
             if handled then
             if handled then
@@ -1353,11 +1377,11 @@ Implementation
         Message1(exec_i_linking,outputname);
         Message1(exec_i_linking,outputname);
         FlushOutput;
         FlushOutput;
 
 
+        exeoutput:=CExeOutput.Create;
+
 { TODO: Load custom linker script}
 { TODO: Load custom linker script}
         DefaultLinkScript;
         DefaultLinkScript;
 
 
-        exeoutput:=CExeOutput.Create;
-
         if (cs_link_map in current_settings.globalswitches) then
         if (cs_link_map in current_settings.globalswitches) then
           exemap:=texemap.create(current_module.mapfilename);
           exemap:=texemap.create(current_module.mapfilename);
 
 

+ 2 - 1
compiler/systems/t_linux.pas

@@ -238,7 +238,6 @@ end;
 function ModulesLinkToLibc:boolean;
 function ModulesLinkToLibc:boolean;
 var
 var
   hp: tmodule;
   hp: tmodule;
-  i: tlinkcontaineritem;
 begin
 begin
   { This is called very early, ImportLibraryList is not yet merged into linkothersharedlibs.
   { This is called very early, ImportLibraryList is not yet merged into linkothersharedlibs.
     The former contains library names qualified with prefix and suffix (coming from
     The former contains library names qualified with prefix and suffix (coming from
@@ -1270,6 +1269,7 @@ begin
   if (cs_link_staticflag in current_settings.globalswitches) or
   if (cs_link_staticflag in current_settings.globalswitches) or
     (linklibc and not reorder) then
     (linklibc and not reorder) then
     begin
     begin
+      LinkScript.Concat('GROUP');
       if (cs_link_staticflag in current_settings.globalswitches) then
       if (cs_link_staticflag in current_settings.globalswitches) then
         begin
         begin
           AddLibraryStatement('gcc');
           AddLibraryStatement('gcc');
@@ -1277,6 +1277,7 @@ begin
         end;
         end;
       if linklibc and not reorder then
       if linklibc and not reorder then
         AddLibraryStatement('c');
         AddLibraryStatement('c');
+      LinkScript.Concat('ENDGROUP');
     end;
     end;
 
 
   { objects which must be at the end }
   { objects which must be at the end }