mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-23 11:13:28 +01:00
[llvm-objcopy] Add e_machine validity check for reserved section indexes
As discussed on llvm-commits it was decided it would be best to check e_machine before declaring that a reserved section index is valid. The only special e_machine value that matters here is EM_HEXAGON. This change adds a special check for EM_HEXAGON. Patch by Jake Ehrlich Differential Revision: https://reviews.llvm.org/D37767 llvm-svn: 313114
This commit is contained in:
parent
357b62f45e
commit
f5534eb2a2
@ -7,7 +7,7 @@ FileHeader:
|
||||
Class: ELFCLASS64
|
||||
Data: ELFDATA2LSB
|
||||
Type: ET_EXEC
|
||||
Machine: EM_X86_64
|
||||
Machine: EM_HEXAGON
|
||||
Symbols:
|
||||
Global:
|
||||
- Name: test
|
||||
|
@ -90,18 +90,22 @@ void StringTableSection::writeSection(FileOutputBuffer &Out) const {
|
||||
StrTabBuilder.write(Out.getBufferStart() + Offset);
|
||||
}
|
||||
|
||||
static bool isValidReservedSectionIndex(uint16_t Index) {
|
||||
static bool isValidReservedSectionIndex(uint16_t Index, uint16_t Machine) {
|
||||
switch (Index) {
|
||||
case SHN_ABS:
|
||||
case SHN_COMMON:
|
||||
case SHN_HEXAGON_SCOMMON:
|
||||
case SHN_HEXAGON_SCOMMON_2:
|
||||
case SHN_HEXAGON_SCOMMON_4:
|
||||
case SHN_HEXAGON_SCOMMON_8:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
if (Machine == EM_HEXAGON) {
|
||||
switch (Index) {
|
||||
case SHN_HEXAGON_SCOMMON:
|
||||
case SHN_HEXAGON_SCOMMON_2:
|
||||
case SHN_HEXAGON_SCOMMON_4:
|
||||
case SHN_HEXAGON_SCOMMON_8:
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
uint16_t Symbol::getShndx() const {
|
||||
@ -133,7 +137,7 @@ void SymbolTableSection::addSymbol(StringRef Name, uint8_t Bind, uint8_t Type,
|
||||
Sym.Type = Type;
|
||||
Sym.DefinedIn = DefinedIn;
|
||||
if (DefinedIn == nullptr) {
|
||||
if (isValidReservedSectionIndex(Shndx))
|
||||
if (Shndx >= SHN_LORESERVE)
|
||||
Sym.ShndxType = static_cast<SymbolShndxType>(Shndx);
|
||||
else
|
||||
Sym.ShndxType = SYMBOL_SIMPLE_INDEX;
|
||||
@ -289,7 +293,7 @@ void Object<ELFT>::initSymbolTable(const llvm::object::ELFFile<ELFT> &ElfFile,
|
||||
SectionBase *DefSection = nullptr;
|
||||
StringRef Name = unwrapOrError(Sym.getName(StrTabData));
|
||||
if (Sym.st_shndx >= SHN_LORESERVE) {
|
||||
if (!isValidReservedSectionIndex(Sym.st_shndx)) {
|
||||
if (!isValidReservedSectionIndex(Sym.st_shndx, Machine)) {
|
||||
error(
|
||||
"Symbol '" + Name +
|
||||
"' has unsupported value greater than or equal to SHN_LORESERVE: " +
|
||||
|
Loading…
Reference in New Issue
Block a user