Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
cc5392e7
R
Rust
项目概览
int
/
Rust
接近 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
cc5392e7
编写于
3月 28, 2021
作者:
V
Vadim Petrochenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
linker: Use data execution prevention options by default when linker supports them
上级
4a20eb6a
变更
11
隐藏空白更改
内联
并排
Showing
11 changed file
with
23 addition
and
73 deletion
+23
-73
compiler/rustc_codegen_ssa/src/back/link.rs
compiler/rustc_codegen_ssa/src/back/link.rs
+4
-0
compiler/rustc_codegen_ssa/src/back/linker.rs
compiler/rustc_codegen_ssa/src/back/linker.rs
+13
-0
compiler/rustc_target/src/spec/dragonfly_base.rs
compiler/rustc_target/src/spec/dragonfly_base.rs
+1
-11
compiler/rustc_target/src/spec/freebsd_base.rs
compiler/rustc_target/src/spec/freebsd_base.rs
+1
-11
compiler/rustc_target/src/spec/linux_base.rs
compiler/rustc_target/src/spec/linux_base.rs
+1
-11
compiler/rustc_target/src/spec/linux_kernel_base.rs
compiler/rustc_target/src/spec/linux_kernel_base.rs
+1
-7
compiler/rustc_target/src/spec/msvc_base.rs
compiler/rustc_target/src/spec/msvc_base.rs
+0
-7
compiler/rustc_target/src/spec/openbsd_base.rs
compiler/rustc_target/src/spec/openbsd_base.rs
+1
-11
compiler/rustc_target/src/spec/redox_base.rs
compiler/rustc_target/src/spec/redox_base.rs
+1
-11
compiler/rustc_target/src/spec/windows_gnu_base.rs
compiler/rustc_target/src/spec/windows_gnu_base.rs
+0
-2
compiler/rustc_target/src/spec/x86_64_fortanix_unknown_sgx.rs
...iler/rustc_target/src/spec/x86_64_fortanix_unknown_sgx.rs
+0
-2
未找到文件。
compiler/rustc_codegen_ssa/src/back/link.rs
浏览文件 @
cc5392e7
...
...
@@ -1651,6 +1651,10 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
cmd
.add_eh_frame_header
();
}
// NO-OPT-OUT, OBJECT-FILES-NO, AUDIT-ORDER
// Make the binary compatible with data execution prevention schemes.
cmd
.add_no_exec
();
// NO-OPT-OUT, OBJECT-FILES-NO
// Avoid linking to dynamic libraries unless they satisfy some undefined symbols
// at the point at which they are specified on the command line.
...
...
compiler/rustc_codegen_ssa/src/back/linker.rs
浏览文件 @
cc5392e7
...
...
@@ -130,6 +130,7 @@ pub trait Linker {
fn
group_end
(
&
mut
self
);
fn
linker_plugin_lto
(
&
mut
self
);
fn
add_eh_frame_header
(
&
mut
self
)
{}
fn
add_no_exec
(
&
mut
self
)
{}
fn
add_as_needed
(
&
mut
self
)
{}
fn
finalize
(
&
mut
self
);
}
...
...
@@ -643,6 +644,14 @@ fn add_eh_frame_header(&mut self) {
self
.linker_arg
(
"--eh-frame-hdr"
);
}
fn
add_no_exec
(
&
mut
self
)
{
if
self
.sess.target.is_like_windows
{
self
.linker_arg
(
"--nxcompat"
);
}
else
if
self
.sess.target.linker_is_gnu
{
self
.linker_arg
(
"-znoexecstack"
);
}
}
fn
add_as_needed
(
&
mut
self
)
{
if
self
.sess.target.linker_is_gnu
{
self
.linker_arg
(
"--as-needed"
);
...
...
@@ -885,6 +894,10 @@ fn group_end(&mut self) {}
fn
linker_plugin_lto
(
&
mut
self
)
{
// Do nothing
}
fn
add_no_exec
(
&
mut
self
)
{
self
.cmd
.arg
(
"/NXCOMPAT"
);
}
}
pub
struct
EmLinker
<
'a
>
{
...
...
compiler/rustc_target/src/spec/dragonfly_base.rs
浏览文件 @
cc5392e7
use
crate
::
spec
::{
LinkArgs
,
LinkerFlavor
,
RelroLevel
,
TargetOptions
};
use
crate
::
spec
::{
RelroLevel
,
TargetOptions
};
pub
fn
opts
()
->
TargetOptions
{
let
mut
args
=
LinkArgs
::
new
();
args
.insert
(
LinkerFlavor
::
Gcc
,
vec!
[
// Always enable NX protection when it is available
"-Wl,-z,noexecstack"
.to_string
(),
],
);
TargetOptions
{
os
:
"dragonfly"
.to_string
(),
dynamic_linking
:
true
,
...
...
@@ -17,7 +8,6 @@ pub fn opts() -> TargetOptions {
os_family
:
Some
(
"unix"
.to_string
()),
linker_is_gnu
:
true
,
has_rpath
:
true
,
pre_link_args
:
args
,
position_independent_executables
:
true
,
relro_level
:
RelroLevel
::
Full
,
dwarf_version
:
Some
(
2
),
...
...
compiler/rustc_target/src/spec/freebsd_base.rs
浏览文件 @
cc5392e7
use
crate
::
spec
::{
LinkArgs
,
LinkerFlavor
,
RelroLevel
,
TargetOptions
};
use
crate
::
spec
::{
RelroLevel
,
TargetOptions
};
pub
fn
opts
()
->
TargetOptions
{
let
mut
args
=
LinkArgs
::
new
();
args
.insert
(
LinkerFlavor
::
Gcc
,
vec!
[
// Always enable NX protection when it is available
"-Wl,-z,noexecstack"
.to_string
(),
],
);
TargetOptions
{
os
:
"freebsd"
.to_string
(),
dynamic_linking
:
true
,
...
...
@@ -17,7 +8,6 @@ pub fn opts() -> TargetOptions {
os_family
:
Some
(
"unix"
.to_string
()),
linker_is_gnu
:
true
,
has_rpath
:
true
,
pre_link_args
:
args
,
position_independent_executables
:
true
,
eliminate_frame_pointer
:
false
,
// FIXME 43575
relro_level
:
RelroLevel
::
Full
,
...
...
compiler/rustc_target/src/spec/linux_base.rs
浏览文件 @
cc5392e7
use
crate
::
spec
::{
LinkArgs
,
LinkerFlavor
,
RelroLevel
,
TargetOptions
};
use
crate
::
spec
::{
RelroLevel
,
TargetOptions
};
pub
fn
opts
()
->
TargetOptions
{
let
mut
args
=
LinkArgs
::
new
();
args
.insert
(
LinkerFlavor
::
Gcc
,
vec!
[
// Always enable NX protection when it is available
"-Wl,-z,noexecstack"
.to_string
(),
],
);
TargetOptions
{
os
:
"linux"
.to_string
(),
dynamic_linking
:
true
,
...
...
@@ -17,7 +8,6 @@ pub fn opts() -> TargetOptions {
os_family
:
Some
(
"unix"
.to_string
()),
linker_is_gnu
:
true
,
has_rpath
:
true
,
pre_link_args
:
args
,
position_independent_executables
:
true
,
relro_level
:
RelroLevel
::
Full
,
has_elf_tls
:
true
,
...
...
compiler/rustc_target/src/spec/linux_kernel_base.rs
浏览文件 @
cc5392e7
use
crate
::
spec
::{
LinkArgs
,
LinkerFlavor
,
PanicStrategy
,
RelocModel
,
RelroLevel
,
StackProbeType
,
TargetOptions
,
};
use
crate
::
spec
::{
PanicStrategy
,
RelocModel
,
RelroLevel
,
StackProbeType
,
TargetOptions
};
pub
fn
opts
()
->
TargetOptions
{
let
mut
pre_link_args
=
LinkArgs
::
new
();
pre_link_args
.insert
(
LinkerFlavor
::
Gcc
,
vec!
[
"-Wl,-z,noexecstack"
.to_string
()]);
TargetOptions
{
env
:
"gnu"
.to_string
(),
disable_redzone
:
true
,
...
...
@@ -17,7 +12,6 @@ pub fn opts() -> TargetOptions {
needs_plt
:
true
,
relro_level
:
RelroLevel
::
Full
,
relocation_model
:
RelocModel
::
Static
,
pre_link_args
,
..
Default
::
default
()
}
...
...
compiler/rustc_target/src/spec/msvc_base.rs
浏览文件 @
cc5392e7
...
...
@@ -5,13 +5,6 @@ pub fn opts() -> TargetOptions {
// Suppress the verbose logo and authorship debugging output, which would needlessly
// clog any log files.
"/NOLOGO"
.to_string
(),
// Tell the compiler that non-code sections can be marked as non-executable,
// including stack pages.
// UEFI is fully compatible to non-executable data pages.
// In fact, firmware might enforce this, so we better let the linker know about this,
// so it will fail if the compiler ever tries placing code on the stack
// (e.g., trampoline constructs and alike).
"/NXCOMPAT"
.to_string
(),
];
let
mut
pre_link_args
=
LinkArgs
::
new
();
pre_link_args
.insert
(
LinkerFlavor
::
Msvc
,
pre_link_args_msvc
.clone
());
...
...
compiler/rustc_target/src/spec/openbsd_base.rs
浏览文件 @
cc5392e7
use
crate
::
spec
::{
LinkArgs
,
LinkerFlavor
,
RelroLevel
,
TargetOptions
};
use
crate
::
spec
::{
RelroLevel
,
TargetOptions
};
pub
fn
opts
()
->
TargetOptions
{
let
mut
args
=
LinkArgs
::
new
();
args
.insert
(
LinkerFlavor
::
Gcc
,
vec!
[
// Always enable NX protection when it is available
"-Wl,-z,noexecstack"
.to_string
(),
],
);
TargetOptions
{
os
:
"openbsd"
.to_string
(),
dynamic_linking
:
true
,
...
...
@@ -18,7 +9,6 @@ pub fn opts() -> TargetOptions {
linker_is_gnu
:
true
,
has_rpath
:
true
,
abi_return_struct_as_int
:
true
,
pre_link_args
:
args
,
position_independent_executables
:
true
,
eliminate_frame_pointer
:
false
,
// FIXME 43575
relro_level
:
RelroLevel
::
Full
,
...
...
compiler/rustc_target/src/spec/redox_base.rs
浏览文件 @
cc5392e7
use
crate
::
spec
::{
LinkArgs
,
LinkerFlavor
,
RelroLevel
,
TargetOptions
};
use
crate
::
spec
::{
RelroLevel
,
TargetOptions
};
pub
fn
opts
()
->
TargetOptions
{
let
mut
args
=
LinkArgs
::
new
();
args
.insert
(
LinkerFlavor
::
Gcc
,
vec!
[
// Always enable NX protection when it is available
"-Wl,-z,noexecstack"
.to_string
(),
],
);
TargetOptions
{
os
:
"redox"
.to_string
(),
env
:
"relibc"
.to_string
(),
...
...
@@ -18,7 +9,6 @@ pub fn opts() -> TargetOptions {
os_family
:
Some
(
"unix"
.to_string
()),
linker_is_gnu
:
true
,
has_rpath
:
true
,
pre_link_args
:
args
,
position_independent_executables
:
true
,
relro_level
:
RelroLevel
::
Full
,
has_elf_tls
:
true
,
...
...
compiler/rustc_target/src/spec/windows_gnu_base.rs
浏览文件 @
cc5392e7
...
...
@@ -9,8 +9,6 @@ pub fn opts() -> TargetOptions {
// Tell GCC to avoid linker plugins, because we are not bundling
// them with Windows installer, and Rust does its own LTO anyways.
"-fno-use-linker-plugin"
.to_string
(),
// Always enable DEP (NX bit) when it is available
"-Wl,--nxcompat"
.to_string
(),
// Enable ASLR
"-Wl,--dynamicbase"
.to_string
(),
// ASLR will rebase it anyway so leaving that option enabled only leads to confusion
...
...
compiler/rustc_target/src/spec/x86_64_fortanix_unknown_sgx.rs
浏览文件 @
cc5392e7
...
...
@@ -4,8 +4,6 @@
pub
fn
target
()
->
Target
{
const
PRE_LINK_ARGS
:
&
[
&
str
]
=
&
[
"-z"
,
"noexecstack"
,
"-e"
,
"elf_entry"
,
"-Bstatic"
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录