Skip to content

Add support for different relocation models #13340

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 6, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/etc/zsh/_rust
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ _rustc_opts_switches=(
--target'[Target triple cpu-manufacturer-kernel\[-os\] to compile]'
--target-cpu'[Select target processor (llc -mcpu=help for details)]'
--target-feature'[Target specific attributes (llc -mattr=help for details)]'
--relocation-model'[Relocation model (llc --help for details)]'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this the right format for the -C options?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so. I think this file is outdated. However, I preferred to add it anyway to keep track of the config options. (Certainly rustc -C help would be better)

{-v,--version}'[Print version info and exit]'
)
_rustc_opts_lint=(
Expand Down
15 changes: 14 additions & 1 deletion src/librustc/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,26 @@ pub mod write {
(sess.targ_cfg.os == abi::OsMacos &&
sess.targ_cfg.arch == abi::X86_64);

let reloc_model = match sess.opts.cg.relocation_model.as_slice() {
"pic" => lib::llvm::RelocPIC,
"static" => lib::llvm::RelocStatic,
"default" => lib::llvm::RelocDefault,
"dynamic-no-pic" => lib::llvm::RelocDynamicNoPic,
_ => {
sess.err(format!("{} is not a valid relocation mode",
sess.opts.cg.relocation_model));
sess.abort_if_errors();
return;
}
};

let tm = sess.targ_cfg.target_strs.target_triple.with_c_str(|t| {
sess.opts.cg.target_cpu.with_c_str(|cpu| {
target_feature(sess).with_c_str(|features| {
llvm::LLVMRustCreateTargetMachine(
t, cpu, features,
lib::llvm::CodeModelDefault,
lib::llvm::RelocPIC,
reloc_model,
opt_level,
true,
use_softfp,
Expand Down
2 changes: 2 additions & 0 deletions src/librustc/driver/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,8 @@ cgoptions!(
"prefer dynamic linking to static linking"),
no_integrated_as: bool = (false, parse_bool,
"use an external assembler rather than LLVM's integrated one"),
relocation_model: ~str = (~"pic", parse_string,
"choose the relocation model to use (llc -relocation-model for details)"),
)

// Seems out of place, but it uses session, so I'm putting it here
Expand Down
15 changes: 15 additions & 0 deletions src/test/run-make/relocation-model/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
-include ../tools.mk

all:
$(RUSTC) -C relocation-model=dynamic-no-pic foo.rs
$(call RUN,foo)

$(RUSTC) -C relocation-model=default foo.rs
$(call RUN,foo)

$(RUSTC) -C relocation-model=static foo.rs
$(call RUN,foo)

$(RUSTC) -C relocation-model=default --crate-type=dylib foo.rs
$(RUSTC) -C relocation-model=static --crate-type=dylib foo.rs
$(RUSTC) -C relocation-model=dynamic-no-pic --crate-type=dylib foo.rs
11 changes: 11 additions & 0 deletions src/test/run-make/relocation-model/foo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.

pub fn main() {}