]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Make the linker return an error status if it fails to merge ARM binaries with
authorTerry Guo <terry.guo@arm.com>
Tue, 16 Sep 2014 12:08:22 +0000 (13:08 +0100)
committerNick Clifton <nickc@redhat.com>
Tue, 16 Sep 2014 12:08:22 +0000 (13:08 +0100)
different architecture tags.  Add a test case to make sure that this works,
and update readelf so that it will not seg-fault when trying to display the
attributes of binaries with invalid architecture tags.

* elf32-arm.c (elf32_arm_merge_eabi_attributes): Return false if
failed to merge.

* ld-arm/attr-merge-arch-2.d: New test case.
* ld-arm/attr-merge-arch-2a.s: New test case source file.
* ld-arm/attr-merge-arch-2b.s: Likewise.
* ld-arm/arm-elf.exp: Run new test case.

* readelf.c (display_arm_attribute): Use unsigned int type for
tag, val and type variables.

bfd/ChangeLog
bfd/elf32-arm.c
binutils/ChangeLog
binutils/readelf.c
ld/testsuite/ChangeLog
ld/testsuite/ld-arm/arm-elf.exp
ld/testsuite/ld-arm/attr-merge-arch-2.d [new file with mode: 0644]
ld/testsuite/ld-arm/attr-merge-arch-2a.s [new file with mode: 0644]
ld/testsuite/ld-arm/attr-merge-arch-2b.s [new file with mode: 0644]

index fcfdeadee1f0e1f5f36981c1225e070dd1c164d2..7076ff46c227a74bc5605ab8fa0df68acd36df58 100644 (file)
@@ -1,3 +1,8 @@
+2014-09-16  Terry Guo  <terry.guo@arm.com>
+
+       * elf32-arm.c (elf32_arm_merge_eabi_attributes): Return false if
+       failed to merge.
+
 2014-09-16  Kuan-Lin Chen  <kuanlinchentw@gmail.com>
 
        * bfd-in2.h: Regenerate.
index 89d51c11b13f2081a789e2e987b0e48ee5eea3b8..08aa3f9e39617a7b4dbe701d25d8c4a6649b5924 100644 (file)
@@ -11778,7 +11778,9 @@ elf32_arm_merge_eabi_attributes (bfd *ibfd, bfd *obfd)
          {
            int secondary_compat = -1, secondary_compat_out = -1;
            unsigned int saved_out_attr = out_attr[i].i;
-           static const char *name_table[] = {
+           int arch_attr;
+           static const char *name_table[] =
+             {
                /* These aren't real CPU names, but we can't guess
                   that from the architecture version alone.  */
                "Pre v4",
@@ -11800,10 +11802,17 @@ elf32_arm_merge_eabi_attributes (bfd *ibfd, bfd *obfd)
            /* Merge Tag_CPU_arch and Tag_also_compatible_with.  */
            secondary_compat = get_secondary_compatible_arch (ibfd);
            secondary_compat_out = get_secondary_compatible_arch (obfd);
-           out_attr[i].i = tag_cpu_arch_combine (ibfd, out_attr[i].i,
-                                                 &secondary_compat_out,
-                                                 in_attr[i].i,
-                                                 secondary_compat);
+           arch_attr = tag_cpu_arch_combine (ibfd, out_attr[i].i,
+                                             &secondary_compat_out,
+                                             in_attr[i].i,
+                                             secondary_compat);
+
+           /* Return with error if failed to merge.  */
+           if (arch_attr == -1)
+             return FALSE;
+
+           out_attr[i].i = arch_attr;
+
            set_secondary_compatible_arch (obfd, secondary_compat_out);
 
            /* Merge Tag_CPU_name and Tag_CPU_raw_name.  */
index c55382edb7855f8dc6400707f6904400d104c074..223bf119b32b1a43b3d05278b308a061d0e1e319 100644 (file)
@@ -1,3 +1,8 @@
+2014-09-16  Nick Clifton  <nickc@redhat.com>
+
+       * readelf.c (display_arm_attribute): Use unsigned int type for
+       tag, val and type variables.
+
 2014-09-16  Kuan-Lin Chen  <kuanlinchentw@gmail.com>
 
        * readelf.c (decode_NDS32_machine_flags): Display ABI2 FP+.
index ef3a68dcb76284a397ed35e20a8f075c11f9e463..d9c12cc8da619bd53b4a6713fdb99f1e940d875e 100644 (file)
@@ -11548,10 +11548,10 @@ display_tag_value (int tag,
 /* ARM EABI attributes section.  */
 typedef struct
 {
-  int tag;
+  unsigned int tag;
   const char * name;
   /* 0 = special, 1 = string, 2 = uleb123, > 0x80 == table lookup.  */
-  int type;
+  unsigned int type;
   const char ** table;
 } arm_attr_public_tag;
 
@@ -11669,12 +11669,12 @@ static unsigned char *
 display_arm_attribute (unsigned char * p,
                       const unsigned char * const end)
 {
-  int tag;
+  unsigned int tag;
   unsigned int len;
-  int val;
+  unsigned int val;
   arm_attr_public_tag * attr;
   unsigned i;
-  int type;
+  unsigned int type;
 
   tag = read_uleb128 (p, &len, end);
   p += len;
index f5aef2a33b1ceb5fbbb3f06a83b1f37495a8225b..556ee1aa13a0647ccb2f2cf04bf72b52e7635ded 100644 (file)
@@ -1,3 +1,10 @@
+2014-09-16  Terry Guo  <terry.guo@arm.com>
+
+       * ld-arm/attr-merge-arch-2.d: New test case.
+       * ld-arm/attr-merge-arch-2a.s: New test case source file.
+       * ld-arm/attr-merge-arch-2b.s: Likewise.
+       * ld-arm/arm-elf.exp: Run new test case.
+
 2014-09-12  Andrew Bennett  <andrew.bennett@imgtec.com>
 
        * ld-mips-elf/mips-elf.exp: Add support for mips*-img-elf* target
index f971afca09b4902ded368d209e9a78a9086ad9d6..3c8cc689fea4d7521065e003052c39531be81776 100644 (file)
@@ -878,6 +878,7 @@ run_dump_test "attr-merge-vfp-6r"
 run_dump_test "attr-merge-vfp-7"
 run_dump_test "attr-merge-vfp-7r"
 run_dump_test "attr-merge-incompatible"
+run_dump_test "attr-merge-arch-2"
 run_dump_test "unresolved-1"
 if { ![istarget "arm*-*-nacl*"] } {
     run_dump_test "unresolved-1-dyn"
diff --git a/ld/testsuite/ld-arm/attr-merge-arch-2.d b/ld/testsuite/ld-arm/attr-merge-arch-2.d
new file mode 100644 (file)
index 0000000..0e98edb
--- /dev/null
@@ -0,0 +1,5 @@
+#source: attr-merge-arch-2a.s
+#source: attr-merge-arch-2b.s
+#as:
+#ld: -e main
+#error: Conflicting CPU architectures 13/0
diff --git a/ld/testsuite/ld-arm/attr-merge-arch-2a.s b/ld/testsuite/ld-arm/attr-merge-arch-2a.s
new file mode 100644 (file)
index 0000000..6235a3e
--- /dev/null
@@ -0,0 +1,18 @@
+        .syntax unified
+        .cpu cortex-m4
+        .fpu softvfp
+        .thumb
+        .file   "m.c"
+        .text
+        .align  2
+        .global main
+        .thumb
+        .thumb_func
+        .type   main, %function
+main:
+        push    {r7, lr}
+        add     r7, sp, #0
+        bl      foo
+        mov     r3, r0
+        mov     r0, r3
+        pop     {r7, pc}
diff --git a/ld/testsuite/ld-arm/attr-merge-arch-2b.s b/ld/testsuite/ld-arm/attr-merge-arch-2b.s
new file mode 100644 (file)
index 0000000..5771835
--- /dev/null
@@ -0,0 +1,8 @@
+        .eabi_attribute 6, 0  @Tag_CPU_arch, 0 means pre-v4.
+        .file   "f.c"
+        .text
+        .align  2
+        .global foo
+        .type   foo, %function
+foo:
+        bx      lr