|
|
bb3be4 |
From 8c30fba366c6814c7bb1795fdda16265eb48efb0 Mon Sep 17 00:00:00 2001
|
|
|
bb3be4 |
From: Alan Modra <amodra@gmail.com>
|
|
|
bb3be4 |
Date: Sun, 8 Nov 2015 09:29:00 -0800
|
|
|
bb3be4 |
Subject: [PATCH 06/11] ELF unexec: _OBJC_ symbols in bss sections
|
|
|
bb3be4 |
|
|
|
bb3be4 |
This code assumed that there was only one bss section. Rather than
|
|
|
bb3be4 |
checking for a particular index, check the section type. Also, handle
|
|
|
bb3be4 |
the possibility that the section was SHT_NOBITS originally and is
|
|
|
bb3be4 |
unchanged, in which case no clearing is needed (and sh_offset isn't
|
|
|
bb3be4 |
necessarily valid, which can lead to a wild memset).
|
|
|
bb3be4 |
|
|
|
bb3be4 |
* unexelf.c (unexec): Properly handle _OBJC_ symbols in bss sections.
|
|
|
bb3be4 |
---
|
|
|
bb3be4 |
src/unexelf.c | 31 ++++++++++++++++++-------------
|
|
|
bb3be4 |
1 file changed, 18 insertions(+), 13 deletions(-)
|
|
|
bb3be4 |
|
|
|
bb3be4 |
diff --git a/src/unexelf.c b/src/unexelf.c
|
|
|
bb3be4 |
index 286ba2e..df99f92 100644
|
|
|
bb3be4 |
--- a/src/unexelf.c
|
|
|
bb3be4 |
+++ b/src/unexelf.c
|
|
|
bb3be4 |
@@ -1176,20 +1176,25 @@ temacs:
|
|
|
bb3be4 |
"_OBJC_", sizeof ("_OBJC_") - 1) == 0)
|
|
|
bb3be4 |
{
|
|
|
bb3be4 |
ElfW (Shdr) *new_shdr = &NEW_SECTION_H (symp->st_shndx);
|
|
|
bb3be4 |
- ptrdiff_t reladdr = symp->st_value - new_shdr->sh_addr;
|
|
|
bb3be4 |
- ptrdiff_t newoff = reladdr + new_shdr->sh_offset;
|
|
|
bb3be4 |
-
|
|
|
bb3be4 |
- /* "Unpatch" index. */
|
|
|
bb3be4 |
- nn = symp->st_shndx;
|
|
|
bb3be4 |
- if (nn > old_bss_index)
|
|
|
bb3be4 |
- nn--;
|
|
|
bb3be4 |
- if (nn == old_bss_index)
|
|
|
bb3be4 |
- memset (new_base + newoff, 0, symp->st_size);
|
|
|
bb3be4 |
- else
|
|
|
bb3be4 |
+ if (new_shdr->sh_type != SHT_NOBITS)
|
|
|
bb3be4 |
{
|
|
|
bb3be4 |
- ElfW (Shdr) *old_shdr = &OLD_SECTION_H (nn);
|
|
|
bb3be4 |
- ptrdiff_t oldoff = reladdr + old_shdr->sh_offset;
|
|
|
bb3be4 |
- memcpy (new_base + newoff, old_base + oldoff, symp->st_size);
|
|
|
bb3be4 |
+ ElfW (Shdr) *old_shdr;
|
|
|
bb3be4 |
+ ptrdiff_t reladdr = symp->st_value - new_shdr->sh_addr;
|
|
|
bb3be4 |
+ ptrdiff_t newoff = reladdr + new_shdr->sh_offset;
|
|
|
bb3be4 |
+
|
|
|
bb3be4 |
+ /* "Unpatch" index. */
|
|
|
bb3be4 |
+ nn = symp->st_shndx;
|
|
|
bb3be4 |
+ if (nn > old_bss_index)
|
|
|
bb3be4 |
+ nn--;
|
|
|
bb3be4 |
+ old_shdr = &OLD_SECTION_H (nn);
|
|
|
bb3be4 |
+ if (old_shdr->sh_type == SHT_NOBITS)
|
|
|
bb3be4 |
+ memset (new_base + newoff, 0, symp->st_size);
|
|
|
bb3be4 |
+ else
|
|
|
bb3be4 |
+ {
|
|
|
bb3be4 |
+ ptrdiff_t oldoff = reladdr + old_shdr->sh_offset;
|
|
|
bb3be4 |
+ memcpy (new_base + newoff, old_base + oldoff,
|
|
|
bb3be4 |
+ symp->st_size);
|
|
|
bb3be4 |
+ }
|
|
|
bb3be4 |
}
|
|
|
bb3be4 |
}
|
|
|
bb3be4 |
#endif
|
|
|
bb3be4 |
--
|
|
|
bb3be4 |
2.7.4
|
|
|
bb3be4 |
|