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.
===========
Check PPC64 specific relocation case.
Signed-off-by: Mohan Kumar M <[EMAIL PROTECTED]>
Signed-off-by: Eric W. Biederman <[EMAIL PROTECTED]>
---
kexec/kexec-elf-rel.c | 38 ++++++++++++++++----------------------
1 files changed, 16 insertions(+), 22 deletions(-)
aa3833fab8b5914563ec54a7a3e40c64e7d9d361
diff --git a/kexec/kexec-elf-rel.c b/kexec/kexec-elf-rel.c
index b55d2c2..46588f3 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;
if (shdr->sh_type == SHT_REL) {
rel = elf_rel(ehdr, ptr);
}
@@ -363,42 +364,35 @@ 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.
*/
- /*
+ 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 +457,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
> diff --git a/kexec/kexec-elf-rel.c b/kexec/kexec-elf-rel.c
> index b55d2c2..999d92a 100644
> --- a/kexec/kexec-elf-rel.c
> +++ b/kexec/kexec-elf-rel.c
> @@ -363,42 +363,36 @@ #ifdef DEBUG
> 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.
> */
> - /*
> + type = ELF32_ST_TYPE(sym.st_info);
> + if ((sym.st_shndx == STN_UNDEF) && (
> + (type == STT_NOTYPE) || (type == STT_OBJECT) ||
> + (type == STT_FUNC) || (type = STT_TLS)))
> 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 +457,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",
_______________________________________________
fastboot mailing list
[email protected]
https://lists.osdl.org/mailman/listinfo/fastboot