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

Fix flags when using clang as linker for Fuchsia #99500

Merged
merged 1 commit into from
Aug 12, 2022
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
20 changes: 16 additions & 4 deletions compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1551,12 +1551,21 @@ fn crt_objects_fallback(sess: &Session, crate_type: CrateType) -> bool {
fn add_pre_link_objects(
cmd: &mut dyn Linker,
sess: &Session,
flavor: LinkerFlavor,
link_output_kind: LinkOutputKind,
self_contained: bool,
) {
// FIXME: we are currently missing some infra here (per-linker-flavor CRT objects),
// so Fuchsia has to be special-cased.
let opts = &sess.target;
let objects =
if self_contained { &opts.pre_link_objects_fallback } else { &opts.pre_link_objects };
let empty = Default::default();
let objects = if self_contained {
&opts.pre_link_objects_fallback
} else if !(sess.target.os == "fuchsia" && flavor == LinkerFlavor::Gcc) {
&opts.pre_link_objects
} else {
&empty
};
for obj in objects.get(&link_output_kind).iter().copied().flatten() {
cmd.add_object(&get_object_file_path(sess, obj, self_contained));
}
Expand Down Expand Up @@ -1881,7 +1890,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
// ------------ Object code and libraries, order-dependent ------------

// Pre-link CRT objects.
add_pre_link_objects(cmd, sess, link_output_kind, crt_objects_fallback);
add_pre_link_objects(cmd, sess, flavor, link_output_kind, crt_objects_fallback);

add_linked_symbol_object(
cmd,
Expand Down Expand Up @@ -2018,7 +2027,10 @@ fn add_order_independent_options(

add_link_script(cmd, sess, tmpdir, crate_type);

if sess.target.os == "fuchsia" && crate_type == CrateType::Executable {
if sess.target.os == "fuchsia"
&& crate_type == CrateType::Executable
&& flavor != LinkerFlavor::Gcc
{
let prefix = if sess.opts.unstable_opts.sanitizer.contains(SanitizerSet::ADDRESS) {
"asan/"
} else {
Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_target/src/spec/fuchsia_base.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
use crate::spec::{crt_objects, cvs, LinkOutputKind, LinkerFlavor, LldFlavor, TargetOptions};

pub fn opts() -> TargetOptions {
// This mirrors the linker options provided by clang. We presume lld for
// now. When using clang as the linker it will supply these options for us,
// so we only list them for ld/lld.
//
// https://github.com/llvm/llvm-project/blob/db9322b2066c55254e7691efeab863f43bfcc084/clang/lib/Driver/ToolChains/Fuchsia.cpp#L31
let pre_link_args = TargetOptions::link_args(
LinkerFlavor::Ld,
&[
Expand Down