Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH 2/3] toolchain-funcs.eclass: Add tc-get-c-rtlib() to get CC runtime
Date: Sat, 08 Oct 2022 09:44:10
Message-Id: 20221008094329.316318-3-mgorny@gentoo.org
In Reply to: [gentoo-dev] [PATCH 0/3] toolchain-funcs.eclass: support for querying C++ stdlib and compiler runtime by "Michał Górny"
1 Add a new tc-get-c-rtlib() that attempts to get the runtime used
2 by the current C compiler. Currently it supports compiler-rt
3 and libgcc.
4
5 Signed-off-by: Michał Górny <mgorny@g.o>
6 ---
7 eclass/tests/toolchain-funcs.sh | 10 ++++++++++
8 eclass/toolchain-funcs.eclass | 28 ++++++++++++++++++++++++++++
9 2 files changed, 38 insertions(+)
10
11 diff --git a/eclass/tests/toolchain-funcs.sh b/eclass/tests/toolchain-funcs.sh
12 index 5a35a44ce018..d8a357fb24fe 100755
13 --- a/eclass/tests/toolchain-funcs.sh
14 +++ b/eclass/tests/toolchain-funcs.sh
15 @@ -202,6 +202,10 @@ if type -P gcc &>/dev/null; then
16 tbegin "tc-get-cxx-stdlib (gcc)"
17 [[ $(CXX=g++ tc-get-cxx-stdlib) == libstdc++ ]]
18 tend $?
19 +
20 + tbegin "tc-get-c-rtlib (gcc)"
21 + [[ $(CC=gcc tc-get-c-rtlib) == libgcc ]]
22 + tend $?
23 fi
24
25 if type -P clang &>/dev/null; then
26 @@ -218,6 +222,12 @@ if type -P clang &>/dev/null; then
27 tbegin "tc-get-cxx-stdlib (clang, invalid)"
28 ! CXX=clang++ CXXFLAGS="-stdlib=invalid" tc-get-cxx-stdlib
29 tend $?
30 +
31 + for rtlib in compiler-rt libgcc; do
32 + tbegin "tc-get-c-rtlib (clang, ${rtlib})"
33 + [[ $(CC=clang CFLAGS="--rtlib=${rtlib}" tc-get-c-rtlib) == ${rtlib} ]]
34 + tend $?
35 + done
36 fi
37
38 texit
39 diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass
40 index 92494158201e..32e446cb2368 100644
41 --- a/eclass/toolchain-funcs.eclass
42 +++ b/eclass/toolchain-funcs.eclass
43 @@ -1209,4 +1209,32 @@ tc-get-cxx-stdlib() {
44 return 0
45 }
46
47 +# @FUNCTION: tc-get-c-rtlib
48 +# @DESCRIPTION:
49 +# Attempt to identify the runtime used by the C/C++ compiler.
50 +# If the runtime is identifed, the function returns 0 and prints one
51 +# of the following:
52 +#
53 +# - ``compiler-rt`` for ``sys-libs/compiler-rt``
54 +# - ``libgcc`` for ``sys-devel/gcc``'s libgcc
55 +#
56 +# If the runtime is not recognized, the function returns 1.
57 +tc-get-c-rtlib() {
58 + local res=$(
59 + $(tc-getCC) ${CFLAGS} ${CPPFLAGS} ${LDFLAGS} \
60 + -print-libgcc-file-name 2>/dev/null
61 + )
62 +
63 + case ${res} in
64 + *libclang_rt*)
65 + echo compiler-rt;;
66 + *libgcc*)
67 + echo libgcc;;
68 + *)
69 + return 1;;
70 + esac
71 +
72 + return 0
73 +}
74 +
75 fi
76 --
77 2.38.0