-
Notifications
You must be signed in to change notification settings - Fork 75
Fix macOS libcachesim compilation #183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
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
libcachesim
fails 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.yaml
includes aclang-tidy
formatter 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
printf
function, specifically that an argument of typeint64_t
should use the%lld
format specifier inprintf
calls. However,%lld
behaves differently across platforms because of differences in how data types are defined and how format specifiers are interpreted (on Ubuntu/Linux,int64_t
requires the%ld
format specifier). The solution for this is to use the format macros defined in<inttypes.h>
, specificallyPRId64
in 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::move
The file
splaytree.hpp
contained unqualified calls tostd::move
. The fix was simple and just required a change from invokingstd::move
instead ofmove
. An example of the error is shown here:Issue 4: Use of deprecated
sprintf
functionThe
sprintf
function 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_char
function inbin/mrcProfiler/cli_parser.cpp
returns 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.h
defines 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.txt
files 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.c
contains GCC-specific#pragma
directives 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_cache
functionThe linker issue indicated that the definition of the
_create_cache
function could not be found. The problem here is that the C fileplugin.c
which contains the_create_cache
function was never compiled and linked and caused an unresolved symbol error. To solve this, thecache/CMakeLists.txt
was modified to includeplugin.c
in the source list for thecachelib
target. 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-arguments
is added to bothCMAKE_C_FLAGS
andCMAKE_CXX_FLAGS
inCMakeLists.txt
. An example of the error is shown here:Issue 11: Library
zstd
not foundThe
zstd
library 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-config
is used to link thezstd
library correctly. An example of the error is shown here: