[lld] 241dbd3 - [ELF] Enable --no-undefined-version by default
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Dec 7 17:41:24 PST 2022
Author: Dan Albert
Date: 2022-12-08T01:41:18Z
New Revision: 241dbd310599e3c1a0f1b0c9ced14c8b8760539e
URL: https://github.com/llvm/llvm-project/commit/241dbd310599e3c1a0f1b0c9ced14c8b8760539e
DIFF: https://github.com/llvm/llvm-project/commit/241dbd310599e3c1a0f1b0c9ced14c8b8760539e.diff
LOG: [ELF] Enable --no-undefined-version by default
Allowing incorrect version scripts is not a helpful default. Flip that
to help users find their bugs at build time rather than at run time.
Reviewed By: MaskRay
Differential Revision: https://reviews.llvm.org/D135402
Added:
Modified:
lld/ELF/Driver.cpp
lld/ELF/Options.td
lld/docs/ReleaseNotes.rst
lld/docs/ld.lld.1
lld/test/ELF/verdef-defaultver.s
lld/test/ELF/verdef-dependency.s
lld/test/ELF/verneed.s
lld/test/ELF/version-script-extern-undefined.s
lld/test/ELF/version-script-local-preemptible.s
lld/test/ELF/version-script-noundef.s
lld/test/ELF/version-script-reassign.s
Removed:
################################################################################
diff --git a/lld/ELF/Driver.cpp b/lld/ELF/Driver.cpp
index 20411d91c2750..a7d1cab433220 100644
--- a/lld/ELF/Driver.cpp
+++ b/lld/ELF/Driver.cpp
@@ -1247,7 +1247,7 @@ static void readConfigs(opt::InputArgList &args) {
config->trace = args.hasArg(OPT_trace);
config->undefined = args::getStrings(args, OPT_undefined);
config->undefinedVersion =
- args.hasFlag(OPT_undefined_version, OPT_no_undefined_version, true);
+ args.hasFlag(OPT_undefined_version, OPT_no_undefined_version, false);
config->unique = args.hasArg(OPT_unique);
config->useAndroidRelrTags = args.hasFlag(
OPT_use_android_relr_tags, OPT_no_use_android_relr_tags, false);
diff --git a/lld/ELF/Options.td b/lld/ELF/Options.td
index 62ac05c47d183..b6a6ef64d017a 100644
--- a/lld/ELF/Options.td
+++ b/lld/ELF/Options.td
@@ -443,7 +443,7 @@ defm unresolved_symbols:
Eq<"unresolved-symbols", "Determine how to handle unresolved symbols">;
defm undefined_version: B<"undefined-version",
- "Allow unused version in version script (default)",
+ "Allow unused version in version script (disabled by default)",
"Report version scripts that refer undefined symbols">;
defm rsp_quoting: EEq<"rsp-quoting", "Quoting style for response files">,
diff --git a/lld/docs/ReleaseNotes.rst b/lld/docs/ReleaseNotes.rst
index 06c604e1509c7..cf52fd3222860 100644
--- a/lld/docs/ReleaseNotes.rst
+++ b/lld/docs/ReleaseNotes.rst
@@ -36,6 +36,9 @@ ELF Improvements
* ``DT_RISCV_VARIANT_CC`` is now produced if at least one ``R_RISCV_JUMP_SLOT``
relocation references a symbol with the ``STO_RISCV_VARIANT_CC`` bit.
(`D107951 <https://reviews.llvm.org/D107951>`_)
+* ``--no-undefined-version`` is now the default; symbols named in version
+ scripts that have no matching symbol in the output will be reported. Use
+ ``--undefined-version`` to revert to the old behavior.
Breaking changes
----------------
diff --git a/lld/docs/ld.lld.1 b/lld/docs/ld.lld.1
index 2b530af39ad64..edeb7c4bfe37c 100644
--- a/lld/docs/ld.lld.1
+++ b/lld/docs/ld.lld.1
@@ -352,8 +352,8 @@ Do not set the text data sections to be writable, page align sections.
Disable target-specific relaxations. For x86-64 this disables R_X86_64_GOTPCRELX and R_X86_64_REX_GOTPCRELX GOT optimization.
.It Fl -no-rosegment
Do not put read-only non-executable sections in their own segment.
-.It Fl -no-undefined-version
-Report version scripts that refer undefined symbols.
+.It Fl -undefined-version
+Do not report version scripts that refer to undefined symbols.
.It Fl -no-undefined
Report unresolved symbols even if the linker is creating a shared library.
.It Fl -no-warn-symbol-ordering
diff --git a/lld/test/ELF/verdef-defaultver.s b/lld/test/ELF/verdef-defaultver.s
index 7becdcf96422b..661f6c4e7da42 100644
--- a/lld/test/ELF/verdef-defaultver.s
+++ b/lld/test/ELF/verdef-defaultver.s
@@ -4,7 +4,7 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %p/Inputs/verdef-defaultver.s -o %t1
# RUN: echo "V1 { global: a; b; local: *; };" > %t.script
# RUN: echo "V2 { global: b; c; } V1;" >> %t.script
-# RUN: ld.lld --hash-style=sysv -shared -soname shared %t1 --version-script %t.script -o %t.so
+# RUN: ld.lld --hash-style=sysv -shared -soname shared %t1 --version-script %t.script --undefined-version -o %t.so
# RUN: llvm-readobj -V --dyn-syms %t.so | FileCheck --check-prefix=DSO %s
# DSO: DynamicSymbols [
@@ -195,9 +195,9 @@
# EXE-NEXT: ]
# RUN: llvm-mc -filetype=obj -triple=x86_64 b.s -o b.o
-# RUN: ld.lld -shared --version-script=%t.script --fatal-warnings %t.so b.o -o b.so
+# RUN: ld.lld -shared --version-script=%t.script --fatal-warnings --undefined-version %t.so b.o -o b.so
# RUN: llvm-readelf --dyn-syms b.so | FileCheck %s --check-prefix=PREEMPT
-# RUN: ld.lld -shared --version-script=%t.script --fatal-warnings b.o %t.so -o b.so
+# RUN: ld.lld -shared --version-script=%t.script --fatal-warnings --undefined-version b.o %t.so -o b.so
# RUN: llvm-readelf --dyn-syms b.so | FileCheck %s --check-prefix=PREEMPT
# PREEMPT-DAG: a@@V1
diff --git a/lld/test/ELF/verdef-dependency.s b/lld/test/ELF/verdef-dependency.s
index d716436202535..89ebc3043ad44 100644
--- a/lld/test/ELF/verdef-dependency.s
+++ b/lld/test/ELF/verdef-dependency.s
@@ -3,7 +3,7 @@
# RUN: echo "LIBSAMPLE_1.0 { global: a; local: *; };" > %t.script
# RUN: echo "LIBSAMPLE_2.0 { global: b; local: *; } LIBSAMPLE_1.0;" >> %t.script
# RUN: echo "LIBSAMPLE_3.0 { global: c; } LIBSAMPLE_2.0;" >> %t.script
-# RUN: ld.lld --version-script %t.script -shared -soname shared %t.o -o %t.so
+# RUN: ld.lld --version-script %t.script --undefined-version -shared -soname shared %t.o -o %t.so
# RUN: llvm-readobj -V --dyn-syms %t.so | FileCheck --check-prefix=DSO %s
# DSO: VersionDefinitions [
diff --git a/lld/test/ELF/verneed.s b/lld/test/ELF/verneed.s
index 6a90cc48e68fb..734387a62785f 100644
--- a/lld/test/ELF/verneed.s
+++ b/lld/test/ELF/verneed.s
@@ -1,9 +1,9 @@
# REQUIRES: x86
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/verneed1.s -o %t1.o
# RUN: echo "v1 {}; v2 {}; v3 { global: f1; local: *; };" > %t.script
-# RUN: ld.lld -shared %t1.o --version-script %t.script -o %t1.so -soname verneed1.so.0
+# RUN: ld.lld -shared %t1.o --version-script %t.script --undefined-version -o %t1.so -soname verneed1.so.0
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %S/Inputs/verneed2.s -o %t2.o
-# RUN: ld.lld -shared %t2.o --version-script %t.script -o %t2.so -soname verneed2.so.0
+# RUN: ld.lld -shared %t2.o --version-script %t.script --undefined-version -o %t2.so -soname verneed2.so.0
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
# RUN: ld.lld --hash-style=sysv %t.o %t1.so %t2.so -o %t
diff --git a/lld/test/ELF/version-script-extern-undefined.s b/lld/test/ELF/version-script-extern-undefined.s
index 58b4d2e0fe53f..38114229e0ce3 100644
--- a/lld/test/ELF/version-script-extern-undefined.s
+++ b/lld/test/ELF/version-script-extern-undefined.s
@@ -2,7 +2,7 @@
# RUN: llvm-mc -filetype=obj -triple=x86_64-pc-linux %s -o %t.o
# RUN: echo "FOO { global: extern \"C++\" { \"abb(int)\"; }; };" > %t.script
-# RUN: ld.lld --version-script %t.script -shared %t.o -o %t.so
+# RUN: ld.lld --version-script %t.script --undefined-version -shared %t.o -o %t.so
# RUN: llvm-readobj -V %t.so | FileCheck %s
# CHECK: VersionSymbols [
diff --git a/lld/test/ELF/version-script-local-preemptible.s b/lld/test/ELF/version-script-local-preemptible.s
index ffb16648dc800..033c9459fb56c 100644
--- a/lld/test/ELF/version-script-local-preemptible.s
+++ b/lld/test/ELF/version-script-local-preemptible.s
@@ -10,7 +10,7 @@
# RUN: echo "{ global: main; local: *; };" > %t.script
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
-# RUN: ld.lld %t.o %t.so -o %t -version-script %t.script
+# RUN: ld.lld %t.o %t.so -o %t -version-script %t.script --undefined-version
# RUN: llvm-readelf -r --symbols %t | FileCheck %s
# CHECK: Relocation section '.rela.plt' at offset {{.*}} contains 1 entries:
diff --git a/lld/test/ELF/version-script-noundef.s b/lld/test/ELF/version-script-noundef.s
index 18916b66f064e..b99fb1779f6eb 100644
--- a/lld/test/ELF/version-script-noundef.s
+++ b/lld/test/ELF/version-script-noundef.s
@@ -2,7 +2,8 @@
# RUN: echo "VERSION_1.0 { global: bar; };" > %t.script
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
-# RUN: ld.lld --version-script %t.script -shared %t.o -o /dev/null --fatal-warnings
+# RUN: not ld.lld --version-script %t.script -shared %t.o -o /dev/null \
+# RUN: --fatal-warnings 2>&1 | FileCheck -check-prefix=ERR1 %s
# RUN: ld.lld --version-script %t.script -shared --undefined-version %t.o -o %t.so
# RUN: not ld.lld --version-script %t.script -shared --no-undefined-version \
# RUN: %t.o -o %t.so 2>&1 | FileCheck -check-prefix=ERR1 %s
diff --git a/lld/test/ELF/version-script-reassign.s b/lld/test/ELF/version-script-reassign.s
index 2ed5b15faceda..371390019a4dd 100644
--- a/lld/test/ELF/version-script-reassign.s
+++ b/lld/test/ELF/version-script-reassign.s
@@ -24,7 +24,7 @@
# RUN: llvm-readelf --dyn-syms %t.so | FileCheck --check-prefix=V1-SYM %s
# RUN: ld.lld -shared %t.o --version-script %t1.ver --version-script %t2w.ver \
-# RUN: -o %t.so --fatal-warnings
+# RUN: -o %t.so --fatal-warnings --undefined-version
# RUN: llvm-readelf --dyn-syms %t.so | FileCheck --check-prefix=V1-SYM %s
# LOCAL: warning: attempt to reassign symbol 'foo' of VER_NDX_LOCAL to version 'V1'
More information about the llvm-commits
mailing list