public inbox for elfutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] strip: Handle compressed relocation target sections.
@ 2016-08-06 13:27 Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2016-08-06 13:27 UTC (permalink / raw)
  To: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 3988 bytes --]

binutils 2.27 assembler will create compressed sections for x86 ELF
targets. The linker will decompress them again and it doesn't do this
for any other target. This broke one of the run-strip-reloc.sh self tests.

Fix by checking if the target of a relocation section is compressed and
first decompressing it before applying relocations and then compressing
again if necessary.

Add explicit testcases for compressed and uncompressed ET_REL files
to run-strip-reloc.sh.

Signed-off-by: Mark Wielaard <mjw@redhat.com>
---
 src/ChangeLog            |  5 +++++
 src/strip.c              | 22 +++++++++++++++++-----
 tests/ChangeLog          |  5 +++++
 tests/run-strip-reloc.sh | 11 +++++++++++
 4 files changed, 38 insertions(+), 5 deletions(-)

diff --git a/src/ChangeLog b/src/ChangeLog
index e5a3fce..835888d 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,8 @@
+2016-08-06  Mark Wielaard  <mjw@redhat.com>
+
+	* strip.c (handle_elf): Uncompress and recompress relocation target
+	section if necessary.
+
 2016-07-08  Mark Wielaard  <mjw@redhat.com>
 
 	* Makefile.am (strip_LDADD): Add libdw.
diff --git a/src/strip.c b/src/strip.c
index 23d3d51..f56554f 100644
--- a/src/strip.c
+++ b/src/strip.c
@@ -1,5 +1,5 @@
 /* Discard section not used at runtime from object files.
-   Copyright (C) 2000-2012, 2014, 2015 Red Hat, Inc.
+   Copyright (C) 2000-2012, 2014, 2015, 2016 Red Hat, Inc.
    This file is part of elfutils.
    Written by Ulrich Drepper <drepper@redhat.com>, 2000.
 
@@ -1791,10 +1791,18 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
 	      Elf_Data *reldata = elf_getdata (scn, NULL);
 	      if (reldata == NULL || reldata->d_buf == NULL)
 		INTERNAL_ERROR (fname);
-	      /* We actually wanted the rawdata, but since we already
-		 accessed it earlier as elf_getdata () that won't
-		 work. But debug sections are all ELF_T_BYTE, so it
-		 doesn't really matter.  */
+
+	      /* Make sure we adjust the uncompressed debug data
+		 (and recompress if necessary at the end).  */
+	      GElf_Chdr tchdr;
+	      int tcompress_type = 0;
+	      if (gelf_getchdr (tscn, &tchdr) != NULL)
+		{
+		  tcompress_type = tchdr.ch_type;
+		  if (elf_compress (tscn, 0, 0) != 1)
+		    INTERNAL_ERROR (fname);
+		}
+
 	      Elf_Data *tdata = elf_getdata (tscn, NULL);
 	      if (tdata == NULL || tdata->d_buf == NULL
 		  || tdata->d_type != ELF_T_BYTE)
@@ -1976,6 +1984,10 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
 	      nrels = next;
 	      shdr->sh_size = reldata->d_size = nrels * shdr->sh_entsize;
 	      gelf_update_shdr (scn, shdr);
+
+	      if (tcompress_type != 0)
+		if (elf_compress (tscn, tcompress_type, 0) != 1)
+		  INTERNAL_ERROR (fname);
 	    }
 	}
     }
diff --git a/tests/ChangeLog b/tests/ChangeLog
index 58a023c..e7b3a4e 100644
--- a/tests/ChangeLog
+++ b/tests/ChangeLog
@@ -1,3 +1,8 @@
+2016-08-06  Mark Wielaard  <mjw@redhat.com>
+
+	* run-strip-reloc.sh: Add explicit compressed and uncompressed
+	test cases.
+
 2016-07-08  Mark Wielaard  <mjw@redhat.com>
 
 	* update3_LDADD: Use libdw instead of libebl.
diff --git a/tests/run-strip-reloc.sh b/tests/run-strip-reloc.sh
index 9fbba29..e587eab 100755
--- a/tests/run-strip-reloc.sh
+++ b/tests/run-strip-reloc.sh
@@ -108,4 +108,15 @@ runtest hello_m68k.ko 1
 runtest ${abs_top_builddir}/src/strip 0
 runtest ${abs_top_builddir}/src/strip.o 1
 
+# Copy ET_REL file for self-test and make sure to run with/without
+# elf section compression.
+tempfiles strip-uncompressed.o strip-compressed.o
+testrun ${abs_top_builddir}/src/elfcompress -o strip-uncompressed.o -t none \
+  ${abs_top_builddir}/src/strip.o
+testrun ${abs_top_builddir}/src/elfcompress -o strip-compressed.o -t zlib \
+  --force ${abs_top_builddir}/src/strip.o
+
+runtest strip-uncompressed.o 1
+runtest strip-compressed.o 1
+
 exit $status
-- 
2.7.4

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] strip: Handle compressed relocation target sections.
@ 2016-08-16  8:37 Mark Wielaard
  0 siblings, 0 replies; 2+ messages in thread
From: Mark Wielaard @ 2016-08-16  8:37 UTC (permalink / raw)
  To: elfutils-devel

[-- Attachment #1: Type: text/plain, Size: 590 bytes --]

On Sat, Aug 06, 2016 at 03:27:29PM +0200, Mark Wielaard wrote:
> binutils 2.27 assembler will create compressed sections for x86 ELF
> targets. The linker will decompress them again and it doesn't do this
> for any other target. This broke one of the run-strip-reloc.sh self tests.
> 
> Fix by checking if the target of a relocation section is compressed and
> first decompressing it before applying relocations and then compressing
> again if necessary.
> 
> Add explicit testcases for compressed and uncompressed ET_REL files
> to run-strip-reloc.sh.

I pushed this to master.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2016-08-16  8:37 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-08-06 13:27 [PATCH] strip: Handle compressed relocation target sections Mark Wielaard
2016-08-16  8:37 Mark Wielaard

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).