Skip to content
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

Use libstdc++ in ASAN #6753

Merged
merged 13 commits into from
Jan 23, 2025
Merged
2 changes: 1 addition & 1 deletion .azure-pipelines-templates/daily-matrix.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ parameters:
cmake_args: "-DCMAKE_BUILD_TYPE=Debug"
cmake_env: ""
ASAN:
cmake_args: "-DSAN=ON"
cmake_args: "-DSAN=ON -DUSE_LIBCXX=OFF"
achamayou marked this conversation as resolved.
Show resolved Hide resolved
cmake_env: ""
TSAN:
cmake_args: "-DTSAN=ON -DWORKER_THREADS=2"
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/long-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
git config --global --add safe.directory "$GITHUB_WORKSPACE"
mkdir build
cd build
cmake -GNinja -DCOMPILE_TARGET=virtual -DCMAKE_BUILD_TYPE=Debug -DLONG_TESTS=ON -DSAN=ON ..
cmake -GNinja -DCOMPILE_TARGET=virtual -DCMAKE_BUILD_TYPE=Debug -DLONG_TESTS=ON -DSAN=ON -DUSE_LIBCXX=OFF ..
ninja

- name: "Test"
Expand Down
7 changes: 0 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -929,13 +929,6 @@ if(BUILD_TESTS)
PROPERTY LABELS unit_test
)

# https://github.com/microsoft/CCF/issues/5198
set_property(
TEST csr_test
APPEND
PROPERTY ENVIRONMENT "ASAN_OPTIONS=alloc_dealloc_mismatch=0"
)

add_test(NAME versionifier_test
COMMAND ${PYTHON}
${CMAKE_SOURCE_DIR}/python/src/ccf/_versionifier.py
Expand Down
7 changes: 0 additions & 7 deletions cmake/common.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,6 @@ function(add_unit_test name)
"TSAN_OPTIONS=suppressions=${CCF_DIR}/tsan_env_suppressions"
)

# https://github.com/microsoft/CCF/issues/5198
set_property(
TEST ${name}
APPEND
PROPERTY ENVIRONMENT "ASAN_OPTIONS=alloc_dealloc_mismatch=0"
)

endfunction()

# Test binary wrapper
Expand Down
2 changes: 1 addition & 1 deletion include/ccf/http_accept.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace ccf::http
bool operator<(const AcceptHeaderField& other) const
{
static constexpr auto float_comp_epsilon = 0.0000001f;
if (abs(q_factor - other.q_factor) > float_comp_epsilon)
if (std::abs(q_factor - other.q_factor) > float_comp_epsilon)
{
return q_factor < other.q_factor;
}
Expand Down
23 changes: 14 additions & 9 deletions src/ds/ring_buffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,19 +145,24 @@ namespace ringbuffer
{
static inline uint64_t read64_impl(const BufferDef& bd, size_t index)
{
auto src = bd.data + index;
auto src_64 = reinterpret_cast<uint64_t*>(src);

#ifdef __cpp_lib_atomic_ref
auto& ref = *(reinterpret_cast<uint64_t*>(bd.data + index));
std::atomic_ref<uint64_t> slot(ref);
return slot.load(std::memory_order_acquire);
#else
// __atomic_load is used instead of std::atomic_ref since it's not
// supported by libc++ yet.
if (Const::is_aligned(src, 8))
{
auto& ref = *src_64;
std::atomic_ref<uint64_t> slot(ref);
return slot.load(std::memory_order_acquire);
}
#endif

// __atomic_load is used instead of std::atomic_ref when std::atomic_ref
// is unavailable, or the src pointer is not aligned
// https://en.cppreference.com/w/Template:cpp/compiler_support/20
uint64_t r = 0;
__atomic_load(
reinterpret_cast<uint64_t*>(bd.data + index), &r, __ATOMIC_ACQUIRE);
__atomic_load(src_64, &r, __ATOMIC_ACQUIRE);
return r;
#endif
}

static inline Message message(uint64_t header)
Expand Down
3 changes: 1 addition & 2 deletions tests/e2e_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,6 @@ def run_config_timeout_check(args):
env = {}
if args.enclave_platform == "snp":
env = snp.get_aci_env()
env["ASAN_OPTIONS"] = "alloc_dealloc_mismatch=0"

proc = subprocess.Popen(
[
Expand Down Expand Up @@ -566,7 +565,7 @@ def run_configuration_file_checks(args):
for config in config_files_to_check:
cmd = [bin_path, f"--config={config}", "--check"]
rc = infra.proc.ccall(
*cmd, env={"ASAN_OPTIONS": "alloc_dealloc_mismatch=0"}
*cmd,
).returncode
assert rc == 0, f"Failed to check configuration: {rc}"
LOG.success(f"Successfully check sample configuration file {config}")
Expand Down
5 changes: 1 addition & 4 deletions tests/infra/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,10 +362,7 @@ def __init__(
if ubsan_opts:
env["UBSAN_OPTIONS"] += ":" + ubsan_opts
env["TSAN_OPTIONS"] = os.environ.get("TSAN_OPTIONS", "")
# https://github.com/microsoft/CCF/issues/5198
env["ASAN_OPTIONS"] = os.environ.get(
"ASAN_OPTIONS", "alloc_dealloc_mismatch=0"
)
env["ASAN_OPTIONS"] = os.environ.get("ASAN_OPTIONS", "")
elif enclave_platform == "snp":
env = snp.get_aci_env()
snp_security_context_directory_envvar = (
Expand Down
Loading