Index: ELF/Config.h =================================================================== --- ELF/Config.h +++ ELF/Config.h @@ -38,10 +38,11 @@ // 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) : Name(Name) {} + Version(llvm::StringRef Name, size_t Id) : Name(Name), Id(Id) {} llvm::StringRef Name; std::vector Globals; size_t NameOff; // Offset in string table. + size_t Id; }; // This struct contains the global configuration for the linker. Index: ELF/SymbolListFile.cpp =================================================================== --- ELF/SymbolListFile.cpp +++ ELF/SymbolListFile.cpp @@ -84,7 +84,10 @@ void VersionScriptParser::parseVersion(StringRef Version) { expect("{"); - Config->SymbolVersions.push_back(elf::Version(Version)); + // Identifiers start at 2 because 0 and 1 are reserved + // by VER_NDX_LOCAL and VER_NDX_GLOBAL constants. + Config->SymbolVersions.push_back( + elf::Version(Version, Config->SymbolVersions.size() + 2)); if (peek() == "global:") { next(); parseVersionSymbols(Version); Index: ELF/SymbolTable.cpp =================================================================== --- ELF/SymbolTable.cpp +++ ELF/SymbolTable.cpp @@ -180,12 +180,10 @@ if (Default) Version = Version.drop_front(); - size_t I = 2; - for (elf::Version &V : Config->SymbolVersions) { + for (elf::Version &V : Config->SymbolVersions) if (V.Name == Version) - return Default ? I : (I | VERSYM_HIDDEN); - ++I; - } + return Default ? V.Id : (V.Id | VERSYM_HIDDEN); + error("symbol " + Name + " has undefined version " + Version); return 0; } @@ -596,7 +594,7 @@ if (B->symbol()->VersionId != VER_NDX_GLOBAL && B->symbol()->VersionId != VER_NDX_LOCAL) warning("duplicate symbol " + Name + " in version script"); - B->symbol()->VersionId = I + 2; + B->symbol()->VersionId = V.Id; } } @@ -609,7 +607,7 @@ for (SymbolBody *B : findAll(Name)) if (B->symbol()->VersionId == VER_NDX_GLOBAL || B->symbol()->VersionId == VER_NDX_LOCAL) - B->symbol()->VersionId = I + 2; + B->symbol()->VersionId = V.Id; } } }