Currently, all the nodes in the Atom graph are read only because "const Atom" is used everywhere. But there are a few cases where it would be nice to make minor modifications to atoms. For example, to implement the darwin linker option -expored_symbols_list, we need to be able to change the scope of atoms. ELF has a case where the dynamicExport attribute on an DefinedAtom may need to
be changed.
There is a couple parts to this patch:
- Two new "notify" methods are added to LinkingContext. They are called by the global symbol table when an atom is added to the symbol table.
- A setScope() method was added to DefinedAtom. The base implementation just asserts.
- For mach-o, yaml, and native the setScope() method modifies the scope of the atom. For the native reader, since the atom is just a pointer into a read-only file buffer, the new scope is stored in a side table.
- The darwin driver has support for the -exported_symbols_list option. The MachOLinkingContext notify methods watch for atoms being added to the symbol table with match the symbol names specified by the exported symbols list
and adjust the scope as appropriate.
If the above goes into lld, then for the ELF issue where particular symbols are currently not be added to the .dynsym table, the fix would be to add a new method setDynamicExport(bool) to DefinedAtom, and in ELFLinkingContext implement the "notify" methods to notice the case (DefinedAtom overriding weak shared library atom) and call setDynamicExport(true) on that DefinedAtom.
I assume we will add more setXX member functions (e.g. setInterposable) when we need it. I don't like to add them now but want to make sure that we are on the same page.