[ELF] - -pie/--pic-executable option implemented

-pie
--pic-executable

Create a position independent executable.  This is currently only
 supported on ELF platforms.  Position independent executables are
 similar to shared libraries in that they are relocated by the
 dynamic linker to the virtual address the OS chooses for them
 (which can vary between invocations).  Like normal dynamically
 linked executables they can be executed and symbols defined in the
 executable cannot be overridden by shared libraries.

Differential revision: http://reviews.llvm.org/D18183

llvm-svn: 263693
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index fa12154..eff2e8d 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -144,6 +144,9 @@
   if (Config->EMachine == EM_AMDGPU && !Config->Entry.empty())
     error("-e option is not valid for AMDGPU.");
 
+  if (Config->Pie && Config->Shared)
+    error("-shared and -pie may not be used together");
+
   if (!Config->Relocatable)
     return;
 
@@ -153,6 +156,8 @@
     error("-r and --gc-sections may not be used together");
   if (Config->ICF)
     error("-r and --icf may not be used together");
+  if (Config->Pie)
+    error("-r and -pie may not be used together");
 }
 
 static StringRef
@@ -238,6 +243,7 @@
   Config->ICF = Args.hasArg(OPT_icf);
   Config->NoUndefined = Args.hasArg(OPT_no_undefined);
   Config->NoinhibitExec = Args.hasArg(OPT_noinhibit_exec);
+  Config->Pie = Args.hasArg(OPT_pie);
   Config->PrintGcSections = Args.hasArg(OPT_print_gc_sections);
   Config->Relocatable = Args.hasArg(OPT_relocatable);
   Config->SaveTemps = Args.hasArg(OPT_save_temps);
@@ -261,6 +267,8 @@
   Config->ZOrigin = hasZOption(Args, "origin");
   Config->ZRelro = !hasZOption(Args, "norelro");
 
+  Config->Pic = Config->Pie || Config->Shared;
+
   if (Config->Relocatable)
     Config->StripAll = false;