Also check e_machine when merging sections
authorH.J. Lu <hjl.tools@gmail.com>
Wed, 30 Sep 2015 12:32:12 +0000 (05:32 -0700)
committerH.J. Lu <hjl.tools@gmail.com>
Wed, 30 Sep 2015 12:37:49 +0000 (05:37 -0700)
When we check consistency for merge ELF sections, we should not only
check EI_CLASS, but also compatible e_machine.

bfd/

PR ld/19013
* elflink.c (_bfd_elf_merge_sections): Only merge input bfds
that have the compatible ELF machine code with the output bfd.

ld/testsuite/

PR ld/19013
* ld-x86-64/pr19013-nacl.d: New file.
* ld-x86-64/pr19013-x32.d: Likewise.
* ld-x86-64/pr19013.d: Likewise.
* ld-x86-64/pr19013.s: Likewise.
* ld-x86-64/x86-64.exp: Run PR ld/19013 tests.

bfd/ChangeLog
bfd/elflink.c
ld/testsuite/ChangeLog
ld/testsuite/ld-x86-64/pr19013-nacl.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr19013-x32.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr19013.d [new file with mode: 0644]
ld/testsuite/ld-x86-64/pr19013.s [new file with mode: 0644]
ld/testsuite/ld-x86-64/x86-64.exp

index f4ca2ec55f27a7b293cb12431345671a01e40310..a218d44483db64f09827c63fcc292daa7a865dce 100644 (file)
@@ -1,3 +1,9 @@
+2015-09-30  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/19013
+       * elflink.c (_bfd_elf_merge_sections): Only merge input bfds
+       that have the compatible ELF machine code with the output bfd.
+
 2015-09-30  Alan Modra  <amodra@gmail.com>
 
        PR ld/19013
index 90af6cfdfa0db957995614c3185a762ca302337e..70c231b4576709454aa50bb73c0df06d61861341 100644 (file)
@@ -6818,15 +6818,23 @@ _bfd_elf_merge_sections (bfd *obfd, struct bfd_link_info *info)
 {
   bfd *ibfd;
   asection *sec;
+  const struct elf_backend_data *bed;
 
   if (!is_elf_hash_table (info->hash))
     return FALSE;
 
+  bed = get_elf_backend_data (obfd);
   for (ibfd = info->input_bfds; ibfd != NULL; ibfd = ibfd->link.next)
     if ((ibfd->flags & DYNAMIC) == 0
        && bfd_get_flavour (ibfd) == bfd_target_elf_flavour
-       && (elf_elfheader (ibfd)->e_ident[EI_CLASS]
-           == get_elf_backend_data (obfd)->s->elfclass))
+       && (elf_elfheader (ibfd)->e_ident[EI_CLASS] == bed->s->elfclass)
+       && (bed->elf_machine_code == elf_elfheader (ibfd)->e_machine
+           || (bed->elf_machine_alt1 != 0
+               && (bed->elf_machine_alt1
+                   == elf_elfheader (ibfd)->e_machine))
+           || (bed->elf_machine_alt2 != 0
+               && (bed->elf_machine_alt2
+                   == elf_elfheader (ibfd)->e_machine))))
       for (sec = ibfd->sections; sec != NULL; sec = sec->next)
        if ((sec->flags & SEC_MERGE) != 0
            && !bfd_is_abs_section (sec->output_section))
index 40eb3589c6f8cbee0bc942f5094568dc301b5bc6..7f1b7acab9f3428fab8076071500e4f72a05d4e1 100644 (file)
@@ -1,3 +1,12 @@
+2015-09-30  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/19013
+       * ld-x86-64/pr19013-nacl.d: New file.
+       * ld-x86-64/pr19013-x32.d: Likewise.
+       * ld-x86-64/pr19013.d: Likewise.
+       * ld-x86-64/pr19013.s: Likewise.
+       * ld-x86-64/x86-64.exp: Run PR ld/19013 tests.
+
 2015-09-29  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR binutils/19005
diff --git a/ld/testsuite/ld-x86-64/pr19013-nacl.d b/ld/testsuite/ld-x86-64/pr19013-nacl.d
new file mode 100644 (file)
index 0000000..7294ed2
--- /dev/null
@@ -0,0 +1,9 @@
+#source: pr19013.s
+#as: --x32
+#ld: --oformat elf32-i386-nacl
+#objdump: -s -j .rodata
+#target: x86_64-*-nacl*
+
+#...
+ [0-9a-f]+ 00000203 00414243 4400 +.....ABCD. +
+#pass
diff --git a/ld/testsuite/ld-x86-64/pr19013-x32.d b/ld/testsuite/ld-x86-64/pr19013-x32.d
new file mode 100644 (file)
index 0000000..fb70966
--- /dev/null
@@ -0,0 +1,9 @@
+#source: pr19013.s
+#as: --x32
+#ld: --oformat elf32-i386 -m elf32_x86_64
+#objdump: -s -j .rodata
+#notarget: x86_64-*-nacl*
+
+#...
+ [0-9a-f]+ 00000203 00414243 4400 +.....ABCD. +
+#pass
diff --git a/ld/testsuite/ld-x86-64/pr19013.d b/ld/testsuite/ld-x86-64/pr19013.d
new file mode 100644 (file)
index 0000000..9b1473a
--- /dev/null
@@ -0,0 +1,8 @@
+#as: --64
+#ld: --oformat elf32-i386
+#objdump: -s -j .rodata
+#notarget: x86_64-*-nacl*
+
+#...
+ [0-9a-f]+ 00000203 00414243 4400 +.....ABCD. +
+#pass
diff --git a/ld/testsuite/ld-x86-64/pr19013.s b/ld/testsuite/ld-x86-64/pr19013.s
new file mode 100644 (file)
index 0000000..db95ecb
--- /dev/null
@@ -0,0 +1,5 @@
+       .section    .rodata.str1.1,"aMS",@progbits,1
+       .globl  _start
+_start:
+       .byte 0x0, 0x0, 0x2, 0x3, 0x0
+       .string "ABCD"
index 6320999b6c87ca520e8fdabc7dffcdb3e4216d35..5de67caa2da57c4731e14c4a8b344d777f0b8eb5 100644 (file)
@@ -327,6 +327,9 @@ run_dump_test "pr18160"
 run_dump_test "pr18176"
 run_dump_test "pr18801"
 run_dump_test "pr18815"
+run_dump_test "pr19013"
+run_dump_test "pr19013-x32"
+run_dump_test "pr19013-nacl"
 
 # Add $PLT_CFLAGS if PLT is expected.
 global PLT_CFLAGS
This page took 0.03677 seconds and 4 git commands to generate.