OpenASIP  2.0
Protected Member Functions | Private Member Functions | Static Private Attributes | List of all members
TPEF::TPEFSymbolSectionWriter Class Reference

#include <TPEFSymbolSectionWriter.hh>

Inheritance diagram for TPEF::TPEFSymbolSectionWriter:
Inheritance graph
Collaboration diagram for TPEF::TPEFSymbolSectionWriter:
Collaboration graph

Protected Member Functions

 TPEFSymbolSectionWriter ()
 
virtual ~TPEFSymbolSectionWriter ()
 
virtual Section::SectionType type () const
 
virtual void createKeys (const Section *sect) const
 
virtual void actualWriteData (BinaryStream &stream, const Section *section) const
 
virtual Word elementSize (const Section *section) const
 
- Protected Member Functions inherited from TPEF::TPEFSectionWriter
 TPEFSectionWriter ()
 
virtual ~TPEFSectionWriter ()
 
virtual const BinaryWriterparent () const
 
virtual void actualWriteHeader (BinaryStream &stream, const Section *sect) const
 
virtual void writeSize (BinaryStream &stream, const Section *sect) const
 
virtual void writeInfo (BinaryStream &stream, const Section *sect) const
 
virtual SectionId getSectionId () const
 
- Protected Member Functions inherited from TPEF::SectionWriter
 SectionWriter ()
 
virtual ~SectionWriter ()
 
virtual void finalize (BinaryStream &stream, Section *section) const
 

Private Member Functions

 TPEFSymbolSectionWriter (const TPEFSymbolSectionWriter &)
 Copying not allowed. More...
 
TPEFSymbolSectionWriter operator= (const TPEFSymbolSectionWriter &)
 Assignment not allowed. More...
 
void writeValueAndSize (BinaryStream &stream, const SymbolElement *elem) const
 

Static Private Attributes

static const TPEFSymbolSectionWriter instance_
 An unique instance of class. More...
 
static const Word elementSize_ = 16
 The fixed size address space element. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from TPEF::SectionWriter
static void writeHeader (BinaryStream &stream, const Section *sect, const BinaryWriter *writer)
 
static void writeData (BinaryStream &stream, const Section *sect, const BinaryWriter *writer)
 
static void finalizeBinary (BinaryStream &stream, const Binary *binaryToFinalize, const BinaryWriter *writer)
 
- Static Protected Member Functions inherited from TPEF::SectionWriter
static void registerSectionWriter (const SectionWriter *sWriter)
 
static SectionId getUniqueSectionId ()
 

Detailed Description

Writes TPEF symbol table to stream.

Definition at line 47 of file TPEFSymbolSectionWriter.hh.

Constructor & Destructor Documentation

◆ TPEFSymbolSectionWriter() [1/2]

TPEF::TPEFSymbolSectionWriter::TPEFSymbolSectionWriter ( )
protected

Constructor.

Registers itself to SectionWriter.

Definition at line 67 of file TPEFSymbolSectionWriter.cc.

67  : TPEFSectionWriter() {
69 }

References TPEF::SectionWriter::registerSectionWriter().

Here is the call graph for this function:

◆ ~TPEFSymbolSectionWriter()

TPEF::TPEFSymbolSectionWriter::~TPEFSymbolSectionWriter ( )
protectedvirtual

Destructor.

Definition at line 74 of file TPEFSymbolSectionWriter.cc.

74  {
75 }

◆ TPEFSymbolSectionWriter() [2/2]

TPEF::TPEFSymbolSectionWriter::TPEFSymbolSectionWriter ( const TPEFSymbolSectionWriter )
private

Copying not allowed.

Member Function Documentation

◆ actualWriteData()

void TPEF::TPEFSymbolSectionWriter::actualWriteData ( BinaryStream stream,
const Section sect 
) const
protectedvirtual

Writes the data of the section in to stream.

Parameters
streamThe stream to be written to.
sectThe section to be written.

Reimplemented from TPEF::TPEFSectionWriter.

Definition at line 94 of file TPEFSymbolSectionWriter.cc.

96  {
97 
98  FileOffset startOffset = stream.writePosition();
99 
100  // file offset to data of section
102  FileOffsetKey(startOffset), sect->element(0));
103 
104  // resolve identification code of currently written section
105  SectionKey sectionKey = SafePointer::sectionKeyFor(sect);
106  SectionId sectionId = sectionKey.sectionId();
107 
108  // first element should match with undefined symbol
109  SymbolElement *undef = dynamic_cast<SymbolElement*>(sect->element(0));
110  assert(undef != NULL);
111  assert(undef->type() == SymbolElement::STT_NOTYPE);
112  assert(undef->absolute() == true);
113  assert(undef->binding() == SymbolElement::STB_LOCAL);
114  assert(undef->name()->offset() == 0);
115 
116  // symbols might have to be organized in a way local symbols are
117  // before weak symbols and global syms will come after everything else
118  for (Word i = 0; i < sect->elementCount(); i++) {
119 
120  SymbolElement* elem = dynamic_cast<SymbolElement*>(sect->element(i));
121  assert(elem != NULL);
122 
123  // each element must be registered with its index
125  SectionIndexKey(sectionId, i), elem);
126 
127  // write name
128  assert(elem->name() != NULL);
129  SectionOffsetReplacer sOffReplacer(elem->name());
130  sOffReplacer.resolve();
131 
132  writeValueAndSize(stream, elem);
133 
134  // write info
135  stream.writeByte(
136  (elem->binding() << (BYTE_BITWIDTH / 2)) |
137  static_cast<Byte>(elem->type()));
138 
139  // other field, right now only STO_ABS is used
140  Byte otherField = 0;
141  if (elem->absolute()) {
142  otherField = otherField | TPEFHeaders::STO_ABS;
143  }
144  stream.writeByte(otherField);
145 
146  // section to which the symbol belongs
147  // NOTE: Maybe nullSection should be used for these,
148  // so NULL would be error.
149 
150  if (elem->section() != NULL) {
151  SectionIdReplacer sectIdReplacer(elem->section());
152  sectIdReplacer.resolve();
153  } else {
154  stream.writeHalfWord(0);
155  }
156  }
157  SectionSizeReplacer::setSize(sect, stream.writePosition() - startOffset);
158 }

References TPEF::SymbolElement::absolute(), TPEF::ReferenceManager::SafePointer::addObjectReference(), assert, TPEF::SymbolElement::binding(), BYTE_BITWIDTH, TPEF::Section::element(), TPEF::Section::elementCount(), TPEF::SymbolElement::name(), TPEF::Chunk::offset(), TPEF::ValueReplacer::resolve(), TPEF::SymbolElement::section(), TPEF::ReferenceManager::SectionKey::sectionId(), TPEF::ReferenceManager::SafePointer::sectionKeyFor(), TPEF::SectionSizeReplacer::setSize(), TPEF::SymbolElement::STB_LOCAL, TPEF::TPEFHeaders::STO_ABS, TPEF::SymbolElement::STT_NOTYPE, TPEF::SymbolElement::type(), TPEF::BinaryStream::writeByte(), TPEF::BinaryStream::writeHalfWord(), TPEF::BinaryStream::writePosition(), and writeValueAndSize().

Here is the call graph for this function:

◆ createKeys()

void TPEF::TPEFSymbolSectionWriter::createKeys ( const Section sect) const
protectedvirtual

Creates needed keys for section if noBits flag is set.

Parameters
sectSection which for keys will be created.

Reimplemented from TPEF::TPEFSectionWriter.

Definition at line 264 of file TPEFSymbolSectionWriter.cc.

264  {
265  SectionSizeReplacer::setSize(sect, 0x0);
266 }

References TPEF::SectionSizeReplacer::setSize().

Here is the call graph for this function:

◆ elementSize()

Word TPEF::TPEFSymbolSectionWriter::elementSize ( const Section section) const
protectedvirtual

Returns the fixed size length of section elements.

Returns
The fixed size length of section elements.

Reimplemented from TPEF::TPEFSectionWriter.

Definition at line 254 of file TPEFSymbolSectionWriter.cc.

254  {
255  return elementSize_;
256 }

References elementSize_.

◆ operator=()

TPEFSymbolSectionWriter TPEF::TPEFSymbolSectionWriter::operator= ( const TPEFSymbolSectionWriter )
private

Assignment not allowed.

◆ type()

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

Returns the section type this writer can write.

Returns
The section type writer can write.

Implements TPEF::TPEFSectionWriter.

Definition at line 83 of file TPEFSymbolSectionWriter.cc.

83  {
84  return Section::ST_SYMTAB;
85 }

References TPEF::Section::ST_SYMTAB.

◆ writeValueAndSize()

void TPEF::TPEFSymbolSectionWriter::writeValueAndSize ( BinaryStream stream,
const SymbolElement elem 
) const
private

Writes value and size fields of symbol.

Parameters
streamStream where to write.
elemElement to write.

Definition at line 167 of file TPEFSymbolSectionWriter.cc.

169  {
170 
171  switch (elem->type()) {
173  // write value
174  // write size
175  stream.writeWord(0);
176  stream.writeWord(0);
177  break;
178  }
179 
182  const CodeSymElement* codeSym =
183  dynamic_cast<const CodeSymElement*>(elem);
184  assert(codeSym != NULL);
185 
186  // write value
187  if (codeSym->reference() != NULL) {
188  SectionOffsetReplacer replacer(codeSym->reference());
189  replacer.resolve();
190  } else {
191  stream.writeWord(0);
192  }
193 
194  // write size
195  stream.writeWord(codeSym->size());
196  break;
197  }
198 
200  const DataSymElement* dataSym =
201  dynamic_cast<const DataSymElement*>(elem);
202  assert(dataSym != NULL);
203 
204  // write value
205  if (dataSym->reference() != NULL) {
206  SectionOffsetReplacer replacer(dataSym->reference());
207  replacer.resolve();
208  } else {
209  stream.writeWord(0);
210  }
211 
212  // write size
213  stream.writeWord(dataSym->size());
214  break;
215  }
216 
218  const SectionSymElement* sectSym =
219  dynamic_cast<const SectionSymElement*>(elem);
220  assert(sectSym != NULL);
221 
222  // write value
223  stream.writeWord(sectSym->value());
224  // write size
225  stream.writeWord(sectSym->size());
226  break;
227  }
228 
230  const FileSymElement* fileSym =
231  dynamic_cast<const FileSymElement*>(elem);
232  assert(fileSym != NULL);
233 
234  // write value
235  stream.writeWord(fileSym->value());
236  // write size
237  stream.writeWord(0);
238  break;
239  }
240 
241  default: {
242  bool unknownSymbolType = false;
243  assert(unknownSymbolType);
244  }
245  }
246 }

References assert, TPEF::DataSymElement::reference(), TPEF::CodeSymElement::reference(), TPEF::ValueReplacer::resolve(), TPEF::DataSymElement::size(), TPEF::SectionSymElement::size(), TPEF::CodeSymElement::size(), TPEF::SymbolElement::STT_CODE, TPEF::SymbolElement::STT_DATA, TPEF::SymbolElement::STT_FILE, TPEF::SymbolElement::STT_NOTYPE, TPEF::SymbolElement::STT_PROCEDURE, TPEF::SymbolElement::STT_SECTION, TPEF::SymbolElement::type(), TPEF::SectionSymElement::value(), TPEF::FileSymElement::value(), and TPEF::BinaryStream::writeWord().

Referenced by actualWriteData().

Here is the call graph for this function:

Member Data Documentation

◆ elementSize_

const Word TPEF::TPEFSymbolSectionWriter::elementSize_ = 16
staticprivate

The fixed size address space element.

Definition at line 75 of file TPEFSymbolSectionWriter.hh.

Referenced by elementSize().

◆ instance_

const TPEFSymbolSectionWriter TPEF::TPEFSymbolSectionWriter::instance_
staticprivate

An unique instance of class.

Definition at line 73 of file TPEFSymbolSectionWriter.hh.


The documentation for this class was generated from the following files:
TPEF::SectionId
HalfWord SectionId
Type for storing binary file section ids.
Definition: TPEFBaseType.hh:43
TPEF::SymbolElement::STT_PROCEDURE
@ STT_PROCEDURE
Symbol gives indicates procedure start position in section.
Definition: SymbolElement.hh:73
TPEF::Section::ST_SYMTAB
@ ST_SYMTAB
Symbol table.
Definition: Section.hh:72
TPEF::SymbolElement::STT_FILE
@ STT_FILE
Name of symbol gives the name of source file associated with this object file.
Definition: SymbolElement.hh:71
Byte
unsigned char Byte
Definition: BaseType.hh:116
TPEF::SymbolElement::STT_SECTION
@ STT_SECTION
Associated with section.
Definition: SymbolElement.hh:70
TPEF::ReferenceManager::SafePointer::addObjectReference
static void addObjectReference(SectionIndexKey key, const SafePointable *obj)
Definition: SafePointer.cc:306
assert
#define assert(condition)
Definition: Application.hh:86
TPEF::SectionWriter::registerSectionWriter
static void registerSectionWriter(const SectionWriter *sWriter)
Definition: SectionWriter.cc:148
TPEF::ReferenceManager::SafePointer::sectionKeyFor
static SectionKey sectionKeyFor(const SafePointable *obj)
Definition: SafePointer.cc:408
TPEF::TPEFSymbolSectionWriter::elementSize_
static const Word elementSize_
The fixed size address space element.
Definition: TPEFSymbolSectionWriter.hh:75
TPEF::FileOffset
Word FileOffset
Type for storing absolute file offsets.
Definition: TPEFBaseType.hh:52
TPEF::SymbolElement::STT_CODE
@ STT_CODE
Associated with executable code.
Definition: SymbolElement.hh:69
TPEF::TPEFSymbolSectionWriter::writeValueAndSize
void writeValueAndSize(BinaryStream &stream, const SymbolElement *elem) const
Definition: TPEFSymbolSectionWriter.cc:167
TPEF::SectionSizeReplacer::setSize
static void setSize(const SafePointable *obj, Word size)
Definition: SectionSizeReplacer.cc:100
BYTE_BITWIDTH
const Byte BYTE_BITWIDTH
Definition: BaseType.hh:136
TPEF::SymbolElement::STT_DATA
@ STT_DATA
Associated with data object.
Definition: SymbolElement.hh:68
TPEF::SymbolElement::STT_NOTYPE
@ STT_NOTYPE
Type is not defined.
Definition: SymbolElement.hh:67
TPEF::SymbolElement::STB_LOCAL
@ STB_LOCAL
Not visible outside the object file that contains it's definition.
Definition: SymbolElement.hh:56
TPEF::TPEFHeaders::STO_ABS
@ STO_ABS
Section is absolute, not relocating.
Definition: TPEFHeaders.hh:97
TPEF::TPEFSectionWriter::TPEFSectionWriter
TPEFSectionWriter()
Definition: TPEFSectionWriter.cc:63