This is the mail archive of the libc-help@sourceware.org mailing list for the glibc 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: How to implement a kernel feature check in the crt* files?


On Fri, Jan 08, 2010 at 01:54:22PM +0100, Andreas Krebbel wrote:
> Hi Roland,
> 
> >There is a reliable method using AT_PHDR.  Find the first PT_LOAD with
> >p_offset=0 (in practice it's always the first there is) and its p_vaddr
> >is where the ELF header appears in memory.
> >
> Thanks! That sounds like a good solution. Unfortunately while implementing 
> it I stumbled over another problem.  Using AT_PHDR for locating the ELF 
> header will
> not work if the executable is not directly executed by the kernel e.g.
> if it is passed as parameter to ld.so.  Then AT_PHDR will point to the
> program headers of ld.so instead of the executable.  I'm not sure how to
> work around this.  I think the situation can be detected by comparing the 
> AT_ENTRY field with the first IP in _start but finding the ELF header using 
> the AT_PHDR will be impossible then.  Perhaps it is ok to simply skip 
> checking in
> that case?!

What you could do is set e_flags bit (in both object files and
executables/shared libraries) and, additionally, when .note.ABI-tag
section is added in the final link (well, just look for
ELF_NOTE_GNU note with ELF_NOTE_ABI and version smaller than 2.6.32,
adjust it to 2.6.32) in the linker.  Then you don't need to add
any runtime code and it will work even with older kernels.
It is ugly, but ELF_NOTE_ABI is well defined and avoiding very ugly runtime
code is desirable.

	Jakub


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