Skip to content

Commit

Permalink
clang: support gcov ARM LLVM clang supports code coverage detection t…
Browse files Browse the repository at this point in the history
…ools

1. Create a libbuiltin folder under libs for building toolchain related libraries such as libgcc and compiler rt
2. The code coverage tool for LLVM clang requires the use of the profile library in the compiler rt under LLVM, which needs to be built-in into the kernel code
3. Porting the compiler rt library for LLVM
4. Implement InstrProfilingPlatformNX.c on the NX platform

Signed-off-by: wangmingrong1 <[email protected]>
  • Loading branch information
W-M-R committed Oct 15, 2024
1 parent 366ede9 commit 4645801
Show file tree
Hide file tree
Showing 14 changed files with 424 additions and 0 deletions.
1 change: 1 addition & 0 deletions Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2759,6 +2759,7 @@ source "libs/libc/Kconfig"
source "libs/libm/Kconfig"
source "libs/libxx/Kconfig"
source "libs/libdsp/Kconfig"
source "libs/libbuiltin/Kconfig"
endmenu

menu "Open Asymmetric Multi Processing"
Expand Down
3 changes: 3 additions & 0 deletions libs/libbuiltin/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/compiler-rt/compiler-rt
*.o
.depend
29 changes: 29 additions & 0 deletions libs/libbuiltin/Kconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#
# For a description of the syntax of this configuration file,
# see the file kconfig-language.txt in the NuttX tools repository.
#

comment "Toolchains Library Support"

config TOOLCHAINS_BUILTIN
bool "Builtin toolchains support"
default n
---help---
Choose to compile libraries related to toolchains into the OS

config BUILTIN_COMPILER_RT
bool "Builtin LLVM Compiler-rt"
depends on ARM_TOOLCHAIN_CLANG
select TOOLCHAINS_BUILTIN
default y
---help---
Compile the LLVM Compiler-rt library into the OS.

if BUILTIN_COMPILER_RT

config COMPILER_RT_VERSION
string "Select LLVM Compiler-rt version"
depends on BUILTIN_COMPILER_RT
default "15.0.2"

endif # COMPILER_RT_VERSION
83 changes: 83 additions & 0 deletions libs/libbuiltin/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
############################################################################
# libs/libbuiltin/Makefile
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
###########################################################################

include $(TOPDIR)/Make.defs

ifeq ($(CONFIG_BUILTIN_COMPILER_RT),y)
include compiler-rt/Make.defs
endif

BIN ?= libbuiltin$(LIBEXT)
BINDIR ?= bin

KBIN = libkbuiltin$(LIBEXT)
KBINDIR = kbin

AOBJS = $(addprefix $(BINDIR)$(DELIM), $(ASRCS:.S=$(OBJEXT)))
COBJS = $(addprefix $(BINDIR)$(DELIM), $(CSRCS:.c=$(OBJEXT)))
CXXOBJS = $(addprefix $(BINDIR)$(DELIM), $(CXXSRCS:.cxx=$(OBJEXT)))
CPPOBJS = $(addprefix $(BINDIR)$(DELIM), $(CPPSRCS:.cpp=$(OBJEXT)))

SRCS = $(ASRCS) $(CSRCS) $(CXXSRCS) $(CPPSRCS)
OBJS = $(AOBJS) $(COBJS) $(CXXOBJS) $(CPPOBJS)

all: $(OBJS)
$(call ARCHIVE, $(BIN), $(OBJS))

.PHONY: depend clean distclean context $(LIBBUILTIN)

$(AOBJS): $(BINDIR)$(DELIM)%$(OBJEXT): %.S
$(call ASSEMBLE, $<, $@)

$(COBJS): $(BINDIR)$(DELIM)%$(OBJEXT): %.c
$(call COMPILE, $<, $@)

$(CXXOBJS): $(BINDIR)$(DELIM)%$(OBJEXT): %.cxx
$(call COMPILEXX, $<, $@)

$(CPPOBJS): $(BINDIR)$(DELIM)%$(OBJEXT): %.cpp
$(call COMPILEXX, $<, $@)

context::

.depend: $(LIBBUILTIN)
$(Q) touch $@

depend: .depend

$(BIN): depend
$(Q) $(MAKE) all EXTRAFLAGS="$(EXTRAFLAGS)"

# C library for the kernel phase of the two-pass kernel build

ifneq ($(BIN),$(KBIN))
$(KBIN): $(OBJS)
$(Q) $(MAKE) $(KBIN) BIN=$(KBIN) BINDIR=$(KBINDIR) EXTRAFLAGS="$(EXTRAFLAGS)"
endif

clean:
$(call DELFILE, $(BIN))
$(Q) $(MAKE) -C bin clean
$(Q) $(MAKE) -C kbin clean

distclean: clean
$(Q) $(MAKE) -C bin distclean
$(Q) $(MAKE) -C kbin distclean
$(call DELFILE, .depend)
35 changes: 35 additions & 0 deletions libs/libbuiltin/bin/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
############################################################################
# libs/libbuiltin/bin/Makefile
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
###########################################################################

include $(TOPDIR)/Make.defs

all:
.PHONY: clean distclean

# Clean Targets:

clean:
$(call DELFILE, *.o)

# Deep clean -- removes all traces of the configuration

distclean: clean
$(call DELFILE, *.dep)
$(call DELFILE, .depend)
131 changes: 131 additions & 0 deletions libs/libbuiltin/compiler-rt/InstrProfilingPlatformNX.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
/****************************************************************************
* libs/libbuiltin/compiler-rt/InstrProfilingPlatformNX.c
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership. The
* ASF licenses this file to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*
****************************************************************************/

/****************************************************************************
* Included Files
****************************************************************************/

#include <stdlib.h>
#include <stdio.h>

#include "InstrProfiling.h"
#include "InstrProfilingInternal.h"

/****************************************************************************
* Public Data
****************************************************************************/

extern char __start__llvm_prf_names[];
extern char __end__llvm_prf_names[];
extern char __start__llvm_prf_data[];
extern char __end__llvm_prf_data[];
extern char __start__llvm_prf_vnds[];
extern char __end__llvm_prf_vnds[];
extern char __start__llvm_prf_cnts[];
extern char __end__llvm_prf_cnts[];

COMPILER_RT_VISIBILITY ValueProfNode *CurrentVNode = 0;
COMPILER_RT_VISIBILITY ValueProfNode *EndVNode = 0;

/****************************************************************************
* Public Functions
****************************************************************************/

COMPILER_RT_VISIBILITY
void __llvm_profile_register_function(void *Data_)
{
}

COMPILER_RT_VISIBILITY
void __llvm_profile_register_names_function(void *NamesStart,
uint64_t NamesSize)
{
}

COMPILER_RT_VISIBILITY
const __llvm_profile_data *__llvm_profile_begin_data(void)
{
return &__start__llvm_prf_data;
}

COMPILER_RT_VISIBILITY
const __llvm_profile_data *__llvm_profile_end_data(void)
{
return &__end__llvm_prf_data;
}

COMPILER_RT_VISIBILITY
const char *__llvm_profile_begin_names(void)
{
return &__start__llvm_prf_names;
}

COMPILER_RT_VISIBILITY
const char *__llvm_profile_end_names(void)
{
return &__end__llvm_prf_names;
}

COMPILER_RT_VISIBILITY
char *__llvm_profile_begin_counters(void)
{
return &__start__llvm_prf_cnts;
}

COMPILER_RT_VISIBILITY
char *__llvm_profile_end_counters(void)
{
return &__end__llvm_prf_cnts;
}

COMPILER_RT_VISIBILITY
char *__llvm_profile_begin_bitmap(void)
{
return 0;
}

COMPILER_RT_VISIBILITY
char *__llvm_profile_end_bitmap(void)
{
return 0;
}

COMPILER_RT_VISIBILITY
uint32_t *__llvm_profile_begin_orderfile(void)
{
return 0;
}

COMPILER_RT_VISIBILITY
ValueProfNode *__llvm_profile_begin_vnodes(void)
{
return 0;
}

COMPILER_RT_VISIBILITY
ValueProfNode *__llvm_profile_end_vnodes(void)
{
return 0;
}

COMPILER_RT_VISIBILITY int __llvm_write_binary_ids(ProfDataWriter *Writer)
{
return 0;
}
58 changes: 58 additions & 0 deletions libs/libbuiltin/compiler-rt/Make.defs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
############################################################################
# libs/libbuiltin/compiler-rt/Make.defs
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
############################################################################

include $(TOPDIR)/Make.defs

LIBBUILTIN += compiler-rt

ifeq ($(wildcard compiler-rt/compiler-rt/lib),)
compiler-rt-$(CONFIG_COMPILER_RT_VERSION).src.tar.xz:
$(call DOWNLOAD,https://github.com/llvm/llvm-project/releases/download/llvmorg-$(CONFIG_COMPILER_RT_VERSION),$@)

compiler-rt/compiler-rt: compiler-rt-$(CONFIG_COMPILER_RT_VERSION).src.tar.xz
$(Q) tar -xf $<
$(Q) mv compiler-rt-$(CONFIG_COMPILER_RT_VERSION).src $@
$(call DELDIR, $<)

compiler-rt: compiler-rt/compiler-rt
endif

FLAGS += ${INCDIR_PREFIX}$(CURDIR)/compiler-rt/compiler-rt/include
FLAGS += ${INCDIR_PREFIX}$(CURDIR)/compiler-rt/compiler-rt/lib/profile
FLAGS += -Wno-strict-prototypes -Wno-shadow -Wno-cleardeprecated-pragma
FLAGS += -Wno-deprecated-pragma -Wno-undef -Wno-incompatible-pointer-types
FLAGS += -Wno-unknown-warning-option -Wno-deprecated-pragma
FLAGS += -DCOMPILER_RT_HAS_UNAME

CFLAGS += $(FLAGS)
CXXFLAGS += $(FLAGS)

CSRCS += GCDAProfiling.c InstrProfilingBuffer.c InstrProfiling.c InstrProfilingFile.c InstrProfilingInternal.c
CSRCS += InstrProfilingMerge.c InstrProfilingMergeFile.c InstrProfilingNameVar.c
CSRCS += InstrProfilingUtil.c InstrProfilingValue.c InstrProfilingVersionVar.c InstrProfilingWriter.c
CPPSRCS += InstrProfilingRuntime.cpp

CSRCS += InstrProfilingPlatformNX.c

DEPPATH += --dep-path compiler-rt/compiler-rt/lib/profile
VPATH += :compiler-rt/compiler-rt/lib/profile

DEPPATH += --dep-path compiler-rt
VPATH += :compiler-rt
35 changes: 35 additions & 0 deletions libs/libbuiltin/kbin/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
############################################################################
# libs/libbuiltin/kbin/Makefile
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership. The
# ASF licenses this file to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
#
###########################################################################

include $(TOPDIR)/Make.defs

all:
.PHONY: clean distclean

# Clean Targets:

clean:
$(call DELFILE, *.o)

# Deep clean -- removes all traces of the configuration

distclean: clean
$(call DELFILE, *.dep)
$(call DELFILE, .depend)
Loading

0 comments on commit 4645801

Please sign in to comment.