-
Notifications
You must be signed in to change notification settings - Fork 13.3k
compiletest: Support opt-in Clang-based run-make tests and use them for testing xLTO. #57514
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
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
75dcf9e
Add an end-to-end run-make test for cross-lang LTO.
michaelwoerister 50b2510
compiletest: Support opt-in Clang-based run-make tests.
michaelwoerister ea4fb95
Support clang-based run-make tests in rustbuild.
michaelwoerister b38125c
compiletest: Simplify handling of Clang-based tests.
michaelwoerister 48cb04f
Enable Clang-based tests on x86_64-gnu-debug builder.
michaelwoerister 4460e7c
Add missing packages.
michaelwoerister 9c29517
bootstrap: Make LLD available to run-make tests.
michaelwoerister 4f534ff
ci: Use clang as the C++ compiler for x86_64-gnu-debug.
michaelwoerister dc20c8c
bootstrap: Expose LLVM_USE_LINKER cmake option to config.toml.
michaelwoerister b17c10d
CI: Use lld for linking LLVM in the x86_64-gnu-debug image.
michaelwoerister 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# needs-matching-clang | ||
|
||
# This test makes sure that cross-language inlining actually works by checking | ||
# the generated machine code. | ||
|
||
-include ../tools.mk | ||
|
||
all: cpp-executable rust-executable | ||
|
||
cpp-executable: | ||
$(RUSTC) -Zcross-lang-lto=on -o $(TMPDIR)/librustlib-xlto.a -Copt-level=2 -Ccodegen-units=1 ./rustlib.rs | ||
$(CLANG) -flto=thin -fuse-ld=lld -L $(TMPDIR) -lrustlib-xlto -o $(TMPDIR)/cmain ./cmain.c -O3 | ||
# Make sure we don't find a call instruction to the function we expect to | ||
# always be inlined. | ||
llvm-objdump -d $(TMPDIR)/cmain | $(CGREP) -v -e "call.*rust_always_inlined" | ||
# As a sanity check, make sure we do find a call instruction to a | ||
# non-inlined function | ||
llvm-objdump -d $(TMPDIR)/cmain | $(CGREP) -e "call.*rust_never_inlined" | ||
|
||
rust-executable: | ||
$(CLANG) ./clib.c -flto=thin -c -o $(TMPDIR)/clib.o -O2 | ||
(cd $(TMPDIR); $(AR) crus ./libxyz.a ./clib.o) | ||
$(RUSTC) -Zcross-lang-lto=on -L$(TMPDIR) -Copt-level=2 -Clinker=$(CLANG) -Clink-arg=-fuse-ld=lld ./main.rs -o $(TMPDIR)/rsmain | ||
llvm-objdump -d $(TMPDIR)/rsmain | $(CGREP) -e "call.*c_never_inlined" | ||
llvm-objdump -d $(TMPDIR)/rsmain | $(CGREP) -v -e "call.*c_always_inlined" |
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,9 @@ | ||
#include <stdint.h> | ||
|
||
uint32_t c_always_inlined() { | ||
return 1234; | ||
} | ||
|
||
__attribute__((noinline)) uint32_t c_never_inlined() { | ||
return 12345; | ||
} |
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,12 @@ | ||
#include <stdint.h> | ||
|
||
// A trivial function defined in Rust, returning a constant value. This should | ||
// always be inlined. | ||
uint32_t rust_always_inlined(); | ||
|
||
|
||
uint32_t rust_never_inlined(); | ||
|
||
int main(int argc, char** argv) { | ||
return rust_never_inlined() + rust_always_inlined(); | ||
} |
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,11 @@ | ||
#[link(name = "xyz")] | ||
extern "C" { | ||
fn c_always_inlined() -> u32; | ||
fn c_never_inlined() -> u32; | ||
} | ||
|
||
fn main() { | ||
unsafe { | ||
println!("blub: {}", c_always_inlined() + c_never_inlined()); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/test/run-make-fulldeps/cross-lang-lto-clang/rustlib.rs
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,12 @@ | ||
#![crate_type="staticlib"] | ||
|
||
#[no_mangle] | ||
pub extern "C" fn rust_always_inlined() -> u32 { | ||
42 | ||
} | ||
|
||
#[no_mangle] | ||
#[inline(never)] | ||
pub extern "C" fn rust_never_inlined() -> u32 { | ||
421 | ||
} |
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
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.
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.
Heh since this is an internal env var I think matching on only "yes" or "1" is probably fine, we tend to not really need that much error handling and support for internal features like this
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 wanted to try and make it less likely to have a typo causing things to be silently ignored. What would be really needed though would be fuzzy matching on env var names...
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.
True yeah, although we could also just check for existence here instead of checking for value perhaps?
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.
That's what wanted to do at first but then I remembered the
CARGO_INCREMENTAL=0
confusion. Since it's not really complicated to support a few different options here, I just did that.