Changeset View
Changeset View
Standalone View
Standalone View
llvm/tools/llvm-objcopy/ELF/Object.cpp
Show First 20 Lines • Show All 591 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
static bool isValidReservedSectionIndex(uint16_t Index, uint16_t Machine) { | static bool isValidReservedSectionIndex(uint16_t Index, uint16_t Machine) { | ||||
switch (Index) { | switch (Index) { | ||||
case SHN_ABS: | case SHN_ABS: | ||||
case SHN_COMMON: | case SHN_COMMON: | ||||
return true; | return true; | ||||
} | } | ||||
if (Machine == EM_AMDGPU) { | |||||
return Index == SHN_AMDGPU_LDS; | |||||
} | |||||
if (Machine == EM_HEXAGON) { | if (Machine == EM_HEXAGON) { | ||||
switch (Index) { | switch (Index) { | ||||
case SHN_HEXAGON_SCOMMON: | case SHN_HEXAGON_SCOMMON: | ||||
case SHN_HEXAGON_SCOMMON_2: | case SHN_HEXAGON_SCOMMON_2: | ||||
case SHN_HEXAGON_SCOMMON_4: | case SHN_HEXAGON_SCOMMON_4: | ||||
case SHN_HEXAGON_SCOMMON_8: | case SHN_HEXAGON_SCOMMON_8: | ||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
// Large indexes force us to clarify exactly what this function should do. This | // Large indexes force us to clarify exactly what this function should do. This | ||||
// function should return the value that will appear in st_shndx when written | // function should return the value that will appear in st_shndx when written | ||||
// out. | // out. | ||||
uint16_t Symbol::getShndx() const { | uint16_t Symbol::getShndx() const { | ||||
if (DefinedIn != nullptr) { | if (DefinedIn != nullptr) { | ||||
if (DefinedIn->Index >= SHN_LORESERVE) | if (DefinedIn->Index >= SHN_LORESERVE) | ||||
return SHN_XINDEX; | return SHN_XINDEX; | ||||
return DefinedIn->Index; | return DefinedIn->Index; | ||||
} | } | ||||
switch (ShndxType) { | |||||
if (ShndxType == SYMBOL_SIMPLE_INDEX) { | |||||
// This means that we don't have a defined section but we do need to | // This means that we don't have a defined section but we do need to | ||||
// output a legitimate section index. | // output a legitimate section index. | ||||
case SYMBOL_SIMPLE_INDEX: | |||||
return SHN_UNDEF; | return SHN_UNDEF; | ||||
case SYMBOL_ABS: | |||||
case SYMBOL_COMMON: | |||||
case SYMBOL_HEXAGON_SCOMMON: | |||||
case SYMBOL_HEXAGON_SCOMMON_2: | |||||
case SYMBOL_HEXAGON_SCOMMON_4: | |||||
case SYMBOL_HEXAGON_SCOMMON_8: | |||||
case SYMBOL_XINDEX: | |||||
return static_cast<uint16_t>(ShndxType); | |||||
} | } | ||||
llvm_unreachable("Symbol with invalid ShndxType encountered"); | |||||
assert(ShndxType == SYMBOL_ABS || ShndxType == SYMBOL_COMMON || | |||||
(ShndxType >= ELF::SHN_LOPROC && ShndxType <= ELF::SHN_HIPROC) || | |||||
(ShndxType >= ELF::SHN_LOOS && ShndxType <= ELF::SHN_HIOS)); | |||||
return static_cast<uint16_t>(ShndxType); | |||||
} | } | ||||
bool Symbol::isCommon() const { return getShndx() == SHN_COMMON; } | bool Symbol::isCommon() const { return getShndx() == SHN_COMMON; } | ||||
void SymbolTableSection::assignIndices() { | void SymbolTableSection::assignIndices() { | ||||
uint32_t Index = 0; | uint32_t Index = 0; | ||||
for (auto &Sym : Symbols) | for (auto &Sym : Symbols) | ||||
Sym->Index = Index++; | Sym->Index = Index++; | ||||
▲ Show 20 Lines • Show All 1,657 Lines • Show Last 20 Lines |