From f8155f0b945c5cfb3600d7c146a5d86870ed09d2 Mon Sep 17 00:00:00 2001 From: jvoisin Date: Tue, 8 Oct 2024 03:51:44 +0200 Subject: Run various C versions in the CI --- .github/workflows/testsuite.yaml | 27 +++++++++++++++++++++++++++ README.md | 5 +++-- tests/Makefile | 5 ++++- tests/common.h | 3 +++ tests/test_compile.c | 2 +- tests/test_fread_overwrite_dynamic.c | 3 +-- tests/test_fread_overwrite_static.c | 3 +-- tests/test_fwrite_overwrite_dynamic.c | 3 +-- tests/test_fwrite_overwrite_static.c | 3 +-- tests/test_getdomainname_dynamic.c | 5 +++-- tests/test_getdomainname_static.c | 5 +++-- tests/test_mbstowcs_dynamic.c | 2 +- tests/test_mbstowcs_static.c | 2 +- 13 files changed, 50 insertions(+), 18 deletions(-) diff --git a/.github/workflows/testsuite.yaml b/.github/workflows/testsuite.yaml index b84998a..b022fb2 100644 --- a/.github/workflows/testsuite.yaml +++ b/.github/workflows/testsuite.yaml @@ -78,3 +78,30 @@ jobs: run: | make -C tests clean clang run > ./results.txt grep -zvq 'FAIL' ./results.txt + + c_versions: + runs-on: ubuntu-latest + strategy: + matrix: + version: ["c89", "c99", "c11", "c17"] + steps: + - name: Checking out the code + uses: actions/checkout@v3 + - name: Cache musl toolchain + uses: actions/cache@v3 + id: cache-musl + with: + path: x86_64-linux-musl-native + key: musl + - name: Downloading musl-based toolchain + if: steps.cache-musl.outputs.cache-hit != 'true' + run: wget --quiet https://musl.cc/x86_64-linux-musl-native.tgz + - name: Extracting musl-based toolchain + if: steps.cache-musl.outputs.cache-hit != 'true' + run: tar xzf ./x86_64-linux-musl-native.tgz + - name: Building with clang + shell: bash + run: make CFLAGS=-std=${{ matrix.version }} -C tests clean clang + - name: Building with gcc + shell: bash + run: make CFLAGS=-std=${{ matrix.version }} -C tests clean gcc diff --git a/README.md b/README.md index 86e73fc..e187776 100644 --- a/README.md +++ b/README.md @@ -21,8 +21,9 @@ on Clang. It was initially intended to be used on - Support for out-of-bounds read interfaces, such as send(), write(), fwrite() etc. - No ABI is enforced. All of the fortify check functions are inlined into the resulting binary. -- It has a [comprehensive suite of tests](https://github.com/jvoisin/fortify-headers/tree/master/tests), - running both on Clang and on GCC for every commit, with +- It has a [comprehensive suite of + tests](https://github.com/jvoisin/fortify-headers/tree/master/tests), running + both on Clang and on GCC for every commit, on C89, C99, C11 and C17, with [significant coverage](https://jvoisin.github.io/fortify-headers/) - Defining `FORTIFY_USE_NATIVE_CHK` will make use of compiler-provided builtin `_chk` functions, which might be a bit better in term of diagnostics, diff --git a/tests/Makefile b/tests/Makefile index 333f088..a8c7ac5 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -159,7 +159,10 @@ clang: CFLAGS+=-I../x86_64-linux-musl-native/include/ clang: CFLAGS+=-Ix86_64-linux-musl-native/include/ clang: CFLAGS+=-nostdinc clang: CXX=clang++ -clang: CXXFLAGS=$(CFLAGS) +clang: CXXFLAGS+=-I/usr/include/x86_64-linux-musl +clang: CXXFLAGS+=-I../x86_64-linux-musl-native/include/ +clang: CXXFLAGS+=-Ix86_64-linux-musl-native/include/ +clang: CXXFLAGS+=-nostdinc clang: comptime $(RUNTIME_TARGETS) cpp coverage: CFLAGS += -fprofile-arcs -ftest-coverage diff --git a/tests/common.h b/tests/common.h index 4c34862..6a30739 100644 --- a/tests/common.h +++ b/tests/common.h @@ -15,6 +15,9 @@ License along with the GNU C Library; if not, see . */ +#define _POSIX_C_SOURCE 1 +#define _XOPEN_SOURCE 700 + #include #include #include diff --git a/tests/test_compile.c b/tests/test_compile.c index edbbb27..b794306 100644 --- a/tests/test_compile.c +++ b/tests/test_compile.c @@ -12,7 +12,7 @@ #include #include -// Check that all headers are compiling. +/* Check that all headers are compiling.*/ int main(int argc, char** argv) { return 0; } diff --git a/tests/test_fread_overwrite_dynamic.c b/tests/test_fread_overwrite_dynamic.c index 74953d6..b108dc5 100644 --- a/tests/test_fread_overwrite_dynamic.c +++ b/tests/test_fread_overwrite_dynamic.c @@ -1,7 +1,6 @@ -#include - #include "common.h" +#include #include int main(int argc, char** argv) { diff --git a/tests/test_fread_overwrite_static.c b/tests/test_fread_overwrite_static.c index e9de2ce..16a5e30 100644 --- a/tests/test_fread_overwrite_static.c +++ b/tests/test_fread_overwrite_static.c @@ -1,7 +1,6 @@ -#include - #include "common.h" +#include #include int main(int argc, char** argv) { diff --git a/tests/test_fwrite_overwrite_dynamic.c b/tests/test_fwrite_overwrite_dynamic.c index a7f2b1b..7da64ab 100644 --- a/tests/test_fwrite_overwrite_dynamic.c +++ b/tests/test_fwrite_overwrite_dynamic.c @@ -1,7 +1,6 @@ -#include - #include "common.h" +#include #include int main(int argc, char** argv) { diff --git a/tests/test_fwrite_overwrite_static.c b/tests/test_fwrite_overwrite_static.c index 492fb47..f844af8 100644 --- a/tests/test_fwrite_overwrite_static.c +++ b/tests/test_fwrite_overwrite_static.c @@ -1,7 +1,6 @@ -#include - #include "common.h" +#include #include int main(int argc, char** argv) { diff --git a/tests/test_getdomainname_dynamic.c b/tests/test_getdomainname_dynamic.c index a7882ba..3c15b8e 100644 --- a/tests/test_getdomainname_dynamic.c +++ b/tests/test_getdomainname_dynamic.c @@ -1,6 +1,7 @@ -#include "common.h" - #define _GNU_SOURCE +#define _DEFAULT_SOURCE + +#include "common.h" #include diff --git a/tests/test_getdomainname_static.c b/tests/test_getdomainname_static.c index a7671c4..478a274 100644 --- a/tests/test_getdomainname_static.c +++ b/tests/test_getdomainname_static.c @@ -1,6 +1,7 @@ -#include "common.h" - #define _GNU_SOURCE +#define _DEFAULT_SOURCE + +#include "common.h" #include diff --git a/tests/test_mbstowcs_dynamic.c b/tests/test_mbstowcs_dynamic.c index 1465bfd..fd02ed9 100644 --- a/tests/test_mbstowcs_dynamic.c +++ b/tests/test_mbstowcs_dynamic.c @@ -3,7 +3,7 @@ #include int main(int argc, char** argv) { - const char* mbstr = "z\u00df\u6c34\U0001f34c"; // or u8"zß水🍌" + const char* mbstr = "z\u00df\u6c34\U0001f34c"; /* or u8"zß水🍌" */ wchar_t wstr[5]; mbstowcs(wstr, mbstr, 4); diff --git a/tests/test_mbstowcs_static.c b/tests/test_mbstowcs_static.c index a15c4d6..847fcf7 100644 --- a/tests/test_mbstowcs_static.c +++ b/tests/test_mbstowcs_static.c @@ -3,7 +3,7 @@ #include int main(int argc, char** argv) { - const char* mbstr = "z\u00df\u6c34\U0001f34c"; // or u8"zß水🍌" + const char* mbstr = "z\u00df\u6c34\U0001f34c"; /* or u8"zß水🍌" */ wchar_t wstr[5]; mbstowcs(wstr, mbstr, 4); -- cgit v1.3