Pārlūkot izejas kodu

* create stubs for library exports on Unix at at the node tree level instead
of using thlcg.g_external_wrapper() for high level targets, because that
way the creation of a new procdef for this stub and adding appropriate
entry/exit code can be handled using the standard compiler infrastructure
(fixes webtbs/tw8730* for LLVM)

git-svn-id: trunk@35088 -

Jonas Maebe 8 gadi atpakaļ
vecāks
revīzija
04f7e47df7
1 mainītis faili ar 41 papildinājumiem un 3 dzēšanām
  1. 41 3
      compiler/expunix.pas

+ 41 - 3
compiler/expunix.pas

@@ -58,11 +58,11 @@ uses
   globtype,globals,
   aasmdata,aasmtai,aasmcpu,
   fmodule,
+  {$ifdef cpuhighleveltarget}
+  symcreat,
+  {$endif}
   cgbase,cgutils,cpubase,cgobj,
   cgcpu,hlcgobj,hlcgcpu,
-{$ifdef llvm}
-  hlcgllvm,
-{$endif llvm}
   ncgutil,
   verbose;
 
@@ -89,6 +89,12 @@ end;
 procedure texportlibunix.exportprocedure(hp : texported_item);
 var
   hp2 : texported_item;
+{$ifdef cpuhighleveltarget}
+  pd,
+  wrapperpd: tprocdef;
+  i: longint;
+  anyhasalias: boolean;
+{$endif cpuhighleveltarget}
 begin
   { first test the index value }
   if eo_index in hp.options then
@@ -120,6 +126,36 @@ begin
     end
   else
     current_module._exports.concat(hp);
+{$ifdef cpuhighleveltarget}
+  { in case of a high level target create a stub procedure at the node/def
+    level instead of via hlcg.g_external_wrapper() later on, because it's
+    hard to manually create a fake procedure there (and it requires a def
+    anyway) }
+
+  { in case of eo_name there is no sym, and this routine is also called from
+    exportvar() so the sym doesn't have to be a procsym }
+  if assigned(hp.sym) and
+     (hp.sym.typ=procsym) then
+    begin
+      anyhasalias:=false;
+      { if the procedure has the exported name as one of its aliases, we don't
+        need a separate stub }
+      for i:=0 to tprocsym(hp.sym).procdeflist.count-1 do
+        begin
+          pd:=tprocdef(tprocsym(hp.sym).procdeflist[i]);
+          anyhasalias:=pd.has_alias_name(hp.name^);
+          if anyhasalias then
+            break;
+        end;
+      if not anyhasalias then
+        begin
+          { avoid name clashes for the identifier }
+          wrapperpd:=create_procdef_alias(pd,'$fpc_exported$'+hp.name^,hp.name^,
+            current_module.localsymtable,nil,
+            tsk_callthrough,pd);
+        end;
+    end;
+{$endif cpuhighleveltarget}
 end;
 
 
@@ -147,6 +183,7 @@ begin
         assigned(hp2.sym) and
         (hp2.sym.typ=procsym) then
       begin
+{$ifndef cpuhighleveltarget}
         { the manglednames can already be the same when the procedure
           is declared with cdecl }
         { note: for "exports" sections we only allow non overloaded procsyms,
@@ -161,6 +198,7 @@ begin
           end;
         if not anyhasalias then
           hlcg.g_external_wrapper(current_asmdata.asmlists[al_procedures],pd,hp2.name^,pd.mangledname,true);
+{$endif cpuhighleveltarget}
         exportedsymnames.insert(hp2.name^);
       end
      else