-
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
Fix linker-plugin-lto only doing thin lto #136840
Open
Flakebi
wants to merge
1
commit into
rust-lang:master
Choose a base branch
from
Flakebi:linker-plugin-lto-fat
base: master
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
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 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 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 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 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,8 @@ | ||
#![feature(no_core, lang_items)] | ||
#![no_core] | ||
#![crate_type = "rlib"] | ||
|
||
#[lang = "sized"] | ||
trait Sized {} | ||
|
||
pub fn foo() {} |
This file contains 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 @@ | ||
#![allow(internal_features)] | ||
#![feature(no_core, lang_items)] | ||
#![no_core] | ||
#![crate_type = "cdylib"] | ||
|
||
extern crate lib; | ||
|
||
#[unsafe(no_mangle)] | ||
pub fn bar() { | ||
lib::foo(); | ||
} |
This file contains 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 @@ | ||
// Compile a library with lto=fat, then compile a binary with lto=thin | ||
// and check that lto is applied with the library. | ||
// The goal is to mimic the standard library being build with lto=fat | ||
// and allowing users to build with lto=thin. | ||
|
||
//@ only-x86_64-unknown-linux-gnu | ||
|
||
use run_make_support::{dynamic_lib_name, llvm_objdump, rustc}; | ||
|
||
fn main() { | ||
rustc().input("lib.rs").opt_level("3").arg("-Clto=fat").run(); | ||
rustc().input("main.rs").panic("abort").opt_level("3").arg("-Clto=thin").run(); | ||
|
||
llvm_objdump() | ||
.input(dynamic_lib_name("main")) | ||
.arg("--disassemble-symbols=bar") | ||
.run() | ||
// The called function should be inlined. | ||
// Check that we have a ret (to detect tail | ||
// calls with a jmp) and no call. | ||
.assert_stdout_contains("bar") | ||
.assert_stdout_contains("ret") | ||
.assert_stdout_not_contains("foo") | ||
.assert_stdout_not_contains("call"); | ||
} |
This file contains 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,6 @@ | ||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" | ||
target triple = "x86_64-unknown-linux-gnu" | ||
|
||
define void @ir_callee() { | ||
ret void | ||
} |
This file contains 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,17 @@ | ||
#![feature(no_core, lang_items)] | ||
#![no_core] | ||
#![crate_type = "cdylib"] | ||
|
||
#[lang = "sized"] | ||
trait Sized {} | ||
|
||
extern "C" { | ||
fn ir_callee(); | ||
} | ||
|
||
#[no_mangle] | ||
extern "C" fn rs_foo() { | ||
unsafe { | ||
ir_callee(); | ||
} | ||
} |
This file contains 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,29 @@ | ||
// Check that -C lto=fat with -C linker-plugin-lto actually works and can inline functions. | ||
// A library is created from LLVM IR, defining a single function. Then a dylib is compiled, | ||
// linking to the library and calling the function from the library. | ||
// The function from the library should end up inlined and disappear from the output. | ||
|
||
//@ only-x86_64-unknown-linux-gnu | ||
//@ needs-rust-lld | ||
|
||
use run_make_support::{dynamic_lib_name, llvm_as, llvm_objdump, rustc}; | ||
|
||
fn main() { | ||
llvm_as().input("ir.ll").run(); | ||
rustc() | ||
.input("main.rs") | ||
.opt_level("3") | ||
.args(&["-Clto=fat", "-Clinker-plugin-lto", "-Zlinker-features=+lld", "-Clink-arg=ir.bc"]) | ||
.run(); | ||
|
||
llvm_objdump() | ||
.input(dynamic_lib_name("main")) | ||
.arg("--disassemble-symbols=rs_foo") | ||
.run() | ||
// The called function should be inlined. | ||
// Check that we have a ret (to detect tail | ||
// calls with a jmp) and no call. | ||
.assert_stdout_contains("foo") | ||
.assert_stdout_contains("ret") | ||
.assert_stdout_not_contains("call"); | ||
} |
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.
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.
What if a dependency is built with lto=true (aka lto=fat), but then the user wants to use thinLTO? I'm pretty sure the standard library is built with lto=true for example, but that shouldn't prevent thinLTO from ever working.
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.
Good question, it seems to change somewhat, but still work in general. I added a test for this.
What changes: Without this change, the test passes when
lib is compiled with
O0
and main withO3
andWith this change, all of these keep passing except for case 3 (lib uses lto=fat and main uses lto=thin).
When lib is compiled with
O1
,O2
orO3
, case 3 passes as well.I assume this is the important case, as the standard library is compiled with optimizations.
(And lto with
O0
is kinda questionable, except maybe for nvptx and amdgpu, but they require lto=fat anyway.)