* 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 -
This commit is contained in:
sergei 2012-11-18 17:40:17 +00:00
parent 5ee506d64e
commit 0369a30f49
3 changed files with 27 additions and 8 deletions

View File

@ -971,10 +971,12 @@ implementation
{user} [oso_Data,oso_load,oso_write,oso_keep], {user} [oso_Data,oso_load,oso_write,oso_keep],
{code} [oso_Data,oso_load,oso_executable,oso_keep], {code} [oso_Data,oso_load,oso_executable,oso_keep],
{Data} [oso_Data,oso_load,oso_write,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], {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_keep],
{roData_norel} [oso_Data,oso_load,oso_write,oso_keep],
{bss} [oso_load,oso_write,oso_keep], {bss} [oso_load,oso_write,oso_keep],
{threadvar} [oso_load,oso_write {threadvar} [oso_load,oso_write
{$ifdef FPC_USE_TLS_DIRECTORY} {$ifdef FPC_USE_TLS_DIRECTORY}

View File

@ -121,6 +121,7 @@ interface
constructor createcoff(const n:string;awin32:boolean;acObjSection:TObjSectionClass); constructor createcoff(const n:string;awin32:boolean;acObjSection:TObjSectionClass);
procedure CreateDebugSections;override; procedure CreateDebugSections;override;
function sectionname(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder):string;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; procedure writereloc(data:aint;len:aword;p:TObjSymbol;reloctype:TObjRelocationType);override;
end; end;
@ -481,7 +482,7 @@ implementation
StrsMaxGrow = 8192; StrsMaxGrow = 8192;
coffsecnames : array[TAsmSectiontype] of string[length('__DATA, __datacoal_nt,coalesced')] = ('','', coffsecnames : array[TAsmSectiontype] of string[length('__DATA, __datacoal_nt,coalesced')] = ('','',
'.text','.data','.data','.data','.bss','.tls', '.text','.data','.rdata','.rdata','.bss','.tls',
'.pdata',{pdata} '.pdata',{pdata}
'.text', {stub} '.text', {stub}
'.data', '.data',
@ -1001,6 +1002,11 @@ const pemagic : array[0..3] of byte = (
result:=aname result:=aname
else else
begin 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]; secname:=coffsecnames[atype];
if create_smartlink_sections and if create_smartlink_sections and
(aname<>'') then (aname<>'') then
@ -1021,6 +1027,20 @@ const pemagic : array[0..3] of byte = (
end; 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; procedure TCoffObjData.CreateDebugSections;
begin begin
if target_dbg.id=dbg_stabs then if target_dbg.id=dbg_stabs then

View File

@ -961,11 +961,8 @@ implementation
function TElfObjData.sectionname(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder):string; function TElfObjData.sectionname(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder):string;
const const
secnames : array[TAsmSectiontype] of string[length('__DATA, __datacoal_nt,coalesced')] = ('','', secnames : array[TAsmSectiontype] of string[length('__DATA, __datacoal_nt,coalesced')] = ('','',
{$ifdef userodata} { TODO: sec_rodata is still writable }
'.text','.data','.data','.rodata','.bss','.threadvar', '.text','.data','.data','.rodata','.bss','.threadvar',
{$else userodata}
'.text','.data','.data','.data','.bss','.threadvar',
{$endif userodata}
'.pdata', '.pdata',
'.text', { darwin stubs } '.text', { darwin stubs }
'__DATA,__nl_symbol_ptr', '__DATA,__nl_symbol_ptr',