Просмотр исходного кода

Fix AOT debug for macOS (#1494)

note: macOS doesn't have elf.h
YAMAMOTO Takashi 3 лет назад
Родитель
Сommit
f5939c7bc1

+ 8 - 0
ATTRIBUTIONS.md

@@ -15,6 +15,7 @@ WAMR project reused some components from other open source project:
 - **uvwasi**: for the WASI Libc with uvwasi implementation
 - **uvwasi**: for the WASI Libc with uvwasi implementation
 - **asmjit**: for the Fast JIT x86-64 codegen implementation
 - **asmjit**: for the Fast JIT x86-64 codegen implementation
 - **zydis**: for the Fast JIT x86-64 codegen implementation
 - **zydis**: for the Fast JIT x86-64 codegen implementation
+- **NuttX ELF headers**: used in core/iwasm/aot/debug/elf_parser.c
 
 
 The WAMR fast interpreter is a clean room development. We would acknowledge the inspirations by [WASM3](https://github.com/wasm3/wasm3) open source project for the approach of pre-calculated oprand stack location.
 The WAMR fast interpreter is a clean room development. We would acknowledge the inspirations by [WASM3](https://github.com/wasm3/wasm3) open source project for the approach of pre-calculated oprand stack location.
 
 
@@ -33,6 +34,7 @@ The WAMR fast interpreter is a clean room development. We would acknowledge the
 | uvwasi | unspecified | v0.0.12 | https://github.com/nodejs/uvwasi | |
 | uvwasi | unspecified | v0.0.12 | https://github.com/nodejs/uvwasi | |
 | asmjit | unspecified | unspecified | https://github.com/asmjit/asmjit | |
 | asmjit | unspecified | unspecified | https://github.com/asmjit/asmjit | |
 | zydis | unspecified | e14a07895136182a5b53e181eec3b1c6e0b434de | https://github.com/zyantific/zydis | |
 | zydis | unspecified | e14a07895136182a5b53e181eec3b1c6e0b434de | https://github.com/zyantific/zydis | |
+| NuttX ELF headers | 72313301e23f9c2de969fb64b9a0f67bb4c284df | 10.3.0 | https://github.com/apache/incubator-nuttx | |
 
 
 ## Licenses
 ## Licenses
 
 
@@ -89,3 +91,9 @@ The WAMR fast interpreter is a clean room development. We would acknowledge the
 
 
 ### zydis
 ### zydis
 [LICENSE](./core/iwasm/fast-jit/cg/LICENSE_ZYDIS)
 [LICENSE](./core/iwasm/fast-jit/cg/LICENSE_ZYDIS)
+
+### NuttX ELF headers
+
+[LICENSE](./core/iwasm/aot/debug/LICENSE_NUTTX)
+
+[NOTICE](./core/iwasm/aot/debug/NOTICE_NUTTX)

+ 202 - 0
core/iwasm/aot/debug/LICENSE_NUTTX

@@ -0,0 +1,202 @@
+                               Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   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.
+

+ 5 - 0
core/iwasm/aot/debug/NOTICE_NUTTX

@@ -0,0 +1,5 @@
+Apache NuttX
+Copyright 2020 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).

+ 368 - 0
core/iwasm/aot/debug/elf.h

@@ -0,0 +1,368 @@
+/****************************************************************************
+ * include/elf.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you 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.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_ELF_H
+#define __INCLUDE_ELF_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdint.h>
+
+#define EI_NIDENT 16 /* Size of e_ident[] */
+
+/* NOTE: elf64.h and elf32.h refer EI_NIDENT defined above */
+
+#include "elf64.h"
+#include "elf32.h"
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Values for Elf_Ehdr::e_type */
+
+#define ET_NONE 0        /* No file type */
+#define ET_REL 1         /* Relocatable file */
+#define ET_EXEC 2        /* Executable file */
+#define ET_DYN 3         /* Shared object file */
+#define ET_CORE 4        /* Core file */
+#define ET_LOPROC 0xff00 /* Processor-specific */
+#define ET_HIPROC 0xffff /* Processor-specific */
+
+/* Values for Elf_Ehdr::e_machine (most of this were not included in the
+ * original SCO document but have been gleaned from elsewhere).
+ */
+
+#define EM_NONE 0         /* No machine */
+#define EM_M32 1          /* AT&T WE 32100 */
+#define EM_SPARC 2        /* SPARC */
+#define EM_386 3          /* Intel 80386 */
+#define EM_68K 4          /* Motorola 68000 */
+#define EM_88K 5          /* Motorola 88000 */
+#define EM_486 6          /* Intel 486+ */
+#define EM_860 7          /* Intel 80860 */
+#define EM_MIPS 8         /* MIPS R3000 Big-Endian */
+#define EM_MIPS_RS4_BE 10 /* MIPS R4000 Big-Endian */
+#define EM_PARISC 15      /* HPPA */
+#define EM_SPARC32PLUS 18 /* Sun's "v8plus" */
+#define EM_PPC 20         /* PowerPC */
+#define EM_PPC64 21       /* PowerPC64 */
+#define EM_ARM 40         /* ARM */
+#define EM_SH 42          /* SuperH */
+#define EM_SPARCV9 43     /* SPARC v9 64-bit */
+#define EM_H8_300 46
+#define EM_IA_64 50  /* HP/Intel IA-64 */
+#define EM_X86_64 62 /* AMD x86-64 */
+#define EM_S390 22   /* IBM S/390 */
+#define EM_CRIS 76   /* Axis Communications 32-bit embedded processor */
+#define EM_V850 87   /* NEC v850 */
+#define EM_M32R 88   /* Renesas M32R */
+#define EM_XTENSA 94 /* Tensilica Xtensa */
+#define EM_RISCV 243 /* RISC-V */
+#define EM_ALPHA 0x9026
+#define EM_CYGNUS_V850 0x9080
+#define EM_CYGNUS_M32R 0x9041
+#define EM_S390_OLD 0xa390
+#define EM_FRV 0x5441
+
+/* Values for Elf_Ehdr::e_version */
+
+#define EV_NONE 0    /* Invalid version */
+#define EV_CURRENT 1 /* The current version */
+
+/* Table 2. Ehe ELF identifier */
+
+#define EI_MAG0 0 /* File identification */
+#define EI_MAG1 1
+#define EI_MAG2 2
+#define EI_MAG3 3
+#define EI_CLASS 4   /* File class */
+#define EI_DATA 5    /* Data encoding */
+#define EI_VERSION 6 /* File version */
+#define EI_OSABI 7   /* OS ABI */
+#define EI_PAD 8     /* Start of padding bytes */
+
+/* EI_NIDENT is defined in "Included Files" section */
+
+#define EI_MAGIC_SIZE 4
+#define EI_MAGIC            \
+    {                       \
+        0x7f, 'E', 'L', 'F' \
+    }
+
+#define ELFMAG0 0x7f /* EI_MAG */
+#define ELFMAG1 'E'
+#define ELFMAG2 'L'
+#define ELFMAG3 'F'
+#define ELFMAG "\177ELF"
+
+/* Table 3. Values for EI_CLASS */
+
+#define ELFCLASSNONE 0 /* Invalid class */
+#define ELFCLASS32 1   /* 32-bit objects */
+#define ELFCLASS64 2   /* 64-bit objects */
+
+/* Table 4. Values for EI_DATA */
+
+#define ELFDATANONE 0 /* Invalid data encoding */
+#define ELFDATA2LSB                                                          \
+    1                 /* Least significant byte occupying the lowest address \
+                       */
+#define ELFDATA2MSB 2 /* Most significant byte occupying the lowest address */
+
+/* Table 6. Values for EI_OSABI */
+
+#define ELFOSABI_NONE 0   /* UNIX System V ABI */
+#define ELFOSABI_SYSV 0   /* Alias.  */
+#define ELFOSABI_HPUX 1   /* HP-UX */
+#define ELFOSABI_NETBSD 2 /* NetBSD.  */
+#define ELFOSABI_GNU 3    /* Object uses GNU ELF extensions.  */
+#define ELFOSABI_LINUX ELFOSABI_GNU
+/* Compatibility alias.  */
+#define ELFOSABI_SOLARIS 6      /* Sun Solaris.  */
+#define ELFOSABI_AIX 7          /* IBM AIX.  */
+#define ELFOSABI_IRIX 8         /* SGI Irix.  */
+#define ELFOSABI_FREEBSD 9      /* FreeBSD.  */
+#define ELFOSABI_TRU64 10       /* Compaq TRU64 UNIX.  */
+#define ELFOSABI_MODESTO 11     /* Novell Modesto.  */
+#define ELFOSABI_OPENBSD 12     /* OpenBSD.  */
+#define ELFOSABI_ARM_AEABI 64   /* ARM EABI */
+#define ELFOSABI_ARM 97         /* ARM */
+#define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */
+
+#ifndef ELF_OSABI
+#define ELF_OSABI ELFOSABI_NONE
+#endif
+
+/* Table 7: Special Section Indexes */
+
+#define SHN_UNDEF 0
+#define SHN_LOPROC 0xff00
+#define SHN_HIPROC 0xff1f
+#define SHN_ABS 0xfff1
+#define SHN_COMMON 0xfff2
+
+/* Figure 4-9: Section Types, sh_type */
+
+#define SHT_NULL 0
+#define SHT_PROGBITS 1
+#define SHT_SYMTAB 2
+#define SHT_STRTAB 3
+#define SHT_RELA 4
+#define SHT_HASH 5
+#define SHT_DYNAMIC 6
+#define SHT_NOTE 7
+#define SHT_NOBITS 8
+#define SHT_REL 9
+#define SHT_SHLIB 10
+#define SHT_DYNSYM 11
+#define SHT_LOPROC 0x70000000
+#define SHT_HIPROC 0x7fffffff
+#define SHT_LOUSER 0x80000000
+#define SHT_HIUSER 0xffffffff
+
+/* Figure 4-11: Section Attribute Flags, sh_flags */
+
+#define SHF_WRITE 1
+#define SHF_ALLOC 2
+#define SHF_EXECINSTR 4
+#define SHF_MASKPROC 0xf0000000
+
+/* Figure 4-16: Symbol Binding, ELF_ST_BIND */
+
+#define STB_LOCAL 0
+#define STB_GLOBAL 1
+#define STB_WEAK 2
+#define STB_LOPROC 13
+#define STB_HIPROC 15
+
+/* Figure 4-17: Symbol Types, ELF_ST_TYPE */
+
+#define STT_NOTYPE 0
+#define STT_OBJECT 1
+#define STT_FUNC 2
+#define STT_SECTION 3
+#define STT_FILE 4
+#define STT_LOPROC 13
+#define STT_HIPROC 15
+
+/* Figure 5-2: Segment Types, p_type */
+
+#define PT_NULL 0
+#define PT_LOAD 1
+#define PT_DYNAMIC 2
+#define PT_INTERP 3
+#define PT_NOTE 4
+#define PT_SHLIB 5
+#define PT_PHDR 6
+#define PT_LOPROC 0x70000000
+#define PT_HIPROC 0x7fffffff
+
+/* Figure 5-3: Segment Flag Bits, p_flags */
+
+#define PF_X 1                 /* Execute */
+#define PF_W 2                 /* Write */
+#define PF_R 4                 /* Read */
+#define PF_MASKPROC 0xf0000000 /* Unspecified */
+
+/* Figure 5-10: Dynamic Array Tags, d_tag */
+
+#define DT_NULL 0            /* d_un=ignored */
+#define DT_NEEDED 1          /* d_un=d_val */
+#define DT_PLTRELSZ 2        /* d_un=d_val */
+#define DT_PLTGOT 3          /* d_un=d_ptr */
+#define DT_HASH 4            /* d_un=d_ptr */
+#define DT_STRTAB 5          /* d_un=d_ptr */
+#define DT_SYMTAB 6          /* d_un=d_ptr */
+#define DT_RELA 7            /* d_un=d_ptr */
+#define DT_RELASZ 8          /* d_un=d_val */
+#define DT_RELAENT 9         /* d_un=d_val */
+#define DT_STRSZ 10          /* d_un=d_val */
+#define DT_SYMENT 11         /* d_un=d_val */
+#define DT_INIT 12           /* d_un=d_ptr */
+#define DT_FINI 13           /* d_un=d_ptr */
+#define DT_SONAME 14         /* d_un=d_val */
+#define DT_RPATH 15          /* d_un=d_val */
+#define DT_SYMBOLIC 16       /* d_un=ignored */
+#define DT_REL 17            /* d_un=d_ptr */
+#define DT_RELSZ 18          /* d_un=d_val */
+#define DT_RELENT 19         /* d_un=d_val */
+#define DT_PLTREL 20         /* d_un=d_val */
+#define DT_DEBUG 21          /* d_un=d_ptr */
+#define DT_TEXTREL 22        /* d_un=ignored */
+#define DT_JMPREL 23         /* d_un=d_ptr */
+#define DT_BINDNOW 24        /* d_un=ignored */
+#define DT_LOPROC 0x70000000 /* d_un=unspecified */
+#define DT_HIPROC 0x7fffffff /* d_un= unspecified */
+
+/* Legal values for note segment descriptor types for core files. */
+
+#define NT_PRSTATUS 1   /* Contains copy of prstatus struct */
+#define NT_PRFPREG 2    /* Contains copy of fpregset struct. */
+#define NT_FPREGSET 2   /* Contains copy of fpregset struct */
+#define NT_PRPSINFO 3   /* Contains copy of prpsinfo struct */
+#define NT_PRXREG 4     /* Contains copy of prxregset struct */
+#define NT_TASKSTRUCT 4 /* Contains copy of task structure */
+#define NT_PLATFORM 5   /* String from sysinfo(SI_PLATFORM) */
+#define NT_AUXV 6       /* Contains copy of auxv array */
+#define NT_GWINDOWS 7   /* Contains copy of gwindows struct */
+#define NT_ASRS 8       /* Contains copy of asrset struct */
+#define NT_PSTATUS 10   /* Contains copy of pstatus struct */
+#define NT_PSINFO 13    /* Contains copy of psinfo struct */
+#define NT_PRCRED 14    /* Contains copy of prcred struct */
+#define NT_UTSNAME 15   /* Contains copy of utsname struct */
+#define NT_LWPSTATUS 16 /* Contains copy of lwpstatus struct */
+#define NT_LWPSINFO 17  /* Contains copy of lwpinfo struct */
+#define NT_PRFPXREG 20  /* Contains copy of fprxregset struct */
+#define NT_SIGINFO 0x53494749
+/* Contains copy of siginfo_t,
+ * size might increase
+ */
+#define NT_FILE 0x46494c45
+/* Contains information about mapped
+ * files
+ */
+#define NT_PRXFPREG 0x46e62b7f
+/* Contains copy of user_fxsr_struct */
+#define NT_PPC_VMX 0x100     /* PowerPC Altivec/VMX registers */
+#define NT_PPC_SPE 0x101     /* PowerPC SPE/EVR registers */
+#define NT_PPC_VSX 0x102     /* PowerPC VSX registers */
+#define NT_PPC_TAR 0x103     /* Target Address Register */
+#define NT_PPC_PPR 0x104     /* Program Priority Register */
+#define NT_PPC_DSCR 0x105    /* Data Stream Control Register */
+#define NT_PPC_EBB 0x106     /* Event Based Branch Registers */
+#define NT_PPC_PMU 0x107     /* Performance Monitor Registers */
+#define NT_PPC_TM_CGPR 0x108 /* TM checkpointed GPR Registers */
+#define NT_PPC_TM_CFPR 0x109 /* TM checkpointed FPR Registers */
+#define NT_PPC_TM_CVMX 0x10a /* TM checkpointed VMX Registers */
+#define NT_PPC_TM_CVSX 0x10b /* TM checkpointed VSX Registers */
+#define NT_PPC_TM_SPR 0x10c  /* TM Special Purpose Registers */
+#define NT_PPC_TM_CTAR                      \
+    0x10d /* TM checkpointed Target Address \
+           * Register                       \
+           */
+#define NT_PPC_TM_CPPR                        \
+    0x10e /* TM checkpointed Program Priority \
+           * Register                         \
+           */
+#define NT_PPC_TM_CDSCR                          \
+    0x10f /* TM checkpointed Data Stream Control \
+           * Register                            \
+           */
+#define NT_PPC_PKEY                                         \
+    0x110                         /* Memory Protection Keys \
+                                   * registers.             \
+                                   */
+#define NT_386_TLS 0x200          /* i386 TLS slots (struct user_desc) */
+#define NT_386_IOPERM 0x201       /* x86 io permission bitmap (1=deny) */
+#define NT_X86_XSTATE 0x202       /* x86 extended state using xsave */
+#define NT_S390_HIGH_GPRS 0x300   /* s390 upper register halves */
+#define NT_S390_TIMER 0x301       /* s390 timer register */
+#define NT_S390_TODCMP 0x302      /* s390 TOD clock comparator register */
+#define NT_S390_TODPREG 0x303     /* s390 TOD programmable register */
+#define NT_S390_CTRS 0x304        /* s390 control registers */
+#define NT_S390_PREFIX 0x305      /* s390 prefix register */
+#define NT_S390_LAST_BREAK 0x306  /* s390 breaking event address */
+#define NT_S390_SYSTEM_CALL 0x307 /* s390 system call restart data */
+#define NT_S390_TDB 0x308         /* s390 transaction diagnostic block */
+#define NT_S390_VXRS_LOW                                      \
+    0x309                       /* s390 vector registers 0-15 \
+                                 * upper half.                \
+                                 */
+#define NT_S390_VXRS_HIGH 0x30a /* s390 vector registers 16-31.  */
+#define NT_S390_GS_CB 0x30b     /* s390 guarded storage registers.  */
+#define NT_S390_GS_BC                                        \
+    0x30c                        /* s390 guarded storage     \
+                                  * broadcast control block. \
+                                  */
+#define NT_S390_RI_CB 0x30d      /* s390 runtime instrumentation.  */
+#define NT_ARM_VFP 0x400         /* ARM VFP/NEON registers */
+#define NT_ARM_TLS 0x401         /* ARM TLS register */
+#define NT_ARM_HW_BREAK 0x402    /* ARM hardware breakpoint registers */
+#define NT_ARM_HW_WATCH 0x403    /* ARM hardware watchpoint registers */
+#define NT_ARM_SYSTEM_CALL 0x404 /* ARM system call number */
+#define NT_ARM_SVE                         \
+    0x405 /* ARM Scalable Vector Extension \
+           * registers                     \
+           */
+#define NT_ARM_PAC_MASK                 \
+    0x406 /* ARM pointer authentication \
+           * code masks.                \
+           */
+#define NT_ARM_PACA_KEYS                \
+    0x407 /* ARM pointer authentication \
+           * address keys.              \
+           */
+#define NT_ARM_PACG_KEYS                                    \
+    0x408                     /* ARM pointer authentication \
+                               * generic key.               \
+                               */
+#define NT_VMCOREDD 0x700     /* Vmcore Device Dump Note.  */
+#define NT_MIPS_DSP 0x800     /* MIPS DSP ASE registers.  */
+#define NT_MIPS_FP_MODE 0x801 /* MIPS floating-point mode.  */
+#define NT_MIPS_MSA 0x802     /* MIPS SIMD registers.  */
+
+/* Legal values for the note segment descriptor types for object files.  */
+
+#define NT_VERSION 1 /* Contains a version string.  */
+
+#endif /* __INCLUDE_ELF_H */

+ 161 - 0
core/iwasm/aot/debug/elf32.h

@@ -0,0 +1,161 @@
+/****************************************************************************
+ * include/elf32.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you 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.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_ELF32_H
+#define __INCLUDE_ELF32_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdint.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define ELF32_ST_BIND(i) ((i) >> 4)
+#define ELF32_ST_TYPE(i) ((i)&0xf)
+#define ELF32_ST_INFO(b, t) (((b) << 4) | ((t)&0xf))
+
+/* Definitions for Elf32_Rel*::r_info */
+
+#define ELF32_R_SYM(i) ((i) >> 8)
+#define ELF32_R_TYPE(i) ((i)&0xff)
+#define ELF32_R_INFO(s, t) (((s) << 8) | ((t)&0xff))
+
+#if 0
+#define ELF_R_SYM(i) ELF32_R_SYM(i)
+#endif
+
+/****************************************************************************
+ * Public Type Definitions
+ ****************************************************************************/
+
+/* Figure 4.2: 32-Bit Data Types */
+
+typedef uint32_t Elf32_Addr; /* Unsigned program address */
+typedef uint16_t Elf32_Half; /* Unsigned medium integer */
+typedef uint32_t Elf32_Off;  /* Unsigned file offset */
+typedef int32_t Elf32_Sword; /* Signed large integer */
+typedef uint32_t Elf32_Word; /* Unsigned large integer */
+
+/* Figure 4-3: ELF Header */
+
+typedef struct {
+    unsigned char e_ident[EI_NIDENT];
+    Elf32_Half e_type;
+    Elf32_Half e_machine;
+    Elf32_Word e_version;
+    Elf32_Addr e_entry;
+    Elf32_Off e_phoff;
+    Elf32_Off e_shoff;
+    Elf32_Word e_flags;
+    Elf32_Half e_ehsize;
+    Elf32_Half e_phentsize;
+    Elf32_Half e_phnum;
+    Elf32_Half e_shentsize;
+    Elf32_Half e_shnum;
+    Elf32_Half e_shstrndx;
+} Elf32_Ehdr;
+
+/* Figure 4-8: Section Header */
+
+typedef struct {
+    Elf32_Word sh_name;
+    Elf32_Word sh_type;
+    Elf32_Word sh_flags;
+    Elf32_Addr sh_addr;
+    Elf32_Off sh_offset;
+    Elf32_Word sh_size;
+    Elf32_Word sh_link;
+    Elf32_Word sh_info;
+    Elf32_Word sh_addralign;
+    Elf32_Word sh_entsize;
+} Elf32_Shdr;
+
+/* Figure 4-15: Symbol Table Entry */
+
+typedef struct {
+    Elf32_Word st_name;
+    Elf32_Addr st_value;
+    Elf32_Word st_size;
+    unsigned char st_info;
+    unsigned char st_other;
+    Elf32_Half st_shndx;
+} Elf32_Sym;
+
+/* Figure 4-19: Relocation Entries */
+
+typedef struct {
+    Elf32_Addr r_offset;
+    Elf32_Word r_info;
+} Elf32_Rel;
+
+typedef struct {
+    Elf32_Addr r_offset;
+    Elf32_Word r_info;
+    Elf32_Sword r_addend;
+} Elf32_Rela;
+
+/* Figure 5-1: Program Header */
+
+typedef struct {
+    Elf32_Word p_type;
+    Elf32_Off p_offset;
+    Elf32_Addr p_vaddr;
+    Elf32_Addr p_paddr;
+    Elf32_Word p_filesz;
+    Elf32_Word p_memsz;
+    Elf32_Word p_flags;
+    Elf32_Word p_align;
+} Elf32_Phdr;
+
+/* Figure 5-7: Note Information */
+
+typedef struct {
+    Elf32_Word n_namesz; /* Length of the note's name.  */
+    Elf32_Word n_descsz; /* Length of the note's descriptor.  */
+    Elf32_Word n_type;   /* Type of the note.  */
+} Elf32_Nhdr;
+
+/* Figure 5-9: Dynamic Structure */
+
+typedef struct {
+    Elf32_Sword d_tag;
+    union {
+        Elf32_Word d_val;
+        Elf32_Addr d_ptr;
+    } d_un;
+} Elf32_Dyn;
+
+#if 0
+typedef Elf32_Addr  Elf_Addr;
+typedef Elf32_Ehdr  Elf_Ehdr;
+typedef Elf32_Rel   Elf_Rel;
+typedef Elf32_Rela  Elf_Rela;
+typedef Elf32_Nhdr  Elf_Nhdr;
+typedef Elf32_Phdr  Elf_Phdr;
+typedef Elf32_Sym   Elf_Sym;
+typedef Elf32_Shdr  Elf_Shdr;
+typedef Elf32_Word  Elf_Word;
+#endif
+
+#endif /* __INCLUDE_ELF32_H */

+ 161 - 0
core/iwasm/aot/debug/elf64.h

@@ -0,0 +1,161 @@
+/****************************************************************************
+ * include/elf64.h
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you 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.
+ *
+ ****************************************************************************/
+
+#ifndef __INCLUDE_ELF64_H
+#define __INCLUDE_ELF64_H
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <stdint.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* See ELF-64 Object File Format: Version 1.5 Draft 2 */
+
+/* Definitions for Elf64_Rel*::r_info */
+
+#define ELF64_R_SYM(i) ((i) >> 32)
+#define ELF64_R_TYPE(i) ((i)&0xffffffffL)
+#define ELF64_R_INFO(s, t) (((s) << 32) + ((t)&0xffffffffL))
+
+#if 0
+#define ELF_R_SYM(i) ELF64_R_SYM(i)
+#endif
+
+/****************************************************************************
+ * Public Type Definitions
+ ****************************************************************************/
+
+/* Table 1: ELF-64 Data Types */
+
+typedef uint64_t Elf64_Addr;  /* Unsigned program address */
+typedef uint64_t Elf64_Off;   /* Unsigned file offset */
+typedef uint16_t Elf64_Half;  /* Unsigned medium integer */
+typedef uint32_t Elf64_Word;  /* Unsigned long integer */
+typedef int32_t Elf64_Sword;  /* Signed integer */
+typedef uint64_t Elf64_Xword; /* Unsigned long integer */
+typedef int64_t Elf64_Sxword; /* Signed large integer */
+
+/* Figure 2: ELF-64 Header */
+
+typedef struct {
+    unsigned char e_ident[EI_NIDENT]; /* ELF identification */
+    Elf64_Half e_type;                /* Object file type */
+    Elf64_Half e_machine;             /* Machine type */
+    Elf64_Word e_version;             /* Object file version */
+    Elf64_Addr e_entry;               /* Entry point address */
+    Elf64_Off e_phoff;                /* Program header offset */
+    Elf64_Off e_shoff;                /* Section header offset */
+    Elf64_Word e_flags;               /* Processor-specific flags */
+    Elf64_Half e_ehsize;              /* ELF header size */
+    Elf64_Half e_phentsize;           /* Size of program header entry */
+    Elf64_Half e_phnum;               /* Number of program header entry */
+    Elf64_Half e_shentsize;           /* Size of section header entry */
+    Elf64_Half e_shnum;               /* Number of section header entries */
+    Elf64_Half e_shstrndx;            /* Section name string table index */
+} Elf64_Ehdr;
+
+/* Figure 3: ELF-64 Section Header */
+
+typedef struct {
+    Elf64_Word sh_name;       /* Section name */
+    Elf64_Word sh_type;       /* Section type */
+    Elf64_Xword sh_flags;     /* Section attributes */
+    Elf64_Addr sh_addr;       /* Virtual address in memory */
+    Elf64_Off sh_offset;      /* Offset in file */
+    Elf64_Xword sh_size;      /* Size of section */
+    Elf64_Word sh_link;       /* Link to other section */
+    Elf64_Word sh_info;       /* Miscellaneous information */
+    Elf64_Xword sh_addralign; /* Address alignment boundary */
+    Elf64_Xword sh_entsize;   /* Size of entries, if section has table */
+} Elf64_Shdr;
+
+/* Figure 4: ELF-64 Symbol Table Entry */
+
+typedef struct {
+    Elf64_Word st_name;     /* Symbol name */
+    unsigned char st_info;  /* Type and Binding attributes */
+    unsigned char st_other; /* Reserved */
+    Elf64_Half st_shndx;    /* Section table index */
+    Elf64_Addr st_value;    /* Symbol value */
+    Elf64_Xword st_size;    /* Size of object (e.g., common) */
+} Elf64_Sym;
+
+/* Figure 5: ELF-64 Relocation Entries */
+
+typedef struct {
+    Elf64_Addr r_offset; /* Address of reference */
+    Elf64_Xword r_info;  /* Symbol index and type of relocation */
+} Elf64_Rel;
+
+typedef struct {
+    Elf64_Addr r_offset;   /* Address of reference */
+    Elf64_Xword r_info;    /* Symbol index and type of relocation */
+    Elf64_Sxword r_addend; /* Constant part of expression */
+} Elf64_Rela;
+
+/* Figure 6: ELF-64 Program Header Table Entry */
+
+typedef struct {
+    Elf64_Word p_type;   /* Type of segment */
+    Elf64_Word p_flags;  /* Segment attributes */
+    Elf64_Off p_offset;  /* Offset in file */
+    Elf64_Addr p_vaddr;  /* Virtual address in memory */
+    Elf64_Addr p_paddr;  /* Reserved */
+    Elf64_Word p_filesz; /* Size of segment in file */
+    Elf64_Word p_memsz;  /* Size of segment in memory */
+    Elf64_Word p_align;  /* Alignment of segment */
+} Elf64_Phdr;
+
+/* Figure 7. Format of a Note Section */
+
+typedef struct {
+    Elf64_Word n_namesz; /* Length of the note's name.  */
+    Elf64_Word n_descsz; /* Length of the note's descriptor.  */
+    Elf64_Word n_type;   /* Type of the note.  */
+} Elf64_Nhdr;
+
+/* Figure 8: Dynamic Table Structure */
+
+typedef struct {
+    Elf64_Sxword d_tag;
+    union {
+        Elf64_Xword d_val;
+        Elf64_Addr d_ptr;
+    } d_un;
+} Elf64_Dyn;
+
+#if 0
+typedef Elf64_Addr  Elf_Addr;
+typedef Elf64_Ehdr  Elf_Ehdr;
+typedef Elf64_Rel   Elf_Rel;
+typedef Elf64_Rela  Elf_Rela;
+typedef Elf64_Nhdr  Elf_Nhdr;
+typedef Elf64_Phdr  Elf_Phdr;
+typedef Elf64_Sym   Elf_Sym;
+typedef Elf64_Shdr  Elf_Shdr;
+typedef Elf64_Word  Elf_Word;
+#endif
+
+#endif /* __INCLUDE_ELF64_H */

+ 1 - 1
core/iwasm/aot/debug/elf_parser.c

@@ -12,7 +12,7 @@
 #include <errno.h>
 #include <errno.h>
 #include <stdbool.h>
 #include <stdbool.h>
 
 
-#include <elf.h>
+#include "elf.h"
 
 
 #include "aot_runtime.h"
 #include "aot_runtime.h"
 #include "bh_log.h"
 #include "bh_log.h"