5#include "../dumper/dumper.h"
6#include "../linker/module.h"
7#include "../linker/options.h"
8#include "../linker/section.h"
9#include "../linker/segment.h"
10#include "../linker/segment_manager.h"
11#include "../linker/writer.h"
46 :
size(
size), type(type), offset(offset)
49 bool operator <(
const Relocation& other)
const;
117 virtual ~Block() =
default;
125 static std::shared_ptr<Block>
ReadBlock(
const std::shared_ptr<Linker::Reader>& rd,
bool is_executable =
false);
127 virtual void Read(
const std::shared_ptr<Linker::Reader>& rd);
129 virtual void Write(
const std::shared_ptr<Linker::Writer>& wr)
const;
132 virtual int GetDisplayOptions()
const;
133 virtual void Dump(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const;
134 void AddCommonFields(
Dumper::Region& region,
unsigned index)
const;
135 virtual void AddExtraFields(
Dumper::Region& region,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const;
145 :
Block(type), name(name)
149 void Read(
const std::shared_ptr<Linker::Reader>& rd)
override;
150 void Write(
const std::shared_ptr<Linker::Writer>& wr)
const override;
158 std::vector<std::string> library_names;
159 uint32_t table_size = 0;
160 uint32_t first_hunk = 0;
161 std::vector<uint32_t> hunk_sizes;
168 void Read(
const std::shared_ptr<Linker::Reader>& rd)
override;
169 void Write(
const std::shared_ptr<Linker::Writer>& wr)
const override;
173 void Dump(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
174 void AddExtraFields(
Dumper::Region& region,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
183 FlagMask = 0xE0000000,
184 BitAdvisory = 0x20000000,
185 BitChipMem = 0x40000000,
186 BitFastMem = 0x80000000,
187 BitAdditional = 0xC0000000,
192 LoadAny = 0x00000000,
193 LoadPublic = 0x00000001,
194 LoadChipMem = 0x00000002,
195 LoadFastMem = 0x00000004,
196 LoadLocalMem = 0x00000008,
197 Load24BitDma = 0x00000010,
198 LoadClear = 0x00010000,
201 bool loaded_with_additional_flags =
false;
217 void Read(
const std::shared_ptr<Linker::Reader>& rd)
override;
218 void Write(
const std::shared_ptr<Linker::Writer>& wr)
const override;
221 void AddExtraFields(
Dumper::Region& region,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
227 virtual void ReadBody(
const std::shared_ptr<Linker::Reader>& rd, uint32_t longword_count);
229 virtual void WriteBody(
const std::shared_ptr<Linker::Writer>& wr)
const;
236 std::shared_ptr<Linker::Contents> image;
243 int GetDisplayOptions()
const override;
244 void Dump(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
247 uint32_t
GetSize()
const override;
248 void ReadBody(
const std::shared_ptr<Linker::Reader>& rd, uint32_t longword_count)
override;
249 void WriteBody(
const std::shared_ptr<Linker::Writer>& wr)
const override;
266 void AddExtraFields(
Dumper::Region& region,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
269 uint32_t
GetSize()
const override;
270 void ReadBody(
const std::shared_ptr<Linker::Reader>& rd, uint32_t longword_count)
override;
280 std::vector<uint32_t> offsets;
282 std::vector<RelocationData> relocations;
292 size_t GetRelocationSize()
const;
296 void Read(
const std::shared_ptr<Linker::Reader>& rd)
override;
297 void Write(
const std::shared_ptr<Linker::Writer>& wr)
const override;
300 int GetDisplayOptions()
const override;
301 void Dump(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
334 Unit(symbol_type type, std::string name)
335 : type(type), name(name)
339 static std::unique_ptr<Unit> ReadData(
const std::shared_ptr<Linker::Reader>& rd);
341 virtual ~Unit() =
default;
343 virtual void Read(
const std::shared_ptr<Linker::Reader>& rd);
345 virtual void Write(
const std::shared_ptr<Linker::Writer>& wr)
const;
348 virtual void DumpContents(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const;
357 Definition(symbol_type type, std::string name, uint32_t value = 0)
358 :
Unit(type, name), value(value)
362 void Read(
const std::shared_ptr<Linker::Reader>& rd)
override;
364 void Write(
const std::shared_ptr<Linker::Writer>& wr)
const override;
373 std::vector<uint32_t> references;
375 References(symbol_type type, std::string name)
380 bool ContainsRelocations()
const;
382 size_t GetRelocationSize()
const;
386 void Read(
const std::shared_ptr<Linker::Reader>& rd)
override;
388 void Write(
const std::shared_ptr<Linker::Writer>& wr)
const override;
391 void DumpContents(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
404 void Read(
const std::shared_ptr<Linker::Reader>& rd)
override;
406 void Write(
const std::shared_ptr<Linker::Writer>& wr)
const override;
412 std::vector<std::unique_ptr<Unit>> symbols;
419 void Read(
const std::shared_ptr<Linker::Reader>& rd)
override;
420 void Write(
const std::shared_ptr<Linker::Writer>& wr)
const override;
422 int GetDisplayOptions()
const override;
423 void Dump(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
431 std::shared_ptr<Linker::Contents> image;
438 void Read(
const std::shared_ptr<Linker::Reader>& rd)
override;
439 void Write(
const std::shared_ptr<Linker::Writer>& wr)
const override;
442 int GetDisplayOptions()
const override;
443 void Dump(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
451 uint32_t maximum_level = 2;
460 uint32_t symbol_hunk;
461 uint32_t symbol_offset;
464 std::vector<OverlaySymbol> overlay_data_table;
467 :
Block(HUNK_OVERLAY)
471 void Read(
const std::shared_ptr<Linker::Reader>& rd)
override;
472 void Write(
const std::shared_ptr<Linker::Writer>& wr)
const override;
475 int GetDisplayOptions()
const override;
476 void Dump(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
485 std::unique_ptr<Module> hunks;
492 void Read(
const std::shared_ptr<Linker::Reader>& rd)
override;
493 void Write(
const std::shared_ptr<Linker::Writer>& wr)
const override;
496 int GetDisplayOptions()
const override;
497 void Dump(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
508 uint16_t string_offset = 0;
509 uint16_t symbol_offset = 0;
512 static Definition Read(
const std::shared_ptr<Linker::Reader>& rd);
513 void Write(
const std::shared_ptr<Linker::Writer>& wr)
const;
519 uint16_t string_offset = 0;
520 uint16_t hunk_size = 0;
521 uint16_t hunk_type = 0;
522 std::vector<uint16_t> references;
523 std::vector<Definition> definitions;
525 static HunkEntry Read(
const std::shared_ptr<Linker::Reader>& rd);
526 void Write(
const std::shared_ptr<Linker::Writer>& wr)
const;
527 offset_t FileSize()
const;
533 int16_t string_offset = 0;
534 uint16_t first_hunk_offset = 0;
535 std::vector<HunkEntry> hunks;
537 static ProgramUnit Read(
const std::shared_ptr<Linker::Reader>& rd);
538 void Write(
const std::shared_ptr<Linker::Writer>& wr)
const;
539 offset_t FileSize()
const;
542 std::vector<std::string> strings;
543 std::vector<ProgramUnit> units;
550 offset_t StringTableSize()
const;
552 void Read(
const std::shared_ptr<Linker::Reader>& rd)
override;
553 void Write(
const std::shared_ptr<Linker::Writer>& wr)
const override;
556 int GetDisplayOptions()
const override;
557 void Dump(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
565 std::vector<std::shared_ptr<Block>>
blocks;
567 enum hunk_type : uint32_t
570 Invalid = uint32_t(-1),
577 hunk_type type = Undefined;
581 LoadBlock::flag_type
flags = LoadBlock::LoadPublic;
583 std::shared_ptr<Linker::Contents>
image;
594 Hunk(hunk_type type, std::string name =
"image",
unsigned flags = LoadBlock::LoadAny)
599 Hunk(hunk_type type, std::shared_ptr<Linker::Segment> segment,
unsigned flags = LoadBlock::LoadAny)
600 : type(hunk_type(type)), flags(LoadBlock::flag_type(flags)),
image(segment)
648 bool IsExecutable()
const;
649 offset_t ImageSize()
const;
650 void ReadFile(
const std::shared_ptr<Linker::Reader>& rd, std::shared_ptr<Block>& next_block, offset_t end);
651 void WriteFile(
const std::shared_ptr<Linker::Writer>& wr)
const;
652 void Dump(
Dumper::Dumper& dump, offset_t current_offset,
unsigned index)
const;
664 bool IsExecutable()
const;
668 void ReadFile(
const std::shared_ptr<Linker::Reader>& rd)
override;
671 offset_t
WriteFile(
const std::shared_ptr<Linker::Writer>& wr)
const override;
674 static std::string ReadString(uint32_t longword_count,
const std::shared_ptr<Linker::Reader>& rd);
675 static std::string ReadString(
const std::shared_ptr<Linker::Reader>& rd, uint32_t& longword_count);
676 static std::string ReadString(
const std::shared_ptr<Linker::Reader>& rd);
677 static void WriteStringContents(
const std::shared_ptr<Linker::Writer>& wr, std::string name);
678 static void WriteString(
const std::shared_ptr<Linker::Writer>& wr, std::string name);
679 static offset_t MeasureString(std::string name);
690 InitializeFields(system);
699 cpu_type cpu = CPU_PPC;
721 std::map<std::shared_ptr<Linker::Segment>,
size_t> segment_index;
723 unsigned FormatAdditionalSectionFlags(std::string section_name)
const override;
737 std::shared_ptr<Linker::OptionCollector>
GetOptions()
override;
739 void SetOptions(std::map<std::string, std::string>& options)
override;
741 void AddHunk(
const Hunk& hunk);
743 void OnNewSegment(std::shared_ptr<Linker::Segment> segment)
override;
Represents the first block inside of an object file or a hunk. This class is used for HUNK_UNIT and H...
Definition hunk.h:140
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:174
void Read(const std::shared_ptr< Linker::Reader > &rd) override
Reads the rest of the block after the type word.
Definition hunk.cc:163
void Write(const std::shared_ptr< Linker::Writer > &wr) const override
Writes the entire block into a file.
Definition hunk.cc:168
An abstract interface that separates structure and presentation of the data inside a file.
Definition dumper.h:1009
A brief record, such as a relocation or imported library.
Definition dumper.h:923
A record that represents a region within the file.
Definition dumper.h:902
Encodes an object module file as a collection of sections, symbols and relocations.
Definition module.h:24
Helper class that contains the options interpreted by the format.
Definition options.h:499
Documents and handles command line options.
Definition options.h:306
@ CustomFlag
Other flags.
Definition section.h:104
A helper class to collect sections into segments.
Definition segment_manager.h:32