On Tue, Aug 08, 2006 at 03:50:18PM +0530, Mohan Kumar M wrote:
> On Thu, Aug 03, 2006 at 12:35:31PM -0600, Eric W. Biederman wrote:
> > Ok. We are close. All of the relocations work as long as value is
> > computed correctly.
> >
> > The final question then is can we limit the type of symbols for which
> > we support an SHN_UNDEF value. So we can still catch programmers errors.
> >
> > I think if we simply don't support STT_OBJECT, STT_FUNC, and STT_TLS,
> > we will catch all of the problems I an worried about while still handling
> > the relocations in your opd section. I threw in STT_NOTYPE for good
> > measure as I don't think that case should ever happen in practice.
> >
> > Does this patch work for you?
> >
>
> Eric,
>
> Your patch didn't work for PPC64.
>
> The retrieved symbol for R_PPC64_TOC relocation type is STN_UNDEF and
> type is STT_NOTYPE. So the condition is always met and it dies.
>
> It will be better to check for rel.r_type as this issue is unique to
> PPC64. I have tested this condition with some undefined symbols and
> undefined functions in the purgatory code and the code could die as desired.
>
> Here is the patch.
>
>
Eric,
There was a small issue with my previous patch, So I am posting the
corrected one here. Previous patch did not check for the elf type (elf32
or elf64) for getting the symbol type. This patch does the required
check.
Any comment?
======
Check for PPC64 specific relocation case.
Signed-off-by: Mohan Kumar <[EMAIL PROTECTED]>
Signed-off-by: Eric W. Biederman <[EMAIL PROTECTED]>
---
kexec/kexec-elf-rel.c | 42 ++++++++++++++++++++----------------------
1 files changed, 20 insertions(+), 22 deletions(-)
275c1c82f95a73060f8e26fe49f2cb054108db89
diff --git a/kexec/kexec-elf-rel.c b/kexec/kexec-elf-rel.c
index b55d2c2..f4d6bb3 100644
--- a/kexec/kexec-elf-rel.c
+++ b/kexec/kexec-elf-rel.c
@@ -339,6 +339,7 @@ int elf_rel_load(struct mem_ehdr *ehdr,
struct mem_sym sym;
const void *location;
unsigned long address, value, sec_base;
+ int type = -1;
if (shdr->sh_type == SHT_REL) {
rel = elf_rel(ehdr, ptr);
}
@@ -363,42 +364,39 @@ int elf_rel_load(struct mem_ehdr *ehdr,
sym.st_size);
#endif
- if (sym.st_shndx == STN_UNDEF) {
- /*
- * NOTE: ppc64 elf .ro shows up a UNDEF section.
- * From Elf 1.2 Spec:
- * Relocation Entries: If the index is STN_UNDEF,
- * the undefined symbol index, the relocation uses 0
- * as the "symbol value".
- * So, is this really an error condition to flag die?
+ /* Don't support weak symbols in purgatory.
+ * They usually indicate that some one has fogotten
+ * to define a variable, or a function.
*/
- /*
+ if (ehdr->ei_class == ELFCLASS32)
+ type = ELF32_ST_TYPE(sym.st_info);
+ else if (ehdr->ei_class == ELFCLASS64)
+ type = ELF64_ST_TYPE(sym.st_info);
+
+ if (sym.st_shndx == STN_UNDEF &&
+ (type != STT_NOTYPE || rel.r_type != R_PPC64_TOC))
die("Undefined symbol: %s\n",
strtab + sym.st_name);
- */
- continue;
- }
+
sec_base = 0;
- if (sym.st_shndx == SHN_COMMON) {
+ value = sym.st_value;
+ if (sym.st_shndx == SHN_COMMON)
die("symbol: '%s' in common section\n",
strtab + sym.st_name);
- }
- else if (sym.st_shndx == SHN_ABS) {
+ else if (sym.st_shndx == SHN_UNDEF)
+ value = 0;
+ else if (sym.st_shndx == SHN_ABS)
sec_base = 0;
- }
- else if (sym.st_shndx > ehdr->e_shnum) {
+ else if (sym.st_shndx > ehdr->e_shnum)
die("Invalid section: %d for symbol %s\n",
sym.st_shndx,
strtab + sym.st_name);
- }
- else {
+ else
sec_base = ehdr->e_shdr[sym.st_shndx].sh_addr;
- }
#ifdef DEBUG
fprintf(stderr, "sym: %s value: %lx addr: %lx\n",
strtab + sym.st_name, value, address);
#endif
- value = sym.st_value;
value += sec_base;
value += rel.r_addend;
machine_apply_elf_rel(ehdr, rel.r_type,
@@ -463,7 +461,7 @@ int elf_rel_find_symbol(struct mem_ehdr
if (strcmp(strtab + sym.st_name, name) != 0) {
continue;
}
- if ((sym.st_shndx == STN_UNDEF) ||
+ if ((sym.st_shndx == SHN_UNDEF) ||
(sym.st_shndx > ehdr->e_shnum))
{
die("Symbol: %s has Bad section index %d\n",
--
1.0.GIT
==========
Regards,
Mohan
_______________________________________________
fastboot mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/fastboot