-
-
Notifications
You must be signed in to change notification settings - Fork 15.1k
Generate debug info for BPF extern declarations #152899
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
Draft
altugbozkurt07
wants to merge
3
commits into
rust-lang:main
Choose a base branch
from
altugbozkurt07:bpf-extern-debuginfo
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+250
−22
Draft
Changes from all commits
Commits
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
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
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
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 |
|---|---|---|
|
|
@@ -1147,6 +1147,22 @@ extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateMethod( | |
| return wrap(Sub); | ||
| } | ||
|
|
||
| // Wraps DIBuilder::createGlobalVariableExpression. Unlike the LLVM-C API | ||
| // (LLVMDIBuilderCreateGlobalVariableExpression), this exposes the IsDefined | ||
| // parameter instead of hard-coding it to true. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be applied to the previous commit (
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be okay now |
||
| extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateGlobalVariableExpression( | ||
| LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, | ||
| size_t NameLen, const char *Linkage, size_t LinkLen, LLVMMetadataRef File, | ||
| unsigned LineNo, LLVMMetadataRef Ty, LLVMBool LocalToUnit, | ||
| LLVMBool IsDefined, LLVMMetadataRef Expr, LLVMMetadataRef Decl, | ||
| uint32_t AlignInBits) { | ||
| return wrap(unwrap(Builder)->createGlobalVariableExpression( | ||
| unwrapDI<DIScope>(Scope), {Name, NameLen}, {Linkage, LinkLen}, | ||
| unwrapDI<DIFile>(File), LineNo, unwrapDI<DIType>(Ty), LocalToUnit, | ||
| IsDefined, unwrap<DIExpression>(Expr), unwrapDI<MDNode>(Decl), nullptr, | ||
| AlignInBits)); | ||
| } | ||
|
|
||
| extern "C" LLVMMetadataRef LLVMRustDIBuilderCreateVariantPart( | ||
| LLVMDIBuilderRef Builder, LLVMMetadataRef Scope, const char *Name, | ||
| size_t NameLen, LLVMMetadataRef File, unsigned LineNumber, | ||
|
|
||
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,35 @@ | ||
| // Checks that BPF extern declarations are emitted as debug info declarations. | ||
| // | ||
| //@ only-bpf | ||
| //@ needs-llvm-components: bpf | ||
| //@ compile-flags: --target bpfel-unknown-none -C debuginfo=2 | ||
|
|
||
| #![no_std] | ||
| #![no_main] | ||
| #![crate_type = "lib"] | ||
|
|
||
| extern "C" { | ||
| // CHECK: !DIGlobalVariable(name: "KERNEL_VERSION" | ||
| // CHECK-SAME: isLocal: false | ||
| // CHECK-SAME: isDefinition: false | ||
| #[link_section = ".ksyms"] | ||
| pub static KERNEL_VERSION: u64; | ||
| } | ||
|
|
||
| extern "C" { | ||
| // CHECK: !DISubprogram(name: "bpf_kfunc" | ||
| // CHECK-SAME: flags: DIFlagPrototyped | ||
| // CHECK-SAME: spFlags: DISPFlagZero | ||
| #[link_section = ".ksyms"] | ||
| pub fn bpf_kfunc(x: u64) -> u64; | ||
| } | ||
|
|
||
| #[no_mangle] | ||
| pub fn test_extern_items() -> u64 { | ||
| unsafe { KERNEL_VERSION + bpf_kfunc(42) } | ||
| } | ||
|
|
||
| #[panic_handler] | ||
| fn panic(_info: &core::panic::PanicInfo) -> ! { | ||
| loop {} | ||
| } |
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,24 @@ | ||
| // Checks that extern declarations do not get debug info outside BPF targets. | ||
| // | ||
| //@ compile-flags: -C debuginfo=2 | ||
|
|
||
| #![crate_type = "lib"] | ||
|
|
||
| extern "C" { | ||
| // CHECK: @EXTERN_STATIC = external {{.*}}global i32 | ||
| // CHECK-NOT: !DIGlobalVariable(name: "EXTERN_STATIC" | ||
| pub static EXTERN_STATIC: i32; | ||
| } | ||
|
|
||
| extern "C" { | ||
| // CHECK: declare {{.*}}void @extern_fn() | ||
| // CHECK-NOT: !DISubprogram(name: "extern_fn" | ||
| pub fn extern_fn(); | ||
| } | ||
|
|
||
| pub fn use_extern_items() -> i32 { | ||
| unsafe { | ||
| extern_fn(); | ||
| EXTERN_STATIC | ||
| } | ||
| } |
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,26 @@ | ||
| // Verifies that #[link_section] works on foreign (extern) items. | ||
| // | ||
| //@ ignore-wasm32 custom sections work differently on wasm | ||
| //@ compile-flags: -C no-prepopulate-passes | ||
|
|
||
| #![crate_type = "lib"] | ||
|
|
||
| extern "C" { | ||
| // CHECK: @EXTERN_STATIC = external global i32, section ".ksyms" | ||
| #[link_section = ".ksyms"] | ||
| pub static EXTERN_STATIC: i32; | ||
| } | ||
|
|
||
| extern "C" { | ||
| // CHECK: declare {{.*}}void @extern_fn(){{.*}} section ".ksyms" | ||
| #[link_section = ".ksyms"] | ||
| pub fn extern_fn(); | ||
| } | ||
|
|
||
| // Ensure the extern items are used so they appear in the IR | ||
| pub fn use_extern_items() -> i32 { | ||
| unsafe { | ||
| extern_fn(); | ||
| EXTERN_STATIC | ||
| } | ||
| } |
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
Oops, something went wrong.
Oops, something went wrong.
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.