# compiler: Rework PIE option logic\. · gitcafe/zig

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

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

Visibility: public

Requested revision: a81fb5fb76131d0df3042f20e2d20a3b9216b254

Requested commit: a81fb5fb76131d0df3042f20e2d20a3b9216b254

Commit: a81fb5fb76131d0df3042f20e2d20a3b9216b254

Tree: 65306edd14da5500e59a54107d159b248237e78a

Author: Alex Rønne Petersen

Committer: Alex Rønne Petersen

## Message

```
compiler: Rework PIE option logic.

To my knowledge, the only platforms that actually *require* PIE are Fuchsia and
Android, and the latter *only* when building a dynamically-linked executable.
OpenBSD and macOS both strongly encourage using PIE by default, but it isn't
technically required. So for the latter platforms, we enable it by default but
don't enforce it.

Also, importantly, if we're building an object file or a static library, and the
user hasn't explicitly told us whether to build PIE or non-PIE code (and the
target doesn't require PIE), we should *not* default to PIE. Doing so produces
code that cannot be linked into non-PIE output. In other words, building an
object file or a static library as PIE is an optimization only to be done when
the user knows that it'll end up in a PIE executable in the end.

Closes #21837.

```

## Parents

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

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