]> git.lizzy.rs Git - rust.git/blob - compiler/rustc_codegen_ssa/src/back/linker.rs
Rollup merge of #83853 - Amanieu:asm_no_high_x86_64, r=nagisa
[rust.git] / compiler / rustc_codegen_ssa / src / back / linker.rs
1 use super::archive;
2 use super::command::Command;
3 use super::symbol_export;
4 use rustc_span::symbol::sym;
5
6 use std::ffi::{OsStr, OsString};
7 use std::fs::{self, File};
8 use std::io::prelude::*;
9 use std::io::{self, BufWriter};
10 use std::mem;
11 use std::path::{Path, PathBuf};
12
13 use rustc_data_structures::fx::FxHashMap;
14 use rustc_hir::def_id::{CrateNum, LOCAL_CRATE};
15 use rustc_middle::middle::dependency_format::Linkage;
16 use rustc_middle::ty::TyCtxt;
17 use rustc_serialize::{json, Encoder};
18 use rustc_session::config::{self, CrateType, DebugInfo, LinkerPluginLto, Lto, OptLevel, Strip};
19 use rustc_session::Session;
20 use rustc_span::symbol::Symbol;
21 use rustc_target::spec::{LinkOutputKind, LinkerFlavor, LldFlavor};
22
23 /// Disables non-English messages from localized linkers.
24 /// Such messages may cause issues with text encoding on Windows (#35785)
25 /// and prevent inspection of linker output in case of errors, which we occasionally do.
26 /// This should be acceptable because other messages from rustc are in English anyway,
27 /// and may also be desirable to improve searchability of the linker diagnostics.
28 pub fn disable_localization(linker: &mut Command) {
29     // No harm in setting both env vars simultaneously.
30     // Unix-style linkers.
31     linker.env("LC_ALL", "C");
32     // MSVC's `link.exe`.
33     linker.env("VSLANG", "1033");
34 }
35
36 /// For all the linkers we support, and information they might
37 /// need out of the shared crate context before we get rid of it.
38 #[derive(Encodable, Decodable)]
39 pub struct LinkerInfo {
40     exports: FxHashMap<CrateType, Vec<String>>,
41 }
42
43 impl LinkerInfo {
44     pub fn new(tcx: TyCtxt<'_>) -> LinkerInfo {
45         LinkerInfo {
46             exports: tcx
47                 .sess
48                 .crate_types()
49                 .iter()
50                 .map(|&c| (c, exported_symbols(tcx, c)))
51                 .collect(),
52         }
53     }
54
55     pub fn to_linker<'a>(
56         &'a self,
57         cmd: Command,
58         sess: &'a Session,
59         flavor: LinkerFlavor,
60         target_cpu: &'a str,
61     ) -> Box<dyn Linker + 'a> {
62         match flavor {
63             LinkerFlavor::Lld(LldFlavor::Link) | LinkerFlavor::Msvc => {
64                 Box::new(MsvcLinker { cmd, sess, info: self }) as Box<dyn Linker>
65             }
66             LinkerFlavor::Em => Box::new(EmLinker { cmd, sess, info: self }) as Box<dyn Linker>,
67             LinkerFlavor::Gcc => Box::new(GccLinker {
68                 cmd,
69                 sess,
70                 info: self,
71                 hinted_static: false,
72                 is_ld: false,
73                 target_cpu,
74             }) as Box<dyn Linker>,
75
76             LinkerFlavor::Lld(LldFlavor::Ld)
77             | LinkerFlavor::Lld(LldFlavor::Ld64)
78             | LinkerFlavor::Ld => Box::new(GccLinker {
79                 cmd,
80                 sess,
81                 info: self,
82                 hinted_static: false,
83                 is_ld: true,
84                 target_cpu,
85             }) as Box<dyn Linker>,
86
87             LinkerFlavor::Lld(LldFlavor::Wasm) => {
88                 Box::new(WasmLd::new(cmd, sess, self)) as Box<dyn Linker>
89             }
90
91             LinkerFlavor::PtxLinker => Box::new(PtxLinker { cmd, sess }) as Box<dyn Linker>,
92         }
93     }
94 }
95
96 /// Linker abstraction used by `back::link` to build up the command to invoke a
97 /// linker.
98 ///
99 /// This trait is the total list of requirements needed by `back::link` and
100 /// represents the meaning of each option being passed down. This trait is then
101 /// used to dispatch on whether a GNU-like linker (generally `ld.exe`) or an
102 /// MSVC linker (e.g., `link.exe`) is being used.
103 pub trait Linker {
104     fn cmd(&mut self) -> &mut Command;
105     fn set_output_kind(&mut self, output_kind: LinkOutputKind, out_filename: &Path);
106     fn link_dylib(&mut self, lib: Symbol);
107     fn link_rust_dylib(&mut self, lib: Symbol, path: &Path);
108     fn link_framework(&mut self, framework: Symbol);
109     fn link_staticlib(&mut self, lib: Symbol);
110     fn link_rlib(&mut self, lib: &Path);
111     fn link_whole_rlib(&mut self, lib: &Path);
112     fn link_whole_staticlib(&mut self, lib: Symbol, search_path: &[PathBuf]);
113     fn include_path(&mut self, path: &Path);
114     fn framework_path(&mut self, path: &Path);
115     fn output_filename(&mut self, path: &Path);
116     fn add_object(&mut self, path: &Path);
117     fn gc_sections(&mut self, keep_metadata: bool);
118     fn full_relro(&mut self);
119     fn partial_relro(&mut self);
120     fn no_relro(&mut self);
121     fn optimize(&mut self);
122     fn pgo_gen(&mut self);
123     fn control_flow_guard(&mut self);
124     fn debuginfo(&mut self, strip: Strip);
125     fn no_crt_objects(&mut self);
126     fn no_default_libraries(&mut self);
127     fn export_symbols(&mut self, tmpdir: &Path, crate_type: CrateType);
128     fn subsystem(&mut self, subsystem: &str);
129     fn group_start(&mut self);
130     fn group_end(&mut self);
131     fn linker_plugin_lto(&mut self);
132     fn add_eh_frame_header(&mut self) {}
133     fn add_no_exec(&mut self) {}
134     fn add_as_needed(&mut self) {}
135     fn finalize(&mut self);
136 }
137
138 impl dyn Linker + '_ {
139     pub fn arg(&mut self, arg: impl AsRef<OsStr>) {
140         self.cmd().arg(arg);
141     }
142
143     pub fn args(&mut self, args: impl IntoIterator<Item: AsRef<OsStr>>) {
144         self.cmd().args(args);
145     }
146
147     pub fn take_cmd(&mut self) -> Command {
148         mem::replace(self.cmd(), Command::new(""))
149     }
150 }
151
152 pub struct GccLinker<'a> {
153     cmd: Command,
154     sess: &'a Session,
155     info: &'a LinkerInfo,
156     hinted_static: bool, // Keeps track of the current hinting mode.
157     // Link as ld
158     is_ld: bool,
159     target_cpu: &'a str,
160 }
161
162 impl<'a> GccLinker<'a> {
163     /// Argument that must be passed *directly* to the linker
164     ///
165     /// These arguments need to be prepended with `-Wl`, when a GCC-style linker is used.
166     fn linker_arg<S>(&mut self, arg: S) -> &mut Self
167     where
168         S: AsRef<OsStr>,
169     {
170         if !self.is_ld {
171             let mut os = OsString::from("-Wl,");
172             os.push(arg.as_ref());
173             self.cmd.arg(os);
174         } else {
175             self.cmd.arg(arg);
176         }
177         self
178     }
179
180     fn takes_hints(&self) -> bool {
181         // Really this function only returns true if the underlying linker
182         // configured for a compiler is binutils `ld.bfd` and `ld.gold`. We
183         // don't really have a foolproof way to detect that, so rule out some
184         // platforms where currently this is guaranteed to *not* be the case:
185         //
186         // * On OSX they have their own linker, not binutils'
187         // * For WebAssembly the only functional linker is LLD, which doesn't
188         //   support hint flags
189         !self.sess.target.is_like_osx && !self.sess.target.is_like_wasm
190     }
191
192     // Some platforms take hints about whether a library is static or dynamic.
193     // For those that support this, we ensure we pass the option if the library
194     // was flagged "static" (most defaults are dynamic) to ensure that if
195     // libfoo.a and libfoo.so both exist that the right one is chosen.
196     fn hint_static(&mut self) {
197         if !self.takes_hints() {
198             return;
199         }
200         if !self.hinted_static {
201             self.linker_arg("-Bstatic");
202             self.hinted_static = true;
203         }
204     }
205
206     fn hint_dynamic(&mut self) {
207         if !self.takes_hints() {
208             return;
209         }
210         if self.hinted_static {
211             self.linker_arg("-Bdynamic");
212             self.hinted_static = false;
213         }
214     }
215
216     fn push_linker_plugin_lto_args(&mut self, plugin_path: Option<&OsStr>) {
217         if let Some(plugin_path) = plugin_path {
218             let mut arg = OsString::from("-plugin=");
219             arg.push(plugin_path);
220             self.linker_arg(&arg);
221         }
222
223         let opt_level = match self.sess.opts.optimize {
224             config::OptLevel::No => "O0",
225             config::OptLevel::Less => "O1",
226             config::OptLevel::Default | config::OptLevel::Size | config::OptLevel::SizeMin => "O2",
227             config::OptLevel::Aggressive => "O3",
228         };
229
230         self.linker_arg(&format!("-plugin-opt={}", opt_level));
231         let target_cpu = self.target_cpu;
232         self.linker_arg(&format!("-plugin-opt=mcpu={}", target_cpu));
233     }
234
235     fn build_dylib(&mut self, out_filename: &Path) {
236         // On mac we need to tell the linker to let this library be rpathed
237         if self.sess.target.is_like_osx {
238             self.cmd.arg("-dynamiclib");
239             self.linker_arg("-dylib");
240
241             // Note that the `osx_rpath_install_name` option here is a hack
242             // purely to support rustbuild right now, we should get a more
243             // principled solution at some point to force the compiler to pass
244             // the right `-Wl,-install_name` with an `@rpath` in it.
245             if self.sess.opts.cg.rpath || self.sess.opts.debugging_opts.osx_rpath_install_name {
246                 self.linker_arg("-install_name");
247                 let mut v = OsString::from("@rpath/");
248                 v.push(out_filename.file_name().unwrap());
249                 self.linker_arg(&v);
250             }
251         } else {
252             self.cmd.arg("-shared");
253             if self.sess.target.is_like_windows {
254                 // The output filename already contains `dll_suffix` so
255                 // the resulting import library will have a name in the
256                 // form of libfoo.dll.a
257                 let implib_name =
258                     out_filename.file_name().and_then(|file| file.to_str()).map(|file| {
259                         format!(
260                             "{}{}{}",
261                             self.sess.target.staticlib_prefix,
262                             file,
263                             self.sess.target.staticlib_suffix
264                         )
265                     });
266                 if let Some(implib_name) = implib_name {
267                     let implib = out_filename.parent().map(|dir| dir.join(&implib_name));
268                     if let Some(implib) = implib {
269                         self.linker_arg(&format!("--out-implib={}", (*implib).to_str().unwrap()));
270                     }
271                 }
272             }
273         }
274     }
275 }
276
277 impl<'a> Linker for GccLinker<'a> {
278     fn cmd(&mut self) -> &mut Command {
279         &mut self.cmd
280     }
281
282     fn set_output_kind(&mut self, output_kind: LinkOutputKind, out_filename: &Path) {
283         match output_kind {
284             LinkOutputKind::DynamicNoPicExe => {
285                 if !self.is_ld && self.sess.target.linker_is_gnu {
286                     self.cmd.arg("-no-pie");
287                 }
288             }
289             LinkOutputKind::DynamicPicExe => {
290                 // `-pie` works for both gcc wrapper and ld.
291                 self.cmd.arg("-pie");
292             }
293             LinkOutputKind::StaticNoPicExe => {
294                 // `-static` works for both gcc wrapper and ld.
295                 self.cmd.arg("-static");
296                 if !self.is_ld && self.sess.target.linker_is_gnu {
297                     self.cmd.arg("-no-pie");
298                 }
299             }
300             LinkOutputKind::StaticPicExe => {
301                 if !self.is_ld {
302                     // Note that combination `-static -pie` doesn't work as expected
303                     // for the gcc wrapper, `-static` in that case suppresses `-pie`.
304                     self.cmd.arg("-static-pie");
305                 } else {
306                     // `--no-dynamic-linker` and `-z text` are not strictly necessary for producing
307                     // a static pie, but currently passed because gcc and clang pass them.
308                     // The former suppresses the `INTERP` ELF header specifying dynamic linker,
309                     // which is otherwise implicitly injected by ld (but not lld).
310                     // The latter doesn't change anything, only ensures that everything is pic.
311                     self.cmd.args(&["-static", "-pie", "--no-dynamic-linker", "-z", "text"]);
312                 }
313             }
314             LinkOutputKind::DynamicDylib => self.build_dylib(out_filename),
315             LinkOutputKind::StaticDylib => {
316                 self.cmd.arg("-static");
317                 self.build_dylib(out_filename);
318             }
319             LinkOutputKind::WasiReactorExe => {
320                 self.linker_arg("--entry");
321                 self.linker_arg("_initialize");
322             }
323         }
324         // VxWorks compiler driver introduced `--static-crt` flag specifically for rustc,
325         // it switches linking for libc and similar system libraries to static without using
326         // any `#[link]` attributes in the `libc` crate, see #72782 for details.
327         // FIXME: Switch to using `#[link]` attributes in the `libc` crate
328         // similarly to other targets.
329         if self.sess.target.os == "vxworks"
330             && matches!(
331                 output_kind,
332                 LinkOutputKind::StaticNoPicExe
333                     | LinkOutputKind::StaticPicExe
334                     | LinkOutputKind::StaticDylib
335             )
336         {
337             self.cmd.arg("--static-crt");
338         }
339     }
340
341     fn link_dylib(&mut self, lib: Symbol) {
342         self.hint_dynamic();
343         self.cmd.arg(format!("-l{}", lib));
344     }
345     fn link_staticlib(&mut self, lib: Symbol) {
346         self.hint_static();
347         self.cmd.arg(format!("-l{}", lib));
348     }
349     fn link_rlib(&mut self, lib: &Path) {
350         self.hint_static();
351         self.cmd.arg(lib);
352     }
353     fn include_path(&mut self, path: &Path) {
354         self.cmd.arg("-L").arg(path);
355     }
356     fn framework_path(&mut self, path: &Path) {
357         self.cmd.arg("-F").arg(path);
358     }
359     fn output_filename(&mut self, path: &Path) {
360         self.cmd.arg("-o").arg(path);
361     }
362     fn add_object(&mut self, path: &Path) {
363         self.cmd.arg(path);
364     }
365     fn full_relro(&mut self) {
366         self.linker_arg("-zrelro");
367         self.linker_arg("-znow");
368     }
369     fn partial_relro(&mut self) {
370         self.linker_arg("-zrelro");
371     }
372     fn no_relro(&mut self) {
373         self.linker_arg("-znorelro");
374     }
375
376     fn link_rust_dylib(&mut self, lib: Symbol, _path: &Path) {
377         self.hint_dynamic();
378         self.cmd.arg(format!("-l{}", lib));
379     }
380
381     fn link_framework(&mut self, framework: Symbol) {
382         self.hint_dynamic();
383         self.cmd.arg("-framework").sym_arg(framework);
384     }
385
386     // Here we explicitly ask that the entire archive is included into the
387     // result artifact. For more details see #15460, but the gist is that
388     // the linker will strip away any unused objects in the archive if we
389     // don't otherwise explicitly reference them. This can occur for
390     // libraries which are just providing bindings, libraries with generic
391     // functions, etc.
392     fn link_whole_staticlib(&mut self, lib: Symbol, search_path: &[PathBuf]) {
393         self.hint_static();
394         let target = &self.sess.target;
395         if !target.is_like_osx {
396             self.linker_arg("--whole-archive").cmd.arg(format!("-l{}", lib));
397             self.linker_arg("--no-whole-archive");
398         } else {
399             // -force_load is the macOS equivalent of --whole-archive, but it
400             // involves passing the full path to the library to link.
401             self.linker_arg("-force_load");
402             let lib = archive::find_library(lib, search_path, &self.sess);
403             self.linker_arg(&lib);
404         }
405     }
406
407     fn link_whole_rlib(&mut self, lib: &Path) {
408         self.hint_static();
409         if self.sess.target.is_like_osx {
410             self.linker_arg("-force_load");
411             self.linker_arg(&lib);
412         } else {
413             self.linker_arg("--whole-archive").cmd.arg(lib);
414             self.linker_arg("--no-whole-archive");
415         }
416     }
417
418     fn gc_sections(&mut self, keep_metadata: bool) {
419         // The dead_strip option to the linker specifies that functions and data
420         // unreachable by the entry point will be removed. This is quite useful
421         // with Rust's compilation model of compiling libraries at a time into
422         // one object file. For example, this brings hello world from 1.7MB to
423         // 458K.
424         //
425         // Note that this is done for both executables and dynamic libraries. We
426         // won't get much benefit from dylibs because LLVM will have already
427         // stripped away as much as it could. This has not been seen to impact
428         // link times negatively.
429         //
430         // -dead_strip can't be part of the pre_link_args because it's also used
431         // for partial linking when using multiple codegen units (-r).  So we
432         // insert it here.
433         if self.sess.target.is_like_osx {
434             self.linker_arg("-dead_strip");
435         } else if self.sess.target.is_like_solaris {
436             self.linker_arg("-zignore");
437
438         // If we're building a dylib, we don't use --gc-sections because LLVM
439         // has already done the best it can do, and we also don't want to
440         // eliminate the metadata. If we're building an executable, however,
441         // --gc-sections drops the size of hello world from 1.8MB to 597K, a 67%
442         // reduction.
443         } else if !keep_metadata {
444             self.linker_arg("--gc-sections");
445         }
446     }
447
448     fn optimize(&mut self) {
449         if !self.sess.target.linker_is_gnu {
450             return;
451         }
452
453         // GNU-style linkers support optimization with -O. GNU ld doesn't
454         // need a numeric argument, but other linkers do.
455         if self.sess.opts.optimize == config::OptLevel::Default
456             || self.sess.opts.optimize == config::OptLevel::Aggressive
457         {
458             self.linker_arg("-O1");
459         }
460     }
461
462     fn pgo_gen(&mut self) {
463         if !self.sess.target.linker_is_gnu {
464             return;
465         }
466
467         // If we're doing PGO generation stuff and on a GNU-like linker, use the
468         // "-u" flag to properly pull in the profiler runtime bits.
469         //
470         // This is because LLVM otherwise won't add the needed initialization
471         // for us on Linux (though the extra flag should be harmless if it
472         // does).
473         //
474         // See https://reviews.llvm.org/D14033 and https://reviews.llvm.org/D14030.
475         //
476         // Though it may be worth to try to revert those changes upstream, since
477         // the overhead of the initialization should be minor.
478         self.cmd.arg("-u");
479         self.cmd.arg("__llvm_profile_runtime");
480     }
481
482     fn control_flow_guard(&mut self) {}
483
484     fn debuginfo(&mut self, strip: Strip) {
485         match strip {
486             Strip::None => {}
487             Strip::Debuginfo => {
488                 // MacOS linker does not support longhand argument --strip-debug
489                 self.linker_arg("-S");
490             }
491             Strip::Symbols => {
492                 // MacOS linker does not support longhand argument --strip-all
493                 self.linker_arg("-s");
494             }
495         }
496     }
497
498     fn no_crt_objects(&mut self) {
499         if !self.is_ld {
500             self.cmd.arg("-nostartfiles");
501         }
502     }
503
504     fn no_default_libraries(&mut self) {
505         if !self.is_ld {
506             self.cmd.arg("-nodefaultlibs");
507         }
508     }
509
510     fn export_symbols(&mut self, tmpdir: &Path, crate_type: CrateType) {
511         // Symbol visibility in object files typically takes care of this.
512         if crate_type == CrateType::Executable && self.sess.target.override_export_symbols.is_none()
513         {
514             return;
515         }
516
517         // We manually create a list of exported symbols to ensure we don't expose any more.
518         // The object files have far more public symbols than we actually want to export,
519         // so we hide them all here.
520
521         if !self.sess.target.limit_rdylib_exports {
522             return;
523         }
524
525         if crate_type == CrateType::ProcMacro {
526             return;
527         }
528
529         let is_windows = self.sess.target.is_like_windows;
530         let mut arg = OsString::new();
531         let path = tmpdir.join(if is_windows { "list.def" } else { "list" });
532
533         debug!("EXPORTED SYMBOLS:");
534
535         if self.sess.target.is_like_osx {
536             // Write a plain, newline-separated list of symbols
537             let res: io::Result<()> = try {
538                 let mut f = BufWriter::new(File::create(&path)?);
539                 for sym in self.info.exports[&crate_type].iter() {
540                     debug!("  _{}", sym);
541                     writeln!(f, "_{}", sym)?;
542                 }
543             };
544             if let Err(e) = res {
545                 self.sess.fatal(&format!("failed to write lib.def file: {}", e));
546             }
547         } else if is_windows {
548             let res: io::Result<()> = try {
549                 let mut f = BufWriter::new(File::create(&path)?);
550
551                 // .def file similar to MSVC one but without LIBRARY section
552                 // because LD doesn't like when it's empty
553                 writeln!(f, "EXPORTS")?;
554                 for symbol in self.info.exports[&crate_type].iter() {
555                     debug!("  _{}", symbol);
556                     writeln!(f, "  {}", symbol)?;
557                 }
558             };
559             if let Err(e) = res {
560                 self.sess.fatal(&format!("failed to write list.def file: {}", e));
561             }
562         } else {
563             // Write an LD version script
564             let res: io::Result<()> = try {
565                 let mut f = BufWriter::new(File::create(&path)?);
566                 writeln!(f, "{{")?;
567                 if !self.info.exports[&crate_type].is_empty() {
568                     writeln!(f, "  global:")?;
569                     for sym in self.info.exports[&crate_type].iter() {
570                         debug!("    {};", sym);
571                         writeln!(f, "    {};", sym)?;
572                     }
573                 }
574                 writeln!(f, "\n  local:\n    *;\n}};")?;
575             };
576             if let Err(e) = res {
577                 self.sess.fatal(&format!("failed to write version script: {}", e));
578             }
579         }
580
581         if self.sess.target.is_like_osx {
582             if !self.is_ld {
583                 arg.push("-Wl,")
584             }
585             arg.push("-exported_symbols_list,");
586         } else if self.sess.target.is_like_solaris {
587             if !self.is_ld {
588                 arg.push("-Wl,")
589             }
590             arg.push("-M,");
591         } else {
592             if !self.is_ld {
593                 arg.push("-Wl,")
594             }
595             // Both LD and LLD accept export list in *.def file form, there are no flags required
596             if !is_windows {
597                 arg.push("--version-script=")
598             }
599         }
600
601         arg.push(&path);
602         self.cmd.arg(arg);
603     }
604
605     fn subsystem(&mut self, subsystem: &str) {
606         self.linker_arg("--subsystem");
607         self.linker_arg(&subsystem);
608     }
609
610     fn finalize(&mut self) {
611         self.hint_dynamic(); // Reset to default before returning the composed command line.
612     }
613
614     fn group_start(&mut self) {
615         if self.takes_hints() {
616             self.linker_arg("--start-group");
617         }
618     }
619
620     fn group_end(&mut self) {
621         if self.takes_hints() {
622             self.linker_arg("--end-group");
623         }
624     }
625
626     fn linker_plugin_lto(&mut self) {
627         match self.sess.opts.cg.linker_plugin_lto {
628             LinkerPluginLto::Disabled => {
629                 // Nothing to do
630             }
631             LinkerPluginLto::LinkerPluginAuto => {
632                 self.push_linker_plugin_lto_args(None);
633             }
634             LinkerPluginLto::LinkerPlugin(ref path) => {
635                 self.push_linker_plugin_lto_args(Some(path.as_os_str()));
636             }
637         }
638     }
639
640     // Add the `GNU_EH_FRAME` program header which is required to locate unwinding information.
641     // Some versions of `gcc` add it implicitly, some (e.g. `musl-gcc`) don't,
642     // so we just always add it.
643     fn add_eh_frame_header(&mut self) {
644         self.linker_arg("--eh-frame-hdr");
645     }
646
647     fn add_no_exec(&mut self) {
648         if self.sess.target.is_like_windows {
649             self.linker_arg("--nxcompat");
650         } else if self.sess.target.linker_is_gnu {
651             self.linker_arg("-znoexecstack");
652         }
653     }
654
655     fn add_as_needed(&mut self) {
656         if self.sess.target.linker_is_gnu {
657             self.linker_arg("--as-needed");
658         }
659     }
660 }
661
662 pub struct MsvcLinker<'a> {
663     cmd: Command,
664     sess: &'a Session,
665     info: &'a LinkerInfo,
666 }
667
668 impl<'a> Linker for MsvcLinker<'a> {
669     fn cmd(&mut self) -> &mut Command {
670         &mut self.cmd
671     }
672
673     fn set_output_kind(&mut self, output_kind: LinkOutputKind, out_filename: &Path) {
674         match output_kind {
675             LinkOutputKind::DynamicNoPicExe
676             | LinkOutputKind::DynamicPicExe
677             | LinkOutputKind::StaticNoPicExe
678             | LinkOutputKind::StaticPicExe => {}
679             LinkOutputKind::DynamicDylib | LinkOutputKind::StaticDylib => {
680                 self.cmd.arg("/DLL");
681                 let mut arg: OsString = "/IMPLIB:".into();
682                 arg.push(out_filename.with_extension("dll.lib"));
683                 self.cmd.arg(arg);
684             }
685             LinkOutputKind::WasiReactorExe => {
686                 panic!("can't link as reactor on non-wasi target");
687             }
688         }
689     }
690
691     fn link_rlib(&mut self, lib: &Path) {
692         self.cmd.arg(lib);
693     }
694     fn add_object(&mut self, path: &Path) {
695         self.cmd.arg(path);
696     }
697
698     fn gc_sections(&mut self, _keep_metadata: bool) {
699         // MSVC's ICF (Identical COMDAT Folding) link optimization is
700         // slow for Rust and thus we disable it by default when not in
701         // optimization build.
702         if self.sess.opts.optimize != config::OptLevel::No {
703             self.cmd.arg("/OPT:REF,ICF");
704         } else {
705             // It is necessary to specify NOICF here, because /OPT:REF
706             // implies ICF by default.
707             self.cmd.arg("/OPT:REF,NOICF");
708         }
709     }
710
711     fn link_dylib(&mut self, lib: Symbol) {
712         self.cmd.arg(&format!("{}.lib", lib));
713     }
714
715     fn link_rust_dylib(&mut self, lib: Symbol, path: &Path) {
716         // When producing a dll, the MSVC linker may not actually emit a
717         // `foo.lib` file if the dll doesn't actually export any symbols, so we
718         // check to see if the file is there and just omit linking to it if it's
719         // not present.
720         let name = format!("{}.dll.lib", lib);
721         if fs::metadata(&path.join(&name)).is_ok() {
722             self.cmd.arg(name);
723         }
724     }
725
726     fn link_staticlib(&mut self, lib: Symbol) {
727         self.cmd.arg(&format!("{}.lib", lib));
728     }
729
730     fn full_relro(&mut self) {
731         // noop
732     }
733
734     fn partial_relro(&mut self) {
735         // noop
736     }
737
738     fn no_relro(&mut self) {
739         // noop
740     }
741
742     fn no_crt_objects(&mut self) {
743         // noop
744     }
745
746     fn no_default_libraries(&mut self) {
747         self.cmd.arg("/NODEFAULTLIB");
748     }
749
750     fn include_path(&mut self, path: &Path) {
751         let mut arg = OsString::from("/LIBPATH:");
752         arg.push(path);
753         self.cmd.arg(&arg);
754     }
755
756     fn output_filename(&mut self, path: &Path) {
757         let mut arg = OsString::from("/OUT:");
758         arg.push(path);
759         self.cmd.arg(&arg);
760     }
761
762     fn framework_path(&mut self, _path: &Path) {
763         bug!("frameworks are not supported on windows")
764     }
765     fn link_framework(&mut self, _framework: Symbol) {
766         bug!("frameworks are not supported on windows")
767     }
768
769     fn link_whole_staticlib(&mut self, lib: Symbol, _search_path: &[PathBuf]) {
770         self.link_staticlib(lib);
771         self.cmd.arg(format!("/WHOLEARCHIVE:{}.lib", lib));
772     }
773     fn link_whole_rlib(&mut self, path: &Path) {
774         self.link_rlib(path);
775         let mut arg = OsString::from("/WHOLEARCHIVE:");
776         arg.push(path);
777         self.cmd.arg(arg);
778     }
779     fn optimize(&mut self) {
780         // Needs more investigation of `/OPT` arguments
781     }
782
783     fn pgo_gen(&mut self) {
784         // Nothing needed here.
785     }
786
787     fn control_flow_guard(&mut self) {
788         self.cmd.arg("/guard:cf");
789     }
790
791     fn debuginfo(&mut self, strip: Strip) {
792         match strip {
793             Strip::None => {
794                 // This will cause the Microsoft linker to generate a PDB file
795                 // from the CodeView line tables in the object files.
796                 self.cmd.arg("/DEBUG");
797
798                 // This will cause the Microsoft linker to embed .natvis info into the PDB file
799                 let natvis_dir_path = self.sess.sysroot.join("lib\\rustlib\\etc");
800                 if let Ok(natvis_dir) = fs::read_dir(&natvis_dir_path) {
801                     for entry in natvis_dir {
802                         match entry {
803                             Ok(entry) => {
804                                 let path = entry.path();
805                                 if path.extension() == Some("natvis".as_ref()) {
806                                     let mut arg = OsString::from("/NATVIS:");
807                                     arg.push(path);
808                                     self.cmd.arg(arg);
809                                 }
810                             }
811                             Err(err) => {
812                                 self.sess
813                                     .warn(&format!("error enumerating natvis directory: {}", err));
814                             }
815                         }
816                     }
817                 }
818             }
819             Strip::Debuginfo | Strip::Symbols => {
820                 self.cmd.arg("/DEBUG:NONE");
821             }
822         }
823     }
824
825     // Currently the compiler doesn't use `dllexport` (an LLVM attribute) to
826     // export symbols from a dynamic library. When building a dynamic library,
827     // however, we're going to want some symbols exported, so this function
828     // generates a DEF file which lists all the symbols.
829     //
830     // The linker will read this `*.def` file and export all the symbols from
831     // the dynamic library. Note that this is not as simple as just exporting
832     // all the symbols in the current crate (as specified by `codegen.reachable`)
833     // but rather we also need to possibly export the symbols of upstream
834     // crates. Upstream rlibs may be linked statically to this dynamic library,
835     // in which case they may continue to transitively be used and hence need
836     // their symbols exported.
837     fn export_symbols(&mut self, tmpdir: &Path, crate_type: CrateType) {
838         // Symbol visibility takes care of this typically
839         if crate_type == CrateType::Executable {
840             return;
841         }
842
843         let path = tmpdir.join("lib.def");
844         let res: io::Result<()> = try {
845             let mut f = BufWriter::new(File::create(&path)?);
846
847             // Start off with the standard module name header and then go
848             // straight to exports.
849             writeln!(f, "LIBRARY")?;
850             writeln!(f, "EXPORTS")?;
851             for symbol in self.info.exports[&crate_type].iter() {
852                 debug!("  _{}", symbol);
853                 writeln!(f, "  {}", symbol)?;
854             }
855         };
856         if let Err(e) = res {
857             self.sess.fatal(&format!("failed to write lib.def file: {}", e));
858         }
859         let mut arg = OsString::from("/DEF:");
860         arg.push(path);
861         self.cmd.arg(&arg);
862     }
863
864     fn subsystem(&mut self, subsystem: &str) {
865         // Note that previous passes of the compiler validated this subsystem,
866         // so we just blindly pass it to the linker.
867         self.cmd.arg(&format!("/SUBSYSTEM:{}", subsystem));
868
869         // Windows has two subsystems we're interested in right now, the console
870         // and windows subsystems. These both implicitly have different entry
871         // points (starting symbols). The console entry point starts with
872         // `mainCRTStartup` and the windows entry point starts with
873         // `WinMainCRTStartup`. These entry points, defined in system libraries,
874         // will then later probe for either `main` or `WinMain`, respectively to
875         // start the application.
876         //
877         // In Rust we just always generate a `main` function so we want control
878         // to always start there, so we force the entry point on the windows
879         // subsystem to be `mainCRTStartup` to get everything booted up
880         // correctly.
881         //
882         // For more information see RFC #1665
883         if subsystem == "windows" {
884             self.cmd.arg("/ENTRY:mainCRTStartup");
885         }
886     }
887
888     fn finalize(&mut self) {}
889
890     // MSVC doesn't need group indicators
891     fn group_start(&mut self) {}
892     fn group_end(&mut self) {}
893
894     fn linker_plugin_lto(&mut self) {
895         // Do nothing
896     }
897
898     fn add_no_exec(&mut self) {
899         self.cmd.arg("/NXCOMPAT");
900     }
901 }
902
903 pub struct EmLinker<'a> {
904     cmd: Command,
905     sess: &'a Session,
906     info: &'a LinkerInfo,
907 }
908
909 impl<'a> Linker for EmLinker<'a> {
910     fn cmd(&mut self) -> &mut Command {
911         &mut self.cmd
912     }
913
914     fn set_output_kind(&mut self, _output_kind: LinkOutputKind, _out_filename: &Path) {}
915
916     fn include_path(&mut self, path: &Path) {
917         self.cmd.arg("-L").arg(path);
918     }
919
920     fn link_staticlib(&mut self, lib: Symbol) {
921         self.cmd.arg("-l").sym_arg(lib);
922     }
923
924     fn output_filename(&mut self, path: &Path) {
925         self.cmd.arg("-o").arg(path);
926     }
927
928     fn add_object(&mut self, path: &Path) {
929         self.cmd.arg(path);
930     }
931
932     fn link_dylib(&mut self, lib: Symbol) {
933         // Emscripten always links statically
934         self.link_staticlib(lib);
935     }
936
937     fn link_whole_staticlib(&mut self, lib: Symbol, _search_path: &[PathBuf]) {
938         // not supported?
939         self.link_staticlib(lib);
940     }
941
942     fn link_whole_rlib(&mut self, lib: &Path) {
943         // not supported?
944         self.link_rlib(lib);
945     }
946
947     fn link_rust_dylib(&mut self, lib: Symbol, _path: &Path) {
948         self.link_dylib(lib);
949     }
950
951     fn link_rlib(&mut self, lib: &Path) {
952         self.add_object(lib);
953     }
954
955     fn full_relro(&mut self) {
956         // noop
957     }
958
959     fn partial_relro(&mut self) {
960         // noop
961     }
962
963     fn no_relro(&mut self) {
964         // noop
965     }
966
967     fn framework_path(&mut self, _path: &Path) {
968         bug!("frameworks are not supported on Emscripten")
969     }
970
971     fn link_framework(&mut self, _framework: Symbol) {
972         bug!("frameworks are not supported on Emscripten")
973     }
974
975     fn gc_sections(&mut self, _keep_metadata: bool) {
976         // noop
977     }
978
979     fn optimize(&mut self) {
980         // Emscripten performs own optimizations
981         self.cmd.arg(match self.sess.opts.optimize {
982             OptLevel::No => "-O0",
983             OptLevel::Less => "-O1",
984             OptLevel::Default => "-O2",
985             OptLevel::Aggressive => "-O3",
986             OptLevel::Size => "-Os",
987             OptLevel::SizeMin => "-Oz",
988         });
989         // Unusable until https://github.com/rust-lang/rust/issues/38454 is resolved
990         self.cmd.args(&["--memory-init-file", "0"]);
991     }
992
993     fn pgo_gen(&mut self) {
994         // noop, but maybe we need something like the gnu linker?
995     }
996
997     fn control_flow_guard(&mut self) {}
998
999     fn debuginfo(&mut self, _strip: Strip) {
1000         // Preserve names or generate source maps depending on debug info
1001         self.cmd.arg(match self.sess.opts.debuginfo {
1002             DebugInfo::None => "-g0",
1003             DebugInfo::Limited => "-g3",
1004             DebugInfo::Full => "-g4",
1005         });
1006     }
1007
1008     fn no_crt_objects(&mut self) {}
1009
1010     fn no_default_libraries(&mut self) {
1011         self.cmd.args(&["-s", "DEFAULT_LIBRARY_FUNCS_TO_INCLUDE=[]"]);
1012     }
1013
1014     fn export_symbols(&mut self, _tmpdir: &Path, crate_type: CrateType) {
1015         let symbols = &self.info.exports[&crate_type];
1016
1017         debug!("EXPORTED SYMBOLS:");
1018
1019         self.cmd.arg("-s");
1020
1021         let mut arg = OsString::from("EXPORTED_FUNCTIONS=");
1022         let mut encoded = String::new();
1023
1024         {
1025             let mut encoder = json::Encoder::new(&mut encoded);
1026             let res = encoder.emit_seq(symbols.len(), |encoder| {
1027                 for (i, sym) in symbols.iter().enumerate() {
1028                     encoder.emit_seq_elt(i, |encoder| encoder.emit_str(&("_".to_owned() + sym)))?;
1029                 }
1030                 Ok(())
1031             });
1032             if let Err(e) = res {
1033                 self.sess.fatal(&format!("failed to encode exported symbols: {}", e));
1034             }
1035         }
1036         debug!("{}", encoded);
1037         arg.push(encoded);
1038
1039         self.cmd.arg(arg);
1040     }
1041
1042     fn subsystem(&mut self, _subsystem: &str) {
1043         // noop
1044     }
1045
1046     fn finalize(&mut self) {}
1047
1048     // Appears not necessary on Emscripten
1049     fn group_start(&mut self) {}
1050     fn group_end(&mut self) {}
1051
1052     fn linker_plugin_lto(&mut self) {
1053         // Do nothing
1054     }
1055 }
1056
1057 pub struct WasmLd<'a> {
1058     cmd: Command,
1059     sess: &'a Session,
1060     info: &'a LinkerInfo,
1061 }
1062
1063 impl<'a> WasmLd<'a> {
1064     fn new(mut cmd: Command, sess: &'a Session, info: &'a LinkerInfo) -> WasmLd<'a> {
1065         // If the atomics feature is enabled for wasm then we need a whole bunch
1066         // of flags:
1067         //
1068         // * `--shared-memory` - the link won't even succeed without this, flags
1069         //   the one linear memory as `shared`
1070         //
1071         // * `--max-memory=1G` - when specifying a shared memory this must also
1072         //   be specified. We conservatively choose 1GB but users should be able
1073         //   to override this with `-C link-arg`.
1074         //
1075         // * `--import-memory` - it doesn't make much sense for memory to be
1076         //   exported in a threaded module because typically you're
1077         //   sharing memory and instantiating the module multiple times. As a
1078         //   result if it were exported then we'd just have no sharing.
1079         //
1080         // * `--export=__wasm_init_memory` - when using `--passive-segments` the
1081         //   linker will synthesize this function, and so we need to make sure
1082         //   that our usage of `--export` below won't accidentally cause this
1083         //   function to get deleted.
1084         //
1085         // * `--export=*tls*` - when `#[thread_local]` symbols are used these
1086         //   symbols are how the TLS segments are initialized and configured.
1087         if sess.target_features.contains(&sym::atomics) {
1088             cmd.arg("--shared-memory");
1089             cmd.arg("--max-memory=1073741824");
1090             cmd.arg("--import-memory");
1091             cmd.arg("--export=__wasm_init_memory");
1092             cmd.arg("--export=__wasm_init_tls");
1093             cmd.arg("--export=__tls_size");
1094             cmd.arg("--export=__tls_align");
1095             cmd.arg("--export=__tls_base");
1096         }
1097         WasmLd { cmd, sess, info }
1098     }
1099 }
1100
1101 impl<'a> Linker for WasmLd<'a> {
1102     fn cmd(&mut self) -> &mut Command {
1103         &mut self.cmd
1104     }
1105
1106     fn set_output_kind(&mut self, output_kind: LinkOutputKind, _out_filename: &Path) {
1107         match output_kind {
1108             LinkOutputKind::DynamicNoPicExe
1109             | LinkOutputKind::DynamicPicExe
1110             | LinkOutputKind::StaticNoPicExe
1111             | LinkOutputKind::StaticPicExe => {}
1112             LinkOutputKind::DynamicDylib | LinkOutputKind::StaticDylib => {
1113                 self.cmd.arg("--no-entry");
1114             }
1115             LinkOutputKind::WasiReactorExe => {
1116                 self.cmd.arg("--entry");
1117                 self.cmd.arg("_initialize");
1118             }
1119         }
1120     }
1121
1122     fn link_dylib(&mut self, lib: Symbol) {
1123         self.cmd.arg("-l").sym_arg(lib);
1124     }
1125
1126     fn link_staticlib(&mut self, lib: Symbol) {
1127         self.cmd.arg("-l").sym_arg(lib);
1128     }
1129
1130     fn link_rlib(&mut self, lib: &Path) {
1131         self.cmd.arg(lib);
1132     }
1133
1134     fn include_path(&mut self, path: &Path) {
1135         self.cmd.arg("-L").arg(path);
1136     }
1137
1138     fn framework_path(&mut self, _path: &Path) {
1139         panic!("frameworks not supported")
1140     }
1141
1142     fn output_filename(&mut self, path: &Path) {
1143         self.cmd.arg("-o").arg(path);
1144     }
1145
1146     fn add_object(&mut self, path: &Path) {
1147         self.cmd.arg(path);
1148     }
1149
1150     fn full_relro(&mut self) {}
1151
1152     fn partial_relro(&mut self) {}
1153
1154     fn no_relro(&mut self) {}
1155
1156     fn link_rust_dylib(&mut self, lib: Symbol, _path: &Path) {
1157         self.cmd.arg("-l").sym_arg(lib);
1158     }
1159
1160     fn link_framework(&mut self, _framework: Symbol) {
1161         panic!("frameworks not supported")
1162     }
1163
1164     fn link_whole_staticlib(&mut self, lib: Symbol, _search_path: &[PathBuf]) {
1165         self.cmd.arg("-l").sym_arg(lib);
1166     }
1167
1168     fn link_whole_rlib(&mut self, lib: &Path) {
1169         self.cmd.arg(lib);
1170     }
1171
1172     fn gc_sections(&mut self, _keep_metadata: bool) {
1173         self.cmd.arg("--gc-sections");
1174     }
1175
1176     fn optimize(&mut self) {
1177         self.cmd.arg(match self.sess.opts.optimize {
1178             OptLevel::No => "-O0",
1179             OptLevel::Less => "-O1",
1180             OptLevel::Default => "-O2",
1181             OptLevel::Aggressive => "-O3",
1182             // Currently LLD doesn't support `Os` and `Oz`, so pass through `O2`
1183             // instead.
1184             OptLevel::Size => "-O2",
1185             OptLevel::SizeMin => "-O2",
1186         });
1187     }
1188
1189     fn pgo_gen(&mut self) {}
1190
1191     fn debuginfo(&mut self, strip: Strip) {
1192         match strip {
1193             Strip::None => {}
1194             Strip::Debuginfo => {
1195                 self.cmd.arg("--strip-debug");
1196             }
1197             Strip::Symbols => {
1198                 self.cmd.arg("--strip-all");
1199             }
1200         }
1201     }
1202
1203     fn control_flow_guard(&mut self) {}
1204
1205     fn no_crt_objects(&mut self) {}
1206
1207     fn no_default_libraries(&mut self) {}
1208
1209     fn export_symbols(&mut self, _tmpdir: &Path, crate_type: CrateType) {
1210         for sym in self.info.exports[&crate_type].iter() {
1211             self.cmd.arg("--export").arg(&sym);
1212         }
1213
1214         // LLD will hide these otherwise-internal symbols since it only exports
1215         // symbols explicity passed via the `--export` flags above and hides all
1216         // others. Various bits and pieces of tooling use this, so be sure these
1217         // symbols make their way out of the linker as well.
1218         self.cmd.arg("--export=__heap_base");
1219         self.cmd.arg("--export=__data_end");
1220     }
1221
1222     fn subsystem(&mut self, _subsystem: &str) {}
1223
1224     fn finalize(&mut self) {}
1225
1226     // Not needed for now with LLD
1227     fn group_start(&mut self) {}
1228     fn group_end(&mut self) {}
1229
1230     fn linker_plugin_lto(&mut self) {
1231         // Do nothing for now
1232     }
1233 }
1234
1235 fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<String> {
1236     if let Some(ref exports) = tcx.sess.target.override_export_symbols {
1237         return exports.clone();
1238     }
1239
1240     let mut symbols = Vec::new();
1241
1242     let export_threshold = symbol_export::crates_export_threshold(&[crate_type]);
1243     for &(symbol, level) in tcx.exported_symbols(LOCAL_CRATE).iter() {
1244         if level.is_below_threshold(export_threshold) {
1245             symbols.push(symbol_export::symbol_name_for_instance_in_crate(
1246                 tcx,
1247                 symbol,
1248                 LOCAL_CRATE,
1249             ));
1250         }
1251     }
1252
1253     let formats = tcx.dependency_formats(LOCAL_CRATE);
1254     let deps = formats.iter().find_map(|(t, list)| (*t == crate_type).then_some(list)).unwrap();
1255
1256     for (index, dep_format) in deps.iter().enumerate() {
1257         let cnum = CrateNum::new(index + 1);
1258         // For each dependency that we are linking to statically ...
1259         if *dep_format == Linkage::Static {
1260             // ... we add its symbol list to our export list.
1261             for &(symbol, level) in tcx.exported_symbols(cnum).iter() {
1262                 if !level.is_below_threshold(export_threshold) {
1263                     continue;
1264                 }
1265
1266                 symbols.push(symbol_export::symbol_name_for_instance_in_crate(tcx, symbol, cnum));
1267             }
1268         }
1269     }
1270
1271     symbols
1272 }
1273
1274 /// Much simplified and explicit CLI for the NVPTX linker. The linker operates
1275 /// with bitcode and uses LLVM backend to generate a PTX assembly.
1276 pub struct PtxLinker<'a> {
1277     cmd: Command,
1278     sess: &'a Session,
1279 }
1280
1281 impl<'a> Linker for PtxLinker<'a> {
1282     fn cmd(&mut self) -> &mut Command {
1283         &mut self.cmd
1284     }
1285
1286     fn set_output_kind(&mut self, _output_kind: LinkOutputKind, _out_filename: &Path) {}
1287
1288     fn link_rlib(&mut self, path: &Path) {
1289         self.cmd.arg("--rlib").arg(path);
1290     }
1291
1292     fn link_whole_rlib(&mut self, path: &Path) {
1293         self.cmd.arg("--rlib").arg(path);
1294     }
1295
1296     fn include_path(&mut self, path: &Path) {
1297         self.cmd.arg("-L").arg(path);
1298     }
1299
1300     fn debuginfo(&mut self, _strip: Strip) {
1301         self.cmd.arg("--debug");
1302     }
1303
1304     fn add_object(&mut self, path: &Path) {
1305         self.cmd.arg("--bitcode").arg(path);
1306     }
1307
1308     fn optimize(&mut self) {
1309         match self.sess.lto() {
1310             Lto::Thin | Lto::Fat | Lto::ThinLocal => {
1311                 self.cmd.arg("-Olto");
1312             }
1313
1314             Lto::No => {}
1315         };
1316     }
1317
1318     fn output_filename(&mut self, path: &Path) {
1319         self.cmd.arg("-o").arg(path);
1320     }
1321
1322     fn finalize(&mut self) {
1323         // Provide the linker with fallback to internal `target-cpu`.
1324         self.cmd.arg("--fallback-arch").arg(match self.sess.opts.cg.target_cpu {
1325             Some(ref s) => s,
1326             None => &self.sess.target.cpu,
1327         });
1328     }
1329
1330     fn link_dylib(&mut self, _lib: Symbol) {
1331         panic!("external dylibs not supported")
1332     }
1333
1334     fn link_rust_dylib(&mut self, _lib: Symbol, _path: &Path) {
1335         panic!("external dylibs not supported")
1336     }
1337
1338     fn link_staticlib(&mut self, _lib: Symbol) {
1339         panic!("staticlibs not supported")
1340     }
1341
1342     fn link_whole_staticlib(&mut self, _lib: Symbol, _search_path: &[PathBuf]) {
1343         panic!("staticlibs not supported")
1344     }
1345
1346     fn framework_path(&mut self, _path: &Path) {
1347         panic!("frameworks not supported")
1348     }
1349
1350     fn link_framework(&mut self, _framework: Symbol) {
1351         panic!("frameworks not supported")
1352     }
1353
1354     fn full_relro(&mut self) {}
1355
1356     fn partial_relro(&mut self) {}
1357
1358     fn no_relro(&mut self) {}
1359
1360     fn gc_sections(&mut self, _keep_metadata: bool) {}
1361
1362     fn pgo_gen(&mut self) {}
1363
1364     fn no_crt_objects(&mut self) {}
1365
1366     fn no_default_libraries(&mut self) {}
1367
1368     fn control_flow_guard(&mut self) {}
1369
1370     fn export_symbols(&mut self, _tmpdir: &Path, _crate_type: CrateType) {}
1371
1372     fn subsystem(&mut self, _subsystem: &str) {}
1373
1374     fn group_start(&mut self) {}
1375
1376     fn group_end(&mut self) {}
1377
1378     fn linker_plugin_lto(&mut self) {}
1379 }