diff --git a/compiler/dwarf.pas b/compiler/dwarf.pas index 0e0c2188c6..a57afe771d 100644 --- a/compiler/dwarf.pas +++ b/compiler/dwarf.pas @@ -80,6 +80,7 @@ interface public constructor create; procedure generate_code(list:taasmoutput); + procedure generate_initial_instructions(list:taasmoutput);virtual; { operations } procedure start_frame(list:taasmoutput); procedure end_frame(list:taasmoutput); @@ -247,9 +248,32 @@ implementation FFrameEndLabel:=nil; FLastLocLabel:=nil; code_alignment_factor:=1; - data_alignment_factor:=-1; + data_alignment_factor:=-4; end; +{$ifdef i386} + { if more cpu dependend stuff is implemented, this needs more refactoring } + procedure tdwarfcfi.generate_initial_instructions(list:taasmoutput); + begin + list.concat(tai_const.create_8bit(DW_CFA_def_cfa)); + list.concat(tai_const.create_uleb128bit(dwarf_reg(NR_STACK_POINTER_REG))); + list.concat(tai_const.create_uleb128bit(sizeof(aint))); + list.concat(tai_const.create_8bit(DW_CFA_offset_extended)); + list.concat(tai_const.create_uleb128bit(dwarf_reg(NR_RETURN_ADDRESS_REG))); + list.concat(tai_const.create_uleb128bit((-sizeof(aint)) div data_alignment_factor)); + end; +{$else i386} + { if more cpu dependend stuff is implemented, this needs more refactoring } + procedure tdwarfcfi.generate_initial_instructions(list:taasmoutput); + begin + list.concat(tai_const.create_8bit(DW_CFA_def_cfa)); + list.concat(tai_const.create_uleb128bit(dwarf_reg(NR_STACK_POINTER_REG))); + list.concat(tai_const.create_uleb128bit(sizeof(aint))); + list.concat(tai_const.create_8bit(DW_CFA_offset_extended)); + list.concat(tai_const.create_uleb128bit(dwarf_reg(NR_RETURN_ADDRESS_REG))); + list.concat(tai_const.create_uleb128bit((-sizeof(aint)) div data_alignment_factor)); + end; +{$endif i386} procedure tdwarfcfi.generate_code(list:taasmoutput); var @@ -286,13 +310,8 @@ implementation def_cfa(stackpointer,sizeof(aint)) cfa_offset_extended(returnaddres,-sizeof(aint)) } -{$warning TODO This needs to be target dependent} - list.concat(tai_const.create_8bit(DW_CFA_def_cfa)); - list.concat(tai_const.create_uleb128bit(dwarf_reg(NR_STACK_POINTER_REG))); - list.concat(tai_const.create_uleb128bit(sizeof(aint))); - list.concat(tai_const.create_8bit(DW_CFA_offset_extended)); - list.concat(tai_const.create_uleb128bit(dwarf_reg(NR_RETURN_ADDRESS_REG))); - list.concat(tai_const.create_uleb128bit((-sizeof(aint)) div data_alignment_factor)); + generate_initial_instructions(list); + list.concat(cai_align.create_zeros(4)); list.concat(tai_label.create(lenendlabel)); lenstartlabel:=nil; diff --git a/compiler/systems/i_linux.pas b/compiler/systems/i_linux.pas index fdcb2d4432..cff8c67fb0 100644 --- a/compiler/systems/i_linux.pas +++ b/compiler/systems/i_linux.pas @@ -50,7 +50,8 @@ unit i_linux; {$ifdef segment_threadvars} tf_section_threadvars, {$endif segment_threadvars} - tf_needs_symbol_type,tf_files_case_sensitive,tf_use_function_relative_addresses]; + tf_needs_symbol_type,tf_files_case_sensitive,tf_use_function_relative_addresses, + tf_needs_dwarf_cfi]; cpu : cpu_i386; unit_env : 'LINUXUNITS'; extradefines : 'UNIX;HASUNIX'; diff --git a/compiler/systems/i_win.pas b/compiler/systems/i_win.pas index 6ab962b6b5..b83db2d736 100644 --- a/compiler/systems/i_win.pas +++ b/compiler/systems/i_win.pas @@ -33,7 +33,7 @@ unit i_win; name : 'Win32 for i386'; shortname : 'Win32'; flags : [tf_files_case_aware,tf_has_dllscanner,tf_use_function_relative_addresses - {,tf_smartlink_sections}{,tf_section_threadvars}]; + {,tf_smartlink_sections}{,tf_section_threadvars},tf_needs_dwarf_cfi]; cpu : cpu_i386; unit_env : 'WIN32UNITS'; extradefines : 'MSWINDOWS;WINDOWS'; diff --git a/compiler/x86/agx86att.pas b/compiler/x86/agx86att.pas index c7ae4f1233..ba0b7784aa 100644 --- a/compiler/x86/agx86att.pas +++ b/compiler/x86/agx86att.pas @@ -258,7 +258,7 @@ interface asmbin : 'as'; asmcmd : '-o $OBJ $ASM'; supported_target : system_any; - flags : [af_allowdirect,af_needar,af_smartlink_sections]; + flags : [af_allowdirect,af_needar,af_smartlink_sections,af_supports_dwarf]; labelprefix : '.L'; comment : '# '; ); diff --git a/compiler/x86/cgx86.pas b/compiler/x86/cgx86.pas index 7581645ac9..e7249fd208 100644 --- a/compiler/x86/cgx86.pas +++ b/compiler/x86/cgx86.pas @@ -1841,7 +1841,7 @@ unit cgx86; if not nostackframe then begin list.concat(tai_regalloc.alloc(current_procinfo.framepointer,nil)); - if (current_procinfo.framepointer=NR_STACK_POINTER_REG) then + if current_procinfo.framepointer=NR_STACK_POINTER_REG then CGmessage(cg_d_stackframe_omited) else begin @@ -1858,6 +1858,8 @@ unit cgx86; if localsize<>0 then begin cg.g_stackpointer_alloc(list,localsize); + if current_procinfo.framepointer=NR_STACK_POINTER_REG then + dwarfcfi.cfa_def_cfa_offset(list,localsize+sizeof(aint)); end; end; end;