@@ -1837,22 +1837,10 @@ template <typename PEHeaderTy> void Writer::writeHeader() {
18371837 dir[DEBUG_DIRECTORY].RelativeVirtualAddress = debugDirectory->getRVA ();
18381838 dir[DEBUG_DIRECTORY].Size = debugDirectory->getSize ();
18391839 }
1840- if (Symbol *sym = ctx.symtab .findUnderscore (" _load_config_used" )) {
1841- if (auto *b = dyn_cast<DefinedRegular>(sym)) {
1842- SectionChunk *sc = b->getChunk ();
1843- assert (b->getRVA () >= sc->getRVA ());
1844- uint64_t offsetInChunk = b->getRVA () - sc->getRVA ();
1845- if (!sc->hasData || offsetInChunk + 4 > sc->getSize ())
1846- Fatal (ctx) << " _load_config_used is malformed" ;
1847-
1848- ArrayRef<uint8_t > secContents = sc->getContents ();
1849- uint32_t loadConfigSize =
1850- *reinterpret_cast <const ulittle32_t *>(&secContents[offsetInChunk]);
1851- if (offsetInChunk + loadConfigSize > sc->getSize ())
1852- Fatal (ctx) << " _load_config_used is too large" ;
1853- dir[LOAD_CONFIG_TABLE].RelativeVirtualAddress = b->getRVA ();
1854- dir[LOAD_CONFIG_TABLE].Size = loadConfigSize;
1855- }
1840+ if (ctx.symtab .loadConfigSym ) {
1841+ dir[LOAD_CONFIG_TABLE].RelativeVirtualAddress =
1842+ ctx.symtab .loadConfigSym ->getRVA ();
1843+ dir[LOAD_CONFIG_TABLE].Size = ctx.symtab .loadConfigSize ;
18561844 }
18571845 if (!delayIdata.empty ()) {
18581846 dir[DELAY_IMPORT_DESCRIPTOR].RelativeVirtualAddress =
@@ -2649,31 +2637,14 @@ void Writer::fixTlsAlignment() {
26492637}
26502638
26512639void Writer::prepareLoadConfig () {
2652- Symbol *sym = ctx.symtab .findUnderscore (" _load_config_used" );
2653- auto *b = cast_if_present<DefinedRegular>(sym);
2654- if (!b) {
2655- if (ctx.config .guardCF != GuardCFLevel::Off)
2656- Warn (ctx)
2657- << " Control Flow Guard is enabled but '_load_config_used' is missing" ;
2658- if (ctx.config .dependentLoadFlags )
2659- Warn (ctx) << " _load_config_used not found, /dependentloadflag will have "
2660- " no effect" ;
2640+ if (!ctx.symtab .loadConfigSym )
26612641 return ;
2662- }
26632642
2664- OutputSection *sec = ctx.getOutputSection (b->getChunk ());
2665- uint8_t *buf = buffer->getBufferStart ();
2666- uint8_t *secBuf = buf + sec->getFileOff ();
2667- uint8_t *symBuf = secBuf + (b->getRVA () - sec->getRVA ());
2668- uint32_t expectedAlign = ctx.config .is64 () ? 8 : 4 ;
2669- if (b->getChunk ()->getAlignment () < expectedAlign)
2670- Warn (ctx) << " '_load_config_used' is misaligned (expected alignment to be "
2671- << expectedAlign << " bytes, got "
2672- << b->getChunk ()->getAlignment () << " instead)" ;
2673- else if (!isAligned (Align (expectedAlign), b->getRVA ()))
2674- Warn (ctx) << " '_load_config_used' is misaligned (RVA is 0x"
2675- << Twine::utohexstr (b->getRVA ()) << " not aligned to "
2676- << expectedAlign << " bytes)" ;
2643+ OutputSection *sec =
2644+ ctx.getOutputSection (ctx.symtab .loadConfigSym ->getChunk ());
2645+ uint8_t *secBuf = buffer->getBufferStart () + sec->getFileOff ();
2646+ uint8_t *symBuf =
2647+ secBuf + (ctx.symtab .loadConfigSym ->getRVA () - sec->getRVA ());
26772648
26782649 if (ctx.config .is64 ())
26792650 prepareLoadConfig (reinterpret_cast <coff_load_configuration64 *>(symBuf));
0 commit comments