Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
6615ee89
R
Rust
项目概览
int
/
Rust
11 个月 前同步成功
通知
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,发现更多精彩内容 >>
提交
6615ee89
编写于
3月 28, 2021
作者:
V
Vadim Petrochenkov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
linker: Use `--as-needed` by default when linker supports it
上级
afaf33dc
变更
21
隐藏空白更改
内联
并排
Showing
21 changed file
with
30 addition
and
94 deletion
+30
-94
compiler/rustc_codegen_ssa/src/back/link.rs
compiler/rustc_codegen_ssa/src/back/link.rs
+6
-0
compiler/rustc_codegen_ssa/src/back/linker.rs
compiler/rustc_codegen_ssa/src/back/linker.rs
+7
-0
compiler/rustc_target/src/spec/avr_gnu_base.rs
compiler/rustc_target/src/spec/avr_gnu_base.rs
+3
-16
compiler/rustc_target/src/spec/dragonfly_base.rs
compiler/rustc_target/src/spec/dragonfly_base.rs
+0
-5
compiler/rustc_target/src/spec/freebsd_base.rs
compiler/rustc_target/src/spec/freebsd_base.rs
+0
-5
compiler/rustc_target/src/spec/i686_unknown_netbsd.rs
compiler/rustc_target/src/spec/i686_unknown_netbsd.rs
+1
-1
compiler/rustc_target/src/spec/i686_wrs_vxworks.rs
compiler/rustc_target/src/spec/i686_wrs_vxworks.rs
+1
-1
compiler/rustc_target/src/spec/linux_base.rs
compiler/rustc_target/src/spec/linux_base.rs
+0
-8
compiler/rustc_target/src/spec/linux_kernel_base.rs
compiler/rustc_target/src/spec/linux_kernel_base.rs
+1
-4
compiler/rustc_target/src/spec/netbsd_base.rs
compiler/rustc_target/src/spec/netbsd_base.rs
+1
-14
compiler/rustc_target/src/spec/openbsd_base.rs
compiler/rustc_target/src/spec/openbsd_base.rs
+0
-5
compiler/rustc_target/src/spec/powerpc64_wrs_vxworks.rs
compiler/rustc_target/src/spec/powerpc64_wrs_vxworks.rs
+1
-1
compiler/rustc_target/src/spec/powerpc_unknown_netbsd.rs
compiler/rustc_target/src/spec/powerpc_unknown_netbsd.rs
+1
-1
compiler/rustc_target/src/spec/powerpc_wrs_vxworks.rs
compiler/rustc_target/src/spec/powerpc_wrs_vxworks.rs
+2
-2
compiler/rustc_target/src/spec/powerpc_wrs_vxworks_spe.rs
compiler/rustc_target/src/spec/powerpc_wrs_vxworks_spe.rs
+2
-2
compiler/rustc_target/src/spec/redox_base.rs
compiler/rustc_target/src/spec/redox_base.rs
+0
-8
compiler/rustc_target/src/spec/sparc64_unknown_netbsd.rs
compiler/rustc_target/src/spec/sparc64_unknown_netbsd.rs
+1
-1
compiler/rustc_target/src/spec/vxworks_base.rs
compiler/rustc_target/src/spec/vxworks_base.rs
+1
-17
compiler/rustc_target/src/spec/x86_64_fortanix_unknown_sgx.rs
...iler/rustc_target/src/spec/x86_64_fortanix_unknown_sgx.rs
+0
-1
compiler/rustc_target/src/spec/x86_64_unknown_netbsd.rs
compiler/rustc_target/src/spec/x86_64_unknown_netbsd.rs
+1
-1
compiler/rustc_target/src/spec/x86_64_wrs_vxworks.rs
compiler/rustc_target/src/spec/x86_64_wrs_vxworks.rs
+1
-1
未找到文件。
compiler/rustc_codegen_ssa/src/back/link.rs
浏览文件 @
6615ee89
...
...
@@ -1651,6 +1651,12 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
cmd
.add_eh_frame_header
();
}
// 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.
// Must be passed before any dynamic libraries.
cmd
.add_as_needed
();
// NO-OPT-OUT, OBJECT-FILES-NO
if
crt_objects_fallback
{
cmd
.no_crt_objects
();
...
...
compiler/rustc_codegen_ssa/src/back/linker.rs
浏览文件 @
6615ee89
...
...
@@ -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_as_needed
(
&
mut
self
)
{}
fn
finalize
(
&
mut
self
);
}
...
...
@@ -641,6 +642,12 @@ fn linker_plugin_lto(&mut self) {
fn
add_eh_frame_header
(
&
mut
self
)
{
self
.linker_arg
(
"--eh-frame-hdr"
);
}
fn
add_as_needed
(
&
mut
self
)
{
if
self
.sess.target.linker_is_gnu
{
self
.linker_arg
(
"--as-needed"
);
}
}
}
pub
struct
MsvcLinker
<
'a
>
{
...
...
compiler/rustc_target/src/spec/avr_gnu_base.rs
浏览文件 @
6615ee89
...
...
@@ -21,22 +21,9 @@ pub fn target(target_cpu: String) -> Target {
has_rpath
:
false
,
position_independent_executables
:
false
,
eh_frame_header
:
false
,
pre_link_args
:
vec!
[(
LinkerFlavor
::
Gcc
,
vec!
[
format!
(
"-mmcu={}"
,
target_cpu
),
// We want to be able to strip as much executable code as possible
// from the linker command line, and this flag indicates to the
// linker that it can avoid linking in dynamic libraries that don't
// actually satisfy any symbols up to that point (as with many other
// resolutions the linker does). This option only applies to all
// following libraries so we're sure to pass it as one of the first
// arguments.
"-Wl,--as-needed"
.to_string
(),
],
)]
.into_iter
()
.collect
(),
pre_link_args
:
vec!
[(
LinkerFlavor
::
Gcc
,
vec!
[
format!
(
"-mmcu={}"
,
target_cpu
)])]
.into_iter
()
.collect
(),
late_link_args
:
vec!
[(
LinkerFlavor
::
Gcc
,
vec!
[
"-lgcc"
.to_owned
()])]
.into_iter
()
.collect
(),
...
...
compiler/rustc_target/src/spec/dragonfly_base.rs
浏览文件 @
6615ee89
...
...
@@ -5,11 +5,6 @@ pub fn opts() -> TargetOptions {
args
.insert
(
LinkerFlavor
::
Gcc
,
vec!
[
// GNU-style linkers will use this to omit linking to libraries
// which don't actually fulfill any relocations, but only for
// libraries which follow this flag. Thus, use it before
// specifying libraries to link to.
"-Wl,--as-needed"
.to_string
(),
// Always enable NX protection when it is available
"-Wl,-z,noexecstack"
.to_string
(),
],
...
...
compiler/rustc_target/src/spec/freebsd_base.rs
浏览文件 @
6615ee89
...
...
@@ -5,11 +5,6 @@ pub fn opts() -> TargetOptions {
args
.insert
(
LinkerFlavor
::
Gcc
,
vec!
[
// GNU-style linkers will use this to omit linking to libraries
// which don't actually fulfill any relocations, but only for
// libraries which follow this flag. Thus, use it before
// specifying libraries to link to.
"-Wl,--as-needed"
.to_string
(),
// Always enable NX protection when it is available
"-Wl,-z,noexecstack"
.to_string
(),
],
...
...
compiler/rustc_target/src/spec/i686_unknown_netbsd.rs
浏览文件 @
6615ee89
...
...
@@ -4,7 +4,7 @@ pub fn target() -> Target {
let
mut
base
=
super
::
netbsd_base
::
opts
();
base
.cpu
=
"pentium4"
.to_string
();
base
.max_atomic_width
=
Some
(
64
);
base
.pre_link_args
.
get_mut
(
&
LinkerFlavor
::
Gcc
)
.unwrap
()
.push
(
"-m32"
.to_string
());
base
.pre_link_args
.
entry
(
LinkerFlavor
::
Gcc
)
.or_default
()
.push
(
"-m32"
.to_string
());
base
.stack_probes
=
StackProbeType
::
InlineOrCall
{
min_llvm_version_for_inline
:
(
11
,
0
,
1
)
};
Target
{
...
...
compiler/rustc_target/src/spec/i686_wrs_vxworks.rs
浏览文件 @
6615ee89
...
...
@@ -4,7 +4,7 @@ pub fn target() -> Target {
let
mut
base
=
super
::
vxworks_base
::
opts
();
base
.cpu
=
"pentium4"
.to_string
();
base
.max_atomic_width
=
Some
(
64
);
base
.pre_link_args
.
get_mut
(
&
LinkerFlavor
::
Gcc
)
.unwrap
()
.push
(
"-m32"
.to_string
());
base
.pre_link_args
.
entry
(
LinkerFlavor
::
Gcc
)
.or_default
()
.push
(
"-m32"
.to_string
());
base
.stack_probes
=
StackProbeType
::
InlineOrCall
{
min_llvm_version_for_inline
:
(
11
,
0
,
1
)
};
Target
{
...
...
compiler/rustc_target/src/spec/linux_base.rs
浏览文件 @
6615ee89
...
...
@@ -5,14 +5,6 @@ pub fn opts() -> TargetOptions {
args
.insert
(
LinkerFlavor
::
Gcc
,
vec!
[
// We want to be able to strip as much executable code as possible
// from the linker command line, and this flag indicates to the
// linker that it can avoid linking in dynamic libraries that don't
// actually satisfy any symbols up to that point (as with many other
// resolutions the linker does). This option only applies to all
// following libraries so we're sure to pass it as one of the first
// arguments.
"-Wl,--as-needed"
.to_string
(),
// Always enable NX protection when it is available
"-Wl,-z,noexecstack"
.to_string
(),
],
...
...
compiler/rustc_target/src/spec/linux_kernel_base.rs
浏览文件 @
6615ee89
...
...
@@ -4,10 +4,7 @@
pub
fn
opts
()
->
TargetOptions
{
let
mut
pre_link_args
=
LinkArgs
::
new
();
pre_link_args
.insert
(
LinkerFlavor
::
Gcc
,
vec!
[
"-Wl,--as-needed"
.to_string
(),
"-Wl,-z,noexecstack"
.to_string
()],
);
pre_link_args
.insert
(
LinkerFlavor
::
Gcc
,
vec!
[
"-Wl,-z,noexecstack"
.to_string
()]);
TargetOptions
{
env
:
"gnu"
.to_string
(),
...
...
compiler/rustc_target/src/spec/netbsd_base.rs
浏览文件 @
6615ee89
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!
[
// GNU-style linkers will use this to omit linking to libraries
// which don't actually fulfill any relocations, but only for
// libraries which follow this flag. Thus, use it before
// specifying libraries to link to.
"-Wl,--as-needed"
.to_string
(),
],
);
TargetOptions
{
os
:
"netbsd"
.to_string
(),
dynamic_linking
:
true
,
...
...
@@ -21,7 +9,6 @@ pub fn opts() -> TargetOptions {
linker_is_gnu
:
true
,
no_default_libraries
:
false
,
has_rpath
:
true
,
pre_link_args
:
args
,
position_independent_executables
:
true
,
relro_level
:
RelroLevel
::
Full
,
use_ctors_section
:
true
,
...
...
compiler/rustc_target/src/spec/openbsd_base.rs
浏览文件 @
6615ee89
...
...
@@ -5,11 +5,6 @@ pub fn opts() -> TargetOptions {
args
.insert
(
LinkerFlavor
::
Gcc
,
vec!
[
// GNU-style linkers will use this to omit linking to libraries
// which don't actually fulfill any relocations, but only for
// libraries which follow this flag. Thus, use it before
// specifying libraries to link to.
"-Wl,--as-needed"
.to_string
(),
// Always enable NX protection when it is available
"-Wl,-z,noexecstack"
.to_string
(),
],
...
...
compiler/rustc_target/src/spec/powerpc64_wrs_vxworks.rs
浏览文件 @
6615ee89
...
...
@@ -4,7 +4,7 @@
pub
fn
target
()
->
Target
{
let
mut
base
=
super
::
vxworks_base
::
opts
();
base
.cpu
=
"ppc64"
.to_string
();
base
.pre_link_args
.
get_mut
(
&
LinkerFlavor
::
Gcc
)
.unwrap
()
.push
(
"-m64"
.to_string
());
base
.pre_link_args
.
entry
(
LinkerFlavor
::
Gcc
)
.or_default
()
.push
(
"-m64"
.to_string
());
base
.max_atomic_width
=
Some
(
64
);
Target
{
...
...
compiler/rustc_target/src/spec/powerpc_unknown_netbsd.rs
浏览文件 @
6615ee89
...
...
@@ -3,7 +3,7 @@
pub
fn
target
()
->
Target
{
let
mut
base
=
super
::
netbsd_base
::
opts
();
base
.pre_link_args
.
get_mut
(
&
LinkerFlavor
::
Gcc
)
.unwrap
()
.push
(
"-m32"
.to_string
());
base
.pre_link_args
.
entry
(
LinkerFlavor
::
Gcc
)
.or_default
()
.push
(
"-m32"
.to_string
());
base
.max_atomic_width
=
Some
(
32
);
Target
{
...
...
compiler/rustc_target/src/spec/powerpc_wrs_vxworks.rs
浏览文件 @
6615ee89
...
...
@@ -3,8 +3,8 @@
pub
fn
target
()
->
Target
{
let
mut
base
=
super
::
vxworks_base
::
opts
();
base
.pre_link_args
.
get_mut
(
&
LinkerFlavor
::
Gcc
)
.unwrap
()
.push
(
"-m32"
.to_string
());
base
.pre_link_args
.
get_mut
(
&
LinkerFlavor
::
Gcc
)
.unwrap
()
.push
(
"--secure-plt"
.to_string
());
base
.pre_link_args
.
entry
(
LinkerFlavor
::
Gcc
)
.or_default
()
.push
(
"-m32"
.to_string
());
base
.pre_link_args
.
entry
(
LinkerFlavor
::
Gcc
)
.or_default
()
.push
(
"--secure-plt"
.to_string
());
base
.max_atomic_width
=
Some
(
32
);
Target
{
...
...
compiler/rustc_target/src/spec/powerpc_wrs_vxworks_spe.rs
浏览文件 @
6615ee89
...
...
@@ -3,8 +3,8 @@
pub
fn
target
()
->
Target
{
let
mut
base
=
super
::
vxworks_base
::
opts
();
base
.pre_link_args
.
get_mut
(
&
LinkerFlavor
::
Gcc
)
.unwrap
()
.push
(
"-mspe"
.to_string
());
base
.pre_link_args
.
get_mut
(
&
LinkerFlavor
::
Gcc
)
.unwrap
()
.push
(
"--secure-plt"
.to_string
());
base
.pre_link_args
.
entry
(
LinkerFlavor
::
Gcc
)
.or_default
()
.push
(
"-mspe"
.to_string
());
base
.pre_link_args
.
entry
(
LinkerFlavor
::
Gcc
)
.or_default
()
.push
(
"--secure-plt"
.to_string
());
base
.max_atomic_width
=
Some
(
32
);
Target
{
...
...
compiler/rustc_target/src/spec/redox_base.rs
浏览文件 @
6615ee89
...
...
@@ -5,14 +5,6 @@ pub fn opts() -> TargetOptions {
args
.insert
(
LinkerFlavor
::
Gcc
,
vec!
[
// We want to be able to strip as much executable code as possible
// from the linker command line, and this flag indicates to the
// linker that it can avoid linking in dynamic libraries that don't
// actually satisfy any symbols up to that point (as with many other
// resolutions the linker does). This option only applies to all
// following libraries so we're sure to pass it as one of the first
// arguments.
"-Wl,--as-needed"
.to_string
(),
// Always enable NX protection when it is available
"-Wl,-z,noexecstack"
.to_string
(),
],
...
...
compiler/rustc_target/src/spec/sparc64_unknown_netbsd.rs
浏览文件 @
6615ee89
...
...
@@ -4,7 +4,7 @@
pub
fn
target
()
->
Target
{
let
mut
base
=
super
::
netbsd_base
::
opts
();
base
.cpu
=
"v9"
.to_string
();
base
.pre_link_args
.
get_mut
(
&
LinkerFlavor
::
Gcc
)
.unwrap
()
.push
(
"-m64"
.to_string
());
base
.pre_link_args
.
entry
(
LinkerFlavor
::
Gcc
)
.or_default
()
.push
(
"-m64"
.to_string
());
base
.max_atomic_width
=
Some
(
64
);
Target
{
...
...
compiler/rustc_target/src/spec/vxworks_base.rs
浏览文件 @
6615ee89
use
crate
::
spec
::
{
LinkArgs
,
LinkerFlavor
,
TargetOptions
}
;
use
crate
::
spec
::
TargetOptions
;
pub
fn
opts
()
->
TargetOptions
{
let
mut
args
=
LinkArgs
::
new
();
args
.insert
(
LinkerFlavor
::
Gcc
,
vec!
[
// We want to be able to strip as much executable code as possible
// from the linker command line, and this flag indicates to the
// linker that it can avoid linking in dynamic libraries that don't
// actually satisfy any symbols up to that point (as with many other
// resolutions the linker does). This option only applies to all
// following libraries so we're sure to pass it as one of the first
// arguments.
"-Wl,--as-needed"
.to_string
(),
],
);
TargetOptions
{
os
:
"vxworks"
.to_string
(),
env
:
"gnu"
.to_string
(),
...
...
@@ -27,7 +12,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
:
false
,
has_elf_tls
:
true
,
crt_static_default
:
true
,
...
...
compiler/rustc_target/src/spec/x86_64_fortanix_unknown_sgx.rs
浏览文件 @
6615ee89
...
...
@@ -4,7 +4,6 @@
pub
fn
target
()
->
Target
{
const
PRE_LINK_ARGS
:
&
[
&
str
]
=
&
[
"--as-needed"
,
"-z"
,
"noexecstack"
,
"-e"
,
...
...
compiler/rustc_target/src/spec/x86_64_unknown_netbsd.rs
浏览文件 @
6615ee89
...
...
@@ -4,7 +4,7 @@ pub fn target() -> Target {
let
mut
base
=
super
::
netbsd_base
::
opts
();
base
.cpu
=
"x86-64"
.to_string
();
base
.max_atomic_width
=
Some
(
64
);
base
.pre_link_args
.
get_mut
(
&
LinkerFlavor
::
Gcc
)
.unwrap
()
.push
(
"-m64"
.to_string
());
base
.pre_link_args
.
entry
(
LinkerFlavor
::
Gcc
)
.or_default
()
.push
(
"-m64"
.to_string
());
base
.stack_probes
=
StackProbeType
::
InlineOrCall
{
min_llvm_version_for_inline
:
(
11
,
0
,
1
)
};
Target
{
...
...
compiler/rustc_target/src/spec/x86_64_wrs_vxworks.rs
浏览文件 @
6615ee89
...
...
@@ -4,7 +4,7 @@ pub fn target() -> Target {
let
mut
base
=
super
::
vxworks_base
::
opts
();
base
.cpu
=
"x86-64"
.to_string
();
base
.max_atomic_width
=
Some
(
64
);
base
.pre_link_args
.
get_mut
(
&
LinkerFlavor
::
Gcc
)
.unwrap
()
.push
(
"-m64"
.to_string
());
base
.pre_link_args
.
entry
(
LinkerFlavor
::
Gcc
)
.or_default
()
.push
(
"-m64"
.to_string
());
base
.stack_probes
=
StackProbeType
::
InlineOrCall
{
min_llvm_version_for_inline
:
(
11
,
0
,
1
)
};
base
.disable_redzone
=
true
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录