PR27952, Disallow ET_DYN DF_1_PIE linker input
authorAlan Modra <amodra@gmail.com>
Fri, 11 Jun 2021 04:36:47 +0000 (14:06 +0930)
committerAlan Modra <amodra@gmail.com>
Fri, 11 Jun 2021 04:36:47 +0000 (14:06 +0930)
This patch adds a new elf_tdata flag, is_pie, set during the linker's
open_input_bfds processing.  The flag is then used to reject attempts
to link a PIE as if it were a shared library.

bfd/
PR 27952
* elf-bfd.h (struct elf_obj_tdata): Add is_pie.
* elflink.c (elf_link_add_object_symbols): Set is_pie.
ld/
PR 27952
* ldelf.c (ldelf_after_open): Error on input PIEs too.

bfd/ChangeLog
bfd/elf-bfd.h
bfd/elflink.c
ld/ChangeLog
ld/ldelf.c

index d1a92dc594d086812360b77f31c838e0ff89eec2..ad63f9cacfb3bd02df8904801b918807366405ae 100644 (file)
@@ -1,3 +1,9 @@
+2021-06-11  Alan Modra  <amodra@gmail.com>
+
+       PR 27952
+       * elf-bfd.h (struct elf_obj_tdata): Add is_pie.
+       * elflink.c (elf_link_add_object_symbols): Set is_pie.
+
 2021-06-09  Nick Clifton  <nickc@redhat.com>
 
        PR 27666
index 92b1722eacb5569dbf47c2eb855a795a5167d82f..8f985ab8917afbb13dfecdb3672f32a778f6a71c 100644 (file)
@@ -2080,6 +2080,9 @@ struct elf_obj_tdata
      symbols.  */
   unsigned int bad_symtab : 1;
 
+  /* Set if DT_FLAGS_1 has DF_1_PIE set.  */
+  unsigned int is_pie : 1;
+
   /* Information grabbed from an elf core file.  */
   struct core_elf_obj_tdata *core;
 
index 0e1871aaac989df653d4ecc837f81bbcdbf9db90..c9a6e78be798ba7677ca8c3d0a5f8cbe10c1c8f1 100644 (file)
@@ -4349,6 +4349,8 @@ elf_link_add_object_symbols (bfd *abfd, struct bfd_link_info *info)
                  unsigned int tagv = dyn.d_un.d_val;
                  audit = bfd_elf_string_from_elf_section (abfd, shlink, tagv);
                }
+             if (dyn.d_tag == DT_FLAGS_1)
+               elf_tdata (abfd)->is_pie = (dyn.d_un.d_val & DF_1_PIE) != 0;
            }
 
          free (dynbuf);
index 7ae7613dc7724f2b38c98175cebd81081f302c04..2d130b455ff96aeab6106d25add5dc3d29feda51 100644 (file)
@@ -1,3 +1,8 @@
+2021-06-11  Alan Modra  <amodra@gmail.com>
+
+       PR 27952
+       * ldelf.c (ldelf_after_open): Error on input PIEs too.
+
 2021-06-09  Nick Clifton  <nickc@redhat.com>
 
        PR 27666
index 4d4d9ca051796a07b8b67f8a658b86a5c9092670..21e655bb55cf3d0990ad4b9b17be526c578b54c3 100644 (file)
@@ -1048,7 +1048,9 @@ ldelf_after_open (int use_libpath, int native, int is_linux, int is_freebsd,
          && elf_tdata (abfd) != NULL
          && elf_tdata (abfd)->elf_header != NULL
          /* FIXME: Maybe check for other non-supportable types as well ?  */
-         && elf_tdata (abfd)->elf_header->e_type == ET_EXEC)
+         && (elf_tdata (abfd)->elf_header->e_type == ET_EXEC
+             || (elf_tdata (abfd)->elf_header->e_type == ET_DYN
+                 && elf_tdata (abfd)->is_pie)))
        einfo (_("%F%P: cannot use executable file '%pB' as input to a link\n"),
               abfd);
     }
This page took 0.037198 seconds and 4 git commands to generate.