Browse Source

* changed last parameter of g_indirect_sym_load() to a set and also
pass on whether the symbol refers to code or data (important for
AIX weak symbols; note that AIX does not support undefined weak
external symbols, and FPC does not yet support weakly defining
non-external symbols, so this functionality isn't really used yet)

git-svn-id: trunk@20802 -

Jonas Maebe 13 years ago
parent
commit
260958eb45
2 changed files with 18 additions and 6 deletions
  1. 16 4
      compiler/cgobj.pas
  2. 2 2
      compiler/x86/cgx86.pas

+ 16 - 4
compiler/cgobj.pas

@@ -45,6 +45,8 @@ unit cgobj;
     type
     type
        talignment = (AM_NATURAL,AM_NONE,AM_2BYTE,AM_4BYTE,AM_8BYTE);
        talignment = (AM_NATURAL,AM_NONE,AM_2BYTE,AM_4BYTE,AM_8BYTE);
        tsubsetloadopt = (SL_REG,SL_REGNOSRCMASK,SL_SETZERO,SL_SETMAX);
        tsubsetloadopt = (SL_REG,SL_REGNOSRCMASK,SL_SETZERO,SL_SETMAX);
+       tindsymflag = (is_data,is_weak);
+       tindsymflags = set of tindsymflag;
 
 
        {# @abstract(Abstract code generator)
        {# @abstract(Abstract code generator)
           This class implements an abstract instruction generator. Some of
           This class implements an abstract instruction generator. Some of
@@ -513,7 +515,7 @@ unit cgobj;
           procedure g_intf_wrapper(list: TAsmList; procdef: tprocdef; const labelname: string; ioffset: longint);virtual;abstract;
           procedure g_intf_wrapper(list: TAsmList; procdef: tprocdef; const labelname: string; ioffset: longint);virtual;abstract;
           procedure g_adjust_self_value(list:TAsmList;procdef: tprocdef;ioffset: tcgint);virtual;
           procedure g_adjust_self_value(list:TAsmList;procdef: tprocdef;ioffset: tcgint);virtual;
 
 
-          function g_indirect_sym_load(list:TAsmList;const symname: string; weak: boolean): tregister;virtual;
+          function g_indirect_sym_load(list:TAsmList;const symname: string; const flags: tindsymflags): tregister;virtual;
           { generate a stub which only purpose is to pass control the given external method,
           { generate a stub which only purpose is to pass control the given external method,
           setting up any additional environment before doing so (if required).
           setting up any additional environment before doing so (if required).
 
 
@@ -626,6 +628,8 @@ unit cgobj;
        cg64 : tcg64;
        cg64 : tcg64;
 {$endif cpu64bitalu}
 {$endif cpu64bitalu}
 
 
+    function asmsym2indsymflags(sym: TAsmSymbol): tindsymflags;
+
     procedure destroy_codegen;
     procedure destroy_codegen;
 
 
 implementation
 implementation
@@ -4174,7 +4178,7 @@ implementation
       end;
       end;
 
 
 
 
-   function tcg.g_indirect_sym_load(list:TAsmList;const symname: string; weak: boolean): tregister;
+   function tcg.g_indirect_sym_load(list:TAsmList;const symname: string; const flags: tindsymflags): tregister;
       var
       var
         l: tasmsymbol;
         l: tasmsymbol;
         ref: treference;
         ref: treference;
@@ -4195,7 +4199,7 @@ implementation
                   new_section(current_asmdata.asmlists[al_picdata],sec_data_nonlazy,'',sizeof(pint));
                   new_section(current_asmdata.asmlists[al_picdata],sec_data_nonlazy,'',sizeof(pint));
                   l:=current_asmdata.DefineAsmSymbol(nlsymname,AB_LOCAL,AT_DATA);
                   l:=current_asmdata.DefineAsmSymbol(nlsymname,AB_LOCAL,AT_DATA);
                   current_asmdata.asmlists[al_picdata].concat(tai_symbol.create(l,0));
                   current_asmdata.asmlists[al_picdata].concat(tai_symbol.create(l,0));
-                  if not(weak) then
+                  if not(is_weak in flags) then
                     current_asmdata.asmlists[al_picdata].concat(tai_directive.Create(asd_indirect_symbol,current_asmdata.RefAsmSymbol(symname).Name))
                     current_asmdata.asmlists[al_picdata].concat(tai_directive.Create(asd_indirect_symbol,current_asmdata.RefAsmSymbol(symname).Name))
                   else
                   else
                     current_asmdata.asmlists[al_picdata].concat(tai_directive.Create(asd_indirect_symbol,current_asmdata.WeakRefAsmSymbol(symname).Name));
                     current_asmdata.asmlists[al_picdata].concat(tai_directive.Create(asd_indirect_symbol,current_asmdata.WeakRefAsmSymbol(symname).Name));
@@ -4210,8 +4214,8 @@ implementation
               { a_load_ref_reg will turn this into a pic-load if needed }
               { a_load_ref_reg will turn this into a pic-load if needed }
               a_load_ref_reg(list,OS_ADDR,OS_ADDR,ref,result);
               a_load_ref_reg(list,OS_ADDR,OS_ADDR,ref,result);
             end;
             end;
-          end;
         end;
         end;
+      end;
 
 
 
 
     procedure tcg.g_maybe_got_init(list: TAsmList);
     procedure tcg.g_maybe_got_init(list: TAsmList);
@@ -4390,6 +4394,14 @@ implementation
       end;
       end;
 {$endif cpu64bitalu}
 {$endif cpu64bitalu}
 
 
+    function asmsym2indsymflags(sym: TAsmSymbol): tindsymflags;
+      begin
+        result:=[];
+        if sym.typ<>AT_FUNCTION then
+          include(result,is_data);
+        if sym.bind=AB_WEAK_EXTERNAL then
+          include(result,is_weak);
+      end;
 
 
     procedure destroy_codegen;
     procedure destroy_codegen;
       begin
       begin

+ 2 - 2
compiler/x86/cgx86.pas

@@ -506,7 +506,7 @@ unit cgx86;
                   ((cs_create_pic in current_settings.moduleswitches) and
                   ((cs_create_pic in current_settings.moduleswitches) and
                    (ref.symbol.bind in [AB_COMMON,AB_GLOBAL,AB_PRIVATE_EXTERN])) then
                    (ref.symbol.bind in [AB_COMMON,AB_GLOBAL,AB_PRIVATE_EXTERN])) then
                  begin
                  begin
-                   hreg:=g_indirect_sym_load(list,ref.symbol.name,ref.symbol.bind=AB_WEAK_EXTERNAL);
+                   hreg:=g_indirect_sym_load(list,ref.symbol.name,asmsym2indsymflags(ref.symbol));
                    ref.symbol:=nil;
                    ref.symbol:=nil;
                  end
                  end
                else
                else
@@ -919,7 +919,7 @@ unit cgx86;
                             (ref.symbol.bind in [AB_COMMON,AB_GLOBAL,AB_PRIVATE_EXTERN])) then
                             (ref.symbol.bind in [AB_COMMON,AB_GLOBAL,AB_PRIVATE_EXTERN])) then
                           begin
                           begin
                              reference_reset_base(tmpref,
                              reference_reset_base(tmpref,
-                               g_indirect_sym_load(list,ref.symbol.name,ref.symbol.bind=AB_WEAK_EXTERNAL),
+                               g_indirect_sym_load(list,ref.symbol.name,asmsym2indsymflags(ref.symbol)),
                                offset,sizeof(pint));
                                offset,sizeof(pint));
                              a_loadaddr_ref_reg(list,tmpref,r);
                              a_loadaddr_ref_reg(list,tmpref,r);
                           end
                           end