summaryrefslogtreecommitdiffstats
path: root/src/strip.c
diff options
context:
space:
mode:
authorRoland McGrath <[email protected]>2005-08-10 08:10:07 +0000
committerRoland McGrath <[email protected]>2005-08-10 08:10:07 +0000
commitce4550aefd57ab68f6f279a5b662eb1716d7b361 (patch)
tree1c03a09458b835fbf87f9658cd770340fc5fab15 /src/strip.c
parentfaf4d19ddeaca1e7fd97b025ccd376eaa3afb30a (diff)
Update DW_LNS_set_epilogue_begin uses to correct misspelling.
Diffstat (limited to 'src/strip.c')
-rw-r--r--src/strip.c78
1 files changed, 49 insertions, 29 deletions
diff --git a/src/strip.c b/src/strip.c
index 42e13b46..37f9eb0e 100644
--- a/src/strip.c
+++ b/src/strip.c
@@ -199,7 +199,8 @@ warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n\
/* Handle program arguments. */
static error_t
-parse_opt (int key, char *arg, struct argp_state *state)
+parse_opt (int key, char *arg,
+ struct argp_state *state __attribute__ ((unused)))
{
switch (key)
{
@@ -368,10 +369,14 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
size_t fname_len = strlen (fname) + 1;
char *fullname = alloca (prefix_len + 1 + fname_len);
char *cp = fullname;
+ Elf *newelf;
Elf *debugelf = NULL;
char *tmp_debug_fname = NULL;
int result = 0;
+ GElf_Ehdr ehdr_mem;
+ GElf_Ehdr *ehdr;
size_t shstrndx;
+ size_t shnum;
struct shdr_info
{
Elf_Scn *scn;
@@ -457,8 +462,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
}
/* Get the information from the old file. */
- GElf_Ehdr ehdr_mem;
- GElf_Ehdr *ehdr = gelf_getehdr (elf, &ehdr_mem);
+ ehdr = gelf_getehdr (elf, &ehdr_mem);
if (ehdr == NULL)
INTERNAL_ERROR (fname);
@@ -470,7 +474,6 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
/* We now create a new ELF descriptor for the same file. We
construct it almost exactly in the same way with some information
dropped. */
- Elf *newelf;
if (output_fname != NULL)
newelf = elf_begin (fd, ELF_C_WRITE_MMAP, NULL);
else
@@ -490,7 +493,9 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
for (cnt = 0; cnt < ehdr->e_phnum; ++cnt)
{
GElf_Phdr phdr_mem;
- GElf_Phdr *phdr = gelf_getphdr (elf, cnt, &phdr_mem);
+ GElf_Phdr *phdr;
+
+ phdr = gelf_getphdr (elf, cnt, &phdr_mem);
if (phdr == NULL
|| unlikely (gelf_update_phdr (newelf, cnt, phdr) == 0))
INTERNAL_ERROR (fname);
@@ -514,7 +519,9 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
for (cnt = 0; cnt < ehdr->e_phnum; ++cnt)
{
GElf_Phdr phdr_mem;
- GElf_Phdr *phdr = gelf_getphdr (elf, cnt, &phdr_mem);
+ GElf_Phdr *phdr;
+
+ phdr = gelf_getphdr (elf, cnt, &phdr_mem);
if (phdr == NULL
|| unlikely (gelf_update_phdr (debugelf, cnt, phdr) == 0))
INTERNAL_ERROR (fname);
@@ -522,7 +529,6 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
}
/* Number of sections. */
- size_t shnum;
if (unlikely (elf_getshnum (elf, &shnum) < 0))
{
error (0, 0, gettext ("cannot determine number of sections: %s"),
@@ -590,6 +596,9 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
}
else if (unlikely (shdr_info[cnt].shdr.sh_type == SHT_GROUP))
{
+ Elf32_Word *grpref;
+ size_t inner;
+
/* Cross-reference the sections contained in the section
group. */
shdr_info[cnt].data = elf_getdata (shdr_info[cnt].scn, NULL);
@@ -597,8 +606,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
INTERNAL_ERROR (fname);
/* XXX Fix for unaligned access. */
- Elf32_Word *grpref = (Elf32_Word *) shdr_info[cnt].data->d_buf;
- size_t inner;
+ grpref = (Elf32_Word *) shdr_info[cnt].data->d_buf;
for (inner = 1;
inner < shdr_info[cnt].data->d_size / sizeof (Elf32_Word);
++inner)
@@ -657,14 +665,16 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
idx = shdr_info[cnt].group_idx;
while (idx != 0)
{
- /* The section group data is already loaded. */
- assert (shdr_info[idx].data != NULL);
-
/* If the references section group is a normal section
group and has one element remaining, or if it is an
empty COMDAT section group it is removed. */
- bool is_comdat = (((Elf32_Word *) shdr_info[idx].data->d_buf)[0]
- & GRP_COMDAT) != 0;
+ bool is_comdat;
+
+ /* The section group data is already loaded. */
+ assert (shdr_info[idx].data != NULL);
+
+ is_comdat = (((Elf32_Word *) shdr_info[idx].data->d_buf)[0]
+ & GRP_COMDAT) != 0;
--shdr_info[idx].group_cnt;
if ((!is_comdat && shdr_info[idx].group_cnt == 1)
@@ -710,6 +720,10 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
if (shdr_info[cnt].shdr.sh_type == SHT_DYNSYM
|| shdr_info[cnt].shdr.sh_type == SHT_SYMTAB)
{
+ Elf_Data *symdata;
+ Elf_Data *xndxdata;
+ size_t elsize;
+
/* Make sure the data is loaded. */
if (shdr_info[cnt].data == NULL)
{
@@ -718,7 +732,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
if (shdr_info[cnt].data == NULL)
INTERNAL_ERROR (fname);
}
- Elf_Data *symdata = shdr_info[cnt].data;
+ symdata = shdr_info[cnt].data;
/* If there is an extended section index table load it
as well. */
@@ -733,13 +747,11 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
if (shdr_info[shdr_info[cnt].symtab_idx].data == NULL)
INTERNAL_ERROR (fname);
}
- Elf_Data *xndxdata
- = shdr_info[shdr_info[cnt].symtab_idx].data;
+ xndxdata = shdr_info[shdr_info[cnt].symtab_idx].data;
/* Go through all symbols and make sure the section they
reference is not removed. */
- size_t elsize = gelf_fsize (elf, ELF_T_SYM, 1,
- ehdr->e_version);
+ elsize = gelf_fsize (elf, ELF_T_SYM, 1, ehdr->e_version);
for (size_t inner = 0;
inner < shdr_info[cnt].data->d_size / elsize;
@@ -747,13 +759,15 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
{
GElf_Sym sym_mem;
Elf32_Word xndx;
- GElf_Sym *sym = gelf_getsymshndx (symdata, xndxdata,
- inner, &sym_mem,
- &xndx);
+ GElf_Sym *sym;
+ size_t scnidx;
+
+ sym = gelf_getsymshndx (symdata, xndxdata, inner,
+ &sym_mem, &xndx);
if (sym == NULL)
INTERNAL_ERROR (fname);
- size_t scnidx = sym->st_shndx;
+ scnidx = sym->st_shndx;
if (scnidx == SHN_UNDEF || scnidx >= shnum
|| (scnidx >= SHN_LORESERVE
&& scnidx <= SHN_HIRESERVE
@@ -816,17 +830,20 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
{
for (cnt = 1; cnt < shnum; ++cnt)
{
+ Elf_Data *debugdata;
+ GElf_Shdr debugshdr;
+ bool discard_section;
+
scn = elf_newscn (debugelf);
if (scn == NULL)
error (EXIT_FAILURE, 0,
gettext ("while generating output file: %s"),
elf_errmsg (-1));
- bool discard_section = (shdr_info[cnt].idx > 0
- && cnt != ehdr->e_shstrndx);
+ discard_section = shdr_info[cnt].idx > 0 && cnt != ehdr->e_shstrndx;
/* Set the section header in the new file. */
- GElf_Shdr debugshdr = shdr_info[cnt].shdr;
+ debugshdr = shdr_info[cnt].shdr;
if (discard_section)
debugshdr.sh_type = SHT_NOBITS;
@@ -843,7 +860,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
}
/* Set the data. This is done by copying from the old file. */
- Elf_Data *debugdata = elf_newdata (scn);
+ debugdata = elf_newdata (scn);
if (debugdata == NULL)
INTERNAL_ERROR (fname);
@@ -914,6 +931,9 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
/* Create the reference to the file with the debug info. */
if (debug_fname != NULL)
{
+ char *debug_basename;
+ off_t crc_offset;
+
/* Add the section header string table section name. */
shdr_info[cnt].se = ebl_strtabadd (shst, ".gnu_debuglink", 15);
shdr_info[cnt].idx = idx++;
@@ -944,8 +964,8 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname,
error (EXIT_FAILURE, 0, gettext ("cannot allocate section data: %s"),
elf_errmsg (-1));
- char *debug_basename = basename (debug_fname_embed ?: debug_fname);
- off_t crc_offset = strlen (debug_basename) + 1;
+ debug_basename = basename (debug_fname_embed ?: debug_fname);
+ crc_offset = strlen (debug_basename) + 1;
/* Align to 4 byte boundary */
crc_offset = ((crc_offset - 1) & ~3) + 4;