# support \-fcompiler-rt in conjunction with build-obj · gitcafe/zig

[View on GitCafe](https://git.cafe/gitcafe/zig/commit/7c25390c957273ff43927608a45e257c4ed73549)

Repository: [gitcafe/zig](https://git.cafe/gitcafe/zig)

Visibility: public

Requested revision: 7c25390c957273ff43927608a45e257c4ed73549

Requested commit: 7c25390c957273ff43927608a45e257c4ed73549

Commit: 7c25390c957273ff43927608a45e257c4ed73549

Tree: 411809c36b20d2575816bcf726330413c3624398

Author: Andrew Kelley

Committer: Andrew Kelley

## Message

```
support -fcompiler-rt in conjunction with build-obj

When using `build-exe` or `build-lib -dynamic`, `-fcompiler-rt` means building
compiler-rt into a static library and then linking it into the executable.

When using `build-lib`, `-fcompiler-rt` means building compiler-rt into an
object file and then adding it into the static archive.

Before this commit, when using `build-obj`, zig would build compiler-rt
into an object file, and then on ELF, use `lld -r` to merge it into the
main object file. Other linker backends of LLD do not support `-r` to
merge objects, so this failed with error messages for those targets.

Now, `-fcompiler-rt` when used with `build-obj` acts as if the user puts
`_ = @import("compiler_rt");` inside their root source file. The symbols
of compiler-rt go into the same compilation unit as the root source file.

This is hooked up for stage1 only for now. Once stage2 is capable of
building compiler-rt, it should be hooked up there as well.

```

## Parents

- [a5fb28070f37c2cad92ac8805bcc704e872fc538](https://git.cafe/gitcafe/zig/commit/a5fb28070f37c2cad92ac8805bcc704e872fc538?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zig/tree/7c25390c957273ff43927608a45e257c4ed73549?format=markdown)
