diff options
| author | Roland McGrath <[email protected]> | 2007-05-18 08:59:43 +0000 |
|---|---|---|
| committer | Roland McGrath <[email protected]> | 2007-05-18 08:59:43 +0000 |
| commit | 9aa8ef7fbb5ada14b7c4585d6c1361aa5eab6f88 (patch) | |
| tree | c4f8af4da6f99ec9b5cc07a90268305c1c7a9853 /src/strip.c | |
| parent | 2be0291b2cc06fc253c73a1564b126580c8f5ea2 (diff) | |
src/
2007-05-18 Roland McGrath <[email protected]>
* unstrip.c (copy_elided_sections): Match up non-NOBITS sections with
stripped file, so as not to duplicate a section copied in both.
* strip.c (handle_elf): Keep SHT_NOTE section copies in the debug file.
tests/
2007-05-18 Roland McGrath <[email protected]>
* run-strip-test4.sh (stripped, debugfile): Use new reference files.
* testfile37.bz2: New data file.
* testfile37.debug.bz2: New data file.
* run-unstrip-test2.sh: New file.
* Makefile.am (TESTS, EXTRA_DIST): Add them.
Diffstat (limited to 'src/strip.c')
| -rw-r--r-- | src/strip.c | 51 |
1 files changed, 31 insertions, 20 deletions
diff --git a/src/strip.c b/src/strip.c index 95eded65..5a2da646 100644 --- a/src/strip.c +++ b/src/strip.c @@ -835,6 +835,7 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, elf_errmsg (-1)); bool discard_section = (shdr_info[cnt].idx > 0 + && shdr_info[cnt].shdr.sh_type != SHT_NOTE && cnt != ehdr->e_shstrndx); /* Set the section header in the new file. */ @@ -1251,6 +1252,24 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, symbol table. */ for (cnt = 1; cnt <= shdridx; ++cnt) { + /* Update section headers when the data size has changed. + We also update the SHT_NOBITS section in the debug + file so that the section headers match in sh_size. */ + inline void update_section_size (const Elf_Data *newdata) + { + GElf_Shdr shdr_mem; + GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem); + shdr->sh_size = newdata->d_size; + (void) gelf_update_shdr (scn, shdr); + if (debugelf != NULL) + { + /* libelf will use d_size to set sh_size. */ + Elf_Data *debugdata = elf_getdata (elf_getscn (debugelf, + cnt), NULL); + debugdata->d_size = newdata->d_size; + } + } + if (shdr_info[cnt].idx == 0 && debug_fname == NULL) /* Ignore sections which are discarded. When we are saving a relocation section in a separate debug file, we must fix up @@ -1354,12 +1373,9 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, Elf32_Word *chain = bucket + nbucket; /* New size of the section. */ - GElf_Shdr shdr_mem; - GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem); - shdr->sh_size = hashd->d_size - = (2 + symd->d_size / elsize + nbucket) - * sizeof (Elf32_Word); - (void) gelf_update_shdr (scn, shdr); + hashd->d_size = ((2 + symd->d_size / elsize + nbucket) + * sizeof (Elf32_Word)); + update_section_size (hashd); /* Clear the arrays. */ memset (bucket, '\0', @@ -1411,12 +1427,9 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, Elf64_Xword *chain = bucket + nbucket; /* New size of the section. */ - GElf_Shdr shdr_mem; - GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem); - shdr->sh_size = hashd->d_size - = (2 + symd->d_size / elsize + nbucket) - * sizeof (Elf64_Xword); - (void) gelf_update_shdr (scn, shdr); + hashd->d_size = ((2 + symd->d_size / elsize + nbucket) + * sizeof (Elf64_Xword)); + update_section_size (hashd); /* Clear the arrays. */ memset (bucket, '\0', @@ -1492,14 +1505,12 @@ handle_elf (int fd, Elf *elf, const char *prefix, const char *fname, verstab[newsymidx[inner]] = verstab[inner]; /* New size of the section. */ - GElf_Shdr shdr_mem; - GElf_Shdr *shdr = gelf_getshdr (scn, &shdr_mem); - shdr->sh_size = verd->d_size - = gelf_fsize (newelf, verd->d_type, - symd->d_size / gelf_fsize (elf, symd->d_type, 1, - ehdr->e_version), - ehdr->e_version); - (void) gelf_update_shdr (scn, shdr); + verd->d_size = gelf_fsize (newelf, verd->d_type, + symd->d_size + / gelf_fsize (elf, symd->d_type, 1, + ehdr->e_version), + ehdr->e_version); + update_section_size (verd); } else if (shdr_info[cnt].shdr.sh_type == SHT_GROUP) { |
