summaryrefslogtreecommitdiff
path: root/misc
diff options
context:
space:
mode:
authorPeter Mitsis <peter.mitsis@windriver.com>2016-01-13 13:02:56 -0500
committerAnas Nashif <anas.nashif@intel.com>2016-02-05 20:25:23 -0500
commit8e35cc8eb4ec10f50819fa402dbc3c44b6bd25ca (patch)
treea9309db124d00e24c3cbc7e5f7be6a505ad35d2e /misc
parenteaed145cb6edf76a7fd686744146ffc526a3562c (diff)
build: Add C++ support
Adds C++ support to the build system. Change-Id: Ice1e57a13598e7a48b0bf3298fc318f4ce012ee6 Signed-off-by: Dmitriy Korovkin <dmitriy.korovkin@windriver.com> Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
Diffstat (limited to 'misc')
-rw-r--r--misc/Kconfig6
-rw-r--r--misc/Makefile2
-rw-r--r--misc/cpp_ctors.c53
-rw-r--r--misc/cpp_dtors.c45
-rw-r--r--misc/cpp_init_array.c39
-rw-r--r--misc/cpp_virtual.c35
-rw-r--r--misc/cpp_vtable.cpp37
7 files changed, 217 insertions, 0 deletions
diff --git a/misc/Kconfig b/misc/Kconfig
index f4b367033..dc50c4ca7 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 cca7f4dee..cb9a718d9 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 000000000..8ec409af0
--- /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 000000000..f38fb43c4
--- /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 <toolchain.h>
+
+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 000000000..d1848e78f
--- /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 000000000..7d3b502c3
--- /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 000000000..cf9ef35c8
--- /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
+};