Hi Joseph Koshy,

Thanks. I find that elf_rawdata does not check the section type. I'll try it.
Is it needed to add arch specific sections support to elf_getdata or the arch specific sections should be handled using elf_rawdata by the caller ? I am not sure about this.

Regards,
Peng 


2013/7/1 Joseph Koshy <jkoshy@users.sourceforge.net>
Hello Peng Fan,

> I am trying to use elftoolchain to handle arm elf object files.
> But I always get error when handling ".ARM.attributes, .ARM.exidx ,
> .ARM.extab " sections.
>
> I traced the source code and found that it fails at elf_data.c line 93.
> The following is a piece of code.
>
> if ((elftype = _libelf_xlate_shtype(sh_type)) < ELF_T_FIRST ||
>    elftype > ELF_T_LAST || (sh_type != SHT_NOBITS &&
>    sh_offset + sh_size > (uint64_t) e->e_rawsize)) {
> LIBELF_SET_ERROR(SECTION, 0);
> return (NULL);
> }
> The .ARM.* sections are specific to ARM and the _libelf_xlate_shtype
> function does not handle such
> arch specific sections.
>
> I have a question about how to add support for arch specific sections, not
> only to arm, but also other archs.
>
> I added the following code before invoke  _libelf_xlate_shtype  to handle
> arm specific sections, but I am not
>  sure whether this is the right way.
>
>   if (s->s_elf->e_u.e_elf.e_ehdr.e_ehdr32->e_machine == EM_ARM) {
>     if ((sh_type == 0x70000003) || (sh_type == 0x70000001)) {
>       if ((d = _libelf_allocate_data(s)) == NULL)
>         return (NULL);
>       d->d_buf = 0;
>       d->d_size = 0;
>       return (d);
>     }
>   }
>    if ((elftype = _libelf_xlate_shtype(sh_type)) < ELF_T_FIRST ||
>
> Thanks very much.

libelf doesn't know how to translate processor specific sections like the above.

You could try the elf_rawdata() API, if you need access to the raw
data in these sections.

HTH,
Joseph Koshy