Warnings: "... specifies less restrictive attributes than its target"
mxmlnkn opened this issue · 4 comments
Hi there,
I'm trying to integrate rpmalloc in my program and I get a lot of warnings when compiling with gcc 11.3.0:
[1/4] Building C object src/CMakeFiles/rpmalloc.dir/external/rpmalloc/rpmalloc/rpmalloc.c.o
In file included from rpmalloc.c:3561:
malloc.c:466:7: warning: ‘__libc_memalign’ specifies less restrictive attributes than its target ‘rpmemalign’: ‘alloc_size’, ‘malloc’ [-Wmissing-attributes]
466 | void* __libc_memalign(size_t align, size_t size) RPALIAS(rpmemalign)
| ^~~~~~~~~~~~~~~
rpmalloc.c:3145:1: note: ‘__libc_memalign’ target declared here
3145 | rpmemalign(size_t alignment, size_t size) {
| ^~~~~~~~~~
In file included from rpmalloc.c:3561:
malloc.c:463:7: warning: ‘__libc_realloc’ specifies less restrictive attributes than its target ‘rprealloc’: ‘alloc_size’, ‘malloc’ [-Wmissing-attributes]
463 | void* __libc_realloc(void* p, size_t size) RPALIAS(rprealloc)
| ^~~~~~~~~~~~~~
rpmalloc.c:3088:1: note: ‘__libc_realloc’ target declared here
3088 | rprealloc(void* ptr, size_t size) {
| ^~~~~~~~~
In file included from rpmalloc.c:3561:
malloc.c:462:7: warning: ‘__libc_calloc’ specifies less restrictive attributes than its target ‘rpcalloc’: ‘alloc_size’, ‘malloc’ [-Wmissing-attributes]
462 | void* __libc_calloc(size_t count, size_t size) RPALIAS(rpcalloc)
| ^~~~~~~~~~~~~
rpmalloc.c:3061:1: note: ‘__libc_calloc’ target declared here
3061 | rpcalloc(size_t num, size_t size) {
| ^~~~~~~~
In file included from rpmalloc.c:3561:
malloc.c:461:7: warning: ‘__libc_malloc’ specifies less restrictive attributes than its target ‘rpmalloc’: ‘alloc_size’, ‘malloc’ [-Wmissing-attributes]
461 | void* __libc_malloc(size_t size) RPALIAS(rpmalloc)
| ^~~~~~~~~~~~~
rpmalloc.c:3044:1: note: ‘__libc_malloc’ target declared here
3044 | rpmalloc(size_t size) {
| ^~~~~~~~
In file included from rpmalloc.c:3561:
malloc.c:249:7: warning: ‘memalign’ specifies less restrictive attributes than its target ‘rpmemalign’: ‘alloc_size’, ‘malloc’ [-Wmissing-attributes]
249 | void* memalign(size_t alignment, size_t size) RPALIAS(rpmemalign)
| ^~~~~~~~
rpmalloc.c:3145:1: note: ‘memalign’ target declared here
3145 | rpmemalign(size_t alignment, size_t size) {
| ^~~~~~~~~~
In file included from rpmalloc.c:3561:
malloc.c:247:7: warning: ‘reallocf’ specifies less restrictive attributes than its target ‘rprealloc’: ‘alloc_size’, ‘malloc’ [-Wmissing-attributes]
247 | void* reallocf(void* ptr, size_t size) RPALIAS(rprealloc)
| ^~~~~~~~
rpmalloc.c:3088:1: note: ‘reallocf’ target declared here
3088 | rprealloc(void* ptr, size_t size) {
| ^~~~~~~~~
In file included from rpmalloc.c:3561:
malloc.c:207:7: warning: ‘_Znam’ specifies less restrictive attributes than its target ‘rpmalloc’: ‘alloc_size’, ‘malloc’ [-Wmissing-attributes]
207 | void* _Znam(uint64_t size) RPALIAS(rpmalloc)
| ^~~~~
rpmalloc.c:3044:1: note: ‘_Znam’ target declared here
3044 | rpmalloc(size_t size) {
| ^~~~~~~~
In file included from rpmalloc.c:3561:
malloc.c:206:7: warning: ‘_Znwm’ specifies less restrictive attributes than its target ‘rpmalloc’: ‘alloc_size’, ‘malloc’ [-Wmissing-attributes]
206 | void* _Znwm(uint64_t size) RPALIAS(rpmalloc)
| ^~~~~
rpmalloc.c:3044:1: note: ‘_Znwm’ target declared here
3044 | rpmalloc(size_t size) {
| ^~~~~~~~
Could you paste your entire command line for gcc? I tried compiling the repository tests with gcc 12.2 and
./configure.py --toolchain gcc
ninja
and did not get any warnings
Actually scratch that, I pushed some fixes, give it a try
I have checked with 29fb845 and I see no improvement.
This is what fixes the warnings for me:
diff --git a/rpmalloc/malloc.c b/rpmalloc/malloc.c
index 59496f0..af278c0 100644
--- a/rpmalloc/malloc.c
+++ b/rpmalloc/malloc.c
@@ -203,8 +203,8 @@ void _ZdaPv(void* p) RPALIAS(rpfree)
#if ARCH_64BIT
// 64-bit operators new and new[], normal and aligned
-void* _Znwm(uint64_t size) RPALIAS(rpmalloc)
-void* _Znam(uint64_t size) RPALIAS(rpmalloc)
+void* _Znwm(uint64_t size) RPMALLOC_ATTRIB_MALLOC RPMALLOC_ATTRIB_ALLOC_SIZE(1) RPALIAS(rpmalloc)
+void* _Znam(uint64_t size) RPMALLOC_ATTRIB_MALLOC RPMALLOC_ATTRIB_ALLOC_SIZE(1) RPALIAS(rpmalloc)
void* _Znwmm(uint64_t size, uint64_t align) RPALIAS(rpaligned_alloc_reverse)
void* _Znamm(uint64_t size, uint64_t align) RPALIAS(rpaligned_alloc_reverse)
void* _ZnwmSt11align_val_t(size_t size, size_t align) RPALIAS(rpaligned_alloc_reverse)
@@ -222,8 +222,8 @@ void _ZdlPvmSt11align_val_t(void* p, size_t n, size_t a) RPALIAS(rpfree_size_ali
void _ZdaPvmSt11align_val_t(void* p, size_t n, size_t a) RPALIAS(rpfree_size_aligned)
#else
// 32-bit operators new and new[], normal and aligned
-void* _Znwj(uint32_t size) RPALIAS(rpmalloc)
-void* _Znaj(uint32_t size) RPALIAS(rpmalloc)
+void* _Znwj(uint32_t size) RPMALLOC_ATTRIB_MALLOC RPMALLOC_ATTRIB_ALLOC_SIZE(1) RPALIAS(rpmalloc)
+void* _Znaj(uint32_t size) RPMALLOC_ATTRIB_MALLOC RPMALLOC_ATTRIB_ALLOC_SIZE(1) RPALIAS(rpmalloc)
void* _Znwjj(uint32_t size, uint32_t align) RPALIAS(rpaligned_alloc_reverse)
void* _Znajj(uint32_t size, uint32_t align) RPALIAS(rpaligned_alloc_reverse)
void* _ZnwjSt11align_val_t(size_t size, size_t align) RPALIAS(rpaligned_alloc_reverse)
@@ -241,12 +241,12 @@ void _ZdlPvjSt11align_val_t(void* p, size_t n, size_t a) RPALIAS(rpfree_size_ali
void _ZdaPvjSt11align_val_t(void* p, size_t n, size_t a) RPALIAS(rpfree_size_aligned)
#endif
-void* malloc(size_t size) RPALIAS(rpmalloc)
+void* malloc(size_t size) RPMALLOC_ATTRIB_MALLOC RPMALLOC_ATTRIB_ALLOC_SIZE(1) RPALIAS(rpmalloc)
void* calloc(size_t count, size_t size) RPALIAS(rpcalloc)
void* realloc(void* ptr, size_t size) RPALIAS(rprealloc)
-void* reallocf(void* ptr, size_t size) RPALIAS(rprealloc)
+void* reallocf(void* ptr, size_t size) RPMALLOC_ATTRIB_MALLOC RPMALLOC_ATTRIB_ALLOC_SIZE(2) RPALIAS(rprealloc)
void* aligned_alloc(size_t alignment, size_t size) RPALIAS(rpaligned_alloc)
-void* memalign(size_t alignment, size_t size) RPALIAS(rpmemalign)
+void* memalign(size_t alignment, size_t size) RPMALLOC_ATTRIB_MALLOC RPMALLOC_ATTRIB_ALLOC_SIZE(2) RPALIAS(rpmemalign)
int posix_memalign(void** memptr, size_t alignment, size_t size) RPALIAS(rpposix_memalign)
void free(void* ptr) RPALIAS(rpfree)
void cfree(void* ptr) RPALIAS(rpfree)
@@ -458,12 +458,12 @@ pthread_create(pthread_t* thread,
#if defined(__GLIBC__) && defined(__linux__)
-void* __libc_malloc(size_t size) RPALIAS(rpmalloc)
-void* __libc_calloc(size_t count, size_t size) RPALIAS(rpcalloc)
-void* __libc_realloc(void* p, size_t size) RPALIAS(rprealloc)
+void* __libc_malloc(size_t size) RPMALLOC_ATTRIB_MALLOC RPMALLOC_ATTRIB_ALLOC_SIZE(1) RPALIAS(rpmalloc)
+void* __libc_calloc(size_t count, size_t size) RPMALLOC_ATTRIB_MALLOC RPMALLOC_ATTRIB_ALLOC_SIZE2(1, 2) RPALIAS(rpcalloc)
+void* __libc_realloc(void* p, size_t size) RPMALLOC_ATTRIB_MALLOC RPMALLOC_ATTRIB_ALLOC_SIZE(2) RPALIAS(rprealloc)
void __libc_free(void* p) RPALIAS(rpfree)
void __libc_cfree(void* p) RPALIAS(rpfree)
-void* __libc_memalign(size_t align, size_t size) RPALIAS(rpmemalign)
+void* __libc_memalign(size_t align, size_t size) RPMALLOC_ATTRIB_MALLOC RPMALLOC_ATTRIB_ALLOC_SIZE(2) RPALIAS(rpmemalign)
int __posix_memalign(void** p, size_t align, size_t size) RPALIAS(rpposix_memalign)
extern void* __libc_valloc(size_t size);
But take it with a grain of salt as I have no idea what I'm doing. Maybe suppressing the warnings is the correct path instead.
Similar issue with jemalloc: jemalloc/jemalloc#1612
Btw, the source files contain a lot of trailing whitespaces, which made it harder to provide this diff than it had to be because my editor automatically deletes trailing whitespaces. Fix for trailing whitespaces:
diff --git a/rpmalloc/malloc.c b/rpmalloc/malloc.c
index af278c0..ecd9330 100644
--- a/rpmalloc/malloc.c
+++ b/rpmalloc/malloc.c
@@ -358,7 +358,7 @@ __declspec(allocate(".CRT$XIB")) void (*_rpmalloc_module_init)(void) = _global_r
#endif
//end !BUILD_DYNAMIC_LINK
-#endif
+#endif
#else
diff --git a/rpmalloc/rpmalloc.c b/rpmalloc/rpmalloc.c
index c018b4c..908fdd9 100644
--- a/rpmalloc/rpmalloc.c
+++ b/rpmalloc/rpmalloc.c
@@ -311,7 +311,7 @@ static FORCEINLINE int atomic_cas_ptr(atomicptr_t* dst, void* val, void* ref
#define EXPECTED(x) __builtin_expect((x), 1)
#define UNEXPECTED(x) __builtin_expect((x), 0)
-
+
#endif
////////////
@@ -1350,7 +1350,7 @@ _rpmalloc_span_initialize_new(heap_t* heap, heap_size_class_t* heap_size_class,
//Setup free list. Only initialize one system page worth of free blocks in list
void* block;
- span->free_list_limit = free_list_partial_init(&heap_size_class->free_list, &block,
+ span->free_list_limit = free_list_partial_init(&heap_size_class->free_list, &block,
span, pointer_offset(span, SPAN_HEADER_SIZE), size_class->block_count, size_class->block_size);
//Link span as partial if there remains blocks to be initialized as free list, or full if fully initialized
if (span->free_list_limit < span->block_count) {
@@ -1454,7 +1454,7 @@ _rpmalloc_global_cache_finalize(global_cache_t* cache) {
static void
_rpmalloc_global_cache_insert_spans(span_t** span, size_t span_count, size_t count) {
- const size_t cache_limit = (span_count == 1) ?
+ const size_t cache_limit = (span_count == 1) ?
GLOBAL_CACHE_MULTIPLIER * MAX_THREAD_SPAN_CACHE :
GLOBAL_CACHE_MULTIPLIER * (MAX_THREAD_SPAN_LARGE_CACHE - (span_count >> 1));
@@ -1479,7 +1479,7 @@ _rpmalloc_global_cache_insert_spans(span_t** span, size_t span_count, size_t cou
// Enable unlimited cache if huge pages, or we will leak since it is unlikely that an entire huge page
// will be unmapped, and we're unable to partially decommit a huge page
while ((_memory_page_size > _memory_span_size) && (insert_count < count)) {
-#endif
+#endif
span_t* current_span = span[insert_count++];
current_span->next = cache->overflow;
cache->overflow = current_span;
@@ -2151,7 +2151,7 @@ _rpmalloc_allocate_from_heap_fallback(heap_t* heap, heap_size_class_t* heap_size
heap_size_class->free_list = span->free_list;
span->free_list = 0;
} else {
- //If the span did not fully initialize free list, link up another page worth of blocks
+ //If the span did not fully initialize free list, link up another page worth of blocks
void* block_start = pointer_offset(span, SPAN_HEADER_SIZE + ((size_t)span->free_list_limit * span->block_size));
span->free_list_limit += free_list_partial_init(&heap_size_class->free_list, &block,
(void*)((uintptr_t)block_start & ~(_memory_page_size - 1)), block_start,
@@ -2999,7 +2999,7 @@ rpmalloc_finalize(void) {
_memory_global_reserve_count = 0;
_memory_global_reserve = 0;
}
- atomic_store32_release(&_memory_global_lock, 0);
+ atomic_store32_release(&_memory_global_lock, 0);
//Free all thread caches and fully free spans
for (size_t list_idx = 0; list_idx < HEAP_ARRAY_SIZE; ++list_idx) {
@@ -3174,7 +3174,7 @@ rpaligned_calloc(size_t alignment, size_t num, size_t size) {
return block;
}
-extern inline RPMALLOC_ALLOCATOR void*
+extern RPMALLOC_ALLOCATOR void*
rpmemalign(size_t alignment, size_t size) {
return rpaligned_alloc(alignment, size);
}
@@ -3502,7 +3502,7 @@ rpmalloc_heap_aligned_realloc(rpmalloc_heap_t* heap, void* ptr, size_t alignment
return 0;
}
#endif
- return _rpmalloc_aligned_reallocate(heap, ptr, alignment, size, 0, flags);
+ return _rpmalloc_aligned_reallocate(heap, ptr, alignment, size, 0, flags);
}
extern inline void
diff --git a/rpmalloc/rpmalloc.h b/rpmalloc/rpmalloc.h
index 7632e0c..049a24a 100644
--- a/rpmalloc/rpmalloc.h
+++ b/rpmalloc/rpmalloc.h
@@ -19,7 +19,7 @@ extern "C" {
#if defined(__clang__) || defined(__GNUC__)
# define RPMALLOC_EXPORT __attribute__((visibility("default")))
-# define RPMALLOC_ALLOCATOR
+# define RPMALLOC_ALLOCATOR
# if (defined(__clang_major__) && (__clang_major__ < 4)) || (defined(__GNUC__) && defined(ENABLE_PRELOAD) && ENABLE_PRELOAD)
# define RPMALLOC_ATTRIB_MALLOC
# define RPMALLOC_ATTRIB_ALLOC_SIZE(size)
I cleaned up the whitespace. Could you provide the changes to function declarations in a PR please?