aggas.pas: Make WriteSection method of TGNUAssembler class virtual.

ppcgen/agppcgas.pas: Override WriteSection method in TPPCAIXAssembler class
  to compute required alignment for base sections.

git-svn-id: trunk@36227 -
This commit is contained in:
pierre 2017-05-16 11:58:33 +00:00
parent de8c780fa7
commit f7c2ab2e7c
2 changed files with 72 additions and 4 deletions

View File

@ -49,7 +49,7 @@ interface
function sectionattrs(atype:TAsmSectiontype):string;virtual;
function sectionattrs_coff(atype:TAsmSectiontype):string;virtual;
function sectionalignment_aix(atype:TAsmSectiontype;secalign: byte):string;
procedure WriteSection(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder;secalign:byte);
procedure WriteSection(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder;secalign:byte);virtual;
procedure WriteExtraHeader;virtual;
procedure WriteExtraFooter;virtual;
procedure WriteInstruction(hp: tai);

View File

@ -54,9 +54,12 @@ unit agppcgas;
end;
TPPCAIXAssembler=class(TPPCGNUAssembler)
max_alignment : array[TAsmSectionType] of byte;
constructor CreateWithWriter(info: pasminfo; wr: TExternalAssemblerOutputFile; freewriter, smart: boolean); override;
protected
function sectionname(atype: TAsmSectiontype; const aname: string; aorder: TAsmSectionOrder): string; override;
procedure WriteSection(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder;secalign:byte); override;
procedure WriteAsmList; override;
procedure WriteExtraHeader; override;
procedure WriteExtraFooter; override;
procedure WriteDirectiveName(dir: TAsmDirective); override;
@ -467,11 +470,75 @@ unit agppcgas;
{****************************************************************************}
constructor TPPCAIXAssembler.CreateWithWriter(info: pasminfo; wr: TExternalAssemblerOutputFile; freewriter, smart: boolean);
var
cur_sectype : TAsmSectionType;
begin
inherited;
InstrWriter := TPPCInstrWriter.create(self);
{ Use 8-byte alignment as default for all sections }
for cur_sectype:=low(TAsmSectionType) to high(TAsmSectionType) do
max_alignment[cur_sectype]:=8;
end;
procedure TPPCAIXAssembler.WriteSection(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder;secalign:byte);
begin
secalign:=max_alignment[atype];
Inherited WriteSection(atype,aname,aorder,secalign);
end;
procedure TPPCAIXAssembler.WriteAsmList;
var
cur_sectype : TAsmSectionType;
cur_list : TAsmList;
hal : tasmlisttype;
hp : tai;
max_al : byte;
begin
{ Parse all asmlists to get maximum alignement used for all types }
for hal:=low(TasmlistType) to high(TasmlistType) do
begin
if not (current_asmdata.asmlists[hal].empty) then
begin
cur_sectype:=sec_none;
hp:=tai(current_asmdata.asmlists[hal].First);
while assigned(hp) do
begin
case hp.typ of
ait_align :
begin
if tai_align_abstract(hp).aligntype > max_alignment[cur_sectype] then
begin
max_alignment[cur_sectype]:=tai_align_abstract(hp).aligntype;
current_asmdata.asmlists[hal].InsertAfter(tai_comment.Create(strpnew('Alignment put to '+tostr(tai_align_abstract(hp).aligntype))),hp);
end;
end;
ait_section :
begin
cur_sectype:=tai_section(hp).sectype;
if tai_section(hp).secalign > max_alignment[cur_sectype] then
begin
max_alignment[cur_sectype]:=tai_section(hp).secalign;
current_asmdata.asmlists[hal].InsertAfter(tai_comment.Create(strpnew('Section '
+sectionname(tai_section(hp).sectype,'',secorder_default)+' alignment put to '+tostr(tai_section(hp).secalign))),hp);
end;
end;
end;
hp:=tai(hp.next);
end;
end;
end;
{ sec_data, sec_rodata and sec_bss all are converted into .data[RW],
in WriteSection below,
so we take the maximum alignment of the three }
max_al:=max_alignment[sec_data];
max_al:=max(max_al,max_alignment[sec_rodata]);
max_al:=max(max_al,max_alignment[sec_bss]);
max_alignment[sec_data]:=max_al;
max_alignment[sec_rodata]:=max_al;
max_alignment[sec_bss]:=max_al;
Inherited WriteAsmList;
end;
procedure TPPCAIXAssembler.WriteExtraHeader;
var
@ -485,13 +552,14 @@ unit agppcgas;
required for correct RTTI alignment.
AIX assembler seems to only care for the first
alignment value given }
writer.AsmWriteln(#9'.csect .data[RW],3');
writer.AsmWriteln(#9'.csect .data[RW],'+sectionalignment_aix(sec_data,max_alignment[sec_data]));
writer.AsmWriteln(#9'.csect _data.bss_[BS],'+sectionalignment_aix(sec_data,max_alignment[sec_data]));
{ .rodata is translated into .text[RO]
see sectionname in aggas unit. }
writer.AsmWriteln(#9'.csect .text[RO],3');
writer.AsmWriteln(#9'.csect .text[RO],'+sectionalignment_aix(sec_rodata_norel,max_alignment[sec_rodata_norel]));
{ make sure we always have a code and toc section,
the linker expects that }
writer.AsmWriteln(#9'.csect .text[PR]');
writer.AsmWriteln(#9'.csect .text[PR],'+sectionalignment_aix(sec_code,max_alignment[sec_code]));
{ set _text_s, to be used by footer below }
writer.AsmWriteln(#9'_text_s:');
writer.AsmWriteln(#9'.toc');