1
1
mirror of https://github.com/rui314/mold.git synced 2024-09-21 01:47:11 +03:00

Merge pull request #63 from Logarithmus/readme-gcc-guide

README.md: add guide to using mold with GCC via -B option
This commit is contained in:
Rui Ueyama 2021-07-01 09:38:34 +09:00 committed by GitHub
commit b044ac844c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -84,10 +84,15 @@ $ sudo apt-get install dwarfdump libc6-dev:i386 lib32gcc-10-dev gcc-multilib
On Unix, the linker command (which is usually `/usr/bin/ld`) is
invoked indirectly by `cc` (or `gcc` or `clang`), which is typically
in turn indirectly invoked by `make` or some other build system
command. It is sometimes very hard to pass an appropriate command line
option to `cc` to specify an alternative linker.
in turn indirectly invoked by `make` or some other build system command.
A classic way to use `mold`:
- `clang` before 12.0: pass `-fuse-ld=<absolute-path-to-mold-executable>`;
- clang after 12.0: pass `--ld-path=<absolute-path-to-mold-executable>`;
- gcc: `--ld-path` patch [has been declined by GCC maintainers](https://gcc.gnu.org/pipermail/gcc-patches/2021-June/573833.html), instead they advise to use a [workaround](https://gcc.gnu.org/pipermail/gcc-patches/2021-June/573823.html): create directory `<dirname>`, then `ln -s <path-to-mold> <dirname>/ld`, and then pass `-B<dirname>` (`-B` tells GCC to look for `ld` in specified location).
It is sometimes very hard to pass an appropriate command line
option to `cc` to specify an alternative linker.
To deal with the situation, mold has a feature to intercept all
invocations of `/usr/bin/ld`, `/usr/bin/ld.lld` or `/usr/bin/ld.gold`
and redirect it to itself. To use the feature, run `make` (or other
@ -103,10 +108,6 @@ file intercepts all function calls to exec-family functions to replace
`argv[0]` with `mold` if it is `/usr/bin/ld`, `/usr/bin/ld.gold` or
`/usr/bin/ld.lld`.
Alternatively, you can pass `-fuse-ld=<absolute-path-to-mold-executable>`
to a linker command line. Since GCC doesn't support that option,
I recommend using clang.
mold leaves its identification string in `.comment` section in an output
file. You can print it out to verify that you are actually using mold.