Allow building x32 DSO from x86-64 object file.
authorH.J. Lu <hjl.tools@gmail.com>
Thu, 9 Jun 2011 05:51:11 +0000 (05:51 +0000)
committerH.J. Lu <hjl.tools@gmail.com>
Thu, 9 Jun 2011 05:51:11 +0000 (05:51 +0000)
bfd/

2011-06-08  H.J. Lu  <hongjiu.lu@intel.com>

* elf64-x86-64.c (elf_x86_64_check_relocs): Allow R_X86_64_64
relocations in SEC_DEBUGGING sections when building shared
libraries.

ld/testsuite/

2011-06-08  H.J. Lu  <hongjiu.lu@intel.com>

* ld-x86-64/simple.c: New.
* ld-x86-64/x86-64-x32.rd: Likewise.

* ld-x86-64/x86-64.exp: Check building x32 DSO from x86-64
object file.

bfd/ChangeLog
bfd/elf64-x86-64.c
ld/testsuite/ChangeLog
ld/testsuite/ld-x86-64/simple.c [new file with mode: 0644]
ld/testsuite/ld-x86-64/x86-64-x32.rd [new file with mode: 0644]
ld/testsuite/ld-x86-64/x86-64.exp

index f9b36883a4545f5205a1da0839bc4e6ac759adb4..25fa50bf1defd6546230c0122e8cbe721cf2d22c 100644 (file)
@@ -1,3 +1,9 @@
+2011-06-08  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * elf64-x86-64.c (elf_x86_64_check_relocs): Allow R_X86_64_64
+       relocations in SEC_DEBUGGING sections when building shared
+       libraries.
+
 2011-06-08  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/12851
index 9d6d4a401aa5caf38c8f71ea87425f8b8c58b97f..72a7cc1dc088ad3520ee17e9e487f43c24182d69 100644 (file)
@@ -1217,6 +1217,13 @@ elf_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info,
            break;
 
          case R_X86_64_64:
+           /* Allow R_X86_64_64 relocations in SEC_DEBUGGING sections
+              when building shared libraries.  */
+           if (info->shared
+               && !info->executable
+               && (sec->flags & SEC_DEBUGGING) != 0)
+             break;
+
          case R_X86_64_DTPOFF64:
          case R_X86_64_TPOFF64:
          case R_X86_64_PC64:
index dcefc10e978e6a89f2da01b6e8ad6de3a0509742..93096b093b39cba031e74e15543b5f2e1fcaa9a4 100644 (file)
@@ -1,3 +1,11 @@
+2011-06-08  H.J. Lu  <hongjiu.lu@intel.com>
+
+       * ld-x86-64/simple.c: New.
+       * ld-x86-64/x86-64-x32.rd: Likewise.
+
+       * ld-x86-64/x86-64.exp: Check building x32 DSO from x86-64
+       object file.
+
 2011-06-08  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/12851
diff --git a/ld/testsuite/ld-x86-64/simple.c b/ld/testsuite/ld-x86-64/simple.c
new file mode 100644 (file)
index 0000000..4ce3e8f
--- /dev/null
@@ -0,0 +1,5 @@
+int
+foo (int x)
+{
+  return x * 4;
+}
diff --git a/ld/testsuite/ld-x86-64/x86-64-x32.rd b/ld/testsuite/ld-x86-64/x86-64-x32.rd
new file mode 100644 (file)
index 0000000..7118cb9
--- /dev/null
@@ -0,0 +1,5 @@
+Symbol table '\.dynsym' contains [0-9]+ entries:
+ +Num: +Value +Size Type +Bind +Vis +Ndx Name
+#...
+ +[0-9]+: +[0-9a-f]+ +[0-9a-f]+ +FUNC +GLOBAL +DEFAULT +[0-9]+ +foo
+#...
index c77640b401155edc82615473d29ef635a807c63d..8d4ed2c3589af8a95130646fc4c4f341b8fa1335 100644 (file)
@@ -203,3 +203,26 @@ run_dump_test "ia32-3"
 run_dump_test "lp64-1"
 run_dump_test "lp64-2"
 run_dump_test "lp64-3"
+
+# Need the C compiler
+if { [which $CC] != 0 } {
+    run_cc_link_tests {
+       {"Helper X32 DSO from x86-64 object" "" "-m64 -fPIC -g"
+        {simple.c} {} "libsimple.a"}
+    }
+
+    set convertx32 "$objcopy -O elf32-x86-64 tmpdir/simple.o tmpdir/simple-x32.o"
+    send_log "$convertx32\n"
+    set got [remote_exec host "$convertx32"]
+    if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
+       send_log "$got\n"
+       fail "Convert x86-64 object to x32"
+       return
+    }
+
+    run_ld_link_tests {
+       {"X32 DSO from x86-64 object"
+        "-shared -melf32_x86_64 tmpdir/simple-x32.o" "--x32"
+       {dummy.s} {{readelf {-s --wide} x86-64-x32.rd}} "x86-64-x32"}
+    }
+}