diff options
Diffstat (limited to '')
-rw-r--r-- | test/sigsegv/CMakeLists.txt | 11 | ||||
-rw-r--r-- | test/sigsegv/lib.c | 5 | ||||
-rw-r--r-- | test/sigsegv/lib.h | 10 | ||||
-rw-r--r-- | test/sigsegv/main.c | 16 |
4 files changed, 42 insertions, 0 deletions
diff --git a/test/sigsegv/CMakeLists.txt b/test/sigsegv/CMakeLists.txt new file mode 100644 index 0000000..b92147d --- /dev/null +++ b/test/sigsegv/CMakeLists.txt @@ -0,0 +1,11 @@ +# Hopefully putting the NULL reference to a separate library should force the +# sigsegv binary to crash. If I put it in main.c, surprisingly, Clang (with +# -O2) produces a binary that doesn't crash: https://godbolt.org/z/joeqEEs3Y. +# To force it to crash, the -fno-delete-null-pointer-checks flag is required: +# https://godbolt.org/z/o3xEoeG3z. This is a bit hacky though; putting the +# reference in a separate library should also do the trick. + +add_library(null lib.c) + +add_executable(sigsegv main.c) +target_link_libraries(sigsegv PRIVATE null) diff --git a/test/sigsegv/lib.c b/test/sigsegv/lib.c new file mode 100644 index 0000000..1e136cc --- /dev/null +++ b/test/sigsegv/lib.c @@ -0,0 +1,5 @@ +#include "lib.h" + +#include <stddef.h> + +struct data *data = NULL; diff --git a/test/sigsegv/lib.h b/test/sigsegv/lib.h new file mode 100644 index 0000000..1f162d5 --- /dev/null +++ b/test/sigsegv/lib.h @@ -0,0 +1,10 @@ +#ifndef __LIB_H__ +#define __LIB_H__ + +struct data { + int x; +}; + +extern struct data *data; + +#endif diff --git a/test/sigsegv/main.c b/test/sigsegv/main.c new file mode 100644 index 0000000..428d168 --- /dev/null +++ b/test/sigsegv/main.c @@ -0,0 +1,16 @@ +#include "lib.h" + +#include <stdio.h> + +int main(void) +{ + puts("Started the test program."); + fflush(stdout); + + printf("This will crash: %d.\n", data->x); + + puts("You shouldn't see this."); + fflush(stdout); + + return 0; +} |