From f071ba31b2e441268518217cbe2ec4fe1c978b31 Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Wed, 2 Dec 2020 15:25:03 +0100 Subject: [PATCH] CMake: Fix arch parsing for oss-fuzz I'll preface by saying, it's not clear to me why the behavior is different. Our qt_run_config_test_architecture function builds a target executable, and then uses file(STRINGS) to try and parse out some magic strings that we expect the executable to have (architecture, abi, etc). In qmake this was done by matching with a regular expression ending on a \\0 null byte character. In CMake, we do a string(FIND) and string(SUBSTRING until the end of the line) on a *line* returned from file(STRINGS). Notably, I did not find any regexp syntax provided by CMake to try and match a null byte character. Note the docs for file(STRINGS) implies to me that *lines* are detected by looking for newline characters '\n'. The docs also mention that binary data in the file is ignored. What's binary data though? If you open the executable with a hex editor, at least on macOS, the strings we are interested in are indeed separated by null byte chars, not newline chars. On most platforms file(STRINGS) did end a line on the null byte character. Except, for some reason not when building Qt for the oss-fuzz project with clang under Docker. Calling message() on one of the lines prints a very long string with null characters seemingly replaced with semicolons, and of course the matched architecture string is wrong and fails configuration. For *some reason*, if I add a "REGEX ==Qt=magic=Qt==" option to the file(STRINGS) command, the captured output lines don't contain semicolons even when building for oss-fuzz. The extracted strings are then correct, and configuration succeeds. Use the REGEX option workaround, with the aim to quickly fix Qt building for oss-fuzz for 6.0.1 release. Pick-to: 6.0 Fixes: QTBUG-89047 Change-Id: Iad11c1090c1187aadd39082f196050bf3290df95 Reviewed-by: Robert Loehning Reviewed-by: Cristian Adam Reviewed-by: Joerg Bornemann --- cmake/QtBaseConfigureTests.cmake | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cmake/QtBaseConfigureTests.cmake b/cmake/QtBaseConfigureTests.cmake index 50fc0c4fc0e..af18131fcd1 100644 --- a/cmake/QtBaseConfigureTests.cmake +++ b/cmake/QtBaseConfigureTests.cmake @@ -42,7 +42,8 @@ function(qt_run_config_test_architecture) endif() message(STATUS "Extracting architecture info from ${_arch_file}.") - file(STRINGS "${_arch_file}" _arch_lines LENGTH_MINIMUM 16 LENGTH_MAXIMUM 1024 ENCODING UTF-8) + file(STRINGS "${_arch_file}" _arch_lines LENGTH_MINIMUM 16 LENGTH_MAXIMUM 1024 ENCODING UTF-8 + REGEX "==Qt=magic=Qt==") foreach (_line ${_arch_lines}) string(LENGTH "${_line}" lineLength)