Browse Source

* Also declare GOT in main program

git-svn-id: trunk@16103 -
pierre 15 years ago
parent
commit
f23695cf92
2 changed files with 37 additions and 17 deletions
  1. 30 15
      compiler/pmodules.pas
  2. 7 2
      compiler/x86/rax86.pas

+ 30 - 15
compiler/pmodules.pas

@@ -935,6 +935,31 @@ implementation
       end;
 
 
+
+    { Insert _GLOBAL_OFFSET_TABLE_ symbol if system uses it }
+
+    procedure maybe_load_got;
+{$ifdef i386}
+       var
+         gotvarsym : tstaticvarsym;
+{$endif i386}
+      begin
+{$ifdef i386}
+         if (cs_create_pic in current_settings.moduleswitches) and
+            (tf_pic_uses_got in target_info.flags) then
+           begin
+             { insert symbol for got access in assembler code}
+             gotvarsym:=tstaticvarsym.create('_GLOBAL_OFFSET_TABLE_',
+                          vs_value,voidpointertype,[vo_is_external]);
+             gotvarsym.set_mangledname('_GLOBAL_OFFSET_TABLE_');
+             current_module.localsymtable.insert(gotvarsym);
+             { avoid unnecessary warnings }
+             gotvarsym.varstate:=vs_read;
+             gotvarsym.refs:=1;
+           end;
+{$endif i386}
+      end;
+
     function gen_implicit_initfinal(flag:word;st:TSymtable):tcgprocinfo;
       begin
         { update module flags }
@@ -1049,9 +1074,6 @@ implementation
          finalize_procinfo : tcgprocinfo;
          unitname8 : string[8];
          ag: boolean;
-{$ifdef i386}
-         gotvarsym : tstaticvarsym;
-{$endif i386}
 {$ifdef debug_devirt}
          i: longint;
 {$endif debug_devirt}
@@ -1215,18 +1237,8 @@ implementation
          { create static symbol table }
          current_module.localsymtable:=tstaticsymtable.create(current_module.modulename^,current_module.moduleid);
 
-{$ifdef i386}
-         if cs_create_pic in current_settings.moduleswitches then
-           begin
-             { insert symbol for got access in assembler code}
-             gotvarsym:=tstaticvarsym.create('_GLOBAL_OFFSET_TABLE_',vs_value,voidpointertype,[vo_is_external]);
-             gotvarsym.set_mangledname('_GLOBAL_OFFSET_TABLE_');
-             current_module.localsymtable.insert(gotvarsym);
-             { avoid unnecessary warnings }
-             gotvarsym.varstate:=vs_read;
-             gotvarsym.refs:=1;
-           end;
-{$endif i386}
+         { Insert _GLOBAL_OFFSET_TABLE_ symbol if system uses it }
+         maybe_load_got;
 
          if not current_module.interface_only then
            begin
@@ -2160,6 +2172,9 @@ implementation
 
          symtablestack.push(current_module.localsymtable);
 
+         { Insert _GLOBAL_OFFSET_TABLE_ symbol if system uses it }
+         maybe_load_got;
+  
          { create whole program optimisation information }
          current_module.wpoinfo:=tunitwpoinfo.create;
 

+ 7 - 2
compiler/x86/rax86.pas

@@ -232,8 +232,13 @@ begin
          not assigned(opr.ref.relsymbol) and
          (opr.ref.refaddr<>addr_pic) then
         begin
-          message(asmr_e_need_pic_ref);
-          result:=false;
+          if (opr.ref.symbol.name <> '_GLOBAL_OFFSET_TABLE_') then
+            begin 
+              message(asmr_e_need_pic_ref);
+              result:=false;
+            end
+          else
+            opr.ref.refaddr:=addr_pic;
         end;
     end;
 end;