Commit Graph

51 Commits

Author SHA1 Message Date
Andrew Kelley
d3648cc030 zig cc: integrate with -fstack-check, -fno-stack-check 2022-03-04 18:10:37 -07:00
Andrew Kelley
fd6d1fe015 stage2: improvements to entry point handling
* rename `entry` to `entry_symbol_name` for the zig build API
 * integrate with `zig cc` command line options
 * integrate with COFF linking with LLD
 * integrate with self-hosted ELF linker
 * don't put it in the hash for MachO since it is ignored
2022-01-19 11:41:08 -07:00
Jakub Konka
6d9c02a54f
zig cc: integration with sysroot arg (#10568)
Prior to this change, even if the use specified the sysroot on the
compiler line like so

```
zig cc --sysroot=/path/to/sdk
```

it would only be used as a prefix to include paths and not as a prefix
for `zig ld` linker.
2022-01-11 12:41:26 -05:00
Lee Cannon
1093b09a98
allocgate: renamed getAllocator function to allocator 2021-11-30 23:32:47 +00:00
Lee Cannon
75548b50ff
allocgate: stage 1 and 2 building 2021-11-30 23:32:47 +00:00
Andrew Kelley
b097545a5f zig cc: honor all -m and -mno- CPU feature flags
closes #9196
2021-11-26 19:59:33 -07:00
Andrew Kelley
96e5f661bd zig cc: add -fcolor-diagnostics and -fcaret-diagnostics integration
Closes #6290
2021-11-21 17:07:18 -07:00
Andrew Kelley
ceeb230c23 zig cc: add -ffunction-sections integration
Also update to latest LLVM 13 command line options.

See #6290
2021-11-21 17:01:07 -07:00
Lee Cannon
b15d6b2a34 Add build.zig and command line flags 2021-10-16 21:55:51 +01:00
Andrew Kelley
d11f42c2b2 zig cc: support -S and -emit-llvm CLI parameters
closes #6425
2021-09-16 16:39:04 -07:00
Andrew Kelley
e41e75a486 stage2: update for new usingnamespace semantics 2021-09-01 17:54:07 -07:00
Jacob G-W
9fffffb07b fix code broken from previous commit 2021-06-21 17:03:03 -07:00
Andrew Kelley
caad5c4960 zig cc: recognize more pie flags
This is a bug fix.
2021-06-11 15:57:52 -07:00
Andrew Kelley
b6277a4b1c better awareness of unwind tables
* stage1 backend allows configuring the uwtables function attr
   via a flag rather than its own logic.
 * stage2 defaults to enabling uwtable attr when
   linking libunwind, or always on windows
 * stage2 makes link_eh_frame_hdr true automatically if uwtable
   attr is set to be on for zig functions
 * CLI: add -funwind-tables and -fno-unwind-tables to allow the user to
   override the defaults.
 * hook it up to `zig cc`

closes #9046
2021-06-11 13:23:00 -04:00
Andrew Kelley
138afd5cbf zig fmt 2021-06-10 20:13:43 -07:00
Takeshi Yoneda
bf568ec62a cc,wasi: support WASI reactors via -mexec-model flag.
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2021-06-09 17:07:06 +09:00
Rejean Loyer
c313e3f509 tools: fix update_clang_options.zig for ArrayHashMap's Separated Key/Value Storage breaking change. 2021-06-08 06:26:39 +02:00
Martin Wickham
fc9430f567 Breaking hash map changes for 0.8.0
- hash/eql functions moved into a Context object
- *Context functions pass an explicit context
- *Adapted functions pass specialized keys and contexts
- new getPtr() function returns a pointer to value
- remove functions renamed to fetchRemove
- new remove functions return bool
- removeAssertDiscard deleted, use assert(remove(...)) instead
- Keys and values are stored in separate arrays
- Entry is now {*K, *V}, the new KV is {K, V}
- BufSet/BufMap functions renamed to match other set/map types
- fixed iterating-while-modifying bug in src/link/C.zig
2021-06-03 17:02:16 -05:00
Michael Dusan
a502c160cd macho: fix various linker flags
fix drivers: zig {cc,c++}
  - `-dynamiclib` is an alias to `-shared`
  - associate `-dynamiclib` with zig `.shared` semantics

fix drivers: zig {cc,c++,build-lib,build-exe}
  - use `-dynamic` for {exe,dylib}
  - for dylib this fixes a regression
  - for exe this replaces incorrect use of `-static`
2021-03-14 17:26:24 -04:00
Andrew Kelley
041212a41c zig cc: fix handling of -MM flag
Clang docs say:
> Like -MMD, but also implies -E and writes to stdout by default.

Previously, Zig handled this option by forwarding it directly to Clang,
and disabling depfiles. However this did not adhere to Clang's documented
behavior of these flags.

Now, in addition to being forwarded directly to Clang, `-MM` also
sets c_out_mode = .preprocessor, just like `-E`.

Another issue I noticed is that Zig did not recognize the aliases for
-MG, -MM, or -MMD. The aliases are now recognized.
2021-03-04 18:14:00 -07:00
Andrew Kelley
e197a03124 zig cc: recognize the -s flag to be "strip" 2021-02-07 14:51:27 -07:00
Andrew Kelley
0d4b6ac741 add LTO support
The CLI gains -flto and -fno-lto options to override the default.
However, the cool thing about this is that the defaults are great! In
general when you use build-exe in release mode, Zig will enable LTO if
it would work and it would help.

zig cc supports detecting and honoring the -flto and -fno-lto flags as
well. The linkWithLld functions are improved to all be the same with
regards to copying the artifact instead of trying to pass single objects
through LLD with -r. There is possibly a future improvement here as
well; see the respective TODOs.

stage1 is updated to support outputting LLVM bitcode instead of machine
code when lto is enabled. This allows LLVM to optimize across the Zig and
C/C++ code boundary.

closes #2845
2021-01-23 18:18:07 -07:00
Andrew Kelley
5b2a79848c stage2: cleanups regarding red zone CLI flags
* CLI: change to -mred-zone and -mno-red-zone to match gcc/clang.
 * build.zig: remove the double negative and make it an optional bool.
   This follows precedent from other flags, allowing the compiler CLI to
   be the decider of what is default instead of duplicating the default
   value into the build system code.
 * Compilation: make it an optional `want_red_zone` instead of a
   `no_red_zone` bool. The default is decided by a call to
   `target_util.hasRedZone`.
 * When creating a Clang command line, put -mred-zone on the command
   line if we are forcing it to be enabled.
 * Update update_clang_options.zig with respect to the recent {s}/{} format changes.
 * `zig cc` integration with red zone preference.
2021-01-11 22:07:21 -07:00
Jay Petacat
a9b505fa77 Reduce use of deprecated IO types
Related: #4917
2021-01-07 23:48:58 -08:00
Andrew Kelley
abc717f203 modernize the PIE patch for the latest master branch
This is the part of #3960 that has to be rewritten to apply to latest
master branch code.
2020-11-22 17:28:11 -07:00
LemonBoy
8eaaa905f7
stage2: Make zig cc more verbose (#7166)
* stage2: Make zig cc more verbose

Make `zig cc` print more info from Clang itself and from our own linker
invocation, this is needed for CMake to properly discover all the
include directories and library search paths.

Closes #7110

* Update `update_clang_options`

* Typo fixes

Co-authored-by: Jakub Konka <kubkon@jakubkonka.com>
2020-11-19 23:30:16 +01:00
Josh Holland
c25b157dda remove deprecated uses of ArrayList.span 2020-11-07 11:15:44 +00:00
redj
c0b2813e04
tools/update_clang_options: add zig run usage example. fix src-self-hosted path. (#6635)
* tools/update_clang_options: fix src-self-hosted path now simply src.

* tools/update_clang_options: add zig run usage example.
2020-10-09 23:09:36 -04:00
xavier
eb33394d14 notice more kinds of optimization flags and debug flags
Closes #6091
2020-10-07 18:43:05 -04:00
Andrew Kelley
a337046832 stage2: properly handle zig cc used as a preprocessor
This cleans up how the CLI parses and handles -E, -S, and -c.
Compilation explicitly acknowledges when it is being used to do C
preprocessing.

-S is properly translated to -fno-emit-bin -femit-asm but Compilation
does not yet handle -femit-asm.

There is not yet a mechanism for skipping the linking step when there is
only a single object file, and so to make this work we have to do a file
copy in link.flush() to copy the file from zig-cache into the output
directory.
2020-09-25 20:52:02 -07:00
Cassidy Dingenskirchen
57f1ed5325 Fix a few std.sort.sort invocations 2020-06-12 13:33:31 -04:00
Andrew Kelley
52db13738b
zig cc looks for native include directories unless -nostdinc
closes #4938
2020-04-04 14:58:24 -04:00
Andrew Kelley
f8cc6a1917
zig cc: fix ambiguity with -MT
In an MSVC context, `-MT` means
"Use static run-time"
and it is a flag with no parameter.

On POSIX it means
"Specify name of main file output in depfile"
and it is "joined or separate".

The former was interfering with the latter. Now, the MT flag is required
to be specified with a `/` to disambiguate: `/MT`.
2020-04-02 21:15:36 -04:00
Andrew Kelley
c4b3c84b3f
zig cc: support -F and -framework 2020-04-02 15:59:48 -04:00
Andrew Kelley
e4edc6d118
zig cc: respect -MF -MV -MD options
Zig disables its caching and forwards these args when any are provided.

see #4784
2020-04-02 15:47:27 -04:00
Andrew Kelley
4848b28ec8
zig cc: detect -mcpu, -march, -mtune
However these are all treated like zig's -mcpu parameter.

See #4784
2020-04-01 18:06:04 -04:00
Rejean Loyer
2b6dfdd3d4 zig cc: add support for -L linker arguments 2020-04-01 17:21:11 -04:00
Andrew Kelley
783f73c7e3
zig cc properly handles -S flag and .ll, .bc extensions 2020-04-01 16:01:06 -04:00
Andrew Kelley
cfedd3aca2
revert detection of rtti and exceptions
This caused link errors in c++ code because it was not correct to pass
these flags to child codegens. And that was the only reason to detect
these flags. Otherwise we can safely rely on non-explicitly-detected
flag forwarding.
2020-03-30 17:42:30 -04:00
Andrew Kelley
9e7ae06249
std lib API deprecations for the upcoming 0.6.0 release
See #3811
2020-03-30 14:23:22 -04:00
Ryan Liptak
874b4618ca zig cc: Add support for -z
This is only the first step; it makes zig cc recognize -z and append it to the linker args, but the linker arg parsing doesn't support -z yet so it will just give the warning 'unsupported linker arg: -z'
2020-03-28 00:35:54 -07:00
Ryan Liptak
b0b29b8a2f zig cc: Add support for -Xlinker, --for-linker, --for-linker= 2020-03-27 23:32:01 -07:00
Andrew Kelley
f407109070
zig c++: get it working with musl and mingw-w64 2020-03-27 12:38:52 -04:00
Andrew Kelley
db17c0d88c
ability to compile c++ hello world with zig c++
closes #4786
2020-03-26 22:48:37 -04:00
Andrew Kelley
e3fec6cce9
zig cc: add detection for -###
it turns on --verbose-cc and --verbose-link
2020-03-25 19:32:12 -04:00
Andrew Kelley
6cbe589b51
zig cc: support -T linker script option 2020-03-25 12:05:48 -04:00
Andrew Kelley
2b65dc1032
zig cc: detect optimization and debug flags 2020-03-21 22:30:46 -04:00
Andrew Kelley
4b0ddb817b
zig cc: better support for the preprocessor option (-E) 2020-03-21 20:32:48 -04:00
Michael Dusan
28ad78cb7f
rename "passthrough" → "driver_punt"
- punt when `-E` is supplied
- punt when `-S` is supplied
2020-03-21 16:53:59 -04:00
Andrew Kelley
0eee98edc1
zig cc improvements
* The generated options data file is sorted now in a way that
   makes sure longer prefixes are first. This prevents collisions
   with some parameters.
 * Add support for `-fPIC`, `-fno-PIC`, `-nostdlib`, `-shared`,
   `-rdynamic`, `-Wl,-soname`, `-Wl,-rpath`
 * Better support for `-o`.
 * Disable generating h files
 * Shared library support.
 * Better positional argument support.
2020-03-21 15:40:49 -04:00