Skip to content

Commit 4971e03

Browse files
committed
Adjust GCC broken strlen optimization check
GCC 8.3 has this fixed. Also cross-compiling for the dlsym underscore prefix check improved and simplified.
1 parent 95a24d1 commit 4971e03

File tree

4 files changed

+23
-14
lines changed

4 files changed

+23
-14
lines changed

cmake/cmake/Flags.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ include(PHP/CheckCompilerFlag)
1111

1212
# Check for broken GCC optimize-strlen.
1313
include(PHP/CheckBrokenGccStrlenOpt)
14-
if(HAVE_BROKEN_OPTIMIZE_STRLEN)
14+
if(PHP_HAVE_BROKEN_OPTIMIZE_STRLEN)
1515
php_check_compiler_flag(C -fno-optimize-strlen HAVE_FNO_OPTIMIZE_STRLEN_C)
1616
if(HAVE_FNO_OPTIMIZE_STRLEN_C)
1717
target_compile_options(

cmake/cmake/modules/PHP/CheckBrokenGccStrlenOpt.cmake

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,31 @@
11
#[=============================================================================[
2-
Early releases of GCC 8 shipped with a strlen() optimization bug, so they didn't
3-
properly handle the 'char val[1]' struct hack. See https://bugs.php.net/76510.
4-
If check is successful the -fno-optimize-strlen compiler flag should be used.
2+
GCC 8.2 shipped with a strlen() optimization bug, so it didn't properly handle
3+
the 'char val[1]' struct hack. Fixed in GCC 8.3. See https://bugs.php.net/76510
4+
and https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86914. If below check is
5+
successful the -fno-optimize-strlen compiler flag should be used.
56
67
Cache variables:
78
8-
HAVE_BROKEN_OPTIMIZE_STRLEN
9-
Whether GCC's optimize-strlen is broken.
9+
PHP_HAVE_BROKEN_OPTIMIZE_STRLEN
10+
Whether GCC has broken strlen() optimization.
1011
]=============================================================================]#
1112

1213
include_guard(GLOBAL)
1314

1415
include(CheckSourceRuns)
1516
include(CMakePushCheckState)
1617

17-
if(NOT CMAKE_C_COMPILER_ID STREQUAL "GNU")
18+
if(
19+
NOT CMAKE_C_COMPILER_ID STREQUAL "GNU"
20+
OR (
21+
CMAKE_C_COMPILER_ID STREQUAL "GNU"
22+
AND CMAKE_C_COMPILER_VERSION VERSION_GREATER_EQUAL 8.3
23+
)
24+
)
1825
return()
1926
endif()
2027

21-
message(CHECK_START "Checking for broken GCC optimize-strlen")
28+
message(CHECK_START "Checking if GCC has broken strlen() optimization")
2229

2330
cmake_push_check_state(RESET)
2431
set(CMAKE_REQUIRED_QUIET TRUE)
@@ -41,10 +48,10 @@ cmake_push_check_state(RESET)
4148

4249
return strlen(s->c+1) == 2;
4350
}
44-
]] HAVE_BROKEN_OPTIMIZE_STRLEN)
51+
]] PHP_HAVE_BROKEN_OPTIMIZE_STRLEN)
4552
cmake_pop_check_state()
4653

47-
if(HAVE_BROKEN_OPTIMIZE_STRLEN)
54+
if(PHP_HAVE_BROKEN_OPTIMIZE_STRLEN)
4855
message(CHECK_PASS "yes")
4956
else()
5057
message(CHECK_FAIL "no")

cmake/cmake/modules/Zend/CheckDlsym.cmake

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ message(
2020
"Checking whether dlsym() requires a leading underscore in symbol names"
2121
)
2222

23-
if(NOT CMAKE_CROSSCOMPILING)
23+
if(CMAKE_CROSSCOMPILING_EMULATOR OR NOT CMAKE_CROSSCOMPILING)
2424
check_include_file(dlfcn.h HAVE_DLFCN_H)
2525

2626
block()
@@ -78,7 +78,8 @@ if(NOT CMAKE_CROSSCOMPILING)
7878

7979
int fnord(void) { return 42; }
8080

81-
int main(void) {
81+
int main(void)
82+
{
8283
void *self = dlopen(0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW);
8384
int status = 0;
8485

cmake/cmake/toolchains/template.cmake

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
# cross-compiling to help identify the target system when cross-compiling
33
# emulator is not available.
44

5-
# Set the exit code for the GNU C compiler with broken strlen check.
6-
set(HAVE_BROKEN_OPTIMIZE_STRLEN_EXITCODE 1)
5+
# Set the exit code for check of GNU C compiler with broken strlen optimization
6+
# (relevant only for GCC version 8.2).
7+
set(PHP_HAVE_BROKEN_OPTIMIZE_STRLEN_EXITCODE 1)
78

89
# Set the exit code for the clock_get_time() check.
910
set(HAVE_CLOCK_GET_TIME_EXITCODE 0)

0 commit comments

Comments
 (0)