aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xconfigure13
-rw-r--r--doc/Invoking_GHDL.rst14
-rw-r--r--src/ghdldrv/default_pathes.ads.in1
-rw-r--r--src/ghdldrv/ghdldrv.adb51
-rw-r--r--src/ortho/llvm-nodebug/ortho_code_main35.adb6
-rw-r--r--src/ortho/llvm-nodebug/ortho_code_main39.adb6
-rw-r--r--src/ortho/llvm/ortho_code_main.adb6
7 files changed, 81 insertions, 16 deletions
diff --git a/configure b/configure
index fed905e2e..1f072e2f7 100755
--- a/configure
+++ b/configure
@@ -25,7 +25,7 @@ PIC_FLAGS=-fPIC
show_help=no
progname=$0
-subst_vars="CC GNATMAKE CFLAGS LDFLAGS build srcdir prefix backend libdirsuffix libdirreverse gcc_src_dir llvm_config llvm_be llvm_be_ver backtrace_lib build_mode EXEEXT SOEXT PIC_FLAGS"
+subst_vars="CC GNATMAKE CFLAGS LDFLAGS build srcdir prefix backend libdirsuffix libdirreverse gcc_src_dir llvm_config llvm_be llvm_be_ver backtrace_lib build_mode EXEEXT SOEXT PIC_FLAGS default_pie"
# Find srcdir
srcdir=`dirname $progname`
@@ -163,7 +163,7 @@ if test $backend = llvm; then
fi
if check_version 3.5 $llvm_version; then
llvm_be=llvm
- elif check_version 3.6 $llvm_version ||
+ elif check_version 3.6 $llvm_version ||
check_version 3.7 $llvm_version ||
check_version 3.8 $llvm_version;
then
@@ -195,6 +195,14 @@ case "$build" in
*) SOEXT=".so"; EXEEXT=""; PIC_FLAGS="-fPIC";;
esac
+# Check if gcc was configured with --enable-default-pie. In that case -fPIC
+# should be added.
+if gcc --version 2>&1 | grep -q enable-default-pie; then
+ default_pie="yes"
+else
+ default_pie="no"
+fi
+
# Generate config.status
rm -f config.status
{
@@ -266,6 +274,7 @@ sed -e "s%@COMPILER_GCC@%ghdl1-gcc$EXEEXT%" \
-e "s%@INSTALL_PREFIX@%$prefix%" \
-e "s%@LIB_PREFIX@%$libdirsuffix%" \
-e "s%@SOEXT@%$SOEXT%" \
+ -e "s%@default_pie@%$default_pie%" \
< $srcdir/src/ghdldrv/default_pathes.ads.in > default_pathes.ads
exit 0
diff --git a/doc/Invoking_GHDL.rst b/doc/Invoking_GHDL.rst
index e3d8f4153..fb121ed22 100644
--- a/doc/Invoking_GHDL.rst
+++ b/doc/Invoking_GHDL.rst
@@ -460,7 +460,19 @@ manual for details.
.. option:: --GHDL1=<COMMAND>
Use :samp:`COMMAND` as the command name for the compiler. If :samp:`COMMAND` is
- not a path, then it is search in the list of program directories.
+ not a path, then it is searched in the path.
+
+
+.. option:: --AS=<COMMAND>
+
+ Use :samp:`COMMAND` as the command name for the assembler. If :samp:`COMMAND` is
+ not a path, then it is searched in the path. The default is :samp:`as`.
+
+
+.. option:: --LINK=<COMMAND>
+
+ Use :samp:`COMMAND` as the linker driver. If :samp:`COMMAND` is
+ not a path, then it is searched in the path. The default is :samp:`gcc`.
.. option:: -v
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;
diff --git a/src/ortho/llvm-nodebug/ortho_code_main35.adb b/src/ortho/llvm-nodebug/ortho_code_main35.adb
index 61b836369..bb5458b49 100644
--- a/src/ortho/llvm-nodebug/ortho_code_main35.adb
+++ b/src/ortho/llvm-nodebug/ortho_code_main35.adb
@@ -62,7 +62,7 @@ procedure Ortho_Code_Main35 is
CPU : constant Cstring := Empty_Cstring;
Features : constant Cstring := Empty_Cstring;
- Reloc : constant RelocMode := RelocDefault;
+ Reloc : RelocMode := RelocDefault;
function To_String (C : Cstring) return String is
function Strlen (C : Cstring) return Natural;
@@ -117,6 +117,10 @@ begin
Optimization := CodeGenLevelDefault;
elsif Arg = "-O3" then
Optimization := CodeGenLevelAggressive;
+ elsif Arg = "-fpic" or Arg = "-fPIC" then
+ Reloc := RelocPIC;
+ elsif Arg = "-fno-pic" then
+ Reloc := RelocStatic;
elsif Arg = "--emit-llvm" then
Output_Kind := Output_Llvm;
elsif Arg = "--emit-bc" then
diff --git a/src/ortho/llvm-nodebug/ortho_code_main39.adb b/src/ortho/llvm-nodebug/ortho_code_main39.adb
index d1e84b6e3..11e52220e 100644
--- a/src/ortho/llvm-nodebug/ortho_code_main39.adb
+++ b/src/ortho/llvm-nodebug/ortho_code_main39.adb
@@ -62,7 +62,7 @@ procedure Ortho_Code_Main39 is
CPU : constant Cstring := Empty_Cstring;
Features : constant Cstring := Empty_Cstring;
- Reloc : constant RelocMode := RelocDefault;
+ Reloc : RelocMode := RelocDefault;
function To_String (C : Cstring) return String is
function Strlen (C : Cstring) return Natural;
@@ -117,6 +117,10 @@ begin
Optimization := CodeGenLevelDefault;
elsif Arg = "-O3" then
Optimization := CodeGenLevelAggressive;
+ elsif Arg = "-fpic" or Arg = "-fPIC" then
+ Reloc := RelocPIC;
+ elsif Arg = "-fno-pic" then
+ Reloc := RelocStatic;
elsif Arg = "--emit-llvm" then
Output_Kind := Output_Llvm;
elsif Arg = "--emit-bc" then
diff --git a/src/ortho/llvm/ortho_code_main.adb b/src/ortho/llvm/ortho_code_main.adb
index 5558a8bbe..56c869ad1 100644
--- a/src/ortho/llvm/ortho_code_main.adb
+++ b/src/ortho/llvm/ortho_code_main.adb
@@ -70,7 +70,7 @@ procedure Ortho_Code_Main is
CPU : constant Cstring := Empty_Cstring;
Features : constant Cstring := Empty_Cstring;
- Reloc : constant RelocMode := RelocDefault;
+ Reloc : RelocMode := RelocDefault;
function To_String (C : Cstring) return String is
function Strlen (C : Cstring) return Natural;
@@ -125,6 +125,10 @@ begin
Optimization := CodeGenLevelDefault;
elsif Arg = "-O3" then
Optimization := CodeGenLevelAggressive;
+ elsif Arg = "-fpic" or Arg = "-fPIC" then
+ Reloc := RelocPIC;
+ elsif Arg = "-fno-pic" then
+ Reloc := RelocStatic;
elsif Arg = "--emit-llvm" then
Output_Kind := Output_Llvm;
elsif Arg = "--emit-bc" then