forked from OSchip/llvm-project
				
			Use a reference for the shared symbol file.
Every shared symbol has a file, so we can use a reference. llvm-svn: 321187
This commit is contained in:
		
							parent
							
								
									7b5cc6c5dc
								
							
						
					
					
						commit
						a32ddc4639
					
				| 
						 | 
					@ -841,14 +841,14 @@ template <class ELFT> void SharedFile<ELFT>::parseRest() {
 | 
				
			||||||
      error(toString(this) + ": alignment too large: " + Name);
 | 
					      error(toString(this) + ": alignment too large: " + Name);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if (!Hidden)
 | 
					    if (!Hidden)
 | 
				
			||||||
      Symtab->addShared(Name, this, Sym, Alignment, VersymIndex);
 | 
					      Symtab->addShared(Name, *this, Sym, Alignment, VersymIndex);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Also add the symbol with the versioned name to handle undefined symbols
 | 
					    // Also add the symbol with the versioned name to handle undefined symbols
 | 
				
			||||||
    // with explicit versions.
 | 
					    // with explicit versions.
 | 
				
			||||||
    if (Ver) {
 | 
					    if (Ver) {
 | 
				
			||||||
      StringRef VerName = this->StringTable.data() + Ver->getAux()->vda_name;
 | 
					      StringRef VerName = this->StringTable.data() + Ver->getAux()->vda_name;
 | 
				
			||||||
      Name = Saver.save(Name + "@" + VerName);
 | 
					      Name = Saver.save(Name + "@" + VerName);
 | 
				
			||||||
      Symtab->addShared(Name, this, Sym, Alignment, VersymIndex);
 | 
					      Symtab->addShared(Name, *this, Sym, Alignment, VersymIndex);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -68,7 +68,7 @@ static void resolveReloc(InputSectionBase &Sec, RelT &Rel,
 | 
				
			||||||
  B.Used = true;
 | 
					  B.Used = true;
 | 
				
			||||||
  if (auto *SS = dyn_cast<SharedSymbol>(&B))
 | 
					  if (auto *SS = dyn_cast<SharedSymbol>(&B))
 | 
				
			||||||
    if (!SS->isWeak())
 | 
					    if (!SS->isWeak())
 | 
				
			||||||
      SS->getFile<ELFT>()->IsNeeded = true;
 | 
					      SS->getFile<ELFT>().IsNeeded = true;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  if (auto *D = dyn_cast<Defined>(&B)) {
 | 
					  if (auto *D = dyn_cast<Defined>(&B)) {
 | 
				
			||||||
    auto *RelSec = dyn_cast_or_null<InputSectionBase>(D->Section);
 | 
					    auto *RelSec = dyn_cast_or_null<InputSectionBase>(D->Section);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -443,8 +443,8 @@ template <class ELFT> static bool isReadOnly(SharedSymbol *SS) {
 | 
				
			||||||
  typedef typename ELFT::Phdr Elf_Phdr;
 | 
					  typedef typename ELFT::Phdr Elf_Phdr;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // Determine if the symbol is read-only by scanning the DSO's program headers.
 | 
					  // Determine if the symbol is read-only by scanning the DSO's program headers.
 | 
				
			||||||
  const SharedFile<ELFT> *File = SS->getFile<ELFT>();
 | 
					  const SharedFile<ELFT> &File = SS->getFile<ELFT>();
 | 
				
			||||||
  for (const Elf_Phdr &Phdr : check(File->getObj().program_headers()))
 | 
					  for (const Elf_Phdr &Phdr : check(File.getObj().program_headers()))
 | 
				
			||||||
    if ((Phdr.p_type == ELF::PT_LOAD || Phdr.p_type == ELF::PT_GNU_RELRO) &&
 | 
					    if ((Phdr.p_type == ELF::PT_LOAD || Phdr.p_type == ELF::PT_GNU_RELRO) &&
 | 
				
			||||||
        !(Phdr.p_flags & ELF::PF_W) && SS->Value >= Phdr.p_vaddr &&
 | 
					        !(Phdr.p_flags & ELF::PF_W) && SS->Value >= Phdr.p_vaddr &&
 | 
				
			||||||
        SS->Value < Phdr.p_vaddr + Phdr.p_memsz)
 | 
					        SS->Value < Phdr.p_vaddr + Phdr.p_memsz)
 | 
				
			||||||
| 
						 | 
					@ -461,14 +461,14 @@ template <class ELFT>
 | 
				
			||||||
static std::vector<SharedSymbol *> getSymbolsAt(SharedSymbol *SS) {
 | 
					static std::vector<SharedSymbol *> getSymbolsAt(SharedSymbol *SS) {
 | 
				
			||||||
  typedef typename ELFT::Sym Elf_Sym;
 | 
					  typedef typename ELFT::Sym Elf_Sym;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  SharedFile<ELFT> *File = SS->getFile<ELFT>();
 | 
					  SharedFile<ELFT> &File = SS->getFile<ELFT>();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  std::vector<SharedSymbol *> Ret;
 | 
					  std::vector<SharedSymbol *> Ret;
 | 
				
			||||||
  for (const Elf_Sym &S : File->getGlobalELFSyms()) {
 | 
					  for (const Elf_Sym &S : File.getGlobalELFSyms()) {
 | 
				
			||||||
    if (S.st_shndx == SHN_UNDEF || S.st_shndx == SHN_ABS ||
 | 
					    if (S.st_shndx == SHN_UNDEF || S.st_shndx == SHN_ABS ||
 | 
				
			||||||
        S.st_value != SS->Value)
 | 
					        S.st_value != SS->Value)
 | 
				
			||||||
      continue;
 | 
					      continue;
 | 
				
			||||||
    StringRef Name = check(S.getName(File->getStringTable()));
 | 
					    StringRef Name = check(S.getName(File.getStringTable()));
 | 
				
			||||||
    Symbol *Sym = Symtab->find(Name);
 | 
					    Symbol *Sym = Symtab->find(Name);
 | 
				
			||||||
    if (auto *Alias = dyn_cast_or_null<SharedSymbol>(Sym))
 | 
					    if (auto *Alias = dyn_cast_or_null<SharedSymbol>(Sym))
 | 
				
			||||||
      Ret.push_back(Alias);
 | 
					      Ret.push_back(Alias);
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -306,7 +306,7 @@ Symbol *SymbolTable::addUndefined(StringRef Name, uint8_t Binding,
 | 
				
			||||||
  if (Binding != STB_WEAK) {
 | 
					  if (Binding != STB_WEAK) {
 | 
				
			||||||
    if (auto *SS = dyn_cast<SharedSymbol>(S))
 | 
					    if (auto *SS = dyn_cast<SharedSymbol>(S))
 | 
				
			||||||
      if (!Config->GcSections)
 | 
					      if (!Config->GcSections)
 | 
				
			||||||
        SS->getFile<ELFT>()->IsNeeded = true;
 | 
					        SS->getFile<ELFT>().IsNeeded = true;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  if (auto *L = dyn_cast<Lazy>(S)) {
 | 
					  if (auto *L = dyn_cast<Lazy>(S)) {
 | 
				
			||||||
    // An undefined weak will not fetch archive members. See comment on Lazy in
 | 
					    // An undefined weak will not fetch archive members. See comment on Lazy in
 | 
				
			||||||
| 
						 | 
					@ -476,7 +476,7 @@ Symbol *SymbolTable::addRegular(StringRef Name, uint8_t StOther, uint8_t Type,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template <typename ELFT>
 | 
					template <typename ELFT>
 | 
				
			||||||
void SymbolTable::addShared(StringRef Name, SharedFile<ELFT> *File,
 | 
					void SymbolTable::addShared(StringRef Name, SharedFile<ELFT> &File,
 | 
				
			||||||
                            const typename ELFT::Sym &Sym, uint32_t Alignment,
 | 
					                            const typename ELFT::Sym &Sym, uint32_t Alignment,
 | 
				
			||||||
                            uint32_t VerdefIndex) {
 | 
					                            uint32_t VerdefIndex) {
 | 
				
			||||||
  // DSO symbols do not affect visibility in the output, so we pass STV_DEFAULT
 | 
					  // DSO symbols do not affect visibility in the output, so we pass STV_DEFAULT
 | 
				
			||||||
| 
						 | 
					@ -485,7 +485,7 @@ void SymbolTable::addShared(StringRef Name, SharedFile<ELFT> *File,
 | 
				
			||||||
  Symbol *S;
 | 
					  Symbol *S;
 | 
				
			||||||
  bool WasInserted;
 | 
					  bool WasInserted;
 | 
				
			||||||
  std::tie(S, WasInserted) = insert(Name, Sym.getType(), STV_DEFAULT,
 | 
					  std::tie(S, WasInserted) = insert(Name, Sym.getType(), STV_DEFAULT,
 | 
				
			||||||
                                    /*CanOmitFromDynSym*/ true, File);
 | 
					                                    /*CanOmitFromDynSym*/ true, &File);
 | 
				
			||||||
  // Make sure we preempt DSO symbols with default visibility.
 | 
					  // Make sure we preempt DSO symbols with default visibility.
 | 
				
			||||||
  if (Sym.getVisibility() == STV_DEFAULT)
 | 
					  if (Sym.getVisibility() == STV_DEFAULT)
 | 
				
			||||||
    S->ExportDynamic = true;
 | 
					    S->ExportDynamic = true;
 | 
				
			||||||
| 
						 | 
					@ -501,7 +501,7 @@ void SymbolTable::addShared(StringRef Name, SharedFile<ELFT> *File,
 | 
				
			||||||
    if (!WasInserted) {
 | 
					    if (!WasInserted) {
 | 
				
			||||||
      S->Binding = Binding;
 | 
					      S->Binding = Binding;
 | 
				
			||||||
      if (!S->isWeak() && !Config->GcSections)
 | 
					      if (!S->isWeak() && !Config->GcSections)
 | 
				
			||||||
        File->IsNeeded = true;
 | 
					        File.IsNeeded = true;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					@ -837,16 +837,16 @@ template void SymbolTable::addLazyObject<ELF32BE>(StringRef, LazyObjFile &);
 | 
				
			||||||
template void SymbolTable::addLazyObject<ELF64LE>(StringRef, LazyObjFile &);
 | 
					template void SymbolTable::addLazyObject<ELF64LE>(StringRef, LazyObjFile &);
 | 
				
			||||||
template void SymbolTable::addLazyObject<ELF64BE>(StringRef, LazyObjFile &);
 | 
					template void SymbolTable::addLazyObject<ELF64BE>(StringRef, LazyObjFile &);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template void SymbolTable::addShared<ELF32LE>(StringRef, SharedFile<ELF32LE> *,
 | 
					template void SymbolTable::addShared<ELF32LE>(StringRef, SharedFile<ELF32LE> &,
 | 
				
			||||||
                                              const typename ELF32LE::Sym &,
 | 
					                                              const typename ELF32LE::Sym &,
 | 
				
			||||||
                                              uint32_t Alignment, uint32_t);
 | 
					                                              uint32_t Alignment, uint32_t);
 | 
				
			||||||
template void SymbolTable::addShared<ELF32BE>(StringRef, SharedFile<ELF32BE> *,
 | 
					template void SymbolTable::addShared<ELF32BE>(StringRef, SharedFile<ELF32BE> &,
 | 
				
			||||||
                                              const typename ELF32BE::Sym &,
 | 
					                                              const typename ELF32BE::Sym &,
 | 
				
			||||||
                                              uint32_t Alignment, uint32_t);
 | 
					                                              uint32_t Alignment, uint32_t);
 | 
				
			||||||
template void SymbolTable::addShared<ELF64LE>(StringRef, SharedFile<ELF64LE> *,
 | 
					template void SymbolTable::addShared<ELF64LE>(StringRef, SharedFile<ELF64LE> &,
 | 
				
			||||||
                                              const typename ELF64LE::Sym &,
 | 
					                                              const typename ELF64LE::Sym &,
 | 
				
			||||||
                                              uint32_t Alignment, uint32_t);
 | 
					                                              uint32_t Alignment, uint32_t);
 | 
				
			||||||
template void SymbolTable::addShared<ELF64BE>(StringRef, SharedFile<ELF64BE> *,
 | 
					template void SymbolTable::addShared<ELF64BE>(StringRef, SharedFile<ELF64BE> &,
 | 
				
			||||||
                                              const typename ELF64BE::Sym &,
 | 
					                                              const typename ELF64BE::Sym &,
 | 
				
			||||||
                                              uint32_t Alignment, uint32_t);
 | 
					                                              uint32_t Alignment, uint32_t);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -57,7 +57,7 @@ public:
 | 
				
			||||||
                     SectionBase *Section, InputFile *File);
 | 
					                     SectionBase *Section, InputFile *File);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  template <class ELFT>
 | 
					  template <class ELFT>
 | 
				
			||||||
  void addShared(StringRef Name, SharedFile<ELFT> *F,
 | 
					  void addShared(StringRef Name, SharedFile<ELFT> &F,
 | 
				
			||||||
                 const typename ELFT::Sym &Sym, uint32_t Alignment,
 | 
					                 const typename ELFT::Sym &Sym, uint32_t Alignment,
 | 
				
			||||||
                 uint32_t VerdefIndex);
 | 
					                 uint32_t VerdefIndex);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -208,10 +208,10 @@ class SharedSymbol : public Symbol {
 | 
				
			||||||
public:
 | 
					public:
 | 
				
			||||||
  static bool classof(const Symbol *S) { return S->kind() == SharedKind; }
 | 
					  static bool classof(const Symbol *S) { return S->kind() == SharedKind; }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  SharedSymbol(InputFile *File, StringRef Name, uint8_t Binding,
 | 
					  SharedSymbol(InputFile &File, StringRef Name, uint8_t Binding,
 | 
				
			||||||
               uint8_t StOther, uint8_t Type, uint64_t Value, uint64_t Size,
 | 
					               uint8_t StOther, uint8_t Type, uint64_t Value, uint64_t Size,
 | 
				
			||||||
               uint32_t Alignment, uint32_t VerdefIndex)
 | 
					               uint32_t Alignment, uint32_t VerdefIndex)
 | 
				
			||||||
      : Symbol(SharedKind, File, Name, Binding, StOther, Type), Value(Value),
 | 
					      : Symbol(SharedKind, &File, Name, Binding, StOther, Type), Value(Value),
 | 
				
			||||||
        Size(Size), VerdefIndex(VerdefIndex), Alignment(Alignment) {
 | 
					        Size(Size), VerdefIndex(VerdefIndex), Alignment(Alignment) {
 | 
				
			||||||
    // GNU ifunc is a mechanism to allow user-supplied functions to
 | 
					    // GNU ifunc is a mechanism to allow user-supplied functions to
 | 
				
			||||||
    // resolve PLT slot values at load-time. This is contrary to the
 | 
					    // resolve PLT slot values at load-time. This is contrary to the
 | 
				
			||||||
| 
						 | 
					@ -233,8 +233,8 @@ public:
 | 
				
			||||||
      this->Type = llvm::ELF::STT_FUNC;
 | 
					      this->Type = llvm::ELF::STT_FUNC;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  template <class ELFT> SharedFile<ELFT> *getFile() const {
 | 
					  template <class ELFT> SharedFile<ELFT> &getFile() const {
 | 
				
			||||||
    return cast<SharedFile<ELFT>>(File);
 | 
					    return *cast<SharedFile<ELFT>>(File);
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
  // If not null, there is a copy relocation to this section.
 | 
					  // If not null, there is a copy relocation to this section.
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2299,8 +2299,8 @@ VersionNeedSection<ELFT>::VersionNeedSection()
 | 
				
			||||||
 | 
					
 | 
				
			||||||
template <class ELFT>
 | 
					template <class ELFT>
 | 
				
			||||||
void VersionNeedSection<ELFT>::addSymbol(SharedSymbol *SS) {
 | 
					void VersionNeedSection<ELFT>::addSymbol(SharedSymbol *SS) {
 | 
				
			||||||
  SharedFile<ELFT> *File = SS->getFile<ELFT>();
 | 
					  SharedFile<ELFT> &File = SS->getFile<ELFT>();
 | 
				
			||||||
  const typename ELFT::Verdef *Ver = File->Verdefs[SS->VerdefIndex];
 | 
					  const typename ELFT::Verdef *Ver = File.Verdefs[SS->VerdefIndex];
 | 
				
			||||||
  if (!Ver) {
 | 
					  if (!Ver) {
 | 
				
			||||||
    SS->VersionId = VER_NDX_GLOBAL;
 | 
					    SS->VersionId = VER_NDX_GLOBAL;
 | 
				
			||||||
    return;
 | 
					    return;
 | 
				
			||||||
| 
						 | 
					@ -2309,14 +2309,14 @@ void VersionNeedSection<ELFT>::addSymbol(SharedSymbol *SS) {
 | 
				
			||||||
  // If we don't already know that we need an Elf_Verneed for this DSO, prepare
 | 
					  // If we don't already know that we need an Elf_Verneed for this DSO, prepare
 | 
				
			||||||
  // to create one by adding it to our needed list and creating a dynstr entry
 | 
					  // to create one by adding it to our needed list and creating a dynstr entry
 | 
				
			||||||
  // for the soname.
 | 
					  // for the soname.
 | 
				
			||||||
  if (File->VerdefMap.empty())
 | 
					  if (File.VerdefMap.empty())
 | 
				
			||||||
    Needed.push_back({File, InX::DynStrTab->addString(File->SoName)});
 | 
					    Needed.push_back({&File, InX::DynStrTab->addString(File.SoName)});
 | 
				
			||||||
  typename SharedFile<ELFT>::NeededVer &NV = File->VerdefMap[Ver];
 | 
					  typename SharedFile<ELFT>::NeededVer &NV = File.VerdefMap[Ver];
 | 
				
			||||||
  // If we don't already know that we need an Elf_Vernaux for this Elf_Verdef,
 | 
					  // If we don't already know that we need an Elf_Vernaux for this Elf_Verdef,
 | 
				
			||||||
  // prepare to create one by allocating a version identifier and creating a
 | 
					  // prepare to create one by allocating a version identifier and creating a
 | 
				
			||||||
  // dynstr entry for the version name.
 | 
					  // dynstr entry for the version name.
 | 
				
			||||||
  if (NV.Index == 0) {
 | 
					  if (NV.Index == 0) {
 | 
				
			||||||
    NV.StrTab = InX::DynStrTab->addString(File->getStringTable().data() +
 | 
					    NV.StrTab = InX::DynStrTab->addString(File.getStringTable().data() +
 | 
				
			||||||
                                          Ver->getAux()->vda_name);
 | 
					                                          Ver->getAux()->vda_name);
 | 
				
			||||||
    NV.Index = NextIndex++;
 | 
					    NV.Index = NextIndex++;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue