Browse Source

Add -Aas-clang for i386/x86_64 unix targets

Fix problems with:
  * Add entry corresponding to cs_link_lld in ppudump source
  * Add ld.lld as default linker for x86_64-openbsd system

(cherry picked from commit 513ba3c733a23a945c002f5d5b673bcffa06e095)
Pierre Muller 1 year ago
parent
commit
272b3eea2e

+ 3 - 1
compiler/globtype.pas

@@ -224,7 +224,9 @@ interface
          cs_link_map,cs_link_pthread,cs_link_no_default_lib_order,
          cs_link_map,cs_link_pthread,cs_link_no_default_lib_order,
          cs_link_native,
          cs_link_native,
          cs_link_pre_binutils_2_19,
          cs_link_pre_binutils_2_19,
-         cs_link_vlink
+         cs_link_vlink,
+         { Use ld.lld linker }
+         cs_link_lld
        );
        );
        tglobalswitches = set of tglobalswitch;
        tglobalswitches = set of tglobalswitch;
 
 

+ 12 - 2
compiler/options.pas

@@ -2713,7 +2713,7 @@ begin
                       end;
                       end;
                     'L' : begin  // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
                     'L' : begin  // -XLO is link order -XLA is link alias. -XLD avoids load defaults.
                                  // these are not aggregable.
                                  // these are not aggregable.
-                            if (j=length(more)) or not (more[j+1] in ['O','A','D']) then
+                            if (j=length(more)) or not (more[j+1] in ['O','A','D','L']) then
                               IllegalPara(opt)
                               IllegalPara(opt)
                             else
                             else
                               begin
                               begin
@@ -2728,7 +2728,17 @@ begin
                                         if not LinkLibraryOrder.AddWeight(s) Then
                                         if not LinkLibraryOrder.AddWeight(s) Then
                                            IllegalPara(opt);
                                            IllegalPara(opt);
                                        end;
                                        end;
-                                 'D' : include(init_settings.globalswitches,cs_link_no_default_lib_order)
+                                 'D' : include(init_settings.globalswitches,cs_link_no_default_lib_order);
+                                 'L' : begin
+                                         if UnsetBool(More, j, opt, false) then
+                                           exclude(init_settings.globalswitches,cs_link_lld)
+                                         else
+                                           begin
+                                             include(init_settings.globalswitches,cs_link_lld);
+                                             include(init_settings.globalswitches,cs_link_extern);
+                                           end;
+                                         LinkerSetExplicitly:=true;
+                                       end
                                 else
                                 else
                                   IllegalPara(opt);
                                   IllegalPara(opt);
                                  end; {case}
                                  end; {case}

+ 5 - 1
compiler/systems/t_bsd.pas

@@ -126,7 +126,11 @@ procedure TLinkerBSD.SetDefaultInfo;
 var
 var
   LdProgram: string='ld';
   LdProgram: string='ld';
 begin
 begin
-  if target_info.system in (systems_openbsd+systems_freebsd+[system_x86_64_dragonfly]) then
+  { Force ld.lld usage for x86_64 openbsd system,
+    because GNU linker generates wrong executable's on x86_64 OpenBSD 7.5 }
+  if (cs_link_lld in current_settings.globalswitches) or (target_info.system = system_x86_64_openbsd) then
+    LdProgram:='ld.lld'
+  else if target_info.system in (systems_openbsd+systems_freebsd+[system_x86_64_dragonfly]) then
     LdProgram:='ld.bfd';
     LdProgram:='ld.bfd';
   LibrarySuffix:=' ';
   LibrarySuffix:=' ';
   LdSupportsNoResponseFile := (target_info.system in ([system_m68k_netbsd]+systems_darwin));
   LdSupportsNoResponseFile := (target_info.system in ([system_m68k_netbsd]+systems_darwin));

+ 2 - 1
compiler/utils/ppuutils/ppudump.pp

@@ -2187,7 +2187,8 @@ const
         'Link no default lib order', {cs_link_no_default_lib_order}
         'Link no default lib order', {cs_link_no_default_lib_order}
         'Link using native linker', {cs_link_native}
         'Link using native linker', {cs_link_native}
         'Link for GNU linker version <=2.19', {cs_link_pre_binutils_2_19}
         'Link for GNU linker version <=2.19', {cs_link_pre_binutils_2_19}
-        'Link using vlink' {cs_link_vlink}
+        'Link using vlink', {cs_link_vlink}
+        'Link using ld.lld GNU compatible LLVM linker' {cs_link_lld}
        );
        );
     localswitchname : array[tlocalswitch] of string[50] =
     localswitchname : array[tlocalswitch] of string[50] =
        { Switches which can be changed locally }
        { Switches which can be changed locally }

+ 30 - 0
compiler/x86/agx86att.pas

@@ -458,6 +458,20 @@ interface
             dollarsign: '$';
             dollarsign: '$';
           );
           );
 
 
+       as_x86_64_clang_gas_info : tasminfo =
+          (
+            id     : as_clang_gas;
+            idtxt  : 'AS-CLANG';
+            asmbin : 'clang';
+            asmcmd : '-x assembler -c -target $TRIPLET -o $OBJ $EXTRAOPT -x assembler $ASM';
+            supported_targets : [system_x86_64_linux, system_x86_64_freebsd, system_x86_64_netbsd, system_x86_64_openbsd];
+            flags : [af_needar,af_smartlink_sections,af_supports_dwarf,af_llvm,af_supports_hlcfi];
+            labelprefix : '.L';
+            labelmaxlen : -1;
+            comment : '// ';
+            dollarsign: '$';
+          );
+
 {$else x86_64}
 {$else x86_64}
        as_i386_as_info : tasminfo =
        as_i386_as_info : tasminfo =
           (
           (
@@ -532,6 +546,20 @@ interface
             dollarsign: '$';
             dollarsign: '$';
           );
           );
 
 
+       as_i386_clang_gas_info : tasminfo =
+          (
+            id     : as_clang_gas;
+            idtxt  : 'AS-CLANG';
+            asmbin : 'clang';
+            asmcmd : '-x assembler -c -target $TRIPLET -o $OBJ $EXTRAOPT -x assembler $ASM';
+            supported_targets : [system_i386_linux, system_i386_freebsd, system_i386_netbsd, system_i386_openbsd];
+            flags : [af_needar,af_smartlink_sections,af_supports_dwarf,af_llvm,af_supports_hlcfi];
+            labelprefix : '.L';
+            labelmaxlen : -1;
+            comment : '// ';
+            dollarsign: '$';
+          );
+
        as_i386_gas_info : tasminfo =
        as_i386_gas_info : tasminfo =
           (
           (
             id     : as_ggas;
             id     : as_ggas;
@@ -571,6 +599,7 @@ initialization
   RegisterAssembler(as_x86_64_gas_info,Tx86ATTAssembler);
   RegisterAssembler(as_x86_64_gas_info,Tx86ATTAssembler);
   RegisterAssembler(as_x86_64_gas_darwin_info,Tx86AppleGNUAssembler);
   RegisterAssembler(as_x86_64_gas_darwin_info,Tx86AppleGNUAssembler);
   RegisterAssembler(as_x86_64_clang_darwin_info,Tx86AppleGNUAssembler);
   RegisterAssembler(as_x86_64_clang_darwin_info,Tx86AppleGNUAssembler);
+  RegisterAssembler(as_x86_64_clang_gas_info,Tx86ATTAssembler);
   RegisterAssembler(as_x86_64_solaris_info,Tx86ATTAssembler);
   RegisterAssembler(as_x86_64_solaris_info,Tx86ATTAssembler);
 {$else x86_64}
 {$else x86_64}
   RegisterAssembler(as_i386_as_info,Tx86ATTAssembler);
   RegisterAssembler(as_i386_as_info,Tx86ATTAssembler);
@@ -578,6 +607,7 @@ initialization
   RegisterAssembler(as_i386_yasm_info,Tx86ATTAssembler);
   RegisterAssembler(as_i386_yasm_info,Tx86ATTAssembler);
   RegisterAssembler(as_i386_gas_darwin_info,Tx86AppleGNUAssembler);
   RegisterAssembler(as_i386_gas_darwin_info,Tx86AppleGNUAssembler);
   RegisterAssembler(as_i386_clang_darwin_info,Tx86AppleGNUAssembler);
   RegisterAssembler(as_i386_clang_darwin_info,Tx86AppleGNUAssembler);
+  RegisterAssembler(as_i386_clang_gas_info,Tx86ATTAssembler);
   RegisterAssembler(as_i386_as_aout_info,Tx86AoutGNUAssembler);
   RegisterAssembler(as_i386_as_aout_info,Tx86AoutGNUAssembler);
   RegisterAssembler(as_i386_solaris_info,Tx86ATTAssembler);
   RegisterAssembler(as_i386_solaris_info,Tx86ATTAssembler);
 {$endif x86_64}
 {$endif x86_64}