aboutsummaryrefslogtreecommitdiff
path: root/binutils
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2015-07-10 14:20:20 -0700
committerH.J. Lu <hjl.tools@gmail.com>2015-07-10 14:27:39 -0700
commit889884731e09b46e4c2ecb051dfde1e2f69d2b47 (patch)
treea4e2caa2763562a127f970dad138ab6769b769be /binutils
parenta0e28e54675fd92e73df71fed5d4f6c718f40102 (diff)
downloadgdb-889884731e09b46e4c2ecb051dfde1e2f69d2b47.zip
gdb-889884731e09b46e4c2ecb051dfde1e2f69d2b47.tar.gz
gdb-889884731e09b46e4c2ecb051dfde1e2f69d2b47.tar.bz2
Properly convert objects between different ELF classes
The output SHF_COMPRESSED section size is different from input if ELF classes of input and output aren't the same. We must adjust the section sizes as well as the compression headers in SHF_COMPRESSED sections when converting objects between different ELF classes. bfd/ PR binutils/18656 * bfd.c (bfd_convert_section_size): New function. (bfd_convert_section_contents): Likewise. * bfd-in2.h: Regenerated. binutils/ 2015-07-10 H.J. Lu <hongjiu.lu@intel.com> PR binutils/18656 * objcopy.c (setup_section): Call bfd_convert_section_size to get the output section size. (copy_section): Get the section size from the output section and call bfd_get_full_section_contents to convert section contents for output. binutils/testsuite/ PR binutils/18656 * binutils-all/compress.exp (convert_test): New proc. Run conversion tests between x86-64 and x32.
Diffstat (limited to 'binutils')
-rw-r--r--binutils/ChangeLog9
-rw-r--r--binutils/objcopy.c11
-rw-r--r--binutils/testsuite/ChangeLog6
-rw-r--r--binutils/testsuite/binutils-all/compress.exp93
4 files changed, 117 insertions, 2 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index 09b0e1c..c504b33 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,5 +1,14 @@
2015-07-10 H.J. Lu <hongjiu.lu@intel.com>
+ PR binutils/18656
+ * objcopy.c (setup_section): Call bfd_convert_section_size
+ to get the output section size.
+ (copy_section): Get the section size from the output section
+ and call bfd_get_full_section_contents to convert section
+ contents for output.
+
+2015-07-10 H.J. Lu <hongjiu.lu@intel.com>
+
* readelf.c (dump_section_as_strings): Warn unsupported compress
type and corrupted compressed section.
(dump_section_as_bytes): Likewise.
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 7f1bd76..d6516e0 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -2872,6 +2872,7 @@ setup_section (bfd *ibfd, sec_ptr isection, void *obfdarg)
elf_section_type (osection) = SHT_NOBITS;
size = bfd_section_size (ibfd, isection);
+ size = bfd_convert_section_size (ibfd, isection, obfd, size);
if (copy_byte >= 0)
size = (size + interleave - 1) / interleave * copy_width;
else if (extract_symbol)
@@ -3109,14 +3110,20 @@ copy_section (bfd *ibfd, sec_ptr isection, void *obfdarg)
return;
osection = isection->output_section;
- size = bfd_get_section_size (isection);
+ /* The output SHF_COMPRESSED section size is different from input if
+ ELF classes of input and output aren't the same. We must use the
+ output section size here, which has been updated in setup_section
+ via bfd_convert_section_size. */
+ size = bfd_get_section_size (osection);
if (bfd_get_section_flags (ibfd, isection) & SEC_HAS_CONTENTS
&& bfd_get_section_flags (obfd, osection) & SEC_HAS_CONTENTS)
{
bfd_byte *memhunk = NULL;
- if (!bfd_get_full_section_contents (ibfd, isection, &memhunk))
+ if (!bfd_get_full_section_contents (ibfd, isection, &memhunk)
+ || !bfd_convert_section_contents (ibfd, isection, obfd,
+ &memhunk))
{
status = 1;
bfd_nonfatal_message (NULL, ibfd, isection, NULL);
diff --git a/binutils/testsuite/ChangeLog b/binutils/testsuite/ChangeLog
index ebc35c3..435961a 100644
--- a/binutils/testsuite/ChangeLog
+++ b/binutils/testsuite/ChangeLog
@@ -1,5 +1,11 @@
2015-07-10 H.J. Lu <hongjiu.lu@intel.com>
+ PR binutils/18656
+ * binutils-all/compress.exp (convert_test): New proc.
+ Run conversion tests between x86-64 and x32.
+
+2015-07-10 H.J. Lu <hongjiu.lu@intel.com>
+
* binutils-all/dw2-3.W: Updated to accept .debug_* sections.
2015-05-20 Ed Maste <emaste@freebsd.org>
diff --git a/binutils/testsuite/binutils-all/compress.exp b/binutils/testsuite/binutils-all/compress.exp
index 43a3ce1..abff197 100644
--- a/binutils/testsuite/binutils-all/compress.exp
+++ b/binutils/testsuite/binutils-all/compress.exp
@@ -570,3 +570,96 @@ if { [regexp_diff objdump.out $srcdir/$subdir/dw2-3gabi.W] } then {
} else {
pass "$testname"
}
+
+proc convert_test { testname as_flags objcop_flags } {
+ global srcdir
+ global subdir
+ global testfile3
+ global copyfile
+ global OBJCOPY
+ global OBJDUMP
+
+ if { ![binutils_assemble_flags $srcdir/$subdir/dw2-3.S ${testfile3}.o "$as_flags"] } then {
+ unresolved "$testname"
+ return
+ }
+
+ set got [binutils_run $OBJCOPY "$objcop_flags ${testfile3}.o ${copyfile}.o"]
+ if ![string match "" $got] then {
+ fail "objcopy ($testname)"
+ return
+ }
+
+ set got [remote_exec host "$OBJDUMP -W ${copyfile}.o" "" "/dev/null" "objdump.out"]
+
+ if { [lindex $got 0] != 0 || ![string match "" [lindex $got 1]] } then {
+ fail "$testname (reason: unexpected output)"
+ send_log $got
+ send_log "\n"
+ return
+ }
+
+ if { [regexp_diff objdump.out $srcdir/$subdir/dw2-3.W] } then {
+ fail "$testname"
+ } else {
+ pass "$testname"
+ }
+}
+
+if { ([istarget "x86_64-*-elf*"]
+ || [istarget "x86_64-*-linux*"]) } {
+ set testname "Convert x86-64 object with zlib-gabi to x32 (1)"
+ convert_test "$testname" "--compress-debug-sections=zlib-gabi --64" "-O elf32-x86-64"
+
+ set testname "Convert x86-64 object with zlib-gabi to x32 (2)"
+ convert_test "$testname" "--compress-debug-sections=zlib-gabi --64" "-O elf32-x86-64 --compress-debug-sections=zlib-gnu"
+
+ set testname "Convert x86-64 object with zlib-gabi to x32 (3)"
+ convert_test "$testname" "--compress-debug-sections=zlib-gabi --64" "-O elf32-x86-64 --decompress-debug-sections"
+
+ set testname "Convert x86-64 object with zlib-gnu to x32 (1)"
+ convert_test "$testname" "--compress-debug-sections=zlib-gnu --64" "-O elf32-x86-64"
+
+ set testname "Convert x86-64 object with zlib-gnu to x32 (2)"
+ convert_test "$testname" "--compress-debug-sections=zlib-gnu --64" "-O elf32-x86-64 --compress-debug-sections=zlib-gabi"
+
+ set testname "Convert x86-64 object with zlib-gnu to x32 (3)"
+ convert_test "$testname" "--compress-debug-sections=zlib-gnu --64" "-O elf32-x86-64 --decompress-debug-sections"
+
+ set testname "Convert x86-64 object to x32 (1)"
+ convert_test "$testname" "--nocompress-debug-sections --64" "-O elf32-x86-64"
+
+ set testname "Convert x86-64 object to x32 (2)"
+ convert_test "$testname" "--nocompress-debug-sections --64" "-O elf32-x86-64 --compress-debug-sections=zlib-gabi"
+
+ set testname "Convert x86-64 object to x32 (3)"
+ convert_test "$testname" "--nocompress-debug-sections --64" "-O elf32-x86-64 --compress-debug-sections=zlib-gnu"
+
+
+ set testname "Convert x32 object with zlib-gabi to x86-64 (1)"
+ convert_test "$testname" "--compress-debug-sections=zlib-gabi --x32" "-O elf64-x86-64"
+
+ set testname "Convert x32 object with zlib-gabi to x86-64 (2)"
+ convert_test "$testname" "--compress-debug-sections=zlib-gabi --x32" "-O elf64-x86-64 --compress-debug-sections=zlib-gnu"
+
+ set testname "Convert x32 object with zlib-gabi to x86-64 (3)"
+ convert_test "$testname" "--compress-debug-sections=zlib-gabi --x32" "-O elf64-x86-64 --decompress-debug-sections"
+
+ set testname "Convert x32 object with zlib-gnu to x86-64 (1)"
+ convert_test "$testname" "--compress-debug-sections=zlib-gnu --x32" "-O elf64-x86-64"
+
+ set testname "Convert x32 object with zlib-gnu to x86-64 (2)"
+ convert_test "$testname" "--compress-debug-sections=zlib-gnu --x32" "-O elf64-x86-64 --compress-debug-sections=zlib-gabi"
+
+ set testname "Convert x32 object with zlib-gnu to x86-64 (3)"
+ convert_test "$testname" "--compress-debug-sections=zlib-gnu --x32" "-O elf64-x86-64 --decompress-debug-sections"
+
+ set testname "Convert x32 object to x86-64 (1)"
+ convert_test "$testname" "--nocompress-debug-sections --x32" "-O elf64-x86-64"
+
+ set testname "Convert x32 object to x86-64 (2)"
+ convert_test "$testname" "--nocompress-debug-sections --x32" "-O elf64-x86-64 --compress-debug-sections=zlib-gabi"
+
+ set testname "Convert x32 object to x86-64 (3)"
+ convert_test "$testname" "--nocompress-debug-sections --x32" "-O elf64-x86-64 --compress-debug-sections=zlib-gnu"
+ }