Repository navigation
Link executables for their target, not for the host - #113
Merged
Merged
Conversation
The native linker decided everything with host macros: on a Windows host it accepted only COFF objects and wrote the kernel32 import library for the host's machine (_M_ARM64), and elsewhere it always ran the host's cc. An executable for another target therefore could not be linked at all, and a Windows-on-Arm host would have written an x64 import library for an x64 target. What a link runs is now planned from the target triple in LinkPlan.cpp, a pure function that touches no file and starts no process: - a Windows target (x86_64, aarch64) is linked by lld-link on every host, with /machine from the target and the import library written for that machine; - the host's own system, architecture and C library is linked by cc, as before; - another Linux, macOS or BSD target is linked by `clang --target=<triple> -fuse-ld=lld`, with --sysroot when given. NativeLinker.cpp runs the plan: it checks that the objects have the target's format, finds the target's runtime (beside talac for the host, in runtimes/<triple>/ for another target), writes the import library and starts the program on either kind of host. The link request carries the resolved target triple from the backend artifact; an object given on the command line belongs to --target. LinkPlanTests plans every pair of target and host on whichever host runs it (native, cross Linux, musl, macOS from Linux, Windows from Linux and macOS, Windows on Arm, and the refusals) and joins the native test list. verify-abi and the runtime-library helper test now read the programs and library names from LinkPlan.cpp. CLI.md and the changelog describe the behaviour. Builds on #112 (--sysroot).
Contributor
Author
|
Self-review: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link executables for their target, not for the host
The native linker decided everything with host macros: on a Windows host
it accepted only COFF objects and wrote the kernel32 import library for
the host's machine (_M_ARM64), and elsewhere it always ran the host's cc.
An executable for another target therefore could not be linked at all,
and a Windows-on-Arm host would have written an x64 import library for an
x64 target.
What a link runs is now planned from the target triple in LinkPlan.cpp,
a pure function that touches no file and starts no process:
with /machine from the target and the import library written for that
machine;
before;
clang --target=<triple> -fuse-ld=lld, with --sysroot when given.NativeLinker.cpp runs the plan: it checks that the objects have the
target's format, finds the target's runtime (beside talac for the host,
in runtimes// for another target), writes the import library and
starts the program on either kind of host. The link request carries the
resolved target triple from the backend artifact; an object given on the
command line belongs to --target.
LinkPlanTests plans every pair of target and host on whichever host runs
it (native, cross Linux, musl, macOS from Linux, Windows from Linux and
macOS, Windows on Arm, and the refusals) and joins the native test list.
verify-abi and the runtime-library helper test now read the programs and
library names from LinkPlan.cpp. CLI.md and the changelog describe the
behaviour.
Builds on #112 (--sysroot).