This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: informations in ELF?


Torsten Mohr <tmohr at s dot netic dot de> writes:

> at the moment i try to write some C++ classes
> that help reading/changing/writing ELF files.
> 
> Reading the file, interpreting its contents,
> getting the value of some symbols etc. works
> quite well.

It would seem appropriate to write wrappers around libelf for this.

> Section names are in section ".shstrtab", index
> "e_shstrndx".  Are all other symbols always in
> section ".strtab"?
> Or could there for example also be a section ".strtab2"
> or something like this?

When used properly, ELF isn't based on section names at all.

Non-dynamic symbols are in sections of type SHT_SYMTAB.  The sh_link
field is the index number of a section of type SHT_STRTAB, which holds
the names of the symbols.  The name of the latter section is normally
.strtab, but in principle it could be anything.

> 2.
> Can i somehow get the size of a pointer of the target
> machine from the ELF file?

Not directly, no.  You can look at e_machine field of the header to
get the architecture, and guess based on that.  However, for
architectures which can reasonably support multiple pointer sizes,
there isn't necessarily any way to tell which pointer size is actually
being used by a particular program.

> 3.
> What sections are copied by objcopy from the ELF
> file to e.g. an SREC file?
> Has (sh_type == PROGBITS && (sh_flags & ALLOC)) to
> be true?  I assume it is the condition above,
> is that right?

More or less, yes.  objcopy proper will copy any section which has
contents (i.e., SHT_PROGBITS).  The srec backend will discard any
section which is not both loadable and allocatable (i.e., SHF_ALLOC).

Ian


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]