Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
1798c1aa
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,发现更多精彩内容 >>
提交
1798c1aa
编写于
7月 14, 2016
作者:
J
Jan-Erik Rediger
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor determining of relocation model into methods
上级
1bc04472
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
41 addition
and
24 deletion
+41
-24
src/librustc_trans/back/write.rs
src/librustc_trans/back/write.rs
+3
-23
src/librustc_trans/context.rs
src/librustc_trans/context.rs
+38
-1
未找到文件。
src/librustc_trans/back/write.rs
浏览文件 @
1798c1aa
...
...
@@ -24,6 +24,7 @@
use
errors
::{
self
,
Handler
,
Level
,
DiagnosticBuilder
};
use
errors
::
emitter
::
Emitter
;
use
syntax_pos
::
MultiSpan
;
use
context
::{
is_pie_binary
,
get_reloc_model
};
use
std
::
collections
::
HashMap
;
use
std
::
ffi
::{
CStr
,
CString
};
...
...
@@ -154,32 +155,11 @@ fn get_llvm_opt_size(optimize: config::OptLevel) -> llvm::CodeGenOptSize {
}
pub
fn
create_target_machine
(
sess
:
&
Session
)
->
TargetMachineRef
{
let
reloc_model_arg
=
match
sess
.opts.cg.relocation_model
{
Some
(
ref
s
)
=>
&
s
[
..
],
None
=>
&
sess
.target.target.options.relocation_model
[
..
],
};
let
reloc_model
=
match
reloc_model_arg
{
"pic"
=>
llvm
::
RelocPIC
,
"static"
=>
llvm
::
RelocStatic
,
"default"
=>
llvm
::
RelocDefault
,
"dynamic-no-pic"
=>
llvm
::
RelocDynamicNoPic
,
_
=>
{
sess
.err
(
&
format!
(
"{:?} is not a valid relocation mode"
,
sess
.opts
.cg
.relocation_model
));
sess
.abort_if_errors
();
bug!
();
}
};
let
reloc_model
=
get_reloc_model
(
sess
);
let
opt_level
=
get_llvm_opt_level
(
sess
.opts.optimize
);
let
use_softfp
=
sess
.opts.cg.soft_float
;
let
any_library
=
sess
.crate_types
.borrow
()
.iter
()
.any
(|
ty
|
{
*
ty
!=
config
::
CrateTypeExecutable
});
let
ffunction_sections
=
sess
.target.target.options.function_sections
;
let
fdata_sections
=
ffunction_sections
;
...
...
@@ -220,7 +200,7 @@ pub fn create_target_machine(sess: &Session) -> TargetMachineRef {
reloc_model
,
opt_level
,
use_softfp
,
!
any_library
&&
reloc_model
==
llvm
::
RelocPIC
,
is_pie_binary
(
sess
)
,
ffunction_sections
,
fdata_sections
,
)
...
...
src/librustc_trans/context.rs
浏览文件 @
1798c1aa
...
...
@@ -34,6 +34,7 @@
use
rustc
::
ty
::{
self
,
Ty
,
TyCtxt
};
use
session
::
config
::
NoDebugInfo
;
use
session
::
Session
;
use
session
::
config
;
use
symbol_map
::
SymbolMap
;
use
util
::
sha2
::
Sha256
;
use
util
::
nodemap
::{
NodeMap
,
NodeSet
,
DefIdMap
,
FnvHashMap
,
FnvHashSet
};
...
...
@@ -322,6 +323,38 @@ fn next(&mut self) -> Option<(CrateContext<'a, 'tcx>, bool)> {
}
}
pub
fn
get_reloc_model
(
sess
:
&
Session
)
->
llvm
::
RelocMode
{
let
reloc_model_arg
=
match
sess
.opts.cg.relocation_model
{
Some
(
ref
s
)
=>
&
s
[
..
],
None
=>
&
sess
.target.target.options.relocation_model
[
..
],
};
match
reloc_model_arg
{
"pic"
=>
llvm
::
RelocPIC
,
"static"
=>
llvm
::
RelocStatic
,
"default"
=>
llvm
::
RelocDefault
,
"dynamic-no-pic"
=>
llvm
::
RelocDynamicNoPic
,
_
=>
{
sess
.err
(
&
format!
(
"{:?} is not a valid relocation mode"
,
sess
.opts
.cg
.relocation_model
));
sess
.abort_if_errors
();
bug!
();
}
}
}
fn
is_any_library
(
sess
:
&
Session
)
->
bool
{
sess
.crate_types
.borrow
()
.iter
()
.any
(|
ty
|
{
*
ty
!=
config
::
CrateTypeExecutable
})
}
pub
fn
is_pie_binary
(
sess
:
&
Session
)
->
bool
{
!
is_any_library
(
sess
)
&&
get_reloc_model
(
sess
)
==
llvm
::
RelocPIC
}
unsafe
fn
create_context_and_module
(
sess
:
&
Session
,
mod_name
:
&
str
)
->
(
ContextRef
,
ModuleRef
)
{
let
llcx
=
llvm
::
LLVMContextCreate
();
let
mod_name
=
CString
::
new
(
mod_name
)
.unwrap
();
...
...
@@ -352,7 +385,11 @@ unsafe fn create_context_and_module(sess: &Session, mod_name: &str) -> (ContextR
let
llvm_target
=
sess
.target.target.llvm_target
.as_bytes
();
let
llvm_target
=
CString
::
new
(
llvm_target
)
.unwrap
();
llvm
::
LLVMRustSetNormalizedTarget
(
llmod
,
llvm_target
.as_ptr
());
llvm
::
LLVMRustSetModulePIELevel
(
llmod
);
if
is_pie_binary
(
sess
)
{
llvm
::
LLVMRustSetModulePIELevel
(
llmod
);
}
(
llcx
,
llmod
)
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录