Skip to content

Commit

Permalink
Merge branch 'develop' into backtracing
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedihabb2 committed Jul 12, 2023
2 parents 0423571 + f41b3c2 commit 06c5d10
Show file tree
Hide file tree
Showing 25 changed files with 154 additions and 213 deletions.
38 changes: 0 additions & 38 deletions .github/workflows/address-sanitizer.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Note: This is duplicated from address-sanitizer.yml in order to keep the ci running if one of both sanitizers fail
name: Thread Sanitizer Test
name: Linux Sanitizer Test

on:
workflow_dispatch:
Expand All @@ -17,12 +16,15 @@ concurrency:

jobs:
linux-sanitizer-gcc:
name: Linux GCC Thread Sanitizer Test
name: Linux GCC Sanitizer Test
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
image: ["debian:bookworm-slim", "debian:bullseye-slim", "ubuntu:kinetic"]
sanitizer: [address-sanitizer, thread-sanitizer] # TODO: memory-sanitizer not supported by GCC

env:
SANITIZER_SKIP_SUMMARY: 1

Expand All @@ -33,6 +35,7 @@ jobs:
fetch-depth: 0

- name: Install, build and run thread sanitizer tests
run: ./docker-compose.sh test-thread-sanitizer
run: ./docker-compose.sh test-${{ matrix.sanitizer }}
env:
METACALL_BUILD_TYPE: debug
METACALL_BASE_IMAGE: ${{ matrix.image }}
6 changes: 0 additions & 6 deletions .github/workflows/linux-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,6 @@ jobs:
build: [debug, release]
image: ["debian:bookworm-slim", "debian:bullseye-slim", "ubuntu:kinetic"] # TODO: "alpine:3.17"

env:
DEBIAN_FRONTEND: noninteractive
LTTNG_UST_REGISTER_TIMEOUT: 0
NUGET_XMLDOC_MODE: skip
DOTNET_CLI_TELEMETRY_OPTOUT: 'true'

steps:
- name: Check out the repository
uses: actions/checkout@v2
Expand Down
1 change: 0 additions & 1 deletion .github/workflows/macos-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ jobs:
{build: debug, sanitizer: without-sanitizer},
{build: debug, sanitizer: address-sanitizer},
{build: debug, sanitizer: thread-sanitizer},
{build: debug, sanitizer: ub-sanitizer},
{build: release, sanitizer: without-sanitizer}
]

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/windows-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ jobs:
options: [
{build: debug, sanitizer: without-sanitizer},
{build: debug, sanitizer: address-sanitizer},
{build: debug, sanitizer: thread-sanitizer},
{build: debug, sanitizer: memory-sanitizer},
{build: debug, sanitizer: ub-sanitizer},
# TODO: Not supported yet
# {build: debug, sanitizer: thread-sanitizer},
# {build: debug, sanitizer: memory-sanitizer},
# TODO: Release build not working
{build: release, sanitizer: without-sanitizer}
]
Expand Down
23 changes: 7 additions & 16 deletions cmake/CompileOptions.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
#

option(OPTION_BUILD_ADDRESS_SANITIZER "Build with sanitizer compiler options." OFF)
option(OPTION_BUILD_MEMORY_SANITIZER "Build with memory sanitizer compiler options." OFF)
option(OPTION_BUILD_THREAD_SANITIZER "Build with thread sanitizer compiler options." OFF)
option(OPTION_BUILD_UB_SANITIZER "Build with undefined behavior sanitizer compiler options." OFF)
option(OPTION_BUILD_MEMORY_SANITIZER "Build with memory sanitizer compiler options." OFF)

if((OPTION_BUILD_ADDRESS_SANITIZER AND OPTION_BUILD_MEMORY_SANITIZER) OR (OPTION_BUILD_ADDRESS_SANITIZER AND OPTION_BUILD_THREAD_SANITIZER) OR (OPTION_BUILD_MEMORY_SANITIZER AND OPTION_BUILD_THREAD_SANITIZER))
message(FATAL_ERROR "OPTION_BUILD_ADDRESS_SANITIZER and OPTION_BUILD_MEMORY_SANITIZER and OPTION_BUILD_THREAD_SANITIZER are mutually exclusive, choose one of them")
Expand Down Expand Up @@ -85,15 +84,6 @@ elseif(OPTION_BUILD_MEMORY_SANITIZER AND "${CMAKE_CXX_COMPILER_ID}" MATCHES "Cla
set(SANITIZER_COMPILE_DEFINITIONS
"__MEMORY_SANITIZER__=1"
)
elseif(OPTION_BUILD_UB_SANITIZER AND "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo"))
# TODO
set(SANITIZER_LIBRARIES)
set(TESTS_SANITIZER_ENVIRONMENT_VARIABLES
"UBSAN_OPTIONS=print_stacktrace=1"
)
set(SANITIZER_COMPILE_DEFINITIONS
"__UB_SANITIZER__=1"
)
elseif(OPTION_BUILD_ADDRESS_SANITIZER AND (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo"))
set(SANITIZER_LIBRARIES -lasan -lubsan)
set(TESTS_SANITIZER_ENVIRONMENT_VARIABLES
Expand Down Expand Up @@ -237,17 +227,16 @@ if(WIN32 AND MSVC)
# Sanitizers
if(OPTION_BUILD_THREAD_SANITIZER AND (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo"))
add_compile_options(/fsanitize=thread)
# add_compile_options(/fsanitize=undefined)
add_link_options(/INCREMENTAL:NO)
elseif(OPTION_BUILD_ADDRESS_SANITIZER AND (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo"))
add_compile_options(/fsanitize=address)
# add_compile_options(/fsanitize=undefined)
add_link_options(/INCREMENTAL:NO)
elseif(OPTION_BUILD_MEMORY_SANITIZER AND (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo"))
add_compile_options(/fsanitize=memory)
add_compile_options(/fsanitize=leak)
add_link_options(/INCREMENTAL:NO)
elseif(OPTION_BUILD_UB_SANITIZER AND (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo"))
add_compile_options(/fsanitize=undefined)
add_link_options(/INCREMENTAL:NO)
endif()
endif()

Expand Down Expand Up @@ -286,6 +275,10 @@ if (PROJECT_OS_FAMILY MATCHES "unix" OR PROJECT_OS_FAMILY MATCHES "macos")
add_compile_options(-fsanitize=undefined)
add_compile_options(-fsanitize=address)
add_compile_options(-fsanitize-address-use-after-scope)
add_compile_options(-fsanitize=float-divide-by-zero)
add_compile_options(-fsanitize=float-cast-overflow)
add_compile_options(-fsanitize=pointer-compare)
add_compile_options(-fsanitize=pointer-subtract)
if(PROJECT_OS_FAMILY MATCHES "unix")
if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
add_compile_options(-fuse-ld=gold)
Expand All @@ -310,8 +303,6 @@ if (PROJECT_OS_FAMILY MATCHES "unix" OR PROJECT_OS_FAMILY MATCHES "macos")
add_link_options(-fsanitize-memory-track-origins)
add_link_options(-fsanitize-memory-use-after-dtor)
endif()
elseif(OPTION_BUILD_UB_SANITIZER AND "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" AND (CMAKE_BUILD_TYPE STREQUAL "Debug" OR CMAKE_BUILD_TYPE STREQUAL "RelWithDebInfo"))
# TODO
endif()

# Debug symbols
Expand Down
24 changes: 11 additions & 13 deletions docker-compose.sh
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ sub_test() {
docker-compose -f docker-compose.yml -f docker-compose.test.yml build --force-rm dev
}

# Build MetaCall Docker Compose with Address Sanitizer for testing (link manually dockerignore files)
sub_test_address_sanitizer() {
# Build MetaCall Docker Compose with Sanitizer for testing (link manually dockerignore files)
sub_test_sanitizer() {
# Disable BuildKit as workaround due to log limits (TODO: https://github.com/docker/buildx/issues/484)
export DOCKER_BUILDKIT=0

Expand Down Expand Up @@ -142,15 +142,6 @@ sub_test_address_sanitizer() {
fi
}

# Build MetaCall Docker Compose with Thread Sanitizer for testing (link manually dockerignore files)
sub_test_thread_sanitizer() {
# Enable build with thread sanitizer
export METACALL_BUILD_SANITIZER="thread-sanitizer"

# Run tests with thread sanitizer
sub_test_address_sanitizer
}

# Build MetaCall Docker Compose with caching (link manually dockerignore files)
sub_cache() {
if [ -z "$IMAGE_REGISTRY" ]; then
Expand Down Expand Up @@ -268,6 +259,7 @@ sub_help() {
echo " test"
echo " test-address-sanitizer"
echo " test-thread-sanitizer"
echo " test-memory-sanitizer"
echo " cache"
echo " push"
echo " pack"
Expand All @@ -288,10 +280,16 @@ case "$1" in
sub_test
;;
test-address-sanitizer)
sub_test_address_sanitizer
export METACALL_BUILD_SANITIZER="address-sanitizer"
sub_test_sanitizer
;;
test-thread-sanitizer)
sub_test_thread_sanitizer
export METACALL_BUILD_SANITIZER="thread-sanitizer"
sub_test_sanitizer
;;
test-memory-sanitizer)
export METACALL_BUILD_SANITIZER="memory-sanitizer"
sub_test_sanitizer
;;
cache)
sub_cache
Expand Down
3 changes: 1 addition & 2 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -708,9 +708,8 @@ For debugging memory leaks, undefined behaviors and other related problems, the
| :--------------------------------: | -------------------------------------------------------------- | :-----------: |
| **OPTION_TEST_MEMORYCHECK** | Enable Valgrind with memcheck tool for the tests. | OFF |
| **OPTION_BUILD_ADDRESS_SANITIZER** | Build with AddressSanitizer family (GCC, Clang and MSVC). | OFF |
| **OPTION_BUILD_MEMORY_SANITIZER** | Build with MemorySanitizer family (Clang and MSVC). | OFF |
| **OPTION_BUILD_THREAD_SANITIZER** | Build with ThreadSanitizer family (GCC, Clang and MSVC). | OFF |
| **OPTION_BUILD_UB_SANITIZER** | Build with UndefinedBehaviorSanitizer family (Clang and MSVC). | OFF |
| **OPTION_BUILD_MEMORY_SANITIZER** | Build with MemorySanitizer family (Clang and MSVC). | OFF |

All options are mutually exclusive. Valgrind is not compatible with AddressSanitizer and AddressSanitizer is not compatible with ThreadSanitizer and AddressSanitizer with MemorySanitizer. Some run-times may fail if they are not compiled with AddressSanitizer too, for example NetCore. Due to this, tests implying may fail with signal 11. The same problem happens with Valgrind, due to that, some tests are excluded of the memcheck target.

Expand Down
2 changes: 1 addition & 1 deletion source/dynlink/source/dynlink_impl_beos.c
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ int dynlink_impl_interface_unload_beos(dynlink handle, dynlink_impl impl)
{
(void)handle;

#if defined(__ADDRESS_SANITIZER__) || defined(__THREAD_SANITIZER__) || defined(__MEMORY_SANITIZER__) || defined(__UB_SANITIZER__)
#if defined(__ADDRESS_SANITIZER__) || defined(__THREAD_SANITIZER__) || defined(__MEMORY_SANITIZER__)
/* Disable dlclose when running with address sanitizer in order to maintain stacktraces */
(void)impl;
return 0;
Expand Down
2 changes: 1 addition & 1 deletion source/dynlink/source/dynlink_impl_unix.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ int dynlink_impl_interface_unload_unix(dynlink handle, dynlink_impl impl)
{
(void)handle;

#if defined(__ADDRESS_SANITIZER__) || defined(__THREAD_SANITIZER__) || defined(__MEMORY_SANITIZER__) || defined(__UB_SANITIZER__)
#if defined(__ADDRESS_SANITIZER__) || defined(__THREAD_SANITIZER__) || defined(__MEMORY_SANITIZER__)
/* Disable dlclose when running with address sanitizer in order to maintain stacktraces */
(void)impl;
return 0;
Expand Down
60 changes: 38 additions & 22 deletions source/loaders/java_loader/bootstrap/lib/bootstrap.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@
import java.nio.file.Path;
import java.nio.file.Paths;

// TODO: Review this: https://www.codeproject.com/Tips/1129615/JNI-Signature-for-Java-Method

public class bootstrap {
private static Set<String> executionPath = new HashSet<String>();

Expand Down Expand Up @@ -143,8 +141,8 @@ public static Class<?>[] load_from_package(String path) {
JarFile jarFile = new JarFile(curJarPath.toString());
Enumeration<JarEntry> e = jarFile.entries();

Path jpath = Paths.get("jar:file:", curExecPath, path);
String jarPath = jpath.toString() + "!/";
Path jpath = Paths.get(curExecPath, path);
String jarPath = "jar:file:" + jpath.toString().replace("\\", "/") + "!/";

Path epath = Paths.get(curExecPath, path);
executionPath.add(epath.toString());
Expand All @@ -157,7 +155,7 @@ public static Class<?>[] load_from_package(String path) {
if (je.getName().endsWith(".class")) {

String className = je.getName().substring(0, je.getName().length() - 6);
className = className.replace(File.separatorChar, '.');
className = className.replace('/', '.');
try {
Class<?> c = clsLoader.loadClass(className);

Expand Down Expand Up @@ -213,25 +211,43 @@ private static String[] getTypeSignature(Class<?> t) {
return new String[] { name, primitive ? "L" + signature + ";" : signature };
}

public static String getSignature(Method m) {
String sig;
try {
Field gSig = Method.class.getDeclaredField("signature");
gSig.setAccessible(true);
sig = (String) gSig.get(m);
if (sig != null)
return sig;
} catch (IllegalAccessException | NoSuchFieldException e) {
e.printStackTrace();
}

StringBuilder sb = new StringBuilder("(");
// Holds a mapping from Java type names to native type codes
private static final Map<Class<?>, String> PRIMITIVE_TO_SIGNATURE;
static {
PRIMITIVE_TO_SIGNATURE = new HashMap<Class<?>, String>(9);
PRIMITIVE_TO_SIGNATURE.put(byte.class, "B");
PRIMITIVE_TO_SIGNATURE.put(char.class, "C");
PRIMITIVE_TO_SIGNATURE.put(short.class, "S");
PRIMITIVE_TO_SIGNATURE.put(int.class, "I");
PRIMITIVE_TO_SIGNATURE.put(long.class, "J");
PRIMITIVE_TO_SIGNATURE.put(float.class, "F");
PRIMITIVE_TO_SIGNATURE.put(double.class, "D");
PRIMITIVE_TO_SIGNATURE.put(void.class, "V");
PRIMITIVE_TO_SIGNATURE.put(boolean.class, "Z");
}

for (Class<?> c : m.getParameterTypes())
sb.append((sig = Array.newInstance(c, 0).toString()).substring(1, sig.indexOf('@')));
// Returns the internal name of {@code clazz} (also known as the descriptor)
private static String getSignature(Class<?> clazz) {
String primitiveSignature = PRIMITIVE_TO_SIGNATURE.get(clazz);
if (primitiveSignature != null) {
return primitiveSignature;
} else if (clazz.isArray()) {
return "[" + getSignature(clazz.getComponentType());
} else {
return "L" + clazz.getName().replace('.', '/') + ";";
}
}

return sb.append(')').append(m.getReturnType() == void.class ? "V"
: (sig = Array.newInstance(m.getReturnType(), 0).toString()).substring(1, sig.indexOf('@'))).toString();
public static String getSignature(Method m) {
StringBuilder result = new StringBuilder();
result.append('(');
Class<?>[] parameterTypes = m.getParameterTypes();
for (Class<?> parameterType : parameterTypes) {
result.append(getSignature(parameterType));
}
result.append(')');
result.append(getSignature(m.getReturnType()));
return result.toString();
}

public static String get_Field_Type(Class<?> cls, String key) {
Expand Down
2 changes: 1 addition & 1 deletion source/portability/source/portability_path.c
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ int portability_path_separator_normalize_inplace(char *path, size_t size)
{
if (separator == 0)
{
separator = path[iterator];
separator = PORTABILITY_PATH_SEPARATOR_C; /* Use current platform style as default */
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion source/ports/go_port/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ add_custom_target(${target}
# Define test
#

if(OPTION_BUILD_ADDRESS_SANITIZER OR OPTION_BUILD_THREAD_SANITIZER OR OPTION_BUILD_MEMORY_SANITIZER OR OPTION_BUILD_UB_SANITIZER)
if(OPTION_BUILD_ADDRESS_SANITIZER OR OPTION_BUILD_THREAD_SANITIZER OR OPTION_BUILD_MEMORY_SANITIZER)
# TODO: Not implemented (https://go.googlesource.com/go/+/go1.7/misc/cgo/testsanitizers/test.bash)
return()
endif()
Expand Down
2 changes: 1 addition & 1 deletion source/ports/go_port/source/go_port.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ package metacall
#include <metacall/metacall.h>
// TODO: Sanitizer
// #if defined(__ADDRESS_SANITIZER__) || defined(__THREAD_SANITIZER__) || defined(__MEMORY_SANITIZER__) || defined(__UB_SANITIZER__)
// #if defined(__ADDRESS_SANITIZER__) || defined(__THREAD_SANITIZER__) || defined(__MEMORY_SANITIZER__)
// void __lsan_do_leak_check(void);
// #endif
Expand Down
2 changes: 1 addition & 1 deletion source/ports/js_port/test/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ void ModulesClear()
it != modules.end(); ++it)
{
/* Disable dlclose when running with address sanitizer in order to maintain stacktraces */
#if !defined(__ADDRESS_SANITIZER__) && !defined(__THREAD_SANITIZER__) && !defined(__MEMORY_SANITIZER__) && !defined(__UB_SANITIZER__)
#if !defined(__ADDRESS_SANITIZER__) && !defined(__THREAD_SANITIZER__) && !defined(__MEMORY_SANITIZER__)
#if defined(JS_PORT_TEST_WIN)
FreeLibrary(it->second);
#elif defined(JS_PORT_TEST_UNIX)
Expand Down
Loading

0 comments on commit 06c5d10

Please sign in to comment.