From 0369a30f491cd6233507aaa70d30ce0053463dfb Mon Sep 17 00:00:00 2001 From: sergei Date: Sun, 18 Nov 2012 17:40:17 +0000 Subject: [PATCH] * Internal linker: made sec_rodata_norel read-only. * For Win32 and Win64 targets made sec_rodata read-only, too (for these targets it doesn't matter if read-only section contains relocations). git-svn-id: trunk@23025 - --- compiler/ogbase.pas | 8 +++++--- compiler/ogcoff.pas | 22 +++++++++++++++++++++- compiler/ogelf.pas | 5 +---- 3 files changed, 27 insertions(+), 8 deletions(-) diff --git a/compiler/ogbase.pas b/compiler/ogbase.pas index 49c0972d8d..a56d5cbdeb 100644 --- a/compiler/ogbase.pas +++ b/compiler/ogbase.pas @@ -971,10 +971,12 @@ implementation {user} [oso_Data,oso_load,oso_write,oso_keep], {code} [oso_Data,oso_load,oso_executable,oso_keep], {Data} [oso_Data,oso_load,oso_write,oso_keep], -{ TODO: Fix sec_rodata be read-only-with-relocs} +{ Readonly data with relocations must be initially writable for some targets. + Moreover, e.g. for ELF it depends on whether the executable is linked statically or + dynamically. Here we declare it writable, target-specific descendants must provide + further handling. } {roData} [oso_Data,oso_load,oso_write,oso_keep], -{ TODO: Fix sec_rodata_norel be read-only/constant} - {roData_norel} [oso_Data,oso_load,oso_write,oso_keep], + {roData_norel} [oso_Data,oso_load,oso_keep], {bss} [oso_load,oso_write,oso_keep], {threadvar} [oso_load,oso_write {$ifdef FPC_USE_TLS_DIRECTORY} diff --git a/compiler/ogcoff.pas b/compiler/ogcoff.pas index 0f420c4b2b..450023b855 100644 --- a/compiler/ogcoff.pas +++ b/compiler/ogcoff.pas @@ -121,6 +121,7 @@ interface constructor createcoff(const n:string;awin32:boolean;acObjSection:TObjSectionClass); procedure CreateDebugSections;override; function sectionname(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder):string;override; + function sectiontype2options(atype:TAsmSectiontype):TObjSectionOptions;override; procedure writereloc(data:aint;len:aword;p:TObjSymbol;reloctype:TObjRelocationType);override; end; @@ -481,7 +482,7 @@ implementation StrsMaxGrow = 8192; coffsecnames : array[TAsmSectiontype] of string[length('__DATA, __datacoal_nt,coalesced')] = ('','', - '.text','.data','.data','.data','.bss','.tls', + '.text','.data','.rdata','.rdata','.bss','.tls', '.pdata',{pdata} '.text', {stub} '.data', @@ -1001,6 +1002,11 @@ const pemagic : array[0..3] of byte = ( result:=aname else begin + { non-PECOFF targets lack rodata support. + TODO: WinCE likely supports it, but needs testing. } + if (atype in [sec_rodata,sec_rodata_norel]) and + not (target_info.system in systems_windows) then + atype:=sec_data; secname:=coffsecnames[atype]; if create_smartlink_sections and (aname<>'') then @@ -1021,6 +1027,20 @@ const pemagic : array[0..3] of byte = ( end; + function TCoffObjData.sectiontype2options(aType:TAsmSectionType): TObjSectionOptions; + begin + if (aType in [sec_rodata,sec_rodata_norel]) then + begin + { TODO: WinCE needs testing } + if (target_info.system in systems_windows) then + aType:=sec_rodata_norel + else + aType:=sec_data; + end; + result:=inherited sectiontype2options(aType); + end; + + procedure TCoffObjData.CreateDebugSections; begin if target_dbg.id=dbg_stabs then diff --git a/compiler/ogelf.pas b/compiler/ogelf.pas index 45b6d3a8aa..be8a352abe 100644 --- a/compiler/ogelf.pas +++ b/compiler/ogelf.pas @@ -961,11 +961,8 @@ implementation function TElfObjData.sectionname(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder):string; const secnames : array[TAsmSectiontype] of string[length('__DATA, __datacoal_nt,coalesced')] = ('','', -{$ifdef userodata} + { TODO: sec_rodata is still writable } '.text','.data','.data','.rodata','.bss','.threadvar', -{$else userodata} - '.text','.data','.data','.data','.bss','.threadvar', -{$endif userodata} '.pdata', '.text', { darwin stubs } '__DATA,__nl_symbol_ptr',