forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#113923 - DianQK:restore-no-builtins-lto, r=pn…
…kfelix Restore `#![no_builtins]` crates participation in LTO. After rust-lang#113716, we can make `#![no_builtins]` crates participate in LTO again. `#![no_builtins]` with LTO does not result in undefined references to the error. I believe this type of issue won't happen again. \(^▽^)/ I will test the following issues later to verify. The task format is `Fixes {issue} {nightly-2023-07-20 result} {PR rust-lang#113923 result}`. - [x] Fixes rust-lang#72140. ❌ ✅ - [x] Fixes rust-lang#112245. ❌ ✅ - [x] Fixes rust-lang#110606. ❌ ✅ - [ ] Fixes rust-lang#105734. - [ ] Fixes rust-lang#96486. - [ ] Fixes rust-lang#108853. - [x] Fixes rust-lang/compiler-builtins#347. ❌ ✅ - [ ] Fixes rust-lang#108893. - [ ] Fixes rust-lang#78744. Fixes rust-lang#91158. Fixes rust-lang/cargo#10118. The `nightly-2023-07-20` version does not always reproduce problems due to changes in compiler-builtins, core, and user code. That's why this issue recurs and disappears. Some issues were not tested due to the difficulty of reproducing them. r? pnkfelix cc `@bjorn3` `@japaric` `@alexcrichton` `@Amanieu`
- Loading branch information
Showing
15 changed files
with
154 additions
and
79 deletions.
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
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 |
---|---|---|
@@ -1,9 +1,15 @@ | ||
include ../tools.mk | ||
|
||
# only-x86_64 | ||
|
||
# We want to check that `no_builtins` is correctly participating in LTO. | ||
# First, verify that the `foo::foo` symbol can be found when linking. | ||
# Next, verify that `memcpy` can be customized using `no_builtins` under LTO. | ||
# Others will use the built-in memcpy. | ||
|
||
all: | ||
# Compile a `#![no_builtins]` rlib crate | ||
$(RUSTC) no_builtins.rs | ||
# Build an executable that depends on that crate using LTO. The no_builtins crate doesn't | ||
# participate in LTO, so its rlib must be explicitly linked into the final binary. Verify this by | ||
# grepping the linker arguments. | ||
$(RUSTC) main.rs -C lto --print link-args | $(CGREP) 'libno_builtins.rlib' | ||
$(RUSTC) -C linker-plugin-lto -C opt-level=2 -C debuginfo=0 foo.rs | ||
$(RUSTC) -C linker-plugin-lto -C opt-level=2 -C debuginfo=0 no_builtins.rs | ||
$(RUSTC) main.rs -C lto -C opt-level=2 -C debuginfo=0 -C save-temps -C metadata=1 -C codegen-units=1 | ||
$(LLVM_BIN_DIR)/llvm-dis $(TMPDIR)/main.main.*-cgu.0.rcgu.lto.input.bc -o $(TMPDIR)/lto.ll | ||
cat "$(TMPDIR)"/lto.ll | "$(LLVM_FILECHECK)" filecheck.lto.txt |
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 @@ | ||
CHECK: define{{.*}} void @bar | ||
CHECK-NEXT: call void @no_builtins | ||
CHECK-NEXT: call void @llvm.memcpy | ||
|
||
CHECK: define{{.*}} i32 @main | ||
CHECK: call void @bar | ||
|
||
CHECK: define{{.*}} void @foo | ||
CHECK-NEXT: call void @llvm.memcpy | ||
|
||
CHECK: define{{.*}} void @no_builtins | ||
CHECK-SAME: #[[ATTR:[0-9]+]] { | ||
CHECK: call void @foo | ||
CHECK-NEXT: call{{.*}} @memcpy | ||
|
||
CHECK: attributes #[[ATTR]] | ||
CHECK-SAME: no-builtins |
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,33 @@ | ||
#![feature(lang_items, no_core)] | ||
#![no_std] | ||
#![no_core] | ||
#![crate_type = "lib"] | ||
|
||
#[inline(never)] | ||
#[no_mangle] | ||
pub unsafe fn foo(dest: *mut u8, src: *const u8) { | ||
// should call `@llvm.memcpy`. | ||
memcpy(dest, src, 1024); | ||
} | ||
|
||
#[no_mangle] | ||
#[inline(never)] | ||
pub unsafe extern "C" fn memcpy(dest: *mut u8, src: *const u8, _n: usize) -> *mut u8 { | ||
*dest = 0; | ||
return src as *mut u8; | ||
} | ||
|
||
#[lang = "sized"] | ||
trait Sized {} | ||
#[lang = "copy"] | ||
trait Copy {} | ||
impl Copy for *mut u8 {} | ||
impl Copy for *const u8 {} | ||
|
||
#[lang = "drop_in_place"] | ||
#[allow(unconditional_recursion)] | ||
pub unsafe fn drop_in_place<T: ?Sized>(to_drop: *mut T) { | ||
// Code here does not matter - this is replaced by the | ||
// real drop glue by the compiler. | ||
drop_in_place(to_drop); | ||
} |
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 |
---|---|---|
@@ -1,3 +1,28 @@ | ||
#![feature(no_core, start, lang_items)] | ||
#![no_std] | ||
// We use `no_core` to reduce the LTO products is small enough. | ||
#![no_core] | ||
|
||
extern crate no_builtins; | ||
extern crate foo; | ||
|
||
#[link(name = "c")] | ||
extern "C" {} | ||
|
||
#[start] | ||
fn main(_: isize, p: *const *const u8) -> isize { | ||
// Make sure the symbols are retained. | ||
unsafe { bar(*p as *mut u8, *p); } | ||
0 | ||
} | ||
|
||
#[no_mangle] | ||
#[inline(never)] | ||
pub unsafe extern "C" fn bar(dest: *mut u8, src: *const u8) { | ||
no_builtins::no_builtins(dest, src); | ||
// should call `@llvm.memcpy` | ||
foo::memcpy(dest, src, 1024); | ||
} | ||
|
||
fn main() {} | ||
#[lang = "eh_personality"] | ||
fn eh_personality() {} |
Oops, something went wrong.