浏览代码

* merged macOS/AArch64 support + revisions these changes depended on

git-svn-id: branches/fixes_3_2@46866 -
Jonas Maebe 4 年之前
父节点
当前提交
76045bfc04
共有 100 个文件被更改,包括 3599 次插入1531 次删除
  1. 33 7
      .gitattributes
  2. 1 1
      Makefile.fpc
  3. 1 1
      compiler/Makefile.fpc
  4. 1 1
      compiler/aarch64/aasmcpu.pas
  5. 4 5
      compiler/aarch64/agcpugas.pas
  6. 143 80
      compiler/aarch64/cgcpu.pas
  7. 12 1
      compiler/aarch64/cpupara.pas
  8. 2 2
      compiler/aarch64/cputarg.pas
  9. 48 0
      compiler/aarch64/tripletcpu.pas
  10. 198 0
      compiler/aasmcfi.pas
  11. 1 0
      compiler/aasmcnst.pas
  12. 6 2
      compiler/aasmtai.pas
  13. 42 3
      compiler/aggas.pas
  14. 5 2
      compiler/aoptobj.pas
  15. 18 5
      compiler/arm/agarmgas.pas
  16. 3 3
      compiler/arm/cgcpu.pas
  17. 1 1
      compiler/arm/cpuelf.pas
  18. 17 0
      compiler/arm/cpuinfo.pas
  19. 1 1
      compiler/arm/cpupara.pas
  20. 1 1
      compiler/arm/cpupi.pas
  21. 3 0
      compiler/arm/cputarg.pas
  22. 51 0
      compiler/arm/tripletcpu.pas
  23. 9 13
      compiler/assemble.pas
  24. 45 0
      compiler/avr/tripletcpu.pas
  25. 122 13
      compiler/cfidwarf.pas
  26. 3 3
      compiler/cfileutl.pas
  27. 1 1
      compiler/cgobj.pas
  28. 13 3
      compiler/compiler.pas
  29. 1 1
      compiler/comprsrc.pas
  30. 1 1
      compiler/dbgdwarf.pas
  31. 1 1
      compiler/dbgstabs.pas
  32. 1 0
      compiler/entfile.pas
  33. 6 1
      compiler/fmodule.pas
  34. 26 0
      compiler/fppu.pas
  35. 35 0
      compiler/globtype.pas
  36. 5 2
      compiler/i386/aoptcpu.pas
  37. 3 0
      compiler/i386/cputarg.pas
  38. 49 0
      compiler/i386/tripletcpu.pas
  39. 45 0
      compiler/i8086/tripletcpu.pas
  40. 45 0
      compiler/jvm/tripletcpu.pas
  41. 57 3
      compiler/link.pas
  42. 245 11
      compiler/llvm/agllvm.pas
  43. 42 81
      compiler/llvm/llvmbase.pas
  44. 1 1
      compiler/m68k/ag68kgas.pas
  45. 45 0
      compiler/m68k/tripletcpu.pas
  46. 48 0
      compiler/mips/tripletcpu.pas
  47. 2 2
      compiler/msg/errore.msg
  48. 1 1
      compiler/msgidx.inc
  49. 47 49
      compiler/msgtxt.inc
  50. 39 10
      compiler/ncal.pas
  51. 1 1
      compiler/ngenutil.pas
  52. 10 0
      compiler/nutils.pas
  53. 1 1
      compiler/objcgutl.pas
  54. 34 20
      compiler/options.pas
  55. 31 5
      compiler/opttail.pas
  56. 1 1
      compiler/pdecvar.pas
  57. 1 1
      compiler/pmodules.pas
  58. 1 1
      compiler/powerpc/agppcmpw.pas
  59. 2 2
      compiler/powerpc/cgcpu.pas
  60. 4 1
      compiler/powerpc/cputarg.pas
  61. 45 0
      compiler/powerpc/tripletcpu.pas
  62. 2 2
      compiler/powerpc64/cputarg.pas
  63. 48 0
      compiler/powerpc64/tripletcpu.pas
  64. 4 4
      compiler/ppcgen/agppcgas.pas
  65. 3 3
      compiler/ppcgen/cgppc.pas
  66. 1 1
      compiler/ppcgen/ngppcadd.pas
  67. 2 2
      compiler/scandir.pas
  68. 48 0
      compiler/sparc/tripletcpu.pas
  69. 45 0
      compiler/sparc64/tripletcpu.pas
  70. 3 3
      compiler/symdef.pas
  71. 10 7
      compiler/systems.inc
  72. 22 11
      compiler/systems.pas
  73. 2 561
      compiler/systems/i_bsd.pas
  74. 680 0
      compiler/systems/i_darwin.pas
  75. 10 10
      compiler/systems/i_macos.pas
  76. 98 539
      compiler/systems/t_bsd.pas
  77. 764 0
      compiler/systems/t_darwin.pas
  78. 5 5
      compiler/systems/t_macos.pas
  79. 101 0
      compiler/triplet.pas
  80. 10 5
      compiler/utils/ppuutils/ppudump.pp
  81. 6 6
      compiler/x86/agx86att.pas
  82. 3 0
      compiler/x86_64/cputarg.pas
  83. 45 0
      compiler/x86_64/tripletcpu.pas
  84. 1 1
      packages/aspell/fpmake.pp
  85. 1 1
      packages/bfd/fpmake.pp
  86. 1 1
      packages/bzip2/fpmake.pp
  87. 1 1
      packages/chm/fpmake.pp
  88. 1 1
      packages/cocoaint/fpmake.pp
  89. 1 1
      packages/cocoaint/src/appkit/NSApplication.inc
  90. 1 1
      packages/cocoaint/src/iobluetooth/IOBluetoothUserLib.inc
  91. 2 2
      packages/fcl-base/fpmake.pp
  92. 4 4
      packages/fcl-db/fpmake.pp
  93. 1 1
      packages/fcl-extra/fpmake.pp
  94. 2 2
      packages/fcl-fpcunit/fpmake.pp
  95. 5 5
      packages/fcl-image/fpmake.pp
  96. 1 1
      packages/fcl-js/fpmake.pp
  97. 1 1
      packages/fcl-json/fpmake.pp
  98. 1 1
      packages/fcl-net/fpmake.pp
  99. 1 1
      packages/fcl-passrc/fpmake.pp
  100. 1 1
      packages/fcl-pdf/fpmake.pp

+ 33 - 7
.gitattributes

@@ -46,7 +46,9 @@ compiler/aarch64/racpu.pas svneol=native#text/plain
 compiler/aarch64/racpugas.pas svneol=native#text/plain
 compiler/aarch64/racpugas.pas svneol=native#text/plain
 compiler/aarch64/rgcpu.pas svneol=native#text/plain
 compiler/aarch64/rgcpu.pas svneol=native#text/plain
 compiler/aarch64/symcpu.pas svneol=native#text/plain
 compiler/aarch64/symcpu.pas svneol=native#text/plain
+compiler/aarch64/tripletcpu.pas svneol=native#text/plain
 compiler/aasmbase.pas svneol=native#text/plain
 compiler/aasmbase.pas svneol=native#text/plain
+compiler/aasmcfi.pas svneol=native#text/plain
 compiler/aasmcnst.pas svneol=native#text/plain
 compiler/aasmcnst.pas svneol=native#text/plain
 compiler/aasmdata.pas svneol=native#text/plain
 compiler/aasmdata.pas svneol=native#text/plain
 compiler/aasmdef.pas svneol=native#text/plain
 compiler/aasmdef.pas svneol=native#text/plain
@@ -102,6 +104,7 @@ compiler/arm/rarmstd.inc svneol=native#text/plain
 compiler/arm/rarmsup.inc svneol=native#text/plain
 compiler/arm/rarmsup.inc svneol=native#text/plain
 compiler/arm/rgcpu.pas svneol=native#text/plain
 compiler/arm/rgcpu.pas svneol=native#text/plain
 compiler/arm/symcpu.pas svneol=native#text/plain
 compiler/arm/symcpu.pas svneol=native#text/plain
+compiler/arm/tripletcpu.pas svneol=native#text/plain
 compiler/assemble.pas svneol=native#text/plain
 compiler/assemble.pas svneol=native#text/plain
 compiler/avr/aasmcpu.pas svneol=native#text/plain
 compiler/avr/aasmcpu.pas svneol=native#text/plain
 compiler/avr/agavrgas.pas svneol=native#text/plain
 compiler/avr/agavrgas.pas svneol=native#text/plain
@@ -138,6 +141,7 @@ compiler/avr/ravrstd.inc svneol=native#text/plain
 compiler/avr/ravrsup.inc svneol=native#text/plain
 compiler/avr/ravrsup.inc svneol=native#text/plain
 compiler/avr/rgcpu.pas svneol=native#text/plain
 compiler/avr/rgcpu.pas svneol=native#text/plain
 compiler/avr/symcpu.pas svneol=native#text/plain
 compiler/avr/symcpu.pas svneol=native#text/plain
+compiler/avr/tripletcpu.pas svneol=native#text/plain
 compiler/blockutl.pas svneol=native#text/plain
 compiler/blockutl.pas svneol=native#text/plain
 compiler/browcol.pas svneol=native#text/plain
 compiler/browcol.pas svneol=native#text/plain
 compiler/catch.pas svneol=native#text/plain
 compiler/catch.pas svneol=native#text/plain
@@ -239,6 +243,7 @@ compiler/i386/ra386att.pas svneol=native#text/plain
 compiler/i386/ra386int.pas svneol=native#text/plain
 compiler/i386/ra386int.pas svneol=native#text/plain
 compiler/i386/rgcpu.pas svneol=native#text/plain
 compiler/i386/rgcpu.pas svneol=native#text/plain
 compiler/i386/symcpu.pas svneol=native#text/plain
 compiler/i386/symcpu.pas svneol=native#text/plain
+compiler/i386/tripletcpu.pas svneol=native#text/plain
 compiler/i8086/aoptcpu.pas svneol=native#text/plain
 compiler/i8086/aoptcpu.pas svneol=native#text/plain
 compiler/i8086/aoptcpub.pas svneol=native#text/plain
 compiler/i8086/aoptcpub.pas svneol=native#text/plain
 compiler/i8086/aoptcpud.pas svneol=native#text/plain
 compiler/i8086/aoptcpud.pas svneol=native#text/plain
@@ -287,6 +292,7 @@ compiler/i8086/ra8086int.pas svneol=native#text/plain
 compiler/i8086/rgcpu.pas svneol=native#text/plain
 compiler/i8086/rgcpu.pas svneol=native#text/plain
 compiler/i8086/symcpu.pas svneol=native#text/plain
 compiler/i8086/symcpu.pas svneol=native#text/plain
 compiler/i8086/tgcpu.pas svneol=native#text/plain
 compiler/i8086/tgcpu.pas svneol=native#text/plain
+compiler/i8086/tripletcpu.pas svneol=native#text/plain
 compiler/impdef.pas svneol=native#text/plain
 compiler/impdef.pas svneol=native#text/plain
 compiler/import.pas svneol=native#text/plain
 compiler/import.pas svneol=native#text/plain
 compiler/jvm/aasmcpu.pas svneol=native#text/plain
 compiler/jvm/aasmcpu.pas svneol=native#text/plain
@@ -330,6 +336,7 @@ compiler/jvm/rjvmstd.inc svneol=native#text/plain
 compiler/jvm/rjvmsup.inc svneol=native#text/plain
 compiler/jvm/rjvmsup.inc svneol=native#text/plain
 compiler/jvm/symcpu.pas svneol=native#text/plain
 compiler/jvm/symcpu.pas svneol=native#text/plain
 compiler/jvm/tgcpu.pas svneol=native#text/plain
 compiler/jvm/tgcpu.pas svneol=native#text/plain
+compiler/jvm/tripletcpu.pas svneol=native#text/plain
 compiler/ldscript.pas svneol=native#text/plain
 compiler/ldscript.pas svneol=native#text/plain
 compiler/link.pas svneol=native#text/plain
 compiler/link.pas svneol=native#text/plain
 compiler/llvm/aasmllvm.pas svneol=native#text/plain
 compiler/llvm/aasmllvm.pas svneol=native#text/plain
@@ -398,6 +405,7 @@ compiler/m68k/ra68k.pas svneol=native#text/plain
 compiler/m68k/ra68kmot.pas svneol=native#text/plain
 compiler/m68k/ra68kmot.pas svneol=native#text/plain
 compiler/m68k/rgcpu.pas svneol=native#text/plain
 compiler/m68k/rgcpu.pas svneol=native#text/plain
 compiler/m68k/symcpu.pas svneol=native#text/plain
 compiler/m68k/symcpu.pas svneol=native#text/plain
+compiler/m68k/tripletcpu.pas svneol=native#text/plain
 compiler/macho.pas svneol=native#text/plain
 compiler/macho.pas svneol=native#text/plain
 compiler/machoutils.pas svneol=native#text/plain
 compiler/machoutils.pas svneol=native#text/plain
 compiler/mips/aasmcpu.pas svneol=native#text/plain
 compiler/mips/aasmcpu.pas svneol=native#text/plain
@@ -440,6 +448,7 @@ compiler/mips/rmipsstd.inc svneol=native#text/plain
 compiler/mips/rmipssup.inc svneol=native#text/plain
 compiler/mips/rmipssup.inc svneol=native#text/plain
 compiler/mips/strinst.inc svneol=native#text/plain
 compiler/mips/strinst.inc svneol=native#text/plain
 compiler/mips/symcpu.pas svneol=native#text/plain
 compiler/mips/symcpu.pas svneol=native#text/plain
+compiler/mips/tripletcpu.pas svneol=native#text/plain
 compiler/msg/errorct.msg svneol=native#text/plain
 compiler/msg/errorct.msg svneol=native#text/plain
 compiler/msg/errord.msg svneol=native#text/plain
 compiler/msg/errord.msg svneol=native#text/plain
 compiler/msg/errorda.msg svneol=native#text/plain
 compiler/msg/errorda.msg svneol=native#text/plain
@@ -583,6 +592,7 @@ compiler/powerpc/rppcstab.inc svneol=native#text/plain
 compiler/powerpc/rppcstd.inc svneol=native#text/plain
 compiler/powerpc/rppcstd.inc svneol=native#text/plain
 compiler/powerpc/rppcsup.inc svneol=native#text/plain
 compiler/powerpc/rppcsup.inc svneol=native#text/plain
 compiler/powerpc/symcpu.pas svneol=native#text/plain
 compiler/powerpc/symcpu.pas svneol=native#text/plain
+compiler/powerpc/tripletcpu.pas svneol=native#text/plain
 compiler/powerpc64/aoptcpu.pas svneol=native#text/plain
 compiler/powerpc64/aoptcpu.pas svneol=native#text/plain
 compiler/powerpc64/aoptcpub.pas svneol=native#text/plain
 compiler/powerpc64/aoptcpub.pas svneol=native#text/plain
 compiler/powerpc64/aoptcpud.pas svneol=native#text/plain
 compiler/powerpc64/aoptcpud.pas svneol=native#text/plain
@@ -619,6 +629,7 @@ compiler/powerpc64/rppcstab.inc svneol=native#text/plain
 compiler/powerpc64/rppcstd.inc svneol=native#text/plain
 compiler/powerpc64/rppcstd.inc svneol=native#text/plain
 compiler/powerpc64/rppcsup.inc svneol=native#text/plain
 compiler/powerpc64/rppcsup.inc svneol=native#text/plain
 compiler/powerpc64/symcpu.pas svneol=native#text/plain
 compiler/powerpc64/symcpu.pas svneol=native#text/plain
+compiler/powerpc64/tripletcpu.pas svneol=native#text/plain
 compiler/pp.lpi svneol=native#text/plain
 compiler/pp.lpi svneol=native#text/plain
 compiler/pp.pas svneol=native#text/plain
 compiler/pp.pas svneol=native#text/plain
 compiler/pparautl.pas svneol=native#text/plain
 compiler/pparautl.pas svneol=native#text/plain
@@ -679,6 +690,7 @@ compiler/sparc/rspsri.inc svneol=native#text/plain
 compiler/sparc/rspstab.inc svneol=native#text/plain
 compiler/sparc/rspstab.inc svneol=native#text/plain
 compiler/sparc/rspstd.inc svneol=native#text/plain
 compiler/sparc/rspstd.inc svneol=native#text/plain
 compiler/sparc/rspsup.inc svneol=native#text/plain
 compiler/sparc/rspsup.inc svneol=native#text/plain
+compiler/sparc/tripletcpu.pas svneol=native#text/plain
 compiler/sparc64/cgcpu.pas svneol=native#text/pascal
 compiler/sparc64/cgcpu.pas svneol=native#text/pascal
 compiler/sparc64/cpugas.pas svneol=native#text/pascal
 compiler/sparc64/cpugas.pas svneol=native#text/pascal
 compiler/sparc64/cpuinfo.pas svneol=native#text/plain
 compiler/sparc64/cpuinfo.pas svneol=native#text/plain
@@ -695,6 +707,7 @@ compiler/sparc64/rsp64stab.inc svneol=native#text/pascal
 compiler/sparc64/rsp64std.inc svneol=native#text/pascal
 compiler/sparc64/rsp64std.inc svneol=native#text/pascal
 compiler/sparc64/rsp64sup.inc svneol=native#text/pascal
 compiler/sparc64/rsp64sup.inc svneol=native#text/pascal
 compiler/sparc64/tgcpu.pas svneol=native#text/plain
 compiler/sparc64/tgcpu.pas svneol=native#text/plain
+compiler/sparc64/tripletcpu.pas svneol=native#text/plain
 compiler/sparcgen/aasmcpu.pas svneol=native#text/plain
 compiler/sparcgen/aasmcpu.pas svneol=native#text/plain
 compiler/sparcgen/aoptcpu.pas svneol=native#text/plain
 compiler/sparcgen/aoptcpu.pas svneol=native#text/plain
 compiler/sparcgen/aoptcpub.pas svneol=native#text/plain
 compiler/sparcgen/aoptcpub.pas svneol=native#text/plain
@@ -737,6 +750,7 @@ compiler/systems/i_aros.pas svneol=native#text/plain
 compiler/systems/i_atari.pas svneol=native#text/plain
 compiler/systems/i_atari.pas svneol=native#text/plain
 compiler/systems/i_beos.pas svneol=native#text/plain
 compiler/systems/i_beos.pas svneol=native#text/plain
 compiler/systems/i_bsd.pas svneol=native#text/plain
 compiler/systems/i_bsd.pas svneol=native#text/plain
+compiler/systems/i_darwin.pas svneol=native#text/plain
 compiler/systems/i_embed.pas svneol=native#text/plain
 compiler/systems/i_embed.pas svneol=native#text/plain
 compiler/systems/i_emx.pas svneol=native#text/plain
 compiler/systems/i_emx.pas svneol=native#text/plain
 compiler/systems/i_gba.pas svneol=native#text/plain
 compiler/systems/i_gba.pas svneol=native#text/plain
@@ -768,6 +782,7 @@ compiler/systems/t_aros.pas svneol=native#text/plain
 compiler/systems/t_atari.pas svneol=native#text/plain
 compiler/systems/t_atari.pas svneol=native#text/plain
 compiler/systems/t_beos.pas svneol=native#text/plain
 compiler/systems/t_beos.pas svneol=native#text/plain
 compiler/systems/t_bsd.pas svneol=native#text/plain
 compiler/systems/t_bsd.pas svneol=native#text/plain
+compiler/systems/t_darwin.pas svneol=native#text/plain
 compiler/systems/t_embed.pas svneol=native#text/plain
 compiler/systems/t_embed.pas svneol=native#text/plain
 compiler/systems/t_emx.pas svneol=native#text/plain
 compiler/systems/t_emx.pas svneol=native#text/plain
 compiler/systems/t_gba.pas svneol=native#text/plain
 compiler/systems/t_gba.pas svneol=native#text/plain
@@ -793,6 +808,7 @@ compiler/systems/t_win.pas svneol=native#text/plain
 compiler/systems/t_win16.pas svneol=native#text/plain
 compiler/systems/t_win16.pas svneol=native#text/plain
 compiler/tgobj.pas svneol=native#text/plain
 compiler/tgobj.pas svneol=native#text/plain
 compiler/tokens.pas svneol=native#text/plain
 compiler/tokens.pas svneol=native#text/plain
+compiler/triplet.pas svneol=native#text/plain
 compiler/utils/Makefile svneol=native#text/plain
 compiler/utils/Makefile svneol=native#text/plain
 compiler/utils/Makefile.fpc svneol=native#text/plain
 compiler/utils/Makefile.fpc svneol=native#text/plain
 compiler/utils/README.txt svneol=native#text/plain
 compiler/utils/README.txt svneol=native#text/plain
@@ -902,6 +918,7 @@ compiler/x86_64/rax64att.pas svneol=native#text/plain
 compiler/x86_64/rax64int.pas svneol=native#text/plain
 compiler/x86_64/rax64int.pas svneol=native#text/plain
 compiler/x86_64/rgcpu.pas svneol=native#text/plain
 compiler/x86_64/rgcpu.pas svneol=native#text/plain
 compiler/x86_64/symcpu.pas svneol=native#text/plain
 compiler/x86_64/symcpu.pas svneol=native#text/plain
+compiler/x86_64/tripletcpu.pas svneol=native#text/plain
 compiler/x86_64/win64unw.pas svneol=native#text/plain
 compiler/x86_64/win64unw.pas svneol=native#text/plain
 compiler/x86_64/x8664ats.inc svneol=native#text/plain
 compiler/x86_64/x8664ats.inc svneol=native#text/plain
 compiler/x86_64/x8664att.inc svneol=native#text/plain
 compiler/x86_64/x8664att.inc svneol=native#text/plain
@@ -12853,6 +12870,7 @@ tests/tbs/tb0657.pp svneol=native#text/pascal
 tests/tbs/tb0665.pp svneol=native#text/pascal
 tests/tbs/tb0665.pp svneol=native#text/pascal
 tests/tbs/tb0666a.pp svneol=native#text/pascal
 tests/tbs/tb0666a.pp svneol=native#text/pascal
 tests/tbs/tb0666b.pp svneol=native#text/pascal
 tests/tbs/tb0666b.pp svneol=native#text/pascal
+tests/tbs/tb0669.pp svneol=native#text/pascal
 tests/tbs/tb205.pp svneol=native#text/plain
 tests/tbs/tb205.pp svneol=native#text/plain
 tests/tbs/tb610.pp svneol=native#text/pascal
 tests/tbs/tb610.pp svneol=native#text/pascal
 tests/tbs/tb613.pp svneol=native#text/plain
 tests/tbs/tb613.pp svneol=native#text/plain
@@ -12985,13 +13003,6 @@ tests/test/cg/obj/darwin/aarch64/tcext3.o -text
 tests/test/cg/obj/darwin/aarch64/tcext4.o -text
 tests/test/cg/obj/darwin/aarch64/tcext4.o -text
 tests/test/cg/obj/darwin/aarch64/tcext5.o -text
 tests/test/cg/obj/darwin/aarch64/tcext5.o -text
 tests/test/cg/obj/darwin/aarch64/tcext6.o -text
 tests/test/cg/obj/darwin/aarch64/tcext6.o -text
-tests/test/cg/obj/darwin/arm/cpptcl1.o -text
-tests/test/cg/obj/darwin/arm/cpptcl2.o -text
-tests/test/cg/obj/darwin/arm/ctest.o -text
-tests/test/cg/obj/darwin/arm/tcext3.o -text
-tests/test/cg/obj/darwin/arm/tcext4.o -text
-tests/test/cg/obj/darwin/arm/tcext5.o -text
-tests/test/cg/obj/darwin/arm/tcext6.o -text
 tests/test/cg/obj/darwin/i386/cpptcl1.o -text
 tests/test/cg/obj/darwin/i386/cpptcl1.o -text
 tests/test/cg/obj/darwin/i386/cpptcl2.o -text
 tests/test/cg/obj/darwin/i386/cpptcl2.o -text
 tests/test/cg/obj/darwin/i386/ctest.o -text
 tests/test/cg/obj/darwin/i386/ctest.o -text
@@ -13048,6 +13059,20 @@ tests/test/cg/obj/haiku/i386/tcext3.o -text
 tests/test/cg/obj/haiku/i386/tcext4.o -text
 tests/test/cg/obj/haiku/i386/tcext4.o -text
 tests/test/cg/obj/haiku/i386/tcext5.o -text
 tests/test/cg/obj/haiku/i386/tcext5.o -text
 tests/test/cg/obj/haiku/i386/tcext6.o -text
 tests/test/cg/obj/haiku/i386/tcext6.o -text
+tests/test/cg/obj/ios/aarch64/cpptcl1.o -text
+tests/test/cg/obj/ios/aarch64/cpptcl2.o -text
+tests/test/cg/obj/ios/aarch64/ctest.o -text
+tests/test/cg/obj/ios/aarch64/tcext3.o -text
+tests/test/cg/obj/ios/aarch64/tcext4.o -text
+tests/test/cg/obj/ios/aarch64/tcext5.o -text
+tests/test/cg/obj/ios/aarch64/tcext6.o -text
+tests/test/cg/obj/ios/arm/cpptcl1.o -text
+tests/test/cg/obj/ios/arm/cpptcl2.o -text
+tests/test/cg/obj/ios/arm/ctest.o -text
+tests/test/cg/obj/ios/arm/tcext3.o -text
+tests/test/cg/obj/ios/arm/tcext4.o -text
+tests/test/cg/obj/ios/arm/tcext5.o -text
+tests/test/cg/obj/ios/arm/tcext6.o -text
 tests/test/cg/obj/linux/aarch64/cpptcl1.o -text
 tests/test/cg/obj/linux/aarch64/cpptcl1.o -text
 tests/test/cg/obj/linux/aarch64/cpptcl2.o -text
 tests/test/cg/obj/linux/aarch64/cpptcl2.o -text
 tests/test/cg/obj/linux/aarch64/ctest.o -text
 tests/test/cg/obj/linux/aarch64/ctest.o -text
@@ -17672,6 +17697,7 @@ tests/webtbs/tw37228.pp svneol=native#text/plain
 tests/webtbs/tw37322.pp svneol=native#text/pascal
 tests/webtbs/tw37322.pp svneol=native#text/pascal
 tests/webtbs/tw37323.pp svneol=native#text/pascal
 tests/webtbs/tw37323.pp svneol=native#text/pascal
 tests/webtbs/tw37355.pp svneol=native#text/pascal
 tests/webtbs/tw37355.pp svneol=native#text/pascal
+tests/webtbs/tw37397.pp svneol=native#text/plain
 tests/webtbs/tw3742.pp svneol=native#text/plain
 tests/webtbs/tw3742.pp svneol=native#text/plain
 tests/webtbs/tw3751.pp svneol=native#text/plain
 tests/webtbs/tw3751.pp svneol=native#text/plain
 tests/webtbs/tw3758.pp svneol=native#text/plain
 tests/webtbs/tw3758.pp svneol=native#text/plain

+ 1 - 1
Makefile.fpc

@@ -199,7 +199,7 @@ INSTALLOPTS=FPC=$(PPNEW) ZIPDESTDIR=$(BASEDIR) FPCMAKE=$(FPCMAKENEW)
 BuildOnlyBaseCPUs=jvm
 BuildOnlyBaseCPUs=jvm
 
 
 ifneq ($(wildcard utils),)
 ifneq ($(wildcard utils),)
-NOUTILSTARGETS=embedded gba nds msdos win16 macos $(BuildOnlyBaseCPUs)
+NOUTILSTARGETS=embedded gba nds msdos win16 macosclassic $(BuildOnlyBaseCPUs)
 ifeq ($(findstring $(OS_TARGET),$(NOUTILSTARGETS)),)
 ifeq ($(findstring $(OS_TARGET),$(NOUTILSTARGETS)),)
 ifdef BUILDFULLNATIVE
 ifdef BUILDFULLNATIVE
 UTILS=1
 UTILS=1

+ 1 - 1
compiler/Makefile.fpc

@@ -348,7 +348,7 @@ endif
 ifeq ($(OS_TARGET),win16)
 ifeq ($(OS_TARGET),win16)
 NoNativeBinaries=1
 NoNativeBinaries=1
 endif
 endif
-ifeq ($(OS_TARGET),macos)
+ifeq ($(OS_TARGET),macosclassic)
 NoNativeBinaries=1
 NoNativeBinaries=1
 endif
 endif
 
 

+ 1 - 1
compiler/aarch64/aasmcpu.pas

@@ -561,7 +561,7 @@ implementation
           exit;
           exit;
         { "ldr literal" must be a 32/64 bit LDR and have a symbol }
         { "ldr literal" must be a 32/64 bit LDR and have a symbol }
         if (ref.refaddr=addr_pic) and
         if (ref.refaddr=addr_pic) and
-           ((op<>A_LDR) or
+           (not (op in [A_LDR,A_B,A_BL]) or
             not(oppostfix in [PF_NONE,PF_W,PF_SW]) or
             not(oppostfix in [PF_NONE,PF_W,PF_SW]) or
             (not assigned(ref.symbol) and
             (not assigned(ref.symbol) and
              not assigned(ref.symboldata))) then
              not assigned(ref.symboldata))) then

+ 4 - 5
compiler/aarch64/agcpugas.pas

@@ -285,18 +285,17 @@ unit agcpugas;
 
 
        as_aarch64_clang_darwin_info : tasminfo =
        as_aarch64_clang_darwin_info : tasminfo =
           (
           (
-            id     : as_clang;
+            id     : as_clang_asdarwin;
             idtxt  : 'CLANG';
             idtxt  : 'CLANG';
             asmbin : 'clang';
             asmbin : 'clang';
-            asmcmd : '-c -o $OBJ $EXTRAOPT -arch arm64 $DARWINVERSION -x assembler $ASM';
-            supported_targets : [system_aarch64_darwin];
-            flags : [af_needar,af_smartlink_sections,af_supports_dwarf];
+            asmcmd : '-x assembler -c -target $TRIPLET -o $OBJ $EXTRAOPT -x assembler $ASM';
+            supported_targets : [system_aarch64_ios,system_aarch64_darwin];
+            flags : [af_needar,af_smartlink_sections,af_supports_dwarf,af_llvm];
             labelprefix : 'L';
             labelprefix : 'L';
             comment : '# ';
             comment : '# ';
             dollarsign: '$';
             dollarsign: '$';
           );
           );
 
 
-
 begin
 begin
   RegisterAssembler(as_aarch64_gas_info,TAArch64Assembler);
   RegisterAssembler(as_aarch64_gas_info,TAArch64Assembler);
   RegisterAssembler(as_aarch64_clang_darwin_info,TAArch64AppleAssembler);
   RegisterAssembler(as_aarch64_clang_darwin_info,TAArch64AppleAssembler);

+ 143 - 80
compiler/aarch64/cgcpu.pas

@@ -578,102 +578,165 @@ implementation
 
 
     procedure tcgaarch64.a_load_const_reg(list: TAsmList; size: tcgsize; a: tcgint; reg : tregister);
     procedure tcgaarch64.a_load_const_reg(list: TAsmList; size: tcgsize; a: tcgint; reg : tregister);
       var
       var
-        preva: tcgint;
         opc: tasmop;
         opc: tasmop;
-        shift,maxshift: byte;
+        shift: byte;
         so: tshifterop;
         so: tshifterop;
-        reginited: boolean;
-        mask: tcgint;
+        reginited,doinverted: boolean;
+        manipulated_a: tcgint;
+        leftover_a: word;
       begin
       begin
-        { if we load a value into a 32 bit register, it is automatically
-          zero-extended to 64 bit }
-        if (hi(a)=0) and
-           (size in [OS_64,OS_S64]) then
-          begin
-            size:=OS_32;
-            reg:=makeregsize(reg,size);
-          end;
-        { values <= 32 bit are stored in a 32 bit register }
-        if not(size in [OS_64,OS_S64]) then
-          a:=cardinal(a);
-
-        if size in [OS_64,OS_S64] then
-          begin
-            mask:=-1;
-            maxshift:=64;
-          end
-        else
-          begin
-            mask:=$ffffffff;
-            maxshift:=32;
-          end;
-        { single movn enough? (to be extended) }
-        shift:=16;
-        preva:=a;
-        repeat
-          if (a shr shift)=(mask shr shift) then
+        case a of
+          { Small positive number }
+          $0..$FFFF:
             begin
             begin
-              if shift=16 then
-                list.concat(taicpu.op_reg_const(A_MOVN,reg,not(word(preva))))
+              list.concat(taicpu.op_reg_const(A_MOVZ, reg, a));
+              Exit;
+            end;
+          { Small negative number }
+          -65536..-1:
+            begin
+              list.concat(taicpu.op_reg_const(A_MOVN, reg, Word(not a)));
+              Exit;
+            end;
+          { Can be represented as a negative number more compactly }
+          $FFFF0000..$FFFFFFFF:
+            begin
+              { if we load a value into a 32 bit register, it is automatically
+                zero-extended to 64 bit }
+              list.concat(taicpu.op_reg_const(A_MOVN, makeregsize(reg,OS_32), Word(not a)));
+              Exit;
+            end;
+          else
+            begin
+
+              if size in [OS_64,OS_S64] then
+                begin
+                  { Check to see if a is a valid shifter constant that can be encoded in ORR as is }
+                  if is_shifter_const(a,size) then
+                    begin
+                      list.concat(taicpu.op_reg_reg_const(A_ORR,reg,makeregsize(NR_XZR,size),a));
+                      Exit;
+                    end;
+
+                  { This determines whether this write can be peformed with an ORR followed by MOVK
+                    by copying the 2nd word to the 4th word for the ORR constant, then overwriting
+                    the 4th word (unless the word is.  The alternative would require 3 instructions }
+                  leftover_a := word(a shr 48);
+                  manipulated_a := (a and $0000FFFFFFFFFFFF);
+
+                  if manipulated_a = $0000FFFFFFFFFFFF then
+                    begin
+                      { This is even better, as we can just use a single MOVN on the last word }
+                      shifterop_reset(so);
+                      so.shiftmode := SM_LSL;
+                      so.shiftimm := 48;
+                      list.concat(taicpu.op_reg_const_shifterop(A_MOVN, reg, word(not leftover_a), so));
+                      Exit;
+                    end;
+
+                  manipulated_a := manipulated_a or (((a shr 16) and $FFFF) shl 48);
+                  { if manipulated_a = a, don't check, because is_shifter_const was already
+                    called for a and it returned False.  Reduces processing time. [Kit] }
+                  if (manipulated_a <> a) and is_shifter_const(manipulated_a, size) then
+                    begin
+                      list.concat(taicpu.op_reg_reg_const(A_ORR, reg, makeregsize(NR_XZR, size), manipulated_a));
+                      if (leftover_a <> 0) then
+                        begin
+                          shifterop_reset(so);
+                          so.shiftmode := SM_LSL;
+                          so.shiftimm := 48;
+                          list.concat(taicpu.op_reg_const_shifterop(A_MOVK, reg, leftover_a, so));
+                        end;
+                      Exit;
+                    end;
+
+                  case a of
+                    { If a is in the given negative range, it can be stored
+                      more efficiently if it is inverted.  }
+                    TCgInt($FFFF000000000000)..-65537:
+                      begin
+                        { NOTE: This excluded range can be more efficiently
+                          stored as the first 16 bits followed by a shifter constant }
+                        case a of
+                          TCgInt($FFFF0000FFFF0000)..TCgInt($FFFF0000FFFFFFFF):
+                            doinverted := False
+                          else
+                            begin
+                              doinverted := True;
+                              a := not a;
+                            end;
+                        end;
+                      end;
+
+                    else
+                      doinverted := False;
+                  end;
+                end
               else
               else
                 begin
                 begin
-                  shifterop_reset(so);
-                  so.shiftmode:=SM_LSL;
-                  so.shiftimm:=shift-16;
-                  list.concat(taicpu.op_reg_const_shifterop(A_MOVN,reg,not(word(preva)),so));
+                  a:=cardinal(a);
+                  doinverted:=False;
                 end;
                 end;
-              exit;
             end;
             end;
-          { only try the next 16 bits if the current one is all 1 bits, since
-            the movn will set all lower bits to 1 }
-          if word(a shr (shift-16))<>$ffff then
-            break;
-          inc(shift,16);
-        until shift=maxshift;
+        end;
+
         reginited:=false;
         reginited:=false;
         shift:=0;
         shift:=0;
-        { can be optimized later to use more movn }
+
+        if doinverted then
+          opc:=A_MOVN
+        else
+          opc:=A_MOVZ;
+
         repeat
         repeat
           { leftover is shifterconst? (don't check if we can represent it just
           { leftover is shifterconst? (don't check if we can represent it just
             as effectively with movz/movk, as this check is expensive) }
             as effectively with movz/movk, as this check is expensive) }
-          if ((shift<tcgsize2size[size]*(8 div 2)) and
-              (word(a)<>0) and
-              ((a shr 16)<>0)) and
-             is_shifter_const(a shl shift,size) then
+          if (word(a)<>0) then
             begin
             begin
-              if reginited then
-                list.concat(taicpu.op_reg_reg_const(A_ORR,reg,reg,a shl shift))
+
+              if not doinverted and
+                ((shift<tcgsize2size[size]*(8 div 2)) and
+                  ((a shr 16)<>0)) and
+                 is_shifter_const(a shl shift,size) then
+                begin
+                  if reginited then
+                    list.concat(taicpu.op_reg_reg_const(A_ORR,reg,reg,a shl shift))
+                  else
+                    list.concat(taicpu.op_reg_reg_const(A_ORR,reg,makeregsize(NR_XZR,size),a shl shift));
+
+                  exit;
+                end;
+
+              { set all 16 bit parts <> 0 }
+              if shift=0 then
+                begin
+                  list.concat(taicpu.op_reg_const(opc,reg,word(a)));
+                  reginited:=true;
+                end
               else
               else
-                list.concat(taicpu.op_reg_reg_const(A_ORR,reg,makeregsize(NR_XZR,size),a shl shift));
-              exit;
+                begin
+                  shifterop_reset(so);
+                  so.shiftmode:=SM_LSL;
+                  so.shiftimm:=shift;
+                  if not reginited then
+                    begin
+                      list.concat(taicpu.op_reg_const_shifterop(opc,reg,word(a),so));
+                      reginited:=true;
+                    end
+                  else
+                    begin
+                      if doinverted then
+                        list.concat(taicpu.op_reg_const_shifterop(A_MOVK,reg,word(not a),so))
+                      else
+                        list.concat(taicpu.op_reg_const_shifterop(A_MOVK,reg,word(a),so));
+                    end;
+                end;
             end;
             end;
-          { set all 16 bit parts <> 0 }
-          if (word(a)<>0) or
-             ((shift=0) and
-              (a=0)) then
-            if shift=0 then
-              begin
-                list.concat(taicpu.op_reg_const(A_MOVZ,reg,word(a)));
-                reginited:=true;
-              end
-            else
-              begin
-                shifterop_reset(so);
-                so.shiftmode:=SM_LSL;
-                so.shiftimm:=shift;
-                if not reginited then
-                  begin
-                    opc:=A_MOVZ;
-                    reginited:=true;
-                  end
-                else
-                  opc:=A_MOVK;
-                list.concat(taicpu.op_reg_const_shifterop(opc,reg,word(a),so));
-              end;
-            preva:=a;
-            a:=a shr 16;
-           inc(shift,16);
-        until word(preva)=preva;
+
+          a:=a shr 16;
+          inc(shift,16);
+        until a = 0;
+
         if not reginited then
         if not reginited then
           internalerror(2014102702);
           internalerror(2014102702);
       end;
       end;

+ 12 - 1
compiler/aarch64/cpupara.pas

@@ -352,6 +352,7 @@ unit cpupara;
     function  tcpuparamanager.get_funcretloc(p : tabstractprocdef; side: tcallercallee; forcetempdef: tdef): tcgpara;
     function  tcpuparamanager.get_funcretloc(p : tabstractprocdef; side: tcallercallee; forcetempdef: tdef): tcgpara;
       var
       var
         retcgsize: tcgsize;
         retcgsize: tcgsize;
+        otherside: tcallercallee;
       begin
       begin
          if set_common_funcretloc_info(p,forcetempdef,retcgsize,result) then
          if set_common_funcretloc_info(p,forcetempdef,retcgsize,result) then
            exit;
            exit;
@@ -359,7 +360,13 @@ unit cpupara;
          { in this case, it must be returned in registers as if it were passed
          { in this case, it must be returned in registers as if it were passed
            as the first parameter }
            as the first parameter }
          init_para_alloc_values;
          init_para_alloc_values;
-         alloc_para(result,p,vs_value,side,result.def,false,false);
+         { if we're on the callee side, filling the result location is actually the "callerside"
+          as far passing it as a parameter value is concerned }
+         if side=callerside then
+           otherside:=calleeside
+         else
+           otherside:=callerside;
+         alloc_para(result,p,vs_value,otherside,result.def,false,false);
          { sanity check (LOC_VOID for empty records) }
          { sanity check (LOC_VOID for empty records) }
          if not assigned(result.location) or
          if not assigned(result.location) or
             not(result.location^.loc in [LOC_REGISTER,LOC_MMREGISTER,LOC_VOID]) then
             not(result.location^.loc in [LOC_REGISTER,LOC_MMREGISTER,LOC_VOID]) then
@@ -615,6 +622,10 @@ unit cpupara;
                begin
                begin
                   paraloc^.size:=paracgsize;
                   paraloc^.size:=paracgsize;
                   paraloc^.loc:=LOC_REFERENCE;
                   paraloc^.loc:=LOC_REFERENCE;
+                  if assigned(hfabasedef) then
+                    paraloc^.def:=carraydef.getreusable_no_free(hfabasedef,paralen div hfabasedef.size)
+                  else
+                    paraloc^.def:=paradef;
 
 
                   { the current stack offset may not be properly aligned in
                   { the current stack offset may not be properly aligned in
                     case we're on Darwin and have allocated a non-variadic argument
                     case we're on Darwin and have allocated a non-variadic argument

+ 2 - 2
compiler/aarch64/cputarg.pas

@@ -38,8 +38,8 @@ implementation
     {$ifndef NOTARGETLINUX}
     {$ifndef NOTARGETLINUX}
       ,t_linux
       ,t_linux
     {$endif}
     {$endif}
-    {$ifndef NOTARGETBSD}
-      ,t_bsd
+    {$ifndef NOTARGETDARWIN}
+      ,t_darwin
     {$endif}
     {$endif}
     {$ifndef NOTARGETANDROID}
     {$ifndef NOTARGETANDROID}
       ,t_android
       ,t_android

+ 48 - 0
compiler/aarch64/tripletcpu.pas

@@ -0,0 +1,48 @@
+{
+    Copyright (c) 2020 by Jonas Maebe
+
+    Construct the cpu part of the triplet
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit tripletcpu;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+  globtype;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+
+implementation
+
+uses
+  globals, systems, cpuinfo;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+  begin
+    if target_info.system in systems_darwin then
+      result:='arm64'
+    else
+      result:='aarch64'
+  end;
+
+
+end.
+

+ 198 - 0
compiler/aasmcfi.pas

@@ -0,0 +1,198 @@
+{
+    Copyright (c) 2019 by Jonas Maebe, member of the
+    Free Pascal Compiler development team
+
+    Dwarf Call Frame Information directives
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit aasmcfi;
+
+{$i fpcdefs.inc}
+
+  interface
+
+    uses
+      globtype,
+      cgbase,
+      aasmtai;
+
+    type
+      tcfikind =
+        (cfi_startproc,
+         cfi_endproc,
+         cfi_personality,
+         cfi_personality_id,
+         cfi_fde_data,
+         cfi_lsda_encoding,
+         cfi_inline_lsda,
+         cfi_def_cfa,
+         cfi_def_cfa_register,
+         cfi_def_cfa_offset,
+         cfi_adjust_cfa_offset,
+         cfi_offset,
+         cfi_val_offset,
+         cfi_rel_offset,
+         cfi_register,
+         cfi_restore,
+         cfi_undefined,
+         cfi_same_value,
+         cfi_remember_state,
+         cfi_restore_state,
+         cfi_return_column,
+         cfi_signal_frame,
+         cfi_window_save,
+         cfi_escape,
+         cfi_val_encoded_addr
+        );
+
+{$push}
+{$j-}
+      const
+        cfi2str: array[tcfikind] of string[length('.cfi_adjust_cfa_offset')] =
+          ('.cfi_startproc',
+           '.cfi_endproc',
+           '.cfi_personality',
+           '.cfi_personality_id',
+           '.cfi_fde_data',
+           '.cfi_lsda_encoding',
+           '.cfi_inline_lsda',
+           '.cfi_def_cfa',
+           '.cfi_def_cfa_register',
+           '.cfi_def_cfa_offset',
+           '.cfi_adjust_cfa_offset',
+           '.cfi_offset',
+           '.cfi_val_offset',
+           '.cfi_rel_offset',
+           '.cfi_register',
+           '.cfi_restore',
+           '.cfi_undefined',
+           '.cfi_same_value',
+           '.cfi_remember_state',
+           '.cfi_restore_state',
+           '.cfi_return_column',
+           '.cfi_signal_frame',
+           '.cfi_window_save',
+           '.cfi_escape',
+           '.cfi_val_encoded_addr'
+          );
+{$pop}
+
+    type
+      tai_cfi_base = class abstract(tai)
+        cfityp: tcfikind;
+        constructor create(ctyp: tcfikind);
+      end;
+
+      tai_cfi_op_none = class(tai_cfi_base)
+      end;
+
+      tai_cfi_op_val = class(tai_cfi_base)
+        val1: aint;
+        constructor create(ctyp: tcfikind; const a: aint);
+      end;
+
+      tai_cfi_op_string = class(tai_cfi_base)
+        s1: TSymStr;
+        constructor create(ctyp: tcfikind; const str1: TSymStr);
+      end;
+
+      tai_cfi_op_val_string = class(tai_cfi_op_val)
+        s: TSymStr;
+        constructor create(ctyp: tcfikind; const a: aint; const str: TSymStr);
+      end;
+
+      tai_cfi_op_string_string = class(tai_cfi_op_string)
+        s2: TSymStr;
+        constructor create(ctyp: tcfikind; const str1, str2: TSymStr);
+      end;
+
+      tai_cfi_op_reg = class(tai_cfi_base)
+        reg1: tregister;
+        constructor create(ctyp: tcfikind; r: tregister);
+      end;
+
+      tai_cfi_op_reg_val = class(tai_cfi_op_reg)
+        val: aint;
+        constructor create(ctyp: tcfikind; r: tregister; a: aint);
+      end;
+
+      tai_cfi_op_reg_reg = class(tai_cfi_op_reg)
+        reg2: tregister;
+        constructor create(ctyp: tcfikind; r1, r2: tregister);
+      end;
+
+
+  implementation
+
+    constructor tai_cfi_base.create(ctyp: tcfikind);
+      begin
+        typ:=ait_cfi;
+        cfityp:=ctyp;
+      end;
+
+
+    constructor tai_cfi_op_val.create(ctyp: tcfikind; const a: aint);
+      begin
+        inherited create(ctyp);
+        val1:=a;
+      end;
+
+
+    constructor tai_cfi_op_string.create(ctyp: tcfikind; const str1: TSymStr);
+      begin
+        inherited create(ctyp);
+        s1:=str1;
+      end;
+
+
+    constructor tai_cfi_op_val_string.create(ctyp: tcfikind; const a: aint; const str: TSymStr);
+      begin
+        inherited create(ctyp,a);
+        s:=str;
+      end;
+
+
+    constructor tai_cfi_op_string_string.create(ctyp: tcfikind; const str1, str2: TSymStr);
+      begin
+        inherited create(ctyp,str1);
+        s2:=str2;
+      end;
+
+
+    constructor tai_cfi_op_reg.create(ctyp: tcfikind; r: tregister);
+      begin
+        inherited create(ctyp);
+        reg1:=r;
+      end;
+
+
+    constructor tai_cfi_op_reg_val.create(ctyp: tcfikind; r: tregister; a: aint);
+      begin
+        inherited create(ctyp,r);
+        val:=a;
+      end;
+
+
+    constructor tai_cfi_op_reg_reg.create(ctyp: tcfikind; r1, r2: tregister);
+      begin
+        inherited create(ctyp,r1);
+        reg2:=r2;
+      end;
+
+end.
+

+ 1 - 0
compiler/aasmcnst.pas

@@ -1096,6 +1096,7 @@ implementation
              secname:=make_mangledname(basename,st,'2_'+itemname);
              secname:=make_mangledname(basename,st,'2_'+itemname);
            exclude(options,tcalo_vectorized_dead_strip_item);
            exclude(options,tcalo_vectorized_dead_strip_item);
          end;
          end;
+       current_module.linkorderedsymbols.concat(sym.Name);
        finalize_asmlist(sym,def,sectype,secname,alignment,options);
        finalize_asmlist(sym,def,sectype,secname,alignment,options);
      end;
      end;
 
 

+ 6 - 2
compiler/aasmtai.pas

@@ -89,7 +89,9 @@ interface
           ait_llvmdecl, { llvm symbol declaration (global/external variable, external procdef) }
           ait_llvmdecl, { llvm symbol declaration (global/external variable, external procdef) }
 {$endif}
 {$endif}
           { SEH directives used in ARM,MIPS and x86_64 COFF targets }
           { SEH directives used in ARM,MIPS and x86_64 COFF targets }
-          ait_seh_directive
+          ait_seh_directive,
+          { Dwarf CFI directive }
+          ait_cfi
           );
           );
 
 
         taiconst_type = (
         taiconst_type = (
@@ -217,6 +219,7 @@ interface
           'llvmalias',
           'llvmalias',
           'llvmdecl',
           'llvmdecl',
 {$endif}
 {$endif}
+          'cfi',
           'seh_directive'
           'seh_directive'
           );
           );
 
 
@@ -312,7 +315,8 @@ interface
 {$ifdef llvm}
 {$ifdef llvm}
                      ait_llvmdecl,
                      ait_llvmdecl,
 {$endif llvm}
 {$endif llvm}
-                     ait_seh_directive
+                     ait_seh_directive,
+                     ait_cfi
                     ];
                     ];
 
 
 
 

+ 42 - 3
compiler/aggas.pas

@@ -32,7 +32,7 @@ interface
 
 
     uses
     uses
       globtype,globals,
       globtype,globals,
-      aasmbase,aasmtai,aasmdata,
+      aasmbase,aasmtai,aasmdata,aasmcfi,
       assemble;
       assemble;
 
 
     type
     type
@@ -68,6 +68,7 @@ interface
         setcount: longint;
         setcount: longint;
         procedure WriteDecodedSleb128(a: int64);
         procedure WriteDecodedSleb128(a: int64);
         procedure WriteDecodedUleb128(a: qword);
         procedure WriteDecodedUleb128(a: qword);
+        procedure WriteCFI(hp: tai_cfi_base);
         function NextSetLabel: string;
         function NextSetLabel: string;
        protected
        protected
         InstrWriter: TCPUInstrWriter;
         InstrWriter: TCPUInstrWriter;
@@ -478,7 +479,8 @@ implementation
          system_i386_iphonesim,
          system_i386_iphonesim,
          system_powerpc64_darwin,
          system_powerpc64_darwin,
          system_x86_64_darwin,
          system_x86_64_darwin,
-         system_arm_darwin,
+         system_arm_ios,
+         system_aarch64_ios,
          system_aarch64_darwin,
          system_aarch64_darwin,
          system_x86_64_iphonesim,
          system_x86_64_iphonesim,
          system_powerpc_aix,
          system_powerpc_aix,
@@ -538,7 +540,7 @@ implementation
                   system_i386_darwin,
                   system_i386_darwin,
                   system_i386_iphonesim:
                   system_i386_iphonesim:
                     writer.AsmWriteln('__IMPORT,__jump_table,symbol_stubs,self_modifying_code+pure_instructions,5');
                     writer.AsmWriteln('__IMPORT,__jump_table,symbol_stubs,self_modifying_code+pure_instructions,5');
-                  system_arm_darwin:
+                  system_arm_ios:
                     if (cs_create_pic in current_settings.moduleswitches) then
                     if (cs_create_pic in current_settings.moduleswitches) then
                       writer.AsmWriteln('__TEXT,__picsymbolstub4,symbol_stubs,none,16')
                       writer.AsmWriteln('__TEXT,__picsymbolstub4,symbol_stubs,none,16')
                     else
                     else
@@ -591,6 +593,39 @@ implementation
       end;
       end;
 
 
 
 
+    procedure TGNUAssembler.WriteCFI(hp: tai_cfi_base);
+      begin
+        writer.AsmWrite(cfi2str[hp.cfityp]);
+        case hp.cfityp of
+          cfi_startproc,
+          cfi_endproc:
+            ;
+          cfi_undefined,
+          cfi_restore,
+          cfi_def_cfa_register:
+            begin
+              writer.AsmWrite(' ');
+              writer.AsmWrite(gas_regname(tai_cfi_op_reg(hp).reg1));
+            end;
+          cfi_def_cfa_offset:
+            begin
+              writer.AsmWrite(' ');
+              writer.AsmWrite(tostr(tai_cfi_op_val(hp).val1));
+            end;
+          cfi_offset:
+            begin
+              writer.AsmWrite(' ');
+              writer.AsmWrite(gas_regname(tai_cfi_op_reg_val(hp).reg1));
+              writer.AsmWrite(',');
+              writer.AsmWrite(tostr(tai_cfi_op_reg_val(hp).val));
+            end;
+          else
+            internalerror(2019030203);
+        end;
+        writer.AsmLn;
+      end;
+
+
     procedure TGNUAssembler.WriteDecodedSleb128(a: int64);
     procedure TGNUAssembler.WriteDecodedSleb128(a: int64);
       var
       var
         i,len : longint;
         i,len : longint;
@@ -1400,6 +1435,10 @@ implementation
                    std_regname(tai_varloc(hp).newlocation)));
                    std_regname(tai_varloc(hp).newlocation)));
                writer.AsmLn;
                writer.AsmLn;
              end;
              end;
+           ait_cfi:
+             begin
+               WriteCFI(tai_cfi_base(hp));
+             end;
            else
            else
              internalerror(2006012201);
              internalerror(2006012201);
          end;
          end;

+ 5 - 2
compiler/aoptobj.pas

@@ -378,6 +378,7 @@ Unit AoptObj;
       globals,
       globals,
       verbose,
       verbose,
       aoptutils,
       aoptutils,
+      aasmcfi,
       procinfo;
       procinfo;
 
 
 
 
@@ -1554,8 +1555,10 @@ Unit AoptObj;
                                      (JumpTargetOp(taicpu(hp1))^.ref^.symbol is TAsmLabel) then
                                      (JumpTargetOp(taicpu(hp1))^.ref^.symbol is TAsmLabel) then
                                      TAsmLabel(JumpTargetOp(taicpu(hp1))^.ref^.symbol).decrefs;
                                      TAsmLabel(JumpTargetOp(taicpu(hp1))^.ref^.symbol).decrefs;
                                   { don't kill start/end of assembler block,
                                   { don't kill start/end of assembler block,
-                                    no-line-info-start/end etc }
-                                  if hp1.typ<>ait_marker then
+                                    no-line-info-start/end, cfi end, etc }
+                                  if not(hp1.typ in [ait_align,ait_marker]) and
+                                     ((hp1.typ<>ait_cfi) or
+                                      (tai_cfi_base(hp1).cfityp<>cfi_endproc)) then
                                     begin
                                     begin
 {$ifdef cpudelayslot}
 {$ifdef cpudelayslot}
                                       if (hp1.typ=ait_instruction) and (taicpu(hp1).is_jmp) then
                                       if (hp1.typ=ait_instruction) and (taicpu(hp1).is_jmp) then

+ 18 - 5
compiler/arm/agarmgas.pas

@@ -49,6 +49,7 @@ unit agarmgas;
 
 
       TArmAppleGNUAssembler=class(TAppleGNUassembler)
       TArmAppleGNUAssembler=class(TAppleGNUassembler)
         constructor CreateWithWriter(info: pasminfo; wr: TExternalAssemblerOutputFile; freewriter, smart: boolean); override;
         constructor CreateWithWriter(info: pasminfo; wr: TExternalAssemblerOutputFile; freewriter, smart: boolean); override;
+        function MakeCmdLine: TCmdStr; override;
         procedure WriteExtraHeader; override;
         procedure WriteExtraHeader; override;
       end;
       end;
 
 
@@ -146,6 +147,18 @@ unit agarmgas;
       end;
       end;
 
 
 
 
+    function TArmAppleGNUAssembler.MakeCmdLine: TCmdStr;
+      begin
+        result:=inherited MakeCmdLine;
+	if (asminfo^.id in [as_clang_gas,as_clang_asdarwin]) then
+          begin
+            if fputypestrllvm[current_settings.fputype] <> '' then
+              result:='-m'+fputypestrllvm[current_settings.fputype]+' '+result;
+            { Apple arm always uses softfp floating point ABI }
+            result:='-mfloat-abi=softfp '+result;
+          end;
+      end;
+
     procedure TArmAppleGNUAssembler.WriteExtraHeader;
     procedure TArmAppleGNUAssembler.WriteExtraHeader;
       begin
       begin
         inherited WriteExtraHeader;
         inherited WriteExtraHeader;
@@ -421,7 +434,7 @@ unit agarmgas;
             idtxt  : 'AS-DARWIN';
             idtxt  : 'AS-DARWIN';
             asmbin : 'as';
             asmbin : 'as';
             asmcmd : '-o $OBJ $EXTRAOPT $ASM -arch $ARCH';
             asmcmd : '-o $OBJ $EXTRAOPT $ASM -arch $ARCH';
-            supported_targets : [system_arm_darwin];
+            supported_targets : [system_arm_ios];
             flags : [af_needar,af_smartlink_sections,af_supports_dwarf,af_stabs_use_function_absolute_addresses];
             flags : [af_needar,af_smartlink_sections,af_supports_dwarf,af_stabs_use_function_absolute_addresses];
             labelprefix : 'L';
             labelprefix : 'L';
             comment : '# ';
             comment : '# ';
@@ -431,12 +444,12 @@ unit agarmgas;
 
 
        as_arm_clang_darwin_info : tasminfo =
        as_arm_clang_darwin_info : tasminfo =
           (
           (
-            id     : as_clang;
+            id     : as_clang_asdarwin;
             idtxt  : 'CLANG';
             idtxt  : 'CLANG';
             asmbin : 'clang';
             asmbin : 'clang';
-            asmcmd : '-c -o $OBJ $EXTRAOPT -arch $ARCH $DARWINVERSION -x assembler $ASM';
-            supported_targets : [system_arm_darwin];
-            flags : [af_needar,af_smartlink_sections,af_supports_dwarf];
+            asmcmd : '-x assembler -c -target $TRIPLET -o $OBJ $EXTRAOPT -x assembler $ASM';
+            supported_targets : [system_arm_ios];
+            flags : [af_needar,af_smartlink_sections,af_supports_dwarf,af_llvm];
             labelprefix : 'L';
             labelprefix : 'L';
             comment : '# ';
             comment : '# ';
             dollarsign: '$';
             dollarsign: '$';

+ 3 - 3
compiler/arm/cgcpu.pas

@@ -274,7 +274,7 @@ unit cgcpu;
       begin
       begin
         inherited init_register_allocators;
         inherited init_register_allocators;
         { currently, we always save R14, so we can use it }
         { currently, we always save R14, so we can use it }
-        if (target_info.system<>system_arm_darwin) then
+        if (target_info.system<>system_arm_ios) then
             begin
             begin
               if assigned(current_procinfo) and (current_procinfo.framepointer<>NR_R11) then
               if assigned(current_procinfo) and (current_procinfo.framepointer<>NR_R11) then
                 rg[R_INTREGISTER]:=trgintcpu.create(R_INTREGISTER,R_SUBWHOLE,
                 rg[R_INTREGISTER]:=trgintcpu.create(R_INTREGISTER,R_SUBWHOLE,
@@ -2463,7 +2463,7 @@ unit cgcpu;
         indirection_done:=false;
         indirection_done:=false;
         if assigned(ref.symbol) then
         if assigned(ref.symbol) then
           begin
           begin
-            if (target_info.system=system_arm_darwin) and
+            if (target_info.system=system_arm_ios) and
                (ref.symbol.bind in [AB_EXTERNAL,AB_WEAK_EXTERNAL,AB_PRIVATE_EXTERN,AB_COMMON]) then
                (ref.symbol.bind in [AB_EXTERNAL,AB_WEAK_EXTERNAL,AB_PRIVATE_EXTERN,AB_COMMON]) then
               begin
               begin
                 tmpreg:=g_indirect_sym_load(list,ref.symbol.name,asmsym2indsymflags(ref.symbol));
                 tmpreg:=g_indirect_sym_load(list,ref.symbol.name,asmsym2indsymflags(ref.symbol));
@@ -4219,7 +4219,7 @@ unit cgcpu;
       begin
       begin
         inherited init_register_allocators;
         inherited init_register_allocators;
         { currently, we save R14 always, so we can use it }
         { currently, we save R14 always, so we can use it }
-        if (target_info.system<>system_arm_darwin) then
+        if (target_info.system<>system_arm_ios) then
           rg[R_INTREGISTER]:=trgintcputhumb2.create(R_INTREGISTER,R_SUBWHOLE,
           rg[R_INTREGISTER]:=trgintcputhumb2.create(R_INTREGISTER,R_SUBWHOLE,
               [RS_R0,RS_R1,RS_R2,RS_R3,RS_R4,RS_R5,RS_R6,RS_R7,RS_R8,
               [RS_R0,RS_R1,RS_R2,RS_R3,RS_R4,RS_R5,RS_R6,RS_R7,RS_R8,
                RS_R9,RS_R10,RS_R12,RS_R14],first_int_imreg,[])
                RS_R9,RS_R10,RS_R12,RS_R14],first_int_imreg,[])

+ 1 - 1
compiler/arm/cpuelf.pas

@@ -954,7 +954,7 @@ implementation
          idtxt  : 'ELF';
          idtxt  : 'ELF';
          asmbin : '';
          asmbin : '';
          asmcmd : '';
          asmcmd : '';
-         supported_targets : [system_arm_embedded,system_arm_darwin,
+         supported_targets : [system_arm_embedded,system_arm_ios,
                               system_arm_linux,system_arm_netbsd,
                               system_arm_linux,system_arm_netbsd,
                               system_arm_gba,system_arm_nds,
                               system_arm_gba,system_arm_nds,
                               system_arm_aros];
                               system_arm_aros];

+ 17 - 0
compiler/arm/cpuinfo.pas

@@ -73,6 +73,23 @@ Type
       fpu_vfpv4
       fpu_vfpv4
      );
      );
 
 
+Const
+  fputypestrllvm : array[tfputype] of string[13] = ('',
+    '',
+    '',
+    '',
+    '',
+    '',
+    'fpu=vfpv2',
+    'fpu=vfpv3',
+    'fpu=vfpv3-d16',
+    'fpu=vfpv4-s16',
+    'fpu=vfpv4'
+  );
+
+Type
+
+
    tcontrollertype =
    tcontrollertype =
      (ct_none,
      (ct_none,
 
 

+ 1 - 1
compiler/arm/cpupara.pas

@@ -63,7 +63,7 @@ unit cpupara;
 
 
     function tcpuparamanager.get_volatile_registers_int(calloption : tproccalloption):tcpuregisterset;
     function tcpuparamanager.get_volatile_registers_int(calloption : tproccalloption):tcpuregisterset;
       begin
       begin
-        if (target_info.system<>system_arm_darwin) then
+        if (target_info.system<>system_arm_ios) then
           result:=VOLATILE_INTREGISTERS
           result:=VOLATILE_INTREGISTERS
         else
         else
           result:=VOLATILE_INTREGISTERS_DARWIN;
           result:=VOLATILE_INTREGISTERS_DARWIN;

+ 1 - 1
compiler/arm/cpupi.pas

@@ -86,7 +86,7 @@ unit cpupi;
           end;
           end;
         if tg.direction = -1 then
         if tg.direction = -1 then
           begin
           begin
-            if (target_info.system<>system_arm_darwin) then
+            if (target_info.system<>system_arm_ios) then
               { Non-Darwin, worst case: r4-r10,r11,r13,r14,r15 is saved -> -28-16, but we
               { Non-Darwin, worst case: r4-r10,r11,r13,r14,r15 is saved -> -28-16, but we
                 always adjust the frame pointer to point to the first stored
                 always adjust the frame pointer to point to the first stored
                 register (= last register in list above) -> + 4 }
                 register (= last register in list above) -> + 4 }

+ 3 - 0
compiler/arm/cputarg.pas

@@ -62,6 +62,9 @@ implementation
     {$ifndef NOTARGETBSD}
     {$ifndef NOTARGETBSD}
       ,t_bsd
       ,t_bsd
     {$endif}
     {$endif}
+    {$ifndef NOTARGETDARWIN}
+      ,t_darwin
+    {$endif}
     {$ifndef NOTARGETAROS}
     {$ifndef NOTARGETAROS}
       ,t_aros
       ,t_aros
     {$endif}
     {$endif}

+ 51 - 0
compiler/arm/tripletcpu.pas

@@ -0,0 +1,51 @@
+{
+    Copyright (c) 2020 by Jonas Maebe
+
+    Construct the cpu part of the triplet
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit tripletcpu;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+  globtype;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+
+implementation
+
+uses
+  globals, cutils, systems, cpuinfo;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+  begin
+    result:=lower(cputypestr[current_settings.cputype]);
+    { llvm replaces the cpu name with thumb for when generating thumb code}
+    if (tripletstyle=triplet_llvm) and
+       (current_settings.instructionset=is_thumb) then
+      result:='thumb'+copy(result,4,255);
+    if target_info.endian=endian_big then
+      result:=result+'be';
+  end;
+
+
+end.
+

+ 9 - 13
compiler/assemble.pas

@@ -261,7 +261,7 @@ Implementation
 {$endif FPC_SOFT_FPUX80}
 {$endif FPC_SOFT_FPUX80}
 {$endif}
 {$endif}
       cscript,fmodule,verbose,
       cscript,fmodule,verbose,
-      cpuinfo,
+      cpuinfo,triplet,
       aasmcpu;
       aasmcpu;
 
 
     var
     var
@@ -741,7 +741,7 @@ Implementation
       begin
       begin
         DoPipe:=(cs_asm_pipe in current_settings.globalswitches) and
         DoPipe:=(cs_asm_pipe in current_settings.globalswitches) and
                 (([cs_asm_extern,cs_asm_leave,cs_link_on_target] * current_settings.globalswitches) = []) and
                 (([cs_asm_extern,cs_asm_leave,cs_link_on_target] * current_settings.globalswitches) = []) and
-                ((asminfo^.id in [as_gas,as_ggas,as_darwin,as_powerpc_xcoff,as_clang,as_solaris_as]));
+                ((asminfo^.id in [as_gas,as_ggas,as_darwin,as_powerpc_xcoff,as_clang_gas,as_clang_llvm,as_solaris_as]));
       end;
       end;
 
 
 
 
@@ -918,17 +918,13 @@ Implementation
 
 
       begin
       begin
         result:=asminfo^.asmcmd;
         result:=asminfo^.asmcmd;
-        { for Xcode 7.x and later }
-        if MacOSXVersionMin<>'' then
-          Replace(result,'$DARWINVERSION','-mmacosx-version-min='+MacOSXVersionMin)
-        else if iPhoneOSVersionMin<>'' then
-          Replace(result,'$DARWINVERSION','-miphoneos-version-min='+iPhoneOSVersionMin)
-        else
-          Replace(result,'$DARWINVERSION','');
+        if af_llvm in target_asm.flags then
+          Replace(result,'$TRIPLET',targettriplet(triplet_llvm))
 {$ifdef arm}
 {$ifdef arm}
-        if (target_info.system=system_arm_darwin) then
-          Replace(result,'$ARCH',lower(cputypestr[current_settings.cputype]));
+        else if (target_info.system=system_arm_ios) then
+          Replace(result,'$ARCH',lower(cputypestr[current_settings.cputype]))
 {$endif arm}
 {$endif arm}
+        ;
         if (cs_link_on_target in current_settings.globalswitches) then
         if (cs_link_on_target in current_settings.globalswitches) then
          begin
          begin
            Replace(result,'$ASM',maybequoted(ScriptFixFileName(AsmFileName)));
            Replace(result,'$ASM',maybequoted(ScriptFixFileName(AsmFileName)));
@@ -938,7 +934,7 @@ Implementation
          begin
          begin
 {$ifdef hasunix}
 {$ifdef hasunix}
           if DoPipe then
           if DoPipe then
-            if asminfo^.id<>as_clang then
+            if not(asminfo^.id in [as_clang_gas,as_clang_asdarwin,as_clang_llvm]) then
               Replace(result,'$ASM','')
               Replace(result,'$ASM','')
             else
             else
               Replace(result,'$ASM','-')
               Replace(result,'$ASM','-')
@@ -2352,7 +2348,7 @@ Implementation
       var
       var
         asmkind: tasm;
         asmkind: tasm;
       begin
       begin
-        for asmkind in [as_gas,as_ggas,as_darwin] do
+        for asmkind in [as_gas,as_ggas,as_darwin,as_clang_gas,as_clang_asdarwin] do
           if assigned(asminfos[asmkind]) and
           if assigned(asminfos[asmkind]) and
              (target_info.system in asminfos[asmkind]^.supported_targets) then
              (target_info.system in asminfos[asmkind]^.supported_targets) then
             begin
             begin

+ 45 - 0
compiler/avr/tripletcpu.pas

@@ -0,0 +1,45 @@
+{
+    Copyright (c) 2020 by Jonas Maebe
+
+    Construct the cpu part of the triplet
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit tripletcpu;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+  globtype;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+
+implementation
+
+uses
+  globals, cpuinfo;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+  begin
+    result:='avr';
+  end;
+
+
+end.
+

+ 122 - 13
compiler/cfidwarf.pas

@@ -29,7 +29,7 @@ interface
       cclasses,
       cclasses,
       globtype,
       globtype,
       cgbase,cpubase,
       cgbase,cpubase,
-      aasmbase,aasmtai,aasmdata;
+      aasmbase,aasmcfi,aasmtai,aasmdata;
 
 
     const
     const
       maxdwarfops = 2;
       maxdwarfops = 2;
@@ -60,6 +60,10 @@ interface
       end;
       end;
 
 
       TDwarfAsmCFI=class(TAsmCFI)
       TDwarfAsmCFI=class(TAsmCFI)
+        constructor create;override;
+      end;
+
+      TDwarfAsmCFILowLevel=class(TDwarfAsmCFI)
       private
       private
         FDwarfList : TLinkedList;
         FDwarfList : TLinkedList;
         FFrameStartLabel,
         FFrameStartLabel,
@@ -85,6 +89,19 @@ interface
       end;
       end;
 
 
 
 
+      TDwarfAsmCFIHighLevel=class(TDwarfAsmCFILowLevel)
+      public
+        procedure generate_code(list:TAsmList);override;
+
+        { operations }
+        procedure start_frame(list:TAsmList);override;
+        procedure end_frame(list:TAsmList);override;
+        procedure cfa_offset(list:TAsmList;reg:tregister;ofs:longint);override;
+        procedure cfa_restore(list:TAsmList;reg:tregister);override;
+        procedure cfa_def_cfa_register(list:TAsmList;reg:tregister);override;
+        procedure cfa_def_cfa_offset(list:TAsmList;ofs:longint);override;
+      end;
+
 implementation
 implementation
 
 
     uses
     uses
@@ -225,6 +242,17 @@ implementation
 ****************************************************************************}
 ****************************************************************************}
 
 
     constructor TDwarfAsmCFI.create;
     constructor TDwarfAsmCFI.create;
+      begin
+        inherited;
+      end;
+
+
+
+{****************************************************************************
+                             TDwarfAsmCFILowLevel
+****************************************************************************}
+
+    constructor TDwarfAsmCFILowLevel.create;
       begin
       begin
         inherited create;
         inherited create;
         FFrameStartLabel:=nil;
         FFrameStartLabel:=nil;
@@ -236,7 +264,7 @@ implementation
       end;
       end;
 
 
 
 
-    destructor TDwarfAsmCFI.destroy;
+    destructor TDwarfAsmCFILowLevel.destroy;
       begin
       begin
         FDwarfList.Free;
         FDwarfList.Free;
       end;
       end;
@@ -244,7 +272,7 @@ implementation
 
 
 {$ifdef i386}
 {$ifdef i386}
     { if more cpu dependend stuff is implemented, this needs more refactoring }
     { if more cpu dependend stuff is implemented, this needs more refactoring }
-    procedure TDwarfAsmCFI.generate_initial_instructions(list:TAsmList);
+    procedure TDwarfAsmCFILowLevel.generate_initial_instructions(list:TAsmList);
       begin
       begin
         list.concat(tai_const.create_8bit(DW_CFA_def_cfa));
         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(dwarf_reg(NR_STACK_POINTER_REG)));
@@ -255,7 +283,7 @@ implementation
       end;
       end;
 {$else i386}
 {$else i386}
     { if more cpu dependend stuff is implemented, this needs more refactoring }
     { if more cpu dependend stuff is implemented, this needs more refactoring }
-    procedure TDwarfAsmCFI.generate_initial_instructions(list:TAsmList);
+    procedure TDwarfAsmCFILowLevel.generate_initial_instructions(list:TAsmList);
       begin
       begin
         list.concat(tai_const.create_8bit(DW_CFA_def_cfa));
         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(dwarf_reg(NR_STACK_POINTER_REG)));
@@ -266,7 +294,7 @@ implementation
       end;
       end;
 {$endif i386}
 {$endif i386}
 
 
-    procedure TDwarfAsmCFI.generate_code(list:TAsmList);
+    procedure TDwarfAsmCFILowLevel.generate_code(list:TAsmList);
       var
       var
         hp : tdwarfitem;
         hp : tdwarfitem;
         cielabel,
         cielabel,
@@ -357,7 +385,7 @@ implementation
       end;
       end;
 
 
 
 
-    procedure TDwarfAsmCFI.start_frame(list:TAsmList);
+    procedure TDwarfAsmCFILowLevel.start_frame(list:TAsmList);
       begin
       begin
         if assigned(FFrameStartLabel) then
         if assigned(FFrameStartLabel) then
           internalerror(200404129);
           internalerror(200404129);
@@ -369,7 +397,7 @@ implementation
       end;
       end;
 
 
 
 
-    procedure TDwarfAsmCFI.end_frame(list:TAsmList);
+    procedure TDwarfAsmCFILowLevel.end_frame(list:TAsmList);
       begin
       begin
         if not assigned(FFrameStartLabel) then
         if not assigned(FFrameStartLabel) then
           internalerror(2004041213);
           internalerror(2004041213);
@@ -381,7 +409,7 @@ implementation
       end;
       end;
 
 
 
 
-    procedure TDwarfAsmCFI.cfa_advance_loc(list:TAsmList);
+    procedure TDwarfAsmCFILowLevel.cfa_advance_loc(list:TAsmList);
       var
       var
         currloclabel : tasmlabel;
         currloclabel : tasmlabel;
       begin
       begin
@@ -394,7 +422,7 @@ implementation
       end;
       end;
 
 
 
 
-    procedure TDwarfAsmCFI.cfa_offset(list:TAsmList;reg:tregister;ofs:longint);
+    procedure TDwarfAsmCFILowLevel.cfa_offset(list:TAsmList;reg:tregister;ofs:longint);
       begin
       begin
         cfa_advance_loc(list);
         cfa_advance_loc(list);
 { TODO: check if ref is a temp}
 { TODO: check if ref is a temp}
@@ -403,27 +431,108 @@ implementation
       end;
       end;
 
 
 
 
-    procedure TDwarfAsmCFI.cfa_restore(list:TAsmList;reg:tregister);
+    procedure TDwarfAsmCFILowLevel.cfa_restore(list:TAsmList;reg:tregister);
       begin
       begin
         cfa_advance_loc(list);
         cfa_advance_loc(list);
         DwarfList.concat(tdwarfitem.create_reg(DW_CFA_restore_extended,doe_uleb,reg));
         DwarfList.concat(tdwarfitem.create_reg(DW_CFA_restore_extended,doe_uleb,reg));
       end;
       end;
 
 
 
 
-    procedure TDwarfAsmCFI.cfa_def_cfa_register(list:TAsmList;reg:tregister);
+    procedure TDwarfAsmCFILowLevel.cfa_def_cfa_register(list:TAsmList;reg:tregister);
       begin
       begin
         cfa_advance_loc(list);
         cfa_advance_loc(list);
         DwarfList.concat(tdwarfitem.create_reg(DW_CFA_def_cfa_register,doe_uleb,reg));
         DwarfList.concat(tdwarfitem.create_reg(DW_CFA_def_cfa_register,doe_uleb,reg));
       end;
       end;
 
 
 
 
-    procedure TDwarfAsmCFI.cfa_def_cfa_offset(list:TAsmList;ofs:longint);
+    procedure TDwarfAsmCFILowLevel.cfa_def_cfa_offset(list:TAsmList;ofs:longint);
       begin
       begin
         cfa_advance_loc(list);
         cfa_advance_loc(list);
         DwarfList.concat(tdwarfitem.create_const(DW_CFA_def_cfa_offset,doe_uleb,ofs));
         DwarfList.concat(tdwarfitem.create_const(DW_CFA_def_cfa_offset,doe_uleb,ofs));
       end;
       end;
 
 
 
 
+{****************************************************************************
+                             TDwarfAsmCFILowLevel
+****************************************************************************}
+
+
+    procedure TDwarfAsmCFIHighLevel.generate_code(list: TAsmList);
+      begin
+        if not(tf_use_hlcfi in target_info.flags) then
+          begin
+            inherited;
+            exit;
+          end;
+      end;
+
+
+    procedure TDwarfAsmCFIHighLevel.start_frame(list: TAsmList);
+      begin
+        if not(tf_use_hlcfi in target_info.flags) then
+          begin
+            inherited;
+            exit;
+          end;
+        list.concat(tai_cfi_op_none.create(cfi_startproc));
+      end;
+
+
+    procedure TDwarfAsmCFIHighLevel.end_frame(list: TAsmList);
+      begin
+        if not(tf_use_hlcfi in target_info.flags) then
+          begin
+            inherited;
+            exit;
+          end;
+        list.concat(tai_cfi_op_none.create(cfi_endproc));
+      end;
+
+
+    procedure TDwarfAsmCFIHighLevel.cfa_offset(list: TAsmList; reg: tregister; ofs: longint);
+      begin
+        if not(tf_use_hlcfi in target_info.flags) then
+          begin
+            inherited;
+            exit;
+          end;
+        list.concat(tai_cfi_op_reg_val.create(cfi_offset,reg,ofs));
+      end;
+
+
+    procedure TDwarfAsmCFIHighLevel.cfa_restore(list: TAsmList; reg: tregister);
+      begin
+        if not(tf_use_hlcfi in target_info.flags) then
+          begin
+            inherited;
+            exit;
+          end;
+        list.concat(tai_cfi_op_reg.create(cfi_restore,reg));
+      end;
+
+
+    procedure TDwarfAsmCFIHighLevel.cfa_def_cfa_register(list: TAsmList; reg: tregister);
+      begin
+        if not(tf_use_hlcfi in target_info.flags) then
+          begin
+            inherited;
+            exit;
+          end;
+        list.concat(tai_cfi_op_reg.create(cfi_def_cfa_register,reg));
+      end;
+
+
+    procedure TDwarfAsmCFIHighLevel.cfa_def_cfa_offset(list: TAsmList; ofs: longint);
+      begin
+        if not(tf_use_hlcfi in target_info.flags) then
+          begin
+            inherited;
+            exit;
+          end;
+        list.concat(tai_cfi_op_val.create(cfi_def_cfa_offset,ofs));
+      end;
+
+
 begin
 begin
-  CAsmCFI:=TDwarfAsmCFI;
+  CAsmCFI:=TDwarfAsmCFIHighLevel;
 end.
 end.

+ 3 - 3
compiler/cfileutl.pas

@@ -526,7 +526,7 @@ end;
    function CurDirRelPath(systeminfo: tsysteminfo): TCmdStr;
    function CurDirRelPath(systeminfo: tsysteminfo): TCmdStr;
 
 
    begin
    begin
-     if systeminfo.system <> system_powerpc_macos then
+     if systeminfo.system <> system_powerpc_macosclassic then
        CurDirRelPath:= '.'+systeminfo.DirSep
        CurDirRelPath:= '.'+systeminfo.DirSep
      else
      else
        CurDirRelPath:= ':'
        CurDirRelPath:= ':'
@@ -877,7 +877,7 @@ end;
      var
      var
        i      : longint;
        i      : longint;
      begin
      begin
-       if source_info.system = system_powerpc_MACOS then
+       if source_info.system = system_powerpc_macosclassic then
          FixFileName:= TranslatePathToMac(s, true)
          FixFileName:= TranslatePathToMac(s, true)
        else
        else
         if (tf_files_case_aware in source_info.flags) or
         if (tf_files_case_aware in source_info.flags) or
@@ -940,7 +940,7 @@ end;
      var
      var
        i : longint;
        i : longint;
      begin
      begin
-       if target_info.system = system_powerpc_MACOS then
+       if target_info.system = system_powerpc_macosclassic then
          TargetFixFileName:= TranslatePathToMac(s, true)
          TargetFixFileName:= TranslatePathToMac(s, true)
        else
        else
         if (tf_files_case_aware in target_info.flags) or
         if (tf_files_case_aware in target_info.flags) or

+ 1 - 1
compiler/cgobj.pas

@@ -2750,7 +2750,7 @@ implementation
           system_i386_darwin,
           system_i386_darwin,
           system_i386_iphonesim,
           system_i386_iphonesim,
           system_powerpc64_darwin,
           system_powerpc64_darwin,
-          system_arm_darwin:
+          system_arm_ios:
             begin
             begin
               nlsymname:='L'+symname+'$non_lazy_ptr';
               nlsymname:='L'+symname+'$non_lazy_ptr';
               l:=current_asmdata.getasmsymbol(nlsymname);
               l:=current_asmdata.getasmsymbol(nlsymname);

+ 13 - 3
compiler/compiler.pas

@@ -81,21 +81,31 @@ uses
 {$ifdef beos}
 {$ifdef beos}
   ,i_beos
   ,i_beos
 {$endif beos}
 {$endif beos}
-{$ifdef fbsd}
-  ,i_fbsd
-{$endif fbsd}
+{$ifdef bsd}
+{$ifdef darwin}
+  ,i_darwin
+{$else darwin}
+  ,i_bsd
+{$endif darwin}
+{$endif bsd}
 {$ifdef gba}
 {$ifdef gba}
   ,i_gba
   ,i_gba
 {$endif gba}
 {$endif gba}
 {$ifdef go32v2}
 {$ifdef go32v2}
   ,i_go32v2
   ,i_go32v2
 {$endif go32v2}
 {$endif go32v2}
+{$ifdef haiku}
+  ,i_haiku
+{$endif haiku}
 {$ifdef linux}
 {$ifdef linux}
   ,i_linux
   ,i_linux
 {$endif linux}
 {$endif linux}
 {$ifdef macos}
 {$ifdef macos}
   ,i_macos
   ,i_macos
 {$endif macos}
 {$endif macos}
+{$ifdef morphos}
+  ,i_morphos
+{$endif morphos}
 {$ifdef nds}
 {$ifdef nds}
   ,i_nds
   ,i_nds
 {$endif nds}
 {$endif nds}

+ 1 - 1
compiler/comprsrc.pas

@@ -296,7 +296,7 @@ begin
             arch:=arch+'le';
             arch:=arch+'le';
         end;
         end;
       Replace(s,'$ARCH',arch);
       Replace(s,'$ARCH',arch);
-      if target_info.system=system_arm_darwin then
+      if target_info.system=system_arm_ios then
         subarch:=lower(cputypestr[current_settings.cputype]);
         subarch:=lower(cputypestr[current_settings.cputype]);
       Replace(s,'$SUBARCH',subarch);
       Replace(s,'$SUBARCH',subarch);
       case target_info.endian of
       case target_info.endian of

+ 1 - 1
compiler/dbgdwarf.pas

@@ -3619,7 +3619,7 @@ implementation
       begin
       begin
         { Reference all DEBUGINFO sections from the main .fpc section }
         { Reference all DEBUGINFO sections from the main .fpc section }
         { to prevent eliminating them by smartlinking                 }
         { to prevent eliminating them by smartlinking                 }
-        if (target_info.system in ([system_powerpc_macos]+systems_darwin)) then
+        if (target_info.system in ([system_powerpc_macosclassic]+systems_darwin)) then
           exit;
           exit;
         new_section(list,sec_fpc,'links',0);
         new_section(list,sec_fpc,'links',0);
 
 

+ 1 - 1
compiler/dbgstabs.pas

@@ -1853,7 +1853,7 @@ implementation
         dbgtable : tai_symbol;
         dbgtable : tai_symbol;
       begin
       begin
         { Reference all DEBUGINFO sections from the main .fpc section }
         { Reference all DEBUGINFO sections from the main .fpc section }
-        if (target_info.system in ([system_powerpc_macos]+systems_darwin)) then
+        if (target_info.system in ([system_powerpc_macosclassic]+systems_darwin)) then
           exit;
           exit;
         new_section(list,sec_fpc,'links',0);
         new_section(list,sec_fpc,'links',0);
         { make sure the debuginfo doesn't get stripped out }
         { make sure the debuginfo doesn't get stripped out }

+ 1 - 0
compiler/entfile.pas

@@ -119,6 +119,7 @@ const
   ibwpofile         = 84;
   ibwpofile         = 84;
   ibmoduleoptions   = 85;
   ibmoduleoptions   = 85;
   ibunitimportsyms  = 86;
   ibunitimportsyms  = 86;
+  iborderedsymbols  = 87;
 
 
   ibmainname       = 90;
   ibmainname       = 90;
   ibsymtableoptions = 91;
   ibsymtableoptions = 91;

+ 6 - 1
compiler/fmodule.pas

@@ -168,7 +168,8 @@ interface
         loaded_from   : tmodule;
         loaded_from   : tmodule;
         _exports      : tlinkedlist;
         _exports      : tlinkedlist;
         dllscannerinputlist : TFPHashList;
         dllscannerinputlist : TFPHashList;
-        resourcefiles : TCmdStrList;
+        resourcefiles,
+        linkorderedsymbols : TCmdStrList;
         linkunitofiles,
         linkunitofiles,
         linkunitstaticlibs,
         linkunitstaticlibs,
         linkunitsharedlibs,
         linkunitsharedlibs,
@@ -563,6 +564,7 @@ implementation
         used_units:=TLinkedList.Create;
         used_units:=TLinkedList.Create;
         dependent_units:=TLinkedList.Create;
         dependent_units:=TLinkedList.Create;
         resourcefiles:=TCmdStrList.Create;
         resourcefiles:=TCmdStrList.Create;
+        linkorderedsymbols:=TCmdStrList.Create;
         linkunitofiles:=TLinkContainer.Create;
         linkunitofiles:=TLinkContainer.Create;
         linkunitstaticlibs:=TLinkContainer.Create;
         linkunitstaticlibs:=TLinkContainer.Create;
         linkunitsharedlibs:=TLinkContainer.Create;
         linkunitsharedlibs:=TLinkContainer.Create;
@@ -683,6 +685,7 @@ implementation
         used_units.free;
         used_units.free;
         dependent_units.free;
         dependent_units.free;
         resourcefiles.Free;
         resourcefiles.Free;
+        linkorderedsymbols.Free;
         linkunitofiles.Free;
         linkunitofiles.Free;
         linkunitstaticlibs.Free;
         linkunitstaticlibs.Free;
         linkunitsharedlibs.Free;
         linkunitsharedlibs.Free;
@@ -839,6 +842,8 @@ implementation
         dependent_units:=TLinkedList.Create;
         dependent_units:=TLinkedList.Create;
         resourcefiles.Free;
         resourcefiles.Free;
         resourcefiles:=TCmdStrList.Create;
         resourcefiles:=TCmdStrList.Create;
+        linkorderedsymbols.Free;
+        linkorderedsymbols:=TCmdStrList.Create;;
         pendingspecializations.free;
         pendingspecializations.free;
         pendingspecializations:=tfphashobjectlist.create(false);
         pendingspecializations:=tfphashobjectlist.create(false);
         if assigned(waitingforunit) and
         if assigned(waitingforunit) and

+ 26 - 0
compiler/fppu.pas

@@ -97,6 +97,7 @@ interface
           procedure writederefdata;
           procedure writederefdata;
           procedure writeImportSymbols;
           procedure writeImportSymbols;
           procedure writeResources;
           procedure writeResources;
+          procedure writeOrderedSymbols;
           procedure writeunitimportsyms;
           procedure writeunitimportsyms;
           procedure writeasmsyms(kind:tunitasmlisttype;list:tfphashobjectlist);
           procedure writeasmsyms(kind:tunitasmlisttype;list:tfphashobjectlist);
           procedure readsourcefiles;
           procedure readsourcefiles;
@@ -106,6 +107,7 @@ interface
           procedure readderefdata;
           procedure readderefdata;
           procedure readImportSymbols;
           procedure readImportSymbols;
           procedure readResources;
           procedure readResources;
+          procedure readOrderedSymbols;
           procedure readwpofile;
           procedure readwpofile;
           procedure readunitimportsyms;
           procedure readunitimportsyms;
           procedure readasmsyms;
           procedure readasmsyms;
@@ -934,6 +936,20 @@ var
       end;
       end;
 
 
 
 
+    procedure tppumodule.writeOrderedSymbols;
+      var
+        res : TCmdStrListItem;
+      begin
+        res:=TCmdStrListItem(linkorderedsymbols.First);
+        while res<>nil do
+          begin
+            ppufile.putstring(res.FPStr);
+            res:=TCmdStrListItem(res.Next);
+          end;
+        ppufile.writeentry(iborderedsymbols);
+      end;
+
+
     procedure tppumodule.writeunitimportsyms;
     procedure tppumodule.writeunitimportsyms;
       var
       var
         i : longint;
         i : longint;
@@ -1240,6 +1256,13 @@ var
       end;
       end;
 
 
 
 
+    procedure tppumodule.readOrderedSymbols;
+      begin
+        while not ppufile.endofentry do
+          linkorderedsymbols.Concat(ppufile.getstring);
+      end;
+
+
     procedure tppumodule.readwpofile;
     procedure tppumodule.readwpofile;
       var
       var
         orgwpofilename: string;
         orgwpofilename: string;
@@ -1375,6 +1398,8 @@ var
                readderefdata;
                readderefdata;
              ibresources:
              ibresources:
                readResources;
                readResources;
+             iborderedsymbols:
+               readOrderedSymbols;
              ibwpofile:
              ibwpofile:
                readwpofile;
                readwpofile;
              ibendinterface :
              ibendinterface :
@@ -1510,6 +1535,7 @@ var
          writelinkcontainer(linkotherframeworks,iblinkotherframeworks,true);
          writelinkcontainer(linkotherframeworks,iblinkotherframeworks,true);
          writeImportSymbols;
          writeImportSymbols;
          writeResources;
          writeResources;
+         writeOrderedSymbols;
          ppufile.do_crc:=true;
          ppufile.do_crc:=true;
 
 
          { generate implementation deref data, the interface deref data is
          { generate implementation deref data, the interface deref data is

+ 35 - 0
compiler/globtype.pas

@@ -348,6 +348,41 @@ interface
        );
        );
        twpoptimizerswitches = set of twpoptimizerswitch;
        twpoptimizerswitches = set of twpoptimizerswitch;
 
 
+       { platform triplet style }
+       ttripletstyle = (
+         triplet_llvm
+         { , triple_gnu }
+       );
+
+       { module flags (extra unit flags not in ppu header) }
+       tmoduleflag = (
+         mf_init,                     { unit has initialization section }
+         mf_finalize,                 { unit has finalization section   }
+         mf_checkpointer_called,      { Unit uses experimental checkpointer test code }
+         mf_has_resourcestrings,      { unit has resource string section }
+         mf_release,                  { unit was compiled with -Ur option }
+         mf_threadvars,               { unit has threadvars }
+         mf_has_stabs_debuginfo,      { this unit has stabs debuginfo generated }
+         mf_local_symtable,           { this unit has a local symtable stored }
+         mf_uses_variants,            { this unit uses variants }
+         mf_has_resourcefiles,        { this unit has external resources (using $R directive)}
+         mf_has_exports,              { this module or a used unit has exports }
+         mf_has_dwarf_debuginfo,      { this unit has dwarf debuginfo generated }
+         mf_wideinits,                { this unit has winlike widestring typed constants }
+         mf_classinits,               { this unit has class constructors/destructors }
+         mf_resstrinits,              { this unit has string consts referencing resourcestrings }
+         mf_i8086_far_code,           { this unit uses an i8086 memory model with far code (i.e. medium, large or huge) }
+         mf_i8086_far_data,           { this unit uses an i8086 memory model with far data (i.e. compact or large) }
+         mf_i8086_huge_data,          { this unit uses an i8086 memory model with huge data (i.e. huge) }
+         mf_i8086_cs_equals_ds,       { this unit uses an i8086 memory model with CS=DS (i.e. tiny) }
+         mf_i8086_ss_equals_ds,       { this unit uses an i8086 memory model with SS=DS (i.e. tiny, small or medium) }
+         mf_package_deny,             { this unit must not be part of a package }
+         mf_package_weak,             { this unit may be completely contained in a package }
+         mf_llvm,                     { compiled for LLVM code generator, not compatible with regular compiler because of different nodes in inline functions }
+         mf_symansistr                { symbols are ansistrings (for ppudump) }
+       );
+       tmoduleflags = set of tmoduleflag;
+
     type
     type
        ttargetswitchinfo = record
        ttargetswitchinfo = record
           name: string[22];
           name: string[22];

+ 5 - 2
compiler/i386/aoptcpu.pas

@@ -53,6 +53,7 @@ unit aoptcpu;
       cpuinfo,
       cpuinfo,
       aasmcpu,
       aasmcpu,
       aoptutils,
       aoptutils,
+      aasmcfi,
       procinfo,
       procinfo,
       cgutils,
       cgutils,
       { units we should get rid off: }
       { units we should get rid off: }
@@ -534,8 +535,10 @@ begin
                       if not(hp1.typ in ([ait_label,ait_align]+skipinstr)) then
                       if not(hp1.typ in ([ait_label,ait_align]+skipinstr)) then
                         begin
                         begin
                           { don't kill start/end of assembler block,
                           { don't kill start/end of assembler block,
-                            no-line-info-start/end etc }
-                          if hp1.typ<>ait_marker then
+                            no-line-info-start/end, cfi end, etc }
+                          if not(hp1.typ in [ait_align,ait_marker]) and
+                             ((hp1.typ<>ait_cfi) or
+                              (tai_cfi_base(hp1).cfityp<>cfi_endproc)) then
                             begin
                             begin
                               asml.remove(hp1);
                               asml.remove(hp1);
                               hp1.free;
                               hp1.free;

+ 3 - 0
compiler/i386/cputarg.pas

@@ -44,6 +44,9 @@ implementation
     {$ifndef NOTARGETBSD}
     {$ifndef NOTARGETBSD}
       ,t_bsd
       ,t_bsd
     {$endif}
     {$endif}
+    {$ifndef NOTARGETDARWIN}
+      ,t_darwin
+    {$endif}
     {$ifndef NOTARGETSUNOS}
     {$ifndef NOTARGETSUNOS}
       ,t_sunos
       ,t_sunos
     {$endif}
     {$endif}

+ 49 - 0
compiler/i386/tripletcpu.pas

@@ -0,0 +1,49 @@
+{
+    Copyright (c) 2020 by Jonas Maebe
+
+    Construct the cpu part of the triplet
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit tripletcpu;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+  globtype;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+
+implementation
+
+uses
+  globals, systems, cpuinfo;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+  begin
+    if (target_info.system in systems_darwin) or
+       (current_settings.cputype<cpu_Pentium2) then
+      result:='i386'
+    else
+      result:='i686'
+  end;
+
+
+end.
+

+ 45 - 0
compiler/i8086/tripletcpu.pas

@@ -0,0 +1,45 @@
+{
+    Copyright (c) 2020 by Jonas Maebe
+
+    Construct the cpu part of the triplet
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit tripletcpu;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+  globtype;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+
+implementation
+
+uses
+  globals, cpuinfo;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+  begin
+    result:='i8086';
+  end;
+
+
+end.
+

+ 45 - 0
compiler/jvm/tripletcpu.pas

@@ -0,0 +1,45 @@
+{
+    Copyright (c) 2020 by Jonas Maebe
+
+    Construct the cpu part of the triplet
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit tripletcpu;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+  globtype;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+
+implementation
+
+uses
+  globals, cpuinfo;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+  begin
+    result:='jvm';
+  end;
+
+
+end.
+

+ 57 - 3
compiler/link.pas

@@ -55,7 +55,8 @@ interface
          ObjectFiles,
          ObjectFiles,
          SharedLibFiles,
          SharedLibFiles,
          StaticLibFiles,
          StaticLibFiles,
-         FrameworkFiles  : TCmdStrList;
+         FrameworkFiles,
+         OrderedSymbols: TCmdStrList;
          Constructor Create;virtual;
          Constructor Create;virtual;
          Destructor Destroy;override;
          Destructor Destroy;override;
          procedure AddModuleFiles(hp:tmodule);
          procedure AddModuleFiles(hp:tmodule);
@@ -65,6 +66,7 @@ interface
          Procedure AddStaticCLibrary(const S : TCmdStr);
          Procedure AddStaticCLibrary(const S : TCmdStr);
          Procedure AddSharedCLibrary(S : TCmdStr);
          Procedure AddSharedCLibrary(S : TCmdStr);
          Procedure AddFramework(S : TCmdStr);
          Procedure AddFramework(S : TCmdStr);
+         Procedure AddOrderedSymbol(const s: TCmdStr);
          procedure AddImportSymbol(const libname,symname,symmangledname:TCmdStr;OrdNr: longint;isvar:boolean);virtual;
          procedure AddImportSymbol(const libname,symname,symmangledname:TCmdStr;OrdNr: longint;isvar:boolean);virtual;
          Procedure InitSysInitUnitName;virtual;
          Procedure InitSysInitUnitName;virtual;
          Function  MakeExecutable:boolean;virtual;
          Function  MakeExecutable:boolean;virtual;
@@ -76,6 +78,8 @@ interface
        end;
        end;
 
 
       TExternalLinker = class(TLinker)
       TExternalLinker = class(TLinker)
+      protected
+         Function WriteSymbolOrderFile: TCmdStr;
       public
       public
          Info : TLinkerInfo;
          Info : TLinkerInfo;
          Constructor Create;override;
          Constructor Create;override;
@@ -85,6 +89,8 @@ interface
          Function  DoExec(const command:TCmdStr; para:TCmdStr;showinfo,useshell:boolean):boolean;
          Function  DoExec(const command:TCmdStr; para:TCmdStr;showinfo,useshell:boolean):boolean;
          procedure SetDefaultInfo;virtual;
          procedure SetDefaultInfo;virtual;
          Function  MakeStaticLibrary:boolean;override;
          Function  MakeStaticLibrary:boolean;override;
+
+         Function UniqueName(const str:TCmdStr): TCmdStr;
        end;
        end;
 
 
       TBooleanArray = array [1..1024] of boolean;
       TBooleanArray = array [1..1024] of boolean;
@@ -353,6 +359,7 @@ Implementation
         SharedLibFiles:=TCmdStrList.Create_no_double;
         SharedLibFiles:=TCmdStrList.Create_no_double;
         StaticLibFiles:=TCmdStrList.Create_no_double;
         StaticLibFiles:=TCmdStrList.Create_no_double;
         FrameworkFiles:=TCmdStrList.Create_no_double;
         FrameworkFiles:=TCmdStrList.Create_no_double;
+        OrderedSymbols:=TCmdStrList.Create;
       end;
       end;
 
 
 
 
@@ -362,6 +369,8 @@ Implementation
         SharedLibFiles.Free;
         SharedLibFiles.Free;
         StaticLibFiles.Free;
         StaticLibFiles.Free;
         FrameworkFiles.Free;
         FrameworkFiles.Free;
+        OrderedSymbols.Free;
+        inherited;
       end;
       end;
 
 
 
 
@@ -371,6 +380,7 @@ Implementation
         i,j  : longint;
         i,j  : longint;
         ImportLibrary : TImportLibrary;
         ImportLibrary : TImportLibrary;
         ImportSymbol  : TImportSymbol;
         ImportSymbol  : TImportSymbol;
+        cmdstritem: TCmdStrListItem;
       begin
       begin
         with hp do
         with hp do
          begin
          begin
@@ -468,6 +478,8 @@ Implementation
                      ImportSymbol.MangledName,ImportSymbol.OrdNr,ImportSymbol.IsVar);
                      ImportSymbol.MangledName,ImportSymbol.OrdNr,ImportSymbol.IsVar);
                  end;
                  end;
              end;
              end;
+           { ordered symbols }
+           OrderedSymbols.concatList(linkorderedsymbols);
          end;
          end;
       end;
       end;
 
 
@@ -536,6 +548,12 @@ Implementation
       end;
       end;
 
 
 
 
+    procedure TLinker.AddOrderedSymbol(const s: TCmdStr);
+      begin
+        OrderedSymbols.Concat(s);
+      end;
+
+
     Procedure TLinker.AddStaticCLibrary(const S:TCmdStr);
     Procedure TLinker.AddStaticCLibrary(const S:TCmdStr);
       var
       var
         ns : TCmdStr;
         ns : TCmdStr;
@@ -619,6 +637,30 @@ Implementation
                               TEXTERNALLINKER
                               TEXTERNALLINKER
 *****************************************************************************}
 *****************************************************************************}
 
 
+    Function TExternalLinker.WriteSymbolOrderFile: TCmdStr;
+      var
+        item: TCmdStrListItem;
+        symfile: TScript;
+      begin
+        result:='';
+        { only for darwin for now; can also enable for other platforms when using
+          the LLVM linker }
+        if (OrderedSymbols.Empty) or
+           not(tf_supports_symbolorderfile in target_info.flags) then
+          exit;
+        symfile:=TScript.Create(outputexedir+'symbol_order.fpc');
+        item:=TCmdStrListItem(OrderedSymbols.First);
+        while assigned(item) do
+          begin
+            symfile.add(item.str);
+            item:=TCmdStrListItem(item.next);
+          end;
+        symfile.WriteToDisk;
+        result:=symfile.fn;
+        symfile.Free;
+      end;
+
+
     Constructor TExternalLinker.Create;
     Constructor TExternalLinker.Create;
       begin
       begin
         inherited Create;
         inherited Create;
@@ -631,8 +673,8 @@ Implementation
           end
           end
         else
         else
           begin
           begin
-            Info.ResName:='link.res';
-            Info.ScriptName:='script.res';
+            Info.ResName:=UniqueName('link')+'.res';
+            Info.ScriptName:=UniqueName('script')+'.res';
           end;
           end;
         { set the linker specific defaults }
         { set the linker specific defaults }
         SetDefaultInfo;
         SetDefaultInfo;
@@ -910,6 +952,18 @@ Implementation
         MakeStaticLibrary:=success;
         MakeStaticLibrary:=success;
       end;
       end;
 
 
+    function TExternalLinker.UniqueName(const str: TCmdStr): TCmdStr;
+      const
+        pid: SizeUInt = 0;
+      begin
+        if pid=0 then
+          pid:=GetProcessID;
+        if pid>0 then
+          result:=str+tostr(pid)
+        else
+          result:=str;
+      end;
+
 
 
 {*****************************************************************************
 {*****************************************************************************
                               TINTERNALLINKER
                               TINTERNALLINKER

+ 245 - 11
compiler/llvm/agllvm.pas

@@ -72,7 +72,16 @@ interface
         InstrWriter: TLLVMInstrWriter;
         InstrWriter: TLLVMInstrWriter;
       end;
       end;
 
 
+<<<<<<< .working
 
 
+||||||| .merge-left.r45806
+      TLLVMLLCAssember=class(TLLVMAssember)
+      public
+       function MakeCmdLine: TCmdStr; override;
+      end;
+
+=======
+>>>>>>> .merge-right.r45807
       {# This is the base class for writing instructions.
       {# This is the base class for writing instructions.
 
 
          The WriteInstruction() method must be overridden
          The WriteInstruction() method must be overridden
@@ -101,7 +110,13 @@ implementation
       objcasm,
       objcasm,
       aasmcnst,symconst,symdef,symtable,
       aasmcnst,symconst,symdef,symtable,
       llvmbase,itllvm,llvmdef,
       llvmbase,itllvm,llvmdef,
+<<<<<<< .working
       cgbase,cgutils,cpubase,llvminfo;
       cgbase,cgutils,cpubase,llvminfo;
+||||||| .merge-left.r45806
+      cgbase,cgutils,cpubase,cpuinfo,llvminfo;
+=======
+      cgbase,cgutils,cpubase,cpuinfo,triplet,llvminfo;
+>>>>>>> .merge-right.r45807
 
 
     const
     const
       line_length = 70;
       line_length = 70;
@@ -815,7 +830,7 @@ implementation
         writer.AsmWrite(target_info.llvmdatalayout);
         writer.AsmWrite(target_info.llvmdatalayout);
         writer.AsmWriteln('"');
         writer.AsmWriteln('"');
         writer.AsmWrite('target triple = "');
         writer.AsmWrite('target triple = "');
-        writer.AsmWrite(llvm_target_name);
+        writer.AsmWrite(targettriplet(triplet_llvm));
         writer.AsmWriteln('"');
         writer.AsmWriteln('"');
       end;
       end;
 
 
@@ -1452,22 +1467,241 @@ implementation
        end;
        end;
 
 
 
 
+<<<<<<< .working
+||||||| .merge-left.r45806
+{****************************************************************************}
+{                               llc Assember                                 }
+{****************************************************************************}
+
+     function TLLVMLLCAssember.MakeCmdLine: TCmdStr;
+       var
+         optstr: TCmdStr;
+       begin
+         result:=inherited;
+         { standard optimization flags for llc -- todo: this needs to be split
+           into a call to opt and one to llc }
+         if cs_opt_level3 in current_settings.optimizerswitches then
+           optstr:='-O3'
+         else if cs_opt_level2 in current_settings.optimizerswitches then
+           optstr:='-O2'
+         else if cs_opt_level1 in current_settings.optimizerswitches then
+           optstr:='-O1'
+         else
+           optstr:='-O0';
+         { stack frame elimination }
+         if not(cs_opt_stackframe in current_settings.optimizerswitches) then
+           optstr:=optstr+' -disable-fp-elim';
+         { fast math }
+         if cs_opt_fastmath in current_settings.optimizerswitches then
+           optstr:=optstr+' -enable-unsafe-fp-math -fp-contract=fast';  { -enable-fp-mad support depends on version }
+         { smart linking }
+         if cs_create_smart in current_settings.moduleswitches then
+           optstr:=optstr+' -data-sections -function-sections';
+         { pic }
+         if cs_create_pic in current_settings.moduleswitches then
+           optstr:=optstr+' -relocation-model=pic'
+         else if not(target_info.system in systems_darwin) then
+           optstr:=optstr+' -relocation-model=static'
+         else
+           optstr:=optstr+' -relocation-model=dynamic-no-pic';
+         { force object output instead of textual assembler code }
+         optstr:=optstr+' -filetype=obj';
+         if fputypestrllvm[current_settings.fputype]<>'' then
+           optstr:=optstr+' -mattr=+'+fputypestrllvm[current_settings.fputype];
+         replace(result,'$OPT',optstr);
+       end;
+
+
+{****************************************************************************}
+{                               clang Assember                               }
+{****************************************************************************}
+
+    function TLLVMClangAssember.MakeCmdLine: TCmdStr;
+      var
+        wpostr,
+        optstr: TCmdStr;
+      begin
+        wpostr:='';
+        if cs_lto in current_settings.moduleswitches then
+          begin
+            case fnextpass of
+              0:
+                begin
+                  ObjFileName:=ChangeFileExt(ObjFileName,'.bc');
+                  wpostr:=' -flto';
+                end;
+              1:
+                begin
+                  ObjFileName:=ChangeFileExt(ObjFileName,'.o');
+                end;
+            end;
+          end;
+        result:=inherited;
+        { standard optimization flags for llc -- todo: this needs to be split
+          into a call to opt and one to llc }
+        if cs_opt_level3 in current_settings.optimizerswitches then
+          optstr:='-O3'
+        else if cs_opt_level2 in current_settings.optimizerswitches then
+          optstr:='-O2'
+        else if cs_opt_level1 in current_settings.optimizerswitches then
+          optstr:='-O1'
+        else
+          optstr:='-O0';
+        optstr:=optstr+wpostr;
+        { stack frame elimination }
+        if not(cs_opt_stackframe in current_settings.optimizerswitches) then
+          optstr:=optstr+' -fno-omit-frame-pointer'
+        else
+          optstr:=optstr+' -fomit-frame-pointer';
+        { fast math }
+        if cs_opt_fastmath in current_settings.optimizerswitches then
+          optstr:=optstr+' -ffast-math';
+        { smart linking }
+        if cs_create_smart in current_settings.moduleswitches then
+          optstr:=optstr+' -fdata-sections -ffunction-sections';
+        { pic }
+        if cs_create_pic in current_settings.moduleswitches then
+          optstr:=optstr+' -fpic'
+        else if not(target_info.system in systems_darwin) then
+          optstr:=optstr+' -static'
+        else
+          optstr:=optstr+' -mdynamic-no-pic';
+        if not(target_info.system in systems_darwin) then
+          begin
+            optstr:=optstr+' --target='+llvm_target_name;
+          end;
+
+        if fputypestrllvm[current_settings.fputype]<>'' then
+          optstr:=optstr+' -m'+fputypestrllvm[current_settings.fputype];
+
+        replace(result,'$OPT',optstr);
+        inc(fnextpass);
+      end;
+
+
+    function TLLVMClangAssember.DoAssemble: boolean;
+      begin
+        fnextpass:=0;
+        result:=inherited;
+      end;
+
+
+    function TLLVMClangAssember.RerunAssembler: boolean;
+      begin
+        result:=
+          (cs_lto in current_settings.moduleswitches) and
+          (fnextpass<=1);
+      end;
+
+
+    function TLLVMClangAssember.DoPipe: boolean;
+      begin
+        result:=
+          not(cs_lto in current_settings.moduleswitches) and
+          inherited;
+      end;
+
+
+=======
+{****************************************************************************}
+{                               clang Assember                               }
+{****************************************************************************}
+
+    function TLLVMClangAssember.MakeCmdLine: TCmdStr;
+      var
+        wpostr,
+        optstr: TCmdStr;
+      begin
+        wpostr:='';
+        if cs_lto in current_settings.moduleswitches then
+          begin
+            case fnextpass of
+              0:
+                begin
+                  ObjFileName:=ChangeFileExt(ObjFileName,'.bc');
+                  wpostr:=' -flto';
+                end;
+              1:
+                begin
+                  ObjFileName:=ChangeFileExt(ObjFileName,'.o');
+                end;
+            end;
+          end;
+        result:=inherited;
+        if cs_opt_level3 in current_settings.optimizerswitches then
+          optstr:='-O3'
+        else if cs_opt_level2 in current_settings.optimizerswitches then
+          optstr:='-O2'
+        else if cs_opt_level1 in current_settings.optimizerswitches then
+          optstr:='-O1'
+        else
+          optstr:='-O0';
+        optstr:=optstr+wpostr;
+        { stack frame elimination }
+        if not(cs_opt_stackframe in current_settings.optimizerswitches) then
+          optstr:=optstr+' -fno-omit-frame-pointer'
+        else
+          optstr:=optstr+' -fomit-frame-pointer';
+        { fast math }
+        if cs_opt_fastmath in current_settings.optimizerswitches then
+          optstr:=optstr+' -ffast-math';
+        { smart linking }
+        if cs_create_smart in current_settings.moduleswitches then
+          optstr:=optstr+' -fdata-sections -ffunction-sections';
+        { pic }
+        if cs_create_pic in current_settings.moduleswitches then
+          optstr:=optstr+' -fpic'
+        else if not(target_info.system in systems_darwin) then
+          optstr:=optstr+' -static'
+        else
+          optstr:=optstr+' -mdynamic-no-pic';
+
+        if fputypestrllvm[current_settings.fputype]<>'' then
+          optstr:=optstr+' -m'+fputypestrllvm[current_settings.fputype];
+
+        replace(result,'$OPT',optstr);
+        inc(fnextpass);
+      end;
+
+
+    function TLLVMClangAssember.DoAssemble: boolean;
+      begin
+        fnextpass:=0;
+        result:=inherited;
+      end;
+
+
+    function TLLVMClangAssember.RerunAssembler: boolean;
+      begin
+        result:=
+          (cs_lto in current_settings.moduleswitches) and
+          (fnextpass<=1);
+      end;
+
+
+    function TLLVMClangAssember.DoPipe: boolean;
+      begin
+        result:=
+          not(cs_lto in current_settings.moduleswitches) and
+          inherited;
+      end;
+
+
    const
    const
-     as_llvm_info : tasminfo =
+     as_clang_llvm_info : tasminfo =
         (
         (
-          id     : as_llvm;
-
-          idtxt  : 'LLVM-AS';
-          asmbin : 'llc';
-          asmcmd: '$OPT -o $OBJ $ASM';
-          supported_targets : [system_x86_64_linux,system_x86_64_darwin,system_powerpc64_darwin];
-          flags : [af_smartlink_sections];
+          id     : as_clang_llvm;
+          idtxt  : 'CLANG-LLVM';
+          asmbin : 'clang';
+          asmcmd: '-x ir -target $TARGET $OPT -target $TRIPLET -c -o $OBJ $ASM $EXTRAOPT';
+          supported_targets : [system_x86_64_linux,system_x86_64_darwin];
+          flags : [af_smartlink_sections,af_llvm];
           labelprefix : 'L';
           labelprefix : 'L';
+          labelmaxlen : -1;
           comment : '; ';
           comment : '; ';
           dollarsign: '$';
           dollarsign: '$';
         );
         );
 
 
-
 begin
 begin
-  RegisterAssembler(as_llvm_info,TLLVMAssember);
+  RegisterAssembler(as_clang_llvm_info,TLLVMClangAssember);
 end.
 end.

+ 42 - 81
compiler/llvm/llvmbase.pas

@@ -101,94 +101,55 @@ interface
     { = max(cpubase.max_operands,7) }
     { = max(cpubase.max_operands,7) }
     max_operands = ((-ord(cpubase.max_operands<=7)) and 7) or ((-ord(cpubase.max_operands>7)) and cpubase.max_operands);
     max_operands = ((-ord(cpubase.max_operands<=7)) and 7) or ((-ord(cpubase.max_operands>7)) and cpubase.max_operands);
 
 
-  function llvm_target_name: ansistring;
-
 implementation
 implementation
 
 
   uses
   uses
     globals,
     globals,
     systems;
     systems;
 
 
-{$j-}
-  const
-    llvmsystemcpu: array[tsystemcpu] of ansistring =
-      ('unknown',
-       'i386',
-       'm68k',
-       'alpha',
-       'powerpc',
-       'sparc',
-       'unknown',
-       'ia64',
-       'x86_64',
-       'mips',
-       'arm',
-       'powerpc64',
-       'avr',
-       'mipsel',
-       'unknown',
-       'unknown',
-       'aarch64',
-       'wasm32',
-       'sparc64'
-      );
-
-  function llvm_target_name: ansistring;
+  function llvm_callingconvention_name(c: tproccalloption): ansistring;
     begin
     begin
-      { architecture }
-{$ifdef arm}
-      llvm_target_name:=lower(cputypestr[current_settings.cputype]);
-{$else arm}
-      llvm_target_name:=llvmsystemcpu[target_info.cpu];
-{$endif}
-      { vendor and/or OS }
-      if target_info.system in systems_darwin then
-        begin
-          llvm_target_name:=llvm_target_name+'-apple';
-          if not(target_info.system in [system_arm_darwin,system_i386_iphonesim]) then
-            llvm_target_name:=llvm_target_name+'-macosx'+MacOSXVersionMin
-          else
-            llvm_target_name:=llvm_target_name+'-ios'+iPhoneOSVersionMin;
-        end
-      else if target_info.system in (systems_linux+systems_android) then
-        llvm_target_name:=llvm_target_name+'-linux'
-      else if target_info.system in systems_windows then
-        begin
-          { WinCE isn't supported (yet) by llvm, but if/when added this is
-            presumably how they will differentiate it }
-          if not(target_info.system in [system_i386_wince,system_arm_wince]) then
-            llvm_target_name:=llvm_target_name+'-pc';
-          llvm_target_name:=llvm_target_name+'-win32'
-        end
-      else if target_info.system in systems_freebsd then
-        llvm_target_name:=llvm_target_name+'-freebsd'
-      else if target_info.system in systems_openbsd then
-        llvm_target_name:=llvm_target_name+'-openbsd'
-      else if target_info.system in systems_netbsd then
-        llvm_target_name:=llvm_target_name+'-netbsd'
-      else if target_info.system in systems_aix then
-        llvm_target_name:=llvm_target_name+'-ibm-aix'
-      else if target_info.system in [system_i386_haiku] then
-        llvm_target_name:=llvm_target_name+'-haiku'
-      else if target_info.system in systems_embedded then
-        llvm_target_name:=llvm_target_name+'-none'
-      else
-        llvm_target_name:=llvm_target_name+'-unknown';
-
-      { environment/ABI }
-      if target_info.system in systems_android then
-        llvm_target_name:=llvm_target_name+'-android';
-{$if defined(FPC_ARMHF)}
-      llvm_target_name:=llvm_target_name+'-gnueabihf';
-{$elseif defined(FPC_ARMEL)}
-      if target_info.system in systems_embedded then
-        llvm_target_name:=llvm_target_name+'-eabi'
-      else if target_info.system=system_arm_android then
-        { handled above already
-        llvm_target_name:=llvm_target_name+'-android' }
-      else
-        llvm_target_name:=llvm_target_name+'-gnueabi';
-{$endif FPC_ARM_HF}
+      // TODO (unsupported by LLVM at this time):
+      //   * pocall_pascal
+      //   * pocall_oldfpccall
+      //   * pocall_syscall
+      //   * pocall_far16
+      //   * possibly pocall_softfloat
+      case c of
+        { to prevent errors if none of the defines below is active }
+        pocall_none:
+          result:='';
+{$ifdef i386}
+        pocall_register:
+          result:='x86_borlandregcallcc';
+        pocall_stdcall:
+          result:='x86_stdcallcc';
+{$endif i386}
+{$ifdef x86}
+        pocall_interrupt:
+          result:='x86_intrcc';
+        pocall_sysv_abi_default,
+        pocall_sysv_abi_cdecl:
+          result:='x86_64_sysvcc';
+        pocall_ms_abi_default,
+        pocall_ms_abi_cdecl:
+          result:='win64cc';
+        pocall_vectorcall:
+          result:='x86_vectorcallcc';
+        pocall_internproc:
+          result:=llvm_callingconvention_name(pocall_default);
+{$endif x86}
+{$ifdef avr}
+        pocall_interrupt:
+          result:='avr_intrcc';
+{$endif avr}
+{$if defined(arm) and not defined(FPC_ARMHF)}
+        pocall_hardfloat:
+          result:='arm_aapcs_vfpcc';
+{$endif arm and not FPC_ARMHF}
+        else
+          result:='';
+      end;
     end;
     end;
 
 
 end.
 end.

+ 1 - 1
compiler/m68k/ag68kgas.pas

@@ -356,7 +356,7 @@ interface
             idtxt  : 'AS';
             idtxt  : 'AS';
             asmbin : 'as';
             asmbin : 'as';
             asmcmd : '$ARCH -o $OBJ $EXTRAOPT $ASM';
             asmcmd : '$ARCH -o $OBJ $EXTRAOPT $ASM';
-            supported_targets : [system_m68k_macos,system_m68k_linux,system_m68k_PalmOS,system_m68k_netbsd,system_m68k_embedded];
+            supported_targets : [system_m68k_macosclassic,system_m68k_linux,system_m68k_PalmOS,system_m68k_netbsd,system_m68k_embedded];
             flags : [af_needar,af_smartlink_sections];
             flags : [af_needar,af_smartlink_sections];
             labelprefix : '.L';
             labelprefix : '.L';
             comment : '# ';
             comment : '# ';

+ 45 - 0
compiler/m68k/tripletcpu.pas

@@ -0,0 +1,45 @@
+{
+    Copyright (c) 2020 by Jonas Maebe
+
+    Construct the cpu part of the triplet
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit tripletcpu;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+  globtype;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+
+implementation
+
+uses
+  globals, cpuinfo;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+  begin
+    result:='m68k';
+  end;
+
+
+end.
+

+ 48 - 0
compiler/mips/tripletcpu.pas

@@ -0,0 +1,48 @@
+{
+    Copyright (c) 2020 by Jonas Maebe
+
+    Construct the cpu part of the triplet
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit tripletcpu;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+  globtype;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+
+implementation
+
+uses
+  globals, systems, cpuinfo;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+  begin
+    if target_info.endian=endian_big then
+      result:='mips'
+    else
+      result:='mipsel'
+  end;
+
+
+end.
+

+ 2 - 2
compiler/msg/errore.msg

@@ -4052,7 +4052,7 @@ F*2P<x>_Set target CPU (aarch64,arm,avr,i386,i8086,jvm,m68k,mips,mipsel,powerpc,
 6*2Tembedded_Embedded
 6*2Tembedded_Embedded
 6*2Tlinux_Linux
 6*2Tlinux_Linux
 6*2Tnetbsd_NetBSD
 6*2Tnetbsd_NetBSD
-6*2Tmacos_Mac OS
+6*2Tmacosclassic_Classic Mac OS
 6*2Tpalmos_PalmOS
 6*2Tpalmos_PalmOS
 # i8086 targets
 # i8086 targets
 8*2Tembedded_Embedded
 8*2Tembedded_Embedded
@@ -4089,7 +4089,7 @@ P*2Tamiga_AmigaOS
 P*2Tdarwin_Darwin/Mac OS X
 P*2Tdarwin_Darwin/Mac OS X
 P*2Tembedded_Embedded
 P*2Tembedded_Embedded
 P*2Tlinux_Linux
 P*2Tlinux_Linux
-P*2Tmacos_Mac OS (classic)
+P*2Tmacosclassic_Classic Mac OS
 P*2Tmorphos_MorphOS
 P*2Tmorphos_MorphOS
 P*2Tnetbsd_NetBSD
 P*2Tnetbsd_NetBSD
 P*2Twii_Wii
 P*2Twii_Wii

+ 1 - 1
compiler/msgidx.inc

@@ -1108,7 +1108,7 @@ const
   option_info=11024;
   option_info=11024;
   option_help_pages=11025;
   option_help_pages=11025;
 
 
-  MsgTxtSize = 82743;
+  MsgTxtSize = 82763;
 
 
   MsgIdxMax : array[1..20] of longint=(
   MsgIdxMax : array[1..20] of longint=(
     28,106,350,127,99,59,142,34,221,67,
     28,106,350,127,99,59,142,34,221,67,

+ 47 - 49
compiler/msgtxt.inc

@@ -1727,14 +1727,14 @@ const msgtxt : array[0..000344,1..240] of char=(
   '6*2Tembedded_Embedded'#010+
   '6*2Tembedded_Embedded'#010+
   '6*2Tlinux_Linux'#010+
   '6*2Tlinux_Linux'#010+
   '6*2Tnetbsd_NetBSD'#010+
   '6*2Tnetbsd_NetBSD'#010+
-  '6*2Tmacos_Mac OS'#010+
+  '6*2Tmacosclassic_Classic Mac OS'#010+
   '6*2Tpalmos_PalmOS'#010+
   '6*2Tpalmos_PalmOS'#010+
   '8*2Tembedded_Embedded'#010+
   '8*2Tembedded_Embedded'#010+
   '8*2Tmsdos_MS-DOS (and compatible)'#010+
   '8*2Tmsdos_MS-DOS (and compatible)'#010+
   '8*2Twin16_Windows 16 Bit'#010+
   '8*2Twin16_Windows 16 Bit'#010+
   'A*2Tandroid_Android'#010+
   'A*2Tandroid_Android'#010+
   'A*2Taros_AROS'#010+
   'A*2Taros_AROS'#010+
-  'A*2Tdarwin_Darwin','/iPhoneOS/iOS'#010+
+  'A*','2Tdarwin_Darwin/iPhoneOS/iOS'#010+
   'A*2Tembedded_Embedded'#010+
   'A*2Tembedded_Embedded'#010+
   'A*2Tgba_Game Boy Advance'#010+
   'A*2Tgba_Game Boy Advance'#010+
   'A*2Tlinux_Linux'#010+
   'A*2Tlinux_Linux'#010+
@@ -1745,8 +1745,8 @@ const msgtxt : array[0..000344,1..240] of char=(
   'A*2Twince_Windows CE'#010+
   'A*2Twince_Windows CE'#010+
   'a*2Tdarwin_Darwin/iOS'#010+
   'a*2Tdarwin_Darwin/iOS'#010+
   'a*2Tlinux_Linux'#010+
   'a*2Tlinux_Linux'#010+
-  'J*2Tandroid_Android'#010+
-  'J*2Tjava','_Java'#010+
+  'J*2Tandroid_A','ndroid'#010+
+  'J*2Tjava_Java'#010+
   'm*2Tandroid_Android'#010+
   'm*2Tandroid_Android'#010+
   'm*2Tembedded_Embedded'#010+
   'm*2Tembedded_Embedded'#010+
   'm*2Tlinux_Linux'#010+
   'm*2Tlinux_Linux'#010+
@@ -1757,8 +1757,8 @@ const msgtxt : array[0..000344,1..240] of char=(
   'P*2Tdarwin_Darwin/Mac OS X'#010+
   'P*2Tdarwin_Darwin/Mac OS X'#010+
   'P*2Tembedded_Embedded'#010+
   'P*2Tembedded_Embedded'#010+
   'P*2Tlinux_Linux'#010+
   'P*2Tlinux_Linux'#010+
-  'P*2Tmacos_Mac OS (classic)'#010+
-  'P*2Tmorphos_Morp','hOS'#010+
+  'P*2Tmacosclassic_Classic Mac',' OS'#010+
+  'P*2Tmorphos_MorphOS'#010+
   'P*2Tnetbsd_NetBSD'#010+
   'P*2Tnetbsd_NetBSD'#010+
   'P*2Twii_Wii'#010+
   'P*2Twii_Wii'#010+
   'p*2Taix_AIX'#010+
   'p*2Taix_AIX'#010+
@@ -1770,144 +1770,142 @@ const msgtxt : array[0..000344,1..240] of char=(
   's*2Tlinux_Linux'#010+
   's*2Tlinux_Linux'#010+
   'V*2Tembedded_Embedded'#010+
   'V*2Tembedded_Embedded'#010+
   '**1u<x>_Undefines the symbol <x>'#010+
   '**1u<x>_Undefines the symbol <x>'#010+
-  '**1U_Unit options:'#010+
-  '**2','Un_Do not check where the unit name matches the file name'#010+
+  '**','1U_Unit options:'#010+
+  '**2Un_Do not check where the unit name matches the file name'#010+
   '**2Ur_Generate release unit files (never automatically recompiled)'#010+
   '**2Ur_Generate release unit files (never automatically recompiled)'#010+
   '**2Us_Compile a system unit'#010+
   '**2Us_Compile a system unit'#010+
-  '**1v<x>_Be verbose. <x> is a combination of the following letters:'#010+
-  '**2*_e : Show errors',' (default)       0 : Show nothing (except errors'+
-  ')'#010+
+  '**1v<x>_Be verbose. <x> is a combination of the following letters:'#010,
+  '**2*_e : Show errors (default)       0 : Show nothing (except errors)'#010+
   '**2*_w : Show warnings               u : Show unit info'#010+
   '**2*_w : Show warnings               u : Show unit info'#010+
   '**2*_n : Show notes                  t : Show tried/used files'#010+
   '**2*_n : Show notes                  t : Show tried/used files'#010+
-  '**2*_h : Show hints                  c : Show conditionals'#010+
-  '**2*_i : Sho','w general info           d : Show debug info'#010+
+  '**2*_h : Show hints                  c : Show condi','tionals'#010+
+  '**2*_i : Show general info           d : Show debug info'#010+
   '**2*_l : Show linenumbers            r : Rhide/GCC compatibility mode'#010+
   '**2*_l : Show linenumbers            r : Rhide/GCC compatibility mode'#010+
   '**2*_s : Show time stamps            q : Show message numbers'#010+
   '**2*_s : Show time stamps            q : Show message numbers'#010+
-  '**2*_a : Show everything             x : Show info about invoke','d too'+
+  '**2*_a : Show everything             x : Sh','ow info about invoked too'+
   'ls'#010+
   'ls'#010+
   '**2*_b : Write file names messages   p : Write tree.log with parse tre'+
   '**2*_b : Write file names messages   p : Write tree.log with parse tre'+
   'e'#010+
   'e'#010+
   '**2*_    with full path              v : Write fpcdebug.txt with'#010+
   '**2*_    with full path              v : Write fpcdebug.txt with'#010+
   '**2*_z : Write output to stderr          lots of debugging info'#010+
   '**2*_z : Write output to stderr          lots of debugging info'#010+
-  '**2*_m<x>,<y> : Do not show mes','sages numbered <x> and <y>'#010+
+  '**2*_m<x>,<','y> : Do not show messages numbered <x> and <y>'#010+
   'F*1V<x>_Append '#039'-<x>'#039' to the used compiler binary name (e.g. f'+
   'F*1V<x>_Append '#039'-<x>'#039' to the used compiler binary name (e.g. f'+
   'or version)'#010+
   'or version)'#010+
   '**1W<x>_Target-specific options (targets)'#010+
   '**1W<x>_Target-specific options (targets)'#010+
   '3*2WA_Specify native type application (Windows)'#010+
   '3*2WA_Specify native type application (Windows)'#010+
-  '4*2WA_Specify native type application (Windows)'#010+
-  'A','*2WA_Specify native type application (Windows)'#010+
+  '4*2WA_Specify native type app','lication (Windows)'#010+
+  'A*2WA_Specify native type application (Windows)'#010+
   '3*2Wb_Create a bundle instead of a library (Darwin)'#010+
   '3*2Wb_Create a bundle instead of a library (Darwin)'#010+
   'P*2Wb_Create a bundle instead of a library (Darwin)'#010+
   'P*2Wb_Create a bundle instead of a library (Darwin)'#010+
   'p*2Wb_Create a bundle instead of a library (Darwin)'#010+
   'p*2Wb_Create a bundle instead of a library (Darwin)'#010+
-  'a*2Wb_Create a bundle instead of a li','brary (Darwin)'#010+
+  'a*2Wb_Create a bu','ndle instead of a library (Darwin)'#010+
   'A*2Wb_Create a bundle instead of a library (Darwin)'#010+
   'A*2Wb_Create a bundle instead of a library (Darwin)'#010+
   '4*2Wb_Create a bundle instead of a library (Darwin)'#010+
   '4*2Wb_Create a bundle instead of a library (Darwin)'#010+
   '3*2WB_Create a relocatable image (Windows, Symbian)'#010+
   '3*2WB_Create a relocatable image (Windows, Symbian)'#010+
-  '3*2WB<x>_Set image base to <x> (Windows, Symbian)'#010+
-  '4*2WB_Create a relo','catable image (Windows)'#010+
+  '3*2WB<x>_Set image base to <x> (Windows, Symbian)',#010+
+  '4*2WB_Create a relocatable image (Windows)'#010+
   '4*2WB<x>_Set image base to <x> (Windows)'#010+
   '4*2WB<x>_Set image base to <x> (Windows)'#010+
   'A*2WB_Create a relocatable image (Windows, Symbian)'#010+
   'A*2WB_Create a relocatable image (Windows, Symbian)'#010+
   'A*2WB<x>_Set image base to <x> (Windows, Symbian)'#010+
   'A*2WB<x>_Set image base to <x> (Windows, Symbian)'#010+
-  '3*2WC_Specify console type application (EMX, OS/2, Windows)'#010+
-  '4*2WC_Specify',' console type application (Windows)'#010+
+  '3*2WC_Specify console type application (EMX, OS/2, Wi','ndows)'#010+
+  '4*2WC_Specify console type application (Windows)'#010+
   'A*2WC_Specify console type application (Windows)'#010+
   'A*2WC_Specify console type application (Windows)'#010+
   'P*2WC_Specify console type application (Classic Mac OS)'#010+
   'P*2WC_Specify console type application (Classic Mac OS)'#010+
   '3*2WD_Use DEFFILE to export functions of DLL or EXE (Windows)'#010+
   '3*2WD_Use DEFFILE to export functions of DLL or EXE (Windows)'#010+
-  '4*2WD_Use DEFFILE to export functions',' of DLL or EXE (Windows)'#010+
+  '4*2WD_Use DEFFILE',' to export functions of DLL or EXE (Windows)'#010+
   'A*2WD_Use DEFFILE to export functions of DLL or EXE (Windows)'#010+
   'A*2WD_Use DEFFILE to export functions of DLL or EXE (Windows)'#010+
   '3*2We_Use external resources (Darwin)'#010+
   '3*2We_Use external resources (Darwin)'#010+
   '4*2We_Use external resources (Darwin)'#010+
   '4*2We_Use external resources (Darwin)'#010+
   'a*2We_Use external resources (Darwin)'#010+
   'a*2We_Use external resources (Darwin)'#010+
-  'A*2We_Use external resources (Darwin)'#010+
-  'P','*2We_Use external resources (Darwin)'#010+
+  'A*2We_Use external ','resources (Darwin)'#010+
+  'P*2We_Use external resources (Darwin)'#010+
   'p*2We_Use external resources (Darwin)'#010+
   'p*2We_Use external resources (Darwin)'#010+
   '3*2WF_Specify full-screen type application (EMX, OS/2)'#010+
   '3*2WF_Specify full-screen type application (EMX, OS/2)'#010+
   '3*2WG_Specify graphic type application (EMX, OS/2, Windows)'#010+
   '3*2WG_Specify graphic type application (EMX, OS/2, Windows)'#010+
-  '4*2WG_Specify graphic type application (Windows)'#010+
-  'A','*2WG_Specify graphic type application (Windows)'#010+
+  '4*2WG_Specify graphic type app','lication (Windows)'#010+
+  'A*2WG_Specify graphic type application (Windows)'#010+
   'P*2WG_Specify graphic type application (Classic Mac OS)'#010+
   'P*2WG_Specify graphic type application (Classic Mac OS)'#010+
   '3*2Wi_Use internal resources (Darwin)'#010+
   '3*2Wi_Use internal resources (Darwin)'#010+
   '4*2Wi_Use internal resources (Darwin)'#010+
   '4*2Wi_Use internal resources (Darwin)'#010+
   'a*2Wi_Use internal resources (Darwin)'#010+
   'a*2Wi_Use internal resources (Darwin)'#010+
-  'A*2Wi_Use internal res','ources (Darwin)'#010+
+  'A*','2Wi_Use internal resources (Darwin)'#010+
   'P*2Wi_Use internal resources (Darwin)'#010+
   'P*2Wi_Use internal resources (Darwin)'#010+
   'p*2Wi_Use internal resources (Darwin)'#010+
   'p*2Wi_Use internal resources (Darwin)'#010+
   '3*2WI_Turn on/off the usage of import sections (Windows)'#010+
   '3*2WI_Turn on/off the usage of import sections (Windows)'#010+
   '4*2WI_Turn on/off the usage of import sections (Windows)'#010+
   '4*2WI_Turn on/off the usage of import sections (Windows)'#010+
-  'A*2WI_Turn on/off the usage of imp','ort sections (Windows)'#010+
+  'A*2WI_Turn on/','off the usage of import sections (Windows)'#010+
   '8*2Wh_Use huge code for units (ignored for models with CODE in a uniqu'+
   '8*2Wh_Use huge code for units (ignored for models with CODE in a uniqu'+
   'e segment)'#010+
   'e segment)'#010+
   '8*2Wm<x>_Set memory model'#010+
   '8*2Wm<x>_Set memory model'#010+
   '8*3WmTiny_Tiny memory model'#010+
   '8*3WmTiny_Tiny memory model'#010+
   '8*3WmSmall_Small memory model (default)'#010+
   '8*3WmSmall_Small memory model (default)'#010+
-  '8*3WmMedium_Medium memory model'#010+
-  '8*3WmCompa','ct_Compact memory model'#010+
+  '8*3WmMedium_Medium mem','ory model'#010+
+  '8*3WmCompact_Compact memory model'#010+
   '8*3WmLarge_Large memory model'#010+
   '8*3WmLarge_Large memory model'#010+
   '8*3WmHuge_Huge memory model'#010+
   '8*3WmHuge_Huge memory model'#010+
   '3*2WM<x>_Minimum Mac OS X deployment version: 10.4, 10.5.1, ... (Darwi'+
   '3*2WM<x>_Minimum Mac OS X deployment version: 10.4, 10.5.1, ... (Darwi'+
   'n)'#010+
   'n)'#010+
-  '4*2WM<x>_Minimum Mac OS X deployment version: 10.4, 10.5.1, ... (Darwi'+
-  'n)'#010+
-  'p*2WM<x>_Min','imum Mac OS X deployment version: 10.4, 10.5.1, ... (Dar'+
+  '4*2WM<x>_Minimum Mac OS X deployment version: 10.4, 10.5.1, ... (','Dar'+
   'win)'#010+
   'win)'#010+
+  'p*2WM<x>_Minimum Mac OS X deployment version: 10.4, 10.5.1, ... (Darwi'+
+  'n)'#010+
   'P*2WM<x>_Minimum Mac OS X deployment version: 10.4, 10.5.1, ... (Darwi'+
   'P*2WM<x>_Minimum Mac OS X deployment version: 10.4, 10.5.1, ... (Darwi'+
   'n)'#010+
   'n)'#010+
   '3*2WN_Do not generate relocation code, needed for debugging (Windows)'#010+
   '3*2WN_Do not generate relocation code, needed for debugging (Windows)'#010+
-  '4*2WN_Do not generate relocation cod','e, needed for debugging (Windows'+
+  '4*2WN_Do not gen','erate relocation code, needed for debugging (Windows'+
   ')'#010+
   ')'#010+
   'A*2WN_Do not generate relocation code, needed for debugging (Windows)'#010+
   'A*2WN_Do not generate relocation code, needed for debugging (Windows)'#010+
   'A*2Wp<x>_Specify the controller type; see fpc -i or fpc -iu for possib'+
   'A*2Wp<x>_Specify the controller type; see fpc -i or fpc -iu for possib'+
   'le values'#010+
   'le values'#010+
-  'm*2Wp<x>_Specify the controller type; see fpc -i or fpc ','-iu for poss'+
+  'm*2Wp<x>_Specify the controller type','; see fpc -i or fpc -iu for poss'+
   'ible values'#010+
   'ible values'#010+
   'V*2Wp<x>_Specify the controller type; see fpc -i or fpc -iu for possib'+
   'V*2Wp<x>_Specify the controller type; see fpc -i or fpc -iu for possib'+
   'le values'#010+
   'le values'#010+
   '3*2WP<x>_Minimum iOS deployment version: 3.0, 5.0.1, ... (iphonesim)'#010+
   '3*2WP<x>_Minimum iOS deployment version: 3.0, 5.0.1, ... (iphonesim)'#010+
-  '4*2WP<x>_Minimum iOS deployment version: 8.0, 8.0.2, ... (iphonesim',')'+
+  '4*2WP<x>_Minimum iOS deployment version: 8.0, 8','.0.2, ... (iphonesim)'+
   #010+
   #010+
   'a*2WP<x>_Minimum iOS deployment version: 7.0, 7.1.2, ... (Darwin)'#010+
   'a*2WP<x>_Minimum iOS deployment version: 7.0, 7.1.2, ... (Darwin)'#010+
   'A*2WP<x>_Minimum iOS deployment version: 3.0, 5.0.1, ... (Darwin)'#010+
   'A*2WP<x>_Minimum iOS deployment version: 3.0, 5.0.1, ... (Darwin)'#010+
   '3*2WR_Generate relocation code (Windows)'#010+
   '3*2WR_Generate relocation code (Windows)'#010+
   '4*2WR_Generate relocation code (Windows)'#010+
   '4*2WR_Generate relocation code (Windows)'#010+
-  'A*2WR_Generate relocatio','n code (Windows)'#010+
+  'A*2W','R_Generate relocation code (Windows)'#010+
   '8*2Wt<x>_Set the target executable format'#010+
   '8*2Wt<x>_Set the target executable format'#010+
   '8*3Wtexe_Create a DOS .EXE file (default)'#010+
   '8*3Wtexe_Create a DOS .EXE file (default)'#010+
   '8*3Wtcom_Create a DOS .COM file (requires tiny memory model)'#010+
   '8*3Wtcom_Create a DOS .COM file (requires tiny memory model)'#010+
   'P*2WT_Specify MPW tool type application (Classic Mac OS)'#010+
   'P*2WT_Specify MPW tool type application (Classic Mac OS)'#010+
-  '**2WX_Enable executab','le stack (Linux)'#010+
+  '*','*2WX_Enable executable stack (Linux)'#010+
   '**1X_Executable options:'#010+
   '**1X_Executable options:'#010+
   '**2X9_Generate linkerscript for GNU Binutils ld older than version 2.1'+
   '**2X9_Generate linkerscript for GNU Binutils ld older than version 2.1'+
   '9.1 (Linux)'#010+
   '9.1 (Linux)'#010+
   '**2Xc_Pass --shared/-dynamic to the linker (BeOS, Darwin, FreeBSD, Lin'+
   '**2Xc_Pass --shared/-dynamic to the linker (BeOS, Darwin, FreeBSD, Lin'+
   'ux)'#010+
   'ux)'#010+
-  '**2Xd_Do not search default library path (','sometimes required for cro'+
+  '**2Xd_Do not search de','fault library path (sometimes required for cro'+
   'ss-compiling when not using -XR)'#010+
   'ss-compiling when not using -XR)'#010+
   '**2Xe_Use external linker'#010+
   '**2Xe_Use external linker'#010+
   '**2Xf_Substitute pthread library name for linking (BSD)'#010+
   '**2Xf_Substitute pthread library name for linking (BSD)'#010+
   '**2Xg_Create debuginfo in a separate file and add a debuglink section '+
   '**2Xg_Create debuginfo in a separate file and add a debuglink section '+
-  'to executable'#010+
-  '**2XD_Try to li','nk units dynamically      (defines FPC_LINK_DYNAMIC)'#010+
+  'to execut','able'#010+
+  '**2XD_Try to link units dynamically      (defines FPC_LINK_DYNAMIC)'#010+
   '**2Xi_Use internal linker'#010+
   '**2Xi_Use internal linker'#010+
   '**2XLA_Define library substitutions for linking'#010+
   '**2XLA_Define library substitutions for linking'#010+
   '**2XLO_Define order of library linking'#010+
   '**2XLO_Define order of library linking'#010+
   '**2XLD_Exclude default order of standard libraries'#010+
   '**2XLD_Exclude default order of standard libraries'#010+
-  '**2Xm_Generate link map',#010+
+  '**2','Xm_Generate link map'#010+
   '**2XM<x>_Set the name of the '#039'main'#039' program routine (default i'+
   '**2XM<x>_Set the name of the '#039'main'#039' program routine (default i'+
   's '#039'main'#039')'#010+
   's '#039'main'#039')'#010+
   '**2Xn_Use target system native linker instead of GNU ld (Solaris, AIX)'+
   '**2Xn_Use target system native linker instead of GNU ld (Solaris, AIX)'+
   #010+
   #010+
   'F*2Xp<x>_First search for the compiler binary in the directory <x>'#010+
   'F*2Xp<x>_First search for the compiler binary in the directory <x>'#010+
-  '**2XP<x>_Prepend the binutils',' names with the prefix <x>'#010+
+  '**2XP<x>_','Prepend the binutils names with the prefix <x>'#010+
   '**2Xr<x>_Set the linker'#039's rlink-path to <x> (needed for cross comp'+
   '**2Xr<x>_Set the linker'#039's rlink-path to <x> (needed for cross comp'+
   'ile, see the ld manual for more information) (BeOS, Linux)'#010+
   'ile, see the ld manual for more information) (BeOS, Linux)'#010+
-  '**2XR<x>_Prepend <x> to all linker search paths (BeOS, Darwin, FreeBSD'+
-  ', Linux, Mac OS, S','olaris)'#010+
+  '**2XR<x>_Prepend <x> to all linker search paths (BeOS, Darwin, FreeB','S'+
+  'D, Linux, Mac OS, Solaris)'#010+
   '**2Xs_Strip all symbols from executable'#010+
   '**2Xs_Strip all symbols from executable'#010+
   '**2XS_Try to link units statically (default, defines FPC_LINK_STATIC)'#010+
   '**2XS_Try to link units statically (default, defines FPC_LINK_STATIC)'#010+
   '**2Xt_Link with static libraries (-static is passed to linker)'#010+
   '**2Xt_Link with static libraries (-static is passed to linker)'#010+
-  '**2Xv_Generate table for Virtual Entry calls'#010+
-  '**2XV_Use VLin','k as external linker       (default on Amiga, MorphOS)'+
-  #010+
+  '**2Xv_Generate table for Virtual Entry ','calls'#010+
+  '**2XV_Use VLink as external linker       (default on Amiga, MorphOS)'#010+
   '**2XX_Try to smartlink units             (defines FPC_LINK_SMART)'#010+
   '**2XX_Try to smartlink units             (defines FPC_LINK_SMART)'#010+
   '**1*_'#010+
   '**1*_'#010+
   '**1?_Show this help'#010+
   '**1?_Show this help'#010+

+ 39 - 10
compiler/ncal.pas

@@ -225,17 +225,17 @@ interface
           fcontains_stack_tainting_call_cached,
           fcontains_stack_tainting_call_cached,
           ffollowed_by_stack_tainting_call_cached : boolean;
           ffollowed_by_stack_tainting_call_cached : boolean;
        protected
        protected
-          { in case of copy-out parameters: initialization code, and the code to
-            copy back the parameter value after the call (including any required
-            finalization code }
-          fparainit,
-          fparacopyback: tnode;
           procedure handlemanagedbyrefpara(orgparadef: tdef);virtual;
           procedure handlemanagedbyrefpara(orgparadef: tdef);virtual;
           { on some targets, value parameters that are passed by reference must
           { on some targets, value parameters that are passed by reference must
             be copied to a temp location by the caller (and then a reference to
             be copied to a temp location by the caller (and then a reference to
             this temp location must be passed) }
             this temp location must be passed) }
           procedure copy_value_by_ref_para;
           procedure copy_value_by_ref_para;
        public
        public
+          { in case of copy-out parameters: initialization code, and the code to
+            copy back the parameter value after the call (including any required
+            finalization code) }
+          fparainit,
+          fparacopyback: tnode;
           callparaflags : tcallparaflags;
           callparaflags : tcallparaflags;
           parasym       : tparavarsym;
           parasym       : tparavarsym;
           { only the processor specific nodes need to override this }
           { only the processor specific nodes need to override this }
@@ -729,7 +729,6 @@ implementation
     procedure tcallparanode.copy_value_by_ref_para;
     procedure tcallparanode.copy_value_by_ref_para;
       var
       var
         initstat,
         initstat,
-        copybackstat,
         finistat: tstatementnode;
         finistat: tstatementnode;
         finiblock: tblocknode;
         finiblock: tblocknode;
         paratemp: ttempcreatenode;
         paratemp: ttempcreatenode;
@@ -743,13 +742,15 @@ implementation
           to be copied by the caller. It's basically the node-level equivalent
           to be copied by the caller. It's basically the node-level equivalent
           of thlcgobj.g_copyvalueparas }
           of thlcgobj.g_copyvalueparas }
 
 
+        if assigned(fparainit) then
+          exit;
+
         { in case of an array constructor, we don't need a copy since the array
         { in case of an array constructor, we don't need a copy since the array
           constructor itself is already constructed on the fly (and hence if
           constructor itself is already constructed on the fly (and hence if
           it's modified by the caller, that's no problem) }
           it's modified by the caller, that's no problem) }
         if not is_array_constructor(left.resultdef) then
         if not is_array_constructor(left.resultdef) then
           begin
           begin
             fparainit:=internalstatements(initstat);
             fparainit:=internalstatements(initstat);
-            fparacopyback:=internalstatements(copybackstat);
             finiblock:=internalstatements(finistat);
             finiblock:=internalstatements(finistat);
             paratemp:=nil;
             paratemp:=nil;
 
 
@@ -928,10 +929,8 @@ implementation
                 left:=ctemprefnode.create(paratemp);
                 left:=ctemprefnode.create(paratemp);
               end;
               end;
             addstatement(finistat,ctempdeletenode.create(paratemp));
             addstatement(finistat,ctempdeletenode.create(paratemp));
-            addstatement(copybackstat,finiblock);
             firstpass(fparainit);
             firstpass(fparainit);
             firstpass(left);
             firstpass(left);
-            firstpass(fparacopyback);
           end;
           end;
       end;
       end;
 
 
@@ -1473,8 +1472,38 @@ implementation
 
 
 
 
     procedure tcallparanode.printnodetree(var t:text);
     procedure tcallparanode.printnodetree(var t:text);
+      var
+        hp: tbinarynode;
       begin
       begin
-        printnodelist(t);
+        hp:=self;
+        while assigned(hp) do
+         begin
+           write(t,printnodeindention,'(');
+           printnodeindent;
+           hp.printnodeinfo(t);
+           writeln(t);
+           if assigned(tcallparanode(hp).fparainit) then
+             begin
+               writeln(t,printnodeindention,'(parainit =');
+               printnodeindent;
+               printnode(t,tcallparanode(hp).fparainit);
+               printnodeunindent;
+               writeln(t,printnodeindention,')');
+             end;
+           if assigned(tcallparanode(hp).fparacopyback) then
+             begin
+               writeln(t,printnodeindention,'(fparacopyback =');
+               printnodeindent;
+               printnode(t,tcallparanode(hp).fparacopyback);
+               printnodeunindent;
+               writeln(t,printnodeindention,')');
+             end;
+           printnode(t,hp.left);
+           writeln(t);
+           printnodeunindent;
+           writeln(t,printnodeindention,')');
+           hp:=tbinarynode(hp.right);
+         end;
       end;
       end;
 
 
 
 

+ 1 - 1
compiler/ngenutil.pas

@@ -1553,7 +1553,7 @@ implementation
      begin
      begin
        { stub for calling FPC_SYSTEMMAIN from the C main -> add argc/argv/argp }
        { stub for calling FPC_SYSTEMMAIN from the C main -> add argc/argv/argp }
        if (tprocdef(pd).proctypeoption=potype_mainstub) and
        if (tprocdef(pd).proctypeoption=potype_mainstub) and
-          (target_info.system in (systems_darwin+[system_powerpc_macos]+systems_aix)) then
+          (target_info.system in (systems_darwin+[system_powerpc_macosclassic]+systems_aix)) then
          begin
          begin
            pvs:=cparavarsym.create('ARGC',1,vs_const,s32inttype,[]);
            pvs:=cparavarsym.create('ARGC',1,vs_const,s32inttype,[]);
            tprocdef(pd).parast.insert(pvs);
            tprocdef(pd).parast.insert(pvs);

+ 10 - 0
compiler/nutils.pas

@@ -188,6 +188,11 @@ implementation
               result := foreachnode(procmethod,tcallnode(n).funcretnode,f,arg) or result;
               result := foreachnode(procmethod,tcallnode(n).funcretnode,f,arg) or result;
               result := foreachnode(procmethod,tnode(tcallnode(n).callcleanupblock),f,arg) or result;
               result := foreachnode(procmethod,tnode(tcallnode(n).callcleanupblock),f,arg) or result;
             end;
             end;
+          callparan:
+            begin
+              result := foreachnode(procmethod,tnode(tcallparanode(n).fparainit),f,arg) or result;
+              result := foreachnode(procmethod,tcallparanode(n).fparacopyback,f,arg) or result;
+            end;
           ifn, whilerepeatn, forn, tryexceptn:
           ifn, whilerepeatn, forn, tryexceptn:
             begin
             begin
               { not in one statement, won't work because of b- }
               { not in one statement, won't work because of b- }
@@ -285,6 +290,11 @@ implementation
               result := foreachnodestatic(procmethod,tcallnode(n).funcretnode,f,arg) or result;
               result := foreachnodestatic(procmethod,tcallnode(n).funcretnode,f,arg) or result;
               result := foreachnodestatic(procmethod,tnode(tcallnode(n).callcleanupblock),f,arg) or result;
               result := foreachnodestatic(procmethod,tnode(tcallnode(n).callcleanupblock),f,arg) or result;
             end;
             end;
+          callparan:
+            begin
+              result := foreachnodestatic(procmethod,tnode(tcallparanode(n).fparainit),f,arg) or result;
+              result := foreachnodestatic(procmethod,tcallparanode(n).fparacopyback,f,arg) or result;
+            end;
           ifn, whilerepeatn, forn, tryexceptn:
           ifn, whilerepeatn, forn, tryexceptn:
             begin
             begin
               { not in one statement, won't work because of b- }
               { not in one statement, won't work because of b- }

+ 1 - 1
compiler/objcgutl.pas

@@ -1770,7 +1770,7 @@ procedure tobjcrttiwriter_nonfragile.gen_objc_classes_sections(list:TAsmList; ob
     metatcb.emit_tai(Tai_const.Create_sym(ObjCEmptyCacheVar),voidpointertype);
     metatcb.emit_tai(Tai_const.Create_sym(ObjCEmptyCacheVar),voidpointertype);
     { pointer to vtable }
     { pointer to vtable }
     if not assigned(ObjCEmptyVtableVar) and
     if not assigned(ObjCEmptyVtableVar) and
-       not(target_info.system in [system_arm_darwin,system_aarch64_darwin,system_i386_iphonesim,system_x86_64_iphonesim]) then
+       not(target_info.system in [system_arm_ios,system_aarch64_ios,system_aarch64_darwin,system_i386_iphonesim,system_x86_64_iphonesim]) then
       ObjCEmptyVtableVar:=current_asmdata.RefAsmSymbol(target_info.Cprefix+'_objc_empty_vtable',AT_DATA);
       ObjCEmptyVtableVar:=current_asmdata.RefAsmSymbol(target_info.Cprefix+'_objc_empty_vtable',AT_DATA);
     ConcatSymOrNil(metatcb,ObjCEmptyVtableVar,voidpointertype);
     ConcatSymOrNil(metatcb,ObjCEmptyVtableVar,voidpointertype);
     { the read-only part }
     { the read-only part }

+ 34 - 20
compiler/options.pas

@@ -107,8 +107,7 @@ uses
   llvminfo,
   llvminfo,
 {$endif llvm}
 {$endif llvm}
   dirparse,
   dirparse,
-  pkgutil,
-  i_bsd;
+  pkgutil;
 
 
 const
 const
   page_size = 24;
   page_size = 24;
@@ -928,7 +927,7 @@ begin
   if MacVersionSet then
   if MacVersionSet then
     exit;
     exit;
   { check for deployment target set via environment variable }
   { check for deployment target set via environment variable }
-  if not(target_info.system in [system_i386_iphonesim,system_arm_darwin,system_aarch64_darwin,system_x86_64_iphonesim]) then
+  if not(target_info.system in [system_i386_iphonesim,system_arm_ios,system_aarch64_ios,system_x86_64_iphonesim]) then
     begin
     begin
       envstr:=GetEnvironmentVariable('MACOSX_DEPLOYMENT_TARGET');
       envstr:=GetEnvironmentVariable('MACOSX_DEPLOYMENT_TARGET');
       if envstr<>'' then
       if envstr<>'' then
@@ -958,30 +957,35 @@ begin
     system_powerpc_darwin:
     system_powerpc_darwin:
       begin
       begin
         set_system_compvar('MAC_OS_X_VERSION_MIN_REQUIRED','1030');
         set_system_compvar('MAC_OS_X_VERSION_MIN_REQUIRED','1030');
-        MacOSXVersionMin:='10.3';
+        MacOSXVersionMin:='10.3.0';
       end;
       end;
     system_powerpc64_darwin:
     system_powerpc64_darwin:
       begin
       begin
         set_system_compvar('MAC_OS_X_VERSION_MIN_REQUIRED','1040');
         set_system_compvar('MAC_OS_X_VERSION_MIN_REQUIRED','1040');
-        MacOSXVersionMin:='10.4';
+        MacOSXVersionMin:='10.4.0';
       end;
       end;
     system_i386_darwin,
     system_i386_darwin,
     system_x86_64_darwin:
     system_x86_64_darwin:
       begin
       begin
         set_system_compvar('MAC_OS_X_VERSION_MIN_REQUIRED','1080');
         set_system_compvar('MAC_OS_X_VERSION_MIN_REQUIRED','1080');
-        MacOSXVersionMin:='10.8';
+        MacOSXVersionMin:='10.8.0';
       end;
       end;
-    system_arm_darwin,
+    system_arm_ios,
     system_i386_iphonesim:
     system_i386_iphonesim:
       begin
       begin
-        set_system_compvar('IPHONE_OS_VERSION_MIN_REQUIRED','30000');
-        iPhoneOSVersionMin:='3.0';
+        set_system_compvar('IPHONE_OS_VERSION_MIN_REQUIRED','90000');
+        iPhoneOSVersionMin:='9.0.0';
       end;
       end;
-    system_aarch64_darwin,
+    system_aarch64_ios,
     system_x86_64_iphonesim:
     system_x86_64_iphonesim:
       begin
       begin
-        set_system_compvar('IPHONE_OS_VERSION_MIN_REQUIRED','70000');
-        iPhoneOSVersionMin:='7.0';
+        set_system_compvar('IPHONE_OS_VERSION_MIN_REQUIRED','90000');
+        iPhoneOSVersionMin:='9.0.0';
+      end;
+    system_aarch64_darwin:
+      begin
+        set_system_compvar('MAC_OS_X_VERSION_MIN_REQUIRED','110000');
+        MacOSXVersionMin:='11.0.0';
       end
       end
     else
     else
       internalerror(2012031001);
       internalerror(2012031001);
@@ -2289,7 +2293,6 @@ begin
                       begin
                       begin
                         if (target_info.system in systems_darwin) then
                         if (target_info.system in systems_darwin) then
                           begin
                           begin
-                            RegisterRes(res_macosx_ext_info,TWinLikeResourceFile);
                             set_target_res(res_ext);
                             set_target_res(res_ext);
                             target_info.resobjext:='.fpcres';
                             target_info.resobjext:='.fpcres';
                           end
                           end
@@ -2373,7 +2376,7 @@ begin
                       end;
                       end;
                     'M':
                     'M':
                       begin
                       begin
-                        if (target_info.system in (systems_darwin-[system_i386_iphonesim,system_arm_darwin,system_aarch64_darwin,system_x86_64_iphonesim])) and
+                        if (target_info.system in (systems_darwin-[system_i386_iphonesim,system_arm_ios,system_aarch64_ios,system_x86_64_iphonesim])) and
                            ParseMacVersionMin(MacOSXVersionMin,iPhoneOSVersionMin,'MAC_OS_X_VERSION_MIN_REQUIRED',copy(More,2,255),false) then
                            ParseMacVersionMin(MacOSXVersionMin,iPhoneOSVersionMin,'MAC_OS_X_VERSION_MIN_REQUIRED',copy(More,2,255),false) then
                           begin
                           begin
                             break;
                             break;
@@ -2417,7 +2420,7 @@ begin
                       end;
                       end;
                     'P':
                     'P':
                       begin
                       begin
-                        if (target_info.system in [system_i386_iphonesim,system_arm_darwin,system_aarch64_darwin,system_x86_64_iphonesim]) and
+                        if (target_info.system in [system_i386_iphonesim,system_arm_ios,system_aarch64_ios,system_x86_64_iphonesim]) and
                            ParseMacVersionMin(iPhoneOSVersionMin,MacOSXVersionMin,'IPHONE_OS_VERSION_MIN_REQUIRED',copy(More,2,255),true) then
                            ParseMacVersionMin(iPhoneOSVersionMin,MacOSXVersionMin,'IPHONE_OS_VERSION_MIN_REQUIRED',copy(More,2,255),true) then
                           begin
                           begin
                             break;
                             break;
@@ -3942,15 +3945,21 @@ begin
   librarysearchpath.AddList(unitsearchpath,false);
   librarysearchpath.AddList(unitsearchpath,false);
 
 
 {$ifdef llvm}
 {$ifdef llvm}
-  { force llvm assembler writer }
-  option.paratargetasm:=as_llvm;
+  { default to clang }
+  if (option.paratargetasm=as_none) then
+    begin
+      option.paratargetasm:=as_clang_llvm;
+    end;
 {$endif llvm}
 {$endif llvm}
   { maybe override assembler }
   { maybe override assembler }
   if (option.paratargetasm<>as_none) then
   if (option.paratargetasm<>as_none) then
     begin
     begin
       if not set_target_asm(option.paratargetasm) then
       if not set_target_asm(option.paratargetasm) then
         begin
         begin
-          Message2(option_incompatible_asm,asminfos[option.paratargetasm]^.idtxt,target_info.name);
+          if assigned(asminfos[option.paratargetasm]) then
+            Message2(option_incompatible_asm,asminfos[option.paratargetasm]^.idtxt,target_info.name)
+          else
+            Message2(option_incompatible_asm,'<invalid assembler>',target_info.name);
           set_target_asm(target_info.assemextern);
           set_target_asm(target_info.assemextern);
           Message1(option_asm_forced,target_asm.idtxt);
           Message1(option_asm_forced,target_asm.idtxt);
         end;
         end;
@@ -3984,7 +3993,11 @@ begin
      (af_outputbinary in target_asm.flags) then
      (af_outputbinary in target_asm.flags) then
    begin
    begin
      Message(option_switch_bin_to_src_assembler);
      Message(option_switch_bin_to_src_assembler);
+{$ifdef llvm}
+     set_target_asm(as_clang_llvm);
+{$else}
      set_target_asm(target_info.assemextern);
      set_target_asm(target_info.assemextern);
+{$endif}
      { At least i8086 needs that for nasm and -CX
      { At least i8086 needs that for nasm and -CX
        which is incompatible with internal linker }
        which is incompatible with internal linker }
      option.checkoptionscompatibility;
      option.checkoptionscompatibility;
@@ -4050,7 +4063,7 @@ begin
 
 
 {$ifdef arm}
 {$ifdef arm}
   case target_info.system of
   case target_info.system of
-    system_arm_darwin:
+    system_arm_ios:
       begin
       begin
         { set default cpu type to ARMv7 for Darwin unless specified otherwise, and fpu
         { set default cpu type to ARMv7 for Darwin unless specified otherwise, and fpu
           to VFPv3 (that's what all 32 bit ARM iOS devices use nowadays)
           to VFPv3 (that's what all 32 bit ARM iOS devices use nowadays)
@@ -4102,7 +4115,8 @@ begin
         end
         end
       else
       else
         begin
         begin
-          if not (init_settings.fputype in [fpu_vfpv2,fpu_vfpv3,fpu_vfpv3_d16,fpu_vfpv4]) then
+          if not (init_settings.fputype in [fpu_vfpv2,fpu_vfpv3,fpu_vfpv3_d16,fpu_vfpv4])
+	     or (target_info.system = system_arm_ios) then
             begin
             begin
               Message(option_illegal_fpu_eabihf);
               Message(option_illegal_fpu_eabihf);
               StopOptions(1);
               StopOptions(1);

+ 31 - 5
compiler/opttail.pas

@@ -50,14 +50,35 @@ unit opttail;
         var
         var
           usedcallnode : tcallnode;
           usedcallnode : tcallnode;
 
 
-        function is_recursivecall(n : tnode) : boolean;
+        function has_copyback_paras(call: tcallnode): boolean;
+          var
+            n: tcallparanode;
           begin
           begin
-            result:=(n.nodetype=calln) and (tcallnode(n).procdefinition=p) and not(assigned(tcallnode(n).methodpointer));
+            n:=tcallparanode(call.left);
+            result:=false;
+            while assigned(n) do
+              begin
+                if assigned(n.fparacopyback) then
+                  begin
+                    result:=true;
+                    exit;
+                  end;
+                n:=tcallparanode(n.right);
+              end;
+          end;
+
+        function is_optimizable_recursivecall(n : tnode) : boolean;
+          begin
+            result:=
+              (n.nodetype=calln) and
+              (tcallnode(n).procdefinition=p) and
+              not(assigned(tcallnode(n).methodpointer)) and
+              not has_copyback_paras(tcallnode(n));
             if result then
             if result then
               usedcallnode:=tcallnode(n)
               usedcallnode:=tcallnode(n)
             else
             else
               { obsolete type cast? }
               { obsolete type cast? }
-              result:=((n.nodetype=typeconvn) and (ttypeconvnode(n).convtype=tc_equal) and is_recursivecall(ttypeconvnode(n).left));
+              result:=((n.nodetype=typeconvn) and (ttypeconvnode(n).convtype=tc_equal) and is_optimizable_recursivecall(ttypeconvnode(n).left));
           end;
           end;
 
 
         function is_resultassignment(n : tnode) : boolean;
         function is_resultassignment(n : tnode) : boolean;
@@ -101,9 +122,9 @@ unit opttail;
             calln,
             calln,
             assignn:
             assignn:
               begin
               begin
-                if ((n.nodetype=calln) and is_recursivecall(n)) or
+                if ((n.nodetype=calln) and is_optimizable_recursivecall(n)) or
                    ((n.nodetype=assignn) and is_resultassignment(tbinarynode(n).left) and
                    ((n.nodetype=assignn) and is_resultassignment(tbinarynode(n).left) and
-                   is_recursivecall(tbinarynode(n).right)) then
+                   is_optimizable_recursivecall(tbinarynode(n).right)) then
                   begin
                   begin
                     { found one! }
                     { found one! }
                     {
                     {
@@ -120,6 +141,11 @@ unit opttail;
                     paranode:=tcallparanode(usedcallnode.left);
                     paranode:=tcallparanode(usedcallnode.left);
                     while assigned(paranode) do
                     while assigned(paranode) do
                       begin
                       begin
+                        if assigned(paranode.fparainit) then
+                          begin
+                            addstatement(calcstatements,paranode.fparainit);
+                            paranode.fparainit:=nil;
+                          end;
                         tempnode:=ctempcreatenode.create(paranode.left.resultdef,paranode.left.resultdef.size,tt_persistent,true);
                         tempnode:=ctempcreatenode.create(paranode.left.resultdef,paranode.left.resultdef.size,tt_persistent,true);
                         addstatement(calcstatements,tempnode);
                         addstatement(calcstatements,tempnode);
                         addstatement(calcstatements,
                         addstatement(calcstatements,

+ 1 - 1
compiler/pdecvar.pas

@@ -1955,7 +1955,7 @@ implementation
               unionsymtable.addalignmentpadding;
               unionsymtable.addalignmentpadding;
 {$if defined(powerpc) or defined(powerpc64)}
 {$if defined(powerpc) or defined(powerpc64)}
               { parent inherits the alignment padding if the variant is the first "field" of the parent record/variant }
               { parent inherits the alignment padding if the variant is the first "field" of the parent record/variant }
-              if (target_info.system in [system_powerpc_darwin, system_powerpc_macos, system_powerpc64_darwin]) and
+              if (target_info.system in [system_powerpc_darwin, system_powerpc_macosclassic, system_powerpc64_darwin]) and
                  is_first_type and
                  is_first_type and
                  (recst.usefieldalignment=C_alignment) and
                  (recst.usefieldalignment=C_alignment) and
                  (maxpadalign>recst.padalignment) then
                  (maxpadalign>recst.padalignment) then

+ 1 - 1
compiler/pmodules.pas

@@ -2143,7 +2143,7 @@ type
                 they are directly added to the assembler output by llvm }
                 they are directly added to the assembler output by llvm }
             exportlib.setinitname(current_asmdata.AsmLists[al_pure_assembler],initname);
             exportlib.setinitname(current_asmdata.AsmLists[al_pure_assembler],initname);
           end
           end
-         else if (target_info.system in ([system_i386_netware,system_i386_netwlibc,system_powerpc_macos]+systems_darwin+systems_aix)) then
+         else if (target_info.system in ([system_i386_netware,system_i386_netwlibc,system_powerpc_macosclassic]+systems_darwin+systems_aix)) then
            begin
            begin
              { create a stub with the name of the desired main routine, with
              { create a stub with the name of the desired main routine, with
                the same signature as the C "main" function, and call through to
                the same signature as the C "main" function, and call through to

+ 1 - 1
compiler/powerpc/agppcmpw.pas

@@ -1232,7 +1232,7 @@ interface
             idtxt  : 'MPW';
             idtxt  : 'MPW';
             asmbin : 'PPCAsm';
             asmbin : 'PPCAsm';
             asmcmd : '-case on $ASM $EXTRAOPT -o $OBJ';
             asmcmd : '-case on $ASM $EXTRAOPT -o $OBJ';
-            supported_targets : [system_powerpc_macos];
+            supported_targets : [system_powerpc_macosclassic];
             flags : [af_needar,af_smartlink_sections,af_labelprefix_only_inside_procedure];
             flags : [af_needar,af_smartlink_sections,af_labelprefix_only_inside_procedure];
             labelprefix : '@';
             labelprefix : '@';
             comment : '; ';
             comment : '; ';

+ 2 - 2
compiler/powerpc/cgcpu.pas

@@ -192,7 +192,7 @@ const
                    list.concat(taicpu.op_sym(A_BL,current_asmdata.WeakRefAsmSymbol('.'+s,AT_FUNCTION)));
                    list.concat(taicpu.op_sym(A_BL,current_asmdata.WeakRefAsmSymbol('.'+s,AT_FUNCTION)));
                end;
                end;
 
 
-             if target_info.system in [system_powerpc_macos,system_powerpc_aix] then
+             if target_info.system in [system_powerpc_macosclassic,system_powerpc_aix] then
                list.concat(taicpu.op_none(A_NOP));
                list.concat(taicpu.op_none(A_NOP));
            end
            end
          else
          else
@@ -216,7 +216,7 @@ const
         tmpref : treference;
         tmpref : treference;
 
 
       begin
       begin
-        if target_info.system=system_powerpc_macos then
+        if target_info.system=system_powerpc_macosclassic then
           begin
           begin
             {Generate instruction to load the procedure address from
             {Generate instruction to load the procedure address from
             the transition vector.}
             the transition vector.}

+ 4 - 1
compiler/powerpc/cputarg.pas

@@ -41,9 +41,12 @@ implementation
     {$ifndef NOTARGETMACOS}
     {$ifndef NOTARGETMACOS}
       ,t_macos
       ,t_macos
     {$endif}
     {$endif}
-    {$ifndef NOTARGETDARWIN}
+    {$ifndef NOTARGETBSD}
       ,t_bsd
       ,t_bsd
     {$endif}
     {$endif}
+    {$ifndef NOTARGETDARWIN}
+      ,t_darwin
+    {$endif}
     {$ifndef NOTARGETMORPHOS}
     {$ifndef NOTARGETMORPHOS}
       ,t_morph
       ,t_morph
     {$endif}
     {$endif}

+ 45 - 0
compiler/powerpc/tripletcpu.pas

@@ -0,0 +1,45 @@
+{
+    Copyright (c) 2020 by Jonas Maebe
+
+    Construct the cpu part of the triplet
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit tripletcpu;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+  globtype;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+
+implementation
+
+uses
+  globals, cpuinfo;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+  begin
+    result:='ppc32';
+  end;
+
+
+end.
+

+ 2 - 2
compiler/powerpc64/cputarg.pas

@@ -38,8 +38,8 @@ implementation
     {$ifndef NOTARGETLINUX}
     {$ifndef NOTARGETLINUX}
       ,t_linux
       ,t_linux
     {$endif}
     {$endif}
-    {$ifndef NOTARGETBSD}
-      ,t_bsd
+    {$ifndef NOTARGETDARWIN}
+      ,t_darwin
     {$endif}
     {$endif}
     {$ifndef NOTARGETAIX}
     {$ifndef NOTARGETAIX}
       ,t_aix
       ,t_aix

+ 48 - 0
compiler/powerpc64/tripletcpu.pas

@@ -0,0 +1,48 @@
+{
+    Copyright (c) 2020 by Jonas Maebe
+
+    Construct the cpu part of the triplet
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit tripletcpu;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+  globtype;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+
+implementation
+
+uses
+  globals, systems, cpuinfo;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+  begin
+    if target_info.endian=endian_little then
+      result:='powerpc64le'
+    else
+      result:='powerpc64'
+  end;
+
+
+end.
+

+ 4 - 4
compiler/ppcgen/agppcgas.pas

@@ -726,12 +726,12 @@ unit agppcgas;
 
 
     as_ppc_clang_darwin_info : tasminfo =
     as_ppc_clang_darwin_info : tasminfo =
        (
        (
-         id     : as_clang;
+         id     : as_clang_asdarwin;
          idtxt  : 'CLANG';
          idtxt  : 'CLANG';
          asmbin : 'clang';
          asmbin : 'clang';
-         asmcmd : '-c -o $OBJ $EXTRAOPT -arch $ARCH $DARWINVERSION -x assembler $ASM';
-         supported_targets : [system_powerpc_macos, system_powerpc_darwin, system_powerpc64_darwin];
-         flags : [af_needar,af_smartlink_sections,af_supports_dwarf];
+         asmcmd : '-x assembler -c -target $TRIPLET -o $OBJ $EXTRAOPT -x assembler $ASM';
+         supported_targets : [system_powerpc_macosclassic, system_powerpc_darwin, system_powerpc64_darwin];
+         flags : [af_needar,af_smartlink_sections,af_supports_dwarf,af_llvm];
          labelprefix : 'L';
          labelprefix : 'L';
          comment : '# ';
          comment : '# ';
          dollarsign: '$';
          dollarsign: '$';

+ 3 - 3
compiler/ppcgen/cgppc.pas

@@ -415,7 +415,7 @@ unit cgppc;
          fixref(list,ref2);
          fixref(list,ref2);
          if assigned(ref2.symbol) then
          if assigned(ref2.symbol) then
            begin
            begin
-             if target_info.system = system_powerpc_macos then
+             if target_info.system = system_powerpc_macosclassic then
                begin
                begin
                  if macos_direct_globals then
                  if macos_direct_globals then
                    begin
                    begin
@@ -1113,7 +1113,7 @@ unit cgppc;
         tmpreg := NR_NO;
         tmpreg := NR_NO;
         largeOffset:= hasLargeOffset(ref);
         largeOffset:= hasLargeOffset(ref);
 
 
-        if target_info.system in ([system_powerpc_macos]+systems_aix) then
+        if target_info.system in ([system_powerpc_macosclassic]+systems_aix) then
           begin
           begin
 
 
             if assigned(ref.symbol) and
             if assigned(ref.symbol) and
@@ -1186,7 +1186,7 @@ unit cgppc;
             else
             else
               list.concat(taicpu.op_reg_ref(op,reg,ref));
               list.concat(taicpu.op_reg_ref(op,reg,ref));
           end
           end
-        else {if target_info.system <> system_powerpc_macos}
+        else {if target_info.system <> system_powerpc_macosclassic}
           begin
           begin
             if assigned(ref.symbol) or
             if assigned(ref.symbol) or
                largeOffset then
                largeOffset then

+ 1 - 1
compiler/ppcgen/ngppcadd.pas

@@ -329,7 +329,7 @@ implementation
               { clang does not recognize fcmpo instruction,
               { clang does not recognize fcmpo instruction,
                 so we need to fall back to fcmpu, which does not
                 so we need to fall back to fcmpu, which does not
                 generate the same exeception information }
                 generate the same exeception information }
-              if target_asm.id = as_clang then
+              if target_asm.id in [as_clang_gas,as_clang_asdarwin] then
                 op:=A_FCMPU
                 op:=A_FCMPU
               else
               else
                 op:=A_FCMPO;
                 op:=A_FCMPO;

+ 2 - 2
compiler/scandir.pas

@@ -356,7 +356,7 @@ unit scandir;
          hs : string;
          hs : string;
       begin
       begin
         if not (target_info.system in systems_all_windows + [system_i386_os2,
         if not (target_info.system in systems_all_windows + [system_i386_os2,
-                                       system_i386_emx, system_powerpc_macos,
+                                       system_i386_emx, system_powerpc_macosclassic,
                                        system_arm_nds, system_i8086_msdos,
                                        system_arm_nds, system_i8086_msdos,
                                        system_i8086_embedded, system_m68k_atari] +
                                        system_i8086_embedded, system_m68k_atari] +
                                        systems_nativent) then
                                        systems_nativent) then
@@ -383,7 +383,7 @@ unit scandir;
                  else if (hs='FS') and (target_info.system in [system_i386_os2,
                  else if (hs='FS') and (target_info.system in [system_i386_os2,
                                                              system_i386_emx]) then
                                                              system_i386_emx]) then
                    SetApptype(app_fs)
                    SetApptype(app_fs)
-                 else if (hs='TOOL') and (target_info.system in [system_powerpc_macos]) then
+                 else if (hs='TOOL') and (target_info.system in [system_powerpc_macosclassic]) then
                    SetApptype(app_tool)
                    SetApptype(app_tool)
                  else if (hs='ARM9') and (target_info.system in [system_arm_nds]) then
                  else if (hs='ARM9') and (target_info.system in [system_arm_nds]) then
                    SetApptype(app_arm9)
                    SetApptype(app_arm9)

+ 48 - 0
compiler/sparc/tripletcpu.pas

@@ -0,0 +1,48 @@
+{
+    Copyright (c) 2020 by Jonas Maebe
+
+    Construct the cpu part of the triplet
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit tripletcpu;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+  globtype;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+
+implementation
+
+uses
+  globals, systems, cpuinfo;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+  begin
+    if target_info.endian=endian_big then
+      result:='sparc'
+    else
+      result:='sparcle'
+  end;
+
+
+end.
+

+ 45 - 0
compiler/sparc64/tripletcpu.pas

@@ -0,0 +1,45 @@
+{
+    Copyright (c) 2020 by Jonas Maebe
+
+    Construct the cpu part of the triplet
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit tripletcpu;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+  globtype;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+
+implementation
+
+uses
+  globals, cpuinfo;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+  begin
+    result:='sparc64';
+  end;
+
+
+end.
+

+ 3 - 3
compiler/symdef.pas

@@ -2879,7 +2879,7 @@ implementation
 
 
     function torddef.alignment:shortint;
     function torddef.alignment:shortint;
       begin
       begin
-        if (target_info.system in [system_i386_darwin,system_i386_iphonesim,system_arm_darwin]) and
+        if (target_info.system in [system_i386_darwin,system_i386_iphonesim,system_arm_ios]) and
            (ordtype in [s64bit,u64bit]) then
            (ordtype in [s64bit,u64bit]) then
           result := 4
           result := 4
         else
         else
@@ -3017,7 +3017,7 @@ implementation
 
 
     function tfloatdef.alignment:shortint;
     function tfloatdef.alignment:shortint;
       begin
       begin
-        if (target_info.system in [system_i386_darwin,system_i386_iphonesim,system_arm_darwin]) then
+        if (target_info.system in [system_i386_darwin,system_i386_iphonesim,system_arm_ios]) then
           case floattype of
           case floattype of
             sc80real,
             sc80real,
             s80real: result:=16;
             s80real: result:=16;
@@ -8282,7 +8282,7 @@ implementation
       begin
       begin
         if assigned(objc_fastenumeration) then
         if assigned(objc_fastenumeration) then
           exit;
           exit;
-        if not(target_info.system in [system_arm_darwin,system_i386_iphonesim,system_aarch64_darwin,system_x86_64_iphonesim]) then
+        if not(target_info.system in [system_arm_ios,system_i386_iphonesim,system_aarch64_ios,system_x86_64_iphonesim]) then
           cocoaunit:='COCOAALL'
           cocoaunit:='COCOAALL'
         else
         else
           cocoaunit:='IPHONEALL';
           cocoaunit:='IPHONEALL';

+ 10 - 7
compiler/systems.inc

@@ -93,12 +93,12 @@
              system_i386_freebsd,       { 6 }
              system_i386_freebsd,       { 6 }
              system_m68k_Amiga,         { 7 }
              system_m68k_Amiga,         { 7 }
              system_m68k_Atari,         { 8 }
              system_m68k_Atari,         { 8 }
-             system_m68k_macos,         { 9 }
+             system_m68k_macosclassic,  { 9 }
              system_m68k_linux,         { 10 }
              system_m68k_linux,         { 10 }
              system_m68k_PalmOS,        { 11 }
              system_m68k_PalmOS,        { 11 }
              obsolete_system_alpha_linux,{ 12 }
              obsolete_system_alpha_linux,{ 12 }
              system_powerpc_linux,      { 13 }
              system_powerpc_linux,      { 13 }
-             system_powerpc_macos,      { 14 }
+             system_powerpc_macosclassic,{ 14 }
              system_i386_solaris,       { 15 }
              system_i386_solaris,       { 15 }
              system_i386_beos,          { 16 }
              system_i386_beos,          { 16 }
              system_i386_netbsd,        { 17 }
              system_i386_netbsd,        { 17 }
@@ -148,7 +148,7 @@
              system_x86_64_darwin,      { 61 }
              system_x86_64_darwin,      { 61 }
              system_avr_embedded,       { 62 }
              system_avr_embedded,       { 62 }
              system_i386_haiku,         { 63 }
              system_i386_haiku,         { 63 }
-             system_arm_darwin,         { 64 }
+             system_arm_ios,            { 64 }
              system_x86_64_solaris,     { 65 }
              system_x86_64_solaris,     { 65 }
              system_mipseb_linux,       { 66 }
              system_mipseb_linux,       { 66 }
              system_mipsel_linux,       { 67 }
              system_mipsel_linux,       { 67 }
@@ -170,7 +170,7 @@
              system_i386_aros,          { 83 }
              system_i386_aros,          { 83 }
              system_x86_64_aros,        { 84 }
              system_x86_64_aros,        { 84 }
              system_x86_64_dragonfly,   { 85 }
              system_x86_64_dragonfly,   { 85 }
-             system_aarch64_darwin,     { 86 }
+             system_aarch64_ios,        { 86 }
              system_x86_64_iphonesim,   { 87 }
              system_x86_64_iphonesim,   { 87 }
              system_aarch64_linux,      { 88 }
              system_aarch64_linux,      { 88 }
              system_i8086_win16,        { 89 }
              system_i8086_win16,        { 89 }
@@ -186,7 +186,8 @@
              system_riscv32_embedded,   { 99 }
              system_riscv32_embedded,   { 99 }
              system_aarch64_android,    { 100 }
              system_aarch64_android,    { 100 }
              system_x86_64_android,     { 101 }
              system_x86_64_android,     { 101 }
-             system_x86_64_haiku        { 102 }
+             system_x86_64_haiku,       { 102 }
+             system_aarch64_darwin      { 111 (in trunk) }
        );
        );
 
 
      type
      type
@@ -234,13 +235,14 @@
              ,as_gas_powerpc_xcoff
              ,as_gas_powerpc_xcoff
              ,as_arm_elf32
              ,as_arm_elf32
              ,as_i8086_omf
              ,as_i8086_omf
-             ,as_llvm
-             ,as_clang
+             ,as_clang_asdarwin        { machine code assembler in Darwin as style assembled by clang }
              ,as_solaris_as
              ,as_solaris_as
              ,as_m68k_vasm
              ,as_m68k_vasm
              ,as_m68k_as_aout
              ,as_m68k_as_aout
              ,as_wasm_binaryen
              ,as_wasm_binaryen
              ,as_powerpc_gas_legacy    { for systems with very old GAS versions only, which don't support eg. named sections }
              ,as_powerpc_gas_legacy    { for systems with very old GAS versions only, which don't support eg. named sections }
+             ,as_clang_llvm
+             ,as_clang_gas             { machine code assembler in gas style assembled by clang }
        );
        );
 
 
        tlink = (ld_none,
        tlink = (ld_none,
@@ -251,6 +253,7 @@
              ld_android,
              ld_android,
              ld_beos,
              ld_beos,
              ld_bsd,
              ld_bsd,
+             ld_darwin,
              ld_embedded,
              ld_embedded,
              ld_emx,
              ld_emx,
              ld_gba,
              ld_gba,

+ 22 - 11
compiler/systems.pas

@@ -65,6 +65,8 @@ interface
          ,af_no_debug
          ,af_no_debug
          ,af_stabs_use_function_absolute_addresses
          ,af_stabs_use_function_absolute_addresses
          ,af_no_stabs
          ,af_no_stabs
+         { assembler is part of the LLVM toolchain }
+         ,af_llvm
        );
        );
 
 
        pasminfo = ^tasminfo;
        pasminfo = ^tasminfo;
@@ -154,7 +156,11 @@ interface
             tf_x86_far_procs_push_odd_bp,
             tf_x86_far_procs_push_odd_bp,
             { indicates that this target can use dynamic packages otherwise an
             { indicates that this target can use dynamic packages otherwise an
               error will be generated if a package file is compiled }
               error will be generated if a package file is compiled }
-            tf_supports_packages
+            tf_supports_packages,
+            { supports symbol order file (to ensure symbols in vectorised sections are kept in the correct order) }
+            tf_supports_symbolorderfile,
+            { use high level cfi directives to generate call frame information }
+            tf_use_hlcfi
        );
        );
 
 
        psysteminfo = ^tsysteminfo;
        psysteminfo = ^tsysteminfo;
@@ -162,7 +168,7 @@ interface
        tsysteminfo = record
        tsysteminfo = record
           system       : tsystem;
           system       : tsystem;
           name         : string[34];
           name         : string[34];
-          shortname    : string[9];
+          shortname    : string[12];
           flags        : set of tsystemflags;
           flags        : set of tsystemflags;
           cpu          : tsystemcpu;
           cpu          : tsystemcpu;
           unit_env     : string[16];
           unit_env     : string[16];
@@ -257,10 +263,12 @@ interface
                              system_i8086_win16];
                              system_i8086_win16];
 
 
        { all darwin systems }
        { all darwin systems }
-       systems_darwin = [system_powerpc_darwin,system_i386_darwin,
+       systems_ios = [system_arm_ios,system_aarch64_ios];
+       systems_iphonesym = [system_i386_iphonesim,system_x86_64_iphonesim];
+       systems_macosx = [system_powerpc_darwin,system_i386_darwin,
                          system_powerpc64_darwin,system_x86_64_darwin,
                          system_powerpc64_darwin,system_x86_64_darwin,
-                         system_arm_darwin,system_i386_iphonesim,
-                         system_aarch64_darwin,system_x86_64_iphonesim];
+                         system_aarch64_darwin];
+       systems_darwin = systems_ios + systems_iphonesym + systems_macosx;
 
 
        {all solaris systems }
        {all solaris systems }
        systems_solaris = [system_sparc_solaris, system_i386_solaris,
        systems_solaris = [system_sparc_solaris, system_i386_solaris,
@@ -295,7 +303,7 @@ interface
        systems_symbian = [system_i386_symbian,system_arm_symbian];
        systems_symbian = [system_i386_symbian,system_arm_symbian];
 
 
        { all classic Mac OS targets }
        { all classic Mac OS targets }
-       systems_macos = [system_m68k_macos,system_powerpc_macos];
+       systems_macos = [system_m68k_macosclassic,system_powerpc_macosclassic];
 
 
        { all OS/2 targets }
        { all OS/2 targets }
        systems_os2 = [system_i386_OS2,system_i386_emx];
        systems_os2 = [system_i386_OS2,system_i386_emx];
@@ -313,7 +321,7 @@ interface
        systems_objc_supported = systems_darwin;
        systems_objc_supported = systems_darwin;
 
 
        { systems using the non-fragile Objective-C ABI }
        { systems using the non-fragile Objective-C ABI }
-       systems_objc_nfabi = [system_powerpc64_darwin,system_x86_64_darwin,system_arm_darwin,system_i386_iphonesim,system_aarch64_darwin,system_x86_64_iphonesim];
+       systems_objc_nfabi = [system_powerpc64_darwin,system_x86_64_darwin,system_arm_ios,system_i386_iphonesim,system_aarch64_ios,system_aarch64_darwin,system_x86_64_iphonesim];
 
 
        { systems supporting "blocks" }
        { systems supporting "blocks" }
        systems_blocks_supported = systems_darwin;
        systems_blocks_supported = systems_darwin;
@@ -383,7 +391,7 @@ interface
 
 
        { all systems where a value parameter passed by reference must be copied
        { all systems where a value parameter passed by reference must be copied
          on the caller side rather than on the callee side }
          on the caller side rather than on the callee side }
-       systems_caller_copy_addr_value_para = [system_aarch64_darwin,system_aarch64_linux];
+       systems_caller_copy_addr_value_para = [system_aarch64_ios,system_aarch64_darwin,system_aarch64_linux];
 
 
        { pointer checking (requires special code in FPC_CHECKPOINTER,
        { pointer checking (requires special code in FPC_CHECKPOINTER,
          and can never work for libc-based targets or any other program
          and can never work for libc-based targets or any other program
@@ -992,7 +1000,7 @@ begin
     {$endif}
     {$endif}
     {$ifdef darwin}
     {$ifdef darwin}
       {$define default_target_set}
       {$define default_target_set}
-      default_target(system_arm_darwin);
+      default_target(system_arm_ios);
     {$endif}
     {$endif}
     {$ifndef default_target_set}
     {$ifndef default_target_set}
       default_target(system_arm_linux);
       default_target(system_arm_linux);
@@ -1029,10 +1037,13 @@ begin
   {$ifdef cpuaarch64}
   {$ifdef cpuaarch64}
     default_target(source_info.system);
     default_target(source_info.system);
   {$else cpuaarch64}
   {$else cpuaarch64}
-    {$ifdef darwin}
+    {$if defined(ios)}
+      {$define default_target_set}
+      default_target(system_aarch64_ios);
+    {$elseif defined(darwin)}
       {$define default_target_set}
       {$define default_target_set}
       default_target(system_aarch64_darwin);
       default_target(system_aarch64_darwin);
-    {$endif darwin}
+    {$endif}
     {$ifdef android}
     {$ifdef android}
       {$define default_target_set}
       {$define default_target_set}
       default_target(system_aarch64_android);
       default_target(system_aarch64_android);

+ 2 - 561
compiler/systems/i_bsd.pas

@@ -1,8 +1,8 @@
 {
 {
     Copyright (c) 1998-2008 by Peter Vreman
     Copyright (c) 1998-2008 by Peter Vreman
 
 
-    This unit implements support information structures for FreeBSD/NetBSD,
-    OpenBSD and Darwin (Mac OS X)
+    This unit implements support information structures for FreeBSD/NetBSD
+    and OpenBSD
 
 
     This program is free software; you can redistribute it and/or modify
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
     it under the terms of the GNU General Public License as published by
@@ -33,27 +33,6 @@ unit i_bsd;
        systems;
        systems;
 
 
     const
     const
-       res_macho_info : tresinfo =
-           (
-             id     : res_macho;
-             resbin : 'fpcres';
-             rescmd : '-o $OBJ -a $ARCH -s $SUBARCH -of mach-o $DBG';
-             rcbin  : 'windres';
-             rccmd  : '--include $INC -O res -D FPC -o $RES $RC';
-             resourcefileclass : nil;
-             resflags : [];
-           );
-       res_macosx_ext_info : tresinfo =
-          (
-             id     : res_ext;
-             resbin : 'fpcres';
-             rescmd : '-o $OBJ -a $ENDIAN -of external $DBG';
-             rcbin  : 'windres';
-             rccmd  : '--include $INC -O res -D FPC -o $RES $RC';
-             resourcefileclass : nil;
-             resflags : [res_external_file,res_arch_in_file_name];
-          );
-
        system_i386_freebsd_info : tsysteminfo =
        system_i386_freebsd_info : tsysteminfo =
           (
           (
             system       : system_i386_FreeBSD;
             system       : system_i386_FreeBSD;
@@ -708,522 +687,6 @@ unit i_bsd;
             llvmdatalayout : 'todo';
             llvmdatalayout : 'todo';
           );
           );
 
 
-       system_powerpc_darwin_info  : tsysteminfo =
-          (
-            system       : system_powerpc_darwin;
-            name         : 'Darwin for PowerPC';
-            shortname    : 'Darwin';
-            flags        : [tf_p_ext_support,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,tf_dwarf_only_local_labels,tf_pic_default,tf_has_winlike_resources];
-            cpu          : cpu_powerpc;
-            unit_env     : 'BSDUNITS';
-            extradefines : 'UNIX;BSD;HASUNIX';
-            exeext       : '';
-            defext       : '.def';
-            scriptext    : '.sh';
-            smartext     : '.sl';
-            unitext      : '.ppu';
-            unitlibext   : '.ppl';
-            asmext       : '.s';
-            objext       : '.o';
-            resext       : '.res';
-            resobjext    : '.or';
-            sharedlibext : '.dylib';
-            staticlibext : '.a';
-            staticlibprefix : 'libp';
-            sharedlibprefix : 'lib';
-            sharedClibext : '.dylib';
-            staticClibext : '.a';
-            staticClibprefix : 'lib';
-            sharedClibprefix : 'lib';
-            importlibprefix : 'libimp';
-            importlibext : '.a';
-            Cprefix      : '_';
-            newline      : #10;
-            dirsep       : '/';
-            assem        : as_darwin;
-            assemextern  : as_darwin;
-            link         : ld_none;
-            linkextern   : ld_bsd;
-            ar           : ar_gnu_ar;
-            res          : res_macho;
-            dbg          : dbg_stabs;
-            script       : script_unix;
-            endian       : endian_big;
-            alignment    :
-              (
-                procalign       : 16;
-                loopalign       : 4;
-                jumpalign       : 0;
-                constalignmin   : 0;
-                constalignmax   : 4;
-                varalignmin     : 0;
-                varalignmax     : 4;
-                localalignmin   : 0;
-                localalignmax   : 4;
-                recordalignmin  : 0;
-                recordalignmax  : 4;
-                maxCrecordalign : 4
-              );
-            first_parm_offset : 24;
-            stacksize   : 262144;
-            stackalign   : 16;
-            abi : abi_powerpc_darwin;
-            llvmdatalayout : 'E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v128:128:128-n32';
-          );
-
-
-
-       system_i386_darwin_info  : tsysteminfo =
-          (
-            system       : system_i386_darwin;
-            name         : 'Darwin for i386';
-            shortname    : 'Darwin';
-            flags        : [tf_p_ext_support,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,tf_dwarf_only_local_labels,tf_pic_uses_got,tf_pic_default,tf_has_winlike_resources];
-            cpu          : cpu_i386;
-            unit_env     : 'BSDUNITS';
-            extradefines : 'UNIX;BSD;HASUNIX';
-            exeext       : '';
-            defext       : '.def';
-            scriptext    : '.sh';
-            smartext     : '.sl';
-            unitext      : '.ppu';
-            unitlibext   : '.ppl';
-            asmext       : '.s';
-            objext       : '.o';
-            resext       : '.res';
-            resobjext    : '.or';
-            sharedlibext : '.dylib';
-            staticlibext : '.a';
-            staticlibprefix : 'libp';
-            sharedlibprefix : 'lib';
-            sharedClibext : '.dylib';
-            staticClibext : '.a';
-            staticClibprefix : 'lib';
-            sharedClibprefix : 'lib';
-            importlibprefix : 'libimp';
-            importlibext : '.a';
-            Cprefix      : '_';
-            newline      : #10;
-            dirsep       : '/';
-            assem        : as_clang;
-            assemextern  : as_clang;
-            link         : ld_none;
-            linkextern   : ld_bsd;
-            ar           : ar_gnu_ar;
-            res          : res_macho;
-            dbg          : dbg_dwarf2;
-            script       : script_unix;
-            endian       : endian_little;
-            alignment    :
-              (
-                procalign       : 16;
-                loopalign       : 4;
-                jumpalign       : 0;
-                constalignmin   : 0;
-                constalignmax   : 16;
-                varalignmin     : 0;
-                varalignmax     : 16;
-                localalignmin   : 0;
-                localalignmax   : 8;
-                recordalignmin  : 0;
-                recordalignmax  : 16;
-                maxCrecordalign : 16
-              );
-            first_parm_offset : 8;
-            stacksize   : 262144;
-            stackalign   : 16;
-            abi         : abi_i386_dynalignedstack;
-            llvmdatalayout : 'e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32-S128';
-          );
-
-
-
-       system_i386_iphonesim_info  : tsysteminfo =
-          (
-            system       : system_i386_iphonesim;
-            name         : 'Darwin/iPhoneSim for i386';
-            shortname    : 'iPhoneSim';
-            flags        : [tf_p_ext_support,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,tf_dwarf_only_local_labels,tf_pic_uses_got,tf_pic_default,tf_has_winlike_resources];
-            cpu          : cpu_i386;
-            unit_env     : 'BSDUNITS';
-            extradefines : 'UNIX;BSD;HASUNIX;DARWIN'; // also define darwin for code compatibility
-            exeext       : '';
-            defext       : '.def';
-            scriptext    : '.sh';
-            smartext     : '.sl';
-            unitext      : '.ppu';
-            unitlibext   : '.ppl';
-            asmext       : '.s';
-            objext       : '.o';
-            resext       : '.res';
-            resobjext    : '.or';
-            sharedlibext : '.dylib';
-            staticlibext : '.a';
-            staticlibprefix : 'libp';
-            sharedlibprefix : 'lib';
-            sharedClibext : '.dylib';
-            staticClibext : '.a';
-            staticClibprefix : 'lib';
-            sharedClibprefix : 'lib';
-            importlibprefix : 'libimp';
-            importlibext : '.a';
-            Cprefix      : '_';
-            newline      : #10;
-            dirsep       : '/';
-            assem        : as_clang;
-            assemextern  : as_clang;
-            link         : ld_none;
-            linkextern   : ld_bsd;
-            ar           : ar_gnu_ar;
-            res          : res_macho;
-            dbg          : dbg_dwarf2;
-            script       : script_unix;
-            endian       : endian_little;
-            alignment    :
-              (
-                procalign       : 16;
-                loopalign       : 4;
-                jumpalign       : 0;
-                constalignmin   : 0;
-                constalignmax   : 16;
-                varalignmin     : 0;
-                varalignmax     : 16;
-                localalignmin   : 0;
-                localalignmax   : 16;
-                recordalignmin  : 0;
-                recordalignmax  : 16;
-                maxCrecordalign : 16
-              );
-            first_parm_offset : 8;
-            stacksize   : 262144;
-            stackalign   : 16;
-            abi         : abi_i386_dynalignedstack;
-            llvmdatalayout : 'e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32-S128';
-          );
-
-
-
-       system_powerpc64_darwin_info  : tsysteminfo =
-          (
-            system       : system_powerpc64_darwin;
-            name         : 'Darwin for PowerPC64';
-            shortname    : 'Darwin';
-            flags        : [tf_p_ext_support,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,tf_dwarf_only_local_labels,tf_pic_default,tf_has_winlike_resources];
-            cpu          : cpu_powerpc64;
-            unit_env     : 'BSDUNITS';
-            extradefines : 'UNIX;BSD;HASUNIX';
-            exeext       : '';
-            defext       : '.def';
-            scriptext    : '.sh';
-            smartext     : '.sl';
-            unitext      : '.ppu';
-            unitlibext   : '.ppl';
-            asmext       : '.s';
-            objext       : '.o';
-            resext       : '.res';
-            resobjext    : '.or';
-            sharedlibext : '.dylib';
-            staticlibext : '.a';
-            staticlibprefix : 'libp';
-            sharedlibprefix : 'lib';
-            sharedClibext : '.dylib';
-            staticClibext : '.a';
-            staticClibprefix : 'lib';
-            sharedClibprefix : 'lib';
-            importlibprefix : 'libimp';
-            importlibext : '.a';
-            Cprefix      : '_';
-            newline      : #10;
-            dirsep       : '/';
-            assem        : as_darwin;
-            assemextern  : as_darwin;
-            link         : ld_none;
-            linkextern   : ld_bsd;
-            ar           : ar_gnu_ar;
-            res          : res_macho;
-            dbg          : dbg_dwarf2;
-            script       : script_unix;
-            endian       : endian_big;
-            alignment    :
-              (
-                procalign       : 16;
-                loopalign       : 4;
-                jumpalign       : 0;
-                constalignmin   : 4;
-                constalignmax   : 8;
-                varalignmin     : 4;
-                varalignmax     : 8;
-                localalignmin   : 4;
-                localalignmax   : 8;
-                recordalignmin  : 0;
-                recordalignmax  : 8;
-                maxCrecordalign : 4
-              );
-            first_parm_offset : 48;
-            stacksize   : 262144;
-            stackalign   : 16;
-            abi : abi_powerpc_darwin;
-            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-v128:128:128-n32:64';
-          );
-
-
-
-       system_x86_64_darwin_info  : tsysteminfo =
-          (
-            system       : system_x86_64_darwin;
-            name         : 'Darwin for x86_64';
-            shortname    : 'Darwin';
-            flags        : [tf_p_ext_support,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,tf_dwarf_only_local_labels,tf_pic_default,tf_has_winlike_resources];
-            cpu          : cpu_x86_64;
-            unit_env     : 'BSDUNITS';
-            extradefines : 'UNIX;BSD;HASUNIX';
-            exeext       : '';
-            defext       : '.def';
-            scriptext    : '.sh';
-            smartext     : '.sl';
-            unitext      : '.ppu';
-            unitlibext   : '.ppl';
-            asmext       : '.s';
-            objext       : '.o';
-            resext       : '.res';
-            resobjext    : '.or';
-            sharedlibext : '.dylib';
-            staticlibext : '.a';
-            staticlibprefix : 'libp';
-            sharedlibprefix : 'lib';
-            sharedClibext : '.dylib';
-            staticClibext : '.a';
-            staticClibprefix : 'lib';
-            sharedClibprefix : 'lib';
-            importlibprefix : 'libimp';
-            importlibext : '.a';
-            Cprefix      : '_';
-            newline      : #10;
-            dirsep       : '/';
-            assem        : as_clang;
-            assemextern  : as_clang;
-            link         : ld_none;
-            linkextern   : ld_bsd;
-            ar           : ar_gnu_ar;
-            res          : res_macho;
-            dbg          : dbg_dwarf2;
-            script       : script_unix;
-            endian       : endian_little;
-            alignment    :
-              (
-                procalign       : 8;
-                loopalign       : 4;
-                jumpalign       : 0;
-                constalignmin   : 0;
-                constalignmax   : 16;
-                varalignmin     : 0;
-                varalignmax     : 16;
-                localalignmin   : 4;
-                localalignmax   : 16;
-                recordalignmin  : 0;
-                recordalignmax  : 16;
-                maxCrecordalign : 16
-              );
-            first_parm_offset : 16;
-            stacksize   : 262144;
-            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-s0:64:64-f80:128:128-n8:16:32:64-S128';
-          );
-
-
-       system_x86_64_iphonesim_info  : tsysteminfo =
-          (
-            system       : system_x86_64_iphonesim;
-            name         : 'Darwin/iPhoneSim for x86_64';
-            shortname    : 'iPhoneSim';
-            flags        : [tf_p_ext_support,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,tf_dwarf_only_local_labels,tf_pic_default,tf_has_winlike_resources];
-            cpu          : cpu_x86_64;
-            unit_env     : 'BSDUNITS';
-            extradefines : 'UNIX;BSD;HASUNIX;DARWIN'; // also define darwin for code compatibility
-            exeext       : '';
-            defext       : '.def';
-            scriptext    : '.sh';
-            smartext     : '.sl';
-            unitext      : '.ppu';
-            unitlibext   : '.ppl';
-            asmext       : '.s';
-            objext       : '.o';
-            resext       : '.res';
-            resobjext    : '.or';
-            sharedlibext : '.dylib';
-            staticlibext : '.a';
-            staticlibprefix : 'libp';
-            sharedlibprefix : 'lib';
-            sharedClibext : '.dylib';
-            staticClibext : '.a';
-            staticClibprefix : 'lib';
-            sharedClibprefix : 'lib';
-            importlibprefix : 'libimp';
-            importlibext : '.a';
-            Cprefix      : '_';
-            newline      : #10;
-            dirsep       : '/';
-            assem        : as_clang;
-            assemextern  : as_clang;
-            link         : ld_none;
-            linkextern   : ld_bsd;
-            ar           : ar_gnu_ar;
-            res          : res_macho;
-            dbg          : dbg_dwarf2;
-            script       : script_unix;
-            endian       : endian_little;
-            alignment    :
-              (
-                procalign       : 8;
-                loopalign       : 4;
-                jumpalign       : 0;
-                constalignmin   : 0;
-                constalignmax   : 16;
-                varalignmin     : 0;
-                varalignmax     : 16;
-                localalignmin   : 4;
-                localalignmax   : 16;
-                recordalignmin  : 0;
-                recordalignmax  : 16;
-                maxCrecordalign : 16
-              );
-            first_parm_offset : 16;
-            stacksize   : 262144;
-            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-s0:64:64-f80:128:128-n8:16:32:64-S128';
-          );
-
-
-       system_arm_darwin_info : tsysteminfo =
-          (
-            system       : system_arm_darwin;
-            name         : 'Darwin for ARM';
-            shortname    : 'Darwin';
-            flags        : [tf_p_ext_support,tf_requires_proper_alignment,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,tf_dwarf_only_local_labels,tf_has_winlike_resources,tf_pic_default];
-            cpu          : cpu_arm;
-            unit_env     : 'BSDUNITS';
-            extradefines : 'UNIX;BSD;HASUNIX;CPUARMEL';
-            exeext       : '';
-            defext       : '.def';
-            scriptext    : '.sh';
-            smartext     : '.sl';
-            unitext      : '.ppu';
-            unitlibext   : '.ppl';
-            asmext       : '.s';
-            objext       : '.o';
-            resext       : '.res';
-            resobjext    : '.or';
-            sharedlibext : '.dylib';
-            staticlibext : '.a';
-            staticlibprefix : 'libp';
-            sharedlibprefix : 'lib';
-            sharedClibext : '.dylib';
-            staticClibext : '.a';
-            staticClibprefix : 'lib';
-            sharedClibprefix : 'lib';
-            importlibprefix : 'libimp';
-            importlibext : '.a';
-            Cprefix      : '_';
-            newline      : #10;
-            dirsep       : '/';
-            assem        : as_clang;
-            assemextern  : as_clang;
-            link         : ld_none;
-            linkextern   : ld_bsd;
-            ar           : ar_gnu_ar;
-            res          : res_macho;
-            dbg          : dbg_dwarf2;
-            script       : script_unix;
-            endian       : endian_little;
-            alignment    :
-              (
-                procalign       : 4;
-                loopalign       : 4;
-                jumpalign       : 0;
-                constalignmin   : 0;
-                constalignmax   : 8;
-                varalignmin     : 0;
-                varalignmax     : 8;
-                localalignmin   : 4;
-                localalignmax   : 8;
-                recordalignmin  : 0;
-                recordalignmax  : 8;
-                maxCrecordalign : 8
-              );
-            first_parm_offset : 8;
-            stacksize    : 262144;
-            stackalign   : 4;
-            abi : abi_default;
-            { note: default LLVM stack alignment is 8 bytes for this target }
-            llvmdatalayout : 'e-p:32:32:32-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:64:128-a0:0:64-n32-S32';
-          );
-
-
-       system_aarch64_darwin_info  : tsysteminfo =
-          (
-            system       : system_aarch64_darwin;
-            name         : 'Darwin for AArch64';
-            shortname    : 'Darwin';
-            flags        : [tf_p_ext_support,tf_requires_proper_alignment,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,tf_dwarf_only_local_labels,tf_pic_default,tf_has_winlike_resources];
-            cpu          : cpu_aarch64;
-            unit_env     : 'BSDUNITS';
-            extradefines : 'UNIX;BSD;HASUNIX';
-            exeext       : '';
-            defext       : '.def';
-            scriptext    : '.sh';
-            smartext     : '.sl';
-            unitext      : '.ppu';
-            unitlibext   : '.ppl';
-            asmext       : '.s';
-            objext       : '.o';
-            resext       : '.res';
-            resobjext    : '.or';
-            sharedlibext : '.dylib';
-            staticlibext : '.a';
-            staticlibprefix : 'libp';
-            sharedlibprefix : 'lib';
-            sharedClibext : '.dylib';
-            staticClibext : '.a';
-            staticClibprefix : 'lib';
-            sharedClibprefix : 'lib';
-            importlibprefix : 'libimp';
-            importlibext : '.a';
-            Cprefix      : '_';
-            newline      : #10;
-            dirsep       : '/';
-            assem        : as_clang;
-            assemextern  : as_clang;
-            link         : ld_none;
-            linkextern   : ld_bsd;
-            ar           : ar_gnu_ar;
-            res          : res_macho;
-            dbg          : dbg_dwarf2;
-            script       : script_unix;
-            endian       : endian_little;
-            alignment    :
-              (
-                procalign       : 8;
-                loopalign       : 4;
-                jumpalign       : 0;
-                constalignmin   : 0;
-                constalignmax   : 16;
-                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_aarch64_darwin;
-            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'
-          );
-
 
 
 
 
   implementation
   implementation
@@ -1239,9 +702,6 @@ initialization
   {$ifdef OpenBSD}
   {$ifdef OpenBSD}
      set_source_info(system_i386_OpenBSD_info);
      set_source_info(system_i386_OpenBSD_info);
   {$endif}
   {$endif}
-  {$ifdef Darwin}
-     set_source_info(system_i386_Darwin_info);
-  {$endif Darwin}
 {$endif cpui386}
 {$endif cpui386}
 {$ifdef cpux86_64}
 {$ifdef cpux86_64}
    {$ifdef FreeBSD}
    {$ifdef FreeBSD}
@@ -1256,9 +716,6 @@ initialization
    {$ifdef NetBSD}
    {$ifdef NetBSD}
      set_source_info(system_x86_64_NetBSD_info);
      set_source_info(system_x86_64_NetBSD_info);
    {$endif}
    {$endif}
-   {$ifdef Darwin}
-     set_source_info(system_x86_64_darwin_info);
-   {$endif}
 {$endif}
 {$endif}
 {$ifdef cpu68}
 {$ifdef cpu68}
   {$ifdef NetBSD}
   {$ifdef NetBSD}
@@ -1266,29 +723,13 @@ initialization
   {$endif NetBSD}
   {$endif NetBSD}
 {$endif cpu68}
 {$endif cpu68}
 {$ifdef cpupowerpc32}
 {$ifdef cpupowerpc32}
-  {$ifdef Darwin}
-     set_source_info(system_powerpc_darwin_info);
-  {$endif Darwin}
   {$ifdef NetBSD}
   {$ifdef NetBSD}
      set_source_info(system_powerpc_netbsd_info);
      set_source_info(system_powerpc_netbsd_info);
   {$endif}
   {$endif}
 {$endif cpupowerpc32}
 {$endif cpupowerpc32}
-{$ifdef cpupowerpc64}
-  {$ifdef Darwin}
-     set_source_info(system_powerpc64_darwin_info);
-  {$endif Darwin}
-{$endif powerpc64}
 {$ifdef cpuarm}
 {$ifdef cpuarm}
-  {$ifdef Darwin}
-     set_source_info(system_arm_darwin_info);
-  {$endif Darwin}
   {$ifdef NetBSD}
   {$ifdef NetBSD}
      set_source_info(system_arm_netbsd_info);
      set_source_info(system_arm_netbsd_info);
   {$endif}
   {$endif}
 {$endif cpuarm}
 {$endif cpuarm}
-{$ifdef cpuaarch64}
-  {$ifdef Darwin}
-     set_source_info(system_aarch64_darwin_info);
-  {$endif Darwin}
-{$endif cpuaarch64}
 end.
 end.

+ 680 - 0
compiler/systems/i_darwin.pas

@@ -0,0 +1,680 @@
+{
+    Copyright (c) 1998-2008 by Peter Vreman
+
+    This unit implements support information structures for Darwin
+    (Mac OS X/OS X/macOS/iOS/iPhoneSimulator/...)
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ ****************************************************************************
+}
+unit i_darwin;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+   systems;
+
+const
+   res_macho_info : tresinfo =
+       (
+         id     : res_macho;
+         resbin : 'fpcres';
+         rescmd : '-o $OBJ -a $ARCH -s $SUBARCH -of mach-o $DBG';
+         rcbin  : 'windres';
+         rccmd  : '--include $INC -O res -D FPC -o $RES $RC';
+         resourcefileclass : nil;
+         resflags : [];
+       );
+   res_macosx_ext_info : tresinfo =
+      (
+         id     : res_ext;
+         resbin : 'fpcres';
+         rescmd : '-o $OBJ -a $ENDIAN -of external $DBG';
+         rcbin  : 'windres';
+         rccmd  : '--include $INC -O res -D FPC -o $RES $RC';
+         resourcefileclass : nil;
+         resflags : [res_external_file,res_arch_in_file_name];
+      );
+
+   system_powerpc_darwin_info  : tsysteminfo =
+      (
+        system       : system_powerpc_darwin;
+        name         : 'Darwin for PowerPC';
+        shortname    : 'Darwin';
+        flags        : [tf_p_ext_support,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,tf_dwarf_only_local_labels,tf_pic_default,tf_has_winlike_resources];
+        cpu          : cpu_powerpc;
+        unit_env     : 'BSDUNITS';
+        extradefines : 'UNIX;BSD;HASUNIX';
+        exeext       : '';
+        defext       : '.def';
+        scriptext    : '.sh';
+        smartext     : '.sl';
+        unitext      : '.ppu';
+        unitlibext   : '.ppl';
+        asmext       : '.s';
+        objext       : '.o';
+        resext       : '.res';
+        resobjext    : '.or';
+        sharedlibext : '.dylib';
+        staticlibext : '.a';
+        staticlibprefix : 'libp';
+        sharedlibprefix : 'lib';
+        sharedClibext : '.dylib';
+        staticClibext : '.a';
+        staticClibprefix : 'lib';
+        sharedClibprefix : 'lib';
+        importlibprefix : 'libimp';
+        importlibext : '.a';
+        Cprefix      : '_';
+        newline      : #10;
+        dirsep       : '/';
+        assem        : as_darwin;
+        assemextern  : as_darwin;
+        link         : ld_none;
+        linkextern   : ld_darwin;
+        ar           : ar_gnu_ar;
+        res          : res_macho;
+        dbg          : dbg_stabs;
+        script       : script_unix;
+        endian       : endian_big;
+        alignment    :
+          (
+            procalign       : 16;
+            loopalign       : 4;
+            jumpalign       : 0;
+            constalignmin   : 0;
+            constalignmax   : 4;
+            varalignmin     : 0;
+            varalignmax     : 4;
+            localalignmin   : 0;
+            localalignmax   : 4;
+            recordalignmin  : 0;
+            recordalignmax  : 4;
+            maxCrecordalign : 4
+          );
+        first_parm_offset : 24;
+        stacksize   : 262144;
+        stackalign   : 16;
+        abi : abi_powerpc_darwin;
+        llvmdatalayout : 'E-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:64:64-v128:128:128-n32';
+      );
+
+
+
+   system_i386_darwin_info  : tsysteminfo =
+      (
+        system       : system_i386_darwin;
+        name         : 'Darwin for i386';
+        shortname    : 'Darwin';
+        flags        : [tf_p_ext_support,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,tf_dwarf_only_local_labels,tf_pic_uses_got,
+                        tf_pic_default,tf_has_winlike_resources,tf_use_hlcfi,tf_supports_symbolorderfile];
+        cpu          : cpu_i386;
+        unit_env     : 'BSDUNITS';
+        extradefines : 'UNIX;BSD;HASUNIX';
+        exeext       : '';
+        defext       : '.def';
+        scriptext    : '.sh';
+        smartext     : '.sl';
+        unitext      : '.ppu';
+        unitlibext   : '.ppl';
+        asmext       : '.s';
+        objext       : '.o';
+        resext       : '.res';
+        resobjext    : '.or';
+        sharedlibext : '.dylib';
+        staticlibext : '.a';
+        staticlibprefix : 'libp';
+        sharedlibprefix : 'lib';
+        sharedClibext : '.dylib';
+        staticClibext : '.a';
+        staticClibprefix : 'lib';
+        sharedClibprefix : 'lib';
+        importlibprefix : 'libimp';
+        importlibext : '.a';
+        Cprefix      : '_';
+        newline      : #10;
+        dirsep       : '/';
+        assem        : as_clang_asdarwin;
+        assemextern  : as_clang_asdarwin;
+        link         : ld_none;
+        linkextern   : ld_darwin;
+        ar           : ar_gnu_ar;
+        res          : res_macho;
+        dbg          : dbg_dwarf2;
+        script       : script_unix;
+        endian       : endian_little;
+        alignment    :
+          (
+            procalign       : 16;
+            loopalign       : 8;
+            jumpalign       : 16;
+            constalignmin   : 0;
+            constalignmax   : 16;
+            varalignmin     : 0;
+            varalignmax     : 16;
+            localalignmin   : 0;
+            localalignmax   : 8;
+            recordalignmin  : 0;
+            recordalignmax  : 16;
+            maxCrecordalign : 16
+          );
+        first_parm_offset : 8;
+        stacksize   : 262144;
+        stackalign   : 16;
+        abi         : abi_i386_dynalignedstack;
+        llvmdatalayout : 'e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32-S128';
+      );
+
+
+
+   system_i386_iphonesim_info  : tsysteminfo =
+      (
+        system       : system_i386_iphonesim;
+        name         : 'Darwin/iPhoneSim for i386';
+        shortname    : 'iPhoneSim';
+        flags        : [tf_p_ext_support,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,tf_dwarf_only_local_labels,
+                        tf_pic_uses_got,tf_pic_default,tf_has_winlike_resources,tf_use_hlcfi];
+        cpu          : cpu_i386;
+        unit_env     : 'BSDUNITS';
+        extradefines : 'UNIX;BSD;HASUNIX;DARWIN'; // also define darwin for code compatibility
+        exeext       : '';
+        defext       : '.def';
+        scriptext    : '.sh';
+        smartext     : '.sl';
+        unitext      : '.ppu';
+        unitlibext   : '.ppl';
+        asmext       : '.s';
+        objext       : '.o';
+        resext       : '.res';
+        resobjext    : '.or';
+        sharedlibext : '.dylib';
+        staticlibext : '.a';
+        staticlibprefix : 'libp';
+        sharedlibprefix : 'lib';
+        sharedClibext : '.dylib';
+        staticClibext : '.a';
+        staticClibprefix : 'lib';
+        sharedClibprefix : 'lib';
+        importlibprefix : 'libimp';
+        importlibext : '.a';
+        Cprefix      : '_';
+        newline      : #10;
+        dirsep       : '/';
+        assem        : as_clang_asdarwin;
+        assemextern  : as_clang_asdarwin;
+        link         : ld_none;
+        linkextern   : ld_darwin;
+        ar           : ar_gnu_ar;
+        res          : res_macho;
+        dbg          : dbg_dwarf2;
+        script       : script_unix;
+        endian       : endian_little;
+        alignment    :
+          (
+            procalign       : 16;
+            loopalign       : 8;
+            jumpalign       : 16;
+            constalignmin   : 0;
+            constalignmax   : 16;
+            varalignmin     : 0;
+            varalignmax     : 16;
+            localalignmin   : 0;
+            localalignmax   : 16;
+            recordalignmin  : 0;
+            recordalignmax  : 16;
+            maxCrecordalign : 16
+          );
+        first_parm_offset : 8;
+        stacksize   : 262144;
+        stackalign   : 16;
+        abi         : abi_i386_dynalignedstack;
+        llvmdatalayout : 'e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:128:128-n8:16:32-S128';
+      );
+
+
+
+   system_powerpc64_darwin_info  : tsysteminfo =
+      (
+        system       : system_powerpc64_darwin;
+        name         : 'Darwin for PowerPC64';
+        shortname    : 'Darwin';
+        flags        : [tf_p_ext_support,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,tf_dwarf_only_local_labels,
+                        tf_pic_default,tf_has_winlike_resources,tf_supports_symbolorderfile];
+        cpu          : cpu_powerpc64;
+        unit_env     : 'BSDUNITS';
+        extradefines : 'UNIX;BSD;HASUNIX';
+        exeext       : '';
+        defext       : '.def';
+        scriptext    : '.sh';
+        smartext     : '.sl';
+        unitext      : '.ppu';
+        unitlibext   : '.ppl';
+        asmext       : '.s';
+        objext       : '.o';
+        resext       : '.res';
+        resobjext    : '.or';
+        sharedlibext : '.dylib';
+        staticlibext : '.a';
+        staticlibprefix : 'libp';
+        sharedlibprefix : 'lib';
+        sharedClibext : '.dylib';
+        staticClibext : '.a';
+        staticClibprefix : 'lib';
+        sharedClibprefix : 'lib';
+        importlibprefix : 'libimp';
+        importlibext : '.a';
+        Cprefix      : '_';
+        newline      : #10;
+        dirsep       : '/';
+        assem        : as_darwin;
+        assemextern  : as_darwin;
+        link         : ld_none;
+        linkextern   : ld_darwin;
+        ar           : ar_gnu_ar;
+        res          : res_macho;
+        dbg          : dbg_dwarf2;
+        script       : script_unix;
+        endian       : endian_big;
+        alignment    :
+          (
+            procalign       : 16;
+            loopalign       : 4;
+            jumpalign       : 0;
+            constalignmin   : 4;
+            constalignmax   : 8;
+            varalignmin     : 4;
+            varalignmax     : 8;
+            localalignmin   : 4;
+            localalignmax   : 8;
+            recordalignmin  : 0;
+            recordalignmax  : 8;
+            maxCrecordalign : 4
+          );
+        first_parm_offset : 48;
+        stacksize   : 262144;
+        stackalign   : 16;
+        abi : abi_powerpc_darwin;
+        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-v128:128:128-n32:64';
+      );
+
+
+
+   system_x86_64_darwin_info  : tsysteminfo =
+      (
+        system       : system_x86_64_darwin;
+        name         : 'Darwin for x86_64';
+        shortname    : 'Darwin';
+        flags        : [tf_p_ext_support,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,tf_dwarf_only_local_labels,tf_pic_default,tf_has_winlike_resources,tf_use_hlcfi
+                        {$ifdef llvm},tf_use_psabieh{$endif},tf_supports_symbolorderfile];
+        cpu          : cpu_x86_64;
+        unit_env     : 'BSDUNITS';
+        extradefines : 'UNIX;BSD;HASUNIX';
+        exeext       : '';
+        defext       : '.def';
+        scriptext    : '.sh';
+        smartext     : '.sl';
+        unitext      : '.ppu';
+        unitlibext   : '.ppl';
+        asmext       : '.s';
+        objext       : '.o';
+        resext       : '.res';
+        resobjext    : '.or';
+        sharedlibext : '.dylib';
+        staticlibext : '.a';
+        staticlibprefix : 'libp';
+        sharedlibprefix : 'lib';
+        sharedClibext : '.dylib';
+        staticClibext : '.a';
+        staticClibprefix : 'lib';
+        sharedClibprefix : 'lib';
+        importlibprefix : 'libimp';
+        importlibext : '.a';
+        Cprefix      : '_';
+        newline      : #10;
+        dirsep       : '/';
+        assem        : as_clang_asdarwin;
+        assemextern  : as_clang_asdarwin;
+        link         : ld_none;
+        linkextern   : ld_darwin;
+        ar           : ar_gnu_ar;
+        res          : res_macho;
+        dbg          : dbg_dwarf2;
+        script       : script_unix;
+        endian       : endian_little;
+        alignment    :
+          (
+            procalign       : 16;
+            loopalign       : 8;
+            jumpalign       : 16;
+            constalignmin   : 0;
+            constalignmax   : 16;
+            varalignmin     : 0;
+            varalignmax     : 16;
+            localalignmin   : 4;
+            localalignmax   : 16;
+            recordalignmin  : 0;
+            recordalignmax  : 16;
+            maxCrecordalign : 16
+          );
+        first_parm_offset : 16;
+        stacksize   : 262144;
+        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-s0:64:64-f80:128:128-n8:16:32:64-S128';
+      );
+
+
+   system_x86_64_iphonesim_info  : tsysteminfo =
+      (
+        system       : system_x86_64_iphonesim;
+        name         : 'Darwin/iPhoneSim for x86_64';
+        shortname    : 'iPhoneSim';
+        flags        : [tf_p_ext_support,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,tf_dwarf_only_local_labels,
+                        tf_pic_default,tf_has_winlike_resources,tf_use_hlcfi];
+        cpu          : cpu_x86_64;
+        unit_env     : 'BSDUNITS';
+        extradefines : 'UNIX;BSD;HASUNIX;DARWIN'; // also define darwin for code compatibility
+        exeext       : '';
+        defext       : '.def';
+        scriptext    : '.sh';
+        smartext     : '.sl';
+        unitext      : '.ppu';
+        unitlibext   : '.ppl';
+        asmext       : '.s';
+        objext       : '.o';
+        resext       : '.res';
+        resobjext    : '.or';
+        sharedlibext : '.dylib';
+        staticlibext : '.a';
+        staticlibprefix : 'libp';
+        sharedlibprefix : 'lib';
+        sharedClibext : '.dylib';
+        staticClibext : '.a';
+        staticClibprefix : 'lib';
+        sharedClibprefix : 'lib';
+        importlibprefix : 'libimp';
+        importlibext : '.a';
+        Cprefix      : '_';
+        newline      : #10;
+        dirsep       : '/';
+        assem        : as_clang_asdarwin;
+        assemextern  : as_clang_asdarwin;
+        link         : ld_none;
+        linkextern   : ld_darwin;
+        ar           : ar_gnu_ar;
+        res          : res_macho;
+        dbg          : dbg_dwarf2;
+        script       : script_unix;
+        endian       : endian_little;
+        alignment    :
+          (
+            procalign       : 16;
+            loopalign       : 8;
+            jumpalign       : 16;
+            constalignmin   : 0;
+            constalignmax   : 16;
+            varalignmin     : 0;
+            varalignmax     : 16;
+            localalignmin   : 4;
+            localalignmax   : 16;
+            recordalignmin  : 0;
+            recordalignmax  : 16;
+            maxCrecordalign : 16
+          );
+        first_parm_offset : 16;
+        stacksize   : 262144;
+        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-s0:64:64-f80:128:128-n8:16:32:64-S128';
+      );
+
+
+   system_arm_ios_info : tsysteminfo =
+      (
+        system       : system_arm_ios;
+        name         : 'iOS for ARM';
+        shortname    : 'iOS';
+        flags        : [tf_p_ext_support,tf_requires_proper_alignment,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,
+                        tf_dwarf_only_local_labels,tf_has_winlike_resources,tf_pic_default,tf_supports_symbolorderfile];
+        cpu          : cpu_arm;
+        unit_env     : 'BSDUNITS';
+        extradefines : 'UNIX;BSD;HASUNIX;CPUARMEL;DARWIN';
+        exeext       : '';
+        defext       : '.def';
+        scriptext    : '.sh';
+        smartext     : '.sl';
+        unitext      : '.ppu';
+        unitlibext   : '.ppl';
+        asmext       : '.s';
+        objext       : '.o';
+        resext       : '.res';
+        resobjext    : '.or';
+        sharedlibext : '.dylib';
+        staticlibext : '.a';
+        staticlibprefix : 'libp';
+        sharedlibprefix : 'lib';
+        sharedClibext : '.dylib';
+        staticClibext : '.a';
+        staticClibprefix : 'lib';
+        sharedClibprefix : 'lib';
+        importlibprefix : 'libimp';
+        importlibext : '.a';
+        Cprefix      : '_';
+        newline      : #10;
+        dirsep       : '/';
+        assem        : as_clang_asdarwin;
+        assemextern  : as_clang_asdarwin;
+        link         : ld_none;
+        linkextern   : ld_darwin;
+        ar           : ar_gnu_ar;
+        res          : res_macho;
+        dbg          : dbg_dwarf2;
+        script       : script_unix;
+        endian       : endian_little;
+        alignment    :
+          (
+            procalign       : 16;
+            loopalign       : 4;
+            jumpalign       : 0;
+            constalignmin   : 0;
+            constalignmax   : 8;
+            varalignmin     : 0;
+            varalignmax     : 8;
+            localalignmin   : 4;
+            localalignmax   : 8;
+            recordalignmin  : 0;
+            recordalignmax  : 8;
+            maxCrecordalign : 8
+          );
+        first_parm_offset : 8;
+        stacksize    : 262144;
+        stackalign   : 4;
+        abi : abi_default;
+        { note: default LLVM stack alignment is 8 bytes for this target }
+        llvmdatalayout : 'e-p:32:32:32-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:64:128-a0:0:64-n32-S32';
+      );
+
+
+   system_aarch64_ios_info  : tsysteminfo =
+      (
+        system       : system_aarch64_ios;
+        name         : 'iOS for AArch64';
+        shortname    : 'iOS';
+        flags        : [tf_p_ext_support,tf_requires_proper_alignment,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,
+                        tf_dwarf_only_local_labels,tf_pic_default,tf_has_winlike_resources,tf_supports_symbolorderfile];
+        cpu          : cpu_aarch64;
+        unit_env     : 'BSDUNITS';
+        extradefines : 'UNIX;BSD;HASUNIX;DARWIN';
+        exeext       : '';
+        defext       : '.def';
+        scriptext    : '.sh';
+        smartext     : '.sl';
+        unitext      : '.ppu';
+        unitlibext   : '.ppl';
+        asmext       : '.s';
+        objext       : '.o';
+        resext       : '.res';
+        resobjext    : '.or';
+        sharedlibext : '.dylib';
+        staticlibext : '.a';
+        staticlibprefix : 'libp';
+        sharedlibprefix : 'lib';
+        sharedClibext : '.dylib';
+        staticClibext : '.a';
+        staticClibprefix : 'lib';
+        sharedClibprefix : 'lib';
+        importlibprefix : 'libimp';
+        importlibext : '.a';
+        Cprefix      : '_';
+        newline      : #10;
+        dirsep       : '/';
+        assem        : as_clang_asdarwin;
+        assemextern  : as_clang_asdarwin;
+        link         : ld_none;
+        linkextern   : ld_darwin;
+        ar           : ar_gnu_ar;
+        res          : res_macho;
+        dbg          : dbg_dwarf2;
+        script       : script_unix;
+        endian       : endian_little;
+        alignment    :
+          (
+            procalign       : 16;
+            loopalign       : 4;
+            jumpalign       : 0;
+            constalignmin   : 0;
+            constalignmax   : 16;
+            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_aarch64_darwin;
+        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_aarch64_darwin_info  : tsysteminfo =
+      (
+        system       : system_aarch64_darwin;
+        name         : 'Darwin for AArch64';
+        shortname    : 'Darwin';
+        flags        : [tf_p_ext_support,tf_requires_proper_alignment,tf_files_case_sensitive,tf_smartlink_sections,tf_dwarf_relative_addresses,
+                        tf_dwarf_only_local_labels,tf_pic_default,tf_has_winlike_resources,tf_supports_symbolorderfile
+                        {$ifdef llvm},tf_use_psabieh{$endif}];
+        cpu          : cpu_aarch64;
+        unit_env     : 'BSDUNITS';
+        extradefines : 'UNIX;BSD;HASUNIX';
+        exeext       : '';
+        defext       : '.def';
+        scriptext    : '.sh';
+        smartext     : '.sl';
+        unitext      : '.ppu';
+        unitlibext   : '.ppl';
+        asmext       : '.s';
+        objext       : '.o';
+        resext       : '.res';
+        resobjext    : '.or';
+        sharedlibext : '.dylib';
+        staticlibext : '.a';
+        staticlibprefix : 'libp';
+        sharedlibprefix : 'lib';
+        sharedClibext : '.dylib';
+        staticClibext : '.a';
+        staticClibprefix : 'lib';
+        sharedClibprefix : 'lib';
+        importlibprefix : 'libimp';
+        importlibext : '.a';
+        Cprefix      : '_';
+        newline      : #10;
+        dirsep       : '/';
+        assem        : as_clang_asdarwin;
+        assemextern  : as_clang_asdarwin;
+        link         : ld_none;
+        linkextern   : ld_darwin;
+        ar           : ar_gnu_ar;
+        res          : res_macho;
+        dbg          : dbg_dwarf2;
+        script       : script_unix;
+        endian       : endian_little;
+        alignment    :
+          (
+            procalign       : 16;
+            loopalign       : 4;
+            jumpalign       : 0;
+            constalignmin   : 0;
+            constalignmax   : 16;
+            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_aarch64_darwin;
+        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'
+      );
+
+implementation
+
+initialization
+  {$ifdef cpui386}
+    {$ifdef Darwin}
+      set_source_info(system_i386_Darwin_info);
+    {$endif Darwin}
+  {$endif cpui386}
+  {$ifdef cpux86_64}
+    {$ifdef Darwin}
+      set_source_info(system_x86_64_darwin_info);
+    {$endif}
+  {$endif cpux86_64}
+  {$ifdef cpupowerpc32}
+    {$ifdef Darwin}
+      set_source_info(system_powerpc_darwin_info);
+    {$endif Darwin}
+  {$endif cpupowerpc32}
+  {$ifdef cpupowerpc64}
+    {$ifdef Darwin}
+      set_source_info(system_powerpc64_darwin_info);
+    {$endif Darwin}
+  {$endif powerpc64}
+  {$ifdef cpuarm}
+    {$ifdef Darwin}
+      set_source_info(system_arm_ios_info);
+    {$endif Darwin}
+  {$endif cpuarm}
+  {$ifdef cpuaarch64}
+    {$ifdef Darwin}
+      {$ifdef ios}
+        set_source_info(system_aarch64_ios_info);
+      {$else}
+        set_source_info(system_aarch64_darwin_info);
+      {$endif}
+    {$endif Darwin}
+  {$endif cpuaarch64}
+
+end.
+

+ 10 - 10
compiler/systems/i_macos.pas

@@ -28,15 +28,15 @@ unit i_macos;
     uses
     uses
        systems;
        systems;
      const
      const
-       system_powerpc_macos_info : tsysteminfo =
+       system_powerpc_macosclassic_info : tsysteminfo =
           (
           (
-            system       : system_powerpc_MACOS;
+            system       : system_powerpc_macosclassic;
             name         : 'Mac OS for PowerPC';
             name         : 'Mac OS for PowerPC';
-            shortname    : 'MacOS';
+            shortname    : 'MacOSClassic';
             flags        : [tf_p_ext_support,tf_files_case_aware];
             flags        : [tf_p_ext_support,tf_files_case_aware];
             cpu          : cpu_powerpc;
             cpu          : cpu_powerpc;
             unit_env     : '';
             unit_env     : '';
-            extradefines : '';
+            extradefines : 'MacOS';
             exeext       : '';
             exeext       : '';
             defext       : '';
             defext       : '';
             scriptext    : '';
             scriptext    : '';
@@ -92,15 +92,15 @@ unit i_macos;
           );
           );
 
 
      const
      const
-       system_m68k_macos_info : tsysteminfo =
+       system_m68k_macosclassic_info : tsysteminfo =
           (
           (
-            system       : system_m68k_macos;
+            system       : system_m68k_macosclassic;
             name         : 'Mac OS for m68k';
             name         : 'Mac OS for m68k';
-            shortname    : 'MacOS';
+            shortname    : 'MacOSClassic';
             flags        : [tf_p_ext_support,tf_files_case_aware];
             flags        : [tf_p_ext_support,tf_files_case_aware];
             cpu          : cpu_m68k;
             cpu          : cpu_m68k;
             unit_env     : '';
             unit_env     : '';
-            extradefines : '';
+            extradefines : 'MacOS';
             exeext       : '';
             exeext       : '';
             defext       : '';
             defext       : '';
             scriptext    : '';
             scriptext    : '';
@@ -160,12 +160,12 @@ unit i_macos;
 initialization
 initialization
 {$ifdef cpupowerpc}
 {$ifdef cpupowerpc}
   {$ifdef macos}
   {$ifdef macos}
-    set_source_info(system_powerpc_macos_info);
+    set_source_info(system_powerpc_macosclassic_info);
   {$endif macos}
   {$endif macos}
 {$endif cpupowerpc}
 {$endif cpupowerpc}
 {$ifdef cpum68k}
 {$ifdef cpum68k}
   {$ifdef macos}
   {$ifdef macos}
-    set_source_info(system_m68k_macos_info);
+    set_source_info(system_m68k_macosclassic_info);
   {$endif macos}
   {$endif macos}
 {$endif cpum68k}
 {$endif cpum68k}
 end.
 end.

+ 98 - 539
compiler/systems/t_bsd.pas

@@ -40,10 +40,6 @@ implementation
     cgutils,cgbase,cgobj,cpuinfo,ogbase;
     cgutils,cgbase,cgobj,cpuinfo,ogbase;
 
 
   type
   type
-    timportlibdarwin=class(timportlib)
-      procedure generatelib;override;
-    end;
-
     timportlibbsd=class(timportlib)
     timportlibbsd=class(timportlib)
       procedure generatelib;override;
       procedure generatelib;override;
     end;
     end;
@@ -51,11 +47,6 @@ implementation
     texportlibbsd=class(texportlibunix)
     texportlibbsd=class(texportlibunix)
     end;
     end;
 
 
-    texportlibdarwin=class(texportlibbsd)
-      procedure setinitname(list: TAsmList; const s: string); override;
-      procedure setfininame(list: TAsmList; const s: string); override;
-    end;
-
     tlinkerbsd=class(texternallinker)
     tlinkerbsd=class(texternallinker)
     private
     private
       LdSupportsNoResponseFile : boolean;
       LdSupportsNoResponseFile : boolean;
@@ -64,8 +55,6 @@ implementation
       ReOrder : Boolean;
       ReOrder : Boolean;
       linklibc : boolean;
       linklibc : boolean;
       Function  WriteResponseFile(isdll:boolean) : Boolean;
       Function  WriteResponseFile(isdll:boolean) : Boolean;
-      function GetDarwinCrt1ObjName(isdll: boolean): TCmdStr;
-      Function GetDarwinPrtobjName(isdll: boolean): TCmdStr;
     public
     public
       constructor Create;override;
       constructor Create;override;
       procedure SetDefaultInfo;override;
       procedure SetDefaultInfo;override;
@@ -98,33 +87,6 @@ begin
 end;
 end;
 
 
 
 
-{*****************************************************************************
-                             TIMPORTLIBDARWIN
-*****************************************************************************}
-
-    procedure timportlibdarwin.generatelib;
-      begin
-      end;
-
-
-{*****************************************************************************
-                             TEXPORTLIBDARWIN
-*****************************************************************************}
-
-    procedure texportlibdarwin.setinitname(list: TAsmList; const s: string);
-      begin
-        new_section(list,sec_init_func,'',sizeof(pint));
-        list.concat(Tai_const.Createname(s,0));
-      end;
-
-
-    procedure texportlibdarwin.setfininame(list: TAsmList; const s: string);
-      begin
-        new_section(list,sec_term_func,'',sizeof(pint));
-        list.concat(Tai_const.Createname(s,0));
-      end;
-
-
 {*****************************************************************************
 {*****************************************************************************
                                TIMPORTLIBBSD
                                TIMPORTLIBBSD
 *****************************************************************************}
 *****************************************************************************}
@@ -150,10 +112,7 @@ Constructor TLinkerBSD.Create;
 begin
 begin
   Inherited Create;
   Inherited Create;
   if not Dontlinkstdlibpath Then
   if not Dontlinkstdlibpath Then
-   if target_info.system in systems_darwin then
-     { Mac OS X doesn't have a /lib }
-     LibrarySearchPath.AddLibraryPath(sysrootpath,'=/usr/lib',true)
-   else if target_info.system in systems_openbsd then
+   if target_info.system in systems_openbsd then
      LibrarySearchPath.AddLibraryPath(sysrootpath,'=/usr/lib;=$OPENBSD_X11BASE/lib;=$OPENBSD_LOCALBASE/lib',true)
      LibrarySearchPath.AddLibraryPath(sysrootpath,'=/usr/lib;=$OPENBSD_X11BASE/lib;=$OPENBSD_LOCALBASE/lib',true)
    else
    else
      LibrarySearchPath.AddLibraryPath(sysrootpath,'=/lib;=/usr/lib;=/usr/X11R6/lib',true);
      LibrarySearchPath.AddLibraryPath(sysrootpath,'=/lib;=/usr/lib;=/usr/X11R6/lib',true);
@@ -175,49 +134,15 @@ begin
    begin
    begin
      if LdSupportsNoResponseFile then
      if LdSupportsNoResponseFile then
        begin
        begin
-         if not(target_info.system in systems_darwin) then
-           begin
-             ExeCmd[1]:=LdProgram+' $TARGET $EMUL $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP $MAP -L. -o $EXE $CATRES $FILELIST';
-             DllCmd[1]:=LdProgram+' $TARGET $EMUL $OPT $MAP -shared -L. -o $EXE $CATRES $FILELIST'
-           end
-         else
-           begin
-{$ifndef cpu64bitaddr}
-             { Set the size of the page at address zero to 64kb, so nothing
-               is loaded below that address. This avoids problems with the
-               strange Windows-compatible resource handling that assumes
-               that addresses below 64kb do not exist.
-
-               On 64bit systems, page zero is 4GB by default, so no problems
-               there.
-             }
-             { In case of valgrind, don't do that, because it cannot deal with
-               a custom pagezero size -- in general, this should not cause any
-               problems because the resources are added at the end and most
-               programs with problems that require Valgrind will have more
-               than 60KB of data (first 4KB of address space is always invalid)
-             }
-               ExeCmd[1]:=LdProgram+' $PRTOBJ $TARGET $EMUL $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP $MAP -multiply_defined suppress -L. -o $EXE $CATRES $FILELIST';
-             if not(cs_gdb_valgrind in current_settings.globalswitches) then
-               ExeCmd[1]:=ExeCmd[1]+' -pagezero_size 0x10000';
-{$else ndef cpu64bitaddr}
-             ExeCmd[1]:=LdProgram+' $PRTOBJ $TARGET $EMUL $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP $MAP -multiply_defined suppress -L. -o $EXE $CATRES $FILELIST';
-{$endif ndef cpu64bitaddr}
-             if (apptype<>app_bundle) then
-               DllCmd[1]:=LdProgram+' $PRTOBJ $TARGET $EMUL $OPT $GCSECTIONS $MAP -dynamic -dylib -multiply_defined suppress -L. -o $EXE $CATRES $FILELIST'
-             else
-               DllCmd[1]:=LdProgram+' $PRTOBJ $TARGET $EMUL $OPT $GCSECTIONS $MAP -dynamic -bundle -multiply_defined suppress -L. -o $EXE $CATRES $FILELIST'
-           end
+         ExeCmd[1]:=LdProgram+' $TARGET $EMUL $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP $MAP $LTO $ORDERSYMS -L. -o $EXE $CATRES $FILELIST';
+         DllCmd[1]:=LdProgram+' $TARGET $EMUL $OPT $MAP $LTO $ORDERSYMS -shared -L. -o $EXE $CATRES $FILELIST'
        end
        end
      else
      else
        begin
        begin
-         ExeCmd[1]:=LdProgram+' $TARGET $EMUL $OPT $DYNLINK $STATIC  $GCSECTIONS $STRIP $MAP -L. -o $EXE $RES';
-         DllCmd[1]:=LdProgram+' $TARGET $EMUL $OPT $INIT $FINI $SONAME $MAP -shared -L. -o $EXE $RES';
+         ExeCmd[1]:=LdProgram+' $TARGET $EMUL $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP $MAP $ORDERSYMS -L. -o $EXE $RES';
+         DllCmd[1]:=LdProgram+' $TARGET $EMUL $OPT $INIT $FINI $SONAME $MAP $ORDERSYMS -shared -L. -o $EXE $RES';
        end;
        end;
-     if not(target_info.system in systems_darwin) then
-       DllCmd[2]:='strip --strip-unneeded $EXE'
-     else
-       DllCmd[2]:='strip -x $EXE';
+     DllCmd[2]:='strip --strip-unneeded $EXE';
      { OpenBSD seems to use a wrong dynamic linker by default }
      { OpenBSD seems to use a wrong dynamic linker by default }
      if target_info.system in systems_openbsd then
      if target_info.system in systems_openbsd then
       DynamicLinker:='/usr/libexec/ld.so'
       DynamicLinker:='/usr/libexec/ld.so'
@@ -234,26 +159,18 @@ procedure TLinkerBSD.LoadPredefinedLibraryOrder;
 // put your linkorder/linkalias overrides here.
 // put your linkorder/linkalias overrides here.
 // Note: assumes only called when reordering/aliasing is used.
 // Note: assumes only called when reordering/aliasing is used.
 Begin
 Begin
-  if not(target_info.system in systems_darwin) then
-    begin
-      if (target_info.system =system_i386_freebsd) and
-         not (cs_link_no_default_lib_order in  current_settings.globalswitches) Then
-        Begin
-          LinkLibraryOrder.add('gcc','',15);
-          LinkLibraryOrder.add('c','',50);		     // c and c_p mutual. excl?
-          LinkLibraryOrder.add('c_p','',55);
-          LinkLibraryOrder.add('pthread','',75);	     // pthread and c_r should be mutually exclusive
-          LinkLibraryOrder.add('c_r','',76);
-          LinkLibraryOrder.add('kvm','',80);		     // must be before ncurses
-          if (cs_link_pthread in current_settings.globalswitches) Then     // convert libpthread to libc_r.
-            LinkLibraryAliases.add('pthread','c_r');
-        end;
-    end
-else
-    begin
-          LinkLibraryOrder.add('gcc','',15);
-          LinkLibraryOrder.add('c','',50);
-   end;
+  if (target_info.system =system_i386_freebsd) and
+     not (cs_link_no_default_lib_order in  current_settings.globalswitches) Then
+    Begin
+      LinkLibraryOrder.add('gcc','',15);
+      LinkLibraryOrder.add('c','',50);		     // c and c_p mutual. excl?
+      LinkLibraryOrder.add('c_p','',55);
+      LinkLibraryOrder.add('pthread','',75);	     // pthread and c_r should be mutually exclusive
+      LinkLibraryOrder.add('c_r','',76);
+      LinkLibraryOrder.add('kvm','',80);		     // must be before ncurses
+      if (cs_link_pthread in current_settings.globalswitches) Then     // convert libpthread to libc_r.
+        LinkLibraryAliases.add('pthread','c_r');
+    end;
 End;
 End;
 
 
 
 
@@ -264,210 +181,50 @@ var
   si_cprt,
   si_cprt,
   si_gprt : string[80];
   si_gprt : string[80];
 begin
 begin
-  if target_info.system in systems_darwin then
+  linklibc:=ModulesLinkToLibc;
+  if current_module.islibrary and
+     (target_info.system in systems_bsd) then
     begin
     begin
-      { for darwin: always link dynamically against libc }
-      linklibc := true;
-      reorder:=reorderentries;
-      prtobj:='';
-      SysInitUnit:='sysinit';
+      prtobj:='dllprt0';
+      cprtobj:='dllprt0';
+      gprtobj:='dllprt0';
+      SysInitUnit:='si_dll';
+      si_cprt:='si_dll';
+      si_gprt:='si_dll';
     end
     end
   else
   else
     begin
     begin
-      linklibc:=ModulesLinkToLibc;
-      if current_module.islibrary and
-         (target_info.system in systems_bsd) then
-        begin
-          prtobj:='dllprt0';
-          cprtobj:='dllprt0';
-          gprtobj:='dllprt0';
-          SysInitUnit:='si_dll';
-          si_cprt:='si_dll';
-          si_gprt:='si_dll';
-        end
-      else
-        begin
-          prtobj:='prt0';
-          cprtobj:='cprt0';
-          gprtobj:='gprt0';
-          SysInitUnit:='si_prc';
-          si_cprt:='si_c';
-          si_gprt:='si_g';
-        end;
-      // this one is a bit complex.
-      // Only reorder for now if -XL or -XO params are given
-      // or when -Xf.
-      reorder:= linklibc and
-                (
-                  ReorderEntries
-                   or
-                  (cs_link_pthread in current_settings.globalswitches));
-      if cs_profile in current_settings.moduleswitches then
-       begin
-         prtobj:=gprtobj;
-         SysInitUnit:=si_gprt;
-         AddSharedLibrary('c');
-         LibrarySuffix:='p';
-         linklibc:=true;
-       end
-      else
-       begin
-         if linklibc then
-           begin
-             prtobj:=cprtobj;
-             SysInitUnit:=si_cprt;
-           end;
-       end;
+      prtobj:='prt0';
+      cprtobj:='cprt0';
+      gprtobj:='gprt0';
+      SysInitUnit:='si_prc';
+      si_cprt:='si_c';
+      si_gprt:='si_g';
     end;
     end;
-end;
-
-
-function TLinkerBSD.GetDarwinCrt1ObjName(isdll: boolean): TCmdStr;
-begin
-  if not isdll then
-    begin
-      if not(cs_profile in current_settings.moduleswitches) then
-        begin
-          case target_info.system of
-            system_powerpc_darwin,
-            system_powerpc64_darwin,
-            system_i386_darwin,
-            system_x86_64_darwin:
-              begin
-                { 10.8 and later: no crt1.* }
-                if CompareVersionStrings(MacOSXVersionMin,'10.8')>=0 then
-                  exit('');
-                { x86: crt1.10.6.o -> crt1.10.5.o -> crt1.o }
-                { others: crt1.10.5 -> crt1.o }
-                if (target_info.system in [system_i386_darwin,system_x86_64_darwin]) and
-                   (CompareVersionStrings(MacOSXVersionMin,'10.6')>=0) then
-                  exit('crt1.10.6.o');
-                if CompareVersionStrings(MacOSXVersionMin,'10.5')>=0 then
-                  exit('crt1.10.5.o');
-              end;
-            system_arm_darwin:
-              begin
-                { iOS:
-                    iOS 6 and later: nothing
-                    iOS 3.1 - 5.x: crt1.3.1.o
-                    pre-iOS 3.1: crt1.o
-                }
-                if (CompareVersionStrings(iPhoneOSVersionMin,'6.0')>=0) then
-                  exit('');
-                if (CompareVersionStrings(iPhoneOSVersionMin,'3.1')>=0) then
-                  exit('crt1.3.1.o');
-              end;
-            system_i386_iphonesim,
-            system_x86_64_iphonesim:
-              begin
-                { "recent versions" must not use anything (https://github.com/llvm-mirror/clang/commit/e6d04f3d152a22077022cf9287d4c538a0918ab0 )
-                  What those recent versions could be, is anyone's guess. It
-                  still seems to work with 8.1 and no longer with 8.3, so use
-                  8.1 as a cut-off point }
-                if (CompareVersionStrings(iPhoneOSVersionMin,'8.1')>0) then
-                  exit('');
-              end;
-            system_aarch64_darwin:
-              { never anything }
-              exit('');
-          end;
-          { nothing special -> default }
-          result:='crt1.o';
-        end
-      else
-        begin
-          result:='gcrt1.o';
-          { 10.8 and later: tell the linker to use 'start' instead of "_main"
-            as entry point }
-          if CompareVersionStrings(MacOSXVersionMin,'10.8')>=0 then
-            Info.ExeCmd[1]:=Info.ExeCmd[1]+' -no_new_main';
-        end;
-    end
+  // this one is a bit complex.
+  // Only reorder for now if -XL or -XO params are given
+  // or when -Xf.
+  reorder:= linklibc and
+            (
+              ReorderEntries
+               or
+              (cs_link_pthread in current_settings.globalswitches));
+  if cs_profile in current_settings.moduleswitches then
+   begin
+     prtobj:=gprtobj;
+     SysInitUnit:=si_gprt;
+     AddSharedLibrary('c');
+     LibrarySuffix:='p';
+     linklibc:=true;
+   end
   else
   else
-    begin
-      if (apptype=app_bundle) then
-        begin
-          case target_info.system of
-            system_powerpc_darwin,
-            system_powerpc64_darwin,
-            system_i386_darwin,
-            system_x86_64_darwin:
-              begin
-                { < 10.6: bundle1.o
-                  >= 10.6: nothing }
-                if CompareVersionStrings(MacOSXVersionMin,'10.6')>=0 then
-                  exit('');
-              end;
-            system_arm_darwin,
-            system_aarch64_darwin:
-              begin
-                { iOS: < 3.1: bundle1.o
-                       >= 3.1: nothing }
-                if (CompareVersionStrings(iPhoneOSVersionMin,'3.1')>=0) then
-                  exit('');
-              end;
-            system_i386_iphonesim,
-            system_x86_64_iphonesim:
-              begin
-                { see rule for crt1.o }
-                if (CompareVersionStrings(iPhoneOSVersionMin,'8.1')>0) then
-                  exit('');
-              end;
-          end;
-          result:='bundle1.o';
-        end
-      else
-        begin
-          case target_info.system of
-            system_powerpc_darwin,
-            system_powerpc64_darwin,
-            system_i386_darwin,
-            system_x86_64_darwin:
-              begin
-                { >= 10.6: nothing
-                  = 10.5: dylib1.10.5.o
-                  < 10.5: dylib1.o
-                }
-                if CompareVersionStrings(MacOSXVersionMin,'10.6')>=0 then
-                  exit('');
-                if CompareVersionStrings(MacOSXVersionMin,'10.5')>=0 then
-                  exit('dylib1.10.5.o');
-              end;
-            system_arm_darwin,
-            system_aarch64_darwin:
-              begin
-                { iOS: < 3.1: dylib1.o
-                       >= 3.1: nothing }
-                if (CompareVersionStrings(iPhoneOSVersionMin,'3.1')>=0) then
-                  exit('');
-              end;
-            system_i386_iphonesim,
-            system_x86_64_iphonesim:
-              begin
-                { see rule for crt1.o }
-                if (CompareVersionStrings(iPhoneOSVersionMin,'8.1')>0) then
-                  exit('');
-              end;
-          end;
-          result:='dylib1.o';
-        end;
-    end;
-end;
-
-
-Function TLinkerBSD.GetDarwinPrtobjName(isdll: boolean): TCmdStr;
-var
-  startupfile: TCmdStr;
-begin
-  result:='';
-
-  startupfile:=GetDarwinCrt1ObjName(isdll);
-  if startupfile<>'' then
-    begin
-     if not librarysearchpath.FindFile(startupfile,false,result) then
-       result:='/usr/lib/'+startupfile;
-    end;
-  result:=maybequoted(result);
+   begin
+     if linklibc then
+       begin
+         prtobj:=cprtobj;
+         SysInitUnit:=si_cprt;
+       end;
+   end;
 end;
 end;
 
 
 
 
@@ -480,29 +237,14 @@ Var
   s,s1,s2      : TCmdStr;
   s,s1,s2      : TCmdStr;
   linkdynamic  : boolean;
   linkdynamic  : boolean;
   Fl1,Fl2      : Boolean;
   Fl1,Fl2      : Boolean;
-  IsDarwin     : Boolean;
 
 
 begin
 begin
   WriteResponseFile:=False;
   WriteResponseFile:=False;
   ReOrder:=False;
   ReOrder:=False;
   linkdynamic:=False;
   linkdynamic:=False;
-  IsDarwin:=target_info.system in systems_darwin;
-{ set special options for some targets }
-  if not IsDarwin Then
-    begin
-      linkdynamic:=not(SharedLibFiles.empty);
-      // after this point addition of shared libs not allowed.
-    end
-  else
-    begin
-{$ifdef MACOSX104ORHIGHER}
-      { not sure what this is for, but gcc always links against it }
-      if not(cs_profile in current_settings.moduleswitches) then
-        AddSharedLibrary('SystemStubs')
-      else
-        AddSharedLibrary('SystemStubs_profile');
-{$endif MACOSX104ORHIGHER}
-    end;
+  { set special options for some targets }
+  linkdynamic:=not(SharedLibFiles.empty);
+  // after this point addition of shared libs not allowed.
 
 
   if reorder Then
   if reorder Then
      ExpandAndApplyOrder(SharedLibFiles);
      ExpandAndApplyOrder(SharedLibFiles);
@@ -510,47 +252,6 @@ begin
   { Open link.res file }
   { Open link.res file }
   LinkRes:=TLinkRes.Create(outputexedir+Info.ResName,not LdSupportsNoResponseFile);
   LinkRes:=TLinkRes.Create(outputexedir+Info.ResName,not LdSupportsNoResponseFile);
 
 
-  if (target_info.system in systems_darwin) and
-     (sysrootpath<>'') then
-    begin
-      LinkRes.Add('-syslibroot');
-      LinkRes.Add(sysrootpath);
-    end;
-
-  if (target_info.system in systems_darwin) then
-    begin
-      LinkRes.Add('-arch');
-      case target_info.system of
-        system_powerpc_darwin:
-          LinkRes.Add('ppc');
-        system_i386_darwin,
-        system_i386_iphonesim:
-          LinkRes.Add('i386');
-        system_powerpc64_darwin:
-          LinkRes.Add('ppc64');
-        system_x86_64_darwin,
-        system_x86_64_iphonesim:
-          LinkRes.Add('x86_64');
-        system_arm_darwin:
-          { current versions of the linker require the sub-architecture type
-            to be specified }
-          LinkRes.Add(lower(cputypestr[current_settings.cputype]));
-        system_aarch64_darwin:
-          LinkRes.Add('arm64');
-        else
-          internalerror(2014121801);
-      end;
-      if MacOSXVersionMin<>'' then
-        begin
-          LinkRes.Add('-macosx_version_min');
-          LinkRes.Add(MacOSXVersionMin);
-        end
-      else if iPhoneOSVersionMin<>'' then
-        begin
-          LinkRes.Add('-iphoneos_version_min');
-          LinkRes.Add(iPhoneOSVersionMin);
-        end;
-    end;
   { Write path to search libraries }
   { Write path to search libraries }
   HPath:=TCmdStrListItem(current_module.locallibrarysearchpath.First);
   HPath:=TCmdStrListItem(current_module.locallibrarysearchpath.First);
   while assigned(HPath) do
   while assigned(HPath) do
@@ -571,22 +272,6 @@ begin
      HPath:=TCmdStrListItem(HPath.Next);
      HPath:=TCmdStrListItem(HPath.Next);
    end;
    end;
 
 
-  if (target_info.system in systems_darwin) then
-    begin
-      HPath:=TCmdStrListItem(current_module.localframeworksearchpath.First);
-      while assigned(HPath) do
-       begin
-         LinkRes.Add('-F'+HPath.Str);
-         HPath:=TCmdStrListItem(HPath.Next);
-       end;
-      HPath:=TCmdStrListItem(FrameworkSearchPath.First);
-      while assigned(HPath) do
-       begin
-         LinkRes.Add('-F'+HPath.Str);
-         HPath:=TCmdStrListItem(HPath.Next);
-       end;
-    end;
-
   { force local symbol resolution (i.e., inside the shared }
   { force local symbol resolution (i.e., inside the shared }
   { library itself) for all non-exorted symbols, otherwise }
   { library itself) for all non-exorted symbols, otherwise }
   { several RTL symbols of FPC-compiled shared libraries   }
   { several RTL symbols of FPC-compiled shared libraries   }
@@ -616,8 +301,7 @@ begin
   if not (target_info.system in systems_internal_sysinit) and (prtobj<>'') then
   if not (target_info.system in systems_internal_sysinit) and (prtobj<>'') then
    LinkRes.AddFileName(FindObjectFile(prtobj,'',false));
    LinkRes.AddFileName(FindObjectFile(prtobj,'',false));
   { try to add crti and crtbegin if linking to C }
   { try to add crti and crtbegin if linking to C }
-  if linklibc and
-     not IsDarwin Then
+  if linklibc then
    begin
    begin
      if librarysearchpath.FindFile('crti.o',false,s) then
      if librarysearchpath.FindFile('crti.o',false,s) then
       LinkRes.AddFileName(s);
       LinkRes.AddFileName(s);
@@ -638,34 +322,15 @@ begin
    end;
    end;
 
 
   { main objectfiles }
   { main objectfiles }
-
-  if (target_info.system in systems_darwin) then
-   begin
-     FilesList:=TLinkRes.Create(outputexedir+'linkfiles.res',false);
-     while not ObjectFiles.Empty do
-      begin
-        s:=ObjectFiles.GetFirst;
-        if s<>'' then
-         begin
-           s:=TargetFixFileName(s);
-           FilesList.Add(s);
-         end;
-      end;
-     FilesList.writetodisk;
-     FilesList.Free;
-   end
-  else
-   begin
-     while not ObjectFiles.Empty do
-      begin
-        s:=ObjectFiles.GetFirst;
-        if s<>'' then
-          if LdSupportsNoResponseFile then
-            LinkRes.AddFileName(s)
-          else
-            LinkRes.AddFileName(maybequoted(s));
-      end;
-   end;
+   while not ObjectFiles.Empty do
+    begin
+      s:=ObjectFiles.GetFirst;
+      if s<>'' then
+        if LdSupportsNoResponseFile then
+          LinkRes.AddFileName(s)
+        else
+          LinkRes.AddFileName(maybequoted(s));
+    end;
 
 
   if not LdSupportsNoResponseFile then
   if not LdSupportsNoResponseFile then
    LinkRes.Add(')');
    LinkRes.Add(')');
@@ -729,17 +394,8 @@ begin
        LinkRes.Add(')');
        LinkRes.Add(')');
    end;
    end;
 
 
-  { frameworks for Darwin }
-  if IsDarwin then
-    while not FrameworkFiles.empty do
-      begin
-        LinkRes.Add('-framework');
-        LinkRes.Add(FrameworkFiles.GetFirst);
-      end;
-
   { objects which must be at the end }
   { objects which must be at the end }
-  if linklibc and
-     not IsDarwin Then
+  if linklibc then
    begin
    begin
      if ((cs_create_pic in current_settings.moduleswitches) and
      if ((cs_create_pic in current_settings.moduleswitches) and
          not (target_info.system in systems_openbsd)) or
          not (target_info.system in systems_openbsd)) or
@@ -774,8 +430,7 @@ var
   mapstr,
   mapstr,
   targetstr,
   targetstr,
   emulstr,
   emulstr,
-  extdbgbinstr,
-  extdbgcmdstr: TCmdStr;
+  ordersymfile: TCmdStr;
   linkscript: TAsmScript;
   linkscript: TAsmScript;
   DynLinkStr : string[60];
   DynLinkStr : string[60];
   GCSectionsStr,
   GCSectionsStr,
@@ -820,20 +475,13 @@ begin
         StaticStr:='-static';
         StaticStr:='-static';
     end;
     end;
   if (cs_link_strip in current_settings.globalswitches) then
   if (cs_link_strip in current_settings.globalswitches) then
-    if (target_info.system in systems_darwin) then
-      StripStr:='-x'
-    else
-      StripStr:='-s';
+    StripStr:='-s';
 
 
   if (cs_link_smart in current_settings.globalswitches) and
   if (cs_link_smart in current_settings.globalswitches) and
      (tf_smartlink_sections in target_info.flags) then
      (tf_smartlink_sections in target_info.flags) then
-    if not(target_info.system in systems_darwin) then
-      GCSectionsStr:='--gc-sections'
-    else
-      GCSectionsStr:='-dead_strip -no_dead_strip_inits_and_terms';
+    GCSectionsStr:='--gc-sections';
 
 
-   if(not(target_info.system in systems_darwin) and
-      (cs_profile in current_settings.moduleswitches)) or
+   if(cs_profile in current_settings.moduleswitches) or
      ((Info.DynamicLinker<>'') and
      ((Info.DynamicLinker<>'') and
       ((not SharedLibFiles.Empty) or
       ((not SharedLibFiles.Empty) or
        (target_info.system in systems_openbsd))) then
        (target_info.system in systems_openbsd))) then
@@ -841,10 +489,7 @@ begin
 
 
   if CShared Then
   if CShared Then
    begin
    begin
-   if not(target_info.system in systems_darwin) then
-     DynLinKStr:=DynLinkStr+' --shared'
-    else
-     DynLinKStr:=DynLinkStr+' -dynamic'; // one dash!
+      DynLinKStr:=DynLinkStr+' --shared'
    end;
    end;
 
 
 { Use -nopie on OpenBSD if PIC support is turned off }
 { Use -nopie on OpenBSD if PIC support is turned off }
@@ -859,6 +504,9 @@ begin
 { Write used files and libraries }
 { Write used files and libraries }
   WriteResponseFile(false);
   WriteResponseFile(false);
 
 
+{ Write symbol order file }
+  ordersymfile:=WriteSymbolOrderFile;
+
 { Call linker }
 { Call linker }
   SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
   SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
   Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename));
   Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename));
@@ -868,37 +516,24 @@ begin
   Replace(cmdstr,'$MAP',mapstr);
   Replace(cmdstr,'$MAP',mapstr);
   Replace(cmdstr,'$CATRES',CatFileContent(outputexedir+Info.ResName));
   Replace(cmdstr,'$CATRES',CatFileContent(outputexedir+Info.ResName));
   Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
   Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
-  if (target_info.system in systems_darwin) then
-    Replace(cmdstr,'$FILELIST','-filelist '+maybequoted(outputexedir+'linkfiles.res'))
+  if ordersymfile<>'' then
+    Replace(cmdstr,'$ORDERSYMS','--symbol-ordering-file '+maybequoted(ordersymfile))
   else
   else
-    Replace(cmdstr,'$FILELIST','');
+    Replace(cmdstr,'$ORDERSYMS','');
+
+  Replace(cmdstr,'$FILELIST','');
   Replace(cmdstr,'$STATIC',StaticStr);
   Replace(cmdstr,'$STATIC',StaticStr);
   Replace(cmdstr,'$STRIP',StripStr);
   Replace(cmdstr,'$STRIP',StripStr);
   Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
   Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
   Replace(cmdstr,'$DYNLINK',DynLinkStr);
   Replace(cmdstr,'$DYNLINK',DynLinkStr);
-  if (target_info.system in systems_darwin) then
-    Replace(cmdstr,'$PRTOBJ',GetDarwinPrtobjName(false));
   BinStr:=FindUtil(utilsprefix+BinStr);
   BinStr:=FindUtil(utilsprefix+BinStr);
 
 
-  { create dsym file? }
-  extdbgbinstr:='';
-  extdbgcmdstr:='';
-  if (target_info.system in systems_darwin) and
-     (target_dbg.id in [dbg_dwarf2,dbg_dwarf3]) and
-     (cs_link_separate_dbg_file in current_settings.globalswitches) then
-    begin
-      extdbgbinstr:=FindUtil(utilsprefix+'dsymutil');
-      extdbgcmdstr:=maybequoted(current_module.exefilename);
-    end;
-
   if (LdSupportsNoResponseFile) and
   if (LdSupportsNoResponseFile) and
      not(cs_link_nolink in current_settings.globalswitches) then
      not(cs_link_nolink in current_settings.globalswitches) then
     begin
     begin
       { we have to use a script to use the IFS hack }
       { we have to use a script to use the IFS hack }
       linkscript:=GenerateScript(outputexedir+'ppaslink');
       linkscript:=GenerateScript(outputexedir+'ppaslink');
       linkscript.AddLinkCommand(BinStr,CmdStr,'');
       linkscript.AddLinkCommand(BinStr,CmdStr,'');
-      if (extdbgcmdstr<>'') then
-        linkscript.AddLinkCommand(extdbgbinstr,extdbgcmdstr,'');
       linkscript.WriteToDisk;
       linkscript.WriteToDisk;
       BinStr:=linkscript.fn;
       BinStr:=linkscript.fn;
       if not path_absolute(BinStr) then
       if not path_absolute(BinStr) then
@@ -911,22 +546,18 @@ begin
 
 
   useshell:=not (tf_no_backquote_support in source_info.flags);
   useshell:=not (tf_no_backquote_support in source_info.flags);
   success:=DoExec(BinStr,CmdStr,true,LdSupportsNoResponseFile or useshell);
   success:=DoExec(BinStr,CmdStr,true,LdSupportsNoResponseFile or useshell);
-  if (success and
-      (extdbgbinstr<>'') and
-      (cs_link_nolink in current_settings.globalswitches)) then
-    success:=DoExec(extdbgbinstr,extdbgcmdstr,false,LdSupportsNoResponseFile);
 
 
 { Remove ReponseFile }
 { Remove ReponseFile }
   if (success) and not(cs_link_nolink in current_settings.globalswitches) then
   if (success) and not(cs_link_nolink in current_settings.globalswitches) then
    begin
    begin
      DeleteFile(outputexedir+Info.ResName);
      DeleteFile(outputexedir+Info.ResName);
+     if ordersymfile<>'' then
+       DeleteFile(ordersymfile);
      if LdSupportsNoResponseFile Then
      if LdSupportsNoResponseFile Then
        begin
        begin
          DeleteFile(linkscript.fn);
          DeleteFile(linkscript.fn);
          linkscript.free
          linkscript.free
        end;
        end;
-     if target_info.system in systems_darwin then
-       DeleteFile(outputexedir+'linkfiles.res');
    end;
    end;
 
 
   MakeExecutable:=success;   { otherwise a recursive call to link method }
   MakeExecutable:=success;   { otherwise a recursive call to link method }
@@ -942,10 +573,9 @@ var
   binstr,
   binstr,
   cmdstr,
   cmdstr,
   mapstr,
   mapstr,
+  ordersymfile,
   targetstr,
   targetstr,
-  emulstr,
-  extdbgbinstr,
-  extdbgcmdstr  : TCmdStr;
+  emulstr       : TCmdStr;
   GCSectionsStr : string[63];
   GCSectionsStr : string[63];
   exportedsyms: text;
   exportedsyms: text;
   success : boolean;
   success : boolean;
@@ -960,13 +590,14 @@ begin
 { Write used files and libraries }
 { Write used files and libraries }
   WriteResponseFile(true);
   WriteResponseFile(true);
 
 
+{ Write symbol order file }
+  ordersymfile:=WriteSymbolOrderFile;
+
   if (cs_link_smart in current_settings.globalswitches) and
   if (cs_link_smart in current_settings.globalswitches) and
      (tf_smartlink_sections in target_info.flags) then
      (tf_smartlink_sections in target_info.flags) then
-    if not(target_info.system in systems_darwin) then
      { disabled because not tested
      { disabled because not tested
       GCSectionsStr:='--gc-sections' }
       GCSectionsStr:='--gc-sections' }
-    else
-      GCSectionsStr:='-dead_strip -no_dead_strip_inits_and_terms';
+    ;
 
 
   if (cs_link_map in current_settings.globalswitches) then
   if (cs_link_map in current_settings.globalswitches) then
     mapstr:='-Map '+maybequoted(ChangeFileExt(current_module.sharedlibfilename,'.map'));
     mapstr:='-Map '+maybequoted(ChangeFileExt(current_module.sharedlibfilename,'.map'));
@@ -991,63 +622,30 @@ begin
 
 
 { Call linker }
 { Call linker }
   SplitBinCmd(Info.DllCmd[1],binstr,cmdstr);
   SplitBinCmd(Info.DllCmd[1],binstr,cmdstr);
-{$ifndef darwin}
   Replace(cmdstr,'$EXE',maybequoted(current_module.sharedlibfilename));
   Replace(cmdstr,'$EXE',maybequoted(current_module.sharedlibfilename));
-{$else darwin}
-  Replace(cmdstr,'$EXE',maybequoted(ExpandFileName(current_module.sharedlibfilename)));
-{$endif darwin}
   Replace(cmdstr,'$OPT',Info.ExtraOptions);
   Replace(cmdstr,'$OPT',Info.ExtraOptions);
   Replace(cmdstr,'$TARGET',targetstr);
   Replace(cmdstr,'$TARGET',targetstr);
   Replace(cmdstr,'$EMUL',EmulStr);
   Replace(cmdstr,'$EMUL',EmulStr);
   Replace(cmdstr,'$CATRES',CatFileContent(outputexedir+Info.ResName));
   Replace(cmdstr,'$CATRES',CatFileContent(outputexedir+Info.ResName));
-  if (target_info.system in systems_darwin) then
-    Replace(cmdstr,'$FILELIST','-filelist '+maybequoted(outputexedir+'linkfiles.res'))
-  else
-    Replace(cmdstr,'$FILELIST','');
+  Replace(cmdstr,'$FILELIST','');
   Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
   Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
   Replace(cmdstr,'$INIT',InitStr);
   Replace(cmdstr,'$INIT',InitStr);
   Replace(cmdstr,'$FINI',FiniStr);
   Replace(cmdstr,'$FINI',FiniStr);
   Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
   Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
   Replace(cmdstr,'$SONAME',SoNameStr);
   Replace(cmdstr,'$SONAME',SoNameStr);
   Replace(cmdstr,'$MAP',mapstr);
   Replace(cmdstr,'$MAP',mapstr);
-  if (target_info.system in systems_darwin) then
-    Replace(cmdstr,'$PRTOBJ',GetDarwinPrtobjName(true));
+  if ordersymfile<>'' then
+    Replace(cmdstr,'$ORDERSYMS','--symbol-ordering-file '+maybequoted(ordersymfile))
+  else
+    Replace(cmdstr,'$ORDERSYMS','');
   BinStr:=FindUtil(utilsprefix+BinStr);
   BinStr:=FindUtil(utilsprefix+BinStr);
 
 
-  { create dsym file? }
-  extdbgbinstr:='';
-  extdbgcmdstr:='';
-  if (target_info.system in systems_darwin) and
-     (target_dbg.id in [dbg_dwarf2,dbg_dwarf3]) and
-     (cs_link_separate_dbg_file in current_settings.globalswitches) then
-    begin
-      extdbgbinstr:=FindUtil(utilsprefix+'dsymutil');
-      extdbgcmdstr:=maybequoted(current_module.sharedlibfilename);
-    end;
-
-  if (target_info.system in systems_darwin) then
-    begin
-      { exported symbols for darwin }
-      if not texportlibunix(exportlib).exportedsymnames.empty then
-        begin
-          assign(exportedsyms,outputexedir+'linksyms.fpc');
-          rewrite(exportedsyms);
-          repeat
-            writeln(exportedsyms,texportlibunix(exportlib).exportedsymnames.getfirst);
-          until texportlibunix(exportlib).exportedsymnames.empty;
-          close(exportedsyms);
-          cmdstr:=cmdstr+' -exported_symbols_list '+maybequoted(outputexedir)+'linksyms.fpc';
-        end;
-    end;
-
   if (LdSupportsNoResponseFile) and
   if (LdSupportsNoResponseFile) and
      not(cs_link_nolink in current_settings.globalswitches) then
      not(cs_link_nolink in current_settings.globalswitches) then
     begin
     begin
       { we have to use a script to use the IFS hack }
       { we have to use a script to use the IFS hack }
       linkscript:=GenerateScript(outputexedir+'ppaslink');
       linkscript:=GenerateScript(outputexedir+'ppaslink');
       linkscript.AddLinkCommand(BinStr,CmdStr,'');
       linkscript.AddLinkCommand(BinStr,CmdStr,'');
-      if (extdbgbinstr<>'') then
-        linkscript.AddLinkCommand(extdbgbinstr,extdbgcmdstr,'');
       linkscript.WriteToDisk;
       linkscript.WriteToDisk;
       BinStr:=linkscript.fn;
       BinStr:=linkscript.fn;
       if not path_absolute(BinStr) then
       if not path_absolute(BinStr) then
@@ -1059,10 +657,6 @@ begin
     end;
     end;
 
 
   success:=DoExec(BinStr,cmdstr,true,LdSupportsNoResponseFile);
   success:=DoExec(BinStr,cmdstr,true,LdSupportsNoResponseFile);
-  if (success and
-      (extdbgbinstr<>'') and
-      (cs_link_nolink in current_settings.globalswitches)) then
-    success:=DoExec(extdbgbinstr,extdbgcmdstr,false,LdSupportsNoResponseFile);
 
 
 { Strip the library ? }
 { Strip the library ? }
   if success and (cs_link_strip in current_settings.globalswitches) then
   if success and (cs_link_strip in current_settings.globalswitches) then
@@ -1076,16 +670,13 @@ begin
   if (success) and not(cs_link_nolink in current_settings.globalswitches) then
   if (success) and not(cs_link_nolink in current_settings.globalswitches) then
     begin
     begin
       DeleteFile(outputexedir+Info.ResName);
       DeleteFile(outputexedir+Info.ResName);
+      if ordersymfile<>'' then
+        DeleteFile(ordersymfile);
       if LdSupportsNoResponseFile Then
       if LdSupportsNoResponseFile Then
         begin
         begin
           DeleteFile(linkscript.fn);
           DeleteFile(linkscript.fn);
           linkscript.free
           linkscript.free
         end;
         end;
-      if (target_info.system in systems_darwin) then
-        begin
-          DeleteFile(outputexedir+'linksyms.fpc');
-          DeleteFile(outputexedir+'linkfiles.res');
-        end;
     end;
     end;
 
 
   MakeSharedLibrary:=success;   { otherwise a recursive call to link method }
   MakeSharedLibrary:=success;   { otherwise a recursive call to link method }
@@ -1111,13 +702,6 @@ initialization
   RegisterImport(system_x86_64_netbsd,timportlibbsd);
   RegisterImport(system_x86_64_netbsd,timportlibbsd);
   RegisterExport(system_x86_64_netbsd,texportlibbsd);
   RegisterExport(system_x86_64_netbsd,texportlibbsd);
   RegisterTarget(system_x86_64_netbsd_info);
   RegisterTarget(system_x86_64_netbsd_info);
-
-  RegisterImport(system_x86_64_darwin,timportlibdarwin);
-  RegisterExport(system_x86_64_darwin,texportlibdarwin);
-  RegisterTarget(system_x86_64_darwin_info);
-  RegisterImport(system_x86_64_iphonesim,timportlibdarwin);
-  RegisterExport(system_x86_64_iphonesim,texportlibdarwin);
-  RegisterTarget(system_x86_64_iphonesim_info);
 {$endif}
 {$endif}
 {$ifdef i386}
 {$ifdef i386}
   RegisterImport(system_i386_freebsd,timportlibbsd);
   RegisterImport(system_i386_freebsd,timportlibbsd);
@@ -1129,12 +713,6 @@ initialization
   RegisterImport(system_i386_openbsd,timportlibbsd);
   RegisterImport(system_i386_openbsd,timportlibbsd);
   RegisterExport(system_i386_openbsd,texportlibbsd);
   RegisterExport(system_i386_openbsd,texportlibbsd);
   RegisterTarget(system_i386_openbsd_info);
   RegisterTarget(system_i386_openbsd_info);
-  RegisterImport(system_i386_darwin,timportlibdarwin);
-  RegisterExport(system_i386_darwin,texportlibdarwin);
-  RegisterTarget(system_i386_darwin_info);
-  RegisterImport(system_i386_iphonesim,timportlibdarwin);
-  RegisterExport(system_i386_iphonesim,texportlibdarwin);
-  RegisterTarget(system_i386_iphonesim_info);
 {$endif i386}
 {$endif i386}
 {$ifdef m68k}
 {$ifdef m68k}
   RegisterImport(system_m68k_netbsd,timportlibbsd);
   RegisterImport(system_m68k_netbsd,timportlibbsd);
@@ -1142,34 +720,15 @@ initialization
   RegisterTarget(system_m68k_netbsd_info);
   RegisterTarget(system_m68k_netbsd_info);
 {$endif m68k}
 {$endif m68k}
 {$ifdef powerpc}
 {$ifdef powerpc}
-  RegisterImport(system_powerpc_darwin,timportlibdarwin);
-  RegisterExport(system_powerpc_darwin,texportlibdarwin);
-  RegisterTarget(system_powerpc_darwin_info);
-
   RegisterImport(system_powerpc_netbsd,timportlibbsd);
   RegisterImport(system_powerpc_netbsd,timportlibbsd);
   RegisterExport(system_powerpc_netbsd,texportlibbsd);
   RegisterExport(system_powerpc_netbsd,texportlibbsd);
   RegisterTarget(system_powerpc_netbsd_info);
   RegisterTarget(system_powerpc_netbsd_info);
 {$endif powerpc}
 {$endif powerpc}
-{$ifdef powerpc64}
-  RegisterImport(system_powerpc64_darwin,timportlibdarwin);
-  RegisterExport(system_powerpc64_darwin,texportlibdarwin);
-  RegisterTarget(system_powerpc64_darwin_info);
-{$endif powerpc64}
 {$ifdef arm}
 {$ifdef arm}
-  RegisterImport(system_arm_darwin,timportlibdarwin);
-  RegisterExport(system_arm_darwin,texportlibdarwin);
-  RegisterTarget(system_arm_darwin_info);
-
   RegisterImport(system_arm_netbsd,timportlibbsd);
   RegisterImport(system_arm_netbsd,timportlibbsd);
   RegisterExport(system_arm_netbsd,texportlibbsd);
   RegisterExport(system_arm_netbsd,texportlibbsd);
   RegisterTarget(system_arm_netbsd_info);
   RegisterTarget(system_arm_netbsd_info);
 {$endif arm}
 {$endif arm}
-{$ifdef aarch64}
-  RegisterImport(system_aarch64_darwin,timportlibdarwin);
-  RegisterExport(system_aarch64_darwin,texportlibdarwin);
-  RegisterTarget(system_aarch64_darwin_info);
-{$endif aarch64}
 
 
   RegisterRes(res_elf_info,TWinLikeResourceFile);
   RegisterRes(res_elf_info,TWinLikeResourceFile);
-  RegisterRes(res_macho_info,TWinLikeResourceFile);
 end.
 end.

+ 764 - 0
compiler/systems/t_darwin.pas

@@ -0,0 +1,764 @@
+{
+    Copyright (c) 1998-2002 by Peter Vreman (original Linux)
+              (c) 2000      by Marco van de Voort (FreeBSD mods)
+
+    This unit implements support import,export,link routines
+    for the (i386)FreeBSD target
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+
+unit t_darwin;
+
+{$i fpcdefs.inc}
+
+interface
+
+implementation
+
+  uses
+    sysutils,
+    cutils,cfileutl,cclasses,
+    verbose,systems,globtype,globals,
+    symconst,cscript,
+    fmodule,aasmbase,aasmtai,aasmdata,aasmcpu,cpubase,symsym,symdef,
+    import,export,link,comprsrc,rescmn,i_darwin,expunix,
+    cgutils,cgbase,cgobj,cpuinfo,ogbase;
+
+  type
+    timportlibdarwin=class(timportlib)
+      procedure generatelib;override;
+    end;
+
+    texportlibdarwin=class(texportlibunix)
+      procedure setinitname(list: TAsmList; const s: string); override;
+      procedure setfininame(list: TAsmList; const s: string); override;
+    end;
+
+    tlinkerdarwin=class(texternallinker)
+    private
+      LinkFilesFileName,
+      LinkSymsFileName   : TCmdStr;
+      Function  WriteResponseFile(isdll:boolean) : Boolean;
+      function GetDarwinCrt1ObjName(isdll: boolean): TCmdStr;
+      Function GetDarwinPrtobjName(isdll: boolean): TCmdStr;
+    public
+      constructor Create;override;
+      procedure SetDefaultInfo;override;
+      function  MakeExecutable:boolean;override;
+      function  MakeSharedLibrary:boolean;override;
+      procedure LoadPredefinedLibraryOrder; override;
+      procedure InitSysInitUnitName; override;
+    end;
+
+{*****************************************************************************
+                             TIMPORTLIBDARWIN
+*****************************************************************************}
+
+    procedure timportlibdarwin.generatelib;
+      begin
+      end;
+
+
+{*****************************************************************************
+                             TEXPORTLIBDARWIN
+*****************************************************************************}
+
+    procedure texportlibdarwin.setinitname(list: TAsmList; const s: string);
+      begin
+        new_section(list,sec_init_func,'',sizeof(pint));
+        list.concat(Tai_const.Createname(s,0));
+      end;
+
+
+    procedure texportlibdarwin.setfininame(list: TAsmList; const s: string);
+      begin
+        new_section(list,sec_term_func,'',sizeof(pint));
+        list.concat(Tai_const.Createname(s,0));
+      end;
+
+
+{*****************************************************************************
+                                  TLINKERBSD
+*****************************************************************************}
+
+    constructor tlinkerdarwin.Create;
+      begin
+        inherited;
+        if not Dontlinkstdlibpath Then
+          LibrarySearchPath.AddLibraryPath(sysrootpath,'=/usr/lib',true)
+      end;
+
+
+    procedure tlinkerdarwin.SetDefaultInfo;
+      begin
+        with Info do
+         begin
+  {$ifndef cpu64bitaddr}
+           { Set the size of the page at address zero to 64kb, so nothing
+             is loaded below that address. This avoids problems with the
+             strange Windows-compatible resource handling that assumes
+             that addresses below 64kb do not exist.
+
+             On 64bit systems, page zero is 4GB by default, so no problems
+             there.
+           }
+           { In case of valgrind, don't do that, because it cannot deal with
+             a custom pagezero size -- in general, this should not cause any
+             problems because the resources are added at the end and most
+             programs with problems that require Valgrind will have more
+             than 60KB of data (first 4KB of address space is always invalid)
+           }
+           ExeCmd[1]:='ld $PRTOBJ $TARGET $EMUL $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP $MAP $ORDERSYMS -multiply_defined suppress -L. -o $EXE $CATRES $FILELIST';
+           if not(cs_gdb_valgrind in current_settings.globalswitches) then
+             ExeCmd[1]:=ExeCmd[1]+' -pagezero_size 0x10000';
+  {$else ndef cpu64bitaddr}
+           ExeCmd[1]:='ld $PRTOBJ $TARGET $EMUL $OPT $DYNLINK $STATIC $GCSECTIONS $STRIP $MAP $ORDERSYMS -multiply_defined suppress -L. -o $EXE $CATRES $FILELIST';
+  {$endif ndef cpu64bitaddr}
+           if (apptype<>app_bundle) then
+             DllCmd[1]:='ld $PRTOBJ $TARGET $EMUL $OPT $GCSECTIONS $MAP $ORDERSYMS -dynamic -dylib -multiply_defined suppress -L. -o $EXE $CATRES $FILELIST'
+           else
+             DllCmd[1]:='ld $PRTOBJ $TARGET $EMUL $OPT $GCSECTIONS $MAP $ORDERSYMS -dynamic -bundle -multiply_defined suppress -L. -o $EXE $CATRES $FILELIST';
+           DllCmd[2]:='strip -x $EXE';
+           DynamicLinker:='';
+         end;
+      end;
+
+
+    procedure tlinkerdarwin.LoadPredefinedLibraryOrder;
+      begin
+        // put your linkorder/linkalias overrides here.
+        // Note: assumes only called when reordering/aliasing is used.
+        LinkLibraryOrder.add('gcc','',15);
+        LinkLibraryOrder.add('c','',50);
+      end;
+
+
+    procedure tlinkerdarwin.InitSysInitUnitName;
+      begin
+        SysInitUnit:='sysinit';
+      end;
+
+
+    function tlinkerdarwin.GetDarwinCrt1ObjName(isdll: boolean): TCmdStr;
+      begin
+        if not isdll then
+          begin
+            if not(cs_profile in current_settings.moduleswitches) then
+              begin
+                case target_info.system of
+                  system_powerpc_darwin,
+                  system_powerpc64_darwin,
+                  system_i386_darwin,
+                  system_x86_64_darwin:
+                    begin
+                      { 10.8 and later: no crt1.* }
+                      if CompareVersionStrings(MacOSXVersionMin,'10.8')>=0 then
+                        exit('');
+                      { x86: crt1.10.6.o -> crt1.10.5.o -> crt1.o }
+                      { others: crt1.10.5 -> crt1.o }
+                      if (target_info.system in [system_i386_darwin,system_x86_64_darwin]) and
+                         (CompareVersionStrings(MacOSXVersionMin,'10.6')>=0) then
+                        exit('crt1.10.6.o');
+                      if CompareVersionStrings(MacOSXVersionMin,'10.5')>=0 then
+                        exit('crt1.10.5.o');
+                    end;
+                  system_arm_ios:
+                    begin
+                      { iOS:
+                          iOS 6 and later: nothing
+                          iOS 3.1 - 5.x: crt1.3.1.o
+                          pre-iOS 3.1: crt1.o
+                      }
+                      if (CompareVersionStrings(iPhoneOSVersionMin,'6.0')>=0) then
+                        exit('');
+                      if (CompareVersionStrings(iPhoneOSVersionMin,'3.1')>=0) then
+                        exit('crt1.3.1.o');
+                    end;
+                  system_i386_iphonesim,
+                  system_x86_64_iphonesim:
+                    begin
+                      { "recent versions" must not use anything (https://github.com/llvm-mirror/clang/commit/e6d04f3d152a22077022cf9287d4c538a0918ab0 )
+                        What those recent versions could be, is anyone's guess. It
+                        still seems to work with 8.1 and no longer with 8.3, so use
+                        8.1 as a cut-off point }
+                      if (CompareVersionStrings(iPhoneOSVersionMin,'8.1')>0) then
+                        exit('');
+                    end;
+                  system_aarch64_ios,
+                  system_aarch64_darwin:
+                    { never anything }
+                    exit('');
+                  else
+                    Internalerror(2019050709);
+                end;
+                { nothing special -> default }
+                result:='crt1.o';
+              end
+            else
+              begin
+                result:='gcrt1.o';
+                { 10.8 and later: tell the linker to use 'start' instead of "_main"
+                  as entry point }
+                if CompareVersionStrings(MacOSXVersionMin,'10.8')>=0 then
+                  Info.ExeCmd[1]:=Info.ExeCmd[1]+' -no_new_main';
+              end;
+          end
+        else
+          begin
+            if (apptype=app_bundle) then
+              begin
+                case target_info.system of
+                  system_powerpc_darwin,
+                  system_powerpc64_darwin,
+                  system_i386_darwin,
+                  system_x86_64_darwin:
+                    begin
+                      { < 10.6: bundle1.o
+                        >= 10.6: nothing }
+                      if CompareVersionStrings(MacOSXVersionMin,'10.6')>=0 then
+                        exit('');
+                    end;
+                  system_arm_ios,
+                  system_aarch64_ios:
+                    begin
+                      { iOS: < 3.1: bundle1.o
+                             >= 3.1: nothing }
+                      if (CompareVersionStrings(iPhoneOSVersionMin,'3.1')>=0) then
+                        exit('');
+                    end;
+                  system_i386_iphonesim,
+                  system_x86_64_iphonesim:
+                    begin
+                      { see rule for crt1.o }
+                      if (CompareVersionStrings(iPhoneOSVersionMin,'8.1')>0) then
+                        exit('');
+                    end;
+                  system_aarch64_darwin:
+                    exit('');
+                  else
+                    Internalerror(2019050710);
+                end;
+                result:='bundle1.o';
+              end
+            else
+              begin
+                case target_info.system of
+                  system_powerpc_darwin,
+                  system_powerpc64_darwin,
+                  system_i386_darwin,
+                  system_x86_64_darwin:
+                    begin
+                      { >= 10.6: nothing
+                        = 10.5: dylib1.10.5.o
+                        < 10.5: dylib1.o
+                      }
+                      if CompareVersionStrings(MacOSXVersionMin,'10.6')>=0 then
+                        exit('');
+                      if CompareVersionStrings(MacOSXVersionMin,'10.5')>=0 then
+                        exit('dylib1.10.5.o');
+                    end;
+                  system_arm_ios,
+                  system_aarch64_ios:
+                    begin
+                      { iOS: < 3.1: dylib1.o
+                             >= 3.1: nothing }
+                      if (CompareVersionStrings(iPhoneOSVersionMin,'3.1')>=0) then
+                        exit('');
+                    end;
+                  system_i386_iphonesim,
+                  system_x86_64_iphonesim:
+                    begin
+                      { see rule for crt1.o }
+                      if (CompareVersionStrings(iPhoneOSVersionMin,'8.1')>0) then
+                        exit('');
+                    end;
+                  system_aarch64_darwin:
+                    exit('');
+                  else
+                    Internalerror(2019050711);
+                end;
+                result:='dylib1.o';
+              end;
+          end;
+      end;
+
+
+    Function tlinkerdarwin.GetDarwinPrtobjName(isdll: boolean): TCmdStr;
+    var
+      startupfile: TCmdStr;
+    begin
+      result:='';
+
+      startupfile:=GetDarwinCrt1ObjName(isdll);
+      if startupfile<>'' then
+        begin
+         if not librarysearchpath.FindFile(startupfile,false,result) then
+           result:='/usr/lib/'+startupfile;
+        end;
+      result:=maybequoted(result);
+    end;
+
+
+    Function tlinkerdarwin.WriteResponseFile(isdll:boolean) : Boolean;
+    Var
+      linkres      : TLinkRes;
+      FilesList    : TLinkRes;
+      i            : longint;
+      HPath        : TCmdStrListItem;
+      s,s1,s2      : TCmdStr;
+      Fl1,Fl2      : Boolean;
+    begin
+      WriteResponseFile:=False;
+      if ReOrderEntries Then
+         ExpandAndApplyOrder(SharedLibFiles);
+
+      { Open link.res file }
+      LinkRes:=TLinkRes.Create(outputexedir+Info.ResName,false);
+
+      if sysrootpath<>'' then
+        begin
+          LinkRes.Add('-syslibroot');
+          LinkRes.Add(sysrootpath);
+        end;
+
+      LinkRes.Add('-arch');
+      case target_info.system of
+        system_powerpc_darwin:
+          LinkRes.Add('ppc');
+        system_i386_darwin,
+        system_i386_iphonesim:
+          LinkRes.Add('i386');
+        system_powerpc64_darwin:
+          LinkRes.Add('ppc64');
+        system_x86_64_darwin,
+        system_x86_64_iphonesim:
+          LinkRes.Add('x86_64');
+        system_arm_ios:
+          { current versions of the linker require the sub-architecture type
+            to be specified }
+          LinkRes.Add(lower(cputypestr[current_settings.cputype]));
+        system_aarch64_ios,
+        system_aarch64_darwin:
+          LinkRes.Add('arm64');
+        else
+          internalerror(2014121801);
+      end;
+      if MacOSXVersionMin<>'' then
+        begin
+          LinkRes.Add('-macosx_version_min');
+          LinkRes.Add(MacOSXVersionMin);
+        end
+      else if iPhoneOSVersionMin<>'' then
+        begin
+          LinkRes.Add('-iphoneos_version_min');
+          LinkRes.Add(iPhoneOSVersionMin);
+        end;
+
+      { Write path to search libraries }
+      HPath:=TCmdStrListItem(current_module.locallibrarysearchpath.First);
+      while assigned(HPath) do
+       begin
+         LinkRes.Add('-L'+HPath.Str);
+         HPath:=TCmdStrListItem(HPath.Next);
+       end;
+      HPath:=TCmdStrListItem(LibrarySearchPath.First);
+      while assigned(HPath) do
+       begin
+         LinkRes.Add('-L'+HPath.Str);
+         HPath:=TCmdStrListItem(HPath.Next);
+       end;
+
+      HPath:=TCmdStrListItem(current_module.localframeworksearchpath.First);
+      while assigned(HPath) do
+       begin
+         LinkRes.Add('-F'+HPath.Str);
+         HPath:=TCmdStrListItem(HPath.Next);
+       end;
+      HPath:=TCmdStrListItem(FrameworkSearchPath.First);
+      while assigned(HPath) do
+       begin
+         LinkRes.Add('-F'+HPath.Str);
+         HPath:=TCmdStrListItem(HPath.Next);
+       end;
+
+      { main objectfiles }
+      LinkFilesFileName:=UniqueName('linkfiles')+'.res';
+      FilesList:=TLinkRes.Create(outputexedir+LinkFilesFileName,false);
+      while not ObjectFiles.Empty do
+        begin
+          s:=ObjectFiles.GetFirst;
+          if s<>'' then
+            begin
+              s:=TargetFixFileName(s);
+              FilesList.Add(s);
+            end;
+        end;
+      FilesList.writetodisk;
+      FilesList.Free;
+
+      { Write staticlibraries }
+      while not StaticLibFiles.Empty do
+        begin
+          S:=StaticLibFiles.GetFirst;
+          LinkRes.AddFileName(s)
+        end;
+
+      { Write sharedlibraries like -l<lib> }
+      while not SharedLibFiles.Empty do
+        begin
+          S:=SharedLibFiles.GetFirst;
+          if (s<>'c') or ReOrderEntries then
+            begin
+              i:=Pos(target_info.sharedlibext,S);
+              if i>0 then
+                Delete(S,i,255);
+              LinkRes.Add('-l'+s);
+            end;
+         { be sure that libc is the last lib }
+         if not ReOrderEntries then
+           begin
+             LinkRes.Add('-lc')
+           end;
+       end;
+
+      while not FrameworkFiles.empty do
+        begin
+          LinkRes.Add('-framework');
+          LinkRes.Add(FrameworkFiles.GetFirst);
+        end;
+
+    { Write and Close response }
+      linkres.writetodisk;
+      linkres.Free;
+
+      WriteResponseFile:=True;
+    end;
+
+
+    function tlinkerdarwin.MakeExecutable:boolean;
+    var
+      binstr,
+      cmdstr,
+      mapstr,
+      targetstr,
+      emulstr,
+      extdbgbinstr,
+      extdbgcmdstr,
+      ltostr,
+      ordersymfile: TCmdStr;
+      linkscript: TAsmScript;
+      DynLinkStr : string[60];
+      GCSectionsStr,
+      StaticStr,
+      StripStr   : string[63];
+      success : boolean;
+    begin
+      if not(cs_link_nolink in current_settings.globalswitches) then
+       Message1(exec_i_linking,current_module.exefilename);
+
+    { Create some replacements }
+      StaticStr:='';
+      StripStr:='';
+      DynLinkStr:='';
+      GCSectionsStr:='';
+      linkscript:=nil;
+      mapstr:='';
+      targetstr:='';
+      emulstr:='';
+      ltostr:='';
+      if (cs_link_map in current_settings.globalswitches) then
+        mapstr:='-Map '+maybequoted(ChangeFileExt(current_module.exefilename,'.map'));
+
+      if (cs_link_staticflag in current_settings.globalswitches) then
+        StaticStr:='-static';
+      if (cs_link_strip in current_settings.globalswitches) then
+        StripStr:='-x';
+
+      if (cs_link_smart in current_settings.globalswitches) then
+        GCSectionsStr:='-dead_strip -no_dead_strip_inits_and_terms';
+
+      if CShared Then
+       begin
+         DynLinKStr:=DynLinkStr+' -dynamic'; // one dash!
+       end;
+
+    { Write used files and libraries }
+      WriteResponseFile(false);
+
+    { Write symbol order file }
+      ordersymfile:=WriteSymbolOrderFile;
+
+    { Call linker }
+      SplitBinCmd(Info.ExeCmd[1],binstr,cmdstr);
+      Replace(cmdstr,'$EXE',maybequoted(current_module.exefilename));
+      Replace(cmdstr,'$OPT',Info.ExtraOptions);
+      Replace(cmdstr,'$TARGET',targetstr);
+      Replace(cmdstr,'$EMUL',EmulStr);
+      Replace(cmdstr,'$MAP',mapstr);
+      Replace(cmdstr,'$CATRES',CatFileContent(outputexedir+Info.ResName));
+      Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
+      if ordersymfile<>'' then
+        Replace(cmdstr,'$ORDERSYMS','-order_file '+maybequoted(ordersymfile))
+      else
+        Replace(cmdstr,'$ORDERSYMS','');
+
+      Replace(cmdstr,'$FILELIST','-filelist '+maybequoted(outputexedir+LinkFilesFileName));
+      Replace(cmdstr,'$STATIC',StaticStr);
+      Replace(cmdstr,'$STRIP',StripStr);
+      Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
+      Replace(cmdstr,'$DYNLINK',DynLinkStr);
+      Replace(cmdstr,'$PRTOBJ',GetDarwinPrtobjName(false));
+      BinStr:=FindUtil(utilsprefix+BinStr);
+
+      { create dsym file? }
+      extdbgbinstr:='';
+      extdbgcmdstr:='';
+      if (target_dbg.id in [dbg_dwarf2,dbg_dwarf3]) and
+         (cs_link_separate_dbg_file in current_settings.globalswitches) then
+        begin
+          extdbgbinstr:=FindUtil(utilsprefix+'dsymutil');
+          extdbgcmdstr:=maybequoted(current_module.exefilename);
+        end;
+
+      if not(cs_link_nolink in current_settings.globalswitches) then
+        begin
+          { we have to use a script to use the IFS hack }
+          linkscript:=GenerateScript(outputexedir+'ppaslink');
+          linkscript.AddLinkCommand(BinStr,CmdStr,'');
+          if (extdbgcmdstr<>'') then
+            linkscript.AddLinkCommand(extdbgbinstr,extdbgcmdstr,'');
+          linkscript.WriteToDisk;
+          BinStr:=linkscript.fn;
+          if not path_absolute(BinStr) then
+            if cs_link_on_target in current_settings.globalswitches then
+              BinStr:='.'+target_info.dirsep+BinStr
+            else
+              BinStr:='.'+source_info.dirsep+BinStr;
+          CmdStr:='';
+        end;
+
+      success:=DoExec(BinStr,CmdStr,true,true);
+      if (success and
+          (extdbgbinstr<>'') and
+          (cs_link_nolink in current_settings.globalswitches)) then
+        success:=DoExec(extdbgbinstr,extdbgcmdstr,false,true);
+
+    { Remove ReponseFile }
+      if (success) and not(cs_link_nolink in current_settings.globalswitches) then
+       begin
+         DeleteFile(outputexedir+Info.ResName);
+         if ordersymfile<>'' then
+           DeleteFile(ordersymfile);
+         DeleteFile(linkscript.fn);
+         linkscript.free;
+         DeleteFile(outputexedir+LinkFilesFileName);
+       end;
+
+      MakeExecutable:=success;   { otherwise a recursive call to link method }
+    end;
+
+
+    Function tlinkerdarwin.MakeSharedLibrary:boolean;
+    var
+      InitStr,
+      FiniStr,
+      SoNameStr : string[80];
+      linkscript: TAsmScript;
+      binstr,
+      cmdstr,
+      mapstr,
+      ltostr,
+      ordersymfile,
+      targetstr,
+      emulstr,
+      extdbgbinstr,
+      extdbgcmdstr  : TCmdStr;
+      GCSectionsStr : string[63];
+      exportedsyms: text;
+      success : boolean;
+    begin
+      MakeSharedLibrary:=false;
+      GCSectionsStr:='';
+      mapstr:='';
+      ltostr:='';
+      linkscript:=nil;
+      if not(cs_link_nolink in current_settings.globalswitches) then
+       Message1(exec_i_linking,current_module.sharedlibfilename);
+
+    { Write used files and libraries }
+      WriteResponseFile(true);
+
+    { Write symbol order file }
+      ordersymfile:=WriteSymbolOrderFile;
+
+      if (cs_link_smart in current_settings.globalswitches) then
+        GCSectionsStr:='-dead_strip -no_dead_strip_inits_and_terms';
+
+      if (cs_link_map in current_settings.globalswitches) then
+        mapstr:='-Map '+maybequoted(ChangeFileExt(current_module.sharedlibfilename,'.map'));
+
+      targetstr:='';
+      emulstr:='';
+
+      InitStr:='-init FPC_LIB_START';
+      FiniStr:='-fini FPC_LIB_EXIT';
+      SoNameStr:='-soname '+ExtractFileName(current_module.sharedlibfilename);
+
+      { Call linker }
+      SplitBinCmd(Info.DllCmd[1],binstr,cmdstr);
+      Replace(cmdstr,'$EXE',maybequoted(ExpandFileName(current_module.sharedlibfilename)));
+      Replace(cmdstr,'$OPT',Info.ExtraOptions);
+      Replace(cmdstr,'$TARGET',targetstr);
+      Replace(cmdstr,'$EMUL',EmulStr);
+      Replace(cmdstr,'$CATRES',CatFileContent(outputexedir+Info.ResName));
+      Replace(cmdstr,'$FILELIST','-filelist '+maybequoted(outputexedir+LinkFilesFileName));
+      Replace(cmdstr,'$RES',maybequoted(outputexedir+Info.ResName));
+      Replace(cmdstr,'$INIT',InitStr);
+      Replace(cmdstr,'$FINI',FiniStr);
+      Replace(cmdstr,'$GCSECTIONS',GCSectionsStr);
+      Replace(cmdstr,'$SONAME',SoNameStr);
+      Replace(cmdstr,'$MAP',mapstr);
+      if ordersymfile<>'' then
+        Replace(cmdstr,'$ORDERSYMS','-order_file '+maybequoted(ordersymfile))
+      else
+        Replace(cmdstr,'$ORDERSYMS','');
+      Replace(cmdstr,'$PRTOBJ',GetDarwinPrtobjName(true));
+      BinStr:=FindUtil(utilsprefix+BinStr);
+
+      { create dsym file? }
+      extdbgbinstr:='';
+      extdbgcmdstr:='';
+      if (target_dbg.id in [dbg_dwarf2,dbg_dwarf3]) and
+         (cs_link_separate_dbg_file in current_settings.globalswitches) then
+        begin
+          extdbgbinstr:=FindUtil(utilsprefix+'dsymutil');
+          extdbgcmdstr:=maybequoted(current_module.sharedlibfilename);
+        end;
+
+      LinkSymsFileName:='';
+      if not texportlibunix(exportlib).exportedsymnames.empty then
+        begin
+          LinkSymsFileName:=UniqueName('linksyms')+'.fpc';
+          assign(exportedsyms,outputexedir+LinkSymsFileName);
+          rewrite(exportedsyms);
+          repeat
+            writeln(exportedsyms,texportlibunix(exportlib).exportedsymnames.getfirst);
+          until texportlibunix(exportlib).exportedsymnames.empty;
+          close(exportedsyms);
+          cmdstr:=cmdstr+' -exported_symbols_list '+maybequoted(outputexedir)+LinkSymsFileName;
+        end;
+
+      if not(cs_link_nolink in current_settings.globalswitches) then
+        begin
+          { we have to use a script to use the IFS hack }
+          linkscript:=GenerateScript(outputexedir+'ppaslink');
+          linkscript.AddLinkCommand(BinStr,CmdStr,'');
+          if (extdbgbinstr<>'') then
+            linkscript.AddLinkCommand(extdbgbinstr,extdbgcmdstr,'');
+          linkscript.WriteToDisk;
+          BinStr:=linkscript.fn;
+          if not path_absolute(BinStr) then
+            if cs_link_on_target in current_settings.globalswitches then
+              BinStr:='.'+target_info.dirsep+BinStr
+            else
+              BinStr:='.'+source_info.dirsep+BinStr;
+          CmdStr:='';
+        end;
+
+      success:=DoExec(BinStr,cmdstr,true,true);
+      if (success and
+          (extdbgbinstr<>'') and
+          (cs_link_nolink in current_settings.globalswitches)) then
+        success:=DoExec(extdbgbinstr,extdbgcmdstr,false,true);
+
+    { Strip the library ? }
+      if success and (cs_link_strip in current_settings.globalswitches) then
+       begin
+         SplitBinCmd(Info.DllCmd[2],binstr,cmdstr);
+         Replace(cmdstr,'$EXE',maybequoted(current_module.sharedlibfilename));
+         success:=DoExec(FindUtil(utilsprefix+binstr),cmdstr,false,false);
+       end;
+
+    { Remove ReponseFile }
+      if (success) and not(cs_link_nolink in current_settings.globalswitches) then
+        begin
+          DeleteFile(outputexedir+Info.ResName);
+          if ordersymfile<>'' then
+            DeleteFile(ordersymfile);
+          DeleteFile(linkscript.fn);
+          linkscript.free;
+           if LinkSymsFileName<>'' then
+             DeleteFile(outputexedir+LinkSymsFileName);
+           DeleteFile(outputexedir+LinkFilesFileName);
+        end;
+
+      MakeSharedLibrary:=success;   { otherwise a recursive call to link method }
+    end;
+
+
+
+{*****************************************************************************
+                                     Initialize
+*****************************************************************************}
+
+initialization
+  RegisterLinker(ld_darwin,tlinkerdarwin);
+{$ifdef x86_64}
+  RegisterImport(system_x86_64_darwin,timportlibdarwin);
+  RegisterExport(system_x86_64_darwin,texportlibdarwin);
+  RegisterTarget(system_x86_64_darwin_info);
+  RegisterImport(system_x86_64_iphonesim,timportlibdarwin);
+  RegisterExport(system_x86_64_iphonesim,texportlibdarwin);
+  RegisterTarget(system_x86_64_iphonesim_info);
+{$endif}
+{$ifdef i386}
+  RegisterImport(system_i386_darwin,timportlibdarwin);
+  RegisterExport(system_i386_darwin,texportlibdarwin);
+  RegisterTarget(system_i386_darwin_info);
+  RegisterImport(system_i386_iphonesim,timportlibdarwin);
+  RegisterExport(system_i386_iphonesim,texportlibdarwin);
+  RegisterTarget(system_i386_iphonesim_info);
+{$endif i386}
+{$ifdef powerpc}
+  RegisterImport(system_powerpc_darwin,timportlibdarwin);
+  RegisterExport(system_powerpc_darwin,texportlibdarwin);
+  RegisterTarget(system_powerpc_darwin_info);
+{$endif powerpc}
+{$ifdef powerpc64}
+  RegisterImport(system_powerpc64_darwin,timportlibdarwin);
+  RegisterExport(system_powerpc64_darwin,texportlibdarwin);
+  RegisterTarget(system_powerpc64_darwin_info);
+{$endif powerpc64}
+{$ifdef arm}
+  RegisterImport(system_arm_ios,timportlibdarwin);
+  RegisterExport(system_arm_ios,texportlibdarwin);
+  RegisterTarget(system_arm_ios_info);
+{$endif arm}
+{$ifdef aarch64}
+  RegisterImport(system_aarch64_ios,timportlibdarwin);
+  RegisterExport(system_aarch64_ios,texportlibdarwin);
+  RegisterTarget(system_aarch64_ios_info);
+  RegisterImport(system_aarch64_darwin,timportlibdarwin);
+  RegisterExport(system_aarch64_darwin,texportlibdarwin);
+  RegisterTarget(system_aarch64_darwin_info);
+{$endif aarch64}
+
+  RegisterRes(res_macho_info,TWinLikeResourceFile);
+  RegisterRes(res_macosx_ext_info,TWinLikeResourceFile);
+end.
+

+ 5 - 5
compiler/systems/t_macos.pas

@@ -276,7 +276,7 @@ end;
 procedure TLinkerMacOS.SetDefaultInfo;
 procedure TLinkerMacOS.SetDefaultInfo;
 begin
 begin
   case (target_info.system) of
   case (target_info.system) of
-    system_m68k_macos:      SetMacOS68kInfo;
+    system_m68k_macosclassic:      SetMacOS68kInfo;
   end;
   end;
 end;
 end;
 
 
@@ -448,8 +448,8 @@ initialization
 {$ifndef macos}
 {$ifndef macos}
   RegisterLinker(ld_mpw,TLinkerMacOS);
   RegisterLinker(ld_mpw,TLinkerMacOS);
 {$endif}
 {$endif}
-  RegisterTarget(system_m68k_macos_info);
-  RegisterImport(system_m68k_macos,timportlibmacos);
+  RegisterTarget(system_m68k_macosclassic_info);
+  RegisterImport(system_m68k_macosclassic,timportlibmacos);
 {$endif m68k}
 {$endif m68k}
 {$ifdef powerpc}
 {$ifdef powerpc}
 {$ifndef macos}
 {$ifndef macos}
@@ -457,7 +457,7 @@ initialization
 {$else}
 {$else}
   RegisterLinker(ld_mpw,TLinkerMPW);
   RegisterLinker(ld_mpw,TLinkerMPW);
 {$endif}
 {$endif}
-  RegisterTarget(system_powerpc_macos_info);
-  RegisterImport(system_powerpc_macos,timportlibmacos);
+  RegisterTarget(system_powerpc_macosclassic_info);
+  RegisterImport(system_powerpc_macosclassic,timportlibmacos);
 {$endif powerpc}
 {$endif powerpc}
 end.
 end.

+ 101 - 0
compiler/triplet.pas

@@ -0,0 +1,101 @@
+{
+    Copyright (c) 2007-2008, 2013, 2019-2020 by Jonas Maebe
+
+    This unit handles constructing target triples
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit triplet;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+  globtype;
+
+function targettriplet(tripletstyle: ttripletstyle): ansistring;
+
+implementation
+
+uses
+  globals,systems,
+  cpuinfo,tripletcpu;
+
+  function targettriplet(tripletstyle: ttripletstyle): ansistring;
+    begin
+      { architecture }
+      result:=tripletcpustr(tripletstyle);
+      { vendor and/or OS }
+      if target_info.system in systems_darwin then
+        begin
+          result:=result+'-apple';
+          if target_info.system in systems_macosx then
+            result:=result+'-macosx'+MacOSXVersionMin
+          else
+            result:=result+'-ios'+iPhoneOSVersionMin;
+        end
+      else if target_info.system in (systems_linux+systems_android) then
+        result:=result+'-unknown-linux'
+      else if target_info.system in systems_all_windows then
+        begin
+          { WinCE isn't supported (yet) by llvm, but if/when added this is
+            presumably how they will differentiate it }
+          if target_info.system in systems_windows then
+            result:=result+'-pc';
+          result:=result+'-windows-msvc19'
+        end
+      else if target_info.system in systems_freebsd then
+        result:=result+'-unknown-freebsd'
+      else if target_info.system in systems_openbsd then
+        result:=result+'-unknown-openbsd'
+      else if target_info.system in systems_netbsd then
+        result:=result+'-unknown-netbsd'
+      else if target_info.system in systems_solaris then
+        result:=result+'-sun-solaris2'
+      else if target_info.system in systems_aix then
+        result:=result+'-ibm-aix53'
+      else if target_info.system in [system_i386_haiku] then
+        result:=result+'-unknown-haiku'
+      else if target_info.system in systems_embedded then
+        result:=result+'-none'
+      else
+        result:=result+'-unknown';
+
+      { environment/ABI }
+      if target_info.system in systems_android then
+        result:=result+'-android'
+      else
+{$ifdef arm}
+      if target_info.abi=abi_eabihf then
+        result:=result+'-gnueabihf'
+      else if target_info.system in systems_embedded then
+        result:=result+'-eabi'
+      else if target_info.abi=abi_eabi then
+        result:=result+'-gnueabi'
+      else
+{$endif}
+      if target_info.system in systems_embedded then
+        result:=result+'-elf'
+      else if target_info.system in systems_linux then
+        result:=result+'-gnu';
+    end;
+
+
+
+end.
+

+ 10 - 5
compiler/utils/ppuutils/ppudump.pp

@@ -121,12 +121,12 @@ const
   { 6 }   'FreeBSD-i386',
   { 6 }   'FreeBSD-i386',
   { 7 }   'Amiga',
   { 7 }   'Amiga',
   { 8 }   'Atari',
   { 8 }   'Atari',
-  { 9 }   'MacOS-m68k',
+  { 9 }   'MacOSClassic-m68k',
   { 10 }  'Linux-m68k',
   { 10 }  'Linux-m68k',
   { 11 }  'PalmOS-m68k',
   { 11 }  'PalmOS-m68k',
   { 12 }  'Linux-alpha (obsolete)',
   { 12 }  'Linux-alpha (obsolete)',
   { 13 }  'Linux-ppc',
   { 13 }  'Linux-ppc',
-  { 14 }  'MacOS-ppc',
+  { 14 }  'MacOSClassic-ppc',
   { 15 }  'Solaris-i386',
   { 15 }  'Solaris-i386',
   { 16 }  'BeOS-i386',
   { 16 }  'BeOS-i386',
   { 17 }  'NetBSD-i386',
   { 17 }  'NetBSD-i386',
@@ -176,7 +176,7 @@ const
   { 61 }  'Darwin-x64',
   { 61 }  'Darwin-x64',
   { 62 }  'Embedded-avr',
   { 62 }  'Embedded-avr',
   { 63 }  'Haiku-i386',
   { 63 }  'Haiku-i386',
-  { 64 }  'Darwin-ARM',
+  { 64 }  'iOS-ARM',
   { 65 }  'Solaris-x86-64',
   { 65 }  'Solaris-x86-64',
   { 66 }  'Linux-MIPS',
   { 66 }  'Linux-MIPS',
   { 67 }  'Linux-MIPSel',
   { 67 }  'Linux-MIPSel',
@@ -198,7 +198,7 @@ const
   { 83 }  'AROS-i386',
   { 83 }  'AROS-i386',
   { 84 }  'AROS-x86-64',
   { 84 }  'AROS-x86-64',
   { 85 }  'DragonFly-x86-64',
   { 85 }  'DragonFly-x86-64',
-  { 86 }  'Darwin-AArch64',
+  { 86 }  'iOS-AArch64',
   { 87 }  'iPhoneSim-x86-64',
   { 87 }  'iPhoneSim-x86-64',
   { 88 }  'Linux-AArch64',
   { 88 }  'Linux-AArch64',
   { 89 }  'Win16',
   { 89 }  'Win16',
@@ -214,7 +214,8 @@ const
   { 99 }  'Embedded-RiscV64',
   { 99 }  'Embedded-RiscV64',
   { 100 } 'Android-AArch64',
   { 100 } 'Android-AArch64',
   { 101 } 'Android-x86-64',
   { 101 } 'Android-x86-64',
-  { 102 } 'Haiku-x86-64'
+  { 102 } 'Haiku-x86-64',
+  { 111 } 'Darwin-AArch64'
   );
   );
 
 
 const
 const
@@ -4692,6 +4693,10 @@ begin
            if not silent then
            if not silent then
              ReadContainer('Resource file: ');
              ReadContainer('Resource file: ');
 
 
+         iborderedsymbols:
+           if not silent then
+             ReadContainer('Ordered symbol: ');
+
          iberror :
          iberror :
            begin
            begin
              WriteError('Error in PPU');
              WriteError('Error in PPU');

+ 6 - 6
compiler/x86/agx86att.pas

@@ -447,12 +447,12 @@ interface
 
 
        as_x86_64_clang_darwin_info : tasminfo =
        as_x86_64_clang_darwin_info : tasminfo =
           (
           (
-            id     : as_clang;
+            id     : as_clang_asdarwin;
             idtxt  : 'CLANG';
             idtxt  : 'CLANG';
             asmbin : 'clang';
             asmbin : 'clang';
-            asmcmd : '-c -o $OBJ $EXTRAOPT -arch x86_64 $DARWINVERSION -x assembler $ASM';
+            asmcmd : '-x assembler -c -target $TRIPLET -o $OBJ $EXTRAOPT -x assembler $ASM';
             supported_targets : [system_x86_64_darwin,system_x86_64_iphonesim];
             supported_targets : [system_x86_64_darwin,system_x86_64_iphonesim];
-            flags : [af_needar,af_smartlink_sections,af_supports_dwarf,af_no_stabs];
+            flags : [af_needar,af_smartlink_sections,af_supports_dwarf,af_no_stabs,af_llvm];
             labelprefix : 'L';
             labelprefix : 'L';
             comment : '# ';
             comment : '# ';
             dollarsign: '$';
             dollarsign: '$';
@@ -521,12 +521,12 @@ interface
 
 
        as_i386_clang_darwin_info : tasminfo =
        as_i386_clang_darwin_info : tasminfo =
           (
           (
-            id     : as_clang;
+            id     : as_clang_asdarwin;
             idtxt  : 'CLANG';
             idtxt  : 'CLANG';
             asmbin : 'clang';
             asmbin : 'clang';
-            asmcmd : '-c -o $OBJ $EXTRAOPT -arch i386 $DARWINVERSION -x assembler $ASM';
+            asmcmd : '-x assembler -c -target $TRIPLET -o $OBJ $EXTRAOPT -x assembler $ASM';
             supported_targets : [system_i386_darwin,system_i386_iphonesim];
             supported_targets : [system_i386_darwin,system_i386_iphonesim];
-            flags : [af_needar,af_smartlink_sections,af_supports_dwarf,af_no_stabs];
+            flags : [af_needar,af_smartlink_sections,af_supports_dwarf,af_no_stabs,af_llvm];
             labelprefix : 'L';
             labelprefix : 'L';
             comment : '# ';
             comment : '# ';
             dollarsign: '$';
             dollarsign: '$';

+ 3 - 0
compiler/x86_64/cputarg.pas

@@ -44,6 +44,9 @@ implementation
     {$ifndef NOTARGETFREEBSD}
     {$ifndef NOTARGETFREEBSD}
       ,t_bsd
       ,t_bsd
     {$endif}
     {$endif}
+    {$ifndef NOTARGETDARWIN}
+      ,t_darwin
+    {$endif}
     {$ifndef NOTARGETWIN}
     {$ifndef NOTARGETWIN}
       ,t_win
       ,t_win
       ,win64unw
       ,win64unw

+ 45 - 0
compiler/x86_64/tripletcpu.pas

@@ -0,0 +1,45 @@
+{
+    Copyright (c) 2020 by Jonas Maebe
+
+    Construct the cpu part of the triplet
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+ ****************************************************************************
+}
+unit tripletcpu;
+
+{$i fpcdefs.inc}
+
+interface
+
+uses
+  globtype;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+
+implementation
+
+uses
+  globals, cpuinfo;
+
+function tripletcpustr(tripletstyle: ttripletstyle): ansistring;
+  begin
+    result:='x86_64';
+  end;
+
+
+end.
+

+ 1 - 1
packages/aspell/fpmake.pp

@@ -23,7 +23,7 @@ begin
     P.Author := 'header:Aleš Katona, library: Kevin Atkinson';
     P.Author := 'header:Aleš Katona, library: Kevin Atkinson';
     P.License := 'header: LGPL with modification, library: LGPL 2.0 or 2.1';
     P.License := 'header: LGPL with modification, library: LGPL 2.0 or 2.1';
     P.HomepageURL := 'www.freepascal.org';
     P.HomepageURL := 'www.freepascal.org';
-    P.OSes := [beos,haiku,freebsd,darwin,iphonesim,netbsd,openbsd,linux,win32,aix,dragonfly];
+    P.OSes := [beos,haiku,freebsd,darwin,iphonesim,ios,netbsd,openbsd,linux,win32,aix,dragonfly];
     P.Email := '';
     P.Email := '';
     P.Description := 'The New Aspell, spelling library';
     P.Description := 'The New Aspell, spelling library';
     P.NeedLibC:= true;
     P.NeedLibC:= true;

+ 1 - 1
packages/bfd/fpmake.pp

@@ -23,7 +23,7 @@ begin
     P.Email := '';
     P.Email := '';
     P.Description := 'Binary File Descriptor library.';
     P.Description := 'Binary File Descriptor library.';
     P.NeedLibC:= true;
     P.NeedLibC:= true;
-    P.OSes := [beos,haiku,freebsd,darwin,iphonesim,solaris,netbsd,openbsd,linux,aix,dragonfly];
+    P.OSes := [beos,haiku,freebsd,darwin,iphonesim,ios,solaris,netbsd,openbsd,linux,aix,dragonfly];
 
 
     P.SourcePath.Add('src');
     P.SourcePath.Add('src');
 
 

+ 1 - 1
packages/bzip2/fpmake.pp

@@ -28,7 +28,7 @@ begin
     P.Email := '';
     P.Email := '';
     P.Description := 'BZip2 decompression unit.';
     P.Description := 'BZip2 decompression unit.';
     P.NeedLibC:= true;
     P.NeedLibC:= true;
-    P.OSes := P.OSes - [embedded,nativent,msdos,win16,macos,palmos];
+    P.OSes := P.OSes - [embedded,nativent,msdos,win16,macosclassic,palmos];
     if Defaults.CPU=jvm then
     if Defaults.CPU=jvm then
       P.OSes := P.OSes - [java,android];
       P.OSes := P.OSes - [java,android];
 
 

+ 1 - 1
packages/chm/fpmake.pp

@@ -25,7 +25,7 @@ begin
     P.Email := '';
     P.Email := '';
     P.Description := 'Standalone CHM reader and writer library';
     P.Description := 'Standalone CHM reader and writer library';
     P.NeedLibC:= false;
     P.NeedLibC:= false;
-    P.OSes := P.OSes - [embedded,nativent,msdos,win16,macos,palmos,atari];
+    P.OSes := P.OSes - [embedded,nativent,msdos,win16,macosclassic,palmos,atari];
     if Defaults.CPU=jvm then
     if Defaults.CPU=jvm then
       P.OSes := P.OSes - [java,android];
       P.OSes := P.OSes - [java,android];
 
 

+ 1 - 1
packages/cocoaint/fpmake.pp

@@ -17,7 +17,7 @@ begin
     P.Directory:=ADirectory;
     P.Directory:=ADirectory;
 {$endif ALLPACKAGES}
 {$endif ALLPACKAGES}
     P.Version:='3.2.1';
     P.Version:='3.2.1';
-    P.CPUs:=[i386,x86_64,powerpc,powerpc64];
+    P.CPUs:=[i386,x86_64,powerpc,powerpc64,aarch64];
     P.OSes:=[darwin];
     P.OSes:=[darwin];
     P.Dependencies.Add('univint');
     P.Dependencies.Add('univint');
     P.SourcePath.Add('src');
     P.SourcePath.Add('src');

+ 1 - 1
packages/cocoaint/src/appkit/NSApplication.inc

@@ -683,7 +683,7 @@ type
 {$endif}
 {$endif}
 
 
 {$ifdef FUNCTIONS}
 {$ifdef FUNCTIONS}
-function NSApplicationMain(argc: cint; argv: PChar { variable size array of PChar }): cint; cdecl; external;
+function NSApplicationMain(argc: cint; argv: PPChar { variable size array of PChar }): cint; cdecl; external;
 function NSApplicationLoad: ObjCBOOL; cdecl; external;
 function NSApplicationLoad: ObjCBOOL; cdecl; external;
 function NSShowsServicesMenuItem(itemName: NSString): ObjCBOOL; cdecl; external;
 function NSShowsServicesMenuItem(itemName: NSString): ObjCBOOL; cdecl; external;
 function NSSetShowsServicesMenuItem(itemName: NSString; enabled: ObjCBOOL): NSInteger; cdecl; external;
 function NSSetShowsServicesMenuItem(itemName: NSString; enabled: ObjCBOOL): NSInteger; cdecl; external;

+ 1 - 1
packages/cocoaint/src/iobluetooth/IOBluetoothUserLib.inc

@@ -15,7 +15,7 @@ type
 {$endif}
 {$endif}
 
 
 {$ifdef FUNCTIONS}
 {$ifdef FUNCTIONS}
-function IOBluetoothGetObjectIDFromArguments(argc: cint; argv: PChar { variable size array of PChar }): IOBluetoothObjectID; cdecl; external; deprecated 'in 10.6 and later';
+function IOBluetoothGetObjectIDFromArguments(argc: cint; argv: PPChar { variable size array of PChar }): IOBluetoothObjectID; cdecl; external; deprecated 'in 10.6 and later';
 {$endif}
 {$endif}
 
 
 {$ifdef TYPES}
 {$ifdef TYPES}

+ 2 - 2
packages/fcl-base/fpmake.pp

@@ -18,7 +18,7 @@ begin
     P.Directory:=ADirectory;
     P.Directory:=ADirectory;
 {$endif ALLPACKAGES}
 {$endif ALLPACKAGES}
     P.Version:='3.2.1';
     P.Version:='3.2.1';
-    P.Dependencies.Add('univint',[Darwin,iPhoneSim]);
+    P.Dependencies.Add('univint',[Darwin,iPhoneSim,ios]);
     p.Dependencies.Add('rtl-objpas');
     p.Dependencies.Add('rtl-objpas');
 
 
     P.Author := '<various>';
     P.Author := '<various>';
@@ -26,7 +26,7 @@ begin
     P.Email := '';
     P.Email := '';
     P.Description := 'Base library of Free Component Libraries (FCL), FPC''s OOP library.';
     P.Description := 'Base library of Free Component Libraries (FCL), FPC''s OOP library.';
     P.NeedLibC:= false;
     P.NeedLibC:= false;
-    P.OSes:=AllOSes-[embedded,msdos,win16,macos,palmos];
+    P.OSes:=AllOSes-[embedded,msdos,win16,macosclassic,palmos];
     if Defaults.CPU=jvm then
     if Defaults.CPU=jvm then
       P.OSes := P.OSes - [java,android];
       P.OSes := P.OSes - [java,android];
 
 

+ 4 - 4
packages/fcl-db/fpmake.pp

@@ -10,9 +10,9 @@ procedure add_fcl_db(const ADirectory: string);
 const
 const
   ParadoxOSes         = [beos,haiku,linux,freebsd,netbsd,openbsd,win32,dragonfly];
   ParadoxOSes         = [beos,haiku,linux,freebsd,netbsd,openbsd,win32,dragonfly];
   DatadictOSes        = [aix,beos,darwin,haiku,linux,freebsd,win32,win64,wince,android,dragonfly];
   DatadictOSes        = [aix,beos,darwin,haiku,linux,freebsd,win32,win64,wince,android,dragonfly];
-  SqldbConnectionOSes = [aix,beos,haiku,linux,freebsd,darwin,iphonesim,netbsd,openbsd,solaris,win32,win64,wince,android,dragonfly];
-  SqliteOSes          = [aix,beos,haiku,linux,freebsd,darwin,iphonesim,netbsd,openbsd,solaris,win32,win64,wince,android,dragonfly];
-  DBaseOSes           = [aix,beos,haiku,linux,freebsd,darwin,iphonesim,netbsd,openbsd,solaris,win32,win64,wince,android,os2,dragonfly];
+  SqldbConnectionOSes = [aix,beos,haiku,linux,freebsd,darwin,iphonesim,ios,netbsd,openbsd,solaris,win32,win64,wince,android,dragonfly];
+  SqliteOSes          = [aix,beos,haiku,linux,freebsd,darwin,iphonesim,ios,netbsd,openbsd,solaris,win32,win64,wince,android,dragonfly];
+  DBaseOSes           = [aix,beos,haiku,linux,freebsd,darwin,iphonesim,ios,netbsd,openbsd,solaris,win32,win64,wince,android,os2,dragonfly];
   MSSQLOSes           = [beos,haiku,linux,freebsd,netbsd,openbsd,solaris,win32,win64,android,dragonfly];
   MSSQLOSes           = [beos,haiku,linux,freebsd,netbsd,openbsd,solaris,win32,win64,android,dragonfly];
 
 
 
 
@@ -32,7 +32,7 @@ begin
     P.Email := '';
     P.Email := '';
     P.Description := 'Database library of Free Component Libraries(FCL), FPC''s OOP library.';
     P.Description := 'Database library of Free Component Libraries(FCL), FPC''s OOP library.';
     P.NeedLibC:= false;
     P.NeedLibC:= false;
-    P.OSes:=AllOSes-[embedded,msdos,win16,macos,palmos];
+    P.OSes:=AllOSes-[embedded,msdos,win16,macosclassic,palmos];
     if Defaults.CPU=jvm then
     if Defaults.CPU=jvm then
       P.OSes := P.OSes - [java,android];
       P.OSes := P.OSes - [java,android];
 
 

+ 1 - 1
packages/fcl-extra/fpmake.pp

@@ -25,7 +25,7 @@ begin
 
 
     P.Dependencies.Add('winunits-jedi',[Win32,Win64]);
     P.Dependencies.Add('winunits-jedi',[Win32,Win64]);
     P.Dependencies.Add('winunits-base',[Win32,Win64]);
     P.Dependencies.Add('winunits-base',[Win32,Win64]);
-    P.Dependencies.Add('univint',[darwin,iPhoneSim]);
+    P.Dependencies.Add('univint',[darwin,iPhoneSim,ios]);
 
 
     P.Author := '<various>';
     P.Author := '<various>';
     P.License := 'LGPL with modification, ';
     P.License := 'LGPL with modification, ';

+ 2 - 2
packages/fcl-fpcunit/fpmake.pp

@@ -22,7 +22,7 @@ begin
     P.Dependencies.Add('fcl-base');
     P.Dependencies.Add('fcl-base');
     P.Dependencies.Add('fcl-xml');
     P.Dependencies.Add('fcl-xml');
     P.Dependencies.Add('libtar');
     P.Dependencies.Add('libtar');
-    P.Dependencies.Add('univint',[Darwin,iPhoneSim]);
+    P.Dependencies.Add('univint',[Darwin,iPhoneSim,ios]);
 
 
     P.Author := ' Dean Zobec, Michael van Canneyt';
     P.Author := ' Dean Zobec, Michael van Canneyt';
     P.License := 'LGPL with modification, ';
     P.License := 'LGPL with modification, ';
@@ -30,7 +30,7 @@ begin
     P.Email := '';
     P.Email := '';
     P.Description := 'Unit testing system inspired by JUnit of Free Component Libraries (FCL), FPC''s OOP library.';
     P.Description := 'Unit testing system inspired by JUnit of Free Component Libraries (FCL), FPC''s OOP library.';
     P.NeedLibC:= false;
     P.NeedLibC:= false;
-    P.OSes := P.OSes - [embedded,nativent,msdos,win16,macos,palmos,symbian];
+    P.OSes := P.OSes - [embedded,nativent,msdos,win16,macosclassic,palmos,symbian];
     if Defaults.CPU=jvm then
     if Defaults.CPU=jvm then
       P.OSes := P.OSes - [java,android];
       P.OSes := P.OSes - [java,android];
 
 

+ 5 - 5
packages/fcl-image/fpmake.pp

@@ -28,7 +28,7 @@ begin
     P.Email := '';
     P.Email := '';
     P.Description := 'Image loading and conversion parts of Free Component Libraries (FCL), FPC''s OOP library.';
     P.Description := 'Image loading and conversion parts of Free Component Libraries (FCL), FPC''s OOP library.';
     P.NeedLibC:= false;
     P.NeedLibC:= false;
-    P.OSes := P.OSes - [embedded,nativent,msdos,win16,macos,palmos];
+    P.OSes := P.OSes - [embedded,nativent,msdos,win16,macosclassic,palmos];
     if Defaults.CPU=jvm then
     if Defaults.CPU=jvm then
       P.OSes := P.OSes - [java,android];
       P.OSes := P.OSes - [java,android];
 
 
@@ -224,18 +224,18 @@ begin
         begin
         begin
           AddUnit('fpimage');
           AddUnit('fpimage');
         end;
         end;
-    T:=P.Targets.AddUnit('freetypeh.pp',[solaris,iphonesim,darwin,freebsd,openbsd,netbsd,linux,haiku,beos,win32,win64,aix,dragonfly]);
+    T:=P.Targets.AddUnit('freetypeh.pp',[solaris,iphonesim,ios,darwin,freebsd,openbsd,netbsd,linux,haiku,beos,win32,win64,aix,dragonfly]);
     T.Dependencies.AddInclude('libfreetype.inc');
     T.Dependencies.AddInclude('libfreetype.inc');
-    T:=P.Targets.AddUnit('freetypehdyn.pp',[solaris,iphonesim,darwin,freebsd,openbsd,netbsd,linux,haiku,beos,win32,win64,aix,dragonfly]);
+    T:=P.Targets.AddUnit('freetypehdyn.pp',[solaris,iphonesim,ios,darwin,freebsd,openbsd,netbsd,linux,haiku,beos,win32,win64,aix,dragonfly]);
       T.ResourceStrings:=true;
       T.ResourceStrings:=true;
     T.Dependencies.AddInclude('libfreetype.inc');
     T.Dependencies.AddInclude('libfreetype.inc');
-    T:=P.Targets.AddUnit('freetype.pp',[solaris,iphonesim,darwin,freebsd,openbsd,netbsd,linux,haiku,beos,win32,win64,aix,dragonfly]);
+    T:=P.Targets.AddUnit('freetype.pp',[solaris,iphonesim,ios,darwin,freebsd,openbsd,netbsd,linux,haiku,beos,win32,win64,aix,dragonfly]);
       with T.Dependencies do
       with T.Dependencies do
         begin
         begin
           AddUnit('freetypeh');
           AddUnit('freetypeh');
           AddUnit('fpimgcmn');
           AddUnit('fpimgcmn');
         end;
         end;
-    T:=P.Targets.AddUnit('ftfont.pp',[solaris,iphonesim,darwin,freebsd,openbsd,netbsd,linux,haiku,beos,win32,win64,aix,dragonfly]);
+    T:=P.Targets.AddUnit('ftfont.pp',[solaris,iphonesim,ios,darwin,freebsd,openbsd,netbsd,linux,haiku,beos,win32,win64,aix,dragonfly]);
       with T.Dependencies do
       with T.Dependencies do
         begin
         begin
           AddUnit('fpcanvas');
           AddUnit('fpcanvas');

+ 1 - 1
packages/fcl-js/fpmake.pp

@@ -23,7 +23,7 @@ begin
     P.HomepageURL := 'www.freepascal.org';
     P.HomepageURL := 'www.freepascal.org';
     P.Email := '[email protected]';
     P.Email := '[email protected]';
     P.Description := 'Javascript scanner/parser/syntax tree units';
     P.Description := 'Javascript scanner/parser/syntax tree units';
-    P.OSes:=AllOSes-[embedded,msdos,win16,macos,palmos];
+    P.OSes:=AllOSes-[embedded,msdos,win16,macosclassic,palmos];
     if Defaults.CPU=jvm then
     if Defaults.CPU=jvm then
       P.OSes := P.OSes - [java,android];
       P.OSes := P.OSes - [java,android];
 
 

+ 1 - 1
packages/fcl-json/fpmake.pp

@@ -26,7 +26,7 @@ begin
     P.Email := '';
     P.Email := '';
     P.Description := 'Json interfacing, part of Free Component Libraries (FCL), FPC''s OOP library.';
     P.Description := 'Json interfacing, part of Free Component Libraries (FCL), FPC''s OOP library.';
     P.NeedLibC:= false;
     P.NeedLibC:= false;
-    P.OSes:=AllOSes-[embedded,msdos,win16,macos,palmos];
+    P.OSes:=AllOSes-[embedded,msdos,win16,macosclassic,palmos];
     if Defaults.CPU=jvm then
     if Defaults.CPU=jvm then
       P.OSes := P.OSes - [java,android];
       P.OSes := P.OSes - [java,android];
 
 

+ 1 - 1
packages/fcl-net/fpmake.pp

@@ -30,7 +30,7 @@ begin
     P.Email := '';
     P.Email := '';
     P.Description := 'Network related parts of Free Component Libraries (FCL), FPC''s OOP library.';
     P.Description := 'Network related parts of Free Component Libraries (FCL), FPC''s OOP library.';
     P.NeedLibC:= false;
     P.NeedLibC:= false;
-    P.OSes:=P.OSes-[embedded,msdos,win16,macos,palmos];
+    P.OSes:=P.OSes-[embedded,msdos,win16,macosclassic,palmos];
     if Defaults.CPU=jvm then
     if Defaults.CPU=jvm then
       P.OSes := P.OSes - [java,android];
       P.OSes := P.OSes - [java,android];
 
 

+ 1 - 1
packages/fcl-passrc/fpmake.pp

@@ -25,7 +25,7 @@ begin
     P.Email := '';
     P.Email := '';
     P.Description := 'Pascal parsing parts of Free Component Libraries (FCL), FPC''s OOP library.';
     P.Description := 'Pascal parsing parts of Free Component Libraries (FCL), FPC''s OOP library.';
     P.NeedLibC:= false;
     P.NeedLibC:= false;
-    P.OSes:=AllOSes-[embedded,msdos,win16,macos,palmos];
+    P.OSes:=AllOSes-[embedded,msdos,win16,macosclassic,palmos];
     if Defaults.CPU=jvm then
     if Defaults.CPU=jvm then
       P.OSes := P.OSes - [java,android];
       P.OSes := P.OSes - [java,android];
 
 

+ 1 - 1
packages/fcl-pdf/fpmake.pp

@@ -24,7 +24,7 @@ begin
     P.Email := '';
     P.Email := '';
     P.Description := 'PDF generating and TTF file info library';
     P.Description := 'PDF generating and TTF file info library';
     P.NeedLibC:= false;
     P.NeedLibC:= false;
-    P.OSes:=P.OSes-[embedded,win16,msdos,nativent,macos,palmos];
+    P.OSes:=P.OSes-[embedded,win16,msdos,nativent,macosclassic,palmos];
     if Defaults.CPU=jvm then
     if Defaults.CPU=jvm then
       P.OSes := P.OSes - [java,android];
       P.OSes := P.OSes - [java,android];
 
 

部分文件因为文件数量过多而无法显示