-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
pie
as another relocation-model
value
- Loading branch information
Showing
11 changed files
with
147 additions
and
8 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 |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// revisions: x64 | ||
// assembly-output: emit-asm | ||
// [x64] compile-flags: --target x86_64-unknown-linux-gnu -Crelocation-model=pic | ||
// [x64] needs-llvm-components: x86 | ||
|
||
|
||
#![feature(no_core, lang_items)] | ||
#![no_core] | ||
#![crate_type="rlib"] | ||
|
||
#[lang = "sized"] | ||
trait Sized {} | ||
#[lang = "copy"] | ||
trait Copy {} | ||
|
||
// CHECK-LABEL: call_other_fn: | ||
// CHECK: {{(jmpq|callq)}} *other_fn@GOTPCREL(%rip) | ||
#[no_mangle] | ||
pub fn call_other_fn() -> u8 { | ||
unsafe { | ||
other_fn() | ||
} | ||
} | ||
|
||
// CHECK-LABEL: other_fn: | ||
// CHECK: callq *foreign_fn@GOTPCREL(%rip) | ||
#[no_mangle] | ||
#[inline(never)] | ||
pub fn other_fn() -> u8 { | ||
unsafe { | ||
foreign_fn() | ||
} | ||
} | ||
|
||
extern "C" {fn foreign_fn() -> u8;} |
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,38 @@ | ||
// revisions: x64 | ||
// assembly-output: emit-asm | ||
// [x64] compile-flags: --target x86_64-unknown-linux-gnu -Crelocation-model=pie | ||
// [x64] needs-llvm-components: x86 | ||
|
||
|
||
#![feature(no_core, lang_items)] | ||
#![no_core] | ||
#![crate_type="rlib"] | ||
|
||
#[lang = "sized"] | ||
trait Sized {} | ||
#[lang = "copy"] | ||
trait Copy {} | ||
|
||
// CHECK-LABEL: call_other_fn: | ||
// With PIE local functions are called "directly". | ||
// CHECK: {{(jmp|callq)}} other_fn | ||
#[no_mangle] | ||
pub fn call_other_fn() -> u8 { | ||
unsafe { | ||
other_fn() | ||
} | ||
} | ||
|
||
// CHECK-LABEL: other_fn: | ||
// External functions are still called through GOT, since we don't know if the symbol | ||
// is defined in the binary or in the shared library. | ||
// CHECK: callq *foreign_fn@GOTPCREL(%rip) | ||
#[no_mangle] | ||
#[inline(never)] | ||
pub fn other_fn() -> u8 { | ||
unsafe { | ||
foreign_fn() | ||
} | ||
} | ||
|
||
extern "C" {fn foreign_fn() -> u8;} |
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,16 @@ | ||
// compile-flags: -C relocation-model=pic | ||
|
||
#![crate_type = "rlib"] | ||
|
||
// CHECK: define i8 @call_foreign_fn() | ||
#[no_mangle] | ||
pub fn call_foreign_fn() -> u8 { | ||
unsafe { | ||
foreign_fn() | ||
} | ||
} | ||
|
||
// CHECK: declare zeroext i8 @foreign_fn() | ||
extern "C" {fn foreign_fn() -> u8;} | ||
|
||
// CHECK: !{i32 7, !"PIC Level", i32 2} |
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,22 @@ | ||
// compile-flags: -C relocation-model=pie | ||
// only-x86_64-unknown-linux-gnu | ||
|
||
#![crate_type = "rlib"] | ||
|
||
// With PIE we know local functions cannot be interpositioned, we can mark them | ||
// as dso_local. | ||
// CHECK: define dso_local i8 @call_foreign_fn() | ||
#[no_mangle] | ||
pub fn call_foreign_fn() -> u8 { | ||
unsafe { | ||
foreign_fn() | ||
} | ||
} | ||
|
||
// External functions are still marked as non-dso_local, since we don't know if the symbol | ||
// is defined in the binary or in the shared library. | ||
// CHECK: declare zeroext i8 @foreign_fn() | ||
extern "C" {fn foreign_fn() -> u8;} | ||
|
||
// CHECK: !{i32 7, !"PIC Level", i32 2} | ||
// CHECK: !{i32 7, !"PIE Level", i32 2} |