bfd/
authorJakub Jelinek <jakub@redhat.com>
Fri, 30 May 2003 15:50:12 +0000 (15:50 +0000)
committerJakub Jelinek <jakub@redhat.com>
Fri, 30 May 2003 15:50:12 +0000 (15:50 +0000)
* elflink.h (elf_link_add_object_symbols): Use !info->executable
instead of info->shared where appropriate.
(bfd_elfNN_size_dynamic_sections, elf_link_output_extsym): Likewise.
* elflink.c (_bfd_elf_create_got_section): Likewise.
(_bfd_elf_link_create_dynamic_sections): Likewise.
(_bfd_elf_link_assign_sym_version): Likewise.
* elf32-i386.c (elf_i386_size_dynamic_sections): Create .interp section
and DT_DEBUG dynamic tag even for position independent executables.
* elf32-ppc.c (ppc_elf_size_dynamic_sections): Likewise.
* elf32-s390.c (elf_s390_size_dynamic_sections: Likewise.
* elf64-ppc.c (ppc64_elf_size_dynamic_sections: Likewise.
* elf64-s390.c (elf_s390_size_dynamic_sections: Likewise.
* elf64-x86-64.c (elf64_x86_64_size_dynamic_sections: Likewise.
* elfxx-ia64.c (elfNN_ia64_size_dynamic_sections: Likewise.
* elf32-sparc.c (elf32_sparc_size_dynamic_sections: Likewise.
* elf64-alpha.c (elf64_alpha_size_dynamic_sections: Likewise.
* elf64-sparc.c (sparc64_elf_size_dynamic_sections: Likewise.
include/
* bfdlink.h (struct bfd_link_info): Add pie and executable
bits.
ld/
* lexsup.c (OPTION_PIE): Define.
(ld_options): Add -pie and --pic-executable options.
(parse_args): Handle OPTION_PIE.
* ldmain.c (main): Initialize link_info.pie and
link_info.executable.
* genscripts.sh: Generate PIE scripts.
* ld.texinfo: Document -pie and --pic-executable options.
* emultempl/elf32.em (gld${EMULATION_NAME}_after_open):
(gld${EMULATION_NAME}_place_orphan): Likewise.
(gld${EMULATION_NAME}_get_script): Include PIE scripts.
* scripttempl/elf.sc: In PIE scripts set . the same way as in
shared scripts.
* emulparams/elf_i386.sh (GENERATE_PIE_SCRIPT): Set to yes.
* emulparams/elf64_ia64.sh (GENERATE_PIE_SCRIPT): Likewise.
* emulparams/elf32ppc.sh (GENERATE_PIE_SCRIPT): Likewise.
* emulparams/elf64ppc.sh (GENERATE_PIE_SCRIPT): Likewise.
* emulparams/elf_x86_64.sh (GENERATE_PIE_SCRIPT): Likewise.
* emulparams/elf_s390.sh (GENERATE_PIE_SCRIPT): Likewise.
* emulparams/elf32_sparc.sh (GENERATE_PIE_SCRIPT): Likewise.
* emulparams/elf64_sparc.sh (GENERATE_PIE_SCRIPT): Likewise.
* emulparams/elf64alpha.sh (GENERATE_PIE_SCRIPT): Likewise.
* emulparams/elf64_s390.sh (GENERATE_PIE_SCRIPT): Likewise.
* emulparams/elf_i386.sh (GENERATE_PIE_SCRIPT): Likewise.

32 files changed:
bfd/ChangeLog
bfd/elf32-i386.c
bfd/elf32-ppc.c
bfd/elf32-s390.c
bfd/elf32-sparc.c
bfd/elf64-alpha.c
bfd/elf64-ppc.c
bfd/elf64-s390.c
bfd/elf64-sparc.c
bfd/elf64-x86-64.c
bfd/elflink.c
bfd/elflink.h
bfd/elfxx-ia64.c
include/ChangeLog
include/bfdlink.h
ld/ChangeLog
ld/emulparams/elf32_sparc.sh
ld/emulparams/elf32ppc.sh
ld/emulparams/elf64_ia64.sh
ld/emulparams/elf64_s390.sh
ld/emulparams/elf64_sparc.sh
ld/emulparams/elf64alpha.sh
ld/emulparams/elf64ppc.sh
ld/emulparams/elf_i386.sh
ld/emulparams/elf_s390.sh
ld/emulparams/elf_x86_64.sh
ld/emultempl/elf32.em
ld/genscripts.sh
ld/ld.texinfo
ld/ldmain.c
ld/lexsup.c
ld/scripttempl/elf.sc

index aa1aeae0da8f4f58a80261059976e4058072c017..8eb1bfe5e30b536b65c0e63e651c573d3be006cd 100644 (file)
@@ -1,3 +1,24 @@
+2003-05-30  Ulrich Drepper  <drepper@redhat.com>
+           Jakub Jelinek  <jakub@redhat.com>
+
+       * elflink.h (elf_link_add_object_symbols): Use !info->executable
+       instead of info->shared where appropriate.
+       (bfd_elfNN_size_dynamic_sections, elf_link_output_extsym): Likewise.
+       * elflink.c (_bfd_elf_create_got_section): Likewise.
+       (_bfd_elf_link_create_dynamic_sections): Likewise.
+       (_bfd_elf_link_assign_sym_version): Likewise.
+       * elf32-i386.c (elf_i386_size_dynamic_sections): Create .interp section
+       and DT_DEBUG dynamic tag even for position independent executables.
+       * elf32-ppc.c (ppc_elf_size_dynamic_sections): Likewise.
+       * elf32-s390.c (elf_s390_size_dynamic_sections: Likewise.
+       * elf64-ppc.c (ppc64_elf_size_dynamic_sections: Likewise.
+       * elf64-s390.c (elf_s390_size_dynamic_sections: Likewise.
+       * elf64-x86-64.c (elf64_x86_64_size_dynamic_sections: Likewise.
+       * elfxx-ia64.c (elfNN_ia64_size_dynamic_sections: Likewise.
+       * elf32-sparc.c (elf32_sparc_size_dynamic_sections: Likewise.
+       * elf64-alpha.c (elf64_alpha_size_dynamic_sections: Likewise.
+       * elf64-sparc.c (sparc64_elf_size_dynamic_sections: Likewise.
+
 2003-05-30  Kris Warkentin <kewarken@qnx.com>
 
        * elf.c (elfcore_grok_nto_status): Only set lwpid for the active or
index cfcb7b34c195e7501f5dfec0039ea6be850ded2b..cd3dc9acbe7e9e005c3353ae84d109f367095d3a 100644 (file)
@@ -1797,7 +1797,7 @@ elf_i386_size_dynamic_sections (output_bfd, info)
   if (htab->elf.dynamic_sections_created)
     {
       /* Set the contents of the .interp section to the interpreter.  */
-      if (! info->shared)
+      if (info->executable)
        {
          s = bfd_get_section_by_name (dynobj, ".interp");
          if (s == NULL)
@@ -1963,7 +1963,7 @@ elf_i386_size_dynamic_sections (output_bfd, info)
 #define add_dynamic_entry(TAG, VAL) \
   bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
 
-      if (! info->shared)
+      if (info->executable)
        {
          if (!add_dynamic_entry (DT_DEBUG, 0))
            return FALSE;
index 1e1ab8cce3b0cfd6877e4440db542f5db2c32bdd..8c0e4d5e8f15a0c80c48c14b1becb25825aab9a5 100644 (file)
@@ -2920,7 +2920,7 @@ ppc_elf_size_dynamic_sections (output_bfd, info)
   if (elf_hash_table (info)->dynamic_sections_created)
     {
       /* Set the contents of the .interp section to the interpreter.  */
-      if (! info->shared)
+      if (info->executable)
        {
          s = bfd_get_section_by_name (htab->elf.dynobj, ".interp");
          BFD_ASSERT (s != NULL);
@@ -3102,7 +3102,7 @@ ppc_elf_size_dynamic_sections (output_bfd, info)
 #define add_dynamic_entry(TAG, VAL) \
   bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
 
-      if (!info->shared)
+      if (info->executable)
        {
          if (!add_dynamic_entry (DT_DEBUG, 0))
            return FALSE;
index 9475f60a669b8db5fd76b855ede46aee6e6802f6..97be1dbd013052ed08ae5b0e4b7d0d9026f25760 100644 (file)
@@ -1927,7 +1927,7 @@ elf_s390_size_dynamic_sections (output_bfd, info)
   if (htab->elf.dynamic_sections_created)
     {
       /* Set the contents of the .interp section to the interpreter.  */
-      if (! info->shared)
+      if (info->executable)
        {
          s = bfd_get_section_by_name (dynobj, ".interp");
          if (s == NULL)
@@ -2085,7 +2085,7 @@ elf_s390_size_dynamic_sections (output_bfd, info)
 #define add_dynamic_entry(TAG, VAL) \
   bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
 
-      if (! info->shared)
+      if (info->executable)
        {
          if (!add_dynamic_entry (DT_DEBUG, 0))
            return FALSE;
index e2c65448150d931c37f6b535a41e27cefa6a2996..5f1bec589c7c2c2eb684f51d4300c59aae7eb43a 100644 (file)
@@ -1820,7 +1820,7 @@ elf32_sparc_size_dynamic_sections (output_bfd, info)
   if (elf_hash_table (info)->dynamic_sections_created)
     {
       /* Set the contents of the .interp section to the interpreter.  */
-      if (! info->shared)
+      if (info->executable)
        {
          s = bfd_get_section_by_name (dynobj, ".interp");
          BFD_ASSERT (s != NULL);
@@ -1997,7 +1997,7 @@ elf32_sparc_size_dynamic_sections (output_bfd, info)
 #define add_dynamic_entry(TAG, VAL) \
   bfd_elf32_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
 
-      if (!info->shared)
+      if (info->executable)
        {
          if (!add_dynamic_entry (DT_DEBUG, 0))
            return FALSE;
index 9ce3bf3b56af1764ef43c87603fa3edf6d79e15a..58ab6ba7a5d739f5bdbed99681c2b7b53a4504df 100644 (file)
@@ -4090,7 +4090,7 @@ elf64_alpha_size_dynamic_sections (output_bfd, info)
   if (elf_hash_table (info)->dynamic_sections_created)
     {
       /* Set the contents of the .interp section to the interpreter.  */
-      if (!info->shared)
+      if (info->executable)
        {
          s = bfd_get_section_by_name (dynobj, ".interp");
          BFD_ASSERT (s != NULL);
@@ -4176,7 +4176,7 @@ elf64_alpha_size_dynamic_sections (output_bfd, info)
 #define add_dynamic_entry(TAG, VAL) \
   bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
 
-      if (!info->shared)
+      if (info->executable)
        {
          if (!add_dynamic_entry (DT_DEBUG, 0))
            return FALSE;
index f32d261fe6e372f2c73f451f44c22383c1d6c990..98af624baf5c2aaddabaaa9452c83778a152edb4 100644 (file)
@@ -5737,7 +5737,7 @@ ppc64_elf_size_dynamic_sections (output_bfd, info)
   if (htab->elf.dynamic_sections_created)
     {
       /* Set the contents of the .interp section to the interpreter.  */
-      if (! info->shared)
+      if (info->executable)
        {
          s = bfd_get_section_by_name (dynobj, ".interp");
          if (s == NULL)
@@ -5936,7 +5936,7 @@ ppc64_elf_size_dynamic_sections (output_bfd, info)
 #define add_dynamic_entry(TAG, VAL) \
   bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
 
-      if (!info->shared)
+      if (info->executable)
        {
          if (!add_dynamic_entry (DT_DEBUG, 0))
            return FALSE;
index 98555f269bf4fff64cee5337587ed17dc8f7d850..b5d724a5582fad28eeb7a50c493f218dc7477313 100644 (file)
@@ -1898,7 +1898,7 @@ elf_s390_size_dynamic_sections (output_bfd, info)
   if (htab->elf.dynamic_sections_created)
     {
       /* Set the contents of the .interp section to the interpreter.  */
-      if (! info->shared)
+      if (info->executable)
        {
          s = bfd_get_section_by_name (dynobj, ".interp");
          if (s == NULL)
@@ -2056,7 +2056,7 @@ elf_s390_size_dynamic_sections (output_bfd, info)
 #define add_dynamic_entry(TAG, VAL) \
   bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
 
-      if (! info->shared)
+      if (info->executable)
        {
          if (!add_dynamic_entry (DT_DEBUG, 0))
            return FALSE;
index d7ad1b725de77f3d83cd209007aa03fdb8325532..d25b429337a5a36daa6872db61a44cfae665b7c8 100644 (file)
@@ -1781,7 +1781,7 @@ sparc64_elf_size_dynamic_sections (output_bfd, info)
   if (elf_hash_table (info)->dynamic_sections_created)
     {
       /* Set the contents of the .interp section to the interpreter.  */
-      if (! info->shared)
+      if (info->executable)
        {
          s = bfd_get_section_by_name (dynobj, ".interp");
          BFD_ASSERT (s != NULL);
@@ -1880,7 +1880,7 @@ sparc64_elf_size_dynamic_sections (output_bfd, info)
       struct elf_strtab_hash *dynstr;
       struct elf_link_hash_table *eht = elf_hash_table (info);
 
-      if (!info->shared)
+      if (info->executable)
        {
          if (!add_dynamic_entry (DT_DEBUG, 0))
            return FALSE;
index c0ce57d708dc38985d685f4522e773177e3088cd..b39cdcd819c17d706e67dcca3e48090966dec3e7 100644 (file)
@@ -1618,7 +1618,7 @@ elf64_x86_64_size_dynamic_sections (output_bfd, info)
   if (htab->elf.dynamic_sections_created)
     {
       /* Set the contents of the .interp section to the interpreter.  */
-      if (! info->shared)
+      if (info->executable)
        {
          s = bfd_get_section_by_name (dynobj, ".interp");
          if (s == NULL)
@@ -1779,7 +1779,7 @@ elf64_x86_64_size_dynamic_sections (output_bfd, info)
 #define add_dynamic_entry(TAG, VAL) \
   bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL))
 
-      if (! info->shared)
+      if (info->executable)
        {
          if (!add_dynamic_entry (DT_DEBUG, 0))
            return FALSE;
index cc311863e1aaaaee1a1a648e2f50e52a2cd66ac3..d6f6d705eadf3c5305be5889bf4334ed1d534561 100644 (file)
@@ -94,7 +94,7 @@ _bfd_elf_create_got_section (abfd, info)
       h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
       h->type = STT_OBJECT;
 
-      if (info->shared
+      if (! info->executable
          && ! _bfd_elf_link_record_dynamic_symbol (info, h))
        return FALSE;
 
@@ -144,7 +144,7 @@ _bfd_elf_link_create_dynamic_sections (abfd, info)
 
   /* A dynamically linked executable has a .interp section, but a
      shared library does not.  */
-  if (! info->shared)
+  if (info->executable)
     {
       s = bfd_make_section (abfd, ".interp");
       if (s == NULL
@@ -227,7 +227,7 @@ _bfd_elf_link_create_dynamic_sections (abfd, info)
   h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
   h->type = STT_OBJECT;
 
-  if (info->shared
+  if (! info->executable
       && ! _bfd_elf_link_record_dynamic_symbol (info, h))
     return FALSE;
 
@@ -295,7 +295,7 @@ _bfd_elf_create_dynamic_sections (abfd, info)
       h->elf_link_hash_flags |= ELF_LINK_HASH_DEF_REGULAR;
       h->type = STT_OBJECT;
 
-      if (info->shared
+      if (! info->executable
          && ! _bfd_elf_link_record_dynamic_symbol (info, h))
        return FALSE;
     }
@@ -1760,7 +1760,7 @@ _bfd_elf_link_assign_sym_version (h, data)
 
       /* If we are building an application, we need to create a
         version node for this version.  */
-      if (t == NULL && ! info->shared)
+      if (t == NULL && info->executable)
        {
          struct bfd_elf_version_tree **pp;
          int version_index;
index 7b32491d945a6b1ade7a91ad1c43af870f8e548f..e7019f3761ea9427e7229e7f242cf82618475c3f 100644 (file)
@@ -474,7 +474,7 @@ elf_link_add_object_symbols (abfd, info)
      .gnu.warning.SYMBOL are treated as warning symbols for the given
      symbol.  This differs from .gnu.warning sections, which generate
      warnings when they are included in an output file.  */
-  if (! info->shared)
+  if (info->executable)
     {
       asection *s;
 
@@ -1321,7 +1321,7 @@ elf_link_add_object_symbols (abfd, info)
                }
              else
                new_flag = ELF_LINK_HASH_DEF_REGULAR;
-             if (info->shared
+             if (! info->executable
                  || (old_flags & (ELF_LINK_HASH_DEF_DYNAMIC
                                   | ELF_LINK_HASH_REF_DYNAMIC)) != 0)
                dynsym = TRUE;
@@ -2174,7 +2174,7 @@ NAME(bfd_elf,size_dynamic_sections) (output_bfd, soname, rpath,
       if (bfd_get_section_by_name (output_bfd, ".preinit_array") != NULL)
        {
          /* DT_PREINIT_ARRAY is not allowed in shared library.  */
-         if (info->shared)
+         if (! info->executable)
            {
              bfd *sub;
              asection *o;
@@ -2440,7 +2440,7 @@ NAME(bfd_elf,size_dynamic_sections) (output_bfd, soname, rpath,
 
       if (info->flags_1)
        {
-         if (! info->shared)
+         if (info->executable)
            info->flags_1 &= ~ (DF_1_INITFIRST
                                | DF_1_NODELETE
                                | DF_1_NOOPEN);
@@ -4417,7 +4417,8 @@ elf_link_output_extsym (h, data)
      referenced by regular files, because we will already have issued
      warnings for them.  */
   if (! finfo->info->relocateable
-      && (! finfo->info->shared || ! finfo->info->allow_shlib_undefined)
+      && (finfo->info->executable
+         || ! finfo->info->allow_shlib_undefined)
       && h->root.type == bfd_link_hash_undefined
       && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) != 0
       && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_REGULAR) == 0
index ab2ff21c887cda9638a1e383f2b63ffba50653de..37fc968f53b1434c7282deaaa0a510ebf6e2ea33 100644 (file)
@@ -2903,7 +2903,7 @@ elfNN_ia64_size_dynamic_sections (output_bfd, info)
 
   /* Set the contents of the .interp section to the interpreter.  */
   if (ia64_info->root.dynamic_sections_created
-      && !info->shared)
+      && info->executable)
     {
       sec = bfd_get_section_by_name (dynobj, ".interp");
       BFD_ASSERT (sec != NULL);
@@ -3078,7 +3078,7 @@ elfNN_ia64_size_dynamic_sections (output_bfd, info)
         later (in finish_dynamic_sections) but we must add the entries now
         so that we get the correct size for the .dynamic section.  */
 
-      if (!info->shared)
+      if (info->executable)
        {
          /* The DT_DEBUG entry is filled in by the dynamic linker and used
             by the debugger.  */
index 8dfa46f77c96cbf634f1587fd2679f0ce0614488..41e67bc3307c3c0a8c7d1997699061aa5a282326 100644 (file)
@@ -1,3 +1,9 @@
+2003-05-30  Ulrich Drepper  <drepper@redhat.com>
+           Jakub Jelinek  <jakub@redhat.com>
+
+       * bfdlink.h (struct bfd_link_info): Add pie and executable
+       bits.
+
 2003-05-21  Nick Clifton  <nickc@redhat.com>
 
        * bfdlink.h (struct bfd_link_hash_table): Fix typo in comment.
index 89d916ee83b3d4aa4f5153a729637a16841781ac..61fcf96f4091b2b103e420645af8c96590b9eb2e 100644 (file)
@@ -291,6 +291,12 @@ struct bfd_link_info
   /* TRUE if relaxation is being finalized.  */
   unsigned int relax_finalizing: 1;
 
+  /* TRUE if generating a position independent executable.  */
+  unsigned int pie: 1;
+
+  /* TRUE if generating an executable, position independent or not.  */
+  unsigned int executable : 1;
+
   /* Which symbols to strip.  */
   enum bfd_link_strip strip;
 
index 52620acd460f97ee0a696ef5714f0ae8e90c44f4..bfd7846a3b3027347ac10be10ed7b965b286a91f 100644 (file)
@@ -1,3 +1,30 @@
+2003-05-30  Ulrich Drepper  <drepper@redhat.com>
+           Jakub Jelinek  <jakub@redhat.com>
+
+       * lexsup.c (OPTION_PIE): Define.
+       (ld_options): Add -pie and --pic-executable options.
+       (parse_args): Handle OPTION_PIE.
+       * ldmain.c (main): Initialize link_info.pie and
+       link_info.executable.
+       * genscripts.sh: Generate PIE scripts.
+       * ld.texinfo: Document -pie and --pic-executable options.
+       * emultempl/elf32.em (gld${EMULATION_NAME}_after_open):
+       (gld${EMULATION_NAME}_place_orphan): Likewise.
+       (gld${EMULATION_NAME}_get_script): Include PIE scripts.
+       * scripttempl/elf.sc: In PIE scripts set . the same way as in
+       shared scripts.
+       * emulparams/elf_i386.sh (GENERATE_PIE_SCRIPT): Set to yes.
+       * emulparams/elf64_ia64.sh (GENERATE_PIE_SCRIPT): Likewise.
+       * emulparams/elf32ppc.sh (GENERATE_PIE_SCRIPT): Likewise.
+       * emulparams/elf64ppc.sh (GENERATE_PIE_SCRIPT): Likewise.
+       * emulparams/elf_x86_64.sh (GENERATE_PIE_SCRIPT): Likewise.
+       * emulparams/elf_s390.sh (GENERATE_PIE_SCRIPT): Likewise.
+       * emulparams/elf32_sparc.sh (GENERATE_PIE_SCRIPT): Likewise.
+       * emulparams/elf64_sparc.sh (GENERATE_PIE_SCRIPT): Likewise.
+       * emulparams/elf64alpha.sh (GENERATE_PIE_SCRIPT): Likewise.
+       * emulparams/elf64_s390.sh (GENERATE_PIE_SCRIPT): Likewise.
+       * emulparams/elf_i386.sh (GENERATE_PIE_SCRIPT): Likewise.
+
 2003-05-30  H.J. Lu <hongjiu.lu@intel.com>
 
        * genscripts.sh: Create tmpdir/libpath.exp.
index 15a837df28c509ba2fb82c31ce8c25629a4e6731..af23252949ff7097ba2c8ab14d30dd9cd7a9296b 100644 (file)
@@ -10,4 +10,5 @@ MACHINE=
 TEMPLATE_NAME=elf32
 DATA_PLT=
 GENERATE_SHLIB_SCRIPT=yes
+GENERATE_PIE_SCRIPT=yes
 NO_SMALL_DATA=yes
index d2d704135a54f9467bc8b8d82224827fe6edde9e..ea05454d6d9377a8389485d1e5eadf51c7e3381b 100644 (file)
@@ -4,6 +4,7 @@
 TEMPLATE_NAME=elf32
 EXTRA_EM_FILE=ppc32elf
 GENERATE_SHLIB_SCRIPT=yes
+GENERATE_PIE_SCRIPT=yes
 SCRIPT_NAME=elf
 OUTPUT_FORMAT="elf32-powerpc"
 TEXT_START_ADDR=0x01800000
index 817c50adad5a8ac32462429f6950017d2ce7a03d..85ffe61a8bd2df7b68e861daa81b1bf0bf68a874 100644 (file)
@@ -16,6 +16,7 @@ fi
 TEXT_START_ADDR="0x4000000000000000"
 DATA_ADDR="0x6000000000000000 + (. & (${MAXPAGESIZE} - 1))"
 GENERATE_SHLIB_SCRIPT=yes
+GENERATE_PIE_SCRIPT=yes
 NOP=0x00300000010070000002000001000400  # a bundle full of nops
 OTHER_GOT_SECTIONS="
   .IA_64.pltoff ${RELOCATING-0} : { *(.IA_64.pltoff) }"
index e441b8ac4dba08a14ad1751a2bb7e7f42a226a6d..233eb98a16c39ec8abea1294cb482d0bdb0cb840 100644 (file)
@@ -9,6 +9,7 @@ MACHINE=
 NOP=0x07070707
 TEMPLATE_NAME=elf32
 GENERATE_SHLIB_SCRIPT=yes 
+GENERATE_PIE_SCRIPT=yes
 
 # Treat a host that matches the target with the possible exception of "x"
 # in the name as if it were native.
index ab3eec0ec60a6a3a439154e17d90610243034f2b..0c0f5d89e3d3cdf6edb5d2655df14007b5267b84 100644 (file)
@@ -8,6 +8,7 @@ ARCH="sparc:v9"
 MACHINE=
 DATA_PLT=
 GENERATE_SHLIB_SCRIPT=yes
+GENERATE_PIE_SCRIPT=yes
 NOP=0x01000000
 NO_SMALL_DATA=yes
 
index 2d16e9caba60eb0bc173cf91e1fe782f5659e5ae..093c8dfd8e1b7550b32e458bea985a9eb4468f56 100644 (file)
@@ -11,6 +11,7 @@ NONPAGED_TEXT_START_ADDR="0x120000000"
 ARCH=alpha
 MACHINE=
 GENERATE_SHLIB_SCRIPT=yes
+GENERATE_PIE_SCRIPT=yes
 DATA_PLT=
 # Note that the number is always big-endian, thus we have to 
 # reverse the digit string.
index 300b8d4b543fc61ab6ec6c08ceca784f4d7a81f8..236b26b5877e169aa6fc8755bf9176094cacec5f 100644 (file)
@@ -2,6 +2,7 @@ TEMPLATE_NAME=elf32
 EXTRA_EM_FILE=ppc64elf
 ELFSIZE=64
 GENERATE_SHLIB_SCRIPT=yes
+GENERATE_PIE_SCRIPT=yes
 SCRIPT_NAME=elf
 OUTPUT_FORMAT="elf64-powerpc"
 TEXT_START_ADDR=0x10000000
index f1b8522fe6f6a4c9b53a962f04604d07ce6f9340..2382286b9afa72d02246b6c4e53fffec65434233 100644 (file)
@@ -9,4 +9,5 @@ MACHINE=
 NOP=0x90909090
 TEMPLATE_NAME=elf32
 GENERATE_SHLIB_SCRIPT=yes
+GENERATE_PIE_SCRIPT=yes
 NO_SMALL_DATA=yes
index 2804aceeb9b9ccf1d0cc42b57b235d44f93b6cdd..3b51bb28c2804ea86519cc317c0be38bb0118f31 100644 (file)
@@ -8,3 +8,4 @@ MACHINE=
 NOP=0x07070707
 TEMPLATE_NAME=elf32
 GENERATE_SHLIB_SCRIPT=yes 
+GENERATE_PIE_SCRIPT=yes 
index 61e8f29f94fc22c7b20a0968d05086b52aea9213..6d3705828b2eb7337185658a7d09bb41b5b7c22f 100644 (file)
@@ -10,6 +10,7 @@ MACHINE=
 NOP=0x90909090
 TEMPLATE_NAME=elf32
 GENERATE_SHLIB_SCRIPT=yes
+GENERATE_PIE_SCRIPT=yes
 NO_SMALL_DATA=yes
 
 if [ "x${host}" = "x${target}" ]; then
index 8d863ee240fa87b99c24f51660b6b85bdc73ecd1..11668fdb9b6d3e465884f73637dab09cde152de2 100644 (file)
@@ -643,7 +643,7 @@ gld${EMULATION_NAME}_after_open ()
   struct bfd_link_needed_list *needed, *l;
 
   /* We only need to worry about this when doing a final link.  */
-  if (link_info.relocateable || link_info.shared)
+  if (link_info.relocateable || !link_info.executable)
     return;
 
   /* Get the list of files which appear in DT_NEEDED entries in
@@ -1180,7 +1180,7 @@ gld${EMULATION_NAME}_place_orphan (file, s)
 
   /* If this is a final link, then always put .gnu.warning.SYMBOL
      sections into the .text section to get them out of the way.  */
-  if (! link_info.shared
+  if (link_info.executable
       && ! link_info.relocateable
       && strncmp (secname, ".gnu.warning.", sizeof ".gnu.warning." - 1) == 0
       && hold_text.os != NULL)
@@ -1474,6 +1474,14 @@ if cmp -s ldscripts/${EMULATION_NAME}.x ldscripts/${EMULATION_NAME}.xn; then : ;
 echo '  ; else if (!config.magic_demand_paged) return' >> e${EMULATION_NAME}.c
 sed $sc ldscripts/${EMULATION_NAME}.xn                 >> e${EMULATION_NAME}.c
 fi
+if test -n "$GENERATE_PIE_SCRIPT" ; then
+if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
+echo '  ; else if (link_info.pie && link_info.combreloc) return' >> e${EMULATION_NAME}.c
+sed $sc ldscripts/${EMULATION_NAME}.xdc                >> e${EMULATION_NAME}.c
+fi
+echo '  ; else if (link_info.pie) return'             >> e${EMULATION_NAME}.c
+sed $sc ldscripts/${EMULATION_NAME}.xd                 >> e${EMULATION_NAME}.c
+fi
 if test -n "$GENERATE_SHLIB_SCRIPT" ; then
 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
 echo '  ; else if (link_info.shared && link_info.combreloc) return' >> e${EMULATION_NAME}.c
@@ -1511,6 +1519,18 @@ cat >>e${EMULATION_NAME}.c <<EOF
     return "ldscripts/${EMULATION_NAME}.xn";
 EOF
 fi
+if test -n "$GENERATE_PIE_SCRIPT" ; then
+if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
+cat >>e${EMULATION_NAME}.c <<EOF
+  else if (link_info.pie && link_info.combreloc)
+    return "ldscripts/${EMULATION_NAME}.xdc";
+EOF
+fi
+cat >>e${EMULATION_NAME}.c <<EOF
+  else if (link_info.pie)
+    return "ldscripts/${EMULATION_NAME}.xd";
+EOF
+fi
 if test -n "$GENERATE_SHLIB_SCRIPT" ; then
 if test -n "$GENERATE_COMBRELOC_SCRIPT" ; then
 cat >>e${EMULATION_NAME}.c <<EOF
index fdfc37dd89f59828f1745e246746a18327edf5bf..dce413692e739e979d6f986d78504cba784bb04e 100755 (executable)
@@ -236,6 +236,31 @@ if test -n "$GENERATE_SHLIB_SCRIPT"; then
     rm -f ${COMBRELOC}
     COMBRELOC=
   fi
+  unset CREATE_SHLIB
+fi
+
+if test -n "$GENERATE_PIE_SCRIPT"; then
+  LD_FLAG=pie
+  DATA_ALIGNMENT=${DATA_ALIGNMENT_s-${DATA_ALIGNMENT_}}
+  CREATE_PIE=" "
+  # Note that TEXT_START_ADDR is set to NONPAGED_TEXT_START_ADDR.
+  (
+    echo "/* Script for ld -pie: link position independent executable */"
+    . ${srcdir}/emulparams/${EMULATION_NAME}.sh
+    . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
+  ) | sed -e '/^ *$/d;s/[      ]*$//' > ldscripts/${EMULATION_NAME}.xd
+  if test -n "$GENERATE_COMBRELOC_SCRIPT"; then
+    LD_FLAG=cpie
+    DATA_ALIGNMENT=${DATA_ALIGNMENT_sc-${DATA_ALIGNMENT}}
+    COMBRELOC=ldscripts/${EMULATION_NAME}.xc.tmp
+    ( echo "/* Script for -pie -z combreloc: position independent executable, combine & sort relocs */"
+      . ${srcdir}/emulparams/${EMULATION_NAME}.sh
+      . ${srcdir}/scripttempl/${SCRIPT_NAME}.sc
+    ) | sed -e '/^ *$/d;s/[    ]*$//' > ldscripts/${EMULATION_NAME}.xdc
+    rm -f ${COMBRELOC}
+    COMBRELOC=
+  fi
+  unset CREATE_PIE
 fi
 
 case " $EMULATION_LIBPATH " in
index cfebf096e4282504a807538ebeefb48cbff937b2..d6e62203307695a8dd66a57362298b703c2124ef 100644 (file)
@@ -1209,6 +1209,18 @@ command @code{OUTPUT_FORMAT} can also specify the output format, but
 this option overrides it.  @xref{BFD}.
 @end ifclear
 
+@kindex -pie
+@kindex --pic-executable
+@item -pie
+@itemx --pic-executable
+@cindex position independent executables
+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 OS chooses for them (which can varry between invocations), like
+normal dynamically linked executables they can be executed and symbols
+defined in the executable cannot be overridden by shared libraries.
+
 @kindex -qmagic
 @item -qmagic
 This option is ignored for Linux compatibility.
index 91818e093d8b834fb2684810371b2fd5d3b99ac5..08a0ec4bc6b5a9ae25aab30da4a18e91c61ffb27 100644 (file)
@@ -291,6 +291,8 @@ main (argc, argv)
   link_info.emitrelocations = FALSE;
   link_info.task_link = FALSE;
   link_info.shared = FALSE;
+  link_info.pie = FALSE;
+  link_info.executable = FALSE;
   link_info.symbolic = FALSE;
   link_info.export_dynamic = FALSE;
   link_info.static_link = FALSE;
@@ -368,6 +370,9 @@ main (argc, argv)
        einfo (_("%P%F: -f may not be used without -shared\n"));
     }
 
+  if (! link_info.shared || link_info.pie)
+    link_info.executable = TRUE;
+
   /* Treat ld -r -s as ld -r -S -x (i.e., strip all local symbols).  I
      don't see how else this can be handled, since in this case we
      must preserve all externally visible symbols.  */
index b2f94f1d367bcc0511014cf2bbd7293d94c164e0..8c85807e32e5e408ef5ad71540ea112d68468ac8 100644 (file)
@@ -138,6 +138,7 @@ int parsing_defsym = 0;
 #define OPTION_NO_STRIP_DISCARDED      (OPTION_STRIP_DISCARDED + 1)
 #define OPTION_ACCEPT_UNKNOWN_INPUT_ARCH    (OPTION_NO_STRIP_DISCARDED + 1)
 #define OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH (OPTION_ACCEPT_UNKNOWN_INPUT_ARCH + 1)
+#define OPTION_PIE                     (OPTION_NO_ACCEPT_UNKNOWN_INPUT_ARCH + 1)
 
 /* The long options.  This structure is used for both the option
    parsing and the help text.  */
@@ -370,6 +371,10 @@ static const struct ld_option ld_options[] =
       '\0', NULL, N_("Create a shared library"), ONE_DASH },
   { {"Bshareable", no_argument, NULL, OPTION_SHARED }, /* FreeBSD.  */
       '\0', NULL, NULL, ONE_DASH },
+  { {"pie", no_argument, NULL, OPTION_PIE},
+      '\0', NULL, N_("Create a position independent executable"), ONE_DASH },
+  { {"pic-executable", no_argument, NULL, OPTION_PIE},
+      '\0', NULL, NULL, TWO_DASHES },
   { {"sort-common", no_argument, NULL, OPTION_SORT_COMMON},
       '\0', NULL, N_("Sort common symbols by size"), TWO_DASHES },
   { {"sort_common", no_argument, NULL, OPTION_SORT_COMMON},
@@ -959,6 +964,15 @@ parse_args (argc, argv)
          else
            einfo (_("%P%F: -shared not supported\n"));
          break;
+       case OPTION_PIE:
+         if (config.has_shared)
+           {
+             link_info.shared = TRUE;
+             link_info.pie = TRUE;
+           }
+         else
+           einfo (_("%P%F: -pie not supported\n"));
+         break;
        case 'h':               /* Used on Solaris.  */
        case OPTION_SONAME:
          command_line.soname = optarg;
index 42d7bda0f5185072abc59ed5f0664de0e3fe14d7..d4ffcd68183610932e72ab0ff21136af23bb35d3 100644 (file)
@@ -180,8 +180,9 @@ ${RELOCATING- /* For some reason, the Solaris linker makes bad executables
 SECTIONS
 {
   /* Read-only sections, merged into text segment: */
-  ${CREATE_SHLIB-${RELOCATING+. = ${TEXT_BASE_ADDRESS};}}
+  ${CREATE_SHLIB-${CREATE_PIE-${RELOCATING+. = ${TEXT_BASE_ADDRESS};}}}
   ${CREATE_SHLIB+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0} + SIZEOF_HEADERS;}}
+  ${CREATE_PIE+${RELOCATING+. = ${SHLIB_TEXT_START_ADDR:-0} + SIZEOF_HEADERS;}}
   ${CREATE_SHLIB-${INTERP}}
   ${INITIAL_READONLY_SECTIONS}
   ${TEXT_DYNAMIC+${DYNAMIC}}