changeset 4156:da0f64b64bfa

6198202 mcs -d dumps core
author ab196087
date Thu, 03 May 2007 09:59:24 -0700
parents 3e38fab0382c
children 2692c9055fcf
files usr/src/cmd/sgs/elfdump/common/elfdump.c usr/src/cmd/sgs/elfdump/common/elfdump.msg usr/src/cmd/sgs/mcs/common/file.c usr/src/cmd/sgs/packages/common/SUNWonld-README
diffstat 4 files changed, 26 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/usr/src/cmd/sgs/elfdump/common/elfdump.c	Thu May 03 09:19:29 2007 -0700
+++ b/usr/src/cmd/sgs/elfdump/common/elfdump.c	Thu May 03 09:59:24 2007 -0700
@@ -2746,7 +2746,14 @@
 	 * Obtain the .shstrtab data buffer to provide the required section
 	 * name strings.
 	 */
-	if ((scn = elf_getscn(elf, shstrndx)) == NULL) {
+	if (shstrndx == SHN_UNDEF) {
+		/*
+		 * It is rare, but legal, for an object to lack a
+		 * header string table section.
+		 */
+		names = NULL;
+		(void) fprintf(stderr, MSG_INTL(MSG_ERR_NOSHSTRSEC), file);
+	} else if ((scn = elf_getscn(elf, shstrndx)) == NULL) {
 		failure(file, MSG_ORIG(MSG_ELF_GETSCN));
 		(void) fprintf(stderr, MSG_INTL(MSG_ELF_ERR_SHDR),
 		    EC_XWORD(shstrndx));
--- a/usr/src/cmd/sgs/elfdump/common/elfdump.msg	Thu May 03 09:19:29 2007 -0700
+++ b/usr/src/cmd/sgs/elfdump/common/elfdump.msg	Thu May 03 09:59:24 2007 -0700
@@ -71,7 +71,10 @@
 
 @ MSG_ERR_BADFILE	"%s: invalid file type\n"
 @ MSG_ERR_BADREL1       "%s: bad relocation entry: %s: relocation requires symbol\n"
-@ MSG_ERR_SHSTRNULL	"%s: zero size section header string table (shstrtab)\n"
+@ MSG_ERR_NOSHSTRSEC	"%s: no header string table section (shstrtab). \
+			 header names are not available\n"
+@ MSG_ERR_SHSTRNULL	"%s: zero size section header string table \
+			 (shstrtab). header names are not available\n"
 @ MSG_ERR_FAILURE	"%s: %s failed: %s\n"
 @ MSG_ERR_BADSHDRALIGN	"%s: bad section header array alignment\n"
 @ MSG_ERR_BADPHDRALIGN	"%s: bad program header array alignment\n"
--- a/usr/src/cmd/sgs/mcs/common/file.c	Thu May 03 09:19:29 2007 -0700
+++ b/usr/src/cmd/sgs/mcs/common/file.c	Thu May 03 09:59:24 2007 -0700
@@ -705,8 +705,16 @@
 	dst_ehdr = *src_ehdr;
 
 	/*
-	 * flush the changes to the ehdr so the
-	 * ident array is filled in.
+	 * If we are removing the header string table section,
+	 * remove the reference to it from the ELF header.
+	 */
+	if ((shstrndx != SHN_UNDEF) &&
+	    (sec_table[shstrndx].secno == (GElf_Word)DELETED))
+		dst_ehdr.e_shstrndx = SHN_UNDEF;
+
+	/*
+	 * flush the changes to the ehdr so the ident
+	 * array and header string table index are filled in.
 	 */
 	(void) gelf_update_ehdr(dst_elf, &dst_ehdr);
 
@@ -983,9 +991,10 @@
 				if (nobits_table[scn_no] == 0)
 					new_offset += dst_shdr.sh_size;
 			}
+
+			/* flush changes */
+			(void) gelf_update_shdr(dst_scn, &dst_shdr);
 		}
-
-		(void) gelf_update_shdr(dst_scn, &dst_shdr); /* flush changes */
 		scn_no++;
 	}
 
--- a/usr/src/cmd/sgs/packages/common/SUNWonld-README	Thu May 03 09:19:29 2007 -0700
+++ b/usr/src/cmd/sgs/packages/common/SUNWonld-README	Thu May 03 09:59:24 2007 -0700
@@ -1231,3 +1231,4 @@
 6547441 Uninitialized variable causes ld.so.1 to crash on object cleanup
 6341667 elfdump should check alignments of ELF header elements
 6387860 elfdump cores, when processing linux built ELF file
+6198202 mcs -d dumps core