Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[build] make LK buildable with LLVM/Clang #322

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions arch/arm64/include/arch/asm_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -63,11 +63,9 @@ ldp \ra, \rb, [sp], #16
mov x1, #8
bl arch_clean_invalidate_cache_range

.if \phys_offset != 0
/* clear page */
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
Expand Down
2 changes: 2 additions & 0 deletions arch/arm64/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,9 @@ ARCH_COMPILEFLAGS_FLOAT :=

ARCH_LDFLAGS += -z max-page-size=4096

ifeq ($(LLVM),)
LIBGCC := $(shell $(TOOLCHAIN_PREFIX)gcc $(GLOBAL_COMPILEFLAGS) $(ARCH_COMPILEFLAGS) -print-libgcc-file-name)
endif

# make sure some bits were set up
MEMVARS_SET := 0
Expand Down
4 changes: 4 additions & 0 deletions arch/arm64/toolchain.mk
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
ifndef ARCH_arm64_TOOLCHAIN_INCLUDED
ARCH_arm64_TOOLCHAIN_INCLUDED := 1

ifneq ($(LLVM),)
LLVM_TARGET_TRIPLE := aarch64-elf
else
ifndef ARCH_arm64_TOOLCHAIN_PREFIX
ARCH_arm64_TOOLCHAIN_PREFIX := aarch64-elf-
FOUNDTOOL=$(shell which $(ARCH_arm64_TOOLCHAIN_PREFIX)gcc)
Expand All @@ -14,3 +17,4 @@ endif
endif
endif
endif
endif
20 changes: 19 additions & 1 deletion engine.mk
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ GLOBAL_INCLUDES := $(BUILDDIR) $(addsuffix /include,$(LKINC))
GLOBAL_OPTFLAGS ?= $(ARCH_OPTFLAGS)
GLOBAL_COMPILEFLAGS := -g -include $(CONFIGHEADER)
GLOBAL_COMPILEFLAGS += -Wextra -Wall -Werror=return-type -Wshadow -Wdouble-promotion
GLOBAL_COMPILEFLAGS += -Wno-multichar -Wno-unused-parameter -Wno-unused-function -Wno-unused-label -Wno-nonnull-compare
GLOBAL_COMPILEFLAGS += -Wno-multichar -Wno-unused-parameter -Wno-unused-function -Wno-unused-label
ifeq ($(LLVM),)
GLOBAL_COMPILEFLAGS += -Wno-nonnull-compare
endif
GLOBAL_COMPILEFLAGS += -fno-common
GLOBAL_CFLAGS := --std=gnu11 -Werror-implicit-function-declaration -Wstrict-prototypes -Wwrite-strings
GLOBAL_CPPFLAGS := --std=c++14 -fno-exceptions -fno-rtti -fno-threadsafe-statics
Expand Down Expand Up @@ -159,9 +162,11 @@ ifndef ARCH
$(error couldn't find arch or platform doesn't define arch)
endif
include arch/$(ARCH)/rules.mk
ifeq ($(LLVM),)
ifndef TOOLCHAIN_PREFIX
$(error TOOLCHAIN_PREFIX not set in the arch rules.mk)
endif
endif

$(info PROJECT = $(PROJECT))
$(info PLATFORM = $(PLATFORM))
Expand Down Expand Up @@ -215,6 +220,18 @@ endif

# default to no ccache
CCACHE ?=

ifneq ($(LLVM),)
CC := $(CCACHE) clang --target=$(LLVM_TARGET_TRIPLE)
LIBGCC := $(shell $(CC) $(GLOBAL_COMPILEFLAGS) $(ARCH_COMPILEFLAGS) -print-libgcc-file-name)
LD := ld.lld
OBJDUMP := llvm-objdump
OBJCOPY := llvm-objcopy
CPPFILT := llvm-cxxfilt
SIZE := llvm-size
NM := llvm-nm
STRIP := llvm-strip
else
CC := $(CCACHE) $(TOOLCHAIN_PREFIX)gcc
LD := $(TOOLCHAIN_PREFIX)ld
OBJDUMP := $(TOOLCHAIN_PREFIX)objdump
Expand All @@ -223,6 +240,7 @@ CPPFILT := $(TOOLCHAIN_PREFIX)c++filt
SIZE := $(TOOLCHAIN_PREFIX)size
NM := $(TOOLCHAIN_PREFIX)nm
STRIP := $(TOOLCHAIN_PREFIX)strip
endif

# try to have the compiler output colorized error messages if available
export GCC_COLORS ?= 1
Expand Down
8 changes: 4 additions & 4 deletions lib/heap/heap_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {}

static inline 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();

Expand All @@ -102,10 +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);
}

Expand Down
4 changes: 2 additions & 2 deletions make/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ $(OUTELF).hex: $(OUTELF)
$(OUTELF): $(ALLMODULE_OBJS) $(EXTRA_OBJS) $(LINKER_SCRIPT) $(EXTRA_LINKER_SCRIPTS)
$(info linking $@)
$(NOECHO)$(SIZE) -t --common $(sort $(ALLMODULE_OBJS)) $(EXTRA_OBJS)
$(NOECHO)$(LD) $(GLOBAL_LDFLAGS) $(ARCH_LDFLAGS) -dT $(LINKER_SCRIPT) \
$(addprefix -T,$(EXTRA_LINKER_SCRIPTS)) \
$(NOECHO)$(LD) $(GLOBAL_LDFLAGS) $(ARCH_LDFLAGS) \
$(addprefix -T,$(EXTRA_LINKER_SCRIPTS)) -T $(LINKER_SCRIPT) \
$(ALLMODULE_OBJS) $(EXTRA_OBJS) $(LIBGCC) -Map=$(OUTELF).map -o $@

$(OUTELF).sym: $(OUTELF)
Expand Down
2 changes: 2 additions & 0 deletions make/help.mk
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ help:
@echo "Environment or command line variables controlling build:"
@echo "PROJECT = <project name>"
@echo "TOOLCHAIN_PREFIX = <absolute path to toolchain or relative path with prefix>"
@echo "LLVM = 1 # use LLVM tools instead of GCC and binutils;"
@echo " # user should add tools to PATH instead of specifying TOOLCHAIN_PREFIX"
@echo ""
@echo "Special make targets:"
@echo "make help: This help"
Expand Down