Skip to content

Commit eccc8cb

Browse files
committed
Cpu: disable IFUNC on GCC 4.8 if --coverage is used.
The offending flag is -fprofile-arcs and it's failing only on Ubuntu 20.04 with GCC 4.8, not with GCC 5 and not with GCC 4.8 on Arch. I couldn't find any even vaguely related bugreport, so I suspect this has something to with binutils or something else on that system. But since GCC 5 works there, I don't see that much of a problem. Unfortunately I also couldn't find any way to detect if such flag is present, the predefined variables are exactly the same in both cases. Which means this won't be able to detect if Corrade is built without --coverage and then used in code that has --coverage enabled. But as I'm probably the only person using --converage on GCC 4.8 (on the CI), I don't think that's a problem either.
1 parent 0662dbe commit eccc8cb

File tree

2 files changed

+22
-2
lines changed

2 files changed

+22
-2
lines changed

CMakeLists.txt

+20-1
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,29 @@ extern \"C\" int(*fooDispatcher())() {
206206
int foo() __attribute__((ifunc(\"fooDispatcher\")));
207207
int main() { return foo() - 42; }\
208208
" _CORRADE_CPU_CAN_USE_IFUNC)
209+
# In cases where ifunc is known to be broken, disable it by default --
210+
# users can still force it to be enabled, but the initial state should not
211+
# cause crashes or other strange behavior.
212+
if(_CORRADE_CPU_CAN_USE_IFUNC)
213+
set(_CORRADE_CPU_USE_IFUNC_DEFAULT ON)
214+
# On GCC 4.8, if --coverage or -fprofile-arcs is enabled, the ifunc
215+
# dispatchers cause a segfault. On Ubuntu 20.04 at least. Not the case
216+
# with GCC 5 there, not the case with GCC 4.8 on Arch. Can't find any
217+
# upstream bug report or commit that would be related to this.
218+
if(CMAKE_CXX_COMPILER_ID AND CMAKE_CXX_COMPILER_VERSION VERSION_LESS "4.9" AND CMAKE_CXX_FLAGS MATCHES "(--coverage|-fprofile-arcs)")
219+
if(NOT DEFINED CORRADE_CPU_USE_IFUNC)
220+
message(WARNING "Disabling CORRADE_CPU_USE_IFUNC by default as it may crash when used together with --coverage on GCC 4.8.")
221+
endif()
222+
set(_CORRADE_CPU_USE_IFUNC_DEFAULT OFF)
223+
endif()
224+
else()
225+
set(_CORRADE_CPU_USE_IFUNC_DEFAULT OFF)
226+
endif()
209227
else()
210228
set(_CORRADE_CPU_CAN_USE_IFUNC OFF)
229+
set(_CORRADE_CPU_USE_IFUNC_DEFAULT OFF)
211230
endif()
212-
cmake_dependent_option(CORRADE_CPU_USE_IFUNC "Allow using GNU IFUNC for runtime CPU dispatch" ON "_CORRADE_CPU_CAN_USE_IFUNC" OFF)
231+
cmake_dependent_option(CORRADE_CPU_USE_IFUNC "Allow using GNU IFUNC for runtime CPU dispatch" ${_CORRADE_CPU_USE_IFUNC_DEFAULT} "_CORRADE_CPU_CAN_USE_IFUNC" OFF)
213232

214233
# Backwards compatibility for unprefixed CMake options. If the user isn't
215234
# explicitly using prefixed options in the first run already, accept the

doc/building-corrade.dox

+2-1
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,8 @@ Platform-specific options:
557557
[GNU IFUNC](https://sourceware.org/glibc/wiki/GNU_IFUNC) to be used for
558558
runtime dispatch in the @ref Cpu library. Available only on platforms that
559559
support it, which is currently only Linux with glibc and Android with API
560-
30+, and there enabled by default. See
560+
30+, and there enabled by default unless a problematic case is detected
561+
that may cause it to misbehave. See
561562
@ref Cpu-usage-automatic-cached-dispatch for details and information about
562563
performance tradeoffs.
563564
- `CORRADE_UTILITY_USE_ANSI_COLORS` --- if building for Windows, this will

0 commit comments

Comments
 (0)