+ Linux/AArch64 compiler support (patch by Edmund Grimley Evans)

git-svn-id: trunk@30893 -
This commit is contained in:
Jonas Maebe 2015-05-22 09:25:05 +00:00
parent 4242934edb
commit 8628d50aba
8 changed files with 356 additions and 16 deletions

View File

@ -39,6 +39,10 @@ unit agcpugas;
procedure WriteInstruction(hp : tai);override;
end;
TAArch64Assembler=class(TGNUassembler)
constructor create(smart: boolean); override;
end;
TAArch64AppleAssembler=class(TAppleGNUassembler)
constructor create(smart: boolean); override;
function MakeCmdLine: TCmdStr; override;
@ -68,6 +72,16 @@ unit agcpugas;
cgbase,cgutils;
{****************************************************************************}
{ AArch64 Assembler writer }
{****************************************************************************}
constructor TAArch64Assembler.create(smart: boolean);
begin
inherited create(smart);
InstrWriter := TAArch64InstrWriter.create(self);
end;
{****************************************************************************}
{ Apple AArch64 Assembler writer }
{****************************************************************************}
@ -99,6 +113,8 @@ unit agcpugas;
const
darwin_addrpage2str: array[addr_page..addr_gotpageoffset] of string[11] =
('@PAGE','@PAGEOFF','@GOTPAGE','@GOTPAGEOFF');
linux_addrpage2str: array[addr_page..addr_gotpageoffset] of string[10] =
('',':lo12:',':got:',':got_lo12:');
begin
if ref.base=NR_NO then
begin
@ -117,8 +133,7 @@ unit agcpugas;
if target_asm.id=as_darwin then
result:=ref.symbol.name+darwin_addrpage2str[ref.refaddr]
else
{ todo }
internalerror(2014121502);
result:=linux_addrpage2str[ref.refaddr]+ref.symbol.name
end
else
internalerror(2015022301);
@ -160,8 +175,7 @@ unit agcpugas;
if target_asm.id=as_darwin then
result:=result+', '+ref.symbol.name+darwin_addrpage2str[ref.refaddr]
else
{ todo }
internalerror(2014122510);
result:=result+', '+linux_addrpage2str[ref.refaddr]+ref.symbol.name
end
else
{ todo: not yet generated/don't know syntax }
@ -269,6 +283,19 @@ unit agcpugas;
const
as_aarch64_gas_info : tasminfo =
(
id : as_gas;
idtxt : 'AS';
asmbin : 'as';
asmcmd : '-o $OBJ $EXTRAOPT $ASM';
supported_targets : [system_aarch64_linux];
flags : [af_needar,af_smartlink_sections];
labelprefix : '.L';
comment : '// ';
dollarsign: '$';
);
as_aarch64_gas_darwin_info : tasminfo =
(
id : as_darwin;
@ -284,5 +311,6 @@ unit agcpugas;
begin
RegisterAssembler(as_aarch64_gas_info,TAArch64Assembler);
RegisterAssembler(as_aarch64_gas_darwin_info,TAArch64AppleAssembler);
end.

View File

@ -171,7 +171,7 @@ implementation
the address of the entry itself from that page (can be relaxed by
the linker in case the variable itself can be stored directly in
the GOT) }
if target_info.system in systems_darwin then
if target_info.system in (systems_darwin + systems_linux) then
begin
if (preferred_newbasereg=NR_NO) or
(ref.base=preferred_newbasereg) or
@ -1631,9 +1631,7 @@ implementation
procedure tcgaarch64.g_maybe_got_init(list : TAsmList);
begin
{ nothing to do on Darwin; check on ELF targets }
if not(target_info.system in systems_darwin) then
internalerror(2014112601);
{ nothing to do on Darwin or Linux }
end;

View File

@ -36,7 +36,7 @@ implementation
**************************************}
{$ifndef NOTARGETLINUX}
// ,t_linux
,t_linux
{$endif}
{$ifndef NOTARGETBSD}
,t_bsd

View File

@ -168,8 +168,9 @@
system_i386_aros, { 83 }
system_x86_64_aros, { 84 }
system_x86_64_dragonfly, { 85 }
system_aarch64_darwin, { 85 }
system_x86_64_iphonesim { 86 }
system_aarch64_darwin, { 86 }
system_x86_64_iphonesim, { 87 }
system_aarch64_linux { 88 }
);
type

View File

@ -224,7 +224,7 @@ interface
systems_android = [system_arm_android, system_i386_android, system_mipsel_android];
systems_linux = [system_i386_linux,system_x86_64_linux,system_powerpc_linux,system_powerpc64_linux,
system_arm_linux,system_sparc_linux,system_alpha_linux,system_m68k_linux,
system_x86_6432_linux,system_mipseb_linux,system_mipsel_linux];
system_x86_6432_linux,system_mipseb_linux,system_mipsel_linux,system_aarch64_linux];
systems_dragonfly = [system_x86_64_dragonfly];
systems_freebsd = [system_i386_freebsd,
system_x86_64_freebsd];
@ -958,8 +958,7 @@ begin
default_target(system_aarch64_darwin);
{$endif darwin}
{$ifndef default_target_set}
{ change to Linux once aarch64 Linux support has been implemented }
default_target(system_aarch64_darwin);
default_target(system_aarch64_linux);
{$define default_target_set}
{$endif}
{$endif cpuaarch64}

View File

@ -824,6 +824,74 @@ unit i_linux;
{$endif FPC_ARMEL}
{$endif FPC_ARMHF}
system_aarch64_linux_info : tsysteminfo =
(
system : system_aarch64_linux;
name : 'Linux for AArch64';
shortname : 'Linux';
flags : [tf_needs_symbol_size,
tf_needs_symbol_type,
tf_files_case_sensitive,
tf_requires_proper_alignment,
tf_smartlink_sections,tf_pic_uses_got,
tf_has_winlike_resources];
cpu : cpu_aarch64;
unit_env : 'LINUXUNITS';
extradefines : 'UNIX;HASUNIX';
exeext : '';
defext : '.def';
scriptext : '.sh';
smartext : '.sl';
unitext : '.ppu';
unitlibext : '.ppl';
asmext : '.s';
objext : '.o';
resext : '.res';
resobjext : '.or';
sharedlibext : '.so';
staticlibext : '.a';
staticlibprefix : 'libp';
sharedlibprefix : 'lib';
sharedClibext : '.so';
staticClibext : '.a';
staticClibprefix : 'lib';
sharedClibprefix : 'lib';
importlibprefix : 'libimp';
importlibext : '.a';
Cprefix : '';
newline : #10;
dirsep : '/';
assem : as_gas;
assemextern : as_gas;
link : ld_none;
linkextern : ld_linux;
ar : ar_gnu_ar;
res : res_elf;
dbg : dbg_dwarf2;
script : script_unix;
endian : endian_little;
alignment :
(
procalign : 8;
loopalign : 4;
jumpalign : 0;
constalignmin : 0;
constalignmax : 8;
varalignmin : 0;
varalignmax : 16;
localalignmin : 4;
localalignmax : 16;
recordalignmin : 0;
recordalignmax : 16;
maxCrecordalign : 16
);
first_parm_offset : 16;
stacksize : 8*1024*1024;
stackalign : 16;
abi : abi_default;
llvmdatalayout : 'e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-n32:64-S128'
);
system_mipseb_linux_info : tsysteminfo =
(
system : system_mipseb_LINUX;
@ -1009,6 +1077,11 @@ initialization
set_source_info(system_arm_linux_info);
{$endif linux}
{$endif CPUARM}
{$ifdef cpuaarch64}
{$ifdef linux}
set_source_info(system_aarch64_linux_info);
{$endif linux}
{$endif cpuaarch64}
{$ifdef CPUMIPSEB}
{$ifdef linux}
set_source_info(system_mipseb_linux_info);

View File

@ -192,6 +192,10 @@ end;
{$endif FPC_ARMHF}
{$endif arm}
{$ifdef aarch64}
const defdynlinker='/lib/ld-linux-aarch64.so.1';
{$endif aarch64}
{$ifdef mips}
const defdynlinker='/lib/ld.so.1';
{$endif mips}
@ -289,6 +293,7 @@ const
{$ifdef POWERPC64} platform_select='';{$endif}
{$ifdef sparc} platform_select='-b elf32-sparc -m elf32_sparc';{$endif}
{$ifdef arm} platform_select='';{$endif} {unknown :( }
{$ifdef aarch64} platform_select='';{$endif} {unknown :( }
{$ifdef m68k} platform_select='';{$endif} {unknown :( }
{$ifdef mips}
{$ifdef mipsel}
@ -722,6 +727,236 @@ begin
add('}');
{$endif x86_64}
{$ifdef AArch64}
{$define LINKERSCRIPT_INCLUDED}
if isdll or (sysrootpath='') then begin
{ On other architectures, supplying a complete linker script
without the -T option just results in:
warning: link.res contains output sections; did you forget -T?
However, with a recent aarch64 linker the result is:
/usr/bin/ld: internal error ../../ld/ldlang.c 5221
So in these cases, where -T will not be used, we supply a
minimal linker script with just the FPC-specific part: }
add('SECTIONS');
add('{');
add(' .data :');
add(' {');
{ extra by FPC }
add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
add(' }');
add('}');
end else begin
{ Complete linker script for aarch64-linux: }
add('SECTIONS');
add('{');
add(' /* Read-only sections, merged into text segment: */');
add(' PROVIDE (__executable_start = SEGMENT_START("text-segment", 0x400000)); . = SEGMENT_START("text-segment", 0x400000) + SIZEOF_HEADERS;');
add(' .interp : { *(.interp) }');
add(' .note.gnu.build-id : { *(.note.gnu.build-id) }');
add(' .hash : { *(.hash) }');
add(' .gnu.hash : { *(.gnu.hash) }');
add(' .dynsym : { *(.dynsym) }');
add(' .dynstr : { *(.dynstr) }');
add(' .gnu.version : { *(.gnu.version) }');
add(' .gnu.version_d : { *(.gnu.version_d) }');
add(' .gnu.version_r : { *(.gnu.version_r) }');
add(' .rela.dyn :');
add(' {');
add(' *(.rela.init)');
add(' *(.rela.text .rela.text.* .rela.gnu.linkonce.t.*)');
add(' *(.rela.fini)');
add(' *(.rela.rodata .rela.rodata.* .rela.gnu.linkonce.r.*)');
add(' *(.rela.data .rela.data.* .rela.gnu.linkonce.d.*)');
add(' *(.rela.tdata .rela.tdata.* .rela.gnu.linkonce.td.*)');
add(' *(.rela.tbss .rela.tbss.* .rela.gnu.linkonce.tb.*)');
add(' *(.rela.ctors)');
add(' *(.rela.dtors)');
add(' *(.rela.got)');
add(' *(.rela.bss .rela.bss.* .rela.gnu.linkonce.b.*)');
add(' *(.rela.ifunc)');
add(' }');
add(' .rela.plt :');
add(' {');
add(' *(.rela.plt)');
add(' PROVIDE_HIDDEN (__rela_iplt_start = .);');
add(' *(.rela.iplt)');
add(' PROVIDE_HIDDEN (__rela_iplt_end = .);');
add(' }');
add(' .init :');
add(' {');
add(' KEEP (*(SORT_NONE(.init)))');
add(' } =0');
add(' .plt : ALIGN(16) { *(.plt) *(.iplt) }');
add(' .text :');
add(' {');
add(' *(.text.unlikely .text.*_unlikely .text.unlikely.*)');
add(' *(.text.exit .text.exit.*)');
add(' *(.text.startup .text.startup.*)');
add(' *(.text.hot .text.hot.*)');
add(' *(.text .stub .text.* .gnu.linkonce.t.*)');
add(' /* .gnu.warning sections are handled specially by elf32.em. */');
add(' *(.gnu.warning)');
add(' } =0');
add(' .fini :');
add(' {');
add(' KEEP (*(SORT_NONE(.fini)))');
add(' } =0');
add(' PROVIDE (__etext = .);');
add(' PROVIDE (_etext = .);');
add(' PROVIDE (etext = .);');
add(' .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }');
add(' .rodata1 : { *(.rodata1) }');
add(' .eh_frame_hdr : { *(.eh_frame_hdr) }');
add(' .eh_frame : ONLY_IF_RO { KEEP (*(.eh_frame)) }');
add(' .gcc_except_table : ONLY_IF_RO { *(.gcc_except_table');
add(' .gcc_except_table.*) }');
add(' /* These sections are generated by the Sun/Oracle C++ compiler. */');
add(' .exception_ranges : ONLY_IF_RO { *(.exception_ranges');
add(' .exception_ranges*) }');
add(' /* Adjust the address for the data segment. We want to adjust up to');
add(' the same address within the page on the next page up. */');
add(' . = ALIGN (CONSTANT (MAXPAGESIZE)) - ((CONSTANT (MAXPAGESIZE) - .) & (CONSTANT (MAXPAGESIZE) - 1)); . = DATA_SEGMENT_ALIGN (CONSTANT (MAXPAGESIZE), CONSTANT (COMMONPAGESIZE));');
add(' /* Exception handling */');
add(' .eh_frame : ONLY_IF_RW { KEEP (*(.eh_frame)) }');
add(' .gcc_except_table : ONLY_IF_RW { *(.gcc_except_table .gcc_except_table.*) }');
add(' .exception_ranges : ONLY_IF_RW { *(.exception_ranges .exception_ranges*) }');
add(' /* Thread Local Storage sections */');
add(' .tdata : { *(.tdata .tdata.* .gnu.linkonce.td.*) }');
add(' .tbss : { *(.tbss .tbss.* .gnu.linkonce.tb.*) *(.tcommon) }');
add(' .preinit_array :');
add(' {');
add(' PROVIDE_HIDDEN (__preinit_array_start = .);');
add(' KEEP (*(.preinit_array))');
add(' PROVIDE_HIDDEN (__preinit_array_end = .);');
add(' }');
add(' .init_array :');
add(' {');
add(' PROVIDE_HIDDEN (__init_array_start = .);');
add(' KEEP (*(SORT_BY_INIT_PRIORITY(.init_array.*) SORT_BY_INIT_PRIORITY(.ctors.*)))');
add(' KEEP (*(.init_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .ctors))');
add(' PROVIDE_HIDDEN (__init_array_end = .);');
add(' }');
add(' .fini_array :');
add(' {');
add(' PROVIDE_HIDDEN (__fini_array_start = .);');
add(' KEEP (*(SORT_BY_INIT_PRIORITY(.fini_array.*) SORT_BY_INIT_PRIORITY(.dtors.*)))');
add(' KEEP (*(.fini_array EXCLUDE_FILE (*crtbegin.o *crtbegin?.o *crtend.o *crtend?.o ) .dtors))');
add(' PROVIDE_HIDDEN (__fini_array_end = .);');
add(' }');
add(' .ctors :');
add(' {');
add(' /* gcc uses crtbegin.o to find the start of');
add(' the constructors, so we make sure it is');
add(' first. Because this is a wildcard, it');
add(' doesn''t matter if the user does not');
add(' actually link against crtbegin.o; the');
add(' linker won''t look for a file to match a');
add(' wildcard. The wildcard also means that it');
add(' doesn''t matter which directory crtbegin.o');
add(' is in. */');
add(' KEEP (*crtbegin.o(.ctors))');
add(' KEEP (*crtbegin?.o(.ctors))');
add(' /* We don''t want to include the .ctor section from');
add(' the crtend.o file until after the sorted ctors.');
add(' The .ctor section from the crtend file contains the');
add(' end of ctors marker and it must be last */');
add(' KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .ctors))');
add(' KEEP (*(SORT(.ctors.*)))');
add(' KEEP (*(.ctors))');
add(' }');
add(' .dtors :');
add(' {');
add(' KEEP (*crtbegin.o(.dtors))');
add(' KEEP (*crtbegin?.o(.dtors))');
add(' KEEP (*(EXCLUDE_FILE (*crtend.o *crtend?.o ) .dtors))');
add(' KEEP (*(SORT(.dtors.*)))');
add(' KEEP (*(.dtors))');
add(' }');
add(' .jcr : { KEEP (*(.jcr)) }');
add(' .data.rel.ro : { *(.data.rel.ro.local* .gnu.linkonce.d.rel.ro.local.*) *(.data.rel.ro .data.rel.ro.* .gnu.linkonce.d.rel.ro.*) }');
add(' .dynamic : { *(.dynamic) }');
add(' .got : { *(.got) *(.igot) }');
add(' . = DATA_SEGMENT_RELRO_END (24, .);');
add(' .got.plt : { *(.got.plt) *(.igot.plt) }');
add(' .data :');
add(' {');
add(' PROVIDE (__data_start = .);');
{ extra by FPC }
add(' KEEP (*(.fpc .fpc.n_version .fpc.n_links))');
add(' *(.data .data.* .gnu.linkonce.d.*)');
add(' SORT(CONSTRUCTORS)');
add(' }');
add(' .data1 : { *(.data1) }');
add(' _edata = .; PROVIDE (edata = .);');
add(' . = .;');
add(' __bss_start = .;');
add(' __bss_start__ = .;');
add(' .bss :');
add(' {');
add(' *(.dynbss)');
add(' *(.bss .bss.* .gnu.linkonce.b.*)');
add(' *(COMMON)');
add(' /* Align here to ensure that the .bss section occupies space up to');
add(' _end. Align after .bss to ensure correct alignment even if the');
add(' .bss section disappears because there are no input sections.');
add(' FIXME: Why do we need it? When there is no .bss section, we don''t');
add(' pad the .data section. */');
add(' . = ALIGN(. != 0 ? 64 / 8 : 1);');
add(' }');
add(' _bss_end__ = . ; __bss_end__ = . ;');
add(' . = ALIGN(64 / 8);');
add(' . = SEGMENT_START("ldata-segment", .);');
add(' . = ALIGN(64 / 8);');
add(' __end__ = . ;');
add(' _end = .; PROVIDE (end = .);');
add(' . = DATA_SEGMENT_END (.);');
add(' /* Stabs debugging sections. */');
add(' .stab 0 : { *(.stab) }');
add(' .stabstr 0 : { *(.stabstr) }');
add(' .stab.excl 0 : { *(.stab.excl) }');
add(' .stab.exclstr 0 : { *(.stab.exclstr) }');
add(' .stab.index 0 : { *(.stab.index) }');
add(' .stab.indexstr 0 : { *(.stab.indexstr) }');
add(' .comment 0 : { *(.comment) }');
add(' /* DWARF debug sections.');
add(' Symbols in the DWARF debugging sections are relative to the beginning');
add(' of the section so we begin them at 0. */');
add(' /* DWARF 1 */');
add(' .debug 0 : { *(.debug) }');
add(' .line 0 : { *(.line) }');
add(' /* GNU DWARF 1 extensions */');
add(' .debug_srcinfo 0 : { *(.debug_srcinfo) }');
add(' .debug_sfnames 0 : { *(.debug_sfnames) }');
add(' /* DWARF 1.1 and DWARF 2 */');
add(' .debug_aranges 0 : { *(.debug_aranges) }');
add(' .debug_pubnames 0 : { *(.debug_pubnames) }');
add(' /* DWARF 2 */');
add(' .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) }');
add(' .debug_abbrev 0 : { *(.debug_abbrev) }');
add(' .debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end ) }');
add(' .debug_frame 0 : { *(.debug_frame) }');
add(' .debug_str 0 : { *(.debug_str) }');
add(' .debug_loc 0 : { *(.debug_loc) }');
add(' .debug_macinfo 0 : { *(.debug_macinfo) }');
add(' /* SGI/MIPS DWARF 2 extensions */');
add(' .debug_weaknames 0 : { *(.debug_weaknames) }');
add(' .debug_funcnames 0 : { *(.debug_funcnames) }');
add(' .debug_typenames 0 : { *(.debug_typenames) }');
add(' .debug_varnames 0 : { *(.debug_varnames) }');
add(' /* DWARF 3 */');
add(' .debug_pubtypes 0 : { *(.debug_pubtypes) }');
add(' .debug_ranges 0 : { *(.debug_ranges) }');
add(' /* DWARF Extension. */');
add(' .debug_macro 0 : { *(.debug_macro) }');
add(' .ARM.attributes 0 : { KEEP (*(.ARM.attributes)) KEEP (*(.gnu.attributes)) }');
add(' .note.gnu.arm.ident 0 : { KEEP (*(.note.gnu.arm.ident)) }');
add(' /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) }');
add('}');
end;
{$endif AArch64}
{$ifdef ARM}
if target_info.abi=abi_eabi then
begin
@ -1569,6 +1804,11 @@ initialization
RegisterExport(system_arm_linux,texportliblinux);
RegisterTarget(system_arm_linux_info);
{$endif ARM}
{$ifdef aarch64}
RegisterImport(system_aarch64_linux,timportliblinux);
RegisterExport(system_aarch64_linux,texportliblinux);
RegisterTarget(system_aarch64_linux_info);
{$endif aarch64}
{$ifdef MIPS}
{$ifdef MIPSEL}
RegisterImport(system_mipsel_linux,timportliblinux);

View File

@ -169,8 +169,9 @@ const
{ 83 } 'AROS-i386',
{ 84 } 'AROS-x86-64',
{ 85 } 'DragonFly-x86-64',
{ 85 } 'Darwin-AArch64',
{ 86 } 'iPhoneSim-x86-64'
{ 86 } 'Darwin-AArch64',
{ 87 } 'iPhoneSim-x86-64',
{ 88 } 'Linux-AArch64'
);
const