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::Contents> 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 bool ContainsRelocations() const;
377
378 size_t GetRelocationSize() const;
379
380 Relocation::relocation_type GetRelocationType() const;
381
382 void Read(Linker::Reader& rd) override;
384 void Write(Linker::Writer& wr) const override;
386 offset_t FileSize() const override;
387 void DumpContents(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
388 };
389
391 {
392 public:
393 uint32_t size;
394
395 CommonReferences(symbol_type type, std::string name, uint32_t size = 0)
396 : References(type, name), size(size)
397 {
398 }
399
400 void Read(Linker::Reader& rd) override;
402 void Write(Linker::Writer& wr) const override;
404 offset_t FileSize() const override;
405 void AddExtraFields(Dumper::Dumper& dump, Dumper::Entry& entry, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
406 };
407
408 std::vector<std::unique_ptr<Unit>> symbols;
409
411 : Block(type)
412 {
413 }
414
415 void Read(Linker::Reader& rd) override;
416 void Write(Linker::Writer& wr) const override;
417 offset_t FileSize() const override;
418 void Dump(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
419 };
420
422 class DebugBlock : public Block
423 {
424 public:
425 // TODO: untested
426 std::shared_ptr<Linker::Contents> image;
427
428 DebugBlock()
430 {
431 }
432
433 void Read(Linker::Reader& rd) override;
434 void Write(Linker::Writer& wr) const override;
435 offset_t FileSize() const override;
436
437 void Dump(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
438 };
439
441 class OverlayBlock : public Block
442 {
443 public:
444 // TODO: untested
445 uint32_t maximum_level = 2;
446
448 {
449 uint32_t offset;
450 uint32_t res1, res2;
451 uint32_t level;
452 uint32_t ordinate;
453 uint32_t first_hunk;
454 uint32_t symbol_hunk;
455 uint32_t symbol_offset;
456 };
457
458 std::vector<OverlaySymbol> overlay_data_table;
459
461 : Block(HUNK_OVERLAY)
462 {
463 }
464
465 void Read(Linker::Reader& rd) override;
466 void Write(Linker::Writer& wr) const override;
467 offset_t FileSize() const override;
468
469 void Dump(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
470 };
471
473 class LibraryBlock : public Block
474 {
475 public:
476 // TODO: untested
477
478 std::unique_ptr<Module> hunks;
479
481 : Block(HUNK_LIB)
482 {
483 }
484
485 void Read(Linker::Reader& rd) override;
486 void Write(Linker::Writer& wr) const override;
487 offset_t FileSize() const override;
488
489 void Dump(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
490 };
491
492 class IndexBlock : public Block
493 {
494 public:
495 // TODO: untested
496
498 {
499 public:
500 uint16_t string_offset = 0;
501 uint16_t symbol_offset = 0;
502 uint16_t type = 0;
503
504 static Definition Read(Linker::Reader& rd);
505 void Write(Linker::Writer& wr) const;
506 };
507
509 {
510 public:
511 uint16_t string_offset = 0;
512 uint16_t hunk_size = 0; // in longwords
513 uint16_t hunk_type = 0;
514 std::vector<uint16_t> references;
515 std::vector<Definition> definitions;
516
517 static HunkEntry Read(Linker::Reader& rd);
518 void Write(Linker::Writer& wr) const;
519 offset_t FileSize() const;
520 };
521
523 {
524 public:
525 int16_t string_offset = 0;
526 uint16_t first_hunk_offset = 0; // in longwords
527 std::vector<HunkEntry> hunks;
528
529 static ProgramUnit Read(Linker::Reader& rd);
530 void Write(Linker::Writer& wr) const;
531 offset_t FileSize() const;
532 };
533
534 std::vector<std::string> strings;
535 std::vector<ProgramUnit> units;
536
537 IndexBlock()
538 : Block(HUNK_INDEX)
539 {
540 }
541
542 offset_t StringTableSize() const;
543
544 void Read(Linker::Reader& rd) override;
545 void Write(Linker::Writer& wr) const override;
546 offset_t FileSize() const override;
547
548 void Dump(Dumper::Dumper& dump, const Module& module, const Hunk * hunk, unsigned index, offset_t current_offset) const override;
549 };
550
552 class Hunk
553 {
554 public:
556 std::vector<std::shared_ptr<Block>> blocks;
557
558 enum hunk_type : uint32_t
559 {
560 Undefined = 0,
561 Invalid = uint32_t(-1),
562
563 Code = Block::HUNK_CODE,
564 CodePPC = Block::HUNK_PPC_CODE,
565 Data = Block::HUNK_DATA,
566 Bss = Block::HUNK_BSS,
567 };
568 hunk_type type = Undefined;
569
570 // TODO: implement advisory flag
571
572 LoadBlock::flag_type flags = LoadBlock::LoadPublic;
574 std::shared_ptr<Linker::Contents> image;
576 offset_t image_size = 0;
577
578 std::string name;
579
580 explicit Hunk()
581 : type(Undefined), flags(LoadBlock::LoadAny), image(nullptr)
582 {
583 }
584
585 Hunk(hunk_type type, std::string name = "image", unsigned flags = LoadBlock::LoadAny)
586 : type(hunk_type(type)), flags(LoadBlock::flag_type(flags)), image(std::make_shared<Linker::Segment>(name))
587 {
588 }
589
590 Hunk(hunk_type type, std::shared_ptr<Linker::Segment> segment, unsigned flags = LoadBlock::LoadAny)
591 : type(hunk_type(type)), flags(LoadBlock::flag_type(flags)), image(segment)
592 {
593 }
594
596 std::map<uint32_t, std::set<Relocation>> relocations;
597
599 std::map<std::string, std::set<Relocation>> externals;
600
601 // TODO: also store defined variables, common variables (only for object files) */
602
604 void ProduceBlocks(HunkFormat& fmt, Module& module);
605
607 uint32_t GetMemorySize() const;
608
610 uint32_t GetFileSize() const;
611
613 uint32_t GetSizeField(HunkFormat& fmt, Module& module);
614
616 void AppendBlock(std::shared_ptr<Block> block);
617 };
618
624 class Module
625 {
626 public:
628 std::shared_ptr<Block> start_block;
630 std::vector<Hunk> hunks;
637 std::shared_ptr<Block> end_block;
638
639 bool IsExecutable() const;
640 offset_t ImageSize() const;
641 void ReadFile(Linker::Reader& rd, std::shared_ptr<Block>& next_block, offset_t end);
642 void WriteFile(Linker::Writer& wr) const;
643 void Dump(Dumper::Dumper& dump, offset_t current_offset, unsigned index) const;
644
646 offset_t GetHunkSizeInHeader(uint32_t index) const;
647 };
648
653 std::vector<Module> modules;
654
655 bool IsExecutable() const;
656
657 offset_t ImageSize() const override;
658
659 void ReadFile(Linker::Reader& rd) override;
660
662 offset_t WriteFile(Linker::Writer& wr) const override;
663 void Dump(Dumper::Dumper& dump) const override;
664
665 static std::string ReadString(uint32_t longword_count, Linker::Reader& rd);
666 static std::string ReadString(Linker::Reader& rd, uint32_t& longword_count);
667 static std::string ReadString(Linker::Reader& rd);
668 static void WriteStringContents(Linker::Writer& wr, std::string name);
669 static void WriteString(Linker::Writer& wr, std::string name);
670 static offset_t MeasureString(std::string name);
671
672 /* * * Writer members * * */
673
675 {
676 public:
677 Linker::Option<std::optional<std::string>> system{"system", "Target system version, determines generated hunk types, permitted options: v1, v37, v38, v39"};
678
680 {
681 InitializeFields(system);
682 }
683 };
684
685 enum cpu_type
686 {
687 CPU_M68K = Block::HUNK_CODE,
688 CPU_PPC = Block::HUNK_PPC_CODE,
689 };
690 cpu_type cpu = CPU_PPC;
691
693 {
694 V1,
698 V38, // TODO: not sure about name, so called because it is newer than V37 but older than V39
700 V39, // TODO: not yet implemented
701 };
702 system_version system = V1;
703
704 HunkFormat() = default;
705
707 : system(system)
708 {
709 }
710
711 /* @brief Convenience map to make it easier to look up the indices of segments */
712 std::map<std::shared_ptr<Linker::Segment>, size_t> segment_index;
713
714 unsigned FormatAdditionalSectionFlags(std::string section_name) const override;
715
727
728 std::shared_ptr<Linker::OptionCollector> GetOptions() override;
729
730 void SetOptions(std::map<std::string, std::string>& options) override;
731
732 void AddHunk(const Hunk& hunk);
733
734 void OnNewSegment(std::shared_ptr<Linker::Segment> segment) override;
735
736 std::unique_ptr<Script::List> GetScript(Linker::Module& module);
737
738 void Link(Linker::Module& module);
739
740 void ProcessModule(Linker::Module& module) override;
741
742 void CalculateValues() override;
743
744 void GenerateFile(std::string filename, Linker::Module& module) override;
745
747 std::string GetDefaultExtension(Linker::Module& module) const override;
748
749 };
750
751}
752
753#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:385
uint32_t GetSize() const override
The actual size of the segment data, as a count of 32-bit longwords.
Definition hunk.cc:390
void ReadBody(Linker::Reader &rd, uint32_t longword_count) override
Reads the segment data (if any)
Definition hunk.cc:395
Represents a HUNK_DEBUG block.
Definition hunk.h:423
void Write(Linker::Writer &wr) const override
Writes the entire block into a file.
Definition hunk.cc:885
void Read(Linker::Reader &rd) override
Reads the rest of the block after the type word.
Definition hunk.cc:879
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:894
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:553
std::map< std::string, std::set< Relocation > > externals
External relocations, grouped according to name of symbol (only for object files)
Definition hunk.h:599
void ProduceBlocks(HunkFormat &fmt, Module &module)
Converts the data collected by the linker into hunk blocks.
Definition hunk.cc:1150
uint32_t GetFileSize() const
The amount of bytes this hunk will take up in the file.
Definition hunk.cc:1346
offset_t image_size
Size of the memory image, if it is a zero filled segment (bss)
Definition hunk.h:576
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:1357
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:1385
uint32_t GetMemorySize() const
The amount of memory this hunk will take up after loading.
Definition hunk.cc:1326
std::map< uint32_t, std::set< Relocation > > relocations
Internal relocations, grouped according to addressed hunk number.
Definition hunk.h:596
std::vector< std::shared_ptr< Block > > blocks
The sequence of blocks the hunk is stored as.
Definition hunk.h:556
std::shared_ptr< Linker::Contents > image
The memory image, if stored in a file (that is, a non-bss segment)
Definition hunk.h:574
Definition hunk.h:493
void Write(Linker::Writer &wr) const override
Writes the entire block into a file.
Definition hunk.cc:1113
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:1133
void Read(Linker::Reader &rd) override
Reads the rest of the block after the type word.
Definition hunk.cc:1091
Represents a HUNK_LIB block.
Definition hunk.h:474
void Read(Linker::Reader &rd) override
Reads the rest of the block after the type word.
Definition hunk.cc:961
void Write(Linker::Writer &wr) const override
Writes the entire block into a file.
Definition hunk.cc:970
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:977
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:364
void WriteBody(Linker::Writer &wr) const override
Writes the segment data (if any)
Definition hunk.cc:374
void ReadBody(Linker::Reader &rd, uint32_t longword_count) override
Reads the segment data (if any)
Definition hunk.cc:369
Module is a program unit containing several hunks.
Definition hunk.h:625
std::vector< Hunk > hunks
The hunks in this module. Hunks in a library are stored inside a HUNK_LIB.
Definition hunk.h:630
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:628
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:1627
std::shared_ptr< Block > end_block
A final block before the start of the next module.
Definition hunk.h:637
Represents a HUNK_OVERLAY block.
Definition hunk.h:442
void Read(Linker::Reader &rd) override
Reads the rest of the block after the type word.
Definition hunk.cc:909
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:948
void Write(Linker::Writer &wr) const override
Writes the entire block into a file.
Definition hunk.cc:929
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:516
bool IsShortRelocationBlock() const
Whether this is a HUNK_RELOC32SHORT block (needed because V37 gives it a different number)
Definition hunk.cc:408
void Write(Linker::Writer &wr) const override
Writes the entire block into a file.
Definition hunk.cc:490
void Read(Linker::Reader &rd) override
Reads the rest of the block after the type word.
Definition hunk.cc:462
void Write(Linker::Writer &wr) const override
Write entire unit.
Definition hunk.cc:784
void Read(Linker::Reader &rd) override
Read data after type and name.
Definition hunk.cc:774
offset_t FileSize() const override
Size of entire unit, including type and name fields.
Definition hunk.cc:795
void Write(Linker::Writer &wr) const override
Write entire unit.
Definition hunk.cc:645
void Read(Linker::Reader &rd) override
Read data after type and name.
Definition hunk.cc:640
offset_t FileSize() const override
Size of entire unit, including type and name fields.
Definition hunk.cc:651
offset_t FileSize() const override
Size of entire unit, including type and name fields.
Definition hunk.cc:753
void Read(Linker::Reader &rd) override
Read data after type and name.
Definition hunk.cc:734
void Write(Linker::Writer &wr) const override
Write entire unit.
Definition hunk.cc:743
virtual void Read(Linker::Reader &rd)
Read data after type and name.
Definition hunk.cc:615
virtual offset_t FileSize() const
Size of entire unit, including type and name fields.
Definition hunk.cc:625
virtual void Write(Linker::Writer &wr) const
Write entire unit.
Definition hunk.cc:619
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:807
offset_t FileSize() const override
Returns the size of the block as stored inside a file.
Definition hunk.cc:827
void Write(Linker::Writer &wr) const override
Writes the entire block into a file.
Definition hunk.cc:818
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:1761
void ProcessModule(Linker::Module &module) override
Processes the module object and initializes format fields.
Definition hunk.cc:1907
void Dump(Dumper::Dumper &dump) const override
Display file contents in a nice manner.
Definition hunk.cc:1684
offset_t ImageSize() const override
Retrieves size of stored data.
Definition hunk.cc:1647
system_version
Definition hunk.h:693
@ V38
generate HUNK_RELOC32SHORT instead of HUNK_V37_RELOC32SHORT
Definition hunk.h:698
@ V39
generate HUNK_RELRELOC32
Definition hunk.h:700
@ V37
generate HUNK_V37_RELOC32SHORT
Definition hunk.h:696
offset_t WriteFile(Linker::Writer &wr) const override
Stores data in memory to file.
Definition hunk.cc:1672
std::vector< Module > modules
A collection of modules/program units.
Definition hunk.h:653
void GenerateFile(std::string filename, Linker::Module &module) override
The main function that handles processing, calculating and generating the final image.
Definition hunk.cc:1994
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:1756
void CalculateValues() override
Intermediate step between processing module and generating output file to set up headers and manageme...
Definition hunk.cc:1990
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:1806
void ReadFile(Linker::Reader &rd) override
Loads file into memory.
Definition hunk.cc:1657
flags
Definition hunk.h:717
@ ChipMemory
Section to be stored in chip memory.
Definition hunk.h:725
@ FastMemory
Section to be stored in fast memory.
Definition hunk.h:721
std::string GetDefaultExtension(Linker::Module &module) const override
Provides a default filename for the output file.
Definition hunk.cc:2004
An abstract interface that separates structure and presentation of the data inside a file.
Definition dumper.h:773
A brief record, such as a relocation or imported library.
Definition dumper.h:687
A record that represents a region within the file.
Definition dumper.h:666
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