Skip to content

Commit aad2e32

Browse files
committed
Add --no-gnu-unique and --no-undefined-version for completeness.
Differential Revision: https://reviews.llvm.org/D42865 llvm-svn: 324145
1 parent a767ee5 commit aad2e32

File tree

7 files changed

+19
-12
lines changed

7 files changed

+19
-12
lines changed

lld/ELF/Config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,14 @@ struct Configuration {
124124
bool GcSections;
125125
bool GdbIndex;
126126
bool GnuHash = false;
127+
bool GnuUnique;
127128
bool HasDynamicList = false;
128129
bool HasDynSymTab;
129130
bool ICF;
130131
bool IgnoreDataAddressEquality;
131132
bool IgnoreFunctionAddressEquality;
132133
bool MergeArmExidx;
133134
bool MipsN32Abi = false;
134-
bool NoGnuUnique;
135-
bool NoUndefinedVersion;
136135
bool NoinhibitExec;
137136
bool Nostdlib;
138137
bool OFormatBinary;
@@ -149,6 +148,7 @@ struct Configuration {
149148
bool SysvHash = false;
150149
bool Target1Rel;
151150
bool Trace;
151+
bool UndefinedVersion;
152152
bool Verbose;
153153
bool WarnCommon;
154154
bool WarnMissingEntry;

lld/ELF/Driver.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,6 +621,7 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) {
621621
Config->Fini = Args.getLastArgValue(OPT_fini, "_fini");
622622
Config->FixCortexA53Errata843419 = Args.hasArg(OPT_fix_cortex_a53_843419);
623623
Config->GcSections = Args.hasFlag(OPT_gc_sections, OPT_no_gc_sections, false);
624+
Config->GnuUnique = Args.hasFlag(OPT_gnu_unique, OPT_no_gnu_unique, true);
624625
Config->GdbIndex = Args.hasFlag(OPT_gdb_index, OPT_no_gdb_index, false);
625626
Config->ICF = Args.hasFlag(OPT_icf_all, OPT_icf_none, false);
626627
Config->IgnoreDataAddressEquality =
@@ -633,10 +634,8 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) {
633634
Config->LTOO = args::getInteger(Args, OPT_lto_O, 2);
634635
Config->LTOPartitions = args::getInteger(Args, OPT_lto_partitions, 1);
635636
Config->MapFile = Args.getLastArgValue(OPT_Map);
636-
Config->NoGnuUnique = Args.hasArg(OPT_no_gnu_unique);
637637
Config->MergeArmExidx =
638638
Args.hasFlag(OPT_merge_exidx_entries, OPT_no_merge_exidx_entries, true);
639-
Config->NoUndefinedVersion = Args.hasArg(OPT_no_undefined_version);
640639
Config->NoinhibitExec = Args.hasArg(OPT_noinhibit_exec);
641640
Config->Nostdlib = Args.hasArg(OPT_nostdlib);
642641
Config->OFormatBinary = isOutputFormatBinary(Args);
@@ -672,6 +671,8 @@ void LinkerDriver::readConfigs(opt::InputArgList &Args) {
672671
ThreadsEnabled = Args.hasFlag(OPT_threads, OPT_no_threads, true);
673672
Config->Trace = Args.hasArg(OPT_trace);
674673
Config->Undefined = args::getStrings(Args, OPT_undefined);
674+
Config->UndefinedVersion =
675+
Args.hasFlag(OPT_undefined_version, OPT_no_undefined_version, true);
675676
Config->UnresolvedSymbols = getUnresolvedSymbolPolicy(Args);
676677
Config->Verbose = Args.hasArg(OPT_verbose);
677678
errorHandler().Verbose = Config->Verbose;

lld/ELF/Options.td

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ defm gdb_index: B<"gdb-index",
150150
"Generate .gdb_index section",
151151
"Do not generate .gdb_index section">;
152152

153+
defm gnu_unique: B<"gnu-unique",
154+
"Enable STB_GNU_UNIQUE symbol binding",
155+
"Disable STB_GNU_UNIQUE symbol binding">;
156+
153157
defm hash_style: Eq<"hash-style">,
154158
HelpText<"Specify hash style (sysv, gnu or both)">;
155159

@@ -193,9 +197,6 @@ def no_color_diagnostics: F<"no-color-diagnostics">,
193197
def no_dynamic_linker: F<"no-dynamic-linker">,
194198
HelpText<"Inhibit output of .interp section">;
195199

196-
def no_gnu_unique: F<"no-gnu-unique">,
197-
HelpText<"Disable STB_GNU_UNIQUE symbol binding">;
198-
199200
def noinhibit_exec: F<"noinhibit-exec">,
200201
HelpText<"Retain the executable output file whenever it is still usable">;
201202

@@ -208,9 +209,6 @@ def no_rosegment: F<"no-rosegment">,
208209
def no_undefined: F<"no-undefined">,
209210
HelpText<"Report unresolved symbols even if the linker is creating a shared library">;
210211

211-
def no_undefined_version: F<"no-undefined-version">,
212-
HelpText<"Report version scripts that refer undefined symbols">;
213-
214212
def o: JoinedOrSeparate<["-"], "o">, MetaVarName<"<path>">,
215213
HelpText<"Path to file to write output">;
216214

@@ -298,6 +296,10 @@ defm undefined: Eq<"undefined">,
298296
defm unresolved_symbols: Eq<"unresolved-symbols">,
299297
HelpText<"Determine how to handle unresolved symbols">;
300298

299+
defm undefined_version: B<"undefined-version",
300+
"Allow unused version in version script",
301+
"Report version scripts that refer undefined symbols">;
302+
301303
defm rsp_quoting: Eq<"rsp-quoting">,
302304
HelpText<"Quoting style for response files. Values supported: windows|posix">;
303305

lld/ELF/SymbolTable.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ void SymbolTable::assignExactVersion(SymbolVersion Ver, uint16_t VersionId,
700700
// Get a list of symbols which we need to assign the version to.
701701
std::vector<Symbol *> Syms = findByVersion(Ver);
702702
if (Syms.empty()) {
703-
if (Config->NoUndefinedVersion)
703+
if (!Config->UndefinedVersion)
704704
error("version script assignment of '" + VersionName + "' to symbol '" +
705705
Ver.Name + "' failed: symbol not defined");
706706
return;

lld/ELF/Symbols.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ uint8_t Symbol::computeBinding() const {
241241
return STB_LOCAL;
242242
if (VersionId == VER_NDX_LOCAL && isDefined())
243243
return STB_LOCAL;
244-
if (Config->NoGnuUnique && Binding == STB_GNU_UNIQUE)
244+
if (!Config->GnuUnique && Binding == STB_GNU_UNIQUE)
245245
return STB_GLOBAL;
246246
return Binding;
247247
}

lld/test/ELF/gnu-unique.s

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
//
44
// RUN: ld.lld %t -shared -o %tout.so
55
// RUN: llvm-readobj -dyn-symbols %tout.so | FileCheck -check-prefix=GNU %s
6+
// RUN: ld.lld %t -shared -o %tout.so --gnu-unique
7+
// RUN: llvm-readobj -dyn-symbols %tout.so | FileCheck -check-prefix=GNU %s
68
//
79
// RUN: ld.lld %t -shared -o %tout.so --no-gnu-unique
810
// RUN: llvm-readobj -dyn-symbols %tout.so | FileCheck -check-prefix=NO %s

lld/test/ELF/version-script-noundef.s

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
# RUN: echo "VERSION_1.0 { global: bar; };" > %t.script
44
# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o
5+
# RUN: ld.lld --version-script %t.script -shared %t.o -o %t.so
6+
# RUN: ld.lld --version-script %t.script -shared --undefined-version %t.o -o %t.so
57
# RUN: not ld.lld --version-script %t.script -shared --no-undefined-version \
68
# RUN: %t.o -o %t.so 2>&1 | FileCheck -check-prefix=ERR1 %s
79
# ERR1: version script assignment of 'VERSION_1.0' to symbol 'bar' failed: symbol not defined

0 commit comments

Comments
 (0)