[ELF] - Introduce multiclass Eq helper for Options.td

Eq helper allows to define `XXX` and `XXX=` options forms easily.
Patch adds testcases for few aliases.

Differential revision: https://reviews.llvm.org/D35619

llvm-svn: 308752
This commit is contained in:
George Rimar 2017-07-21 16:27:26 +00:00
parent 2f3073b5cb
commit 4f37d57547
10 changed files with 82 additions and 73 deletions

View File

@ -660,7 +660,7 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) {
Config->Rpath = getRpath(Args);
Config->Relocatable = Args.hasArg(OPT_relocatable);
Config->SaveTemps = Args.hasArg(OPT_save_temps);
Config->SearchPaths = getArgs(Args, OPT_L);
Config->SearchPaths = getArgs(Args, OPT_library_path);
Config->SectionStartMap = getSectionStartMap(Args);
Config->Shared = Args.hasArg(OPT_shared);
Config->SingleRoRx = Args.hasArg(OPT_no_rosegment);
@ -806,7 +806,7 @@ static bool getBinaryOption(StringRef S) {
void LinkerDriver::createFiles(opt::InputArgList &Args) {
for (auto *Arg : Args) {
switch (Arg->getOption().getUnaliasedOption().getID()) {
case OPT_l:
case OPT_library:
addLibrary(Arg->getValue());
break;
case OPT_INPUT:

View File

@ -155,8 +155,8 @@ std::string elf::createResponseFile(const opt::InputArgList &Args) {
// Strip directories to prevent the issue.
OS << "-o " << quote(sys::path::filename(Arg->getValue())) << "\n";
break;
case OPT_L:
case OPT_dynamic_list:
case OPT_library_path:
case OPT_rpath:
case OPT_script:
case OPT_version_script:

View File

@ -7,6 +7,11 @@ class J<string name>: Joined<["--", "-"], name>;
class S<string name>: Separate<["--", "-"], name>;
class JS<string name>: JoinedOrSeparate<["--", "-"], name>;
multiclass Eq<string name> {
def "": Separate<["--", "-"], name>;
def _eq: Joined<["--", "-"], name # "=">, Alias<!cast<Separate>(NAME)>;
}
def auxiliary: S<"auxiliary">, HelpText<"Set DT_AUXILIARY field to the specified name">;
def Bsymbolic: F<"Bsymbolic">, HelpText<"Bind defined symbols locally">;
@ -22,21 +27,24 @@ def build_id: F<"build-id">, HelpText<"Generate build ID note">;
def build_id_eq: J<"build-id=">, HelpText<"Generate build ID note">;
def compress_debug_sections : J<"compress-debug-sections=">,
defm compress_debug_sections : Eq<"compress-debug-sections">,
HelpText<"Compress DWARF debug sections">;
def defsym: J<"defsym=">, HelpText<"Define a symbol alias">;
defm defsym: Eq<"defsym">, HelpText<"Define a symbol alias">;
def L: JoinedOrSeparate<["-"], "L">, MetaVarName<"<dir>">,
HelpText<"Add a directory to the library search path">;
defm library_path: Eq<"library-path">,
HelpText<"Add a directory to the library search path">, MetaVarName<"<dir>">;
def O: Joined<["-"], "O">, HelpText<"Optimize output file size">;
def Tbss: S<"Tbss">, HelpText<"Same as --section-start with .bss as the sectionname">;
defm Tbss: Eq<"Tbss">,
HelpText<"Same as --section-start with .bss as the sectionname">;
def Tdata: S<"Tdata">, HelpText<"Same as --section-start with .data as the sectionname">;
defm Tdata: Eq<"Tdata">,
HelpText<"Same as --section-start with .data as the sectionname">;
def Ttext: S<"Ttext">, HelpText<"Same as --section-start with .text as the sectionname">;
defm Ttext: Eq<"Ttext">,
HelpText<"Same as --section-start with .text as the sectionname">;
def allow_multiple_definition: F<"allow-multiple-definition">,
HelpText<"Allow multiple definitions">;
@ -72,7 +80,7 @@ def discard_none: F<"discard-none">,
def dynamic_linker: S<"dynamic-linker">,
HelpText<"Which dynamic linker to use">;
def dynamic_list: S<"dynamic-list">,
defm dynamic_list: Eq<"dynamic-list">,
HelpText<"Read a list of dynamic symbols">;
def eh_frame_hdr: F<"eh-frame-hdr">,
@ -86,37 +94,39 @@ def enable_new_dtags: F<"enable-new-dtags">,
def end_lib: F<"end-lib">,
HelpText<"End a grouping of objects that should be treated as if they were together in an archive">;
def entry: S<"entry">, MetaVarName<"<entry>">,
HelpText<"Name of entry point symbol">;
defm entry: Eq<"entry">, HelpText<"Name of entry point symbol">,
MetaVarName<"<entry>">;
def error_limit: S<"error-limit">,
defm error_limit: Eq<"error-limit">,
HelpText<"Maximum number of errors to emit before stopping (0 = no limit)">;
def error_unresolved_symbols: F<"error-unresolved-symbols">,
HelpText<"Report unresolved symbols as errors">;
def exclude_libs: S<"exclude-libs">,
defm exclude_libs: Eq<"exclude-libs">,
HelpText<"Exclude static libraries from automatic export">;
def export_dynamic: F<"export-dynamic">,
HelpText<"Put symbols in the dynamic symbol table">;
def export_dynamic_symbol: S<"export-dynamic-symbol">,
defm export_dynamic_symbol: Eq<"export-dynamic-symbol">,
HelpText<"Put a symbol in the dynamic symbol table">;
def fatal_warnings: F<"fatal-warnings">,
HelpText<"Treat warnings as errors">;
def filter: J<"filter=">, HelpText<"Set DT_FILTER field to the specified name">;
defm filter: Eq<"filter">,
HelpText<"Set DT_FILTER field to the specified name">;
def fini: S<"fini">, MetaVarName<"<symbol>">,
HelpText<"Specify a finalizer function">;
defm fini: Eq<"fini">,
HelpText<"Specify a finalizer function">, MetaVarName<"<symbol>">;
def full_shutdown : F<"full-shutdown">,
HelpText<"Perform a full shutdown instead of calling _exit">;
def format: J<"format=">, MetaVarName<"<input-format>">,
HelpText<"Change the input format of the inputs following this option">;
defm format: Eq<"format">,
HelpText<"Change the input format of the inputs following this option">,
MetaVarName<"<input-format>">;
def gc_sections: F<"gc-sections">,
HelpText<"Enable garbage collection of unused sections">;
@ -124,27 +134,27 @@ def gc_sections: F<"gc-sections">,
def gdb_index: F<"gdb-index">,
HelpText<"Generate .gdb_index section">;
def hash_style: S<"hash-style">,
defm hash_style: Eq<"hash-style">,
HelpText<"Specify hash style (sysv, gnu or both)">;
def help: F<"help">, HelpText<"Print option help">;
def icf: F<"icf=all">, HelpText<"Enable identical code folding">;
def image_base : J<"image-base=">, HelpText<"Set the base address">;
defm image_base : Eq<"image-base">, HelpText<"Set the base address">;
def init: S<"init">, MetaVarName<"<symbol>">,
HelpText<"Specify an initializer function">;
defm init: Eq<"init">, HelpText<"Specify an initializer function">,
MetaVarName<"<symbol>">;
def l: JoinedOrSeparate<["-"], "l">, MetaVarName<"<libName>">,
HelpText<"Root name of library to use">;
defm library: Eq<"library">, HelpText<"Root name of library to use">,
MetaVarName<"<libName>">;
def lto_O: J<"lto-O">, MetaVarName<"<opt-level>">,
HelpText<"Optimization level for LTO">;
def m: JoinedOrSeparate<["-"], "m">, HelpText<"Set target emulation">;
def Map: JS<"Map">, HelpText<"Print a link map to the specified file">;
defm Map: Eq<"Map">, HelpText<"Print a link map to the specified file">;
def nostdlib: F<"nostdlib">,
HelpText<"Only search directories specified on the command line">;
@ -184,7 +194,8 @@ def noinhibit_exec: F<"noinhibit-exec">,
def nopie: F<"nopie">, HelpText<"Do not create a position independent executable">;
def no_rosegment: F<"no-rosegment">, HelpText<"Do not put read-only non-executable sections in their own segment">;
def no_rosegment: F<"no-rosegment">,
HelpText<"Do not put read-only non-executable sections in their own segment">;
def no_undefined: F<"no-undefined">,
HelpText<"Report unresolved symbols even if the linker is creating a shared library">;
@ -209,26 +220,28 @@ def print_gc_sections: F<"print-gc-sections">,
def print_map: F<"print-map">,
HelpText<"Print a link map to the standard output">;
def reproduce: S<"reproduce">,
defm reproduce: Eq<"reproduce">,
HelpText<"Dump linker invocation and input files for debugging">;
def rpath: S<"rpath">, HelpText<"Add a DT_RUNPATH to the output">;
defm rpath: Eq<"rpath">, HelpText<"Add a DT_RUNPATH to the output">;
def relocatable: F<"relocatable">, HelpText<"Create relocatable object file">;
def retain_symbols_file: J<"retain-symbols-file=">, MetaVarName<"<file>">,
HelpText<"Retain only the symbols listed in the file">;
defm retain_symbols_file: Eq<"retain-symbols-file">,
HelpText<"Retain only the symbols listed in the file">,
MetaVarName<"<file>">;
def script: S<"script">, HelpText<"Read linker script">;
defm script: Eq<"script">, HelpText<"Read linker script">;
def section_start: S<"section-start">, MetaVarName<"<address>">,
HelpText<"Set address of section">;
def shared: F<"shared">, HelpText<"Build a shared object">;
def soname: J<"soname=">, HelpText<"Set DT_SONAME">;
defm soname: Eq<"soname">, HelpText<"Set DT_SONAME">;
def sort_section: S<"sort-section">, HelpText<"Specifies sections sorting rule when linkerscript is used">;
defm sort_section: Eq<"sort-section">,
HelpText<"Specifies sections sorting rule when linkerscript is used">;
def start_lib: F<"start-lib">,
HelpText<"Start a grouping of objects that should be treated as if they were together in an archive">;
@ -240,27 +253,29 @@ def strip_debug: F<"strip-debug">, HelpText<"Strip debugging information">;
def symbol_ordering_file: S<"symbol-ordering-file">,
HelpText<"Layout sections in the order specified by symbol file">;
def sysroot: J<"sysroot=">, HelpText<"Set the system root">;
defm sysroot: Eq<"sysroot">, HelpText<"Set the system root">;
def target1_rel: F<"target1-rel">, HelpText<"Interpret R_ARM_TARGET1 as R_ARM_REL32">;
def target1_abs: F<"target1-abs">, HelpText<"Interpret R_ARM_TARGET1 as R_ARM_ABS32">;
def target2: J<"target2=">, MetaVarName<"<type>">, HelpText<"Interpret R_ARM_TARGET2 as <type>, where <type> is one of rel, abs, or got-rel">;
defm target2: Eq<"target2">,
HelpText<"Interpret R_ARM_TARGET2 as <type>, where <type> is one of rel, abs, or got-rel">,
MetaVarName<"<type>">;
def threads: F<"threads">, HelpText<"Run the linker multi-threaded">;
def trace: F<"trace">, HelpText<"Print the names of the input files">;
def trace_symbol : S<"trace-symbol">, HelpText<"Trace references to symbols">;
defm trace_symbol : Eq<"trace-symbol">, HelpText<"Trace references to symbols">;
def undefined: S<"undefined">,
defm undefined: Eq<"undefined">,
HelpText<"Force undefined symbol during linking">;
def unresolved_symbols: J<"unresolved-symbols=">,
defm unresolved_symbols: Eq<"unresolved-symbols">,
HelpText<"Determine how to handle unresolved symbols">;
def rsp_quoting: J<"rsp-quoting=">,
defm rsp_quoting: Eq<"rsp-quoting">,
HelpText<"Quoting style for response files. Values supported: windows|posix">;
def v: Flag<["-"], "v">, HelpText<"Display the version number">;
@ -269,8 +284,7 @@ def verbose: F<"verbose">, HelpText<"Verbose mode">;
def version: F<"version">, HelpText<"Display the version number and exit">;
def version_script: S<"version-script">,
HelpText<"Read a version script">;
defm version_script: Eq<"version-script">, HelpText<"Read a version script">;
def warn_common: F<"warn-common">,
HelpText<"Warn about duplicate common symbols">;
@ -281,8 +295,8 @@ def warn_unresolved_symbols: F<"warn-unresolved-symbols">,
def whole_archive: F<"whole-archive">,
HelpText<"Force load of all members in a static library">;
def wrap: S<"wrap">, MetaVarName<"<symbol>">,
HelpText<"Use wrapper functions for symbol">;
defm wrap: Eq<"wrap">, HelpText<"Use wrapper functions for symbol">,
MetaVarName<"<symbol>">;
def z: JoinedOrSeparate<["-"], "z">, MetaVarName<"<option>">,
HelpText<"Linker option extensions">;
@ -294,60 +308,36 @@ def alias_Bdynamic_dy: F<"dy">, Alias<Bdynamic>;
def alias_Bstatic_dn: F<"dn">, Alias<Bstatic>;
def alias_Bstatic_non_shared: F<"non_shared">, Alias<Bstatic>;
def alias_Bstatic_static: F<"static">, Alias<Bstatic>;
def alias_L__library_path: J<"library-path=">, Alias<L>;
def alias_define_common_d: Flag<["-"], "d">, Alias<define_common>;
def alias_define_common_dc: F<"dc">, Alias<define_common>;
def alias_define_common_dp: F<"dp">, Alias<define_common>;
def alias_defsym: S<"defsym">, Alias<defsym>;
def alias_discard_all_x: Flag<["-"], "x">, Alias<discard_all>;
def alias_discard_locals_X: Flag<["-"], "X">, Alias<discard_locals>;
def alias_dynamic_list: J<"dynamic-list=">, Alias<dynamic_list>;
def alias_emit_relocs: Flag<["-"], "q">, Alias<emit_relocs>;
def alias_entry_e: JoinedOrSeparate<["-"], "e">, Alias<entry>;
def alias_entry_entry: J<"entry=">, Alias<entry>;
def alias_error_limit: J<"error-limit=">, Alias<error_limit>;
def alias_exclude_libs: J<"exclude-libs=">, Alias<exclude_libs>;
def alias_export_dynamic_E: Flag<["-"], "E">, Alias<export_dynamic>;
def alias_export_dynamic_symbol: J<"export-dynamic-symbol=">,
Alias<export_dynamic_symbol>;
def alias_filter: Separate<["-"], "F">, Alias<filter>;
def alias_fini_fini: J<"fini=">, Alias<fini>;
def alias_format_b: S<"b">, Alias<format>;
def alias_hash_style_hash_style: J<"hash-style=">, Alias<hash_style>;
def alias_init_init: J<"init=">, Alias<init>;
def alias_l__library: J<"library=">, Alias<l>;
def alias_Map_eq: J<"Map=">, Alias<Map>;
def alias_library: JoinedOrSeparate<["-"], "l">, Alias<library>;
def alias_library_path: JoinedOrSeparate<["-"], "L">, Alias<library_path>;
def alias_omagic: Flag<["-"], "N">, Alias<omagic>;
def alias_o_output: Joined<["--"], "output=">, Alias<o>;
def alias_o_output2 : Separate<["--"], "output">, Alias<o>;
def alias_pie_pic_executable: F<"pic-executable">, Alias<pie>;
def alias_print_map_M: Flag<["-"], "M">, Alias<print_map>;
def alias_relocatable_r: Flag<["-"], "r">, Alias<relocatable>;
def alias_reproduce_eq: J<"reproduce=">, Alias<reproduce>;
def alias_retain_symbols_file: S<"retain-symbols-file">, Alias<retain_symbols_file>;
def alias_rpath_R: JoinedOrSeparate<["-"], "R">, Alias<rpath>;
def alias_rpath_rpath: J<"rpath=">, Alias<rpath>;
def alias_script_T: JoinedOrSeparate<["-"], "T">, Alias<script>;
def alias_shared_Bshareable: F<"Bshareable">, Alias<shared>;
def alias_soname_h: JoinedOrSeparate<["-"], "h">, Alias<soname>;
def alias_soname_soname: S<"soname">, Alias<soname>;
def alias_sort_section: J<"sort-section=">, Alias<sort_section>;
def alias_script: J<"script=">, Alias<script>;
def alias_strip_all: Flag<["-"], "s">, Alias<strip_all>;
def alias_strip_debug_S: Flag<["-"], "S">, Alias<strip_debug>;
def alias_Tbss: J<"Tbss=">, Alias<Tbss>;
def alias_Tdata: J<"Tdata=">, Alias<Tdata>;
def alias_trace: Flag<["-"], "t">, Alias<trace>;
def trace_trace_symbol_eq : J<"trace-symbol=">, Alias<trace_symbol>;
def alias_trace_symbol_y : JoinedOrSeparate<["-"], "y">, Alias<trace_symbol>;
def alias_Ttext: J<"Ttext=">, Alias<Ttext>;
def alias_Ttext_segment: S<"Ttext-segment">, Alias<Ttext>;
def alias_Ttext_segment_eq: J<"Ttext-segment=">, Alias<Ttext>;
def alias_undefined_eq: J<"undefined=">, Alias<undefined>;
def alias_undefined_u: JoinedOrSeparate<["-"], "u">, Alias<undefined>;
def alias_version_script_eq: J<"version-script=">, Alias<version_script>;
def alias_version_V: Flag<["-"], "V">, Alias<version>;
def alias_wrap_wrap: J<"wrap=">, Alias<wrap>;
// Our symbol resolution algorithm handles symbols in archive files differently
// than traditional linkers, so we don't need --start-group and --end-group.

View File

@ -21,6 +21,11 @@
# DEBUGSTR-NEXT: AAAAAAAAAAAAAAAAAAAAAAAAAAA
# DEBUGSTR-NEXT: BBBBBBBBBBBBBBBBBBBBBBBBBBB
## Test alias.
# RUN: ld.lld %t.o -o %t2 --compress-debug-sections zlib
# RUN: llvm-objdump -s %t2 | FileCheck %s --check-prefix=ZLIBCONTENT
# RUN: llvm-readobj -s %t2 | FileCheck %s --check-prefix=ZLIBFLAGS
# RUN: not ld.lld %t.o -o %t1 --compress-debug-sections=zlib-gabi 2>&1 | \
# RUN: FileCheck -check-prefix=ERR %s
# ERR: unknown --compress-debug-sections value: zlib-gabi

View File

@ -1,6 +1,7 @@
// RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
// RUN: cd %S
// RUN: not ld.lld %t.o --format=binary duplicated-synthetic-sym.s -o %t.elf 2>&1 | FileCheck %s
// RUN: not ld.lld %t.o --format binary duplicated-synthetic-sym.s -o %t.elf 2>&1 | FileCheck %s
// CHECK: duplicate symbol: _binary_duplicated_synthetic_sym_s_start
// CHECK: defined at (internal):(.data+0x0)

View File

@ -2,10 +2,14 @@
# RUN: ld.lld %t.o -shared -F foo.so -F boo.so -o %t1
# RUN: llvm-readobj --dynamic-table %t1 | FileCheck %s
# Test alias.
# Test alias #1.
# RUN: ld.lld %t.o -shared --filter=foo.so --filter=boo.so -o %t2
# RUN: llvm-readobj --dynamic-table %t2 | FileCheck %s
# Test alias #2.
# RUN: ld.lld %t.o -shared --filter foo.so --filter boo.so -o %t3
# RUN: llvm-readobj --dynamic-table %t3 | FileCheck %s
# CHECK: DynamicSection [
# CHECK-NEXT: Tag Type Name/Value
# CHECK-NEXT: 0x000000007FFFFFFF FILTER Filter library: [foo.so]

View File

@ -6,6 +6,9 @@
# RUN: ld.lld -image-base=0x1000 -z max-page-size=0x2000 %t -o %t1 2>&1 | FileCheck --check-prefix=WARN %s
# WARN: warning: -image-base: address isn't multiple of page size: 0x1000
# Check alias.
# RUN: ld.lld -image-base 0x1000000 %t -o %t1
# RUN: llvm-readobj -program-headers %t1 | FileCheck %s
.global _start
_start:

View File

@ -60,6 +60,7 @@
// Check long forms as well
// RUN: ld.lld -o %t3 %t.o --library-path=%t.dir --library=ls
// RUN: ld.lld -o %t3 %t.o --library-path %t.dir --library ls
// Should not search for dynamic libraries if -Bstatic is specified
// RUN: ld.lld -o %t3 %t.o -L%t.dir -Bstatic -lls

View File

@ -28,6 +28,8 @@
// Should substitute SysRoot if specified
// RUN: ld.lld -o %t/r %t/m.o --sysroot=%t -L=lib -l:libls.a
// RUN: ld.lld -o %t/r %t/m.o --sysroot=%t -L=/lib -l:libls.a
// Check alias.
// RUN: ld.lld -o %t/r %t/m.o --sysroot %t -L=lib -l:libls.a
// Should not substitute SysRoot if the directory name does not start with '='
// RUN: not ld.lld -o %t/r %r/m.o --sysroot=%t -Llib -l:libls.a

View File

@ -13,6 +13,9 @@
# RUN: not ld.lld %t1.o %t2.o -o %t --unresolved-symbols=xxx 2>&1 | \
# RUN: FileCheck -check-prefix=ERR1 %s
# ERR1: unknown --unresolved-symbols value: xxx
## Check alias.
# RUN: not ld.lld %t1.o %t2.o -o %t --unresolved-symbols xxx 2>&1 | \
# RUN: FileCheck -check-prefix=ERR1 %s
## Ignore all should not produce error for symbols from object except
## case when --no-undefined specified.