-
-
Notifications
You must be signed in to change notification settings - Fork 15.1k
Direct access external data #158409
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
Open
ilovepi
wants to merge
2
commits into
rust-lang:main
Choose a base branch
from
ilovepi:direct_access_external_data
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.
Open
Direct access external data #158409
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1113,11 +1113,17 @@ LLVMRustSetDataLayoutFromTargetMachine(LLVMModuleRef Module, | |
| } | ||
|
|
||
| extern "C" void LLVMRustSetModulePICLevel(LLVMModuleRef M) { | ||
| unwrap(M)->setPICLevel(PICLevel::Level::BigPIC); | ||
| Module *Mod = unwrap(M); | ||
| if (!Mod->getModuleFlag("PIC Level")) { | ||
| Mod->setPICLevel(PICLevel::Level::BigPIC); | ||
| } | ||
| } | ||
|
|
||
| extern "C" void LLVMRustSetModulePIELevel(LLVMModuleRef M) { | ||
| unwrap(M)->setPIELevel(PIELevel::Level::Large); | ||
| Module *Mod = unwrap(M); | ||
| if (!Mod->getModuleFlag("PIE Level")) { | ||
| Mod->setPIELevel(PIELevel::Level::Large); | ||
| } | ||
| } | ||
|
Comment on lines
1115
to
1127
Contributor
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. Not totally convinced this is 100% the right approach. Alternatively, we could set the merge strategy and do it that way, but I figured its probably better to only replace if it doesn't exist. Happy to amend the strategy here. |
||
|
|
||
| extern "C" void LLVMRustSetModuleCodeModel(LLVMModuleRef M, | ||
|
|
||
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 |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| #![feature(no_core, lang_items)] | ||
| #![no_std] | ||
| #![no_core] | ||
| #![crate_type = "lib"] | ||
|
|
||
| #[lang = "pointee_sized"] | ||
| trait PointeeSized {} | ||
| #[lang = "meta_sized"] | ||
| trait MetaSized: PointeeSized {} | ||
| #[lang = "sized"] | ||
| trait Sized: MetaSized {} | ||
|
|
||
| #[lang = "copy"] | ||
| pub trait Copy {} | ||
|
|
||
| impl Copy for i32 {} | ||
|
|
||
| unsafe extern "C" { | ||
| pub safe static VAR: i32; | ||
| } | ||
|
|
||
| #[no_mangle] | ||
| pub fn refer_dep() -> i32 { | ||
| unsafe { VAR } | ||
| } |
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,65 @@ | ||
| #![feature(no_core, lang_items)] | ||
| #![no_std] | ||
| #![no_core] | ||
|
|
||
| extern crate dep; | ||
|
|
||
| unsafe extern "C" { | ||
| pub safe static VAR: i32; | ||
| } | ||
|
|
||
| pub mod mod_0 { | ||
| use super::VAR; | ||
| #[no_mangle] | ||
| pub fn refer_0() -> i32 { | ||
| VAR | ||
| } | ||
| } | ||
|
|
||
| pub mod mod_1 { | ||
| use super::VAR; | ||
| #[no_mangle] | ||
| pub fn refer_1() -> i32 { | ||
| VAR | ||
| } | ||
| } | ||
|
|
||
| #[no_mangle] | ||
| pub fn call_dep() -> i32 { | ||
| dep::refer_dep() | ||
| } | ||
|
|
||
| // DEFAULT: @VAR = {{.*}}dso_local{{.*}}global i32 | ||
| // DEFAULT-NOT: direct-access-external-data | ||
| // DEFAULT-NOT: PIE Level | ||
|
|
||
| // PIE: @VAR = external | ||
| // PIE-NOT: dso_local | ||
| // PIE-SAME: global i32 | ||
| // PIE-NOT: direct-access-external-data | ||
| // PIE: !{{[0-9]+}} = !{i32 7, !"PIE Level", i32 2} | ||
|
|
||
| // DIRECT: @VAR = {{.*}}dso_local{{.*}}global i32 | ||
| // DIRECT-DAG: !{{[0-9]+}} = !{i32 7, !"direct-access-external-data", i32 1} | ||
| // DIRECT-DAG: !{{[0-9]+}} = !{i32 7, !"PIE Level", i32 2} | ||
|
|
||
| // INDIRECT: @VAR = external | ||
| // INDIRECT-NOT: dso_local | ||
| // INDIRECT-SAME: global i32 | ||
| // INDIRECT: !{{[0-9]+}} = !{i32 7, !"direct-access-external-data", i32 0} | ||
| // INDIRECT-NOT: PIE Level | ||
|
|
||
| // DEP-PIE: !{{[0-9]+}} = !{i32 7, !"PIE Level", i32 2} | ||
|
|
||
| // For Full & Thin LTO we expect direct PC-relative access. | ||
| // DIRECT-RELOC-NOT: R_X86_64_GOTPCREL{{.*}}VAR | ||
| // DIRECT-RELOC: R_X86_64_PC32{{.*}}VAR | ||
|
|
||
| // For indirect cases, we always expect GOT indirection. | ||
| // INDIRECT-RELOC: R_X86_64_GOTPCREL{{.*}}VAR | ||
| // INDIRECT-RELOC-NOT: R_X86_64_PC32{{.*}}VAR | ||
|
|
||
| // Default PIE without direct-access enabled should use GOT indirection. | ||
| // This is correct and is not changed by setting PIE Level consistently. | ||
| // PIE-RELOC: R_X86_64_GOTPCREL{{.*}}VAR | ||
| // PIE-RELOC-NOT: R_X86_64_PC32{{.*}}VAR |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm confused by why this is necessary. Aren't we just loading a previously serialized module here? Shouldn't the PIC/PIE flags have been set at the time the module was created?
View changes since the review
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I was surprised too. I believe the main contributor is that
core&stdlibs end up w/o the PIE levels set at all, since they aren't being used in an executable. I can't recall if we have other examples or not, but its my vague recollection that we triggered this issue w/o use ofcoreat all whencodegen-units>1.For our kernel specifically, this becomes an issue as we'd really like to use code from
core. However, that would be a hard sell if we cannot prevent GOT indirection when accessing globals that would normally be safe to directly access (and have been accessed that way from C++ code for a very long time).Do you think there's a better way to address this? Maybe somewhere in the lto.rs code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So the problem is that libcore/libstd are compiled as PIC but you want them to be PIE? And you're solving this by adding the PIE metadata during LTO? I don't think that's the right way to fix this.
Wouldn't the correct solution here to use build-std and enable PIE for libstd?