+ // pre-fill gotMap with existing non-lazy pointers
+ std::map<const ld::Atom*, const ld::Atom*> gotMap;
+ for (ld::Internal::FinalSection* sect : internal.sections) {
+ if ( sect->type() != ld::Section::typeNonLazyPointer )
+ continue;
+ for (const ld::Atom* atom : sect->atoms) {
+ const ld::Atom* target = NULL;
+ for (ld::Fixup::iterator fit = atom->fixupsBegin(), end=atom->fixupsEnd(); fit != end; ++fit) {
+ switch (fit->kind) {
+ case ld::Fixup::kindStoreTargetAddressLittleEndian64:
+ case ld::Fixup::kindStoreTargetAddressLittleEndian32:
+ switch ( fit->binding ) {
+ case ld::Fixup::bindingsIndirectlyBound:
+ target = internal.indirectBindingTable[fit->u.bindingIndex];
+ break;
+ case ld::Fixup::bindingDirectlyBound:
+ target = fit->u.target;
+ break;
+ default:
+ fprintf(stderr, "non-pointer is got entry\n");
+ break;
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ if ( target != NULL ) {
+ if (log) fprintf(stderr, "found existing got entry to %s\n", target->name());
+ gotMap[target] = atom;
+ }
+ }
+ }
+
+ // walk all atoms and fixups looking for GOT-able references
+ // don't create GOT atoms during this loop because that could invalidate the sections iterator