diff --git a/Makefile b/Makefile index f5528fe10dd..90c80a18dd6 100644 --- a/Makefile +++ b/Makefile @@ -300,8 +300,10 @@ AS = $(CROSS_COMPILE)as LD = $(CROSS_COMPILE)ld ifeq ($(USE_CCACHE),1) CC = $(CCACHE) $(CROSS_COMPILE)gcc +CXX = $(CCACHE) $(CROSS_COMPILE)g++ else CC = $(CROSS_COMPILE)gcc +CXX = $(CROSS_COMPILE)g++ endif CPP = $(CC) -E AR = $(CROSS_COMPILE)ar @@ -366,6 +368,18 @@ KBUILD_CFLAGS := -c -g -std=c99 \ -Wno-format-zero-length \ -Wno-main -ffreestanding +KBUILD_CXXFLAGS := -c -g -std=c++11 \ + -fno-reorder-functions \ + -fno-asynchronous-unwind-tables \ + -fno-omit-frame-pointer \ + -fcheck-new \ + -fno-defer-pop -Wall \ + -Wno-unused-but-set-variable \ + -Wno-format-zero-length \ + -Wno-main -ffreestanding \ + -ffunction-sections -fdata-sections \ + -fno-rtti -fno-exceptions + KBUILD_AFLAGS := -c -g -xassembler-with-cpp LDFLAGS += $(call ld-option,-nostartfiles) @@ -377,13 +391,13 @@ KERNELVERSION = $(VERSION_MAJOR)$(if $(VERSION_MINOR),.$(VERSION_MINOR)$(if $(PA export VERSION_MAJOR VERSION_MINOR PATCHLEVEL VERSION_RESERVED EXTRAVERSION export KERNELRELEASE KERNELVERSION -export ARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC +export ARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC CXX export CPP AR NM STRIP OBJCOPY OBJDUMP export MAKE AWK INSTALLKERNEL PERL PYTHON GENIDT GENOFFSET_H export HOSTCXX HOSTCXXFLAGS CHECK CHECKFLAGS export KBUILD_CPPFLAGS NOSTDINC_FLAGS ZEPHYRINCLUDE OBJCOPYFLAGS LDFLAGS -export KBUILD_CFLAGS CFLAGS_GCOV KBUILD_AFLAGS AFLAGS_KERNEL +export KBUILD_CFLAGS KBUILD_CXXFLAGS CFLAGS_GCOV KBUILD_AFLAGS AFLAGS_KERNEL export KBUILD_ARFLAGS @@ -599,6 +613,7 @@ export LDFLAG_LINKERCMD include arch/$(ARCH)/Makefile KBUILD_CFLAGS += $(CFLAGS) +KBUILD_CXXFLAGS += $(CXXFLAGS) KBUILD_AFLAGS += $(CFLAGS) @@ -1103,6 +1118,10 @@ qemu: zephyr $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) %.o: %.c prepare scripts FORCE $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) +%.o: %.cpp prepare scripts FORCE + $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) +%.o: %.cxx prepare scripts FORCE + $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) %.lst: %.c prepare scripts FORCE $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@) %.s: %.S prepare scripts FORCE diff --git a/arch/arc/Makefile b/arch/arc/Makefile index 77e95c2ce99..d9a8976ab3f 100644 --- a/arch/arc/Makefile +++ b/arch/arc/Makefile @@ -4,4 +4,5 @@ arch-$(CONFIG_CPU_ARCEM4) = $(call cc-option,-mARCv2EM) \ $(call cc-option,-mav2em,) $(call cc-option,-mno-sdata) KBUILD_CFLAGS += $(arch-y) $(cflags-y) +KBUILD_CXXFLAGS += $(arch-y) $(cflags-y) KBUILD_AFLAGS += $(arch-y) diff --git a/arch/arm/Makefile b/arch/arm/Makefile index 9484210ca0e..e717d7b3c76 100644 --- a/arch/arm/Makefile +++ b/arch/arm/Makefile @@ -8,6 +8,7 @@ arch-$(CONFIG_CPU_CORTEX_M4) += $(call cc-option,-mthumb -mcpu=cortex-m4) \ cflags-$(CONFIG_LTO) = $(call cc-option,-flto,) KBUILD_CFLAGS += $(cflags-y) $(arch-y) +KBUILD_CXXFLAGS += $(cflags-y) $(arch-y) KBUILD_AFLAGS += $(arch-y) QEMU_CPU_TYPE_arm = cortex-m3 diff --git a/arch/arm/core/Makefile b/arch/arm/core/Makefile index 5b7827e4929..4987df7d063 100644 --- a/arch/arm/core/Makefile +++ b/arch/arm/core/Makefile @@ -10,6 +10,7 @@ obj-y = atomic.o exc_exit.o irq_init.o \ fault_s.o gdb_stub.o isr_wrapper.o \ fatal.o sys_fatal_error_handler.o +obj-$(CONFIG_CPLUSPLUS) += __aeabi_atexit.o obj-$(CONFIG_MICROKERNEL) += task_abort.o obj-$(CONFIG_IRQ_OFFLOAD) += irq_offload.o obj-$(CONFIG_CPU_CORTEX_M) += cortex_m/ diff --git a/arch/arm/core/__aeabi_atexit.c b/arch/arm/core/__aeabi_atexit.c new file mode 100644 index 00000000000..a2f8ad8090c --- /dev/null +++ b/arch/arm/core/__aeabi_atexit.c @@ -0,0 +1,38 @@ +/* + * Copyright (c) 2016 Wind River Systems, Inc. + * + * Licensed 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. + */ + +/* + * @file + * @brief Basic C++ destructor module for globals for ARM + */ + +#include + +EXTERN_C int __cxa_atexit(void (*destructor)(void *), void *objptr, void *dso); + +/** + * @brief Register destructor for a global object + * + * @param objptr global object pointer + * @param destructor the global object destructor function + * @param dso Dynamic Shared Object handle for shared libraries + * + * Wrapper for __cxa_atexit() + */ +int __aeabi_atexit(void *objptr, void (*destructor)(void *), void *dso) +{ + return __cxa_atexit(destructor, objptr, dso); +} diff --git a/arch/x86/Makefile b/arch/x86/Makefile index cb6920e37c1..5c1f49550f2 100644 --- a/arch/x86/Makefile +++ b/arch/x86/Makefile @@ -25,6 +25,7 @@ arch-$(CONFIG_CPU_ATOM) += $(call cc-option,-march=atom) \ arch-$(CONFIG_CPU_MINUTEIA) += $(call cc-option,-march=pentium) KBUILD_CFLAGS += $(cflags-y) $(arch-y) +KBUILD_CXXFLAGS += $(cflags-y) $(arch-y) KBUILD_AFLAGS += $(arch-y) QEMU_BIOS ?= /usr/share/qemu diff --git a/include/arch/arc/v2/linker.cmd b/include/arch/arc/v2/linker.cmd index ea60bdb841b..afbc167e8b4 100644 --- a/include/arch/arc/v2/linker.cmd +++ b/include/arch/arc/v2/linker.cmd @@ -86,6 +86,7 @@ SECTIONS { *(.text) *(".text.*") + *(.gnu.linkonce.t.*) _image_text_end = .; } GROUP_LINK_IN(ROMABLE_REGION) @@ -98,6 +99,7 @@ SECTIONS { __devconfig_end = .; } GROUP_LINK_IN(ROMABLE_REGION) +#ifdef CONFIG_CPLUSPLUS SECTION_PROLOGUE(_CTOR_SECTION_NAME,,) { /* * The compiler fills the constructor pointers table below, hence @@ -114,9 +116,19 @@ SECTIONS { __CTOR_END__ = .; } GROUP_LINK_IN(ROMABLE_REGION) + SECTION_PROLOGUE(init_array, (OPTIONAL),) + { + . = ALIGN(4); + __init_array_start = .; + KEEP(*(SORT_BY_NAME(".init_array*"))) + __init_array_end = .; + } GROUP_LINK_IN(ROMABLE_REGION) +#endif + SECTION_PROLOGUE(_RODATA_SECTION_NAME,,) { *(.rodata) *(".rodata.*") + *(.gnu.linkonce.r.*) } GROUP_LINK_IN(ROMABLE_REGION) _image_rom_end = .; diff --git a/include/arch/arm/cortex_m/scripts/linker.cmd b/include/arch/arm/cortex_m/scripts/linker.cmd index d4ba52fd0a5..8b5288e284f 100644 --- a/include/arch/arm/cortex_m/scripts/linker.cmd +++ b/include/arch/arm/cortex_m/scripts/linker.cmd @@ -101,6 +101,7 @@ SECTIONS _image_text_start = .; *(.text) *(".text.*") + *(.gnu.linkonce.t.*) } GROUP_LINK_IN(ROMABLE_REGION) _image_text_end = .; @@ -128,10 +129,38 @@ SECTIONS __exidx_end = .; } GROUP_LINK_IN(ROMABLE_REGION) +#ifdef CONFIG_CPLUSPLUS + SECTION_PROLOGUE(_CTOR_SECTION_NAME,,) + { + /* + * The compiler fills the constructor pointers table below, hence symbol + * __CTOR_LIST__ must be aligned on 4 byte boundary. + * To align with the C++ standard, the first elment of the array + * contains the number of actual constructors. The last element is + * NULL. + */ + . = ALIGN(4); + __CTOR_LIST__ = .; + LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2) + KEEP(*(SORT_BY_NAME(".ctors*"))) + LONG(0) + __CTOR_END__ = .; + } GROUP_LINK_IN(ROMABLE_REGION) + + SECTION_PROLOGUE(init_array, (OPTIONAL),) + { + . = ALIGN(4); + __init_array_start = .; + KEEP(*(SORT_BY_NAME(".init_array*"))) + __init_array_end = .; + } GROUP_LINK_IN(ROMABLE_REGION) +#endif + SECTION_PROLOGUE(_RODATA_SECTION_NAME,,) { *(.rodata) *(".rodata.*") + *(.gnu.linkonce.r.*) } GROUP_LINK_IN(ROMABLE_REGION) _image_rom_end = .; diff --git a/include/arch/x86/linker-common-sections.h b/include/arch/x86/linker-common-sections.h index e1e738f6ca0..5cd3185e990 100644 --- a/include/arch/x86/linker-common-sections.h +++ b/include/arch/x86/linker-common-sections.h @@ -74,6 +74,7 @@ SECTIONS *(".text_start.*") *(.text) *(".text.*") + *(.gnu.linkonce.t.*) *(.eh_frame) *(.init) *(.fini) @@ -83,6 +84,33 @@ SECTIONS _image_text_end = .; +#ifdef CONFIG_CPLUSPLUS + SECTION_PROLOGUE(_CTOR_SECTION_NAME, ,) + { + /* + * The compiler fills the constructor pointers table below, hence symbol + * __CTOR_LIST__ must be aligned on 4 byte boundary. + * To align with the C++ standard, the first elment of the array + * contains the number of actual constructors. The last element is + * NULL. + */ + . = ALIGN(4); + __CTOR_LIST__ = .; + LONG((__CTOR_END__ - __CTOR_LIST__) / 4 - 2) + KEEP(*(SORT_BY_NAME(".ctors*"))) + LONG(0) + __CTOR_END__ = .; + } GROUP_LINK_IN(ROMABLE_REGION) + + SECTION_PROLOGUE(init_array, (OPTIONAL),) + { + . = ALIGN(4); + __init_array_start = .; + KEEP(*(SORT_BY_NAME(".init_array*"))) + __init_array_end = .; + } GROUP_LINK_IN(ROMABLE_REGION) +#endif + SECTION_PROLOGUE(devconfig, (OPTIONAL),) { __devconfig_start = .; @@ -95,6 +123,7 @@ SECTIONS { *(.rodata) *(".rodata.*") + *(.gnu.linkonce.r.*) #if ALL_DYN_STUBS == 0 IDT_MEMORY #endif diff --git a/include/nanokernel.h b/include/nanokernel.h index 7fc41cd73e6..2a35df92ab6 100644 --- a/include/nanokernel.h +++ b/include/nanokernel.h @@ -1363,6 +1363,35 @@ struct nano_timer *_track_list_nano_timer; } #endif +#if defined(CONFIG_CPLUSPLUS) && defined(__cplusplus) +/* + * Define new and delete operators. + * At this moment they do nothing since objects are supposed + * to be statically allocated + */ +inline void operator delete(void *ptr) +{ + (void)ptr; +} + +inline void operator delete[](void *ptr) +{ + (void)ptr; +} + +inline void *operator new(size_t size) +{ + (void)size; + return NULL; +} + +inline void *operator new[](size_t size) +{ + (void)size; + return NULL; +} +#endif + /* architecture-specific nanokernel public APIs */ #include diff --git a/kernel/microkernel/k_init.c b/kernel/microkernel/k_init.c index 61821aeca54..bb596fbc422 100644 --- a/kernel/microkernel/k_init.c +++ b/kernel/microkernel/k_init.c @@ -96,6 +96,14 @@ void _main(void) _sys_device_do_config_level(_SYS_INIT_LEVEL_MICROKERNEL); _sys_device_do_config_level(_SYS_INIT_LEVEL_APPLICATION); +#ifdef CONFIG_CPLUSPLUS + /* Process the .ctors and .init_array sections */ + extern void __do_global_ctors_aux(void); + extern void __do_init_array_aux(void); + __do_global_ctors_aux(); + __do_init_array_aux(); +#endif + #ifdef CONFIG_WORKLOAD_MONITOR _k_workload_monitor_calibrate(); diff --git a/kernel/nanokernel/nano_init.c b/kernel/nanokernel/nano_init.c index 6eb4176897a..aaaf5629291 100644 --- a/kernel/nanokernel/nano_init.c +++ b/kernel/nanokernel/nano_init.c @@ -105,6 +105,14 @@ static void _main(void) _sys_device_do_config_level(_SYS_INIT_LEVEL_NANOKERNEL); _sys_device_do_config_level(_SYS_INIT_LEVEL_APPLICATION); +#ifdef CONFIG_CPLUSPLUS + /* Process the .ctors and .init_array sections */ + extern void __do_global_ctors_aux(void); + extern void __do_init_array_aux(void); + __do_global_ctors_aux(); + __do_init_array_aux(); +#endif + extern void main(void); main(); } diff --git a/misc/Kconfig b/misc/Kconfig index f4b36703360..dc50c4ca7fe 100644 --- a/misc/Kconfig +++ b/misc/Kconfig @@ -93,6 +93,12 @@ config TOOLCHAIN_VARIANT For optimized compilers with reduced features, specify the name of the variant. +config CPLUSPLUS + bool "Enable C++ support for the application" + default n + help + This option enables the use of applications built with C++. + choice prompt "C Library" default MINIMAL_LIBC diff --git a/misc/Makefile b/misc/Makefile index cca7f4dee8b..cb9a718d980 100644 --- a/misc/Makefile +++ b/misc/Makefile @@ -1,4 +1,6 @@ obj-y = +obj-$(CONFIG_CPLUSPLUS) += cpp_virtual.o cpp_vtable.o \ + cpp_init_array.o cpp_ctors.o cpp_dtors.o obj-$(CONFIG_PRINTK) += printk.o obj-$(CONFIG_REBOOT) += reboot.o obj-y += generated/ diff --git a/misc/cpp_ctors.c b/misc/cpp_ctors.c new file mode 100644 index 00000000000..8ec409af0e2 --- /dev/null +++ b/misc/cpp_ctors.c @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2012-2014 Wind River Systems, Inc. + * + * Licensed 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. + */ + +/** + * @file - Constructor module + * @brief + * The ctors section contains a list of function pointers that execute the + * C++ constructors of static global objects. These must be executed before + * the application's main() routine. + * + * NOTE: Not all compilers put those function pointers into the ctors section; + * some put them into the init_array section instead. + */ + +/* What a constructor function pointer looks like */ + +typedef void (*CtorFuncPtr)(void); + +/* Constructor function pointer list is generated by the linker script. */ + +extern CtorFuncPtr __CTOR_LIST__[]; +extern CtorFuncPtr __CTOR_END__[]; + +/** + * + * @brief Invoke all C++ style global object constructors + * + * This routine is invoked by the kernel prior to the execution of the + * application's main(). + */ +void __do_global_ctors_aux(void) +{ + unsigned int nCtors; + + nCtors = (unsigned int)__CTOR_LIST__[0]; + + while (nCtors >= 1) { + __CTOR_LIST__[nCtors--](); + } +} diff --git a/misc/cpp_dtors.c b/misc/cpp_dtors.c new file mode 100644 index 00000000000..f38fb43c492 --- /dev/null +++ b/misc/cpp_dtors.c @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2016 Wind River Systems, Inc. + * + * Licensed 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. + */ + +/* + * @file + * @brief Basic C++ destructor module for globals + * + */ + +#include + +void *__dso_handle = 0; + +/** + * @brief Register destructor for a global object + * + * @param destructor the global object destructor function + * @param objptr global object pointer + * @param dso Dynamic Shared Object handle for shared libraries + * + * Function does nothing at the moment, assuming the global objects + * do not need to be deleted + * + * @return N/A + */ +int __cxa_atexit(void (*destructor)(void *), void *objptr, void *dso) +{ + ARG_UNUSED(destructor); + ARG_UNUSED(objptr); + ARG_UNUSED(dso); + return 0; +} diff --git a/misc/cpp_init_array.c b/misc/cpp_init_array.c new file mode 100644 index 00000000000..d1848e78f16 --- /dev/null +++ b/misc/cpp_init_array.c @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2015 Wind River Systems, Inc. + * + * Licensed 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. + */ + +/* + * @file + * @brief Execute initialization routines referenced in .init_array section + */ + +typedef void (*func_ptr)(void); + +extern func_ptr __init_array_start[0]; +extern func_ptr __init_array_end[0]; + +/** + * @brief Execute initialization routines referenced in .init_array section + * + * @return N/A + */ +void __do_init_array_aux(void) +{ + for (func_ptr *func = __init_array_start; + func < __init_array_end; + func++) { + (*func)(); + } +} diff --git a/misc/cpp_virtual.c b/misc/cpp_virtual.c new file mode 100644 index 00000000000..7d3b502c3d1 --- /dev/null +++ b/misc/cpp_virtual.c @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2015 Wind River Systems, Inc. + * + * Licensed 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. + */ + +/* + * @file + * @brief Stub for C++ pure virtual functions + */ + +/** + * @brief Stub for pure virtual functions + * + * This routine is needed for linking C++ code that uses pure virtual + * functions. + * + * @return N/A + */ +void __cxa_pure_virtual(void) +{ + while (1) { + ; + } +} diff --git a/misc/cpp_vtable.cpp b/misc/cpp_vtable.cpp new file mode 100644 index 00000000000..cf9ef35c828 --- /dev/null +++ b/misc/cpp_vtable.cpp @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2015 Wind River Systems, Inc. + * + * Licensed 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. + */ + +/* + * @file + * @brief Stub for C++ virtual tables + */ + +/** + * + * @brief basic virtual tables required for classes to build + * + */ + +namespace __cxxabiv1 { + class __class_type_info { + virtual void dummy(); + }; + class __si_class_type_info { + virtual void dummy(); + }; + void __class_type_info::dummy() { } // causes the vtable to get created here + void __si_class_type_info::dummy() { } // causes the vtable to get created here +}; diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 4862d0430f7..6295c2e7579 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -20,6 +20,7 @@ subdir-y := subdir-m := EXTRA_AFLAGS := EXTRA_CFLAGS := +EXTRA_CXXFLAGS := EXTRA_CPPFLAGS := EXTRA_LDFLAGS := asflags-y := @@ -196,6 +197,47 @@ quiet_cmd_cc_lst_c = MKLST $@ $(obj)/%.lst: $(src)/%.c FORCE $(call if_changed_dep,cc_lst_c) +# C++ (.cpp and .cxx) files +# The C++ file is compiled and updated dependency information is generated. +# (See cmd_cc_o_cxx + relevant part of rule_cc_o_cxx) + +# No support for module versioning for C++ (for now) +quiet_cmd_cc_o_cxx = C++ $(quiet_modtag) $@ +cmd_cc_o_cxx = $(CXX) $(cxx_flags) -c -o $@ $< + +define rule_cc_o_cxx + $(call echo-cmd,checksrc) $(cmd_checksrc) \ +$(call echo-cmd,cc_o_cxx) $(cmd_cc_o_cxx); \ + $(cmd_modversions) \ + $(call echo-cmd,record_mcount) \ + $(cmd_record_mcount) \ + scripts/basic/fixdep $(depfile) $@ '$(call make-cmd,cc_o_cxx)' > \ + $(dot-target).tmp; \ + rm -f $(depfile); \ + mv -f $(dot-target).tmp $(dot-target).cmd +endef + +# Built-in and composite module parts +$(obj)/%.o: $(src)/%.cpp $(recordmcount_source) FORCE + $(call cmd,force_checksrc) + $(call if_changed_rule,cc_o_cxx) + +$(obj)/%.o: $(src)/%.cxx $(recordmcount_source) FORCE + $(call cmd,force_checksrc) + $(call if_changed_rule,cc_o_cxx) + +quiet_cmd_cc_lst_cxx = MKLST $@ + cmd_cc_lst_cxx = $(CXX) $(cxx_flags) -g -c -o $*.o $< && \ + $(CONFIG_SHELL) $(srctree)/scripts/makelst $*.o \ + System.map $(OBJDUMP) > $@ + +$(obj)/%.lst: $(src)/%.cxx FORCE + $(call if_changed_dep,cc_lst_cxx) + +$(obj)/%.lst: $(src)/%.cpp FORCE + $(call if_changed_dep,cc_lst_cxx) + + # Compile assembler sources (.S) # --------------------------------------------------------------------------- diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib index bb02ca4eac1..b907af8ab34 100644 --- a/scripts/Makefile.lib +++ b/scripts/Makefile.lib @@ -3,6 +3,7 @@ asflags-y += $(EXTRA_AFLAGS) ccflags-y += $(EXTRA_CFLAGS) cppflags-y += $(EXTRA_CPPFLAGS) +cxxflags-y += $(EXTRA_CXXFLAGS) ldflags-y += $(EXTRA_LDFLAGS) # @@ -114,6 +115,9 @@ _c_flags = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(orig_c_flags)) _a_flags = $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(KBUILD_SUBDIR_ASFLAGS) \ $(asflags-y) $(AFLAGS_$(basetarget).o) _cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(@F)) +orig_cxx_flags = $(KBUILD_CPPFLAGS) $(KBUILD_CXXFLAGS) $(KBUILD_SUBDIR_CXXFLAGS) \ + $(cxxflags-y) $(CXXFLAGS_$(basetarget).o) +_cxx_flags = $(filter-out $(CXXFLAGS_REMOVE_$(basetarget).o), $(orig_cxx_flags)) # If building the kernel in a separate objtree expand all occurrences # of -Idir to -I$(srctree)/dir except for absolute paths (starting with '/'). @@ -122,6 +126,7 @@ ifeq ($(KBUILD_SRC),) __c_flags = $(_c_flags) __a_flags = $(_a_flags) __cpp_flags = $(_cpp_flags) +__cxx_flags = $(_cxx_flags) else # -I$(obj) locates generated .h files @@ -131,6 +136,7 @@ else __c_flags = $(call addtree,-I$(obj)) $(call flags,_c_flags) __a_flags = $(call flags,_a_flags) __cpp_flags = $(call flags,_cpp_flags) +__cxx_flags = $(call flags,_cxx_flags) endif c_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(ZEPHYRINCLUDE) \ @@ -149,6 +155,10 @@ dtc_cpp_flags = -Wp,-MD,$(depfile).pre.tmp -nostdinc \ -I$(srctree)/drivers/of/testcase-data \ -undef -D__DTS__ +cxx_flags = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(ZEPHYRINCLUDE) \ + $(__cxx_flags) $(modkern_cflags) \ + -D"KBUILD_STR(s)=\#s" $(basename_flags) $(modname_flags) + # Finds the multi-part object the current object will be linked into modname-multi = $(sort $(foreach m,$(multi-used),\ $(if $(filter $(subst $(obj)/,,$*.o), $($(m:.o=-objs)) $($(m:.o=-y))),$(m:.o=)))) diff --git a/scripts/sysgen b/scripts/sysgen index 17cadcb13d7..2abdcb26068 100755 --- a/scripts/sysgen +++ b/scripts/sysgen @@ -320,7 +320,7 @@ def kernel_main_c_tasks(): kernel_main_c_out("\n") for task in task_list: - kernel_main_c_out("extern void %s(void);\n" % task[2]) + kernel_main_c_out("EXTERN_C void %s(void);\n" % task[2]) # task descriptors (including one for idle task) #