[llvm] r313114 - [llvm-objcopy] Add e_machine validity check for reserved section indexes
Petr Hosek via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 12 20:04:50 PDT 2017
Author: phosek
Date: Tue Sep 12 20:04:50 2017
New Revision: 313114
URL: http://llvm.org/viewvc/llvm-project?rev=313114&view=rev
Log:
[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
Modified:
llvm/trunk/test/tools/llvm-objcopy/common-symbol.test
llvm/trunk/tools/llvm-objcopy/Object.cpp
Modified: llvm/trunk/test/tools/llvm-objcopy/common-symbol.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-objcopy/common-symbol.test?rev=313114&r1=313113&r2=313114&view=diff
==============================================================================
--- llvm/trunk/test/tools/llvm-objcopy/common-symbol.test (original)
+++ llvm/trunk/test/tools/llvm-objcopy/common-symbol.test Tue Sep 12 20:04:50 2017
@@ -7,7 +7,7 @@ FileHeader:
Class: ELFCLASS64
Data: ELFDATA2LSB
Type: ET_EXEC
- Machine: EM_X86_64
+ Machine: EM_HEXAGON
Symbols:
Global:
- Name: test
Modified: llvm/trunk/tools/llvm-objcopy/Object.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-objcopy/Object.cpp?rev=313114&r1=313113&r2=313114&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-objcopy/Object.cpp (original)
+++ llvm/trunk/tools/llvm-objcopy/Object.cpp Tue Sep 12 20:04:50 2017
@@ -90,18 +90,22 @@ void StringTableSection::writeSection(Fi
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(Strin
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
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: " +
More information about the llvm-commits
mailing list