@@ -202,7 +202,13 @@ class COFFLinkGraphLowering_x86_64 {
202202 switch (E.getKind ()) {
203203 case EdgeKind_coff_x86_64::Pointer32NB: {
204204 auto ImageBase = GetImageBase (G);
205- assert (ImageBase && " __ImageBase symbol must be defined" );
205+ assert (ImageBase && " __ImageBase esymbol must be defined" );
206+ if (!ImageBase->getAddress ())
207+ setImageBaseToGraphBase (G, ImageBase);
208+ LLVM_DEBUG ({
209+ dbgs () << " Lowing IMAGE_REL_AMD64_ADDR32NB to Pointer32 using __ImageBase = "
210+ << formatv (" {0:x}" , ImageBase->getAddress ()) << " \n " ;
211+ });
206212 E.setAddend (E.getAddend () - ImageBase->getAddress ().getValue ());
207213 E.setKind (x86_64::Pointer32);
208214 break ;
@@ -243,6 +249,16 @@ class COFFLinkGraphLowering_x86_64 {
243249 return It->second ;
244250 }
245251
252+ void setImageBaseToGraphBase (LinkGraph &G, Symbol *ImageBase) {
253+ if (G.defined_symbols ().empty ())
254+ return ;
255+ orc::ExecutorAddr GraphBase =
256+ (*G.defined_symbols ().begin ())->getAddress ();
257+ for (auto *Sym : G.defined_symbols ())
258+ GraphBase = std::min (GraphBase, Sym->getAddress ());
259+ G.makeAbsolute (*ImageBase, GraphBase);
260+ }
261+
246262 GetImageBaseSymbol GetImageBase;
247263 DenseMap<Section *, orc::ExecutorAddr> SectionStartCache;
248264};
0 commit comments