33 enum compatibility_type
44 std::shared_ptr<Linker::Image> image;
53 PreloadPages = 0x0040,
54 InvalidPages = 0x0080,
55 ZeroFilledPages = 0x0100,
57 ResidentContiguous = 0x0300,
58 ResidentLongLockable = 0x0400,
66 flag_type flags = flag_type(0);
67 uint32_t page_table_index = 0;
68 uint32_t page_entry_count = 0;
69 uint32_t data_pages_offset = 0;
75 Object(std::shared_ptr<Linker::Segment> segment,
unsigned flags)
76 : image(segment), flags(flag_type(flags))
85 std::vector<std::shared_ptr<Linker::Image>> pages;
96 std::shared_ptr<Linker::Image> image;
100 SegmentPage(std::shared_ptr<Linker::Image> image, offset_t offset, offset_t size)
101 : image(image), offset(offset), size(size)
108 std::shared_ptr<const Linker::ActualImage>
AsImage()
const override;
117 std::vector<uint8_t> data;
119 std::vector<IterationRecord> records;
131 : iterated_page(iterated_page)
148 uint32_t fixup_table_index;
173 uint32_t fixup_offset = 0;
188 SourceTypeMask = 0x0F,
193 source_type type = source_type(0);
210 flag_type flags = flag_type(0);
213 uint32_t addition = 0;
216 : Writer(::LittleEndian)
220 Relocation(
unsigned type,
unsigned flags, uint16_t offset, uint16_t module, uint32_t target = 0, uint32_t addition = 0)
221 : Writer(::LittleEndian), type(source_type(type)), flags(flag_type(flags)), module(module), target(target), addition(addition)
223 sources.push_back(Chain{offset});
228 bool IsExternal()
const;
230 bool IsSelectorOrOffset()
const;
232 bool ComesBefore()
const;
234 size_t GetSourceSize()
const;
246 std::vector<ChainLink> chains;
249 std::vector<Chain> sources;
253 void DecrementSingleSourceOffset(
size_t amount);
255 bool IsSelector()
const;
256 bool IsSourceList()
const;
257 bool IsAdditive()
const;
258 size_t GetTargetSize()
const;
259 size_t GetAdditiveSize()
const;
260 size_t GetModuleSize()
const;
261 size_t GetOrdinalSize()
const;
263 uint16_t GetFirstSource()
const;
265 void CalculateSizes(compatibility_type compatibility);
267 size_t GetSize()
const;
272 std::map<uint16_t, Relocation> relocations;
273 uint32_t checksum = 0;
274 std::shared_ptr<Linker::Image> image;
282 Page(uint16_t fixup_table_index, uint8_t type)
283 : le{fixup_table_index, type}
287 Page(uint32_t offset, uint16_t size, uint8_t flags)
288 : lx{offset, size, flags}
293 static Page LEPage(uint16_t fixup_table_index, uint8_t type);
295 static Page LXPage(uint32_t offset, uint16_t size, uint8_t flags);
301 uint16_t type = 0, name = 0;
311 uint16_t ordinal = 0;
325 entry_type type = Unused;
332 flag_type flags = flag_type(0);
336 : Writer(::LittleEndian)
340 Entry(
unsigned type, uint16_t
object,
unsigned flags, uint32_t offset)
341 : Writer(::LittleEndian), type(entry_type(type)), object(
object), flags(flag_type(flags)), offset(offset)
345 mutable bool same_bundle =
false;
347 bool SameBundle(
const Entry& other)
const;
349 offset_t GetEntryHeadSize()
const;
351 offset_t GetEntryBodySize()
const;
364 enum directive_number : uint16_t
366 VerifyRecordDirective = 0x8001,
367 LanguageInformationDirective = 0x0002,
368 CoProcessorRequiredSupportTable = 0x0003,
369 ThreadStateInitializationDirective = 0x0004,
370 CSetBrowseInformation = 0x0005,
372 static constexpr uint16_t ResidentFlagMask = 0x8000;
373 directive_number directive = directive_number(0);
377 bool IsResident()
const;
380 ::EndianType endiantype = ::LittleEndian;
385 bool IsExtendedFormat()
const;
387 uint32_t format_level = 0;
413 system_type system = system_type(0);
415 uint32_t module_version = 0;
419 PreProcessInitialization = 0x00000004,
420 NoInternalFixup = 0x00000010,
421 NoExternalFixup = 0x00000020,
422 FullScreen = 0x00000100,
423 GUIAware = 0x00000200,
425 ErrorInImage = 0x00002000,
426 Library = 0x00008000,
427 ProtectedMemoryLibrary = 0x00018000,
428 PhysicalDriver = 0x00020000,
429 VirtualDriver = 0x00028000,
430 PerProcessTermination = 0x40000000,
432 uint32_t module_flags = 0;
434 uint32_t page_count = 0, page_size = 0x1000;
435 uint32_t eip_object = 0, eip_value = 0, esp_object = 0, esp_value = 0;
438 uint32_t last_page_size;
439 uint32_t page_offset_shift;
441 uint32_t fixup_section_size = 0, fixup_section_checksum = 0;
442 uint32_t loader_section_size = 0, loader_section_checksum = 0;
443 uint32_t object_table_offset = 0, object_page_table_offset = 0, object_iterated_pages_offset = 0;
444 uint32_t resource_table_offset = 0, resource_table_entry_count = 0, resident_name_table_offset = 0;
445 uint32_t entry_table_offset = 0, module_directives_offset = 0, fixup_page_table_offset = 0, fixup_record_table_offset = 0;
446 uint32_t imported_module_table_offset = 0, imported_procedure_table_offset = 0;
447 uint32_t per_page_checksum_offset = 0;
448 uint32_t data_pages_offset = 0, preload_page_count = 0;
449 uint32_t nonresident_name_table_offset = 0, nonresident_name_table_size = 0, nonresident_name_table_checksum = 0;
450 uint32_t automatic_data = 0;
451 uint32_t debug_info_offset = 0, debug_info_size = 0, instance_preload_page_count = 0, instance_demand_page_count = 0;
452 uint32_t stack_size = 0, heap_size = 0;
454 uint32_t vxd_version_info_resource_offset = 0;
455 uint32_t vxd_version_info_resource_length = 0;
456 uint16_t vxd_device_id = 0;
457 uint16_t vxd_ddk_version = 0;
459 std::vector<Object> objects;
460 std::vector<ModuleDirective> module_directives;
462 std::vector<Page> pages;
463 std::map<uint16_t, std::map<uint16_t, Resource>> resources;
464 std::vector<Name> resident_names, nonresident_names;
465 std::vector<Entry> entries;
466 std::vector<std::string> imported_modules, imported_procedures;
468 offset_t file_size = offset_t(-1);
475 LEFormat(
unsigned system,
unsigned module_flags,
bool extended_format)
476 : system(system_type(system)), module_flags(module_flags), last_page_size(0)
482 bool IsLibrary()
const;
484 bool IsDriver()
const;
496 offset_t GetPageOffset(uint32_t index)
const;
497 offset_t GetPageSize(uint32_t index)
const;
508 InitializeFields(stub);
512 static std::shared_ptr<LEFormat> CreateConsoleApplication(system_type system = OS2);
514 static std::shared_ptr<LEFormat> CreateGUIApplication(system_type system = OS2);
516 static std::shared_ptr<LEFormat> CreateLibraryModule(system_type system = OS2);
518 std::shared_ptr<LEFormat> SimulateLinker(compatibility_type compatibility);
522 compatibility_type compatibility = CompatibleNone;
525 std::string program_name, module_name;
531 unsigned FormatAdditionalSectionFlags(std::string section_name)
const override;
535 void GetRelocationOffset(
Object&
object,
size_t offset,
size_t& page_index, uint16_t& page_offset);
536 void AddRelocation(
Object&
object,
unsigned type,
unsigned flags,
size_t offset, uint16_t module, uint32_t target = 0, uint32_t addition = 0);
538 std::shared_ptr<Linker::Segment> stack, heap;
539 std::map<std::shared_ptr<Linker::Segment>,
size_t> object_index;
540 std::map<std::string, uint32_t> imported_procedure_name_offsets;
541 offset_t imported_procedure_names_length = 0;
543 unsigned GetDefaultObjectFlags()
const;
544 void AddObject(
const Object&
object);
545 uint16_t FetchImportedModuleName(std::string name);
546 uint16_t FetchImportedProcedureName(std::string name);
549 uint8_t CountBundles(
size_t entry_index)
const;
551 static std::vector<Linker::OptionDescription<void> *> ParameterNames;
553 std::shared_ptr<Linker::OptionCollector>
GetOptions()
override;
554 void SetOptions(std::map<std::string, std::string>& options)
override;
555 void OnNewSegment(std::shared_ptr<Linker::Segment> segment)
override;