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

[BUG] Issue and regression with libcxx #13497

Open
1 task done
g2gps opened this issue Sep 17, 2024 · 2 comments
Open
1 task done

[BUG] Issue and regression with libcxx #13497

g2gps opened this issue Sep 17, 2024 · 2 comments
Labels
Arch: risc-v Issues related to the RISC-V (32-bit or 64-bit) architecture Area: OS Components OS Components issues OS: Linux Issues related to Linux (building system, etc) Type: Bug Something isn't working

Comments

@g2gps
Copy link
Contributor

g2gps commented Sep 17, 2024

Description / Steps to reproduce the issue

I've identified a couple of issues when using LLVM libcxx and userspace applications. This is reproducible on rv-virt:knsh with the addition of:

CONFIG_HAVE_CXX=y
CONFIG_EXAMPLES_HELLOXX=m
CONFIG_HAVE_CXX=y
CONFIG_LIBCXX=y
CONFIG_TLS_NELEM=4

The first issue is that the static constructor isn't called. For example, when running the helloxx application:

nsh> helloxx
[68719476736000.001000] CHelloWorld: Constructor: mSecret=42
helloxx_main: Saying hello from the dynamically constructed instance
[77309411328000.001000] HelloWorld: HelloWorld: mSecret=42
CHelloWorld::HelloWorld: Hello, World!!
[77309411328000.001000] CHelloWorld: Constructor: mSecret=42
helloxx_main: Saying hello from the instance constructed on the stack
[77309411328000.001000] HelloWorld: HelloWorld: mSecret=42
CHelloWorld::HelloWorld: Hello, World!!
helloxx_main: Saying hello from the statically constructed instance
[81604378624000.001000] HelloWorld: HelloWorld: mSecret=0
CHelloWorld::HelloWorld: CONSTRUCTION FAILED!
[81604378624000.001000] ~CHelloWorld: Destructor
[85899345920000.001000] ~CHelloWorld: Destructor

However, if I change the cxx standard version to CONFIG_CXX_STANDARD="c++2b", the static construct is called:

nsh> helloxx
[914828034048000.001000] CHelloWorld: Constructor: mSecret=42
[923417968640000.001000] CHelloWorld: Constructor: mSecret=42
helloxx_main: Saying hello from the dynamically constructed instance
[923417968640000.001000] HelloWorld: HelloWorld: mSecret=42
CHelloWorld::HelloWorld: Hello, World!!
[927712935936000.001000] CHelloWorld: Constructor: mSecret=42
helloxx_main: Saying hello from the instance constructed on the stack
[927712935936000.001000] HelloWorld: HelloWorld: mSecret=42
CHelloWorld::HelloWorld: Hello, World!!
helloxx_main: Saying hello from the statically constructed instance
[932007903232000.001000] HelloWorld: HelloWorld: mSecret=42
CHelloWorld::HelloWorld: Hello, World!!
[932007903232000.001000] ~CHelloWorld: Destructor
[936302870528000.001000] ~CHelloWorld: Destructor

The second issue seems to be a regression with #13110, in which exceptions are always enabled for libcxx, after this change, running any c++ application results in an IPC:

nsh> helloxx
[    2.271000] riscv_exception: EXCEPTION: Instruction page fault. MCAUSE: 0000000c, EPC: 018c0000, MTVAL: 018c0000
[    2.271000] riscv_exception: Segmentation fault in PID 3: helloxx

This is only an issue when static constructors are called, (so enabling c++2b in this example). Reverting #13110 seems to fix this behaviour.

Running addr2line on the faulting instruction yields to results. My assumption is that there is an additional static constructor called for exception support, and this is what is causing the issue. However, I don't know enough about these layers to be sure.

Enabling CONFIG_CXX_EXCEPTION doesn't resolve the issue.

Possibly a reasonable solution to the second issue would be to revert the change which removed the CONFIG_CXX_EXCEPTION change from the libcxx build and let targets which need the library build with exception support add this option in the defconfigs?

On which OS does this issue occur?

[Linux]

What is the version of your OS?

Ubuntu 22.04 (Docker)

NuttX Version

NuttX 12.6.0-RC1 f5b50be05e Sep 17 2024 05:07:45 risc-v rv-virt

Issue Architecture

[risc-v]

Issue Area

[OS Components]

Verification

  • I have verified before submitting the report.
@g2gps g2gps added the Type: Bug Something isn't working label Sep 17, 2024
@github-actions github-actions bot added OS: Linux Issues related to Linux (building system, etc) Area: OS Components OS Components issues Arch: risc-v Issues related to the RISC-V (32-bit or 64-bit) architecture labels Sep 17, 2024
@xiaoxiang781216
Copy link
Contributor

@g2gps only kernel mode has this problem?

@g2gps
Copy link
Contributor Author

g2gps commented Sep 19, 2024

@g2gps only kernel mode has this problem?

Yes, it seems to be just kernel mode. It works with rv-virt:libcxx using c++2b and gnu++20.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Arch: risc-v Issues related to the RISC-V (32-bit or 64-bit) architecture Area: OS Components OS Components issues OS: Linux Issues related to Linux (building system, etc) Type: Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants