aboutsummaryrefslogtreecommitdiff
blob: 062f51325247247541345d3cf0a43b89c86e41e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
# QA checks for ignored *FLAGS.

ignored_flag_check() {
	type -P scanelf > /dev/null || return
	has binchecks ${RESTRICT} && return

	local qa_var="QA_FLAGS_IGNORED_${ARCH/-/_}"
	eval "[[ -n \${!qa_var} ]] && QA_FLAGS_IGNORED=(\"\${${qa_var}[@]}\")"
	if [[ ${#QA_FLAGS_IGNORED[@]} -eq 1 ]] ; then
		local shopts=$-
		set -o noglob
		QA_FLAGS_IGNORED=(${QA_FLAGS_IGNORED})
		set +o noglob
		set -${shopts}
	fi

	local f x

	# Check for files built without respecting *FLAGS. Note that
	# -frecord-gcc-switches must be in all *FLAGS variables, in
	# order to avoid false positive results here.
	# NOTE: This check must execute before prepall/prepstrip, since
	# prepstrip strips the .GCC.command.line sections.
	if [[ "${CFLAGS}" == *-frecord-gcc-switches* ]] && \
	[[ "${CXXFLAGS}" == *-frecord-gcc-switches* ]] && \
	[[ "${FFLAGS}" == *-frecord-gcc-switches* ]] && \
	[[ "${FCFLAGS}" == *-frecord-gcc-switches* ]] ; then
		rm -f "${T}"/scanelf-ignored-CFLAGS.log
		for x in $(scanelf -qyRF '#k%p' -k '!.GCC.command.line' "${ED%/}/") ; do
			# Separate out file types that are known to support
			# .GCC.command.line sections, using the `file` command
			# similar to how prepstrip uses it.
			f=$(file "${x}") || continue
			[[ -z ${f} ]] && continue
			if [[ ${f} == *"SB executable"* || ${f} == *"SB pie executable"* ||
				${f} == *"SB shared object"* ]] ; then
				echo "${x}" >> "${T}"/scanelf-ignored-CFLAGS.log
			fi
		done

		if [[ -f "${T}"/scanelf-ignored-CFLAGS.log ]] ; then

			if [ "${QA_STRICT_FLAGS_IGNORED-unset}" = unset ] ; then
				for x in "${QA_FLAGS_IGNORED[@]}" ; do
					sed -e "s#^${x#/}\$##" -i "${T}"/scanelf-ignored-CFLAGS.log
				done
			fi
			# Filter anything under /usr/lib/debug/ in order to avoid
			# duplicate warnings for splitdebug files.
			sed -e "s#^usr/lib/debug/.*##" -e "/^\$/d" -e "s#^#/#" \
				-i "${T}"/scanelf-ignored-CFLAGS.log
			f=$(<"${T}"/scanelf-ignored-CFLAGS.log)
			if [[ -n ${f} ]] ; then
				__vecho -ne '\n'
				eqawarn "${BAD}QA Notice: Files built without respecting CFLAGS have been detected${NORMAL}"
				eqawarn " Please include the following list of files in your report:"
				eqawarn "${f}"
				__vecho -ne '\n'
				sleep 1
			else
				rm -f "${T}"/scanelf-ignored-CFLAGS.log
			fi
		fi
	fi

	# Check for files built without respecting LDFLAGS
	if [[ "${LDFLAGS}" == *,--defsym=__gentoo_check_ldflags__* ]] && \
		! has binchecks ${RESTRICT} ; then
		f=$(LC_ALL=C comm -2 -3 <(scanelf -qyRF '#k%p' -k .dynsym "${ED%/}/" | LC_ALL=C sort) \
			<(scanelf -qyRF '#s%p' -s __gentoo_check_ldflags__ "${ED%/}/" | LC_ALL=C sort))
		if [[ -n ${f} ]] ; then
			echo "${f}" > "${T}"/scanelf-ignored-LDFLAGS.log
			if [ "${QA_STRICT_FLAGS_IGNORED-unset}" = unset ] ; then
				for x in "${QA_FLAGS_IGNORED[@]}" ; do
					sed -e "s#^${x#/}\$##" -i "${T}"/scanelf-ignored-LDFLAGS.log
				done
			fi
			# Filter anything under /usr/lib/debug/ in order to avoid
			# duplicate warnings for splitdebug files.
			sed -e "s#^usr/lib/debug/.*##" -e "/^\$/d" -e "s#^#/#" \
				-i "${T}"/scanelf-ignored-LDFLAGS.log
			f=$(<"${T}"/scanelf-ignored-LDFLAGS.log)
			if [[ -n ${f} ]] ; then
				__vecho -ne '\n'
				eqawarn "${BAD}QA Notice: Files built without respecting LDFLAGS have been detected${NORMAL}"
				eqawarn " Please include the following list of files in your report:"
				eqawarn "${f}"
				__vecho -ne '\n'
				sleep 1
			else
				rm -f "${T}"/scanelf-ignored-LDFLAGS.log
			fi
		fi
	fi
}

ignored_flag_check
: # guarantee successful exit

# vim:ft=sh