Skip to content

Commit 9f0f36e

Browse files
committed
[ELF] accept thinlto options without --plugin-opt= prefix
Summary: When support for ThinLTO was first added to lld, the options that control it were prefixed with --plugin-opt= for compatibility with an existing implementation as a linker plugin. This change enables shorter versions of the options to be used, as follows: New Existing -thinlto-emit-imports-files --plugin-opt=thinlto-emit-imports-files -thinlto-index-only --plugin-opt=thinlto-index-only -thinlto-index-only= --plugin-opt=thinlto-index-only= -thinlto-object-suffix-replace= --plugin-opt=thinlto-object-suffix-replace= -thinlto-prefix-replace= --plugin-opt=thinlto-prefix-replace= -lto-obj-path= --plugin-opt=obj-path= The options with the --plugin-opt= prefix have been retained as aliases for the shorter variants so that they continue to be accepted. Reviewers: tejohnson, ruiu, espindola Reviewed By: ruiu Subscribers: emaste, arichardson, MaskRay, steven_wu, dexonsmith, arphaman, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D67782 llvm-svn: 372798
1 parent 4cd7126 commit 9f0f36e

File tree

7 files changed

+70
-22
lines changed

7 files changed

+70
-22
lines changed

lld/ELF/Driver.cpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,12 @@ static bool getCompressDebugSections(opt::InputArgList &args) {
757757
return true;
758758
}
759759

760+
static StringRef getAliasSpelling(opt::Arg *arg) {
761+
if (const opt::Arg *alias = arg->getAlias())
762+
return alias->getSpelling();
763+
return arg->getSpelling();
764+
}
765+
760766
static std::pair<StringRef, StringRef> getOldNewOptions(opt::InputArgList &args,
761767
unsigned id) {
762768
auto *arg = args.getLastArg(id);
@@ -766,7 +772,7 @@ static std::pair<StringRef, StringRef> getOldNewOptions(opt::InputArgList &args,
766772
StringRef s = arg->getValue();
767773
std::pair<StringRef, StringRef> ret = s.split(';');
768774
if (ret.second.empty())
769-
error(arg->getSpelling() + " expects 'old;new' format, but got " + s);
775+
error(getAliasSpelling(arg) + " expects 'old;new' format, but got " + s);
770776
return ret;
771777
}
772778

@@ -858,7 +864,7 @@ static void readConfigs(opt::InputArgList &args) {
858864
config->ltoNewPassManager = args.hasArg(OPT_lto_new_pass_manager);
859865
config->ltoNewPmPasses = args.getLastArgValue(OPT_lto_newpm_passes);
860866
config->ltoo = args::getInteger(args, OPT_lto_O, 2);
861-
config->ltoObjPath = args.getLastArgValue(OPT_plugin_opt_obj_path_eq);
867+
config->ltoObjPath = args.getLastArgValue(OPT_lto_obj_path_eq);
862868
config->ltoPartitions = args::getInteger(args, OPT_lto_partitions, 1);
863869
config->ltoSampleProfile = args.getLastArgValue(OPT_lto_sample_profile);
864870
config->mapFile = args.getLastArgValue(OPT_Map);
@@ -903,17 +909,15 @@ static void readConfigs(opt::InputArgList &args) {
903909
config->thinLTOCachePolicy = CHECK(
904910
parseCachePruningPolicy(args.getLastArgValue(OPT_thinlto_cache_policy)),
905911
"--thinlto-cache-policy: invalid cache policy");
906-
config->thinLTOEmitImportsFiles =
907-
args.hasArg(OPT_plugin_opt_thinlto_emit_imports_files);
908-
config->thinLTOIndexOnly = args.hasArg(OPT_plugin_opt_thinlto_index_only) ||
909-
args.hasArg(OPT_plugin_opt_thinlto_index_only_eq);
910-
config->thinLTOIndexOnlyArg =
911-
args.getLastArgValue(OPT_plugin_opt_thinlto_index_only_eq);
912+
config->thinLTOEmitImportsFiles = args.hasArg(OPT_thinlto_emit_imports_files);
913+
config->thinLTOIndexOnly = args.hasArg(OPT_thinlto_index_only) ||
914+
args.hasArg(OPT_thinlto_index_only_eq);
915+
config->thinLTOIndexOnlyArg = args.getLastArgValue(OPT_thinlto_index_only_eq);
912916
config->thinLTOJobs = args::getInteger(args, OPT_thinlto_jobs, -1u);
913917
config->thinLTOObjectSuffixReplace =
914-
getOldNewOptions(args, OPT_plugin_opt_thinlto_object_suffix_replace_eq);
918+
getOldNewOptions(args, OPT_thinlto_object_suffix_replace_eq);
915919
config->thinLTOPrefixReplace =
916-
getOldNewOptions(args, OPT_plugin_opt_thinlto_prefix_replace_eq);
920+
getOldNewOptions(args, OPT_thinlto_prefix_replace_eq);
917921
config->trace = args.hasArg(OPT_trace);
918922
config->undefined = args::getStrings(args, OPT_undefined);
919923
config->undefinedVersion =

lld/ELF/Options.td

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ def lto_cs_profile_generate: F<"lto-cs-profile-generate">,
481481
HelpText<"Perform context senstive PGO instrumentation">;
482482
def lto_cs_profile_file: J<"lto-cs-profile-file=">,
483483
HelpText<"Context sensitive profile file path">;
484+
def lto_obj_path_eq: J<"lto-obj-path=">;
484485
def lto_sample_profile: J<"lto-sample-profile=">,
485486
HelpText<"Sample profile file path">;
486487
def disable_verify: F<"disable-verify">;
@@ -498,7 +499,12 @@ def save_temps: F<"save-temps">;
498499
def thinlto_cache_dir: J<"thinlto-cache-dir=">,
499500
HelpText<"Path to ThinLTO cached object file directory">;
500501
defm thinlto_cache_policy: Eq<"thinlto-cache-policy", "Pruning policy for the ThinLTO cache">;
502+
def thinlto_emit_imports_files: F<"thinlto-emit-imports-files">;
503+
def thinlto_index_only: F<"thinlto-index-only">;
504+
def thinlto_index_only_eq: J<"thinlto-index-only=">;
501505
def thinlto_jobs: J<"thinlto-jobs=">, HelpText<"Number of ThinLTO jobs">;
506+
def thinlto_object_suffix_replace_eq: J<"thinlto-object-suffix-replace=">;
507+
def thinlto_prefix_replace_eq: J<"thinlto-prefix-replace=">;
502508

503509
def: J<"plugin-opt=O">, Alias<lto_O>, HelpText<"Alias for -lto-O">;
504510
def: F<"plugin-opt=debug-pass-manager">,
@@ -512,19 +518,31 @@ def: J<"plugin-opt=lto-partitions=">, Alias<lto_partitions>, HelpText<"Alias for
512518
def plugin_opt_mcpu_eq: J<"plugin-opt=mcpu=">;
513519
def: F<"plugin-opt=new-pass-manager">,
514520
Alias<lto_new_pass_manager>, HelpText<"Alias for -lto-new-pass-manager">;
515-
def plugin_opt_obj_path_eq: J<"plugin-opt=obj-path=">;
516521
def: F<"plugin-opt=cs-profile-generate">,
517522
Alias<lto_cs_profile_generate>, HelpText<"Alias for -lto-cs-profile-generate">;
518523
def: J<"plugin-opt=cs-profile-path=">,
519524
Alias<lto_cs_profile_file>, HelpText<"Alias for -lto-cs-profile-file">;
525+
def: J<"plugin-opt=obj-path=">,
526+
Alias<lto_obj_path_eq>,
527+
HelpText<"Alias for -lto-obj-path=">;
520528
def: J<"plugin-opt=sample-profile=">,
521529
Alias<lto_sample_profile>, HelpText<"Alias for -lto-sample-profile">;
522530
def: F<"plugin-opt=save-temps">, Alias<save_temps>, HelpText<"Alias for -save-temps">;
523-
def plugin_opt_thinlto_emit_imports_files: F<"plugin-opt=thinlto-emit-imports-files">;
524-
def plugin_opt_thinlto_index_only: F<"plugin-opt=thinlto-index-only">;
525-
def plugin_opt_thinlto_index_only_eq: J<"plugin-opt=thinlto-index-only=">;
526-
def plugin_opt_thinlto_object_suffix_replace_eq: J<"plugin-opt=thinlto-object-suffix-replace=">;
527-
def plugin_opt_thinlto_prefix_replace_eq: J<"plugin-opt=thinlto-prefix-replace=">;
531+
def: F<"plugin-opt=thinlto-emit-imports-files">,
532+
Alias<thinlto_emit_imports_files>,
533+
HelpText<"Alias for -thinlto-emit-imports-files">;
534+
def: F<"plugin-opt=thinlto-index-only">,
535+
Alias<thinlto_index_only>,
536+
HelpText<"Alias for -thinlto-index-only">;
537+
def: J<"plugin-opt=thinlto-index-only=">,
538+
Alias<thinlto_index_only_eq>,
539+
HelpText<"Alias for -thinlto-index-only=">;
540+
def: J<"plugin-opt=thinlto-object-suffix-replace=">,
541+
Alias<thinlto_object_suffix_replace_eq>,
542+
HelpText<"Alias for -thinlto-object-suffix-replace=">;
543+
def: J<"plugin-opt=thinlto-prefix-replace=">,
544+
Alias<thinlto_prefix_replace_eq>,
545+
HelpText<"Alias for -thinlto-prefix-replace=">;
528546

529547
// Ignore LTO plugin-related options.
530548
// clang -flto passes -plugin and -plugin-opt to the linker. This is required

lld/test/ELF/lto/thinlto-emit-imports.ll

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414

1515
; The imports file for this module contains the bitcode file for
1616
; Inputs/thinlto.ll
17-
; RUN: cat %t1.o.imports | count 1
18-
; RUN: cat %t1.o.imports | FileCheck %s --check-prefix=IMPORTS1
17+
; RUN: count 1 < %t1.o.imports
18+
; RUN: FileCheck %s --check-prefix=IMPORTS1 < %t1.o.imports
1919
; IMPORTS1: thinlto-emit-imports.ll.tmp2.o
2020

2121
; The imports file for Input/thinlto.ll is empty as it does not import anything.
22-
; RUN: cat %t2.o.imports | count 0
22+
; RUN: count 0 < %t2.o.imports
2323

2424
; The imports file for Input/thinlto_empty.ll is empty but should exist.
25-
; RUN: cat %t3.o.imports | count 0
25+
; RUN: count 0 < %t3.o.imports
2626

2727
; The index file should be created even for the input with an empty summary.
2828
; RUN: ls %t3.o.thinlto.bc
@@ -43,6 +43,13 @@
4343
; RUN: not ls %t2.o.imports
4444
; RUN: not ls %t3.o.imports
4545

46+
; Check that imports files are generated also when -thinlto-index-only
47+
; is specified without --plugin-opt=.
48+
; RUN: rm -f %t1.o.imports
49+
; RUN: ld.lld -thinlto-index-only -thinlto-emit-imports-files -shared %t1.o %t2.o %t3.o -o %t4
50+
; RUN: count 1 < %t1.o.imports
51+
; RUN: FileCheck %s --check-prefix=IMPORTS1 < %t1.o.imports
52+
4653
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
4754
target triple = "x86_64-unknown-linux-gnu"
4855

lld/test/ELF/lto/thinlto-index-file.ll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,16 @@
66
; RUN: opt -module-summary %p/Inputs/thinlto_empty.ll -o %t3.o
77

88
; Ensure lld writes linked files to linked objects file
9-
; RUN: ld.lld --plugin-opt=thinlto-index-only=%t.idx -shared %t1.o %t2.o %t3.o -o %t4
9+
; RUN: ld.lld --plugin-opt=thinlto-index-only=%t.idx -shared %t1.o %t2.o %t3.o -o /dev/null
1010
; RUN: FileCheck %s < %t.idx
1111
; CHECK: {{.*}}thinlto-index-file.ll.tmp1.o
1212
; CHECK: {{.*}}thinlto-index-file.ll.tmp2.o
1313
; CHECK: {{.*}}thinlto-index-file.ll.tmp3.o
1414

15+
; Check that this also works without the --plugin-opt= prefix.
16+
; RUN: ld.lld -thinlto-index-only=%t.idx -shared %t1.o %t2.o %t3.o -o /dev/null
17+
; RUN: FileCheck %s < %t.idx
18+
1519
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
1620
target triple = "x86_64-unknown-linux-gnu"
1721

lld/test/ELF/lto/thinlto-obj-path.ll

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,16 @@
55

66
; Test to ensure that thinlto-index-only with obj-path creates the file.
77
; RUN: rm -f %t4.o
8-
; RUN: ld.lld --plugin-opt=thinlto-index-only --plugin-opt=obj-path=%t4.o -shared %t1.o %t2.o -o %t3
8+
; RUN: ld.lld --plugin-opt=thinlto-index-only --plugin-opt=obj-path=%t4.o -shared %t1.o %t2.o -o /dev/null
99
; RUN: llvm-readobj -h %t4.o | FileCheck %s
1010
; RUN: llvm-nm %t4.o 2>&1 | FileCheck %s -check-prefix=NO-SYMBOLS
1111
; NO-SYMBOLS: no symbols
1212

13+
; Check that this also works without the --plugin-opt= prefix.
14+
; RUN: rm -f %t4.o
15+
; RUN: ld.lld -thinlto-index-only -lto-obj-path=%t4.o -shared %t1.o %t2.o -o /dev/null
16+
; RUN: llvm-readobj -h %t4.o | FileCheck %s
17+
1318
; CHECK: Format: ELF64-x86-64
1419

1520
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"

lld/test/ELF/lto/thinlto-object-suffix-replace.ll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
; RUN: --plugin-opt=thinlto-object-suffix-replace=".thinlink.bc;.o" \
2222
; RUN: -shared %t1.thinlink.bc -o %t3
2323
; RUN: diff %t1.o.thinlto.bc.orig %t1.o.thinlto.bc
24+
; Also check that this works without the --plugin-opt= prefix.
25+
; RUN: ld.lld -thinlto-index-only \
26+
; RUN: -thinlto-object-suffix-replace=".thinlink.bc;.o" \
27+
; RUN: -shared %t1.thinlink.bc -o %t3
28+
; RUN: diff %t1.o.thinlto.bc.orig %t1.o.thinlto.bc
2429

2530
; Ensure lld generates error if object suffix replace option does not have 'old;new' format
2631
; RUN: rm -f %t1.o.thinlto.bc

lld/test/ELF/lto/thinlto-prefix-replace.ll

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
; RUN: ld.lld --plugin-opt=thinlto-index-only --plugin-opt=thinlto-prefix-replace="%t/oldpath/;%t/newpath/" -shared %t/oldpath/thinlto_prefix_replace.o -o %t/thinlto_prefix_replace
1010
; RUN: ls %t/newpath/thinlto_prefix_replace.o.thinlto.bc
1111

12+
; Check that this also works without the --plugin-opt= prefix.
13+
; RUN: rm -f %t/newpath/thinlto_prefix_replace.o.thinlto.bc
14+
; RUN: ld.lld -thinlto-index-only -thinlto-prefix-replace="%t/oldpath/;%t/newpath/" -shared %t/oldpath/thinlto_prefix_replace.o -o %t/thinlto_prefix_replace
15+
; RUN: ls %t/newpath/thinlto_prefix_replace.o.thinlto.bc
16+
1217
; Ensure that lld generates error if prefix replace option does not have 'old;new' format
1318
; RUN: rm -f %t/newpath/thinlto_prefix_replace.o.thinlto.bc
1419
; RUN: not ld.lld --plugin-opt=thinlto-index-only --plugin-opt=thinlto-prefix-replace=abc:def -shared %t/oldpath/thinlto_prefix_replace.o -o %t/thinlto_prefix_replace 2>&1 | FileCheck %s --check-prefix=ERR

0 commit comments

Comments
 (0)