Skip to content

Commit

Permalink
link-arg will be prefixed "-Wl," if flavor.uses_cc and not verbatim
Browse files Browse the repository at this point in the history
  • Loading branch information
azhogin committed Nov 23, 2023
1 parent e24e5af commit cce53d3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
15 changes: 14 additions & 1 deletion compiler/rustc_codegen_ssa/src/back/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2136,6 +2136,7 @@ fn linker_with_args<'a>(
add_local_native_libraries(
cmd,
sess,
flavor,
archive_builder_builder,
codegen_results,
tmpdir,
Expand All @@ -2146,6 +2147,7 @@ fn linker_with_args<'a>(
add_upstream_rust_crates(
cmd,
sess,
flavor,
archive_builder_builder,
codegen_results,
crate_type,
Expand All @@ -2157,6 +2159,7 @@ fn linker_with_args<'a>(
add_upstream_native_libraries(
cmd,
sess,
flavor,
archive_builder_builder,
codegen_results,
tmpdir,
Expand Down Expand Up @@ -2411,6 +2414,7 @@ fn collect_natvis_visualizers(
fn add_native_libs_from_crate(
cmd: &mut dyn Linker,
sess: &Session,
flavor: LinkerFlavor,
archive_builder_builder: &dyn ArchiveBuilderBuilder,
codegen_results: &CodegenResults,
tmpdir: &Path,
Expand Down Expand Up @@ -2522,7 +2526,10 @@ fn add_native_libs_from_crate(
NativeLibKind::WasmImportModule => {}
NativeLibKind::LinkArg => {
if link_static {
cmd.arg(name);
let need_wrap = flavor.uses_cc() && !verbatim;
let wrapped_arg =
if need_wrap { "-Wl,".to_owned() + name } else { name.to_string() };
cmd.arg(wrapped_arg);
}
}
}
Expand All @@ -2532,6 +2539,7 @@ fn add_native_libs_from_crate(
fn add_local_native_libraries(
cmd: &mut dyn Linker,
sess: &Session,
flavor: LinkerFlavor,
archive_builder_builder: &dyn ArchiveBuilderBuilder,
codegen_results: &CodegenResults,
tmpdir: &Path,
Expand All @@ -2557,6 +2565,7 @@ fn add_local_native_libraries(
add_native_libs_from_crate(
cmd,
sess,
flavor,
archive_builder_builder,
codegen_results,
tmpdir,
Expand All @@ -2572,6 +2581,7 @@ fn add_local_native_libraries(
fn add_upstream_rust_crates<'a>(
cmd: &mut dyn Linker,
sess: &'a Session,
flavor: LinkerFlavor,
archive_builder_builder: &dyn ArchiveBuilderBuilder,
codegen_results: &CodegenResults,
crate_type: CrateType,
Expand Down Expand Up @@ -2646,6 +2656,7 @@ fn add_upstream_rust_crates<'a>(
add_native_libs_from_crate(
cmd,
sess,
flavor,
archive_builder_builder,
codegen_results,
tmpdir,
Expand All @@ -2662,6 +2673,7 @@ fn add_upstream_rust_crates<'a>(
fn add_upstream_native_libraries(
cmd: &mut dyn Linker,
sess: &Session,
flavor: LinkerFlavor,
archive_builder_builder: &dyn ArchiveBuilderBuilder,
codegen_results: &CodegenResults,
tmpdir: &Path,
Expand All @@ -2686,6 +2698,7 @@ fn add_upstream_native_libraries(
add_native_libs_from_crate(
cmd,
sess,
flavor,
archive_builder_builder,
codegen_results,
tmpdir,
Expand Down
4 changes: 3 additions & 1 deletion tests/run-make/pass-linker-flags/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
include ../tools.mk

all:
$(RUSTC) rs.rs -Z unstable-options -l static=l1 -l link-arg=a1 -l static=l2 -l link-arg=a2 -l dylib=d1 -l link-arg=a3 --print link-args | $(CGREP) -e 'l1.*a1.*l2.*a2.*d1.*a3'
$(RUSTC) rs.rs -Z unstable-options -C linker-flavor=gnu-cc -l static=l1 -l link-arg=a1 -l static=l2 -l link-arg=a2 -l dylib=d1 -l link-arg=a3 --print link-args | $(CGREP) -e 'l1.*-Wl,a1.*l2.*-Wl,a2.*d1.*-Wl,a3'
$(RUSTC) rs.rs -Z unstable-options -C linker-flavor=gnu-cc -l static=l1 -l link-arg:+verbatim=a1 -l static=l2 -l link-arg=a2 -l dylib=d1 -l link-arg=a3 --print link-args | $(CGREP) -e 'l1.*"a1".*l2.*-Wl,a2.*d1.*-Wl,a3'
$(RUSTC) rs.rs -Z unstable-options -C linker-flavor=ld -l static=l1 -l link-arg=a1 -l static=l2 -l link-arg=a2 -l dylib=d1 -l link-arg=a3 --print link-args | $(CGREP) -e 'l1.*"a1".*l2.*"a2".*d1.*"a3"'

0 comments on commit cce53d3

Please sign in to comment.