Add --linker
option to pass flags to the linker
This commit is contained in:
parent
9f03d45c56
commit
00ede34fcb
@ -904,6 +904,9 @@ pub fn link_binary(sess: Session,
|
||||
// extern libraries might live, based on the addl_lib_search_paths
|
||||
cc_args.push_all(rpath::get_rpath_flags(sess, &output));
|
||||
|
||||
// Finally add all the linker arguments provided on the command line
|
||||
cc_args.push_all(sess.opts.linker_args);
|
||||
|
||||
debug!("%s link args: %s", cc_prog, str::connect(cc_args, ~" "));
|
||||
// We run 'cc' here
|
||||
let prog = run::program_output(cc_prog, cc_args);
|
||||
|
@ -645,9 +645,16 @@ pub fn build_session_options(binary: @~str,
|
||||
Some(s) => s
|
||||
};
|
||||
|
||||
let addl_lib_search_paths =
|
||||
getopts::opt_strs(matches, ~"L")
|
||||
.map(|s| Path(*s));
|
||||
let addl_lib_search_paths = getopts::opt_strs(matches, ~"L").map(|s| Path(*s));
|
||||
|
||||
let linker_args = getopts::opt_strs(matches, ~"linker").flat_map( |a| {
|
||||
let mut args = ~[];
|
||||
for str::each_split_char(*a, ',') |arg| {
|
||||
args.push(str::from_slice(arg));
|
||||
}
|
||||
args
|
||||
});
|
||||
|
||||
let cfg = parse_cfgspecs(getopts::opt_strs(matches, ~"cfg"), demitter);
|
||||
let test = opt_present(matches, ~"test");
|
||||
let android_cross_path = getopts::opt_maybe_str(
|
||||
@ -664,6 +671,7 @@ pub fn build_session_options(binary: @~str,
|
||||
jit: jit,
|
||||
output_type: output_type,
|
||||
addl_lib_search_paths: addl_lib_search_paths,
|
||||
linker_args: linker_args,
|
||||
maybe_sysroot: sysroot_opt,
|
||||
target_triple: target,
|
||||
target_feature: target_feature,
|
||||
@ -737,62 +745,66 @@ pub fn parse_pretty(sess: Session, name: &str) -> pp_mode {
|
||||
// rustc command line options
|
||||
pub fn optgroups() -> ~[getopts::groups::OptGroup] {
|
||||
~[
|
||||
optflag(~"", ~"bin", ~"Compile an executable crate (default)"),
|
||||
optflag(~"c", ~"", ~"Compile and assemble, but do not link"),
|
||||
optmulti(~"", ~"cfg", ~"Configure the compilation
|
||||
environment", ~"SPEC"),
|
||||
optflag(~"", ~"emit-llvm",
|
||||
~"Produce an LLVM bitcode file"),
|
||||
optflag(~"h", ~"help",~"Display this message"),
|
||||
optmulti(~"L", ~"", ~"Add a directory to the library search path",
|
||||
~"PATH"),
|
||||
optflag(~"", ~"lib", ~"Compile a library crate"),
|
||||
optflag(~"", ~"ls", ~"List the symbols defined by a library crate"),
|
||||
optflag(~"", ~"no-trans",
|
||||
~"Run all passes except translation; no output"),
|
||||
optflag(~"O", ~"", ~"Equivalent to --opt-level=2"),
|
||||
optopt(~"o", ~"", ~"Write output to <filename>", ~"FILENAME"),
|
||||
optopt(~"", ~"opt-level",
|
||||
~"Optimize with possible levels 0-3", ~"LEVEL"),
|
||||
optopt( ~"", ~"out-dir",
|
||||
~"Write output to compiler-chosen filename
|
||||
in <dir>", ~"DIR"),
|
||||
optflag(~"", ~"parse-only",
|
||||
~"Parse only; do not compile, assemble, or link"),
|
||||
optflagopt(~"", ~"pretty",
|
||||
~"Pretty-print the input instead of compiling;
|
||||
optflag("", "bin", "Compile an executable crate (default)"),
|
||||
optflag("c", "", "Compile and assemble, but do not link"),
|
||||
optmulti("", "cfg", "Configure the compilation
|
||||
environment", "SPEC"),
|
||||
optflag("", "emit-llvm",
|
||||
"Produce an LLVM bitcode file"),
|
||||
optflag("h", "help","Display this message"),
|
||||
optmulti("L", "", "Add a directory to the library search path",
|
||||
"PATH"),
|
||||
optflag("", "lib", "Compile a library crate"),
|
||||
optmulti("", "linker", "FLAGS is a comma-separated list of flags
|
||||
passed to the linker", "FLAGS"),
|
||||
optflag("", "ls", "List the symbols defined by a library crate"),
|
||||
optflag("", "no-trans",
|
||||
"Run all passes except translation; no output"),
|
||||
optflag("O", "", "Equivalent to --opt-level=2"),
|
||||
optopt("o", "", "Write output to <filename>", "FILENAME"),
|
||||
optopt("", "opt-level",
|
||||
"Optimize with possible levels 0-3", "LEVEL"),
|
||||
optopt( "", "out-dir",
|
||||
"Write output to compiler-chosen filename
|
||||
in <dir>", "DIR"),
|
||||
optflag("", "parse-only",
|
||||
"Parse only; do not compile, assemble, or link"),
|
||||
optflagopt("", "pretty",
|
||||
"Pretty-print the input instead of compiling;
|
||||
valid types are: normal (un-annotated source),
|
||||
expanded (crates expanded),
|
||||
typed (crates expanded, with type annotations),
|
||||
or identified (fully parenthesized,
|
||||
AST nodes and blocks with IDs)", ~"TYPE"),
|
||||
optflag(~"S", ~"", ~"Compile only; do not assemble or link"),
|
||||
optflag(~"", ~"save-temps",
|
||||
~"Write intermediate files (.bc, .opt.bc, .o)
|
||||
AST nodes and blocks with IDs)", "TYPE"),
|
||||
optflag("", "print-link-args", "Prints all the arguments that would be
|
||||
passed to the linker."),
|
||||
optflag("S", "", "Compile only; do not assemble or link"),
|
||||
optflag("", "save-temps",
|
||||
"Write intermediate files (.bc, .opt.bc, .o)
|
||||
in addition to normal output"),
|
||||
optopt(~"", ~"sysroot",
|
||||
~"Override the system root", ~"PATH"),
|
||||
optflag(~"", ~"test", ~"Build a test harness"),
|
||||
optopt(~"", ~"target",
|
||||
~"Target triple cpu-manufacturer-kernel[-os]
|
||||
optopt("", "sysroot",
|
||||
"Override the system root", "PATH"),
|
||||
optflag("", "test", "Build a test harness"),
|
||||
optopt("", "target",
|
||||
"Target triple cpu-manufacturer-kernel[-os]
|
||||
to compile for (see chapter 3.4 of http://www.sourceware.org/autobook/
|
||||
for detail)", ~"TRIPLE"),
|
||||
optopt(~"", ~"target-feature",
|
||||
~"Target specific attributes (llc -mattr=help
|
||||
for detail)", ~"FEATURE"),
|
||||
optopt(~"", ~"android-cross-path",
|
||||
~"The path to the Android NDK", "PATH"),
|
||||
optmulti(~"W", ~"warn",
|
||||
~"Set lint warnings", ~"OPT"),
|
||||
optmulti(~"A", ~"allow",
|
||||
~"Set lint allowed", ~"OPT"),
|
||||
optmulti(~"D", ~"deny",
|
||||
~"Set lint denied", ~"OPT"),
|
||||
optmulti(~"F", ~"forbid",
|
||||
~"Set lint forbidden", ~"OPT"),
|
||||
optmulti(~"Z", ~"", ~"Set internal debugging options", "FLAG"),
|
||||
optflag( ~"v", ~"version",
|
||||
~"Print version info and exit"),
|
||||
for detail)", "TRIPLE"),
|
||||
optopt("", "target-feature",
|
||||
"Target specific attributes (llc -mattr=help
|
||||
for detail)", "FEATURE"),
|
||||
optopt("", "android-cross-path",
|
||||
"The path to the Android NDK", "PATH"),
|
||||
optmulti("W", "warn",
|
||||
"Set lint warnings", "OPT"),
|
||||
optmulti("A", "allow",
|
||||
"Set lint allowed", "OPT"),
|
||||
optmulti("D", "deny",
|
||||
"Set lint denied", "OPT"),
|
||||
optmulti("F", "forbid",
|
||||
"Set lint forbidden", "OPT"),
|
||||
optmulti("Z", "", "Set internal debugging options", "FLAG"),
|
||||
optflag( "v", "version",
|
||||
"Print version info and exit"),
|
||||
]
|
||||
}
|
||||
|
||||
|
@ -122,6 +122,7 @@ pub struct options {
|
||||
jit: bool,
|
||||
output_type: back::link::output_type,
|
||||
addl_lib_search_paths: ~[Path],
|
||||
linker_args: ~[~str],
|
||||
maybe_sysroot: Option<Path>,
|
||||
target_triple: ~str,
|
||||
target_feature: ~str,
|
||||
@ -299,6 +300,7 @@ pub fn basic_options() -> @options {
|
||||
jit: false,
|
||||
output_type: link::output_type_exe,
|
||||
addl_lib_search_paths: ~[],
|
||||
linker_args:~[],
|
||||
maybe_sysroot: None,
|
||||
target_triple: host_triple(),
|
||||
target_feature: ~"",
|
||||
|
Loading…
x
Reference in New Issue
Block a user