This is the mail archive of the binutils-cvs@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Make import libraries relocatable objects


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=046734ff424bc5a4c1b6a69630d5bb31aa67165c

commit 046734ff424bc5a4c1b6a69630d5bb31aa67165c
Author: Thomas Preud'homme <thomas.preudhomme@arm.com>
Date:   Mon May 8 15:26:51 2017 +0100

    Make import libraries relocatable objects
    
    For ELF targets --out-implib currently generates an executable file
    (e_type is ET_EXEC) despite the file being expected to be linked against
    some other object file to make an executable later. It seems therefore
    more sensible to make the import library a relocatable object file
    (e_type set to ET_REL).
    
    Incidentally, as dicted by requirement 8 of
    "ARM v8-M Security Extensions: Requirements on Development Tools"
    (document ARM-ECM-0359818) version 1.0, import libraries generated when
    using --cmse-implib *must* be relocatable object file so this commit
    also adds an assert there in case the type of ELF import library is
    changed again in the future.
    
    2017-05-08  Thomas Preud'homme  <thomas.preudhomme@arm.com>
    
    bfd/
    	* elflink.c (elf_output_implib): Remove executable flag from import
    	library bfd.
    	* elf32-arm.c (elf32_arm_filter_implib_symbols): Assert that the import
    	library is a relocatable object file.
    
    ld/
    	* testsuite/ld-arm/arm-elf.exp
    	(Secure gateway import library generation): Check e_type field
    	of import library and executable produced.
    	* testsuite/ld-arm/cmse-implib.type: Expectations for e_type field.

Diff:
---
 bfd/ChangeLog                        | 7 +++++++
 bfd/elf32-arm.c                      | 4 ++++
 bfd/elflink.c                        | 3 ++-
 ld/ChangeLog                         | 7 +++++++
 ld/testsuite/ld-arm/arm-elf.exp      | 3 ++-
 ld/testsuite/ld-arm/cmse-implib.type | 9 +++++++++
 6 files changed, 31 insertions(+), 2 deletions(-)

diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 27ac8c3..8c7c021 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,10 @@
+2017-05-08  Thomas Preud'homme  <thomas.preudhomme@arm.com>
+
+	* elflink.c (elf_output_implib): Remove executable flag from import
+	library bfd.
+	* elf32-arm.c (elf32_arm_filter_implib_symbols): Assert that the import
+	library is a relocatable object file.
+
 2017-05-01  Senthil Kumar Selvaraj  <senthil_kumar.selvaraj@atmel.com>
 
 	PR ld/21404
diff --git a/bfd/elf32-arm.c b/bfd/elf32-arm.c
index 434649f..8dcaf45 100644
--- a/bfd/elf32-arm.c
+++ b/bfd/elf32-arm.c
@@ -17498,6 +17498,10 @@ elf32_arm_filter_implib_symbols (bfd *abfd ATTRIBUTE_UNUSED,
 {
   struct elf32_arm_link_hash_table *globals = elf32_arm_hash_table (info);
 
+  /* Requirement 8 of "ARM v8-M Security Extensions: Requirements on
+     Development Tools" (ARM-ECM-0359818) mandates Secure Gateway import
+     library to be a relocatable object file.  */
+  BFD_ASSERT (!(bfd_get_file_flags (info->out_implib_bfd) & EXEC_P));
   if (globals->cmse_implib)
     return elf32_arm_filter_cmse_symbols (abfd, info, syms, symcount);
   else
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 9acc069..ba50b68 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -11277,10 +11277,11 @@ elf_output_implib (bfd *abfd, struct bfd_link_info *info)
   if (!bfd_set_format (implib_bfd, bfd_object))
     return FALSE;
 
+  /* Use flag from executable but make it a relocatable object.  */
   flags = bfd_get_file_flags (abfd);
   flags &= ~HAS_RELOC;
   if (!bfd_set_start_address (implib_bfd, 0)
-      || !bfd_set_file_flags (implib_bfd, flags))
+      || !bfd_set_file_flags (implib_bfd, flags & ~EXEC_P))
     return FALSE;
 
   /* Copy architecture of output file to import library file.  */
diff --git a/ld/ChangeLog b/ld/ChangeLog
index 8318173..cd85a35 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,3 +1,10 @@
+2017-05-08  Thomas Preud'homme  <thomas.preudhomme@arm.com>
+
+	* testsuite/ld-arm/arm-elf.exp
+	(Secure gateway import library generation): Check e_type field
+	of import library and executable produced.
+	* testsuite/ld-arm/cmse-implib.type: Expectations for e_type field.
+
 2017-04-28  Senthil Kumar Selvaraj  <senthil_kumar.selvaraj@atmel.com>
 
 	PR ld/21404
diff --git a/ld/testsuite/ld-arm/arm-elf.exp b/ld/testsuite/ld-arm/arm-elf.exp
index 1a4d262..2e19332 100644
--- a/ld/testsuite/ld-arm/arm-elf.exp
+++ b/ld/testsuite/ld-arm/arm-elf.exp
@@ -685,7 +685,8 @@ set armeabitests_nonacl {
      "--section-start .gnu.sgstubs=0x20000 --out-implib=tmpdir/cmse-implib.lib --cmse-implib" ""
      "-march=armv8-m.base -mthumb --defsym VER=1"
      {cmse-implib.s}
-     {{readelf {-s tmpdir/cmse-implib.lib} cmse-implib.rd}}
+     {{readelf {-s tmpdir/cmse-implib.lib} cmse-implib.rd}
+      {readelf {-h tmpdir/cmse-implib.lib} cmse-implib.type}}
      "cmse-implib"}
     {"Input secure gateway import library"
      "--section-start .gnu.sgstubs=0x20000 --out-implib=tmpdir/cmse-new-implib.lib --in-implib=tmpdir/cmse-implib.lib --cmse-implib" ""
diff --git a/ld/testsuite/ld-arm/cmse-implib.type b/ld/testsuite/ld-arm/cmse-implib.type
new file mode 100644
index 0000000..7bb3bcc
--- /dev/null
+++ b/ld/testsuite/ld-arm/cmse-implib.type
@@ -0,0 +1,9 @@
+#...
+File: tmpdir/cmse-implib.lib
+#...
+[[:space:]]+Type:[[:space:]]+REL \(Relocatable file\)
+#...
+File: tmpdir/cmse-implib
+#...
+[[:space:]]+Type:[[:space:]]+EXEC \(Executable file\)
+#...


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]