Commit Graph

10517 Commits (bc01887376c227a5f42715f48471dcca14b3d31b)

Author SHA1 Message Date
Andrew Kelley 2627778b25 stage2: don't create empty object files when no zig source 2020-09-13 22:15:03 -07:00
Andrew Kelley 046dce9cef stage2: fix not creating cache o dir before writing to it
also remove non-working debug CLI options
2020-09-13 21:13:24 -07:00
Andrew Kelley 2456df5f4e stage2: rename ZigModule to Module 2020-09-13 19:56:35 -07:00
Andrew Kelley 4d59f77528 stage2: rename Module to Compilation 2020-09-13 19:49:52 -07:00
Andrew Kelley 2a8fc1a18e stage2: caching system integration & Module/Compilation splitting
* update to the new cache hash API
 * std.Target defaultVersionRange moves to std.Target.Os.Tag
 * std.Target.Os gains getVersionRange which returns a tagged union
 * start the process of splitting Module into Compilation and "zig
   module".
   - The parts of Module having to do with only compiling zig code are
     extracted into ZigModule.zig.
   - Next step is to rename Module to Compilation.
   - After that rename ZigModule back to Module.
 * implement proper cache hash usage when compiling C objects, and
   properly manage the file lock of the build artifacts.
 * make versions optional to match recent changes to master branch.
 * proper cache hash integration for compiling zig code
 * proper cache hash integration for linking even when not compiling zig
   code.
 * ELF LLD linking integrates with the caching system. A comment from
   the source code:

   Here we want to determine whether we can save time by not invoking LLD when the
   output is unchanged. None of the linker options or the object files that are being
   linked are in the hash that namespaces the directory we are outputting to. Therefore,
   we must hash those now, and the resulting digest will form the "id" of the linking
   job we are about to perform.
   After a successful link, we store the id in the metadata of a symlink named "id.txt" in
   the artifact directory. So, now, we check if this symlink exists, and if it matches
   our digest. If so, we can skip linking. Otherwise, we proceed with invoking LLD.

 * implement disable_c_depfile option
 * add tracy to a few more functions
2020-09-13 19:29:07 -07:00
Andrew Kelley 1baa56a25f std.cache_hash: break up the API and improve implementation
into smaller exposed components and expose all of them. This makes it
more flexible.

`*const Cache` is now passed in with an open manifest dir handle which
the caller is responsible for managing.

Expose some of the base64 stuff.

Extract the hash helper functions into `HashHelper` and add some more
methods such as addOptional and addListOfFiles.

Add `CacheHash.toOwnedLock` so that you can deinitialize everything
except the open file handle which represents the file system lock on the
build artifacts.

Use ArrayListUnmanaged, saving space per allocated CacheHash.

Avoid 1 memory allocation in hit() with a static buffer.

hit() returns a bool; caller code is responsible for calling final() in
either case. This is a simpler and easier to use API.

writeManifest() is no longer called from deinit() with errors ignored.
2020-09-13 18:04:52 -07:00
LemonBoy 61e9e82bdc std: Make the CRC32 calculation slightly faster
Speed up a little the slicing-by-8 code path by replacing the
(load+shift+xor)*4 sequence with a single u32 load plus a xor.

Before:

```
iterative:  1018 MiB/s [000000006c3b110d]
small keys:  1075 MiB/s [0035bf3dcac00000]
```

After:

```
iterative:  1114 MiB/s [000000006c3b110d]
small keys:  1324 MiB/s [0035bf3dcac00000]
```
2020-09-13 16:32:21 -04:00
LemonBoy 5e50d145d9 std: Limit the read/write size on Darwin
It turns out that the kernel won't read or write more than 0x7fffffff
bytes in a single call, failing with EINVAL when trying to do so.

Adjust the limit and curse whoever is responsible for this.

Closes #6332
2020-09-13 16:31:21 -04:00
Matt Knight 88dacd3b70
changed to opaque 2020-09-13 09:53:20 -07:00
Matt Knight 1afbf4fb21
removed all those kern aliases 2020-09-13 09:43:49 -07:00
Matt Knight cb5f76bb1c
got booleans wrong 2020-09-13 09:24:56 -07:00
Matt Knight b043a31889
added helper definitions 2020-09-12 23:45:35 -07:00
Andrew Kelley af4cc20ce2 Merge remote-tracking branch 'origin/master' into stage2-zig-cc
Master branch added in the concept of library versioning being optional
to main.cpp. It will need to be re-added into this branch before merging
back into master.
2020-09-12 10:48:38 -07:00
Andrew Kelley 03a23418ff stage2: linking with LLD and building glibc static CRT files
* implement --debug-cc and --debug-link
 * implement C source files having extra flags
   - TODO a way to pass them on the CLI
 * introduce the Directory abstraction which contains both an open file
   descriptor and a file path name. The former is preferred but the
   latter is needed when communicating paths over a command line (e.g.
   to Clang or LLD).
 * use the cache hash to choose an artifact directory
   - TODO: use separate cache hash instances for the zig module and
     each C object
 * Module: introduce the crt_files table for keeping track of built libc
   artifacts for linking.
 * Add the ability to build 4/6 of the glibc static CRT lib files.
 * The zig-cache directory is now passed as a parameter to Module.
 * Implement the CLI logic of -femit-bin and -femit-h
   - TODO: respect -fno-emit-bin
   - TODO: the emit .h feature
 * Add the -fvalgrind, -fstack-check, and --single-threaded CLI options.
 * Implement the logic for auto detecting whether to enable PIC,
   sanitize-C, stack-check, valgrind, and single-threaded.
 * Properly add PIC args (or not) to clang argv.
 * Implement renaming clang-compiled object files into their proper
   place within the cache artifact directory.
   - TODO: std lib needs a proper higher level abstraction for
     std.os.renameat.
 * Package is cleaned up to use the "Unmanaged" StringHashMap and use the
   new Directory abstraction.
 * Clean up zig lib directory detection to make proper use of directory
   handles.
 * Linker code invokes LLD.
   - TODO properly deal with the stdout and stderr that we get from it
     and expose diagnostics from the Module API that match the expected
     error message format.
 * Delete the bitrotted LLVM C ABI bindings. We'll resurrect just the
   functions we need as we introduce dependencies on them. So far it
   only has ZigLLDLink in it.
 * Remove dead timer code.
 * `zig env` now prints the path to the zig executable as well.
2020-09-12 00:51:06 -07:00
Andrew Kelley 8374be1a1c std.cache_hash: bump up the base64 digest len to avoid '==' 2020-09-12 00:50:37 -07:00
Andrew Kelley c903dad915 fix zig_llvm.h not complying with C 2020-09-12 00:50:17 -07:00
LemonBoy 9fe4c89230 std: Add a gzip decoder 2020-09-11 20:02:41 -04:00
Andrew Kelley 1edf097871
Merge pull request #6323 from LemonBoy/fast-zlib
std: Make the DEFLATE decompression routine 3x faster
2020-09-11 17:25:18 -04:00
Andrew Kelley 1eaf0691f9
Merge pull request #6320 from ifreund/prctl
std: add prctl and securebits definitions for linux/C
2020-09-11 16:33:57 -04:00
Isaac Freund 1078810cef
std: add prctl definition when linking libc 2020-09-11 22:32:23 +02:00
Isaac Freund b6f4601545
std: add securebits definitions for linux 2020-09-11 22:32:23 +02:00
Isaac Freund 744b73ab46
std: add prctl wrapper to std.os 2020-09-11 22:32:23 +02:00
Isaac Freund 7b961a876b
std: add prctl definition for linux 2020-09-11 22:32:22 +02:00
Andrew Kelley 42c32dbc7b
Merge pull request #6315 from ifreund/optional-shlib-version
std, stage1: make shared library versioning optional
2020-09-11 16:07:13 -04:00
LemonBoy 4b851c7255 Re-enable a compression test
It somehow got commented out...
2020-09-11 21:04:08 +02:00
LemonBoy 41f244bd2f std: Make the DEFLATE decompression routine 3x faster
A profiler run showed that the main bottleneck was the naive decoding of
the Huffman codes, replacing it with a nice trick borrowed by Zlib gave
a substantial speedup.
Replacing a `%` with a `and (mask-1)` gave another significant
improvement (yay for low hanging fruits).

A few numbers obtained by decompressing a 22M file:

Before:
```
./decompress  2,39s user 0,00s system 99% cpu 2,400 total
```

After:
```
./decompress  0,79s user 0,00s system 99% cpu 0,798 total
````
2020-09-11 21:00:15 +02:00
Andrew Kelley bee34f5d03 add a manifesto to the readme 2020-09-11 11:30:21 -07:00
Isaac Freund 0a76a9bd73
std, stage1: make shared library versioning optional
This commit changes the behavior of stage1 to emit libfoo.so instead
of libfoo.so.0.0.0 when none of the --ver-major, --ver-minor, or
--ver-patch flags are set.

It also makes it possible to create unversioned shared libraries
using the zig build system, changing the version parameter of
addSharedLibrary() to a tagged union.
2020-09-11 10:46:37 +02:00
Isaac Freund 68bf29c31e std: allow overriding install dir of artifacts
This is necessary when, for example, writing a PAM module which should
be installed to lib/security/module_name.so.
2020-09-11 04:32:36 -04:00
Andrew Kelley 8cf40f3445 stage2: loading glibc metadata 2020-09-10 22:24:27 -07:00
Andrew Kelley 98583be6e1 stage1: fix crash with slice type 2020-09-10 22:22:42 -07:00
Andrew Kelley c41cd3e13a std.fs.File: fix typo in writeFileAll 2020-09-10 18:53:20 -07:00
Andrew Kelley 800c5de2ae update the stack trace test case for lines added to start.zig 2020-09-10 14:40:33 -07:00
Andrew Kelley 2315331d23
Merge pull request #5527 from shawnanastasio/ppc64le
Implement support for powerpc64{,le}
2020-09-10 15:56:27 -04:00
Christian Wesselhoeft ea9b38c93c fs/file.zig: Update reader to use type alias
This is a minor cosmetic change which updates `reader` and `inStream`
to match `writer` and `outStream` below.
2020-09-10 15:42:24 -04:00
Isaac Freund 13b8c63834 std: complete C definitions for uid/gid setters
Also:
- correct the definition of setgid
- update the existing definitions to use the uid_t/gid_t types
2020-09-10 15:41:52 -04:00
Isaac Freund bb9773f695 std: fix errorset of std.os.seteuid/setegid 2020-09-10 15:41:21 -04:00
Isaac Freund 486a774e5f std: add option to use single-threaded event loop
std.event.Loop does not yet work in single threaded builds. However,
using evented io on a single thread can be very convenient. This commit
allows settind @import("root").event_loop_mode to .single_threaded
in order to allow this without reimplementing the startup code in
start.zig
2020-09-10 15:40:38 -04:00
Isaac Freund 4170f3f77f std: fix bitrot in process.posixGetUserInfo() 2020-09-10 14:30:07 -04:00
Vexu 0833c8d06b
translate-c: support sizeof and _Alignof in macros
Closes  #6301
2020-09-10 13:04:03 +03:00
Literally Void 78baa16da0 Fix issue #6303: iterating empty PriorityQueue crashes 2020-09-10 12:00:53 +03:00
Andrew Kelley e05ecbf165 stage2: progress towards LLD linking
* add `zig libc` command
 * add `--libc` CLI and integrate it with Module and linker code
 * implement libc detection and paths resolution
 * port LLD ELF linker line construction to stage2
 * integrate dynamic linker option into Module and linker code
 * implement default link_mode detection and error handling if
   user requests static when it cannot be fulfilled
 * integrate more linker options
 * implement detection of .so.X.Y.Z file extension as a shared object
   file. nice try, you can't fool me.
 * correct usage text for -dynamic and -static
2020-09-09 22:29:41 -07:00
Andrew Kelley 5746a8658e stage1: link: fix incorrect LDM option for mips64 2020-09-09 22:23:59 -07:00
Andrew Kelley b37955f273 stage2 linker code supports opening an intermediate object file
For when linking with LLD, we always create an object rather than going
straight to the executable. Next step is putting this object on the LLD
linker line.
2020-09-09 10:54:40 -07:00
Andrew Kelley 193ad413f0 stage2: compiling C objects with clang
* add target_util.zig which has ported code from src/target.cpp
 * Module gains an arena that owns memory used during initialization
   that has the same lifetime as the Module. Useful for constructing
   file paths and lists of strings that have mixed lifetimes.
   - The Module memory itself is allocated in this arena. init/deinit
     are modified to be create/destroy.
   - root_name moves to the arena and no longer needs manual free
 * implement the ability to invoke `zig clang` as a subprocess
   - there are lots of TODOs that should be solved before merging
 * Module now requires a Random object and zig_lib_dir
 * Module now requires a path to its own executable or any zig
   executable that can do `zig clang`.
 * Wire up more CLI options.
 * Module creates "zig-cache" directory and "tmp" and "o" subdirectories
   ("h" is created by the cache_hash)
 * stubbed out some of the things linker code needs to do with TODO
   prints
 * delete dead code for computing compiler id. the previous commit
   eliminated the need for it.
 * add `zig translate-c` CLI option but it's not fully hooked up yet.
   It should be possible for this to be fully wired up before merging
   this branch.
 * `zig targets` now uses canonical data for available_libcs
2020-09-09 09:28:05 -07:00
Andrew Kelley c99e34a00e stage2: eliminate the "compiler id" concept
Instead, append a "dirty suffix" to the version string when there are
dirty git changes and use the version string as the compiler id.

This avoids a dependency on the cache hash system, and saves time on
first invocation of the compiler since it does not have to compute its
compiler id. It also saves time by not having to check the cache for a
saved compiler id.
2020-09-09 09:28:05 -07:00
Andrew Kelley 35f334ae0f organize some TODO comments 2020-09-09 09:28:05 -07:00
Andrew Kelley 4056bb92e6 stage2: more progress moving `zig cc` to stage2
* std.cache_hash exposes Hasher type
 * std.cache_hash makes hasher_init a global const
 * std.cache_hash supports cloning so that clones can share the same
   open manifest dir handle as well as fork from shared hasher state
 * start to populate the cache_hash for stage2 builds
 * remove a footgun from std.cache_hash add function
 * get rid of std.Target.ObjectFormat.unknown
 * rework stage2 logic for resolving output artifact names by adding
   object_format as an optional parameter to std.zig.binNameAlloc
 * support -Denable-llvm in stage2 tests
 * Module supports the use case when there are no .zig files
 * introduce c_object_table and failed_c_objects to Module
 * propagate many new kinds of data from CLI into Module and into
   linker.Options
 * introduce -fLLVM, -fLLD, -fClang and their -fno- counterparts.
   closes #6251.
   - add logic for choosing when to use LLD or zig's self-hosted linker
 * stub code for implementing invoking Clang to build C objects
 * add -femit-h, -femit-h=foo, and -fno-emit-h CLI options
2020-09-09 09:28:05 -07:00
Andrew Kelley 472ee18486 stage2: infer --name in more ways 2020-09-09 09:28:05 -07:00
Andrew Kelley f064f0564f stage2: improve log message format 2020-09-09 09:28:05 -07:00