Enhance standard library integration
This change makes the split between standard library related and non
standard library related build settings cleaner. This may make
enabling other standard libraries to be used in SPs easier
Changes:
- the standard library target is renamed to stdlib::c
- newlib specific files moved to newlib component
- GCC flags changing standard library related search paths moved to
newlib component
- modified newlib targets to use transitive dependencies to get
libnosys.a linked
- newlib component defines the -nostdinc flag again
Change-Id: I5e9ef72cc42454c70d234a15d516634eea51d494
Signed-off-by: Gyorgy Szing <Gyorgy.Szing@arm.com>
diff --git a/environments/opteesp/component.cmake b/environments/opteesp/component.cmake
index f6a65cd..1b7c418 100644
--- a/environments/opteesp/component.cmake
+++ b/environments/opteesp/component.cmake
@@ -11,9 +11,6 @@
target_sources(${TGT} PRIVATE
"${CMAKE_CURRENT_LIST_DIR}/optee_sp_header.c"
- "${CMAKE_CURRENT_LIST_DIR}/newlib_init.c"
- "${CMAKE_CURRENT_LIST_DIR}/newlib_sp_assert.c"
- "${CMAKE_CURRENT_LIST_DIR}/newlib_sp_heap.c"
"${CMAKE_CURRENT_LIST_DIR}/sp_entry.c"
"${CMAKE_CURRENT_LIST_DIR}/sp_trace.c"
)
@@ -36,8 +33,7 @@
include(../../../external/newlib/newlib.cmake)
target_link_libraries(${TGT} PRIVATE
- c
- nosys
+ stdlib::c
)
target_link_options(${TGT} PRIVATE
diff --git a/environments/opteesp/default_toolchain_file.cmake b/environments/opteesp/default_toolchain_file.cmake
index 643773c..541cd89 100644
--- a/environments/opteesp/default_toolchain_file.cmake
+++ b/environments/opteesp/default_toolchain_file.cmake
@@ -22,9 +22,4 @@
string(APPEND CMAKE_C_FLAGS_INIT " -fpic")
# - Disable startup files and default libraries.
# - Link position independent executable
-string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " -nostartfiles -nodefaultlibs -pie")
-
-# -link libgcc with full PATH to work around disabled linker search paths.
-gcc_get_lib_location("libgcc.a" _TMP_VAR)
-string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " ${_TMP_VAR} ")
-unset(_TMP_VAR)
+string(APPEND CMAKE_EXE_LINKER_FLAGS_INIT " -pie")
diff --git a/environments/opteesp/newlib_init.c b/environments/opteesp/newlib_init.c
deleted file mode 100644
index 9450a68..0000000
--- a/environments/opteesp/newlib_init.c
+++ /dev/null
@@ -1,20 +0,0 @@
-// SPDX-License-Identifier: BSD-3-Clause
-/*
- * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
- */
-
-#include "libc_init.h"
-
-/* Comes from libc */
-void __libc_init_array(void);
-
-void _init(void)
-{
- /* Dummy */
-}
-
-void libc_init(void)
-{
- /* Initializing global variables, calling constructors */
- __libc_init_array();
-}
diff --git a/environments/opteesp/newlib_sp_assert.c b/environments/opteesp/newlib_sp_assert.c
deleted file mode 100644
index 5a2d428..0000000
--- a/environments/opteesp/newlib_sp_assert.c
+++ /dev/null
@@ -1,21 +0,0 @@
-// SPDX-License-Identifier: BSD-3-Clause
-/*
- * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
- */
-
-#include <assert.h>
-#include "compiler.h"
-#include "trace.h"
-
-/*
- * The generic trace function called on assert fail.
- */
-void __noreturn __assert_func(const char *file, int line, const char *func, const char *failedexpr)
-{
-#if TRACE_LEVEL >= TRACE_LEVEL_ERROR
- trace_printf(func, line, TRACE_LEVEL_ERROR, "assertion %s failed", failedexpr);
-#endif /* TRACE_LEVEL */
-
- while (1)
- ;
-}
diff --git a/environments/opteesp/newlib_sp_heap.c b/environments/opteesp/newlib_sp_heap.c
deleted file mode 100644
index 77a288a..0000000
--- a/environments/opteesp/newlib_sp_heap.c
+++ /dev/null
@@ -1,37 +0,0 @@
-// SPDX-License-Identifier: BSD-3-Clause
-/*
- * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
- */
-
-#include "compiler.h"
-#include "optee_sp_user_defines.h"
-#include <errno.h>
-#include <stdint.h>
-#include <unistd.h>
-
-/* Allocating heap area */
-#ifndef OPTEE_SP_HEAP_SIZE
-#error "OPTEE_SP_HEAP_SIZE is not defined in SP"
-#endif
-
-static uint8_t sp_heap[OPTEE_SP_HEAP_SIZE] __aligned(16);
-static uint8_t *program_break = sp_heap;
-
-/**
- * Basic sbrk implementation which increases the program break through the
- * sp_heap buffer.
- */
-void *_sbrk(ptrdiff_t incr)
-{
- uint8_t *previous_break = program_break;
- uint8_t *new_break = program_break + incr;
-
- if ((new_break < sp_heap) || (new_break > (sp_heap + sizeof(sp_heap)))) {
- errno = ENOMEM;
- return (void *)(uintptr_t) -1;
- }
-
- program_break += incr;
-
- return (void *) previous_break;
-}