[lld] Initial commit for new Mach-O backend

Authored by int3 on Mar 31 2020, 11:45 AM.


[lld] Initial commit for new Mach-O backend

This is the first commit for the new Mach-O backend, designed to roughly
follow the architecture of the existing ELF and COFF backends, and
building off work that @ruiu and @pcc did in a branch a while back. Note
that this is a very stripped-down commit with the bare minimum of
functionality for ease of review. We'll be following up with more diffs

Currently, we're able to generate a simple "Hello World!" executable
that runs on OS X Catalina (and possibly on earlier OS X versions; I
haven't tested them). (This executable can be obtained by compiling
test/MachO/relocations.s.) We're mocking out a few load commands to
achieve this -- for example, we can't load dynamic libraries, but
Catalina requires binaries to be linked against dyld, so we hardcode
the emission of a LC_LOAD_DYLIB command. Other mocked out load
commands include LC_SYMTAB and LC_DYSYMTAB.

Differential Revision: https://reviews.llvm.org/D75382

Event Timeline

This is causing a compile failure on the 32-bit ARM bots:

[4031/4120] Building CXX object tools/lld/MachO/CMakeFiles/lldMachO2.dir/InputFiles.cpp.o
FAILED: tools/lld/MachO/CMakeFiles/lldMachO2.dir/InputFiles.cpp.o 
/usr/local/bin/c++   -DGTEST_HAS_RTTI=0 -D_DEBUG -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE -D_LARGEFILE_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -Itools/lld/MachO -I/home/buildslave/buildslave/clang-cmake-armv8-lld/llvm/lld/MachO -I/home/buildslave/buildslave/clang-cmake-armv8-lld/llvm/lld/include -Itools/lld/include -I/usr/include/libxml2 -Iinclude -I/home/buildslave/buildslave/clang-cmake-armv8-lld/llvm/llvm/include -mcpu=cortex-a57 -fPIC -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wstring-conversion -fdiagnostics-color -ffunction-sections -fdata-sections -O3     -fno-exceptions -fno-rtti -UNDEBUG -std=c++14 -MMD -MT tools/lld/MachO/CMakeFiles/lldMachO2.dir/InputFiles.cpp.o -MF tools/lld/MachO/CMakeFiles/lldMachO2.dir/InputFiles.cpp.o.d -o tools/lld/MachO/CMakeFiles/lldMachO2.dir/InputFiles.cpp.o -c /home/buildslave/buildslave/clang-cmake-armv8-lld/llvm/lld/MachO/InputFiles.cpp
/home/buildslave/buildslave/clang-cmake-armv8-lld/llvm/lld/MachO/InputFiles.cpp:106:37: error: non-constant-expression cannot be narrowed from type 'uint64_t' (aka 'unsigned long long') to 'size_t' (aka 'unsigned int') in initializer list [-Wc++11-narrowing]
    isec->data = {buf + sec.offset, sec.size};
/home/buildslave/buildslave/clang-cmake-armv8-lld/llvm/lld/MachO/InputFiles.cpp:106:37: note: insert an explicit cast to silence this issue
    isec->data = {buf + sec.offset, sec.size};
                                    static_cast<size_t>( )
1 error generated.


Could you please investigate this, and either fix (if quick and obvious) or revert?

lldong added a subscriber: lldong.Apr 7 2020, 3:32 AM
Ankit added a subscriber: Ankit.May 25 2020, 3:51 AM
hans added a subscriber: hans.Aug 25 2020, 11:28 AM

Would you like to add a mention of this in the lld release notes?

Ankit removed a subscriber: Ankit.Aug 25 2020, 11:30 AM
int3 added a comment.Aug 25 2020, 2:29 PM

We're still in the early stages of development, so I don't think it makes sense to put them in this round's release notes. We should be in the next one though. Thanks for checking!