From b57a56f249ec1e8b2870446137ec3c6f92924e93 Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Thu, 9 Dec 2021 11:02:59 +0000 Subject: [PATCH 1/6] [clang] Avoid a nested function in heap_wrapper.c This GCC extension is not supported by clang and in this case is not necessary. Move the function to the top level to avoid the syntax error. --- lib/heap/heap_wrapper.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/heap/heap_wrapper.c b/lib/heap/heap_wrapper.c index 162f643c16..2764f4265c 100644 --- a/lib/heap/heap_wrapper.c +++ b/lib/heap/heap_wrapper.c @@ -89,6 +89,10 @@ static inline void *HEAP_CALLOC(size_t n, size_t s) { #define HEAP_FREE(p) dlfree(p) static inline void HEAP_INIT(void) {} +void dump_callback(void *start, void *end, size_t used_bytes, void *arg) { + printf("\t\tstart %p end %p used_bytes %zu\n", start, end, used_bytes); +} + static inline void HEAP_DUMP(void) { struct mallinfo minfo = dlmallinfo(); @@ -102,9 +106,6 @@ static inline void HEAP_DUMP(void) { printf("\t\treleasable space 0x%zx\n", minfo.keepcost); printf("\theap block list:\n"); - void dump_callback(void *start, void *end, size_t used_bytes, void *arg) { - printf("\t\tstart %p end %p used_bytes %zu\n", start, end, used_bytes); - } dlmalloc_inspect_all(&dump_callback, NULL); } From 793175ca19c3dbe826c4269d6906a0bc1dc239db Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Thu, 9 Dec 2021 14:35:37 +0000 Subject: [PATCH 2/6] [clang][compiler.h] Expose a few more macros for Clang Clang sets the defines for GCC 4.2.1, so we have to check __clang__ for these macros in addition to the GCC version. --- top/include/lk/compiler.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/top/include/lk/compiler.h b/top/include/lk/compiler.h index 75c57a4a33..45b1dc81d2 100644 --- a/top/include/lk/compiler.h +++ b/top/include/lk/compiler.h @@ -87,19 +87,22 @@ #define __WARN_UNUSED_RESULT #endif -#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) +#if defined(__clang__) +/* Clang does not support externally_visible, used should be similar. */ +#define __EXTERNALLY_VISIBLE __attribute__((used)) +#elif (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1) #define __EXTERNALLY_VISIBLE __attribute__((externally_visible)) #else #define __EXTERNALLY_VISIBLE #endif -#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) +#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 5) || defined(__clang__) #define __UNREACHABLE __builtin_unreachable() #else #define __UNREACHABLE #endif -#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) +#if (__GNUC__ > 4) || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6) || defined(__clang__) #ifdef __cplusplus #define STATIC_ASSERT(e) static_assert(e, #e) #else From 684930ed7fce2af0f885ea1c2a364785a666748d Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Thu, 9 Dec 2021 14:40:59 +0000 Subject: [PATCH 3/6] [arm64] Allow assembling with clang Clang does not accept this .if condition since phys_offset is a register alias and not an absolute expression. We can keep these two instructions here if the argument is zero since the result will be the same. Additionally, this macro is only called once and always passes a non-zero argument. If more calls are added in the future and avoiding these two instructions just before a loop is really important, we could use `.ifnc \phys_offset,0` instead, but that looks rather obscure to me. --- arch/arm64/include/arch/asm_macros.h | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/arch/asm_macros.h b/arch/arm64/include/arch/asm_macros.h index 94df594ff2..9fe6c12037 100644 --- a/arch/arm64/include/arch/asm_macros.h +++ b/arch/arm64/include/arch/asm_macros.h @@ -36,7 +36,7 @@ ldp \ra, \rb, [sp], #16 .endif .endm -.macro calloc_bootmem_aligned, new_ptr, new_ptr_end, tmp, size_shift, phys_offset=0 +.macro calloc_bootmem_aligned, new_ptr, new_ptr_end, tmp, size_shift, phys_offset .if \size_shift < 4 .error "calloc_bootmem_aligned: Unsupported size_shift, \size_shift" .endif @@ -63,11 +63,9 @@ ldp \ra, \rb, [sp], #16 mov x1, #8 bl arch_clean_invalidate_cache_range -.if \phys_offset != 0 - /* clear page */ + /* calculate virtual address */ sub \new_ptr, \new_ptr, \phys_offset sub \new_ptr_end, \new_ptr_end, \phys_offset -.endif /* clean and invalidate new page */ mov x0, \new_ptr From c43761ed9497e1daab66c3d791f035b3adf61464 Mon Sep 17 00:00:00 2001 From: Alex Richardson Date: Thu, 9 Dec 2021 11:19:20 +0000 Subject: [PATCH 4/6] [make] Fix linker invocation to be compatible with ld.lld The LLD linker does not allow joined short arguments, so split -dT