RetroLinker
Linker for several 8-bit, 16-bit and 32-bit formats
Loading...
Searching...
No Matches
hunk.h
1#ifndef HUNK_H
2#define HUNK_H
3
4#include "../common.h"
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"
12
13namespace Amiga
14{
20 class HunkFormat : public virtual Linker::SegmentManager
21 {
22 public:
23 /* * * General members * * */
24
25 class Hunk;
26 class Module;
27
29 {
31 size_t size;
43 relocation_type type;
44 uint32_t offset;
45 Relocation(size_t size, relocation_type type, uint32_t offset)
46 : size(size), type(type), offset(offset)
47 {
48 }
49 bool operator <(const Relocation& other) const;
50 };
51
55 class Block
56 {
57 public:
59 {
61 HUNK_UNIT = 0x3E7,
63 HUNK_NAME = 0x3E8,
65 HUNK_CODE = 0x3E9,
67 HUNK_DATA = 0x3EA,
69 HUNK_BSS = 0x3EB,
77 HUNK_EXT = 0x3EF,
79 HUNK_SYMBOL = 0x3F0,
81 HUNK_DEBUG = 0x3F1,
83 HUNK_END = 0x3F2,
85 HUNK_HEADER = 0x3F3,
86 HUNK_OVERLAY = 0x3F5,
87 HUNK_BREAK = 0x3F6,
93 HUNK_DRELOC8 = 0x3F9,
94 HUNK_LIB = 0x3FA,
95 HUNK_INDEX = 0x3FB,
106
109 };
110 block_type type;
112 bool is_executable = false;
113 Block(block_type type, bool is_executable = false)
114 : type(type), is_executable(is_executable)
115 {
116 }
117 virtual ~Block() = default;
125 static std::shared_ptr<Block> ReadBlock(Linker::Reader& rd, bool is_executable = false);
127 virtual void Read(Linker::Reader& rd);
129 virtual void Write(Linker::Writer& wr) const;
131 virtual offset_t FileSize() const;
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;
135 };
136
138 class TextBlock : public Block
139 {
140 public:
141 std::string name;
142
143 TextBlock(block_type type, std::string name = "")
144 : Block(type), name(name)
145 {
146 }
147
148 void Read(Linker::Reader& rd) override;
149 void Write(Linker::Writer& wr) const override;
150 offset_t FileSize() const override;
151 };
152
154 class HeaderBlock : public Block
155 {
156 public:
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;
161
164 {
165 }
166
167 void Read(Linker::Reader& rd) override;
168 void Write(Linker::Writer& wr) const override;
169 offset_t FileSize() const override;
170
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;
173 };
174
176 class RelocatableBlock : public Block
177 {
178 public:
179 enum
180 {
181 FlagMask = 0xE0000000,
182 BitAdvisory = 0x20000000,
183 BitChipMem = 0x40000000,
184 BitFastMem = 0x80000000,
185 BitAdditional = 0xC0000000,
186 };
187
188 enum flag_type
189 {
190 LoadAny = 0x00000000,
191 LoadPublic = 0x00000001, /* default, not stored */
192 LoadChipMem = 0x00000002,
193 LoadFastMem = 0x00000004,
194 LoadLocalMem = 0x00000008,
195 Load24BitDma = 0x00000010,
196 LoadClear = 0x00010000,
197 };
198 flag_type flags;
199 bool loaded_with_additional_flags = false;
200
201 RelocatableBlock(block_type type, uint32_t flags = LoadAny)
202 : Block(type), flags(flag_type(flags | LoadPublic))
203 {
204 }
205
207 uint32_t GetSizeField() const;
208
210 bool RequiresAdditionalFlags() const;
211
213 uint32_t GetAdditionalFlags() const;
214
215 void Read(Linker::Reader& rd) override;
216 void Write(Linker::Writer& wr) const override;
217 offset_t FileSize() const override;
218
219 void AddExtraFields(Dumper::Region& region, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
220
221 protected:
223 virtual uint32_t GetSize() const = 0;
225 virtual void ReadBody(Linker::Reader& rd, uint32_t longword_count);
227 virtual void WriteBody(Linker::Writer& wr) const;
228 };
229
232 {
233 public:
234 std::shared_ptr<Linker::Image> image;
235
236 LoadBlock(block_type type, uint32_t flags = LoadAny)
237 : RelocatableBlock(type, flags)
238 {
239 }
240
241 void Dump(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
242
243 protected:
244 uint32_t GetSize() const override;
245 void ReadBody(Linker::Reader& rd, uint32_t longword_count) override;
246 void WriteBody(Linker::Writer& wr) const override;
247 };
248
251 {
252 public:
254 uint32_t size;
255
256 BssBlock(uint32_t size = 0, uint32_t flags = LoadAny)
258 {
259 }
260
261 offset_t FileSize() const override;
262
263 void AddExtraFields(Dumper::Region& region, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
264
265 protected:
266 uint32_t GetSize() const override;
267 void ReadBody(Linker::Reader& rd, uint32_t longword_count) override;
268 };
269
271 class RelocationBlock : public Block
272 {
273 public:
275 {
276 uint32_t hunk;
277 std::vector<uint32_t> offsets;
278 };
279 std::vector<RelocationData> relocations;
280
281 RelocationBlock(block_type type, bool is_executable = false)
282 : Block(type, is_executable)
283 {
284 }
285
287 bool IsShortRelocationBlock() const;
288
289 size_t GetRelocationSize() const;
290
291 Relocation::relocation_type GetRelocationType() const;
292
293 void Read(Linker::Reader& rd) override;
294 void Write(Linker::Writer& wr) const override;
295 offset_t FileSize() const override;
296
297 void Dump(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
298 };
299
301 class SymbolBlock : public Block
302 {
303 public:
304 class Unit
305 {
306 public:
307 enum symbol_type
308 {
309 EXT_SYMB = 0,
310 EXT_DEF = 1,
311 EXT_ABS = 2,
312 EXT_RES = 3,
313
314 EXT_ABSREF32 = 129,
315 EXT_COMMON = 130,
316 EXT_RELREF16 = 131,
317 EXT_RELREF8 = 132,
318 EXT_DREF32 = 133,
319 EXT_DREF16 = 134,
320 EXT_DREF8 = 135,
321 EXT_RELREF32 = 136,
322 EXT_RELCOMMON = 137,
323 EXT_ABSREF16 = 138,
324 EXT_ABSREF8 = 139,
325 EXT_RELREF26 = 229,
326 };
327 symbol_type type;
328 std::string name;
329
330 Unit(symbol_type type, std::string name)
331 : type(type), name(name)
332 {
333 }
334
335 static std::unique_ptr<Unit> ReadData(Linker::Reader& rd);
336
337 virtual ~Unit() = default;
339 virtual void Read(Linker::Reader& rd);
341 virtual void Write(Linker::Writer& wr) const;
343 virtual offset_t FileSize() const;
344 virtual void DumpContents(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const;
345 virtual void AddExtraFields(Dumper::Dumper& dump, Dumper::Entry& entry, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const;
346 };
347
348 class Definition : public Unit
349 {
350 public:
351 uint32_t value;
352
353 Definition(symbol_type type, std::string name, uint32_t value = 0)
354 : Unit(type, name), value(value)
355 {
356 }
357
358 void Read(Linker::Reader& rd) override;
360 void Write(Linker::Writer& wr) const override;
362 offset_t FileSize() const override;
363 void AddExtraFields(Dumper::Dumper& dump, Dumper::Entry& entry, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
364 };
365
366 class References : public Unit
367 {
368 public:
369 std::vector<uint32_t> references;
370
371 References(symbol_type type, std::string name)
372 : Unit(type, name)
373 {
374 }
375
376 void Read(Linker::Reader& rd) override;
378 void Write(Linker::Writer& wr) const override;
380 offset_t FileSize() const override;
381 void DumpContents(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
382 };
383
385 {
386 public:
387 uint32_t size;
388
389 CommonReferences(symbol_type type, std::string name, uint32_t size = 0)
390 : References(type, name), size(size)
391 {
392 }
393
394 void Read(Linker::Reader& rd) override;
396 void Write(Linker::Writer& wr) const override;
398 offset_t FileSize() const override;
399 void AddExtraFields(Dumper::Dumper& dump, Dumper::Entry& entry, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
400 };
401
402 std::vector<std::unique_ptr<Unit>> symbols;
403
405 : Block(type)
406 {
407 }
408
409 void Read(Linker::Reader& rd) override;
410 void Write(Linker::Writer& wr) const override;
411 offset_t FileSize() const override;
412 void Dump(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
413 };
414
416 class DebugBlock : public Block
417 {
418 public:
419 // TODO: untested
420 std::shared_ptr<Linker::Image> image;
421
422 DebugBlock()
424 {
425 }
426
427 void Read(Linker::Reader& rd) override;
428 void Write(Linker::Writer& wr) const override;
429 offset_t FileSize() const override;
430
431 void Dump(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
432 };
433
435 class OverlayBlock : public Block
436 {
437 public:
438 // TODO: untested
439 uint32_t maximum_level = 2;
440
442 {
443 uint32_t offset;
444 uint32_t res1, res2;
445 uint32_t level;
446 uint32_t ordinate;
447 uint32_t first_hunk;
448 uint32_t symbol_hunk;
449 uint32_t symbol_offset;
450 };
451
452 std::vector<OverlaySymbol> overlay_data_table;
453
455 : Block(HUNK_OVERLAY)
456 {
457 }
458
459 void Read(Linker::Reader& rd) override;
460 void Write(Linker::Writer& wr) const override;
461 offset_t FileSize() const override;
462
463 void Dump(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
464 };
465
467 class LibraryBlock : public Block
468 {
469 public:
470 // TODO: untested
471
472 std::unique_ptr<Module> hunks;
473
475 : Block(HUNK_LIB)
476 {
477 }
478
479 void Read(Linker::Reader& rd) override;
480 void Write(Linker::Writer& wr) const override;
481 offset_t FileSize() const override;
482
483 void Dump(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
484 };
485
486 class IndexBlock : public Block
487 {
488 public:
489 // TODO: untested
490
492 {
493 public:
494 uint16_t string_offset = 0;
495 uint16_t symbol_offset = 0;
496 uint16_t type = 0;
497
498 static Definition Read(Linker::Reader& rd);
499 void Write(Linker::Writer& wr) const;
500 };
501
503 {
504 public:
505 uint16_t string_offset = 0;
506 uint16_t hunk_size = 0; // in longwords
507 uint16_t hunk_type = 0;
508 std::vector<uint16_t> references;
509 std::vector<Definition> definitions;
510
511 static HunkEntry Read(Linker::Reader& rd);
512 void Write(Linker::Writer& wr) const;
513 offset_t FileSize() const;
514 };
515
517 {
518 public:
519 int16_t string_offset = 0;
520 uint16_t first_hunk_offset = 0; // in longwords
521 std::vector<HunkEntry> hunks;
522
523 static ProgramUnit Read(Linker::Reader& rd);
524 void Write(Linker::Writer& wr) const;
525 offset_t FileSize() const;
526 };
527
528 std::vector<std::string> strings;
529 std::vector<ProgramUnit> units;
530
531 IndexBlock()
532 : Block(HUNK_INDEX)
533 {
534 }
535
536 offset_t StringTableSize() const;
537
538 void Read(Linker::Reader& rd) override;
539 void Write(Linker::Writer& wr) const override;
540 offset_t FileSize() const override;
541
542 void Dump(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
543 };
544
546 class Hunk
547 {
548 public:
550 std::vector<std::shared_ptr<Block>> blocks;
551
552 enum hunk_type : uint32_t
553 {
554 Undefined = 0,
555 Invalid = uint32_t(-1),
556
557 Code = Block::HUNK_CODE,
558 CodePPC = Block::HUNK_PPC_CODE,
559 Data = Block::HUNK_DATA,
560 Bss = Block::HUNK_BSS,
561 };
562 hunk_type type = Undefined;
563
564 // TODO: implement advisory flag
565
566 LoadBlock::flag_type flags = LoadBlock::LoadPublic;
568 std::shared_ptr<Linker::Image> image;
570 offset_t image_size = 0;
571
572 std::string name;
573
574 explicit Hunk()
575 : type(Undefined), flags(LoadBlock::LoadAny), image(nullptr)
576 {
577 }
578
579 Hunk(hunk_type type, std::string name = "image", unsigned flags = LoadBlock::LoadAny)
580 : type(hunk_type(type)), flags(LoadBlock::flag_type(flags)), image(std::make_shared<Linker::Segment>(name))
581 {
582 }
583
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)
586 {
587 }
588
589 std::map<uint32_t, std::set<Relocation>> relocations;
590
592 void ProduceBlocks(HunkFormat& fmt, Module& module);
593
595 uint32_t GetMemorySize() const;
596
598 uint32_t GetFileSize() const;
599
601 uint32_t GetSizeField(HunkFormat& fmt, Module& module);
602
604 void AppendBlock(std::shared_ptr<Block> block);
605 };
606
612 class Module
613 {
614 public:
616 std::shared_ptr<Block> start_block;
618 std::vector<Hunk> hunks;
625 std::shared_ptr<Block> end_block;
626
627 bool IsExecutable() const;
628 offset_t ImageSize() const;
629 void ReadFile(Linker::Reader& rd, std::shared_ptr<Block>& next_block, offset_t end);
630 void WriteFile(Linker::Writer& wr) const;
631 void Dump(Dumper::Dumper& dump, offset_t current_offset, unsigned index) const;
632
634 offset_t GetHunkSizeInHeader(uint32_t index) const;
635 };
636
641 std::vector<Module> modules;
642
643 bool IsExecutable() const;
644
645 offset_t ImageSize() const override;
646
647 void ReadFile(Linker::Reader& rd) override;
648
650 offset_t WriteFile(Linker::Writer& wr) const override;
651 void Dump(Dumper::Dumper& dump) const override;
652
653 static std::string ReadString(uint32_t longword_count, Linker::Reader& rd);
654 static std::string ReadString(Linker::Reader& rd, uint32_t& longword_count);
655 static std::string ReadString(Linker::Reader& rd);
656 static void WriteStringContents(Linker::Writer& wr, std::string name);
657 static void WriteString(Linker::Writer& wr, std::string name);
658 static offset_t MeasureString(std::string name);
659
660 /* * * Writer members * * */
661
663 {
664 public:
665 Linker::Option<std::optional<std::string>> system{"system", "Target system version, determines generated hunk types, permitted options: v1, v37, v38, v39"};
666
668 {
669 InitializeFields(system);
670 }
671 };
672
673 enum cpu_type
674 {
675 CPU_M68K = Block::HUNK_CODE,
676 CPU_PPC = Block::HUNK_PPC_CODE,
677 };
678 cpu_type cpu = CPU_PPC;
679
681 {
682 V1,
686 V38, // TODO: not sure about name, so called because it is newer than V37 but older than V39
688 V39, // TODO: not yet implemented
689 };
690 system_version system = V1;
691
692 HunkFormat() = default;
693
695 : system(system)
696 {
697 }
698
699 /* @brief Convenience map to make it easier to look up the indices of segments */
700 std::map<std::shared_ptr<Linker::Segment>, size_t> segment_index;
701
702 unsigned FormatAdditionalSectionFlags(std::string section_name) const override;
703
715
716 std::shared_ptr<Linker::OptionCollector> GetOptions() override;
717
718 void SetOptions(std::map<std::string, std::string>& options) override;
719
720 void AddHunk(const Hunk& hunk);
721
722 void OnNewSegment(std::shared_ptr<Linker::Segment> segment) override;
723
724 std::unique_ptr<Script::List> GetScript(Linker::Module& module);
725
726 void Link(Linker::Module& module);
727
728 void ProcessModule(Linker::Module& module) override;
729
730 void CalculateValues() override;
731
732 void GenerateFile(std::string filename, Linker::Module& module) override;
733
735 std::string GetDefaultExtension(Linker::Module& module) const override;
736
737 };
738
739}
740
741#endif /* HUNK_H */
The smallest unit of a Hunk file, it starts with a type word. A HUNK_END or HUNK_BREAK block is repre...
Definition hunk.h:56
static std::shared_ptr< Block > ReadBlock(Linker::Reader &rd, bool is_executable=false)
Reads a single block from file.
Definition hunk.cc:18
virtual void Read(Linker::Reader &rd)
Reads the rest of the block after the type word.
Definition hunk.cc:88
virtual offset_t FileSize() const
Returns the size of the block as stored inside a file.
Definition hunk.cc:97
bool is_executable
Required because V37 executables define HUNK_DRELOC32 as HUNK_RELOC32SHORT, must block types ignore t...
Definition hunk.h:112
virtual void Write(Linker::Writer &wr) const
Writes the entire block into a file.
Definition hunk.cc:92
block_type
Definition hunk.h:59
@ HUNK_UNIT
First block inside an object file.
Definition hunk.h:61
@ HUNK_END
Block terminates a hunk.
Definition hunk.h:83
@ HUNK_DATA
First block of a data segment (hunk)
Definition hunk.h:67
@ HUNK_BSS
First block of a bss segment (hunk)
Definition hunk.h:69
@ HUNK_DRELOC8
Block containing 8-bit data section relative relocations.
Definition hunk.h:93
@ HUNK_CODE
First block of a code segment (hunk) containing Motorola 68k instructions.
Definition hunk.h:65
@ HUNK_RELRELOC8
Block containing 8-bit PC-relative relocations.
Definition hunk.h:75
@ HUNK_DRELOC32
Block containing 32-bit data section relative relocations.
Definition hunk.h:89
@ HUNK_HEADER
First block inside an executable or library file.
Definition hunk.h:85
@ HUNK_DEBUG
Debug information.
Definition hunk.h:81
@ HUNK_RELRELOC32
Block containing 32-bit PC-relative relocations.
Definition hunk.h:99
@ HUNK_RELOC32SHORT
Block containing 32-bit relocations in a compactified form.
Definition hunk.h:97
@ HUNK_RELRELOC16
Block containing 16-bit PC-relative relocations.
Definition hunk.h:73
@ HUNK_RELRELOC26
Block containing 26-bit PC-relative relocations inside 4-byte words.
Definition hunk.h:105
@ HUNK_ABSRELOC32
Block containing 32-bit relocations.
Definition hunk.h:71
@ HUNK_V37_RELOC32SHORT
V37 Block containing 32-bit relocations in a compactified form, only found in executables.
Definition hunk.h:108
@ HUNK_PPC_CODE
First block of a code segment (hunk) containing PowerPC instructions.
Definition hunk.h:103
@ HUNK_ABSRELOC16
Block containing 8-bit relocations.
Definition hunk.h:101
@ HUNK_NAME
Name of hunk.
Definition hunk.h:63
@ HUNK_DRELOC16
Block containing 16-bit data section relative relocations.
Definition hunk.h:91
@ HUNK_SYMBOL
Block containing a symbol table.
Definition hunk.h:79
@ HUNK_EXT
Block containing externally visible references.
Definition hunk.h:77
Represents the declaration block of a HUNK_BSS segment (hunk) that needs to be allocated and filled w...
Definition hunk.h:251
uint32_t size
Size of memory in 4-byte longwords.
Definition hunk.h:254
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:378
uint32_t GetSize() const override
The actual size of the segment data, as a count of 32-bit longwords.
Definition hunk.cc:383
void ReadBody(Linker::Reader &rd, uint32_t longword_count) override
Reads the segment data (if any)
Definition hunk.cc:388
Represents a HUNK_DEBUG block.
Definition hunk.h:417
void Write(Linker::Writer &wr) const override
Writes the entire block into a file.
Definition hunk.cc:807
void Read(Linker::Reader &rd) override
Reads the rest of the block after the type word.
Definition hunk.cc:801
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:816
Represents the first block inside of an executable file, a HUNK_HEADER.
Definition hunk.h:155
void Read(Linker::Reader &rd) override
Reads the rest of the block after the type word.
Definition hunk.cc:176
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:212
void Write(Linker::Writer &wr) const override
Writes the entire block into a file.
Definition hunk.cc:195
The smallest loadable unit of a Hunk file is the hunk, it roughly corresponds to a segment in other f...
Definition hunk.h:547
void ProduceBlocks(HunkFormat &fmt, Module &module)
Converts the data collected by the linker into hunk blocks.
Definition hunk.cc:1072
uint32_t GetFileSize() const
The amount of bytes this hunk will take up in the file.
Definition hunk.cc:1268
std::shared_ptr< Linker::Image > image
The memory image, if stored in a file (that is, a non-bss segment)
Definition hunk.h:568
offset_t image_size
Size of the memory image, if it is a zero filled segment (bss)
Definition hunk.h:570
uint32_t GetSizeField(HunkFormat &fmt, Module &module)
Retrieves the size field of the first block, to be stored in a header block.
Definition hunk.cc:1279
void AppendBlock(std::shared_ptr< Block > block)
Appends a new block to the block sequence and updates the internal structure of the hunk,...
Definition hunk.cc:1307
uint32_t GetMemorySize() const
The amount of memory this hunk will take up after loading.
Definition hunk.cc:1248
std::vector< std::shared_ptr< Block > > blocks
The sequence of blocks the hunk is stored as.
Definition hunk.h:550
Definition hunk.h:487
void Write(Linker::Writer &wr) const override
Writes the entire block into a file.
Definition hunk.cc:1035
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:1055
void Read(Linker::Reader &rd) override
Reads the rest of the block after the type word.
Definition hunk.cc:1013
Represents a HUNK_LIB block.
Definition hunk.h:468
void Read(Linker::Reader &rd) override
Reads the rest of the block after the type word.
Definition hunk.cc:883
void Write(Linker::Writer &wr) const override
Writes the entire block into a file.
Definition hunk.cc:892
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:899
Represents the load block of a non-bss segment (hunk) HUNK_CODE/HUNK_DATA/HUNK_PPC_CODE,...
Definition hunk.h:232
uint32_t GetSize() const override
The actual size of the segment data, as a count of 32-bit longwords.
Definition hunk.cc:357
void WriteBody(Linker::Writer &wr) const override
Writes the segment data (if any)
Definition hunk.cc:367
void ReadBody(Linker::Reader &rd, uint32_t longword_count) override
Reads the segment data (if any)
Definition hunk.cc:362
Module is a program unit containing several hunks.
Definition hunk.h:613
std::vector< Hunk > hunks
The hunks in this module. Hunks in a library are stored inside a HUNK_LIB.
Definition hunk.h:618
std::shared_ptr< Block > start_block
For an object unit, HUNK_UNIT, for an executable node, HUNK_HEADER, for a new type library,...
Definition hunk.h:616
offset_t GetHunkSizeInHeader(uint32_t index) const
If a header block is available, checks the associated hunk size in the header, returns 0 otherwise.
Definition hunk.cc:1532
std::shared_ptr< Block > end_block
A final block before the start of the next module.
Definition hunk.h:625
Represents a HUNK_OVERLAY block.
Definition hunk.h:436
void Read(Linker::Reader &rd) override
Reads the rest of the block after the type word.
Definition hunk.cc:831
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:870
void Write(Linker::Writer &wr) const override
Writes the entire block into a file.
Definition hunk.cc:851
Represents the block that gives the memory loaded contents of the hunk (segment)
Definition hunk.h:177
virtual void WriteBody(Linker::Writer &wr) const
Writes the segment data (if any)
Definition hunk.cc:331
uint32_t GetSizeField() const
Returns the 32-bit longword that stores the size of the segment plus 2 flag bits.
Definition hunk.cc:254
uint32_t GetAdditionalFlags() const
The contents of an additional 32-bit longword is needed for flags.
Definition hunk.cc:268
void Read(Linker::Reader &rd) override
Reads the rest of the block after the type word.
Definition hunk.cc:273
virtual void ReadBody(Linker::Reader &rd, uint32_t longword_count)
Reads the segment data (if any)
Definition hunk.cc:327
bool RequiresAdditionalFlags() const
Returns true if an additional 32-bit longword is needed for flags.
Definition hunk.cc:263
void Write(Linker::Writer &wr) const override
Writes the entire block into a file.
Definition hunk.cc:288
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:297
virtual uint32_t GetSize() const =0
The actual size of the segment data, as a count of 32-bit longwords.
Represents a block containing relocations.
Definition hunk.h:272
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:509
bool IsShortRelocationBlock() const
Whether this is a HUNK_RELOC32SHORT block (needed because V37 gives it a different number)
Definition hunk.cc:401
void Write(Linker::Writer &wr) const override
Writes the entire block into a file.
Definition hunk.cc:483
void Read(Linker::Reader &rd) override
Reads the rest of the block after the type word.
Definition hunk.cc:455
void Write(Linker::Writer &wr) const override
Write entire unit.
Definition hunk.cc:706
void Read(Linker::Reader &rd) override
Read data after type and name.
Definition hunk.cc:696
offset_t FileSize() const override
Size of entire unit, including type and name fields.
Definition hunk.cc:717
void Write(Linker::Writer &wr) const override
Write entire unit.
Definition hunk.cc:638
void Read(Linker::Reader &rd) override
Read data after type and name.
Definition hunk.cc:633
offset_t FileSize() const override
Size of entire unit, including type and name fields.
Definition hunk.cc:644
offset_t FileSize() const override
Size of entire unit, including type and name fields.
Definition hunk.cc:675
void Read(Linker::Reader &rd) override
Read data after type and name.
Definition hunk.cc:656
void Write(Linker::Writer &wr) const override
Write entire unit.
Definition hunk.cc:665
virtual void Read(Linker::Reader &rd)
Read data after type and name.
Definition hunk.cc:608
virtual offset_t FileSize() const
Size of entire unit, including type and name fields.
Definition hunk.cc:618
virtual void Write(Linker::Writer &wr) const
Write entire unit.
Definition hunk.cc:612
Represents a HUNK_EXT or HUNK_SYMBOL block.
Definition hunk.h:302
void Read(Linker::Reader &rd) override
Reads the rest of the block after the type word.
Definition hunk.cc:729
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:749
void Write(Linker::Writer &wr) const override
Writes the entire block into a file.
Definition hunk.cc:740
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
AmigaOS/TRIPOS Hunk files.
Definition hunk.h:21
void SetOptions(std::map< std::string, std::string > &options) override
Passes command line parameters as settings over to format object.
Definition hunk.cc:1668
void ProcessModule(Linker::Module &module) override
Processes the module object and initializes format fields.
Definition hunk.cc:1814
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition hunk.cc:1591
offset_t ImageSize() const override
Retrieves size of stored data.
Definition hunk.cc:1552
system_version
Definition hunk.h:681
@ V38
generate HUNK_RELOC32SHORT instead of HUNK_V37_RELOC32SHORT
Definition hunk.h:686
@ V39
generate HUNK_RELRELOC32
Definition hunk.h:688
@ V37
generate HUNK_V37_RELOC32SHORT
Definition hunk.h:684
offset_t WriteFile(Linker::Writer &wr) const override
Stores data in memory to file.
Definition hunk.cc:1579
std::vector< Module > modules
A collection of modules/program units.
Definition hunk.h:641
void GenerateFile(std::string filename, Linker::Module &module) override
The main function that handles processing, calculating and generating the final image.
Definition hunk.cc:1901
std::shared_ptr< Linker::OptionCollector > GetOptions() override
Returns object containing a sequence of option fields provided with the -S command line flag.
Definition hunk.cc:1663
void CalculateValues() override
Intermediate step between processing module and generating output file to set up headers and manageme...
Definition hunk.cc:1897
void OnNewSegment(std::shared_ptr< Linker::Segment > segment) override
Callback function when allocating a new segment When the linker script runs, it creates segments cons...
Definition hunk.cc:1713
void ReadFile(Linker::Reader &rd) override
Loads file into memory.
Definition hunk.cc:1562
flags
Definition hunk.h:705
@ ChipMemory
Section to be stored in chip memory.
Definition hunk.h:713
@ FastMemory
Section to be stored in fast memory.
Definition hunk.h:709
std::string GetDefaultExtension(Linker::Module &module) const override
Provides a default filename for the output file.
Definition hunk.cc:1911
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
offset_t WriteFile(Writer &wr) const override=0
Stores data in memory to file.
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
virtual std::string GetDefaultExtension(Module &module, std::string filename) const
Appends a default extension to the filename.
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
Definition hunk.h:29
size_t size
Size of relocation in bytes.
Definition hunk.h:31
relocation_type
Definition hunk.h:33
@ SelfRelative26
Relocation is 26-bit PC-relative, for PowerPC.
Definition hunk.h:41
@ Absolute
Relocation is an absolute reference.
Definition hunk.h:35
@ DataRelative
Relocation relative to the data section.
Definition hunk.h:39
@ SelfRelative
Relocation is PC-relative.
Definition hunk.h:37