summaryrefslogtreecommitdiffstats
path: root/elfcopy
diff options
context:
space:
mode:
Diffstat (limited to 'elfcopy')
-rw-r--r--elfcopy/binary.c11
-rw-r--r--elfcopy/elfcopy.19
-rw-r--r--elfcopy/main.c6
-rw-r--r--elfcopy/sections.c16
-rw-r--r--elfcopy/segments.c4
5 files changed, 32 insertions, 14 deletions
diff --git a/elfcopy/binary.c b/elfcopy/binary.c
index 23e46e7..7c834a9 100644
--- a/elfcopy/binary.c
+++ b/elfcopy/binary.c
@@ -35,7 +35,7 @@
#include "elfcopy.h"
-ELFTC_VCSID("$Id: binary.c 3174 2015-03-27 17:13:41Z emaste $");
+ELFTC_VCSID("$Id: binary.c 3270 2015-12-11 18:48:56Z emaste $");
/*
* Convert ELF object to `binary'. Sections with SHF_ALLOC flag set
@@ -140,6 +140,7 @@ create_elf_from_binary(struct elfcopy *ecp, int ifd, const char *ifn)
GElf_Shdr sh;
void *content;
uint64_t off, data_start, data_end, data_size;
+ char *sym_basename, *p;
/* Reset internal section list. */
if (!TAILQ_EMPTY(&ecp->v_sec))
@@ -210,8 +211,13 @@ create_elf_from_binary(struct elfcopy *ecp, int ifd, const char *ifn)
/* Count in .symtab and .strtab section headers. */
shtab->sz += gelf_fsize(ecp->eout, ELF_T_SHDR, 2, EV_CURRENT);
+ if ((sym_basename = strdup(ifn)) == NULL)
+ err(1, "strdup");
+ p = sym_basename;
+ while ((p = strchr(p, '.')) != NULL)
+ *p++ = '_';
#define _GEN_SYMNAME(S) do { \
- snprintf(name, sizeof(name), "%s%s%s", "_binary_", ifn, S); \
+ snprintf(name, sizeof(name), "%s%s%s", "_binary_", sym_basename, S); \
} while (0)
/*
@@ -233,6 +239,7 @@ create_elf_from_binary(struct elfcopy *ecp, int ifd, const char *ifn)
finalize_external_symtab(ecp);
create_symtab_data(ecp);
#undef _GEN_SYMNAME
+ free(sym_basename);
/*
* Write the underlying ehdr. Note that it should be called
diff --git a/elfcopy/elfcopy.1 b/elfcopy/elfcopy.1
index 4889570..83cda5d 100644
--- a/elfcopy/elfcopy.1
+++ b/elfcopy/elfcopy.1
@@ -21,9 +21,9 @@
.\" out of the use of this software, even if advised of the possibility of
.\" such damage.
.\"
-.\" $Id: elfcopy.1 3195 2015-05-12 17:22:19Z emaste $
+.\" $Id: elfcopy.1 3266 2015-12-07 15:38:26Z emaste $
.\"
-.Dd March 27, 2015
+.Dd December 7, 2015
.Os
.Dt ELFCOPY 1
.Sh NAME
@@ -47,6 +47,7 @@
.Op Fl p | Fl -preserve-dates
.Op Fl w | Fl -wildcard
.Op Fl x | Fl -discard-all
+.Op Fl -add-gnu-debuglink Ns = Ns Ar filename
.Op Fl -add-section Ar sectionname Ns = Ns Ar filename
.Oo
.Fl -adjust-section-vma Ar section Ns {+|-|=} Ns Ar val |
@@ -165,6 +166,10 @@ Mark the end of a character class.
.El
.It Fl x | Fl -discard-all
Do not copy non-global symbols to the output.
+.It Fl -add-gnu-debuglink Ns = Ns Ar filename
+Create a .gnu_debuglink section in the output file that references the
+debug data in
+.Ar filename .
.It Fl -add-section Ar sectionname Ns = Ns Ar filename
Add a new section to the output file with name
.Ar sectionname .
diff --git a/elfcopy/main.c b/elfcopy/main.c
index cbd48d3..e2685b4 100644
--- a/elfcopy/main.c
+++ b/elfcopy/main.c
@@ -39,7 +39,7 @@
#include "elfcopy.h"
-ELFTC_VCSID("$Id: main.c 3216 2015-05-23 21:16:36Z kaiwang27 $");
+ELFTC_VCSID("$Id: main.c 3268 2015-12-07 20:30:55Z emaste $");
enum options
{
@@ -1375,11 +1375,13 @@ Usage: %s [options] infile [outfile]\n\
-w | --wildcard Use shell-style patterns to name symbols.\n\
-x | --discard-all Do not copy non-globals to the output.\n\
-I FORMAT | --input-target=FORMAT\n\
- (Accepted but ignored).\n\
+ Specify object format for the input file.\n\
-K SYM | --keep-symbol=SYM Copy symbol SYM to the output.\n\
-L SYM | --localize-symbol=SYM\n\
Make symbol SYM local to the output file.\n\
-N SYM | --strip-symbol=SYM Do not copy symbol SYM to the output.\n\
+ -O FORMAT | --output-target=FORMAT\n\
+ Specify object format for the output file.\n\
-R NAME | --remove-section=NAME\n\
Remove the named section.\n\
-S | --strip-all Remove all symbol and relocation information\n\
diff --git a/elfcopy/sections.c b/elfcopy/sections.c
index f1ec6c0..0c18171 100644
--- a/elfcopy/sections.c
+++ b/elfcopy/sections.c
@@ -34,7 +34,7 @@
#include "elfcopy.h"
-ELFTC_VCSID("$Id: sections.c 3225 2015-06-06 02:35:23Z kaiwang27 $");
+ELFTC_VCSID("$Id: sections.c 3272 2015-12-11 20:00:54Z kaiwang27 $");
static void add_gnu_debuglink(struct elfcopy *ecp);
static uint32_t calc_crc32(const char *p, size_t len, uint32_t crc);
@@ -457,11 +457,17 @@ create_scn(struct elfcopy *ecp)
/*
* If strip action is STRIP_NONDEBUG(only keep debug),
- * change sections flags of loadable sections to SHF_NOBITS,
- * and the content of those sections will be ignored.
+ * change sections type of loadable sections and section
+ * groups to SHT_NOBITS, and the content of those sections
+ * will be discarded. However, SHT_NOTE sections should
+ * be kept.
*/
- if (ecp->strip == STRIP_NONDEBUG && (ish.sh_flags & SHF_ALLOC))
- s->type = SHT_NOBITS;
+ if (ecp->strip == STRIP_NONDEBUG) {
+ if (((ish.sh_flags & SHF_ALLOC) ||
+ (ish.sh_flags & SHF_GROUP)) &&
+ ish.sh_type != SHT_NOTE)
+ s->type = SHT_NOBITS;
+ }
check_section_rename(ecp, s);
diff --git a/elfcopy/segments.c b/elfcopy/segments.c
index 1e271a6..837cea5 100644
--- a/elfcopy/segments.c
+++ b/elfcopy/segments.c
@@ -34,7 +34,7 @@
#include "elfcopy.h"
-ELFTC_VCSID("$Id: segments.c 3196 2015-05-12 17:33:48Z emaste $");
+ELFTC_VCSID("$Id: segments.c 3269 2015-12-11 18:38:43Z kaiwang27 $");
static void insert_to_inseg_list(struct segment *seg, struct section *sec);
@@ -77,8 +77,6 @@ add_to_inseg_list(struct elfcopy *ecp, struct section *s)
if (s->off + s->sz > seg->off + seg->fsz &&
s->type != SHT_NOBITS)
continue;
- if (s->off + s->sz > seg->off + seg->msz)
- continue;
if (s->vma + s->sz > seg->addr + seg->msz)
continue;
OpenPOWER on IntegriCloud