6#include "../dumper/dumper.h"
7#include "../linker/module.h"
8#include "../linker/options.h"
9#include "../linker/segment.h"
10#include "../linker/segment_manager.h"
11#include "../linker/writer.h"
51 ::EndianType endiantype = ::UndefinedEndian;
240 static constexpr uint16_t MID_UNKNOWN = 0x000;
241 static constexpr uint16_t MID_68010 = 0x001;
242 static constexpr uint16_t MID_68020 = 0x002;
243 static constexpr uint16_t MID_PC386 = 0x064;
244 static constexpr uint16_t MID_I386 = 0x086;
245 static constexpr uint16_t MID_ARM6 = 0x08F;
246 static constexpr uint16_t MID_MIPS1 = 0x097;
247 static constexpr uint16_t MID_MIPS2 = 0x098;
248 static constexpr uint16_t MID_HP200 = 0x0C8;
249 static constexpr uint16_t MID_HP300 = 0x12C;
250 static constexpr uint16_t MID_HPUX800 = 0x20B;
251 static constexpr uint16_t MID_HPUX = 0x20C;
254 static constexpr uint16_t MID_LINUX_OLDSUN2 = 0x000;
255 static constexpr uint16_t MID_LINUX_SPARC = 0x003;
258 static constexpr uint16_t MID_FREEBSD_SPARC = 0x08C;
261 static constexpr uint16_t MID_NETBSD_M68K = 0x087;
262 static constexpr uint16_t MID_NETBSD_M68K4K = 0x088;
263 static constexpr uint16_t MID_NETBSD_NS32532K = 0x089;
264 static constexpr uint16_t MID_NETBSD_SPARC = 0x08A;
265 static constexpr uint16_t MID_NETBSD_PMAX = 0x08B;
266 static constexpr uint16_t MID_NETBSD_VAX1K = 0x08C;
267 static constexpr uint16_t MID_NETBSD_ALPHA = 0x08D;
268 static constexpr uint16_t MID_NETBSD_MIPS = 0x08E;
269 static constexpr uint16_t MID_NETBSD_M680002K = 0x090;
270 static constexpr uint16_t MID_NETBSD_SH3 = 0x091;
271 static constexpr uint16_t MID_NETBSD_POWERPC64 = 0x094;
272 static constexpr uint16_t MID_NETBSD_POWERPC = 0x095;
273 static constexpr uint16_t MID_NETBSD_VAX = 0x096;
274 static constexpr uint16_t MID_NETBSD_M88K = 0x099;
275 static constexpr uint16_t MID_NETBSD_HPPA = 0x09A;
276 static constexpr uint16_t MID_NETBSD_SH5_64 = 0x09B;
277 static constexpr uint16_t MID_NETBSD_SPARC64 = 0x09C;
278 static constexpr uint16_t MID_NETBSD_X86_64 = 0x09D;
279 static constexpr uint16_t MID_NETBSD_SH5_32 = 0x09E;
280 static constexpr uint16_t MID_NETBSD_IA64 = 0x09F;
281 static constexpr uint16_t MID_NETBSD_AARCH64 = 0x0B7;
282 static constexpr uint16_t MID_NETBSD_OR1K = 0x0B8;
283 static constexpr uint16_t MID_NETBSD_RISCV = 0x0B9;
285 static constexpr uint16_t MID_BFD_ARM = 0x067;
315 constexpr offset_t GetRelocationSize()
const
354 cpu_type cpu = UNKNOWN;
362 uint32_t code_size = 0;
363 uint32_t data_size = 0;
364 uint32_t bss_size = 0;
365 uint32_t symbol_table_size = 0;
366 uint32_t entry_address = 0;
368 uint16_t reserved = 0;
369 uint16_t relocations_suppressed = 0;
371 uint32_t code_relocation_size = 0;
372 uint32_t data_relocation_size = 0;
374 uint16_t environment_stamp = 0;
426 std::vector<Relocation> code_relocations, data_relocations;
428 std::shared_ptr<Linker::Contents> code, data, bss;
431 bool AttemptFetchMagic(uint8_t signature[4]);
435 bool AttemptReadFileWithCurrentSettings(
Linker::Reader& rd, uint8_t signature[4], offset_t image_size);
437 struct read_attempt_type
440 ::EndianType midmag_endiantype;
443 bool AttemptReadFile(
Linker::Reader& rd, uint8_t signature[4], offset_t image_size, read_attempt_type first_attempt)
448 template <
typename ... read_attempt_types>
449 bool AttemptReadFile(
Linker::Reader& rd, uint8_t signature[4], offset_t image_size, read_attempt_type first_attempt, read_attempt_types ... remaining_attempts)
454 if(!AttemptReadFileWithCurrentSettings(rd, signature, image_size))
456 return AttemptReadFile(rd, signature, image_size, remaining_attempts...);
478 offset_t name_offset = 0;
479 uint32_t type_etc = 0;
494 uint16_t GetTypeByte(
const AOutFormat& aout)
const;
495 segment_type GetType(
const AOutFormat& aout)
const;
496 bool IsExternal(
const AOutFormat& aout)
const;
499 std::vector<Symbol> symbols;
501 mutable uint32_t page_size = 0;
503 uint32_t GetPageSize()
const;
504 uint32_t GetTextOffset()
const;
505 uint32_t GetTextAddress()
const;
506 uint32_t GetDataOffsetAlign()
const;
507 uint32_t GetDataAddressAlign()
const;
619 { Version1,
"UNIX Version 1" },
620 { Version2,
"UNIX Version 2" },
621 { Version3,
"UNIX Version 3" },
622 { Version4,
"UNIX Version 4" },
623 { Version5,
"UNIX Version 5" },
624 { Version6,
"UNIX Version 6" },
625 { Version7,
"UNIX Version 7" },
626 { SystemIII,
"UNIX System III" },
627 { SystemV,
"UNIX System V" },
628 { AnyBSD,
"2.11BSD (16-bit) or 4.3BSD (32-bit)" },
648 "SEPARATE", MAGIC_SEPARATE,
655 {
OMAGIC,
"Impure executable (OMAGIC)" },
656 {
NMAGIC,
"Pure executable (NMAGIC)" },
657 {
ZMAGIC,
"Demand paged (ZMAGIC)" },
658 {
QMAGIC,
"Demand paged with unmapped page zero (QMAGIC)" },
659 { MAGIC_SEPARATE,
"Separate instruction and data spaces (PDP-11 only)" },
677 AOutOptionCollector()
679 InitializeFields(stub, unix_v, type, magic, Nflag, nflag, iflag, zflag, Oflag);
686 static std::vector<Linker::OptionDescription<void> *> ParameterNames;
689 std::shared_ptr<Linker::OptionCollector>
GetOptions()
override;
691 void SetOptions(std::map<std::string, std::string>& options)
override;
693 void OnNewSegment(std::shared_ptr<Linker::Segment> segment)
override;
695 void CreateDefaultSegments();
701 std::shared_ptr<Linker::Segment> GetCodeSegment();
703 std::shared_ptr<Linker::Segment> GetDataSegment();
705 std::shared_ptr<Linker::Segment> GetBssSegment();
An abstract interface that separates structure and presentation of the data inside a file.
Definition dumper.h:773
A representation of an enumeration with associated string representations for each value.
Definition options.h:15
std::map< value_type, std::string > descriptions
An empty dictionary that explains the value types in detail.
Definition options.h:20
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
A helper class, encapsulating functionality needed to import binary data.
Definition reader.h:20
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