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

cheri_compartment: Warn if return type is void or return value is unused #47

Conversation

v01dXYZ
Copy link

@v01dXYZ v01dXYZ commented Nov 15, 2024

Fixes #34.

@v01dXYZ v01dXYZ marked this pull request as ready for review November 15, 2024 23:12
@davidchisnall
Copy link

Thanks for doing this. We are in the middle of rebasing our changes on a newer LLVM, so I’d like to hold off merging until that’s done.

The warning would be better if it is explicit about why it’s a bad idea, rather than saying that it’s unsupported. I’d recommend something like:

void return on a cross-compartment call makes it impossible for callers to detect failure.

A fixit hint that changed the type to int and changed return statements to return 0 (and adds one at the end of the function) would be ideal.

@v01dXYZ
Copy link
Author

v01dXYZ commented Nov 21, 2024

Thank you. I'll look at FixItHint.

@v01dXYZ
Copy link
Author

v01dXYZ commented Nov 30, 2024

This comment is for documentation.

  • note diagnosis are not meant to be emitted alone but in conjunction with a warning/error. If you do it nonetheless, it is very likely it would be ignored as the last non-note diagnosis could have been an ignored warning (and there are a lot of those).
  • emiting a diagnosis at a given location with a fixit at another line (location?) doesn't work. In this case, use warning + note. If you do it nonetheless, the fixit will be ignored.
  • ~FuncDec::getFunctionTypeLoc fails when there are attributes. The TypeSourceInfo has a TypeLoc with the following structure: AttributedType, FunctionTypeProto.

@v01dXYZ
Copy link
Author

v01dXYZ commented Dec 2, 2024

I need to adapt an existing function, I will reimplement it where it's needed but I also opened an issue to know if it's acceptable to directly modify the function: llvm/llvm-project#118290.

@v01dXYZ
Copy link
Author

v01dXYZ commented Dec 2, 2024

@davidchisnall

Here the following error messages:

  • void return type:
    • Warning: void return on a cross compartment call makes it impossible for callers to detect failures
    • Note: Replace void return type with int + fix-it hint replacement
  • return;, no return:
    • Warning: cross-compartment calls that always succeed should return 0 instead + fix-it hint insertion

Do you agree with the diagnosis levels (warn, note, ...) ? Don't forget to comment on capitalisation or ending the messages with dot (or not). Just asking to not turn this PR into a Nicaea council.

I plan to add this (corrected) description of the messages to the issue description.

@davidchisnall
Copy link

That sounds good to me as a structure. @rmn30 / @nwf, any opinions on the message text?

@rmn30
Copy link

rmn30 commented Dec 2, 2024

Sounds good!

@nwf
Copy link
Member

nwf commented Dec 2, 2024

Sounds good to me (and it's a useful diagnostic to have; thanks!)

@v01dXYZ
Copy link
Author

v01dXYZ commented Dec 9, 2024

This PR is almost finished but there is some parts that depend on modifying the behavior of some core clang class (FunctionDecl::getReturnTypeLoc). I'm working on a patch for trunk llvm and waiting for review. This modification is needed for the FixItHint to replace void by int. I think it's going to take 2 more weeks.

@davidchisnall
Copy link

I don't mind carrying the FunctionDecl::getReturnTypeLoc patch here while it's being upstreamed. We can probably move to LLVM 17 this week, and then merge this.

@davidchisnall davidchisnall deleted the branch CHERIoT-Platform:cheriot December 12, 2024 10:03
@resistor resistor reopened this Dec 12, 2024
@resistor
Copy link
Collaborator

You're probably going to need to cherry-pick this onto the new llvm-17 based branch.

@v01dXYZ v01dXYZ force-pushed the cheriot-compartment-warn-if-return-void-or-unused branch from de97656 to 2eac335 Compare December 12, 2024 12:49
@v01dXYZ
Copy link
Author

v01dXYZ commented Dec 12, 2024

The CI timed out. Is there any way to relaunch it without pushing ?

@v01dXYZ v01dXYZ force-pushed the cheriot-compartment-warn-if-return-void-or-unused branch 2 times, most recently from 7795792 to 5c89ebb Compare December 13, 2024 04:18
clang/include/clang/Basic/DiagnosticSemaKinds.td Outdated Show resolved Hide resolved
clang/include/clang/Basic/DiagnosticSemaKinds.td Outdated Show resolved Hide resolved
clang/lib/AST/Decl.cpp Outdated Show resolved Hide resolved
Copy link
Collaborator

@resistor resistor left a comment

Choose a reason for hiding this comment

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

LGTM

@resistor
Copy link
Collaborator

@v01dXYZ I'm not sure if you can merge this of it you need me to do it. If the latter, please rebase it and then ping me to merge it.

v01dxyz added 7 commits December 16, 2024 06:27
The current implementation has a little shortcoming: the warning
message for void return type is shown twice because cheri_compartment
is a function type attribute (cf SemaType.cpp) that is added to both
the attribute list of the declarator and the one of the function type.
@v01dXYZ v01dXYZ force-pushed the cheriot-compartment-warn-if-return-void-or-unused branch from c2d7cc6 to b8c007f Compare December 16, 2024 05:27
@v01dXYZ
Copy link
Author

v01dXYZ commented Dec 16, 2024

It seems it's pretty easy to run out of credits with the Cirrus CI free plan.

@resistor resistor enabled auto-merge (rebase) December 16, 2024 11:27
@resistor resistor merged commit b603b3e into CHERIoT-Platform:cheriot Dec 16, 2024
1 check passed
@resistor
Copy link
Collaborator

@v01dXYZ Getting a report from @nwf that this is causing linker errors in cheriot-rtos. I'm going to revert these changes for now. I won't have time to look into the failure in detail in the next two days. If you figure out what's wrong in the meantime, go ahead and re-PR it. Otherwise I'll help figure out the problem when I'm around again.

@resistor
Copy link
Collaborator

@nwf reports that git bisect points to: 4d8ad0b

@resistor
Copy link
Collaborator

The full link error is:

[ 99%]: linking firmware build/cheriot/cheriot/release/test-suite
/home/ubuntu/llvm-project-1/build/install/bin/ld.lld -n --script=build/test-suite-firmware.ldscript --relax -o build/cheriot/cheriot/release/test-suite --compartment-report=build/cheriot/cheriot/release/test-suite.json build/.objs/cheriot.loader/cheriot/cheriot/release/__/sdk/core/loader/boot.S.o build/.objs/cheriot.loader/cheriot/cheriot/release/__/sdk/core/loader/boot.cc.o build/.objs/cheriot.switcher/cheriot/cheriot/release/__/sdk/core/switcher/entry.S.o build/cheriot/cheriot/release/allocator_test.compartment build/cheriot/cheriot/release/atomic1.library build/cheriot/cheriot/release/atomic2.library build/cheriot/cheriot/release/atomic4.library build/cheriot/cheriot/release/atomic8.library build/cheriot/cheriot/release/ccompile_test.compartment build/cheriot/cheriot/release/check_pointer_test.compartment build/cheriot/cheriot/release/cheriot.allocator.compartment build/cheriot/cheriot/release/compartment_helpers.library build/cheriot/cheriot/release/locks.library build/cheriot/cheriot/release/cheriot.software_revoker.compartment build/cheriot/cheriot/release/cheriot.token_library.library build/cheriot/cheriot/release/compartment_calls_inner.compartment build/cheriot/cheriot/release/compartment_calls_test.compartment build/cheriot/cheriot/release/crash_recovery_inner.compartment build/cheriot/cheriot/release/crash_recovery_outer.compartment build/cheriot/cheriot/release/crash_recovery_test.compartment build/cheriot/cheriot/release/crt.library build/cheriot/cheriot/release/cxxrt.library build/cheriot/cheriot/release/debug.library build/cheriot/cheriot/release/debug_test.compartment build/cheriot/cheriot/release/event_group.library build/cheriot/cheriot/release/eventgroup_test.compartment build/cheriot/cheriot/release/freestanding.library build/cheriot/cheriot/release/futex_test.compartment build/cheriot/cheriot/release/list_test.compartment build/cheriot/cheriot/release/locks_test.compartment build/cheriot/cheriot/release/message_queue.compartment build/cheriot/cheriot/release/message_queue_library.library build/cheriot/cheriot/release/misc_test.compartment build/cheriot/cheriot/release/mmio_test.compartment build/cheriot/cheriot/release/multiwaiter_test.compartment build/cheriot/cheriot/release/queue_test.compartment build/cheriot/cheriot/release/stack_integrity_thread.compartment build/cheriot/cheriot/release/stack_test.compartment build/cheriot/cheriot/release/static_sealing_inner.compartment build/cheriot/cheriot/release/static_sealing_test.compartment build/cheriot/cheriot/release/stdio.library build/cheriot/cheriot/release/string.library build/cheriot/cheriot/release/stdio_test.compartment build/cheriot/cheriot/release/test-suite.scheduler.compartment build/cheriot/cheriot/release/test_runner.compartment build/cheriot/cheriot/release/thread_pool.compartment build/cheriot/cheriot/release/thread_pool_test.compartment build/cheriot/cheriot/release/unwind_cleanup_test.compartment
ld.lld: error: undefined symbol: heap_allocate
>>> referenced by global_constructors.hh:49 (/workspaces/cheriot-rtos/sdk/include/c++-config/global_constructors.hh:49)
>>>               build/cheriot/cheriot/release/allocator_test.compartment:()
>>> referenced by global_constructors.hh:29 (/workspaces/cheriot-rtos/sdk/include/c++-config/global_constructors.hh:29)
>>>               build/cheriot/cheriot/release/allocator_test.compartment:()
>>> referenced by global_constructors.hh:0 (/workspaces/cheriot-rtos/sdk/include/c++-config/global_constructors.hh:0)
>>>               build/cheriot/cheriot/release/allocator_test.compartment:()
>>> referenced 17 more times

ld.lld: error: undefined symbol: heap_allocate_array
>>> referenced by __cpp_allocator-test.cc.cc
>>>               build/cheriot/cheriot/release/allocator_test.compartment:()
>>> referenced by __cpp_allocator-test.cc.cc
>>>               build/cheriot/cheriot/release/allocator_test.compartment:()

ld.lld: error: undefined symbol: revoker_epoch_get()
>>> referenced by main.cc:931 (../sdk/core/allocator/main.cc:931)
>>>               build/cheriot/cheriot/release/cheriot.allocator.compartment:()

ld.lld: error: undefined symbol: __library_export_libcalls__Z6memcpyPvPKvj
>>> referenced by __cpp_misc-test.cc.cc
>>>               build/cheriot/cheriot/release/misc_test.compartment:()

ld.lld: error: undefined symbol: __export__heap_allocate
>>> referenced by __cpp_queue.cc.cc
>>>               build/cheriot/cheriot/release/message_queue_library.library:()
>>> referenced by __cpp_event_group.cc.cc
>>>               build/cheriot/cheriot/release/event_group.library:()

The memcpy part is due to another commit that I'm also backing out, but the rest are due to this PR.

@v01dXYZ
Copy link
Author

v01dXYZ commented Dec 17, 2024

I suspect a strange behavior from xmake. My reasoning: compilation should fail as there is the Werror flag set. There are some bits of code that have a void return type or ignore the return value of a compartment call. I wonder also if it creates a empty file instead of no file, this file is then ignored by the linker.

@resistor
Copy link
Collaborator

I made some time to look into it, and I think I found it. I'll push a PR for you to review soon.

@v01dXYZ
Copy link
Author

v01dXYZ commented Dec 17, 2024

At least it forced me to compile cheriot-rtos tests. I'll add a line in my local cirrus.yml for doing that since it only requires installing xmake which is debian/Ubuntu available

@rmn30
Copy link

rmn30 commented Dec 17, 2024

xmake which is debian/Ubuntu available

Be careful as there we were hit by some issues in various versions of xmake and the version available in debian / ubuntu repos may not work correctly. At present the devcontainer Dockerfile is installing a version from a ppa but that may only work on Ubuntu.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Warn if compartment call returns void
5 participants