Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
For COMP9242 16s2
From 16fb4aa41e1ac236cf1f57747b70ab650292658d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=B0=8F=E5=A4=AA?= <nospam@kota.moe>
Date: Thu, 4 Aug 2016 21:55:53 +1000
Subject: [PATCH] Hack in C++ support
Also via a unusual method to update the musl version without creating a huge
diff that give won't accept.
musl needed to be updated because libc++ depends on a newer one than the one
provided.
To compile and link successfully with C++:
1. Use the CXXFILES makefile variable for C++ source files
2. Add "libc++" to the list of prerequisites in your app/lib Kbuild
3. If linking, add "c++ c++abi" to the LIBS makefile variable before "c"
4. If using exceptions, substitute occurences of "gcc_eh" with "unwind" in
LDFLAGS. The program will also need to have valid program header
related auxillary vectors passed in on startup (already done for SOS)
Remember to use extern "C"
Things that don't work:
1. Naturally, anything that ends up calling an unimplemented syscall
(You will usually get an assertion failure for this)
2. Using too much heap memory (Until sys_mmap2() is fully implemented)
3. Real threads (You will need to implement __set_thread_area() properly)
4. Probably a lot more things (Do let me know)
---
.gitignore | 3 +
Kbuild | 2 +-
Kconfig | 3 +-
apps/sos/Makefile | 3 +-
apps/sos/crt/arch-arm/crt0.S | 4 +-
apps/sos/crt/arch-arm/sel4_main.c | 32 +++++++--
apps/sos/src/sys/sys_exit.c | 15 ++++
apps/sos/src/sys/sys_stubs.c | 16 ++---
apps/sosh/Makefile | 3 +-
apps/sosh/crt/arch-arm/crt0.c | 25 -------
apps/sosh/crt/arch-ia32/crt0.s | 24 -------
apps/tty_test/Makefile | 3 +-
apps/tty_test/crt/arch-arm/crt0.c | 25 -------
apps/tty_test/crt/arch-ia32/crt0.S | 24 -------
configs/aos_defconfig | 3 +-
libs/libc++/Kbuild | 2 +
libs/libc++/Kconfig | 4 ++
libs/libc++/Makefile | 89 +++++++++++++++++++++++
libs/libc++/libcxx-sos.patch | 13 ++++
libs/libc++/libcxxabi-sos.patch | 13 ++++
libs/libmuslc-updated/Kbuild | 19 +++++
libs/libmuslc-updated/Kconfig | 23 ++++++
libs/libmuslc-updated/sos.patch | 143 +++++++++++++++++++++++++++++++++++++
libs/libmuslc/Kbuild | 4 --
libs/libsos/src/sys_exit.c | 14 +++-
libs/libsos/src/sys_stubs.c | 16 ++---
tools/common/common.mk | 10 +--
27 files changed, 395 insertions(+), 140 deletions(-)
delete mode 100644 apps/sosh/crt/arch-arm/crt0.c
delete mode 100644 apps/sosh/crt/arch-ia32/crt0.s
delete mode 100644 apps/tty_test/crt/arch-arm/crt0.c
delete mode 100644 apps/tty_test/crt/arch-ia32/crt0.S
create mode 100644 libs/libc++/Kbuild
create mode 100644 libs/libc++/Kconfig
create mode 100644 libs/libc++/Makefile
create mode 100644 libs/libc++/libcxx-sos.patch
create mode 100644 libs/libc++/libcxxabi-sos.patch
create mode 100644 libs/libmuslc-updated/Kbuild
create mode 100644 libs/libmuslc-updated/Kconfig
create mode 100644 libs/libmuslc-updated/sos.patch
delete mode 100644 libs/libmuslc/Kbuild
diff --git a/.gitignore b/.gitignore
index 1aea3cb..1224e6d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,6 @@
+/libs/libc++/*
+/libs/libmuslc-updated/*
+
/.config
/.config.old
diff --git a/Kbuild b/Kbuild
index 334d81b..575f5f5 100644
--- a/Kbuild
+++ b/Kbuild
@@ -7,7 +7,7 @@
#
# @TAG(NICTA_BSD)
#
-libc=libmuslc
+libc=libmuslc-updated
-include $(wildcard libs/*/Kbuild)
-include $(wildcard apps/*/Kbuild)
diff --git a/Kconfig b/Kconfig
index aff99be..4f9b304 100644
--- a/Kconfig
+++ b/Kconfig
@@ -19,7 +19,8 @@ menu "seL4 Kernel"
endmenu
menu "seL4 Libraries"
- source "libs/libmuslc/Kconfig"
+ source "libs/libmuslc-updated/Kconfig"
+ source "libs/libc++/Kconfig"
source "libs/libsel4/Kconfig"
source "libs/libsel4cspace/Kconfig"
source "libs/liblwip/Kconfig"
diff --git a/apps/sos/Makefile b/apps/sos/Makefile
index 67f4316..f805f3e 100644
--- a/apps/sos/Makefile
+++ b/apps/sos/Makefile
@@ -22,11 +22,12 @@ OFILES := archive.o
INCLUDE_DIRS += $(SOURCE_DIR)/include
# Libraries required to build the target
-LIBS := sel4 elf muslc cpio lwip ethdrivers \
+LIBS := sel4 elf c cpio lwip ethdrivers \
serial nfs clock sel4cspace platsupport
include $(SEL4_COMMON)/common.mk
+CRTOBJFILES :=
${COMPONENTS}:
false
diff --git a/apps/sos/crt/arch-arm/crt0.S b/apps/sos/crt/arch-arm/crt0.S
index 479d815..1cf0808 100644
--- a/apps/sos/crt/arch-arm/crt0.S
+++ b/apps/sos/crt/arch-arm/crt0.S
@@ -25,7 +25,7 @@ _start:
/*
* Symbols required for libgcc.
*/
-.global raise
+/*.global raise
//.global __aeabi_unwind_cpp_pr0
.global __aeabi_unwind_cpp_pr1
.global __aeabi_unwind_cpp_pr2
@@ -33,7 +33,7 @@ raise:
//__aeabi_unwind_cpp_pr0:
__aeabi_unwind_cpp_pr1:
__aeabi_unwind_cpp_pr2:
- b raise
+ b raise*/
/* .text Literal Pool */
.pool
diff --git a/apps/sos/crt/arch-arm/sel4_main.c b/apps/sos/crt/arch-arm/sel4_main.c
index 4fb4dde..ac14480 100644
--- a/apps/sos/crt/arch-arm/sel4_main.c
+++ b/apps/sos/crt/arch-arm/sel4_main.c
@@ -8,20 +8,40 @@
* @TAG(NICTA_BSD)
*/
+#include <elf.h>
+#include <elf/elf32.h>
+#include <limits.h>
#include <sel4/sel4.h>
-#include <syscall_stubs_sel4.h>
#include <stdlib.h>
-MUSLC_SYSCALL_TABLE;
-
int main(void);
void exit(int code);
+void _init() __attribute__((weak));
+void _fini() __attribute__((weak));
+_Noreturn int __libc_start_main(int (*)(), int, char **,
+ void (*)(), void(*)(), void(*)());
+
void __attribute__((externally_visible)) _sel4_main(seL4_BootInfo *bi) {
seL4_InitBootInfo(bi);
- SET_MUSLC_SYSCALL_TABLE;
- int ret = main();
- exit(ret);
+
+ #if UINTPTR_MAX != 0xffffffff
+ #error Only 32-bit supported
+ #endif
+ struct Elf32_Header *elfHeader = (struct Elf32_Header *)0x10000;
+ size_t argv[] = {
+ // argv
+ 0,
+ // envp
+ 0,
+ // auxv (Needed for exception handling)
+ AT_PHDR, (size_t)elf32_getProgramHeaderTable(elfHeader),
+ AT_PHENT, sizeof(Elf32_Phdr),
+ AT_PHNUM, elf32_getNumProgramHeaders(elfHeader),
+ AT_NULL, 0
+ };
+
+ __libc_start_main(main, 0, (void *)argv, _init, _fini, NULL);
/* should not get here */
while(1);
}
diff --git a/apps/sos/src/sys/sys_exit.c b/apps/sos/src/sys/sys_exit.c
index 2daf0b9..3d39984 100644
--- a/apps/sos/src/sys/sys_exit.c
+++ b/apps/sos/src/sys/sys_exit.c
@@ -68,6 +68,21 @@ sys_getpid(va_list ap)
}
long
+sys_set_tid_address(va_list ap)
+{
+ printf("Ignoring call to %s\n", __FUNCTION__);
+ return sys_gettid(ap);
+}
+
+long
+sys_tkill(va_list ap)
+{
+ printf("%s assuming self kill\n", __FUNCTION__);
+ sel4_abort();
+ return 0;
+}
+
+long
sys_tgkill(va_list ap)
{
printf("%s assuming self kill\n", __FUNCTION__);
diff --git a/apps/sos/src/sys/sys_stubs.c b/apps/sos/src/sys/sys_stubs.c
index 1fb6ee8..f03d857 100644
--- a/apps/sos/src/sys/sys_stubs.c
+++ b/apps/sos/src/sys/sys_stubs.c
@@ -1170,11 +1170,11 @@ long sys_fremovexattr(va_list ap)
assert(!"sys_fremovexattr not implemented");
return 0;
}
-long sys_tkill(va_list ap)
+/*long sys_tkill(va_list ap)
{
assert(!"sys_tkill not implemented");
return 0;
-}
+}*/
long sys_sendfile64(va_list ap)
{
assert(!"sys_sendfile64 not implemented");
@@ -1265,11 +1265,11 @@ long sys_remap_file_pages(va_list ap)
assert(!"sys_remap_file_pages not implemented");
return 0;
}
-long sys_set_tid_address(va_list ap)
+/*long sys_set_tid_address(va_list ap)
{
assert(!"sys_set_tid_address not implemented");
return 0;
-}
+}*/
long sys_timer_create(va_list ap)
{
assert(!"sys_timer_create not implemented");
@@ -2650,11 +2650,11 @@ long sys_fremovexattr(va_list ap)
assert(!"sys_fremovexattr not implemented");
return 0;
}
-long sys_tkill(va_list ap)
+/*long sys_tkill(va_list ap)
{
assert(!"sys_tkill not implemented");
return 0;
-}
+}*/
long sys_sendfile64(va_list ap)
{
assert(!"sys_sendfile64 not implemented");
@@ -2730,11 +2730,11 @@ long sys_remap_file_pages(va_list ap)
assert(!"sys_remap_file_pages not implemented");
return 0;
}
-long sys_set_tid_address(va_list ap)
+/*long sys_set_tid_address(va_list ap)
{
assert(!"sys_set_tid_address not implemented");
return 0;
-}
+}*/
long sys_timer_create(va_list ap)
{
assert(!"sys_timer_create not implemented");
diff --git a/apps/sosh/Makefile b/apps/sosh/Makefile
index ba7c714..4cec033 100644
--- a/apps/sosh/Makefile
+++ b/apps/sosh/Makefile
@@ -13,9 +13,8 @@ TARGETS := $(notdir $(SOURCE_DIR)).bin
# Source files required to build the target
CFILES := $(patsubst $(SOURCE_DIR)/%,%,$(wildcard $(SOURCE_DIR)/src/*.c))
-CFILES += $(patsubst $(SOURCE_DIR)/%,%,$(wildcard $(SOURCE_DIR)/crt/arch-${ARCH}/*.c))
# Libraries required to build the target
-LIBS := muslc sel4 sos
+LIBS := c sel4 sos
include $(SEL4_COMMON)/common.mk
diff --git a/apps/sosh/crt/arch-arm/crt0.c b/apps/sosh/crt/arch-arm/crt0.c
deleted file mode 100644
index 54f37ab..0000000
--- a/apps/sosh/crt/arch-arm/crt0.c
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright 2014, NICTA
- *
- * This software may be distributed and modified according to the terms of
- * the BSD 2-Clause license. Note that NO WARRANTY is provided.
- * See "LICENSE_BSD2.txt" for details.
- *
- * @TAG(NICTA_BSD)
- */
-
-#include <stddef.h>
-#include <syscall_stubs_sel4.h>
-
-MUSLC_SYSCALL_TABLE;
-
-int main(void);
-void exit(int code);
-
-void __attribute__((externally_visible)) _start(void) {
- SET_MUSLC_SYSCALL_TABLE;
- int ret = main();
- exit(ret);
- /* should not get here */
- while(1);
-}
diff --git a/apps/sosh/crt/arch-ia32/crt0.s b/apps/sosh/crt/arch-ia32/crt0.s
deleted file mode 100644
index ca8ae4b..0000000
--- a/apps/sosh/crt/arch-ia32/crt0.s
+++ /dev/null
@@ -1,24 +0,0 @@
-# @LICENSE(NICTA)
-
- .global _start
- .extern seL4_InitBootInfo
- .extern exit
-
- .text
-
-_start:
- leal _stack_top, %esp
- pushl %ebx
- call seL4_InitBootInfo
- addl $4, %esp
- call main
- pushl %eax
- call exit
-1: jmp 1b
-
- .bss
- .align 4
-
-_stack_bottom:
- .space 1024
-_stack_top:
diff --git a/apps/tty_test/Makefile b/apps/tty_test/Makefile
index 6cf462a..442692b 100644
--- a/apps/tty_test/Makefile
+++ b/apps/tty_test/Makefile
@@ -13,9 +13,8 @@ TARGETS := tty_test.bin
# Source files required to build the target
CFILES := $(patsubst $(SOURCE_DIR)/%,%,$(wildcard $(SOURCE_DIR)/src/*.c))
-CFILES += $(patsubst $(SOURCE_DIR)/%,%,$(wildcard $(SOURCE_DIR)/crt/arch-${ARCH}/*.c))
# Libraries required to build the target
-LIBS := muslc sel4 sos
+LIBS := c sel4 sos
#export DEBUG=1
include $(SEL4_COMMON)/common.mk
diff --git a/apps/tty_test/crt/arch-arm/crt0.c b/apps/tty_test/crt/arch-arm/crt0.c
deleted file mode 100644
index 54f37ab..0000000
--- a/apps/tty_test/crt/arch-arm/crt0.c
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright 2014, NICTA
- *
- * This software may be distributed and modified according to the terms of
- * the BSD 2-Clause license. Note that NO WARRANTY is provided.
- * See "LICENSE_BSD2.txt" for details.
- *
- * @TAG(NICTA_BSD)
- */
-
-#include <stddef.h>
-#include <syscall_stubs_sel4.h>
-
-MUSLC_SYSCALL_TABLE;
-
-int main(void);
-void exit(int code);
-
-void __attribute__((externally_visible)) _start(void) {
- SET_MUSLC_SYSCALL_TABLE;
- int ret = main();
- exit(ret);
- /* should not get here */
- while(1);
-}
diff --git a/apps/tty_test/crt/arch-ia32/crt0.S b/apps/tty_test/crt/arch-ia32/crt0.S
deleted file mode 100644
index ca8ae4b..0000000
--- a/apps/tty_test/crt/arch-ia32/crt0.S
+++ /dev/null
@@ -1,24 +0,0 @@
-# @LICENSE(NICTA)
-
- .global _start
- .extern seL4_InitBootInfo
- .extern exit
-
- .text
-
-_start:
- leal _stack_top, %esp
- pushl %ebx
- call seL4_InitBootInfo
- addl $4, %esp
- call main
- pushl %eax
- call exit
-1: jmp 1b
-
- .bss
- .align 4
-
-_stack_bottom:
- .space 1024
-_stack_top:
diff --git a/configs/aos_defconfig b/configs/aos_defconfig
index 3923920..9998c24 100644
--- a/configs/aos_defconfig
+++ b/configs/aos_defconfig
@@ -68,8 +68,9 @@ CONFIG_OPTIMISATION_O2=y
# seL4 Libraries
#
CONFIG_LIB_MUSL_C=y
-CONFIG_LIB_MUSL_C_USE_PREBUILT=y
CONFIG_HAVE_LIBC=y
+CONFIG_HAVE_CRT=y
+CONFIG_LIB_CXX=y
CONFIG_LIB_SEL4=y
# CONFIG_LIB_SEL4_STUBS_USE_IPC_BUFFER_ONLY is not set
CONFIG_LIB_SEL4_CSPACE=y
diff --git a/libs/libc++/Kbuild b/libs/libc++/Kbuild
new file mode 100644
index 0000000..09315db
--- /dev/null
+++ b/libs/libc++/Kbuild
@@ -0,0 +1,2 @@
+libs-$(CONFIG_LIB_CXX) += libc++ libc++abi libunwind
+libc++: $(libc) libsel4 libsos
diff --git a/libs/libc++/Kconfig b/libs/libc++/Kconfig
new file mode 100644
index 0000000..6db8dae
--- /dev/null
+++ b/libs/libc++/Kconfig
@@ -0,0 +1,4 @@
+config LIB_CXX
+ bool "Build libc++"
+ depends on HAVE_LIBC
+ default y
diff --git a/libs/libc++/Makefile b/libs/libc++/Makefile
new file mode 100644
index 0000000..49e038a
--- /dev/null
+++ b/libs/libc++/Makefile
@@ -0,0 +1,89 @@
+# Targets
+TARGETS := libc++ libc++abi libunwind
+
+include $(SEL4_COMMON)/common.mk
+
+CFLAGS := $(CFLAGS) $(CPPFLAGS)
+CXXFLAGS := $(filter-out -I$(STAGE_DIR)/include/c++/v1,$(CXXFLAGS) $(CPPFLAGS))
+
+# cmake tries to link during config despite nothing needing the linker in the
+# actual build, but causes problems due to missing libraries, so we ignore all
+# unresolved symbols
+LDFLAGS := -Wl,--unresolved-symbols=ignore-all
+
+.PHONY: libc++ libc++abi libunwind
+
+$(SOURCE_DIR)/llvm/CMakeLists.txt:
+ mkdir -p "$(SOURCE_DIR)/llvm"
+ # No HTTPS gosh :(
+ curl "http://llvm.org/releases/3.8.1/llvm-3.8.1.src.tar.xz" | tar xJf - -C "$(SOURCE_DIR)/llvm" --strip-components=1
+
+$(SOURCE_DIR)/libcxx/CMakeLists.txt: | $(SOURCE_DIR)/libcxx-sos.patch
+ mkdir -p "$(SOURCE_DIR)/libcxx"
+ curl "http://llvm.org/releases/3.8.1/libcxx-3.8.1.src.tar.xz" | tar xJf - -C "$(SOURCE_DIR)/libcxx" --strip-components=1
+ (cd "$(SOURCE_DIR)/libcxx" && patch -mp1 < ../libcxx-sos.patch)
+
+$(SOURCE_DIR)/libcxxabi/CMakeLists.txt: | $(SOURCE_DIR)/libcxxabi-sos.patch
+ mkdir -p "$(SOURCE_DIR)/libcxxabi"
+ curl "http://llvm.org/releases/3.8.1/libcxxabi-3.8.1.src.tar.xz" | tar xJf - -C "$(SOURCE_DIR)/libcxxabi" --strip-components=1
+ (cd "$(SOURCE_DIR)/libcxxabi" && patch -mp1 < ../libcxxabi-sos.patch)
+
+$(SOURCE_DIR)/libunwind/CMakeLists.txt:
+ mkdir -p "$(SOURCE_DIR)/libunwind"
+ curl "http://llvm.org/releases/3.8.1/libunwind-3.8.1.src.tar.xz" | tar xJf - -C "$(SOURCE_DIR)/libunwind" --strip-components=1
+
+libc++: $(SOURCE_DIR)/llvm/CMakeLists.txt $(SOURCE_DIR)/libcxx/CMakeLists.txt $(SOURCE_DIR)/libcxxabi/CMakeLists.txt
+ mkdir -p "$(BUILD_DIR)/libcxx"
+ cd "$(BUILD_DIR)/libcxx" && \
+ cmake \
+ -DCMAKE_SYSTEM_NAME=Generic \
+ -DCMAKE_SYSTEM_PROCESSOR=arm-eabi \
+ -DCMAKE_C_COMPILER="$(strip $(CC))" \
+ -DCMAKE_CXX_COMPILER="$(strip $(CXX))" \
+ -DLLVM_PATH="$(SOURCE_DIR)/llvm" \
+ -DLIBCXX_HAS_MUSL_LIBC=on \
+ -DLIBCXX_ENABLE_THREADS=off \
+ -DLIBCXX_CXX_ABI=libcxxabi \
+ -DLIBCXX_CXX_ABI_INCLUDE_PATHS="$(SOURCE_DIR)/libcxxabi/include" \
+ -DLIBCXX_ENABLE_STATIC_ABI_LIBRARY=on \
+ -DLIBCXXABI_USE_LLVM_UNWINDER=on \
+ -DLIBCXX_ENABLE_SHARED=off \
+ -DCMAKE_INSTALL_PREFIX="$(STAGE_DIR)" \
+ -DUNIX=1 \
+ "$(SOURCE_DIR)/libcxx" && \
+ $(MAKE) -j && $(MAKE) install
+
+libc++abi: libc++ $(SOURCE_DIR)/llvm/CMakeLists.txt $(SOURCE_DIR)/libcxx/CMakeLists.txt $(SOURCE_DIR)/libcxxabi/CMakeLists.txt $(SOURCE_DIR)/libunwind/CMakeLists.txt
+ mkdir -p "$(BUILD_DIR)/libcxxabi"
+ cd "$(BUILD_DIR)/libcxxabi" && \
+ cmake \
+ -DCMAKE_SYSTEM_NAME=Generic \
+ -DCMAKE_SYSTEM_PROCESSOR=arm-eabi \
+ -DCMAKE_C_COMPILER="$(strip $(CC))" \
+ -DCMAKE_CXX_COMPILER="$(strip $(CXX))" \
+ -DLLVM_PATH="$(SOURCE_DIR)/llvm" \
+ -DLIBCXXABI_LIBCXX_PATH="$(SOURCE_DIR)/libcxx" \
+ -DLIBCXXABI_LIBUNWIND_PATH="$(SOURCE_DIR)/libunwind" \
+ -DLIBCXXABI_USE_LLVM_UNWINDER=on \
+ -DLIBCXXABI_ENABLE_SHARED=off \
+ -DCMAKE_INSTALL_PREFIX="$(STAGE_DIR)" \
+ -DUNIX=1 \
+ -DLLVM_FORCE_USE_OLD_TOOLCHAIN=1 \
+ "$(SOURCE_DIR)/libcxxabi" && \
+ $(MAKE) -j && $(MAKE) install
+
+libunwind: libc++ $(SOURCE_DIR)/llvm/CMakeLists.txt
+ mkdir -p "$(BUILD_DIR)/libunwind"
+ cd "$(BUILD_DIR)/libunwind" && \
+ CXXFLAGS="-I$(STAGE_DIR)/include/c++/v1 $(CXXFLAGS)" cmake \
+ -DCMAKE_SYSTEM_NAME=Generic \
+ -DCMAKE_SYSTEM_PROCESSOR=arm-eabi \
+ -DCMAKE_C_COMPILER="$(strip $(CC))" \
+ -DCMAKE_CXX_COMPILER="$(strip $(CXX))" \
+ -DLLVM_PATH="$(SOURCE_DIR)/llvm" \
+ -DLIBUNWIND_ENABLE_SHARED=off \
+ -DCMAKE_INSTALL_PREFIX="$(STAGE_DIR)" \
+ -DUNIX=1 \
+ -DLLVM_FORCE_USE_OLD_TOOLCHAIN=1 \
+ "$(SOURCE_DIR)/libunwind" && \
+ $(MAKE) -j && $(MAKE) install
diff --git a/libs/libc++/libcxx-sos.patch b/libs/libc++/libcxx-sos.patch
new file mode 100644
index 0000000..3cc235d
--- /dev/null
+++ b/libs/libc++/libcxx-sos.patch
@@ -0,0 +1,13 @@
+diff --git a/include/stddef.h b/include/stddef.h
+index 8841bbe..a98f41d 100644
+--- a/include/stddef.h
++++ b/include/stddef.h
+@@ -53,7 +53,7 @@ using std::nullptr_t;
+ }
+
+ // Re-use the compiler's <stddef.h> max_align_t where possible.
+-#if !defined(__CLANG_MAX_ALIGN_T_DEFINED) && !defined(_GCC_MAX_ALIGN_T)
++#if !defined(__CLANG_MAX_ALIGN_T_DEFINED) && !defined(_GCC_MAX_ALIGN_T) && !defined(__DEFINED_max_align_t)
+ typedef long double max_align_t;
+ #endif
+
diff --git a/libs/libc++/libcxxabi-sos.patch b/libs/libc++/libcxxabi-sos.patch
new file mode 100644
index 0000000..46635d8
--- /dev/null
+++ b/libs/libc++/libcxxabi-sos.patch
@@ -0,0 +1,13 @@
+diff --git a/src/cxa_personality.cpp b/src/cxa_personality.cpp
+index 63adf31..da2d9cf 100644
+--- a/src/cxa_personality.cpp
++++ b/src/cxa_personality.cpp
+@@ -336,6 +336,8 @@ static const void* read_target2_value(const void* ptr)
+ #endif
+ }
+
++#endif
++#if 0
+ static const __shim_type_info*
+ get_shim_type_info(uint64_t ttypeIndex, const uint8_t* classInfo,
+ uint8_t ttypeEncoding, bool native_exception,
diff --git a/libs/libmuslc-updated/Kbuild b/libs/libmuslc-updated/Kbuild
new file mode 100644
index 0000000..4575b85
--- /dev/null
+++ b/libs/libmuslc-updated/Kbuild
@@ -0,0 +1,19 @@
+#
+# Copyright 2014, NICTA
+#
+# This software may be distributed and modified according to the terms of
+# the BSD 2-Clause license. Note that NO WARRANTY is provided.
+# See "LICENSE_BSD2.txt" for details.
+#
+# @TAG(NICTA_BSD)
+#
+
+libs-$(CONFIG_LIB_MUSL_C) += libmuslc-updated
+libmuslc-updated: libs/libmuslc-updated/Makefile common
+
+libs/libmuslc-updated/Makefile: | libs/libmuslc-updated/sos.patch
+ curl -L https://github.com/seL4/musllibc/archive/b5c66eef4a8bb274d7a4b9b5b82bce412224dbf9.tar.gz | \
+ tar xzf - -C libs/libmuslc-updated --exclude="*/Kbuild" --strip-components=1
+ (cd libs/libmuslc-updated && patch -mp1 < sos.patch)
+ grep -vF '#include <syscall_sel4.h>' libs/libmuslc/arch_include/arm/arch/syscall_stubs_sel4.h \
+ > libs/libmuslc-updated/arch/arm_sel4/syscall_stubs_sel4.h
diff --git a/libs/libmuslc-updated/Kconfig b/libs/libmuslc-updated/Kconfig
new file mode 100644
index 0000000..cffb56b
--- /dev/null
+++ b/libs/libmuslc-updated/Kconfig
@@ -0,0 +1,23 @@
+#
+# Copyright 2014, NICTA
+#
+# This software may be distributed and modified according to the terms of
+# the BSD 2-Clause license. Note that NO WARRANTY is provided.
+# See "LICENSE_BSD2.txt" for details.
+#
+# @TAG(NICTA_BSD)
+#
+
+menuconfig LIB_MUSL_C
+ bool "libmuslc"
+ default y
+ select HAVE_LIBC
+ select HAVE_CRT
+ help
+ Musl C standard library.
+
+config HAVE_LIBC
+ bool
+
+config HAVE_CRT
+ bool
diff --git a/libs/libmuslc-updated/sos.patch b/libs/libmuslc-updated/sos.patch
new file mode 100644
index 0000000..98d875a
--- /dev/null
+++ b/libs/libmuslc-updated/sos.patch
@@ -0,0 +1,143 @@
+diff --git a/Makefile b/Makefile
+index 229e4ed..0a69a3c 100644
+--- a/Makefile
++++ b/Makefile
+@@ -18,7 +18,7 @@ includedir = $(prefix)/include
+ libdir = $(prefix)/lib
+ syslibdir = /lib
+
+-SRCS = $(sort $(wildcard ${SOURCE_DIR}/src/*/*.c ${SOURCE_DIR}/arch/$(ARCH)/src/*.c))
++SRCS = $(filter-out ${SOURCE_DIR}/src/thread/__set_thread_area.c,$(sort $(wildcard ${SOURCE_DIR}/src/*/*.c ${SOURCE_DIR}/arch/$(ARCH)/src/*.c)))
+ OBJS = $(patsubst ${SOURCE_DIR}/%.c,%.o,$(SRCS))
+ LOBJS = $(OBJS:.o=.lo)
+ GENH = include/bits/alltypes.h
+diff --git a/arch/arm/pthread_arch.h b/arch/arm/pthread_arch.h
+index 4a4dd09..10576f4 100644
+--- a/arch/arm/pthread_arch.h
++++ b/arch/arm/pthread_arch.h
+@@ -1,10 +1,11 @@
+ #if ((__ARM_ARCH_6K__ || __ARM_ARCH_6ZK__) && !__thumb__) \
+ || __ARM_ARCH_7A__ || __ARM_ARCH_7R__ || __ARM_ARCH >= 7
+
++extern void *__thread_area;
++
+ static inline pthread_t __pthread_self()
+ {
+- char *p;
+- __asm__ __volatile__ ( "mrc p15,0,%0,c13,c0,3" : "=r"(p) );
++ char *p = __thread_area;
+ return (void *)(p+8-sizeof(struct pthread));
+ }
+
+diff --git a/arch/arm_sel4/src/__set_thread_area.c b/arch/arm_sel4/src/__set_thread_area.c
+index fbabe57..e4a1334 100644
+--- a/arch/arm_sel4/src/__set_thread_area.c
++++ b/arch/arm_sel4/src/__set_thread_area.c
+@@ -1,5 +1,8 @@
++void *__thread_area;
++
+ int __set_thread_area(void *p)
+ {
+ /* no support for TLS on seL4 at the moment */
++ __thread_area = p;
+ return 0;
+ }
+diff --git a/arch/arm_sel4/src/syscall.c b/arch/arm_sel4/src/syscall.c
+new file mode 100644
+index 0000000..be82805
+--- /dev/null
++++ b/arch/arm_sel4/src/syscall.c
+@@ -0,0 +1,35 @@
++/* @LICENSE(MUSLC_MIT) */
++
++/* The system call distribut interface. */
++
++#include <assert.h>
++#include <stddef.h>
++#include <bits/syscall.h>
++#include "syscall_stubs_sel4.h"
++
++#define SYSCALL_MUSLC_NUM 378
++
++typedef long (*muslc_syscall_t)(va_list);
++typedef muslc_syscall_t muslc_syscall_array_t[378];
++extern muslc_syscall_array_t *__muslc_syscall_ptr_table;
++
++muslc_syscall_array_t *__muslc_syscall_ptr_table;
++
++long __stub_syscall(long n, ...)
++{
++ long ret = 0;
++ va_list ap;
++ va_start(ap, n);
++
++ if (!__muslc_syscall_ptr_table)
++ SET_MUSLC_SYSCALL_TABLE;
++
++ assert (n >=0 && n < SYSCALL_MUSLC_NUM);
++ assert((*__muslc_syscall_ptr_table)[n]);
++
++ ret = (*__muslc_syscall_ptr_table)[n](ap);
++
++ va_end(ap);
++
++ return ret;
++}
+diff --git a/crt/crt1.c b/crt/crt1.c
+index af02af9..dbfc7ee 100644
+--- a/crt/crt1.c
++++ b/crt/crt1.c
+@@ -12,7 +12,11 @@ _Noreturn int __libc_start_main(int (*)(), int, char **,
+
+ void _start_c(long *p)
+ {
++ /* TODO: Uncomment when creating processes with arguments is implemented
+ int argc = p[0];
+ char **argv = (void *)(p+1);
++ */
++ int argc = 0;
++ char *argv[] = {0, 0, 0};
+ __libc_start_main(main, argc, argv, _init, _fini, 0);
+ }
+diff --git a/src/env/__libc_start_main.c b/src/env/__libc_start_main.c
+index d1f6a5e..1359168 100644
+--- a/src/env/__libc_start_main.c
++++ b/src/env/__libc_start_main.c
+@@ -1,4 +1,5 @@
+ #include <elf.h>
++#include <limits.h>
+ #include <poll.h>
+ #include <fcntl.h>
+ #include <signal.h>
+@@ -6,6 +7,7 @@
+ #include "atomic.h"
+ #include "libc.h"
+
++long __stub_syscall(long n, ...);
+ void __init_tls(size_t *);
+
+ #ifndef SHARED
+@@ -34,6 +36,11 @@ void __init_libc(char **envp, char *pn)
+ __sysinfo = aux[AT_SYSINFO];
+ libc.page_size = aux[AT_PAGESZ];
+
++ if (!__sysinfo)
++ __sysinfo = __stub_syscall;
++ if (!libc.page_size)
++ libc.page_size = PAGE_SIZE;
++
+ if (pn) {
+ __progname = __progname_full = pn;
+ for (i=0; pn[i]; i++) if (pn[i]=='/') __progname = pn+i+1;
+diff --git a/src/internal/libc.c b/src/internal/libc.c
+index 2e10942..0ad57d6 100644
+--- a/src/internal/libc.c
++++ b/src/internal/libc.c
+@@ -6,5 +6,7 @@ size_t __hwcap;
+ size_t __sysinfo;
+ char *__progname=0, *__progname_full=0;
+
++void *__dso_handle;
++
+ weak_alias(__progname, program_invocation_short_name);
+ weak_alias(__progname_full, program_invocation_name);
diff --git a/libs/libmuslc/Kbuild b/libs/libmuslc/Kbuild
deleted file mode 100644
index b35a2a2..0000000
--- a/libs/libmuslc/Kbuild
+++ /dev/null
@@ -1,4 +0,0 @@
-# @LICENSE(NICTA)
-
-libs-$(CONFIG_LIB_MUSL_C) += libmuslc
-libmuslc: common
diff --git a/libs/libsos/src/sys_exit.c b/libs/libsos/src/sys_exit.c
index 2b241f9..d6c464a 100644
--- a/libs/libsos/src/sys_exit.c
+++ b/libs/libsos/src/sys_exit.c
@@ -40,6 +40,11 @@ sys_getpid(va_list ap) {
}
long
+sys_set_tid_address(va_list ap) {
+ return sys_gettid(ap);
+}
+
+long
sys_exit(va_list ap)
{
abort();
@@ -54,8 +59,15 @@ sys_exit_group(va_list ap)
}
long
-sys_tgkill(va_list ap)
+sys_tkill(va_list ap)
{
sel4_abort();
return 0;
}
+
+long
+sys_tgkill(va_list ap)
+{
+ sel4_abort();
+ return 0;
+}
\ No newline at end of file
diff --git a/libs/libsos/src/sys_stubs.c b/libs/libsos/src/sys_stubs.c
index 1ac2668..e336a18 100644
--- a/libs/libsos/src/sys_stubs.c
+++ b/libs/libsos/src/sys_stubs.c
@@ -1170,11 +1170,11 @@ long sys_fremovexattr(va_list ap)
assert(!"sys_fremovexattr not implemented");
return 0;
}
-long sys_tkill(va_list ap)
+/*long sys_tkill(va_list ap)
{
assert(!"sys_tkill not implemented");
return 0;
-}
+}*/
long sys_sendfile64(va_list ap)
{
assert(!"sys_sendfile64 not implemented");
@@ -1265,11 +1265,11 @@ long sys_remap_file_pages(va_list ap)
assert(!"sys_remap_file_pages not implemented");
return 0;
}
-long sys_set_tid_address(va_list ap)
+/*long sys_set_tid_address(va_list ap)
{
assert(!"sys_set_tid_address not implemented");
return 0;
-}
+}*/
long sys_timer_create(va_list ap)
{
assert(!"sys_timer_create not implemented");
@@ -2650,11 +2650,11 @@ long sys_fremovexattr(va_list ap)
assert(!"sys_fremovexattr not implemented");
return 0;
}
-long sys_tkill(va_list ap)
+/*long sys_tkill(va_list ap)
{
assert(!"sys_tkill not implemented");
return 0;
-}
+}*/
long sys_sendfile64(va_list ap)
{
assert(!"sys_sendfile64 not implemented");
@@ -2730,11 +2730,11 @@ long sys_remap_file_pages(va_list ap)
assert(!"sys_remap_file_pages not implemented");
return 0;
}
-long sys_set_tid_address(va_list ap)
+/*long sys_set_tid_address(va_list ap)
{
assert(!"sys_set_tid_address not implemented");
return 0;
-}
+}*/
long sys_timer_create(va_list ap)
{
assert(!"sys_timer_create not implemented");
diff --git a/tools/common/common.mk b/tools/common/common.mk
index 3239706..cd25899 100644
--- a/tools/common/common.mk
+++ b/tools/common/common.mk
@@ -76,7 +76,7 @@ ENDGROUP := -Wl,--end-group
ifeq (${CONFIG_USER_CFLAGS},)
CFLAGS += $(WARNINGS:%=-W%) -nostdinc -std=gnu11
- CXXFLAGS += $(WARNINGS:%=-W%) -nostdinc -std=gnu++98
+ CXXFLAGS += $(WARNINGS:%=-W%) -nostdinc -std=c++14 -I$(SEL4_INCLUDEDIR)/c++/v1
ifeq (${CONFIG_USER_OPTIMISATION_Os},y)
CFLAGS += -Os
@@ -149,7 +149,7 @@ LDFLAGS += -e ${ENTRY_POINT}
ASFLAGS += $(NK_ASFLAGS)
# Object files
-OBJFILES = $(ASMFILES:%.S=%.o) $(CFILES:%.c=%.o) $(CXXFILES:%.cxx=%.o) $(OFILES)
+OBJFILES = $(ASMFILES:%.S=%.o) $(CFILES:%.c=%.o) $(CXXFILES:%.cpp=%.o) $(OFILES)
# Define standard crt files if are building against a C library that has them
ifeq (${CONFIG_HAVE_CRT},y)
@@ -172,7 +172,7 @@ vpath %.a $(SEL4_LIBDIR)
# Where to find the sources
vpath %.c $(SOURCE_DIR)
-vpath %.cxx $(SOURCE_DIR)
+vpath %.cpp $(SOURCE_DIR)
vpath %.S $(SOURCE_DIR)
# Default is to build/install all targets
@@ -231,7 +231,7 @@ else
$(Q)$(call make-depend,$<,$@,$(patsubst %.o,%.d,$@))
$(Q)$(CC) -x c $(CFLAGS) $(CPPFLAGS) -c $< -o $@
endif
-%.o: %.cxx $(HFILES) | install-headers
+%.o: %.cpp $(HFILES) | install-headers
@echo " [CXX] $@"
$(Q)mkdir -p $(dir $@)
$(Q)$(call make-cxx-depend,$<,$@,$(patsubst %.o,%.d,$@))
@@ -286,7 +286,7 @@ $(TARGETS): $(LIBS:%=-l%)
# (Default is .LIBPATTERNS = lib%.so lib%.a)
.LIBPATTERNS = lib%.a
-DEPS = $(patsubst %.c,%.d,$(CFILES)) $(patsubst %.cxx,%.d,$(CXXFILES)) $(patsubst %.S,%.d,$(ASMFILES))
+DEPS = $(patsubst %.c,%.d,$(CFILES)) $(patsubst %.cpp,%.d,$(CXXFILES)) $(patsubst %.S,%.d,$(ASMFILES))
ifneq "$(MAKECMDGOALS)" "clean"
-include ${DEPS}
--
2.9.2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.