Skip to content

Commit d343ed4

Browse files
author
mjw
committed
GCC 5.1 is too smart. Disable Identical Code Folding for preload libs.
We want to disabled Identical Code Folding for the tools preload shared objects to get better backraces. For GCC 5.1 -fipa-icf is enabled by default at -O2. The optimization reduces code size and may disturb unwind stacks by replacing a function by equivalent one with a different name. Add a configure check to see if GCC supports -fno-ipa-icf. If it does then add the flag to AM_CFLAGS_PSO_BASE. Without this GCC will notice some of the preload replacement functions in vg_replace_strmem are identical and fold them all into one picking a random (existing) function name. This causes backtraces showing completely unexpected function names. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@15305 a5019735-40e9-0310-863c-91ae7b9d1cf9
1 parent ca799bc commit d343ed4

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

Makefile.all.am

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,10 @@ endif
133133
if VGCONF_OS_IS_DARWIN
134134
AM_CFLAGS_PSO_BASE = -dynamic \
135135
-O -g -fno-omit-frame-pointer -fno-strict-aliasing \
136-
-fpic -fPIC -fno-builtin
136+
-fpic -fPIC -fno-builtin @FLAG_FNO_IPA_ICF@
137137
else
138138
AM_CFLAGS_PSO_BASE = -O -g -fno-omit-frame-pointer -fno-strict-aliasing \
139-
-fpic -fno-builtin
139+
-fpic -fno-builtin @FLAG_FNO_IPA_ICF@
140140
endif
141141

142142

configure.ac

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1811,6 +1811,33 @@ CFLAGS=$safe_CFLAGS
18111811

18121812
AC_SUBST(FLAG_FNO_STACK_PROTECTOR)
18131813

1814+
# Does GCC support disabling Identical Code Folding?
1815+
# We want to disabled Identical Code Folding for the
1816+
# tools preload shared objects to get better backraces.
1817+
# For GCC 5.1+ -fipa-icf is enabled by default at -O2.
1818+
# "The optimization reduces code size and may disturb
1819+
# unwind stacks by replacing a function by equivalent
1820+
# one with a different name."
1821+
AC_MSG_CHECKING([if gcc accepts -fno-ipa-icf])
1822+
1823+
safe_CFLAGS=$CFLAGS
1824+
CFLAGS="-fno-ipa-icf"
1825+
1826+
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[
1827+
return 0;
1828+
]])], [
1829+
no_ipa_icf=yes
1830+
FLAG_FNO_IPA_ICF="-fno-ipa-icf"
1831+
AC_MSG_RESULT([yes])
1832+
], [
1833+
no_ipa_icf=no
1834+
FLAG_FNO_IPA_ICF=""
1835+
AC_MSG_RESULT([no])
1836+
])
1837+
CFLAGS=$safe_CFLAGS
1838+
1839+
AC_SUBST(FLAG_FNO_IPA_ICF)
1840+
18141841

18151842
# Does this compiler support -fsanitize=undefined?
18161843
# Only checked for if --enable-ubsan was given.

0 commit comments

Comments
 (0)