summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoremaste <emaste@FreeBSD.org>2016-04-15 19:06:36 +0000
committeremaste <emaste@FreeBSD.org>2016-04-15 19:06:36 +0000
commit6f846e4655a5731e34fcf7d5e9c2e61ca5be5203 (patch)
tree71cff751642d65705c49d567f7f685548adab32b
parent7d10ac17e2cfbadd8788e87d133fe09e55997281 (diff)
downloadFreeBSD-src-6f846e4655a5731e34fcf7d5e9c2e61ca5be5203.zip
FreeBSD-src-6f846e4655a5731e34fcf7d5e9c2e61ca5be5203.tar.gz
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
-rw-r--r--contrib/elftoolchain/elfcopy/sections.c17
1 files changed, 15 insertions, 2 deletions
diff --git a/contrib/elftoolchain/elfcopy/sections.c b/contrib/elftoolchain/elfcopy/sections.c
index 5848eab..1434138 100644
--- a/contrib/elftoolchain/elfcopy/sections.c
+++ b/contrib/elftoolchain/elfcopy/sections.c
@@ -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;
OpenPOWER on IntegriCloud