-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Add support for storing code model to LLVM module IR #74002
Changes from 3 commits
825eb47
b99a08a
4a89c9f
67a5e2b
5c24a94
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1163,6 +1163,20 @@ extern "C" void LLVMRustSetModulePIELevel(LLVMModuleRef M) { | |
unwrap(M)->setPIELevel(PIELevel::Level::Large); | ||
} | ||
|
||
// Linking object files with different code models is undefined behavior | ||
// because the compiler would have to generate additional code (to span | ||
// longer jumps) if a larger code model is used with a smaller one. | ||
// Therefore we will treat attempts to mix code models as an error. | ||
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 last sentence is super interesting, but it is not super clear where the "error" comes from. Does it happen at LTO time? Quick skim of the linked differentials does not answer it, you need to read the comments, so it would be great if more about this was said here. I would also probably move it to this function’s call location as people are way more likely to read it in 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.
Thank you for having a look, and sorry for not clear that. |
||
// | ||
// See https://reviews.llvm.org/D52322 and https://reviews.llvm.org/D52323. | ||
extern "C" void LLVMRustSetModuleCodeModel(LLVMModuleRef M, | ||
LLVMRustCodeModel Model) { | ||
auto CM = fromRust(Model); | ||
if (!CM.hasValue()) | ||
return; | ||
unwrap(M)->setCodeModel(*CM); | ||
} | ||
|
||
// Here you'll find an implementation of ThinLTO as used by the Rust compiler | ||
// right now. This ThinLTO support is only enabled on "recent ish" versions of | ||
// LLVM, and otherwise it's just blanket rejected from other compilers. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// revisions: NOMODEL MODEL-SMALL MODEL-KERNEL MODEL-MEDIUM MODEL-LARGE | ||
//[NOMODEL] compile-flags: | ||
//[MODEL-SMALL] compile-flags: -C code-model=small | ||
//[MODEL-KERNEL] compile-flags: --target=x86_64-unknown-linux-gnu -C code-model=kernel | ||
//[MODEL-MEDIUM] compile-flags: --target=x86_64-unknown-linux-gnu -C code-model=medium | ||
//[MODEL-LARGE] compile-flags: -C code-model=large | ||
|
||
#![crate_type = "lib"] | ||
|
||
// MODEL-SMALL: !llvm.module.flags = !{{{.*}}} | ||
// MODEL-SMALL: !{{[0-9]+}} = !{i32 1, !"Code Model", i32 1} | ||
// MODEL-KERNEL: !llvm.module.flags = !{{{.*}}} | ||
// MODEL-KERNEL: !{{[0-9]+}} = !{i32 1, !"Code Model", i32 2} | ||
// MODEL-MEDIUM: !llvm.module.flags = !{{{.*}}} | ||
// MODEL-MEDIUM: !{{[0-9]+}} = !{i32 1, !"Code Model", i32 3} | ||
// MODEL-LARGE: !llvm.module.flags = !{{{.*}}} | ||
// MODEL-LARGE: !{{[0-9]+}} = !{i32 1, !"Code Model", i32 4} | ||
// NOMODEL-NOT: Code Model |
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.
Consider
pub(crate)
or justcrate
.