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

Fix C++ exception handling on NIOS2 #35790

Merged
merged 3 commits into from
May 28, 2021

Conversation

stephanosio
Copy link
Member

Summary

nios2: Fix C++ exception handling info linking

The NIOS2 architecture linker script was including `cplusplus-ram.ld`
linker script after `__data_ram_end`, and this caused the content of
`.gcc_except_table` section to be not copied to the RAM by the
`z_data_copy` function; leading to the C++ exception handling
malfunction.

This commit relocates the `cplusplus-ram.ld` linker script inclusion
such that the contents of the relevant sections are properly copied by
the `z_data_copy` function.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>

Test Result

[110/111] Linking CXX executable zephyr/zephyr.elf
Memory region         Used Size  Region Size  %age Used
           RESET:          0 GB         32 B      0.00%
           FLASH:      158544 B   16777184 B      0.94%
            SRAM:       10824 B   16777184 B      0.06%
        IDT_LIST:          0 GB         2 KB      0.00%
[110/111] To exit from QEMU enter: 'CTRL+a, x'[QEMU] CPU: nios2
        cpu->env.reset_addr:            0
        cpu->env.exception_addr:        400020
*** Booting Zephyr OS build v2.6.0-rc2-57-g053ff6fa0e72  ***
version 201703
Running test suite libcxx_tests
===================================================================
START - test_array
 PASS - test_array in 0.0 seconds
===================================================================
START - test_vector
 PASS - test_vector in 0.0 seconds
===================================================================
START - test_make_unique
 PASS - test_make_unique in 0.0 seconds
===================================================================
START - test_exception
 PASS - test_exception in 0.0 seconds
===================================================================
Test suite libcxx_tests succeeded
===================================================================
PROJECT EXECUTION SUCCESSFUL

Note that, in order to test this in qemu_nios2, you must do so with a patched QEMU: see #35772 (comment).

Fixes #35772.

The NIOS2 architecture linker script was including `cplusplus-ram.ld`
linker script after `__data_ram_end`, and this caused the content of
`.gcc_except_table` section to be not copied to the RAM by the
`z_data_copy` function; leading to the C++ exception handling
malfunction.

This commit relocates the `cplusplus-ram.ld` linker script inclusion
such that the contents of the relevant sections are properly copied by
the `z_data_copy` function.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
The C++ exception handling feature is now supported on all
architectures.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
The C++ exception handling feature is now supported on all
architectures.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
@github-actions github-actions bot added area: API Changes to public APIs area: NIOS2 NIOS2 Architecture area: Tests Issues related to a particular existing or missing test labels May 28, 2021
@stephanosio stephanosio added area: C++ area: Linker Scripts bug The issue is a bug, or the PR is fixing a bug priority: medium Medium impact/importance bug and removed area: API Changes to public APIs labels May 28, 2021
@stephanosio stephanosio added this to the v2.6.0 milestone May 28, 2021
@@ -9,7 +9,6 @@ tests:
min_flash: 54
tags: cpp
cpp.libcxx.exceptions:
arch_exclude: nios2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we probably need to platform_exclude: qemu_nios2 here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the time being, twister automatically skips any tests with FLASH overflow and treats it as a non-failure. Also, If we ever manage to slim down Zephyr such that it can fit into the current 128KB flash, it will pass anyway.

stephanos@devworx1:~/Dev/zephyrproject/zephyr$ scripts/twister -v -N -s tests/subsys/cpp/libcxx/cpp.libcxx.exceptions -p qemu_nios2
ZEPHYR_BASE unset, using "/home/stephanos/Dev/zephyrproject/zephyr"
Renaming output directory to /home/stephanos/Dev/zephyrproject/zephyr/twister-out.14
INFO    - Zephyr version: v2.6.0-rc2-57-g053ff6fa0e72
INFO    - JOBS: 60
INFO    - Using 'zephyr' toolchain.
INFO    - Building initial testcase list...
INFO    - 1 test scenarios (1 configurations) selected, 0 configurations discarded due to filters.
INFO    - Adding tasks to the queue...
INFO    - Added initial list of jobs to queue
INFO    - 1/1 qemu_nios2                tests/subsys/cpp/libcxx/cpp.libcxx.exceptions      SKIPPED (FLASH overflow)

INFO    - 0 of 0 test configurations passed (0.00%), 0 failed, 1 skipped with 0 warnings in 11.06 seconds
INFO    - In total 0 test cases were executed, 4 skipped on 1 out of total 372 platforms (0.27%)
INFO    - 0 test configurations executed on platforms, 0 test configurations were only built.
INFO    - Saving reports...
INFO    - Writing xunit report /home/stephanos/Dev/zephyrproject/zephyr/twister-out/twister.xml...
INFO    - Writing xunit report /home/stephanos/Dev/zephyrproject/zephyr/twister-out/twister_report.xml...
INFO    - Run completed

In that sense, I doubt it is necessary to platform_exclude: qemu_nios2 here.

@nashif any comments on this?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, if that's the case than no issues.

Copy link
Collaborator

@galak galak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably need to exclude qemu_nios2 from the test. Can you add a comment that qemu6 as expected in SDK 0.13.0 should fix that.

@galak galak merged commit cec683d into zephyrproject-rtos:main May 28, 2021
@stephanosio stephanosio deleted the fix_nios2_cpp_exc branch May 28, 2021 19:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: C++ area: Linker Scripts area: NIOS2 NIOS2 Architecture area: Tests Issues related to a particular existing or missing test bug The issue is a bug, or the PR is fixing a bug priority: medium Medium impact/importance bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support C++ exceptions on NIOS2
4 participants