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/section.h"
8#include "../linker/segment.h"
9#include "../linker/segment_manager.h"
10#include "../linker/writer.h"
11
12namespace Amiga
13{
19 class HunkFormat : public virtual Linker::SegmentManager
20 {
21 public:
22 /* * * General members * * */
23
24 class Hunk;
25 class Module;
26
28 {
30 size_t size;
42 relocation_type type;
43 uint32_t offset;
44 Relocation(size_t size, relocation_type type, uint32_t offset)
45 : size(size), type(type), offset(offset)
46 {
47 }
48 bool operator <(const Relocation& other) const;
49 };
50
54 class Block
55 {
56 public:
58 {
60 HUNK_UNIT = 0x3E7,
62 HUNK_NAME = 0x3E8,
64 HUNK_CODE = 0x3E9,
66 HUNK_DATA = 0x3EA,
68 HUNK_BSS = 0x3EB,
76 HUNK_EXT = 0x3EF,
78 HUNK_SYMBOL = 0x3F0,
80 HUNK_DEBUG = 0x3F1,
82 HUNK_END = 0x3F2,
84 HUNK_HEADER = 0x3F3,
85 HUNK_OVERLAY = 0x3F5,
86 HUNK_BREAK = 0x3F6,
92 HUNK_DRELOC8 = 0x3F9,
93 HUNK_LIB = 0x3FA,
94 HUNK_INDEX = 0x3FB,
105
108 };
109 block_type type;
111 bool is_executable = false;
112 Block(block_type type, bool is_executable = false)
113 : type(type), is_executable(is_executable)
114 {
115 }
116 virtual ~Block() = default;
124 static std::shared_ptr<Block> ReadBlock(Linker::Reader& rd, bool is_executable = false);
126 virtual void Read(Linker::Reader& rd);
128 virtual void Write(Linker::Writer& wr) const;
130 virtual offset_t FileSize() const;
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;
134 };
135
137 class TextBlock : public Block
138 {
139 public:
140 std::string name;
141
142 TextBlock(block_type type, std::string name = "")
143 : Block(type), name(name)
144 {
145 }
146
147 void Read(Linker::Reader& rd) override;
148 void Write(Linker::Writer& wr) const override;
149 offset_t FileSize() const override;
150 };
151
153 class HeaderBlock : public Block
154 {
155 public:
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;
160
163 {
164 }
165
166 void Read(Linker::Reader& rd) override;
167 void Write(Linker::Writer& wr) const override;
168 offset_t FileSize() const override;
169
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;
172 };
173
175 class RelocatableBlock : public Block
176 {
177 public:
178 enum
179 {
180 FlagMask = 0xE0000000,
181 BitAdvisory = 0x20000000,
182 BitChipMem = 0x40000000,
183 BitFastMem = 0x80000000,
184 BitAdditional = 0xC0000000,
185 };
186
187 enum flag_type
188 {
189 LoadAny = 0x00000000,
190 LoadPublic = 0x00000001, /* default, not stored */
191 LoadChipMem = 0x00000002,
192 LoadFastMem = 0x00000004,
193 LoadLocalMem = 0x00000008,
194 Load24BitDma = 0x00000010,
195 LoadClear = 0x00010000,
196 };
197 flag_type flags;
198 bool loaded_with_additional_flags = false;
199
200 RelocatableBlock(block_type type, uint32_t flags = LoadAny)
201 : Block(type), flags(flag_type(flags | LoadPublic))
202 {
203 }
204
206 uint32_t GetSizeField() const;
207
209 bool RequiresAdditionalFlags() const;
210
212 uint32_t GetAdditionalFlags() const;
213
214 void Read(Linker::Reader& rd) override;
215 void Write(Linker::Writer& wr) const override;
216 offset_t FileSize() const override;
217
218 void AddExtraFields(Dumper::Region& region, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
219
220 protected:
222 virtual uint32_t GetSize() const = 0;
224 virtual void ReadBody(Linker::Reader& rd, uint32_t longword_count);
226 virtual void WriteBody(Linker::Writer& wr) const;
227 };
228
231 {
232 public:
233 std::shared_ptr<Linker::Image> image;
234
235 LoadBlock(block_type type, uint32_t flags = LoadAny)
236 : RelocatableBlock(type, flags)
237 {
238 }
239
240 void Dump(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
241
242 protected:
243 uint32_t GetSize() const override;
244 void ReadBody(Linker::Reader& rd, uint32_t longword_count) override;
245 void WriteBody(Linker::Writer& wr) const override;
246 };
247
250 {
251 public:
253 uint32_t size;
254
255 BssBlock(uint32_t size = 0, uint32_t flags = LoadAny)
257 {
258 }
259
260 offset_t FileSize() const override;
261
262 void AddExtraFields(Dumper::Region& region, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
263
264 protected:
265 uint32_t GetSize() const override;
266 void ReadBody(Linker::Reader& rd, uint32_t longword_count) override;
267 };
268
270 class RelocationBlock : public Block
271 {
272 public:
274 {
275 uint32_t hunk;
276 std::vector<uint32_t> offsets;
277 };
278 std::vector<RelocationData> relocations;
279
280 RelocationBlock(block_type type, bool is_executable = false)
281 : Block(type, is_executable)
282 {
283 }
284
286 bool IsShortRelocationBlock() const;
287
288 size_t GetRelocationSize() const;
289
290 Relocation::relocation_type GetRelocationType() const;
291
292 void Read(Linker::Reader& rd) override;
293 void Write(Linker::Writer& wr) const override;
294 offset_t FileSize() const override;
295
296 void Dump(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
297 };
298
300 class SymbolBlock : public Block
301 {
302 public:
303 class Unit
304 {
305 public:
306 enum symbol_type
307 {
308 EXT_SYMB = 0,
309 EXT_DEF = 1,
310 EXT_ABS = 2,
311 EXT_RES = 3,
312
313 EXT_ABSREF32 = 129,
314 EXT_COMMON = 130,
315 EXT_RELREF16 = 131,
316 EXT_RELREF8 = 132,
317 EXT_DREF32 = 133,
318 EXT_DREF16 = 134,
319 EXT_DREF8 = 135,
320 EXT_RELREF32 = 136,
321 EXT_RELCOMMON = 137,
322 EXT_ABSREF16 = 138,
323 EXT_ABSREF8 = 139,
324 EXT_RELREF26 = 229,
325 };
326 symbol_type type;
327 std::string name;
328
329 Unit(symbol_type type, std::string name)
330 : type(type), name(name)
331 {
332 }
333
334 static std::unique_ptr<Unit> ReadData(Linker::Reader& rd);
335
336 virtual ~Unit() = default;
338 virtual void Read(Linker::Reader& rd);
340 virtual void Write(Linker::Writer& wr) const;
342 virtual offset_t FileSize() const;
343 virtual void DumpContents(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const;
344 virtual void AddExtraFields(Dumper::Dumper& dump, Dumper::Entry& entry, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const;
345 };
346
347 class Definition : public Unit
348 {
349 public:
350 uint32_t value;
351
352 Definition(symbol_type type, std::string name, uint32_t value = 0)
353 : Unit(type, name), value(value)
354 {
355 }
356
357 void Read(Linker::Reader& rd) override;
359 void Write(Linker::Writer& wr) const override;
361 offset_t FileSize() const override;
362 void AddExtraFields(Dumper::Dumper& dump, Dumper::Entry& entry, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
363 };
364
365 class References : public Unit
366 {
367 public:
368 std::vector<uint32_t> references;
369
370 References(symbol_type type, std::string name)
371 : Unit(type, name)
372 {
373 }
374
375 void Read(Linker::Reader& rd) override;
377 void Write(Linker::Writer& wr) const override;
379 offset_t FileSize() const override;
380 void DumpContents(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
381 };
382
384 {
385 public:
386 uint32_t size;
387
388 CommonReferences(symbol_type type, std::string name, uint32_t size = 0)
389 : References(type, name), size(size)
390 {
391 }
392
393 void Read(Linker::Reader& rd) override;
395 void Write(Linker::Writer& wr) const override;
397 offset_t FileSize() const override;
398 void AddExtraFields(Dumper::Dumper& dump, Dumper::Entry& entry, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
399 };
400
401 std::vector<std::unique_ptr<Unit>> symbols;
402
404 : Block(type)
405 {
406 }
407
408 void Read(Linker::Reader& rd) override;
409 void Write(Linker::Writer& wr) const override;
410 offset_t FileSize() const override;
411 void Dump(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
412 };
413
415 class DebugBlock : public Block
416 {
417 public:
418 // TODO: untested
419 std::shared_ptr<Linker::Image> image;
420
421 DebugBlock()
423 {
424 }
425
426 void Read(Linker::Reader& rd) override;
427 void Write(Linker::Writer& wr) const override;
428 offset_t FileSize() const override;
429
430 void Dump(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
431 };
432
434 class OverlayBlock : public Block
435 {
436 public:
437 // TODO: untested
438 uint32_t maximum_level = 2;
439
441 {
442 uint32_t offset;
443 uint32_t res1, res2;
444 uint32_t level;
445 uint32_t ordinate;
446 uint32_t first_hunk;
447 uint32_t symbol_hunk;
448 uint32_t symbol_offset;
449 };
450
451 std::vector<OverlaySymbol> overlay_data_table;
452
454 : Block(HUNK_OVERLAY)
455 {
456 }
457
458 void Read(Linker::Reader& rd) override;
459 void Write(Linker::Writer& wr) const override;
460 offset_t FileSize() const override;
461
462 void Dump(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
463 };
464
466 class LibraryBlock : public Block
467 {
468 public:
469 // TODO: untested
470
471 std::unique_ptr<Module> hunks;
472
474 : Block(HUNK_LIB)
475 {
476 }
477
478 void Read(Linker::Reader& rd) override;
479 void Write(Linker::Writer& wr) const override;
480 offset_t FileSize() const override;
481
482 void Dump(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
483 };
484
485 class IndexBlock : public Block
486 {
487 public:
488 // TODO: untested
489
491 {
492 public:
493 uint16_t string_offset = 0;
494 uint16_t symbol_offset = 0;
495 uint16_t type = 0;
496
497 static Definition Read(Linker::Reader& rd);
498 void Write(Linker::Writer& wr) const;
499 };
500
502 {
503 public:
504 uint16_t string_offset = 0;
505 uint16_t hunk_size = 0; // in longwords
506 uint16_t hunk_type = 0;
507 std::vector<uint16_t> references;
508 std::vector<Definition> definitions;
509
510 static HunkEntry Read(Linker::Reader& rd);
511 void Write(Linker::Writer& wr) const;
512 offset_t FileSize() const;
513 };
514
516 {
517 public:
518 int16_t string_offset = 0;
519 uint16_t first_hunk_offset = 0; // in longwords
520 std::vector<HunkEntry> hunks;
521
522 static ProgramUnit Read(Linker::Reader& rd);
523 void Write(Linker::Writer& wr) const;
524 offset_t FileSize() const;
525 };
526
527 std::vector<std::string> strings;
528 std::vector<ProgramUnit> units;
529
530 IndexBlock()
531 : Block(HUNK_INDEX)
532 {
533 }
534
535 offset_t StringTableSize() const;
536
537 void Read(Linker::Reader& rd) override;
538 void Write(Linker::Writer& wr) const override;
539 offset_t FileSize() const override;
540
541 void Dump(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
542 };
543
545 class Hunk
546 {
547 public:
549 std::vector<std::shared_ptr<Block>> blocks;
550
551 enum hunk_type : uint32_t
552 {
553 Undefined = 0,
554 Invalid = uint32_t(-1),
555
556 Code = Block::HUNK_CODE,
557 CodePPC = Block::HUNK_PPC_CODE,
558 Data = Block::HUNK_DATA,
559 Bss = Block::HUNK_BSS,
560 };
561 hunk_type type = Undefined;
562
563 // TODO: implement advisory flag
564
565 LoadBlock::flag_type flags = LoadBlock::LoadPublic;
567 std::shared_ptr<Linker::Image> image;
569 offset_t image_size = 0;
570
571 std::string name;
572
573 explicit Hunk()
574 : type(Undefined), flags(LoadBlock::LoadAny), image(nullptr)
575 {
576 }
577
578 Hunk(hunk_type type, std::string name = "image", unsigned flags = LoadBlock::LoadAny)
579 : type(hunk_type(type)), flags(LoadBlock::flag_type(flags)), image(std::make_shared<Linker::Segment>(name))
580 {
581 }
582
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)
585 {
586 }
587
588 std::map<uint32_t, std::set<Relocation>> relocations;
589
591 void ProduceBlocks();
592
594 uint32_t GetMemorySize() const;
595
597 uint32_t GetFileSize() const;
598
600 uint32_t GetSizeField();
601
603 void AppendBlock(std::shared_ptr<Block> block);
604 };
605
611 class Module
612 {
613 public:
615 std::shared_ptr<Block> start_block;
617 std::vector<Hunk> hunks;
624 std::shared_ptr<Block> end_block;
625
626 bool IsExecutable() const;
627 offset_t ImageSize() const;
628 void ReadFile(Linker::Reader& rd, std::shared_ptr<Block>& next_block, offset_t end);
629 void WriteFile(Linker::Writer& wr) const;
630 void Dump(Dumper::Dumper& dump, offset_t current_offset, unsigned index) const;
631
633 offset_t GetHunkSizeInHeader(uint32_t index) const;
634 };
635
640 std::vector<Module> modules;
641
642 bool IsExecutable() const;
643
644 offset_t ImageSize() const override;
645
646 void ReadFile(Linker::Reader& rd) override;
647
649 offset_t WriteFile(Linker::Writer& wr) const override;
650 void Dump(Dumper::Dumper& dump) const override;
651
652 static std::string ReadString(uint32_t longword_count, Linker::Reader& rd);
653 static std::string ReadString(Linker::Reader& rd, uint32_t& longword_count);
654 static std::string ReadString(Linker::Reader& rd);
655 static void WriteStringContents(Linker::Writer& wr, std::string name);
656 static void WriteString(Linker::Writer& wr, std::string name);
657 static offset_t MeasureString(std::string name);
658
659 /* * * Writer members * * */
660
661 enum cpu_type
662 {
663 CPU_M68K = Block::HUNK_CODE,
664 CPU_PPC = Block::HUNK_PPC_CODE,
665 };
666 cpu_type cpu = CPU_PPC;
667
668 /* @brief Convenience map to make it easier to look up the indices of segments */
669 std::map<std::shared_ptr<Linker::Segment>, size_t> segment_index;
670
671 unsigned FormatAdditionalSectionFlags(std::string section_name) const override;
672
684
685 void SetOptions(std::map<std::string, std::string>& options) override;
686
687 void AddHunk(const Hunk& hunk);
688
689 void OnNewSegment(std::shared_ptr<Linker::Segment> segment) override;
690
691 std::unique_ptr<Script::List> GetScript(Linker::Module& module);
692
693 void Link(Linker::Module& module);
694
695 void ProcessModule(Linker::Module& module) override;
696
697 void CalculateValues() override;
698
699 void GenerateFile(std::string filename, Linker::Module& module) override;
700
702 std::string GetDefaultExtension(Linker::Module& module) const override;
703
704 };
705
706}
707
708#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:55
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:85
virtual offset_t FileSize() const
Returns the size of the block as stored inside a file.
Definition hunk.cc:94
bool is_executable
Required because V37 executables define HUNK_DRELOC32 as HUNK_RELOC32SHORT, must block types ignore t...
Definition hunk.h:111
virtual void Write(Linker::Writer &wr) const
Writes the entire block into a file.
Definition hunk.cc:89
block_type
Definition hunk.h:58
@ HUNK_UNIT
First block inside an object file.
Definition hunk.h:60
@ HUNK_END
Block terminates a hunk.
Definition hunk.h:82
@ HUNK_DATA
First block of a data segment (hunk)
Definition hunk.h:66
@ HUNK_BSS
First block of a bss segment (hunk)
Definition hunk.h:68
@ HUNK_DRELOC8
Block containing 8-bit data section relative relocations.
Definition hunk.h:92
@ HUNK_CODE
First block of a code segment (hunk) containing Motorola 68k instructions.
Definition hunk.h:64
@ HUNK_RELRELOC8
Block containing 8-bit PC-relative relocations.
Definition hunk.h:74
@ HUNK_DRELOC32
Block containing 32-bit data section relative relocations.
Definition hunk.h:88
@ HUNK_HEADER
First block inside an executable or library file.
Definition hunk.h:84
@ HUNK_DEBUG
Debug information.
Definition hunk.h:80
@ HUNK_RELRELOC32
Block containing 32-bit PC-relative relocations.
Definition hunk.h:98
@ HUNK_RELOC32SHORT
Block containing 32-bit relocations in a compactified form.
Definition hunk.h:96
@ HUNK_RELRELOC16
Block containing 16-bit PC-relative relocations.
Definition hunk.h:72
@ HUNK_RELRELOC26
Block containing 26-bit PC-relative relocations inside 4-byte words.
Definition hunk.h:104
@ HUNK_ABSRELOC32
Block containing 32-bit relocations.
Definition hunk.h:70
@ HUNK_V37_RELOC32SHORT
V37 Block containing 32-bit relocations in a compactified form, only found in executables.
Definition hunk.h:107
@ HUNK_PPC_CODE
First block of a code segment (hunk) containing PowerPC instructions.
Definition hunk.h:102
@ HUNK_ABSRELOC16
Block containing 8-bit relocations.
Definition hunk.h:100
@ HUNK_NAME
Name of hunk.
Definition hunk.h:62
@ HUNK_DRELOC16
Block containing 16-bit data section relative relocations.
Definition hunk.h:90
@ HUNK_SYMBOL
Block containing a symbol table.
Definition hunk.h:78
@ HUNK_EXT
Block containing externally visible references.
Definition hunk.h:76
Represents the declaration block of a HUNK_BSS segment (hunk) that needs to be allocated and filled w...
Definition hunk.h:250
uint32_t size
Size of memory in 4-byte longwords.
Definition hunk.h:253
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:365
uint32_t GetSize() const override
The actual size of the segment data, as a count of 32-bit longwords.
Definition hunk.cc:370
void ReadBody(Linker::Reader &rd, uint32_t longword_count) override
Reads the segment data (if any)
Definition hunk.cc:375
Represents a HUNK_DEBUG block.
Definition hunk.h:416
void Write(Linker::Writer &wr) const override
Writes the entire block into a file.
Definition hunk.cc:785
void Read(Linker::Reader &rd) override
Reads the rest of the block after the type word.
Definition hunk.cc:779
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:794
Represents the first block inside of an executable file, a HUNK_HEADER.
Definition hunk.h:154
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:199
void Write(Linker::Writer &wr) const override
Writes the entire block into a file.
Definition hunk.cc:182
The smallest loadable unit of a Hunk file is the hunk, it roughly corresponds to a segment in other f...
Definition hunk.h:546
uint32_t GetFileSize() const
The amount of bytes this hunk will take up in the file.
Definition hunk.cc:1118
std::shared_ptr< Linker::Image > image
The memory image, if stored in a file (that is, a non-bss segment)
Definition hunk.h:567
offset_t image_size
Size of the memory image, if it is a zero filled segment (bss)
Definition hunk.h:569
void ProduceBlocks()
Converts the data collected by the linker into hunk blocks.
Definition hunk.cc:1050
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:1157
uint32_t GetMemorySize() const
The amount of memory this hunk will take up after loading.
Definition hunk.cc:1098
std::vector< std::shared_ptr< Block > > blocks
The sequence of blocks the hunk is stored as.
Definition hunk.h:549
uint32_t GetSizeField()
Retrieves the size field of the first block, to be stored in a header block.
Definition hunk.cc:1129
Definition hunk.h:486
void Write(Linker::Writer &wr) const override
Writes the entire block into a file.
Definition hunk.cc:1013
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:1033
void Read(Linker::Reader &rd) override
Reads the rest of the block after the type word.
Definition hunk.cc:991
Represents a HUNK_LIB block.
Definition hunk.h:467
void Read(Linker::Reader &rd) override
Reads the rest of the block after the type word.
Definition hunk.cc:861
void Write(Linker::Writer &wr) const override
Writes the entire block into a file.
Definition hunk.cc:870
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:877
Represents the load block of a non-bss segment (hunk) HUNK_CODE/HUNK_DATA/HUNK_PPC_CODE,...
Definition hunk.h:231
uint32_t GetSize() const override
The actual size of the segment data, as a count of 32-bit longwords.
Definition hunk.cc:344
void WriteBody(Linker::Writer &wr) const override
Writes the segment data (if any)
Definition hunk.cc:354
void ReadBody(Linker::Reader &rd, uint32_t longword_count) override
Reads the segment data (if any)
Definition hunk.cc:349
Module is a program unit containing several hunks.
Definition hunk.h:612
std::vector< Hunk > hunks
The hunks in this module. Hunks in a library are stored inside a HUNK_LIB.
Definition hunk.h:617
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:615
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:1382
std::shared_ptr< Block > end_block
A final block before the start of the next module.
Definition hunk.h:624
Represents a HUNK_OVERLAY block.
Definition hunk.h:435
void Read(Linker::Reader &rd) override
Reads the rest of the block after the type word.
Definition hunk.cc:809
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:848
void Write(Linker::Writer &wr) const override
Writes the entire block into a file.
Definition hunk.cc:829
Represents the block that gives the memory loaded contents of the hunk (segment)
Definition hunk.h:176
virtual void WriteBody(Linker::Writer &wr) const
Writes the segment data (if any)
Definition hunk.cc:318
uint32_t GetSizeField() const
Returns the 32-bit longword that stores the size of the segment plus 2 flag bits.
Definition hunk.cc:241
uint32_t GetAdditionalFlags() const
The contents of an additional 32-bit longword is needed for flags.
Definition hunk.cc:255
void Read(Linker::Reader &rd) override
Reads the rest of the block after the type word.
Definition hunk.cc:260
virtual void ReadBody(Linker::Reader &rd, uint32_t longword_count)
Reads the segment data (if any)
Definition hunk.cc:314
bool RequiresAdditionalFlags() const
Returns true if an additional 32-bit longword is needed for flags.
Definition hunk.cc:250
void Write(Linker::Writer &wr) const override
Writes the entire block into a file.
Definition hunk.cc:275
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:284
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:271
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:493
bool IsShortRelocationBlock() const
Whether this is a HUNK_RELOC32SHORT block (needed because V37 gives it a different number)
Definition hunk.cc:388
void Write(Linker::Writer &wr) const override
Writes the entire block into a file.
Definition hunk.cc:467
void Read(Linker::Reader &rd) override
Reads the rest of the block after the type word.
Definition hunk.cc:441
void Write(Linker::Writer &wr) const override
Write entire unit.
Definition hunk.cc:686
void Read(Linker::Reader &rd) override
Read data after type and name.
Definition hunk.cc:676
offset_t FileSize() const override
Size of entire unit, including type and name fields.
Definition hunk.cc:697
void Write(Linker::Writer &wr) const override
Write entire unit.
Definition hunk.cc:618
void Read(Linker::Reader &rd) override
Read data after type and name.
Definition hunk.cc:613
offset_t FileSize() const override
Size of entire unit, including type and name fields.
Definition hunk.cc:624
offset_t FileSize() const override
Size of entire unit, including type and name fields.
Definition hunk.cc:655
void Read(Linker::Reader &rd) override
Read data after type and name.
Definition hunk.cc:636
void Write(Linker::Writer &wr) const override
Write entire unit.
Definition hunk.cc:645
virtual void Read(Linker::Reader &rd)
Read data after type and name.
Definition hunk.cc:588
virtual offset_t FileSize() const
Size of entire unit, including type and name fields.
Definition hunk.cc:598
virtual void Write(Linker::Writer &wr) const
Write entire unit.
Definition hunk.cc:592
Represents a HUNK_EXT or HUNK_SYMBOL block.
Definition hunk.h:301
void Read(Linker::Reader &rd) override
Reads the rest of the block after the type word.
Definition hunk.cc:709
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:729
void Write(Linker::Writer &wr) const override
Writes the entire block into a file.
Definition hunk.cc:720
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
AmigaOS/TRIPOS Hunk files.
Definition hunk.h:20
void SetOptions(std::map< std::string, std::string > &options) override
Passes command line parameters as settings over to format object.
Definition hunk.cc:1513
void ProcessModule(Linker::Module &module) override
Processes the module object and initializes format fields.
Definition hunk.cc:1634
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition hunk.cc:1441
offset_t ImageSize() const override
Retrieves size of stored data.
Definition hunk.cc:1402
offset_t WriteFile(Linker::Writer &wr) const override
Stores data in memory to file.
Definition hunk.cc:1429
std::vector< Module > modules
A collection of modules/program units.
Definition hunk.h:640
void GenerateFile(std::string filename, Linker::Module &module) override
The main function that handles processing, calculating and generating the final image.
Definition hunk.cc:1695
void CalculateValues() override
Intermediate step between processing module and generating output file to set up headers and manageme...
Definition hunk.cc:1691
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:1527
void ReadFile(Linker::Reader &rd) override
Loads file into memory.
Definition hunk.cc:1412
flags
Definition hunk.h:674
@ ChipMemory
Section to be stored in chip memory.
Definition hunk.h:682
@ FastMemory
Section to be stored in fast memory.
Definition hunk.h:678
std::string GetDefaultExtension(Linker::Module &module) const override
Provides a default filename for the output file.
Definition hunk.cc:1705
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
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:28
size_t size
Size of relocation in bytes.
Definition hunk.h:30
relocation_type
Definition hunk.h:32
@ SelfRelative26
Relocation is 26-bit PC-relative, for PowerPC.
Definition hunk.h:40
@ Absolute
Relocation is an absolute reference.
Definition hunk.h:34
@ DataRelative
Relocation relative to the data section.
Definition hunk.h:38
@ SelfRelative
Relocation is PC-relative.
Definition hunk.h:36