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 int GetDisplayOptions() const;
133 virtual void Dump(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const;
134 void AddCommonFields(Dumper::Region& region, unsigned index) const;
135 virtual void AddExtraFields(Dumper::Region& region, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const;
136 };
137
139 class TextBlock : public Block
140 {
141 public:
142 std::string name;
143
144 TextBlock(block_type type, std::string name = "")
145 : Block(type), name(name)
146 {
147 }
148
149 void Read(Linker::Reader& rd) override;
150 void Write(Linker::Writer& wr) const override;
151 offset_t FileSize() const override;
152 };
153
155 class HeaderBlock : public Block
156 {
157 public:
158 std::vector<std::string> library_names;
159 uint32_t table_size = 0;
160 uint32_t first_hunk = 0;
161 std::vector<uint32_t> hunk_sizes;
162
165 {
166 }
167
168 void Read(Linker::Reader& rd) override;
169 void Write(Linker::Writer& wr) const override;
170 offset_t FileSize() const override;
171
172 //int GetDisplayOptions() const override;
173 void Dump(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
174 void AddExtraFields(Dumper::Region& region, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
175 };
176
178 class RelocatableBlock : public Block
179 {
180 public:
181 enum
182 {
183 FlagMask = 0xE0000000,
184 BitAdvisory = 0x20000000,
185 BitChipMem = 0x40000000,
186 BitFastMem = 0x80000000,
187 BitAdditional = 0xC0000000,
188 };
189
190 enum flag_type
191 {
192 LoadAny = 0x00000000,
193 LoadPublic = 0x00000001, /* default, not stored */
194 LoadChipMem = 0x00000002,
195 LoadFastMem = 0x00000004,
196 LoadLocalMem = 0x00000008,
197 Load24BitDma = 0x00000010,
198 LoadClear = 0x00010000,
199 };
200 flag_type flags;
201 bool loaded_with_additional_flags = false;
202
203 RelocatableBlock(block_type type, uint32_t flags = LoadAny)
204 : Block(type), flags(flag_type(flags | LoadPublic))
205 {
206 }
207
209 uint32_t GetSizeField() const;
210
212 bool RequiresAdditionalFlags() const;
213
215 uint32_t GetAdditionalFlags() const;
216
217 void Read(Linker::Reader& rd) override;
218 void Write(Linker::Writer& wr) const override;
219 offset_t FileSize() const override;
220
221 void AddExtraFields(Dumper::Region& region, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
222
223 protected:
225 virtual uint32_t GetSize() const = 0;
227 virtual void ReadBody(Linker::Reader& rd, uint32_t longword_count);
229 virtual void WriteBody(Linker::Writer& wr) const;
230 };
231
234 {
235 public:
236 std::shared_ptr<Linker::Contents> image;
237
238 LoadBlock(block_type type, uint32_t flags = LoadAny)
239 : RelocatableBlock(type, flags)
240 {
241 }
242
243 int GetDisplayOptions() const override;
244 void Dump(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
245
246 protected:
247 uint32_t GetSize() const override;
248 void ReadBody(Linker::Reader& rd, uint32_t longword_count) override;
249 void WriteBody(Linker::Writer& wr) const override;
250 };
251
254 {
255 public:
257 uint32_t size;
258
259 BssBlock(uint32_t size = 0, uint32_t flags = LoadAny)
261 {
262 }
263
264 offset_t FileSize() const override;
265
266 void AddExtraFields(Dumper::Region& region, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
267
268 protected:
269 uint32_t GetSize() const override;
270 void ReadBody(Linker::Reader& rd, uint32_t longword_count) override;
271 };
272
274 class RelocationBlock : public Block
275 {
276 public:
278 {
279 uint32_t hunk;
280 std::vector<uint32_t> offsets;
281 };
282 std::vector<RelocationData> relocations;
283
284 RelocationBlock(block_type type, bool is_executable = false)
285 : Block(type, is_executable)
286 {
287 }
288
290 bool IsShortRelocationBlock() const;
291
292 size_t GetRelocationSize() const;
293
294 Relocation::relocation_type GetRelocationType() const;
295
296 void Read(Linker::Reader& rd) override;
297 void Write(Linker::Writer& wr) const override;
298 offset_t FileSize() const override;
299
300 int GetDisplayOptions() const override;
301 void Dump(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
302 };
303
305 class SymbolBlock : public Block
306 {
307 public:
308 class Unit
309 {
310 public:
311 enum symbol_type
312 {
313 EXT_SYMB = 0,
314 EXT_DEF = 1,
315 EXT_ABS = 2,
316 EXT_RES = 3,
317
318 EXT_ABSREF32 = 129,
319 EXT_COMMON = 130,
320 EXT_RELREF16 = 131,
321 EXT_RELREF8 = 132,
322 EXT_DREF32 = 133,
323 EXT_DREF16 = 134,
324 EXT_DREF8 = 135,
325 EXT_RELREF32 = 136,
326 EXT_RELCOMMON = 137,
327 EXT_ABSREF16 = 138,
328 EXT_ABSREF8 = 139,
329 EXT_RELREF26 = 229,
330 };
331 symbol_type type;
332 std::string name;
333
334 Unit(symbol_type type, std::string name)
335 : type(type), name(name)
336 {
337 }
338
339 static std::unique_ptr<Unit> ReadData(Linker::Reader& rd);
340
341 virtual ~Unit() = default;
343 virtual void Read(Linker::Reader& rd);
345 virtual void Write(Linker::Writer& wr) const;
347 virtual offset_t FileSize() const;
348 virtual void DumpContents(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const;
349 virtual void AddExtraFields(Dumper::Dumper& dump, Dumper::Entry& entry, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const;
350 };
351
352 class Definition : public Unit
353 {
354 public:
355 uint32_t value;
356
357 Definition(symbol_type type, std::string name, uint32_t value = 0)
358 : Unit(type, name), value(value)
359 {
360 }
361
362 void Read(Linker::Reader& rd) override;
364 void Write(Linker::Writer& wr) const override;
366 offset_t FileSize() const override;
367 void AddExtraFields(Dumper::Dumper& dump, Dumper::Entry& entry, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
368 };
369
370 class References : public Unit
371 {
372 public:
373 std::vector<uint32_t> references;
374
375 References(symbol_type type, std::string name)
376 : Unit(type, name)
377 {
378 }
379
380 bool ContainsRelocations() const;
381
382 size_t GetRelocationSize() const;
383
384 Relocation::relocation_type GetRelocationType() const;
385
386 void Read(Linker::Reader& rd) override;
388 void Write(Linker::Writer& wr) const override;
390 offset_t FileSize() const override;
391 void DumpContents(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
392 };
393
395 {
396 public:
397 uint32_t size;
398
399 CommonReferences(symbol_type type, std::string name, uint32_t size = 0)
400 : References(type, name), size(size)
401 {
402 }
403
404 void Read(Linker::Reader& rd) override;
406 void Write(Linker::Writer& wr) const override;
408 offset_t FileSize() const override;
409 void AddExtraFields(Dumper::Dumper& dump, Dumper::Entry& entry, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
410 };
411
412 std::vector<std::unique_ptr<Unit>> symbols;
413
415 : Block(type)
416 {
417 }
418
419 void Read(Linker::Reader& rd) override;
420 void Write(Linker::Writer& wr) const override;
421 offset_t FileSize() const override;
422 int GetDisplayOptions() const override;
423 void Dump(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
424 };
425
427 class DebugBlock : public Block
428 {
429 public:
430 // TODO: untested
431 std::shared_ptr<Linker::Contents> image;
432
433 DebugBlock()
435 {
436 }
437
438 void Read(Linker::Reader& rd) override;
439 void Write(Linker::Writer& wr) const override;
440 offset_t FileSize() const override;
441
442 int GetDisplayOptions() const override;
443 void Dump(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
444 };
445
447 class OverlayBlock : public Block
448 {
449 public:
450 // TODO: untested
451 uint32_t maximum_level = 2;
452
454 {
455 uint32_t offset;
456 uint32_t res1, res2;
457 uint32_t level;
458 uint32_t ordinate;
459 uint32_t first_hunk;
460 uint32_t symbol_hunk;
461 uint32_t symbol_offset;
462 };
463
464 std::vector<OverlaySymbol> overlay_data_table;
465
467 : Block(HUNK_OVERLAY)
468 {
469 }
470
471 void Read(Linker::Reader& rd) override;
472 void Write(Linker::Writer& wr) const override;
473 offset_t FileSize() const override;
474
475 int GetDisplayOptions() const override;
476 void Dump(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
477 };
478
480 class LibraryBlock : public Block
481 {
482 public:
483 // TODO: untested
484
485 std::unique_ptr<Module> hunks;
486
488 : Block(HUNK_LIB)
489 {
490 }
491
492 void Read(Linker::Reader& rd) override;
493 void Write(Linker::Writer& wr) const override;
494 offset_t FileSize() const override;
495
496 int GetDisplayOptions() const override;
497 void Dump(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
498 };
499
500 class IndexBlock : public Block
501 {
502 public:
503 // TODO: untested
504
506 {
507 public:
508 uint16_t string_offset = 0;
509 uint16_t symbol_offset = 0;
510 uint16_t type = 0;
511
512 static Definition Read(Linker::Reader& rd);
513 void Write(Linker::Writer& wr) const;
514 };
515
517 {
518 public:
519 uint16_t string_offset = 0;
520 uint16_t hunk_size = 0; // in longwords
521 uint16_t hunk_type = 0;
522 std::vector<uint16_t> references;
523 std::vector<Definition> definitions;
524
525 static HunkEntry Read(Linker::Reader& rd);
526 void Write(Linker::Writer& wr) const;
527 offset_t FileSize() const;
528 };
529
531 {
532 public:
533 int16_t string_offset = 0;
534 uint16_t first_hunk_offset = 0; // in longwords
535 std::vector<HunkEntry> hunks;
536
537 static ProgramUnit Read(Linker::Reader& rd);
538 void Write(Linker::Writer& wr) const;
539 offset_t FileSize() const;
540 };
541
542 std::vector<std::string> strings;
543 std::vector<ProgramUnit> units;
544
545 IndexBlock()
546 : Block(HUNK_INDEX)
547 {
548 }
549
550 offset_t StringTableSize() const;
551
552 void Read(Linker::Reader& rd) override;
553 void Write(Linker::Writer& wr) const override;
554 offset_t FileSize() const override;
555
556 int GetDisplayOptions() const override;
557 void Dump(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
558 };
559
561 class Hunk
562 {
563 public:
565 std::vector<std::shared_ptr<Block>> blocks;
566
567 enum hunk_type : uint32_t
568 {
569 Undefined = 0,
570 Invalid = uint32_t(-1),
571
572 Code = Block::HUNK_CODE,
573 CodePPC = Block::HUNK_PPC_CODE,
574 Data = Block::HUNK_DATA,
575 Bss = Block::HUNK_BSS,
576 };
577 hunk_type type = Undefined;
578
579 // TODO: implement advisory flag
580
581 LoadBlock::flag_type flags = LoadBlock::LoadPublic;
583 std::shared_ptr<Linker::Contents> image;
585 offset_t image_size = 0;
586
587 std::string name;
588
589 explicit Hunk()
590 : type(Undefined), flags(LoadBlock::LoadAny), image(nullptr)
591 {
592 }
593
594 Hunk(hunk_type type, std::string name = "image", unsigned flags = LoadBlock::LoadAny)
595 : type(hunk_type(type)), flags(LoadBlock::flag_type(flags)), image(std::make_shared<Linker::Segment>(name))
596 {
597 }
598
599 Hunk(hunk_type type, std::shared_ptr<Linker::Segment> segment, unsigned flags = LoadBlock::LoadAny)
600 : type(hunk_type(type)), flags(LoadBlock::flag_type(flags)), image(segment)
601 {
602 }
603
605 std::map<uint32_t, std::set<Relocation>> relocations;
606
608 std::map<std::string, std::set<Relocation>> externals;
609
610 // TODO: also store defined variables, common variables (only for object files) */
611
613 void ProduceBlocks(HunkFormat& fmt, Module& module);
614
616 uint32_t GetMemorySize() const;
617
619 uint32_t GetFileSize() const;
620
622 uint32_t GetSizeField(HunkFormat& fmt, Module& module);
623
625 void AppendBlock(std::shared_ptr<Block> block);
626 };
627
633 class Module
634 {
635 public:
637 std::shared_ptr<Block> start_block;
639 std::vector<Hunk> hunks;
646 std::shared_ptr<Block> end_block;
647
648 bool IsExecutable() const;
649 offset_t ImageSize() const;
650 void ReadFile(Linker::Reader& rd, std::shared_ptr<Block>& next_block, offset_t end);
651 void WriteFile(Linker::Writer& wr) const;
652 void Dump(Dumper::Dumper& dump, offset_t current_offset, unsigned index) const;
653
655 offset_t GetHunkSizeInHeader(uint32_t index) const;
656 };
657
662 std::vector<Module> modules;
663
664 bool IsExecutable() const;
665
666 offset_t ImageSize() const override;
667
668 void ReadFile(Linker::Reader& rd) override;
669
671 offset_t WriteFile(Linker::Writer& wr) const override;
672 void Dump(Dumper::Dumper& dump) const override;
673
674 static std::string ReadString(uint32_t longword_count, Linker::Reader& rd);
675 static std::string ReadString(Linker::Reader& rd, uint32_t& longword_count);
676 static std::string ReadString(Linker::Reader& rd);
677 static void WriteStringContents(Linker::Writer& wr, std::string name);
678 static void WriteString(Linker::Writer& wr, std::string name);
679 static offset_t MeasureString(std::string name);
680
681 /* * * Writer members * * */
682
684 {
685 public:
686 Linker::Option<std::optional<std::string>> system{"system", "Target system version, determines generated hunk types, permitted options: v1, v37, v38, v39"};
687
689 {
690 InitializeFields(system);
691 }
692 };
693
694 enum cpu_type
695 {
696 CPU_M68K = Block::HUNK_CODE,
697 CPU_PPC = Block::HUNK_PPC_CODE,
698 };
699 cpu_type cpu = CPU_PPC;
700
702 {
703 V1,
707 V38, // TODO: not sure about name, so called because it is newer than V37 but older than V39
709 V39, // TODO: not yet implemented
710 };
711 system_version system = V1;
712
713 HunkFormat() = default;
714
716 : system(system)
717 {
718 }
719
720 /* @brief Convenience map to make it easier to look up the indices of segments */
721 std::map<std::shared_ptr<Linker::Segment>, size_t> segment_index;
722
723 unsigned FormatAdditionalSectionFlags(std::string section_name) const override;
724
736
737 std::shared_ptr<Linker::OptionCollector> GetOptions() override;
738
739 void SetOptions(std::map<std::string, std::string>& options) override;
740
741 void AddHunk(const Hunk& hunk);
742
743 void OnNewSegment(std::shared_ptr<Linker::Segment> segment) override;
744
745 std::unique_ptr<Script::List> GetScript(Linker::Module& module);
746
747 void Link(Linker::Module& module);
748
749 void ProcessModule(Linker::Module& module) override;
750
751 void CalculateValues() override;
752
753 void GenerateFile(std::string filename, Linker::Module& module) override;
754
756 std::string GetDefaultExtension(Linker::Module& module) const override;
757
758 };
759
760}
761
762#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:254
uint32_t size
Size of memory in 4-byte longwords.
Definition hunk.h:257
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:400
uint32_t GetSize() const override
The actual size of the segment data, as a count of 32-bit longwords.
Definition hunk.cc:405
void ReadBody(Linker::Reader &rd, uint32_t longword_count) override
Reads the segment data (if any)
Definition hunk.cc:410
Represents a HUNK_DEBUG block.
Definition hunk.h:428
void Write(Linker::Writer &wr) const override
Writes the entire block into a file.
Definition hunk.cc:910
void Read(Linker::Reader &rd) override
Reads the rest of the block after the type word.
Definition hunk.cc:904
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:919
Represents the first block inside of an executable file, a HUNK_HEADER.
Definition hunk.h:156
void Read(Linker::Reader &rd) override
Reads the rest of the block after the type word.
Definition hunk.cc:181
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:217
void Write(Linker::Writer &wr) const override
Writes the entire block into a file.
Definition hunk.cc:200
The smallest loadable unit of a Hunk file is the hunk, it roughly corresponds to a segment in other f...
Definition hunk.h:562
std::map< std::string, std::set< Relocation > > externals
External relocations, grouped according to name of symbol (only for object files)
Definition hunk.h:608
void ProduceBlocks(HunkFormat &fmt, Module &module)
Converts the data collected by the linker into hunk blocks.
Definition hunk.cc:1195
uint32_t GetFileSize() const
The amount of bytes this hunk will take up in the file.
Definition hunk.cc:1391
offset_t image_size
Size of the memory image, if it is a zero filled segment (bss)
Definition hunk.h:585
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:1402
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:1430
uint32_t GetMemorySize() const
The amount of memory this hunk will take up after loading.
Definition hunk.cc:1371
std::map< uint32_t, std::set< Relocation > > relocations
Internal relocations, grouped according to addressed hunk number.
Definition hunk.h:605
std::vector< std::shared_ptr< Block > > blocks
The sequence of blocks the hunk is stored as.
Definition hunk.h:565
std::shared_ptr< Linker::Contents > image
The memory image, if stored in a file (that is, a non-bss segment)
Definition hunk.h:583
Definition hunk.h:501
void Write(Linker::Writer &wr) const override
Writes the entire block into a file.
Definition hunk.cc:1153
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:1173
void Read(Linker::Reader &rd) override
Reads the rest of the block after the type word.
Definition hunk.cc:1131
Represents a HUNK_LIB block.
Definition hunk.h:481
void Read(Linker::Reader &rd) override
Reads the rest of the block after the type word.
Definition hunk.cc:996
void Write(Linker::Writer &wr) const override
Writes the entire block into a file.
Definition hunk.cc:1005
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:1012
Represents the load block of a non-bss segment (hunk) HUNK_CODE/HUNK_DATA/HUNK_PPC_CODE,...
Definition hunk.h:234
uint32_t GetSize() const override
The actual size of the segment data, as a count of 32-bit longwords.
Definition hunk.cc:379
void WriteBody(Linker::Writer &wr) const override
Writes the segment data (if any)
Definition hunk.cc:389
void ReadBody(Linker::Reader &rd, uint32_t longword_count) override
Reads the segment data (if any)
Definition hunk.cc:384
Module is a program unit containing several hunks.
Definition hunk.h:634
std::vector< Hunk > hunks
The hunks in this module. Hunks in a library are stored inside a HUNK_LIB.
Definition hunk.h:639
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:637
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:1672
std::shared_ptr< Block > end_block
A final block before the start of the next module.
Definition hunk.h:646
Represents a HUNK_OVERLAY block.
Definition hunk.h:448
void Read(Linker::Reader &rd) override
Reads the rest of the block after the type word.
Definition hunk.cc:939
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:978
void Write(Linker::Writer &wr) const override
Writes the entire block into a file.
Definition hunk.cc:959
Represents the block that gives the memory loaded contents of the hunk (segment)
Definition hunk.h:179
virtual void WriteBody(Linker::Writer &wr) const
Writes the segment data (if any)
Definition hunk.cc:341
uint32_t GetSizeField() const
Returns the 32-bit longword that stores the size of the segment plus 2 flag bits.
Definition hunk.cc:264
uint32_t GetAdditionalFlags() const
The contents of an additional 32-bit longword is needed for flags.
Definition hunk.cc:278
void Read(Linker::Reader &rd) override
Reads the rest of the block after the type word.
Definition hunk.cc:283
virtual void ReadBody(Linker::Reader &rd, uint32_t longword_count)
Reads the segment data (if any)
Definition hunk.cc:337
bool RequiresAdditionalFlags() const
Returns true if an additional 32-bit longword is needed for flags.
Definition hunk.cc:273
void Write(Linker::Writer &wr) const override
Writes the entire block into a file.
Definition hunk.cc:298
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:307
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:275
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:531
bool IsShortRelocationBlock() const
Whether this is a HUNK_RELOC32SHORT block (needed because V37 gives it a different number)
Definition hunk.cc:423
void Write(Linker::Writer &wr) const override
Writes the entire block into a file.
Definition hunk.cc:505
void Read(Linker::Reader &rd) override
Reads the rest of the block after the type word.
Definition hunk.cc:477
void Write(Linker::Writer &wr) const override
Write entire unit.
Definition hunk.cc:804
void Read(Linker::Reader &rd) override
Read data after type and name.
Definition hunk.cc:794
offset_t FileSize() const override
Size of entire unit, including type and name fields.
Definition hunk.cc:815
void Write(Linker::Writer &wr) const override
Write entire unit.
Definition hunk.cc:665
void Read(Linker::Reader &rd) override
Read data after type and name.
Definition hunk.cc:660
offset_t FileSize() const override
Size of entire unit, including type and name fields.
Definition hunk.cc:671
offset_t FileSize() const override
Size of entire unit, including type and name fields.
Definition hunk.cc:773
void Read(Linker::Reader &rd) override
Read data after type and name.
Definition hunk.cc:754
void Write(Linker::Writer &wr) const override
Write entire unit.
Definition hunk.cc:763
virtual void Read(Linker::Reader &rd)
Read data after type and name.
Definition hunk.cc:635
virtual offset_t FileSize() const
Size of entire unit, including type and name fields.
Definition hunk.cc:645
virtual void Write(Linker::Writer &wr) const
Write entire unit.
Definition hunk.cc:639
Represents a HUNK_EXT or HUNK_SYMBOL block.
Definition hunk.h:306
void Read(Linker::Reader &rd) override
Reads the rest of the block after the type word.
Definition hunk.cc:827
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:847
void Write(Linker::Writer &wr) const override
Writes the entire block into a file.
Definition hunk.cc:838
Represents the first block inside of an object file or a hunk. This class is used for HUNK_UNIT and H...
Definition hunk.h:140
void Write(Linker::Writer &wr) const override
Writes the entire block into a file.
Definition hunk.cc:168
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:174
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:1806
void ProcessModule(Linker::Module &module) override
Processes the module object and initializes format fields.
Definition hunk.cc:1952
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition hunk.cc:1729
offset_t ImageSize() const override
Retrieves size of stored data.
Definition hunk.cc:1692
system_version
Definition hunk.h:702
@ V38
generate HUNK_RELOC32SHORT instead of HUNK_V37_RELOC32SHORT
Definition hunk.h:707
@ V39
generate HUNK_RELRELOC32
Definition hunk.h:709
@ V37
generate HUNK_V37_RELOC32SHORT
Definition hunk.h:705
offset_t WriteFile(Linker::Writer &wr) const override
Stores data in memory to file.
Definition hunk.cc:1717
std::vector< Module > modules
A collection of modules/program units.
Definition hunk.h:662
void GenerateFile(std::string filename, Linker::Module &module) override
The main function that handles processing, calculating and generating the final image.
Definition hunk.cc:2039
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:1801
void CalculateValues() override
Intermediate step between processing module and generating output file to set up headers and manageme...
Definition hunk.cc:2035
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:1851
void ReadFile(Linker::Reader &rd) override
Loads file into memory.
Definition hunk.cc:1702
flags
Definition hunk.h:726
@ ChipMemory
Section to be stored in chip memory.
Definition hunk.h:734
@ FastMemory
Section to be stored in fast memory.
Definition hunk.h:730
std::string GetDefaultExtension(Linker::Module &module) const override
Provides a default filename for the output file.
Definition hunk.cc:2049
An abstract interface that separates structure and presentation of the data inside a file.
Definition dumper.h:828
A brief record, such as a relocation or imported library.
Definition dumper.h:742
A record that represents a region within the file.
Definition dumper.h:721
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:474
Documents and handles command line options.
Definition options.h:306
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: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
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