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 void Dump(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const;
133 void AddCommonFields(
Dumper::Region& region,
unsigned index)
const;
134 virtual void AddExtraFields(
Dumper::Region& region,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const;
144 :
Block(type), name(name)
157 std::vector<std::string> library_names;
158 uint32_t table_size = 0;
159 uint32_t first_hunk = 0;
160 std::vector<uint32_t> hunk_sizes;
171 void Dump(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
172 void AddExtraFields(
Dumper::Region& region,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
181 FlagMask = 0xE0000000,
182 BitAdvisory = 0x20000000,
183 BitChipMem = 0x40000000,
184 BitFastMem = 0x80000000,
185 BitAdditional = 0xC0000000,
190 LoadAny = 0x00000000,
191 LoadPublic = 0x00000001,
192 LoadChipMem = 0x00000002,
193 LoadFastMem = 0x00000004,
194 LoadLocalMem = 0x00000008,
195 Load24BitDma = 0x00000010,
196 LoadClear = 0x00010000,
199 bool loaded_with_additional_flags =
false;
219 void AddExtraFields(
Dumper::Region& region,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
234 std::shared_ptr<Linker::Contents> image;
241 void Dump(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
244 uint32_t
GetSize()
const override;
263 void AddExtraFields(
Dumper::Region& region,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
266 uint32_t
GetSize()
const override;
277 std::vector<uint32_t> offsets;
279 std::vector<RelocationData> relocations;
289 size_t GetRelocationSize()
const;
297 void Dump(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
330 Unit(symbol_type type, std::string name)
331 : type(type), name(name)
337 virtual ~Unit() =
default;
344 virtual void DumpContents(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const;
353 Definition(symbol_type type, std::string name, uint32_t value = 0)
354 :
Unit(type, name), value(value)
369 std::vector<uint32_t> references;
371 References(symbol_type type, std::string name)
376 bool ContainsRelocations()
const;
378 size_t GetRelocationSize()
const;
387 void DumpContents(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
408 std::vector<std::unique_ptr<Unit>> symbols;
418 void Dump(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
426 std::shared_ptr<Linker::Contents> image;
437 void Dump(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
445 uint32_t maximum_level = 2;
454 uint32_t symbol_hunk;
455 uint32_t symbol_offset;
458 std::vector<OverlaySymbol> overlay_data_table;
461 :
Block(HUNK_OVERLAY)
469 void Dump(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
478 std::unique_ptr<Module> hunks;
489 void Dump(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
500 uint16_t string_offset = 0;
501 uint16_t symbol_offset = 0;
511 uint16_t string_offset = 0;
512 uint16_t hunk_size = 0;
513 uint16_t hunk_type = 0;
514 std::vector<uint16_t> references;
515 std::vector<Definition> definitions;
519 offset_t FileSize()
const;
525 int16_t string_offset = 0;
526 uint16_t first_hunk_offset = 0;
527 std::vector<HunkEntry> hunks;
531 offset_t FileSize()
const;
534 std::vector<std::string> strings;
535 std::vector<ProgramUnit> units;
542 offset_t StringTableSize()
const;
548 void Dump(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
556 std::vector<std::shared_ptr<Block>>
blocks;
558 enum hunk_type : uint32_t
561 Invalid = uint32_t(-1),
568 hunk_type type = Undefined;
572 LoadBlock::flag_type
flags = LoadBlock::LoadPublic;
574 std::shared_ptr<Linker::Contents>
image;
585 Hunk(hunk_type type, std::string name =
"image",
unsigned flags = LoadBlock::LoadAny)
590 Hunk(hunk_type type, std::shared_ptr<Linker::Segment> segment,
unsigned flags = LoadBlock::LoadAny)
591 : type(hunk_type(type)), flags(LoadBlock::flag_type(flags)),
image(segment)
639 bool IsExecutable()
const;
640 offset_t ImageSize()
const;
641 void ReadFile(
Linker::Reader& rd, std::shared_ptr<Block>& next_block, offset_t end);
643 void Dump(
Dumper::Dumper& dump, offset_t current_offset,
unsigned index)
const;
655 bool IsExecutable()
const;
665 static std::string ReadString(uint32_t longword_count,
Linker::Reader& rd);
666 static std::string ReadString(
Linker::Reader& rd, uint32_t& longword_count);
668 static void WriteStringContents(
Linker::Writer& wr, std::string name);
670 static offset_t MeasureString(std::string name);
681 InitializeFields(system);
690 cpu_type cpu = CPU_PPC;
712 std::map<std::shared_ptr<Linker::Segment>,
size_t> segment_index;
714 unsigned FormatAdditionalSectionFlags(std::string section_name)
const override;
728 std::shared_ptr<Linker::OptionCollector>
GetOptions()
override;
730 void SetOptions(std::map<std::string, std::string>& options)
override;
732 void AddHunk(
const Hunk& hunk);
734 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:139
void Write(Linker::Writer &wr) const override
Writes the entire block into a file.
Definition hunk.cc:163
void Read(Linker::Reader &rd) override
Reads the rest of the block after the type word.
Definition hunk.cc:158
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:169
An abstract interface that separates structure and presentation of the data inside a file.
Definition dumper.h:773
A brief record, such as a relocation or imported library.
Definition dumper.h:687
A record that represents a region within the file.
Definition dumper.h:666
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