-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[RISC-V] Adjust trampoline code for branch control flow protection #141949
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
Merged
+178
−31
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d02379c
[RISC-V] Adjust trampoline code for branch control flow protection
jaidTw 55b3510
[RISCV] Use software-guarded jump in the trampoline code
jaidTw 0ffff6d
Use SmallVector to handle both trampoline sequence
jaidTw 38a8ec5
fixup! Add assertion to ensure the size of OutChains
jaidTw e3088d7
fixup! clang-format
jaidTw 0779b88
fixup! use different way to get module flag
jaidTw 9bbae97
rebase and update test
jaidTw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,99 @@ | ||
| ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5 | ||
| ; RUN: llc -O0 -mtriple=riscv64 -mattr=+experimental-zicfilp -verify-machineinstrs < %s \ | ||
| ; RUN: | FileCheck -check-prefix=RV64 %s | ||
| ; RUN: llc -O0 -mtriple=riscv64-unknown-linux-gnu -mattr=+experimental-zicfilp -verify-machineinstrs < %s \ | ||
| ; RUN: | FileCheck -check-prefix=RV64-LINUX %s | ||
|
|
||
| declare void @llvm.init.trampoline(ptr, ptr, ptr) | ||
| declare ptr @llvm.adjust.trampoline(ptr) | ||
| declare i64 @f(ptr nest, i64) | ||
|
|
||
| define i64 @test0(i64 %n, ptr %p) nounwind { | ||
| ; RV64-LABEL: test0: | ||
| ; RV64: # %bb.0: | ||
| ; RV64-NEXT: lpad 0 | ||
| ; RV64-NEXT: addi sp, sp, -64 | ||
| ; RV64-NEXT: sd ra, 56(sp) # 8-byte Folded Spill | ||
| ; RV64-NEXT: sd a0, 0(sp) # 8-byte Folded Spill | ||
| ; RV64-NEXT: lui a0, %hi(f) | ||
| ; RV64-NEXT: addi a0, a0, %lo(f) | ||
| ; RV64-NEXT: sw a0, 44(sp) | ||
| ; RV64-NEXT: srli a0, a0, 32 | ||
| ; RV64-NEXT: sw a0, 48(sp) | ||
| ; RV64-NEXT: sw a1, 36(sp) | ||
| ; RV64-NEXT: srli a0, a1, 32 | ||
| ; RV64-NEXT: sw a0, 40(sp) | ||
| ; RV64-NEXT: li a0, 23 | ||
| ; RV64-NEXT: sw a0, 16(sp) | ||
| ; RV64-NEXT: lui a0, 56 | ||
| ; RV64-NEXT: addi a0, a0, 103 | ||
| ; RV64-NEXT: sw a0, 32(sp) | ||
| ; RV64-NEXT: lui a0, 4324 | ||
| ; RV64-NEXT: addi a0, a0, -509 | ||
| ; RV64-NEXT: sw a0, 28(sp) | ||
| ; RV64-NEXT: lui a0, 6371 | ||
| ; RV64-NEXT: addi a0, a0, 899 | ||
| ; RV64-NEXT: sw a0, 24(sp) | ||
| ; RV64-NEXT: lui a0, 1 | ||
| ; RV64-NEXT: addi a0, a0, -489 | ||
| ; RV64-NEXT: sw a0, 20(sp) | ||
| ; RV64-NEXT: addi a1, sp, 36 | ||
| ; RV64-NEXT: addi a0, sp, 16 | ||
| ; RV64-NEXT: sd a0, 8(sp) # 8-byte Folded Spill | ||
| ; RV64-NEXT: call __clear_cache | ||
| ; RV64-NEXT: ld a0, 0(sp) # 8-byte Folded Reload | ||
| ; RV64-NEXT: ld a1, 8(sp) # 8-byte Folded Reload | ||
| ; RV64-NEXT: jalr a1 | ||
| ; RV64-NEXT: ld ra, 56(sp) # 8-byte Folded Reload | ||
| ; RV64-NEXT: addi sp, sp, 64 | ||
| ; RV64-NEXT: ret | ||
| ; | ||
| ; RV64-LINUX-LABEL: test0: | ||
| ; RV64-LINUX: # %bb.0: | ||
| ; RV64-LINUX-NEXT: lpad 0 | ||
| ; RV64-LINUX-NEXT: addi sp, sp, -64 | ||
| ; RV64-LINUX-NEXT: sd ra, 56(sp) # 8-byte Folded Spill | ||
| ; RV64-LINUX-NEXT: sd a0, 0(sp) # 8-byte Folded Spill | ||
| ; RV64-LINUX-NEXT: lui a0, %hi(f) | ||
| ; RV64-LINUX-NEXT: addi a0, a0, %lo(f) | ||
| ; RV64-LINUX-NEXT: sw a0, 44(sp) | ||
| ; RV64-LINUX-NEXT: srli a0, a0, 32 | ||
| ; RV64-LINUX-NEXT: sw a0, 48(sp) | ||
| ; RV64-LINUX-NEXT: sw a1, 36(sp) | ||
| ; RV64-LINUX-NEXT: srli a0, a1, 32 | ||
| ; RV64-LINUX-NEXT: sw a0, 40(sp) | ||
| ; RV64-LINUX-NEXT: li a0, 23 | ||
| ; RV64-LINUX-NEXT: sw a0, 16(sp) | ||
| ; RV64-LINUX-NEXT: lui a0, 56 | ||
| ; RV64-LINUX-NEXT: addi a0, a0, 103 | ||
| ; RV64-LINUX-NEXT: sw a0, 32(sp) | ||
| ; RV64-LINUX-NEXT: lui a0, 4324 | ||
| ; RV64-LINUX-NEXT: addi a0, a0, -509 | ||
| ; RV64-LINUX-NEXT: sw a0, 28(sp) | ||
| ; RV64-LINUX-NEXT: lui a0, 6371 | ||
| ; RV64-LINUX-NEXT: addi a0, a0, 899 | ||
| ; RV64-LINUX-NEXT: sw a0, 24(sp) | ||
| ; RV64-LINUX-NEXT: lui a0, 1 | ||
| ; RV64-LINUX-NEXT: addi a0, a0, -489 | ||
| ; RV64-LINUX-NEXT: sw a0, 20(sp) | ||
| ; RV64-LINUX-NEXT: addi a1, sp, 36 | ||
| ; RV64-LINUX-NEXT: addi a0, sp, 16 | ||
| ; RV64-LINUX-NEXT: sd a0, 8(sp) # 8-byte Folded Spill | ||
| ; RV64-LINUX-NEXT: li a2, 0 | ||
| ; RV64-LINUX-NEXT: call __riscv_flush_icache | ||
| ; RV64-LINUX-NEXT: ld a0, 0(sp) # 8-byte Folded Reload | ||
| ; RV64-LINUX-NEXT: ld a1, 8(sp) # 8-byte Folded Reload | ||
| ; RV64-LINUX-NEXT: jalr a1 | ||
| ; RV64-LINUX-NEXT: ld ra, 56(sp) # 8-byte Folded Reload | ||
| ; RV64-LINUX-NEXT: addi sp, sp, 64 | ||
| ; RV64-LINUX-NEXT: ret | ||
| %alloca = alloca [36 x i8], align 8 | ||
| call void @llvm.init.trampoline(ptr %alloca, ptr @f, ptr %p) | ||
| %tramp = call ptr @llvm.adjust.trampoline(ptr %alloca) | ||
| %ret = call i64 %tramp(i64 %n) | ||
| ret i64 %ret | ||
| } | ||
|
|
||
| !llvm.module.flags = !{!0} | ||
|
|
||
| !0 = !{i32 8, !"cf-protection-branch", i32 1} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.