1 |
From: Arfrever Frehtes Taifersar Arahesis <Arfrever@××××××.Org> |
2 |
|
3 |
Newly added tc-enables-pie(), tc-enables-ssp(), tc-enables-ssp-strong() |
4 |
and tc-enables-ssp-all() check macros instead of specs. |
5 |
This solution also works with older GCC and with Clang. |
6 |
|
7 |
Signed-off-by: Matthias Maier <tamiko@g.o> |
8 |
--- |
9 |
eclass/toolchain-funcs.eclass | 67 +++++++++++++++++++++++++++++++++++++++++++ |
10 |
1 file changed, 67 insertions(+) |
11 |
|
12 |
diff --git a/eclass/toolchain-funcs.eclass b/eclass/toolchain-funcs.eclass |
13 |
index a0c359a950..8cfe329a96 100644 |
14 |
--- a/eclass/toolchain-funcs.eclass |
15 |
+++ b/eclass/toolchain-funcs.eclass |
16 |
@@ -792,6 +792,73 @@ gcc-specs-stack-check() { |
17 |
} |
18 |
|
19 |
|
20 |
+# @FUNCTION: tc-enables-pie |
21 |
+# @RETURN: Truth if the current compiler generates position-independent code (PIC) which can be linked into executables |
22 |
+# @DESCRIPTION: |
23 |
+# Return truth if the current compiler generates position-independent code (PIC) |
24 |
+# which can be linked into executables. |
25 |
+tc-enables-pie() { |
26 |
+ local ret="$($(tc-getCC) ${CPPFLAGS} ${CFLAGS} -E -P - <<-EOF 2> /dev/null |
27 |
+ #if defined(__PIE__) |
28 |
+ true |
29 |
+ #endif |
30 |
+ EOF |
31 |
+ )" |
32 |
+ [ "${ret}" = "true" ] |
33 |
+} |
34 |
+ |
35 |
+# @FUNCTION: tc-enables-ssp |
36 |
+# @RETURN: Truth if the current compiler enables stack smashing protection (SSP) on at least minimal level |
37 |
+# @DESCRIPTION: |
38 |
+# Return truth if the current compiler enables stack smashing protection (SSP) |
39 |
+# on level corresponding to any of the following options: |
40 |
+# -fstack-protector |
41 |
+# -fstack-protector-strong |
42 |
+# -fstack-protector-all |
43 |
+tc-enables-ssp() { |
44 |
+ local ret="$($(tc-getCC) ${CPPFLAGS} ${CFLAGS} -E -P - <<-EOF 2> /dev/null |
45 |
+ #if defined(__SSP__) || defined(__SSP_STRONG__) || defined(__SSP_ALL__) |
46 |
+ true |
47 |
+ #endif |
48 |
+ EOF |
49 |
+ )" |
50 |
+ [ "${ret}" = "true" ] |
51 |
+} |
52 |
+ |
53 |
+# @FUNCTION: tc-enables-ssp-strong |
54 |
+# @RETURN: Truth if the current compiler enables stack smashing protection (SSP) on at least middle level |
55 |
+# @DESCRIPTION: |
56 |
+# Return truth if the current compiler enables stack smashing protection (SSP) |
57 |
+# on level corresponding to any of the following options: |
58 |
+# -fstack-protector-strong |
59 |
+# -fstack-protector-all |
60 |
+tc-enables-ssp-strong() { |
61 |
+ local ret="$($(tc-getCC) ${CPPFLAGS} ${CFLAGS} -E -P - <<-EOF 2> /dev/null |
62 |
+ #if defined(__SSP_STRONG__) || defined(__SSP_ALL__) |
63 |
+ true |
64 |
+ #endif |
65 |
+ EOF |
66 |
+ )" |
67 |
+ [ "${ret}" = "true" ] |
68 |
+} |
69 |
+ |
70 |
+# @FUNCTION: tc-enables-ssp-all |
71 |
+# @RETURN: Truth if the current compiler enables stack smashing protection (SSP) on maximal level |
72 |
+# @DESCRIPTION: |
73 |
+# Return truth if the current compiler enables stack smashing protection (SSP) |
74 |
+# on level corresponding to any of the following options: |
75 |
+# -fstack-protector-all |
76 |
+tc-enables-ssp-all() { |
77 |
+ local ret="$($(tc-getCC) ${CPPFLAGS} ${CFLAGS} -E -P - <<-EOF 2> /dev/null |
78 |
+ #if defined(__SSP_ALL__) |
79 |
+ true |
80 |
+ #endif |
81 |
+ EOF |
82 |
+ )" |
83 |
+ [ "${ret}" = "true" ] |
84 |
+} |
85 |
+ |
86 |
+ |
87 |
# @FUNCTION: gen_usr_ldscript |
88 |
# @USAGE: [-a] <list of libs to create linker scripts for> |
89 |
# @DESCRIPTION: |
90 |
-- |
91 |
2.13.0 |