From f6cdba7689ea423245a232cc13103dd988363845 Mon Sep 17 00:00:00 2001 From: WANG Xuerui Date: Mon, 9 Aug 2021 15:31:25 +0800 Subject: [PATCH] multilib_category.py: recognize LoongArch ABIs Add its ELF machine number constant as well. The Gentoo ARCH is "loong"; all six ABIs defined in the LoongArch ELF psABI spec [1] are supported. The upstream binutils port currently implements an earlier version of the spec [2]; the ILP32 ABIs are never fully implemented so far, and the value for LP64D is coincidentally the same, so the code here stays compatible. This is preparatory work towards a port to the LoongArch architecture, which is the new RISC architecture from Loongson Corporation after switching away from MIPS. [1]: https://github.com/loongson/LoongArch-Documentation/blob/23d53fe146a4/docs/LoongArch-ELF-ABI-EN.adoc [2]: https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=include/elf/loongarch.h;h=b4d801ae9bd5a6c4562ca6b1cbae6e6d45d6c704;hb=HEAD Signed-off-by: WANG Xuerui Closes: https://github.com/gentoo/portage/pull/740 Signed-off-by: Sam James --- lib/portage/dep/soname/multilib_category.py | 26 +++++++++++++++++++++ lib/portage/util/elf/constants.py | 9 +++++++ 2 files changed, 35 insertions(+) diff --git a/lib/portage/dep/soname/multilib_category.py b/lib/portage/dep/soname/multilib_category.py index ab855d339..567b1d32e 100644 --- a/lib/portage/dep/soname/multilib_category.py +++ b/lib/portage/dep/soname/multilib_category.py @@ -11,6 +11,7 @@ # arm_{32,64} # hppa_{32,64} # ia_{32,64} +# loong_{ilp32s,ilp32f,ilp32d,lp64s,lp64f,lp64d} # m68k_{32,64} # mips_{eabi32,eabi64,n32,n64,o32,o64} # ppc_{32,64} @@ -37,6 +38,13 @@ from portage.util.elf.constants import ( EF_MIPS_ABI2, EF_RISCV_FLOAT_ABI_DOUBLE, EF_RISCV_RVC, + EF_LOONGARCH_ABI_LP64_SOFT_FLOAT, + EF_LOONGARCH_ABI_LP64_SINGLE_FLOAT, + EF_LOONGARCH_ABI_LP64_DOUBLE_FLOAT, + EF_LOONGARCH_ABI_ILP32_SOFT_FLOAT, + EF_LOONGARCH_ABI_ILP32_SINGLE_FLOAT, + EF_LOONGARCH_ABI_ILP32_DOUBLE_FLOAT, + EF_LOONGARCH_ABI_MASK, ELFCLASS32, ELFCLASS64, EM_386, @@ -46,6 +54,7 @@ from portage.util.elf.constants import ( EM_ARM, EM_ALTERA_NIOS2, EM_IA_64, + EM_LOONGARCH, EM_MIPS, EM_PARISC, EM_PPC, @@ -71,6 +80,7 @@ _machine_prefix_map = { EM_ALTERA_NIOS2: "nios2", EM_ARM: "arm", EM_IA_64: "ia64", + EM_LOONGARCH: "loong", EM_MIPS: "mips", EM_PARISC: "hppa", EM_PPC: "ppc", @@ -84,6 +94,15 @@ _machine_prefix_map = { EM_X86_64: "x86", } +_loong_abi_map = { + EF_LOONGARCH_ABI_LP64_SOFT_FLOAT: "lp64s", + EF_LOONGARCH_ABI_LP64_SINGLE_FLOAT: "lp64f", + EF_LOONGARCH_ABI_LP64_DOUBLE_FLOAT: "lp64d", + EF_LOONGARCH_ABI_ILP32_SOFT_FLOAT: "ilp32s", + EF_LOONGARCH_ABI_ILP32_SINGLE_FLOAT: "ilp32f", + EF_LOONGARCH_ABI_ILP32_DOUBLE_FLOAT: "ilp32d", +} + _mips_abi_map = { E_MIPS_ABI_EABI32: "eabi32", E_MIPS_ABI_EABI64: "eabi64", @@ -92,6 +111,12 @@ _mips_abi_map = { } +def _compute_suffix_loong(elf_header): + + loong_abi = elf_header.e_flags & EF_LOONGARCH_ABI_MASK + return _loong_abi_map.get(loong_abi) + + def _compute_suffix_mips(elf_header): name = None @@ -136,6 +161,7 @@ def _compute_suffix_riscv(elf_header): _specialized_funcs = { + "loong": _compute_suffix_loong, "mips": _compute_suffix_mips, "riscv": _compute_suffix_riscv, } diff --git a/lib/portage/util/elf/constants.py b/lib/portage/util/elf/constants.py index d86b39483..19b72cfa1 100644 --- a/lib/portage/util/elf/constants.py +++ b/lib/portage/util/elf/constants.py @@ -36,6 +36,7 @@ EM_X86_64 = 62 EM_ALTERA_NIOS2 = 113 EM_AARCH64 = 183 EM_RISCV = 243 +EM_LOONGARCH = 258 EM_ALPHA = 0x9026 E_ENTRY = 24 @@ -52,3 +53,11 @@ EF_RISCV_FLOAT_ABI_SOFT = 0x0000 EF_RISCV_FLOAT_ABI_SINGLE = 0x0002 EF_RISCV_FLOAT_ABI_DOUBLE = 0x0004 EF_RISCV_FLOAT_ABI_QUAD = 0x0006 + +EF_LOONGARCH_ABI_LP64_SOFT_FLOAT = 0b001 +EF_LOONGARCH_ABI_LP64_SINGLE_FLOAT = 0b010 +EF_LOONGARCH_ABI_LP64_DOUBLE_FLOAT = 0b011 +EF_LOONGARCH_ABI_ILP32_SOFT_FLOAT = 0b101 +EF_LOONGARCH_ABI_ILP32_SINGLE_FLOAT = 0b110 +EF_LOONGARCH_ABI_ILP32_DOUBLE_FLOAT = 0b111 +EF_LOONGARCH_ABI_MASK = 0x07 -- 2.35.1