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.91 2005/07/22 21:47:51 vapier Exp $ |
3 | # $Header: /var/cvsroot/gentoo-x86/eclass/flag-o-matic.eclass,v 1.92 2005/08/01 10:50:55 kevquinn Exp $ |
4 | |
4 | |
5 | |
5 | |
6 | # need access to emktemp() |
6 | # need access to emktemp() |
7 | inherit eutils toolchain-funcs multilib |
7 | inherit eutils toolchain-funcs multilib |
8 | |
8 | |
… | |
… | |
56 | # hooked function for hardened gcc that appends |
56 | # hooked function for hardened gcc that appends |
57 | # -fno-stack-protector to {C,CXX,LD}FLAGS |
57 | # -fno-stack-protector to {C,CXX,LD}FLAGS |
58 | # when a package is filtering -fstack-protector, -fstack-protector-all |
58 | # when a package is filtering -fstack-protector, -fstack-protector-all |
59 | # notice: modern automatic specs files will also suppress -fstack-protector-all |
59 | # notice: modern automatic specs files will also suppress -fstack-protector-all |
60 | # when only -fno-stack-protector is given |
60 | # when only -fno-stack-protector is given |
|
|
61 | # |
|
|
62 | # |
|
|
63 | ################ DEPRECATED functions ################ |
|
|
64 | # The following are still present to avoid breaking existing |
|
|
65 | # code more than necessary; however they are deprecated. Please |
|
|
66 | # use gcc-specs-* from toolchain-funcs.eclass instead, if you |
|
|
67 | # need to know which hardened techs are active in the compiler. |
|
|
68 | # See bug #100974 |
|
|
69 | # |
|
|
70 | #### has_hardened #### |
|
|
71 | # Returns true if the compiler has 'Hardened' in its version string, |
|
|
72 | # (note; switched-spec vanilla compilers satisfy this condition) or |
|
|
73 | # the specs file name contains 'hardened'. |
|
|
74 | # |
|
|
75 | #### has_pie #### |
|
|
76 | # Returns true if the compiler by default or with current CFLAGS |
|
|
77 | # builds position-independent code. |
61 | # |
78 | # |
62 | #### has_pic #### |
79 | #### has_pic #### |
63 | # Returns true if the compiler by default or with current CFLAGS |
80 | # Returns true if the compiler by default or with current CFLAGS |
64 | # builds position-independent code. |
81 | # builds position-independent code. |
65 | # |
82 | # |
… | |
… | |
315 | fi |
332 | fi |
316 | done |
333 | done |
317 | return 1 |
334 | return 1 |
318 | } |
335 | } |
319 | |
336 | |
|
|
337 | # DEPRECATED - use gcc-specs-relro or gcc-specs-now from toolchain-funcs |
320 | has_hardened() { |
338 | has_hardened() { |
321 | test_version_info Hardened && return 0 |
339 | test_version_info Hardened && return 0 |
322 | # the specs file wont exist unless gcc has GCC_SPECS support |
340 | # the specs file wont exist unless gcc has GCC_SPECS support |
323 | [ -f "${GCC_SPECS}" -a "${GCC_SPECS}" != "${GCC_SPECS/hardened/}" ] && \ |
341 | [ -f "${GCC_SPECS}" -a "${GCC_SPECS}" != "${GCC_SPECS/hardened/}" ] && \ |
324 | return 0 |
342 | return 0 |
325 | return 1 |
343 | return 1 |
326 | } |
344 | } |
327 | |
345 | |
|
|
346 | # DEPRECATED - use gcc-specs-pie from toolchain-funcs |
328 | # indicate whether PIC is set |
347 | # indicate whether PIC is set |
329 | has_pic() { |
348 | has_pic() { |
330 | [ "${CFLAGS/-fPIC}" != "${CFLAGS}" ] && return 0 |
349 | [ "${CFLAGS/-fPIC}" != "${CFLAGS}" ] && return 0 |
331 | [ "${CFLAGS/-fpic}" != "${CFLAGS}" ] && return 0 |
350 | [ "${CFLAGS/-fpic}" != "${CFLAGS}" ] && return 0 |
332 | [ "$(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__)" ] && return 0 |
351 | [ "$(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__)" ] && return 0 |
333 | return 1 |
352 | return 1 |
334 | } |
353 | } |
335 | |
354 | |
|
|
355 | # DEPRECATED - use gcc-specs-pie from toolchain-funcs |
336 | # indicate whether PIE is set |
356 | # indicate whether PIE is set |
337 | has_pie() { |
357 | has_pie() { |
338 | [ "${CFLAGS/-fPIE}" != "${CFLAGS}" ] && return 0 |
358 | [ "${CFLAGS/-fPIE}" != "${CFLAGS}" ] && return 0 |
339 | [ "${CFLAGS/-fpie}" != "${CFLAGS}" ] && return 0 |
359 | [ "${CFLAGS/-fpie}" != "${CFLAGS}" ] && return 0 |
340 | [ "$(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIE__)" ] && return 0 |
360 | [ "$(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIE__)" ] && return 0 |
341 | # test PIC while waiting for specs to be updated to generate __PIE__ |
361 | # test PIC while waiting for specs to be updated to generate __PIE__ |
342 | [ "$(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__)" ] && return 0 |
362 | [ "$(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __PIC__)" ] && return 0 |
343 | return 1 |
363 | return 1 |
344 | } |
364 | } |
345 | |
365 | |
|
|
366 | # DEPRECATED - use gcc-specs-ssp from toolchain-funcs |
346 | # indicate whether code for SSP is being generated for all functions |
367 | # indicate whether code for SSP is being generated for all functions |
347 | has_ssp_all() { |
368 | has_ssp_all() { |
348 | # note; this matches only -fstack-protector-all |
369 | # note; this matches only -fstack-protector-all |
349 | [ "${CFLAGS/-fstack-protector-all}" != "${CFLAGS}" ] && return 0 |
370 | [ "${CFLAGS/-fstack-protector-all}" != "${CFLAGS}" ] && return 0 |
350 | [ "$(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP_ALL__)" ] && return 0 |
371 | [ "$(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP_ALL__)" ] && return 0 |
|
|
372 | gcc-specs-ssp && return 0 |
351 | return 1 |
373 | return 1 |
352 | } |
374 | } |
353 | |
375 | |
|
|
376 | # DEPRECATED - use gcc-specs-ssp from toolchain-funcs |
354 | # indicate whether code for SSP is being generated |
377 | # indicate whether code for SSP is being generated |
355 | has_ssp() { |
378 | has_ssp() { |
356 | # note; this matches both -fstack-protector and -fstack-protector-all |
379 | # note; this matches both -fstack-protector and -fstack-protector-all |
357 | [ "${CFLAGS/-fstack-protector}" != "${CFLAGS}" ] && return 0 |
380 | [ "${CFLAGS/-fstack-protector}" != "${CFLAGS}" ] && return 0 |
358 | [ "$(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP__)" ] && return 0 |
381 | [ "$(echo | $(tc-getCC) ${CFLAGS} -E -dM - | grep __SSP__)" ] && return 0 |
|
|
382 | gcc-specs-ssp && return 0 |
359 | return 1 |
383 | return 1 |
360 | } |
384 | } |
361 | |
385 | |
362 | has_m64() { |
386 | has_m64() { |
363 | # this doesnt test if the flag is accepted, it tests if the flag |
387 | # this doesnt test if the flag is accepted, it tests if the flag |
… | |
… | |
438 | export LDFLAGS |
462 | export LDFLAGS |
439 | return 0 |
463 | return 0 |
440 | } |
464 | } |
441 | |
465 | |
442 | fstack-flags() { |
466 | fstack-flags() { |
443 | if has_ssp; then |
467 | if gcc-specs-ssp; then |
444 | [ -z "`is-flag -fno-stack-protector`" ] && |
468 | [ -z "`is-flag -fno-stack-protector`" ] && |
445 | export CFLAGS="${CFLAGS} `test_flag -fno-stack-protector`" |
469 | export CFLAGS="${CFLAGS} `test_flag -fno-stack-protector`" |
446 | fi |
470 | fi |
447 | return 0 |
471 | return 0 |
448 | } |
472 | } |