Build: Build stub functions of system calls when required

Change-Id: I286bec82f63d97175d12e486330f62bea5a0c449
Signed-off-by: Kevin Peng <kevin.peng@arm.com>
diff --git a/app_broker/syscalls_stub.c b/app_broker/syscalls_stub.c
new file mode 100644
index 0000000..9ebe78e
--- /dev/null
+++ b/app_broker/syscalls_stub.c
@@ -0,0 +1,55 @@
+/*
+ * Copyright (c) 2023, Arm Limited. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ *
+ */
+
+/*
+ * NOTE: When GNU Arm compiler version greater equal than *11.3.Rel1*, there is a linker issue that
+ * some system calls are not implemented, such as _close, _fstat and _getpid etc. So add this file
+ * including stub functions of system calls to avoid the above linker issue.
+ */
+
+#include <stddef.h>
+#include <stdint.h>
+
+__attribute__((weak))
+void _close(void)
+{
+}
+
+__attribute__((weak))
+void _fstat(void)
+{
+}
+
+__attribute__((weak))
+void _getpid(void)
+{
+}
+
+__attribute__((weak))
+void _isatty(void)
+{
+}
+
+__attribute__((weak))
+void _kill(void)
+{
+}
+
+__attribute__((weak))
+void _lseek(void)
+{
+}
+
+__attribute__((weak))
+void _read(void)
+{
+}
+
+__attribute__((weak))
+void _write(void)
+{
+}
diff --git a/tests_psa_arch/CMakeLists.txt b/tests_psa_arch/CMakeLists.txt
index 51dd279..1c6fe67 100644
--- a/tests_psa_arch/CMakeLists.txt
+++ b/tests_psa_arch/CMakeLists.txt
@@ -104,6 +104,7 @@
 target_sources(tfm_ns
     PRIVATE
         test_app.c
+        $<$<BOOL:${CONFIG_GNU_SYSCALL_STUB_ENABLED}>:../app_broker/syscalls_stub.c>
 )
 
 target_link_libraries(tfm_ns
diff --git a/tests_reg/CMakeLists.txt b/tests_reg/CMakeLists.txt
index 091a5ec..330566a 100644
--- a/tests_reg/CMakeLists.txt
+++ b/tests_reg/CMakeLists.txt
@@ -69,6 +69,7 @@
 target_sources(tfm_ns
     PRIVATE
         test_app.c
+        $<$<BOOL:${CONFIG_GNU_SYSCALL_STUB_ENABLED}>:../app_broker/syscalls_stub.c>
 )
 
 target_link_libraries(tfm_ns