Fix for Trac #4318 (Linker failure on OS X 10.6)
This patch fixes two bugs in the Mach-O linker and adds debugging statements
to the same. The bugs:
- The test for symbol->n_value == 0 is removed and replaced by a test of the
flag field. Checking the n_value field was just wrong; the value of a
symbol should only be examined when allocating space for a common block,
in which case the n_value field gives the size of the block. This bug
led to an infrequently occuring linker crash.
I believe the behavior of the linker now agrees with the intent of the
sketchy Apple documentation.
- Jump islands were being filled with garbage instead of the the location
of the referenced symbol. This caused relocations of type X86_64_RELOC_GOT and
X86_64_RELOC_GOT_LOAD to eventually lead to crashes. The fix is simply to
look up the symbol.
Enough debug statements have been added to follow the operation of the Mach-O
linker while it loads modules. They are not yet as informative and well
organized as for ELF. Improving the debug statements will require some
reorganization of the code -- the Mach-O linker seems basically sound, but
is crying out for some refactoring and commenting.