Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o
Cc: "Andreas K . Hüttel" <dilfridge@g.o>, Zac Medico <zmedico@g.o>
Subject: [gentoo-portage-dev] [PATCH] Recognize riscv ABIs (bug 686194)
Date: Sat, 18 May 2019 06:19:21
Message-Id: 20190518061542.14235-1-zmedico@gentoo.org
1 In order to avoid possibe misidentification, only the following ABIs
2 are recognized:
3
4 * lp64
5 * lp64d
6
7 The compute_multilib_category function correctly identifies both
8 riscv_lp64 and riscv_lp64d files found in the experimental stages
9 from https://dev.gentoo.org/~dilfridge/stages/rv64gc-multilib/.
10
11 Bug: https://bugs.gentoo.org/686194
12 Signed-off-by: Zac Medico <zmedico@g.o>
13 ---
14 lib/portage/dep/soname/multilib_category.py | 51 +++++++++++++++++++--
15 lib/portage/util/elf/constants.py | 10 +++-
16 2 files changed, 55 insertions(+), 6 deletions(-)
17
18 diff --git a/lib/portage/dep/soname/multilib_category.py b/lib/portage/dep/soname/multilib_category.py
19 index 84e018fb0..37af98705 100644
20 --- a/lib/portage/dep/soname/multilib_category.py
21 +++ b/lib/portage/dep/soname/multilib_category.py
22 @@ -1,4 +1,4 @@
23 -# Copyright 2015 Gentoo Foundation
24 +# Copyright 2015-2019 Gentoo Authors
25 # Distributed under the terms of the GNU General Public License v2
26 #
27 # Compute a multilib category, as discussed here:
28 @@ -14,6 +14,7 @@
29 # m68k_{32,64}
30 # mips_{eabi32,eabi64,n32,n64,o32,o64}
31 # ppc_{32,64}
32 +# riscv_{lp64,lp64d}
33 # s390_{32,64}
34 # sh_{32,64}
35 # sparc_{32,64}
36 @@ -34,10 +35,21 @@
37 from __future__ import unicode_literals
38
39 from portage.util.elf.constants import (
40 - EF_MIPS_ABI, EF_MIPS_ABI2, ELFCLASS32, ELFCLASS64,
41 + EF_MIPS_ABI,
42 + EF_MIPS_ABI2,
43 + EF_RISCV_FLOAT_ABI_DOUBLE,
44 + EF_RISCV_RVC,
45 + ELFCLASS32,
46 + ELFCLASS64,
47 EM_386, EM_68K, EM_AARCH64, EM_ALPHA, EM_ARM, EM_ALTERA_NIOS2,
48 EM_IA_64, EM_MIPS,
49 - EM_PARISC, EM_PPC, EM_PPC64, EM_S390, EM_SH, EM_SPARC,
50 + EM_PARISC,
51 + EM_PPC,
52 + EM_PPC64,
53 + EM_RISCV,
54 + EM_S390,
55 + EM_SH,
56 + EM_SPARC,
57 EM_SPARC32PLUS, EM_SPARCV9, EM_X86_64, E_MIPS_ABI_EABI32,
58 E_MIPS_ABI_EABI64, E_MIPS_ABI_O32, E_MIPS_ABI_O64)
59
60 @@ -53,6 +65,7 @@ _machine_prefix_map = {
61 EM_PARISC: "hppa",
62 EM_PPC: "ppc",
63 EM_PPC64: "ppc",
64 + EM_RISCV: "riscv",
65 EM_S390: "s390",
66 EM_SH: "sh",
67 EM_SPARC: "sparc",
68 @@ -82,6 +95,33 @@ def _compute_suffix_mips(elf_header):
69
70 return name
71
72 +
73 +def _compute_suffix_riscv(elf_header):
74 + """
75 + Compute riscv multilib suffix. In order to avoid possible
76 + misidentification, only the following ABIs are recognized:
77 +
78 + * lp64
79 + * lp64d
80 + """
81 +
82 + name = None
83 +
84 + if elf_header.ei_class == ELFCLASS64:
85 + if elf_header.e_flags == EF_RISCV_RVC:
86 + name = "lp64"
87 + elif elf_header.e_flags == EF_RISCV_RVC | EF_RISCV_FLOAT_ABI_DOUBLE:
88 + name = "lp64d"
89 +
90 + return name
91 +
92 +
93 +_specialized_funcs = {
94 + "mips": _compute_suffix_mips,
95 + "riscv": _compute_suffix_riscv,
96 +}
97 +
98 +
99 def compute_multilib_category(elf_header):
100 """
101 Compute a multilib category from an ELF header.
102 @@ -96,10 +136,11 @@ def compute_multilib_category(elf_header):
103 if elf_header.e_machine is not None:
104
105 prefix = _machine_prefix_map.get(elf_header.e_machine)
106 + specialized_func = _specialized_funcs.get(prefix)
107 suffix = None
108
109 - if prefix == "mips":
110 - suffix = _compute_suffix_mips(elf_header)
111 + if specialized_func is not None:
112 + suffix = specialized_func(elf_header)
113 elif elf_header.ei_class == ELFCLASS64:
114 suffix = "64"
115 elif elf_header.ei_class == ELFCLASS32:
116 diff --git a/lib/portage/util/elf/constants.py b/lib/portage/util/elf/constants.py
117 index 2704e85c3..9ab0ba8ce 100644
118 --- a/lib/portage/util/elf/constants.py
119 +++ b/lib/portage/util/elf/constants.py
120 @@ -1,4 +1,4 @@
121 -# Copyright 2015-2018 Gentoo Foundation
122 +# Copyright 2015-2019 Gentoo Authors
123 # Distributed under the terms of the GNU General Public License v2
124 #
125 # These constants are available from elfutils:
126 @@ -35,6 +35,7 @@ EM_IA_64 = 50
127 EM_X86_64 = 62
128 EM_ALTERA_NIOS2 = 113
129 EM_AARCH64 = 183
130 +EM_RISCV = 243
131 EM_ALPHA = 0x9026
132
133 E_ENTRY = 24
134 @@ -44,3 +45,10 @@ E_MIPS_ABI_O32 = 0x00001000
135 E_MIPS_ABI_O64 = 0x00002000
136 E_MIPS_ABI_EABI32 = 0x00003000
137 E_MIPS_ABI_EABI64 = 0x00004000
138 +
139 +EF_RISCV_RVC = 0x0001
140 +EF_RISCV_FLOAT_ABI = 0x0006
141 +EF_RISCV_FLOAT_ABI_SOFT = 0x0000
142 +EF_RISCV_FLOAT_ABI_SINGLE = 0x0002
143 +EF_RISCV_FLOAT_ABI_DOUBLE = 0x0004
144 +EF_RISCV_FLOAT_ABI_QUAD = 0x0006
145 --
146 2.21.0