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::Image> 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)
381 void DumpContents(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
402 std::vector<std::unique_ptr<Unit>> symbols;
412 void Dump(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
420 std::shared_ptr<Linker::Image> image;
431 void Dump(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
439 uint32_t maximum_level = 2;
448 uint32_t symbol_hunk;
449 uint32_t symbol_offset;
452 std::vector<OverlaySymbol> overlay_data_table;
455 :
Block(HUNK_OVERLAY)
463 void Dump(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
472 std::unique_ptr<Module> hunks;
483 void Dump(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
494 uint16_t string_offset = 0;
495 uint16_t symbol_offset = 0;
505 uint16_t string_offset = 0;
506 uint16_t hunk_size = 0;
507 uint16_t hunk_type = 0;
508 std::vector<uint16_t> references;
509 std::vector<Definition> definitions;
513 offset_t FileSize()
const;
519 int16_t string_offset = 0;
520 uint16_t first_hunk_offset = 0;
521 std::vector<HunkEntry> hunks;
525 offset_t FileSize()
const;
528 std::vector<std::string> strings;
529 std::vector<ProgramUnit> units;
536 offset_t StringTableSize()
const;
542 void Dump(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
550 std::vector<std::shared_ptr<Block>>
blocks;
552 enum hunk_type : uint32_t
555 Invalid = uint32_t(-1),
562 hunk_type type = Undefined;
566 LoadBlock::flag_type
flags = LoadBlock::LoadPublic;
568 std::shared_ptr<Linker::Image>
image;
579 Hunk(hunk_type type, std::string name =
"image",
unsigned flags = LoadBlock::LoadAny)
584 Hunk(hunk_type type, std::shared_ptr<Linker::Segment> segment,
unsigned flags = LoadBlock::LoadAny)
585 : type(hunk_type(type)), flags(LoadBlock::flag_type(flags)),
image(segment)
589 std::map<uint32_t, std::set<Relocation>> relocations;
627 bool IsExecutable()
const;
628 offset_t ImageSize()
const;
629 void ReadFile(
Linker::Reader& rd, std::shared_ptr<Block>& next_block, offset_t end);
631 void Dump(
Dumper::Dumper& dump, offset_t current_offset,
unsigned index)
const;
643 bool IsExecutable()
const;
653 static std::string ReadString(uint32_t longword_count,
Linker::Reader& rd);
654 static std::string ReadString(
Linker::Reader& rd, uint32_t& longword_count);
656 static void WriteStringContents(
Linker::Writer& wr, std::string name);
658 static offset_t MeasureString(std::string name);
669 InitializeFields(system);
678 cpu_type cpu = CPU_PPC;
700 std::map<std::shared_ptr<Linker::Segment>,
size_t> segment_index;
702 unsigned FormatAdditionalSectionFlags(std::string section_name)
const override;
716 std::shared_ptr<Linker::OptionCollector>
GetOptions()
override;
718 void SetOptions(std::map<std::string, std::string>& options)
override;
720 void AddHunk(
const Hunk& hunk);
722 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:586
A brief record, such as a relocation or imported library.
Definition dumper.h:506
A record that represents a region within the file.
Definition dumper.h:485
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:308
Documents and handles command line options.
Definition options.h:196
A helper class, encapsulating functionality needed to import binary data.
Definition reader.h:16
@ CustomFlag
Other flags.
Definition section.h:100
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