mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-06-26 23:24:34 +00:00
Object/COFF: Add function to check if section number is reserved one.
Differential Revision: http://llvm-reviews.chandlerc.com/D3103 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@204199 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@ -30,6 +30,9 @@
|
|||||||
namespace llvm {
|
namespace llvm {
|
||||||
namespace COFF {
|
namespace COFF {
|
||||||
|
|
||||||
|
// The maximum number of sections that a COFF object can have (inclusive).
|
||||||
|
const int MaxNumberOfSections = 65299;
|
||||||
|
|
||||||
// The PE signature bytes that follows the DOS stub header.
|
// The PE signature bytes that follows the DOS stub header.
|
||||||
static const char PEMagic[] = { 'P', 'E', '\0', '\0' };
|
static const char PEMagic[] = { 'P', 'E', '\0', '\0' };
|
||||||
|
|
||||||
@ -625,6 +628,10 @@ namespace COFF {
|
|||||||
DEBUG_INDEX_SUBSECTION = 0xF4
|
DEBUG_INDEX_SUBSECTION = 0xF4
|
||||||
};
|
};
|
||||||
|
|
||||||
|
inline bool isReservedSectionNumber(int N) {
|
||||||
|
return N == IMAGE_SYM_UNDEFINED || N > MaxNumberOfSections;
|
||||||
|
}
|
||||||
|
|
||||||
} // End namespace COFF.
|
} // End namespace COFF.
|
||||||
} // End namespace llvm.
|
} // End namespace llvm.
|
||||||
|
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
#include "llvm/ADT/SmallString.h"
|
#include "llvm/ADT/SmallString.h"
|
||||||
#include "llvm/ADT/StringSwitch.h"
|
#include "llvm/ADT/StringSwitch.h"
|
||||||
#include "llvm/ADT/Triple.h"
|
#include "llvm/ADT/Triple.h"
|
||||||
|
#include "llvm/Support/COFF.h"
|
||||||
#include "llvm/Support/Debug.h"
|
#include "llvm/Support/Debug.h"
|
||||||
#include "llvm/Support/raw_ostream.h"
|
#include "llvm/Support/raw_ostream.h"
|
||||||
#include <cctype>
|
#include <cctype>
|
||||||
@ -177,7 +178,7 @@ error_code COFFObjectFile::getSymbolType(DataRefImpl Ref,
|
|||||||
Result = SymbolRef::ST_Function;
|
Result = SymbolRef::ST_Function;
|
||||||
} else {
|
} else {
|
||||||
uint32_t Characteristics = 0;
|
uint32_t Characteristics = 0;
|
||||||
if (Symb->SectionNumber > 0) {
|
if (!COFF::isReservedSectionNumber(Symb->SectionNumber)) {
|
||||||
const coff_section *Section = NULL;
|
const coff_section *Section = NULL;
|
||||||
if (error_code EC = getSection(Symb->SectionNumber, Section))
|
if (error_code EC = getSection(Symb->SectionNumber, Section))
|
||||||
return EC;
|
return EC;
|
||||||
@ -239,9 +240,9 @@ error_code COFFObjectFile::getSymbolSize(DataRefImpl Ref,
|
|||||||
error_code COFFObjectFile::getSymbolSection(DataRefImpl Ref,
|
error_code COFFObjectFile::getSymbolSection(DataRefImpl Ref,
|
||||||
section_iterator &Result) const {
|
section_iterator &Result) const {
|
||||||
const coff_symbol *Symb = toSymb(Ref);
|
const coff_symbol *Symb = toSymb(Ref);
|
||||||
if (Symb->SectionNumber <= COFF::IMAGE_SYM_UNDEFINED)
|
if (COFF::isReservedSectionNumber(Symb->SectionNumber)) {
|
||||||
Result = section_end();
|
Result = section_end();
|
||||||
else {
|
} else {
|
||||||
const coff_section *Sec = 0;
|
const coff_section *Sec = 0;
|
||||||
if (error_code EC = getSection(Symb->SectionNumber, Sec)) return EC;
|
if (error_code EC = getSection(Symb->SectionNumber, Sec)) return EC;
|
||||||
DataRefImpl Ref;
|
DataRefImpl Ref;
|
||||||
@ -721,9 +722,7 @@ error_code COFFObjectFile::getDataDirectory(uint32_t Index,
|
|||||||
error_code COFFObjectFile::getSection(int32_t Index,
|
error_code COFFObjectFile::getSection(int32_t Index,
|
||||||
const coff_section *&Result) const {
|
const coff_section *&Result) const {
|
||||||
// Check for special index values.
|
// Check for special index values.
|
||||||
if (Index == COFF::IMAGE_SYM_UNDEFINED ||
|
if (COFF::isReservedSectionNumber(Index))
|
||||||
Index == COFF::IMAGE_SYM_ABSOLUTE ||
|
|
||||||
Index == COFF::IMAGE_SYM_DEBUG)
|
|
||||||
Result = NULL;
|
Result = NULL;
|
||||||
else if (Index > 0 && Index <= COFFHeader->NumberOfSections)
|
else if (Index > 0 && Index <= COFFHeader->NumberOfSections)
|
||||||
// We already verified the section table data, so no need to check again.
|
// We already verified the section table data, so no need to check again.
|
||||||
|
Binary file not shown.
@ -39,7 +39,7 @@ COFF32-NEXT: Machine: IMAGE_FILE_MACHINE_I386 (0x14C)
|
|||||||
COFF32-NEXT: SectionCount: 2
|
COFF32-NEXT: SectionCount: 2
|
||||||
COFF32-NEXT: TimeDateStamp: 2013-03-20 17:56:46 (0x5149F85E)
|
COFF32-NEXT: TimeDateStamp: 2013-03-20 17:56:46 (0x5149F85E)
|
||||||
COFF32-NEXT: PointerToSymbolTable: 0xA5
|
COFF32-NEXT: PointerToSymbolTable: 0xA5
|
||||||
COFF32-NEXT: SymbolCount: 7
|
COFF32-NEXT: SymbolCount: 9
|
||||||
COFF32-NEXT: OptionalHeaderSize: 0
|
COFF32-NEXT: OptionalHeaderSize: 0
|
||||||
COFF32-NEXT: Characteristics [ (0x0)
|
COFF32-NEXT: Characteristics [ (0x0)
|
||||||
COFF32-NEXT: ]
|
COFF32-NEXT: ]
|
||||||
|
@ -5,6 +5,24 @@ RUN: | FileCheck %s -check-prefix ELF
|
|||||||
|
|
||||||
COFF: Symbols [
|
COFF: Symbols [
|
||||||
COFF-NEXT: Symbol {
|
COFF-NEXT: Symbol {
|
||||||
|
COFF-NEXT: Name: @comp.id
|
||||||
|
COFF-NEXT: Value: 14766605
|
||||||
|
COFF-NEXT: Section: (65535)
|
||||||
|
COFF-NEXT: BaseType: Null (0x0)
|
||||||
|
COFF-NEXT: ComplexType: Null (0x0)
|
||||||
|
COFF-NEXT: StorageClass: Static (0x3)
|
||||||
|
COFF-NEXT: AuxSymbolCount: 0
|
||||||
|
COFF-NEXT: }
|
||||||
|
COFF-NEXT: Symbol {
|
||||||
|
COFF-NEXT: Name: @feat.00
|
||||||
|
COFF-NEXT: Value: 2147484049
|
||||||
|
COFF-NEXT: Section: (65535)
|
||||||
|
COFF-NEXT: BaseType: Null (0x0)
|
||||||
|
COFF-NEXT: ComplexType: Null (0x0)
|
||||||
|
COFF-NEXT: StorageClass: Static (0x3)
|
||||||
|
COFF-NEXT: AuxSymbolCount: 0
|
||||||
|
COFF-NEXT: }
|
||||||
|
COFF-NEXT: Symbol {
|
||||||
COFF-NEXT: Name: .text
|
COFF-NEXT: Name: .text
|
||||||
COFF-NEXT: Value: 0
|
COFF-NEXT: Value: 0
|
||||||
COFF-NEXT: Section: .text (1)
|
COFF-NEXT: Section: .text (1)
|
||||||
|
@ -27,6 +27,7 @@
|
|||||||
#include "llvm/Object/MachO.h"
|
#include "llvm/Object/MachO.h"
|
||||||
#include "llvm/Object/MachOUniversal.h"
|
#include "llvm/Object/MachOUniversal.h"
|
||||||
#include "llvm/Object/ObjectFile.h"
|
#include "llvm/Object/ObjectFile.h"
|
||||||
|
#include "llvm/Support/COFF.h"
|
||||||
#include "llvm/Support/CommandLine.h"
|
#include "llvm/Support/CommandLine.h"
|
||||||
#include "llvm/Support/FileSystem.h"
|
#include "llvm/Support/FileSystem.h"
|
||||||
#include "llvm/Support/Format.h"
|
#include "llvm/Support/Format.h"
|
||||||
@ -317,9 +318,7 @@ static char getSymbolNMTypeChar(COFFObjectFile &Obj, symbol_iterator I) {
|
|||||||
return Ret;
|
return Ret;
|
||||||
|
|
||||||
uint32_t Characteristics = 0;
|
uint32_t Characteristics = 0;
|
||||||
if (Symb->SectionNumber > 0 &&
|
if (!COFF::isReservedSectionNumber(Symb->SectionNumber)) {
|
||||||
Symb->SectionNumber != llvm::COFF::IMAGE_SYM_DEBUG &&
|
|
||||||
Symb->SectionNumber != llvm::COFF::IMAGE_SYM_ABSOLUTE) {
|
|
||||||
section_iterator SecI = Obj.section_end();
|
section_iterator SecI = Obj.section_end();
|
||||||
if (error(SymI->getSection(SecI)))
|
if (error(SymI->getSection(SecI)))
|
||||||
return '?';
|
return '?';
|
||||||
|
@ -985,7 +985,7 @@ void COFFDumper::printSymbol(const SymbolRef &Sym) {
|
|||||||
} else if (
|
} else if (
|
||||||
Symbol->StorageClass == COFF::IMAGE_SYM_CLASS_WEAK_EXTERNAL ||
|
Symbol->StorageClass == COFF::IMAGE_SYM_CLASS_WEAK_EXTERNAL ||
|
||||||
(Symbol->StorageClass == COFF::IMAGE_SYM_CLASS_EXTERNAL &&
|
(Symbol->StorageClass == COFF::IMAGE_SYM_CLASS_EXTERNAL &&
|
||||||
Symbol->SectionNumber == 0 &&
|
Symbol->SectionNumber == COFF::IMAGE_SYM_UNDEFINED &&
|
||||||
Symbol->Value == 0)) {
|
Symbol->Value == 0)) {
|
||||||
const coff_aux_weak_external_definition *Aux;
|
const coff_aux_weak_external_definition *Aux;
|
||||||
if (error(getSymbolAuxData(Obj, Symbol + I, Aux)))
|
if (error(getSymbolAuxData(Obj, Symbol + I, Aux)))
|
||||||
|
Reference in New Issue
Block a user