Skip to content

Commit

Permalink
[ELF] Enforce two dashes for Flag options not supported by GNU ld (i.…
Browse files Browse the repository at this point in the history
…e. no compatibility burden)

Announced on https://lists.llvm.org/pipermail/llvm-dev/2020-May/141416.html

Similar to D79371, but for `multiclass B` (convenience helper for defining --foo and --no-foo)

Some changed options are also used by gold, but I haven't seen their
one-dash use cases outside of lld's testsuite.
  • Loading branch information
MaskRay committed May 15, 2020
1 parent b1c688d commit e36223c
Show file tree
Hide file tree
Showing 11 changed files with 29 additions and 24 deletions.
33 changes: 19 additions & 14 deletions lld/ELF/Options.td
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ multiclass EEq<string name, string help> {
HelpText<help>;
}

multiclass BB<string name, string help1, string help2> {
def NAME: Flag<["--"], name>, HelpText<help1>;
def no_ # NAME: Flag<["--"], "no-" # name>, HelpText<help2>;
}

// For options whose names are multiple letters, either one dash or
// two can precede the option name except those that start with 'o'.
class F<string name>: Flag<["--", "-"], name>;
Expand Down Expand Up @@ -55,7 +60,7 @@ defm compress_debug_sections:

defm defsym: Eq<"defsym", "Define a symbol alias">, MetaVarName<"<symbol>=<value>">;

defm optimize_bb_jumps: B<"optimize-bb-jumps",
defm optimize_bb_jumps: BB<"optimize-bb-jumps",
"Remove direct jumps at the end to the next basic block",
"Do not remove any direct jumps at the end to the next basic block (default)">;

Expand Down Expand Up @@ -86,11 +91,11 @@ defm allow_shlib_undefined: B<"allow-shlib-undefined",
"Allow unresolved references in shared libraries (default when linking a shared library)",
"Do not allow unresolved references in shared libraries (default when linking an executable)">;

defm apply_dynamic_relocs: B<"apply-dynamic-relocs",
defm apply_dynamic_relocs: BB<"apply-dynamic-relocs",
"Apply link-time values for dynamic relocations",
"Do not apply link-time values for dynamic relocations (default)">;

defm dependent_libraries: B<"dependent-libraries",
defm dependent_libraries: BB<"dependent-libraries",
"Process dependent library specifiers from input files (default)",
"Ignore dependent library specifiers from input files">;

Expand All @@ -101,7 +106,7 @@ defm as_needed: B<"as-needed",
defm call_graph_ordering_file:
Eq<"call-graph-ordering-file", "Layout sections to optimize the given callgraph">;

defm call_graph_profile_sort: B<"call-graph-profile-sort",
defm call_graph_profile_sort: BB<"call-graph-profile-sort",
"Reorder sections with call graph profile (default)",
"Do not reorder sections with call graph profile">;

Expand Down Expand Up @@ -168,7 +173,7 @@ def error_unresolved_symbols: F<"error-unresolved-symbols">,

defm exclude_libs: Eq<"exclude-libs", "Exclude static libraries from automatic export">;

defm execute_only: B<"execute-only",
defm execute_only: BB<"execute-only",
"Mark executable sections unreadable",
"Mark executable sections readable (default)">;

Expand Down Expand Up @@ -200,11 +205,11 @@ defm gc_sections: B<"gc-sections",
"Enable garbage collection of unused sections",
"Disable garbage collection of unused sections (default)">;

defm gdb_index: B<"gdb-index",
defm gdb_index: BB<"gdb-index",
"Generate .gdb_index section",
"Do not generate .gdb_index section (default)">;

defm gnu_unique: B<"gnu-unique",
defm gnu_unique: BB<"gnu-unique",
"Enable STB_GNU_UNIQUE symbol binding (default)",
"Disable STB_GNU_UNIQUE symbol binding">;

Expand Down Expand Up @@ -244,7 +249,7 @@ defm merge_exidx_entries: B<"merge-exidx-entries",
"Enable merging .ARM.exidx entries (default)",
"Disable merging .ARM.exidx entries">;

defm mmap_output_file: B<"mmap-output-file",
defm mmap_output_file: BB<"mmap-output-file",
"Mmap the output file for writing (default)",
"Do not mmap the output file for writing">;

Expand Down Expand Up @@ -288,7 +293,7 @@ defm pack_dyn_relocs:
Eq<"pack-dyn-relocs", "Pack dynamic relocations in the given format">,
MetaVarName<"[none,android,relr,android+relr]">;

defm use_android_relr_tags: B<"use-android-relr-tags",
defm use_android_relr_tags: BB<"use-android-relr-tags",
"Use SHT_ANDROID_RELR / DT_ANDROID_RELR* tags instead of SHT_RELR / DT_RELR*",
"Use SHT_RELR / DT_RELR* tags (default)">;

Expand Down Expand Up @@ -325,7 +330,7 @@ def print_map: F<"print-map">,

defm reproduce: Eq<"reproduce", "Write a tar file containing input files and command line options to reproduce link">;

defm rosegment: B<"rosegment",
defm rosegment: BB<"rosegment",
"Put read-only non-executable sections in their own segment (default)",
"Do not put read-only non-executable sections in their own segment">;

Expand Down Expand Up @@ -417,7 +422,7 @@ def version: F<"version">, HelpText<"Display the version number and exit">;

defm version_script: Eq<"version-script", "Read a version script">;

defm warn_backrefs: B<"warn-backrefs",
defm warn_backrefs: BB<"warn-backrefs",
"Warn about backward symbol references to fetch archive members",
"Do not warn about backward symbol references to fetch archive members (default)">;

Expand All @@ -431,11 +436,11 @@ defm warn_common: B<"warn-common",
"Warn about duplicate common symbols",
"Do not warn about duplicate common symbols (default)">;

defm warn_ifunc_textrel: B<"warn-ifunc-textrel",
defm warn_ifunc_textrel: BB<"warn-ifunc-textrel",
"Warn about using ifunc symbols with text relocations",
"Do not warn about using ifunc symbols with text relocations (default)">;

defm warn_symbol_ordering: B<"warn-symbol-ordering",
defm warn_symbol_ordering: BB<"warn-symbol-ordering",
"Warn about problems with the symbol ordering file (default)",
"Do not warn about problems with the symbol ordering file">;

Expand Down Expand Up @@ -533,7 +538,7 @@ def opt_remarks_format: Separate<["--"], "opt-remarks-format">,
def save_temps: F<"save-temps">;
def lto_basicblock_sections: JJ<"lto-basicblock-sections=">,
HelpText<"Enable basic block sections for LTO">;
defm lto_unique_bb_section_names: B<"lto-unique-bb-section-names",
defm lto_unique_bb_section_names: BB<"lto-unique-bb-section-names",
"Give unique names to every basic block section for LTO",
"Do not give unique names to every basic block section for LTO (default)">;
def shuffle_sections: JJ<"shuffle-sections=">, MetaVarName<"<seed>">,
Expand Down
2 changes: 1 addition & 1 deletion lld/test/ELF/debug-gnu-pubnames.s
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# CHECK: .debug_gnu_pubnames
# CHECK: .debug_gnu_pubtypes

# RUN: ld.lld -gdb-index %t.o -o %t2.exe
# RUN: ld.lld --gdb-index %t.o -o %t2.exe
# RUN: llvm-readobj --sections %t2.exe | FileCheck %s --check-prefix=GDB
# GDB-NOT: .debug_gnu_pubnames
# GDB-NOT: .debug_gnu_pubtypes
Expand Down
2 changes: 1 addition & 1 deletion lld/test/ELF/dynstr-no-rosegment.s
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# Verify that a .dynstr in the .text segment has null byte terminators

# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
# RUN: ld.lld %t.o -no-rosegment -o %t.so -shared
# RUN: ld.lld %t.o --no-rosegment -o %t.so -shared
# RUN: llvm-objdump %t.so -s -j .dynstr | FileCheck %s

# CHECK: 00666f6f 00 .foo.
Expand Down
2 changes: 1 addition & 1 deletion lld/test/ELF/eh-frame-padding-no-rosegment.s
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ bar:
// OBJ-NEXT: 0020: 20000000 00000000 00000000 00000000
// OBJ-NEXT: )

// RUN: ld.lld --hash-style=sysv %t.o -no-rosegment -o %t -shared
// RUN: ld.lld --hash-style=sysv %t.o --no-rosegment -o %t -shared

// Check that .eh_frame is in the same segment as .text
// RUN: llvm-readelf -l %t | FileCheck --check-prefix=PHDR %s
Expand Down
2 changes: 1 addition & 1 deletion lld/test/ELF/elf-header.s
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# RUN: ld.lld %t.o -o %t1
# RUN: llvm-readobj --file-headers %t1 | FileCheck %s

# RUN: ld.lld %t.o -no-rosegment -o %t2
# RUN: ld.lld %t.o --no-rosegment -o %t2
# RUN: llvm-readobj --file-headers %t2 | FileCheck %s

# CHECK: ElfHeader {
Expand Down
2 changes: 1 addition & 1 deletion lld/test/ELF/execute-only-mixed-data.s
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
// RUN: .text : { *(.text) *(.rodata.foo) } \
// RUN: .rodata : { *(.rodata.bar) } \
// RUN: }" > %t.lds
// RUN: not ld.lld -T%t.lds %t.o -o /dev/null -execute-only 2>&1 | FileCheck %s
// RUN: not ld.lld -T%t.lds %t.o -o /dev/null --execute-only 2>&1 | FileCheck %s

// RUN: echo "SECTIONS \
// RUN: { \
Expand Down
2 changes: 1 addition & 1 deletion lld/test/ELF/execute-only.s
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// REQUIRES: aarch64

// RUN: llvm-mc -filetype=obj -triple=aarch64-linux-none %s -o %t.o
// RUN: ld.lld -Ttext=0xcafe0000 %t.o -o %t.so -shared -execute-only
// RUN: ld.lld -Ttext=0xcafe0000 %t.o -o %t.so -shared --execute-only
// RUN: llvm-readelf -l %t.so | FileCheck %s

// CHECK: LOAD {{.*}} 0x00000000cafe0000 0x000004 0x000004 E 0x{{.*}}
Expand Down
2 changes: 1 addition & 1 deletion lld/test/ELF/gdb-index-no-debug.s
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
# RUN: ld.lld -o %t.exe -gdb-index %t.o
# RUN: ld.lld -o %t.exe --gdb-index %t.o
# RUN: llvm-objdump --section-headers %t.exe | FileCheck %s
# CHECK-NOT: .gdb_index

Expand Down
2 changes: 1 addition & 1 deletion lld/test/ELF/invalid/invalid-debug-relocations.test
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# REQUIRES: x86
# RUN: yaml2obj %s -o %t.o
# RUN: not ld.lld -gdb-index %t.o -o /dev/null 2>&1 | FileCheck %s
# RUN: not ld.lld --gdb-index %t.o -o /dev/null 2>&1 | FileCheck %s

# CHECK: error: {{.*}}invalid-debug-relocations.test.tmp.o:(.debug_info+0x0): unknown relocation (255) against symbol _start

Expand Down
2 changes: 1 addition & 1 deletion lld/test/ELF/segments.s
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
# ROSEGMENT-NEXT: Alignment: 4096
# ROSEGMENT-NEXT: }

# RUN: ld.lld -no-rosegment %t -o %t2
# RUN: ld.lld --no-rosegment %t -o %t2
# RUN: llvm-readobj --program-headers %t2 | FileCheck --check-prefix=NOROSEGMENT %s

# NOROSEGMENT: ProgramHeader {
Expand Down
2 changes: 1 addition & 1 deletion lld/test/ELF/sort-norosegment.s
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o

# RUN: ld.lld --hash-style=sysv -no-rosegment -o %t %t.o -shared
# RUN: ld.lld --hash-style=sysv --no-rosegment -o %t %t.o -shared
# RUN: llvm-readelf -S %t | FileCheck %s

# CHECK: .dynsym {{.*}} A
Expand Down

0 comments on commit e36223c

Please sign in to comment.