From 0710ab894a5234cc68a6f43dfb9aac95c9c96010 Mon Sep 17 00:00:00 2001 From: Tristan Gingold Date: Mon, 5 Dec 2016 21:00:35 +0100 Subject: Use -fpic if gcc is configured with --enable-default-pie Test in configure and set Default_Pie in default_pathes.ads Pass -fpic to ghdl1 if Default_Pie is set. Decode -fpic in ghdl1_llvm Fix #213 --- src/ghdldrv/default_pathes.ads.in | 1 + src/ghdldrv/ghdldrv.adb | 51 +++++++++++++++++++++++++++++++-------- 2 files changed, 42 insertions(+), 10 deletions(-) (limited to 'src/ghdldrv') diff --git a/src/ghdldrv/default_pathes.ads.in b/src/ghdldrv/default_pathes.ads.in index a7c3d15f7..8b0801e13 100644 --- a/src/ghdldrv/default_pathes.ads.in +++ b/src/ghdldrv/default_pathes.ads.in @@ -39,4 +39,5 @@ package Default_Pathes is Shared_Library_Extension : constant String := "@SOEXT@"; + Default_Pie : constant Boolean := "@default_pie@" = String'("yes"); end Default_Pathes; diff --git a/src/ghdldrv/ghdldrv.adb b/src/ghdldrv/ghdldrv.adb index 082d1db57..ae8e510f3 100644 --- a/src/ghdldrv/ghdldrv.adb +++ b/src/ghdldrv/ghdldrv.adb @@ -41,8 +41,8 @@ package body Ghdldrv is -- Name of the tools used. Compiler_Cmd : String_Access := null; Post_Processor_Cmd : String_Access := null; - Assembler_Cmd : constant String := "as"; - Linker_Cmd : constant String := "gcc"; + Assembler_Cmd : String_Access := null; + Linker_Cmd : String_Access := null; -- Path of the tools. Compiler_Path : String_Access; @@ -63,6 +63,9 @@ package body Ghdldrv is -- "-quiet" option. Dash_Quiet : constant String_Access := new String'("-quiet"); + -- "-fpic" option. + Dash_Fpic : constant String_Access := new String'("-fpic"); + -- True if --post is present. Flag_Postprocess : Boolean := False; @@ -162,7 +165,7 @@ package body Ghdldrv is declare P : Natural; Nbr_Args : constant Natural := - Last (Compiler_Args) + Options'Length + 4; + Last (Compiler_Args) + Options'Length + 5; Args : Argument_List (1 .. Nbr_Args); begin P := 0; @@ -191,6 +194,20 @@ package body Ghdldrv is end case; end if; + -- Add -fpic for gcc/llvm. + if not Flag_Postprocess + and then Default_Pathes.Default_Pie + then + case Backend is + when Backend_Gcc + | Backend_Llvm => + P := P + 1; + Args (P) := Dash_Fpic; + when Backend_Mcode => + null; + end case; + end if; + -- Object file (or assembly file). Args (P + 1) := Dash_o; if Flag_Postprocess then @@ -409,7 +426,7 @@ package body Ghdldrv is raise Option_Error; end Tool_Not_Found; - -- Set the compiler command according to the configuration (and swicthes). + -- Set the compiler command according to the configuration (and switches). procedure Set_Tools_Name is begin -- Set tools name. @@ -430,6 +447,12 @@ package body Ghdldrv is if Post_Processor_Cmd = null then Post_Processor_Cmd := new String'(Default_Pathes.Post_Processor); end if; + if Assembler_Cmd = null then + Assembler_Cmd := new String'("as"); + end if; + if Linker_Cmd = null then + Linker_Cmd := new String'("gcc"); + end if; end Set_Tools_Name; function Locate_Exec_Tool (Toolname : String) return String_Access is @@ -489,9 +512,9 @@ package body Ghdldrv is -- Assembler. case Backend is when Backend_Gcc => - Assembler_Path := Locate_Exec_On_Path (Assembler_Cmd); + Assembler_Path := Locate_Exec_On_Path (Assembler_Cmd.all); if Assembler_Path = null and not Flag_Asm then - Tool_Not_Found (Assembler_Cmd); + Tool_Not_Found (Assembler_Cmd.all); end if; when Backend_Llvm | Backend_Mcode => @@ -499,9 +522,9 @@ package body Ghdldrv is end case; -- Linker. - Linker_Path := Locate_Exec_On_Path (Linker_Cmd); + Linker_Path := Locate_Exec_On_Path (Linker_Cmd.all); if Linker_Path = null then - Tool_Not_Found (Linker_Cmd); + Tool_Not_Found (Linker_Cmd.all); end if; end Locate_Tools; @@ -570,6 +593,12 @@ package body Ghdldrv is elsif Opt'Length > 8 and then Opt (1 .. 8) = "--GHDL1=" then Compiler_Cmd := new String'(Opt (9 .. Opt'Last)); Res := Option_Ok; + elsif Opt'Length > 5 and then Opt (1 .. 5) = "--AS=" then + Assembler_Cmd := new String'(Opt (6 .. Opt'Last)); + Res := Option_Ok; + elsif Opt'Length > 7 and then Opt (1 .. 7) = "--LINK=" then + Linker_Cmd := new String'(Opt (8 .. Opt'Last)); + Res := Option_Ok; elsif Opt = "-S" then Flag_Asm := True; Res := Option_Ok; @@ -649,6 +678,8 @@ package body Ghdldrv is Disp_Long_Help (Command_Lib (Cmd)); Put_Line (" -v Be verbose"); Put_Line (" --GHDL1=PATH Set the path of the ghdl1 compiler"); + Put_Line (" --AS=as Use as for the assembler"); + Put_Line (" --LINK=gcc Use gcc for the linker driver"); Put_Line (" -S Do not assemble"); Put_Line (" -o FILE Set the name of the output file"); -- Put_Line (" -m32 Generate 32bit code on 64bit machines"); @@ -705,13 +736,13 @@ package body Ghdldrv is case Backend is when Backend_Gcc => Put ("assembler command: "); - Put_Line (Assembler_Cmd); + Put_Line (Assembler_Cmd.all); when Backend_Llvm | Backend_Mcode => null; end case; Put ("linker command: "); - Put_Line (Linker_Cmd); + Put_Line (Linker_Cmd.all); Put_Line ("default lib prefix: " & Default_Pathes.Lib_Prefix); New_Line; -- cgit v1.2.3