svn commit: r298085 - head/contrib/elftoolchain/elfcopy

Ed Maste emaste at FreeBSD.org
Fri Apr 15 19:06:37 UTC 2016


Author: emaste
Date: Fri Apr 15 19:06:36 2016
New Revision: 298085
URL: https://svnweb.freebsd.org/changeset/base/298085

Log:
  elfcopy: fix symbol table handling when sections come after symtab/strtab
  
    Fix a symbol table handling bug in elfcopy: elfcopy puts .symtab,
    .strtab and .shstrtab sections in the end of the output object.  If
    the input objects have more sections after any of these 3 sections,
    the section table will be reordered, and in that case the section
    symbols should be regenerated for relocations.
  
    The bug is triggered since newer clang puts .strtab section in the
    beginning of the object produced.
  
     Ticket: #525
  
  Reported by:	royger
  Obtained from:	ELF Tool Chain r3443

Modified:
  head/contrib/elftoolchain/elfcopy/sections.c

Modified: head/contrib/elftoolchain/elfcopy/sections.c
==============================================================================
--- head/contrib/elftoolchain/elfcopy/sections.c	Fri Apr 15 18:49:26 2016	(r298084)
+++ head/contrib/elftoolchain/elfcopy/sections.c	Fri Apr 15 19:06:36 2016	(r298085)
@@ -343,7 +343,7 @@ create_scn(struct elfcopy *ecp)
 	GElf_Shdr	 ish;
 	size_t		 indx;
 	uint64_t	 oldndx, newndx;
-	int		 elferr, sec_flags;
+	int		 elferr, sec_flags, reorder;
 
 	/*
 	 * Insert a pseudo section that contains the ELF header
@@ -367,6 +367,7 @@ create_scn(struct elfcopy *ecp)
 		errx(EXIT_FAILURE, "elf_getshstrndx failed: %s",
 		    elf_errmsg(-1));
 
+	reorder = 0;
 	is = NULL;
 	while ((is = elf_nextscn(ecp->ein, is)) != NULL) {
 		if (gelf_getshdr(is, &ish) == NULL)
@@ -482,8 +483,20 @@ create_scn(struct elfcopy *ecp)
 		/* create section header based on input object. */
 		if (strcmp(name, ".symtab") != 0 &&
 		    strcmp(name, ".strtab") != 0 &&
-		    strcmp(name, ".shstrtab") != 0)
+		    strcmp(name, ".shstrtab") != 0) {
 			copy_shdr(ecp, s, NULL, 0, sec_flags);
+			/*
+			 * elfcopy puts .symtab, .strtab and .shstrtab
+			 * sections in the end of the output object.
+			 * If the input objects have more sections
+			 * after any of these 3 sections, the section
+			 * table will be reordered. section symbols
+			 * should be regenerated for relocations.
+			 */
+			if (reorder)
+				ecp->flags &= ~SYMTAB_INTACT;
+		} else
+			reorder = 1;
 
 		if (strcmp(name, ".symtab") == 0) {
 			ecp->flags |= SYMTAB_EXIST;


More information about the svn-src-all mailing list