Collapse all uses of target.options.foo
into target.foo
with an eye on merging `TargetOptions` into `Target`. `TargetOptions` as a separate structure is mostly an implementation detail of `Target` construction, all its fields logically belong to `Target` and available from `Target` through `Deref` impls.
This commit is contained in:
parent
87a0997ef9
commit
bf66988aa1
48 changed files with 235 additions and 260 deletions
|
@ -7,10 +7,8 @@ use std::path::{Path, PathBuf};
|
|||
pub fn find_library(name: Symbol, search_paths: &[PathBuf], sess: &Session) -> PathBuf {
|
||||
// On Windows, static libraries sometimes show up as libfoo.a and other
|
||||
// times show up as foo.lib
|
||||
let oslibname = format!(
|
||||
"{}{}{}",
|
||||
sess.target.options.staticlib_prefix, name, sess.target.options.staticlib_suffix
|
||||
);
|
||||
let oslibname =
|
||||
format!("{}{}{}", sess.target.staticlib_prefix, name, sess.target.staticlib_suffix);
|
||||
let unixlibname = format!("lib{}.a", name);
|
||||
|
||||
for path in search_paths {
|
||||
|
|
|
@ -151,9 +151,7 @@ fn get_linker(
|
|||
Some(linker) if cfg!(windows) && linker.ends_with(".bat") => Command::bat_script(linker),
|
||||
_ => match flavor {
|
||||
LinkerFlavor::Lld(f) => Command::lld(linker, f),
|
||||
LinkerFlavor::Msvc
|
||||
if sess.opts.cg.linker.is_none() && sess.target.options.linker.is_none() =>
|
||||
{
|
||||
LinkerFlavor::Msvc if sess.opts.cg.linker.is_none() && sess.target.linker.is_none() => {
|
||||
Command::new(msvc_tool.as_ref().map(|t| t.path()).unwrap_or(linker))
|
||||
}
|
||||
_ => Command::new(linker),
|
||||
|
@ -197,7 +195,7 @@ fn get_linker(
|
|||
// PATH for the child.
|
||||
let mut new_path = sess.host_filesearch(PathKind::All).get_tools_search_paths(self_contained);
|
||||
let mut msvc_changed_path = false;
|
||||
if sess.target.options.is_like_msvc {
|
||||
if sess.target.is_like_msvc {
|
||||
if let Some(ref tool) = msvc_tool {
|
||||
cmd.args(tool.args());
|
||||
for &(ref k, ref v) in tool.env() {
|
||||
|
@ -365,7 +363,7 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>(
|
|||
// After adding all files to the archive, we need to update the
|
||||
// symbol table of the archive. This currently dies on macOS (see
|
||||
// #11162), and isn't necessary there anyway
|
||||
if !sess.target.options.is_like_osx {
|
||||
if !sess.target.is_like_osx {
|
||||
ab.update_symbols();
|
||||
}
|
||||
}
|
||||
|
@ -476,10 +474,10 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
|
|||
|
||||
linker::disable_localization(&mut cmd);
|
||||
|
||||
for &(ref k, ref v) in &sess.target.options.link_env {
|
||||
for &(ref k, ref v) in &sess.target.link_env {
|
||||
cmd.env(k, v);
|
||||
}
|
||||
for k in &sess.target.options.link_env_remove {
|
||||
for k in &sess.target.link_env_remove {
|
||||
cmd.env_remove(k);
|
||||
}
|
||||
|
||||
|
@ -515,7 +513,7 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
|
|||
// if the linker doesn't support -no-pie then it should not default to
|
||||
// linking executables as pie. Different versions of gcc seem to use
|
||||
// different quotes in the error message so don't check for them.
|
||||
if sess.target.options.linker_is_gnu
|
||||
if sess.target.linker_is_gnu
|
||||
&& flavor != LinkerFlavor::Ld
|
||||
&& (out.contains("unrecognized command line option")
|
||||
|| out.contains("unknown argument"))
|
||||
|
@ -535,7 +533,7 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
|
|||
|
||||
// Detect '-static-pie' used with an older version of gcc or clang not supporting it.
|
||||
// Fallback from '-static-pie' to '-static' in that case.
|
||||
if sess.target.options.linker_is_gnu
|
||||
if sess.target.linker_is_gnu
|
||||
&& flavor != LinkerFlavor::Ld
|
||||
&& (out.contains("unrecognized command line option")
|
||||
|| out.contains("unknown argument"))
|
||||
|
@ -548,7 +546,7 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
|
|||
);
|
||||
// Mirror `add_(pre,post)_link_objects` to replace CRT objects.
|
||||
let self_contained = crt_objects_fallback(sess, crate_type);
|
||||
let opts = &sess.target.options;
|
||||
let opts = &sess.target;
|
||||
let pre_objects = if self_contained {
|
||||
&opts.pre_link_objects_fallback
|
||||
} else {
|
||||
|
@ -670,7 +668,7 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
|
|||
// is not a Microsoft LNK error then suggest a way to fix or
|
||||
// install the Visual Studio build tools.
|
||||
if let Some(code) = prog.status.code() {
|
||||
if sess.target.options.is_like_msvc
|
||||
if sess.target.is_like_msvc
|
||||
&& flavor == LinkerFlavor::Msvc
|
||||
// Respect the command line override
|
||||
&& sess.opts.cg.linker.is_none()
|
||||
|
@ -741,7 +739,7 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
|
|||
|
||||
linker_error.emit();
|
||||
|
||||
if sess.target.options.is_like_msvc && linker_not_found {
|
||||
if sess.target.is_like_msvc && linker_not_found {
|
||||
sess.note_without_error(
|
||||
"the msvc targets depend on the msvc linker \
|
||||
but `link.exe` was not found",
|
||||
|
@ -758,7 +756,7 @@ fn link_natively<'a, B: ArchiveBuilder<'a>>(
|
|||
// On macOS, debuggers need this utility to get run to do some munging of
|
||||
// the symbols. Note, though, that if the object files are being preserved
|
||||
// for their debug information there's no need for us to run dsymutil.
|
||||
if sess.target.options.is_like_osx
|
||||
if sess.target.is_like_osx
|
||||
&& sess.opts.debuginfo != DebugInfo::None
|
||||
&& !preserve_objects_for_their_debuginfo(sess)
|
||||
{
|
||||
|
@ -775,9 +773,7 @@ fn link_sanitizers(sess: &Session, crate_type: CrateType, linker: &mut dyn Linke
|
|||
// executables only.
|
||||
let needs_runtime = match crate_type {
|
||||
CrateType::Executable => true,
|
||||
CrateType::Dylib | CrateType::Cdylib | CrateType::ProcMacro => {
|
||||
sess.target.options.is_like_osx
|
||||
}
|
||||
CrateType::Dylib | CrateType::Cdylib | CrateType::ProcMacro => sess.target.is_like_osx,
|
||||
CrateType::Rlib | CrateType::Staticlib => false,
|
||||
};
|
||||
|
||||
|
@ -846,7 +842,7 @@ pub fn ignored_for_lto(sess: &Session, info: &CrateInfo, cnum: CrateNum) -> bool
|
|||
// If our target enables builtin function lowering in LLVM then the
|
||||
// crates providing these functions don't participate in LTO (e.g.
|
||||
// no_builtins or compiler builtins crates).
|
||||
!sess.target.options.no_builtins
|
||||
!sess.target.no_builtins
|
||||
&& (info.compiler_builtins == Some(cnum) || info.is_no_builtins.contains(&cnum))
|
||||
}
|
||||
|
||||
|
@ -906,7 +902,7 @@ fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
|
|||
} else if stem == "link" || stem == "lld-link" {
|
||||
LinkerFlavor::Msvc
|
||||
} else if stem == "lld" || stem == "rust-lld" {
|
||||
LinkerFlavor::Lld(sess.target.options.lld_flavor)
|
||||
LinkerFlavor::Lld(sess.target.lld_flavor)
|
||||
} else {
|
||||
// fall back to the value in the target spec
|
||||
sess.target.linker_flavor
|
||||
|
@ -926,7 +922,7 @@ fn linker_and_flavor(sess: &Session) -> (PathBuf, LinkerFlavor) {
|
|||
|
||||
if let Some(ret) = infer_from(
|
||||
sess,
|
||||
sess.target.options.linker.clone().map(PathBuf::from),
|
||||
sess.target.linker.clone().map(PathBuf::from),
|
||||
Some(sess.target.linker_flavor),
|
||||
) {
|
||||
return ret;
|
||||
|
@ -962,7 +958,7 @@ fn preserve_objects_for_their_debuginfo(sess: &Session) -> bool {
|
|||
// Basically as a result this just means that if we're on OSX and we're
|
||||
// *not* running dsymutil then the object files are the only source of truth
|
||||
// for debug information, so we must preserve them.
|
||||
if sess.target.options.is_like_osx {
|
||||
if sess.target.is_like_osx {
|
||||
return !sess.opts.debugging_opts.run_dsymutil;
|
||||
}
|
||||
|
||||
|
@ -988,7 +984,7 @@ fn print_native_static_libs(sess: &Session, all_native_libs: &[NativeLib]) {
|
|||
NativeLibKind::StaticNoBundle
|
||||
| NativeLibKind::Dylib
|
||||
| NativeLibKind::Unspecified => {
|
||||
if sess.target.options.is_like_msvc {
|
||||
if sess.target.is_like_msvc {
|
||||
Some(format!("{}.lib", name))
|
||||
} else {
|
||||
Some(format!("-l{}", name))
|
||||
|
@ -1070,13 +1066,13 @@ fn exec_linker(
|
|||
let mut args = String::new();
|
||||
for arg in cmd2.take_args() {
|
||||
args.push_str(
|
||||
&Escape { arg: arg.to_str().unwrap(), is_like_msvc: sess.target.options.is_like_msvc }
|
||||
&Escape { arg: arg.to_str().unwrap(), is_like_msvc: sess.target.is_like_msvc }
|
||||
.to_string(),
|
||||
);
|
||||
args.push('\n');
|
||||
}
|
||||
let file = tmpdir.join("linker-arguments");
|
||||
let bytes = if sess.target.options.is_like_msvc {
|
||||
let bytes = if sess.target.is_like_msvc {
|
||||
let mut out = Vec::with_capacity((1 + args.len()) * 2);
|
||||
// start the stream with a UTF-16 BOM
|
||||
for c in std::iter::once(0xFEFF).chain(args.encode_utf16()) {
|
||||
|
@ -1192,7 +1188,7 @@ fn link_output_kind(sess: &Session, crate_type: CrateType) -> LinkOutputKind {
|
|||
};
|
||||
|
||||
// Adjust the output kind to target capabilities.
|
||||
let opts = &sess.target.options;
|
||||
let opts = &sess.target;
|
||||
let pic_exe_supported = opts.position_independent_executables;
|
||||
let static_pic_exe_supported = opts.static_position_independent_executables;
|
||||
let static_dylib_supported = opts.crt_static_allows_dylibs;
|
||||
|
@ -1233,7 +1229,7 @@ fn crt_objects_fallback(sess: &Session, crate_type: CrateType) -> bool {
|
|||
return self_contained;
|
||||
}
|
||||
|
||||
match sess.target.options.crt_objects_fallback {
|
||||
match sess.target.crt_objects_fallback {
|
||||
// FIXME: Find a better heuristic for "native musl toolchain is available",
|
||||
// based on host and linker path, for example.
|
||||
// (https://github.com/rust-lang/rust/pull/71769#issuecomment-626330237).
|
||||
|
@ -1256,7 +1252,7 @@ fn add_pre_link_objects(
|
|||
link_output_kind: LinkOutputKind,
|
||||
self_contained: bool,
|
||||
) {
|
||||
let opts = &sess.target.options;
|
||||
let opts = &sess.target;
|
||||
let objects =
|
||||
if self_contained { &opts.pre_link_objects_fallback } else { &opts.pre_link_objects };
|
||||
for obj in objects.get(&link_output_kind).iter().copied().flatten() {
|
||||
|
@ -1271,7 +1267,7 @@ fn add_post_link_objects(
|
|||
link_output_kind: LinkOutputKind,
|
||||
self_contained: bool,
|
||||
) {
|
||||
let opts = &sess.target.options;
|
||||
let opts = &sess.target;
|
||||
let objects =
|
||||
if self_contained { &opts.post_link_objects_fallback } else { &opts.post_link_objects };
|
||||
for obj in objects.get(&link_output_kind).iter().copied().flatten() {
|
||||
|
@ -1282,7 +1278,7 @@ fn add_post_link_objects(
|
|||
/// Add arbitrary "pre-link" args defined by the target spec or from command line.
|
||||
/// FIXME: Determine where exactly these args need to be inserted.
|
||||
fn add_pre_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
|
||||
if let Some(args) = sess.target.options.pre_link_args.get(&flavor) {
|
||||
if let Some(args) = sess.target.pre_link_args.get(&flavor) {
|
||||
cmd.args(args);
|
||||
}
|
||||
cmd.args(&sess.opts.debugging_opts.pre_link_args);
|
||||
|
@ -1290,9 +1286,9 @@ fn add_pre_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor)
|
|||
|
||||
/// Add a link script embedded in the target, if applicable.
|
||||
fn add_link_script(cmd: &mut dyn Linker, sess: &Session, tmpdir: &Path, crate_type: CrateType) {
|
||||
match (crate_type, &sess.target.options.link_script) {
|
||||
match (crate_type, &sess.target.link_script) {
|
||||
(CrateType::Cdylib | CrateType::Executable, Some(script)) => {
|
||||
if !sess.target.options.linker_is_gnu {
|
||||
if !sess.target.linker_is_gnu {
|
||||
sess.fatal("can only use link script when linking with GNU-like linker");
|
||||
}
|
||||
|
||||
|
@ -1335,15 +1331,15 @@ fn add_late_link_args(
|
|||
*ty == crate_type && list.iter().any(|&linkage| linkage == Linkage::Dynamic)
|
||||
});
|
||||
if any_dynamic_crate {
|
||||
if let Some(args) = sess.target.options.late_link_args_dynamic.get(&flavor) {
|
||||
if let Some(args) = sess.target.late_link_args_dynamic.get(&flavor) {
|
||||
cmd.args(args);
|
||||
}
|
||||
} else {
|
||||
if let Some(args) = sess.target.options.late_link_args_static.get(&flavor) {
|
||||
if let Some(args) = sess.target.late_link_args_static.get(&flavor) {
|
||||
cmd.args(args);
|
||||
}
|
||||
}
|
||||
if let Some(args) = sess.target.options.late_link_args.get(&flavor) {
|
||||
if let Some(args) = sess.target.late_link_args.get(&flavor) {
|
||||
cmd.args(args);
|
||||
}
|
||||
}
|
||||
|
@ -1351,7 +1347,7 @@ fn add_late_link_args(
|
|||
/// Add arbitrary "post-link" args defined by the target spec.
|
||||
/// FIXME: Determine where exactly these args need to be inserted.
|
||||
fn add_post_link_args(cmd: &mut dyn Linker, sess: &Session, flavor: LinkerFlavor) {
|
||||
if let Some(args) = sess.target.options.post_link_args.get(&flavor) {
|
||||
if let Some(args) = sess.target.post_link_args.get(&flavor) {
|
||||
cmd.args(args);
|
||||
}
|
||||
}
|
||||
|
@ -1453,7 +1449,7 @@ fn add_library_search_dirs(cmd: &mut dyn Linker, sess: &Session, self_contained:
|
|||
/// Add options making relocation sections in the produced ELF files read-only
|
||||
/// and suppressing lazy binding.
|
||||
fn add_relro_args(cmd: &mut dyn Linker, sess: &Session) {
|
||||
match sess.opts.debugging_opts.relro_level.unwrap_or(sess.target.options.relro_level) {
|
||||
match sess.opts.debugging_opts.relro_level.unwrap_or(sess.target.relro_level) {
|
||||
RelroLevel::Full => cmd.full_relro(),
|
||||
RelroLevel::Partial => cmd.partial_relro(),
|
||||
RelroLevel::Off => cmd.no_relro(),
|
||||
|
@ -1484,9 +1480,9 @@ fn add_rpath_args(
|
|||
let mut rpath_config = RPathConfig {
|
||||
used_crates: &codegen_results.crate_info.used_crates_dynamic,
|
||||
out_filename: out_filename.to_path_buf(),
|
||||
has_rpath: sess.target.options.has_rpath,
|
||||
is_like_osx: sess.target.options.is_like_osx,
|
||||
linker_is_gnu: sess.target.options.linker_is_gnu,
|
||||
has_rpath: sess.target.has_rpath,
|
||||
is_like_osx: sess.target.is_like_osx,
|
||||
linker_is_gnu: sess.target.linker_is_gnu,
|
||||
get_install_prefix_lib_path: &mut get_install_prefix_lib_path,
|
||||
};
|
||||
cmd.args(&rpath::get_rpath_flags(&mut rpath_config));
|
||||
|
@ -1528,7 +1524,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
|
|||
add_link_script(cmd, sess, tmpdir, crate_type);
|
||||
|
||||
// NO-OPT-OUT, OBJECT-FILES-NO, AUDIT-ORDER
|
||||
if sess.target.options.is_like_fuchsia && crate_type == CrateType::Executable {
|
||||
if sess.target.is_like_fuchsia && crate_type == CrateType::Executable {
|
||||
let prefix = if sess.opts.debugging_opts.sanitizer.contains(SanitizerSet::ADDRESS) {
|
||||
"asan/"
|
||||
} else {
|
||||
|
@ -1538,7 +1534,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
|
|||
}
|
||||
|
||||
// NO-OPT-OUT, OBJECT-FILES-NO, AUDIT-ORDER
|
||||
if sess.target.options.eh_frame_header {
|
||||
if sess.target.eh_frame_header {
|
||||
cmd.add_eh_frame_header();
|
||||
}
|
||||
|
||||
|
@ -1551,7 +1547,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
|
|||
add_pre_link_objects(cmd, sess, link_output_kind, crt_objects_fallback);
|
||||
|
||||
// NO-OPT-OUT, OBJECT-FILES-NO, AUDIT-ORDER
|
||||
if sess.target.options.is_like_emscripten {
|
||||
if sess.target.is_like_emscripten {
|
||||
cmd.arg("-s");
|
||||
cmd.arg(if sess.panic_strategy() == PanicStrategy::Abort {
|
||||
"DISABLE_EXCEPTION_CATCHING=1"
|
||||
|
@ -1579,7 +1575,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
|
|||
cmd.output_filename(out_filename);
|
||||
|
||||
// OBJECT-FILES-NO, AUDIT-ORDER
|
||||
if crate_type == CrateType::Executable && sess.target.options.is_like_windows {
|
||||
if crate_type == CrateType::Executable && sess.target.is_like_windows {
|
||||
if let Some(ref s) = codegen_results.windows_subsystem {
|
||||
cmd.subsystem(s);
|
||||
}
|
||||
|
@ -1623,7 +1619,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
|
|||
// OBJECT-FILES-NO, AUDIT-ORDER
|
||||
// We want to prevent the compiler from accidentally leaking in any system libraries,
|
||||
// so by default we tell linkers not to link to any default libraries.
|
||||
if !sess.opts.cg.default_linker_libraries && sess.target.options.no_default_libraries {
|
||||
if !sess.opts.cg.default_linker_libraries && sess.target.no_default_libraries {
|
||||
cmd.no_default_libraries();
|
||||
}
|
||||
|
||||
|
@ -1843,7 +1839,7 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
|
|||
|
||||
// Converts a library file-stem into a cc -l argument
|
||||
fn unlib<'a>(target: &Target, stem: &'a str) -> &'a str {
|
||||
if stem.starts_with("lib") && !target.options.is_like_windows { &stem[3..] } else { stem }
|
||||
if stem.starts_with("lib") && !target.is_like_windows { &stem[3..] } else { stem }
|
||||
}
|
||||
|
||||
// Adds the static "rlib" versions of all crates to the command line.
|
||||
|
@ -1938,7 +1934,7 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>(
|
|||
// though, so we let that object file slide.
|
||||
let skip_because_lto = are_upstream_rust_objects_already_included(sess)
|
||||
&& is_rust_object
|
||||
&& (sess.target.options.no_builtins
|
||||
&& (sess.target.no_builtins
|
||||
|| !codegen_results.crate_info.is_no_builtins.contains(&cnum));
|
||||
|
||||
if skip_because_cfg_say_so || skip_because_lto {
|
||||
|
|
|
@ -184,7 +184,7 @@ impl<'a> GccLinker<'a> {
|
|||
// * On OSX they have their own linker, not binutils'
|
||||
// * For WebAssembly the only functional linker is LLD, which doesn't
|
||||
// support hint flags
|
||||
!self.sess.target.options.is_like_osx && self.sess.target.arch != "wasm32"
|
||||
!self.sess.target.is_like_osx && self.sess.target.arch != "wasm32"
|
||||
}
|
||||
|
||||
// Some platforms take hints about whether a library is static or dynamic.
|
||||
|
@ -232,7 +232,7 @@ impl<'a> GccLinker<'a> {
|
|||
|
||||
fn build_dylib(&mut self, out_filename: &Path) {
|
||||
// On mac we need to tell the linker to let this library be rpathed
|
||||
if self.sess.target.options.is_like_osx {
|
||||
if self.sess.target.is_like_osx {
|
||||
self.cmd.arg("-dynamiclib");
|
||||
self.linker_arg("-dylib");
|
||||
|
||||
|
@ -248,7 +248,7 @@ impl<'a> GccLinker<'a> {
|
|||
}
|
||||
} else {
|
||||
self.cmd.arg("-shared");
|
||||
if self.sess.target.options.is_like_windows {
|
||||
if self.sess.target.is_like_windows {
|
||||
// The output filename already contains `dll_suffix` so
|
||||
// the resulting import library will have a name in the
|
||||
// form of libfoo.dll.a
|
||||
|
@ -256,9 +256,9 @@ impl<'a> GccLinker<'a> {
|
|||
out_filename.file_name().and_then(|file| file.to_str()).map(|file| {
|
||||
format!(
|
||||
"{}{}{}",
|
||||
self.sess.target.options.staticlib_prefix,
|
||||
self.sess.target.staticlib_prefix,
|
||||
file,
|
||||
self.sess.target.options.staticlib_suffix
|
||||
self.sess.target.staticlib_suffix
|
||||
)
|
||||
});
|
||||
if let Some(implib_name) = implib_name {
|
||||
|
@ -280,7 +280,7 @@ impl<'a> Linker for GccLinker<'a> {
|
|||
fn set_output_kind(&mut self, output_kind: LinkOutputKind, out_filename: &Path) {
|
||||
match output_kind {
|
||||
LinkOutputKind::DynamicNoPicExe => {
|
||||
if !self.is_ld && self.sess.target.options.linker_is_gnu {
|
||||
if !self.is_ld && self.sess.target.linker_is_gnu {
|
||||
self.cmd.arg("-no-pie");
|
||||
}
|
||||
}
|
||||
|
@ -291,7 +291,7 @@ impl<'a> Linker for GccLinker<'a> {
|
|||
LinkOutputKind::StaticNoPicExe => {
|
||||
// `-static` works for both gcc wrapper and ld.
|
||||
self.cmd.arg("-static");
|
||||
if !self.is_ld && self.sess.target.options.linker_is_gnu {
|
||||
if !self.is_ld && self.sess.target.linker_is_gnu {
|
||||
self.cmd.arg("-no-pie");
|
||||
}
|
||||
}
|
||||
|
@ -386,7 +386,7 @@ impl<'a> Linker for GccLinker<'a> {
|
|||
fn link_whole_staticlib(&mut self, lib: Symbol, search_path: &[PathBuf]) {
|
||||
self.hint_static();
|
||||
let target = &self.sess.target;
|
||||
if !target.options.is_like_osx {
|
||||
if !target.is_like_osx {
|
||||
self.linker_arg("--whole-archive").cmd.arg(format!("-l{}", lib));
|
||||
self.linker_arg("--no-whole-archive");
|
||||
} else {
|
||||
|
@ -400,7 +400,7 @@ impl<'a> Linker for GccLinker<'a> {
|
|||
|
||||
fn link_whole_rlib(&mut self, lib: &Path) {
|
||||
self.hint_static();
|
||||
if self.sess.target.options.is_like_osx {
|
||||
if self.sess.target.is_like_osx {
|
||||
self.linker_arg("-force_load");
|
||||
self.linker_arg(&lib);
|
||||
} else {
|
||||
|
@ -424,9 +424,9 @@ impl<'a> Linker for GccLinker<'a> {
|
|||
// -dead_strip can't be part of the pre_link_args because it's also used
|
||||
// for partial linking when using multiple codegen units (-r). So we
|
||||
// insert it here.
|
||||
if self.sess.target.options.is_like_osx {
|
||||
if self.sess.target.is_like_osx {
|
||||
self.linker_arg("-dead_strip");
|
||||
} else if self.sess.target.options.is_like_solaris {
|
||||
} else if self.sess.target.is_like_solaris {
|
||||
self.linker_arg("-zignore");
|
||||
|
||||
// If we're building a dylib, we don't use --gc-sections because LLVM
|
||||
|
@ -440,7 +440,7 @@ impl<'a> Linker for GccLinker<'a> {
|
|||
}
|
||||
|
||||
fn optimize(&mut self) {
|
||||
if !self.sess.target.options.linker_is_gnu {
|
||||
if !self.sess.target.linker_is_gnu {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -454,7 +454,7 @@ impl<'a> Linker for GccLinker<'a> {
|
|||
}
|
||||
|
||||
fn pgo_gen(&mut self) {
|
||||
if !self.sess.target.options.linker_is_gnu {
|
||||
if !self.sess.target.linker_is_gnu {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -503,8 +503,7 @@ impl<'a> Linker for GccLinker<'a> {
|
|||
|
||||
fn export_symbols(&mut self, tmpdir: &Path, crate_type: CrateType) {
|
||||
// Symbol visibility in object files typically takes care of this.
|
||||
if crate_type == CrateType::Executable
|
||||
&& self.sess.target.options.override_export_symbols.is_none()
|
||||
if crate_type == CrateType::Executable && self.sess.target.override_export_symbols.is_none()
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -513,7 +512,7 @@ impl<'a> Linker for GccLinker<'a> {
|
|||
// The object files have far more public symbols than we actually want to export,
|
||||
// so we hide them all here.
|
||||
|
||||
if !self.sess.target.options.limit_rdylib_exports {
|
||||
if !self.sess.target.limit_rdylib_exports {
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -521,13 +520,13 @@ impl<'a> Linker for GccLinker<'a> {
|
|||
return;
|
||||
}
|
||||
|
||||
let is_windows = self.sess.target.options.is_like_windows;
|
||||
let is_windows = self.sess.target.is_like_windows;
|
||||
let mut arg = OsString::new();
|
||||
let path = tmpdir.join(if is_windows { "list.def" } else { "list" });
|
||||
|
||||
debug!("EXPORTED SYMBOLS:");
|
||||
|
||||
if self.sess.target.options.is_like_osx {
|
||||
if self.sess.target.is_like_osx {
|
||||
// Write a plain, newline-separated list of symbols
|
||||
let res: io::Result<()> = try {
|
||||
let mut f = BufWriter::new(File::create(&path)?);
|
||||
|
@ -573,12 +572,12 @@ impl<'a> Linker for GccLinker<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
if self.sess.target.options.is_like_osx {
|
||||
if self.sess.target.is_like_osx {
|
||||
if !self.is_ld {
|
||||
arg.push("-Wl,")
|
||||
}
|
||||
arg.push("-exported_symbols_list,");
|
||||
} else if self.sess.target.options.is_like_solaris {
|
||||
} else if self.sess.target.is_like_solaris {
|
||||
if !self.is_ld {
|
||||
arg.push("-Wl,")
|
||||
}
|
||||
|
@ -1203,7 +1202,7 @@ impl<'a> Linker for WasmLd<'a> {
|
|||
}
|
||||
|
||||
fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<String> {
|
||||
if let Some(ref exports) = tcx.sess.target.options.override_export_symbols {
|
||||
if let Some(ref exports) = tcx.sess.target.override_export_symbols {
|
||||
return exports.clone();
|
||||
}
|
||||
|
||||
|
@ -1293,7 +1292,7 @@ impl<'a> Linker for PtxLinker<'a> {
|
|||
// Provide the linker with fallback to internal `target-cpu`.
|
||||
self.cmd.arg("--fallback-arch").arg(match self.sess.opts.cg.target_cpu {
|
||||
Some(ref s) => s,
|
||||
None => &self.sess.target.options.cpu,
|
||||
None => &self.sess.target.cpu,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -229,8 +229,7 @@ fn exported_symbols_provider_local(
|
|||
// needs to be exported.
|
||||
// However, on platforms that don't allow for Rust dylibs, having
|
||||
// external linkage is enough for monomorphization to be linked to.
|
||||
let need_visibility =
|
||||
tcx.sess.target.options.dynamic_linking && !tcx.sess.target.options.only_cdylib;
|
||||
let need_visibility = tcx.sess.target.dynamic_linking && !tcx.sess.target.only_cdylib;
|
||||
|
||||
let (_, cgus) = tcx.collect_and_partition_mono_items(LOCAL_CRATE);
|
||||
|
||||
|
|
|
@ -139,7 +139,7 @@ impl ModuleConfig {
|
|||
|
||||
let emit_obj = if !should_emit_obj {
|
||||
EmitObj::None
|
||||
} else if sess.target.options.obj_is_bitcode
|
||||
} else if sess.target.obj_is_bitcode
|
||||
|| (sess.opts.cg.linker_plugin_lto.enabled() && !no_builtins)
|
||||
{
|
||||
// This case is selected if the target uses objects as bitcode, or
|
||||
|
@ -221,11 +221,11 @@ impl ModuleConfig {
|
|||
false
|
||||
),
|
||||
emit_obj,
|
||||
bc_cmdline: sess.target.options.bitcode_llvm_cmdline.clone(),
|
||||
bc_cmdline: sess.target.bitcode_llvm_cmdline.clone(),
|
||||
|
||||
verify_llvm_ir: sess.verify_llvm_ir(),
|
||||
no_prepopulate_passes: sess.opts.cg.no_prepopulate_passes,
|
||||
no_builtins: no_builtins || sess.target.options.no_builtins,
|
||||
no_builtins: no_builtins || sess.target.no_builtins,
|
||||
|
||||
// Exclude metadata and allocator modules from time_passes output,
|
||||
// since they throw off the "LLVM passes" measurement.
|
||||
|
@ -252,7 +252,7 @@ impl ModuleConfig {
|
|||
.opts
|
||||
.debugging_opts
|
||||
.merge_functions
|
||||
.unwrap_or(sess.target.options.merge_functions)
|
||||
.unwrap_or(sess.target.merge_functions)
|
||||
{
|
||||
MergeFunctions::Disabled => false,
|
||||
MergeFunctions::Trampolines | MergeFunctions::Aliases => {
|
||||
|
@ -388,7 +388,7 @@ fn need_bitcode_in_object(sess: &Session) -> bool {
|
|||
let requested_for_rlib = sess.opts.cg.embed_bitcode
|
||||
&& sess.crate_types().contains(&CrateType::Rlib)
|
||||
&& sess.opts.output_types.contains_key(&OutputType::Exe);
|
||||
let forced_by_target = sess.target.options.forces_embed_bitcode;
|
||||
let forced_by_target = sess.target.forces_embed_bitcode;
|
||||
requested_for_rlib || forced_by_target
|
||||
}
|
||||
|
||||
|
@ -1865,11 +1865,11 @@ fn msvc_imps_needed(tcx: TyCtxt<'_>) -> bool {
|
|||
// something is wrong with commandline arg validation.
|
||||
assert!(
|
||||
!(tcx.sess.opts.cg.linker_plugin_lto.enabled()
|
||||
&& tcx.sess.target.options.is_like_windows
|
||||
&& tcx.sess.target.is_like_windows
|
||||
&& tcx.sess.opts.cg.prefer_dynamic)
|
||||
);
|
||||
|
||||
tcx.sess.target.options.is_like_windows &&
|
||||
tcx.sess.target.is_like_windows &&
|
||||
tcx.sess.crate_types().iter().any(|ct| *ct == CrateType::Rlib) &&
|
||||
// ThinLTO can't handle this workaround in all cases, so we don't
|
||||
// emit the `__imp_` symbols. Instead we make them unnecessary by disallowing
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue