Commit Graph

122 Commits

Author SHA1 Message Date
YAMAMOTO Takashi
e596d5bd5e binfmt/libelf: Implement sh_addralign handling
Basically, mirror the following two commits from modlib.
It's shame we have two copies of elf loaders.

```
commit 51490bad55
Author: YAMAMOTO Takashi <yamamoto@midokura.com>
Date:   Wed Apr 14 17:07:39 2021 +0900

    modlib: Implement sh_addralign handling

    I've seen a module with 16 bytes .rodata alignment for xmm operations.
    It was getting SEGV on sim/Linux because of the alignment issue.
    The same module binary seems working fine after applying this patch.

    Also, tested on sim/macOS and esp32 on qemu,
    using a module with an artificially large alignment. (64 bytes)
```

```
commit 418e11b8b3
Author: YAMAMOTO Takashi <yamamoto@midokura.com>
Date:   Thu Apr 15 11:33:48 2021 +0900

    modlib: Always use separate allocation for text and data

    Pros:

    * Reduce code differences
    * Smaller allocations for !CONFIG_ARCH_USE_MODULE_TEXT

    Cons:

    * Likely to use more memory for !CONFIG_ARCH_USE_MODULE_TEXT in total

    Tested with:

    * sim:module on macOS
    * esp32-devkit:nsh + CONFIG_MODULE on qemu
    * lm3s6965-ek:qemu-protected + CONFIG_EXAMPLES_SOTEST on qemu
```
2022-01-28 16:23:23 +08:00
Xiang Xiao
f903a55102 sched/tcbinfo: Fix the compile warning
Update tcbinfo struct

armv8-m/arm_tcbinfo.c:109:3: warning: excess elements in struct initializer
  109 |   TCB_REG_OFF(REG_S31),
      |   ^~~~~~~~~~~
armv8-m/arm_tcbinfo.c:109:3: note: (near initialization for 'g_tcbinfo')
armv8-m/arm_tcbinfo.c:110:3: warning: excess elements in struct initializer
  110 |   0,
      |   ^
armv8-m/arm_tcbinfo.c:110:3: note: (near initialization for 'g_tcbinfo')
armv8-m/arm_tcbinfo.c:111:3: warning: excess elements in struct initializer
  111 |   TCB_REG_OFF(REG_FPSCR),
      |   ^~~~~~~~~~~
armv8-m/arm_tcbinfo.c:111:3: note: (near initialization for 'g_tcbinfo')
armv8-m/arm_tcbinfo.c:112:3: warning: excess elements in struct initializer
  112 |   0,
      |   ^
armv8-m/arm_tcbinfo.c:112:3: note: (near initialization for 'g_tcbinfo')
armv8-m/arm_tcbinfo.c:37:1: warning: missing braces around initializer [-Wmissing-braces]
   37 | {

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Signed-off-by: zhuyanlin <zhuyanlin1@xiaomi.com>
2022-01-27 17:36:27 +08:00
chao.an
47f9ec9c45 binfmt/coredump: remove the block fragmentation
Hide the segmentation details to backend implementation

Signed-off-by: chao.an <anchao@xiaomi.com>
2022-01-14 23:07:05 +08:00
chao.an
7cbb8da692 binfmt/elf: add bare metal coredump support
Signed-off-by: chao.an <anchao@xiaomi.com>
2021-11-23 20:48:00 -06:00
Xiang Xiao
9e60c33d4d binfmt: Remove umm_initialize from elf_load
since umm_try_initialize will do it automatically

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-10-18 22:51:18 -03:00
chao.an
5ff4e33e3f binfmt/Makefile: remove the specified prefix from target variables
Signed-off-by: chao.an <anchao@xiaomi.com>
2021-10-19 00:35:35 +02:00
Xiang Xiao
841a4922aa binfmt: Replace all nx_ API with file_ API
since binfmt is a kernel component

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-07-06 11:18:13 +09:00
Abdelatif Guettouche
af5e0c620f Rename MODULE_TEXT to TEXT_HEAP as the latter is more generic.
Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
2021-06-18 07:14:17 -05:00
Masayuki Ishikawa
4d492104a7 binfmt: Introduce a separate text memory for ELF
Summary:
- This commit introduces a separate text memory for ELF
- The logic is similar to modlib

Impact:
- None

Testing:
- Tested with spresense:elf
- NOTE: needs separate commits

Signed-off-by: Masayuki Ishikawa <Masayuki.Ishikawa@jp.sony.com>
2021-06-02 02:27:04 -05:00
Alexander Lunev
4018cc186c libelf: fix "nsh: nsh_session: readline failed: 13" error
Resolves issue #3751
2021-05-21 02:12:31 -07:00
Xiang Xiao
85c1354043 binfmt/elf: Don't close filfd in the fail path
to avoid close the same handle twice because
the caller also call elf_uninit in this case

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: Iddcbae9587d11d3b5b06e876d4a037ac0d11992e
2021-05-12 21:09:29 -07:00
Byron Ellacott
c9db653c8d symtabs: improve handling of symbol lookups
When CONFIG_SYMTAB_ORDEREDBYNAME is selected most code will use
the ordered search function. When it is not selected no code will
use the ordered search function. This change merges the two
functions and varies its behaviour based on the config setting,
such that all callers can simply call the one search function
and get the best behaviour.

An additional configuration option allows leading underscores to
be stripped from symbols being relocated in loaded objects. This
allows toolchains which prefix C symbol with underscores to make
loadable ELF objects.
2021-03-16 10:18:17 -07:00
Abdelatif Guettouche
d85c432278 Few typos fixes in binfmt and libc/machine.
Signed-off-by: Abdelatif Guettouche <abdelatif.guettouche@espressif.com>
2021-03-11 10:35:40 +08:00
Gustavo Henrique Nihei
330eff36d7 sourcefiles: Fix relative path in file header 2021-03-09 23:18:28 +08:00
Alin Jerpelea
f9fb182809 Author: Gregory Nutt: update licenses to Apache
Update files from Gregory Nutt to Apache 2.0 license.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2021-02-05 12:15:56 -03:00
Xiang Xiao
0536953ded Kernel module should prefer functions with nx/kmm prefix
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2021-01-13 08:57:58 +01:00
YAMAMOTO Takashi
85f38b01c1 binfmt/libelf/libelf_dtors.c: Fix a syslog format 2020-11-27 05:18:57 -06:00
YAMAMOTO Takashi
44e61d7fe7 binfmt/libelf/libelf_ctors.c: Fix a syslog format 2020-11-27 05:18:57 -06:00
YAMAMOTO Takashi
d068713738 binfmt/libelf/libelf_symbols.c: Fix syslog formats 2020-11-21 19:38:32 -08:00
YAMAMOTO Takashi
148ee150f0 binfmt/libelf/libelf_bind.c: Fix syslog formats 2020-11-21 19:38:32 -08:00
Xiang Xiao
2b7528feae binfmt: Fix warning: unused variable ‘exidx’
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: I55d3355813b8b24727e2a7f78fcd72622a1e6758
2020-07-21 00:03:47 -07:00
Xiang Xiao
fbfd9d62da libelf: Parse .ARM.exidx only for ARM architecture
since other arch has the different unwind approach

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
Change-Id: Icefa0d4bc31bff967372949216d337770cd7e768
2020-07-11 10:34:22 -07:00
Alin Jerpelea
7ddf7c6c25 binfmt: nxstyle fixes
small nxstyle fixes for binfmt to avoid CI warnings

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2020-04-22 14:07:04 -06:00
YAMAMOTO Takashi
24c9fa3cd9 Kconfig: Move ELF_64BIT out of !BINFMT_DISABLE
Because it's also used by LIBC_MODLIB.
2020-03-27 00:04:36 -05:00
YAMAMOTO Takashi
bb09d564db libelf: Don't truncate 64-bit values 2020-03-27 00:04:36 -05:00
YAMAMOTO Takashi
f8077022bd Introduce CONFIG_DEFAULT_TASK_STACKSIZE
* The appropriate size of stack varies among archs.
  E.g. for 64-bit sim, 2048 is way too small, especially when the task
  happens to use host OS functionalities.
  I plan to allow an arch provide its own default.

* I plan to use this to replace hardcoded "STACKSIZE = 2048" in APPDIR.
2020-03-26 22:30:13 -05:00
YAMAMOTO Takashi
8ad9d1e0b4 libelf: Appease nxstyle complaints
Also, fix a minor typo.
2020-03-26 02:51:34 -05:00
Xiang Xiao
cde88cabcc Run codespell -w with the latest dictonary again
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2020-02-23 22:27:46 +01:00
Xiang Xiao
bd4e8e19d3 Run codespell -w against all files
and fix the wrong correction
2020-02-22 14:45:07 -06:00
Masayuki Ishikawa
81f1133174 ELF64 support (#220)
* include: Introduce elf64.h and elf.h

    Added elf64.h for 64bit ELF support and moved common definitions
    from elf32.h to elf.h. Also introduced Elf_xxx to be used in
    common libraries such as binfmt.

  * binfmt, include, modlib, module: Add support for ELF64

    Elf_xxx must be used instead of Elf32_xxx to support ELF64.
    To use ELF64, CONFIG_ELF_64BIT must be enabled.

  * binfmt, modlib: Add support for relocate address

  * arch: risc-v: Add include/elf.h

  * libs: machine: Add risc-v related files.

    NOTE: Currently only supports ELF64

  * boards: maix-bit: Add elf and posix_spawn configurations

  * boards: maix-bit: Add support for module configuration
2020-02-07 17:10:23 -06:00
Xiang Xiao
68951e8d72 Remove exra whitespace from files (#189)
* Remove multiple newlines at the end of files
* Remove the whitespace from the end of lines
2020-01-31 09:24:49 -06:00
Xiang Xiao
f8bcd58be2 Fix format warn (#96)
* fix warning: format '%x' expects argument of type 'unsigned int', but argument 4 has type 'long unsigned int'
* fix warning: implicit declaration of function 'up_init_exidx'
2020-01-13 16:41:09 -06:00
Gregory Nutt
dd5748cee8 binfmt/: Update copyright dates in all modified files. 2020-01-11 13:44:58 -03:00
Gregory Nutt
7a72d1e8ca binfmt/: Run all .c files under binfmt/ through tools/nxstyle and fix all resulting complaints. 2020-01-11 13:44:58 -03:00
Gregory Nutt
9d5d60fee1 Run all .c and .h files in last PR49 through nxstyle. 2020-01-07 09:54:35 -06:00
Alin Jerpelea
a8d63c0cec various fixes (#49)
* libs: libc: math: Fix tanh() math functions
* drivers: mtd: smart: Fix trivial debug message in smartfs
* binfmt: libelf: Fix fd not closed on error
* binfmt: Fix stack memory leak on error
* fs: romfs: Fix private data not free on error
* sched: group: Fix reference after free memory
* sched: clock: Fix clock sync

Fix clock sync when CONFIG_RTC_HIRES is enabled
2020-01-07 09:06:02 -06:00
Xiang Xiao
6a3c2aded6 Fix wait loop and void cast (#24)
* Simplify EINTR/ECANCEL error handling

1. Add semaphore uninterruptible wait function
2 .Replace semaphore wait loop with a single uninterruptible wait
3. Replace all sem_xxx to nxsem_xxx

* Unify the void cast usage

1. Remove void cast for function because many place ignore the returned value witout cast
2. Replace void cast for variable with UNUSED macro
2020-01-02 10:54:43 -06:00
Gregory Nutt
2925c28f8f All linker scripts: Preface all _edata defininitions with . = ALIGN(4). Otherwise, the last bytes in the .data section may not be initialized properly. Also convert all linker scripts indent in units of 8-spaces to units of 4-spaces. 2019-09-15 17:22:16 -06:00
Gregory Nutt
da1a561b6e binfmt/libelf/libelf_bind.c: Make naming of internal type compliant with coding standard. Yes, the ELF32 types do not follow the standard for historical reasons (and will be fixed someday), but let's not perpetuate the naming violation. 2019-03-20 09:34:08 -06:00
Xiang Xiao
64252a298f arch/: Unify the cache interface for all architectures 2019-03-19 10:37:13 -06:00
anchao
6e69dba341 binfmt/libelf/ and libs/libc/modlib: Add symbol buffer table to reduce filesystem access. 2019-03-19 09:13:50 -06:00
anchao
2f2d432f7c binfmt/libelf and libs/libc/modlib: Add relocation buffer table to reduce access fs. 2019-03-19 08:57:13 -06:00
Gregory Nutt
c17145e550 Revert "binfmt/libelf/libelf_load.c: Remove the guard(CONFIG_BUILD_KERNEL) for umm_initialize()"
This commit has to be reverted because it causes errors in build testing.

This reverts commit b9c7a9a18f.
2019-02-03 18:08:46 -06:00
Xiang Xiao
b9c7a9a18f binfmt/libelf/libelf_load.c: Remove the guard(CONFIG_BUILD_KERNEL) for umm_initialize() 2019-01-28 06:19:48 -06:00
Gregory Nutt
78c8485b0d Fix some warnings found in build testing. 2019-01-27 17:23:01 -06:00
Xiang Xiao
b7f958a02e binfmt/, binfmt/libelf: binfmt/elf: Call umm_initialize as soon as possible otherwise elf_loadctors/elf_loaddtors will fail to allocate memory. 2019-01-26 11:36:38 -06:00
Xiang Xiao
0edcd6b85e binfmt/libelf, libs/libc/modlib: Optimize elf load speed: (1) Don't zero out memory, (2) Reduce the initial buffer size to 32 bytes. 2019-01-26 11:34:40 -06:00
Xiang Xiao
264a7164bc binfmt/: If there is an address environment (CONFIG_ARCH_ADDRENV), binfmt/elf doesn't need to free ctor/dtor alloc since freeing the address environment releases the heap automatically. 2019-01-26 11:29:08 -06:00
Xiang Xiao
38ffb98f1b Kconfig files, binfmt/libelf, libs/libc/machin, libs/libxx: Correct libcxx exception handling by introducing the generic config(CXX_EXCEPTION and CXX_LIBSUPCXX) 2019-01-26 11:23:31 -06:00
Xiang Xiao
095e28d45e binfmt/, binfmt/libelf/, include/nuttx, libs/libc/machine, libs/libc/modlib, and others: Move elf related arch function to include/nuttx/elf.h because the implementation is located in libs/libc/machine and in order to avoid the conflict with the 3rd party libraries and clean up the file inclusion: (1) Remove redundant elf32.h, (2) Remove nuttx/binfmt/elf.h in libs/libc/machine, (2) Remove nuttx/binfmt/elf.h in modlib, and (4) Rmove nuttx/module.h in modlib. 2019-01-26 11:18:45 -06:00