diff --git a/compiler/aasmtai.pas b/compiler/aasmtai.pas index 3a9c16a114..4e3c2c0845 100644 --- a/compiler/aasmtai.pas +++ b/compiler/aasmtai.pas @@ -1305,7 +1305,10 @@ implementation result:=8; aitconst_indirect_symbol, aitconst_rva_symbol : - result:=sizeof(aint); + if target_info.system=system_x86_64_win64 then + result:=sizeof(longint) + else + result:=sizeof(aint); aitconst_uleb128bit : result:=LengthUleb128(value); aitconst_sleb128bit : diff --git a/compiler/assemble.pas b/compiler/assemble.pas index 86de99a176..be673be4b1 100644 --- a/compiler/assemble.pas +++ b/compiler/assemble.pas @@ -1124,7 +1124,11 @@ Implementation ObjData.writebytes(Tai_const(hp).value,tai_const(hp).size); end; aitconst_rva_symbol : - ObjData.writereloc(Tai_const(hp).value,sizeof(aint),Objdata.SymbolRef(tai_const(hp).sym),RELOC_RVA); + { PE32+? } + if target_info.system=system_x86_64_win64 then + ObjData.writereloc(Tai_const(hp).value,sizeof(longint),Objdata.SymbolRef(tai_const(hp).sym),RELOC_RVA) + else + ObjData.writereloc(Tai_const(hp).value,sizeof(aint),Objdata.SymbolRef(tai_const(hp).sym),RELOC_RVA); aitconst_uleb128bit : begin leblen:=EncodeUleb128(Tai_const(hp).value,lebbuf); diff --git a/compiler/ogcoff.pas b/compiler/ogcoff.pas index 5127a7298c..a8105c6f4e 100644 --- a/compiler/ogcoff.pas +++ b/compiler/ogcoff.pas @@ -1996,7 +1996,7 @@ const win32stub : array[0..131] of byte=( if win32 then begin header.flag:=PE_FILE_EXECUTABLE_IMAGE or PE_FILE_RELOCS_STRIPPED or - {PE_FILE_BYTES_REVERSED_LO or }PE_FILE_32BIT_MACHINE or + {PE_FILE_BYTES_REVERSED_LO or } PE_FILE_LINE_NUMS_STRIPPED; if FindExeSection('.stab')=nil then header.flag:=header.flag or PE_FILE_DEBUG_STRIPPED; @@ -2005,6 +2005,10 @@ const win32stub : array[0..131] of byte=( end else header.flag:=COFF_FLAG_AR32WR or COFF_FLAG_EXE or COFF_FLAG_NORELOCS or COFF_FLAG_NOLINES; + + if target_info.system in [system_i386_win32,system_arm_wince,system_i386_wince] then + header.flag:=header.flag or PE_FILE_32BIT_MACHINE; + FWriter.write(header,sizeof(header)); { Optional COFF Header } if win32 then @@ -2172,11 +2176,11 @@ const win32stub : array[0..131] of byte=( idata7label:=internalobjdata.SymbolDefine('__imp_dll_'+basedllname,AB_LOCAL,AT_DATA); { idata2 } internalobjdata.SetSection(idata2objsection); - internalobjdata.writereloc(0,sizeof(aint),idata4label,RELOC_RVA); + internalobjdata.writereloc(0,sizeof(longint),idata4label,RELOC_RVA); internalobjdata.writebytes(emptyint,sizeof(emptyint)); internalobjdata.writebytes(emptyint,sizeof(emptyint)); - internalobjdata.writereloc(0,sizeof(aint),idata7label,RELOC_RVA); - internalobjdata.writereloc(0,sizeof(aint),idata5label,RELOC_RVA); + internalobjdata.writereloc(0,sizeof(longint),idata7label,RELOC_RVA); + internalobjdata.writereloc(0,sizeof(longint),idata5label,RELOC_RVA); { idata7 } internalobjdata.SetSection(idata7objsection); internalobjdata.writebytes(basedllname[1],length(basedllname)); @@ -2191,9 +2195,13 @@ const win32stub : array[0..131] of byte=( { idata4 } internalobjdata.SetSection(idata4objsection); internalobjdata.writebytes(emptyint,sizeof(emptyint)); + if target_info.system=system_x86_64_win64 then + internalobjdata.writebytes(emptyint,sizeof(emptyint)); { idata5 } internalobjdata.SetSection(idata5objsection); internalobjdata.writebytes(emptyint,sizeof(emptyint)); + if target_info.system=system_x86_64_win64 then + internalobjdata.writebytes(emptyint,sizeof(emptyint)); end; function AddProcImport(const afuncname:string):TObjSymbol; @@ -2225,11 +2233,16 @@ const win32stub : array[0..131] of byte=( internalobjdata.writebytes(emptyint,align(internalobjdata.CurrObjSec.size,2)-internalobjdata.CurrObjSec.size); { idata4, import lookup table } internalobjdata.SetSection(idata4objsection); - internalobjdata.writereloc(0,sizeof(aint),idata6label,RELOC_RVA); + internalobjdata.writereloc(0,sizeof(longint),idata6label,RELOC_RVA); + internalobjdata.writebytes(emptyint,sizeof(emptyint)); + if target_info.system=system_x86_64_win64 then + internalobjdata.writebytes(emptyint,sizeof(emptyint)); { idata5, import address table } internalobjdata.SetSection(idata5objsection); idata5label:=internalobjdata.SymbolDefine('__imp_'+afuncname,AB_LOCAL,AT_DATA); - internalobjdata.writereloc(0,sizeof(aint),idata6label,RELOC_RVA); + internalobjdata.writereloc(0,sizeof(longint),idata6label,RELOC_RVA); + if target_info.system=system_x86_64_win64 then + internalobjdata.writebytes(emptyint,sizeof(emptyint)); { text, jmp } internalobjdata.SetSection(textobjsection); result:=internalobjdata.SymbolDefine('_'+afuncname,AB_GLOBAL,AT_FUNCTION); diff --git a/compiler/systems/t_win.pas b/compiler/systems/t_win.pas index 4dad581a2c..640bd50991 100644 --- a/compiler/systems/t_win.pas +++ b/compiler/systems/t_win.pas @@ -283,12 +283,12 @@ implementation hp1:=timportlist(current_module.imports.first); while assigned(hp1) do begin - { Get labels for the sections } + { Get labels for the sections } current_asmdata.getdatalabel(lhead); current_asmdata.getdatalabel(lname); current_asmdata.getaddrlabel(lidata4); current_asmdata.getaddrlabel(lidata5); - { create header for this importmodule } + { create header for this importmodule } current_asmdata.asmlists[al_imports].concat(Tai_cutobject.Create_begin); new_section(current_asmdata.asmlists[al_imports],sec_idata2,'',0); current_asmdata.asmlists[al_imports].concat(Tai_label.Create(lhead)); @@ -353,12 +353,14 @@ implementation current_asmdata.getjumplabel(tasmlabel(hp2.lab)); new_section(current_asmdata.asmlists[al_imports],sec_idata4,'',0); current_asmdata.asmlists[al_imports].concat(Tai_const.Create_rva_sym(hp2.lab)); + if target_info.system=system_x86_64_win64 then + current_asmdata.asmlists[al_imports].concat(Tai_const.Create_32bit(0)); { add jump field to al_imports } new_section(current_asmdata.asmlists[al_imports],sec_idata5,'',0); if hp2.is_var then - current_asmdata.asmlists[al_imports].concat(Tai_symbol.Createname_global(hp2.func^,AT_FUNCTION,0)) + current_asmdata.asmlists[al_imports].concat(Tai_symbol.Createname_global(hp2.func^,AT_FUNCTION,0)) else - current_asmdata.asmlists[al_imports].concat(Tai_label.Create(lcode)); + current_asmdata.asmlists[al_imports].concat(Tai_label.Create(lcode)); if (cs_debuginfo in aktmoduleswitches) then begin if assigned(hp2.name) then @@ -385,9 +387,19 @@ implementation end; end; if hp2.name^<>'' then - current_asmdata.asmlists[al_imports].concat(Tai_const.Create_rva_sym(hp2.lab)) + begin + current_asmdata.asmlists[al_imports].concat(Tai_const.Create_rva_sym(hp2.lab)); + if target_info.system=system_x86_64_win64 then + current_asmdata.asmlists[al_imports].concat(Tai_const.Create_32bit(0)); + end else - current_asmdata.asmlists[al_imports].concat(Tai_const.Create_32bit(longint($80000000) or longint(hp2.ordnr))); + begin + if target_info.system=system_x86_64_win64 then + current_asmdata.asmlists[al_imports].concat(Tai_const.Create_64bit(int64($8000000000000000) or int64(hp2.ordnr))) + else + current_asmdata.asmlists[al_imports].concat(Tai_const.Create_32bit(longint($80000000) or longint(hp2.ordnr))); + end; + { finally the import information } new_section(current_asmdata.asmlists[al_imports],sec_idata6,'',0); current_asmdata.asmlists[al_imports].concat(Tai_label.Create(hp2.lab)); @@ -402,6 +414,8 @@ implementation { end of name references } new_section(current_asmdata.asmlists[al_imports],sec_idata4,'',0); current_asmdata.asmlists[al_imports].concat(Tai_const.Create_32bit(0)); + if target_info.system=system_x86_64_win64 then + current_asmdata.asmlists[al_imports].concat(Tai_const.Create_32bit(0)); { end if addresses } new_section(current_asmdata.asmlists[al_imports],sec_idata5,'',0); current_asmdata.asmlists[al_imports].concat(Tai_const.Create_32bit(0)); @@ -462,17 +476,29 @@ implementation begin current_asmdata.getjumplabel(tasmlabel(hp2.lab)); if hp2.name^<>'' then - current_asmdata.asmlists[al_imports].concat(Tai_const.Create_rva_sym(hp2.lab)) + begin + current_asmdata.asmlists[al_imports].concat(Tai_const.Create_rva_sym(hp2.lab)); + if target_info.system=system_x86_64_win64 then + current_asmdata.asmlists[al_imports].concat(Tai_const.Create_32bit(0)); + end else - current_asmdata.asmlists[al_imports].concat(Tai_const.Create_32bit(longint($80000000) or hp2.ordnr)); + begin + if target_info.system=system_x86_64_win64 then + current_asmdata.asmlists[al_imports].concat(Tai_const.Create_64bit(int64($8000000000000000) or hp2.ordnr)) + else + current_asmdata.asmlists[al_imports].concat(Tai_const.Create_32bit(longint($80000000) or hp2.ordnr)); + end; hp2:=twin32imported_item(hp2.next); end; { finalize the names ... } current_asmdata.asmlists[al_imports].concat(Tai_const.Create_32bit(0)); + if target_info.system=system_x86_64_win64 then + current_asmdata.asmlists[al_imports].concat(Tai_const.Create_32bit(0)); { then the addresses and create also the indirect jump } new_section(current_asmdata.asmlists[al_imports],sec_idata5,'',0); current_asmdata.asmlists[al_imports].concat(Tai_label.Create(l3)); + hp2:=twin32imported_item(hp1.imported_items.first); while assigned(hp2) do begin @@ -538,10 +564,14 @@ implementation current_asmdata.asmlists[al_imports].concat(Tai_symbol.Createname_global(hp2.func^,AT_DATA,0)); end; current_asmdata.asmlists[al_imports].concat(Tai_const.Create_rva_sym(hp2.lab)); + if target_info.system=system_x86_64_win64 then + current_asmdata.asmlists[al_imports].concat(Tai_const.Create_32bit(0)); hp2:=twin32imported_item(hp2.next); end; { finalize the addresses } current_asmdata.asmlists[al_imports].concat(Tai_const.Create_32bit(0)); + if target_info.system=system_x86_64_win64 then + current_asmdata.asmlists[al_imports].concat(Tai_const.Create_32bit(0)); { finally the import information } new_section(current_asmdata.asmlists[al_imports],sec_idata6,'',0);