[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 5/8] ELF unexec: _OBJC_ symbols in bss sections
From: |
Alan Modra |
Subject: |
[PATCH 5/8] ELF unexec: _OBJC_ symbols in bss sections |
Date: |
Mon, 2 Nov 2015 12:27:19 +1030 |
User-agent: |
Mutt/1.5.23 (2014-03-12) |
This code assumed that there was only one bss section. Rather than
checking for a particular index, check the section type. Also, handle
the possibility that the section was SHT_NOBITS originally and is
unchanged, in which case no clearing is needed (and sh_offset isn't
necessarily valid, which can lead to a wild memset).
* unexelf.c (unexec): Properly handle _OBJC_ symbols in bss sections.
diff --git a/src/unexelf.c b/src/unexelf.c
index 286ba2e..df99f92 100644
--- a/src/unexelf.c
+++ b/src/unexelf.c
@@ -1176,20 +1176,25 @@ temacs:
"_OBJC_", sizeof ("_OBJC_") - 1) == 0)
{
ElfW (Shdr) *new_shdr = &NEW_SECTION_H (symp->st_shndx);
- ptrdiff_t reladdr = symp->st_value - new_shdr->sh_addr;
- ptrdiff_t newoff = reladdr + new_shdr->sh_offset;
-
- /* "Unpatch" index. */
- nn = symp->st_shndx;
- if (nn > old_bss_index)
- nn--;
- if (nn == old_bss_index)
- memset (new_base + newoff, 0, symp->st_size);
- else
+ if (new_shdr->sh_type != SHT_NOBITS)
{
- ElfW (Shdr) *old_shdr = &OLD_SECTION_H (nn);
- ptrdiff_t oldoff = reladdr + old_shdr->sh_offset;
- memcpy (new_base + newoff, old_base + oldoff, symp->st_size);
+ ElfW (Shdr) *old_shdr;
+ ptrdiff_t reladdr = symp->st_value - new_shdr->sh_addr;
+ ptrdiff_t newoff = reladdr + new_shdr->sh_offset;
+
+ /* "Unpatch" index. */
+ nn = symp->st_shndx;
+ if (nn > old_bss_index)
+ nn--;
+ old_shdr = &OLD_SECTION_H (nn);
+ if (old_shdr->sh_type == SHT_NOBITS)
+ memset (new_base + newoff, 0, symp->st_size);
+ else
+ {
+ ptrdiff_t oldoff = reladdr + old_shdr->sh_offset;
+ memcpy (new_base + newoff, old_base + oldoff,
+ symp->st_size);
+ }
}
}
#endif
--
Alan Modra
Australia Development Lab, IBM
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [PATCH 5/8] ELF unexec: _OBJC_ symbols in bss sections,
Alan Modra <=