Index: ELF/Config.h =================================================================== --- ELF/Config.h +++ ELF/Config.h @@ -32,6 +32,15 @@ enum class BuildIdKind { None, Fnv1, Md5, Sha1, Hexstring }; +// This struct contains symbols version definition that +// can be found in version script if it is used for link. +struct Version { + Version(llvm::StringRef Name) { this->Name = Name; } + llvm::StringRef Name; + std::vector Globals; + size_t NameOff; // Offset in string table. +}; + // This struct contains the global configuration for the linker. // Most fields are direct mapping from the command line options // and such fields have the same name as the corresponding options. @@ -50,6 +59,7 @@ llvm::StringRef SoName; llvm::StringRef Sysroot; std::string RPath; + std::vector SymbolVersions; std::vector DynamicList; std::vector SearchPaths; std::vector Undefined; Index: ELF/OutputSections.h =================================================================== --- ELF/OutputSections.h +++ ELF/OutputSections.h @@ -24,6 +24,7 @@ class SymbolBody; struct SectionPiece; +struct Version; template class SymbolTable; template class SymbolTableSection; template class StringTableSection; @@ -230,10 +231,31 @@ // For more information about .gnu.version and .gnu.version_r see: // https://www.akkadia.org/drepper/symbol-versioning +// The .gnu.version_d section which has a section type of SHT_GNU_verdef shall +// contain symbol version definitions. The number of entries in this section +// shall be contained in the DT_VERDEFNUM entry of the .dynamic section. +// The section shall contain an array of Elf_Verdef structures, optionally +// followed by an array of Elf_Verdaux structures. +template +class VersionDefinitionSection final : public OutputSectionBase { + typedef typename ELFT::Verdef Elf_Verdef; + typedef typename ELFT::Verdaux Elf_Verdaux; + + size_t FileDefNameOff; + +public: + VersionDefinitionSection(); + void finalize() override; + void writeTo(uint8_t *Buf) override; + void createDefs(); +}; + // The .gnu.version section specifies the required version of each symbol in the // dynamic symbol table. It contains one Elf_Versym for each dynamic symbol // table entry. An Elf_Versym is just a 16-bit integer that refers to a version -// identifier defined in the .gnu.version_r section. +// identifier defined in the .gnu.version_d section. The values 0 and 1 are +// reserved. All other values are used for versions in the own object or in any +// of the dependencies. template class VersionTableSection final : public OutputSectionBase { typedef typename ELFT::Versym Elf_Versym; @@ -242,6 +264,7 @@ VersionTableSection(); void finalize() override; void writeTo(uint8_t *Buf) override; + bool isRequired(); }; // The .gnu.version_r section defines the version identifiers used by @@ -258,9 +281,8 @@ // string table offsets of their sonames. std::vector *, size_t>> Needed; - // The next available version identifier. Identifiers start at 2 because 0 and - // 1 are reserved. - unsigned NextIndex = 2; + // The next available version identifier. + unsigned NextIndex; public: VersionNeedSection(); @@ -612,6 +634,7 @@ static StringTableSection *StrTab; static SymbolTableSection *DynSymTab; static SymbolTableSection *SymTab; + static VersionDefinitionSection *VerDef; static VersionTableSection *VerSym; static VersionNeedSection *VerNeed; static Elf_Phdr *TlsPhdr; @@ -640,6 +663,7 @@ template StringTableSection *Out::StrTab; template SymbolTableSection *Out::DynSymTab; template SymbolTableSection *Out::SymTab; +template VersionDefinitionSection *Out::VerDef; template VersionTableSection *Out::VerSym; template VersionNeedSection *Out::VerNeed; template typename ELFT::Phdr *Out::TlsPhdr; Index: ELF/OutputSections.cpp =================================================================== --- ELF/OutputSections.cpp +++ ELF/OutputSections.cpp @@ -563,6 +563,16 @@ V.push_back({Sym.Body, Sym.STName}); } +static unsigned getVerDefNum() { + // At least one version dependency must exist. Additional version dependencies + // can be present, the number being indicated by the vn_cnt value of + // Elf_Verdef. We do not support version hierarchies currently, so each + // Elf_Verdef associated exactly with single Elf_Verdaux for us. + // The base version definition is always present when version definitions, or + // symbol auto-reduction, have been applied to the file. + return Config->SymbolVersions.size() + 1; +} + template DynamicSection::DynamicSection() : OutputSectionBase(".dynamic", SHT_DYNAMIC, SHF_ALLOC | SHF_WRITE) { @@ -665,8 +675,15 @@ if (!Config->Entry.empty()) Add({DT_DEBUG, (uint64_t)0}); - if (size_t NeedNum = Out::VerNeed->getNeedNum()) { + if (Out::VerSym->isRequired()) Add({DT_VERSYM, Out::VerSym}); + + if (!Config->SymbolVersions.empty()) { + Add({DT_VERDEF, Out::VerDef}); + Add({DT_VERDEFNUM, getVerDefNum()}); + } + + if (size_t NeedNum = Out::VerNeed->getNeedNum()) { Add({DT_VERNEED, Out::VerNeed}); Add({DT_VERNEEDNUM, NeedNum}); } @@ -1407,6 +1424,60 @@ } template +VersionDefinitionSection::VersionDefinitionSection() + : OutputSectionBase(".gnu.version_d", SHT_GNU_verdef, SHF_ALLOC) {} + +template void VersionDefinitionSection::createDefs() { + FileDefNameOff = Out::DynStrTab->addString(Config->OutputFile); + for (Version &V : Config->SymbolVersions) + V.NameOff = Out::DynStrTab->addString(V.Name); +} + +template void VersionDefinitionSection::finalize() { + this->Header.sh_size = + (sizeof(Elf_Verdef) + sizeof(Elf_Verdaux)) * getVerDefNum(); + this->Header.sh_link = Out::DynStrTab->SectionIndex; + this->Header.sh_addralign = sizeof(uint32_t); + + // sh_info should be set to the number of definitions. This fact is missed in + // documentation, but confirmed by binutils community: + // https://sourceware.org/ml/binutils/2014-11/msg00355.html + this->Header.sh_info = getVerDefNum(); +} + +template +void VersionDefinitionSection::writeTo(uint8_t *Buf) { + Elf_Verdef *Verdef = reinterpret_cast(Buf); + Elf_Verdaux *Verdaux = + reinterpret_cast(Verdef + getVerDefNum()); + + size_t Cnt = Config->SymbolVersions.size() + 1; + for (size_t I = 0; I < Cnt; ++I) { + bool IsBase = I == 0; + + Verdef->vd_version = 1; + Verdef->vd_flags = IsBase ? VER_FLG_BASE : 0; + Verdef->vd_ndx = I + 1; + Verdef->vd_cnt = 1; + Verdef->vd_hash = IsBase ? hashSysv(Config->OutputFile) + : hashSysv(Config->SymbolVersions[I - 1].Name); + + Verdef->vd_aux = + reinterpret_cast(Verdaux) - reinterpret_cast(Verdef); + Verdef->vd_next = sizeof(Elf_Verdef); + ++Verdef; + + // Now write the single Elf_Verdaux entry. + Verdaux->vda_name = + IsBase ? FileDefNameOff : Config->SymbolVersions[I - 1].NameOff; + Verdaux->vda_next = 0; + ++Verdaux; + } + + Verdef[-1].vd_next = 0; +} + +template VersionTableSection::VersionTableSection() : OutputSectionBase(".gnu.version", SHT_GNU_versym, SHF_ALLOC) { this->Header.sh_addralign = sizeof(uint16_t); @@ -1425,24 +1496,32 @@ auto *OutVersym = reinterpret_cast(Buf) + 1; for (const std::pair &P : Out::DynSymTab->getSymbols()) { - if (auto *SS = dyn_cast>(P.first)) - OutVersym->vs_index = SS->VersionId; - else - OutVersym->vs_index = VER_NDX_GLOBAL; + SymbolBody *Body = P.first; + OutVersym->vs_index = Body->symbol()->VersionId; ++OutVersym; } } +template bool VersionTableSection::isRequired() { + return !Config->SymbolVersions.empty() || + Out::VerNeed->getNeedNum() != 0; +} + template VersionNeedSection::VersionNeedSection() : OutputSectionBase(".gnu.version_r", SHT_GNU_verneed, SHF_ALLOC) { this->Header.sh_addralign = sizeof(uint32_t); + + // Identifiers in verneed section start at 2 because 0 and 1 are reserved + // for VER_NDX_LOCAL and VER_NDX_GLOBAL. + // First identifiers are reserved by verdef section if it exist. + NextIndex = getVerDefNum() + 1; } template void VersionNeedSection::addSymbol(SharedSymbol *SS) { if (!SS->Verdef) { - SS->VersionId = VER_NDX_GLOBAL; + SS->symbol()->VersionId = VER_NDX_GLOBAL; return; } SharedFile *F = SS->File; @@ -1460,7 +1539,7 @@ SS->File->getStringTable().data() + SS->Verdef->getAux()->vda_name); NV.Index = NextIndex++; } - SS->VersionId = NV.Index; + SS->symbol()->VersionId = NV.Index; } template void VersionNeedSection::writeTo(uint8_t *Buf) { @@ -1716,6 +1795,11 @@ template class VersionNeedSection; template class VersionNeedSection; +template class VersionDefinitionSection; +template class VersionDefinitionSection; +template class VersionDefinitionSection; +template class VersionDefinitionSection; + template class BuildIdSection; template class BuildIdSection; template class BuildIdSection; Index: ELF/SymbolListFile.h =================================================================== --- ELF/SymbolListFile.h +++ ELF/SymbolListFile.h @@ -11,6 +11,7 @@ #define LLD_ELF_SYMBOL_LIST_FILE_H #include "lld/Core/LLVM.h" +#include "llvm/ADT/MapVector.h" #include "llvm/Support/MemoryBuffer.h" namespace lld { Index: ELF/SymbolListFile.cpp =================================================================== --- ELF/SymbolListFile.cpp +++ ELF/SymbolListFile.cpp @@ -74,46 +74,78 @@ public: VersionScriptParser(StringRef S) : ScriptParserBase(S) {} + ~VersionScriptParser() { + if (!hasLocal) + Config->VersionScript = false; + } + void run(); private: - void parseVersion(); + bool hasLocal = false; + void parseVersion(StringRef Version); + void parseLocal(); + void parseVersionSymbols(StringRef Version); }; -void VersionScriptParser::parseVersion() { +void VersionScriptParser::parseVersion(StringRef Version) { expect("{"); if (peek() == "global:") { next(); - while (!Error) { - Config->VersionScriptGlobals.push_back(next()); - expect(";"); - if (peek() == "local:") - break; - } + parseVersionSymbols(Version); } + if (peek() == "local:") + parseLocal(); + else + parseVersionSymbols(Version); + + expect("}"); + expect(";"); +} + +void VersionScriptParser::parseLocal() { expect("local:"); expect("*"); expect(";"); - expect("}"); - expect(";"); + hasLocal = true; +} + +void VersionScriptParser::parseVersionSymbols(StringRef Version) { + for (;;) { + StringRef Cur = peek(); + if (Cur == "}" || Cur == "local:") + return; + next(); + if (Version.empty()) { + Config->VersionScriptGlobals.push_back(Cur); + expect(";"); + continue; + } + + Config->SymbolVersions.push_back(elf::Version(Version)); + elf::Version &V = Config->SymbolVersions.back(); + V.Globals.push_back(Cur); + expect(";"); + } } void VersionScriptParser::run() { StringRef Msg = "anonymous version definition is used in " "combination with other version definitions"; if (peek() == "{") { - parseVersion(); + parseVersion(""); if (!atEOF()) setError(Msg); return; } while (!atEOF() && !Error) { - if (next() == "{") { + StringRef Version = next(); + if (Version == "{") { setError(Msg); return; } - parseVersion(); + parseVersion(Version); } } Index: ELF/SymbolTable.cpp =================================================================== --- ELF/SymbolTable.cpp +++ ELF/SymbolTable.cpp @@ -514,9 +514,25 @@ // symbols with the VersionScriptGlobal flag, which acts as a filter on the // dynamic symbol table. template void SymbolTable::scanVersionScript() { - for (StringRef S : Config->VersionScriptGlobals) - if (SymbolBody *B = find(S)) - B->symbol()->VersionScriptGlobal = true; + // If version script does not contain versions declarations, + // we just should mark global symbols. + if (!Config->VersionScriptGlobals.empty()) { + for (StringRef S : Config->VersionScriptGlobals) + if (SymbolBody *B = find(S)) + B->symbol()->VersionScriptGlobal = true; + return; + } + + // If we have symbols version declarations, we should + // assign version references for each symbol. + for (size_t I = 0, E = Config->SymbolVersions.size(); I < E; ++I) { + lld::elf::Version &V = Config->SymbolVersions[I]; + for (StringRef Name : V.Globals) + if (SymbolBody *B = find(Name)) { + B->symbol()->VerDef = &V; + B->symbol()->VersionId = I + 2; + } + } } template class elf::SymbolTable; Index: ELF/Symbols.h =================================================================== --- ELF/Symbols.h +++ ELF/Symbols.h @@ -30,6 +30,7 @@ class InputFile; class LazyObjectFile; class SymbolBody; +struct Version; template class ObjectFile; template class OutputSection; template class OutputSectionBase; @@ -299,13 +300,8 @@ SharedFile *File; const Elf_Sym &Sym; - // This field is initially a pointer to the symbol's version definition. As - // symbols are added to the version table, this field is replaced with the - // version identifier to be stored in .gnu.version in the output file. - union { - const Elf_Verdef *Verdef; - uint16_t VersionId; - }; + // This field is a pointer to the symbol's version definition. + const Elf_Verdef *Verdef; // OffsetInBss is significant only when needsCopy() is true. uintX_t OffsetInBss = 0; @@ -425,6 +421,12 @@ // section of the version script. unsigned VersionScriptGlobal : 1; + // This is reference to version definition for symbol. + Version* VerDef = nullptr; + + // Version definition index. + uint16_t VersionId = llvm::ELF::VER_NDX_GLOBAL; + bool includeInDynsym() const; bool isWeak() const { return Binding == llvm::ELF::STB_WEAK; } Index: ELF/Symbols.cpp =================================================================== --- ELF/Symbols.cpp +++ ELF/Symbols.cpp @@ -266,8 +266,8 @@ bool Symbol::includeInDynsym() const { if (Visibility != STV_DEFAULT && Visibility != STV_PROTECTED) return false; - return (ExportDynamic && VersionScriptGlobal) || body()->isShared() || - (body()->isUndefined() && Config->Shared); + return (ExportDynamic && (VersionScriptGlobal || body()->symbol()->VerDef)) || + body()->isShared() || (body()->isUndefined() && Config->Shared); } template InputFile *SymbolBody::template getSourceFile(); Index: ELF/Writer.cpp =================================================================== --- ELF/Writer.cpp +++ ELF/Writer.cpp @@ -118,6 +118,7 @@ StringTableSection DynStrTab(".dynstr", true); StringTableSection ShStrTab(".shstrtab", false); SymbolTableSection DynSymTab(DynStrTab); + VersionDefinitionSection VerDef; VersionTableSection VerSym; VersionNeedSection VerNeed; @@ -189,6 +190,7 @@ Out::ShStrTab = &ShStrTab; Out::StrTab = StrTab.get(); Out::SymTab = SymTabSec.get(); + Out::VerDef = &VerDef; Out::VerSym = &VerSym; Out::VerNeed = &VerNeed; Out::MipsRldMap = MipsRldMap.get(); @@ -807,6 +809,9 @@ }); } + if (!Config->SymbolVersions.empty()) + Out::VerDef->createDefs(); + // Now that we have defined all possible symbols including linker- // synthesized ones. Visit all symbols to give the finishing touches. std::vector CommonSymbols; @@ -904,10 +909,14 @@ Add(Out::StrTab); if (isOutputDynamic()) { Add(Out::DynSymTab); - if (Out::VerNeed->getNeedNum() != 0) { + + if (Out::VerSym->isRequired()) Add(Out::VerSym); + if (!Config->SymbolVersions.empty()) + Add(Out::VerDef); + if (Out::VerNeed->getNeedNum() != 0) Add(Out::VerNeed); - } + Add(Out::GnuHashTab); Add(Out::HashTab); Add(Out::Dynamic); Index: test/ELF/Inputs/verdef.s =================================================================== --- test/ELF/Inputs/verdef.s +++ test/ELF/Inputs/verdef.s @@ -0,0 +1,6 @@ +.text +.globl _start +_start: + callq a + callq b + callq c Index: test/ELF/lto/version-script.ll =================================================================== --- test/ELF/lto/version-script.ll +++ test/ELF/lto/version-script.ll @@ -0,0 +1,50 @@ +; REQUIRES: x86 +; RUN: llvm-as %s -o %t.o +; RUN: echo "VERSION_1.0{ global: foo; local: *; }; VERSION_2.0{ global: bar; local: *; };" > %t.script +; RUN: ld.lld -m elf_x86_64 %t.o -o %t2 -shared --version-script %t.script -save-temps +; RUN: llvm-dis < %t2.lto.bc | FileCheck %s +; RUN: llvm-readobj -V -dyn-symbols %t2 | FileCheck --check-prefix=DSO %s + +target triple = "x86_64-unknown-linux-gnu" +target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" + +define void @foo() { + ret void +} + +define void @bar() { + ret void +} + +; CHECK: define void @foo() +; CHECK: define void @bar() + +; DSO: DynamicSymbols [ +; DSO: Symbol { +; DSO: Name: @ (0) +; DSO: Value: 0x0 +; DSO: Size: 0 +; DSO: Binding: Local +; DSO: Type: None +; DSO: Other: 0 +; DSO: Section: Undefined +; DSO: } +; DSO: Symbol { +; DSO: Name: foo@@VERSION_1.0 +; DSO: Value: 0x1000 +; DSO: Size: 1 +; DSO: Binding: Global +; DSO: Type: Function +; DSO: Other: 0 +; DSO: Section: .text +; DSO: } +; DSO: Symbol { +; DSO: Name: bar@@VERSION_2.0 +; DSO: Value: 0x1010 +; DSO: Size: 1 +; DSO: Binding: Global +; DSO: Type: Function +; DSO: Other: 0 +; DSO: Section: .text +; DSO: } +; DSO: ] Index: test/ELF/verdef.s =================================================================== --- test/ELF/verdef.s +++ test/ELF/verdef.s @@ -0,0 +1,131 @@ +# REQUIRES: x86 +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: echo "LIBSAMPLE_1.0{ \ +# RUN: global: a; \ +# RUN: local: *; }; \ +# RUN: LIBSAMPLE_2.0{ \ +# RUN: global: b; \ +# RUN: local: *; }; \ +# RUN: LIBSAMPLE_3.0{ \ +# RUN: global: c; \ +# RUN: local: *; };" > %t.script +# RUN: ld.lld --version-script %t.script -shared %t.o -o %t.so +# RUN: llvm-readobj -V -dyn-symbols %t.so | FileCheck --check-prefix=DSO %s + +# DSO: Version symbols { +# DSO-NEXT: Section Name: .gnu.version +# DSO-NEXT: Address: 0x228 +# DSO-NEXT: Offset: 0x228 +# DSO-NEXT: Link: 1 +# DSO-NEXT: Symbols [ +# DSO-NEXT: Symbol { +# DSO-NEXT: Version: 0 +# DSO-NEXT: Name: @ +# DSO-NEXT: } +# DSO-NEXT: Symbol { +# DSO-NEXT: Version: 2 +# DSO-NEXT: Name: a@@LIBSAMPLE_1.0 +# DSO-NEXT: } +# DSO-NEXT: Symbol { +# DSO-NEXT: Version: 3 +# DSO-NEXT: Name: b@@LIBSAMPLE_2.0 +# DSO-NEXT: } +# DSO-NEXT: Symbol { +# DSO-NEXT: Version: 4 +# DSO-NEXT: Name: c@@LIBSAMPLE_3.0 +# DSO-NEXT: } +# DSO-NEXT: ] +# DSO-NEXT: } +# DSO-NEXT: Version definition { +# DSO-NEXT: Section Name: .gnu.version_d +# DSO-NEXT: Address: 0x230 +# DSO-NEXT: Offset: 0x230 +# DSO-NEXT: Link: 5 +# DSO-NEXT: Entries [ +# DSO-NEXT: Entry { +# DSO-NEXT: Offset: 0x0 +# DSO-NEXT: Rev: 1 +# DSO-NEXT: Flags: 1 +# DSO-NEXT: Index: 1 +# DSO-NEXT: Cnt: 1 +# DSO-NEXT: Hash: 146942095 +# DSO-NEXT: Name: +# DSO-NEXT: } +# DSO-NEXT: Entry { +# DSO-NEXT: Offset: 0x14 +# DSO-NEXT: Rev: 1 +# DSO-NEXT: Flags: 0 +# DSO-NEXT: Index: 2 +# DSO-NEXT: Cnt: 1 +# DSO-NEXT: Hash: 98457184 +# DSO-NEXT: Name: LIBSAMPLE_1.0 +# DSO-NEXT: } +# DSO-NEXT: Entry { +# DSO-NEXT: Offset: 0x28 +# DSO-NEXT: Rev: 1 +# DSO-NEXT: Flags: 0 +# DSO-NEXT: Index: 3 +# DSO-NEXT: Cnt: 1 +# DSO-NEXT: Hash: 98456416 +# DSO-NEXT: Name: LIBSAMPLE_2.0 +# DSO-NEXT: } +# DSO-NEXT: Entry { +# DSO-NEXT: Offset: 0x3C +# DSO-NEXT: Rev: 1 +# DSO-NEXT: Flags: 0 +# DSO-NEXT: Index: 4 +# DSO-NEXT: Cnt: 1 +# DSO-NEXT: Hash: 98456672 +# DSO-NEXT: Name: LIBSAMPLE_3.0 +# DSO-NEXT: } +# DSO-NEXT: ] +# DSO-NEXT: } +# DSO-NEXT: SHT_GNU_verneed { +# DSO-NEXT: } + +## Check that we can link agains DSO we produced. +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %S/Inputs/verdef.s -o %tmain.o +# RUN: ld.lld %tmain.o %t.so -o %tout +# RUN: llvm-readobj -V %tout | FileCheck --check-prefix=MAIN %s + +# MAIN: Version symbols { +# MAIN-NEXT: Section Name: .gnu.version +# MAIN-NEXT: Address: 0x10228 +# MAIN-NEXT: Offset: 0x228 +# MAIN-NEXT: Link: 1 +# MAIN-NEXT: Symbols [ +# MAIN-NEXT: Symbol { +# MAIN-NEXT: Version: 0 +# MAIN-NEXT: Name: @ +# MAIN-NEXT: } +# MAIN-NEXT: Symbol { +# MAIN-NEXT: Version: 2 +# MAIN-NEXT: Name: a@LIBSAMPLE_1.0 +# MAIN-NEXT: } +# MAIN-NEXT: Symbol { +# MAIN-NEXT: Version: 3 +# MAIN-NEXT: Name: b@LIBSAMPLE_2.0 +# MAIN-NEXT: } +# MAIN-NEXT: Symbol { +# MAIN-NEXT: Version: 4 +# MAIN-NEXT: Name: c@LIBSAMPLE_3.0 +# MAIN-NEXT: } +# MAIN-NEXT: ] +# MAIN-NEXT: } +# MAIN-NEXT: Version definition { +# MAIN-NEXT: } + +.globl a +.type a,@function +a: +retq + +.globl b +.type b,@function +b: +retq + +.globl c +.type c,@function +c: +retq Index: test/ELF/version-script.s =================================================================== --- test/ELF/version-script.s +++ test/ELF/version-script.s @@ -26,7 +26,7 @@ # RUN: global: foo3; \ # RUN: local: *; }; " > %t4.script # RUN: ld.lld --version-script %t4.script -shared %t.o %t2.so -o %t4.so -# RUN: llvm-readobj -dyn-symbols %t4.so | FileCheck --check-prefix=DSO %s +# RUN: llvm-readobj -dyn-symbols %t4.so | FileCheck --check-prefix=VERDSO %s # RUN: echo "VERSION_1.0{ \ # RUN: global: foo1; \ @@ -140,6 +140,111 @@ # EXE-NEXT: } # EXE-NEXT: ] +# VERDSO: DynamicSymbols [ +# VERDSO-NEXT: Symbol { +# VERDSO-NEXT: Name: @ +# VERDSO-NEXT: Value: 0x0 +# VERDSO-NEXT: Size: 0 +# VERDSO-NEXT: Binding: Local +# VERDSO-NEXT: Type: None +# VERDSO-NEXT: Other: 0 +# VERDSO-NEXT: Section: Undefined +# VERDSO-NEXT: } +# VERDSO-NEXT: Symbol { +# VERDSO-NEXT: Name: bar@ +# VERDSO-NEXT: Value: 0x0 +# VERDSO-NEXT: Size: 0 +# VERDSO-NEXT: Binding: Global +# VERDSO-NEXT: Type: Function +# VERDSO-NEXT: Other: 0 +# VERDSO-NEXT: Section: Undefined +# VERDSO-NEXT: } +# VERDSO-NEXT: Symbol { +# VERDSO-NEXT: Name: foo1@@VERSION_1.0 +# VERDSO-NEXT: Value: 0x1000 +# VERDSO-NEXT: Size: 0 +# VERDSO-NEXT: Binding: Global +# VERDSO-NEXT: Type: None +# VERDSO-NEXT: Other: 0 +# VERDSO-NEXT: Section: .text +# VERDSO-NEXT: } +# VERDSO-NEXT: Symbol { +# VERDSO-NEXT: Name: foo3@@VERSION_2.0 +# VERDSO-NEXT: Value: 0x1007 +# VERDSO-NEXT: Size: 0 +# VERDSO-NEXT: Binding: Global +# VERDSO-NEXT: Type: None +# VERDSO-NEXT: Other: 0 +# VERDSO-NEXT: Section: .text +# VERDSO-NEXT: } +# VERDSO-NEXT: ] + +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: ld.lld -shared %t.o %t2.so -o %t.so +# RUN: llvm-readobj -dyn-symbols %t.so | FileCheck --check-prefix=ALL %s + +# RUN: echo "{ global: foo1; foo3; };" > %t2.script +# RUN: llvm-mc -filetype=obj -triple=x86_64-unknown-linux %s -o %t.o +# RUN: ld.lld --version-script %t2.script -shared %t.o %t2.so -o %t.so +# RUN: llvm-readobj -dyn-symbols %t.so | FileCheck --check-prefix=ALL %s + +# ALL: DynamicSymbols [ +# ALL-NEXT: Symbol { +# ALL-NEXT: Name: @ +# ALL-NEXT: Value: 0x0 +# ALL-NEXT: Size: 0 +# ALL-NEXT: Binding: Local +# ALL-NEXT: Type: None +# ALL-NEXT: Other: 0 +# ALL-NEXT: Section: Undefined +# ALL-NEXT: } +# ALL-NEXT: Symbol { +# ALL-NEXT: Name: _start@ +# ALL-NEXT: Value: +# ALL-NEXT: Size: 0 +# ALL-NEXT: Binding: Global +# ALL-NEXT: Type: None +# ALL-NEXT: Other: 0 +# ALL-NEXT: Section: .text +# ALL-NEXT: } +# ALL-NEXT: Symbol { +# ALL-NEXT: Name: bar@ +# ALL-NEXT: Value: +# ALL-NEXT: Size: 0 +# ALL-NEXT: Binding: Global +# ALL-NEXT: Type: Function +# ALL-NEXT: Other: 0 +# ALL-NEXT: Section: Undefined +# ALL-NEXT: } +# ALL-NEXT: Symbol { +# ALL-NEXT: Name: foo1@ +# ALL-NEXT: Value: +# ALL-NEXT: Size: 0 +# ALL-NEXT: Binding: Global +# ALL-NEXT: Type: None +# ALL-NEXT: Other: 0 +# ALL-NEXT: Section: .text +# ALL-NEXT: } +# ALL-NEXT: Symbol { +# ALL-NEXT: Name: foo2@ +# ALL-NEXT: Value: +# ALL-NEXT: Size: 0 +# ALL-NEXT: Binding: Global +# ALL-NEXT: Type: None +# ALL-NEXT: Other: 0 +# ALL-NEXT: Section: .text +# ALL-NEXT: } +# ALL-NEXT: Symbol { +# ALL-NEXT: Name: foo3@ +# ALL-NEXT: Value: +# ALL-NEXT: Size: 0 +# ALL-NEXT: Binding: Global +# ALL-NEXT: Type: None +# ALL-NEXT: Other: 0 +# ALL-NEXT: Section: .text +# ALL-NEXT: } +# ALL-NEXT: ] + .globl foo1 foo1: call bar@PLT