You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by da...@apache.org on 2020/07/11 17:34:36 UTC
[incubator-nuttx] 02/03: libc: Move unwind code to
libs/libc/machine/arm
This is an automated email from the ASF dual-hosted git repository.
davids5 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit aa0d57e8adc1b6dfdbe4cc61607c494cf0072764
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sun Jun 28 18:18:34 2020 +0800
libc: Move unwind code to libs/libc/machine/arm
because the logic:
1.only work on arm platform
2.couple with elf format
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
Change-Id: I25dc95b5fc7b24196e2e71fdcf82d71d621ee2d3
---
libs/libc/machine/arm/Make.defs | 7 ++
libs/libc/machine/arm/gnu_unwind_find_exidx.c | 121 ++++++++++++++++++++++++++
libs/libxx/Makefile | 3 -
libs/libxx/libxx__gnu_unwind_find_exidx.cxx | 108 -----------------------
libs/libxx/libxx__gnu_unwind_find_exidx.hxx | 79 -----------------
5 files changed, 128 insertions(+), 190 deletions(-)
diff --git a/libs/libc/machine/arm/Make.defs b/libs/libc/machine/arm/Make.defs
index 5f8cd9e..0afb80c 100644
--- a/libs/libc/machine/arm/Make.defs
+++ b/libs/libc/machine/arm/Make.defs
@@ -50,3 +50,10 @@ include $(TOPDIR)/libs/libc/machine/arm/armv7-m/Make.defs
else ifeq ($(CONFIG_ARCH_CORTEXM33),y) # Cortex-M33 is ARMv8-M
include $(TOPDIR)/libs/libc/machine/arm/armv8/Make.defs
endif
+
+ifeq ($(CONFIG_CXX_EXCEPTION),y)
+CSRCS += gnu_unwind_find_exidx.c
+endif
+
+DEPPATH += --dep-path machine/arm
+VPATH += :machine/arm
diff --git a/libs/libc/machine/arm/gnu_unwind_find_exidx.c b/libs/libc/machine/arm/gnu_unwind_find_exidx.c
new file mode 100644
index 0000000..449208c
--- /dev/null
+++ b/libs/libc/machine/arm/gnu_unwind_find_exidx.c
@@ -0,0 +1,121 @@
+/****************************************************************************
+ * libs/libc/machine/arm/gnu_unwind_find_exidx.c
+ *
+ * Copyright (C) 2015 Gregory Nutt. All rights reserved.
+ * Author: Gregory Nutt <gn...@nuttx.org>
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ * 3. Neither the name NuttX nor the names of its contributors may be
+ * used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
+ * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
+ * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
+ * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
+ * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/elf.h>
+#include <unwind.h>
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+typedef struct __EIT_entry
+{
+ _uw fnoffset;
+ _uw content;
+} __EIT_entry;
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+static __EIT_entry *__exidx_start_elf;
+static __EIT_entry *__exidx_end_elf;
+
+/****************************************************************************
+ * Public Data
+ ****************************************************************************/
+
+extern __EIT_entry __exidx_start;
+extern __EIT_entry __exidx_end;
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: __gnu_Unwind_Find_exidx
+ *
+ * Description:
+ * This function is called (if exists) by the gcc generated unwind
+ * run-time in order to retrieve an alternative .ARM.exidx Exception
+ * index section.
+ * This is the case for an ELF module loaded by the elf binary loader.
+ * It is needed to support exception handling for loadable ELF modules.
+ *
+ * NOTES:
+ *
+ * 1. The section to be searched is chosen by the address of the calling
+ * site: if we are in a runtime loaded ELF, the code will be executed
+ * in ram ( > 0x20000000 ) otherwise we will be executing code from
+ * flash (0x08000000) (running nuttx from ram will break this logic)
+ *
+ * 2. __exidx_start and __exidx_end refers to main nuttx elf image and
+ * are defined in its linker script.
+ *
+ * 2. __exidx_start_elf and __exidx_end_elf refers to the elf module
+ * loaded by the elf binary loader, and are initialized at run-time.
+ *
+ * 3. TODO: if nuttx itself is running from ram, this logic will not work
+ *
+ * 4. TODO: in order to support multiple elf modules running at the same
+ * time, this error logic needs to be extended to store multiple
+ * start/end ranges that refers to the loaded binaries.
+ *
+ ****************************************************************************/
+
+int up_init_exidx(Elf_Addr start, Elf_Word size)
+{
+ __exidx_start_elf = (__EIT_entry *)start;
+ __exidx_end_elf = (__EIT_entry *)(start + size);
+ return 0;
+}
+
+_Unwind_Ptr __gnu_Unwind_Find_exidx(_Unwind_Ptr return_address, int *nrecp)
+{
+ if (return_address < 0x20000000)
+ {
+ *nrecp = &__exidx_end - &__exidx_start;
+ return (_Unwind_Ptr)&__exidx_start;
+ }
+ else
+ {
+ *nrecp = __exidx_end_elf - __exidx_start_elf;
+ return (_Unwind_Ptr)__exidx_start_elf;
+ }
+}
diff --git a/libs/libxx/Makefile b/libs/libxx/Makefile
index 149b4b3..423e659 100644
--- a/libs/libxx/Makefile
+++ b/libs/libxx/Makefile
@@ -37,9 +37,6 @@ include $(TOPDIR)/Make.defs
CXXSRCS = libxx_cxapurevirtual.cxx libxx_eabi_atexit.cxx libxx_cxa_atexit.cxx
CXXSRCS += libxx_cxa_guard.cxx
-ifeq ($(CONFIG_CXX_EXCEPTION),y)
-CXXSRCS += libxx__gnu_unwind_find_exidx.cxx
-endif
# Some of the libs/libxx/ files are not need if uClibc++ or libcxx is installed
# because uClibx++ or libcxx will replace them
diff --git a/libs/libxx/libxx__gnu_unwind_find_exidx.cxx b/libs/libxx/libxx__gnu_unwind_find_exidx.cxx
deleted file mode 100644
index 08b67fa..0000000
--- a/libs/libxx/libxx__gnu_unwind_find_exidx.cxx
+++ /dev/null
@@ -1,108 +0,0 @@
-//***************************************************************************
-// libs/libxx/libxx__gnu_unwind_find_exidx.cxx
-//
-// Copyright (C) 2015 Gregory Nutt. All rights reserved.
-// Author: Gregory Nutt <gn...@nuttx.org>
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions
-// are met:
-//
-// 1. Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// 2. Redistributions in binary form must reproduce the above copyright
-// notice, this list of conditions and the following disclaimer in
-// the documentation and/or other materials provided with the
-// distribution.
-// 3. Neither the name NuttX nor the names of its contributors may be
-// used to endorse or promote products derived from this software
-// without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
-// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
-// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
-// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-// POSSIBILITY OF SUCH DAMAGE.
-//
-//***************************************************************************
-
-//***************************************************************************
-// Included Files
-//***************************************************************************
-
-#include <nuttx/elf.h>
-#include "libxx__gnu_unwind_find_exidx.hxx"
-
-//***************************************************************************
-// Pre-processor Definitions
-//***************************************************************************
-
-//***************************************************************************
-// Private Data
-//***************************************************************************
-
-//***************************************************************************
-// Operators
-//***************************************************************************
-
-//***************************************************************************
-// Name: __gnu_Unwind_Find_exidx
-//
-// Description:
-// This function is called (if exists) by the gcc generated unwind
-// run-time in order to retrieve an alternative .ARM.exidx Exception
-// index section.
-// This is the case for an ELF module loaded by the elf binary loader.
-// It is needed to support exception handling for loadable ELF modules.
-//
-// NOTES:
-//
-// 1. The section to be searched is chosen by the address of the calling
-// site: if we are in a runtime loaded ELF, the code will be executed
-// in ram ( > 0x20000000 ) otherwise we will be executing code from
-// flash (0x08000000) (running nuttx from ram will break this logic)
-//
-// 2. __exidx_start and __exidx_end refers to main nuttx elf image and
-// are defined in its linker script.
-//
-// 2. __exidx_start_elf and __exidx_end_elf refers to the elf module
-// loaded by the elf binary loader, and are initialized at run-time.
-//
-// 3. TODO: if nuttx itself is running from ram, this logic will not work
-//
-// 4. TODO: in order to support multiple elf modules running at the same
-// time, this error logic needs to be extended to store multiple
-// start/end ranges that refers to the loaded binaries.
-//
-//***************************************************************************
-
-extern "C"
-{
- int up_init_exidx(Elf_Addr start, Elf_Word size)
- {
- __exidx_start_elf = (__EIT_entry *) start;
- __exidx_end_elf = __exidx_start_elf + size;
- return 0;
- }
-
- _Unwind_Ptr __gnu_Unwind_Find_exidx (_Unwind_Ptr return_address, int *nrecp)
- {
- if (return_address < 0x20000000)
- {
- *nrecp = &__exidx_end - &__exidx_start;
- return (_Unwind_Ptr) &__exidx_start;
- }
- else
- {
- *nrecp = (__exidx_end_elf - __exidx_start_elf) / sizeof(__EIT_entry);
- return (_Unwind_Ptr) __exidx_start_elf;
- }
- }
-}
diff --git a/libs/libxx/libxx__gnu_unwind_find_exidx.hxx b/libs/libxx/libxx__gnu_unwind_find_exidx.hxx
deleted file mode 100644
index 63925b0..0000000
--- a/libs/libxx/libxx__gnu_unwind_find_exidx.hxx
+++ /dev/null
@@ -1,79 +0,0 @@
-//***************************************************************************
-// lib/libxx__gnu_unwind_find_exidx.hxx
-//
-// Copyright (C) 2015 Gregory Nutt. All rights reserved.
-// Author: Gregory Nutt <gn...@nuttx.org>
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions
-// are met:
-//
-// 1. Redistributions of source code must retain the above copyright
-// notice, this list of conditions and the following disclaimer.
-// 2. Redistributions in binary form must reproduce the above copyright
-// notice, this list of conditions and the following disclaimer in
-// the documentation and/or other materials provided with the
-// distribution.
-// 3. Neither the name NuttX nor the names of its contributors may be
-// used to endorse or promote products derived from this software
-// without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
-// FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
-// COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
-// INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
-// BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
-// OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
-// AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
-// LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
-// ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-// POSSIBILITY OF SUCH DAMAGE.
-//
-//***************************************************************************
-
-#ifndef __LIBXX_LIBXX__GNU_UNWIND_FIND_EXIDX_HXX
-#define __LIBXX_LIBXX__GNU_UNWIND_FIND_EXIDX_HXX
-
-extern "C"
-{
-//***************************************************************************
-// Included Files
-//***************************************************************************
-
-#include <unwind.h>
-
-//***************************************************************************
-// Pre-processor Definitions
-//***************************************************************************
-
-//***************************************************************************
-// Public Types
-//***************************************************************************/
-
-typedef struct __EIT_entry
-{
- _uw fnoffset;
- _uw content;
-} __EIT_entry;
-
-//***************************************************************************
-// Public Data
-//***************************************************************************
-
-extern __EIT_entry __exidx_start;
-extern __EIT_entry __exidx_end;
-
-__EIT_entry *__exidx_start_elf;
-__EIT_entry *__exidx_end_elf;
-
-//***************************************************************************
-// Public Function Prototypes
-//***************************************************************************
-
- _Unwind_Ptr __gnu_Unwind_Find_exidx(_Unwind_Ptr return_address, int *nrecp);
-
-} // extern "C"
-
-#endif // __LIBXX__GNU_UNWIND_FIND_EXIDX_HXX