OpenASIP 2.2
Loading...
Searching...
No Matches
Protected Member Functions | Private Member Functions | Static Private Attributes | List of all members
TPEF::TPEFSymbolSectionReader Class Reference

#include <TPEFSymbolSectionReader.hh>

Inheritance diagram for TPEF::TPEFSymbolSectionReader:
Inheritance graph
Collaboration diagram for TPEF::TPEFSymbolSectionReader:
Collaboration graph

Protected Member Functions

 TPEFSymbolSectionReader ()
 
virtual ~TPEFSymbolSectionReader ()
 
virtual void readData (BinaryStream &stream, Section *section) const
 
virtual Section::SectionType type () const
 
- Protected Member Functions inherited from TPEF::TPEFSectionReader
 TPEFSectionReader ()
 
virtual BinaryReaderparent () const
 
virtual void readInfo (BinaryStream &stream, Section *sect) const
 
- Protected Member Functions inherited from TPEF::SectionReader
 SectionReader ()
 
virtual void finalize (Section *section) const
 

Private Member Functions

 TPEFSymbolSectionReader (const TPEFSymbolSectionReader &)
 Copying not allowed.
 
TPEFSymbolSectionReaderoperator= (TPEFSymbolSectionReader &)
 Assignment not allowed.
 
SymbolElementcreateSymbol (SymbolElement::SymbolType symType, Word aValue, Word aSize, SectionId sectToBelong) const
 

Static Private Attributes

static const Byte SYMBOL_TYPE_MASK = 0x0F
 Mask for getting type of symbol from st_info field of symbol element.
 
static TPEFSymbolSectionReader proto_
 Prototype instance of TPEFSymbolSectionReader to be registered to SectionReader.
 

Additional Inherited Members

- Public Types inherited from TPEF::SectionReader
typedef BinaryReader::Length Length
 
- Public Member Functions inherited from TPEF::TPEFSectionReader
virtual ~TPEFSectionReader ()
 
- Public Member Functions inherited from TPEF::SectionReader
virtual ~SectionReader ()
 
- Static Public Member Functions inherited from TPEF::SectionReader
static void readSection (BinaryStream &stream, Section *section, BinaryReader *reader)
 
static void finalizeBinary (Binary *binaryToFinalize, BinaryReader *reader)
 
- Static Protected Member Functions inherited from TPEF::TPEFSectionReader
static const Headerheader ()
 
- Static Protected Member Functions inherited from TPEF::SectionReader
static const SectionReaderfindSectionReader (const Section::SectionType type, const BinaryReader *bReader)
 
static void registerSectionReader (const SectionReader *sReader)
 

Detailed Description

Reads symbol section from TPEF binary file.

Definition at line 47 of file TPEFSymbolSectionReader.hh.

Constructor & Destructor Documentation

◆ TPEFSymbolSectionReader() [1/2]

TPEF::TPEFSymbolSectionReader::TPEFSymbolSectionReader ( )
protected

Constructor.

Registers itself to SectionReader.

Definition at line 70 of file TPEFSymbolSectionReader.cc.

72}
static void registerSectionReader(const SectionReader *sReader)

References TPEF::SectionReader::registerSectionReader().

Here is the call graph for this function:

◆ ~TPEFSymbolSectionReader()

TPEF::TPEFSymbolSectionReader::~TPEFSymbolSectionReader ( )
protectedvirtual

Destructor.

Definition at line 77 of file TPEFSymbolSectionReader.cc.

77 {
78}

◆ TPEFSymbolSectionReader() [2/2]

TPEF::TPEFSymbolSectionReader::TPEFSymbolSectionReader ( const TPEFSymbolSectionReader )
private

Copying not allowed.

Member Function Documentation

◆ createSymbol()

SymbolElement * TPEF::TPEFSymbolSectionReader::createSymbol ( SymbolElement::SymbolType  symType,
Word  aValue,
Word  aSize,
SectionId  sectToBelong 
) const
private

Creates symbol element.

Parameters
symTypeType of symbol to create.
aValueValue of element.
aSizeSize of element.
sectToBelongIdentification code of the section that contains the element.
Returns
Newly created symbol.

Definition at line 203 of file TPEFSymbolSectionReader.cc.

207 {
208
209 SymbolElement *elem = NULL;
210
211 // NOTE: check symbols from latest spec and
212 // add whole element reading stuff here.
213 switch (symType) {
215 elem = new NoTypeSymElement();
216 break;
217
219 elem = new ProcedSymElement();
220 /* fall through */
221
223 if (elem == NULL) {
224 elem = new CodeSymElement();
225 }
226
227 if (sectToBelong != 0) {
228 SectionOffsetKey sOffKey(sectToBelong, aValue);
229 dynamic_cast<CodeSymElement*>
230 (elem)->setReference(CREATE_SAFEPOINTER(sOffKey));
231 dynamic_cast<CodeSymElement*>
232 (elem)->setSize(aSize);
233 }
234
235 break;
236
238 elem = new DataSymElement();
239
240 if (sectToBelong != 0) {
241 SectionOffsetKey sOffKey(sectToBelong, aValue);
242 dynamic_cast<DataSymElement*>
243 (elem)->setReference(CREATE_SAFEPOINTER(sOffKey));
244
245 dynamic_cast<DataSymElement*>
246 (elem)->setSize(aSize);
247 }
248
249 break;
250
252 elem = new SectionSymElement();
253 dynamic_cast<SectionSymElement*>(elem)->setValue(aValue);
254 dynamic_cast<SectionSymElement*>(elem)->setSize(aSize);
255 break;
256
258 elem = new FileSymElement();
259 dynamic_cast<FileSymElement*>(elem)->setValue(aValue);
260 break;
261
262 default:
263 ;
264 }
265
266 return elem;
267}
@ STT_PROCEDURE
Symbol gives indicates procedure start position in section.
@ STT_FILE
Name of symbol gives the name of source file associated with this object file.
@ STT_CODE
Associated with executable code.
@ STT_NOTYPE
Type is not defined.
@ STT_SECTION
Associated with section.
@ STT_DATA
Associated with data object.

References TPEF::SymbolElement::STT_CODE, TPEF::SymbolElement::STT_DATA, TPEF::SymbolElement::STT_FILE, TPEF::SymbolElement::STT_NOTYPE, TPEF::SymbolElement::STT_PROCEDURE, and TPEF::SymbolElement::STT_SECTION.

Referenced by readData().

◆ operator=()

TPEFSymbolSectionReader & TPEF::TPEFSymbolSectionReader::operator= ( TPEFSymbolSectionReader )
private

Assignment not allowed.

◆ readData()

void TPEF::TPEFSymbolSectionReader::readData ( BinaryStream stream,
Section section 
) const
protectedvirtual

Reads section data from TPEF binary file.

Parameters
streamStream to be read from.
sectionSection where the information is to be stored.
Exceptions
UnreachableStreamIf reading of section fails.
KeyAlreadyExistsKey was in use when trying to register object.
EndOfFileIf end of file were reached while it shouldn't.
OutOfRangeSome of read value were out of range.
WrongSubclassSome class couldn't do what it was asked for.
UnexpectedValueIf there was unexpected value when reading.

Reimplemented from TPEF::TPEFSectionReader.

Definition at line 103 of file TPEFSymbolSectionReader.cc.

104 {
105 // base classes implementation must be called with these.
106 TPEFSectionReader::readData(stream, section);
107
108 SymbolSection* symbolSection =
109 dynamic_cast<SymbolSection*>(section);
110 assert(symbolSection != NULL);
111
112 // create indexs' starting from 0 undefined element is checked
113 SectionIndex index = 0;
114 bool undefSymbolDefined = false;
115
116 // check that link section is defined properly
117 assert(header().linkId != 0);
118
119 if (!section->noBits()) {
120 // start of first element
121 SectionOffset elementStart = header().bodyOffset;
122
123 while (elementStart + header().elementSize <=
124 header().bodyOffset + header().bodyLength) {
125
126 SymbolElement *elem = NULL;
127
128 Word nameOffset = stream.readWord();
129 Word value = stream.readWord();
130 Word size = stream.readWord();
131 Byte info = stream.readByte();
132 Byte otherField = stream.readByte();
133
134 SectionId sectionToBelong = stream.readHalfWord();
135
136 // lower half byte is type of symbol
137 SymbolType typeOfSym =
138 static_cast<SymbolType>(info & SYMBOL_TYPE_MASK);
139
140 // upper half byte is binding
141 SymbolBinding binding =
142 static_cast<SymbolBinding>(info >> (BYTE_BITWIDTH / 2));
143
144 // symbol of right type
145 elem = createSymbol(typeOfSym, value, size, sectionToBelong);
146
147 elem->setAbsolute(otherField & TPEFHeaders::STO_ABS);
148 elem->setBinding(binding);
149
150 SectionOffsetKey sOffKey(header().linkId, nameOffset);
151 elem->setName(CREATE_SAFEPOINTER(sOffKey));
152
153 // section which to symbol belongs
154 SectionKey sKey(sectionToBelong);
155 elem->setSection(CREATE_SAFEPOINTER(sKey));
156
157 SectionIndexKey sectionIndexKey(header().sectionId, index);
158 SafePointer::addObjectReference(sectionIndexKey, elem);
159
160
161 // check undefined symbol
162 if (index == 0) {
163 assert(elem->type() == SymbolElement::STT_NOTYPE);
164 assert(elem->binding() == SymbolElement::STB_LOCAL);
165 assert(elem->absolute() == true);
166 assert(nameOffset == 0);
167 undefSymbolDefined = true;
168 }
169
170 section->addElement(elem);
171
172 elementStart += header().elementSize;
173 stream.setReadPosition(elementStart);
174 index++;
175 }
176 }
177
178 // create undefined symbol if not found from table
179 // (e.g. if section had nobits flag set)
180 if (!undefSymbolDefined) {
181 NoTypeSymElement* elem = new NoTypeSymElement();
182 elem->setBinding(SymbolElement::STB_LOCAL);
183 elem->setAbsolute(true);
184 SectionOffsetKey sOffKey(header().linkId, 0);
185 elem->setName(CREATE_SAFEPOINTER(sOffKey));
186 SectionIndexKey sectionIndexKey(header().sectionId, 0);
187 SafePointer::addObjectReference(sectionIndexKey, elem);
188 section->addElement(elem);
189 }
190}
#define assert(condition)
const Byte BYTE_BITWIDTH
Definition BaseType.hh:136
unsigned char Byte
Definition BaseType.hh:116
static void addObjectReference(SectionIndexKey key, const SafePointable *obj)
@ STB_LOCAL
Not visible outside the object file that contains it's definition.
virtual void readData(BinaryStream &stream, Section *section) const
static const Header & header()
SymbolElement * createSymbol(SymbolElement::SymbolType symType, Word aValue, Word aSize, SectionId sectToBelong) const
static const Byte SYMBOL_TYPE_MASK
Mask for getting type of symbol from st_info field of symbol element.
@ STO_ABS
Section is absolute, not relocating.
HalfWord SectionId
Type for storing binary file section ids.
SymbolElement::SymbolType SymbolType
Word SectionIndex
Type for storing section indexes.
Word SectionOffset
Type for storing offsets relative to a given base offset value.
SymbolElement::SymbolBinding SymbolBinding

References TPEF::SymbolElement::absolute(), TPEF::Section::addElement(), TPEF::ReferenceManager::SafePointer::addObjectReference(), assert, TPEF::SymbolElement::binding(), TPEF::TPEFSectionReader::Header::bodyOffset, BYTE_BITWIDTH, createSymbol(), TPEF::TPEFSectionReader::Header::elementSize, TPEF::TPEFSectionReader::header(), TPEF::Section::noBits(), TPEF::BinaryStream::readByte(), TPEF::TPEFSectionReader::readData(), TPEF::BinaryStream::readHalfWord(), TPEF::BinaryStream::readWord(), TPEF::SymbolElement::setAbsolute(), TPEF::SymbolElement::setBinding(), TPEF::SymbolElement::setName(), TPEF::BinaryStream::setReadPosition(), TPEF::SymbolElement::setSection(), TPEF::SymbolElement::STB_LOCAL, TPEF::TPEFHeaders::STO_ABS, TPEF::SymbolElement::STT_NOTYPE, SYMBOL_TYPE_MASK, and TPEF::SymbolElement::type().

Here is the call graph for this function:

◆ type()

Section::SectionType TPEF::TPEFSymbolSectionReader::type ( ) const
protectedvirtual

Returns the type of section it is meant to read.

Returns
The type of section it can read.

Implements TPEF::SectionReader.

Definition at line 86 of file TPEFSymbolSectionReader.cc.

86 {
87 return Section::ST_SYMTAB;
88}
@ ST_SYMTAB
Symbol table.
Definition Section.hh:72

References TPEF::Section::ST_SYMTAB.

Member Data Documentation

◆ proto_

TPEFSymbolSectionReader TPEF::TPEFSymbolSectionReader::proto_
staticprivate

Prototype instance of TPEFSymbolSectionReader to be registered to SectionReader.

Definition at line 72 of file TPEFSymbolSectionReader.hh.

◆ SYMBOL_TYPE_MASK

const Byte TPEF::TPEFSymbolSectionReader::SYMBOL_TYPE_MASK = 0x0F
staticprivate

Mask for getting type of symbol from st_info field of symbol element.

Definition at line 69 of file TPEFSymbolSectionReader.hh.

Referenced by readData().


The documentation for this class was generated from the following files: