Expand description
Finding a linker and telling it what to link.
Design: spec/04-driver-and-cli.md section 4.9. There is no linker of our own before 1.0, so
this finds one on the machine and builds the command line it wants.
The linker is invoked directly rather than through the system compiler driver. Going through
cc would be shorter to write and would borrow that compiler’s idea of where everything is,
and it would also mean this compiler cannot link on a machine that has no other compiler on
it, which is most of the machines a compiler ends up on. It would also make -### output a
line that does not say what happens, since the interesting half would be inside the program
being spawned.
§What is not decided here
The startup files and the library directories are looked for rather than configured, for the
same reason library looks for the headers: gcc settles this when it is built because a gcc
is built for the machine it will run on, and this is one binary that runs wherever it is
copied. So the shape of the answer is a list of candidates per platform of which the ones
that exist are taken, and a cross build says where the rest is with --sysroot.
§What is not here yet
crtbegin and crtend, and -lgcc. Those are a compiler’s own runtime rather than the
library’s, and this compiler’s is rucc-builtins, which is not written. A program that needs
neither links and runs without them, which is every program that does not divide a 128-bit
integer or unwind through a frame, and a program that needs one gets an undefined symbol from
the linker naming exactly what is missing rather than a wrong answer at run time.
Darwin and Windows. ld64 wants a different line, a platform version load command and a
different set of default libraries, and link.exe wants another one again. Each arrives with
the target that needs it.
Structs§
- Link
Options - What the command line said about linking.
- Linker
- A linker, found.
Enums§
- Error
- Why a link could not be run.
- Item
- One item on the link line, in the order it was written, because link order is semantic.
Functions§
- candidates
- Where the library’s own files might be, in search order.
- find
- The linker to use, looked for where a linker is.
- line
- What the linker is told, in order, not counting the linker itself.
- order
- The names to look for, in the order section 4.9 gives.
- render
- The whole invocation as one line, quoted the way
-###prints it. - run
- Runs the linker and waits for it.