Add ISan related options and isan-force-options package
[platform/upstream/gcc-contrib.git] / packaging / gcc-contrib.spec
1 #
2 # spec file for package gcc-contrib
3 #
4 # Copyright (c) 2017 Tizen
5 # Please submit bugfixes or comments via http://bugs.tizen.org/
6 #
7 # we use %%{?macro: ... } as it is more compact
8
9 %define quadmath_arch %ix86 x86_64 ia64
10 %define tsan_arch x86_64 aarch64
11 %define asan_arch x86_64 %ix86 ppc ppc64 %sparc %arm aarch64
12 %define itm_arch x86_64 %ix86 %arm ppc ppc64 ppc64le s390 s390x %sparc aarch64
13 %define atomic_arch x86_64 %ix86 %arm aarch64 ppc ppc64 ppc64le s390 s390x %sparc m68k
14 %define lsan_arch x86_64 %ix86 armv7l aarch64
15 %define ubsan_arch x86_64 %ix86 ppc ppc64 %arm aarch64
16 %define cilkrts_arch x86_64 %ix86
17
18 %ifarch armv7l
19 %define ARCH armv7l
20 %define ABI eabi
21 %endif
22 %ifarch %ix86
23 %define ARCH i586
24 %endif
25 %ifarch x86_64
26 %define ARCH x86_64
27 %endif
28 %ifarch aarch64
29 %define ARCH aarch64
30 %endif
31 %define host_arch %{ARCH}-tizen-linux-gnu%{?ABI}
32
33 %define target_cpu %{?cross}%{!?cross:%{ARCH}}
34 %define target_abi %{?cross:%{?armv7l:eabi}}%{!?cross:%{?ABI}}
35
36 %define target_arch %{target_cpu}-tizen-linux-gnu%{?target_abi}
37 %define libdir %{!?cross:%{_libdir}}%{?cross:%{_prefix}/lib%{?aarch64:64}}
38 %define libsubdir %{libdir}/gcc/%{target_arch}/%{version}
39
40 %define asan_force_options -fsanitize-recover=address -fsanitize=address -fno-omit-frame-pointer -Wp,-U_FORTIFY_SOURCE -Wl,--as-needed -ldl -lpthread
41 %define ubsan_force_options -fsanitize=undefined,bounds-strict,float-divide-by-zero,float-cast-overflow
42 %define lsan_force_options -fsanitize=leak -marm -Wa,-mimplicit-it=arm -fno-omit-frame-pointer -Wp,-U_FORTIFY_SOURCE -Wl,--as-needed -ldl -lpthread
43 %define isan_force_options -fsanitize=unsigned-integer-overflow
44
45 %define asan_runtime_options halt_on_error=false:start_deactivated=true:print_cmdline=true:quarantine_size_mb=1:detect_leaks=0:log_path=/tmp/asan.log:log_exe_name=1
46 %define ubsan_runtime_options print_cmdline=true:log_path=/tmp/ubsan.log
47 %define lsan_runtime_options print_cmdline=true:detect_leaks=1:log_path=/tmp/lsan.log:log_exe_name=1:fast_unwind_on_malloc=false:malloc_context_size=5:suppressions=/lsan.supp:print_suppressions=false
48
49 Name:         gcc-contrib%{?cross:-%{cross}}
50 # With generated files in src we could drop the following
51 ## until here, but at least renaming and patching info files breaks this
52 %{?cross:BuildRequires: binutils-%{cross}}
53 # here we use %%if because OBS spec parser cannot expand
54 # %%{?macro:...} correctly
55 Version:       6.2.1
56 Release:       0
57 Source15: gcc-force-options
58 Source16: gcc-unforce-options
59 Source17: ASAN_OPTIONS
60 Source18: asan_symbolize.py
61 Source19: LSAN_OPTIONS
62 Source20: gcc-contrib.manifest
63 Source21: UBSAN_OPTIONS
64 Source22: macros.ubsan
65 Source23: extract-ubsan-logs
66 Source24: lsan.supp
67 Group:         Development/Building
68 Summary:       GCC related scripts
69 License:       MIT 
70 %{?cross:ExcludeArch: %{cross}}
71 %description
72 GCC related scripts
73
74 %package -n asan-force-options
75 Summary:    Scripts to enable automatic package sanitization
76 Group:      System Environment
77 Requires:   gcc rpm
78 Requires:   libasan
79
80 %description -n asan-force-options
81 Scripts for ASan instrumentation
82
83 %post -n asan-force-options
84 # Change mode to allow all users to run gcc-force/unforce-options
85 chmod a+w /usr/bin
86 chmod a+w %{libsubdir}
87 [ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-*/obj/gcc/ \
88               && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a+w
89 /usr/bin/gcc-force-options %asan_force_options -fno-common
90 # Add ASan-related macros
91 cat >> /usr/lib/rpm/tizen_macros << EOF
92
93 %%asan_force_options %{asan_force_options}
94 %%gcc_unforce_options /usr/bin/gcc-unforce-options
95 %%gcc_force_options /usr/bin/gcc-force-options
96 %%gcc_force_default_options %%gcc_force_options %%asan_force_options -fno-common
97 %%restore_fcommon \\
98   %%gcc_unforce_options \\
99   %%gcc_force_options %%asan_force_options -fcommon
100 EOF
101 # ASan needs a whole shadow address space
102 # Using ulimit can only set the value for current user so we need to set /etc/security/limits.conf directly.
103 sed '/End of file/i\abuild\tsoft\tas\t-1\nabuild\thard\tas\t-1' -i /etc/security/limits.conf
104
105 %preun -n asan-force-options
106 # Restore read-only mode
107 chmod a-w /usr/bin
108 chmod a-w %{libsubdir}
109 [ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-*/obj/gcc/ \
110               && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a-w
111 /usr/bin/gcc-unforce-options
112 # Restore limit configurations set for ASan
113 sed '/abuild/d' -i /etc/security/limits.conf
114
115 %package -n ubsan-force-options
116 Summary:    Scripts to enable automatic package sanitization
117 Group:      System Environment
118 Requires:   gcc
119 Requires:   libubsan
120
121 %description -n ubsan-force-options
122 Scripts for UBSan instrumentation
123
124 %post -n ubsan-force-options
125 # Change mode to allow all users to run gcc-force/unforce-options
126 chmod a+w /usr/bin
127 chmod a+w %{libsubdir}
128 [ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-*/obj/gcc/ \
129               && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a+w
130 /usr/bin/gcc-force-options %ubsan_force_options
131 # Add UBSan-related macros
132 cat >> /usr/lib/rpm/tizen_macros << EOF
133
134 %%ubsan_force_options %{ubsan_force_options}
135 %%gcc_unforce_options /usr/bin/gcc-unforce-options
136 %%gcc_force_options /usr/bin/gcc-force-options
137 %%gcc_force_default_options %%gcc_force_options %%ubsan_force_options
138 EOF
139
140 %preun -n ubsan-force-options
141 # Restore read-only mode
142 chmod a-w /usr/bin
143 chmod a-w %{libsubdir}
144 [ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-*/obj/gcc/ \
145               && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a-w
146 /usr/bin/gcc-unforce-options
147
148 %package -n isan-force-options
149 Summary:    Scripts to enable automatic package sanitization
150 Group:      System Environment
151 Requires:   gcc
152 Requires:   libubsan
153
154 %description -n isan-force-options
155 Scripts for ISan instrumentation
156
157 %post -n isan-force-options
158 # Change mode to allow all users to run gcc-force/unforce-options
159 chmod a+w /usr/bin
160 chmod a+w %{libsubdir}
161 [ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-*/obj/gcc/ \
162               && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a+w
163 /usr/bin/gcc-force-options %isan_force_options
164 # Add ISan-related macros
165 cat >> /usr/lib/rpm/tizen_macros << EOF
166
167 %%isan_force_options %{isan_force_options}
168 %%gcc_unforce_options /usr/bin/gcc-unforce-options
169 %%gcc_force_options /usr/bin/gcc-force-options
170 %%gcc_force_default_options %%gcc_force_options %%isan_force_options
171 EOF
172
173 %preun -n isan-force-options
174 # Restore read-only mode
175 chmod a-w /usr/bin
176 chmod a-w %{libsubdir}
177 [ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-*/obj/gcc/ \
178               && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a-w
179 /usr/bin/gcc-unforce-options
180
181 %package -n ubsan-build-env
182 Summary:    UBSan build environment
183 Group:      System Environment
184 Requires:   gcc
185 Requires:   libubsan rpm
186
187 %description -n ubsan-build-env
188 UBSan build environment support files and scripts
189
190 %post -n ubsan-build-env
191 cat %{_rpmconfigdir}/macros.ubsan >> %{_rpmconfigdir}/tizen_macros
192
193 %package -n lsan-force-options
194 Summary:    Scripts to enable automatic package sanitization
195 Group:      System Environment
196 Requires:   gcc
197 Requires:   liblsan
198
199 %description -n lsan-force-options
200 Scripts for LSan instrumentation
201
202 %post -n lsan-force-options
203 # Change mode to allow all users to run gcc-force/unforce-options
204 chmod a+w /usr/bin
205 chmod a+w %{libsubdir}
206 [ -d /emul/ ] && chmod a+w /emul/usr/bin/ && chmod a+w /emul/home/abuild/rpmbuild/BUILD/gcc-*/obj/gcc/ \
207               && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a+w
208 /usr/bin/gcc-force-options %lsan_force_options
209 # Add LSan-related macros
210 cat >> /usr/lib/rpm/tizen_macros << EOF
211
212 %%lsan_force_options %{lsan_force_options}
213 %%gcc_unforce_options /usr/bin/gcc-unforce-options
214 %%gcc_force_options /usr/bin/gcc-force-options
215 %%gcc_force_default_options %%gcc_force_options %%lsan_force_options
216 EOF
217
218 %preun -n lsan-force-options
219 # Restore read-only mode
220 chmod a-w /usr/bin
221 chmod a-w %{libsubdir}
222 [ -d /emul/ ] && chmod a-w /emul/usr/bin/ && chmod a-w /emul/home/abuild/rpmbuild/BUILD/gcc-*/obj/gcc/ \
223               && find -L /emul/usr/*/gcc -name 'collect2' | xargs dirname | xargs chmod a-w
224 /usr/bin/gcc-unforce-options
225 [ -d /emul/ ] && chmod a-w /emul/usr/bin/
226
227 %package -n asan-build-env
228 Summary:    Asan build environment
229 Group:      Development/Libraries
230 Requires:   libasan
231
232 %description -n asan-build-env
233 Asan build environment
234
235 %post -n asan-build-env
236 # Add /usr/lib/libasan.so to /etc/ld.so.preload
237 [ -f /etc/ld.so.preload ] && mv -v /etc/ld.so.preload /etc/ld.so.preload.orig
238 echo "libasan.so" > /etc/ld.so.preload
239 [ -f /etc/ld.so.preload.orig ] && cat /etc/ld.so.preload.orig >> /etc/ld.so.preload
240
241 %preun -n asan-build-env
242 # Restore /etc/ld.so.preload
243 [ -f /etc/ld.so.preload.orig ] && mv -v /etc/ld.so.preload.orig /etc/ld.so.preload
244
245 %package -n lsan-runtime-env
246 Summary:    LSan runtime environment
247 Group:      Development/Libraries
248 Requires:   liblsan
249 Requires(post): smack
250
251 %description -n lsan-runtime-env
252 LSan runtime environment
253
254 %post -n lsan-runtime-env
255 # Add /usr/lib64/liblsan.so to /etc/ld.so.preload
256 [ -f /etc/ld.so.preload ] && mv -v /etc/ld.so.preload /etc/ld.so.preload.orig
257 echo "%{libdir}/liblsan.so" > /etc/ld.so.preload
258 [ -f /etc/ld.so.preload.orig ] && cat /etc/ld.so.preload.orig >> /etc/ld.so.preload
259 echo "%{lsan_runtime_options}" > /LSAN_OPTIONS
260 chsmack -a "_" /etc/ld.so.preload /LSAN_OPTIONS /lsan.supp
261
262 %preun -n lsan-runtime-env
263 # Restore /etc/ld.so.preload
264 [ -f /etc/ld.so.preload.orig ] && mv -v /etc/ld.so.preload.orig /etc/ld.so.preload
265
266 %package -n sanitizer-devel
267 Summary:    Sanitizer platform-independent tools
268 License:       MIT
269 Group:      Development/Tools
270 BuildArch:  noarch
271 Requires:   binutils python
272 Requires(post): smack
273
274 %description -n sanitizer-devel
275 The package contatins platform-independent tools for sanitization:
276 - asan_symbolize.py: script for offline symbolization of asan logs
277
278 %package -n asan-runtime-env
279 Summary:    Asan runtime environment for target device
280 Group:      Development/Libraries
281 Requires:   libasan
282
283 %description -n asan-runtime-env
284 Asan runtime environment
285
286 %post -n asan-runtime-env
287 # Add /usr/lib/libasan.so to /etc/ld.so.preload
288 [ -f /etc/ld.so.preload ] && mv -v /etc/ld.so.preload /etc/ld.so.preload.orig
289 echo "%{libdir}/libasan.so" > /etc/ld.so.preload
290 [ -f /etc/ld.so.preload.orig ] && cat /etc/ld.so.preload.orig >> /etc/ld.so.preload
291 echo "%{asan_runtime_options}" > /ASAN_OPTIONS
292 chsmack -a "_" /etc/ld.so.preload /ASAN_OPTIONS
293
294 %preun -n asan-runtime-env
295 # Restore /etc/ld.so.preload
296 [ -f /etc/ld.so.preload.orig ] && mv -v /etc/ld.so.preload.orig /etc/ld.so.preload
297
298 %package -n ubsan-runtime-env
299 Summary:    UBSan runtime environment for target device
300 Group:      Development/Libraries
301 Requires:   libubsan
302
303 %description -n ubsan-runtime-env
304 UBSan runtime environment
305
306 %post -n ubsan-runtime-env
307 echo "%{ubsan_runtime_options}" > /UBSAN_OPTIONS
308
309 %package -n sanitizer-sources
310 Summary:    Sanitizer family tools sources
311 License:       MIT
312 Group:      Development/Tools
313 BuildArch:  noarch
314
315 %description -n sanitizer-sources
316 Sanitizer family tools sources for external tools.
317
318 %prep
319
320 %build
321
322 %install
323 mkdir -p %buildroot%_prefix
324 mkdir -p %buildroot%_prefix/bin
325 sed -e 's|GCC_LIBSUBDIR|%{libsubdir}|' -i %{SOURCE15}
326
327 cp %{SOURCE15} %{SOURCE16} %{SOURCE18} %{buildroot}%{_prefix}/bin
328 chmod a+x %{buildroot}%{_prefix}/bin/gcc-force-options
329 chmod a+x %{buildroot}%{_prefix}/bin/gcc-unforce-options
330 chmod a+x %{buildroot}%{_prefix}/bin/asan_symbolize.py
331
332 cp %{SOURCE17} %{buildroot}
333 chmod 644 %{buildroot}/ASAN_OPTIONS
334
335 %ifarch %lsan_arch
336 cp %{SOURCE19} %{SOURCE24} %{buildroot}
337 chmod 644 %{buildroot}/LSAN_OPTIONS
338 chmod 644 %{buildroot}/lsan.supp
339 %endif
340
341 mkdir -p %{buildroot}/%{_rpmconfigdir}/tizen/
342 install -m 0644 %{SOURCE21} %{buildroot}/
343 install -m 0644 %{SOURCE22} %{buildroot}/%{_rpmconfigdir}/
344 install -m 0755 %{SOURCE23} %{buildroot}/%{_rpmconfigdir}/tizen/
345
346 %files
347 #%manifest gcc-contrib.manifest
348
349 %files -n asan-force-options
350 %defattr(-,root,root,-)
351 %{_prefix}/bin/gcc-force-options
352 %{_prefix}/bin/gcc-unforce-options
353
354 %files -n ubsan-force-options
355 %defattr(-,root,root,-)
356 %{_prefix}/bin/gcc-force-options
357 %{_prefix}/bin/gcc-unforce-options
358
359 %files -n isan-force-options
360 %defattr(-,root,root,-)
361 %{_prefix}/bin/gcc-force-options
362 %{_prefix}/bin/gcc-unforce-options
363
364 %ifarch %lsan_arch
365 %files -n lsan-force-options
366 #%manifest gcc-contrib.manifest
367 %defattr(-,root,root,-)
368 %{_prefix}/bin/gcc-force-options
369 %{_prefix}/bin/gcc-unforce-options
370 %endif
371
372 %files -n asan-build-env
373 %defattr(-,root,root,-)
374 /ASAN_OPTIONS
375
376 %files -n asan-runtime-env
377 %defattr(-,root,root,-)
378
379 %ifarch %lsan_arch
380 %files -n lsan-runtime-env
381 %defattr(-,root,root,-)
382 /LSAN_OPTIONS
383 /lsan.supp
384 %endif
385
386 %ifarch %ubsan_arch
387 %files -n ubsan-build-env
388 %defattr(-,root,root,-)
389 /UBSAN_OPTIONS
390 %{_rpmconfigdir}/macros.ubsan
391 %{_rpmconfigdir}/tizen/extract-ubsan-logs
392
393 %files -n ubsan-runtime-env
394 %defattr(-,root,root,-)
395 %endif
396
397 %files -n sanitizer-devel
398 %defattr(-,root,root,-)
399 %{_prefix}/bin/asan_symbolize.py
400
401 %changelog