[PATCH] ld: Add -no-pie

Fangrui Song maskray@google.com
Mon Jun 7 21:32:59 GMT 2021


gold has had this option for many years. Not having this option caused
some confusion to users.  The help message clarifies the default state.

ld/
    * ldlex.h (enum option_values): Add OPTION_NO_PIE.
    * lexsup.c (struct ld_options): Add -no-pie.
    (parse_args): Handle -Bsymbolic-non-weak-functions.
    * ld.texi: Document -Bsymbolic-non-weak-functions.
---
 ld/ld.texi  | 5 +++++
 ld/ldlex.h  | 1 +
 ld/lexsup.c | 5 +++++
 3 files changed, 11 insertions(+)

diff --git a/ld/ld.texi b/ld/ld.texi
index 29874688a73..5df04ee2069 100644
--- a/ld/ld.texi
+++ b/ld/ld.texi
@@ -2150,6 +2150,11 @@ 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.
 
+@kindex -no-pie
+@item -no-pie
+@cindex position dependent executables
+Create a position dependent executable.  This is the default.
+
 @kindex -qmagic
 @item -qmagic
 This option is ignored for Linux compatibility.
diff --git a/ld/ldlex.h b/ld/ldlex.h
index e0f0241d9cc..9e8bf5fb835 100644
--- a/ld/ldlex.h
+++ b/ld/ldlex.h
@@ -133,6 +133,7 @@ enum option_values
   OPTION_ACCEPT_UNKNOWN_INPUT_ARCH,
   OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH,
   OPTION_PIE,
+  OPTION_NO_PIE,
   OPTION_UNRESOLVED_SYMBOLS,
   OPTION_WARN_UNRESOLVED_SYMBOLS,
   OPTION_ERROR_UNRESOLVED_SYMBOLS,
diff --git a/ld/lexsup.c b/ld/lexsup.c
index dcb2d9d9ab3..00274c500d0 100644
--- a/ld/lexsup.c
+++ b/ld/lexsup.c
@@ -453,6 +453,8 @@ static const struct ld_option ld_options[] =
     '\0', NULL, N_("Create a position independent executable"), ONE_DASH },
   { {"pic-executable", no_argument, NULL, OPTION_PIE},
     '\0', NULL, NULL, TWO_DASHES },
+  { {"no-pie", no_argument, NULL, OPTION_NO_PIE},
+    '\0', NULL, N_("Create a position dependent executable (default)"), ONE_DASH },
   { {"sort-common", optional_argument, NULL, OPTION_SORT_COMMON},
     '\0', N_("[=ascending|descending]"),
     N_("Sort common symbols by alignment [in specified order]"),
@@ -1262,6 +1264,9 @@ parse_args (unsigned argc, char **argv)
 	  else
 	    einfo (_("%F%P: -shared not supported\n"));
 	  break;
+	case OPTION_NO_PIE:
+	  link_info.type = type_pde;
+	  break;
 	case OPTION_PIE:
 	  if (config.has_shared)
 	    {
-- 
2.32.0.rc1.229.g3e70b5a671-goog



More information about the Binutils mailing list