summaryrefslogtreecommitdiff
path: root/elfcopy/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'elfcopy/main.c')
-rw-r--r--elfcopy/main.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/elfcopy/main.c b/elfcopy/main.c
index a48aea589748..cbd48d3fc4b9 100644
--- a/elfcopy/main.c
+++ b/elfcopy/main.c
@@ -39,7 +39,7 @@
#include "elfcopy.h"
-ELFTC_VCSID("$Id: main.c 3174 2015-03-27 17:13:41Z emaste $");
+ELFTC_VCSID("$Id: main.c 3216 2015-05-23 21:16:36Z kaiwang27 $");
enum options
{
@@ -404,8 +404,19 @@ create_elf(struct elfcopy *ecp)
* Insert SHDR table into the internal section list as a "pseudo"
* section, so later it will get sorted and resynced just as "normal"
* sections.
+ *
+ * Under FreeBSD, Binutils objcopy always put the section header
+ * at the end of all the sections. We want to do the same here.
+ *
+ * However, note that the behaviour is still different with Binutils:
+ * elfcopy checks the FreeBSD OSABI tag to tell whether it needs to
+ * move the section headers, while Binutils is probably configured
+ * this way when it's compiled on FreeBSD.
*/
- shtab = insert_shtab(ecp, 0);
+ if (oeh.e_ident[EI_OSABI] == ELFOSABI_FREEBSD)
+ shtab = insert_shtab(ecp, 1);
+ else
+ shtab = insert_shtab(ecp, 0);
/*
* Resync section offsets in the output object. This is needed
@@ -485,6 +496,11 @@ free_elf(struct elfcopy *ecp)
free(sec);
}
}
+
+ if (ecp->secndx != NULL) {
+ free(ecp->secndx);
+ ecp->secndx = NULL;
+ }
}
/* Create a temporary file. */