2015-07-25 05:03:07 +08:00
|
|
|
//===- Symbols.cpp --------------------------------------------------------===//
|
|
|
|
//
|
|
|
|
// The LLVM Linker
|
|
|
|
//
|
|
|
|
// This file is distributed under the University of Illinois Open Source
|
|
|
|
// License. See LICENSE.TXT for details.
|
|
|
|
//
|
|
|
|
//===----------------------------------------------------------------------===//
|
|
|
|
|
|
|
|
#include "Symbols.h"
|
|
|
|
#include "Chunks.h"
|
2015-08-06 23:33:19 +08:00
|
|
|
#include "Error.h"
|
2015-07-29 06:58:25 +08:00
|
|
|
#include "InputFiles.h"
|
2015-07-25 05:03:07 +08:00
|
|
|
|
|
|
|
using namespace llvm::object;
|
2015-09-02 07:12:52 +08:00
|
|
|
using namespace llvm::ELF;
|
2015-07-25 05:03:07 +08:00
|
|
|
|
|
|
|
using namespace lld;
|
|
|
|
using namespace lld::elf2;
|
|
|
|
|
2015-09-02 07:12:52 +08:00
|
|
|
static uint8_t getMinVisibility(uint8_t VA, uint8_t VB) {
|
|
|
|
if (VA == STV_DEFAULT)
|
|
|
|
return VB;
|
|
|
|
if (VB == STV_DEFAULT)
|
|
|
|
return VA;
|
|
|
|
return std::min(VA, VB);
|
|
|
|
}
|
|
|
|
|
2015-07-25 05:03:07 +08:00
|
|
|
// Returns 1, 0 or -1 if this symbol should take precedence
|
|
|
|
// over the Other, tie or lose, respectively.
|
2015-08-31 09:16:19 +08:00
|
|
|
template <class ELFT> int SymbolBody::compare(SymbolBody *Other) {
|
2015-08-31 07:17:30 +08:00
|
|
|
std::pair<bool, bool> L(isDefined(), !isWeak());
|
|
|
|
std::pair<bool, bool> R(Other->isDefined(), !Other->isWeak());
|
2015-07-28 04:39:01 +08:00
|
|
|
|
2015-08-29 04:19:34 +08:00
|
|
|
// Normalize
|
|
|
|
if (L > R)
|
2015-08-31 09:16:19 +08:00
|
|
|
return -Other->compare<ELFT>(this);
|
2015-07-25 05:03:07 +08:00
|
|
|
|
2015-09-02 07:12:52 +08:00
|
|
|
uint8_t LV = getMostConstrainingVisibility();
|
|
|
|
uint8_t RV = Other->getMostConstrainingVisibility();
|
|
|
|
MostConstrainingVisibility = getMinVisibility(LV, RV);
|
|
|
|
Other->MostConstrainingVisibility = MostConstrainingVisibility;
|
|
|
|
|
2015-08-29 04:19:34 +08:00
|
|
|
if (L != R)
|
|
|
|
return -1;
|
2015-07-25 05:03:07 +08:00
|
|
|
|
2015-08-31 07:17:30 +08:00
|
|
|
if (L.first && L.second) {
|
2015-08-31 09:16:19 +08:00
|
|
|
if (isCommon()) {
|
|
|
|
if (Other->isCommon()) {
|
2015-09-01 09:19:12 +08:00
|
|
|
auto *ThisC = cast<DefinedCommon<ELFT>>(this);
|
|
|
|
auto *OtherC = cast<DefinedCommon<ELFT>>(Other);
|
|
|
|
typename DefinedCommon<ELFT>::uintX_t MaxAlign =
|
|
|
|
std::max(ThisC->MaxAlignment, OtherC->MaxAlignment);
|
|
|
|
if (ThisC->Sym.st_size >= OtherC->Sym.st_size) {
|
|
|
|
ThisC->MaxAlignment = MaxAlign;
|
2015-08-31 09:16:19 +08:00
|
|
|
return 1;
|
2015-09-01 09:19:12 +08:00
|
|
|
}
|
|
|
|
OtherC->MaxAlignment = MaxAlign;
|
2015-08-31 09:16:19 +08:00
|
|
|
return -1;
|
|
|
|
}
|
2015-08-31 07:17:30 +08:00
|
|
|
return -1;
|
2015-08-31 09:16:19 +08:00
|
|
|
}
|
2015-08-31 07:17:30 +08:00
|
|
|
if (Other->isCommon())
|
|
|
|
return 1;
|
2015-07-25 05:03:07 +08:00
|
|
|
return 0;
|
2015-08-31 07:17:30 +08:00
|
|
|
}
|
2015-08-29 04:19:34 +08:00
|
|
|
return 1;
|
2015-07-25 05:03:07 +08:00
|
|
|
}
|
2015-08-31 09:16:19 +08:00
|
|
|
|
|
|
|
template int SymbolBody::compare<ELF32LE>(SymbolBody *Other);
|
|
|
|
template int SymbolBody::compare<ELF32BE>(SymbolBody *Other);
|
|
|
|
template int SymbolBody::compare<ELF64LE>(SymbolBody *Other);
|
|
|
|
template int SymbolBody::compare<ELF64BE>(SymbolBody *Other);
|