From 04bd105cf5d2446cf6953e424af99437327d2abc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A1roly=20Balogh?= Date: Tue, 28 Apr 2020 23:10:03 +0000 Subject: [PATCH] z80: fix global symbols and section attributes in the vasm writer git-svn-id: trunk@45163 - --- compiler/z80/agz80vasm.pas | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/compiler/z80/agz80vasm.pas b/compiler/z80/agz80vasm.pas index 8598337afa..1e2e749c50 100644 --- a/compiler/z80/agz80vasm.pas +++ b/compiler/z80/agz80vasm.pas @@ -44,6 +44,7 @@ unit agz80vasm; procedure WriteDecodedSleb128(a: int64); procedure WriteDecodedUleb128(a: qword); procedure WriteRealConstAsBytes(hp: tai_realconst; const dbdir: string; do_line: boolean); + function sectionattrs(atype:TAsmSectiontype):string; function sectionname(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder):string; procedure WriteSection(atype:TAsmSectiontype;const aname:string;aorder:TAsmSectionOrder;secalign:longint; secflags:TSectionFlags=[];secprogbits:TSectionProgbits=SPB_None); @@ -245,6 +246,21 @@ unit agz80vasm; writer.AsmLn; end; + function TZ80vasm.sectionattrs(atype:TAsmSectiontype):string; + begin + case atype of + sec_code, sec_fpc, sec_init, sec_fini: + result:='acrx'; + sec_data, sec_rodata, sec_rodata_norel, sec_bss, sec_threadvar: + result:='adrw'; + sec_stab, sec_stabstr: + result:='dr'; + else + result:=''; + end; + end; + + function TZ80vasm.sectionname(atype: TAsmSectiontype; const aname: string; aorder: TAsmSectionOrder): string; const @@ -352,6 +368,9 @@ unit agz80vasm; end; s:=sectionname(atype,aname,aorder); writer.AsmWrite(s); + s:=sectionattrs(atype); + if (s<>'') then + writer.AsmWrite(',"'+s+'"'); writer.AsmLn; LastSecType:=atype; end; @@ -646,16 +665,14 @@ unit agz80vasm; if not(tai_symbol(hp).has_value) then begin if tai_symbol(hp).is_global then - writer.AsmWriteLn(ApplyAsmSymbolRestrictions(tai_symbol(hp).sym.name) + ':') - else - writer.AsmWriteLn(ApplyAsmSymbolRestrictions(tai_symbol(hp).sym.name) + ':'); + writer.AsmWriteLn(#9'.globl '+ApplyAsmSymbolRestrictions(tai_symbol(hp).sym.name)); + writer.AsmWriteLn(ApplyAsmSymbolRestrictions(tai_symbol(hp).sym.name) + ':'); end else begin if tai_symbol(hp).is_global then - writer.AsmWriteLn(ApplyAsmSymbolRestrictions(tai_symbol(hp).sym.name) + '=' + tostr(tai_symbol(hp).value)) - else - writer.AsmWriteLn(ApplyAsmSymbolRestrictions(tai_symbol(hp).sym.name) + '=' + tostr(tai_symbol(hp).value)); + writer.AsmWriteLn(#9'.globl '+ApplyAsmSymbolRestrictions(tai_symbol(hp).sym.name)) + writer.AsmWriteLn(ApplyAsmSymbolRestrictions(tai_symbol(hp).sym.name) + '=' + tostr(tai_symbol(hp).value)); end; end; ait_symbol_end : @@ -664,9 +681,8 @@ unit agz80vasm; ait_datablock : begin if tai_datablock(hp).is_global or SmartAsm then - writer.AsmWriteLn(ApplyAsmSymbolRestrictions(tai_datablock(hp).sym.name) + ':') - else - writer.AsmWriteLn(ApplyAsmSymbolRestrictions(tai_datablock(hp).sym.name) + ':'); + writer.AsmWriteLn(#9'.globl '+ApplyAsmSymbolRestrictions(tai_datablock(hp).sym.name)); + writer.AsmWriteLn(ApplyAsmSymbolRestrictions(tai_datablock(hp).sym.name) + ':'); {if SmartAsm then AddSymbol(tai_datablock(hp).sym.name,true);} writer.AsmWriteLn(#9'.zero'#9+tostr(tai_datablock(hp).size));