| 1 | # Copyright 1999-2005 Gentoo Foundation |
1 | # Copyright 1999-2005 Gentoo Foundation |
| 2 | # Distributed under the terms of the GNU General Public License v2 |
2 | # Distributed under the terms of the GNU General Public License v2 |
| 3 | # $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.85 2005/04/06 23:29:23 vapier Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.86 2005/04/28 20:06:00 solar Exp $ |
| 4 | |
4 | |
| 5 | ECLASS=flag-o-matic |
5 | ECLASS=flag-o-matic |
| 6 | INHERITED="$INHERITED $ECLASS" |
6 | INHERITED="$INHERITED $ECLASS" |
| 7 | |
7 | |
| 8 | IUSE="debug" |
8 | IUSE="debug" |
| … | |
… | |
| 60 | # hooked function for hardened gcc that appends |
60 | # hooked function for hardened gcc that appends |
| 61 | # -fno-stack-protector to {C,CXX,LD}FLAGS |
61 | # -fno-stack-protector to {C,CXX,LD}FLAGS |
| 62 | # when a package is filtering -fstack-protector, -fstack-protector-all |
62 | # when a package is filtering -fstack-protector, -fstack-protector-all |
| 63 | # notice: modern automatic specs files will also suppress -fstack-protector-all |
63 | # notice: modern automatic specs files will also suppress -fstack-protector-all |
| 64 | # when only -fno-stack-protector is given |
64 | # when only -fno-stack-protector is given |
|
|
65 | # |
|
|
66 | #### has_pic #### |
|
|
67 | # Returns true if the compiler by default or with current CFLAGS |
|
|
68 | # builds position-independent code. |
|
|
69 | # |
|
|
70 | #### has_ssp_all #### |
|
|
71 | # Returns true if the compiler by default or with current CFLAGS |
|
|
72 | # generates stack smash protections for all functions |
|
|
73 | # |
|
|
74 | #### has_ssp #### |
|
|
75 | # Returns true if the compiler by default or with current CFLAGS |
|
|
76 | # generates stack smash protections for most vulnerable functions |
| 65 | # |
77 | # |
| 66 | |
78 | |
| 67 | # C[XX]FLAGS that we allow in strip-flags |
79 | # C[XX]FLAGS that we allow in strip-flags |
| 68 | setup-allowed-flags() { |
80 | setup-allowed-flags() { |
| 69 | if [[ -z ${ALLOWED_FLAGS} ]] ; then |
81 | if [[ -z ${ALLOWED_FLAGS} ]] ; then |
| … | |
… | |
| 324 | # indicate whether PIC is set |
336 | # indicate whether PIC is set |
| 325 | has_pic() { |
337 | has_pic() { |
| 326 | [ "${CFLAGS/-fPIC}" != "${CFLAGS}" ] && return 0 |
338 | [ "${CFLAGS/-fPIC}" != "${CFLAGS}" ] && return 0 |
| 327 | [ "${CFLAGS/-fpic}" != "${CFLAGS}" ] && return 0 |
339 | [ "${CFLAGS/-fpic}" != "${CFLAGS}" ] && return 0 |
| 328 | [ "$(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__)" ] && return 0 |
340 | [ "$(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__)" ] && return 0 |
| 329 | test_version_info pie && return 0 |
|
|
| 330 | return 1 |
341 | return 1 |
| 331 | } |
342 | } |
| 332 | |
343 | |
| 333 | # indicate whether PIE is set |
344 | # indicate whether PIE is set |
| 334 | has_pie() { |
345 | has_pie() { |
| 335 | [ "${CFLAGS/-fPIE}" != "${CFLAGS}" ] && return 0 |
346 | [ "${CFLAGS/-fPIE}" != "${CFLAGS}" ] && return 0 |
| 336 | [ "${CFLAGS/-fpie}" != "${CFLAGS}" ] && return 0 |
347 | [ "${CFLAGS/-fpie}" != "${CFLAGS}" ] && return 0 |
| 337 | [ "$(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIE__)" ] && return 0 |
348 | [ "$(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIE__)" ] && return 0 |
| 338 | # test PIC while waiting for specs to be updated to generate __PIE__ |
349 | # test PIC while waiting for specs to be updated to generate __PIE__ |
| 339 | [ "$(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__)" ] && return 0 |
350 | [ "$(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__)" ] && return 0 |
|
|
351 | return 1 |
|
|
352 | } |
|
|
353 | |
|
|
354 | # indicate whether code for SSP is being generated for all functions |
|
|
355 | has_ssp_all() { |
|
|
356 | # note; this matches only -fstack-protector-all |
|
|
357 | [ "${CFLAGS/-fstack-protector-all}" != "${CFLAGS}" ] && return 0 |
|
|
358 | [ "$(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP_ALL__)" ] && return 0 |
| 340 | return 1 |
359 | return 1 |
| 341 | } |
360 | } |
| 342 | |
361 | |
| 343 | # indicate whether code for SSP is being generated |
362 | # indicate whether code for SSP is being generated |
| 344 | has_ssp() { |
363 | has_ssp() { |