Go to:
Gentoo Home
Documentation
Forums
Lists
Bugs
Planet
Store
Wiki
Get Gentoo!
Gentoo's Bugzilla – Attachment 393046 Details for
Bug 534206
sys-apps/portage: NEEDED.ELF.2 does not distinguish all possible ABI types, such as x32 for x86_64, and various MIPS multilib ABIs
Home
|
New
–
[Ex]
|
Browse
|
Search
|
Privacy Policy
|
[?]
|
Reports
|
Requests
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
elf-multilib-id.py: reference implementation for generating a multilib identifier
elf-multilib-id.py (text/x-python), 4.58 KB, created by
Zac Medico
on 2015-01-03 08:45:44 UTC
(
hide
)
Description:
elf-multilib-id.py: reference implementation for generating a multilib identifier
Filename:
MIME Type:
Creator:
Zac Medico
Created:
2015-01-03 08:45:44 UTC
Size:
4.58 KB
patch
obsolete
>#!/usr/bin/env python ># ># Compute a multilib ABI identifier, as discussed here: ># ># https://bugs.gentoo.org/show_bug.cgi?id=534206 ># ># Supported identifiers: ># ># alpha_{32,64} ># arm_{32,64} ># hppa_{32,64} ># ia_{32,64} ># m68k_{32,64} ># mips_{eabi32,eabi64,n32,n64,o32,o64} ># ppc_{32,64} ># s390_{32,64} ># sh_{32,64} ># sparc_{32,64} ># x86_{32,64,x64} ># ># NOTES: ># ># * The ABIs referenced by some of the above *_32 and *_64 identifiers ># may be imaginary, but they are listed anyway, since the goal is to ># establish a naming convention that is as consistent and uniform as ># possible. ># ># * The Elf header's e_ident[EI_OSABI] byte is completely ignored, ># since OS-independence is one of the goals. The assumption is that, ># for given installation, we are only interested in tracking multilib ># ABIs for a single OS. > >from __future__ import print_function > >import collections >import os >import sys > >USAGE = "%s <filename>\n" > >EI_CLASS = 4 >ELFCLASS32 = 1 >ELFCLASS64 = 2 > >EI_DATA = 5 >ELFDATA2LSB = 1 >ELFDATA2MSB = 2 > >E_MACHINE = 18 >EM_SPARC = 2 >EM_386 = 3 >EM_68K = 4 >EM_MIPS = 8 >EM_PARISC = 15 >EM_SPARC32PLUS = 18 >EM_PPC = 20 >EM_PPC64 = 21 >EM_S390 = 22 >EM_ARM = 40 >EM_ALPHA = 41 >EM_SH = 42 >EM_SPARCV9 = 43 >EM_IA_64 = 50 >EM_X86_64 = 62 >EM_AARCH64 = 183 > >E_ENTRY = 24 >EF_MIPS_ABI = 0x0000F000 >EF_MIPS_ABI2 = 0x00000020 >E_MIPS_ABI_O32 = 0x00001000 >E_MIPS_ABI_O64 = 0x00002000 >E_MIPS_ABI_EABI32 = 0x00003000 >E_MIPS_ABI_EABI64 = 0x00004000 > >machine_prefix_map = { > EM_386: "x86", > EM_68K: "m68k", > EM_AARCH64: "arm", > EM_ALPHA: "alpha", > EM_ARM: "arm", > EM_IA_64: "ia", > EM_MIPS: "mips", > EM_PARISC: "hppa", > EM_PPC: "ppc", > EM_PPC64: "ppc", > EM_S390: "s390", > EM_SH: "sh", > EM_SPARC: "sparc", > EM_SPARC32PLUS: "sparc", > EM_SPARCV9: "sparc", > EM_X86_64: "x86", >} > >_elf_header = collections.namedtuple('_elf_header', > ('ei_class', 'ei_data', 'e_machine', 'e_flags')) > >def compute_suffix_mips(elf_header): > > name = None > mips_abi = elf_header.e_flags & EF_MIPS_ABI > > if mips_abi: > if mips_abi == E_MIPS_ABI_O32: > name = "o32" > elif mips_abi == E_MIPS_ABI_O64: > name = "o64" > elif mips_abi == E_MIPS_ABI_EABI32: > name = "eabi32" > elif mips_abi == E_MIPS_ABI_EABI64: > name = "eabi64" > > elif elf_header.e_flags & EF_MIPS_ABI2: > name = "n32" > elif elf_header.ei_class == ELFCLASS64: > name = "n64" > > return name > >def compute_multilib_id(elf_header): > > prefix = machine_prefix_map.get(elf_header.e_machine) > suffix = None > > if prefix == "mips": > suffix = compute_suffix_mips(elf_header) > elif elf_header.ei_class == ELFCLASS64: > suffix = "64" > elif elf_header.ei_class == ELFCLASS32: > if elf_header.e_machine == EM_X86_64: > suffix = "x32" > else: > suffix = "32" > > if prefix is None or suffix is None: > multilib_id = None > else: > multilib_id = "%s_%s" % (prefix, suffix) > > return multilib_id > >def uint16_be(data): > return (ord(data[0:1]) << 8) + ord(data[1:2]) > >def uint16_le(data): > return ord(data[0:1]) + (ord(data[1:2]) << 8) > >def uint32_be(data): > return ( > (ord(data[0:1]) << 24) + > (ord(data[1:2]) << 16) + > (ord(data[2:3]) << 8) + > ord(data[3:4]) > ) > >def uint32_le(data): > return ( > ord(data[0:1]) + > (ord(data[1:2]) << 8) + > (ord(data[2:3]) << 16) + > (ord(data[3:4]) << 24) > ) > >def read_elf_header(f): > > f.seek(EI_CLASS) > ei_class = ord(f.read(1)) > ei_data = ord(f.read(1)) > > if ei_class == ELFCLASS32: > width = 32 > elif ei_class == ELFCLASS64: > width = 64 > else: > width = None > > if ei_data == ELFDATA2LSB: > uint16 = uint16_le > uint32 = uint32_le > elif ei_data == ELFDATA2MSB: > uint16 = uint16_be > uint32 = uint32_be > else: > uint16 = None > uint32 = None > > if width is None or uint16 is None: > e_machine = None > e_flags = None > else: > f.seek(E_MACHINE) > e_machine = uint16(f.read(2)) > > # E_ENTRY + 3 * sizeof(uintN) > e_flags_offset = E_ENTRY + 3 * width // 8 > f.seek(e_flags_offset) > e_flags = uint32(f.read(4)) > > return _elf_header(ei_class, ei_data, e_machine, e_flags) > >def main(argv): > > if len(argv) != 2 or not os.path.isfile(argv[1]): > sys.stderr.write(USAGE % argv[0]) > return 1 > > with open(argv[1], 'rb') as f: > elf_header = read_elf_header(f) > > if elf_header.e_machine is None: > multilib_id = None > else: > multilib_id = compute_multilib_id(elf_header) > > print(multilib_id) > return multilib_id is None and 1 or os.EX_OK > >if __name__ == "__main__": > sys.exit(main(sys.argv))
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 534206
:
393042
| 393046 |
393378