Преглед на файлове

+ Implemented resources for ELF

git-svn-id: trunk@956 -
michael преди 20 години
родител
ревизия
3392189fb0

+ 5 - 2
compiler/aasmbase.pas

@@ -57,7 +57,9 @@ interface
          { C++ exception handling unwinding (uses dwarf) }
          sec_eh_frame,
          { dwarf }
-         sec_debug_frame
+         sec_debug_frame,
+         { ELF resources }
+         sec_fpc
        );
 
        TAsmSectionOption = (aso_alloconly,aso_executable);
@@ -578,7 +580,8 @@ implementation
           'stab','stabstr',
           'idata2','idata4','idata5','idata6','idata7','edata',
           'eh_frame',
-          'debug_frame'
+          'debug_frame',
+          'fpc'
         );
       begin
         if aname<>'' then

+ 5 - 2
compiler/aggas.pas

@@ -287,7 +287,8 @@ var
           '.stab','.stabstr',
           '.idata$2','.idata$4','.idata$5','.idata$6','.idata$7','.edata',
           '.eh_frame',
-          '.debug_frame'
+          '.debug_frame',
+          'fpc.resptrs'
         );
       begin
         if use_smartlink_section and
@@ -320,7 +321,9 @@ var
               sec_code :
                 AsmWrite(',"x"');
             end;
-          end;
+          end
+        else if atype=sec_fpc then
+          AsmWrite(', "a", @progbits');
         AsmLn;
 {$ifdef GDB}
         { this is needed for line info in data }

+ 3 - 1
compiler/comprsrc.pas

@@ -166,12 +166,14 @@ var
 begin
   { OS/2 (EMX) must be processed elsewhere (in the linking/binding stage).
     same with MacOS}
-  if not (target_info.system in [system_i386_os2,system_i386_emx,system_powerpc_macos]) then
+  if not (target_info.system in [system_i386_os2,
+                                 system_i386_emx,system_powerpc_macos]) then
    While not current_module.ResourceFiles.Empty do
     begin
       case target_info.system of
         system_m68k_palmos,
         system_i386_win32,
+        system_i386_linux,
         system_i386_wdosx :
           hr:=new(presourcefile,init(current_module.ResourceFiles.getfirst));
         else

+ 2 - 1
compiler/i386/ag386nsm.pas

@@ -361,7 +361,8 @@ interface
           '.stab','.stabstr',
           '.idata2','.idata4','.idata5','.idata6','.idata7','.edata',
           '.eh_frame',
-          '.debug_frame'
+          '.debug_frame',
+          '.fpc'
         );
       begin
         AsmLn;

+ 2 - 1
compiler/ogcoff.pas

@@ -560,7 +560,8 @@ const go32v2stub : array[0..2047] of byte=(
           '.stab','.stabstr',
           '.idata$2','.idata$4','.idata$5','.idata$6','.idata$7','.edata',
           '.eh_frame',
-          '.debug_frame'
+          '.debug_frame',
+          '.fpc'
         );
       begin
         { No support for named sections, because section names are limited to 8 chars }

+ 8 - 1
compiler/ogelf.pas

@@ -253,6 +253,12 @@ implementation
               AshType:=SHT_STRTAB;
               AAlign:=1;
             end;
+          sec_fpc :
+            begin
+              AshFlags:=SHF_ALLOC;
+              AshType:=SHT_PROGBITS ;
+              AAlign:=4;// max(sizeof(aint),AAlign);
+            end;
         end;
         create_ext(Aname,Atype,Ashtype,Ashflags,0,0,Aalign,Aentsize);
       end;
@@ -343,7 +349,8 @@ implementation
           '.stab','.stabstr',
           '.idata$2','.idata$4','.idata$5','.idata$6','.idata$7','.edata',
           '.eh_frame',
-          '.debug_frame'
+          '.debug_frame',
+          'fpc.resptrs'
         );
       begin
         if use_smartlink_section and

+ 47 - 0
compiler/pmodules.pas

@@ -270,6 +270,50 @@ implementation
       end;
 {$endif}
 
+    Procedure InsertResourceInfo;
+    
+    var
+      hp           : tused_unit;
+      found        : Boolean;
+      I            : Integer;
+      ResourceInfo : taasmoutput;
+      
+    begin
+      if target_res.id=res_elf then
+        begin
+        hp:=tused_unit(usedunits.first);
+        found:=false;
+        While Assigned(hp) and not Found do
+          begin
+          Found:=((hp.u.flags and uf_has_resourcefiles)=uf_has_resourcefiles);
+          hp:=tused_unit(hp.next);
+          end;
+        ResourceInfo:=TAAsmOutput.Create;
+        if found then
+          begin
+{$ifdef EXTERNALRESPTRS}
+          current_module.linkotherofiles.add('resptrs.o',link_allways);
+{$else EXTERNALRESPTRS}
+          new_section(ResourceInfo,sec_fpc,'resptrs',4);
+          ResourceInfo.concat(Tai_symbol.Createname_global('FPC_RESSYMBOL',AT_DATA,0));
+          For I:=1 to 32 do 
+            ResourceInfo.Concat(Tai_const.Create_32bit(0));
+{$endif EXTERNALRESPTRS}
+          { Valid pointer to resource information }
+          ResourceInfo.concat(Tai_symbol.Createname_global('FPC_RESLOCATION',AT_DATA,0));
+          ResourceInfo.concat(Tai_const.Createname('FPC_RESSYMBOL',AT_DATA,0));
+          end
+        else
+          begin
+          { Nil pointer to resource information }
+          ResourceInfo.concat(Tai_symbol.Createname_global('FPC_RESLOCATION',AT_DATA,0));
+          ResourceInfo.Concat(Tai_const.Create_32bit(0));
+          end;
+        maybe_new_object_file(asmlist[al_data]);
+        asmlist[al_data].concatlist(ResourceInfo);
+        ResourceInfo.free;
+        end;
+    end;
 
     Procedure InsertResourceTablesTable;
       var
@@ -1593,6 +1637,9 @@ implementation
          insertResourceTablesTable;
          insertinitfinaltable;
          insertmemorysizes;
+         { Insert symbol to resource info }
+         
+         InsertResourceInfo;
 
          { create dwarf debuginfo }
          create_dwarf;

+ 4 - 2
compiler/ppu.pas

@@ -143,7 +143,7 @@ const
   uf_local_browser = $200;
   uf_no_link       = $400;    { unit has no .o generated, but can still have
                                 external linking! }
-  uf_has_resources = $800;    { unit has resource section }
+  uf_has_resources = $800;    { unit has resource string section }
   uf_little_endian = $1000;
   uf_release       = $2000;   { unit was compiled with -Ur option }
   uf_threadvars    = $4000;   { unit has threadvars }
@@ -151,7 +151,9 @@ const
   uf_has_debuginfo = $10000;  { this unit has debuginfo generated }
   uf_local_symtable = $20000; { this unit has a local symtable stored }
   uf_uses_variants  = $40000; { this unit uses variants }
-
+  uf_has_resourcefiles = $80000; { this unit has external resources (using $R directive)}
+  
+  
 type
   ppureal=extended;
 

+ 5 - 2
compiler/scandir.pas

@@ -33,7 +33,7 @@ implementation
     uses
       cutils,
       globtype,globals,systems,widestr,
-      verbose,comphook,
+      verbose,comphook,ppu,
       scanner,switches,
       fmodule,
       symtable,
@@ -846,11 +846,14 @@ implementation
             end;
         s:=AddExtension(FixFileName(s),target_info.resext);
         if target_info.res<>res_none then
+          begin
+          current_module.flags:=current_module.flags or uf_has_resourcefiles;
           if (target_info.res = res_emxbind) and
                                  not (Current_module.ResourceFiles.Empty) then
             Message(scan_w_only_one_resourcefile_supported)
           else
-            current_module.resourcefiles.insert(FixFileName(s))
+            current_module.resourcefiles.insert(FixFileName(s));
+          end 
         else
           Message(scan_e_resourcefiles_not_supported);
       end;

+ 1 - 1
compiler/systems.pas

@@ -152,7 +152,7 @@ interface
        tres = (res_none
             ,res_gnu_windres,res_emxbind
             ,res_m68k_palmos,res_m68k_mpw
-            ,res_powerpc_mpw
+            ,res_powerpc_mpw,res_elf
        );
 
        tscripttype = (script_none

+ 16 - 2
compiler/systems/i_linux.pas

@@ -25,8 +25,22 @@ unit i_linux;
 
     uses
        systems;
-
+       
     const
+       res_elf32_info : tresinfo =
+          (
+             id     : res_elf;
+             resbin : 'fpcres';
+             rescmd : '-o $OBJ -i $RES'
+          );
+          
+       res_elf64_info : tresinfo =
+          (
+             id     : res_elf;
+             resbin : 'fpcres';
+             rescmd : '-o $OBJ -i $RES'
+          );
+                                                              
        system_i386_linux_info : tsysteminfo =
           (
             system       : system_i386_LINUX;
@@ -64,7 +78,7 @@ unit i_linux;
             link         : nil;
             linkextern   : nil;
             ar           : ar_gnu_ar;
-            res          : res_none;
+            res          : res_elf;
             script       : script_unix;
             endian       : endian_little;
             alignment    :

+ 35 - 2
compiler/systems/t_linux.pas

@@ -27,7 +27,7 @@ unit t_linux;
 interface
 
   uses
-    symsym,symdef,
+    symsym,symdef,ppu,
     import,export,link;
 
   type
@@ -54,6 +54,7 @@ interface
       procedure SetDefaultInfo;override;
       function  MakeExecutable:boolean;override;
       function  MakeSharedLibrary:boolean;override;
+      function  postprocessexecutable(const fn : string;isdll:boolean):boolean;
     end;
 
 
@@ -591,7 +592,11 @@ begin
 { Remove ReponseFile }
   if (success) and not(cs_link_extern in aktglobalswitches) then
    RemoveFile(outputexedir+Info.ResName);
-
+   
+  if (success) then
+    success:=PostProcessExecutable(current_module.exefilename^,false);
+    
+ 
   MakeExecutable:=success;   { otherwise a recursive call to link method }
 end;
 
@@ -644,6 +649,32 @@ begin
   MakeSharedLibrary:=success;   { otherwise a recursive call to link method }
 end;
 
+function tlinkerLinux.postprocessexecutable(const fn : string;isdll:boolean):boolean;
+
+Var
+  cmdstr: string;
+  found : boolean;
+  hp    : tused_unit;
+
+begin
+  postprocessexecutable:=True;
+  if target_res.id=res_elf then
+    begin
+    hp:=tused_unit(usedunits.first);
+    found:=false;
+    While Assigned(hp) and not Found do
+      begin
+      Found:=((hp.u.flags and uf_has_resourcefiles)=uf_has_resourcefiles);
+      hp:=tused_unit(hp.next);
+      end;
+    if found then
+      begin  
+      cmdstr:=' -f -i '+maybequoted(fn);
+      postprocessexecutable:=DoExec(FindUtil(utilsprefix+'fpcres'),cmdstr,false,false);
+      end;
+    end;  
+end;
+
 
 {*****************************************************************************
                                   Initialize
@@ -655,6 +686,7 @@ initialization
   RegisterImport(system_i386_linux,timportliblinux);
   RegisterExport(system_i386_linux,texportliblinux);
   RegisterTarget(system_i386_linux_info);
+  RegisterRes(res_elf32_info);
 
   RegisterExternalLinker(system_x86_6432_linux_info,TLinkerLinux);
   RegisterImport(system_x86_6432_linux,timportliblinux);
@@ -684,6 +716,7 @@ initialization
   RegisterImport(system_x86_64_linux,timportliblinux);
   RegisterExport(system_x86_64_linux,texportliblinux);
   RegisterTarget(system_x86_64_linux_info);
+  RegisterRes(res_elf64_info);
 {$endif x86_64}
 {$ifdef SPARC}
   RegisterExternalLinker(system_sparc_linux_info,TLinkerLinux);

+ 2 - 2
compiler/x86/agx86int.pas

@@ -61,14 +61,14 @@ implementation
       secnames : array[TAsmSectionType] of string[4] = ('',
         'CODE','DATA','DATA','BSS','',
         '','','','','','',
-        '','','','','',''
+        '','','','','','',''
       );
 
       secnamesml64 : array[TAsmSectionType] of string[7] = ('',
         '_TEXT','_DATE','_DATA','_BSS','',
         '','','','',
         'idata$2','idata$4','idata$5','idata$6','idata$7','edata',
-        '',''
+        '','',''
       );
 
     function single2str(d : single) : string;