]>
Commit | Line | Data |
---|---|---|
513f8ca4 MT |
1 | 2014-05-12 Magnus Granberg <zorry@gentoo.org> |
2 | ||
3 | * gcc/esp.h New file to support --enable-esp | |
4 | Version 20140512.1 | |
5 | ||
6 | --- gcc/config/esp.h 2010-04-09 16:14:00.000000000 +0200 | |
7 | +++ gcc/config/esp.h 2012-06-23 01:00:31.248348491 +0200 | |
8 | @@ -0,0 +1,127 @@ | |
9 | +/* License terms see GNU GENERAL PUBLIC LICENSE Version 3. | |
10 | + * Version 20140512.1 | |
11 | + * Magnus Granberg (Zorry) <zorry@gentoo.org> */ | |
12 | +#ifndef GCC_ESP_H | |
13 | +#define GCC_ESP_H | |
14 | + | |
15 | +/* This file will add -fstack-protector-all, -fstack-check, -fPIE, -pie and -z now | |
16 | + as default if the defines and the spec allow it. | |
17 | + Added a hack for gcc-specs-* in toolchain-funcs.eclass and _filter-hardened in flag-o-matic.eclass | |
18 | + to support older hardened GCC patches and we don't need to change the code on gcc-specs-* and _filter-hardened. | |
19 | + This will add some unsupported upstream commands options as -nopie and -nonow. | |
20 | + -D__KERNEL__ is added so we don't have -fPIE, -pie and -fstack-protector-all and -fstack-check when building kernels. | |
21 | + ESP_CC1_SPEC is added to CC1_SPEC. | |
22 | + ESP_CC1_STRICT_OVERFLOW_SPEC is added so we don't disable the strict-overflow check. | |
23 | + ESP_LINK_PIE_CHECK_SPEC check for -pie, -p, -pg, -profile and -static. | |
24 | + ENABLE_CRTBEGINP add support for crtbeginP.o, build -static with -fPIE or -fpie. | |
25 | +*/ | |
26 | +#ifdef ENABLE_ESP | |
27 | + | |
28 | + /* Hack to support gcc-specs-* in toolchain-funcs.eclass and _filter-hardened in flag-o-matic.eclass */ | |
29 | + #define ESP_CC1_SPEC " %(esp_cc1_ssp) %(esp_cc1_pie) %(esp_cc1_strict_overflow)" | |
30 | + #if defined ( EFAULT_SSP ) || defined ( EFAULT_PIE_SSP ) | |
31 | + #define ESP_CC1_SSP_SPEC "%{!fno-stack-protector: %{!fno-stack-protector-all: %{!fno-stack-check: }}}" | |
32 | + #else | |
33 | + #define ESP_CC1_SSP_SPEC "" | |
34 | + #endif | |
35 | + #if defined ( EFAULT_PIE ) || defined ( EFAULT_PIE_SSP ) | |
36 | + #define ESP_CC1_PIE_SPEC "%{!nopie: }" | |
37 | + #else | |
38 | + #define ESP_CC1_PIE_SPEC "" | |
39 | + #endif | |
40 | + #define ESP_CC1_STRICT_OVERFLOW_SPEC "%{!fstrict-overflow:%{!fno-strict-overflow: -fno-strict-overflow}}" | |
41 | + | |
42 | + /* ESP_LINK_SPEC is added to LINK_PIE_SPEC if esp is enable | |
43 | + -z now will be added if we don't have -vanilla spec. We do a -pie incompatible check | |
44 | + Don't remove the specs in the end */ | |
45 | + #define ESP_LINK_SPEC "%(esp_link_now) %(esp_link_pie_check) " | |
46 | + #define ESP_LINK_NOW_SPEC "%{!nonow:-z now}" | |
47 | + | |
48 | + /* We use ESP_DRIVER_SELF_SPEC to add pie and ssp command-line options. */ | |
49 | + #define ESP_DRIVER_SELF_SPEC "%{D__KERNEL__:;:%{!nopie:%(esp_options_pie) \ | |
50 | + %(esp_link_pie)} %(esp_options_ssp) }" | |
51 | + | |
52 | + /* This will add -fstack-protector-all if we don't have -nostdlib -nodefaultlibs -fno-stack-protector -fstack-protector | |
53 | + -fstack-protector-all and we have EFAULT_SSP or EFAULT_PIE_SSP defined. */ | |
54 | + #if defined ( EFAULT_SSP ) || defined ( EFAULT_PIE_SSP ) | |
55 | + #define ESP_OPTIONS_SSP_SPEC \ | |
56 | + "%{nostdlib|ffreestanding|fno-stack-protector|fstack-protector| \ | |
57 | + fstack-protector-all|fstack-protector-strong:;:-fstack-protector-all} \ | |
58 | + %{fstack-check|fstack-check=*:;: -fstack-check}" | |
59 | + #else | |
60 | + #define ESP_OPTIONS_SSP_SPEC "" | |
61 | + #endif | |
62 | + | |
63 | + /* If EFAULT_PIE or EFAULT_PIE_SSP is defined we will add -fPIE -pie */ | |
64 | + #if defined ( EFAULT_PIE ) || defined ( EFAULT_PIE_SSP ) | |
65 | + | |
66 | + /* This will add -fPIE if we don't have -pie -fpic -fPIC -fpie -fPIE -fno-pic -fno-PIC -fno-pie -fno-PIE -shared -static | |
67 | + -nostdlib -nostartfiles. */ | |
68 | + /* With ENABLE_CRTBEGINP we don't need to check for -static */ | |
69 | + #ifdef ENABLE_CRTBEGINP | |
70 | + #define ESP_OPTIONS_PIE_SPEC \ | |
71 | + "%{!pie: %{!fpic:%{!fPIC:%{!fpie:%{!fPIE: %{!fno-pic:%{!fno-PIC:%{!fno-pie:%{!fno-PIE: \ | |
72 | + %{!shared: %{!nostdlib: %{!nostartfiles:-fPIE}} } }}}} }}}} }" | |
73 | + #else | |
74 | + #define ESP_OPTIONS_PIE_SPEC \ | |
75 | + "%{!pie: %{!fpic:%{!fPIC:%{!fpie:%{!fPIE: %{!fno-pic:%{!fno-PIC:%{!fno-pie:%{!fno-PIE: \ | |
76 | + %{!shared: %{!static: %{!nostdlib: %{!nostartfiles:-fPIE}} } }}}} }}}} }}" | |
77 | + #endif | |
78 | + | |
79 | + /* This will add -pie if we don't have -pie -A -fno-pic -fno-PIC -fno-pie -fno-PIE -shared -static -r -nostdlib | |
80 | + -nostartfiles */ | |
81 | + /* With ENABLE_CRTBEGINP we don't need to check for -static | |
82 | + and we add -pie only to get the start and endfiles. -pie will not go to the linker. */ | |
83 | + #ifdef ENABLE_CRTBEGINP | |
84 | + #define ESP_LINK_PIE_SPEC \ | |
85 | + "%{!pie:%{!A:%{!fno-pie:%{!fno-PIE:%{!fno-pic:%{!fno-PIC:%{!shared:%{!r: \ | |
86 | + %{!nostdlib:%{!nostartfiles:-pie}}}}}}}}}}" | |
87 | + #else | |
88 | + #define ESP_LINK_PIE_SPEC \ | |
89 | + "%{!pie:%{!A:%{!fno-pie:%{!fno-PIE:%{!fno-pic:%{!fno-PIC:%{!shared:%{!static:%{!r: \ | |
90 | + %{!nostdlib:%{!nostartfiles:-pie}}}}}}}}}}}" | |
91 | + #endif | |
92 | + | |
93 | + /* This will check if -pie is set when (-static) -pg -p -profile. If set it will make gcc print out | |
94 | + "-pie and (static)|pg|p|profile are incompatible when linking" */ | |
95 | + /* With ENABLE_CRTBEGINP we don't need to check for -static */ | |
96 | + #ifdef ENABLE_CRTBEGINP | |
97 | + #define ESP_LINK_PIE_CHECK_SPEC \ | |
98 | + "%{pie:%{pg|p|profile:%e-pie and -pg|p|profile are incompatible when linking}}" | |
99 | + #else | |
100 | + #define ESP_LINK_PIE_CHECK_SPEC \ | |
101 | + "%{pie:%{static|pg|p|profile:%e-pie and -static|pg|p|profile are incompatible when linking}}" | |
102 | + #endif | |
103 | + | |
104 | + /* We don't pass -pie to the linker when -static. */ | |
105 | + #ifdef ENABLE_CRTBEGINP | |
106 | + #define LINK_PIE_SPEC "%{!static:%{pie:-pie}} %(esp_link)" | |
107 | + #else | |
108 | + #define LINK_PIE_SPEC "%{pie:-pie} %(esp_link)" | |
109 | + #endif | |
110 | + | |
111 | + #else | |
112 | + #define ESP_OPTIONS_PIE_SPEC "" | |
113 | + #define ESP_LINK_PIE_CHECK_SPEC "" | |
114 | + #define ESP_LINK_PIE_SPEC "" | |
115 | + #define LINK_PIE_SPEC "%{pie:-pie} %(esp_link)" | |
116 | + #endif | |
117 | + | |
118 | + /* We add extra spec name's to the EXTRA_SPECS list */ | |
119 | + #define ESP_EXTRA_SPECS \ | |
120 | + { "esp_cc1", ESP_CC1_SPEC }, \ | |
121 | + { "esp_cc1_pie", ESP_CC1_PIE_SPEC }, \ | |
122 | + { "esp_cc1_ssp", ESP_CC1_SSP_SPEC }, \ | |
123 | + { "esp_cc1_strict_overflow", ESP_CC1_STRICT_OVERFLOW_SPEC }, \ | |
124 | + { "esp_link", ESP_LINK_SPEC }, \ | |
125 | + { "esp_link_now", ESP_LINK_NOW_SPEC }, \ | |
126 | + { "esp_link_pie", ESP_LINK_PIE_SPEC }, \ | |
127 | + { "esp_link_pie_check", ESP_LINK_PIE_CHECK_SPEC }, \ | |
128 | + { "esp_driver_self", ESP_DRIVER_SELF_SPEC }, \ | |
129 | + { "esp_options_pie", ESP_OPTIONS_PIE_SPEC }, \ | |
130 | + { "esp_options_ssp", ESP_OPTIONS_SSP_SPEC } | |
131 | + | |
132 | + static const char *cc1_spec = CC1_SPEC ESP_CC1_SPEC; | |
133 | + | |
134 | +#endif | |
135 | +#endif /* End GCC_ESP_H */ |