[lld] consolidating the usage of saving references


It looks like each flavor chooses to save references in its own way.

The GNU flavor (ELF) uses a single vector of references and uses referenceStartIndex/referenceEndIndex to point to the references for each DefinedAtom.

Darwin(Mach-O) / WinLink (PECOFF) uses a different way of storing references ?

Is there a plan to make the WinLink/Darwin(Mach-O) use a single vector of references too at some point in time.

There are merits/demerits of the approach that the Gnu flavor uses but it would be nice if we settle on one design for storing references.


Shankar Easwaran

Look at COFFBaseDefinedAtom in lib/ReaderWriter/PECOFF/Atoms.h for PE/COFF. Specifically, these functions and a field are for References.

void addReference(std::unique_ptr reference);
virtual reference_iterator begin() const;
virtual reference_iterator end() const;
virtual const Reference *derefIterator(const void *iter) const;
virtual void incrementIterator(const void *&iter) const;

std::vector<std::unique_ptr> _references;

As you can see References are stored into a single vector already. We don’t have anything similar to reference{Start,End}Index because we have never needed it. Iterator knows where it is pointing to, so I don’t see any reason why DefiendAtom have to know it separately. What is the use case of the fields in ELF?