Skip to content

Commit

Permalink
[ELF] - Depricate version references.
Browse files Browse the repository at this point in the history
This is PR28358

According to
https://www.akkadia.org/drepper/dsohowto.pdf

"The fourth point, the VERS 1.0 version being referred to in the VERS 2.0 definition, is not really important in symbol versioning. It marks the predecessor relationship of the two versions and it is done to maintain the similar- ities with Solaris’ internal versioning. It does not cause any problem it might in fact be useful to a human reader so predecessors should always be mentioned."

Patch partially reverts 273423 "[ELF] - Implemented version script hierarchies.",
version references are just ignored now.

Differential revision: http://reviews.llvm.org/D21888

llvm-svn: 274345
  • Loading branch information
George Rimar committed Jul 1, 2016
1 parent b0b52fc commit 33b9de4
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 40 deletions.
1 change: 0 additions & 1 deletion lld/ELF/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ enum class UnresolvedPolicy { NoUndef, Error, Warn, Ignore };
struct Version {
Version(llvm::StringRef Name) : Name(Name) {}
llvm::StringRef Name;
llvm::StringRef Parent;
std::vector<llvm::StringRef> Globals;
size_t NameOff; // Offset in string table.
};
Expand Down
29 changes: 4 additions & 25 deletions lld/ELF/OutputSections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1488,10 +1488,6 @@ template <class ELFT> void VersionDefinitionSection<ELFT>::finalize() {

this->Header.sh_size =
(sizeof(Elf_Verdef) + sizeof(Elf_Verdaux)) * getVerDefNum();
for (Version &V : Config->SymbolVersions)
if (!V.Parent.empty())
this->Header.sh_size += sizeof(Elf_Verdaux);

this->Header.sh_link = Out<ELFT>::DynStrTab->SectionIndex;
this->Header.sh_addralign = sizeof(uint32_t);

Expand All @@ -1501,22 +1497,12 @@ template <class ELFT> void VersionDefinitionSection<ELFT>::finalize() {
this->Header.sh_info = getVerDefNum();
}

static size_t getVersionNameStrTabOffset(StringRef Name) {
for (Version &V : Config->SymbolVersions)
if (V.Name == Name)
return V.NameOff;
error("unknown version name " + Name + " used as a dependency");
return 0;
}

template <class Elf_Verdef, class Elf_Verdaux>
static void writeDefinition(Elf_Verdef *&Verdef, Elf_Verdaux *&Verdaux,
uint32_t Flags, uint32_t Index, StringRef Name,
size_t StrTabOffset, StringRef ParentName) {
bool HasParent = !ParentName.empty();

size_t StrTabOffset) {
Verdef->vd_version = 1;
Verdef->vd_cnt = HasParent ? 2 : 1;
Verdef->vd_cnt = 1;
Verdef->vd_aux =
reinterpret_cast<char *>(Verdaux) - reinterpret_cast<char *>(Verdef);
Verdef->vd_next = sizeof(Elf_Verdef);
Expand All @@ -1527,12 +1513,6 @@ static void writeDefinition(Elf_Verdef *&Verdef, Elf_Verdaux *&Verdaux,
++Verdef;

Verdaux->vda_name = StrTabOffset;
if (HasParent) {
Verdaux->vda_next = sizeof(Elf_Verdaux);
++Verdaux;
Verdaux->vda_name = getVersionNameStrTabOffset(ParentName);
}

Verdaux->vda_next = 0;
++Verdaux;
}
Expand All @@ -1544,12 +1524,11 @@ void VersionDefinitionSection<ELFT>::writeTo(uint8_t *Buf) {
reinterpret_cast<Elf_Verdaux *>(Verdef + getVerDefNum());

writeDefinition(Verdef, Verdaux, VER_FLG_BASE, 1, getFileDefName(),
FileDefNameOff, "" /* Parent */);
FileDefNameOff);

uint32_t I = 2;
for (Version &V : Config->SymbolVersions)
writeDefinition(Verdef, Verdaux, 0 /* Flags */, I++, V.Name, V.NameOff,
V.Parent);
writeDefinition(Verdef, Verdaux, 0 /* Flags */, I++, V.Name, V.NameOff);

Verdef[-1].vd_next = 0;
}
Expand Down
7 changes: 6 additions & 1 deletion lld/ELF/SymbolListFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,13 @@ void VersionScriptParser::parseVersion(StringRef Version) {
parseVersionSymbols(Version);

expect("}");

// Each version may have a parent version. For example, "Ver2" defined as
// "Ver2 { global: foo; local: *; } Ver1;" has "Ver1" as a parent. This
// version hierarchy is, probably against your instinct, purely for human; the
// runtime doesn't care about them at all. In LLD, we simply skip the token.
if (!Version.empty() && peek() != ";")
Config->SymbolVersions.back().Parent = next();
next();
expect(";");
}

Expand Down
1 change: 0 additions & 1 deletion lld/test/ELF/verdef-defaultver.s
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@
# DSO-NEXT: Index: 3
# DSO-NEXT: Hash: 98456416
# DSO-NEXT: Name: LIBSAMPLE_2.0
# DSO-NEXT: Predecessor: LIBSAMPLE_1.0
# DSO-NEXT: }
# DSO-NEXT: }

Expand Down
12 changes: 0 additions & 12 deletions lld/test/ELF/verdef-dependency.s
Original file line number Diff line number Diff line change
Expand Up @@ -33,24 +33,12 @@
# DSO-NEXT: Index: 3
# DSO-NEXT: Hash: 98456416
# DSO-NEXT: Name: LIBSAMPLE_2.0
# DSO-NEXT: Predecessor: LIBSAMPLE_1.0
# DSO-NEXT: }
# DSO-NEXT: Definition {
# DSO-NEXT: Version: 1
# DSO-NEXT: Flags: 0x0
# DSO-NEXT: Index: 4
# DSO-NEXT: Hash: 98456672
# DSO-NEXT: Name: LIBSAMPLE_3.0
# DSO-NEXT: Predecessor: LIBSAMPLE_2.0
# DSO-NEXT: }
# DSO-NEXT: }

# RUN: echo "LIBSAMPLE_1.0{ \
# RUN: global: a; \
# RUN: local: *; }; \
# RUN: LIBSAMPLE_2.0{ \
# RUN: global: b; \
# RUN: local: *; }LIBSAMPLE_X.X; " > %t.script
# RUN: not ld.lld --version-script %t.script -shared %t.o -o %t.so 2>&1 \
# RUN: | FileCheck -check-prefix=ERR %s
# ERR: unknown version name LIBSAMPLE_X.X used as a dependency

0 comments on commit 33b9de4

Please sign in to comment.