Skip to content
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

Add TargetOption::force_pic_relocation_model and use it for mips64 #49508

Closed
Closed
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
3 changes: 3 additions & 0 deletions src/librustc_back/target/mips64_unknown_linux_gnuabi64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ pub fn target() -> TargetResult {
// see #36994
exe_allocation_crate: None,

// see #49421
force_pic_relocation_model: true,

..super::linux_base::opts()
},
})
Expand Down
3 changes: 3 additions & 0 deletions src/librustc_back/target/mips64el_unknown_linux_gnuabi64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ pub fn target() -> TargetResult {
// see #36994
exe_allocation_crate: None,

// see #49421
force_pic_relocation_model: true,

..super::linux_base::opts()
},
})
Expand Down
6 changes: 6 additions & 0 deletions src/librustc_back/target/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,9 @@ pub struct TargetOptions {

/// Whether or not bitcode is embedded in object files
pub embed_bitcode: bool,

/// This target requires everything to be compiled with pic reloc model.
pub force_pic_relocation_model: bool,
}

impl Default for TargetOptions {
Expand Down Expand Up @@ -550,6 +553,7 @@ impl Default for TargetOptions {
codegen_backend: "llvm".to_string(),
default_hidden_visibility: false,
embed_bitcode: false,
force_pic_relocation_model: false,
}
}
}
Expand Down Expand Up @@ -799,6 +803,7 @@ impl Target {
key!(codegen_backend);
key!(default_hidden_visibility, bool);
key!(embed_bitcode, bool);
key!(force_pic_relocation_model, bool);

if let Some(array) = obj.find("abi-blacklist").and_then(Json::as_array) {
for name in array.iter().filter_map(|abi| abi.as_string()) {
Expand Down Expand Up @@ -1002,6 +1007,7 @@ impl ToJson for Target {
target_option_val!(codegen_backend);
target_option_val!(default_hidden_visibility);
target_option_val!(embed_bitcode);
target_option_val!(force_pic_relocation_model);

if default.abi_blacklist != self.options.abi_blacklist {
d.insert("abi-blacklist".to_string(), self.options.abi_blacklist.iter()
Expand Down
10 changes: 9 additions & 1 deletion src/librustc_trans/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,14 @@ fn get_llvm_opt_size(optimize: config::OptLevel) -> llvm::CodeGenOptSize {
}
}

fn get_llvm_reloc_model(sess: &Session) -> llvm::RelocMode {
if sess.target.target.options.force_pic_relocation_model {
llvm::RelocMode::PIC
} else {
get_reloc_model(sess)
}
}

pub fn create_target_machine(sess: &Session) -> TargetMachineRef {
target_machine_factory(sess)().unwrap_or_else(|err| {
llvm_err(sess.diagnostic(), err).raise()
Expand All @@ -163,7 +171,7 @@ pub fn create_target_machine(sess: &Session) -> TargetMachineRef {
pub fn target_machine_factory(sess: &Session)
-> Arc<Fn() -> Result<TargetMachineRef, String> + Send + Sync>
{
let reloc_model = get_reloc_model(sess);
let reloc_model = get_llvm_reloc_model(sess);

let opt_level = get_llvm_opt_level(sess.opts.optimize);
let use_softfp = sess.opts.cg.soft_float;
Expand Down