This is an archive of the discontinued LLVM Phabricator instance.

lld: improve the `-arch` handling for MachO
ClosedPublic

Authored by compnerd on Jun 5 2020, 8:04 PM.

Details

Reviewers
smeenai
int3
Ktwu
Summary

Use the default target triple configured by the user to determine the
default architecture for ld64.lld. Stash the architecture in the
configuration as when linking against TBDs, we will need to filter out
the symbols based upon the architecture. Treat the Haswell slice as it
is equivalent to x86_64 but with the extra Haswell extensions (e.g.
AVX2, FMA3, BMI1, etc). This will make it easier to add new
architectures in the future.

This change also changes the failure mode where an invalid -arch
parameter will result in the linker exiting without further processing.

Diff Detail

Event Timeline

compnerd created this revision.Jun 5 2020, 8:04 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 5 2020, 8:04 PM
int3 accepted this revision.Jun 7 2020, 10:18 PM

lgtm

lld/MachO/Driver.cpp
99

I assume the h suffix means Haswell

This revision is now accepted and ready to land.Jun 7 2020, 10:18 PM
Ktwu added inline comments.Jun 8 2020, 9:54 AM
lld/MachO/Driver.cpp
99

Yup that's Haswell.

compnerd closed this revision.Jun 8 2020, 11:04 AM
compnerd marked an inline comment as done.
lld/MachO/Driver.cpp
99

Yes, the x86_64h is the Haswell indicator. This allows for non-Haswell and Haswell targets to be lipo'ed into a single fat binary.

int3 added a comment.Jun 15 2020, 2:05 PM

Hey @compnerd, didn't realize that this diff would mean we needed to specify -arch in all our tests... I tried to remove that in D81802: [lld-macho] No need to explicitly specify -arch in tests but it appears that REQUIRES: x86 tests still run on non-x86 machines, because (we think) the REQUIRES line is about what targets are supported by the LLVM that we're building, and not what the host machine is running. Looking at lld-ELF and ld64, it seems that they both try to infer the architecture from the input object files, so we should probably implement that at some point. But in the meantime, could we revert to the old behavior of defaulting to x86_64 regardless of the default target triple?

mgorny added a subscriber: mgorny.Jun 17 2020, 1:33 PM

This change broke standalone builds of LLD:

FAILED: MachO/CMakeFiles/lldMachO2.dir/Driver.cpp.o 
/usr/lib64/ccache/bin/x86_64-pc-linux-gnu-g++ -DGTEST_HAS_RTTI=0 -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -IMachO -I/var/tmp/portage/sys-devel/lld-11.0.0.9999/work/lld/MachO -I/var/tmp/portage/sys-devel/lld-11.0.0.9999/work/lld/include -Iinclude -I/usr/lib64/llvm/11/include  -O2 -pipe -fPIC -fvisibility-inlines-hidden -Werror=date-time -w -fdiagnostics-color -ffunction-sections -fdata-sections    -fno-exceptions -fno-rtti -MD -MT MachO/CMakeFiles/lldMachO2.dir/Driver.cpp.o -MF MachO/CMakeFiles/lldMachO2.dir/Driver.cpp.o.d -o MachO/CMakeFiles/lldMachO2.dir/Driver.cpp.o -c /var/tmp/portage/sys-devel/lld-11.0.0.9999/work/lld/MachO/Driver.cpp
/var/tmp/portage/sys-devel/lld-11.0.0.9999/work/lld/MachO/Driver.cpp:30:10: fatal error: llvm/Config/config.h: No such file or directory
 #include "llvm/Config/config.h"
          ^~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
lld/MachO/Driver.cpp
30

This file is not part of LLVM install, so including it breaks standalone builds.

@int3, are we able to get rid of that include with D81983?

int3 added a comment.Jun 17 2020, 8:47 PM

Yup. Just did that and landed. Thanks for the heads up @mgorny

Thanks for the fix.