5#include "../dumper/dumper.h"
6#include "../linker/module.h"
7#include "../linker/section.h"
8#include "../linker/segment.h"
9#include "../linker/segment_manager.h"
10#include "../linker/writer.h"
45 :
size(
size), type(type), offset(offset)
48 bool operator <(
const Relocation& other)
const;
116 virtual ~Block() =
default;
131 virtual void Dump(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const;
132 void AddCommonFields(
Dumper::Region& region,
unsigned index)
const;
133 virtual void AddExtraFields(
Dumper::Region& region,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const;
143 :
Block(type), name(name)
156 std::vector<std::string> library_names;
157 uint32_t table_size = 0;
158 uint32_t first_hunk = 0;
159 std::vector<uint32_t> hunk_sizes;
170 void Dump(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
171 void AddExtraFields(
Dumper::Region& region,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
180 FlagMask = 0xE0000000,
181 BitAdvisory = 0x20000000,
182 BitChipMem = 0x40000000,
183 BitFastMem = 0x80000000,
184 BitAdditional = 0xC0000000,
189 LoadAny = 0x00000000,
190 LoadPublic = 0x00000001,
191 LoadChipMem = 0x00000002,
192 LoadFastMem = 0x00000004,
193 LoadLocalMem = 0x00000008,
194 Load24BitDma = 0x00000010,
195 LoadClear = 0x00010000,
198 bool loaded_with_additional_flags =
false;
218 void AddExtraFields(
Dumper::Region& region,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
233 std::shared_ptr<Linker::Image> image;
240 void Dump(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
243 uint32_t
GetSize()
const override;
262 void AddExtraFields(
Dumper::Region& region,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
265 uint32_t
GetSize()
const override;
276 std::vector<uint32_t> offsets;
278 std::vector<RelocationData> relocations;
288 size_t GetRelocationSize()
const;
296 void Dump(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
329 Unit(symbol_type type, std::string name)
330 : type(type), name(name)
336 virtual ~Unit() =
default;
343 virtual void DumpContents(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const;
352 Definition(symbol_type type, std::string name, uint32_t value = 0)
353 :
Unit(type, name), value(value)
368 std::vector<uint32_t> references;
370 References(symbol_type type, std::string name)
380 void DumpContents(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
401 std::vector<std::unique_ptr<Unit>> symbols;
411 void Dump(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
419 std::shared_ptr<Linker::Image> image;
430 void Dump(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
438 uint32_t maximum_level = 2;
447 uint32_t symbol_hunk;
448 uint32_t symbol_offset;
451 std::vector<OverlaySymbol> overlay_data_table;
454 :
Block(HUNK_OVERLAY)
462 void Dump(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
471 std::unique_ptr<Module> hunks;
482 void Dump(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
493 uint16_t string_offset = 0;
494 uint16_t symbol_offset = 0;
504 uint16_t string_offset = 0;
505 uint16_t hunk_size = 0;
506 uint16_t hunk_type = 0;
507 std::vector<uint16_t> references;
508 std::vector<Definition> definitions;
512 offset_t FileSize()
const;
518 int16_t string_offset = 0;
519 uint16_t first_hunk_offset = 0;
520 std::vector<HunkEntry> hunks;
524 offset_t FileSize()
const;
527 std::vector<std::string> strings;
528 std::vector<ProgramUnit> units;
535 offset_t StringTableSize()
const;
541 void Dump(
Dumper::Dumper& dump,
const Module& module,
const Hunk * hunk,
unsigned index, offset_t current_offset)
const override;
549 std::vector<std::shared_ptr<Block>>
blocks;
551 enum hunk_type : uint32_t
554 Invalid = uint32_t(-1),
561 hunk_type type = Undefined;
565 LoadBlock::flag_type
flags = LoadBlock::LoadPublic;
567 std::shared_ptr<Linker::Image>
image;
578 Hunk(hunk_type type, std::string name =
"image",
unsigned flags = LoadBlock::LoadAny)
583 Hunk(hunk_type type, std::shared_ptr<Linker::Segment> segment,
unsigned flags = LoadBlock::LoadAny)
584 : type(hunk_type(type)), flags(LoadBlock::flag_type(flags)),
image(segment)
588 std::map<uint32_t, std::set<Relocation>> relocations;
626 bool IsExecutable()
const;
627 offset_t ImageSize()
const;
628 void ReadFile(
Linker::Reader& rd, std::shared_ptr<Block>& next_block, offset_t end);
630 void Dump(
Dumper::Dumper& dump, offset_t current_offset,
unsigned index)
const;
642 bool IsExecutable()
const;
652 static std::string ReadString(uint32_t longword_count,
Linker::Reader& rd);
653 static std::string ReadString(
Linker::Reader& rd, uint32_t& longword_count);
655 static void WriteStringContents(
Linker::Writer& wr, std::string name);
657 static offset_t MeasureString(std::string name);
666 cpu_type cpu = CPU_PPC;
669 std::map<std::shared_ptr<Linker::Segment>,
size_t> segment_index;
671 unsigned FormatAdditionalSectionFlags(std::string section_name)
const override;
685 void SetOptions(std::map<std::string, std::string>& options)
override;
687 void AddHunk(
const Hunk& hunk);
689 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:138
void Write(Linker::Writer &wr) const override
Writes the entire block into a file.
Definition hunk.cc:150
void Read(Linker::Reader &rd) override
Reads the rest of the block after the type word.
Definition hunk.cc:145
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:156
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
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