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;
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)
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;
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;
221 void AddExtraFields(
Dumper::Region& region,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
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;
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;
280 std::vector<uint32_t> offsets;
282 std::vector<RelocationData> relocations;
292 size_t GetRelocationSize()
const;
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)
341 virtual ~Unit() =
default;
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)
373 std::vector<uint32_t> references;
375 References(symbol_type type, std::string name)
380 bool ContainsRelocations()
const;
382 size_t GetRelocationSize()
const;
391 void DumpContents(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
412 std::vector<std::unique_ptr<Unit>> symbols;
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;
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)
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;
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;
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;
527 offset_t FileSize()
const;
533 int16_t string_offset = 0;
534 uint16_t first_hunk_offset = 0;
535 std::vector<HunkEntry> hunks;
539 offset_t FileSize()
const;
542 std::vector<std::string> strings;
543 std::vector<ProgramUnit> units;
550 offset_t StringTableSize()
const;
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(
Linker::Reader& rd, std::shared_ptr<Block>& next_block, offset_t end);
652 void Dump(
Dumper::Dumper& dump, offset_t current_offset,
unsigned index)
const;
664 bool IsExecutable()
const;
674 static std::string ReadString(uint32_t longword_count,
Linker::Reader& rd);
675 static std::string ReadString(
Linker::Reader& rd, uint32_t& longword_count);
677 static void WriteStringContents(
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
void Write(Linker::Writer &wr) const override
Writes the entire block into a file.
Definition hunk.cc:168
void Read(Linker::Reader &rd) override
Reads the rest of the block after the type word.
Definition hunk.cc:163
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:174
An abstract interface that separates structure and presentation of the data inside a file.
Definition dumper.h:828
A brief record, such as a relocation or imported library.
Definition dumper.h:742
A record that represents a region within the file.
Definition dumper.h:721
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:474
Documents and handles command line options.
Definition options.h:306
A helper class, encapsulating functionality needed to import binary data.
Definition reader.h:20
@ CustomFlag
Other flags.
Definition section.h:104
A helper class to collect sections into segments.
Definition segment_manager.h:32
A helper class, encapsulating functionality needed to export binary data.
Definition writer.h:15