Skip to content

Commit 00ede34

Browse files
author
James Miller
committed
Add --linker option to pass flags to the linker
1 parent 9f03d45 commit 00ede34

File tree

3 files changed

+70
-53
lines changed

3 files changed

+70
-53
lines changed

src/librustc/back/link.rs

+3
Original file line numberDiff line numberDiff line change
@@ -904,6 +904,9 @@ pub fn link_binary(sess: Session,
904904
// extern libraries might live, based on the addl_lib_search_paths
905905
cc_args.push_all(rpath::get_rpath_flags(sess, &output));
906906
907+
// Finally add all the linker arguments provided on the command line
908+
cc_args.push_all(sess.opts.linker_args);
909+
907910
debug!("%s link args: %s", cc_prog, str::connect(cc_args, ~" "));
908911
// We run 'cc' here
909912
let prog = run::program_output(cc_prog, cc_args);

src/librustc/driver/driver.rs

+65-53
Original file line numberDiff line numberDiff line change
@@ -645,9 +645,16 @@ pub fn build_session_options(binary: @~str,
645645
Some(s) => s
646646
};
647647
648-
let addl_lib_search_paths =
649-
getopts::opt_strs(matches, ~"L")
650-
.map(|s| Path(*s));
648+
let addl_lib_search_paths = getopts::opt_strs(matches, ~"L").map(|s| Path(*s));
649+
650+
let linker_args = getopts::opt_strs(matches, ~"linker").flat_map( |a| {
651+
let mut args = ~[];
652+
for str::each_split_char(*a, ',') |arg| {
653+
args.push(str::from_slice(arg));
654+
}
655+
args
656+
});
657+
651658
let cfg = parse_cfgspecs(getopts::opt_strs(matches, ~"cfg"), demitter);
652659
let test = opt_present(matches, ~"test");
653660
let android_cross_path = getopts::opt_maybe_str(
@@ -664,6 +671,7 @@ pub fn build_session_options(binary: @~str,
664671
jit: jit,
665672
output_type: output_type,
666673
addl_lib_search_paths: addl_lib_search_paths,
674+
linker_args: linker_args,
667675
maybe_sysroot: sysroot_opt,
668676
target_triple: target,
669677
target_feature: target_feature,
@@ -737,62 +745,66 @@ pub fn parse_pretty(sess: Session, name: &str) -> pp_mode {
737745
// rustc command line options
738746
pub fn optgroups() -> ~[getopts::groups::OptGroup] {
739747
~[
740-
optflag(~"", ~"bin", ~"Compile an executable crate (default)"),
741-
optflag(~"c", ~"", ~"Compile and assemble, but do not link"),
742-
optmulti(~"", ~"cfg", ~"Configure the compilation
743-
environment", ~"SPEC"),
744-
optflag(~"", ~"emit-llvm",
745-
~"Produce an LLVM bitcode file"),
746-
optflag(~"h", ~"help",~"Display this message"),
747-
optmulti(~"L", ~"", ~"Add a directory to the library search path",
748-
~"PATH"),
749-
optflag(~"", ~"lib", ~"Compile a library crate"),
750-
optflag(~"", ~"ls", ~"List the symbols defined by a library crate"),
751-
optflag(~"", ~"no-trans",
752-
~"Run all passes except translation; no output"),
753-
optflag(~"O", ~"", ~"Equivalent to --opt-level=2"),
754-
optopt(~"o", ~"", ~"Write output to <filename>", ~"FILENAME"),
755-
optopt(~"", ~"opt-level",
756-
~"Optimize with possible levels 0-3", ~"LEVEL"),
757-
optopt( ~"", ~"out-dir",
758-
~"Write output to compiler-chosen filename
759-
in <dir>", ~"DIR"),
760-
optflag(~"", ~"parse-only",
761-
~"Parse only; do not compile, assemble, or link"),
762-
optflagopt(~"", ~"pretty",
763-
~"Pretty-print the input instead of compiling;
748+
optflag("", "bin", "Compile an executable crate (default)"),
749+
optflag("c", "", "Compile and assemble, but do not link"),
750+
optmulti("", "cfg", "Configure the compilation
751+
environment", "SPEC"),
752+
optflag("", "emit-llvm",
753+
"Produce an LLVM bitcode file"),
754+
optflag("h", "help","Display this message"),
755+
optmulti("L", "", "Add a directory to the library search path",
756+
"PATH"),
757+
optflag("", "lib", "Compile a library crate"),
758+
optmulti("", "linker", "FLAGS is a comma-separated list of flags
759+
passed to the linker", "FLAGS"),
760+
optflag("", "ls", "List the symbols defined by a library crate"),
761+
optflag("", "no-trans",
762+
"Run all passes except translation; no output"),
763+
optflag("O", "", "Equivalent to --opt-level=2"),
764+
optopt("o", "", "Write output to <filename>", "FILENAME"),
765+
optopt("", "opt-level",
766+
"Optimize with possible levels 0-3", "LEVEL"),
767+
optopt( "", "out-dir",
768+
"Write output to compiler-chosen filename
769+
in <dir>", "DIR"),
770+
optflag("", "parse-only",
771+
"Parse only; do not compile, assemble, or link"),
772+
optflagopt("", "pretty",
773+
"Pretty-print the input instead of compiling;
764774
valid types are: normal (un-annotated source),
765775
expanded (crates expanded),
766776
typed (crates expanded, with type annotations),
767777
or identified (fully parenthesized,
768-
AST nodes and blocks with IDs)", ~"TYPE"),
769-
optflag(~"S", ~"", ~"Compile only; do not assemble or link"),
770-
optflag(~"", ~"save-temps",
771-
~"Write intermediate files (.bc, .opt.bc, .o)
778+
AST nodes and blocks with IDs)", "TYPE"),
779+
optflag("", "print-link-args", "Prints all the arguments that would be
780+
passed to the linker."),
781+
optflag("S", "", "Compile only; do not assemble or link"),
782+
optflag("", "save-temps",
783+
"Write intermediate files (.bc, .opt.bc, .o)
772784
in addition to normal output"),
773-
optopt(~"", ~"sysroot",
774-
~"Override the system root", ~"PATH"),
775-
optflag(~"", ~"test", ~"Build a test harness"),
776-
optopt(~"", ~"target",
777-
~"Target triple cpu-manufacturer-kernel[-os]
785+
optopt("", "sysroot",
786+
"Override the system root", "PATH"),
787+
optflag("", "test", "Build a test harness"),
788+
optopt("", "target",
789+
"Target triple cpu-manufacturer-kernel[-os]
778790
to compile for (see chapter 3.4 of http://www.sourceware.org/autobook/
779-
for detail)", ~"TRIPLE"),
780-
optopt(~"", ~"target-feature",
781-
~"Target specific attributes (llc -mattr=help
782-
for detail)", ~"FEATURE"),
783-
optopt(~"", ~"android-cross-path",
784-
~"The path to the Android NDK", "PATH"),
785-
optmulti(~"W", ~"warn",
786-
~"Set lint warnings", ~"OPT"),
787-
optmulti(~"A", ~"allow",
788-
~"Set lint allowed", ~"OPT"),
789-
optmulti(~"D", ~"deny",
790-
~"Set lint denied", ~"OPT"),
791-
optmulti(~"F", ~"forbid",
792-
~"Set lint forbidden", ~"OPT"),
793-
optmulti(~"Z", ~"", ~"Set internal debugging options", "FLAG"),
794-
optflag( ~"v", ~"version",
795-
~"Print version info and exit"),
791+
for detail)", "TRIPLE"),
792+
optopt("", "target-feature",
793+
"Target specific attributes (llc -mattr=help
794+
for detail)", "FEATURE"),
795+
optopt("", "android-cross-path",
796+
"The path to the Android NDK", "PATH"),
797+
optmulti("W", "warn",
798+
"Set lint warnings", "OPT"),
799+
optmulti("A", "allow",
800+
"Set lint allowed", "OPT"),
801+
optmulti("D", "deny",
802+
"Set lint denied", "OPT"),
803+
optmulti("F", "forbid",
804+
"Set lint forbidden", "OPT"),
805+
optmulti("Z", "", "Set internal debugging options", "FLAG"),
806+
optflag( "v", "version",
807+
"Print version info and exit"),
796808
]
797809
}
798810

src/librustc/driver/session.rs

+2
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ pub struct options {
122122
jit: bool,
123123
output_type: back::link::output_type,
124124
addl_lib_search_paths: ~[Path],
125+
linker_args: ~[~str],
125126
maybe_sysroot: Option<Path>,
126127
target_triple: ~str,
127128
target_feature: ~str,
@@ -299,6 +300,7 @@ pub fn basic_options() -> @options {
299300
jit: false,
300301
output_type: link::output_type_exe,
301302
addl_lib_search_paths: ~[],
303+
linker_args:~[],
302304
maybe_sysroot: None,
303305
target_triple: host_triple(),
304306
target_feature: ~"",

0 commit comments

Comments
 (0)