[mach-o] Support linker synthesized mach_header symbols.
authorNick Kledzik <kledzik@apple.com>
Wed, 12 Nov 2014 22:21:56 +0000 (22:21 +0000)
committerNick Kledzik <kledzik@apple.com>
Wed, 12 Nov 2014 22:21:56 +0000 (22:21 +0000)
commit16cfa60cbd8c792228fc9d112c5bcc1b7eb55743
tree5424bf9cf159e408381f570d0aa5634be8391cf7
parent0140aa8756d5a8fa58a0a02b306aa685d22caa42
[mach-o] Support linker synthesized mach_header symbols.

On darwin in final linked images, the __TEXT segment covers that start of the
file.  That means in memory a process can see the mach_header (and load commands)
for every loaded image in a process.  There are APIs that take and return the
mach_header addresses as a way to specify a particular loaded image.

For completeness, any code can get the address of the mach_header of the image
it is in by using &__dso_handle.  In addition there are mach-o type specific
symbols like __mh_execute_header.

The linker needs to supply a definition for any of these symbols if used.  But
the address the symbol it resolves to is not in any section.  Instead it is the
address of the start of the __TEXT segment.

I needed to make a small change to SimpleFileNode to not override
resetNextIndex() because the Driver creates a SimpleFileNode to hold the
internal/implicit files that the context/writer can create. For some reason
SimpleFileNode overrode resetNextIndex() to do nothing instead of reseting
the index (which mach-o needs if the internal file is an archive).

llvm-svn: 221822
lld/include/lld/Core/DefinedAtom.h
lld/include/lld/Core/InputGraph.h
lld/lib/Core/DefinedAtom.cpp
lld/lib/ReaderWriter/MachO/ExecutableAtoms.hpp
lld/lib/ReaderWriter/MachO/MachONormalizedFileFromAtoms.cpp
lld/lib/ReaderWriter/MachO/WriterMachO.cpp
lld/lib/ReaderWriter/YAML/ReaderWriterYAML.cpp
lld/test/mach-o/dso_handle.yaml [new file with mode: 0644]
lld/test/mach-o/mh_bundle_header.yaml [new file with mode: 0644]
lld/test/mach-o/mh_dylib_header.yaml [new file with mode: 0644]