pub enum Slot {
Imported,
Referred,
}Expand description
Which pointer a name on COFF is reached through, when it is reached through one.
The code is the same for both, a load of the pointer from the instruction pointer and then the name’s address in a register. What differs is who writes the pointer.
Variants§
Imported
The one the loader fills in for a name in another DLL, which the import library calls
__imp_ and the name. A declaration said dllimport, so there is no other way to the name:
the import library has no stub under the plain name for a variable, and for a function the
stub is a jump through this same pointer, so going through it here saves the jump.
Referred
One this file writes itself, called .refptr. and the name, for a variable it only
declares and nothing said was in a DLL.
The variable may still turn out to be in one, and environ in the C runtime is one that
is. Then the address a lea would work out is not a distance the linker has, since the DLL
is loaded wherever it fits, and what it does instead is write a record for the runtime to
patch the reference with once the DLL is loaded. A four byte reference from the code cannot
hold an address that far away, and an eight byte pointer in a data section can, so the
reference the runtime patches is this pointer. Every object that reads the name writes the
same one in a section of its own that the linker keeps one copy of, which is what gcc and
clang both do for x86_64-w64-mingw32.