forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
Showing
8 changed files
with
105 additions
and
57 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
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 @_ZN11no_builtins11no_builtins17hcda8eeb3c587012fE | ||
CHECK-NEXT: call void @llvm.memcpy | ||
|
||
CHECK: define{{.*}} i32 @main | ||
CHECK: call void @bar | ||
|
||
CHECK: define{{.*}} void @_ZN3foo3foo17hfad400915e51b713E | ||
CHECK-NEXT: call void @llvm.memcpy | ||
|
||
CHECK: define{{.*}} void @_ZN11no_builtins11no_builtins17hcda8eeb3c587012fE | ||
CHECK-SAME: #[[ATTR:[0-9]+]] { | ||
CHECK: call void @_ZN3foo3foo17hfad400915e51b713E | ||
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,32 @@ | ||
#![feature(lang_items, no_core)] | ||
#![no_std] | ||
#![no_core] | ||
#![crate_type = "lib"] | ||
|
||
#[inline(never)] | ||
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() {} |
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,2 +1,14 @@ | ||
#![feature(lang_items, no_core)] | ||
#![no_std] | ||
#![no_core] | ||
#![crate_type = "lib"] | ||
#![no_builtins] | ||
|
||
extern crate foo; | ||
|
||
pub unsafe fn no_builtins(dest: *mut u8, src: *const u8) { | ||
// There should be no "undefined reference to `foo::foo'". | ||
foo::foo(dest, src); | ||
// should call `@memcpy` instead of `@llvm.memcpy`. | ||
foo::memcpy(dest, src, 1024); | ||
} |