Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unify the code of libelf and modlib, and delete the implementation of libelf #14100

Merged
merged 20 commits into from
Oct 12, 2024

Conversation

anjiahao1
Copy link
Contributor

Summary

Move the special usage of libelf to modlib, enhance and fix bugs in modlib, and then remove the libelf implementation. This will allow us to better reuse the code for dynamic loading

Impact

Dynamic loading/kernal mode

Testing

run rv-virt:knsh and pass ostest

@github-actions github-actions bot added Area: Documentation Improvements or additions to documentation Area: Tooling Arch: arm Issues related to ARM (32-bit) architecture Arch: arm64 Issues related to ARM64 (64-bit) architecture Arch: avr Issues related to all AVR(8-bit or 32-bit) architectures Arch: ceva Issues related to CEVA architecture Arch: mips Issues related to the MIPS architecture Arch: openrisc Issues related to the OpenRISC architecture Arch: risc-v Issues related to the RISC-V (32-bit or 64-bit) architecture Arch: sparc Issues related to the SPARC architecture Arch: x86 Issues related to the x86 architecture Arch: x86_64 Issues related to the x86_64 architecture Arch: xtensa Issues related to the Xtensa architecture Arch: z16 Issues related to the Z16 architecture Arch: z80 Issues related to the Z80 architecture Area: OS Components OS Components issues Area: BINFMT Board: arm Board: risc-v Board: simulator Board: sparc Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces. labels Oct 11, 2024
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

anjiahao1 and others added 8 commits October 11, 2024 20:56
this commit is part two, all logic move to modlib, so we can remove it.
and change all use defconfig

Signed-off-by: anjiahao <[email protected]>
if modp is NULL, we can use export and nexport load externl symbol

Signed-off-by: anjiahao <[email protected]>
undefine lib_free

Signed-off-by: anjiahao <[email protected]>
Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@anjiahao1
Copy link
Contributor Author

depends on app 2696

Copy link

This PR exceeds the recommended size of 1000 lines. Please make sure you are NOT addressing multiple issues with one PR. Note this PR might be rejected due to its size.

@xiaoxiang781216 xiaoxiang781216 merged commit b503b32 into apache:master Oct 12, 2024
37 checks passed
@masayuki2009
Copy link
Contributor

@anjiahao1

I noticed that getprime crashes with rv-virt:knsh after merging this PR.

/home/ishikawa/opensource/QEMU/qemu-9.0.0/build/qemu-system-riscv32 -semihosting -nographic -cpu rv32 -M virt,aclint=on -kernel nuttx

OpenSBI v1.4
   ____                    _____ ____ _____
  / __ \                  / ____|  _ \_   _|
 | |  | |_ __   ___ _ __ | (___ | |_) || |
 | |  | | '_ \ / _ \ '_ \ \___ \|  _ < | |
 | |__| | |_) |  __/ | | |____) | |_) || |_
  \____/| .__/ \___|_| |_|_____/|____/_____|
        | |
        |_|

Platform Name             : riscv-virtio,qemu
Platform Features         : medeleg
Platform HART Count       : 1
Platform IPI Device       : aclint-mswi
Platform Timer Device     : aclint-mtimer @ 10000000Hz
Platform Console Device   : semihosting
Platform HSM Device       : ---
Platform PMU Device       : ---
Platform Reboot Device    : syscon-reboot
Platform Shutdown Device  : syscon-poweroff
Platform Suspend Device   : ---
Platform CPPC Device      : ---
Firmware Base             : 0x80000000
Firmware Size             : 319 KB
Firmware RW Offset        : 0x40000
Firmware RW Size          : 63 KB
Firmware Heap Offset      : 0x47000
Firmware Heap Size        : 35 KB (total), 2 KB (reserved), 9 KB (used), 24 KB (free)
Firmware Scratch Size     : 4096 B (total), 184 B (used), 3912 B (free)
Runtime SBI Version       : 2.0

Domain0 Name              : root
Domain0 Boot HART         : 0
Domain0 HARTs             : 0*
Domain0 Region00          : 0x00100000-0x00100fff M: (I,R,W) S/U: (R,W)
Domain0 Region01          : 0x02000000-0x0200ffff M: (I,R,W) S/U: ()
Domain0 Region02          : 0x80040000-0x8004ffff M: (R,W) S/U: ()
Domain0 Region03          : 0x80000000-0x8003ffff M: (R,X) S/U: ()
Domain0 Region04          : 0x0c400000-0x0c5fffff M: (I,R,W) S/U: (R,W)
Domain0 Region05          : 0x0c000000-0x0c3fffff M: (I,R,W) S/U: (R,W)
Domain0 Region06          : 0x00000000-0xffffffff M: () S/U: (R,W,X)
Domain0 Next Address      : 0x80200000
Domain0 Next Arg1         : 0x87e00000
Domain0 Next Mode         : S-mode
Domain0 SysReset          : yes
Domain0 SysSuspend        : yes

Boot HART ID              : 0
Boot HART Domain          : root
Boot HART Priv Version    : v1.12
Boot HART Base ISA        : rv32imafdch
Boot HART ISA Extensions  : sstc,zicntr,zihpm,zicboz,zicbom
Boot HART PMP Count       : 16
Boot HART PMP Granularity : 2 bits
Boot HART PMP Address Bits: 32
Boot HART MHPM Info       : 16 (0x0007fff8)
Boot HART MIDELEG         : 0x00001666
Boot HART MEDELEG         : 0x00f0b509
ABC
NuttShell (NSH) NuttX-12.0.0
nsh> uname -a
NuttX 12.0.0 b503b323ce Oct 12 2024 15:55:50 risc-v rv-virt
nsh> ps
  PID GROUP PRI POLICY   TYPE    NPX STATE    EVENT     SIGMASK           STACK COMMAND
    0     0   0 FIFO     Kthread   - Ready              0000000000000000 0003056 Idle_Task
    1     0 100 RR       Kthread   - Waiting  Semaphore 0000000000000000 0001984 lpwork 0x80600010 0x80600034
    2     2 100 RR       Task      - Running            0000000000000000 0003024 /system/bin/init
nsh> free
      total       used       free    maxused    maxfree  nused  nfree name
    4164028      17236    4146792     716368    3448016    343      5 Kmem
    4194304     606208    3588096    3588096 Page
nsh> hello
Hello, World!!
nsh> getprime
[1846835937280000.001000] dump_assert_info: Current Version: NuttX  12.0.0 b503b323ce Oct 12 2024 15:55:48 risc-v
[1846835937280000.001000] dump_assert_info: Assertion failed : at file: misc/lib_envpath.c:167 task: /system/bin/init process: /system/bin/init 0xc000001a
[1846835937280000.001000] up_dump_register: EPC: 802129ae
[1846835937280000.001000] up_dump_register: A0: 80606780 A1: 000000a7 A2: 00000000 A3: 00000000
[1846835937280000.001000] up_dump_register: A4: 00000002 A5: 00000000 A6: ffffffff A7: 00000001
[1846835937280000.001000] up_dump_register: T0: 00000000 T1: ffff0000 T2: 00000000 T3: 00000000
[1846835937280000.001000] up_dump_register: T4: 00030001 T5: c0802a54 T6: 00000000
[1846835937280000.001000] up_dump_register: S0: 80606000 S1: 00000000 S2: 00000000 S3: 00042022
[1846835937280000.001000] up_dump_register: S4: 80607000 S5: 00000006 S6: 80607000 S7: 8021ad94
[1846835937280000.001000] up_dump_register: S8: 000000a7 S9: 80608808 S10: c000e000 S11: 00000000
[1846835937280000.001000] up_dump_register: SP: 80609254 FP: 80606000 TP: 80608808 RA: 802129ae

@lupyuen
Copy link
Member

lupyuen commented Oct 13, 2024

Sorry @anjiahao1 I'm also having problems with knsh64: https://gist.github.com/lupyuen/5bfa7af7e2927e7fd1ba7b65e8c405e5

$ git reset --hard 56aa628eeca4d96d80eba21a90656f17f771a451
HEAD is now at 56aa628eec binfmt_loadmodule.c:fix build break
...
$ qemu-system-riscv64 -semihosting -M virt,aclint=on -cpu rv64 -kernel nuttx -nographic
QEMU emulator version 9.0.2
OpenSBI v1.4
ABC
dump_assert_info: Current Version: NuttX  12.7.0-RC0 56aa628eec Oct 13 2024 13:07:08 risc-v
dump_assert_info: Assertion failed : at file: init/nx_bringup.c:381 task: Idle_Task process: Kernel 0x80200fda

The previous commit works OK: https://gist.github.com/lupyuen/c6a32aab4ba186c53ffc4c1150541a8b

Any idea why this is failing? Thanks!

@xiaoxiang781216
Copy link
Contributor

@anjiahao1 please take a look.

@anjiahao1
Copy link
Contributor Author

Ok, I will fix this problem today.

@anjiahao1
Copy link
Contributor Author

#14205 @lupyuen @masayuki2009 hello, this pr fix it

@tmedicci
Copy link
Contributor

Hi @anjiahao1 , we are facing problems on ESP32-S3 caused by this PR too I created an issue #14487 Could you please take a look?

@tmedicci
Copy link
Contributor

Hi @anjiahao1 , we are facing problems on ESP32-S3 caused by this PR too I created an issue #14487 Could you please take a look?

Hi @anjiahao1 , did you see this too?

@anjiahao1
Copy link
Contributor Author

Hi @anjiahao1 , we are facing problems on ESP32-S3 caused by this PR too I created an issue #14487 Could you please take a look?

Hi @anjiahao1 , did you see this too?

Sorry, I have some things to deal with during the week. I will fix this problem on Friday.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arch: arm Issues related to ARM (32-bit) architecture Arch: arm64 Issues related to ARM64 (64-bit) architecture Arch: avr Issues related to all AVR(8-bit or 32-bit) architectures Arch: ceva Issues related to CEVA architecture Arch: mips Issues related to the MIPS architecture Arch: openrisc Issues related to the OpenRISC architecture Arch: risc-v Issues related to the RISC-V (32-bit or 64-bit) architecture Arch: sparc Issues related to the SPARC architecture Arch: x86 Issues related to the x86 architecture Arch: x86_64 Issues related to the x86_64 architecture Arch: xtensa Issues related to the Xtensa architecture Arch: z16 Issues related to the Z16 architecture Arch: z80 Issues related to the Z80 architecture Area: BINFMT Area: Documentation Improvements or additions to documentation Area: OS Components OS Components issues Area: Tooling Board: arm Board: risc-v Board: simulator Board: sparc Size: XL The size of the change in this PR is very large. Consider breaking down the PR into smaller pieces.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants