[prev in list] [next in list] [prev in thread] [next in thread]
List: hpux-devtools
Subject: Re: HPUX-DEVTOOLS: shared library?
From: Eric Gouriou <egouriou () cup ! hp ! com>
Date: 2002-08-08 22:30:57
[Download RAW message or body]
"Rajiv K. Shukla" wrote:
> Use of 'dlopen' is undesirable, so is the use of
> 'file' command. For now, simple c code based on
> /etc/magic serves the purpose. Unfortunately, it's not
> very portable.
* For Elf shared libraries (PA64 or IPF ILP32 / LP64),
use /usr/include/elf.h .
The important elements are:
1) Check e_ident
char e_ident[EI_NIDENT];
is_elf = ( (ELFMAG0 == e_ident[EI_MAG0])
&& (ELFMAG1 == e_ident[EI_MAG1])
&& (ELFMAG2 == e_ident[EI_MAG2])
&& (ELFMAG3 == e_ident[EI_MAG3]));
2) If is_elf, read the Elf header (Elf<N>_Ehdr type)
Watch for Elf64 vs Elf32 formats (which are
_not_ necessarily linked to 32bit / 64bit ABIS)
See EI_CLASS in e_ident (ELFCLASS32 / ELFCLASS64)
Watch for endianness and byte-swap if necessary.
See EI_DATA in e_ident (ELFDATA2LSB / ELFDATA2MSB)
Read e_type.
Then: e_type -> ET_DYN shared library
ET_EXEC executable
others (.o , etc)
This should be pretty portable, but I am no expert
on object formats.
* For SOM files (to check for HP-UX PA32 shared libraries),
use /usr/include/filehdr.h, read the header content and
the fields check system_id and a_magic. Unfortunately I
don't know where/if the relevant constants are officially
documented, however you could piece this together from
/etc/magic:
system_id 0x20b -> PA1.0
0x210 -> PA1.1
0x214 -> PA2.0
a_magic 0x10E -> shared library
Obviously those checks can be fooled but a lot of
tools / the runtime will be unhappy if a file passes
those checks but isn't a shared library.
I hope this helps. No guarantee.
Eric
--
Eric Gouriou egouriou@cup.hp.com
_________________________________________________________________
To leave this mailing list, send mail to majordomo@cxx.cup.hp.com
with the message UNSUBSCRIBE hpux-devtools
_________________________________________________________________
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic