Ver código fonte

* split off sec_rodata_norel from sec_rodata, and only put constant data
without relocations in sec_rodata_norel. It should be possible to make
this new section read-only on all platforms, although currently it
is only done for darwin, and for non-pic code written using the
-Aas assembler writer.

Most platforms also have a special section for "constant but with
relocations" data, but such a section is currently only used for
Darwin (others still use plain .data sections for that, like they
did before)

git-svn-id: trunk@8650 -

Jonas Maebe 18 anos atrás
pai
commit
70c2414daa

+ 3 - 0
compiler/aasmbase.pas

@@ -60,7 +60,10 @@ interface
        TAsmSectiontype=(sec_none,
          sec_code,
          sec_data,
+         { read-only, but may contain relocations }
          sec_rodata,
+         { read-only and cannot contain relocations }
+         sec_rodata_norel,
          sec_bss,
          sec_threadvar,
          { used for wince exception handling }

+ 16 - 8
compiler/aggas.pas

@@ -253,12 +253,13 @@ implementation
 { not relocated properly on e.g. linux/ppc64. g++ generates there for a   }
 { vtable for a class called Window:                                       }
 { .section .data.rel.ro._ZTV6Window,"awG",@progbits,_ZTV6Window,comdat    }
-{$warning TODO .rodata not yet working}
+{$warning TODO .data.ro not yet working}
 {$if defined(arm) or defined(powerpc)}
           '.rodata',
 {$else arm}
           '.data',
 {$endif arm}
+          '.rodata',
           '.bss',
           '.threadvar',
           '.pdata',
@@ -277,6 +278,7 @@ implementation
           '.text',
           '.data.rel',
           '.data.rel',
+          '.data.rel',
           '.bss',
           '.threadvar',
           '.pdata',
@@ -600,12 +602,12 @@ implementation
              begin
                if (target_info.system in systems_darwin) then
                  begin
-                   {On Mac OS X you can't have common symbols in a shared
-                    library, since those are in the TEXT section and the text section is
-                    read-only in shared libraries (so it can be shared among different
-                    processes). The alternate code creates some kind of common symbols in
-                    the data segment. The generic code no longer uses common symbols, but
-                    this doesn't work on Mac OS X as well.}
+                   { On Mac OS X you can't have common symbols in a shared library
+                     since those are in the TEXT section and the text section is
+                     read-only in shared libraries (so it can be shared among different
+                     processes). The alternate code creates some kind of common symbols
+                     in the data segment.
+                   }
                    if tai_datablock(hp).is_global then
                      begin
                        asmwrite('.globl ');
@@ -733,7 +735,7 @@ implementation
                            { Values with symbols are written on a single line to improve
                              reading of the .s file (PFV) }
                            if assigned(tai_const(hp).sym) or
-                              not(CurrSecType in [sec_data,sec_rodata]) or
+                              not(CurrSecType in [sec_data,sec_rodata,sec_rodata_norel]) or
                               (l>line_length) or
                               (hp.next=nil) or
                               (tai(hp.next).typ<>ait_const) or
@@ -1116,6 +1118,11 @@ implementation
                  exit;
                end;
             sec_rodata:
+              begin
+                result := '.const_data';
+                exit;
+              end;
+            sec_rodata_norel:
               begin
                 result := '.const';
                 exit;
@@ -1142,6 +1149,7 @@ implementation
          sec_code,
          sec_data,
          sec_data (* sec_rodata *),
+         sec_data (* sec_rodata_norel *),
          sec_bss,
          sec_data (* sec_threadvar *),
          { used for wince exception handling }

+ 1 - 0
compiler/i386/ag386nsm.pas

@@ -458,6 +458,7 @@ interface
         secnames : array[TAsmSectiontype] of string[17] = ('',
           '.text',
           '.data',
+          '.data',
           '.rodata',
           '.bss',
           '.tbss',

+ 7 - 3
compiler/ncgcon.pas

@@ -167,7 +167,7 @@ implementation
                   current_asmdata.getdatalabel(lastlabel);
                   lab_real:=lastlabel;
                   maybe_new_object_file(current_asmdata.asmlists[al_typedconsts]);
-                  new_section(current_asmdata.asmlists[al_typedconsts],sec_rodata,lastlabel.name,const_align(resultdef.size));
+                  new_section(current_asmdata.asmlists[al_typedconsts],sec_rodata_norel,lastlabel.name,const_align(resultdef.size));
                   current_asmdata.asmlists[al_typedconsts].concat(Tai_label.Create(lastlabel));
                   case realait of
                     ait_real_32bit :
@@ -413,7 +413,11 @@ implementation
                    current_asmdata.getdatalabel(lastlabel);
                    lab_str:=lastlabel;
                    maybe_new_object_file(current_asmdata.asmlists[al_typedconsts]);
-                   new_section(current_asmdata.asmlists[al_typedconsts],sec_rodata,lastlabel.name,const_align(sizeof(aint)));
+                   if (len=0) or
+                      not(cst_type in [cst_ansistring,cst_widestring]) then
+                     new_section(current_asmdata.asmlists[al_typedconsts],sec_rodata_norel,lastlabel.name,const_align(sizeof(aint)))
+                   else
+                     new_section(current_asmdata.asmlists[al_typedconsts],sec_rodata,lastlabel.name,const_align(sizeof(aint)));
                    current_asmdata.asmlists[al_typedconsts].concat(Tai_label.Create(lastlabel));
                    { generate an ansi string ? }
                    case cst_type of
@@ -617,7 +621,7 @@ implementation
                  current_asmdata.getdatalabel(lastlabel);
                  lab_set:=lastlabel;
                  maybe_new_object_file(current_asmdata.asmlists[al_typedconsts]);
-                 new_section(current_asmdata.asmlists[al_typedconsts],sec_rodata,lastlabel.name,const_align(sizeof(aint)));
+                 new_section(current_asmdata.asmlists[al_typedconsts],sec_rodata_norel,lastlabel.name,const_align(sizeof(aint)));
                  current_asmdata.asmlists[al_typedconsts].concat(Tai_label.Create(lastlabel));
                  { already handled at the start of this method?? (JM)
                  if tsetdef(resultdef).settype=smallset then

+ 4 - 1
compiler/ogbase.pas

@@ -799,6 +799,7 @@ implementation
         secnames : array[TAsmSectiontype] of string[16] = ('',
           'code',
           'Data',
+          'Data',
           'roData',
           'bss',
           'threadvar',
@@ -838,8 +839,10 @@ implementation
         secoptions : array[TAsmSectiontype] of TObjSectionOptions = ([],
           {code} [oso_Data,oso_load,oso_readonly,oso_executable,oso_keep],
           {Data} [oso_Data,oso_load,oso_write,oso_keep],
-{$warning TODO Fix roData be read-only}
+{$warning TODO Fix sec_rodata be read-only-with-relocs}
           {roData} [oso_Data,oso_load,oso_write,oso_keep],
+{$warning TODO Fix sec_rodata_norel be read-only/constant}
+          {roData_norel} [oso_Data,oso_load,oso_write,oso_keep],
           {bss} [oso_load,oso_write,oso_keep],
           {threadvar} [oso_load,oso_write],
           {pdata} [oso_load,oso_readonly,oso_keep],

+ 1 - 1
compiler/ogcoff.pas

@@ -477,7 +477,7 @@ implementation
        StrsMaxGrow   = 8192;
 
        coffsecnames : array[TAsmSectiontype] of string[17] = ('',
-          '.text','.data','.data','.bss','.tls',
+          '.text','.data','.data','.data','.bss','.tls',
           '.text',
           '.pdata',
           '.stab','.stabstr',

+ 3 - 2
compiler/ogelf.pas

@@ -571,9 +571,9 @@ implementation
       const
         secnames : array[TAsmSectiontype] of string[13] = ('',
 {$ifdef userodata}
-          '.text','.data','.rodata','.bss','.threadvar',
+          '.text','.data','.data','.rodata','.bss','.threadvar',
 {$else userodata}
-          '.text','.data','.data','.bss','.threadvar',
+          '.text','.data','.data','.data','.bss','.threadvar',
 {$endif userodata}
           '.pdata',
           '.text', { darwin stubs }
@@ -590,6 +590,7 @@ implementation
           '.text',
           '.data.rel',
           '.data.rel',
+          '.data.rel',
           '.bss',
           '.threadvar',
           '.pdata',

+ 1 - 0
compiler/powerpc/agppcmpw.pas

@@ -72,6 +72,7 @@ interface
         'csect', {code}
         'csect', {data}
         'csect', {read only data}
+        'csect', {read only data - no relocations}
         'csect', {bss} 'csect', '',
         'csect','csect','csect','csect',
          '','','','','','','','','','','','','',''

+ 2 - 2
compiler/x86/agx86int.pas

@@ -60,7 +60,7 @@ implementation
       line_length = 70;
 
       secnames : array[TAsmSectiontype] of string[4] = ('',
-        'CODE','DATA','DATA','BSS','',
+        'CODE','DATA','DATA','DATA','BSS','',
         '','','','','','',
         '','','','',
         '',
@@ -72,7 +72,7 @@ implementation
       );
 
       secnamesml64 : array[TAsmSectiontype] of string[7] = ('',
-        '_TEXT','_DATE','_DATA','_BSS','',
+        '_TEXT','_DATE','_DATA','_DATA','_BSS','',
         '','','','',
         'idata$2','idata$4','idata$5','idata$6','idata$7','edata',
         '',