Fix macOS libcachesim compilation#183
Conversation
3b2977d to
6c03548
Compare
6c03548 to
fd5388d
Compare
|
The SonarCloud failures are not my failures; these already existed but had not been triggered due to the CI configuration. They were now triggered due to the repository-wide reformat to conform to the clang-format style. Either way, the warnings shown on SonarCloud are not very useful, complaining about strlen being unsafe. Yeah, it can be unsafe, this is C code :) |
a8ef48a to
f5d972e
Compare
4394a8a to
81b6c39
Compare
|
Thank you for the detailed summary! The code quality check was added recently, so it has not been run on most of the files. |
|
BTW, issue 2: we might want to use something like |
|
One more tip, if you want to break down the changes into smaller PRs, it might be easier to review them. :) |
…so adds DATA_PATH_LEN for cleaner code
…ive, no-whole-archive)
81b6c39 to
8354917
Compare
|
|
Are you still working on this? If we can resolve the build issue, we can enable macOS bulld in GitHub action #217 |
|
I have fixed the build in #221 |
|
Sorry for the silence, I planned to break this down into smaller separate PRs as you had suggested previously. Issue 2 was fixed by PR 188 |
|
Awesome! Note that the eviction tests fail on macOS, which still needs investigation. |




Problem
The problem is that the installation of
libcachesimfails on macOS due to too many errors caught by Clang that are otherwise ignored by the less strict GCC. This MR addresses issues listed in Issue #182 and fixes further issues encountered along the way.Issue 1: Code quality CI never triggers
The
code-quality.yamlincludes aclang-tidyformatter that seemed to not run previously due to its configuration. After ensuring that all C and C++ files are captured, the whole repository was reformatted to conform to clang-tidy. As the repository-wide reformatting affected a lot of files without changing their functionality, the commit is ignored from git blame.Issue 2: Incorrect format specifiers
A common error reported by Clang was incorrect format specifiers used with the
printffunction, specifically that an argument of typeint64_tshould use the%lldformat specifier inprintfcalls. However,%lldbehaves differently across platforms because of differences in how data types are defined and how format specifiers are interpreted (on Ubuntu/Linux,int64_trequires the%ldformat specifier). The solution for this is to use the format macros defined in<inttypes.h>, specificallyPRId64in this case - this expands to the correct format specifier depending on the platform and ensures that this is portable and has correct formatting across all systems. An example of the error is shown here:Issue 3: Unqualified calls to
std::moveThe file
splaytree.hppcontained unqualified calls tostd::move. The fix was simple and just required a change from invokingstd::moveinstead ofmove. An example of the error is shown here:Issue 4: Use of deprecated
sprintffunctionThe
sprintffunction is reported to be deprecated and insecure, so it is replaced bysnprintf. An example of the error is shown here:Issue 5: Unused variables
There are some unused variables that have been removed. An example of the error is shown here:
Issue 6: C++ constructs used in C scope
The
split_by_charfunction inbin/mrcProfiler/cli_parser.cppreturns an instance of typestd::vector<std::string>. The problem here is that this function is declared within anextern "C" {...}block, so is treated as a C function type eventhough its return type is unsupported (only supported in C++). The fix here is to move the function outside of the extern block. An example of the error is shown here:Issue 7: Variadic argument list (...) with optional arguments is not handled correctly
The header file
inclue/libCacheSim/macro.hdefines some macros for assertions with optional arguments. The problem here is that this only works if__VA_ARGS__is not empty. Otherwise, it leaves a dangling comma likeCHECK_CONDITION(x, ==, NULL, FMT, )and causes compilation errors on Clang (GCC silently ignores these). The solution is to wrap the comma in__VA_OPT__likeCHECK_CONDITION(x, ==, NULL, FMT __VA_OPT__(,) __VA_ARGS__), so the expansion only adds a comma when__VA_ARGS__is not empty, else no dangling comma. An example of the error is shown here:Issue 7: Unsupported linker options for macOS
There are three linker options used in
CMakeLists.txtfiles across the project that are unsupported by Clang:export-dynamic,whole-archive, andno-whole-archive. Thus, logic has been added around these instances to ensure these options are only linked when run on Linux systems. An example of the error is shown here:Issue 8: Specific GCC flags not recognised by Clang
The C file
bin/cachesim/sim.ccontains GCC-specific#pragmadirectives used to temporarily surpress the compiler warning-Wformat-truncation. The problem is that Clang does not recognize GCC-specific warnings. To fix this, preprocessor checks are applied to ensure the pragma is only applied for real GCC. An example of the error is shown here:Issue 9: Linker issue with
_create_cachefunctionThe linker issue indicated that the definition of the
_create_cachefunction could not be found. The problem here is that the C fileplugin.cwhich contains the_create_cachefunction was never compiled and linked and caused an unresolved symbol error. To solve this, thecache/CMakeLists.txtwas modified to includeplugin.cin the source list for thecachelibtarget. An example of the error is shown here:Issue 10: GNU-style variadic arguments not supported by Clang
GNU-style variadic arguments are used in the project, which Clang warns about by default. To resolve this by suppressing these warnings about zero-argument variadic macros, the compiler flag
-Wno-gnu-zero-variadic-macro-argumentsis added to bothCMAKE_C_FLAGSandCMAKE_CXX_FLAGSinCMakeLists.txt. An example of the error is shown here:Issue 11: Library
zstdnot foundThe
zstdlibrary was not found on macOS due to the path in which the library exists. Since brew is used to install packages on macOS, the path is different than the default path. To correctly handle this difference, the package managerpkg-configis used to link thezstdlibrary correctly. An example of the error is shown here: