commit bc50ed6c3de76c11b2dde92d0f28dd45941fc327
parent c17d47669ff12057f732f9ae3f69b22d52b4c6b5
Author: jvoisin <julien.voisin@dustri.org>
Date: Sun, 20 Aug 2023 19:02:03 +0200
Fix clang build
- s/CLFAGS/CFLAGS/
- provide paths to local includes
- sprinkle more __pass_object_size__
- remove a problematic test
Diffstat:
9 files changed, 32 insertions(+), 17 deletions(-)
diff --git a/.github/workflows/testsuite.yaml b/.github/workflows/testsuite.yaml
@@ -34,6 +34,18 @@ jobs:
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: Setting up clang version
run: |
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-${{ matrix.version }} 100
diff --git a/include/fortify-headers.h b/include/fortify-headers.h
@@ -25,7 +25,7 @@
#ifdef __clang__
/* clang uses overloads; see https://github.com/llvm/llvm-project/issues/53516 */
-#define _FORTIFY_POSN(n) const __attribute__((__pass_object_size__(n)))
+#define _FORTIFY_POSN(n) const __attribute__((pass_object_size(n)))
/* we can't use extern inline with overloads without making them external */
#define _FORTIFY_INLINE static __inline__ \
__attribute__((__always_inline__,__artificial__,__overloadable__))
@@ -38,6 +38,7 @@
#endif /* __clang__ */
+/* https://gcc.gnu.org/onlinedocs/gcc/Object-Size-Checking.html */
#define _FORTIFY_POS0 _FORTIFY_POSN(0)
#define _FORTIFY_POS1 _FORTIFY_POSN(1)
#define _FORTIFY_POS2 _FORTIFY_POSN(2)
@@ -47,7 +48,6 @@
#define _FORTIFY_FNB(fn) _FORTIFY_ORIG(__USER_LABEL_PREFIX__,fn)
#define _FORTIFY_FN(fn) _FORTIFY_FNB(fn); _FORTIFY_INLINE
-
/* Use __builtin_dynamic_object_size with _FORTIFY_SOURCE>2, if available. */
#if _FORTIFY_SOURCE > 2 && __has_builtin (__builtin_dynamic_object_size)
/*
@@ -73,7 +73,11 @@
#endif
#if __has_attribute (malloc)
+#ifdef __clang__
+#define __malloc(...) __attribute__ ((malloc))
+#else
#define __malloc(...) __attribute__ ((malloc, __VA_ARGS__))
+#endif /* __clang__ */
#else
#define __malloc(...)
#endif
diff --git a/include/stdio.h b/include/stdio.h
@@ -36,15 +36,13 @@ extern "C" {
#undef fread
#undef fwrite
#undef popen
-#undef tmpfile
#undef snprintf
#undef sprintf
#undef vsnprintf
#undef vsprintf
__access(read_only, 2)
-__malloc(malloc (fclose, 1))
-_FORTIFY_FN(fdopen) FILE *fdopen(int __f, const char* __m)
+_FORTIFY_FN(fdopen) FILE *fdopen(int __f, const char* _FORTIFY_POS0 __m)
{
return __orig_fdopen(__f, __m);
}
@@ -60,7 +58,7 @@ _FORTIFY_FN(fgets) char *fgets(char * _FORTIFY_POS0 __s, int __n, FILE *__f)
}
__malloc(malloc (fclose, 1))
-_FORTIFY_FN(fmemopen) FILE *fmemopen(void* __b, size_t __s, const char* __m)
+_FORTIFY_FN(fmemopen) FILE *fmemopen(void* _FORTIFY_POS0 __b, size_t __s, const char* _FORTIFY_POS0 __m)
{
return __orig_fmemopen(__b, __s, __m);
}
@@ -68,7 +66,7 @@ _FORTIFY_FN(fmemopen) FILE *fmemopen(void* __b, size_t __s, const char* __m)
__access(read_only, 1)
__access(read_only, 2)
__malloc(malloc (fclose, 1))
-_FORTIFY_FN(fopen) FILE *fopen(const char* __p, const char* __m)
+_FORTIFY_FN(fopen) FILE *fopen(const char* _FORTIFY_POS0 __p, const char* _FORTIFY_POS0 __m)
{
return __orig_fopen(__p, __m);
}
@@ -100,16 +98,19 @@ _FORTIFY_FN(fwrite) size_t fwrite(const void * _FORTIFY_POS0 __d, size_t __n,
}
__malloc(malloc (pclose, 1))
-_FORTIFY_FN(popen) FILE *popen(const char* __c, const char* __t)
+_FORTIFY_FN(popen) FILE *popen(const char* _FORTIFY_POS0 __c, const char* _FORTIFY_POS0 __t)
{
return __orig_popen(__c, __t);
}
+#ifndef __clang__ /* FIXME */
+#undef tmpfile
__malloc(malloc (fclose, 1))
_FORTIFY_FN(tmpfile) FILE *tmpfile(void)
{
return __orig_tmpfile();
}
+#endif
__access(read_write, 1, 2)
_FORTIFY_FN(vsnprintf) int vsnprintf(char * _FORTIFY_POS0 __s, size_t __n,
diff --git a/include/stdlib.h b/include/stdlib.h
@@ -38,6 +38,7 @@ extern "C" {
#undef malloc
#undef realloc
+#undef calloc
__malloc(malloc (free, 1))
__alloc_size(1)
diff --git a/tests/Makefile b/tests/Makefile
@@ -31,7 +31,6 @@ TARGETS= \
test_gethostname_static \
test_getlogin_r_dynamic \
test_getlogin_r_static \
- test_malloc \
test_memchr_dynamic_read \
test_memchr_static_read \
test_memcpy_dynamic_read \
@@ -103,7 +102,9 @@ gcc: clean all
clang: CC=clang
clang: GCOV=gcov
clang: CFLAGS+=-I/usr/include/x86_64-linux-musl
-clang: CLFAGS+=-nostdlib
+clang: CFLAGS+=-I../x86_64-linux-musl-native/include/
+clang: CFLAGS+=-Ix86_64-linux-musl-native/include/
+clang: CFLAGS+=-nostdinc
clang: clean all
diff --git a/tests/test_malloc.c b/tests/test_malloc.c
@@ -1,7 +0,0 @@
-#include "common.h"
-
-#include <stdlib.h>
-
-int main(int argc, char** argv) {
- free(malloc(1));
-}
diff --git a/tests/test_vsnprintf_dynamic.c b/tests/test_vsnprintf_dynamic.c
@@ -10,6 +10,7 @@ int msg_valid(int n, const char * format, ... ) {
va_start (args, format);
vsnprintf(buffer, n, format, args);
va_end (args);
+ return 0;
}
int msg(int n, const char * format, ... ) {
diff --git a/tests/test_vsnprintf_static.c b/tests/test_vsnprintf_static.c
@@ -10,6 +10,7 @@ int msg_valid(int n, const char * format, ... ) {
va_start (args, format);
vsnprintf(buffer, n, format, args);
va_end (args);
+ return 0;
}
int msg(int n, const char * format, ... ) {
diff --git a/tests/test_vsprintf.c b/tests/test_vsprintf.c
@@ -10,6 +10,7 @@ int msg_valid(const char * format, ... ) {
va_start (args, format);
vsprintf(buffer, format, args);
va_end (args);
+ return 0;
}
int msg(const char * format, ... ) {