8046 Commits
0.5.0 ... 0.8.1

Author SHA1 Message Date
Andrew Kelley
12828c09d6 Release 0.8.1 2021-09-06 19:41:54 -07:00
Sebastian Ullrich
c72f584218 libunwind: fix unwinding through libunwind stack frames
Fixes #9591
2021-09-03 10:19:01 -07:00
Andrew Kelley
3617615e2d CI: update Linux and macOS tarballs to LLVM 12.0.1 2021-09-03 10:18:53 -07:00
Philip Åkesson
b3a4074358 std: Use truncating cast in WIFSTOPPED for Linux, FreeBSD and DragonFly
The intermediate value can be larger than an u16, so @truncate is needed
to match the behavior of musl.
2021-09-03 10:18:28 -07:00
Andrew Kelley
46f93807aa fix merge conflicts for this branch 2021-09-01 17:01:35 -07:00
Philipp Lühmann
5356151172 fix typo 2021-08-31 13:45:04 -07:00
Andrew Kelley
f7e08ea780 re-enable all the MIPS tests
LLVM 12.0.1 fixed the regressions from LLVM 12.0.0.

Closes #8155
2021-08-31 13:44:57 -07:00
Frank Denis
a1d532752f Don't define valgrind_support on macOS (#9612)
Unfortunately, Valgrind for macOS has been broken for years,
and the Homebrew formula is only for Linux.
2021-08-31 13:44:23 -07:00
Zach Banks
2588451967 std/ArrayList: Allow ArrayList(u0) to be created
Enable creating ArrayList with zero-sized types.
This type still tracks length, but does not allocate
additional memory.
2021-08-31 13:41:05 -07:00
Meghan Denny
551971b5c3 stage1: add c_longdouble mapping for s390x 2021-08-31 13:40:01 -07:00
Takeshi Yoneda
5d08e2b5d8 Wasm,libc: fix wasm-ld failure in matching libc symbols.
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2021-08-31 13:39:15 -07:00
fn ⌃ ⌥
d38bd443ef Use -isysroot on Mojave too 2021-08-31 13:38:52 -07:00
David May
c9ab6baf06 Docs fix array/pointer/slice type coercion section (#9392)
* removed deprecated coercion: [X]T => [] const T

* Fixed tests and added desc for first test

* Improved heading
2021-08-31 13:35:24 -07:00
Alex Rønne Petersen
a45c0c5033 zig: -rdynamic now implies -fdll-export-fns unless the latter is explicitly set.
Fixes #9340.
2021-08-31 13:32:27 -07:00
Michal Ziulek
7b9612a922 Fixed compile error: 'bMenu' needs to casted. (#9426) 2021-08-31 13:31:41 -07:00
Biolunar
1cddcf4484 linux stdlib: fix definition of RW flags (#9428) 2021-08-31 13:31:27 -07:00
Frank Denis
b8a77f3d59 std.crypto: handle the top bit in 25519.field.fromBytes64() (#9435)
The only known use case for this is the hash-to-curve operation where the top bit is always cleared.

But the function is public, so let's make it work as one would expect in the general case.

Also fix the comment by the way.
2021-08-31 13:31:06 -07:00
Tau
d4e22e3eb6 Correct hasUniqueRepresentation for vectors
Closes #9333.
2021-07-21 12:30:56 -07:00
Andrew Kelley
d99f55b7cf std.ArrayList: add missing assertion in appendSliceAssumeCapacity 2021-07-21 12:30:37 -07:00
Isaac Freund
2561b1eb67 langref: remove incorrect statement on c_void
c_void is *not* simply `const c_void = opaque{};`. It has unique
semantics as any pointer type may coerce to `*c_void` which is not true
for an arbitrary `*opaque{}`.
2021-07-21 12:27:21 -07:00
Adam C
c1e444b07c FIX typo in doc comment for std.math.hypot (#9413) 2021-07-21 12:25:52 -07:00
Ryan Liptak
84154b10a2 Add inotify_rm_watch definition to c/linux.zig
Also make inotify_add_watch's pathname marked as nul-terminated
2021-07-21 12:25:10 -07:00
Ryan Liptak
ba47e09373 Add NotDir as possible error for os.inotify_add_watch
Possible when "mask contains IN_ONLYDIR and pathname is not a directory."
2021-07-21 12:25:05 -07:00
leesongun
1063bf696e Fix bigint_shl (#9305) 2021-07-21 12:24:53 -07:00
Jonathan Marler
3b8c4f07a4 clarify @bitSizeOf behavior 2021-07-21 12:24:47 -07:00
Martin Wickham
3dcbd489eb Fix libc include directories for the MSVC target 2021-07-21 12:22:09 -07:00
Malcolm Still
5582d20f04 Add waitid syscall on linux (#9335) 2021-07-21 12:22:03 -07:00
Andrew Kelley
13aedf09d6 mingw-w64: add odbc32 and dbghelp def files
related: #9124
2021-07-21 12:21:58 -07:00
Martin Wickham
cd078c518f Fix argument forwarding to LLVM on Windows 2021-07-21 12:21:48 -07:00
leesongun
ceebcfa317 Fix unexpected truncation behavior with comptime_int larger than u64 range (#9303)
Closes #9299
2021-07-06 21:30:58 -07:00
Jacob G-W
b26ab39836 remove really weird debugging statement from stage1 2021-07-06 21:30:46 -07:00
Nulo
eac9bfaa01 Link to the GPA now that it's on upstream 2021-07-06 21:30:24 -07:00
Nulo
8a83143316 CODE_OF_CONDUCT: change Freenode to Libera.chat 2021-07-06 21:30:15 -07:00
Andrew Kelley
3ef9bd5879 stage2: add the zig version to AstGen cache hash
This solves the problem of different versions of Zig having different
binary representations of ZIR code.

closes #9290
2021-07-03 15:31:29 -07:00
Veikka Tuominen
f385522ab0 stage2: fix @asyncCall parameter count
Closes #9269
2021-07-03 15:29:52 -07:00
Nameless
de028d5130 std/os/uefi: fix packed struct bitfields 2021-07-03 15:28:57 -07:00
Andrew Kelley
390a4ded98 Merge pull request #9258 from ziglang/shared-cache-locking
Shared Cache Locking
2021-07-03 15:28:29 -07:00
Andrew Kelley
b0be0c77d8 Merge pull request #9148 from marler8997/windowsChildOutput
finish ChildProcess collectOutputWindows
2021-07-03 15:25:22 -07:00
xackus
440da6bfad mark tsan as linguist-vendored 2021-07-03 15:24:28 -07:00
Jacob G-W
b7fe0db9d2 langref: make @setRuntimeSafety more correct 2021-07-03 15:24:18 -07:00
Andrew Kelley
d59fc1ac04 stage1: @shuffle type and mask params in comptime scope 2021-07-03 15:22:53 -07:00
Roman Frołow
9349c9c4b1 Docs clarification: local static variable (#8381) 2021-07-03 15:22:21 -07:00
Jacob G-W
6caa77ea52 docs: top level global assembly -> container level 2021-07-03 15:22:17 -07:00
Andrew Kelley
caddd7eb18 std.crypto.p256: fix neg function compile error
There was a typo here and the neg function referenced a non-existent
variable.
2021-07-03 15:19:50 -07:00
Andrew Kelley
2b6727c98f std.os.linux.bpf: fix incorrect usage of unexpectedErrno 2021-07-03 15:19:50 -07:00
Andrew Kelley
5ef70b8b87 mips: fix syscall_pipe
Previously the fd parameter was ignored and so the result would not get
populated. Now it passes the fd pointer to the inline assembly so that
the results can be observed.
2021-07-03 15:19:50 -07:00
Isaac Freund
e75dfbcb3f std/build: add --sysroot general option 2021-06-26 12:51:49 +02:00
Isaac Freund
16228e87d6 stage2: add --sysroot link option
This feature is necessary for cross-compiling code that dynamically
links system libraries, at least with the current feature set of lld.
2021-06-26 12:49:08 +02:00
Isaac Freund
3e4f3a1924 zig build: add --libc general option
This new option sets a default libc paths file to be used for all
LibExeObjSteps. Setting LibExeObjStep.libc_file overrides this default.

This is required to allow users to cross compile projects linking system
libraries without needing to patch the build.zig.
2021-06-26 12:41:05 +02:00
mason1920
939408289c Bring your own MAX_PATH_BYTES
Previous to #7082, users could overwrite PATH_MAX in the root file to support std.os.toPosixPath, permitting the "bring your own operating system" layer to implement the POSIX API for opening files. Unfortunately that is no longer the case.

This commit intends to fix what is arguably a regression from 0.7 in a way that doesn't break any code targeting 0.8.0, making it suitable to be included in a 0.8 patch release.
However in a future release that permits breaking changes, I am of the opinion that it would be beneficial to overwrite the value, even for "supported" operating systems. Same for all the other POSIX/BYOOS functions and values. However this is beyond the scope of this commit. Further discussion of this will be made into an issue in due time.
2021-06-21 16:18:59 -07:00
Andrew Kelley
d0575310dc Merge pull request #9168 from LemonBoy/fix-pie
std: Fix PIE startup sequence
2021-06-20 17:03:50 -07:00
LemonBoy
b72d55ea5f std: Make copy_file_range checks run at compile-time
* Avoid emitting the copy_file_range symbol at all to prevent link-time
  errors.
* Fix a bug in the check logic, the has_copy_file_range_syscall was
  set to the wrong value in case of ENOSYS
* If link_libc is true don't fall-back to the raw syscall approach,
  there's no policy about what to do in this case but let's follow what
  the other impls do.

Fixes #9146
2021-06-20 16:54:39 -07:00
pithlessly
c7dd3cc535 stage2 sema: change impl of @setCold to use zirSetCold (typo?) 2021-06-20 16:37:55 -07:00
Michael Dusan
96b77e030f macho: LC_RPATH: reserve byte for null-terminator 2021-06-20 16:36:27 -07:00
hadroncfy
cf6e2d318a HashMap.getOrPutAssumeCapacityAdapted should set key to undefined (#9138)
* std.hash_map.HashMap: getOrPutAssumeCapacityAdapted should set key to undefined

* add test for std.hash_map.HashMap.getOrPutAdapted
2021-06-20 16:26:01 -07:00
Andrew Kelley
1fe0142d1f AstGen: properly generate errdefer expressions when returning
`return` statements use a new function `nodeMayEvalToError` which does
some basic checks on the AST node to return never, always, or maybe.

Depending on this result, AstGen skips the errdefers, always includes
the errdefers, or emits a conditional branch to check whether the return
value is an error that Sema will have to evaluate.

Closes #8821
Unblocks #9047
2021-06-20 16:25:52 -07:00
LemonBoy
76102ea41f stage1: Store the specified code model in the LLVM module
This is needed for LTO builds to pick up the correct module.

Closes #9132
2021-06-20 16:25:22 -07:00
Andrew Kelley
74ca811a66 Merge pull request #9117 from greenfork/unify-compiler-error-printing
stage2: Unify compiler error printing
2021-06-17 20:28:54 -07:00
Vincent Rischmann
721ec8fa53 zig cc: improve linker args parsing
Handle linker args joined with a = like -Wl,-rpath=foo

Update existing args --major-os-version, --minor-os-version,
--major-subsystem-version and --minor-subsytem-version to work with the
new parsing.

Also handle -Wl,--script in addition to -Wl,-T
2021-06-17 20:28:37 -07:00
Andrew Kelley
dc392f49f8 stage1: fix zig0 help message
closes #9140
2021-06-17 20:28:37 -07:00
d18g
71ec89383b Fix lakemont CpuModel (#9099)
Lakemont has no x86, no MMX, no SSE and no way of handling any fp-math. In theory LLVM is able to implicitly use the soft-float emulation library calls to legalize any such operation but, given Zig's use of many non-standard features, sometimes we hit a weak spot in the X86 codegen backend.

Consider this as a work-around for this LLVM problem, fixing the problem in LLVM is not so high in my todo list as the target is pretty niche and Intel axed it in '19.

(Commit message by @LemonBoy)
2021-06-17 20:28:37 -07:00
Michael Dusan
4adbdcb587 netbsd: add more std.os.bits 2021-06-17 20:28:37 -07:00
Michael Dusan
162b92c93e netbsd: add args to limit number of PT_LOAD segs
NetBSD expects 2 PT_LOAD segments in a shared object, otherwise
ld.elf_so fails to load, emitting a general "not found" error.

Workaround issue by adding args `--no-rosegment` and `-znorelro`.

see #9109
2021-06-17 20:28:37 -07:00
Andrew Kelley
8be29674a9 fix RISC-V assembly CPU features
Previously, Zig did not properly communicate the target CPU features for
RISC-V to clang assembler, because Clang has a different way to pass CPU
features for C code and for assembly code. This commit makes Zig pass a
RISC-V -march flag in order to communicate CPU features to Clang when
compiling assembly files.
2021-06-17 20:28:37 -07:00
Björn Linse
52ead255a2 std: don't reference non-existant ComptimeStringHashMap type 2021-06-15 13:32:14 -07:00
Andrew Kelley
6f180131a5 ci: azure: update to newer msys2 release 2021-06-14 12:16:54 -07:00
Isaac Freund
4453f6a5ce std: fix auto hash of tagged union with void field 2021-06-14 12:16:36 -07:00
viri
7f6e7e3e5d std.windows: fix OVERLAPPED, add OVERLAPPED_ENTRY 2021-06-14 12:14:46 -07:00
LemonBoy
5c9eb94a2b std: Fix complex ldexp implementation
Two bugs in the implementation ported from musl made all the complex
functions relying on ldexp return incorrect results in some cases.

Spotted in #9047
2021-06-14 12:13:53 -07:00
Andrew Kelley
9c1e7de6c6 zig cc: recognize more pie flags
This is a bug fix.
2021-06-14 12:13:03 -07:00
codic12
54229fec33 c.zig: fix waitpid() definition 2021-06-11 14:50:48 -07:00
Andrew Kelley
264969a8c3 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 10:31:48 -07:00
Veikka Tuominen
e3a74697f0 Merge pull request #8330 from kivikakk/single-limb-bigint-overflow
bigint add failures with aliasing
2021-06-11 10:31:08 -07:00
LemonBoy
a913311f3c std: Fix tanh for negative inputs
It turns out the code was not ported correctly from C and produced wrong
results for negative input values. As a bonus fix the NaN codepath by
adding yet another missing piece of code.

Spotted in #9047
2021-06-11 10:30:07 -07:00
Andrew Kelley
ec4c60c481 zig fmt 2021-06-11 10:28:42 -07:00
LemonBoy
29386f0d30 stage1: Fix handling of C ABI parameters split in multiple regs
Take into account the increased number of parameters when flattening a
structure into one or more SSE registers.

Fixes #9061
2021-06-10 10:22:08 -07:00
Frank Denis
80e1797faf aes 128-bit key expansion test - properly test the inverse round keys (#9065) 2021-06-10 10:22:03 -07:00
Jakub Konka
f677c24740 Re-enable multiple wasm32 vector tests
Fixes #5339
2021-06-10 10:21:13 -07:00
Andrew Kelley
6afdc3cc79 CLI: remove --verbose-ast and --verbose-tokenize
closes #9034

These options were listed under the
"Debug Options (Zig Compiler Development)" heading. Anything in this
section should be considered unstable and can be modified at any time
at any developer's discretion.
2021-06-10 10:20:59 -07:00
Andrew Kelley
c230258d9b native libc detection: respect spaces in CC env var
Zig has detection for when it is accidentally being called recursively
when trying to find the native libc installation. However it was not
working, resulting in a cryptic failure, because zig tried to execute
a command which had spaces in it rather than tokenizing it.

This improves the user experience of `zig cc` for systems that Zig
does not support cross-compiling for.

Closes #8960
2021-06-10 10:20:52 -07:00
Andrew Kelley
2d0dff6498 langref: link to 0.7.1 not 0.7.0 for the previous docs 2021-06-10 10:20:27 -07:00
Andrew Kelley
060cb0f277 langref: remove paragraph that mentions IRC
I want the language reference to be divorced from any particular
community. Also remove the call to action since the docs are
known to be incomplete and are not the current focus of the project.

Closes #9055
2021-06-10 10:20:16 -07:00
Filippo Casarin
05380a11a4 std.math.sqrt_int: fixed odd size integers types 2021-06-10 10:20:09 -07:00
viri
4a3ac16711 std.Progress: use *W functions on windows
Closes #534.
See: https://source.winehq.org/git/wine.git/blob/refs/heads/stable:/dlls/kernelbase/console.c#l520
2021-06-10 10:19:37 -07:00
Jakub Konka
51076f4e1d libc,macos: update and add missing libc headers 2021-06-10 10:10:24 -07:00
Matthew Borkowski
503b85a1b0 stage1: make @truncate to an integer type of different sign an error at comptime too 2021-06-08 12:27:22 -07:00
Dustin Taylor
0c25ff81a3 Limit Fixed Buffer Stream seekTo (#9023) 2021-06-08 12:27:22 -07:00
Matthew Borkowski
39c80942e7 stage1: fix render_const_value for printing const optional pointers 2021-06-08 22:24:55 +03:00
Andrew Kelley
bfc85211bb link: windows: look for more DLL import lib path names
When linking with -lfoo syntax, this indicates to Zig that the
dependency should either be provided by Zig, or it should be dynamically
provided by the system.

For windows-gnu targets, the search path was "foo.lib". Now it
additionally looks for "libfoo.dll.a".

Closes #7799
2021-06-07 22:31:32 -07:00
LemonBoy
7ca86936ca std: Add helpers to safely align pointers
Add two helpers to ensure people won't ignore some edge cases such as
pointers overflowing the address space.

Also fix #8924 to some degree, the amount of unchecked alignForward is
still scary.

Revert "tests: disable i386-linux-gnu -lc target due to CI failures"

This reverts commit 97a2f4e7ae.
2021-06-06 18:07:47 -07:00
LemonBoy
5c765b2ec4 std: Fix some BPF fn definitions
Cros-checked with bpf.h of kernel 5.12.9.
2021-06-06 18:02:52 -07:00
LemonBoy
a745a17aa9 build: Avoid using undefined variables
Closes #9013
Closes #8928
Closes #7991
2021-06-06 18:01:52 -07:00
LemonBoy
2681e1ffe0 stage1: Apply the same set of fn attributes everywhere
Make sure to propagate the target-specific attributes to internal
functions too.

Closes #8965
2021-06-06 18:01:47 -07:00
Sebastien Marie
27f6db66e3 openbsd: adjust dynamic linker path (#9010)
the dynamic linker on OpenBSD is at /usr/libexec/ld.so (and not /libexec/ld.so)
2021-06-06 18:01:40 -07:00
Michael Dusan
6d6ba1e998 test: re-enable dragonfly tests
Tests with LLVM assertions enabled are no longer failing.

closes #3563
2021-06-05 19:54:45 -07:00
Nicolas
c8ee445c86 Add zig_llvm-ar.cpp in build.zig
This was added in 0afb5b2ec6 8 days ago, but it seems it was only added in the cmake files and not build.zig
2021-06-05 19:54:33 -07:00
LemonBoy
072c3202c3 std: Better handing of POLLHUP in ChildProcess (#8988)
* std: Better handing of POLLHUP in ChildProcess

Upon hitting the EOF condition there are two main differences between
how Linux and the *BSD-derived systems behave: the former sets POLLHUP
and POLLIN and, after reading any residual data, only POLLHUP remains
set. The latter signal the EOF condition by setting both flags thus
requiring some extra checks to determine if the stream is "done".

DragonFly workaround/hack for POLLHUP is no longer required.

Closes #8969
2021-06-05 19:54:26 -07:00
LemonBoy
07852a4bc8 compiler-rt: Fix __floatunsitf signature
The function transforms an unsigned integer into a f128.

Closes #8996
2021-06-05 10:35:05 -07:00
Andrew Kelley
ae1871a028 start the 0.8.1 release branch 2021-06-04 11:30:34 -07:00
Andrew Kelley
a642552faf Release 0.8.0 2021-06-04 11:21:32 -07:00
Andrew Kelley
2699232c4e Merge pull request #8990 from ziglang/mingw-w64-9.0.0
upgrade to mingw-w64 9.0.0
2021-06-04 14:17:40 -04:00
Felix (xq) Queißner
167754b31b Makes std.io.StreamSource usable with freestanding 2021-06-04 13:04:36 -04:00
Andrew Kelley
6f4339be3a update mingw-w64 crt files to v9.0.0 2021-06-04 09:49:36 -07:00
Andrew Kelley
d7f00c4389 update mingw-w64 headers to v9.0.0 2021-06-04 09:29:56 -07:00
Jacob G-W
5d94e754f4 fmt: fix #8974
also add a regression test
2021-06-04 10:49:05 +03:00
Min-Yih Hsu
83e0a49ba4 llvm: Add support for collecting time trace (#8546)
LLVM time profiler can collect time traces and present them in a
hierarchical view. Which breakdowns the time spent in each Pass or even
IR unit. The result is also exported into a format that can be easily
visualized by the Chrome browser.

Currently this features is controlled by the following environment
variables:
 - `ZIG_LLVM_TIME_TRACE_FILE` toggles this feature and specifies the
   output time trace file.
 - `ZIG_LLVM_TIME_TRACE_GRANULARITY` controls the time granularity in
   ms (default to 500).
2021-06-04 09:32:37 +02:00
Andrew Kelley
9c08a33b22 Merge pull request #8750 from lithdew/master
x/io, x/os: async i/o reactor, cross-platform socket syscalls and bits
2021-06-04 01:21:28 -04:00
Isaac Freund
05b677f0c4 langref: sync grammar with zig-spec repo 2021-06-04 01:18:45 -04:00
viri
ce072894a1 docs: minor spelling fix 2021-06-04 01:18:14 -04:00
Andrew Kelley
7d15a3ac71 Merge pull request #8975 from SpexGuy/hash-map-updates
Breaking hash map changes for 0.8.0
2021-06-04 01:12:38 -04:00
Martin Wickham
6953c8544b Fix return type of HashMap.getAdapted 2021-06-03 17:58:06 -05: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
Andrew Kelley
87dae0ce98 Merge pull request #8932 from ziglang/llvm-needs-zlib
cmake: LLVM needs to link against zlib
2021-06-03 02:13:37 -04:00
Andrew Kelley
05cd8936c8 ci: drone: use zig-bootstrap tarball instead of system toolchain 2021-06-02 17:03:11 -07:00
Jakub Konka
d1f60a63bd zld: fix the linker for 32bit comp targets 2021-06-03 00:23:04 +02:00
Andrew Kelley
16c5cbab0c ci: update x86_64-freebsd tarball
to llvm 12.0.1-rc1, and -DLLVM_ENABLE_ZLIB=FORCE_ON
2021-06-01 23:26:53 -07:00
Evan Haas
a9dd8d7543 translate-c: Fix performance hazard in transPreprocessorEntities
Fixes O(N^2) behavior of `transPreprocessorEntities` due to repeated calls to
`mem.len`

Closes #8959
2021-06-02 09:12:45 +03:00
Veikka Tuominen
c6a0a4e728 translate-c: support designated initializers in macros 2021-06-01 23:40:43 -04:00
Jonathan Marler
99b6305aa8 handle LimitToBig error on setrlimit 2021-06-01 23:39:48 -04:00
Andrew Kelley
f693247295 Merge pull request #8917 from ifreund/fix-float-tokenize2
stage1, stage2: disallow 1.e9 and 0x1.p9 as float literals
2021-06-01 14:00:54 -04:00
Kenta Iwasaki
4909aa1da4 os/bits: remove duplicate sockaddr_storage for dragonfly 2021-06-01 18:35:13 +09:00
Kenta Iwasaki
aad8491dbd os: make msghdr, msghdr_const, and sockaddr_storage backwards-compatible
`msghdr` and `msghdr_const` definitions have been added back the way
they were in std.os. std.os.sendmsg has also been modified to accept a
msghdr_const again to ensure backwards-compatibility with this PR.
Underneath the hood, std.os.sendmsg will @ptrCast the provided
msghdr_const into a std.x.os.Socket.Message.

`sockaddr_storage` definitions have been added back the way they were in
std.os, except that it now simply aliases
std.x.os.Socket.Address.Native.Storage as all of
std.x.os.Socket.Address.Native.Storage's fields are equivalent to the
fields that were previously defined for std.x.os.bits.sockaddr_storage.

std.x.os.Socket.sendMessage now no longer is a stub that aliases
std.os.sendmsg, but instead calls and handles
errors from std.os.system.sendmsg directly.

Addresses feedback to urge backwards compatibility from @andrewrk.
2021-06-01 18:24:43 +09:00
Kenta Iwasaki
6950e4c294 x/os/net: remove unnecessary comptime prefix in resolveScopeID() 2021-06-01 18:24:43 +09:00
Kenta Iwasaki
278e5d398e x: replace std.builtin with std.Target.current 2021-06-01 18:24:43 +09:00
Kenta Iwasaki
21ec0158a1 os: sockaddr_storage -> std.x.os.Socket.Address.Native.Storage 2021-06-01 18:24:42 +09:00
Kenta Iwasaki
7b6ec3e354 x/os: {read, write}Vectorized() -> {read, write}Message() 2021-06-01 18:23:54 +09:00
lithdew
9ba65592d6 os: have sendmsg, recvmsg flags be c_int 2021-06-01 18:22:58 +09:00
lithdew
12650bcda4 x/os, x/tcp: fix Socket.Message init values and tcp test buf len 2021-06-01 18:22:58 +09:00
lithdew
494665e408 std/c: have sendmsg, recvmsg flags be u32 2021-06-01 18:22:58 +09:00
lithdew
d41575737e std/c: add recvmsg, sendmsg 2021-06-01 18:22:58 +09:00
lithdew
3600508fe1 x/io, x/os: async i/o reactor, cross-platform socket syscalls and bits
Cross-platform versions of msghdr, sendmsg, recvmsg, linger, and iovec
were provided based on findings from glibc, musl, and Microsoft's
documentation.

Implemented initial Reactor interface for epoll (linux) which wraps
around I/O reactor subsystems such as epoll, kqueue, select, etc. across
different platforms. The Reactor interface allows for driving async I/O
in Zig applications.

A test was added for the Reactor interface to drive a TCP
client/listener socket pair.

A greatest-common-subset of possible socket initialization flags (close
socket on exec syscalls, initialize socket to be non-blocking) were
implemented.

A test was added for using sendmsg/recvmsg syscalls across different
platforms for a TCP client/listener socket pair.
2021-06-01 18:22:57 +09:00
Frank Denis
d496400cff std.crypto.p256.scalar: fe struct member is not a function (#8954) 2021-06-01 11:02:48 +02:00
Andrew Kelley
a23fa896ef Tweak license in celebration of the upcoming 0.8.0 release :) 2021-05-31 14:12:20 -07:00
Isaac Freund
abd1c75c4a stage1: disallow 1.e9 and 0x1.p9 as float literals 2021-05-31 19:51:11 +00:00
Isaac Freund
608bc1cbd5 stage2: disallow 1.e9 and 0x1.p9 as float literals
Instead require `1e9` and `0x1p9`, disallowing the trailing dot.

This change to the grammar is consistent with forbidding `1.` and `0x1.`
as float literals and ensures there is only one way to do things here.
2021-05-31 19:51:11 +00:00
protty
eb6975f088 std.sync.atomic: extended atomic helper functions (#8866)
- deprecates `std.Thread.spinLoopHint` and moves it to `std.atomic.spinLoopHint`
- added an Atomic(T) generic wrapper type which replaces atomic.Bool and atomic.Int
- in Atomic(T), selectively expose member functions depending on T and include bitwise atomic methods when T is an Integer
- added fence() and compilerFence() to std.atomic
2021-05-31 11:11:30 -05:00
daurnimator
57cf9f7ea6 std: by default, disallow trailing data when parsing json 2021-05-31 14:09:59 +03:00
daurnimator
556d3e3d80 std: fix json.parse with 0 length arrays 2021-05-31 14:09:59 +03:00
Andrew Kelley
11ae6c42c1 Merge pull request #7918 from EthanGruffudd/json-ignore-fields
Add option to ignore unknown fields when parsing json
2021-05-30 14:59:02 -04:00
Andrew Kelley
32815914a4 std.json: update to new testing API 2021-05-30 11:57:44 -07:00
Ethan Gruffudd
781a21af2f std.json: option to ignore unknown fields
Closes #7906
2021-05-30 11:36:10 -07:00
Takeshi Yoneda
0ad1c04dd9 build: rename ast_render in build.zig.
Signed-off-by: Takeshi Yoneda <takeshi@tetrate.io>
2021-05-30 13:31:12 -04:00
Jakub Konka
0ad534b392 ci: update x86_64-macos and aarch64-macos tarballs
to llvm 12.0.1-rc1, and -DLLVM_ENABLE_ZLIB=FORCE_ON
2021-05-30 08:46:35 +02:00
Andrew Kelley
e46c55edbd ci: update x86_64-linux, aarch64-linux, and windows tarballs
to llvm 12.0.1-rc1, and -DLLVM_ENABLE_ZLIB=FORCE_ON
2021-05-29 20:18:02 -07:00
Andrew Kelley
f8bc5294f2 cmake: LLVM needs to link against zlib
For more details on why this dependency is needed, see
https://github.com/ziglang/zig-bootstrap/issues/57
2021-05-29 17:22:27 -07:00
Andrew Kelley
322215bf0a Merge pull request #8933 from ziglang/zig-ar
stage2: add `zig ar` subcommand
2021-05-29 19:31:30 -04:00
Andrew Kelley
e078b4f20e zig ar: workaround for LLVM bug
In this file is copy+pasted WindowsSupport.h from LLVM 12.0.1-rc1.
This is so that we can patch it. The upstream sources are incorrectly
including "llvm/Config/config.h" which is a private header and thus not
available in the include files distributed with LLVM.
The patch here changes it to include "llvm/Config/config.h" instead.
Patch submitted upstream: https://reviews.llvm.org/D103370
2021-05-29 13:54:31 -07:00
Andrew Kelley
0afb5b2ec6 stage2: add zig ar subcommand
The same entrypoint supports the following commands:

 * ar
 * ranlib
 * dlltool
 * lib

For now, our strategy is to bundle the (renamed) `main()` function of
llvm-ar, same as our strategy for `zig clang`. However, as Zig matures,
a goal will be to replace the dependency on LLVM  with our own
implementation of this tool, so that it is available in builds of zig
that do not have LLVM extensions enabled.

This commit also categorizes the subcommands into categories in the
--help menu.
2021-05-28 20:54:11 -07:00
Andrew Kelley
e248de93a0 add llvm-ar.cpp from llvm 12.0.1-rc1 2021-05-28 20:12:28 -07:00
Andrew Kelley
c12704a339 Merge pull request #8918 from ziglang/stage1-tokenizer
stage1: rework tokenizer to match stage2
2021-05-28 21:54:01 -04:00
Andrew Kelley
3f5ca3920a AstGen: properly restore previous state after temporary changes
Before this, if a compile error occurred, it would cause the previous
value for e.g. the function scope to not get reset. If the AstGen
process continued, it would result in a violation of the data
guarantees that it relies on.

This commit takes advantage of defer to ensure the previous value is
always reset, even in the case of an error.

Closes #8920
2021-05-28 17:29:56 -07:00
Matthew Borkowski
54f774f796 make writeIntSlice functions work for signed integers 2021-05-28 19:43:58 -04:00
Andrew Kelley
97a2f4e7ae tests: disable i386-linux-gnu -lc target due to CI failures
See #8930
2021-05-28 16:31:09 -07:00
LemonBoy
d3fb9f9532 stage1: Fix for atomicrmw xchg on fp types
Bitcast the pointer and operands to integer types having the same size,
working around LLVM inability to lower a LL/SC operation when the
operands have floating-point types (and are reasonably sized).

Closes #4457
2021-05-28 19:18:42 -04:00
Andrew Kelley
d888fa12a8 stage1 parser: fix the TODOs 2021-05-28 16:11:27 -07:00
Andrew Kelley
3483931d2a Merge pull request #8923 from Luukdegram/wasm-errors
stage2: wasm backend - Error sets and error unions
2021-05-28 18:45:36 -04:00
Andrew Kelley
f5d4fe3e17 stage1: memoize strings in the AST
Currently, stage1 runs astgen for every comptime function call,
resulting in identifier strings being allocated multiple times,
wasting memory. As a workaround until the code is adjusted to
make astgen run only once per source node, we memoize the
result into the AST.

 * Rename `ir_gen_*` to `astgen_*`
   - Oops, meant to do this in a separate commit. My bad.
 * tokenizer: avoid using designated initializer syntax.
   MSVC does not support it.
2021-05-28 15:22:03 -07:00
Andrew Kelley
52b3daa90e stage1: get test-compile-errors passing again 2021-05-28 14:19:08 -07:00
Andrew Kelley
9de2c1b76e stage1: tokenizer: backport recent stage2 changes
This backports ec10595b65 stage2 tokenizer
logic to stage1.
2021-05-28 13:26:16 -07:00
Andrew Kelley
33a779c7f6 start.zig: intentional silent failure when cannot increase stack size 2021-05-28 13:17:04 -07:00
Andrew Kelley
01e0a4b2f0 stage1: rename IrBasicBlockSrc to Stage1ZirBasicBlock 2021-05-28 12:58:40 -07:00
Andrew Kelley
548ef78070 stage1: remove source_node field from Stage1Zir
This field is unneeded because we always have the source node available
in the context that we have a Stage1Zir object.
2021-05-28 12:58:40 -07:00
Andrew Kelley
554dd52c36 stage1: remove c_import_buf from Stage1Zir
All we need is a boolean in Stage1AstGen. This is part of an effort to
make Stage1Zir immutable.
2021-05-28 12:58:40 -07:00
Andrew Kelley
4ea421f8cb stage1: move the ZigFn from Stage1Zir to Stage1AstGen
Part of an effort to make Stage1Zir immutable.
2021-05-28 12:58:40 -07:00
Andrew Kelley
42f4ee0aeb stage1: rename IrBuilderSrc to Stage1AstGen 2021-05-28 12:58:40 -07:00
Andrew Kelley
2440c08ab0 stage1: move next_debug_id from Stage1Zir to IrBuilderSrc
Part of an effort to make Stage1Zir immutable.
2021-05-28 12:58:40 -07:00
Andrew Kelley
b11ac9c5bf stage1: move some mutable state from Stage1Zir to IrAnalyze
This is progress towards making Stage1Zir immutable, so that we can
avoid generating it for every comptime function call.

Also rename IrExecutableGen to Stage1Air.
2021-05-28 12:58:40 -07:00
Andrew Kelley
e072ace436 stage1: rename IrExecutableSrc to Stage1Zir
and make IrBuilderSrc private to astgen.cpp
2021-05-28 12:58:40 -07:00
Andrew Kelley
eb37722d79 lol that's never going to happen in stage1 2021-05-28 12:58:40 -07:00
Andrew Kelley
2a990d6966 stage1: rework tokenizer to match stage2
* Extracts AstGen logic from ir.cpp into astgen.cpp. Reduces the
   largest file of stage1 from 33,551 lines to 25,510.
 * tokenizer: rework it completely to match the stage2 tokenizer logic.
   They can now be maintained together; when one is changed, the other
   can be changed in the same way.
   - Each token now takes up 13 bytes instead of 64 bytes. The tokenizer
     does not parse char literals, string literals, integer literals,
     etc into meaningful data. Instead, that happens during parsing or
     astgen.
   - no longer store line offsets. Error messages scan source
     files to find the line/column as needed (same as stage2).
   - main loop: instead of checking the loop, handle a null byte
     explicitly in the switch statements. This is a nice improvement
     that we may want to backport to stage2.
   - delete some dead tokens, artifacts of past syntax that no longer
     exists.
 * Parser: fix a TODO by parsing builtin functions as tokens rather than
   `@` as a separate token. This is how stage2 does it.
 * Remove some debugging infrastructure. These will need to be redone,
   if at all, as the code migrates to match stage2.
   - remove the ast_render code.
   - remove the IR debugging stuff
   - remove teh token printing code
2021-05-28 12:58:40 -07:00
Luuk de Gram
5cbe930e36 wasm: Add stage2 tests for error unions 2021-05-28 12:58:17 +02:00
Luuk de Gram
8a81dfc999 wasm: Reverse the order of error and payload
This will set us up to correctly retrieve the error local index and payload index
depending on that of the multi_value's index. As from now, the error will always use
the multi_value's index, and the payload will use the following locals.
2021-05-28 12:58:17 +02:00
Luuk de Gram
967a299c34 wasm: Add support for error union as return type
- This currently uses the multi-value feature to return both the possible error, and its payload.
- Also genAlloc and the logic to allocate the locals itself have been seperated, so we can create more locals
whenever needed, and not only when `genAlloc` is called.
2021-05-28 12:58:17 +02:00
Luuk de Gram
5481059232 wasm: Implement error unions and unwrapping
- Slightly refactored `Wvalue.multi_value` to also contain the amount of locals it contains,
this allows us to set all fields at once.
2021-05-28 12:58:17 +02:00
Luuk de Gram
a5b5a5532e wasm: Support error sets 2021-05-28 12:58:17 +02:00
Matthew Borkowski
673ae5b457 update comments to match changes to the formal grammar 2021-05-27 21:03:49 -04:00
Jakub Konka
c0aa9292ba build: allow specifying rpaths explicitly (#8912)
It currently looks like that if the user links in a dylib using
`lib_or_exe.linkSystemLibrary`, and the linked lib doesn't have
a hardcoded path in its description load command but rather it
allows for any runtime path via `@rpath`, then it is not possible
to specify the runtime path explicitly using the build system.
2021-05-27 21:01:32 -04:00
Isaac Freund
ec10595b65 stage2: disallow trailing dot on float literals
This disallows e.g. `1.` or `0x1.` as a float literal, which is
consistent with the grammar.
2021-05-27 21:00:44 -04:00
Andrew Kelley
4bf8ec9952 Merge pull request #8910 from mattbork/parser-small-allocs
Use shared scratch buffer to avoid allocating and freeing many small lists in parse.zig
2021-05-27 17:39:55 -04:00
Frank Denis
7674a8b43d p256: update to the last fiat-crypto code & share PC tables
fiat-crypto now generates proper types, so take advantage of that.

Add mixed subtraction and double base multiplication.

We will eventually leverage mixed addition/subtraction for fixed
base multiplication. The reason we don't right now is that
precomputing the tables at comptime would take forever.
We don't use combs for the same reason. Stage2 + less function
calls in the fiat-crypto generated code will eventually address
that.

Also make the edwards25519 code consistent with these changes.

No functional changes.
2021-05-27 16:35:10 -04:00
Matthew Borkowski
80c86ec960 keep temporary list from escaping parseParamDeclList, make SmallSpan.multi hold Node.SubRange instead of owned memory 2021-05-27 14:30:42 -04:00
Jakub Konka
d8d92dafe8 zld: search for .a before .dylib by default
Change default behaviour to search for static archives before searching
for dynamic libraries if no flag such as `-search_paths_first` is
specified. Also, fix a bug with early break from outer loop (label
in the wrong place).
2021-05-27 15:33:48 +02:00
Jakub Konka
ae15281c05 zld: dylib paths need nul terminator included 2021-05-27 11:36:13 +02:00
Matthew Borkowski
9ddd12ea14 parse.zig: use shared scratch buffer to avoid allocating and freeing many small lists 2021-05-26 22:01:04 -04:00
Matthew Borkowski
f750618846 stop tokenizer from recognizing lone @ or @ followed by a digit as a builtin 2021-05-26 04:13:04 -04:00
Andrew Kelley
44de884980 tokenizer: fix crash on multiline string with only 1 backslash
Closes #8904
2021-05-25 18:13:10 -07:00
LemonBoy
3ed6379192 stage1: Store target info in the LLVM module
This is needed to let LLVM (or, better, libLTO) produce code using the
target options specified by the user.

Fix #8803
2021-05-25 18:03:05 -04:00
Andrew Kelley
2f538f30fd Merge pull request #8894 from xxxbxxx/standalone_buildmodes
add standalone test for c compiler with build modes
2021-05-25 15:44:38 -04:00
Andrew Kelley
5c25160452 Merge pull request #8892 from mattbork/prec-doc
fix position of `orelse` and `catch` in precedence table documentation
2021-05-25 15:39:43 -04:00
joachimschmidt557
4c75f834e7 Re-enable building the self-hosted compiler for 32-bit targets 2021-05-25 15:38:32 -04:00
Matthew Borkowski
b01e5d9301 fix position of .* and .? in operator precedence table documentation 2021-05-25 00:09:28 -04:00
xavier
acaa0b8f08 remove reduntant new/delete implementation
The same code is provided by both libxx and libxxabi, and removed at linktime.
2021-05-25 00:42:39 +02:00
xavier
32154fbf0d add a standalone for zig as a c/c++ compiler 2021-05-25 00:42:31 +02:00
xavier
7e4f28fac9 standalone tests may now test cross targets and build modes. 2021-05-25 00:19:23 +02:00
Matthew Borkowski
46d8e010a0 fix position of orelse and catch in precedence table and remove misplaced error union operator 2021-05-24 16:58:20 -04:00
Andrew Kelley
8c5d4295e5 Merge pull request #8876 from xxxbxxx/cxx-lto
build libc++ with lto and function-sections
2021-05-24 13:58:02 -04:00
xavier
8275c771c8 zig cc: expose header files when linking libunwind 2021-05-24 13:48:49 -04:00
Jens Goldberg
1df993706a Fix socklen_t cast in win32 recvfrom
All other uses of `ws2_32.socklen_t` in windows.zig casts the value to an i32. `recvfrom` should do so as well; it currently errors out with `expected type '?*i32', found '?*u32'`.
2021-05-24 13:46:35 -04:00
Andrew Kelley
0a99898b98 Merge pull request #8862 from hoanga/haiku-support-linker
further haiku support    initial compile and link
2021-05-24 13:45:47 -04:00
Andrew Kelley
156b968ad8 stage2: remove dead code; rename crtbegin_dir to gcc_dir 2021-05-24 10:41:59 -07:00
Al Hoang
e8cf15236d add haiku case to csu 2021-05-24 10:39:02 -07:00
Al Hoang
5280ea5d22 update compilation and elf link for haiku case
* for some reason part of the linkable bits for the crt libraries
  are split in different locations for haiku. this changeset
  accomodates this situation (crtbegin_dir lookup)
2021-05-24 10:39:02 -07:00
Al Hoang
c4a4330cc7 haiku case for libc link flags 2021-05-24 10:39:01 -07:00
Al Hoang
2be2c983cb enable symbol lookup for haiku 2021-05-24 10:39:01 -07:00
Al Hoang
db8eae65de avoid usage of execv on Haiku 2021-05-24 10:39:01 -07:00
Michael Dusan
8cebbc352a housekeeping: builtin.arch → builtin.cpu.arch 2021-05-24 13:38:47 -04:00
Michael Dusan
1dc7764f2d clang driver: fix lost argv[0] 2021-05-24 13:26:52 -04:00
Ryan Liptak
6426519e32 zig fmt: Remove workaround for . and .. path handling on Windows
Added in #4655/#5187, obsoleted by #7664
2021-05-24 13:24:21 -04:00
Michael Dusan
75cd37b8f7 dragonfly: pass zig build test 2021-05-24 10:24:41 -04:00
Andrew Kelley
55811d8dac stage2: introduce clangAssemblerSupportsMcpuArg
Clang has a completely inconsistent CLI for its integrated assembler for
each target architecture. For x86_64, for example, it does not accept
an -mcpu parameter, and emits "warning: unused parameter". However, for
ARM, -mcpu is needed in order to properly lower assembly to machine code
instructions (see new standalone test case provided thanks to @g-w1).

This is a compromise between
b8f85a805b and
afb9f695b1.
2021-05-23 21:51:10 -07:00
Andrew Kelley
609207801a make "gnu" (mingw-w64) the default C ABI on Windows
Closes #6565
2021-05-24 00:13:54 -04:00
Andrew Kelley
8fa6ca6daa Merge pull request #8879 from squeek502/dot-and-dotdot-test
Add . and .. tests for std.fs functions
2021-05-23 23:26:05 -04:00
Michael Dusan
b3e4832240 housekeeping: remove pub from ccPrintFileName()
- this was inadvertently made public while iterating on #8730
2021-05-23 19:45:05 -04:00
Ryan Liptak
78019452f7 Add updateFile to . and .. fs tests 2021-05-23 16:35:31 -07:00
Andrew Kelley
b8f85a805b Revert "stage2: add support for zig cc assembler -mcpu option"
This reverts commit afb9f695b1.

I don't think this was ever actually verified to fix the thing it
purported to, and it started causing warnings for unused command line
parameters.
2021-05-23 16:32:22 -07:00
Ryan Liptak
1bc0df7250 Add . and .. tests for std.fs functions
These tests check that . and .. are able to be handled by the std.fs functions. Before #7664, these tests would have failed on Windows.

Closes #4659
2021-05-23 16:22:27 -07:00
Andrew Kelley
ae01c65a58 stage2: fix reference to musl arch name
Also rename musl.archMuslName to musl.archName.

Fixes a merge conflict from #8730 and #8837
2021-05-23 13:32:52 -07:00
Michael Dusan
0f26120377 overhaul elf csu (c-runtime startup) logic
- more support for linux, android, freebsd, netbsd, openbsd, dragonfly
- centralize musl utils; musl logic is no longer intertwined with csu
- fix musl compilation to build crti/crtn for full archs list
- fix openbsd to support `zig build-lib -dynamic`
- initial dragonfly linking success (with a warning)

ancillary:

- fix emutls (openbsd) tests to use `try`
2021-05-23 15:38:57 -04:00
Daniele Cocca
44e480aa2c translate_c: remove unused WriteFileStep import 2021-05-23 14:35:19 -04:00
xavier
a6e65f3a0e keep statically linked libc++ symbols hidden. 2021-05-23 19:58:38 +02:00
xavier
40d8518253 apply -flto and -ffunction-sections when compiling libc++ 2021-05-23 19:58:26 +02:00
Evan Haas
d321a4b765 translate-c: Translate FnDecl's that appear within functions 2021-05-23 15:42:36 +03:00
joachimschmidt557
e8236551ab stage2: Move BlockData out of ir.Inst.Block 2021-05-22 21:15:25 -04:00
Andrew Kelley
1c636e2564 Merge pull request #8844 from ifreund/inline
Support inline keyword as well as callconv(.Inline)
2021-05-22 20:56:30 -04:00
jacob gw
9baf891772 stage2: astgen error for return or try in defer block 2021-05-22 20:54:14 -04:00
Sébastien Marie
ceacb7d247 openbsd: complete kqueue(2) constant definitions 2021-05-22 20:52:44 -04:00
Isaac Freund
b2126d3345 stage2: only pass -lm -lc -ldl for android libc
The other libc components are not available on android.
2021-05-22 20:52:14 -04:00
Sobeston
742d588b3a std.os: munmap takes a const pointer 2021-05-22 20:51:53 -04:00
Matthew Borkowski
d7bf4f8070 fix Boyer-Moore-Horspool algorithm in indexOfPos and lastIndexOf when element type is larger than a byte 2021-05-22 20:51:17 -04:00
Jakub Konka
8c87a981f1 cc,wasi: force isysroot to / 2021-05-22 20:50:06 -04:00
Andrew Kelley
b750e074c6 stage2: rework astgen command into zig ast-check
This addresses the use case of quickly reporting AstGen compile errors
for a file, for use with an IDE for example.

 * Rename from `zig asgen` to `zig ast-check`
 * It is now a command always available; not only in debug builds.
 * Give it usage text and proper CLI parsing.
 * Support reading from stdin when no positional arg is provided.
 * `-t` flag makes it print textual ZIR. Without this flag, it only
   provides compile errors.
 * Support `--color` parameter to override the tty detection

closes #8871
2021-05-22 17:23:16 -07:00
Andrew Kelley
51701fb2da stage2: omit printing source lines in compile errors
when configured to not use tty awareness
2021-05-22 17:17:32 -07:00
Andrew Kelley
63aabbbba7 Merge pull request #8852 from Snektron/spirv
SPIR-V: More codegen
2021-05-22 18:20:20 -04:00
Andrew Kelley
7cd9b30e0a Merge pull request #7664 from marler8997/fixWindowsPaths
implement nt path conversion for windows
2021-05-22 17:58:59 -04:00
Andrew Kelley
79dee75b1c stage2: rename ir.zig to air.zig
We've settled on the nomenclature for the artifacts the compiler
pipeline produces:

1. Tokens
2. AST (Abstract Syntax Tree)
3. ZIR (Zig Intermediate Representation)
4. AIR (Analyzed Intermediate Representation)
5. Machine Code

Renaming `ir` identifiers to `air` will come with the inevitable
air-memory-layout branch that I plan to start after the 0.8.0 release.
2021-05-22 14:29:16 -07:00
Jakub Konka
9d311e9960 Merge pull request #8857 from ziglang/cc-wasm-ar
wasm: produce static lib by default and rename produced object files to simply .o from .o.wasm
2021-05-22 16:13:47 +02:00
Jakub Konka
2b0d322ea0 zld: permit system static libs
This commits permits passing in static archives using the system
lib flag `-la`. With this commit, `zig ld` will now look firstly for
a dynamic library (which always takes precedence), and will fall back
on `liba.a` if the dylib is not found. The static archive is searched
for in the system lib search dirs like the dylibs.
2021-05-22 16:12:45 +02:00
Robin Voetter
cba97e4773 SPIR-V: Make functions which always return a null result return void instead 2021-05-22 16:11:56 +02:00
Robin Voetter
228f71fa0c SPIR-V: Generate locals at the start of a function 2021-05-22 16:11:56 +02:00
Robin Voetter
6634abfd26 SPIR-V: Debug line info/source info 2021-05-22 16:11:56 +02:00
Robin Voetter
e3be1a1e88 SPIR-V: DeclGen constructor/destructor 2021-05-22 16:11:56 +02:00
Robin Voetter
46184ab85e SPIR-V: branching 2021-05-22 16:11:56 +02:00
Robin Voetter
5edc5f9730 SPIR-V: Pass source location to genType and genConstant for better error reporting 2021-05-22 16:11:56 +02:00
Robin Voetter
63d0576f1c SPIR-V: Preliminary alloc/store/load generation 2021-05-22 16:11:56 +02:00
Robin Voetter
6a121d9ccd SPIR-V: Split out genCmp from genBinOp 2021-05-22 16:11:56 +02:00
Robin Voetter
b8444d2c51 SPIR-V: Preliminary integer constant encoding 2021-05-22 16:11:56 +02:00
Robin Voetter
c190b2ff83 SPIR-V: ResultId and Word aliases to improve code clarity 2021-05-22 16:11:56 +02:00
Robin Voetter
9ddd7f4a60 SPIR-V: Put types in SPIRVModule, some general restructuring 2021-05-22 16:11:56 +02:00
Robin Voetter
bcda3c5b82 SPIR-V: Use Value.toFloat instead of switching on value tag when generating float constants 2021-05-22 16:11:56 +02:00
Matthew Borkowski
f4101c1153 fix accidental quadratic dependence on haystack length in replace and replacementSize (#8859) 2021-05-22 10:55:28 +02:00
Jakub Konka
bd325d1bd9 wasm: fix object extension to standard .o from .o.wasm
This should offer more compatibility with external tooling when
cross-compiling to wasm with zig.
2021-05-21 22:29:36 +02:00
Jakub Konka
fbd96907c9 wasm: build static archive unless -dynamic specified
This matches the behaviour for other targets in that

```
zig build-lib math.zig -target wasm32-freestanding
```

produces now `libmath.a` while

```
zig build-lib math.zig -dynamic -target wasm32-freestanding
```

is required to create a loadable Wasm module.
2021-05-21 20:24:13 +02:00
Jonathan Marler
b0116afd8a handle relative paths with too many ".." 2021-05-21 01:29:40 -06:00
Jakub Konka
4b69bd61e4 Merge pull request #8837 from ziglang/cc-wasm32-wasi
cc,wasi: ship WASI libc and autobuild it when needed
2021-05-21 09:04:16 +02:00
Andrew Kelley
0267abfe9b Merge pull request #8847 from Luukdegram/wasm-struct-switch
stage2: wasm - Structs and switch support
2021-05-20 18:55:49 -04:00
mason1920
884547f177 Const correct GUID parameter of getInfo and setInfo 2021-05-20 18:53:59 -04:00
Andrew Kelley
495e996169 Merge pull request #8776 from notviri/windows-wm-constants
fix & add some Win32 window message constants
2021-05-20 18:51:45 -04:00
Matthew Borkowski
510f858143 fix calculation of max_io_bits in PackedIntIo 2021-05-20 18:47:16 -04:00
Andrew Kelley
3845c264a6 stage2: fix compile error rendering for hard tabs
render them as 1 space instead. This fixes the column caret.
2021-05-20 15:20:27 -07:00
Jonathan Marler
59de5d0350 add the openDir cwd parent test 2021-05-20 14:00:41 -06:00
Jonathan Marler
a72ad61cd4 have collapseRepeats return slice intead of just len 2021-05-20 14:00:41 -06:00
Jonathan Marler
666584067a implement nt path conversion for windows 2021-05-20 14:00:40 -06:00
Isaac Freund
563ea60a86 translate-c: use inline keyword instead of callconv(.Inline) 2021-05-20 21:59:46 +02:00
Andrew Kelley
34d0542a53 Merge pull request #8695 from Bxil/socket
std.os: WSAStartup is now called upon socket creation when needed
2021-05-20 15:31:22 -04:00
Andrew Kelley
61850f8883 std: Windows: WSASocketW ensures WSAStartup
When WSASocketW gets WSANOTINITIALISED, now it will lock a mutex to
safely call WSAStartup and then try again one time.

This implementation:
 * Does not use recursion
 * Contains a detailed doc comment explaining why things are how they are
 * Is careful about which errors are surfaced in the respective error
   sets. `std.os.socket` intentionally does not have "not initialised"
   as one of the possible errors.
2021-05-20 12:28:30 -07:00
Bxil
85c2ffc9ba std.os: WSAStartup is now called upon socket creation when needed 2021-05-20 11:22:55 -07:00
Andrew Kelley
df56bf94a2 Merge pull request #8789 from Luukdegram/wasm-enum
stage2: wasm backend - Enums
2021-05-20 14:03:54 -04:00
Luuk de Gram
0ac56e7f3a Add test cases for switches 2021-05-20 19:59:37 +02:00
Isaac Freund
5b850d5c92 Run zig fmt on src/ and lib/std/
This replaces callconv(.Inline) with the more idiomatic inline keyword.
2021-05-20 17:14:18 +02:00
Isaac Freund
4a582734fd zig fmt: replace callconv(.Inline) with the inline keyword 2021-05-20 17:13:47 +02:00
Jakub Konka
b63c92f0b9 cc,wasi: do not add stack protector 2021-05-20 16:54:00 +02:00
Jakub Konka
3a5d0f7700 wasm: link dynamically by default when targeting wasm
This matches the behaviour of other languages and leaves us
the ability to create actual static Wasm archives with

```
zig build-lib -static some.zig
```

which can then be combined with other Wasm object files and linked
into either a Wasm lib or executable using `wasm-ld`.

Update langref to reflect the fact we now ship WASI libc.
2021-05-20 16:54:00 +02:00
Jakub Konka
f291b8b9bc cc,wasi: remove unused headers and sources 2021-05-20 16:54:00 +02:00
Jakub Konka
6d5002028a cc,wasi: link compiled WASI libc with wasm-ld 2021-05-20 16:54:00 +02:00
Jakub Konka
f102a5800c cc,wasi: compile all WASI libc objects 2021-05-20 16:54:00 +02:00
Jakub Konka
60d8779eae cc,wasi: add source file paths to wasi_libc.zig 2021-05-20 16:54:00 +02:00
Jakub Konka
7b74de7d71 wasi,cc: fix naming and add stubs for building
Rename include dir to match the convention:
  from `wasm32-wasi` to `wasm-wasi-musl`

Add building stubs which will be used to build and cache WASI
libc sysroot.
2021-05-20 16:54:00 +02:00
Jakub Konka
782cfedaf6 cc,wasi: add wasi-libc source 2021-05-20 16:54:00 +02:00
Jakub Konka
a901d44b4e cc,wasi: add wasi libc headers 2021-05-20 16:53:59 +02:00
Jakub Konka
b09936d728 Merge pull request #8842 from LemonBoy/thinko
Some TLCSPRNG fixes
2021-05-20 16:53:24 +02:00
Luuk de Gram
f8d0501f50 Also support multi-prong branches 2021-05-20 16:21:11 +02:00
LemonBoy
ec9a44b2a5 std: Make atfork handler more robust
The atfork handler is executed even when fork()-ing threads that have
never initialized their local csprng. Handle this case gracefully
instead of raising a runtime error.

Fixes #8841
2021-05-20 15:28:59 +02:00
LemonBoy
abfe7f96dd std: Call pthread_atfork only once
Some libc implementations (glib) deduplicate identical hooks, others
(musl, macos) do not and blindly append them to an internal list.
Ensure there's only a single call to pthread_atfork to prevent unbounded
memory use when lots of threads/forks are used.
2021-05-20 15:26:17 +02:00
Isaac Freund
3fd8ac092e stage2: support inline keyword on function decls
This is an alternative to callconv(.Inline). Using an inline keyword
as well as an explicit callconv() is a compile error.
2021-05-20 14:54:44 +02:00
Isaac Freund
569525f03e stage1: support inline keyword on function decls
This is an alternative to callconv(.Inline). Using an inline keyword
as well as an explicit callconv() is a compile error.
2021-05-20 14:54:44 +02:00
LemonBoy
992c02ab95 std: Fix error in tlcsprng init sequence
The fallback case was actually switched with the success one.
2021-05-20 14:43:04 +02:00
Luuk de Gram
81d8fe7558 stage2 wasm: Support basic switches
- Adds support for single branches
- Allows both enums and integers
- Supports 'else' branch
2021-05-20 14:21:02 +02:00
Luuk de Gram
87a9c6946d wasm backend: implement multi_value for WValue
This allows us to differentiate between regular locals and variables that create multiple locals
on the stack such as optionals and structs.
Now `struct_a = struct_b;` works and only updates a reference, rather than update all local's values.

Also created more test cases to test against this.
2021-05-20 09:25:02 +02:00
Andrew Kelley
9910bfa6d8 ci: use a different ssh private key to deploy the website
This changes the deploy key to a different one on www.ziglang.org so
that we can test notifications.
2021-05-19 21:36:48 -07:00
Andrew Kelley
a8eac0cf07 stage2 test harness: show source file name
Also support specifying source file name in compile error test cases.

closes #8829
2021-05-19 20:59:06 -07:00
Andrew Kelley
bfd051a53c stage2: use c_allocator not raw_c_allocator
when the raw C allocator alignment is not sufficient.

closes #8835
2021-05-19 10:26:50 -07:00
Evan Haas
1273bc277f translate-c: add support for __cleanup__ attribute
Use a `defer` statement to implement the C __cleanup__ attribute.

See https://gcc.gnu.org/onlinedocs/gcc/Common-Variable-Attributes.html
2021-05-19 12:12:18 +03:00
Sébastien Marie
28a89b9ebc openbsd: convert builtin.arch to builtin.target.cpu.arch 2021-05-19 10:55:21 +02:00
Luuk de Gram
6962647862 Do not create a local for the struct itself + test cases 2021-05-19 10:37:44 +02:00
Luuk de Gram
ac5fd47e2e Initial support for structs in wasm backend
- Creates a 'local' for the struct itself and each field
- The index of the local is calculated from the struct's local index + field index
2021-05-19 10:37:44 +02:00
Luuk de Gram
141a0cbb5a Explicit return & more complex wasm enum test
- When returning within a block, we must use an explicit return opcode. For now always emit the opcode when calling return, rather than using implicit return statements.
- Also added a more comprehensive test case to test for enum values using conditions
2021-05-19 10:35:45 +02:00
Andrew Kelley
22f51f2f7d Merge pull request #8667 from sagehane/nixos
std.zig: handle -frandom-seed in NIX_CFLAGS_COMPILE
2021-05-19 03:28:12 -04:00
Luuk de Gram
9ddede2950 Add enum test case for wasm backend 2021-05-19 08:59:11 +02:00
Luuk de Gram
b22e22ef55 wasm backend - Initial enum support
- This adds support for enum values using field indexes
- EmitConstant's signature was changed so it's easier to recursively call it using a different type (enum -> int type).
- Implemented initial support for bitcast which for now just returns the `WValue` of the operand.
2021-05-19 08:59:08 +02:00
Isaac Freund
1d6c804b29 stage2: only default to linking system libc if linking system libs
We do need to link the system libc if linking system libraries as
they may potentially be compiled against e.g. a newer glibc version
than zig can provide. However if not linking system libraries, using
the zig provided libc is more reliable as it does not depend on any
quirks of the host system or being able to invoke the system cc to
find include dirs.
2021-05-19 01:22:36 -04:00
Andrew Kelley
8861ee18f7 std: add android __SIZEOF_PTHREAD_MUTEX_T
closes #8384
2021-05-18 21:08:41 -07:00
Andrew Kelley
6435750c99 Merge pull request #8554 from ziglang/stage2-whole-file-astgen
Stage2 whole file astgen
2021-05-18 20:20:46 -04:00
Andrew Kelley
667236668f build.zig: blank out "*test.zig" files instead of omit
Now that `@import` of a non-existent file name is a compile error, the
Zig installation needs to include files that end with test.zig. However
we still want to avoid bloat in the installation size, so we blank them
out instead of omitting them entirely.

Now AstGen of the full standard library can complete successfully on a
Zig installation rather than erroring out with file not found.
2021-05-18 17:18:42 -07:00
Andrew Kelley
2c12f5f55b stage2 tests: fix missing 'pub' in one of the test cases 2021-05-18 12:53:23 -07:00
Andrew Kelley
a9cd9b021b Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
I want the updated Drone CI stuff to get the CI green.
2021-05-18 12:37:03 -07:00
Andrew Kelley
ab8f8465a3 stage2: fix deletion of Decls that get re-referenced
When scanDecls happens, we create stub Decl objects that
have not been semantically analyzed. When they get referenced,
they get semantically analyzed.

Before this commit, when they got unreferenced, they were completely
deleted, including deleted from the containing Namespace.

However, if the update did not cause the containing Namespace to get
deleted, for example, if `std.builtin.ExportOptions` is no longer
referenced, but `std.builtin` is still referenced, and then `ExportOptions`
gets referenced again, the Namespace would be incorrectly missing the
Decl, so we get an incorrect "no such member" error.

The solution is to, when dealing with a no longer referenced Decl
objects during an update, clear them to the state they would be in
on a fresh scanDecl, rather than completely deleting them.
2021-05-18 12:35:36 -07:00
Andrew Kelley
d228d86059 ci: drone: refresh docker image with latest alpine
hopefully resolves the failures we've been seeing recently
2021-05-18 11:29:14 -07:00
Andrew Kelley
4187008b5e std: update freebsd bits to new builtin 2021-05-18 10:49:33 -07:00
Jakub Konka
7588fcdd2a Merge pull request #8806 from ziglang/zld-link-shared
zig ld: add preliminary mechanism for linking dylibs
2021-05-18 11:04:06 +02:00
Jakub Konka
cb45c5521a zld: refactor warnings 2021-05-18 09:28:00 +02:00
Jakub Konka
daaec68aec zld: apply @mikdusan's suggestions
Library search paths now should be closer to what ld64 does.
Also, cwd now has to be specified explicitly to be considered.
2021-05-18 09:28:00 +02:00
Jakub Konka
1dac5f5214 zld: parse dylibs as positionals
* add preliminary rpath support
* enable shared_library test on x86_64 macOS
2021-05-18 09:28:00 +02:00
Jakub Konka
ca772735c3 zld: refactor order of searching for the dylibs
Current assumed order is:
* cwd
* `self.base.options.lib_dirs`
* finally, if `self.base.options.syslibroot` is defined,
  `self.base.options.lib_dirs` prefixed with syslibroot
2021-05-18 09:28:00 +02:00
Jakub Konka
73c015b956 zld: parse dylib id 2021-05-18 09:28:00 +02:00
Jakub Konka
17b2588598 zld: refactor out logic for dylib LC creation 2021-05-18 09:28:00 +02:00
Jakub Konka
138cecc028 zld: add prelim way of linking dylibs
The support is minimalistic in the sense that we only support actual
dylib files and not stubs/tbds yet, and we also don't support re-exports
just yet.
2021-05-18 09:28:00 +02:00
Evan Haas
35c694d614 translate-c: Demote initialization of opaque types
This fixes a segfault in translate-c that would previously occur when
initializing structs with unnamed bitfields, due to a failed assertion in
`transInitListExprRecord`. Unnamed bitfields do not have initializers,
so `transInitListExprRecord` erroneously assumes that `init_count` equals
the number of fields in the record.

Since attempting to initialize an opaque type is a syntax error in Zig,
we can just demote any attempts to initialize them.
2021-05-18 09:04:19 +03:00
Andrew Kelley
93dbf30dcf std.fmt: fix regressions from master
A previous commit from this branch incorrectly changed the usage of
`comptime` keyword, and broke the std lib tests. This commit adds
`comptime` to a few function calls, correcting the behavior.
2021-05-17 19:53:46 -07:00
Andrew Kelley
615d45da77 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * src/codegen/spirv.zig
 * src/link/SpirV.zig

We're going to want to improve the stage2 test harness to print
the source file name when a compile error occurs otherwise std lib
contributors are going to see some confusing CI failures when they cause
stage2 AstGen compile errors.
2021-05-17 19:30:38 -07:00
Andrew Kelley
1d3f76bbda stage2: skip recursion test on some hosts
In order for this test to pass, the host linking/start code needs to
support explicitly setting the stack size. Zig defaults to 16 MiB stack
size, which is enough to pass the test in Debug builds, however, most
operating systems do not honor the stack size we request for and give a
smaller amount.

Eventually the goal is to pass this test on all hosts.
2021-05-17 19:14:13 -07:00
Andrew Kelley
1d808d0dd2 stage2: fix crash in switch compile error
when the AST for the switch has never been loaded
2021-05-17 19:11:11 -07:00
Andrew Kelley
0dd0c9620d Merge pull request #8796 from Snektron/spirv
SPIR-V: Codegen basis
2021-05-17 21:25:02 -04:00
Andrew Kelley
67f5a28257 Sema: use a hash map for ZIR->AIR mapping
Previously, ZIR was per-function so we could simply allocate a slice for
all ZIR instructions. However now ZIR is whole-file, so we need a sparse
mapping of ZIR to AIR instructions in order to not waste memory.
2021-05-17 17:39:52 -07:00
Andrew Kelley
5cacc446c4 stage2: update @import("builtin") API usage 2021-05-17 17:39:26 -07:00
Andrew Kelley
98a28ece0b remove separate issues from my branch todo file 2021-05-17 16:09:39 -07:00
Andrew Kelley
910f67f77b behavior tests: re-enable commented out test
Not sure why it was failing, also not sure why it started passing again
2021-05-17 16:09:20 -07:00
Andrew Kelley
731c35f15a stage2: get rid of NameHash
Previously, stage2 used a global decl_table for all Decl objects, keyed
by a 16-byte name hash that was hopefully unique. Now, there is a tree
of Namespace objects that own their named Decl objects.
2021-05-17 16:09:20 -07:00
Andrew Kelley
3d99fb3352 stage2: get rid of DeclRef 2021-05-17 16:09:20 -07:00
Andrew Kelley
d5e894a9a7 stage2: get rid of failed_root_src_file 2021-05-17 16:09:20 -07:00
Andrew Kelley
ab6b0ad8a4 test runner: prepare stage2 workaround
This provides a simpler test runner that exercises fewer language
features so that we can get to the point faster where `zig test` works
for stage2.
2021-05-17 16:09:20 -07:00
Andrew Kelley
8a7a07f30d stage2: test cases take advantage of pub fn main support 2021-05-17 16:09:20 -07:00
Andrew Kelley
83677074f9 std: update regarding std.builtin reorganization
There are also some regressed std.fmt tests here and I haven't figured
out what's wrong yet.
2021-05-17 16:08:09 -07:00
Andrew Kelley
8cfa231104 update langref, compile-error tests, safety tests
for the std.builtin re-arranging
2021-05-17 15:25:27 -07:00
Andrew Kelley
f41892f736 std: @import("builtin").StackTrace -> std.builtin.StackTrace 2021-05-17 14:36:51 -07:00
Andrew Kelley
84fdeb47a3 compiler-rt: fix usage of builtin
In this branch std.builtin and `@import("builtin")` are rearranged, fix
a trivial compile error due to the conflict with master.
2021-05-17 14:18:30 -07:00
joachimschmidt557
65cee0b3fd stage2 ARM: correct spilling in genArmMul as well 2021-05-17 17:18:01 -04:00
LemonBoy
b7eab32f42 std: Allocate tlscsprng memory as needed
Let mmap allocate a block of memory that's wide enough to use with
MADV_WIPEONFORK, madvise granularity is the current system page size
(using a static buffer of mem.page_size bytes would be wrong, that's the
minimum page size).

As a result, we don't zero some random chunk of memory every time we
fork the process.

Fixes #7609
2021-05-17 17:16:38 -04:00
LemonBoy
fe1a166589 translate-c: Add @truncate where needed
Make getLimitedValue API much easier to use with zig.
Fixes the compilation on 32bit hosts.
2021-05-17 17:15:22 -04:00
Andrew Kelley
23fd15fd76 link/Elf: remove unintended link again libunwind
This was a merge conflict with master branch. The logic for linking
libunwind is already handled above.
2021-05-17 13:56:17 -07:00
Andrew Kelley
8405d6f7e2 link/MachO: bring in some of the Elf logic
There was missing incremental compilation logic in the MachO linker
code, causing test failures. With this logic ported over from the
corresponding ELF logic, tests pass again.
2021-05-17 13:46:54 -07:00
Andrew Kelley
3697022a41 stage2: avoid calling freeDecl when hasCodeGenBits == false
Previously the frontend incorrectly called freeDecl for structs, which
never got allocateDecl called for them. There was simply a missing check
for hasCodeGenBits().
2021-05-17 13:44:20 -07:00
aiz
5414bd48ed std.math.Complex: Change new() to init() 2021-05-17 21:57:51 +02:00
Andrew Kelley
d839835273 stage2: add some debug logs for when link functions are called 2021-05-17 11:33:21 -07:00
Michael Dusan
04d95ea419 ci linux: bump qemu-5.2.0.1
- apply patch for qemu-user syscall do_sendrecvmsg_locked
- see #8750
2021-05-17 12:06:25 -04:00
Aiz672
8467373bb8 Remove isIntegerNumber and isFloatingNumber 2021-05-17 08:41:44 +03:00
Andrew Kelley
751bb12a96 stage2: fix error message coloring
After 7a4b53fdee, bold no longer changes
the color back, so we need an extra reset.
2021-05-16 14:31:55 -07:00
Andrew Kelley
f4ee46e839 MachO/DebugSymbols: fix debug line offset
In c8b78706b7 I incorrectly made it be the
line offset from Decl to function lbrace; it needed to be line offset
from lbrace to rbrace.
2021-05-16 14:20:51 -07:00
Jonathan Marler
5042a47682 add missing EBADF error code for openat 2021-05-16 22:36:50 +02:00
Robin Voetter
880473dc3f SPIR-V: Unary not operation 2021-05-16 14:55:09 +02:00
Robin Voetter
489b3ef7d4 SPIR-V: bool binary operations 2021-05-16 14:52:11 +02:00
Robin Voetter
585122b1ac SPIR-V: comparison and equality operations 2021-05-16 14:46:58 +02:00
Robin Voetter
f14000c7e1 SPIR-V: More bitwise binary operations 2021-05-16 14:20:18 +02:00
Robin Voetter
4735e95d16 SPIR-V: More binary operations 2021-05-16 14:20:12 +02:00
Robin Voetter
10678af876 SPIR-V: genBinOp setup 2021-05-16 14:13:23 +02:00
Robin Voetter
ae2e21639a SPIR-V: Some initial floating point constant generation 2021-05-16 14:13:23 +02:00
Robin Voetter
cbf5280f54 SPIR-V: Some instructions + constant generation setup 2021-05-16 14:13:23 +02:00
Robin Voetter
da0cc732ea SPIR-V: Function parameter generation 2021-05-16 14:13:23 +02:00
Robin Voetter
074cb9f1da SPIR-V: OpFunction/OpFunctionEnd generation 2021-05-16 14:13:23 +02:00
Robin Voetter
4403f3598a SPIR-V: Proper floating point type generation 2021-05-16 14:13:23 +02:00
Robin Voetter
38cdfebad3 SPIR-V: Function prototype generation 2021-05-16 14:13:23 +02:00
Robin Voetter
458c338aeb SPIR-V: Compute backing integer bits 2021-05-16 14:13:23 +02:00
Robin Voetter
de6df2bc12 SPIR-V: Restructure codegen a bit 2021-05-16 14:13:23 +02:00
Andrew Kelley
c8b78706b7 linker: update MachO DebugSymbols to use the new line/column Decl API 2021-05-16 00:04:16 -07:00
Andrew Kelley
ae04ec776d Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Need that _main -> main improvement
2021-05-16 00:00:36 -07:00
Jakub Konka
6461b95163 macho: fix DWARF in dSYM and sym naming more consistent
* Advance line and PC prior to ending sequence in debug line program
  for a fn_decl. This is equivalent to closing scope in the debugger
  and without it, the debugger will not map source-to-address info
  as a result will not print the source when breaking at a symbol.
* Fix debug aranges sentinels to be of the size as the actual tuple
  descriptor (assuming segment selector to be ommitted). In summary,
  the sentinels were 32bit 0s, whereas they ought to be 64bit 0s.
* Make naming of symbols in the binary more consistent by prefixing
  each symbol name with an underscore '_'.
2021-05-16 08:12:29 +02:00
Andrew Kelley
9a95478c62 cmake: remove deleted file
This should have been part of 07606d12da
2021-05-15 21:46:36 -07:00
Andrew Kelley
597082adf4 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * build.zig
 * src/Compilation.zig
 * src/codegen/spirv/spec.zig
 * src/link/SpirV.zig
 * test/stage2/darwin.zig
   - this one might be problematic; start.zig looks for `main` in the
     root source file, not `_main`. Not sure why there is an underscore
     there in master branch.
2021-05-15 21:44:38 -07:00
Andrew Kelley
07606d12da stage2: remove SPU Mark II backend
As it stands, the backend is incomplete, and there is no active contributor,
making it dead weight.

However, anyone is free to resurrect this backend at any time.
2021-05-15 21:25:42 -07:00
Andrew Kelley
7cd94d2123 stage2: omit Decl compile errors from failed AstGen files
Just like when new parse errors occur during an update, when new AstGen
errors occur during an update, we do not reveal compile errors for Decl
objects which are inside of a newly failed File. Once the File passes
AstGen successfully, it will be compared with the previously succeeded
ZIR and the saved Decl compile errors will be handled properly.
2021-05-15 21:20:06 -07:00
Andrew Kelley
dc036f5b6f codegen: implement const value rendering for ints <= 64 bits 2021-05-15 21:00:15 -07:00
Isaac Freund
d98e39fa68 stage2: make failure to find native libc verbose 2021-05-15 22:13:28 +02:00
LemonBoy
7a4b53fdee std: Avoid using white color when printing stacktraces
Use .bold instead of .white, the effect is the same for light-on-dark
terminals but greatly improves the readability for dark-on-light ones.

Closes #8761
2021-05-15 13:44:52 -04:00
viri
a994966870 remove range constants 2021-05-15 10:08:07 -06:00
Evan Haas
36da8d02b5 translate-c: translate global (file scope) assembly 2021-05-15 11:53:01 +03:00
Andrew Kelley
607abb5b14 std: dragonfly: fix duplicate definition of sockaddr_storage 2021-05-14 23:16:46 -07:00
Andrew Kelley
5769ed2d44 stage2: compile log stores node offset
Previously, compile log stored full SrcLoc info, which included absolute
AST node index. This becomes invalid after an incremental compilation.
To make it survive incremental compilation, store an offset from parent
Decl instead.
2021-05-14 23:10:38 -07:00
ZapAnton
e94bbc2237 std.testing: Added newline to the error messages
Added newline to every `std.debug.print` message.
Closes https://github.com/ziglang/zig/issues/8777
2021-05-15 01:27:39 -04:00
Andrew Kelley
1e5e664555 Merge pull request #8773 from ziglang/macho-dsym-path
macho: put dSYM bundle in zig-cache
2021-05-15 01:25:37 -04:00
Andrew Kelley
b4692c9a78 stage2: improve Decl dependency management
* Do not report export collision errors until the very end, because it
   is possible, during an update, for a new export to be added before an
   old one is semantically analyzed to be deleted. In such a case there
   should be no compile error.
   - Likewise we defer emitting exports until the end when we know for
     sure what will happen.
 * Sema: Fix not adding a Decl dependency on imported files.
 * Sema: Properly add Decl dependencies for all identifier and namespace
   lookups.
 * After semantic analysis for a Decl, if it is still marked as
   `in_progress`, change it to `dependency_failure` because if the Decl
   itself failed, it would have already been changed during the call to
   add the compile error.
2021-05-14 17:41:22 -07:00
viri
ca575f887c std: re-add weird undocumented Win32 constants
Got deleted. Not documented but sure.
2021-05-14 15:15:20 -06:00
viri
150a3ad6ff std: fix & add os.windows.user32 WM constants 2021-05-14 15:06:47 -06:00
Andrew Kelley
2dcec42b74 Merge pull request #8757 from Snektron/spirv-stuff
SPIR-V: Features + some other stuff
2021-05-14 17:02:51 -04:00
Jakub Konka
e93254412b macho: if strip is true, do not generate dSYM 2021-05-14 22:27:26 +02:00
viri
612ad779bb std: rework math.scalbn (#8733)
* std: fix overflow in math.scalbn32

* std: rewrite math.scalbn to be generic

* std: support f128 in math.isNormal

* std: enable f128 tests in math.scalbn
2021-05-14 16:15:53 -04:00
Andrew Kelley
114c6612cb Merge pull request #8764 from mattbork/json-usefirst
Fix duplicate_field_behavior UseFirst for parse in json.zig
2021-05-14 15:32:32 -04:00
Andrew Kelley
8f35c60b39 stage2: clarify logic of passing -integrated-as to clang
make it clear that the logic is only there to lower the amount of
noise on the clang command line.
2021-05-14 12:24:47 -07:00
LemonBoy
193a926301 stage2: Force Clang to use LLVM's assembler for SPARC targets
This change allows cross-compiling C code for SPARC, if you hit any
error with the internal assembler please open a ticket.
2021-05-14 15:22:22 -04:00
Andrew Kelley
826d833416 Merge pull request #8746 from koachan/sparc64-fixes
Various Linux/SPARCv9 fixes
2021-05-14 15:21:17 -04:00
LemonBoy
a52e472307 stage1: Widen non byte-sized atomic loads/stores
Checking if the size is a power of two is not enough, should also check
if it's a multiple of 8.

Closes #7976
2021-05-14 15:16:24 -04:00
Sahnvour
2d4d4baa42 std.hash_map: use 7 bits of metadata instead of 6
we only effectively need 1 control bit to represent 2 special states for
the metadata (free and tombstone)
this should reduce the number of actual element equality tests, but since
it's very low already, the impact is negligible
2021-05-14 15:15:55 -04:00
joachimschmidt557
8b4e91e18c stage2 register manager: clean up API and add more unit tests 2021-05-14 15:12:33 -04:00
LemonBoy
5185b5619a compiler-rt: Fix signedness mismatch in f128 mul impl
The `1 - shift` expression was computed using small unsigned types and
then casted to i32, producing either an underflow error or an incorrect
result.

Reported by `@notviri` in #8733
2021-05-14 15:11:54 -04:00
Robin Voetter
00428ac11b SPIR-V: Don't parse/render in gen_spirv_spec.zig, just emit in the right format 2021-05-14 19:49:32 +02:00
Robin Voetter
98dc8eb7d9 SPIR-V: Add generated SPIR-V features 2021-05-14 19:49:32 +02:00
Robin Voetter
4fe0a0b82b SPIR-V: SPIR-V feature generation tool
There is a lot left to be desired for this tool, as currently dependencies of extensions and dependencies
of capabilities on extensions are not included:
- There is no machine-readable definition of dependencies of extensions.
- A capability may depend on either of a multitude of extensions, which as of yet cannot be properly
  modelled in the target system.
2021-05-14 19:49:32 +02:00
Robin Voetter
25329ca852 SPIR-V: Split out registry from gen_spirv_spec.zig 2021-05-14 19:49:32 +02:00
Robin Voetter
42f2ff6ec9 SPIR-V: Re-generate spec.zig 2021-05-14 19:49:32 +02:00
Robin Voetter
6d1a4c8b1e SPIR-V: Adapt spec generator to new render api 2021-05-14 19:49:32 +02:00
Robin Voetter
d45e7dfc24 SPIR-V: Begin generating types 2021-05-14 19:49:32 +02:00
Robin Voetter
fa3afede58 SPIR-V: Set default ofmt to spirv 2021-05-14 19:49:32 +02:00
Jakub Konka
af9c6f2c69 macho: put dSYM bundle in zig-cache
Originally, I thought that the dSYM bundle has to reside side-by-side
with the binary it carries the debugging information for. However, it
turns out macOS is clever enough that it auto-searches for matching
dSYM bundle based on the embedded UUID of the binary.

To verify this, run this on your macOS:

```
mdfind "com_apple_xcode_dsym_uuids == <UUID from LC_UUID>"
```

See [here] for more info.

[here]: https://developer.apple.com/documentation/xcode/adding-identifiable-symbol-names-to-a-crash-report
2021-05-14 13:09:40 +02:00
Jakub Konka
00ebbe6df2 macho: require _main as global export in self-hosted
Clean up type and description flags generation for exports
in self-hosted MachO backend.
2021-05-14 13:08:56 +02:00
Jakub Konka
8eea5eddf7 macho: fix bug with symbol growth and realloc 2021-05-14 11:02:43 +02:00
Andrew Kelley
9958652d92 stage2: update test cases to improved source locations 2021-05-14 00:08:29 -07:00
Andrew Kelley
8344a50e1c AstGen: add compile error for decl name conflicts
* Remove the ability for GenZir parent Scope to be null. Now there is a
   Top Scope at the top.
 * Introduce Scope.Namespace to contain a table of decl names in order
   to emit a compile error for name conflicts.
 * Fix use of invalid memory when reporting compile errors by
   duplicating decl names into a temporary heap allocated buffer.
 * Fix memory leak in while and for loops, not cleaning up their
   labeled_breaks and store_to_block_ptr_list arrays.
 * Fix stage2 test cases because now the source location of redundant
   comptime keyword compile errors is improved.
 * Implement compile error for local variable shadowing declaration.
2021-05-13 23:51:22 -07:00
Andrew Kelley
93896ef860 std: dragonfly: fix duplicate definition of sockaddr_storage 2021-05-13 23:50:39 -07:00
Matthew Borkowski
11fd2aa767 fix logic for duplicate comptime fields and avoid freeing comptime fields in parseFree and parseInternal 2021-05-14 01:51:39 -04:00
Andrew Kelley
134853f106 stage2: fix tests expected values 2021-05-13 20:44:34 -07:00
Andrew Kelley
579694893e Sema: remove compile error for comptime function calls
Not sure why that was there - comptime function calls are already
implemented!
2021-05-13 20:09:25 -07:00
Andrew Kelley
2cee19ab21 CLI repl: "run" command handles cross compiled binaries
with an appropriate error message, and does not terminate the repl.
2021-05-13 20:08:35 -07:00
Andrew Kelley
a854795f52 link: fix memory leak of system_libs 2021-05-13 20:08:17 -07:00
Andrew Kelley
edab03bc22 link/MachO: fixes to debug symbols
commitDeclDebugInfo: stop trying to write length 0 debug info - avoids
hitting an error where zig tries to move the debug info section
unnecessarily, gets confused, and reports `error.InputOutput`.

The 2 pieces of code that looked at the source and tried to compute
source line offsets is now improved to match link/Elf - use the
line/column data stored in the Decl object to skip the costly scanning
of source bytes. No need to load Zig source code, AST, or tokens, when
we have the ZIR!
2021-05-13 20:05:41 -07:00
Andrew Kelley
826179bff4 stage2: -lunwind is handled specially
* `-lc++` now implies `-lc`.
 * `-lunwind` is now pulled out into a separate `link_libunwind` flag in
   the frontend driver code. This allows a project to request zig to
   provide libunwind even if the default situation that causes it to be
   implicitly added, is not active.
 * build.zig: ask for -lunwind when building the self-hosted compiler on
   Linux. Otherwise we get linker errors with unresolved symbols to
   libunwind.
2021-05-13 22:42:57 -04:00
Andrew Kelley
78632894da AstGen: fix elision of store_to_block_ptr for condbr 2021-05-13 17:56:01 -07:00
Andrew Kelley
e83cf6a454 Sema: detect and skip over elided instructions
It would be better if AstGen would actually omit these instructions
rather than only marking them as elided, but that can be solved
separately.
2021-05-13 16:50:27 -07:00
Andrew Kelley
76a259799d stage2: only build and link libunwind when linking libc++ 2021-05-13 17:40:39 -04:00
Andrew Kelley
173142cc36 Merge pull request #8611 from shachaf/precedence
parser: Use an operator precedence table
2021-05-13 17:40:03 -04:00
Jakub Konka
1b222cb1ff start.zig: export main with strong linkage
Unmarks `_main` as weak symbol making it global (the entire linked
program) in scope.
2021-05-13 17:24:32 -04:00
Jakub Konka
402264ab0e Add experimental Darling support for cross testing macOS
* for cross testing stage2 tests, we use `darling shell` command
  since the path to the tested binary is relative to cwd
* for the `zig test` command, we simply use `darling` since the
  path to the binary is absolute
2021-05-13 20:31:33 +02:00
Matthew Borkowski
cadb84b3ac fix duplicate_field_behavior UseFirst in json.zig 2021-05-13 09:43:55 -04:00
Matthew Borkowski
e902c19c0e std/json: Fix premature closing brace being considered valid JSON
return error from StreamingParser when reading closing brace when expecting value for an object key
2021-05-13 11:11:28 +02:00
Jakub Konka
4f71852c10 Merge branch 'streamline-stage2-build-script' 2021-05-13 08:24:46 +02:00
Jakub Konka
1aee896cae Merge branch 'master' into streamline-stage2-build-script 2021-05-13 08:24:21 +02:00
Andrew Kelley
b109daacdd stage2: fix test cases to add pub on exported _start fn
This way the start code respects them.
2021-05-12 23:17:24 -07:00
Jakub Konka
6c3050e3c3 macos: link static libc++ when building stage2
With this change, it is now possible to use zig-bootstrap as the
initial C/C++ compiler, and then build stage2 with the resultant
stage1 without the need to link any system libs!
2021-05-13 07:55:59 +02:00
Andrew Kelley
c102e13710 stage2: fix source location of Decl compile errors
In `Module.semaDecl`, the source location being used was double-relative
to the `Decl`, causing a crash when trying to compute byte offset for
the compile error.

Change the source location to node_offset = 0 since the scope being used
makes the source location relative to the Decl, which already has the
source node index populated.
2021-05-12 22:50:47 -07:00
Andrew Kelley
4b59f56434 stage2: build and provide libunwind when compiling for native libc
5ac91794cc made Zig link against the
system libc when targeting the native C ABI. However this made it stop
putting libunwind.a on the linker line when it needed to sometimes,
causing undefined symbols when linking against C++ code.
2021-05-12 22:29:21 -07:00
Andrew Kelley
a7aa3ca66c stage2: build and provide libunwind when compiling for native libc
5ac91794cc made Zig link against the
system libc when targeting the native C ABI. However this made it stop
putting libunwind.a on the linker line when it needed to sometimes,
causing undefined symbols when linking against C++ code.
2021-05-12 22:25:20 -07:00
Andrew Kelley
344dc0cc0f stage2: fix handling of "prev successful ZIR"
Before this change, the attempt to save the most recent successful ZIR
code only worked in some cases; this reworks the code to be more robust,
thereby fixing a crash when running the stage2 "enums" CBE test cases.
2021-05-12 22:02:44 -07:00
Isaac Freund
459c9f0535 stage2: fix build on OpenBSD/NetBSD
Apparently these systems do not provide libdl or librt.
2021-05-13 00:44:56 -04:00
Andrew Kelley
417b5b1daa std: fix redundant comptime keywords
caught by stage2 astgen
2021-05-12 20:44:05 -07:00
Andrew Kelley
1ab3dff846 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Need the latest commit which fixes std and behavior tests for cross
compiled glibcs.
2021-05-12 20:37:40 -07:00
Andrew Kelley
799d1f0d36 build system: fix wrong glibc dir passed to qemu for i386
Without this, and with `-Denable-qemu -Denable-foreign-glibc`,
i386-linux-gnu tests failed because the `-L` path passed to qemu
was "i386-linux-gnu" (nonexistent) rather than "i686-linux-gnu".

Fixes std lib and behavior tests when using these options to enable
test coverage with cross compiled glibcs.
2021-05-12 20:34:54 -07:00
Andrew Kelley
c9cc09a3bf Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * lib/std/os/linux.zig
 * lib/std/os/windows/bits.zig
 * src/Module.zig
 * src/Sema.zig
 * test/stage2/test.zig

Mainly I wanted Jakub's new macOS code for respecting stack size, since
we now depend on it for debug builds able to pass one of the test cases
for recursive comptime function calls with `@setEvalBranchQuota`.

The conflicts were all trivial.
2021-05-12 16:41:20 -07:00
Koakuma
90a54f06e5 Add a comment to explain the alignment directive 2021-05-13 06:18:51 +07:00
Matthew Borkowski
40a47eae65 fix shrinkAndFree and remove shrinkRetainingCapacity in PriorityQueue and PriorityDequeue 2021-05-12 18:33:25 -04:00
Evan Haas
19aab5302c translate-c: Ensure extra_cflags are passed to clang
Additionally ensure that the Zig cache incorporates any extra cflags when
using translate-c.

Fixes the issue identified in #8662
2021-05-12 18:17:45 -04:00
Andrew Kelley
43da102920 Merge pull request #8698 from ifreund/scanZ
std/mem: add sliceTo(), deprecate spanZ(), lenZ()
2021-05-12 18:15:36 -04:00
LemonBoy
893a428656 stage2: Drop LLVM's host CPU detection method as fallback
The CPU detection code is nearly at feature parity, we do support
detecting the native CPU on Sparc systems and macos, our ARM/AArch64
model list is quite comprehensive and so is our PPC one.

The only missing pieces are:
- ARM32 detection on Darwin hosts (I don't think anybody is planning on
  running the compiler on a old-ass iPhone)
- s390x detection on Linux hosts, this can be easily added at a later
  stage.
2021-05-12 14:03:59 -04:00
Jakub Konka
7b77246289 macho: allow overriding stack size in binary 2021-05-12 19:25:26 +02:00
Koakuma
9e67c062c4 Add missing f128 compiler-rt shim 2021-05-12 20:13:29 +07:00
Michael Dusan
fb8527b289 azure: bump timeout for macos-arm64 2021-05-12 06:38:01 -04:00
Isaac Freund
cd7b5a3718 std/mem: add sliceTo(), deprecate spanZ(), lenZ()
The current spanZ() function will not scan for a 0 terminator if the
type is not 0 terminated. This encourages using 0 terminated array
types to bind C arrays which hold 0 terminated strings. However, this is
a big footgun as nothing in the C type system guarantees there to be a
0 terminator at the end of the array and if there is none this becomes
Illegal Behavior in Zig.

To solve this, deprecate spanZ() and lenZ(), adding a new sliceTo()
function that always scans for the given terminator even if the type is
not sentinel terminated.
2021-05-12 11:24:49 +02:00
Jakub Konka
53acb54fad Bump zig-bootstrap and wasmtime versions in linux CI (#8738)
* Bump zig-bootstrap and wasmtime versions in linux CI

* Revert wasm stage2 test fixup; point to issue
2021-05-12 09:56:55 +02:00
Koakuma
f24d0fbb07 Remove SPARC pthreadtypes-arch.h to match upstream glibc
This is only a temporary measure, we need to properly update the bundled glibc.
2021-05-12 14:54:13 +07:00
Koakuma
5dd6f9616e Fix linux dirent64 buffer align directive 2021-05-12 14:52:53 +07:00
LemonBoy
e260cfae85 stage2: Add CPU feature detection for macos
This is mostly meant to detect the current and future AArch64 core types
as the x86 part is already taken care of with OS-independent machinery.
2021-05-12 09:43:49 +02:00
Koakuma
9c07d30ef5 Fix crti/crtn path for SPARC 2021-05-12 14:23:28 +07:00
Koakuma
6e5330ee38 Define ENOTSUP for SPARC 2021-05-12 14:23:08 +07:00
Andrew Kelley
71afc30880 stage2: more Decl lifetime fixes
* File stores `root_decl: Decl` instead of `namespace: *Namespace`.
   This maps more cleanly to the actual ownership, since the `File` does
   own the root decl, but it does not directly own the `Namespace`.
 * `semaFile` completes the creation of the `Decl` even when semantic
   analysis fails. The `analysis` field of the `Decl` will contain the
   results of semantic analysis. This prevents cleaning up of memory
   still referenced by other Decl objects.
 * `semaDecl` sets `Struct.zir_index` of the root struct decl, which
   fixes use of undefined value in case the first update contained a ZIR
   compile error.
2021-05-11 23:20:22 -07:00
Andrew Kelley
1ab1a96f87 stage2: improve Decl lifetime management
* Compilation: iteration over the deletion_set only tries to delete the
   first one, relying on Decl destroy to remove itself from the deletion
   set.
 * link: `freeDecl` now has to handle the possibility of freeing a Decl
   that was never called with `allocateDeclIndexes`.
 * `deleteDecl` recursively iterates over a Decl's Namespace sub-Decl
   objects and calls `deleteDecl` on them.
   - Prevents Decl objects from being destroyed when they are still in
     `deletion_set`.
 * Sema: fix cleanup of anonymous Decl objects when an error occurs
   during semantic analysis.
 * tests: update test cases for fully qualified names
2021-05-11 22:12:36 -07:00
Michael Dusan
30ace64fc4 bsd: detect os version
- netbsd, dragonly: use sysctlbyname
- openbsd: use sysctl
- updated default semver ranges
2021-05-11 22:05:08 -04:00
Andrew Kelley
d7567c06fd Sema: implement duplicate enum tag compile error 2021-05-11 18:56:56 -07:00
Andrew Kelley
7873e4f588 stage2: lookupIdentifier can return error.AnalysisFailed
This avoids causing false positive compile errors when, for example, a
file had ZIR errors, and then code tried to look up a public decl from
the failed file.
2021-05-11 17:44:19 -07:00
Andrew Kelley
cbbc7cc8b1 stage2: better handling of file-level compile errors across updates
* `Module.File` now retains the most recent successful ZIR in the event
   that an update causes a ZIR compile error. This way Zig does not
   throw out useful semantic analysis results when an update temporarily
   introduces a ZIR compile error.
 * Semantic analysis of a File now unconditionally creates a Decl object
   for the File. The Decl object is marked as `file_failed` in case of
   File-level compile errors. This allows detecting of the File being
   outdated, and dependency tracking just like any other Decl.
2021-05-11 17:34:13 -07:00
Andrew Kelley
e3dd4dc91d Merge pull request #8737 from ifreund/link-system-libc
stage2: use system libc when targeting the native OS/ABI
2021-05-11 20:28:14 -04:00
Andrew Kelley
5d9fc11d18 stage2: update tests now that structs have fully qualified names 2021-05-11 14:51:54 -07:00
Andrew Kelley
a74632b50a C backend: fix emitting '$' in identifier names
This causes warnings from clang when compiled.
2021-05-11 14:51:21 -07:00
Andrew Kelley
fb39526159 AstGen: support emitting multiple compile errors 2021-05-11 14:51:08 -07:00
Andrew Kelley
bcf15e39e2 stage2: add owns_tv flag to Module.Decl
Decl objects need to know whether they are the owner of the Type/Value
associated with them, in order to decide whether to destroy the
associated Namespace, Fn, or Var when cleaning up.
2021-05-11 14:17:52 -07:00
Isaac Freund
e6881d4373 std/json: fix previous commit for std.testing changes 2021-05-11 23:09:25 +02:00
Matthew Borkowski
1b87d45494 fix a double free in parse when duplicate_field_behavior is UseLast and a leak in parse when allocating a single item 2021-05-11 22:54:02 +02:00
Isaac Freund
c036957521 std.meta.Elem: support all optional types 2021-05-11 22:22:21 +02:00
Isaac Freund
f8cf106fc9 ci: unset CC/CXX before make install on macos arm64
Having these set causes zig's native libc detection code to fail.
2021-05-11 21:30:13 +02:00
Isaac Freund
3b2c9ef828 stage2: link all libc components if using system libc 2021-05-11 21:30:13 +02:00
Isaac Freund
01e30002c5 stage2: error if requested glibc version too high
Falling back to the max provided glibc version is insufficient as
linking to shared objects compiled against the requested version
will fail.
2021-05-11 21:30:13 +02:00
Isaac Freund
5ac91794cc stage2: use system libc when targeting the native OS/ABI
Currently zig will always try to build its own libc and compile against
that. This of course makes sense for cross-compilation, but can cause
problems when targeting the native OS/ABI.

For example, if the system uses a newer glibc version than zig ships
zig will fall back to using the newest version it does ship. However
this causes linking system libraries to fail as they are built against a
different glibc version than the zig code is built against.

To remedy this, simply default to linking the system libc when targeting
the native OS/ABI.
2021-05-11 21:30:07 +02:00
Andrew Kelley
ace5714551 Merge pull request #8705 from LemonBoy/libc-fix
32bit glibc fixes
2021-05-11 15:15:00 -04:00
Andrew Kelley
c3d4733a00 test runner: avoid an "out of memory" error return trace entry
The long term solution to this will be #1923
2021-05-11 11:47:22 -07:00
Andrew Kelley
65d279bc05 test runner: print error return trace after failed test 2021-05-11 10:50:17 -07:00
LemonBoy
8bb58fb428 std: Fix offset param splitting for preadv/pwritev
The kernel interface expects the offset as a low+high pair even on BE
systems.
2021-05-11 15:49:53 +02:00
Matthew Borkowski
75ed835d08 fix AutoArrayHashMap's store_hash logic 2021-05-11 16:14:23 +03:00
LemonBoy
2bb8e1ff55 stage2: Change libc components' linking order
Use the same order as Clang (and, by extension, GCC) for the three most
important libc components: lm comes first, followed by lpthread and then
lc.
2021-05-11 12:43:58 +02:00
LemonBoy
780f510ac0 std: Fix fallocate offset type 2021-05-11 12:33:48 +02:00
LemonBoy
c065e12dbe std: Add more tests, fix broken code
It turns out that nothing in the test suite was exercising
preadv/pwritev and so the previous commits silently broke them.

Adding tests revealed readvAll and preadvAll were also broken and not
covered by any test.
2021-05-11 12:33:48 +02:00
LemonBoy
31f1cc9a0d std: Harmonize use of off_t between libc and Zig impls
Let's follow the libc/kernel convention and use an i64 for offsets, we
bitcast as needed and avoid the useless conditional casts.
2021-05-11 12:33:48 +02:00
LemonBoy
f4a05286d3 std: Fix cast that's sometimes invalid 2021-05-11 12:33:48 +02:00
LemonBoy
93f48189f1 test: Enable i386-linux-gnu test
This is needed to catch any possible problem with executables linking to
32bit glibc.
2021-05-11 12:33:48 +02:00
LemonBoy
679876ba72 c: Fix prototypes for bcmp and memcmp
They return c_int and not isize.
2021-05-11 12:33:47 +02:00
LemonBoy
a909db6aea std: Prefer 64bit libc functions where possible
While musl decided to hard-wire off_t to a 64bit quantity, glibc is much
older and defaults to 32bit offsets and offers some -64 suffixed
versions of I/O functions.

There's a weird mix-up of types: sometimes off_t is used, sometimes not,
sometimes it's defined as a signed quantity and sometimes as an unsigned
one, but we'll sort this problem later.
2021-05-11 12:33:47 +02:00
LemonBoy
28a9e4c4aa libc: Add workaround for #4926
This change was cherry-picked from an updated version of the sysdep
folder contents, we're still shipping an outdated and incomplete set of
files.
2021-05-11 12:33:47 +02:00
LemonBoy
ac546f56eb stage2: Allow building musl/glibc in thumb mode 2021-05-11 12:27:24 +02:00
LemonBoy
b288f8c9a6 stage2: Always link -lpthread when using system libc
This is required when cross-compiling glibc targets.
2021-05-11 12:27:24 +02:00
LemonBoy
65ee7909b9 stage2: Pass -mthumb when compiling C/C++ code
Apparently the Clang driver requires this flag and ignores the target
triple.
2021-05-11 12:27:24 +02:00
Andrew Kelley
dae22a0a1f stage2: struct, union, enum, opaque, error sets get better names
This commit takes advantage of the new "NameStrategy" that is exposed
in the ZIR in order to name Decls after their parent when asked to. This
makes the next failing test case pass.
2021-05-10 22:50:00 -07:00
Andrew Kelley
b9a099e83c stage2: type declarations ZIR encode AnonNameStrategy
which can be either parent, func, or anon. Here's the enum reproduced in
the commit message for convenience:

```zig
pub const NameStrategy = enum(u2) {
    /// Use the same name as the parent declaration name.
    /// e.g. `const Foo = struct {...};`.
    parent,
    /// Use the name of the currently executing comptime function call,
    /// with the current parameters. e.g. `ArrayList(i32)`.
    func,
    /// Create an anonymous name for this declaration.
    /// Like this: "ParentDeclName_struct_69"
    anon,
};
```

With this information in the ZIR, a future commit can improve the
names of structs, unions, enums, and opaques.

In order to accomplish this, the following ZIR instruction forms were
removed and replaced with Extended op codes:

 * struct_decl
 * struct_decl_packed
 * struct_decl_extern
 * union_decl
 * union_decl_packed
 * union_decl_extern
 * enum_decl
 * enum_decl_nonexhaustive

By being extended opcodes, one more u32 is needed, however we more than
make up for it by repurposing the 16 "small" bits to provide shorter
encodings for when decls_len == 0, fields_len == 0, a source node is not
provided, etc. There tends to be no downside, and in fact sometimes
upsides, to using an extended op code when there is a need for flag
bits, which is the case for all three of these. Likewise, the container
layout can be encoded in these bits rather than into the opcode.

The following 4 ZIR instructions were added, netting a total of 4 freed
up ZIR enum tags for future use:

 * opaque_decl_anon
 * opaque_decl_func
 * error_set_decl_anon
 * error_set_decl_func

This is so that opaques and error sets can have the same name hint as
structs, enums, and unions.

`std.builtin.ContainerLayout` gets an explicit integer tag type so that
it can be used inside packed structs.

This commit also makes `Module.Namespace` use a separate set for
anonymous decls, thus allowing anonymous decls to share the same
`Decl.name` as their owner `Decl` objects.
2021-05-10 21:34:43 -07:00
Andrew Kelley
9e72f31735 stage1: ignore enum ContainerLayout for comptime memory purposes
See #2115. The concept of `packed enum` and `extern enum` is
getting removed from the language.
2021-05-10 20:34:18 -07:00
Andrew Kelley
55d235dc38 Merge pull request #8711 from lithdew/master
std/os, x/os/socket: windows support, socket helpers, getpeername()
2021-05-10 19:00:53 -04:00
Andrew Kelley
2e4a48ef29 Merge pull request #8736 from ziglang/macos-zig-bootstrap
Use zig-bootstrap to build macOS binaries
2021-05-10 18:41:29 -04:00
jacob gw
24dfa61236 stage1: remove outdated error message regarding #447 2021-05-10 21:00:10 +02:00
xackus
8f8efcdd6e translate-c: fix typedefs with multiple names 2021-05-10 21:59:42 +03:00
Jakub Konka
b7a6a251a0 Tweak macos_arm64_script to use bootstrapped zig 2021-05-10 18:42:01 +02:00
Jakub Konka
603242fa86 Use zig-bootstrapped x86_64 macos compiler in CI 2021-05-10 13:55:48 +02:00
lithdew
0d0edd23a8 std/os: add missing sockaddr_storage defs 2021-05-10 19:22:31 +09:00
lithdew
e652595f2a std/os: fix sockaddr_storage padding size 2021-05-10 19:22:31 +09:00
lithdew
6d41e08664 x/os, os: fix setsockopt on windows, simplify Socket.setOption error set 2021-05-10 19:22:31 +09:00
lithdew
6cb6edb6f6 std/os/windows/ws2_32: add missing FIONBIO constant 2021-05-10 19:22:31 +09:00
lithdew
77f8a9ae22 x/os/socket, std/os/windows: implement loading winsock extensions
Implement loading Winsock extensions.

Add missing Winsock extension GUID's.

Implement readVectorized() for POSIX sockets and
readVectorized() / writeVectorized() for Windows
sockets.

Inverse how mixins are used to implement platform-independent syscalls
for the std.x.os.Socket abstraction. This cleans up the API as suggested
by @komuw.
2021-05-10 19:22:31 +09:00
lithdew
3d946ef5eb x/os, x/net, os:, fix typos/errors, add missing constants/docs
Add missing constants to ws2_32 such as SIO_BASE_HANDLE.

Made all declared constants in ws2_32 comptime_int, and fixed a few
broken constants (i.e. GUID's).

Fixed a few syscalls not having callconv(WINAPI) in ws2_32.

Fixed a typo in std.x.net.tcp.Client.

Removed unnecessary @alignCast's for socket addresses in
std.x.net.Socket.

Added a warning on using timeout methods for std.x.net.Socket.

Fixed compilation error spotted by CI in std.os that references
std.os.windows.ws2_32.SD_RECEIVE.

Renamed std.x.os.Socket.setOption()'s parameter `name: u32` to `code:
u32`.
2021-05-10 19:22:31 +09:00
Kenta Iwasaki
a24101be5b x/os/socket_posix.zig: make linger struct extern
Co-authored-by: LemonBoy <LemonBoy@users.noreply.github.com>
2021-05-10 19:22:31 +09:00
lithdew
e739b2b7d6 x/os/socket: use sockaddr_storage for accept() 2021-05-10 19:22:31 +09:00
lithdew
d3871af724 x/net/tcp, x/os/socket: tcp.Client.{Reader, Writer}
Only allow SOCK_STREAM (std.x.net.tcp.Client) sockets to have wrappers
for std.io.Reader and std.io.Writer provided, instead of Socket's in
general.
2021-05-10 19:22:31 +09:00
lithdew
d7b601b35e std/os, x/os/socket: windows support, socket helpers, getpeername()
Socket I/O methods such as read, readv, write, writev, send, recv,
sendmsg, recvmsg have been generalized to read(buf, flags), write(buf,
flags), readVectorized(vectors, flags), and writeVectorized(vectors,
flags). There is still some work left to be done abstracting both
readVectorized and writeVectorized properly across platforms, which is
work to be done in a future PR.

Support for setting the linger timeout of a socket, querying the remote
address of a socket, setting whether or not keep-alive messages are to
be sent through a connection-oriented socket periodically depending on
host operating system settings has been added.

`std.io.Reader` and `std.io.Writer` wrappers around `Socket` has been
implemented, which wrap around Socket.read(buf, flags) and
Socket.write(buf, flags). Both wrappers may be provided flags which are
passed to Socket.read / Socket.write accordingly.

Cross-platform support for `getpeername()` has been implemented.

Windows support for the new `std.x.os.Socket` has been implemented. To
accomplish this, a full refactor of `std.os.windows.ws2_32` has been
done to supply any missing definitions and constants based on
auto-generated Windows syscall bindings by @marler8997.

`std.x.net.TCP.Listener.setQuickACK` has been moved to
`std.x.net.TCP.Client.setQuickACK`.

Windows support for resolving the scope ID of an interface name
specified in an IPv6 address has been provided.

`sockaddr_storage` definitions have been provided for Windows, Linux,
and Darwin. `sockaddr_storage` is used to allocate space before any
socket addresses are queried via. calls such as accept(), getsockname(),
and getpeername().

Zig-friendly wrappers for GetQueuedCompletionStatusEx(), getpeername(),
SetConsoleCtrlHandler(), SetFileCompletionNotificationModes() syscalls
on Windows have been provided.

Socket.setOption() was provided to set the value of a socket option in
place of os.setsockopt. Socket.getOption() will be provided in a future
PR.

There is still further work to be done regarding querying socket option
values on Windows, which is to be done in a subsequent PR.
2021-05-10 19:22:31 +09:00
Jakub Konka
9c03b39d1e Merge pull request #8723 from jedisct1/init-stat
Initialize the Stat structure
2021-05-10 09:42:37 +02:00
Frank Denis
2d11967734 p256: properly handle neutral element & add AffineCoordinates struct (#8718)
Instead of multiple references to an anonymous structure to represent affine coordinates, add an actual `AffineCoordinates` structure.

Also properly handle the neutral element during coordinate conversion and fix mixed addition.

And comptime the small precomputation table for basepoint multiplication.
2021-05-09 18:20:43 +02:00
Frank Denis
c3675d9351 Shorten 2021-05-09 18:17:09 +02:00
Frank Denis
4e399ef62c Initialize the Stat structure
The system `stat` structure includes padding, and, on some
operating systems such as all BSDs, "spare" bytes at the end.

We can't reliably compare two `Stat` values if these are
uninitialized, while being later compared.

This is what was causing the `fstatat` test to fail on FreeBSD
since the update to LLVM 12. It was previously only passing by
accident.
2021-05-09 18:15:42 +02:00
Jakub Konka
f67e756211 zld: adjust signed displacement source target addr
Previously, I mistakenly assumed that offset of the relocation
is enough when calculating relative offset of the target from the
source target section base address in case of section-based relocs
on x86_64. While this is true for `__TEXT,__text` section which
always starts at 0x0 in object files, this is absolutely not true
for `__TEXT,__StaticInit` section which will have nonzero base
address hence resulting in incorrect displacement calculations for
SIGNED relocs.
2021-05-09 16:24:53 +02:00
Jakub Konka
15d6efecfb Merge pull request #8709 from joachimschmidt557/stage2-arm
stage2 ARM: Generate correct code when spilling registers
2021-05-09 14:16:40 +02:00
joachimschmidt557
f2a3368891 stage2 ARM: Add spill registers test 2021-05-09 08:48:58 +02:00
joachimschmidt557
d211dc37c8 stage2 ARM: Overhaul of genArmBinOp 2021-05-09 08:48:58 +02:00
Andrew Kelley
2299e5ff1d fix merge conflicts from previous commit
Any PRs merged after the one that made testing functions return errors
needs to get rebased!
2021-05-08 23:12:34 -07:00
Andrew Kelley
b88d381dec Merge pull request #8474 from gracefuu/grace/encode-instruction
stage2 x86_64: encoding helpers, fix bugs
2021-05-09 01:36:51 -04:00
Andrew Kelley
6361d7a928 stage2 test harness: report multiple failures
so you can debug more than one thing at a time
2021-05-08 16:11:07 -07:00
Andrew Kelley
5619ce2406 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * doc/langref.html.in
 * lib/std/enums.zig
 * lib/std/fmt.zig
 * lib/std/hash/auto_hash.zig
 * lib/std/math.zig
 * lib/std/mem.zig
 * lib/std/meta.zig
 * test/behavior/alignof.zig
 * test/behavior/bitcast.zig
 * test/behavior/bugs/1421.zig
 * test/behavior/cast.zig
 * test/behavior/ptrcast.zig
 * test/behavior/type_info.zig
 * test/behavior/vector.zig

Master branch added `try` to a bunch of testing function calls, and some
lines also had changed how to refer to the native architecture and other
`@import("builtin")` stuff.
2021-05-08 14:45:21 -07:00
Andrew Kelley
5cd9afc6b6 stage2: fully qualified names and better anonymous names
* no more global atomic variable for anonymous decl indexes. Instead
   the Namespace decl table is used to figure out anonymous decl names.
   - This prepares for better multi-threaded semantic analysis in the
     future, with no contention on this global atomic integer.
 * implement fully qualified names for namespaces.
2021-05-08 14:34:30 -07:00
Andrew Kelley
67154d233e Merge pull request #8686 from Vexu/try
Allow tests to fail
2021-05-08 17:29:44 -04:00
Andrew Kelley
aa0352fad6 Sema: fix @setEvalBranchQuota incorrectly requiring a function body 2021-05-08 14:06:36 -07:00
Andrew Kelley
b98a753b52 AstGen: fix incorrect logic for adding implicit return instruction 2021-05-08 13:48:40 -07:00
Andrew Kelley
fed1c9c3ec link/MachO: fix --verbose-link ensureCapacity bug 2021-05-08 11:24:07 -07:00
Andrew Kelley
3d351c91d8 Type: fix abiAlignment calculation for unions 2021-05-08 10:54:40 -07:00
Andrew Kelley
b6bb0ee1ac Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * lib/std/os/linux/tls.zig
 * test/behavior/align.zig
 * test/behavior/atomics.zig
 * test/behavior/vector.zig
2021-05-08 10:53:22 -07:00
Veikka Tuominen
7437c47d55 tests: work around miscompilation 2021-05-08 15:18:13 +03:00
Veikka Tuominen
08b6baca12 update usage of std.testing in langref.html 2021-05-08 15:16:05 +03:00
Veikka Tuominen
7fe39c4e96 update usage of std.testing in compiler_rt 2021-05-08 15:15:30 +03:00
Veikka Tuominen
42a95197f3 update usage of std.testing in stage2 2021-05-08 15:15:30 +03:00
Veikka Tuominen
0a38f61d58 update usage of std.testing in behavior and standalone tests 2021-05-08 15:15:30 +03:00
Veikka Tuominen
fd77f2cfed std: update usage of std.testing 2021-05-08 15:15:30 +03:00
Veikka Tuominen
59f9253d94 allow tests to fail 2021-05-08 15:15:23 +03:00
Andrew Kelley
28353b3159 stage2: fix struct inits not getting fields resolved 2021-05-07 22:16:15 -07:00
Andrew Kelley
73bf53069d ZIR: implement iteration over switch instructions
for changelist detection
2021-05-07 21:54:26 -07:00
Andrew Kelley
6ec24a6502 std: start code on linux when -lc also expands stack size
See #8708
2021-05-07 21:34:53 -07:00
Andrew Kelley
f69cf93064 std: start code increases stack size as appropriate on linux
closes #8708
2021-05-07 21:23:51 -07:00
Andrew Kelley
d577654e66 stage2: fix stack overflow in @setEvalBranchQuota test case
Some of the reworkings in this branch put us over the limit, on Linux,
where the kernel disregards the fact that we ask for 16 MiB in the ELF
file. So we ask for more stack space in `main`.
2021-05-07 20:03:27 -07:00
Andrew Kelley
81d5104e22 stage2: implement global variables
* Sema: implement global variables
   - Improved global constants to stop needlessly creating a Var
     structure; they can just store the value directly.
   - This required making memory management a bit more sophisticated to
     detect when a Decl owns the Namespace associated with it, for the
     purposes of deinitialization.
 * Decl.name and Namespace decl table keys no longer directly
   reference ZIR; instead they have heap-duped names, so that deleted
   decls, which no longer have any ZIR to reference for their names, can
   be removed from the parent Namespace table.
   - In the future I would like to explore going a different direction
     with this, where the strings would still point to the ZIR however
     they would be removed from their owner Namespace objects during the
     update detection. The design principle here is that the existence
     of incremental compilation as a feature should not incur any cost
     for the use case when it is not used. In this example Decl names
     could simply point to ZIR string table memory, and it is only
     because of incremental compilation that we duplicate their names.
 * AstGen: implement threadlocal variables
 * CLI: call cleanExit after building a compilation so that in release
   modes we don't bother freeing memory or closing file descriptors,
   allowing the OS to do it more efficiently.
 * Avoid calling `freeDecl` in the linker for unreferenced Decl objects.
 * Fix CBE test case expecting the compile error to point to the wrong
   column.
2021-05-07 18:52:11 -07:00
Andrew Kelley
e7c4d545cd stage2: no '$' in anonymous decl names
This way it will not cause a compile error for the C backend.
2021-05-07 16:18:49 -07:00
Andrew Kelley
6ac2047142 stage2: implement extern functions 2021-05-07 16:06:25 -07:00
Andrew Kelley
47531b7d93 Sema: support enough to check main calling convention via @typeInfo
After this commit, `pub export fn main() c_int { ... }` will be
correctly detected as the intended entry point, and therefore start code
will not try to export its own conflicting `main` function.

 * Implement basic union support
   - lots of stuff is still TODO, including runtime field access
   - also TODO: resolving the union tag type
   - comptime field access is implemented
 * DRY up some code by using the `Zir.DeclIterator` for skipping over
   decls in structs and unions.
 * Start to clean up Sema with regards to calling `.value()` to find out
   a const value. Instead, Sema code should call one of these two:
   - `resolvePossiblyUndefinedValue` (followed by logic dealing with
     undefined values)
   - `resolveDefinedValue` (a compile error will be emitted if the value
     is undefined)
 * An exported function with an unspecified calling convention gets the
   C calling convention.
 * Implement comptime field access for structs.
 * Add another implementation of "type has one possible value" in Sema.
   This is a bit unfortunate since the logic is duplicated, but the one
   in Type asserts that the types are resolved already, and is
   appropriate to call from codegen, while the one in Sema performs
   type resolution if necessary, reporting any compile errors that occur
   in the process.
2021-05-07 14:18:14 -07:00
Andrew Kelley
a7221ef4e9 Sema: implement @typeInfo for functions
The goal is to get start code to be able to inspect the calling
convention of `main` in order to determine whether to export a main for
libc to call, or to allow the root source file to do it.
2021-05-06 22:30:44 -07:00
Michael Dusan
84d5cc31c5 fix test to restore cwd after chdir
- `../zig-cache/tmp` is no longer created by subsequent test(s)
2021-05-07 01:04:38 -04:00
Andrew Kelley
3acd98fa34 stage2: CBE tests pub export instead of export main
This is needed so that start code can avoid redundantly trying to export
a main function for libc to call.
2021-05-06 17:51:09 -07:00
Andrew Kelley
7dd33d4316 stage2: fix compile errors in test harness 2021-05-06 17:48:38 -07:00
Andrew Kelley
9b9ea405ef CLI: add an update-and-run cmd and make enter re-run last cmd 2021-05-06 17:35:21 -07:00
Andrew Kelley
cdea22f5d7 stage2: wire up outdated/deleted decl detection
we're back to incremental compilation working smoothly
2021-05-06 17:20:45 -07:00
Andrew Kelley
3791cd6781 CLI: add 'run' command to the repl 2021-05-06 12:51:51 -07:00
Andrew Kelley
426e4c784c std.ArrayHashMap: ensureUnusedCapacity and ensureTotalCapacity
Same as 22015c1b3b, but for ArrayHashMap.
2021-05-06 12:50:53 -07:00
Andrew Kelley
530e67cb86 Merge pull request #8683 from LemonBoy/thumblinux
Initial bringup for Linux/Thumb2
2021-05-06 12:50:34 -04:00
lars
96e593145d stage1: improve message for missing fn return type
Coming from other languages it might be tempting for programmers to
accidentally leave out the return type instead of returning 'void'.

The error for this used to be

    error: invalid token: '{'
    pub fn main() {
                  ^

which is misleading. The '{' is expected but only after a return type.

The new message is

    error: expected return type (use 'void' to return nothing), found: '{'
    pub fn main() {
                  ^

which not only points out the real error but also hints at a (probably)
very common case where someone coming from e.g. Go is used to not
specifying a return type if a function returns nothing and thus forgets
to put 'void' there.

It might seem overkill to hint at the 'void' option but then the
compiler error messages are our user interface to the programmer. We
can be better than other languages in our error messages and leaving
out the return type seems to be a rather clear indication of the above
mentioned issue. Adding this will help more than distract.
2021-05-06 18:44:10 +02:00
Jakub Konka
88d40fc005 zld: sort tlv offsets by source address 2021-05-06 17:10:05 +02:00
Jakub Konka
ef8a666797 zld: cleanup relocs and flag errors on unhandled symbol types 2021-05-06 17:09:58 +02:00
Andrew Kelley
17067e0e6b stage2: fix contents hash computation
during an incremental update change detection,
the function call to get the old contents hash took place
after mangling the old ZIR index, making it access the wrong
array index.
2021-05-05 17:00:10 -07:00
Andrew Kelley
9b1aac8a65 stage2: mapping old to new ZIR recursively
now it walks into functions and blocks to find decls.
2021-05-05 16:56:24 -07:00
Andrew Kelley
c714a3250f std.ArrayList: add clearRetainingCapacity and clearAndFree 2021-05-05 16:55:49 -07:00
Andrew Kelley
5d7f2697de stage2: add zig changelist debug command
and implement the first pass at mechanism to map old ZIR to new ZIR.
2021-05-05 13:16:14 -07:00
Jakub Konka
ad33e34836 tests: re-enable reduce behavior tests for wasm32 2021-05-05 21:26:50 +02:00
Andrew Kelley
6b5d0b3711 std: fix compile errors found by stage2
* redundant `comptime`
 * `try` outside function
 * `extern enum`
2021-05-05 11:03:54 -07:00
Andrew Kelley
fc40d23723 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
 * build.zig
 * lib/std/array_list.zig
 * lib/std/c/ast.zig
 * lib/std/c/parse.zig
 * lib/std/os/bits/linux.zig
2021-05-05 10:48:22 -07:00
LemonBoy
9d409233b2 std: Implement hex float printing
The results have been cross-checked with LLVM's APFloat implementation
by randomly sampling the f32/f64 space, while the f16 one was completely
checked given the small size.
2021-05-05 12:37:40 -04:00
LemonBoy
18b46485bc stage2: Fix UAF in ErrorMsg destructor
After calling gpa.destroy the object is gone for good, setting the
contents to undefined is a bug and may crash the compiler.
2021-05-05 12:37:04 -04:00
Michael Dusan
622a3ac876 Merge pull request #8691 from lithdew/master
x/net: fix tcp tests for openbsd and add missing `fmt` import
2021-05-05 05:54:47 -04:00
Andrew Kelley
368e13a9a1 Merge pull request #8671 from LemonBoy/arm-host-det
ARM/AArch64 CPU host detection
2021-05-05 03:17:32 -04:00
LemonBoy
e863204c47 zig fmt: Fix edge case in inline asm parsing
The presence of a trailing comma in the single and only input/output
declaration confused the parser and made zig fmt discard any element
placed after the comma.
2021-05-05 03:16:07 -04:00
Jay Petacat
70a9a3a562 stage1: Fix other OS target
PR #7827 added some new `std.Target.Os.Tag` before `other`.
The corresponding enum in stage1.h was not updated, which caused a
mismatch in the underlying integer values. While attempting to target
`other`, I encountered crashes.

This PR updates the stage1.h enum to include the added OS tags.
The new tags also had to be added to various switch cases to fix
compiler warnings, but have not been tested in any way.
2021-05-05 03:15:44 -04:00
lithdew
c75ae8b66d x/net: fix tcp tests for openbsd and add missing fmt import
On OpenBSD, connecting to a newly-allocated port on an unspecified IPv4
host address causes EINVAL. This was found by @mikdusan when running TCP
tests on OpenBSD.

This commit fixes TCP tests on OpenBSD by having all tests that allocate
a new host-port pair to have the host IPv4/IPv6 address point to the
host's loopback adapter (on localhost).
2021-05-05 16:09:08 +09:00
Andrew Kelley
7a27f0d80c Sema: restore the extern lib name functionality 2021-05-04 14:40:59 -07:00
Andrew Kelley
1f0fd64302 stage2: test coverage for inline asm return type not type 2021-05-04 14:23:53 -07:00
Andrew Kelley
edfbf85ecd Sema: implement error sets 2021-05-04 13:58:08 -07:00
Andrew Kelley
230ce72f16 stage2: fix "other symbol here" error note
It wasn't setting the source location properly.
2021-05-04 12:32:22 -07:00
Sage Hane
975cb9e9a9 std.zig: make the unrecognized C flag case non-fatal 2021-05-05 04:19:08 +09:00
Andrew Kelley
3dafec0acd stage2: fix structs and enums setting wrong owner_decl
No more memory leaks.
2021-05-04 11:08:40 -07:00
Andrew Kelley
785a6c1aa9 std: remove dead and rotting C parsing code 2021-05-04 10:26:44 -07:00
LemonBoy
afbcb6209d std: Initial bringup for Linux on Thumb2
There are some small problems here and there, mostly due to the pointers
having the lsb set and disrupting the fn alignment tests and the
`@FrameSize` implementation.
2021-05-04 18:52:53 +02:00
LemonBoy
4bf093f1a0 compiler-rt: Better selection of __clzsi implementation
To be honest all this detection logic is starting to become a real PITA,
the ARM32 version can be possibly removed as the generic version
optimizes pretty well...
2021-05-04 18:45:52 +02:00
LemonBoy
389d1177a5 stage1: Fix LLVM error in inline asm invocation
Pointer types need an extra indirection layer during the generation of
the function prototype for inline asm blocks.

Closes #3606
2021-05-04 18:43:31 +02:00
Jakub Konka
96556ce8b8 zld: port over a few more bits from ld64
* UTF16 gets its own section, `__TEXT,__ustring`
* TLV data and bss sections have to aligned to the same max alignment
  according to Apple rdar comment in the latest ld64
2021-05-04 13:09:32 +02:00
Jakub Konka
1867c3c34c zld: disable most logs 2021-05-04 13:09:32 +02:00
Jakub Konka
9e11f27c41 zld: build updated macho backend 2021-05-04 13:09:32 +02:00
Jakub Konka
00c3d57a51 zld: rewrite symbol allocations 2021-05-04 13:09:32 +02:00
Jakub Konka
fcd57f0857 zld: resolve GOT loads and stubs 2021-05-04 13:09:32 +02:00
Jakub Konka
68ebc7cba0 zld: rewrite symbol resolution 2021-05-04 13:09:32 +02:00
Jakub Konka
86ab6ca56c zld: rewrite Object to include pointers to Symbols 2021-05-04 13:09:32 +02:00
LemonBoy
b6be28ddcc std: Accept unaligned slice in several ArrayListAligned ops
Do not impose the internal alignment requirements to the user-supplied
parameters.

Closes #8647
2021-05-04 14:08:19 +03:00
Andrew Kelley
2910b10033 build.zig: add -Dmem-leak-frames option
to configure how many stack frames to save with every allocation, in
case it leaks and needs to get printed on process termination.
2021-05-03 20:42:36 -07:00
Andrew Kelley
2ae72c6f09 Sema: implement ExportOptions support in @export
Also fix switch blocks not emitting their AIR code.
2021-05-03 20:05:29 -07:00
Andrew Kelley
69d18ad7f0 ZIR: typeof uses the un_node field not un_tok 2021-05-03 18:47:53 -07:00
Andrew Kelley
95b014caea Sema: implement struct_decl instruction 2021-05-03 18:35:37 -07:00
Andrew Kelley
0e3930bb5a Merge pull request #8649 from lithdew/master
x/os, x/net: layout tcp, ipv4/ipv6, and socket abstractions
2021-05-03 17:38:10 -04:00
Andrew Kelley
5622f9382c Merge pull request #8657 from jedisct1/ci-split
Azure CI: Test std.* and the rest separately
2021-05-03 17:36:51 -04:00
Andrew Kelley
aa4e9399db ZIR: implement debug text printing for struct_init and friends 2021-05-03 12:25:20 -07:00
Andrew Kelley
773902e9de stage2: hook up semantic analysis of struct fields
Now that they are lazy, they need to get analyzed in the correct
context, when requested.

This commit also hooks up std.builtin type values being resolved
properly. This is needed, for example, with the `@export` builtin
function, which occurs in start.zig, for `std.builtin.ExportOptions`.
The ZIR code uses the special `Ref.export_options` value, and semantic
analysis has to map this to the corresponding type from `std.builtin`.
2021-05-03 11:46:02 -07:00
LemonBoy
3eed613407 std: Add two more ARM CPUs to the known CPU list
Modeled after GCC's description.
2021-05-03 12:32:13 +02:00
LemonBoy
e2d2295382 std: Add many more vendors and cpus to the ARM detection list
Hand-picked from GCC and LLVM lists.
2021-05-03 12:32:13 +02:00
LemonBoy
a7f3e12d23 std: Add fallback on pre-v6 ARM targets
Thanks xackus for noticing the missing else branch.
2021-05-03 12:32:13 +02:00
LemonBoy
792cf925ec std: Fix missing CPU feature check
We need both the v6k and the v6m checks.
2021-05-03 12:32:13 +02:00
LemonBoy
b10d40b89b stage2: Implement CPU host detection for ARM/AArch64 targets 2021-05-03 12:32:13 +02:00
Frank Denis
97779442d0 Prepare std/crypto/pcurves for ecdsa and other curves (#8670)
Functions generated by Fiat-crypto are not prefixed by their description any more. This matches an upstream change.

We can now use a single type for different curves and implementations.

The field type is now generic, so we can properly handle the base field and scalars without code duplication.
2021-05-03 09:57:45 +02:00
lithdew
96fe49ef62 std/os/bits/windows: add timeval extern struct 2021-05-03 14:49:10 +09:00
lithdew
16fc1b904c std/os/linux/bits: correct socket option codes for ppc/ppc64 2021-05-03 14:49:10 +09:00
lithdew
af057c888b x/net/ip: add copyright header 2021-05-03 14:49:10 +09:00
lithdew
5c4fbc4014 x/net: generalize tcp.Address into ip.Address
Generalize `tcp.Address` into `ip.Address` given that multiple transport
protocols apart from TCP (i.e. UDP) operate solely over IP.
2021-05-03 14:49:10 +09:00
lithdew
cc6714a929 std/os/bits: add timeval struct for riscv64 linux 2021-05-03 14:49:10 +09:00
lithdew
a799ad05b3 x/net/tcp: make tcp tests blocking to avoid unit test races 2021-05-03 14:49:10 +09:00
lithdew
aa15699269 x/os/net: skip ipv6 scope id parse test on unsupported platforms 2021-05-03 14:49:10 +09:00
lithdew
9a7c57144d x/net: disable tcp tests on wasi 2021-05-03 14:49:10 +09:00
lithdew
8ef9d98e6d x/os: fix compile errors on mac and linux
Use i32 instead of isize for os.timeval's for socket read/write
timeouts.

Add a comptime check to resolveScopeID to see if `IFNAMESIZE` is
available on the host. If it is not available, return an error
indicating that resolving the scope ID of a IPv6 address is not yet
supported on the host platform.
2021-05-03 14:49:10 +09:00
lithdew
76304a36af std/builtin: add missing comma to CallingConvention 2021-05-03 14:49:10 +09:00
lithdew
13068da43e x/os, x/net: re-approach Address, rename namespace TCP -> tcp
Address comments from @ifreund and @MasterQ32 to address unsafeness and
ergonomics of the `Address` API.

Rename the `TCP` namespace to `tcp` as it does not contain any
top-level fields.

Fix missing reference to `sockaddr` which was identified by @kprotty in
os/bits/linux/arm64.zig.
2021-05-03 14:49:10 +09:00
lithdew
2ab588049e x/os, x/net: layout tcp, ipv4/ipv6, and socket abstractions
The `Socket` abstraction was refactored to only comprise of methods that
can be generically used/applied to all socket domains and protocols.

A more comprehensive IPv4/IPv6 module derived from @LemonBoy's earlier
work was implemented under `std.x.os.IPv4` and `std.x.os.IPv6`. Using
this module, one can then combine them together into a union for example
in order to optimize memory usage when dealing with socket addresses.

A `TCP.Client` and `TCP.Listener` abstraction is introduced that is one
layer over the `Socket` abstraction, which isolates methods that can
only be applied to a "client socket" and a "listening socket". All prior
tests from the `Socket` abstraction, which all previously operated
assuming the socket is operating via. TCP/IP, were moved. All TCP socket
options were also moved into the `TCP.Client` and `TCP.Listener`
abstractions respectively away from the `Socket` abstraction.

Some additional socket options from @LemonBoy's prior PR for Darwin were
also moved in (i.e. SIGNOPIPE).
2021-05-03 14:49:10 +09:00
Andrew Kelley
807a8b6f75 stage2: make struct field analysis lazy
This commit breaks struct field analysis; will be fixed in a future
commit.
2021-05-02 18:50:01 -07:00
Andrew Kelley
5f4c52209e AstGen: fix outdated doc comment 2021-05-02 17:17:24 -07:00
Andrew Kelley
a973c362e5 AstGen: decouple from Module/Compilation
AstGen is now completely independent from the rest of the compiler. It
ingests an AST tree and produces ZIR code as the output, without
depending on any of the glue code of the compiler.
2021-05-02 17:08:19 -07:00
Andrew Kelley
d5f77c0bab stage2: fix error reporting not loading AST
In the byteOffset function, compile errors may need to compute the AST
from source bytes in order to resolve source locations. Previously there
were a few lines trying to access the AST before it was loaded. Trivial
fix, just move load the tree at the beginning.
2021-05-02 15:06:32 -07:00
Andrew Kelley
0611aa3985 stage2: test decls encode that they are tests in ZIR
This allows Sema to namespace them separately from function decls with
the same name. Ran into this in std.math.order conflicting with a test
with the same name.
2021-05-02 14:58:27 -07:00
Luna
c47028cd02 ci: freebsd: use py38-s3cmd 2021-05-02 17:24:17 -04:00
Andrew Kelley
4dd724d06a Sema: fix struct decl decoding ZIR incorrectly 2021-05-01 23:31:26 -07:00
Andrew Kelley
eadcefc124 stage2: dbg_stmt ZIR instructions have line/col
instead of node indexes.

 * AstGen: dbg_stmt instructions now have line and column indexes,
   relative to the parent declaration. This allows codegen to emit debug
   info without having the source bytes, tokens, or AST nodes loaded
   in memory.
 * ZIR: each decl has the absolute line number. This allows computing
   line numbers from offsets without consulting source code bytes.

Memory management: creating a function definition does not prematurely
set the Decl arena. Instead the function is allocated with the general
purpose allocator.

Codegen no longer looks at source code bytes for any reason. They can
remain unloaded from disk.
2021-05-01 21:57:52 -07:00
Andrew Kelley
6248e2a560 std.GeneralPurposeAllocator: print leaked memory addresses
This helps when using it with other tools, such as memory watchpoints.
2021-05-01 21:25:01 -07:00
Frank Denis
9a637f81e0 Restore the CI logging as before 2021-05-02 02:07:59 +02:00
Andrew Kelley
4f9c928e56 Merge pull request #8665 from LemonBoy/misc
Miscellaneous patches
2021-05-01 18:07:58 -04:00
Andrew Kelley
d788181a3b fix typo
Co-authored-by: Maciej Walczak <14938807+xackus@users.noreply.github.com>
2021-05-01 18:07:26 -04:00
Sage Hane
6490e57136 std.zig: handle -frandom-seed in NIX_CFLAGS_COMPILE 2021-05-02 02:44:55 +09:00
LemonBoy
06b2fee05e std: Implement isFinite for f128 2021-05-01 16:28:13 +02:00
LemonBoy
236dba8ba9 std: Implement copysign for f128 2021-05-01 16:28:08 +02:00
LemonBoy
9f6edfd201 std: Implement signbit for f128 2021-05-01 16:28:03 +02:00
LemonBoy
718b43504e std: Fix pwrite/pread syscalls on SPARC targets 2021-05-01 15:46:28 +02:00
LemonBoy
69a9c1488d std: Add signal numbers for SPARC 2021-05-01 12:25:40 +02:00
LemonBoy
527053a4e4 std: Import correct errno defs for SPARC
Taken from Linux arch/sparc/include/uapi/asm/errno.h
2021-05-01 11:03:59 +02:00
LemonBoy
51f80deaf6 std: Fix stack overflow in SPARC clone() impl
Leave the minimum amount of stack space required by the ABI (16 * 8
bytes for the window contents plus 6 * 8 bytes for the input arguments)
on the new thread stack.
2021-05-01 11:02:04 +02:00
g-w1
e9e91b4ed0 std.build: if using a RunStep, show the command run on verbose (#8571) 2021-05-01 08:17:17 +02:00
Frank Denis
fe8781357a std.crypto: add support for the NIST P-256 curve (#8627)
Uses verified code generated by fiat-crypto for field arithmetic, and complete formulas to avoid side channels.

There's still plenty of room for optimizations, especially with a fixed base. But this gives us a framework to easily add other similar curves.
2021-05-01 08:14:32 +02:00
Andrew Kelley
dc28f5c3ec Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
	lib/std/crypto/25519/field.zig
	lib/std/crypto/poly1305.zig

I had resolved those by removing `comptime` but master branch decided to
make the parameters `comptime`.

This also pulls in the updated default `zig build` install directory.
2021-04-30 23:13:17 -07:00
Andrew Kelley
351b57497b stage2: implement function body analysis
now with whole-file-astgen
2021-04-30 23:11:20 -07:00
Andrew Kelley
557eb414ee CLI: fix incorrect error message with -cflags 2021-04-30 21:55:28 -07:00
Andrew Kelley
077b8d3def stage2: introduce new ZIR instruction: arg
* AstGen: LocalVal and LocalPtr use string table indexes for their
   names. This is more efficient because local variable declarations do
   need to include the variable names so that semantic analysis can emit
   a compile error if a declaration is shadowed. So we take advantage of
   this fact by comparing string table indexes when resolving names.

 * The arg ZIR instructions are needed for the above reasoning, as well
   as to emit equivalent AIR instructions for debug info.
   Now that we have these arg instructions, get rid of the special
   `Zir.Inst.Ref` range for parameters. ZIR instructions now refer
   to the arg instructions for parameters.

 * Move identAsString and strLitAsString from Module.GenZir to AstGen
   where they belong.
2021-04-30 21:43:18 -07:00
Devin Bayer
5fcc922ff2 add doc in Anonymous Struct Literal section for special @"0" syntax. (#8630) 2021-05-01 01:05:45 +02:00
Frank Denis
33cb660838 Doc: zig-cache/bin -> zig-out/bin (#8659) 2021-05-01 00:41:59 +02:00
Frank Denis
3e389d01ed CI: no need to try qemu and wasmtime on macOS builds 2021-05-01 00:38:54 +02:00
Frank Denis
b49d99b246 Azure CI: Test std.* and the rest separately
On CI, we have been running into OOM issues when running the test
suite on Windows for quite some time.

Unfortunately, we are very close to having the same issues on Linux
as well. Some additional comptime work immediately makes these builds
fail as well.

Add a new `test-toolchain` step, that tests everything except `std.*`
and documentation.

On CI, call `test-toolchain`, `test-std` and `docs` separately
instead of the `test` big hammer that emcompasses all of them.

Change the special case we made for Windows to the same code as other
platforms.

This is a stopgap measure that stage2 will eventually make useless.

Until then, it gives us some headroom.

Change `linux_script` by the way to only output the log of failing
steps. This shrinks the Linux CI log from a bazilion lines down to
something more humanely manageable.
2021-04-30 23:41:28 +02:00
Andrew Kelley
db7acd83d2 Sema: implement function declarations 2021-04-30 14:36:02 -07:00
Devin Bayer
d3f55782b0 rename doc refs to deprecated functions like openC (#8467) 2021-04-30 21:31:01 +02:00
Andrew Kelley
fb95fd8443 start.zig: unconditionally import the root source file
stage1 did this by accident by unconditionally semantically analyzing
std.builtin.panic, which imports the root source file to look for a
panic handler override. But stage2 is smarter; it will only semantically
analyze std.builtin.panic if any panic calls are emitted. So for very
simple compilations, the root source file was being ignored, even if it
contained `export` functions in it.
2021-04-30 11:24:15 -07:00
Andrew Kelley
2d8d681b5e stage2: un-tangle memory management of Decl and Namespace
Before there was this "top_decl" and "tmp_namespace" stack values that
were kludgy and buggy. Now Sema is slightly reworked so that files which
are structs are analyzed with their own Decl and Namespace already set
up.

After this commit there are no memory leaks for a successful build-obj.
2021-04-30 11:07:31 -07:00
LemonBoy
807bb7c03f std: Improve spinloop hint
* Add a yield pattern for PowerPC64
* Fix compile error on pre-v6 ARM targets
* Use isb instead of yield on AArch64 to give the CPU a chance to enter
  low-power states.
* Make the hint an inline function, the call overhead can be avoided.
2021-04-30 17:11:03 +02:00
Yorhel
f79b487337 Handle EPERM and ELOOP in os.fstatat() 2021-04-30 15:08:07 +02:00
Andrew Kelley
4e07755ce7 Merge pull request #8638 from ifreund/build-default-prefix
std/build: change default install prefix to zig-out
2021-04-30 00:10:44 -04:00
Andrew Kelley
5d696b0706 stage2: fix File incorrectly freeing its Namespace 2021-04-29 20:49:31 -07:00
Andrew Kelley
8ab4a003c8 stage2: properly free Decl name
Two problems solved:

 * The Decl name may be allocated with gpa or it may be a reference to
   the ZIR string table.

 * The main update() function was freeing the ZIR when we still had
   Decl objects referencing it.
2021-04-29 20:34:33 -07:00
Andrew Kelley
474ade88b5 std: fix compile errors found by stage2 AstGen 2021-04-29 20:33:29 -07:00
Andrew Kelley
8944240aec AstGen: represent global variables directly
Rather than with `block_inline_var`. This matches how function
declarations work and how extern variables work.
2021-04-29 19:56:01 -07:00
Andrew Kelley
86d564eed8 AstGen: implement extern variables 2021-04-29 19:44:51 -07:00
Andrew Kelley
ba9b9cb38d AstGen: implement function prototypes with alignment exprs 2021-04-29 18:25:25 -07:00
Andrew Kelley
2eef83e85f AstGen: fix comptime compile error source location 2021-04-29 17:43:07 -07:00
Andrew Kelley
47585cbe12 Sema: rename TZIR to AIR
Analyzed Intermediate Representation
2021-04-29 17:26:21 -07:00
Andrew Kelley
478dac5346 Sema: skip analysis of empty enum blocks
For these, the ZIR code has an empty block rather than a block with a
single `break_inline` instruction.
2021-04-29 17:25:10 -07:00
Andrew Kelley
9e49a65e1b AstGen: implement anytype struct fields 2021-04-29 17:13:18 -07:00
Andrew Kelley
55e86b724a AstGen: implement comptime struct fields 2021-04-29 16:57:13 -07:00
Andrew Kelley
fb4cb430e0 std.enums: remove stuff for enums with field aliases
This will probably conflict with the real patch to rework this code, and
in such case this commit should be discarded in favor of the other
commit.
2021-04-29 16:05:30 -07:00
Andrew Kelley
4307436b99 move behavior tests from test/stage1/ to test/
And fix test cases to make them pass. This is in preparation for
starting to pass behavior tests with self-hosted.
2021-04-29 15:54:04 -07:00
Andrew Kelley
5a02c938da update behavior tests with respect to new builtin pkg 2021-04-29 15:18:40 -07:00
Isaac Freund
5079d11b21 std/build: change default install prefix to zig-out
Currently the default install prefix is $BUILD_ROOT/zig-cache,
but mixing cache and artifacts makes little sense. Instead make
$BUILD_ROOT/zig-out the default.
2021-04-29 23:58:45 +02:00
Andrew Kelley
eb53680bce tests: prepare behavior tests for stage2 2021-04-29 14:51:21 -07:00
Matthew Borkowski
585479500e check for overflow when reading code lengths for a block with dynamic Huffman codes 2021-04-29 17:48:08 -04:00
Frank Denis
687ef42f98 x: comptime bool -> comptime x: bool (#8639) 2021-04-29 16:27:50 +02:00
Isaac Freund
2ed368fb92 std/build: add -p alias for --prefix 2021-04-29 14:25:58 +02:00
Andrew Kelley
d36a31ba75 stage2: fix scanDecls not advancing the field bits
Also fix `semaFile` not handling compile errors properly.
2021-04-28 23:16:13 -07:00
Andrew Kelley
c60d8f017e std: remove redundant comptime keyword
@g-w1's fancy new compile error in action
2021-04-28 22:58:12 -07:00
Andrew Kelley
0c71d2fdc1 stage2: implement semantic analysis for functions and global vars
* AstGen: add missing `break_inline` for comptime blocks.
 * Module: call getTree() in byteOffset(). This generates the AST when
   using cached ZIR and compile errors need to be reported.
 * Scope.File: distinguish between successful ZIR generation and AIR
   generation (when Decls in scope have been scanned).
   - `semaFile` correctly avoids doing work twice.
 * Implement first pass at `lookupInNamespace`. It has various TODOs
   left, such as `usingnamespace`, and setting up Decl dependencies.
2021-04-28 22:43:26 -07:00
Andrew Kelley
3462193d30 stage2: prepare for mainining Decl references to ZIR indexes 2021-04-28 16:57:01 -07:00
Andrew Kelley
f86469bc5e stage2: semaDecl properly analyzes the decl block
Also flattened out Decl TypedValue fields into
ty, val, has_tv
and add relevant fields to Decl for alignment and link section.
2021-04-28 16:57:01 -07:00
Andrew Kelley
fa6bb4b662 Sema: do not analyze test decls when not in test mode
We do this by reserving string table indexes 0 and 1 in ZIR to be
special. Decls now have 0 to mean comptime or usingnamespace, and 1 to
mean an unnamed test decl.
2021-04-28 16:57:01 -07:00
jacob gw
2354cbafdb stage2: implement #8364 2021-04-28 19:54:04 -04:00
Andrew Kelley
c90e52b74c std: remove redundant comptime const 2021-04-28 15:15:44 -07:00
Andrew Kelley
d3ffacb55c AstGen: hook up hex float parsing to float literals
Thanks @LemonBoy!
2021-04-28 15:13:43 -07:00
Andrew Kelley
9db5b2c5c6 AstGen: function prototypes can have alignment 2021-04-28 15:02:52 -07:00
Andrew Kelley
df24ce52b1 Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
In particular I wanted to take advantage of the new hex float parsing
code.
2021-04-28 14:57:38 -07:00
LemonBoy
55c58f226d std: Add a parser for hexadecimal floating point numbers
Should be good enough to unblock progress on the stage2 compiler.

Unifying this parser and the regular one (and perhaps rewrite it, #2207)
is left as an exercise for the reader.
2021-04-28 17:36:12 -04:00
Andrew Kelley
86e129eff6 std.Target: bump freebsd known maximum version 2021-04-28 10:26:47 -07:00
Andrew Kelley
2c9ed6daee Merge pull request #8472 from sreehax/master
callconv: add SysV
2021-04-28 13:11:40 -04:00
joachimschmidt557
bc06e19828 stage2 riscv64: cleanup code and add tests 2021-04-28 07:20:45 +02:00
Andrew Kelley
eb9c29eb81 AstGen: fix function src hash not including body 2021-04-27 22:20:25 -07:00
Andrew Kelley
3d9e4edb57 link: fix compile error from previous commit 2021-04-27 14:46:55 -07:00
LemonBoy
da9da76e3f stage1: Implement CPU host detection for PowerPC targets
Untested but should work well on both 32 and 64 bit systems.
2021-04-27 13:11:39 -04:00
Andrew Kelley
bfded492f0 stage2: rewire the frontend driver to whole-file-zir
* Remove some unused imports in AstGen.zig. I think it would make sense
   to start decoupling AstGen from the rest of the compiler code,
   similar to how the tokenizer and parser are decoupled.
 * AstGen: For decls, move the block_inline instructions to the top of
   the function so that they get lower ZIR instruction indexes. With
   this, the block_inline instruction index combined with its corresponding
   break_inline instruction index can be used to form a ZIR instruction
   range. This is useful for allocating an array to map ZIR instructions
   to semantically analyzed instructions.

 * Module: extract emit-h functionality into a struct, and only allocate
   it when emit-h is activated.
 * Module: remove the `decl_table` field. This previously was a table of
   all Decls in the entire Module. A "name hash" strategy was used to
   find decls within a given namespace, using this global table. Now,
   each Namespace has its own map of name to children Decls.
   - Additionally, there were 3 places that relied on iterating over
     decl_table in order to function:
     - C backend and SPIR-V backend. These now have their own decl_table
       that they keep populated when `updateDecl` and `removeDecl` are
       called.
     - emit-h. A `decl_table` field has been added to the new GlobalEmitH
       struct which is only allocated when emit-h is activated.
 * Module: fix ZIR serialization/deserialization bug in debug mode having
   to do with the secret safety tag for untagged unions. There is still an
   open TODO to investigate a friendlier solution to this problem with
   the language.
 * Module: improve deserialization of ZIR to allocate only exactly as
   much capacity as length in the instructions array so as to not waste
   space.
 * Module: move `srcHashEql` to `std.zig` to live next to the definition
   of `SrcHash` itself.
 * Module: re-introduce the logic for scanning top level declarations
   within a namespace.

 * Compilation: add an `analyze_pkg` Job which is used to kick off the
   start of semantic analysis by doing the equivalent of
   `_ = @import("std");`. The `analyze_pkg` job is unconditionally added
   to the work queue on every update(), with pkg set to the std lib pkg.

 * Rename TZIR to AIR in a few places. A more comprehensive rename will
   come later.
2021-04-26 20:41:07 -07:00
Andrew Kelley
1c0259f11e Merge pull request #8609 from jedisct1/timingSafeCompare
Add std.crypto.utils.timingSafeCompare
2021-04-26 23:03:46 -04:00
Andrew Kelley
91c317bb9a AstGen: improved handling of declarations
* Every decl provides a 16 byte source hash which can be used to detect
   if the source code for any particular decl has changed.
 * Include comptime decls, test decls, and usingnamespace decls in the
   decls list of namespaces.
   - Tests are encoded as extended functions with is_test bit set.
2021-04-26 17:36:28 -07:00
Frank Denis
d3361c41db Change timingSafeCompare() to accept slices 2021-04-26 22:32:22 +02:00
Frank Denis
030fa5e7eb 25519: remove unused const, safeguard against unreduced scalars (#8624)
* 25519: remove unused const, safeguard against unreduced scalars

No behavior change, but it makes the existing code better match
the forthcoming code for other curves.

Rename nonAdjacentForm() to slide(), remove an unneeded and
confusing constant, and do a reduction in slide() if 257 bits would
be required.

Note that in all the high-level functions, the top bit is always
cleared, so the reduction is never necessary. But since the low-level
functions are public, the check is a safe thing to have.

* 25519: make identityElement public, deprecate neutralElement

Also fix a few comments by the way.
2021-04-26 22:25:48 +02:00
Andrew Kelley
95b42f9e6b Merge pull request #8604 from hoanga/haiku-support-sysdefs
further haiku support system definitions
2021-04-26 16:12:23 -04:00
Andrew Kelley
0de962fdd9 Merge pull request #8622 from LemonBoy/cpuinfo
stage2: Add framework for host CPU detection on Linux
2021-04-26 16:02:07 -04:00
Andrew Kelley
646eb1fa93 AstGen: implement opaque decls
Also move the decls to the beginning in ZIR encoding because in Sema we
want to create the namespace with the decls before evaluating the
fields.
2021-04-26 12:49:02 -07:00
Andrew Kelley
528a83dd6b Merge pull request #8618 from LemonBoy/mini-stuff
Two small patches
2021-04-26 14:32:45 -04:00
Andrew Kelley
ddf9ff79bd Revert "thread: simplify and remove useless return in spawn (#8621)"
This reverts commit 77cb45f59f.

Zig's error return traces will point to the return token if they
happen to occur, so having multiple return statements makes those
stack traces really helpful. This destroys debuggability.
2021-04-26 10:44:40 -07:00
LemonBoy
7e6cc4c505 stage2: Ensure the features set is populated 2021-04-26 18:28:17 +02:00
LemonBoy
896d93e1e6 stage2: Add framework for host CPU detection on Linux
Add a generic framework to parse /proc/cpuinfo and implement the model
detection for 64bit SPARC targets as proof of concept.
2021-04-26 18:11:28 +02:00
Vincent Rischmann
77cb45f59f thread: simplify and remove useless return in spawn (#8621) 2021-04-26 18:03:32 +02:00
jumpnbrownweasel
bf67a3fdc9 #8454 Fix for std.mem.replacementSize adjacent matches bug. (#8455)
* #8454 Fix for std.mem.replacementSize adjacent matches bug.

When two 'needle' values are adjacent in the 'input' slice, the size is not
counted correctly. The 2nd 'needle' value is not matched because the index is
incremented by one after changing the index to account for the first value.

The impact is the the size returned is incorrect, and could cause UB when this
amount is used to size of the buffer passed to std.mem.replace.

* Apply changes from PR review:

- Add assert checking that the needle is non-empty and doc for this.
- Add minimal test that an empty input works.
- Use testing.expectEqualStrings.
2021-04-25 19:16:24 -04:00
Andrew Kelley
c420eb60ad Merge pull request #8590 from lithdew/master
x,  x/os/Socket: initial work on new Socket abstraction
2021-04-25 19:15:15 -04:00
Andrew Kelley
2fc6b347ec Merge pull request #8616 from LemonBoy/fn-align
Function pointer alignment
2021-04-25 19:12:06 -04:00
LemonBoy
82f1d592fa stage1: Use correct alignment for asyncCall frame 2021-04-25 20:41:49 +02:00
Andrew Kelley
56226449d2 stage2: pre-open ZIR cache dir handles
So that we do not needlessly open and close the ZIR cache dir handles in
each AstGen operation.
2021-04-25 10:43:07 -07:00
Andrew Kelley
6f61594692 Merge pull request #8496 from xackus/isError
std.meta: add isError
2021-04-25 13:27:44 -04:00
LemonBoy
5a94794b73 std: Fix thread creation with field-less context type
Closes #8524
2021-04-25 13:21:15 -04:00
joachimschmidt557
3a55cda14d stage2 register manager: Use an array instead of a hashmap for tracking
allocated registers
2021-04-25 13:20:53 -04:00
LemonBoy
dc29d86649 std: Fix wrong alignOf expression
Mostly harmless but conceptually wrong, luckily it hasn't tripped any
safety check.
2021-04-25 19:12:49 +02:00
LemonBoy
54db36cd88 std: Fix backtraces on sparcv9
Flush all the register windows to stack before starting the stack walk,
we may otherwise try to read garbage and crash and burn.

Add a few comptime annotations to debloat some functions.
2021-04-25 19:10:11 +02:00
Frank Denis
0747591c3d Add std.crypto.utils.timingSafeCompare
A little function to complement the existing crypto.utils.timingSafeEql
function with a way to compare large numbers serialized as arrays.

This is useful to compare nonces and to check that group elements are
in canonical form.

Absence of side channels remains a best effort, reusing the common
pattern we use elsewhere.
2021-04-25 17:07:11 +02:00
LemonBoy
0340ed3a9e build: Re-add test-translate-c and test-run-translated-c 2021-04-25 17:02:48 +02:00
LemonBoy
ae15022406 translate-c: Fix casting of function pointers
The @ptrCast(X, @alignCast(@alignOf(T), Y)) pattern is only correct if T
is not a function type or a pointer, in that case the @alignOf refers to
the pointer itself and not to the pointee type.
2021-04-25 16:50:41 +02:00
LemonBoy
19cec0db1e std: Make met.alignment work on more types
Make it return the correct value for function types and optional
pointers.
2021-04-25 16:49:21 +02:00
LemonBoy
50a8124f45 stage1: Change how the Frame alignment is computed
The code would previously assume every function would start at addresses
being multiples of 16, this is not true beside some specific cases.
Moreover LLVM picks different alignment values depending on whether it's
trying to generate dense or fast code.

Let's use the minimum guaranteed alignment as base value, computed
according to how big the opcodes are.

The alignment of function pointers is always 1, a safe value that won't
cause any error at runtime. Note that this was already the case before
this commit, here we're making this choice explicit.

Let the 'alignment' field for TypeInfo of fn types reflect the ABI
alignment used by the compiler, make this field behave similarly to the
'alignment' one for pointers.
2021-04-25 16:40:41 +02:00
lithdew
98706c9686 x: fmt source code 2021-04-25 21:15:02 +09:00
lithdew
b435d7fa60 x, x/os/Socket: initial work on new Socket abstraction
Kick-start initial work on new cross-platform abstraction for
sockets. Adds a test for read timeouts and a test for creating
a non-blocking socket pair on Linux.

The new Socket abstraction is barebones and is made to support both
blocking and non-blocking abstractions, alongside different socket
protocols and domains.

Support for platform-dependant socket options that handles unsupported
platforms gracefully via. comptime checks is provided for the new Socket
abstraction.

This also marks the first out of many commits for introducing breaking
changes to the standard library in a separate `x` folder, which was
pre-approved by @andrewrk.

The intent for the new `x` package is to introduce new async, event loop,
networking, and operating system abstractions that would require breaking
the standard library significantly. By having the `x` package, code in the
standard library and compiler may then slowly be refactored to use the `x`
package. Once modules in the `x` package are stabilized, they can be moved
out of the `x` package, and a global 'grep' can be done to update import
paths that resolve to the stabilized module in the `x` package.
2021-04-25 21:15:02 +09:00
Andrew Kelley
015cd79f89 stage2: implement caching for ZIR code
Notably this exposed an issue with the language having to do with the
secret safety tag on untagged unions. How can we have our cake and eat
it too? Not solved in this commit. I will file a language proposal to
tackle this issue soon.

Fixes a compile error in `std.fs.File.readvAll`.
2021-04-25 00:02:58 -07:00
Shachaf Ben-Kiki
33da465079 Use a directEnumArray lookup table instead of a switch 2021-04-24 23:03:48 -07:00
Shachaf Ben-Kiki
01aa74a93f parser: Use an operator precedence table
Instead of having one function per precedence level, mirroring the BNF grammar,
this uses the "precedence climbing" algorithm with a table of operator
precedences (and a few special cases that don't fit into the table as it is).

This is a first pass -- it's probably possible to put more of the parser
into this form, e.g. to support prefix/suffix operators with precedence, if
necessary, or just to simplify the code more.

It may also be possible to speed this up by putting more useful information
into the tokens during tokenization, to avoid the extra branch on the token in
operInfo.
2021-04-24 22:40:41 -07:00
Michael Dusan
37b05742ff ci: drone disable debug test suite for aarch64
Temporary workaround for #8597 until upstream fix lands.

- add `zig build -Dskip-debug` option
- build a release-fast build.exe
- disable test suite build modes { debug, release-small, release-safe }
- enable passing test-* components
- use parallel pipeline steps for tests
2021-04-25 00:02:36 -04:00
Andrew Kelley
ff2ec0dc5a AstGen: implement @Vector 2021-04-24 17:44:07 -07:00
Andrew Kelley
e018e64a53 stage2: move overflow builtin ZIR instructions to Extended
make some more room in our ZIR enum tag space
2021-04-24 17:31:15 -07:00
Andrew Kelley
6951889f6e Merge pull request #8608 from LemonBoy/fix-8602
translate-c: Prevent mistranslation of fp literals
2021-04-24 19:55:13 -04:00
Andrew Kelley
15e891823e AstGen: parser ensures all suspend have blocks
See #8603.
2021-04-24 14:41:27 -07:00
Andrew Kelley
1592206965 AstGen: implement await and resume
based on @Vexu's code from before
2021-04-24 14:39:44 -07:00
LemonBoy
cf98dfbe22 Remove translate-c test using long double literal
Removed until the rendering logic is adapted to deal with 80bit (and
bigger) floats, those are used sparingly in the wild so it's not much of
a loss.
2021-04-24 20:35:04 +02:00
Andrew Kelley
e86cee258c Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
In particular I wanted the change that makes `suspend;` illegal in the
parser.
2021-04-24 10:44:41 -07:00
Matt Knight
8530b6b724 fix import path 2021-04-24 13:35:55 -04:00
Frank Denis
7a793a9b9d ed25519: use double-base multiplication for signature verification
This makes single signature verification about 60% faster.

Also check that R is not the identity point.
2021-04-24 13:35:36 -04:00
Andrew Kelley
29e5e98eed Merge pull request #8606 from LemonBoy/suspend-block
stage1: Require a block after suspend
2021-04-24 13:34:33 -04:00
LemonBoy
7c3896e6cd translate-c: Prevent mistranslation of fp literals
When trying to retrieve 80bit fp values from clang using
getValueAsApproximateDouble we'd eventually hit the ceiling value and
return infinity, an invalid value for a fp literal.

Add some logic to prevent this error and warn the user.

Closes #8602
2021-04-24 18:42:23 +02:00
LemonBoy
eabf378a56 zig fmt: Automagically fix block-less suspend exprs 2021-04-24 15:37:55 +02:00
LemonBoy
0aede1a8fc stage1: Require a block after suspend
Closes #8603
2021-04-24 10:25:43 +02:00
Andrew Kelley
224fbb23c4 stage2: better error reporting for LazySrcLoc.entire_file
instead of crashing the compilation, uses a plain error message
2021-04-23 23:51:27 -07:00
Andrew Kelley
27fa4bc2be AstGen: support struct init with ref result location 2021-04-23 23:40:10 -07:00
Jakub Konka
4ec6d174ad zld: new approach at handling static inits 2021-04-24 08:13:53 +02:00
Jakub Konka
b00d08b667 zld: add temp debug info fix by setting mtime=0 2021-04-24 08:13:53 +02:00
Jakub Konka
b03983b450 zld: analyze static initializers 2021-04-24 08:13:53 +02:00
Jakub Konka
4f7765de7c zld: common section should be writable 2021-04-24 08:13:53 +02:00
Andrew Kelley
d2b06c2612 stage2: remove call_none and call_none_chkused ZIR
These are unproven optimizations and we need some more room in the
`Zir.Inst.Tag` enum for some more syntax.
2021-04-23 22:43:20 -07:00
Andrew Kelley
6b98384e20 stage2: remove dead ZIR instructions
clearing up some enum tag space for future added instructions
2021-04-23 22:40:57 -07:00
Al Hoang
762d4a959c update haiku system constants 2021-04-23 23:40:42 -05:00
Al Hoang
914d57a1a6 support output collection for haiku 2021-04-23 23:39:13 -05:00
Al Hoang
7a78b92fa0 header path detection for haiku 2021-04-23 23:37:35 -05:00
Andrew Kelley
fbfae832ea AstGen: emit nosuspend function calls
Inside a nosuspend block, emit function calls as nosuspend calls.
Also inside a comptime block, emit function calls as comptime calls.
Also emit `async foo()` calls as async calls.

Remove compile error for `nosuspend` block inside `suspend` block.
Instead of implicitly treating every `suspend` block also as a
`nosuspend` block (which would make sense), we leave suspension points
as compile errors, to hint to the programmer about accidents. Of course
they may then assert `nosuspend` by introducing a block within their
suspend block.

To make room in `Zir.Inst.Tag` I moved `typeof_peer` and `compile_log`
to `Extended`.
2021-04-23 21:12:29 -07:00
Andrew Kelley
49be88859d AstGen: implement nosuspend expressions
Also implement ZIR error notes
2021-04-23 20:31:12 -07:00
Andrew Kelley
9a271347fe AstGen: implement suspend blocks 2021-04-23 20:09:56 -07:00
Andrew Kelley
b40a8efb9a stage2: implement anyframe, anyframe->T and fix assembly
* AstGen: implement `anyframe_literal` and `anyframe_type`.
 * Introduce `makeSubBlock` to avoid redundant AstGen code for GenZir
   scopes. Allows adding/removing a field without possibility of
   accidentally introducing a bug of forgetting to set the new field.
 * Add to GenZir `nosuspend_node` and `suspend_node` in preparation for
   implementing `suspend` blocks and `nosuspend` blocks.
 * AstGen: fix assembly to support clobbers, multiple outputs, and
   outputs without `->` syntax.
   - `asm` and `asm_volatile` move to `Extended` enum with `small` being
     repurposed for a few things. This frees up 2 ZIR tags, 1 of which
     is used in this commit and 1 is leftover.
 * AstGen: fix `simple_types` incorrectly having multiple conflicting
   values for "undefined" and "null".
   - Also add "anyframe" to `simple_types`.
 * Add `anyframe_type` to type.zig, value.zig and `Zir.Inst.Ref`.
   - Also add i128 and u128 types to `Zir.Inst.Ref` and `simple_types`.
 * Sema/Zir: Fix incorrect math causing the function body to be messed
   up for Extended-encoded functions.
 * Zir: support `i32` fields for "extra" payloads.
2021-04-23 18:35:21 -07:00
Andrew Kelley
a279f18bce Merge pull request #8599 from LemonBoy/unsigned-neg
stage1: Allow wrapping negation on unsigned ints at comptime
2021-04-23 16:59:01 -04:00
Hadron67
e86a1df9f2 std.atomic: load should take const pointer to Self 2021-04-23 22:39:49 +02:00
Andrew Kelley
dfb34c3155 Merge pull request #8586 from LemonBoy/ppc32-touchups
A few more PPC32 touch-ups
2021-04-23 15:12:38 -04:00
Andrew Kelley
183ee0965f AstGen: compile error for unable to infer array size 2021-04-23 11:14:11 -07:00
LemonBoy
9ac5f98200 std: Remove unneeded workaround
Now that -% works on unsigned integers at comptime this (clever) hack is
not not needed anymore.
2021-04-23 19:19:44 +02:00
LemonBoy
cc8e49283d stage1: Allow wrapping negation on unsigned ints at comptime
Closes #7951
Closes #8574
2021-04-23 19:15:52 +02:00
Andrew Kelley
0262dda9b8 std: remove comptime const 2021-04-22 23:52:52 -07:00
Andrew Kelley
715abe8ebe AstGen: implement integers bigger than u64
also get rid of the `optional_type_from_ptr_elem` instruction.
2021-04-22 23:47:31 -07:00
Andrew Kelley
2d290d6f82 stage2: write out builtin.zig before spawning AstGen tasks
Otherwise it's possible for AstGen to get FileNotFound when trying to
eager-load `import("builtin")`.
2021-04-22 22:35:18 -07:00
Andrew Kelley
a830ebe718 ZIR: fix text printing of field_ptr_type
Thanks @g-w1
2021-04-22 22:18:53 -07:00
Andrew Kelley
8df4bb7c96 stage2: fix builtin.zig for zig test 2021-04-22 19:48:12 -07:00
jacob gw
ce41ddcd23 std: fix potential bug in parseInt 2021-04-22 22:42:46 -04:00
Andrew Kelley
93d1c2d6d4 std: fix compile errors caught by stage2 AstGen
Follow-up from 507a8096d2
2021-04-22 19:32:57 -07:00
Andrew Kelley
8dd7378013 delete packed enums from the language
No need for any such thing. Instead, provide an integer tag type for the
enum.
2021-04-22 19:21:50 -07:00
Andrew Kelley
329a359974 AstGen: implement align and linksection on globals 2021-04-22 19:21:33 -07:00
Andrew Kelley
507a8096d2 std: fix compile errors caught by stage2 AstGen
* `comptime const` is redundant
 * don't use `extern enum`; specify a tag type.
   `extern enum` is only when you need tags to alias. But aliasing tags
   is a smell. I will be making a proposal shortly to remove `extern enum`
   from the language.
 * there is no such thing as `packed enum`.
 * instead of `catch |_|`, omit the capture entirely.
 * unused function definition with missing parameter name
 * using `try` outside of a function or test
2021-04-22 18:07:46 -07:00
Andrew Kelley
7c453b91b8 AstGen: implement @extern builtin 2021-04-22 16:31:51 -07:00
Andrew Kelley
41efdc73b9 langref: add docs for @extern 2021-04-22 16:24:14 -07:00
Andrew Kelley
3d637e6dd2 AstGen: fix @export
Make it properly use `std.builtin.ExportOptions`.
2021-04-22 16:07:58 -07:00
Andrew Kelley
130ad08001 AstGen: implement function prototypes 2021-04-22 14:24:22 -07:00
Andrew Kelley
389020009a AstGen: implement alignment on locals 2021-04-21 22:43:57 -07:00
Andrew Kelley
ea00ddfe37 AstGen: implement comptime locals 2021-04-21 20:42:49 -07:00
Andrew Kelley
8ee0cbe50a AstGen: fix switch result location elision
It was eliding wrong instructions for nested break from labeled block
2021-04-21 19:49:58 -07:00
Andrew Kelley
570ed7b3bf AstGen: implement @bitCast for other result location types 2021-04-21 19:11:36 -07:00
Andrew Kelley
4cfea2fbd5 AstGen: fix @floatCast having wrong arity
It's not time for #5909 yet.
2021-04-21 19:10:54 -07:00
LemonBoy
6cd71931cb stage1: Unbreak build on FreeBSD
It turns out that the endianness-detection header delivered with the
softfloat library is extremely brittle and gives wrong results when
targeting FreeBSD (long story short, _BIG_ENDIAN is always defined there
and that breaks the #if defined() chain).

Use our own endianness detection header to work around any potential
problem.
2021-04-21 22:07:55 +02:00
LemonBoy
c5cc6b7082 compiler-rt: Export __extendhftf2 and __trunctfhf2
Even though LLVM12 doesn't make use of those intrinsics at the moment
let's export them anyway.
2021-04-21 19:02:13 +02:00
LemonBoy
e0d7cfce5f compiler-rt: Don't re-define PPC builtins in test mode
Prevent linking errors when `zig test`-ing the compiler_rt module for
powerpc-linux triples.
2021-04-21 19:00:57 +02:00
LemonBoy
89d0cc4d8c test: Add 32bit PowerPC to the test plan
Since MIPS is temporarily out of order due to some issues with LLD let's
add PPC32 to have at least one big-endian platform in the testing plan.
2021-04-21 16:31:30 +02:00
LemonBoy
e4f9a3041a std: Use stat definition with 32bit *time fields
We're not ready for Y38K yet.
2021-04-21 16:31:30 +02:00
LemonBoy
d82eb8dd40 std: Split syscall parameters for PowerPC targets 2021-04-21 16:31:29 +02:00
Andrew Kelley
d10ec6e70d AstGen: slightly better eager-allocating heuristic
Some early ensureCapacity calls to avoid needless reallocations.
2021-04-20 22:16:45 -07:00
Jakub Konka
c8753aceef macho: fix typos in consts defs 2021-04-21 06:49:34 +02:00
Andrew Kelley
a1ac2b95bb AstGen: implement union decls 2021-04-20 21:48:18 -07:00
Andrew Kelley
971f3d95f9 AstGen: implement size zero inferred length arrays 2021-04-20 18:32:43 -07:00
Andrew Kelley
c69a95f64b AstGen: fix store_to_block_ptr elision for switch statements
to make sure it matches the expected block
2021-04-20 17:58:04 -07:00
Andrew Kelley
a008fb0a71 std.fs: delete unused label
stage2 starting to catch problems with the standard library :)
2021-04-20 17:57:35 -07:00
Andrew Kelley
e9477048e5 AstGen: implement for loop payload 2021-04-20 17:52:35 -07:00
Andrew Kelley
30c9808391 AstGen: implement anytype parameters 2021-04-20 17:38:06 -07:00
Andrew Kelley
a62db38d90 AstGen: implement defer for break 2021-04-20 17:04:11 -07:00
Andrew Kelley
458c4b6fc6 AstGen: implement defer for continue 2021-04-20 17:04:11 -07:00
Andrew Kelley
a59bcae59f AstGen: basic defer implementation 2021-04-20 17:04:11 -07:00
jacob gw
b4aec0e31d stage2: make std.fmt.parseInt ignore _ 2021-04-20 17:08:05 -04:00
jacob gw
6b944492b5 stage2: fix compile error in codegen 2021-04-20 17:08:05 -04:00
Michael Dusan
0c6dfa6f0c target: drop ppc32 and prefer ppc
- original PR #7949 (incorrectly) patched a generated-file and changes
  have subsequently been lost/overwritten
- fix #7947 in a different way: drop `ppc32` because `ppc` already exists
2021-04-20 16:19:59 -04:00
Andrew Kelley
b4baa9eda2 AstGen: try fixups
Primarily this required fixing `setCondBrPayloadElideBlockStorePtr` to
not assume there would always be two `store_to_block_ptr` instructions
in each of the condbr prongs.
2021-04-20 11:16:50 -07:00
Frank Denis
10f2d62789 std/crypto: use finer-grained error sets in function signatures (#8558)
std/crypto: use finer-grained error sets in function signatures

Returning the `crypto.Error` error set for all crypto operations
was very convenient to ensure that errors were used consistently,
and to avoid having multiple error names for the same thing.

The flipside is that callers were forced to always handle all
possible errors, even those that could never be returned by a
function.

This PR makes all functions return union sets of the actual errors
they can return.

The error sets themselves are all limited to a single error.

Larger sets are useful for platform-specific APIs, but we don't have
any of these in `std/crypto`, and I couldn't find any meaningful way
to build larger sets.
2021-04-20 19:57:27 +02:00
Andrew Kelley
1e06a74348 Merge pull request #8542 from LemonBoy/floating-point-is-hard-my-dude
Floating point is hard my dude
2021-04-20 13:28:03 -04:00
jacob gw
ee3c1c763c stage2: astgen try 2021-04-20 13:16:08 -04:00
Veikka Tuominen
2ca26ffde7 Merge pull request #8582 from LemonBoy/more-libc-impl
Improve the libc implementation
2021-04-20 19:54:16 +03:00
Jakub Konka
d64c76e8f1 zld: fix parsing of weak symbols 2021-04-20 16:55:32 +02:00
Jakub Konka
7bc6554a58 zld: map __DATA,__common as __DATA_CONST,__common 2021-04-20 16:55:32 +02:00
Jakub Konka
e5b83056ae zld: resolve symbols as globals before resolving locals 2021-04-20 16:55:32 +02:00
Jakub Konka
8943a0aaaa zld: dedup initializers and finalizers 2021-04-20 16:55:32 +02:00
Jakub Konka
3e73a3c29b zld: treat priv extern as weak symbol 2021-04-20 16:55:32 +02:00
LemonBoy
a5a3ad5e10 c: Minor cleanup
* Remove superfluous "test_" prefix in test names
* Use aliased isNan everywhere
2021-04-20 15:44:54 +02:00
LemonBoy
a4e2539b09 c: Implement fmax and fmaxf 2021-04-20 15:44:21 +02:00
LemonBoy
fcfe25710b c: Implement fmin and fminf 2021-04-20 15:43:46 +02:00
LemonBoy
c7c77fb1b0 c: Add tests for generic_fmod implementation 2021-04-20 15:43:01 +02:00
LemonBoy
be551d85b7 translate-c: Group field access LHS if necessary 2021-04-20 15:16:25 +03:00
Evan Haas
63304a871e translate-c: group LHS of array access if necessary 2021-04-20 11:33:01 +03:00
Evan Haas
55e6bd10fe translate-c: use transCreateNodeInfixOp for pointer arithmetic 2021-04-20 11:33:01 +03:00
Andrew Kelley
e315120b79 AstGen: implement array initialization expressions 2021-04-19 23:23:24 -07:00
Andrew Kelley
693dbeeef2 stage2: make @alignCast accept 2 parameters
It is not yet time to implement #5909.
2021-04-19 18:46:45 -07:00
Andrew Kelley
4630e3891c AstGen: implement inline asm output 2021-04-19 18:44:59 -07:00
Andrew Kelley
a136c093bf zig astgen: print instruction counts and byte sizes 2021-04-19 16:23:05 -07:00
Andrew Kelley
7f931a7522 AstGen: implement error set decls 2021-04-19 16:03:46 -07:00
Andrew Kelley
2083208f19 AstGen: implement functions with inferred error sets
This commit also reclaims +2 ZIR instruction tags by moving the
following to `extended`:
 * func_var_args
 * func_extra
 * func_extra_var_args
The following ZIR instruction tag is added:
 * func_inferred
2021-04-19 15:03:41 -07:00
Andrew Kelley
22015c1b3b std.MultiArrayList: ensureUnusedCapacity/ensureTotalCapacity
Same as c8ae581fef, but for
MultiArrayList.
2021-04-19 15:02:37 -07:00
Isaac Freund
e2cc02717e Fix .gitattributes rules that should be recursive
These are currently incorrect according to the gitattributes(5) and
gitignore(5) man pages. However, it seems github ended up treating them
as we intended due to a bug until recently when that bug was fixed.
2021-04-19 16:55:12 -04:00
Andrew Kelley
27d4bea9a4 AstGen: implement if optional, if error union 2021-04-19 12:25:16 -07:00
Andrew Kelley
3dadccec45 AstGen: implement while optional and while error union 2021-04-19 12:02:11 -07:00
Andrew Kelley
3f60481be4 AstGen: implement the remaining struct init ResultLoc forms 2021-04-19 11:09:00 -07:00
Hubert Jasudowicz
d605f02756 std: Add process_vm_readv/writev wrappers 2021-04-19 16:12:28 +02:00
Andrew Kelley
ae495de54d AstGen: implement all the builtin functions 2021-04-18 22:38:41 -07:00
joachimschmidt557
fbda9991f4 stage2 codegen: Fix silent bug in reuseOperand 2021-04-17 20:57:26 -04:00
Isaac Freund
4081e0a475 zig fmt: bypass auto indentation for // zig fmt: on
Currently an indented `// zig fmt: on` will be indented an additional
time on every run of zig fmt.
2021-04-17 20:10:20 -04:00
Andrew Kelley
5a3045b5de AstGen: implement overflow arithmetic builtins 2021-04-17 13:00:10 -07:00
Isaac Freund
8e6865c8ee std/build: fix linker_allow_shlib_undefined
The relevant flags were renamed in 01a1365 but updating std.build
was overlooked.
2021-04-17 15:17:54 +02:00
Frank Denis
9f6b56ab4b Merge pull request #8555 from chivay/pidfd
std: Add pidfd wrappers
2021-04-17 15:03:25 +02:00
jacob gw
afb9f695b1 stage2: add support for zig cc assembler -mcpu option 2021-04-17 02:00:07 -04:00
Andrew Kelley
8cf0ef2779 AstGen: implement simple enums and decls for enums 2021-04-16 22:21:26 -07:00
Andrew Kelley
0409d433ba AstGen: fix compile error using wrong node/token function 2021-04-16 19:49:19 -07:00
Andrew Kelley
e13fc6b119 stage2: make @import relative to the current file
previously, it was incorrectly relative to the package directory
2021-04-16 19:45:58 -07:00
Andrew Kelley
415ef1be51 AstGen: fix function decl astgen
it was using the wrong scope and other mistakes too
2021-04-16 19:45:24 -07:00
Andrew Kelley
dd5a1b1106 build.zig: add a way to skip installing lib/ files 2021-04-16 18:58:27 -07:00
Andrew Kelley
9375ad0d3b AstGen: implement global var decls
And fix bug with using `ensureCapacity` when I wanted
`ensureUnusedCapacity`.
2021-04-16 17:57:51 -07:00
Andrew Kelley
c8ae581fef std: deprecate ensureCapacity, add two other capacity functions
I've run into this footgun enough times, nearly every time I want
`ensureUnusedCapacity`, not `ensureCapacity`. This commit deprecates
`ensureCapacity` in favor of `ensureTotalCapacity` and introduces
`ensureUnusedCapacity`.
2021-04-16 17:56:30 -07:00
Andrew Kelley
5ff45b3f44 stage2: use import list from ZIR to queue up more AstGen tasks 2021-04-16 17:28:28 -07:00
Andrew Kelley
a271f12a14 AstGen: store list of imports 2021-04-16 16:20:29 -07:00
Hubert Jasudowicz
5134fb72ef std: Add pidfd wrappers 2021-04-17 01:13:16 +02:00
Andrew Kelley
edd75d03e3 ZIR: rename decl_val and decl_ref to remove redundant suffix 2021-04-16 15:52:26 -07:00
Andrew Kelley
adc2aed587 AstGen: require @import operand to be string literal
See #2206
2021-04-16 15:50:28 -07:00
Andrew Kelley
333a577d73 AstGen: put decls into blocks to be evaluated independently 2021-04-16 15:34:09 -07:00
Isaac Freund
01a1365857 Rename --(no-)allow-shilb-undefined to -f(no-)allow-shilb-undefined
This breaks with GNU ld but is consistent with our naming convention for
all the rest of the flags.
2021-04-17 00:03:35 +02:00
Andrew Kelley
01b4bf34ea stage2: AstGen improvements
* AstGen: represent compile errors in ZIR rather than returning
   `error.AnalysisFail`.
 * ZIR: remove decl_ref and decl_val instructions. These are replaced by
   `decl_ref_named` and `decl_val_named`, respectively, which will
   probably get renamed in the future to the instructions that were just
   deleted.
 * AstGen: implement `@This()`, `@fence()`, `@returnAddress()`, and
   `@src()`.
 * AstGen: struct_decl improved to support fields_len=0 but have decls.
 * AstGen: fix missing null bytes after compile error messages.
 * SrcLoc: no longer depend on `Decl`. Instead have an explicit field
   `parent_decl_node` which is an absolute AST Node index.
 * Module: `failed_files` table can have null value, in which case the
   key, which is a `*Scope.File`, will have ZIR errors in it.
 * ZIR: implement text rendering of struct decls.
 * CLI: introduce debug_usage and `zig astgen` command which is enabled
   when the compiler is built in debug mode.
2021-04-16 14:48:10 -07:00
daurnimator
99e7ba24b1 Add LibExeObjStep.linker_allow_shlib_undefined field to set --allow-shlib-undefined 2021-04-16 22:51:51 +02:00
daurnimator
0e687d125b Add --(no-)allow-shlib-undefined to supported zig linking flags 2021-04-16 22:51:51 +02:00
Andrew Kelley
140d9df99b Merge pull request #8506 from LemonBoy/test-c-file
build: Test the c.zig file too
2021-04-16 13:03:52 -04:00
joachimschmidt557
5edabb3990 stage2 register manager: Add functions for allocating multiple registers 2021-04-16 13:03:10 -04:00
Manuel Floruß
2cd49d20e8 Fix std.os.windows.user32.messageBoxW
Arguments to `selectSymbol` were passed in the wrong order.
2021-04-16 13:01:25 -04:00
Andrew Kelley
235aa8c078 ci: drone: don't skip stage2 tests
the stalls seem to be happening for a different reason
2021-04-16 09:57:31 -07:00
Mahdi Khanalizadeh
d1a41feddc linux: fix number of arguments for tgkill syscall 2021-04-16 17:09:15 +02:00
gracefu
cfeb412a42 stage2 x86_64: fix incorrect comment in genX8664BinMath
Co-authored-by: joachimschmidt557 <joachim.schmidt557@outlook.com>
2021-04-16 15:21:17 +08:00
gracefu
dc13662725 stage2 x86_64: force 64 bit mode when loading address of GOT
Co-authored-by: joachimschmidt557 <joachim.schmidt557@outlook.com>
2021-04-16 15:21:17 +08:00
gracefu
1e63e8d8b6 stage2 x86_64: fix codegen ensureCapacity bug for function calls
Co-authored-by: joachimschmidt557 <joachim.schmidt557@outlook.com>
2021-04-16 15:21:17 +08:00
gracefu
62e755623f stage2 x86_64: bugfix abi_size == 64 should be abi_size == 8 2021-04-16 15:21:17 +08:00
gracefu
b004c3da15 stage2 x86_64: try to fix RIP-relative offset to GOT for macho 2021-04-16 15:21:17 +08:00
gracefu
0409f9e024 stage2 x86_64: simplify inst encoder to a set of dumb helper fns 2021-04-16 15:21:17 +08:00
gracefu
613f39eb62 stage2 x86_64: fix comptime integer multiplication when rhs=0
Co-authored-by: joachimschmidt557 <joachim.schmidt557@outlook.com>
2021-04-16 15:21:17 +08:00
gracefu
c4b83ea021 stage2 x86_64: implement integer mul
This was also an experiment to see if it were easier to implement a new
feature when using the instruction encoder.

Verdict: It's not that much easier, but I think it's certainly much more
readable, because the description of the Instruction annotates what each
field means. Right now, precise knowledge of x86_64 instructions is
still required because things like when to set the 64-bit flag, how to
read x86_64 instruction references, etc. are still not automatically
done for you.

In the future, this interface might make it sligtly easier to write an
assembler for x86_64, by abstracting the bit-fiddling aspects of
instruction encoding.
2021-04-16 15:21:17 +08:00
gracefu
5bd464e386 stage2 x86_64: use abi size to determine 64-bit operation
From my very cursory reading, it seems that the register manager doesn't
distinguish between registers that are physically the same but have
different sizes.

In that case, this means that during codegen, we can't rely on
`reg.size()` when determining the width of the operations we have to
perform. Instead, we must use some form of `ty.abiSize(self.target.*)`
to determine the size of the type we're operating with. If this size is
64 bits, then we should enable 64-bit operation.

This fixed a bug in the codegen for spilling instructions, which was
overwriting the previous stack entry with zeroes. See the modified test
case in this commit.
2021-04-16 15:21:17 +08:00
gracefu
36df1526da stage2 x86_64: refactor codegen to use inst encoder
There are parts of it that I didn't modify because the byte
representation was important (e.g. we need to know what the exact
byte position where we store the address into the offset table is)
2021-04-16 15:21:17 +08:00
gracefu
e1959ccd4e stage2 x86_64: add instruction encoder helper fn 2021-04-16 15:21:16 +08:00
Andrew Kelley
cf57e8223f AstGen: implement comptimeDecl, usingnamespaceDecl, testDecl 2021-04-15 20:55:54 -07:00
Andrew Kelley
8387307807 AstGen: implement global variable decls 2021-04-15 20:34:21 -07:00
Evan Haas
d4d21dd46d translate-c: better handling of int -> enum casts
In std.meta.cast when casting to an enum type from an integer type, first
do a C-style cast from the source value to the tag type of the enum.
This ensures that we don't get an error due to the source value not being
representable by the enum.

In transCCast() use std.meta.cast instead of directly emitting the cast
operation since the enum's underlying type may not be known at translation
time due to an MSVC bug, see https://github.com/ziglang/zig/issues/8003

Fixes #6011
2021-04-15 22:46:22 -04:00
Andrew Kelley
7818586a2b fix new references to std.builtin that should have been std.Target 2021-04-15 19:14:54 -07:00
Andrew Kelley
f37451a63a stage2: fix zir.zig => Zir.zig in CMakeLists.txt 2021-04-15 19:12:05 -07:00
Andrew Kelley
3114115348 stage2: preliminary reworking for whole-file-AstGen
See #8516.

 * AstGen is now done on whole files at once rather than per Decl.

 * Introduce a new wait group for AstGen tasks. `performAllTheWork`
   waits for all AstGen tasks to be complete before doing Sema,
   single-threaded.
   - The C object compilation tasks are moved to be spawned after
     AstGen, since they only need to complete by the end of
     the function.

With this commit, the codebase compiles, but much more reworking is
needed to get things back into a useful state.
2021-04-15 19:06:39 -07:00
Andrew Kelley
9088d40e83 stage2: rename zir to Zir
since it now uses top level fields
2021-04-15 19:06:39 -07:00
Andrew Kelley
0170a242bb stage2: move zir.Code to become root level fields of zir.zig
next commit will do the rename
2021-04-15 19:06:39 -07:00
Andrew Kelley
798ad631f3 stage2 start.zig: slight simplification
fewer required language features to allow this to work
2021-04-15 19:06:39 -07:00
Andrew Kelley
6dba9bc6fc stage2: implement @bitSizeOf 2021-04-15 19:06:39 -07:00
Andrew Kelley
df983b30d2 stage2: implement comptime division 2021-04-15 19:06:39 -07:00
Andrew Kelley
69645e2817 stage2: implement @sizeOf 2021-04-15 19:06:39 -07:00
Andrew Kelley
0e50a0c1e5 stage2: implement non-trivial enums 2021-04-15 19:06:39 -07:00
Andrew Kelley
bcfebb4b2b stage2: improvements aimed at std lib integration
* AstGen: emit decl lookup ZIR instructions rather than directly
   looking up decls in AstGen. This is necessary because we want to
   reuse the same immutable ZIR code for multiple generic instantiations
   (and comptime function calls).
 * AstGen: fix using members_len instead of fields_len for struct decls.
 * structs: the struct_decl ZIR instruction is now also a block. This is
   so that the type expressions, default field value expressions, and
   alignment expressions can be evaluated in a scope that contains the
   decls from the struct namespace itself.
 * Add "std" and "builtin" packages to the builtin package.
 * Don't try to build glibc, musl, or mingw-w64 when using `-ofmt=c`.
 * builtin.zig is generated without `usingnamespace`.
 * builtin.zig takes advantage of `std.zig.fmtId` for CPU features.
 * A first pass at implementing `usingnamespace`. It's problematic and
   should either be deleted, or polished, before merging this branch.
 * Sema: allow explicitly specifying the namespace in which to look up
   Decls. This is used by `struct_decl` in order to put the decls from
   the struct namespace itself in scope when evaluating the type
   expressions, default value expressions, and alignment expressions.
 * Module: fix `analyzeNamespace` assuming that it is the top-level root
   declaration node.
 * Sema: implement comptime and runtime cmp operator.
 * Sema: implement peer type resolution for enums and enum literals.
 * Pull in the changes from master branch:
   262e09c482.
 * ZIR: complete out simple_ptr_type debug printing
2021-04-15 19:06:39 -07:00
Andrew Kelley
429cd2b5dd std: change @import("builtin") to std.builtin 2021-04-15 19:06:39 -07:00
Andrew Kelley
a4bb7c8bb1 stage2: remove redundant source hash 2021-04-15 19:06:39 -07:00
Andrew Kelley
f458192e56 stage2: entry point via std lib and proper updated file detection
Instead of Module setting up the root_scope with the root source file,
instead, Module relies on the package table graph being set up properly,
and inside `update()`, it does the equivalent of `_ = @import("std");`.
This, in term, imports start.zig, which has the logic to call main (or
not). `Module` no longer has `root_scope` - the root source file is no
longer special, it's just in the package table mapped to "root".

I also went ahead and implemented proper detection of updated files.
mtime, inode, size, and source hash are kept in `Scope.File`.
During an update, iterate over `import_table` and stat each file to find
out which ones are updated.

The source hash is redundant with the source hash used by the struct
decl that corresponds to the file, so it should be removed in a future
commit before merging the branch.

 * AstGen: add "previously declared here" notes for variables shadowing
   decls.
 * Parse imports as structs. Module now calls `AstGen.structDeclInner`,
   which is called by `AstGen.containerDecl`.
   - `importFile` is a bit kludgy with how it handles the top level Decl
     that kinda gets merged into the struct decl at the end of the
     function. Be on the look out for bugs related to that as well as
     possibly cleaner ways to implement this.
 * Module: factor out lookupDeclName into lookupIdentifier and lookupNa
 * Rename `Scope.Container` to `Scope.Namespace`.
 * Delete some dead code.

This branch won't work until `usingnamespace` is implemented because it
relies on `@import("builtin").OutputMode` and `OutputMode` comes from a
`usingnamespace`.
2021-04-15 19:06:39 -07:00
Andrew Kelley
ccdf55310b stage2: properly model miscellaneous failed tasks
with error messages that go away after updates
2021-04-15 19:01:55 -07:00
Andrew Kelley
2b2920f599 ci: drone: disable stage2 tests
See #8545
2021-04-15 16:20:43 -07:00
LemonBoy
bd4421befe compiler-rt: Don't pass f16 around as arguments
Fixes some failures on AArch64.
f16 was a mistake.
2021-04-15 21:52:08 +02:00
Andrew Kelley
c795e82cbc ci: windows: update to llvm 12 msvc tarball 2021-04-15 12:40:22 -07:00
Andrew Kelley
c49fe52cb1 ci: update macos tarball to llvm 12 2021-04-15 11:27:02 -07:00
Andrew Kelley
68e69aae2b build.zig: omit LLVMTableGen from llvm libs 2021-04-15 10:58:53 -07:00
Andrew Kelley
2a6ec2e155 build.zig: update llvm libs 2021-04-15 10:43:39 -07:00
LemonBoy
5bc1dc59e6 compiler-rt: Implement __trunctfhf2 2021-04-15 18:23:09 +02:00
LemonBoy
b29677dd12 compiler-rt: Implement __extendhftf2 2021-04-15 18:21:58 +02:00
LemonBoy
7a4dad7e87 stage1: More precise serialization of f16 values
Taking a detour trough a f64 is dangerous as the softfloat library
doesn't like converting sNaN values.

The error went unnoticed as an exception is raised by the library but
the stage1 compiler doesn't give a damn.
2021-04-15 18:17:31 +02:00
LemonBoy
2d00f17d15 test: Add test to ensure signed zeros are properly computed
Ensure everything's ok at comptime and runtime.
2021-04-15 18:17:21 +02:00
LemonBoy
8e0b2f0e52 compiler-rt: Fix typo in implementation of fp truncation ops
The problem went unnoticed for years, yay.
2021-04-15 18:14:25 +02:00
LemonBoy
f9481402f0 stage1: Fix negation for zero floating point values
Toggling the sign by computing 0-x doesn't really work for zero values.
2021-04-15 18:12:11 +02:00
Andrew Kelley
a38042e3ac ci: windows: proper flags to zig build 2021-04-15 02:02:36 -07:00
Andrew Kelley
fa633a658f ci: windows: try the dev kit strategy 2021-04-15 01:44:17 -07:00
Andrew Kelley
4a1d3465cc ci: windows: ranlib take 2 2021-04-15 01:22:42 -07:00
Andrew Kelley
3266f326de ci: windows: better -DCMAKE_RANLIB option 2021-04-15 01:14:33 -07:00
Andrew Kelley
04b8354702 freebsd: disable failing test
See #8538
2021-04-15 00:59:40 -07:00
Andrew Kelley
996193c228 ci: freebsd: don't try to compile with zig cc 2021-04-15 00:51:26 -07:00
Andrew Kelley
a680c7ba98 ci: windows: use llvm-ar.exe from the tarball 2021-04-15 00:41:30 -07:00
Andrew Kelley
c59241bda0 ci: better handle of -mcpu 2021-04-15 00:18:21 -07:00
Andrew Kelley
553fbeba82 ci: better target triple and mcpu cmake args 2021-04-14 23:49:16 -07:00
Andrew Kelley
85755c51d5 ci: freebsd: set the target triple 2021-04-14 23:35:51 -07:00
Andrew Kelley
df319db058 ci: windows: install git 2021-04-14 23:18:03 -07:00
Andrew Kelley
3967823f3a ci: freebsd: pass -DZIG_USE_LLVM_CONFIG=OFF 2021-04-14 23:17:08 -07:00
Andrew Kelley
ee42178b43 ci: aarch64-linux: disable run-translated-c tests
See #8537
2021-04-14 23:10:51 -07:00
Andrew Kelley
45eb9554c4 ci: windows: try using zig-bootstrap to build zig 2021-04-14 23:03:16 -07:00
Andrew Kelley
406353103a ci: freebsd: update to llvm 12 2021-04-14 22:59:34 -07:00
Andrew Kelley
1438c324a4 ci: update drone CI to llvm 12 2021-04-14 21:18:23 -07:00
Andrew Kelley
391a40d601 ci: update linux to llvm12 tarball 2021-04-14 20:35:33 -07:00
Michael Dusan
6a7f21d1b8 ci: macos-aarch64 update dep tarballs for llvm12 2021-04-14 19:43:17 -07:00
lithdew
81adcd533e os/posix: handle ECONNRESET for write/writev 2021-04-14 16:40:06 -07:00
Andrew Kelley
5a3ea9bece Merge remote-tracking branch 'origin/llvm12'
Happy LLVM 12 Release Day.

Please note that the llvm 12 tag does not include the latest commit in
the release/12.x branch, which is in fact a bug fix for a regression
that is causing a failure in Zig's test suite.

Zig master branch is tracking release/12.x, and will be enabling the
test that is fixed by that commit.
2021-04-14 14:41:57 -07:00
LemonBoy
2ebd6bd706 std: Fix sqrt for u0/u1 input types 2021-04-14 17:53:27 +02:00
LemonBoy
ebf97627fd build: Test the c.zig file too
* Add some more tests for the sqrt/sqrtf implementations.
  The idea is to cross-check the software impl with the HW one whenever
  possible.
* Fix a broken test, oops.
2021-04-14 17:53:26 +02:00
Frank Denis
1fada37466 Merge pull request #8518 from akvadrako/doc-field-align
Update doc for struct field alignment.
2021-04-14 10:56:37 +02:00
Evan Haas
e761e0ac18 translate-c: wrap switch statements in a while (true) loop
This allows `break` statements to be directly translated from the original C.
Add a break statement as the last statement of the while loop to ensure we
don't have an infinite loop if no breaks / returns are hit in the switch.

Fixes #8387
2021-04-13 11:45:03 -07:00
Jakub Konka
36a33c99e3 Merge pull request #8517 from ziglang/zld-archive-fix
zld: fix symbol resolution from interdependent static archives
2021-04-13 17:12:26 +02:00
Devin Bayer
ca3aa02206 Update doc for struct field alignment. 2021-04-13 14:53:44 +02:00
Jakub Konka
461543a5fd zld: fix symbol resolution from interdep archives
Fixes symbol resolution if an archive occurring later in the linker
line depends on a object embedded within the archive that occurred
before.
2021-04-13 13:36:08 +02:00
Jakub Konka
65e4725aba Add standalone test for interdep C archives
Tests a scenario where the linker line has the following:

```
main.o libA.a libB.a
```

where `main.o` pulls a symbol from `libB.a`, which in turn is
dependent on a symbol from `libA.a`.
2021-04-13 13:32:59 +02:00
Jakub Konka
a5bbc66f10 zld: cleanup redundant changes 2021-04-13 10:56:03 +02:00
Jakub Konka
db30033de2 zld: rebase to new naming conv for aarch64 2021-04-13 10:56:03 +02:00
Jakub Konka
1119970d22 zld: add x86_64 relocs 2021-04-13 10:56:03 +02:00
Jakub Konka
b1f9db75f3 zld: save locals per TU 2021-04-13 10:56:03 +02:00
Jakub Konka
3b7c9dd6bd zld: differentiate between static and global in stabs 2021-04-13 10:56:03 +02:00
Jakub Konka
717d382871 zld: streamline tags for Symbol 2021-04-13 10:56:03 +02:00
Jakub Konka
b377e0b370 zld: fix indirect symtab 2021-04-13 10:56:03 +02:00
Jakub Konka
b0a4e1fa46 zld: fix rebase vs bind for GOT entries 2021-04-13 10:56:03 +02:00
Jakub Konka
6e3f82ef28 zld: fix parsing debug info 2021-04-13 10:56:03 +02:00
Jakub Konka
65c27d51f6 zld: limit exports to just main entrypoint 2021-04-13 10:56:03 +02:00
Jakub Konka
421102ba72 zld: move parsing debug info into object 2021-04-13 10:56:03 +02:00
Jakub Konka
dc7cff8ebc zld: add prelim support for locals 2021-04-13 10:56:03 +02:00
Jakub Konka
23bb6fa9f4 zld: flush MachO 2021-04-13 10:56:03 +02:00
Jakub Konka
db44a7803f zld: resolve target addresses for relocs 2021-04-13 10:56:03 +02:00
Jakub Konka
b667fe2c62 zld: resolve stubs and GOT entries 2021-04-13 10:56:03 +02:00
Jakub Konka
46cc214f2d zld: migrate parts of main to new relocs 2021-04-13 10:56:03 +02:00
Jakub Konka
6a866f1a96 zld: preprocess relocs on arm64 2021-04-13 10:56:03 +02:00
Jakub Konka
4e676ecbb5 zld: allocate addresses for global symbols 2021-04-13 10:56:03 +02:00
Jakub Konka
d5c2f8ed32 zld: store a single global symtab 2021-04-13 10:56:03 +02:00
Jakub Konka
1b5bceec91 zld: start work on reloc preprocessing 2021-04-13 10:56:03 +02:00
Jakub Konka
04659f5b82 zld: allocate segments based on worst-case and upper-limit 2021-04-13 10:56:03 +02:00
Jakub Konka
116ea1bf2c zld: assume remaining undefs are from libSystem 2021-04-13 10:56:03 +02:00
Jakub Konka
b0105029ca zld: refactor object and archive parsing 2021-04-13 10:56:03 +02:00
Jakub Konka
988b184d03 zld: redo symbol resolution in objects
Store only globals and undefs at the linker level, while all locals
stay scoped to the actual object file they were defined in. This is
fine since the relocations referencing locals will always be resolved
first using the local symbol table before checking for the reference
within the linker's global symbol table.

This also paves the way for proper symbol resolution from within static
and dynamic libraries.
2021-04-13 10:56:03 +02:00
Andrew Kelley
262e09c482 stage1: resolve builtin types and values via std.builtin
rather than via `@import("builtin")`. This helps avoid the need for
`usingnamespace` used in builtin.zig or in std.builtin.
2021-04-12 15:54:28 -07:00
Michael Dusan
cc186dac65 test-stack-traces: enable elf/dwarf platforms 2021-04-12 17:18:56 -04:00
Michael Dusan
28ae498254 dwarf: fix LineNumberProgram check
- on first iteration populate `prev_` fields and do nothing else

closes #8421
2021-04-12 17:18:56 -04:00
Andrew Kelley
c4c7cb252a Merge pull request #8502 from xackus/std-docs
std docs: @This() in generic types
2021-04-12 11:37:00 -07:00
Jakub Konka
d6d27d51ef CI: update brew before installing pkgs 2021-04-12 18:42:51 +02:00
Michael Dusan
0fa1a2cb73 Revert "dwarf: fix LineNumberProgram check"
- needed/needs to go through review process

This reverts commit 746f65f8b3.
2021-04-12 06:55:12 -04:00
Michael Dusan
746f65f8b3 dwarf: fix LineNumberProgram check
- tolerate out-of-order DW_AT_ranges

closes #8421
2021-04-12 06:12:00 -04:00
xackus
ab991cab84 std docs: @This() in generic types 2021-04-12 09:31:45 +02:00
Andrew Kelley
d2d4df4074 Merge pull request #8477 from joachimschmidt557/stage2-arm
stage2 codegen: Set MCValue of register arguments to their stack copies
2021-04-11 19:00:25 -07:00
Andrew Kelley
c5e662d860 Merge pull request #8497 from LemonBoy/some-ppc-fixes
Improve Improve PowerPC support
2021-04-11 18:59:31 -07:00
Michael Dusan
93cf9560b1 Merge remote-tracking branch 'origin/master' into llvm12 2021-04-11 17:40:19 -04:00
xackus
7857ad78db std docs: update var to anytype 2021-04-11 22:59:30 +02:00
LemonBoy
44f8ce690d std: Fix typo in sqrt implementation
The code initializes twice `t` instead of `t1`, leaving the latter
uninitialized. The problem manifested itself by corrupting the LSBs of
the result in unpredictable ways.
2021-04-11 21:27:39 +02:00
LemonBoy
8d94dc625b compiler-rt: Introduce PowerPC-specific f128 helpers
For historical reasons IEEE f128 ops use `kf` instead of `tf` in their
names, there's no functional change.
2021-04-11 21:26:22 +02:00
LemonBoy
9bebdc77d6 std: Fix TLS definitions for 32bit PowerPC targets
Correct some silly errors and add the missing piece to set the thread
pointer (r2).
2021-04-11 21:26:22 +02:00
xackus
89c41f30c3 zig fmt 2021-04-11 20:16:17 +02:00
Andrew Kelley
82a31aac9b Merge pull request #8483 from fengb/powerpc
Improve PowerPC support
2021-04-11 10:12:02 -07:00
LemonBoy
d97981f6fd std: Make a test-case independent of the target endianness 2021-04-11 18:38:04 +02:00
xackus
a5007d819a std.meta: add isError 2021-04-11 16:26:29 +02:00
Michael Dusan
cab1d5c1a3 azure: OnMasterSuccess dependsOn BuildMacOS_arm64 2021-04-11 05:17:18 -04:00
joachimschmidt557
4fe575f47b stage2 ARM: Add fibonacci test 2021-04-11 10:19:36 +02:00
joachimschmidt557
a6ddc12b33 stage2 codegen: Set MCValue of register arguments to their stack copy 2021-04-11 10:19:35 +02:00
Michael Dusan
c676c21824 ci: remove superfluous linefeed from macos arm64 2021-04-11 01:33:17 -04:00
Benjamin Feng
073d8e55c3 Initialize the ppc stack frame correctly 2021-04-10 22:47:22 -05:00
Benjamin Feng
2e85eb2bf8 Rename time32 syscalls to match rest of stdlib 2021-04-10 22:47:22 -05:00
Benjamin Feng
ae3a0ff2d1 _start assembly for ppc 2021-04-10 22:47:22 -05:00
Benjamin Feng
b409accc96 Copy over ppc clone from musl 2021-04-10 22:47:22 -05:00
Benjamin Feng
df910b33f4 Add ppc Linux bits 2021-04-10 22:47:22 -05:00
Michael Dusan
d99dc21b9f test: overhaul stack_trace testing
- limit expected-output to main source file;
  ie. tolerate changes to start.zig
- when mode != .Debug the function name is now symbolically represented;
  ie. tolerate changes in llvm optimizer effects on the callstack
- cleanup how test cases are specified
- add test case predicates for excluding by arch, os or custom fn
2021-04-10 23:20:06 -04:00
Michael Dusan
75f86dab3f macos: add aarch64 (arm64) to downloads page 2021-04-10 19:33:17 -07:00
Isaac Freund
5b9ea5dd1e zig fmt: fix line comment detection
Previously hasComment() would consider a string literal "//" to be a
line comment. Fix this by only searching the bytes between tokens.
2021-04-10 23:10:24 +02:00
Carlos Zúñiga
ecd38c70cc Fix langref.html anchor navigation 2021-04-10 12:51:39 -07:00
Meghan Denny
ab43f2376e lib/std: remove empty init from HashMapUnmanaged 2021-04-10 12:49:02 -07:00
Lewis Gaul
ecf555c693 zig fmt: render array init on one line if no trailing comma
Continue to insert a trailing comma if there is a comment or multiline
string literal present.
2021-04-10 16:39:26 +02:00
Andrew Kelley
86b31394c9 Merge pull request #8482 from mshockwave/dev-llvm-newpm
Switch to new LLVM PassManager
2021-04-09 17:21:06 -07:00
Min-Yih Hsu
52d871844c llvm new-pm: Build O0 pipeline in the correct way
Use `PassBuilder::buildO0DefaultPipeline` to build pipeline for -O0
in replacement of `PassBuilder::buildPerModuleDefaultPipeline`. This
affects both normal and LTO settings.

Two redundant Passes - which were added by accident - were also removed
from LTO pipeline.
2021-04-09 16:51:35 -07:00
Min-Yih Hsu
6b3eaa62e8 Revert "Revert back to the old LLVM PassManager"
This reverts commit 09008125e7.
2021-04-09 16:51:35 -07:00
jacob gw
0d92bd474f stage2: fix case where public variables did not work 2021-04-09 11:54:38 -07:00
Andrew Kelley
b3f5d4dc4c stage2: fix regression from previous commit
I forgot to build, sorry about that.
2021-04-09 10:38:44 -07:00
Andrew Kelley
7c4c5495be stage2: fix stderr deadlock and slightly wrong tty coloring 2021-04-09 10:34:10 -07:00
Andrew Kelley
f75cdd1acd Merge pull request #8470 from ziglang/stage2-start
stage2: blaze the trail for std lib integration
2021-04-09 10:15:46 -07:00
Andrew Kelley
952032b40c Merge pull request #8439 from Luukdegram/wasm-mem
stage2: wasm - "Hello world"
2021-04-09 10:08:21 -07:00
jacob gw
afe5862111 stage2: add error for private decls accessed from other files 2021-04-09 10:05:15 -07:00
LemonBoy
bfc8500390 testing: Avoid @import-ing builtins module
Use std.builtins instead.
2021-04-09 10:04:16 -07:00
LemonBoy
b0e905a30d testing: Avoid printing expected line twice
When the line has trailing whitespace we already print it with a
carriage return symbol at the end, don't print it one more time.
2021-04-09 10:04:16 -07:00
LemonBoy
1943c2dc68 testing: Use indexOfScalar instead of indexOf 2021-04-09 10:04:16 -07:00
LemonBoy
5ebcd8ccaf zig fmt: Fix rendering of arrays with single row
rowSize used to return null if all the elements were placed on the same
line as the right brace, making the rendering logic skip the whole set
of elements.

Given the usage of rowSize let's just drop the null and always return
the number of elements.

Fixes #8423
2021-04-09 10:03:45 -07:00
Luuk de Gram
eaaf75c157 Fix memory cleanup and update unplugging to avoid infinite loop 2021-04-09 09:24:52 +02:00
Andrew Kelley
cc525bc002 Merge pretty printing compile errors branch 2021-04-09 00:20:26 -07:00
Andrew Kelley
9a2de796bd stage2: clean up pretty printing compile errors 2021-04-09 00:19:44 -07:00
jacob gw
0f105ea324 stage2: fix bug where a parser error would break errors
A parser error would deinit the tree, but the tree is needed for the
node locations. This removes the offending code written before node
locations.
2021-04-08 23:17:36 -07:00
jacob gw
99ec511c4c stage2: pretty print compilation errors 2021-04-08 23:17:36 -07:00
g-w1
c6791d87d4 stage2: delete allowing input (and output) zir from the pipeline (#8471)
Remove -femit-zir as we aren't going to need it. Also remove zir test code
This removes a TODO that asserts the file is not zir.
2021-04-09 02:11:33 -04:00
Andrew Kelley
23db96931e AstGen: implement @typeInfo builtin 2021-04-08 22:38:13 -07:00
Andrew Kelley
6e05d53e88 AstGen: implement struct init with ResultLoc.ty 2021-04-08 22:33:40 -07:00
Sreehari S
906ac7b2f9 fix unannotated fall-through bug in case 2021-04-08 22:26:35 -07:00
Andrew Kelley
91e1414b50 stage2: implement array access to a global array 2021-04-08 21:56:42 -07:00
Andrew Kelley
6d616d8257 update stack trace test cases to new start.zig line offsets 2021-04-08 21:56:19 -07:00
Sreehari S
9ebdbca379 callconv: add SysV 2021-04-08 21:00:53 -07:00
Andrew Kelley
1b702f8ddb stage2: fix the memory leaks 2021-04-08 20:52:02 -07:00
Andrew Kelley
61b868f9a5 stage2: simplify Decl src_node field
Also fix "previous definition here" error notes to be correct.
2021-04-08 20:37:19 -07:00
Andrew Kelley
482b995a49 stage2: blaze the trail for std lib integration
This branch adds "builtin" and "std" to the import table when using the
self-hosted backend.

"builtin" gains one additional item:

```
pub const zig_is_stage2 = true; // false when using stage1 backend
```

This allows the std lib to do conditional compilation based on detecting
which backend is being used. This will be removed from builtin as soon
as self-hosted catches up to feature parity with stage1.
Keep a sharp eye out - people are going to be tempted to abuse this.
The general rule of thumb is do not use `builtin.zig_is_stage2`. However
this commit breaks the rule so that we can gain limited start.zig support
as we incrementally improve the self-hosted compiler.

This commit also implements `fullyQualifiedNameHash` and related
functionality, which effectively puts all Decls in their proper
namespaces. `fullyQualifiedName` is not yet implemented.

Stop printing "todo" log messages for test decls unless we are in test
mode.

Add "previous definition here" error notes for Decl name collisions.

This commit does not bring us yet to a newly passing test case.

Here's what I'm working towards:

```zig
const std = @import("std");

export fn main() c_int {
    const a = std.fs.base64_alphabet[0];
    return a - 'A';
}
```

Current output:

```
$ ./zig-cache/bin/zig build-exe test.zig
test.zig:3:1: error: TODO implement more analyze elemptr
zig-cache/lib/zig/std/start.zig:38:46: error: TODO implement structInitExpr ty
```

So the next steps are clear:
 * Sema: improve elemptr
 * AstGen: implement structInitExpr
2021-04-08 19:05:05 -07:00
xackus
c28d1fe173 std docs: fix layout broken by the banner 2021-04-09 00:36:59 +02:00
Luuk de Gram
ff5774d93d Refactor link/wasm.zig to use offset table
This refactor inserts an offset table into wasm's data section
where each offset points to the actual data region.
This means we can keep offset indexes consistant and do not
have to perform any computer to determine where in the data section
something like a static string exists. Instead during runtime
it will load the data offset onto the stack.
2021-04-08 22:47:08 +02:00
Luuk de Gram
47f3642788 Cleanup 2021-04-08 22:47:08 +02:00
Luuk de Gram
9fd1dab582 Handle incremental compilation correctly 2021-04-08 22:47:08 +02:00
Luuk de Gram
1bd5552fc1 Calculate data length to ensure correct pointer offsets 2021-04-08 22:47:08 +02:00
Luuk de Gram
00b2e31589 Basic "Hello world" working 2021-04-08 22:47:08 +02:00
Andrew Kelley
9f744f19e7 Merge pull request #8464 from gracefuu/grace/wasm-ops
stage2 wasm: Add division and bitwise/boolean ops &, |, ^, and, or
2021-04-08 13:41:49 -07:00
joachimschmidt557
d7a89f9876 stage2 AArch64: Add conditional branch instructions 2021-04-08 13:39:11 -07:00
Michael Dusan
000c0845b1 freebsd: disable failing stack traces test cases due to LLVM12 changes 2021-04-08 14:48:27 -04:00
Andrew Kelley
b9e508c410 stage2: revert to only has_decl and export ZIR support
Reverting most of the code from the previous commits in this branch.
Will pull in the code with modifications bit by bit.
2021-04-08 11:29:31 -07:00
Timon Kruiper
a483e38df6 stage2: fix bug where invalid ZIR was generated
The following code caused an assertion to be hit:
```
pub fn main() void {
    var e: anyerror!c_int = error.Foo;
    const i = e catch 69;
    assert(69 - i == 0);
}
```
2021-04-08 14:23:18 +02:00
Timon Kruiper
ac14b52e85 stage2: add support for start.zig
This adds a simplified start2.zig that the current stage2 compiler is
able to generate code for.
2021-04-08 14:23:18 +02:00
Timon Kruiper
e85cd616ef stage2: implement builtin function hasDecl 2021-04-08 14:23:18 +02:00
Timon Kruiper
a97efbd185 stage2: add support for root pkg
Fix some infinite recursions, because the code assumed that packages
cannot point to each other. But this assumption does not hold anymore.
2021-04-08 14:23:18 +02:00
Timon Kruiper
fb16cb9183 stage2: add initial support for builtin pkg
We currently emit a simplified builtin2.zig that is able to be parsed
and correctly interpreted in stage2.
2021-04-08 14:23:17 +02:00
Timon Kruiper
91e416bbf0 stage2: add a simplified export builtin call
std.builtin.ExportOptions is not yet supported, thus the second argument
of export is now a simple string that specifies the exported symbol
name.
2021-04-08 14:22:56 +02:00
Timon Kruiper
272fe0cbfe stage2: fix bug in ZIR gen of global comptime block
A global comptime block did not end with a break_inline instruction
which caused an assertion to be hit.
2021-04-08 14:20:40 +02:00
Andrew Kelley
ab5a445d25 Merge pull request #8459 from joachimschmidt557/stage2-regalloc
Stage2 Register Manager: add getReg function
2021-04-08 00:01:46 -07:00
xackus
2d2316f5c0 translate-c: fix meta.cast to ?*c_void 2021-04-08 08:33:26 +03:00
Andrew Kelley
d4f61f9842 Merge pull request #8449 from ziglang/stage2-enums
stage2: implement simple enums
2021-04-07 22:29:28 -07:00
Andrew Kelley
7595915775 stage2: add remaining enum compile error test cases 2021-04-07 22:24:52 -07:00
Andrew Kelley
57aa289fde Sema: fix switch validation '_' prong on wrong type 2021-04-07 22:19:17 -07:00
Andrew Kelley
e730172e47 stage2: fix switch validation of handling all enum values
There were several problems, all fixed:
 * AstGen was storing field names as references to the original
   source code bytes. However, that data would be destroyed when the
   source file is updated. Now, it correctly stores the field names in
   the Decl arena for the enum. The same fix applies to error set field
   names.
 * Sema was missing a memset inside `analyzeSwitch`, leaving the "seen
   enum fields" array with undefined memory. Now that they are all
   properly set to null, the validation works.
 * Moved the "enum declared here" note to the end. It looked weird
   interrupting the notes for which enum values were missing.
2021-04-07 22:02:45 -07:00
Andrew Kelley
b67378fb08 Sema: @intToEnum error msg includes a "declared here" hint 2021-04-07 21:04:55 -07:00
Andrew Kelley
a62e19ec8e AstGen: fix incorrect source loc for duplicate enum tag 2021-04-07 20:50:57 -07:00
Andrew Kelley
12087d4cba stage2: fix incremental compilation handling of parse errors
Before, incremental compilation would crash when trying to emit compile
errors for the update after introducing a parse error.

Parse errors are handled by not invalidating any existing semantic
analysis. However, only the parse error must be reported, with all the
other errors suppressed. Once the parse error is fixed, the new file can
be treated as an update to the previously-succeeded update.
2021-04-07 20:36:01 -07:00
Andrew Kelley
4996c2b6a9 stage2: fix incremental compilation Decl deletion logic
* `analyzeContainer` now has an `outdated_decls` set as well as
   `deleted_decls`. Instead of queuing up outdated Decls for re-analysis
   right away, they are added to this new set. When processing the
   `deleted_decls` set, we remove deleted Decls from the
   `outdated_decls` set, to avoid deleted Decl pointers from being in
   the work_queue. Only after processing the deleted decls do we add
   analyze_decl work items to the queue.

 * Module.deletion_set is now an `AutoArrayHashMap` rather than `ArrayList`.
   `declareDeclDependency` will now remove a Decl from it as appropriate.
   When processing the `deletion_set` in `Compilation.performAllTheWork`,
   it now assumes all Decl in the set are to be deleted.

 * Fix crash when handling parse errors. Currently we unload the
   `ast.Tree` if any parse errors occur. Previously the code emitted a
   LazySrcLoc pointing to a token index, but then when we try to resolve
   the token index to a byte offset to create a compile error message,
   the  ast.Tree` would be unloaded. Now we use
   `LazySrcLoc.byte_abs` instead of `token_abs` so the error message can
   be created even with the `ast.Tree` unloaded.

Together, these changes solve a crash that happened with incremental
compilation when Decls were added and removed in some combinations.
2021-04-07 19:54:28 -07:00
Andrew Kelley
8f28e26e7a Sema: implement switch validation for enums 2021-04-07 16:39:10 -07:00
Michael Dusan
341dc03b63 netbsd: minor fixes to allow stage1 to build 2021-04-07 16:26:21 -07:00
Andrew Kelley
ccdba774c8 AstGen: fix ZIR struct encoding
off by one error in the bits that describe defaults/field alignments
as soon as we have tests for struct field alignment and default values,
there will be coverage for this.
2021-04-07 15:02:46 -07:00
gracefu
6dc35efe49 Sema: fix typo bug for boolean ops (and, or) 2021-04-08 05:27:00 +08:00
gracefu
e4a60b63f2 stage2 wasm: Add bitwise/boolean ops &, |, ^, and, or 2021-04-08 05:27:00 +08:00
gracefu
4c71942f84 stage2: Add .div to ir.zig 2021-04-08 05:26:56 +08:00
Andrew Kelley
015599d1ef C backend: enumerate all the types in renderType
Now that we're close to supporting all the types, get rid of the `else`
prong and explicitly list out those types that are not yet implemented.

Thanks @g-w1
2021-04-07 13:17:23 -07:00
Andrew Kelley
090834380c Type: use isPtrLikeOptional instead of isAbiPtr
Thanks @Vexu
2021-04-07 13:06:21 -07:00
Andrew Kelley
e32898b0de AstGen: fix switch expressions with all prongs noreturn 2021-04-07 12:59:50 -07:00
Andrew Kelley
18119aae30 Sema: implement comparison analysis for non-numeric types 2021-04-07 12:15:05 -07:00
Andrew Kelley
d9c25ec672 zir: use node union field for alloc_inferred
Previously we used `un_node` and passed `undefined` for the operand, but
this causes illegal behavior when printing ZIR code.
2021-04-07 11:34:23 -07:00
Andrew Kelley
4e8fb9e6a5 Sema: DRY up enum field analysis and add "declared here" notes 2021-04-07 11:26:07 -07:00
Andrew Kelley
bcc371618f AstGen: fix @breakpoint ZIR
Previously it relied on the breakpoint ZIR instruction being void, but
that's no longer how things work.
2021-04-07 10:24:57 -07:00
joachimschmidt557
4ff5a3cd94 stage2 regalloc: Add unit test for getReg 2021-04-07 15:15:14 +02:00
Michael Dusan
2871d32be7 test: fix std.time timing tests to skip on failure 2021-04-07 08:33:32 -04:00
jacob gw
01a39fa1d4 stage2: coerce enum_literal -> enum 2021-04-07 07:19:11 -04:00
Andrew Kelley
19cf987198 C backend: implement Enum types and values
They are lowered directly as the integer tag type, with no typedef.
2021-04-06 23:19:46 -07:00
Andrew Kelley
acf9151008 stage2: implement field access for Enum.tag syntax 2021-04-06 22:36:28 -07:00
Andrew Kelley
2adeace905 std: modernize zig parser perf test
use the file size formatting functions
2021-04-06 22:34:48 -07:00
Andrew Kelley
f253822415 stage2: do not set clang_passthrough_mode for zig run
Thanks to @g-w1 for discovering this bug.

closes #8450
2021-04-06 19:50:53 -07:00
Andrew Kelley
b40d36c90b stage2: implement simple enums
A simple enum is an enum which has an automatic integer tag type,
all tag values automatically assigned, and no top level declarations.
Such enums are created directly in AstGen and shared by all the
generic/comptime instantiations of the surrounding ZIR code. This
commit implements, but does not yet add any test cases for, simple enums.

A full enum is an enum for which any of the above conditions are not
true. Full enums are created in Sema, and therefore will create a unique
type per generic/comptime instantiation. This commit does not implement
full enums. However the `enum_decl_nonexhaustive` ZIR instruction is
added and the respective Type functions are filled out.

This commit makes an improvement to ZIR code, removing the decls array
and removing the decl_map from AstGen. Instead, decl_ref and
decl_val ZIR instructions index into the `owner_decl.dependencies`
ArrayHashMap. We already need this dependencies array for incremental
compilation purposes, and so repurposing it to also use it for ZIR decl
indexes makes for efficient memory usage.

Similarly, this commit fixes up incorrect memory management by removing
the `const` ZIR instruction. The two places it was used stored memory in
the AstGen arena, which may get freed after Sema. Now it properly sets
up a new anonymous Decl for error sets and uses a normal decl_val
instruction.

The other usage of `const` ZIR instruction was float literals. These are
now changed to use `float` ZIR instruction when the value fits inside
`zir.Inst.Data` and `float128` otherwise.

AstGen + Sema: implement int_to_enum and enum_to_int. No tests yet; I expect to
have to make some fixes before they will pass tests. Will do that in the
branch before merging.

AstGen: fix struct astgen incorrectly counting decls as fields.

Type/Value: give up on trying to exhaustively list every tag all the
time. This makes the file more manageable. Also found a bug with
i128/u128 this way, since the name of the function was more obvious when
looking at the tag values.

Type: implement abiAlignment and abiSize for structs. This will need to
get more sophisticated at some point, but for now it is progress.

Value: add new `enum_field_index` tag.
Value: add hash_u32, needed when using ArrayHashMap.
2021-04-06 18:17:37 -07:00
joachimschmidt557
ac2211118f stage2 regalloc: Add getReg and getRegWithoutTracking 2021-04-06 21:14:00 +02:00
Andrew Kelley
ec212c82be Merge pull request #8416 from gracefuu/grace/wasm-ops
stage2 wasm codegen: refactor Opcode, add `sub` and `mul` operators
2021-04-06 11:48:40 -07:00
Evan Haas
8de14a98a6 translate-c: Add support for vector expressions
Includes vector types, __builtin_shufflevector, and __builtin_convertvector
2021-04-06 11:22:27 -07:00
Michael Holmes
38d8aab4d2 std/build: fix ?[:0]const u8 build options
As per the other string types, `?[:0]const u8` needs its own case
as otherwise it will raise an error about using `{}` with slices.

There's no reasonable workaround for this, as you would have to
either discount the use of the empty string value or manually
rework the string to be sentinel-terminated at runtime. It's
useful for passing build options to code making use of C libraries
that make strong use of sentinel-terminated arrays for strings.
2021-04-06 11:09:54 -07:00
LemonBoy
10c2b36444 stage1: Work around a small problem in LLVM API
The missing initializer for a single field in the TargetOptions class
was enough to turn the stack protectors into hot garbage.

Fixes #8408
2021-04-06 11:02:18 -07:00
LemonBoy
89df41e5d8 stage2: Default AVR generic cpu to avr2
The avr1 target is a very minimal subset of the AVR ISA, quoting the GCC
manual:

> This ISA is implemented by the minimal AVR core and supported for
> assembler only.

Default to avr2 as GCC and Clang do.
2021-04-06 10:18:11 -07:00
lithdew
2bfc6d14d5 os/linux: return error on EALREADY for connect() and getsockoptError()
When a connected socket file descriptor on Linux is re-acquired
    after being closed, through fuzz testing, it appears that a
    subsequent attempt to establish a connection with the file
    descriptor causes EALREADY to be reported.

    Instead of panicking, choose to return error.ConnectionPending
    to allow for users to handle this fairly rare case.
2021-04-06 11:30:20 +02:00
gracefu
ec84742c89 stage2 wasm codegen: refactor to use wasm.buildOpcode 2021-04-05 16:19:52 +08:00
gracefu
3648e43dda std/wasm: add buildOpcode to help construction of Opcodes 2021-04-05 14:44:00 +08:00
gracefu
869fc06c57 stage2 wasm: codegen mul op 2021-04-05 14:37:04 +08:00
gracefu
d1244d3608 stage2 wasm: codegen sub op 2021-04-05 14:37:04 +08:00
Edward Dean
83a2665772 Fixed error types for GetSeekPosError 2021-04-04 17:04:46 -07:00
Lewis Gaul
7302b096bd Tidy-up in json test module (#8431)
* Switch json testing 'roundTrip()' to use FixedBufferStream, improve error handling, remove comptime from param

* Add 'try' to calls to roundTrip() that can now return an error

* Remove comptime from params in json testing, replace expect(false) with letting error propagate

* Add 'try' to calls to ok() that can now return an error

Co-authored-by: Lewis Gaul <legaul@cisco.com>
2021-04-04 19:27:47 -04:00
Hannu Hartikainen
c9ffb6f734 std docs: enhance search browser history UX
Before this change every keypress in the search field causes a browser
history entry, which makes navigating back annoying.

On first keypress in the search field, a new history entry is created.
On subsequent keypresses, the most recent history entry is replaced.
Therefore a typical history after searching and navigating to an entry
might look like

1. documentation root
2. search page "print"
3. docs for `std.debug.print`


Co-authored-by: Žiga Željko <ziga.zeljko@gmail.com>
2021-04-04 16:25:47 -07:00
Andrew Kelley
545830c0ff LLVM sub-arch triple: remove TODO comment
See #6542 for more details. Upon investigation, this change is not
needed.
2021-04-04 16:10:54 -07:00
Andrew Kelley
0fee4b55a8 glibc: update ABI files to 2.33 2021-04-04 12:04:02 -07:00
Andrew Kelley
0e2da11379 glibc: update headers to 2.33
This introduces csky support.
2021-04-04 12:04:02 -07:00
Andrew Kelley
4d729ebc87 glibc: update ABI files to 2.33 2021-04-04 11:57:41 -07:00
Andrew Kelley
4d4bb69d7b glibc: update headers to 2.33
This introduces csky support.
2021-04-04 11:54:47 -07:00
Andrew Kelley
b25476bf12 glibc: add support for csky architecture 2021-04-04 11:52:40 -07:00
Vincent Rischmann
5ce4524027 os/bits/linux: add IPv6 socket options 2021-04-04 20:43:41 +03:00
xackus
e4563860fe translate-c: fix calls with no args in macros 2021-04-04 20:43:13 +03:00
Lewis Gaul
74fd7107e8 Switch std.json to use an ordered hashmap 2021-04-04 10:16:59 +02:00
Frank Denis
6fc822a948 Merge pull request #8410 from antlilja/remove-undefined-math
Make sqrt and log functions undefined for signed integer types
2021-04-03 19:27:37 +02:00
antlilja
d4dc2eb807 Compile error for signed integer math
Output compile errors when signed integer types are used on functions
where the answer might've been a complex number but that functionality hasn't
been implemented.

This applies to sqrt, log, log2, log10 and ln.

A test which used a signed integer was also changed to use an unsigned
integer instead.
2021-04-03 13:09:20 +02:00
Andrew Kelley
2f07d76eee stage2: implement Type.onePossibleValue for structs 2021-04-02 21:17:23 -07:00
Andrew Kelley
d47f0abd5b stage2: Sema: implement validate_struct_init_ptr 2021-04-02 21:06:09 -07:00
Andrew Kelley
97d7fddfb7 stage2: progress towards basic structs
Introduce `ResultLoc.none_or_ref` which is used by field access
expressions to avoid unnecessary loads when the field access itself
will do the load. This turns:

```zig
p.y - p.x - p.x
```

from

```zir
  %14 = load(%4) node_offset:8:12
  %15 = field_val(%14, "y") node_offset:8:13
  %16 = load(%4) node_offset:8:18
  %17 = field_val(%16, "x") node_offset:8:19
  %18 = sub(%15, %17) node_offset:8:16
  %19 = load(%4) node_offset:8:24
  %20 = field_val(%19, "x") node_offset:8:25
```

to

```zir
  %14 = field_val(%4, "y") node_offset:8:13
  %15 = field_val(%4, "x") node_offset:8:19
  %16 = sub(%14, %15) node_offset:8:16
  %17 = field_val(%4, "x") node_offset:8:25
```

Much more compact. This requires `Sema.zirFieldVal` to support both
pointers and non-pointers.

C backend: Implement typedefs for struct types, as well as the following
TZIR instructions:
 * mul
 * mulwrap
 * addwrap
 * subwrap
 * ref
 * struct_field_ptr

Note that add, addwrap, sub, subwrap, mul, mulwrap instructions are all
incorrect currently and need to be updated to properly handle wrapping
and non wrapping for signed and unsigned.

C backend: change indentation delta to 1, to make the output smaller and
to process fewer bytes.

I promise I will add a test case as soon as I fix those warnings that
are being printed for my test case.
2021-04-02 19:11:51 -07:00
Andrew Kelley
4bab90512d disable failing stack traces test cases due to LLVM12 changes 2021-04-02 16:33:38 -07:00
Andrew Kelley
e2a7c01331 disable failing MIPS tests due to LLVM12 regressions
See #8155
2021-04-02 16:33:07 -07:00
joachimschmidt557
43d364afef stage2 AArch64: Add ldrh and ldrb instructions 2021-04-02 14:46:30 -07:00
Andrew Kelley
09008125e7 Revert back to the old LLVM PassManager
See #8418

This reverts commit ba1bea2fe8.
This reverts commit 94383d14df.
This reverts commit 0d53a2bff0.
2021-04-02 14:35:45 -07:00
Andrew Kelley
12e2523730 docgen: correct the progress bar
It wasn't showing progress for non-code nodes.
2021-04-02 13:57:16 -07:00
Andrew Kelley
ba1bea2fe8 zig_llvm.cpp: remove dead code 2021-04-02 12:10:39 -07:00
Andrew Kelley
a0e89c9b46 Merge remote-tracking branch 'origin/master' into llvm12 2021-04-02 12:09:38 -07:00
Min-Yih Hsu
94383d14df llvm new-pm: Add missing pipeline option and Passes
- Enable MergeFunctionsPass in non-debug build.
 - Verify input and output IR when the assertion is turned on.
 - Add AlwaysInlinePass in debug build.
 - Add more comments.
2021-04-02 12:04:49 -07:00
Min-Yih Hsu
0d53a2bff0 llvm new-pm: Port LLVM 11.x-based changes to LLVM 12.x
Now zig will use new PM for optimization by default.
2021-04-02 12:04:49 -07:00
joachimschmidt557
228a1ce3e8 stage2 register_manager: Add unit tests for tryAllocReg and allocReg 2021-04-02 12:01:52 -07:00
joachimschmidt557
4efbcad26d stage2 codegen: Extract register management code into separate file 2021-04-02 12:01:52 -07:00
Andrew Kelley
fc9c1b4e4a Merge pull request #8028 from mguaypaq/nosuspend-allow
stage1: allow async and resume inside nosuspend blocks
2021-04-02 11:59:34 -07:00
Mathieu Guay-Paquet
f270bef9a4 docs: document the nosuspend keyword (#7972)
* docs: document the nosuspend keyword

* Specify that resuming from suspend is allowed in nosuspend

* Fix the description of the requirements of nosuspend

* Make use of nosuspend in some example code.

This is mainly motivated by the incorrect claim that "there would be
no way to collect the return value of amain, if it were something
other than void".
2021-04-02 14:57:42 -04:00
Loris Cro
354c14d6a2 make visited links readable in the stdlib docs warning bar 2021-04-02 20:22:02 +02:00
Loris Cro
4fef1d2982 added warning banner to stdlib docs 2021-04-02 20:13:55 +02:00
Andrew Kelley
d780848ae4 Merge pull request #7792 from zanderxyz/zanderxyz/priority-dequeue
std: Add Priority Dequeue
2021-04-02 10:52:23 -07:00
Woze Parrot
833f258297 put async frame in correct addrspace 2021-04-02 10:39:56 -07:00
Frank Denis
45db0e93a9 Merge pull request #8412 from g-w1/fix-docgen-test-release
docgen: fix typo
2021-04-02 18:40:55 +02:00
jacob gw
cdc5921073 docgen: fix typo
zig test test.zig-OReleaseFast -> zig test test.zig -OReleaseFast
2021-04-02 12:08:52 -04:00
Michael Dusan
cc435dab2f test: fix io_uring timing test to skip on failure 2021-04-02 07:12:09 -04:00
Andrew Kelley
8ebfdc14f6 stage2: implement structs in the frontend
New ZIR instructions:
 * struct_decl_packed
 * struct_decl_extern

New TZIR instruction: struct_field_ptr

Introduce `Module.Struct`. It uses `Value` to store default values and
abi alignments.

Implemented Sema.analyzeStructFieldPtr and zirStructDecl.

Some stuff I changed from `@panic("TODO")` to `log.warn("TODO")`.
It's becoming more clear that we need the lazy value mechanism soon;
Type is becoming unruly, and some of these functions have too much logic
given that they don't have any context for memory management or error
reporting.
2021-04-01 22:39:09 -07:00
Andrew Kelley
c66b48194f stage2: AstGen and ZIR printing for struct decls 2021-04-01 19:27:17 -07:00
Andrew Kelley
09000c3f77 zig cc: copy .pdb files from zig-cache/ when appropriate
closes #8407
2021-04-01 16:33:29 -07:00
Andrew Kelley
50bcfb8c90 stage2: implement struct init syntax with ptr result loc 2021-04-01 11:58:55 -07:00
lithdew
59035ae3e9 os: handle ECONNRESET for connect() syscall 2021-04-01 14:18:49 +02:00
Andrew Kelley
070a28e493 Merge pull request #8266 from ziglang/zir-memory-layout
rework ZIR memory layout; overhaul source locations
2021-03-31 23:11:15 -07:00
Andrew Kelley
c9e31febf8 stage2: finish implementation of LazySrcLoc 2021-03-31 23:00:00 -07:00
Andrew Kelley
b27d052676 stage2: finish source location reworkings in the branch
* remove the LazySrcLoc.todo tag
 * finish updating Sema and AstGen, remove the last of the
   `@panic("TODO")`.
2021-03-31 21:36:32 -07:00
Andrew Kelley
e8143f6cbe stage2: compile error for duplicate switch value on sparse 2021-03-31 18:39:34 -07:00
Andrew Kelley
cec766f73c stage2: compile error for duplicate switch value on boolean 2021-03-31 18:30:23 -07:00
jacob gw
fedc9ebd26 stage2: cbe: restore all previously passing tests! 2021-03-31 18:09:45 -07:00
Andrew Kelley
3cebaaad1c astgen: improved handling of coercion
GenZir struct now has rl_ty_inst field which tracks the result location
type (if any) a block expects all of its results to be coerced to.

Remove a redundant coercion on const local initialization with a
specified type.

Switch expressions, during elision of store_to_block_ptr instructions,
now re-purpose them to be type coercion when the block has a type in the
result location.
2021-03-31 18:05:37 -07:00
Andrew Kelley
08eedc962d Sema: fix else case code generation for switch 2021-03-31 16:17:47 -07:00
Andrew Kelley
abd06d8eab stage2: clean up RangeSet and fix swapped Sema switch logic for lhs/rhs 2021-03-31 15:39:04 -07:00
Andrew Kelley
e272c29c16 Sema: implement switch validation for ranges 2021-03-31 15:06:03 -07:00
joachimschmidt557
1b657e6e41 stage2 codegen: Make sure function return value is in a callee
preserved register
2021-03-31 23:27:50 +02:00
joachimschmidt557
e088a17f56 stage2 AArch64: implement strb and strh 2021-03-31 23:26:49 +02:00
Andrew Kelley
c7b09be8de AstGen: improve switch expressions
* use the proper result location strategy even when there are noreturn
   prongs in the switch expression
 * when using break_operand strategy, actually omit the
   store_to_block_ptr instructions rather than eliding them.
 * for both strategies, properly handle noreturn prongs.
2021-03-31 12:37:20 -07:00
Andrew Kelley
549af582e7 AstGen: switch expressions properly handle result locations 2021-03-30 23:57:22 -07:00
Andrew Kelley
2a1dd174cd stage2: rework AstGen for switch expressions
The switch_br ZIR instructions are now switch_block instructions. This
avoids a pointless block always surrounding a switchbr in emitted ZIR
code.

Introduce typeof_elem ZIR instruction for getting the type of the
element of a pointer value in 1 instruction.

Change typeof to be un_node, not un_tok.

Introduce switch_capture ZIR instructions for obtaining the capture
value of switch prongs.

Introduce Sema.resolveBody for when you want to extract a *Inst out of a
block and you know that there is only going to be 1 break from it.

What's not working yet: AstGen does not correctly elide
store instructions when it turns out that the result location does not
need to be used as a pointer.

Also Sema validation code for duplicate switch items is not yet
implemented.
2021-03-30 21:28:36 -07:00
Andrew Kelley
195ddab2be Sema: implement switch expressions
The logic for putting ranges into the else prong is moved from AstGen to
Sema. However, logic to emit multi-items the same as single-items cannot
be done until TZIR supports mapping multiple items to the same block of
code. This will be simple to represent when we do the upcoming TZIR memory
layout changes.

Not yet implemented in this commit is the validation of duplicate
values. The trick is going to be emitting error messages with accurate
source locations, without adding extra source nodes to the ZIR
switch instruction.

This will be done by computing the respective AST node based on the
switch node (which we do have available), only when a compile error
occurs and we need to know the source location to attach the message to.
2021-03-29 21:59:08 -07:00
Matthew Borkowski
501b4aff99 Add tests for the fill functions of the Isaac64, Pcg, Sfc64, and Xoroshiro128 PRNGs 2021-03-29 09:22:06 +02:00
Matthew Borkowski
a5cc5f7854 Fix typo in Pcg.zig's fill function
When filling the last (len % 4) bytes of a buffer, the random number n was only being shifted right by 4 bits for each byte instead of 8. A random u16, for example, would always have its middle two nybbles be equal when generated this way. For comparison, Isaac64.zig, Sfc64.zig, and Xoroshiro128.zig all correctly shift right by 8 bits for each of the last bytes in their nearly identical fill functions.
2021-03-29 09:22:06 +02:00
Andrew Kelley
623d5f442c stage2: guidance on how to implement switch expressions
Here's what I think the ZIR should be. AstGen is not yet implemented to
match this, and the main implementation of analyzeSwitch in Sema is not
yet implemented to match it either.

Here are some example byte size reductions from master branch, with the
ZIR memory layout from this commit:

```
switch (foo) {
  a => 1,
  b => 2,
  c => 3,
  d => 4,
}
```

184 bytes (master) => 40 bytes (this branch)

```
switch (foo) {
  a, b => 1,
  c..d, e, f => 2,
  g => 3,
  else => 4,
}
```

240 bytes (master) => 80 bytes (this branch)
2021-03-28 23:12:26 -07:00
Andrew Kelley
b85ef2300f Merge remote-tracking branch 'origin/master' into llvm12 2021-03-28 21:42:56 -07:00
Andrew Kelley
281a7baaea Merge remote-tracking branch 'origin/master' into zir-memory-layout
Wanted to make sure those new test cases still pass.

Also grab that CI fix so we can get those green check marks.
2021-03-28 19:42:43 -07:00
Andrew Kelley
8f469c1127 stage2: fix error sets 2021-03-28 19:40:21 -07:00
jacob gw
0005b34637 stage2: implement sema for @errorToInt and @intToError 2021-03-28 18:22:01 -07:00
Andrew Kelley
175adc0bd7 ci: update msys2 installer 2021-03-28 17:49:28 -07:00
Andrew Kelley
bb5cfbcb72 Merge pull request #8305 from jedisct1/base64
std/base64: cleanups & support url-safe and other non-padded variants
2021-03-28 17:11:07 -07:00
Isaac Freund
f80f8a7a78 AstGen: pass *GenZir as the first arg, not *Module
This avoids the unnecessary scope.getGenZir() virtual call for both
convenience and performance.
2021-03-28 22:42:17 +02:00
Isaac Freund
d5d88087dd translate-c: fix typo made in prior commit 2021-03-28 22:29:37 +02:00
Isaac Freund
d123a5ec67 AstGen: scope result location related functions 2021-03-28 19:53:38 +02:00
Isaac Freund
402f87a213 stage2: rename WipZirCode => AstGen, astgen.zig => AstGen.zig 2021-03-28 19:10:10 +02:00
Jonathan Knezek
bbe6a0dddd Add a test & fix for std.fmt.fmtDuration 2021-03-28 15:44:15 +02:00
Frank Denis
6993087edc Remove the base64 unsafe decoder 2021-03-28 14:32:34 +02:00
Frank Denis
99bed37fc7 Add more variants 2021-03-28 14:32:34 +02:00
Frank Denis
b8c019ef49 std/base64: cleanups & support url-safe and other non-padded variants
This makes a few changes to the base64 codecs.

* The padding character is optional. The common "URL-safe" variant, in
particular, is generally not used with padding. This is also the case for
password hashes, so having this will avoid code duplication with bcrypt,
scrypt and other functions.
* The URL-safe variant is added. Instead of having individual constants
for each parameter of each variant, we are now grouping these in a
struct. So, `standard_pad_char` just becomes `standard.pad_char`.
* Types are not `snake_case`'d any more. So, `standard_encoder` becomes
`standard.Encoder`, as it is a type.
* Creating a decoder with ignored characters required the alphabet and
padding. Now, `standard.decoderWithIgnore(<ignored chars>)` returns a
decoder with the standard parameters and the set of ignored chars.
* Whatever applies to `standard.*` obviously also works with `url_safe.*`
* the `calcSize()` interface was inconsistent, taking a length in the
encoder, and a slice in the encoder. Rename the variant that takes a
slice to `calcSizeForSlice()`.
* In the decoder with ignored characters, add `calcSizeUpperBound()`,
which is more useful than the one that takes a slice in order to size
a fixed buffer before we have the data.
* Return `error.InvalidCharacter` when the input actually contains
characters that are neither padding nor part of the alphabet. If we
hit a padding issue (which includes extra bits at the end),
consistently return `error.InvalidPadding`.
* Don't keep the `char_in_alphabet` array permanently in a decoder;
it is only required for sanity checks during initialization.
* Tests are unchanged, but now cover both the standard (padded) and
the url-safe (non-padded) variants.
* Add an error set, rename `OutputTooSmallError` to `NoSpaceLeft`
to match the `hex2bin` equivalent.
2021-03-28 14:32:34 +02:00
Evan Haas
ab9324e604 translate-c: intcast compound assignment operand if different-sized integer
Use transCCast to cast the RHS of compound assignment if necessary.
2021-03-28 15:21:12 +03:00
lithdew
c8d721aa42 array_hash_map: decrement entries slice len after popping from entries in pop() to prevent oob 2021-03-28 11:02:37 +02:00
Jakub Konka
54b42a7596 azure: run pacman with -Sy 2021-03-28 11:01:57 +02:00
Andrew Kelley
68f4eb0f67 stage2: fully implement Type.eql for pointers
Also fixed abiAlignment - for pointers it was returning the abi
alignment inside the type, rather than of the pointer itself. There is
now `ptrAlignment` for getting the alignment inside the type of
pointers.
2021-03-27 23:55:19 -07:00
LemonBoy
75080e351a std: Detect AMD Zen3 CPU family
Easy peasy lemon squeezy.
2021-03-27 12:23:40 -07:00
Andrew Kelley
95cc457d97 stage2: enable passing tests 2021-03-26 23:54:36 -07:00
Andrew Kelley
1f5617ac07 stage2: implement bitwise expr and error literals 2021-03-26 23:46:37 -07:00
Andrew Kelley
da731e18c9 stage2: implement source location: .node_offset_var_decl_ty 2021-03-26 18:35:15 -07:00
Andrew Kelley
a72bfd00cf astgen: fix continue expressions 2021-03-26 18:26:39 -07:00
Isaac Freund
a217ad59c7 astgen: fix result location for sliced objects 2021-03-26 23:39:29 +01:00
Isaac Freund
22338d7816 astgen: implement float literals 2021-03-26 15:46:50 +01:00
Isaac Freund
d8ee8794e1 astgen: implement more builtin functions 2021-03-26 15:20:11 +01:00
Isaac Freund
5eea13f5cc astgen: implement slicing 2021-03-26 11:46:42 +01:00
Andrew Kelley
b2deaf8027 stage2: improve source locations of Decl access
* zir.Code: introduce a decls array. This is so that `decl_val` and
   `decl_ref` instructions can refer to a Decl with a u32 and therefore
   they can also store a source location. This is needed for proper
   compile error reporting.
 * astgen uses a hash map to avoid redundantly adding a Decl to the
   decls array.
 * fixed reporting "instruction illegal outside function body" instead
   of the desired message "unable to resolve comptime value".
 * astgen skips emitting dbg_stmt instructions in comptime scopes.
 * astgen has some logic to avoid adding unnecessary type coercion
   instructions for common values.
2021-03-25 23:45:17 -07:00
Andrew Kelley
4bfcd105ef stage2: fix @compileLog. 2021-03-25 20:11:23 -07:00
Andrew Kelley
4fd3a2e8e8 astgen: fix var decl source locations 2021-03-25 19:39:30 -07:00
Andrew Kelley
b9c5a1fdf5 astgen: fix for loop expressions
also rename the ZIR instruction `deref_node` to `load`.
2021-03-25 19:25:26 -07:00
Michael Dusan
9f01598a49 zig build: use ZIG_GLOBAL_CACHE_DIR
- move ZIG_GLOBAL_CACHE_DIR to `introspect`
- cleanup some dead fields from stage1 codegen
2021-03-25 22:05:21 -04:00
Jakub Konka
f1e324216d zld: parse archive's table of contents 2021-03-25 22:48:04 +01:00
Andrew Kelley
399bb2e154 astgen: fix array access 2021-03-25 13:03:54 -07:00
lithdew
4ce212739b os/linux: handle ECONNRESET for recv 2021-03-25 12:41:51 -07:00
Veikka Tuominen
df0f7f4692 translate-c: stop creating unnamed decls for typedefs child types 2021-03-25 16:59:26 +02:00
Sreehari S
5c28b8cd11 boot_services: implement locateDevicePath 2021-03-25 16:45:43 +02:00
Andrew Kelley
31023de6c4 stage2: implement inline while
Introduce "inline" variants of ZIR tags:
 * block => block_inline
 * repeat => repeat_inline
 * break => break_inline
 * condbr => condbr_inline

The inline variants perform control flow at compile-time, and they
utilize the return value of `Sema.analyzeBody`.

`analyzeBody` now returns an Index, not a Ref, which is the ZIR index of
a break instruction. This effectively communicates both the intended
break target block as well as the operand, allowing parent blocks to
find out whether they, in turn, should return the break instruction up the
call stack, or accept the operand as the block's result and continue
analyzing instructions in the block.

Additionally:
 * removed the deprecated ZIR tag `block_comptime`.
 * removed `break_void_node` so that all break instructions use the same Data.
 * zir.Code: remove the `root_start` and `root_len` fields. There is now
   implied to be a block at index 0 for the root body. This is so that
   `break_inline` has something to point at and we no longer need the
   special instruction `break_flat`.
 * implement source location byteOffset() for .node_offset_if_cond
   .node_offset_for_cond is probably redundant and can be deleted.

We don't have `comptime var` supported yet, so this commit adds a test
that at least makes sure the condition is required to be comptime known
for `inline while`.
2021-03-25 00:55:36 -07:00
Andrew Kelley
12d18a36e5 stage2: enable passing tests 2021-03-24 20:58:38 -07:00
Andrew Kelley
01bfd835bb stage2: clean up break / noreturn astgen
* Module.addBreak and addBreakVoid return zir.Inst.Index not Ref
   because Index is the simpler type and we never need a Ref for these.
 * astgen: make noreturn stuff return the unreachable_value and avoid
   unnecessary calls to rvalue()
 * breakExpr: avoid unnecessary access into the tokens array
 * breakExpr: fix incorrect `@intCast` (previously this unsafely
   casted an Index to a Ref)
2021-03-24 20:45:14 -07:00
Timon Kruiper
ea42ab34ab stage2: add block test cases llvm backend 2021-03-24 19:54:03 -07:00
Timon Kruiper
522707622e astgen: implement breaking from a block 2021-03-24 19:54:03 -07:00
Andrew Kelley
d73a4940e0 stage2: cleanups from previous commits
Change some ZIR instructions from un_tok to un_node. Idea here is to
avoid needlessly accessing the tokens array.

Go ahead and finish the catch code in orelseCatchExpr. Otherwise it
would be an easy mistake to get the scopes wrong when updating that
code and introduce a bug.

Delete a function that is now dead code.
2021-03-24 16:14:11 -07:00
Timon Kruiper
3543373fd4 stage2: add passing optional test case in LLVM backend 2021-03-24 15:48:18 -07:00
Timon Kruiper
2c99fbb672 astgen: implement orelse 2021-03-24 15:48:18 -07:00
Andrew Kelley
0c6581e01d stage2: fix memory leak when updating a function 2021-03-24 15:46:06 -07:00
Andrew Kelley
180dae4196 stage2: further cleanups regarding zir.Inst.Ref
* Introduce helper functions on Module.WipZirCode and zir.Code
 * Move some logic around
 * re-introduce ref_start_index
 * prefer usize for local variables + `@intCast` at the end.
   Empirically this is easier to optimize.
 * Avoid using mem.{bytesAsSlice,sliceAsBytes} because it incurs an
   unnecessary multiplication/division which may cause problems for the
   optimizer.
 * Use a regular enum, not packed, for `Ref`. Memory layout is
   guaranteed for enums which specify their tag type. Packed enums have
   ABI alignment of 1 byte which is too small.
2021-03-24 15:36:23 -07:00
Isaac Freund
0c601965ab stage2: make zir.Inst.Ref a non-exhaustive enum
This provides us greatly increased type safety and prevents the common
mistake of using a zir.Inst.Ref where a zir.Inst.Index was expected or
vice-versa. It also increases the ergonomics of using the typed values
which can be directly referenced with a Ref over the previous zir.Const
approach.

The main pain point is casting between a []Ref and []u32, which could be
alleviated in the future with a new std.mem function.
2021-03-24 19:11:44 +01:00
Isaac Freund
3bf72f2b3a std.build: make Builder.install_prefix non optional
This is useful for build.zig files to check in some cases, for example
to adhere to the convention of installing config to /etc instead of
/usr/etc on linux when using the /usr prefix. Perhaps std.build will
handle such common cases eventually, but that is not yet the case.
2021-03-24 12:29:50 +01:00
Andrew Kelley
a1afe69395 stage2: comment out failing test cases; implement more things
* comment out the failing stage2 test cases
   (so that we can uncomment the ones that are newly passing with
   further commits)
 * Sema: implement negate, negatewrap
 * astgen: implement field access, multiline string literals, and
   character literals
 * Module: when resolving an AST node into a byte offset, use the
   main_tokens array, not the firstToken function
2021-03-23 23:13:01 -07:00
Andrew Kelley
13ced07f23 stage2: fix while loops
also start to form a plan for how inline while loops will work
2021-03-23 21:37:10 -07:00
Andrew Kelley
bf7c3e9355 astgen: fixups regarding var decls and rl_ptr 2021-03-23 16:47:41 -07:00
Andrew Kelley
be673e6793 stage2: implement inttype ZIR
also add i128 and u128 to const inst list
2021-03-23 16:12:26 -07:00
Andrew Kelley
aa46a705ad astgen: finishThenElseBlock: fix putting store_to_block_ptr in wrong block 2021-03-23 15:32:25 -07:00
Andrew Kelley
af73f79490 stage2: fix comptimeExpr and comptime function calls 2021-03-23 13:25:58 -07:00
Andrew Kelley
866be099f8 stage2: add helper functions to clean up astgen Ref/Index 2021-03-23 12:54:18 -07:00
Timon Kruiper
830143905e Sema: use correct LazySrcLoc for resolvePeerTypes 2021-03-23 11:56:06 -07:00
Timon Kruiper
7194baed66 astgen: implement typeof 2021-03-23 11:56:06 -07:00
Timon Kruiper
99cf9f8bf1 astgen: fix an issue where the alloc wasnt elided 2021-03-23 11:49:12 -07:00
Timon Kruiper
982df37135 stage2: handle void value in genRet in LLVM backend 2021-03-23 11:42:46 -07:00
Timon Kruiper
d73b0473a1 stage2: rename fail to todo in LLVM backend
This way we don't have to pass src to every function and we can simply
use the first node as the lazy source location for all the todo
errors.
2021-03-23 11:42:46 -07:00
Isaac Freund
668148549a stage2: fix two return types to be Ref not Index
We currently have no type safety between zir.Inst.Ref, zir.Inst.Index,
and plain u32s.
2021-03-23 11:58:43 +01:00
Timon Kruiper
f3e8073e05 astgen: implement assign operations 2021-03-23 11:40:55 +01:00
Andrew Kelley
d24be85be8 stage2: fix if expressions 2021-03-22 23:47:13 -07:00
Andrew Kelley
749c3f014b Merge pull request #8339 from Luukdegram/wasm-control-flow
stage2: Wasm control flow
2021-03-22 19:52:31 -07:00
Andrew Kelley
568f333681 astgen: improve the ensure_unused_result elision 2021-03-22 18:57:46 -07:00
Andrew Kelley
2f391df2a7 stage2: Sema improvements and boolean logic astgen
* add `Module.setBlockBody` and related functions
 * redo astgen for `and` and `or` to use fewer ZIR instructions and
   require less processing for comptime known values
 * Sema: rework `analyzeBody` function. See the new doc comments in this
   commit. Divides ZIR instructions up into 3 categories:
   - always noreturn
   - never noreturn
   - sometimes noreturn
2021-03-22 17:29:56 -07:00
Isaac Freund
9f0b9b8da1 stage2: remove all async related code
The current plan is to avoid using async and related features in the
stage2 compiler so that we can bootstrap before implementing them.

Having this untested and incomplete code in the codebase increases
friction while working on stage2, in particular when preforming
larger refactors such as the current zir memory layout rework.

Therefore remove all async related code, leaving only error messages
in astgen.
2021-03-23 00:23:41 +01:00
Dimenus
240b15381d fix calculation in ensureCapacity 2021-03-22 11:58:44 -07:00
Luuk de Gram
4b854b75d2 Fix getNot and add test cases 2021-03-22 19:56:38 +01:00
Luuk de Gram
803f9e5dd0 Implement more instructions for more control flow support 2021-03-22 19:56:35 +01:00
Jakub Konka
3b48ea874e zld: naively handle static initializers in C++ 2021-03-22 17:14:53 +01:00
Isaac Freund
f3770dcc30 astgen: implement pointer types 2021-03-22 16:03:00 +01:00
Isaac Freund
8111453cc1 astgen: implement array types 2021-03-22 14:54:13 +01:00
Evan Haas
dce612ac2b translate-c: Ensure assignments are within a block when necessary
Ensures that if an assignment statement is the sole statement within a
C if statement, for loop, do loop, or do while loop, then when translated
it resides within a block, even though it does not in the original C.

Fixes the following invalid translation:

`if (1) if (1) 2;` -> `if (true) if (true) _ = @as(c_int, 2);`

To this:
```zig
    if (true) if (true) {
        _ = @as(c_int, 2);
    };
```

Fixes #8159
2021-03-22 10:48:08 +02:00
Carlos Zúñiga
187af14599 Fixed typo in user32
Use CreateWindowExW instead of RegisterClassExW as the type of pfnCreateWindowExW.
2021-03-22 10:43:04 +02:00
Andrew Kelley
4f3071a817 cleanups from previous commit 2021-03-21 20:18:13 -07:00
jacob gw
7a55671b89 zir-memory-layout: astgen: varDecl 2021-03-21 20:10:27 -07:00
Andrew Kelley
5769c963e0 Sema: implement arithmetic 2021-03-21 19:23:12 -07:00
Jakub Konka
ba8ac46e1f stage1: add cmake flag for enabling logging
Now that we ship our own linker for MachO by default in both stage1
and stage2, we need a way to enable logs for verbose debugging.
This commit adds `ZIG_ENABLE_LOGGING` cmake option which is equivalent
to stage2's `-Dlog` flag.

To enable it when building stage1 with cmake, add:

```
cmake .. -DZIG_ENABLE_LOGGING=on
```
2021-03-21 18:03:55 -07:00
Andrew Kelley
07c204393f Sema: no explicit coercion needed for inline asm args
These are now done with result locations.
2021-03-21 17:55:31 -07:00
Isaac Freund
72bcdb639f astgen: implement bool_and/bool_or 2021-03-22 00:51:25 +01:00
Joris Hartog
5e40560367 Specify type in autoHash error message
This commit simply specifies the type which `autoHash` can't hash in the
compile error.

Closes #7970.
2021-03-21 23:07:02 +02:00
Isaac Freund
4cfd5f6a30 astgen: implement simple binary operators 2021-03-21 20:32:39 +01:00
Isaac Freund
310a44d5be zir: add negate/negate_wrap, implement astgen
These were previously implemented as a sub/sub_wrap instruction with a
lhs of 0. Making this separate instructions however allows us to save
some memory as there is no need to store a lhs.
2021-03-21 20:32:39 +01:00
Andrew Kelley
7800ae05a2 astgen: fix not detecting volatile asm
if only we could have compile errors for unused locals
2021-03-20 22:48:36 -07:00
Andrew Kelley
7598a00f34 stage2: fix memory management of ZIR code
* free Module.Fn ZIR code when destroying the owner Decl
 * unreachable_safe and unreachable_unsafe are collapsed into one ZIR
   instruction with a safety flag.
 * astgen: emit an unreachable instruction for unreachable literals
 * don't forget to call deinit on ZIR code
 * astgen: implement some builtin functions
2021-03-20 22:40:08 -07:00
Nuno Leiria
0d96a284e8 std: Add reset to TokenIterator 2021-03-20 22:01:09 -07:00
Andrew Kelley
d8692b8bdb astgen: implement string literals 2021-03-20 21:59:28 -07:00
Andrew Kelley
8bad5dfa72 astgen: implement inline assembly 2021-03-20 21:48:35 -07:00
Andrew Kelley
260c610708 ZIR: move some un_tok tags to un_node instead
Idea here is to prefer un_node to un_tok in order to avoid unnecessary
calls to `tree.firstToken`.
2021-03-20 17:18:44 -07:00
Andrew Kelley
50010447bd astgen: implement function calls 2021-03-20 17:09:06 -07:00
jacob gw
907142a036 zir-memory-layout: remove all absolute src consts
this is to prevent future bugs
2021-03-20 15:56:59 -07:00
jacob gw
12eeb18a26 zir-memory-layout: astgen: more instructions 2021-03-20 15:56:59 -07:00
Timon Kruiper
a710368054 stage2: restructure LLVM backend
The LLVM backend is now structured into 3 different structs, namely
Object, DeclGen and FuncGen. Object represents an object that is
generated by the LLVM backend. DeclGen is responsible for generating
a decl and FuncGen is responsible for generating llvm instructions
from tzir in a function.
2021-03-20 15:10:44 -07:00
Jakub Konka
3913332145 Fix digest format specifier after std.fmt updates 2021-03-20 15:09:45 -07:00
Michael Dusan
e35f325dd1 azure: produce macos arm64 binaries
new pipeline `BuildMacOS_arm64`
  - `vmImage: 'macOS-10.15' `

new `macos_arm64_script`
  - switch from using `make` to `ninja`
  - select xcode 12.4
  - set zig-cache env variables
  - build host-zig binary with xcode, link against llvm for x86_64 (target macos 10.15)
  - build arm64-zig binary with xcode and host-zig, link against llvm for arm64 (target macos 11.0)
  - ad-hoc codesign arm64 binary with linker
  - use host-zig for docgen
  - use host-zig for experimental std lib docs
  - sync final `release/` hierarchy with `linux_script`
  - use gnu-tar for good-practices (set owner, set sort)

enhance `CMakeLists.txt`
  - do not build `zig0` when cross-compiling
  - disable `BYPRODUCTS` directive `zig1.o` to avoid `ninja` error

see #8265
2021-03-20 22:50:51 +01:00
Andrew Kelley
56677f2f2d astgen: support blocks
We are now passing this test:

```zig
export fn _start() noreturn {}
```

```
test.zig:1:30: error: expected noreturn, found void
```

I ran into an issue where we get an integer overflow trying to compute
node index offsets from the containing Decl. The problem is that the
parser adds the Decl node after adding the child nodes. For some things,
it is easy to reserve the node index and then set it later, however, for
this case, it is not a trivial code change, because depending on tokens
after parsing the decl determines whether we want to add a new node or
not.

Possible strategies here:

1. Rework the parser code to make sure that Decl nodes are before
   children nodes in the AST node array.

2. Use signed integers for Decl node offsets.

3. Just flip the order of subtraction and addition. Expect Decl Node
   index to be greater than children Node indexes.

I opted for (3) because it seems like the simplest thing to do. We'll
want to unify the logic for computing the offsets though because if the
logic gets repeated, it will probably get repeated wrong.
2021-03-19 23:15:18 -07:00
Andrew Kelley
937c43ddf1 stage2: first pass at repairing ZIR printing 2021-03-19 19:33:11 -07:00
Jakub Konka
f6ba810f27 zld: apply offset for DICE in archive 2021-03-19 23:37:16 +01:00
Andrew Kelley
0357cd8653 Sema: allocate inst_map with arena where appropriate 2021-03-19 15:31:50 -07:00
Andrew Kelley
81a935aef8 stage2: fix some math oopsies and typos 2021-03-19 15:19:47 -07:00
Andrew Kelley
132df14ee1 stage2: fix export source locations not being relative to Decl 2021-03-19 14:59:46 -07:00
jacob gw
a4f0ccdfe4 zir-memory-layout: astgen: literals and *, &
this was pretty low hanging fruit
2021-03-19 14:50:15 -07:00
jacob gw
c50397c268 llvm backend: use new srcloc
this allows to compile with ninja
2021-03-19 14:46:37 -07:00
jacob gw
e9810d9e79 zir-memory-layout: astgen: fill in identifier 2021-03-19 14:43:08 -07:00
LemonBoy
867ae506e3 std: Add syscall7 stub for Linux/MIPS
Some syscalls such as fadvise require an extra argument to comply with
the register pair alignment imposed by the ABI.

Wacky, isn't it?
2021-03-19 13:03:55 -07:00
Jakub Konka
652842637c zld: continue on invalid/missing debug info 2021-03-19 20:05:02 +01:00
Jakub Konka
d1b376cac9 zld: fix parsing archive/object name from header 2021-03-19 11:06:51 +01:00
Andrew Kelley
abdbc11c7e stage2: codegen: update asm IR to new names 2021-03-18 22:54:59 -07:00
Andrew Kelley
bd2154da3d stage2: the code is compiling again
(with a lot of things commented out)
2021-03-18 22:48:28 -07:00
Andrew Kelley
b2682237db stage2: get Module and Sema compiling again
There are some `@panic("TODO")` in there but I'm trying to get the
branch to the point where collaborators can jump in.

Next is to repair the seam between LazySrcLoc and codegen's expected
absolute file offsets.
2021-03-18 22:19:28 -07:00
Andrew Kelley
f5aca4a6a1 Merge remote-tracking branch 'origin/master' into zir-memory-layout
I need the enum arrays that were just merged into master.
2021-03-18 15:52:12 -07:00
Martin Wickham
96ae451bbe Add some enum utilities 2021-03-18 14:05:01 -07:00
Andrew Kelley
5e5b35f107 stage1: small memory optimization for simple pointer types
Avoid storing extra IR instruction data for simple pointer types.
2021-03-18 14:04:02 -07:00
Andrew Kelley
a6f5aa71ac stage1: small IR memory optimization on CheckSwitchProngs 2021-03-18 14:04:02 -07:00
Veikka Tuominen
ac7217e1f5 translate-c: preserve zero fractional part in float literals 2021-03-18 22:46:00 +02:00
jacob gw
7c6eb41619 cbe tests: fix test on windows
"\n" -> std.cstr.line_sep
2021-03-18 22:45:01 +02:00
Andrew Kelley
5cbb642525 stage1: small mem usage improvement for IR
move a boolean field to be represented implicitly with the enum tag.
Just borrowing one of the many strategies of stage2.

This simple change took the peak mem usage from std lib tests on
my machine from 8.21 GiB to 8.11 GiB.
2021-03-18 13:14:26 -07:00
Jakub Konka
17c066e925 Merge pull request #8282 from kubkon/zld
macho: upstream zld linker
2021-03-18 19:14:17 +01:00
Evan Haas
b54514d9dd translate-c: Use [N:0] arrays when initializer is a string literal (#8264)
* translate-c: Use [N:0] arrays when initializer is a string literal

Translate incomplete arrays as [N:0] when initialized by a string literal.
This preserves a bit more of the type information from the original C program.

Fixes #8215
2021-03-18 14:41:04 +02:00
root
75a7abb0c4 std: Fix std.fs.path.joinZ 2021-03-18 14:33:38 +02:00
Veikka Tuominen
bcc97bc1ed Merge pull request #8247 from Ersikan/fmt-fix-encoding
zig fmt: fix non-UTF-8 encoding #2820
2021-03-18 14:30:11 +02:00
Jakub Konka
f3b4f79c7f zld: temporarily disable testing shared lib linking 2021-03-18 11:10:31 +01:00
Jakub Konka
2cf1c1b96b macho: honor verbose_link when linking with zld 2021-03-18 11:10:09 +01:00
Jakub Konka
861ea64009 macho: remove now obsolete LLD fixups 2021-03-18 11:09:47 +01:00
Dimenus
dfeca48e35 @intCast takes two args 2021-03-17 22:58:52 -07:00
Andrew Kelley
66245ac834 stage2: Module and Sema are compiling again
Next up is reworking the seam between the LazySrcLoc emitted by Sema
and the byte offsets currently expected by codegen.

And then the big one: updating astgen.zig to use the new memory layout.
2021-03-17 22:54:56 -07:00
Jakub Konka
7516dfff83 zld: use zld when linking aarch64 by default and cross-comp 2021-03-18 00:37:13 +01:00
Jakub Konka
900658a85d rebase with master 2021-03-17 20:05:29 +01:00
Jakub Konka
1ec620be62 zld: fix GOT loads and indirection on x86_64 2021-03-17 19:59:57 +01:00
Jakub Konka
ac0c669473 zld: add/fix more issues
* fix debug info for static archives
* allow handling of empty object files
* fix some relocs for GOT loads
2021-03-17 19:59:13 +01:00
Jakub Konka
de209afbba zld: fix TLV initializers 2021-03-17 19:59:13 +01:00
Jakub Konka
349f878ecf zld: mimick Apple and add __DATA_CONST seg 2021-03-17 19:59:13 +01:00
Jakub Konka
62f43fbc06 zld: clean up use of commands.zig module 2021-03-17 19:59:13 +01:00
Jakub Konka
d484b3b3cb zld: use aarch64 for opcodes 2021-03-17 19:59:13 +01:00
Jakub Konka
dc34ac2b9e zld: fix incorrect offset calc for DICE 2021-03-17 19:59:13 +01:00
Jakub Konka
5d8944edc1 Revert log.warn hack 2021-03-17 19:59:13 +01:00
Jakub Konka
a1b0ec5277 zld: start bringing x64 up to speed 2021-03-17 19:59:13 +01:00
Jakub Konka
066c1386a3 zld: demote logs from warn to debug 2021-03-17 19:59:13 +01:00
Jakub Konka
b0ee480177 zld: merge and sort sections 2021-03-17 19:59:13 +01:00
Jakub Konka
44ebf48631 zld: fix handling of section alignment 2021-03-17 19:59:13 +01:00
Jakub Konka
7c22f4f851 zld: pass test-std and test-compiler-rt 2021-03-17 19:59:13 +01:00
Jakub Konka
7cbdbab376 zld: differentiate locals from globals 2021-03-17 19:59:13 +01:00
Jakub Konka
7e32947871 zld: add nop to reloc module 2021-03-17 19:59:13 +01:00
Jakub Konka
d2008db623 zld: bullet-proof stubs for long jumps 2021-03-17 19:59:13 +01:00
Jakub Konka
14590795b1 zld: cleanup section alignment when allocating 2021-03-17 19:59:13 +01:00
Jakub Konka
586c704212 zld: pass stage2 tests linked with zld! 2021-03-17 19:59:13 +01:00
Jakub Konka
e825a15b05 zld: replace ldr with add if indivisible 2021-03-17 19:59:13 +01:00
Jakub Konka
f52f23618d macho: start upstreaming zld 2021-03-17 19:59:13 +01:00
Jakub Konka
0f7b036eb7 Merge pull request #8281 from kubkon/macho-got-refactor
stage2+macho: refactor global offset table for incremental linker
2021-03-17 19:44:32 +01:00
Frank Denis
119fc318a7 std/crypto/chacha20: add round-reduced versions & cleanup internals
See https://eprint.iacr.org/2019/1492.pdf for justification.

8 rounds ChaCha20 provides a 2.5x speedup, and is still believed
to be safe.

Round-reduced versions are actually deployed (ex: Android filesystem
encryption), and thanks to the magic of comptime, it doesn't take much
to support them.

This also makes the ChaCha20 code more consistent with the Salsa20 code,
removing internal functions that were not part of the public API any more.

No breaking changes; the public API remains backwards compatible.
2021-03-17 11:25:51 -07:00
Andrew Kelley
587243c7a5 Merge pull request #8273 from jedisct1/pbkdf2-check
crypto/pbkdf2: simplify the check for the max number of iterations
2021-03-17 11:25:19 -07:00
Jakub Konka
e5234c0e9e macho: offset table part of GOT 2021-03-17 12:16:36 +01:00
Jakub Konka
b9fa80e588 macho: use latest bind functionality 2021-03-17 12:10:39 +01:00
Jakub Konka
1181543dad macho: extract writing stub helper preamble into fn 2021-03-17 12:10:39 +01:00
Jakub Konka
3df2ae1f9d macho: clean up writing of stub helper section 2021-03-17 12:10:39 +01:00
Jakub Konka
643b4898f5 macho: handle all jumps in stubs on aarch64 2021-03-17 12:10:39 +01:00
Jakub Konka
3019676440 macho: apply some renames to bring closer to zld 2021-03-17 12:10:39 +01:00
Ersikan
36db4b7cc4 test-cli: Remove temporary directory after tests 2021-03-17 10:27:41 +01:00
Ersikan
8942243f7a zig fmt: factorize source file reading and decoding
Now reading a source file and decoding it from UTF-16LE to UTF-8 is
done in a single function. Error messages are improved, and an error is
emitted when the source file has a BOM not supported (UTF-16BE, UTF-32).

Please note that the BOM of UTF-32 is composed of the same bytes as the
BOM of UTF-16 followed by a null character. Therefore a source file in
UTF-16LE starting with a null byte will be interpreted as an UTF-32, and
rejeted because of an invalid format. In pratice this is not a problem,
as the code would have been rejected later anyway because of the null
character.
2021-03-17 10:27:26 +01:00
Ersikan
a354000090 zig fmt: fix non-UTF-8 encoding #2820
Fixes #2820

After reading the source code, the first two bytes are inspected, and
if they correspond to a UTF-16 BOM in little-endian order, the source
code is converted to UTF-8.
2021-03-17 10:26:47 +01:00
Frank Denis
6d9b3e7b19 pbkdf2: use std.math.divCeil() 2021-03-17 10:11:47 +01:00
Andrew Kelley
38b3d4b00a stage2: work through some compile errors in Module and Sema 2021-03-17 00:56:08 -07:00
Evan Haas
f76bd56588 translate-c: fix __builtin_object_size
Previous code assumed `c_long` and `usize` were the same size.
Use `isize` instead.
2021-03-17 09:06:47 +02:00
Evan Haas
715370a10a translate-c: demote usage of un-implemented builtins 2021-03-17 09:06:47 +02:00
Andrew Kelley
4683de1e91 Merge pull request #8252 from tadeokondrak/llvm-bool
stage2 llvm bindings: use correct type for LLVMBool for ABI compat
2021-03-16 21:56:00 -07:00
Tadeo Kondrak
e8aa6f90d6 stage2 llvm bindings: use correct type for LLVMBool for ABI compat 2021-03-16 17:05:36 -06:00
Evan Haas
c558a1ae26 translate-c: Implement generic selection expressions
Enables translation of C code that uses the `_Generic` keyword
2021-03-17 00:07:33 +02:00
xackus
9a94415680 translate-c: improve std.meta.cast 2021-03-17 00:05:42 +02:00
jacob gw
83d0c2ed67 std: make all errors in os.zig public 2021-03-16 14:48:31 -07:00
jacob gw
e430f3f7e0 zir-memory-layout: fix @setEvalBranchQuota
also make emitBackwardBranch fail correctly
2021-03-16 14:47:54 -07:00
Frank Denis
f609c4ddb3 crypto/pbkdf2: use snake_case for variables like everywhere else 2021-03-16 19:08:38 +01:00
Frank Denis
d1b1e542a0 crypto/pbkdf2: simplify the check for the max number of iterations 2021-03-16 18:55:58 +01:00
Lewis Gaul
6787f163eb zig fmt: don't add trailing whitespace on switch case 2021-03-16 09:26:28 +01:00
LemonBoy
5ecf8bddae zig fmt: Respect line breaks in struct default value decls
Bring this in line with how variable declarations are handled.

Open a new indentation level for the initialization expression to handle
nested expressions like blocks.

Closes #7618
2021-03-16 09:22:16 +01:00
Andrew Kelley
099af0e008 stage2: rename zir_sema.zig to Sema.zig 2021-03-16 00:04:17 -07:00
Andrew Kelley
aef3e534f5 stage2: *WIP*: rework ZIR memory layout; overhaul source locations
The memory layout for ZIR instructions is completely reworked. See
zir.zig for those changes. Some new types:

 * `zir.Code`: a "finished" set of ZIR instructions. Instead of allocating
   each instruction independently, there is now a Tag and 8 bytes of
   data available for all ZIR instructions. Small instructions fit
   within these 8 bytes; larger ones use 4 bytes for an index into
   `extra`. There is also `string_bytes` so that we can have 4 byte
   references to strings. `zir.Inst.Tag` describes how to interpret
   those 8 bytes of data.
   - This is shared by all `Block` scopes.

 * `Module.WipZirCode`: represents an in-progress `zir.Code`. In this
   structure, the arrays are mutable, and get resized as we add/delete
   things. There is extra state to keep track of things. This struct is
   stored on the stack. Once it is finished, it produces an immutable
   `zir.Code`, which will remain on the heap for the duration of a
   function's existence.
   - This is shared by all `GenZir` scopes.

 * `Sema`: represents in-progress semantic analysis of a `zir.Code`.
   This data is stored on the stack and is shared among all `Block`
   scopes. It is now the main "self" argument to everything in the file
   that was previously named `zir_sema.zig`.
   Additionally, I moved some logic that was in `Module` into here.

`Module.Fn` now stores its parameter names inside the `zir.Code`,
instead of inside ZIR instructions. When the TZIR memory layout
reworking time comes, codegen will be able to reference this data
directly instead of duplicating it.

astgen.zig is (so far) almost entirely untouched, but nearly all of it
will need to be reworked to adhere to this new memory layout structure.

I have no benchmarks to report yet, as I am still working through
compile errors and fixing various things that I broke in this branch.

Overhaul of Source Locations:

Previously we used `usize` everywhere to mean byte offset, but sometimes
also mean other stuff. This was error prone and also made us do
unnecessary work, and store unnecessary bytes in memory.

Now there are more types involved into source locations, and more ways
to describe a source location.

 * AllErrors.Message: embrace the assumption that files always have less
   than 2 << 32 bytes.
 * SrcLoc gets more complicated, to model more complicated source
   locations.
 * Introduce LazySrcLoc, which can model interesting source locations
   with very little stored state. Useful for avoiding doing unnecessary
   work when no compile errors occur.

Also, previously, we had `src: usize` on every ZIR instruction. This is
no longer the case. Each instruction now determines whether it even cares
about source location, and if so, how that source location is stored.
This requires more careful work inside `Sema`, but it results in fewer
bytes stored on the heap, without compromising accuracy and power of
compile error messages.

Miscellaneous:

 * std.zig: string literals have more helpful result values for
   reporting errors. There is now a lower level API and a higher level
   API.
   - side note: I noticed that the string literal logic needs some love.
     There is some unnecessarily hacky code there.
 * cut & pasted some TZIR logic that was in zir.zig to ir.zig. This
   probably broke stuff and needs to get fixed.
 * Removed type/Enum.zig, type/Union.zig, and type/Struct.zig. I don't
   think this quite how this code will be organized. Need some more
   careful planning about how to implement structs, unions, enums. They
   need to be independent Decls, just like a top level function.
2021-03-16 00:03:22 -07:00
Anders Conbere
f16f25047c std: support optional getaddrinfo arguments 2021-03-16 01:10:32 +01:00
Lewis Gaul
aa1c780560 Add test for multi-line while cont expr with same-line then expr 2021-03-15 20:44:45 +01:00
Isaac Freund
48efa3bcb6 zig fmt: simplify and improve consistency of if/for/while handling
The main realization here was that getting rid of the early returns
in renderWhile() and rewriting the logic into a mostly unified execution
path took things from ~200 lines to ~100 lines and improved consistency
by deduplicating code.

Also add several test cases and fix a few issues along the way:

Fixes https://github.com/ziglang/zig/issues/6114
Fixes https://github.com/ziglang/zig/issues/8022
2021-03-15 14:55:34 +01:00
Lewis Gaul
b4db03d8bb zig fmt: fix extra newline before if nested in for
Add failing testcase to reproduce issue 8088

Tidy up renderWhile(), factoring out renderWhilePayload()

Ensure correct newline is used before 'then' token in while/for/if

Handle indents for 'if' inside 'for' or 'while'

Stop special-casing 'if' compared to 'for' and 'while'
2021-03-15 14:55:34 +01:00
Tadeo Kondrak
277b01a089 stage2 llvm bindings: rename LLVMBool to Bool 2021-03-14 22:32:26 -06: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
LemonBoy
27d07c6c4d std: Replace testing fns for floating-point values
Beside handling NaNs and other non-numeric values better we finally
offer the same pair of testing predicates in math and testing.
2021-03-14 17:23:47 -04:00
LemonBoy
d33f0d3375 docgen: Use Progress API
Really slow as usual but now looks slightly better.
2021-03-14 17:22:48 -04:00
Frank Denis
b98d7747fa Use a unified error set for std/crypto/*
This ensures that errors are used consistently across all operations.
2021-03-14 20:51:31 +01:00
Ersikan
f69305f865 stage2: Warn when using --debug-log without logging enabled
A warning is emitted when using the debug option --debug-log when the compiler
was not compiled using the build option -Dlog. Additionnaly, the scopes are not
added to log_scopes as they have no effect.
2021-03-14 17:48:02 +01:00
Andrew Kelley
a4316d5505 Merge remote-tracking branch 'origin/master' into llvm12 2021-03-13 14:35:03 -07:00
Andrew Kelley
4e9894cfc4 cmake build: allow overriding whether to use llvm-config
Previously, there was an option ZIG_PREFER_LLVM_CONFIG which would
override the default of not using llvm-config when cross compiling.

That option is now removed in favor of the more powerful
ZIG_USE_LLVM_CONFIG which defaults to OFF for cross compiling and ON for
native compilation. The option overrides the default.

This will be used in zig-bootstrap to improve support for native builds.
2021-03-13 14:30:56 -07:00
Michael Dusan
cc650abf09 lld: handle error instead of abort
closes #6675
2021-03-13 18:14:59 +01:00
Andrew Kelley
ce14bc7176 Merge pull request #8152 from LemonBoy/fix-riscv-ret
stage1: Follow the C ABI for return types
2021-03-12 20:12:36 -05:00
Dave Gauer
95eb711ca8 langref: Use "single-item pointer" and "many-item pointer" (#8217)
These terms give short, descriptive names for the two pointer
types which reflect the names used in src/type.zig.
2021-03-12 20:10:55 -05:00
Andrew Kelley
1f34c03ac1 Merge remote-tracking branch 'origin/master' into llvm12 2021-03-12 18:05:27 -07:00
LemonBoy
8ebb18d9da std: Use more common escape sequences in Progress
This should fix the badly-rendered progress message when run in
Terminal.app.
2021-03-12 19:31:59 -05:00
Isaac Freund
b83ef595a5 std/linux: sync io_uring library with liburing
liburing commit: 1bafb3ce5f

As stated in the liburing commit message, this fixes a regression,
reverting code that was added specutively to avoid a syscall in some
cases.
2021-03-12 22:22:06 +01:00
Andrew Kelley
f950489ed9 Merge pull request #8174 from LemonBoy/progress-line-wrap
std: Better handling of line-wrapping in Progress
2021-03-12 15:45:11 -05:00
Jakub Konka
a745e704f6 macos: add missing x86_64 libc headers 2021-03-12 18:05:50 +01:00
LemonBoy
b0724a350f Handle some weird edge cases of Win32 API
Sometimes the viewport srWindow may report an invalid rectangle where
the top row is below the bottom one.
2021-03-12 17:14:50 +01:00
LemonBoy
b5a50a26eb Fix many thinkos
Somehow I forgot to save after copy-pasting some code and changing it.
2021-03-12 15:08:48 +01:00
Sébastien Marie
89e522b935 make std.c.getErrno() return same type as _errno() aka c_int
adjust std.os.unexpectedErrno() to be correct for all std.os.system.errno (c_int, u12, usize, ...)
2021-03-12 15:04:36 +01:00
LemonBoy
36c4037144 stage1: Add tests for C ABI integer return types 2021-03-12 11:50:56 +01:00
LemonBoy
7813068e21 stage1: Follow the C ABI for return types
The current implementation of the target C ABI rules is hopelessly bad,
let's tack some more rules on top in order to prevent some
miscompilations.

Truth to be told the same rule should be applied also to parameters, but
I really can't stand stage1.
2021-03-12 11:50:56 +01:00
LemonBoy
3010bfb08a Fix Progress printing on Windows systems
The cursor must be restored after the line is printed, not before.
Take into account the visible viewport to correctly compute the terminal
size.
2021-03-12 10:15:38 +01:00
Michael Dusan
868253a9c9 re-enable behavior/vector test for aarch64
- issue fixed in llvmorg-12.0.0-rc3

closes #8130
2021-03-12 02:00:29 -05:00
Andrew Kelley
e9a038c33b Merge pull request #7934 from Vexu/stage2-cbe
Stage2 cbe: optionals and errors
2021-03-11 22:02:35 -05:00
Isaac Freund
a5cb4ab95e parser: disallow ptr modifiers on array types 2021-03-12 00:18:30 +01:00
LemonBoy
482424e2b1 std: Handle empty MultiArrayList in items()
Closes #8211
2021-03-12 00:17:35 +01:00
Andrew Kelley
4fc6f631e0 Merge pull request #8126 from xackus/translate_c_int_literal_promotion
translate-c: promote int literals to bigger types
2021-03-11 14:32:37 -05:00
joachimschmidt557
bdb917006c stage2 tzir: Add wrapping integer arithmetic instructions 2021-03-11 14:31:21 -05:00
Andrew Kelley
b1a22fdbab Merge pull request #8193 from kivikakk/elf-expose-em
elf: expose machine field in ELF header
2021-03-11 14:30:06 -05:00
Asherah Connor
24e5959840 elf: make EM non-exhaustive 2021-03-11 10:09:51 +11:00
Asherah Connor
c5eb15526d expose machine field in ELF header 2021-03-10 16:26:41 +11:00
LemonBoy
f2b96782ec stage2: Fix glibc lookup path for MIPS crt files
Add some more rules to let the compiler find the correct startup files
for the selected target and ABI.
2021-03-09 18:20:34 -05:00
LemonBoy
1a5d0cea15 stage2: Use correct ELF emulation for mips64
The n32 ABI requires a different emulation string than n64.
2021-03-09 18:20:34 -05:00
Loris Cro
a033735c8d update to latest fetch-them-macos-headers 2021-03-09 22:43:16 +01:00
Loris Cro
767eb2d469 update to latest fetch-them-macos-headers 2021-03-09 22:15:01 +01:00
Evan Haas
c760532be0 translate-c: Add compound literal support 2021-03-08 10:09:12 +02:00
Isaac Freund
b988815bf0 parser: fix parsing/rendering of a[b.. :c] slicing
The modification to the grammar in the comment is in line with the
grammar in the zig-spec repo.

Note: checking if the previous token is a colon is insufficent to tell
if a block has a label, the identifier must be checked for as well. This
can be seen in sentinel terminated slicing: `foo[0..1:{}]`
2021-03-08 01:37:28 +01:00
Evan Haas
d01bb21173 translate-c: Explicitly cast decayed array to pointer with @ptrCast
This enables translation of code that uses pointer arithmetic with arrays
2021-03-08 00:35:17 +02:00
Veikka Tuominen
fc62ff77c3 stage2: error union payload must also be a valid variable type 2021-03-08 00:33:59 +02:00
jacob gw
d9e46a4b90 stage2: fix memory leak in the cbe 2021-03-08 00:33:59 +02:00
jacob gw
30ffa052f2 stage2 cbe: add error union and error union operations 2021-03-08 00:33:59 +02:00
jacob gw
6467ef6d3b cbe: add error comparison support 2021-03-08 00:33:59 +02:00
Veikka Tuominen
0a7be71bc2 stage2 cbe: non pointer optionals 2021-03-08 00:33:56 +02:00
Veikka Tuominen
cfc19eace7 stage2 cbe: errors 2021-03-08 00:33:07 +02:00
Veikka Tuominen
c22f010fdd stage2 cbe: regular optional types 2021-03-08 00:33:07 +02:00
Veikka Tuominen
ca20d0ea26 stage2 cbe: pointer like optionals 2021-03-08 00:32:52 +02:00
jacob gw
5d215cc76b stage2 Elf linker: fill in bswapAllFields
I moved it to std.elf since it could be used there and added test
2021-03-07 23:18:26 +02:00
LemonBoy
4fc2e92876 std: Better handling of line-wrapping in Progress
In order to update the printed progress string the code tried to move
the cursor N cells to the left, where N is the number of written bytes,
and then clear the remaining part of the line.
This strategy has two main issues:
 - Is only valid if the number of characters is equal to the number of
   written bytes,
 - Is only valid if the line doesn't get too long.

The second point is the main motivation for this change, when the line
becomes too long the terminal wraps it to a new physical line. This
means that moving the cursor to the left won't be enough anymore as once
the left border is reached it cannot move anymore.

The wrapped line is still stored by the terminal as a single line,
despite now taking more than a single one when displayed. If you try to
resize the terminal you'll notice how the contents are reflowed and are
essentially illegible.

Querying the cursor position on non-Windows systems (plot twist,
Microsoft suggests using VT escape sequences on newer systems) is
extremely cumbersome so let's do something different.

Before printing anything let's save the cursor position and clear the
screen below the cursor, this way we ensure there's absolutely no trace
of stale data on screen, and after the message is printed we simply
restore it.
2021-03-07 15:23:20 +01:00
Veikka Tuominen
2d286100ef stage1: add tests for nosuspend async/resume 2021-03-07 15:30:59 +02:00
Jonathan Knezek
0447a2c041 Implement fmtDuration using Formatter (#8137)
* Implement fmtDuration using Formatter

Deprecate Duration, duration

* fmtDuration: Fixed ns remainder

* fmtDuration: Fixed visibility; removed [Dd]uration
2021-03-07 15:00:15 +02:00
LemonBoy
72664df491 std: Deprecate the B and Bi format specifiers
Following #8007 and #8137 let's get rid of the last weird format.
2021-03-07 14:58:45 +02:00
LemonBoy
e47b754b28 std: Prevent null pointer deref in mem.len{,Z}
Closes #8140
2021-03-07 14:58:45 +02:00
Evan Haas
6d69a29d75 translate-c: Support compound assignment of pointer and signed int
This handles `ptr += idx` and `ptr -= idx` when `idx` is a
signed integer expression.
2021-03-07 14:54:04 +02:00
Evan Haas
874c63f89c translate-c: translate align attribute for block scoped variables 2021-03-07 14:53:33 +02:00
Josh Wolfe
a7c0234eee docgen --skip-code-tests 2021-03-07 14:52:52 +02:00
Vincent Rischmann
272ae0ca0d fix parsing of assignment with 'inline for' and 'inline while' 2021-03-06 17:39:54 -08:00
Andrew Kelley
34cb5934dd Merge pull request #7910 from Vexu/stage2-async
Stage2: astgen async stuff, implement var args functions
2021-03-06 13:35:48 -08:00
Veikka Tuominen
8c6e7fb2c7 stage2: implement var args 2021-03-06 15:55:29 +02:00
Veikka Tuominen
17e6e09285 stage2: astgen async 2021-03-06 15:01:25 +02:00
Meghan
9f722f43ac std/special: init-exe,lib make import(std) its own decl (#8160)
std/special: init-exe,lib make import(std) its own decl
2021-03-05 19:13:05 -08:00
Isaac Freund
ef3adbdb36 zig fmt: fix lastToken() for container_decl_arg 2021-03-05 21:33:27 +01:00
xackus
eda1b53723 strip the leading zero from octal literals 2021-03-05 21:21:23 +01:00
xackus
eee43a65ae add tests 2021-03-05 21:21:23 +01:00
xackus
b4ef6fa09d fix test-translate-c 2021-03-05 21:04:27 +01:00
Maciej Walczak
5f53b77c2b remove redundant cast
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2021-03-05 21:04:27 +01:00
xackus
679910ecec translate-c: promote int literals to bigger types 2021-03-05 21:04:27 +01:00
Veikka Tuominen
9cd038d73a std: fix memory leak in MultiArrayList 2021-03-05 10:52:40 -08:00
Evan Haas
291edafa1b translate-c: enable pointer arithmetic with signed integer operand
Given a pointer operand `ptr` and a signed integer operand `idx`

`ptr + idx` and `idx + ptr` -> ptr + @bitCast(usize, @intCast(isize, idx))
`ptr - idx` -> ptr - @bitCast(usize, @intCast(isize, idx))

Thanks @LemonBoy for pointing out that we can take advantage of wraparound
to dramatically simplify the code.
2021-03-05 14:16:40 +02:00
cryptocode
02737d535a Reject bare +/- input when parsing floats 2021-03-05 13:11:20 +01:00
Andrew Kelley
434fce2146 zig fmt: recovery: missing while rbrace
Previously, this test case resulted in zig fmt entering an endless loop.
2021-03-04 20:54:09 -07:00
Andrew Kelley
bccef44196 Merge remote-tracking branch 'origin/master' into llvm12
Syncing with master branch because I want to re-run
update_clang_options.zig in the llvm12 branch.
2021-03-04 18:23:11 -07: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
98b24aa47f stage2: support environment variables for verbose options
The presence of ZIG_VERBOSE_LINK now enables --verbose-link.
The presence of ZIG_VERBOSE_CC now enables --verbose-cc.

These are useful when debugging usage of `zig cc` which does not have
CLI flags for these options, since they are not valid C compiler flags.
2021-03-04 17:37:53 -07:00
Andrew Kelley
ffb2568a9f Merge pull request #7763 from kivikakk/zig-elf-parse
std.elf: expose parsing decoupled from std.fs.File
2021-03-04 11:56:31 -08:00
daurnimator
34ca6b7b44 std: add io.Writer.writeStruct
We have readStruct, add writeStruct for symmetry
2021-03-03 22:45:45 +01:00
Andrew Kelley
fcd25065ef stage2: fix merge conflict with previous commit
The compiler failed to build from source; this fixes it.
2021-03-03 13:18:13 -07:00
jacob gw
2ebeb0dbf3 stage2: remove error number from error set map
This saves memory since it is already stored in module
as well as allowing for better threading.
Part 2 of what is outlined in #8079.
2021-03-03 11:49:54 -08:00
Veikka Tuominen
904f774563 translate-c: fix c tokenizer giving invalid tokens 2021-03-03 11:33:14 -08:00
Josh Wolfe
7fbe9e7d60 update docs and grammar to allow CRLF line endings (#8063) 2021-03-03 14:30:46 -05:00
Andrew Kelley
5bd9a64516 Merge pull request #7778 from g-w1/stage2-merge-errors
stage2: error set merging with tests
2021-03-02 23:19:22 -08:00
Andrew Kelley
3995783207 astgen: fix crash looking for wrong token in error sets
Fixes a regression from #7920.
2021-03-03 00:17:36 -07:00
Veikka Tuominen
ad3f7e0cf0 fix small inconsistency 2021-03-02 23:53:10 -07:00
g-w1
8b100792eb stage2: error set merging with tests
I had to come up with creative tests because we don't have error set type equality yet.
2021-03-02 23:53:05 -07:00
Andrew Kelley
4b57fb5f23 Merge pull request #7741 from FireFox317/optionals-llvm
stage2: add support for optionals in the LLVM backend
2021-03-02 21:03:50 -08:00
Andrew Kelley
713f113822 stage2: improve orelse implementation
* Now it supports being an lvalue (see additional lines in the test
   case).
 * Properly handles a pointer result location (see additional lines in
   the test case that assign the result of the orelse to a variable
   rather than a const).
 * Properly sets the result location type when possible, so that type
   inference of an `orelse` operand expression knows its result type.
2021-03-02 21:59:23 -07:00
Michael Dusan
0c06a1885f disable failing behavior tests with llvm 12
- consolidate into single code block

    See #8130
    See #8131
2021-03-02 20:14:10 -08:00
Timon Kruiper
6aa1ea9c59 stage2: fixup some formatting errors ({x} -> {s})
These were missed in cd7c870bd8
2021-03-02 19:02:55 -07:00
Timon Kruiper
ed6757ece6 stage2: add a test for for loops in LLVM backend 2021-03-02 19:02:55 -07:00
Timon Kruiper
d4ec0279d3 stage2: add support for optionals in the LLVM backend
We can now codegen optionals! This includes the following instructions:
- is_null
- is_null_ptr
- is_non_null
- is_non_null_ptr
- optional_payload
- optional_payload_ptr
- br_void

Also includes a test for optionals.
2021-03-02 19:02:55 -07:00
Isaac Freund
3ad9cb8b47 zig fmt: allow and trim whitespace around zig fmt: (off|on)
Currently `//  zig fmt: off` does not work as there are two spaces
after the `//` instead of one. This can cause confusion, so allow
arbitrary whitespace before the `zig fmt: (off|on)` in the comment but
trim this whitespace to the canonical single space in the output.
2021-03-03 01:06:09 +01:00
Andrew Kelley
8ca299ddbe disable failing behavior tests with llvm 12
See #8130
2021-03-02 16:54:46 -07:00
Andrew Kelley
84f3b3dff2 re-enable behavior tests: translate-c macros
These were temporarily disabled in
dd973fb365 and we forgot re-enable
them until now.
2021-03-02 16:32:52 -07:00
Andrew Kelley
934b170d67 Revert "update i386 assembly to satisify llvm12"
This reverts commit 6af6c3c979.
2021-03-02 15:03:19 -07:00
Andrew Kelley
c10a2d7649 stage2: use std.zig.fmtId for builtin.zig source 2021-03-02 15:00:10 -07:00
Andrew Kelley
70d100b1e2 update to latest std Thread API 2021-03-02 14:59:34 -07:00
Andrew Kelley
68c00122b1 x86: detect and set 16bit_mode and 32bit_mode CPU features 2021-03-02 14:49:28 -07:00
Vincent Rischmann
3dd8396a55 os/linux: fix IO_Uring.timeout
According to the io_uring PDF (https://kernel.dk/io_uring.pdf) the
timeout struct must be 64 bits on both 32 and 64 bit architectures.
2021-03-02 14:13:11 +02:00
Andrew Kelley
f296c95599 Merge pull request #8120 from joachimschmidt557/stage2-arm
stage2 ARM: implement basic integer multiplication
2021-03-01 19:11:37 -08:00
Andrew Kelley
f9c9b92175 Merge pull request #7946 from koachan/sparc64-framefixes
SPARCv9: Handle various stack frame related quirks.
2021-03-01 19:10:36 -08:00
Andrew Kelley
a20169a610 zig fmt the std lib 2021-03-01 20:04:28 -07:00
Martin Wickham
7613e51a57 Add some bit set variants 2021-03-01 18:52:15 -08:00
daurnimator
1f861ecc95 Bring back ZIG_SKIP_INSTALL_LIB_FILES 2021-03-01 16:23:10 -08:00
Isaac Freund
7b5b7bda87 parser: fix infinite loop on missing comma in param list 2021-03-01 16:09:57 -08:00
joachimschmidt557
278bd60732 stage2 ARM: Add tests for basic integer multiplication 2021-03-02 00:34:41 +01:00
LemonBoy
cd7c870bd8 std: Deprecate 'x'/'X'/'e'/'E' special cases for u8 slices
Let's follow the road paved by the removal of 'z'/'Z', the Formatter
pattern is nice enough to let us remove the remaining four special cases
and declare u8 slices free from any special casing!
2021-03-01 15:33:10 -08:00
joachimschmidt557
345ac53836 stage2 ARM: Implement basic integer multiplication 2021-03-02 00:14:56 +01:00
Timon Kruiper
939f334221 cmake: update findllvm.cmake file to include llvm12 libraries 2021-03-01 12:51:25 -08:00
Andrew Kelley
584cb2e4fb Merge remote-tracking branch 'origin/master' into llvm12 2021-03-01 12:09:26 -07:00
LemonBoy
bee7db77fe std: Replace lastIndexOf with lastIndexOfScalar
This may work around the miscompilation in LLVM 12.
2021-03-01 11:08:16 -08:00
Timon Kruiper
24215df8c5 zig c++: fix compilation that includes any c++ std library file
LLVM 12 included a patch that changed the way availability annotations
are specified. We now have to define the _LIBCPP_DISABLE_VISIBILITY_ANNOTATIONS
flag to make sure that we tell the c++ headers that we don't use
visibility annotations.

Related LLVM patch: D90843
2021-03-01 11:02:20 -08:00
fancl20
baab1b2f31 std: Add std.fs.path.joinZ (#7974)
* std: Add std.fs.path.joinZ

* Merge std.fs.path.join and std.fs.path.joinZZ tests
2021-03-01 10:38:56 +02:00
Evan Haas
45d220cac6 translate-c: add <assert.h> support
Implement __builtin_expect so C code that uses assert() can be translated.
2021-03-01 10:34:23 +02:00
Michael Dusan
85eb05e9a8 tools/update_cpu_features: fix usage() 2021-02-28 22:47:29 -08:00
Andrew Kelley
72404db31f stage1: update to LLVM 12 sret callsite requirements
Without this, the LLVM IR that zig generates cannot be compiled by LLVM.
2021-02-28 22:01:13 -07:00
Andrew Kelley
6af6c3c979 update i386 assembly to satisify llvm12
Without this, LLVM 12 says:
error: ambiguous instructions require an explicit suffix (could be
'retw', or 'retl')
2021-02-28 21:59:45 -07:00
Andrew Kelley
9550db33cb Merge pull request #8097 from LemonBoy/thread-spawn-order
std: Swap arguments in Thread.spawn
2021-02-28 20:42:34 -08:00
Frank Denis
a5a3ad4f95 std/crypto: add AES-OCB
OCB has been around for a long time.

It's simpler, faster and more secure than AES-GCM.

RFC 7253 was published in 2014. OCB also won the CAESAR competition
along with AEGIS.

It's been implemented in OpenSSL and other libraries for years.

So, why isn't everybody using it instead of GCM? And why don't we
have it in Zig already?

The sad reason for this was patents. GCM was invented only to work
around these patents, and for all this time, OCB was that nice
thing that everybody knew existed but that couldn't be freely used.

That just changed. The OCB patents are now abandoned, and OCB's
author just announced that OCB was officially public domain.
2021-02-28 20:40:49 -08:00
jacob gw
58b14d01ae stage2: remove value field from error
This saves memory and from what I have heard allows threading
to be easier.
2021-02-28 22:01:13 +02:00
daurnimator
1f17221bc4 std: add sendmsg 2021-02-28 21:57:43 +02:00
Evan Haas
294ee1bbc9 translate-c: add limited OffsetOfExpr support
Add support for OffsetOfExpr that contain exactly 1 component, when that component
is a field.

For example, given:

```c
struct S {
  float f;
  double d;
};
struct T {
  long l;
  int i;
  struct S s[10];
};
```

Then:
```c
offsetof(struct T, i)       // supported
offsetof(struct T, s[2].d)  // not supported currently
```
2021-02-28 21:56:57 +02:00
Frank Denis
0423f0f7d8 std/crypto/aes: fix AES {encrypt,decrypt}Wide
These functions are  not used by anything yet, but run the last
round only once.
2021-02-28 21:55:58 +02:00
Frank Denis
b959029f88 std/crypto/benchmark: update format strings
Use the s formatter to format strings.
2021-02-28 21:55:24 +02:00
LemonBoy
d3d3e55fae langref: Update usage of Thread.spawn() 2021-02-28 17:01:30 +01:00
LemonBoy
566adc2510 std: Swap arguments in Thread.spawn
Beside the new order being consistent with the ThreadPool API and making
more sense, this shuffling allows to write the context argument type in
terms of the startFn arguments, reducing the use of anytype (eg. less
explicit casts when using comptime_int parameters, yay).

Sorry for the breakage.

Closes #8082
2021-02-28 14:03:19 +01:00
Andrew Kelley
4b1fe8e492 glibc: clang 12 assembler regression workaround
Our glibc stub assembly file looked something like this:

```
.globl _Exit_2_2_5
.type _Exit_2_2_5, %function;
.symver _Exit_2_2_5, _Exit@@GLIBC_2.2.5
.hidden _Exit_2_2_5
_Exit_2_2_5:
```

With clang 12, the shared objects this produced stopped having any
exported symbols. When I removed the `.hidden` directive, it resolved
the issue, however, there are now unwanted exports:

```
$ readelf -W --dyn-syms libc.so.6 | grep sys_errlist
   139: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 _sys_errlist_GLIBC_2_3
   147: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 _sys_errlist_GLIBC_2_4
   395: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 _sys_errlist_GLIBC_2_2_5
   487: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 sys_errlist_GLIBC_2_2_5
  1266: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 _sys_errlist@@GLIBC_2.12
  1267: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 _sys_errlist@GLIBC_2.2.5
  1268: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 _sys_errlist@GLIBC_2.3
  1269: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 _sys_errlist@GLIBC_2.4
  2137: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 sys_errlist@@GLIBC_2.12
  2138: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 sys_errlist@GLIBC_2.2.5
  2139: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 sys_errlist@GLIBC_2.3
  2140: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 sys_errlist@GLIBC_2.4
  2156: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 sys_errlist_GLIBC_2_3
  2161: 000000000001ee08     0 FUNC    GLOBAL DEFAULT    7 sys_errlist_GLIBC_2_4
```

Every line here without an `@` symbol is an unwanted export. Before, the
unwanted ones had LOCAL HIDDEN linkage.

As a mitigation, I did two things:

 * Added `_GLIBC_` to the unwanted exports so that they would not
   conflict with anything.
 * Made the default export (the `@@` one) the bare symbol name. This
   appears to reduce the unwanted exports to only symbols that have more
   than one symbol (which is still quite many).

This will unblock progress on this branch, however, there is now a new
issue to solve, that the provided glibc stub .so files have too many
symbols exported. We will have to find a way to avoid this.
2021-02-28 00:53:05 -07:00
Andrew Kelley
ab36a162d0 update ARM target CPU features
This completes the process. All target CPU features are now
auto-generated by the tools/update_cpu_features.zig script, which
contains all the overrides.

Invoking this tool against LLVM 12rc2 now produces an empty git diff.
2021-02-27 21:10:00 -07:00
Andrew Kelley
85ab1b01e7 tools/update_cpu_features: add a "flatten" feature
and use it to clean up aarch64 target CPU features
2021-02-27 17:26:06 -07:00
Andrew Kelley
e02acc0288 tools/update_cpu_features: better patching API
With this change, added & modified cpus & features participate in the
same pruning system, and sorting takes into account the zig name, not
the pre-modified llvm name.

The modified target files in this commit are due to the improved
sorting and pruning.

The script now fully supports extra cpus & features.
2021-02-27 15:57:01 -07:00
Michael Dusan
e65b6d99ac std.zig.fmtEscapes: update impacted test 2021-02-27 12:53:49 -07:00
Michael Dusan
9082d76168 std.zig.fmtEscapes: update impacted test 2021-02-27 11:53:08 -08:00
Michael Dusan
6fe2fb6cdb std.Target.Abi: add gnuilp32 2021-02-27 11:53:08 -08:00
daurnimator
d4af35b3fe HashMap.put returns !void, not a !bool 2021-02-27 13:11:47 +02:00
Andrew Kelley
280195038a std.Target: add powerpcle 2021-02-27 02:51:35 -07:00
Andrew Kelley
9e8943736e Merge remote-tracking branch 'origin/master' into llvm12 2021-02-27 02:25:58 -07:00
Andrew Kelley
d91605e27e tools/update_cpu_features: consistent naming of neoverse cpus 2021-02-27 02:25:15 -07:00
Andrew Kelley
02bda72d91 update amdgpu target CPU features 2021-02-27 01:54:07 -07:00
Andrew Kelley
a9f19221e9 update RISC-V target CPU features 2021-02-27 01:49:35 -07:00
Andrew Kelley
490654c332 std.ascii: add lessThanIgnoreCase and orderIgnoreCase
For sorting ascii strings, case insensitively.
2021-02-27 01:21:01 -07:00
Andrew Kelley
4a548002af translate-c: upgrade to new std.zig.fmtEscapes API
fixes regressions from previous commit
2021-02-27 01:20:19 -07:00
Andrew Kelley
50a5fc98dc update most target CPU features to llvm12
The tools/update_cpu_features script is coming along, and generates
correct information for all these targets. The remaining targets are:

 * arm
 * aarch64
 * amdgpu
 * riscv

I will commit them once the issues with the updater tool are resolved.
2021-02-27 01:05:53 -07:00
Andrew Kelley
59b4facd34 update x86 CPU features 2021-02-27 00:54:40 -07:00
Andrew Kelley
45739725c1 tools/update_cpu_features: prune redundant features
When a CPU feature implies that another one must be present, avoid
redundantly specifying the other one.
2021-02-27 00:50:23 -07:00
Andrew Kelley
3f844cba0b std.zig.fmt escaped string formatting recognizes single quote style
This introduces {'} to indicate escape for a single-quoted string,
and {} to indicate escape for a double quoted string.

Without this, there would be unnecessary \' inside double quoted
strings, and unnecessary \" inside single quoted strings.

Motivated by the llvm12 branch, in the new tool I am writing for
updating target CPU features.
2021-02-27 00:27:53 -07:00
Andrew Kelley
03de5ec6dd tools/update_cpu_features: handle ISAs with no features
These are represented by not having a file for them.
2021-02-26 23:52:04 -07:00
Andrew Kelley
a804944c7d tools/update_cpu_features: branch quota where necessary
also avoid unnecessary escaping of single quotes inside double quoted
strings (depends on a master branch commit that will be merged into this
branch in a future commit)
2021-02-26 23:21:05 -07:00
Andrew Kelley
2733ca91b2 introduce tools/update_cpu_features.zig
This replaces the previous target cpu features tool, taking advantage of
llvm-tblgen --dump-json instead of trying to use python to parse the .td
files.

This is an initial version that has the basics working, including a
simple feature override system, as well as multi-threaded processing.

Follow-up commits will do clean ups to make the diff of the newly generated
source files against previous versions be as desired.
2021-02-26 21:16:04 -07:00
Andrew Kelley
3519b74c06 zig cc: update clang command line options to LLVM 12 rc2 2021-02-26 15:00:41 -07:00
Michael Dusan
659f712ae8 llvm12: sync with llvmorg-12.0.0-rc2
- update lib/include
- update lib/libcxx
- update lib/libcxxabi
- update lib/libunwind
- (no changes) src/libcxx.zig
- (no changes) src/libunwind.zig
2021-02-26 13:44:33 -08:00
LemonBoy
b706b9bce7 stage1: Fix emission of sret annotation for LLVM
LLVM12 deprecated `sret` and replaced it with the `sret(<Ty>)` form.

Closes #8075
2021-02-26 12:48:27 -08:00
Andrew Kelley
431801707f Revert "stage1: upgrade to new LLVM sret attribute requirement"
This reverts commit 685b5c26b7.

@LemonBoy has a better patch, so reverting this to merge that one.
2021-02-26 13:47:33 -07:00
Andrew Kelley
685b5c26b7 stage1: upgrade to new LLVM sret attribute requirement
LLVM 12 requires sret attributes to have the struct type as a parameter,
and provides no C function for supplying it. Therefore, we must add
another C++ wrapper API for adding the sret attribute.

Fixes ability to build from source in the llvm12 branch.
2021-02-26 13:32:04 -07:00
Evan Haas
0816981561 translate-c: add typeof support 2021-02-25 22:33:42 -08:00
Andrew Kelley
70e935db5b translate-c: fix botched merge conflict
Previous commit failed to correctly solve the translate-c merge
conflict; this commit fixes it.
2021-02-25 21:27:56 -07:00
Andrew Kelley
0b58b61799 Merge remote-tracking branch 'origin/master' into llvm12
Conflicts:
 * src/clang.zig
 * src/llvm.zig
   - this file got moved to src/llvm/bindings.zig in master branch so I
     had to put the new LLVM arch/os enum tags into it.
 * lib/std/target.zig, src/stage1/target.cpp
   - haiku had an inconsistency with its default target ABI, gnu vs
     eabi. In this commit we make it gnu in both places to match the
     latest changes by @hoanga.
 * src/translate_c.zig
2021-02-25 21:04:23 -07:00
Michael Dusan
dc325669e3 fix to compile against 12.0.0-rc2 2021-02-25 19:41:30 -08:00
Andrew Kelley
fd208d9d59 stage2: implement the error_value AST tag 2021-02-25 18:21:22 -07:00
Andrew Kelley
4360f45d7f std.os: remove special case for haiku
This is an accident from a merge conflict introduced in
7edb204edf.

The new pipe2 code I believe is supposed to work for all posix-like
systems. If haiku needs special handling here, it should be
re-introduced.
2021-02-25 17:42:14 -07:00
g-w1
153c97ac9e improve stage2 to allow catch at comptime:
* add error_union value tag.
* add analyzeIsErr
* add Value.isError
* add TZIR wrap_errunion_payload and wrap_errunion_err for
  wrapping from T -> E!T and E -> E!T
* add anlyzeInstUnwrapErrCode and analyzeInstUnwrapErr
* add analyzeInstEnsureErrPayloadVoid:
* add wrapErrorUnion
* add comptime error comparison for tests
* tests!
2021-02-25 16:41:16 -08:00
Andrew Kelley
7edb204edf Merge pull request #7546 from hoanga/haiku-support
initial support for haiku
2021-02-25 16:00:00 -08:00
Andrew Kelley
37a1d08de2 haiku: minor fixups
* no isHaiku() function since there is not more than one os tag that
   this applies to.
 * clean up some control flow into a switch
 * add some TODO comments to investigate panics that suspiciously look
   like they should be compile errors (see #363)
2021-02-25 16:54:32 -07:00
Al Hoang
96a08c1698 initial support for haiku defer debug 2021-02-25 16:41:42 -07:00
Al Hoang
c17396691c initial support for haiku sync update
* add cpu count
* use haiku find_directory
* add definitions and exports for building in haiku
2021-02-25 16:41:42 -07:00
Al Hoang
6b0372229d initial support for haiku continue clean up
* remove unused definitions
* setup os specific blocks
2021-02-25 16:41:42 -07:00
Al Hoang
025635c3f8 initial support for haiku past stage0 2021-02-25 16:41:42 -07:00
joachimschmidt557
297eabd4ac stage2 ARM: Save callee-saved registers
Add a new allocated_registers bitmap to keep track of all callee-saved
registers allocated during generation of this function.

Function(.arm).gen uses this data to generate instructions in the
function prologue and epilogue to push and pop these registers
respectively.
2021-02-25 22:27:19 +02:00
Hubert Jasudowicz
3c0238e731 std/build: Add support for LTO configuration 2021-02-25 22:25:42 +02:00
Evan Haas
4f11a88b9f translate-c: Add support for pointer subtraction
When two pointers are subtracted, both shall point to elements of the
same array object, or one past the last element of the array object;
the result is the difference of the subscripts of the two array elements.

The size of the result is implementation-defined, and its type
(a signed integer type) is ptrdiff_t defined in the <stddef.h> header.
If the result is not representable in an object of that type,
the behavior is undefined.

See C Standard, §6.5.6 [ISO/IEC 9899:2011]

Fixes #7216
2021-02-25 22:24:11 +02:00
LemonBoy
53cc63f0c9 std: Clear old memory on free
Re-enable the clear-on-free step, it was previously disabled due to
translate-c using freed memory.
2021-02-25 22:20:30 +02:00
Andrew Kelley
449f4de382 zig fmt src/ 2021-02-24 21:54:23 -07:00
Andrew Kelley
9b8a94265a zig fmt: fix extern function with missing param name
Regressed in d7049fc8e0.
2021-02-24 21:50:57 -07:00
Andrew Kelley
5f35dc0c0d zig fmt the std lib 2021-02-24 21:29:23 -07:00
Andrew Kelley
d7049fc8e0 Merge pull request #7920 from ziglang/ast-memory-layout
Rework AST memory layout for better memory usage and performance
2021-02-24 18:49:07 -08:00
Andrew Kelley
9ada7638a5 zig fmt: function with labeled block as return type 2021-02-24 16:42:46 -07:00
Andrew Kelley
c79ee1fc8d build.zig: expose a strip option 2021-02-24 16:36:27 -07:00
Andrew Kelley
8e6c2b7a47 Merge remote-tracking branch 'origin/master' into ast-memory-layout 2021-02-24 15:08:23 -07:00
Andrew Kelley
38441b5eab MultiArrayList: use @memcpy as a workaround
Reverts bf642204b3 and uses a different
workaround, suggested by @LemonBoy.

There is either a compiler bug or a design flaw somewhere around here.
It does not have to block this branch, but I need to understand exactly
what's going on here and make it so that nobody ever has to run into
this problem again.
2021-02-24 12:49:12 -07:00
Isaac Freund
52c45bf44d zig fmt: rework single statement if/while/for indentation
This approach properly handles nesting unlike the approach in the
previous commit.
2021-02-24 17:28:29 +01:00
Josh Wolfe
8b9434871e Avoid concept of a "Unicode character" in documentation and error messages (#8059) 2021-02-24 08:26:13 -05:00
Isaac Freund
371b21bdfb zig fmt: fix comment indent after multiline single statement if/while/for 2021-02-24 13:46:11 +01:00
Isaac Freund
15c7c6ab97 zig fmt: handle comments in switch case value list 2021-02-24 12:29:17 +01:00
Isaac Freund
1b8eca030e zig fmt: fix firstToken() for switch_case 2021-02-24 12:14:15 +01:00
Andrew Kelley
db4c15be50 zig fmt: respect extra newline between fn and pub usingnamespace 2021-02-23 23:01:16 -07:00
Andrew Kelley
bf642204b3 std.MultiArrayList: add workaround for LLVM bug 2021-02-23 22:24:59 -07:00
Andrew Kelley
05f304807f zig fmt: add 3 more disabled failing test cases
Found by running `zig fmt` on the std lib.
2021-02-23 18:48:01 -07:00
Andrew Kelley
4420fe97be zig fmt: for loop with ptr payload and index 2021-02-23 18:33:13 -07:00
Andrew Kelley
988f1c6a6f zig fmt: fn proto end with anytype and comma
also

zig fmt: space after top level doc comment
2021-02-23 18:23:49 -07:00
Andrew Kelley
08107a555e zig fmt: fix inline assembly test cases
All zig fmt test cases are now passing again in this branch.
2021-02-23 17:19:01 -07:00
Andrew Kelley
bb89c619ed zig fmt: multiline string literals + array init 2021-02-23 17:00:33 -07:00
Andrew Kelley
6f4a1bafcf zig fmt: fn call with comments and multiline strings
forcing the parameters over multiple lines
2021-02-23 16:09:51 -07:00
Isaac Freund
4ee368c4b3 zig fmt: comments/line breaks in field access chain 2021-02-23 23:17:38 +01:00
Andrew Kelley
ca9259340d zig fmt now intentionally respects all empty line comments 2021-02-23 14:30:21 -07:00
Andrew Kelley
f041425e48 translate-c: fix using wrong slice and AST tag 2021-02-23 13:55:12 -07:00
Andrew Kelley
01e89c9171 translate-c: update to latest AST tag changes 2021-02-23 12:39:50 -07:00
Isaac Freund
b028a92a60 zig fmt: handle comments in array type/init/access 2021-02-23 19:56:56 +01:00
Isaac Freund
abfe213830 zig fmt: enable array init trailing comment insertion test
Modify the test case slightly to match similar modifications done in
5820bd0 and 0f24b61.
2021-02-23 19:40:34 +01:00
Isaac Freund
6b9f19a644 zig fmt: remove stray std.debug.print() 2021-02-23 19:18:36 +01:00
Isaac Freund
0f24b61ed5 zig fmt: insert trailing comma in struct init with comment 2021-02-23 19:17:11 +01:00
Isaac Freund
5820bd0e64 zig fmt: insert trailing comma in fn params with comment 2021-02-23 19:11:50 +01:00
Isaac Freund
5306b1a9ab zig fmt: container doc comments 2021-02-23 18:32:47 +01:00
johnLate
d9e46dceec std.Thread.Semaphore: Fix wrong variable name
Fixes ziglang#8052
2021-02-23 11:10:24 +02:00
Veikka Tuominen
1f62e87031 fix formatting in translate-c test case 2021-02-23 10:53:25 +02:00
Andrew Kelley
1e3a200ba6 zig fmt: array literal with hint
This regresses the test case of `zig fmt` deleting empty line comments.
Two open questions here:

 * What should the rules be about deleting empty line comments?
   It makes sense usually, but for array initization, empty line
   comments cause a line break, affecting the row/column alignment.
   Perhaps we should therefore respect all empty line comments?
   Or should we special case array initializations?

 * If we decide to special case some kinds of line comments to respect
   them (which is status quo!), how should that be implemented?
2021-02-22 23:25:12 -07:00
Andrew Kelley
1253903fef zig fmt: struct literal containing a multiline expression
I modified this test case to expect different results.

Now, the trailing comma on a list of struct fields is the only deciding
factor, not whether or not the field init expressions contain a newline.
2021-02-22 21:33:21 -07:00
Andrew Kelley
8379fff804 zig fmt: alignment in anonymous literal 2021-02-22 21:04:22 -07:00
Andrew Kelley
a6038f0375 zig fmt: function params should align nicely 2021-02-22 18:17:26 -07:00
Andrew Kelley
fec51ad7c5 zig fmt: while 2021-02-22 17:55:19 -07:00
Andrew Kelley
20cfa0b5b6 zig fmt: if condition has line break, no fn call comma 2021-02-22 17:34:30 -07:00
Andrew Kelley
ec987a7a46 zig fmt: if condition has line break but must not wrap 2021-02-22 16:39:50 -07:00
Andrew Kelley
b301999cd3 zig fmt: if condition wraps 2021-02-22 16:21:19 -07:00
Andrew Kelley
253906fb93 zig fmt: 2nd arg multiline string 2021-02-22 16:00:21 -07:00
Isaac Freund
45634851de zig fmt: fix firstToken() for extern fn_protos 2021-02-22 23:51:54 +01:00
Isaac Freund
550688f427 zig fmt: insert trailing comma in switches 2021-02-22 23:51:54 +01:00
Veikka Tuominen
4758e0c9a6 update docgen to use new ast 2021-02-22 21:52:22 +02:00
Veikka Tuominen
d83698ab54 translate-c: check for noreturn in switch in more cases 2021-02-22 21:52:22 +02:00
Isaac Freund
f3ee10b454 zig fmt: fix comments ending with EOF after decls
Achieve this by reducing the amount of special casing to handle EOF so
that the already correct logic for normal comments does not need to be
duplicated.
2021-02-22 18:32:37 +01:00
Veikka Tuominen
011bc1b84f translate-c: switch default should have an empty block not break 2021-02-22 19:26:19 +02:00
Isaac Freund
ce9b3ee0f9 parser: anytype is not a vaild return type 2021-02-22 17:38:09 +01:00
Isaac Freund
34c08a91d5 zig fmt: fix formatting of parser tests 2021-02-22 17:37:17 +01:00
Veikka Tuominen
928790364a zig fmt: correct Node.firstToken for .fn_decl, add error for missing container 2021-02-22 17:39:41 +02:00
Veikka Tuominen
69d5a106da render: handle comments ending in EOF 2021-02-22 16:59:44 +02:00
Veikka Tuominen
67dac2936c parser: warn on missing for loop payload, recover from invalid global error set access 2021-02-22 10:04:05 +02:00
Andrew Kelley
621ad241d6 zig fmt: if nested 2021-02-21 20:25:31 -07:00
Andrew Kelley
a17a5ca3a8 translate-c: fix fn_decl vs fn_proto
Regressed in 15603f403c.
2021-02-21 18:31:32 -07:00
Andrew Kelley
c6efb23796 zig fmt: rewrite inline functions as callconv(.Inline) 2021-02-21 18:20:46 -07:00
Andrew Kelley
878e99d580 parser: fix recovery for missing semicolons 2021-02-21 18:04:23 -07:00
Andrew Kelley
1247b7b9ef parser: modify another recovery test case
Zig no longer has `error` as the global error set; it is now a special
case keyword. The new parse error message is correct.
2021-02-21 18:00:37 -07:00
Andrew Kelley
79f1876367 parser: remove support for recovering from extra top level end curlies
After #35 is implemented,
we should be able to recover from this *at any indentation level*,
reporting a parse error and yet also parsing all the decls even
inside structs. Until then, I don't want to add any hacks to make
this work.
2021-02-21 17:57:04 -07:00
Andrew Kelley
2da2123128 parser: remove support for a recovery test case
I don't understand the idea here of this kind of recovery. If we
want to resurrect this test case we need some comments on it to explain
the purpose, example use cases, expected behavior, etc.
2021-02-21 17:37:39 -07:00
Andrew Kelley
866f7dc7d6 parser: support more recovery test cases 2021-02-21 17:37:10 -07:00
Andrew Kelley
15603f403c AST: use fn_proto not fn_decl for extern decls
saves a few bytes per extern function declaration
2021-02-21 16:01:22 -07:00
ducdetronquito
0aef1faa82 std.fifo.LinearFifo - Expose reader and writer type. 2021-02-22 00:22:46 +02:00
Ryan Greenblatt
36178caf3e Added support for passing write file args as build options (#7909)
* Added support for passing write file args as build options

* Fix missing fmtEscapes and unused format

* Actually fixed now, must be formatted

* remove addPathBuildOption
2021-02-21 12:26:46 +02:00
joachimschmidt557
9712e89265 stage2 codegen: Add Type argument to genSetReg 2021-02-21 12:23:36 +02:00
Veikka Tuominen
ef6aa3d027 Merge pull request #7960 from Luukdegram/wasm-extern
stage2: Add support for extern functions for the wasm backend
2021-02-21 12:22:01 +02:00
LemonBoy
057bf1afc9 std: Add more error checking in hexToBytes
Prevent the function from turning into an endless loop that may or may
not perform OOB accesses.
2021-02-21 12:19:03 +02:00
Asherah Connor
4272f07f66 std.os.uefi.Guid fixes (#8032)
* uefi: Guid.format compiles again

Also use "writer" nomenclature in argument name.

* uefi: add Guid.eql
2021-02-21 12:17:59 +02:00
Bill Nagel
cc5e5cca83 fix race condition in linuxWaitFd 2021-02-21 12:16:48 +02:00
jacob gw
1bd434fd18 std.Progress: improve support for "dumb" terminals 2021-02-21 12:12:17 +02:00
Tau
840331ee48 Rebase link(at) properly 2021-02-21 12:04:40 +02:00
Benjamin Graf
c70832bc41 replace ArrayList.shrinkAndFree by ArrayList.shrinkRetainingCapacity 2021-02-21 11:56:14 +02:00
Jonathan Marler
a448210fcf remove z/Z format specifier deprecations
The z/Z format specifiers were merged last October (4 months ago).  They were then deprecated in January (just over a month ago).  This PR removes them altogether.
2021-02-21 11:55:21 +02:00
rgreenblatt
f9be7471bc fix readable slice bug (and add tests) 2021-02-21 11:48:38 +02:00
data-man
340825a7af Add epoll_pwait2 Linux syscall 2021-02-21 11:47:13 +02:00
Andrew Kelley
88d0e77b97 parse: implement error for invalid bit range and alignment 2021-02-21 00:18:20 -07:00
rgreenblatt
a5dcd07382 fix unspecified fmt 2021-02-21 01:31:46 +02:00
Veikka Tuominen
4074e79748 translate-c: use global scope for typedef/record/enum type translation if needed
If the type is a reference to a global declaration that has not yet
been translated we need to use the global scope for translation
so that other functions can also reference it.
2021-02-20 13:32:07 +02:00
Andrew Kelley
669c2054a8 stage2: debug line nops supports bigger padding 2021-02-19 22:55:42 -07:00
Andrew Kelley
ed1e5cb3f6 stage2: fix a couple off by one errors
All stage2 tests are passing again in this branch.

Remaining checklist for this branch:
 * get the rest of the zig fmt test cases passing
   - re-enable the translate-c test case that is blocking on this
 * implement the 2 `@panic(TODO)`'s in parse.zig
 * use fn_proto not fn_decl for extern function declarations
2021-02-19 21:47:11 -07:00
Michael Dusan
153cd4da0c macos: fix cond to enable ZIG_SYSTEM_LINKER_HACK
closes #8037
2021-02-19 23:37:13 -05:00
Andrew Kelley
5b597a16c6 stage2: fix not setting up ZIR arg instruction correctly
This is a regression from when I briefly flirted with changing how arg
ZIR instructions work in this branch, and then failed to revert it
correctly.
2021-02-19 20:57:06 -07:00
Andrew Kelley
d8560edc29 stage2: fix incorrect ast.Tree.getNodeSource impl 2021-02-19 20:28:47 -07:00
Andrew Kelley
70761d7c52 stage2: remove incorrect newlines from log statements 2021-02-19 20:27:06 -07:00
Andrew Kelley
6959b177ef stage2: test harness: panic on OOM rather than assert
also add a prefix to test names for C backend
2021-02-19 20:26:48 -07:00
Andrew Kelley
8fee41b1d5 stage2: AST: clean up parse errors
* struct instead of tagged union
 * delete dead code
 * simplify parser code
 * remove unnecessary metaprogramming
2021-02-19 18:04:52 -07:00
Andrew Kelley
74878565e5 readme: update introduction link 2021-02-19 16:38:04 -07:00
Isaac Freund
95b95ea33e stage2: make same line doc comments a parse error
Allowing same line doc comments causes some ambiguity as to how
generated docs should represent the case in which both same line
and preceding line doc comments are present:

/// preceding line
const foobar = 42; /// same line

Furthermore disallowing these makes things simpler as there is now only
one way to add a doc comment to a decl or struct field.
2021-02-19 22:59:27 +01:00
Veikka Tuominen
6f6568b1fd translate-c: correctly add semicolon to if statements 2021-02-19 20:48:06 +02:00
Veikka Tuominen
d672c20b8a Merge pull request #7479 from ziglang/translate-c-ast
Make translate-c use intermediate AST
2021-02-19 13:03:29 +02:00
Veikka Tuominen
974a1c5525 translate-c: small fixes to avoid generating invalid code for macros 2021-02-19 12:50:42 +02:00
Andrew Kelley
914540ddb5 astgen: fix remaining compile errors
Now it builds and what remains in this branch is:
 * fix the stage2 compiler regressions from this branch
 * finish the rest of zig fmt test cases, get them passing
 * Merge in Vexu's translate-c AST branch & fix translate-c regressions
2021-02-19 00:04:31 -07:00
Andrew Kelley
9010bd8aec stage2: astgen: fix most of the remaining compile errors
more progress on converting astgen to the new AST memory layout.
only a few code paths left to update.
2021-02-18 20:09:29 -07:00
Veikka Tuominen
3aba1fa04f translate-c: ensure failed macros don't get defined multiple times 2021-02-19 01:52:27 +02:00
Veikka Tuominen
df5a8120df translate-c: small miscellaneous improvements 2021-02-18 21:34:31 +02:00
Andrew Kelley
29daf10639 stage2: fix a couple more compilation errors 2021-02-17 22:34:06 -07:00
Andrew Kelley
5a2620fcca stage2: fix some of the compilation errors in this branch 2021-02-17 22:22:10 -07:00
Andrew Kelley
c66481f9bc astgen: finish updating expressions to new mem layout
Now all that is left is compile errors and whatever regressions this
branch introduced.
2021-02-17 20:59:21 -07:00
Veikka Tuominen
7ca53bdfaa translate-c: improve switch translation 2021-02-17 22:11:26 +02:00
Evan Haas
3717bedb4e translate-c: Add test for using correct block label for StmtExpr
The previous iteration of translate-c used an incorrect block label
in the break statement for a translated C statement expression. This adds
a test to ensure the correct label is used in the new intermediate AST
version of translate-c.
2021-02-17 16:27:21 +02:00
Veikka Tuominen
d5fecbd0ba translate-c: support scoped typedef, enum and record decls
Closes #5256
2021-02-17 16:26:11 +02:00
Veikka Tuominen
e2974759dd translate-c: demote untranslatable declarations to externs 2021-02-17 14:11:49 +02:00
Mathieu Guay-Paquet
93f8110e5d Allow async in nosuspend scope
Starting an async function call is actually a synchronous operation,
since the caller is not awaiting on the callee for a return value.

This commit removes the compiler code which generates the error and
updates the relevant test case.

In the presence of CallModifierAsync, the callee is expected to
suspend, so it should not be changed to CallModifierNoSuspend.
2021-02-16 23:43:36 -05:00
Mathieu Guay-Paquet
c0cfbe98f3 Allow resume in nosuspend scope
Resuming a suspended async function call is actually a synchronous
operation.

This commit removes the compiler code which generates the error and
updates the relevant test case.
2021-02-16 21:51:19 -05:00
Isaac Freund
4b226286e8 zig fmt: get rid of Space.no_comment
Using this in its current state would be a bug as it could cause line
comments to be deleted or a `// zig fmt: (on|off)` directive to be
missed.

Removing it doesn't currently cause any test failures, if a reason for
its continued existence is discovered in the future another solution
will have to be found.
2021-02-17 00:03:39 +01:00
Isaac Freund
895fb2bd6d zig fmt: implement 'zig fmt: (on|off)' directives
With the new implementation, these now work anywhere in the source code
as opposed to only at the top level.
2021-02-16 23:20:53 +01:00
Isaac Freund
070e548acf std: remove io.AutoIndentingStream
This type is not widely applicable enough to be a public part of the
public interface of the std.

The current implementation in only fully utilized by the zig fmt
implementation, which could benefit by even tighter integration as
will be demonstrated in the next commit. Therefore, move the current
io.AutoIndentingStream to lib/std/zig/render.zig.

The C backend of the self hosted compiler also use this type currently,
but it does not require anywhere near its full complexity. Therefore,
implement a greatly simplified version of this interface in
src/codegen/c.zig.
2021-02-16 23:20:46 +01:00
Andrew Kelley
68e7726478 std.fs.net.Stream: add writev and writevAll
I noticed that the write function does not properly use non-blocking
I/O. This file needs to be reworked for evented I/O to properly take
advantage of non-blocking writes to network sockets.
2021-02-16 11:01:17 -07:00
Veikka Tuominen
9a826ccbe0 translate-c: elide some unecessary casts of literals 2021-02-16 16:40:43 +02:00
Veikka Tuominen
74e9d4ca82 translate-c: get all translate-c tests passing 2021-02-16 16:40:43 +02:00
Veikka Tuominen
78fba4e021 translate-c: get all run-translated-c tests passing 2021-02-16 16:40:43 +02:00
Veikka Tuominen
77a11e6873 translate-c: render records and enums 2021-02-16 16:40:43 +02:00
Veikka Tuominen
c0540967e9 translate-c: render array stuff 2021-02-16 16:40:43 +02:00
Veikka Tuominen
62162a0717 translate-c: render control flow 2021-02-16 16:40:42 +02:00
Veikka Tuominen
c4dfabf4dc translate-c: render macro functions, use cast type as return type
Closes #8004
2021-02-16 16:40:42 +02:00
Veikka Tuominen
f191251ddb translate-c: render functions 2021-02-16 16:40:42 +02:00
Veikka Tuominen
227f167958 translate-c: render binops and break/continue 2021-02-16 16:40:42 +02:00
Veikka Tuominen
685778c5a7 translate-c: render unary ops 2021-02-16 16:40:42 +02:00
Veikka Tuominen
1147ecc5fd translate-c: render variables and builtin calls 2021-02-16 16:40:42 +02:00
Veikka Tuominen
d7460db044 translate-c: render a bunch of simple nodes and calls 2021-02-16 16:40:39 +02:00
Veikka Tuominen
13a9db2085 translate-c: begin implementing ast.render 2021-02-16 16:40:06 +02:00
Veikka Tuominen
2a74a1ebaa translate-c: bunch of small fixes to get it compiling 2021-02-16 16:40:06 +02:00
Veikka Tuominen
66bbd75a83 translate-c: convert macro translation 2021-02-16 16:40:06 +02:00
Veikka Tuominen
c30c2f7c13 translate-c: convert assignment and conditional exprs 2021-02-16 16:40:05 +02:00
Veikka Tuominen
450b718b9e translate-c: convert field/array access, call, pre/postcrement 2021-02-16 16:40:05 +02:00
Veikka Tuominen
cadd4483be translate-c: convert switch 2021-02-16 16:40:05 +02:00
Veikka Tuominen
66dd64ec15 translate-c: convert most control flow 2021-02-16 16:40:05 +02:00
Veikka Tuominen
d8b9fca0b1 translate-c: convert casts and string/array init 2021-02-16 16:40:05 +02:00
Veikka Tuominen
5dac3683c9 translate-c: convert record and enum decls 2021-02-16 16:40:05 +02:00
Veikka Tuominen
bb867b071a translate-c: convert vardecl and typedef 2021-02-16 16:40:02 +02:00
Veikka Tuominen
f36849fed2 translate-c: convert function translation 2021-02-16 16:37:08 +02:00
Veikka Tuominen
7514c0ad0d translate-c: unary operator, integers and misc 2021-02-16 16:37:08 +02:00
Veikka Tuominen
f5041caa2e translate-c: more binaryoperator chagnes, blocks and unary type expressions 2021-02-16 16:37:07 +02:00
Veikka Tuominen
4c0c9b0755 translate-c: convert transBinaryOperator 2021-02-16 16:37:07 +02:00
Veikka Tuominen
d835f5cce5 translate-c: make Node more like Type 2021-02-16 16:37:07 +02:00
Veikka Tuominen
6ecec4c8b7 translate-c: translate C types to stage2 types 2021-02-16 16:37:07 +02:00
Veikka Tuominen
7051ef32bf translate-c: start creating intermediate AST 2021-02-16 16:37:07 +02:00
Andrew Kelley
4006a3afb3 astgen: update more expression types to new mem layout
additionally introduce a new file to centralize all the data about
builtin functions that we have, including:
 * enum tag identifying the builtin function
 * number of parameters.
 * whether the expression may need a memory location.
 * whether the expression allows an lvalue (currently only true for
   `@field`).
Now there is only one ComptimeStringMap that has this data as the value,
and we dispatch on the enum tag in order to asgen the builtin function.
In particular this simplifies the logic for checking the number of
parameters.

This removes some untested code paths from if and while, which need to
be restored with #7929 in mind.

After this there are only a handful left of expression types to rework
to the new memory layout, and then it will be only compile errors left
to solve.
2021-02-15 22:36:46 -07:00
Isaac Freund
bbf5a4d7c5 zig fmt: fix inferred error union return types 2021-02-15 13:54:48 +01:00
Andrew Kelley
c2b4d51749 astgen: update a handful of expression types to new mem layout
break, continue, blocks, bit_not, negation, identifiers, string
literals, integer literals, inline assembly

also gave multiline string literals a different node tag from regular
string literals, for code clarity and to avoid an unnecessary load from
token_tags array.
2021-02-13 21:40:12 -07:00
Isaac Freund
24798b84ad zig fmt: implement multiline string literals 2021-02-13 16:57:34 -08:00
Isaac Freund
75ba8d8db6 zig fmt: remove empty lines at start/end of block 2021-02-13 16:57:34 -08:00
Andrew Kelley
7630a5c566 stage2: more progress towards Module/astgen building with new mem layout 2021-02-12 23:47:17 -07:00
Tadeo Kondrak
9270aae071 stage2: fix zero-sized function parameters (#7998) 2021-02-12 15:40:44 -05:00
Andrew Kelley
a9db40e870 zig fmt: add failing test case for inline/callconv conversion 2021-02-11 23:53:04 -07:00
Andrew Kelley
b4e344bcf8 Merge remote-tracking branch 'origin/master' into ast-memory-layout
Conflicts:
 * lib/std/zig/ast.zig
 * lib/std/zig/parse.zig
 * lib/std/zig/parser_test.zig
 * lib/std/zig/render.zig
 * src/Module.zig
 * src/zir.zig

I resolved some of the conflicts by reverting a small portion of
@tadeokondrak's stage2 logic here regarding `callconv(.Inline)`.
It will need to get reworked as part of this branch.
2021-02-11 23:45:40 -07:00
Andrew Kelley
3d0f4b9030 stage2: start reworking Module/astgen for memory layout changes
This commit does not reach any particular milestone, it is
work-in-progress towards getting things to build.

There's a `@panic("TODO")` in translate-c that should be removed when
working on translate-c stuff.
2021-02-11 23:29:55 -07:00
Veikka Tuominen
288e180598 snake_case render.Space 2021-02-12 02:14:07 +02:00
Veikka Tuominen
bb22490fcc snake_case Node.Tag 2021-02-12 02:12:43 +02:00
Veikka Tuominen
e2289961c6 snake_case Token.Tag 2021-02-12 02:12:00 +02:00
Andrew Kelley
d3565ed6b4 Merge pull request #7749 from tadeokondrak/6429-callconv-inline
Replace inline fn with callconv(.Inline)
2021-02-11 16:01:58 -08:00
Isaac Freund
faa3fa65ac zig fmt: implement line comments 2021-02-11 15:49:49 -08:00
Isaac Freund
b6448a533d zig fmt: fix Tree.lastToken() for empty *Two nodes 2021-02-11 15:49:49 -08:00
Evan Haas
d98f09e4f6 translate-c: comma operator should introduce a new scope
This prevents inadvertent side-effects when an expression is not evaluated
due to boolean short-circuiting

Fixes #7989
2021-02-12 01:40:43 +02:00
Tadeo Kondrak
bb4f4c043e test/cli.zig: Remove inline from panic function in testGodboltApi
Might add another line to stack traces there.
2021-02-10 20:22:20 -07:00
Tadeo Kondrak
bcc13597fc translate_c: switch from inline fn to callconv(.Inline) 2021-02-10 20:22:19 -07:00
Tadeo Kondrak
7644e9a752 stage2: switch from inline fn to callconv(.Inline) 2021-02-10 20:22:18 -07:00
Tadeo Kondrak
1c15091bc8 stage1: switch from inline fn to callconv(.Inline) 2021-02-10 20:06:13 -07:00
Tadeo Kondrak
5dfe0e7e8f Convert inline fn to callconv(.Inline) everywhere 2021-02-10 20:06:12 -07:00
Tadeo Kondrak
9c797fe3ac std.zig: reformat inline fn to callconv(.Inline) 2021-02-10 20:06:11 -07:00
Jonathan Marler
61bcac108c Add more mingw def files
I've added more of the ".def" files from mingw. The list is based on all the libraries referenced by the win32metadata project. (see https://github.com/marlersoft/zigwin32).
2021-02-10 13:38:16 -08:00
Isaac Freund
4c8caf3343 zig fmt: implement Tree.lastToken() for all nodes 2021-02-10 11:53:53 -08:00
Isaac Freund
515d4920e7 zig fmt: fix 0 element struct and array init 2021-02-10 11:53:53 -08:00
Isaac Freund
5df7fc36c6 zig fmt: implement Tree.lastToken() for struct init 2021-02-10 11:53:53 -08:00
Isaac Freund
928f6f48a6 zig fmt: implement Tree.lastToken() for array init 2021-02-10 11:53:53 -08:00
Isaac Freund
3110a73486 zig fmt: implement Tree.lastToken() for array types 2021-02-10 11:53:53 -08:00
Isaac Freund
8c4f3e5a31 zig fmt: fix render of pointers with ** tokens 2021-02-10 11:53:53 -08:00
Isaac Freund
a524e57090 zig fmt: support bodyless function decls
extern function declarations do not have a body, so allow setting
the rhs for FnDecl to 0 to indicate this is the case.
2021-02-10 11:53:53 -08:00
Isaac Freund
80b719d967 zig fmt: fix typo in firstToken() for pointer types 2021-02-10 11:53:53 -08:00
Isaac Freund
6dc2236054 musl: update to 1.2.2 2021-02-10 11:50:55 -08:00
Evan Haas
a2ec77041b translate-c: call @boolToInt on return value when necessary
In C, if a function has return type `int` and the return expression
is a boolean expression, there is no implicit cast. Therefore the
translated Zig code needs to call @boolToInt() on the result.

Written with feedback from @Vexu

Fixes #6215
2021-02-10 20:23:27 +02:00
Jonathan Marler
1480c42806 require specifier for arrayish types 2021-02-09 22:25:52 -08:00
Andrew Kelley
58db3d2775 zig fmt: re-enable now-passing test cases 2021-02-09 23:07:29 -07:00
Andrew Kelley
fa5fcdd734 zig fmt: fix regression with many container members 2021-02-09 22:42:00 -07:00
Andrew Kelley
9d87e6aeb8 zig fmt: remove dead code
likely these will be resurrected to make array literal cases pass.
2021-02-09 22:29:01 -07:00
Andrew Kelley
36eee7bc6c zig fmt: anytype, fn calls with one param, trailing commas
and extra newlines between top level declarations
2021-02-09 22:26:21 -07:00
Andrew Kelley
25bcf4eb99 zig fmt: grouped expressions 2021-02-09 21:17:43 -07:00
Andrew Kelley
7295d4b807 zig fmt: suspend blocks 2021-02-09 20:35:43 -07:00
Andrew Kelley
ebf04c56e1 zig fmt: usingnamespace 2021-02-09 20:17:47 -07:00
Andrew Kelley
39acc4c020 zig fmt: for loops 2021-02-09 20:08:40 -07:00
Andrew Kelley
1c79eea125 zig fmt: while loops 2021-02-09 17:23:57 -07:00
joachimschmidt557
6a5a6386c6 stage2 ARM: fix register allocation in genArmBinOp
Previously, this would reuse an operand even if reuseOperand returned
false for both operands.

genArmBinOpCode was also changed to be more Three-address code oriented
in the process.
2021-02-09 23:58:41 +01:00
joachimschmidt557
c2beaba85a stage2 ARM: fix callee_preserved_regs
Previously, the registers included r0, r1, r2, r3 which are not
included in the callee saved registers according to the Procedure Call
Standard for the ARM Architecture.
2021-02-09 23:57:43 +01:00
Andrew Kelley
bcafc51e58 zig fmt: fn protos and anytype 2021-02-09 14:41:50 -07:00
Andrew Kelley
b1d8a0a5a6 zig fmt: asm expressions 2021-02-08 22:03:23 -07:00
Isaac Freund
d869133a9f zig fmt: implement switches 2021-02-08 15:41:31 -08:00
Isaac Freund
837cd748a8 zig fmt: fix block lbrace indent 2021-02-08 15:41:31 -08:00
Isaac Freund
aaf13a2bb3 zig fmt: implement break 2021-02-08 15:41:31 -08:00
Evan Haas
221f1d898c translate-c: Improve function pointer handling
Omit address-of operator if operand is a function.

Improve handling of function-call translation when using function pointers

Fixes #4124
2021-02-08 10:15:00 +02:00
Isaac Freund
57cec38e61 std/zig/ast: fix Tree.lastToken() for blocks
The fact that blocks may end in a semicolon but this semicolon is not
counted by recursive lastToken() evaluation on the sub expression causes
off-by-one errors for lastToken() on blocks currently.

To fix this, introduce BlockSemicolon and BlockTwoSemicolon following
the pattern used for trailing commas in e.g. builtin function arguments.
2021-02-07 14:51:37 -08:00
Isaac Freund
0e38362d24 zig fmt: split Slice and SliceSentinel
This saves 4 whole bytes in the common case where there is no sentinel.
2021-02-07 14:51:37 -08:00
Isaac Freund
1d71b19c0d zig fmt: implement error set decls 2021-02-07 14:51:37 -08:00
Andrew Kelley
1adac0a55b never pass -s to clang
We only use clang to produce object files; the idea of stripping is not
relevant here.

Fixes regression in previous commit.
2021-02-07 15:08:48 -07:00
Andrew Kelley
e197a03124 zig cc: recognize the -s flag to be "strip" 2021-02-07 14:51:27 -07:00
Isaac Freund
bb7b5ee2ac zig fmt: implement catch and return 2021-02-07 12:04:32 -08:00
Isaac Freund
0929fcbc34 zig fmt: implement slices 2021-02-07 12:04:32 -08:00
Isaac Freund
33915cb1ed zig fmt: implement pointer types
rename PtrType => PtrTypeBitRange, SliceType => PtrType

This rename was done as the current SliceType is used for non-bitrange
pointers as well as slices and because PtrTypeSentinel/PtrTypeAligned
are also used for slices. Therefore using the same Ptr prefix for all
these pointer/slice nodes is an improvement.
2021-02-06 21:29:45 -08:00
Michael Dusan
905c85be96 Merge pull request #7957 from mk12/catalina
Use -isysroot on Catalina too, not just Big Sur
2021-02-06 20:12:09 -05:00
Mitchell Kember
fc79cbcc80 Use -isysroot on Catalina too, not just Big Sur
This amends #7506 to apply to macOS versions since Catalina (10.15),
rather than since Big Sur (11.0).
2021-02-06 16:32:32 -05:00
Andrew Kelley
d898945786 zig fmt: builtin call with trailing comma 2021-02-05 20:38:30 -07:00
Andrew Kelley
409ca88829 zig fmt: trailing comma in fn parameter list 2021-02-05 17:46:15 -07:00
Andrew Kelley
16a2562c3f zig fmt: implement container decls 2021-02-05 15:47:18 -07:00
Andrew Kelley
cf42ae178d std.MultiArrayList: use @memset builtin for undefined
See comment for more details
2021-02-05 15:45:33 -07:00
Isaac Freund
0f3fa4d654 zig fmt: array types 2021-02-05 11:36:19 -08:00
Isaac Freund
6f3b93e2e8 zig fmt: struct and anon array initialization 2021-02-05 10:51:45 -08:00
Isaac Freund
3e960cfffe zig fmt: float literal with exponent 2021-02-05 10:51:45 -08:00
Isaac Freund
0b4bb9b84f std.MultiArrayList: implement review comments 2021-02-05 10:51:45 -08:00
Luuk de Gram
36df6a008f Ensure function indices are correct and fix a memory leak 2021-02-05 18:06:25 +01:00
Luuk de Gram
aa3e0ff454 Create type declarations for extern functions and write the 'import' section 2021-02-05 18:06:20 +01:00
Andrew Kelley
7069459a76 zig fmt: implement struct init 2021-02-04 19:59:06 -07:00
Andrew Kelley
8e46d06650 zig fmt: implement fn protos and defers 2021-02-04 16:38:29 -07:00
Michael Dusan
300ebbd560 target: map zig ppc32 → llvm ppc
- llvm does not accept `ppc32` as a CPU type

closes #7947
2021-02-04 14:22:38 -08:00
Asherah Connor
4428acf0f7 zig fmt: deref, unwrap optional 2021-02-04 10:49:45 -08:00
Koakuma
448a28325c Fix previous %fp calculation 2021-02-05 00:28:07 +07:00
Koakuma
d23dfdeab9 Add comment explaining the alignment setting 2021-02-05 00:25:01 +07:00
Koakuma
e3e4af7271 stage1: set gen_frame_size alignment to work around requirement mismatch
Explicitly set the alignment requirements to 1 (i.e, mark the load as unaligned)
since there are some architectures (e.g SPARCv9) which has different alignment
requirements between a function pointer and usize pointer. On those
architectures, not explicitly setting it will lead into @frameSize generating
usize-aligned load instruction that could crash if the function pointer happens
to be not usize-aligned.
2021-02-04 21:07:54 +07:00
Koakuma
1eb2e48014 std.debug.StackIterator: account for SPARC %fp quirk
On SPARC, previous %fp is saved with a 14 slots offset from current %fp+bias.
Also account for the bias constant at the new_fp calculation.
2021-02-04 20:51:41 +07:00
Andrew Kelley
725adf8332 zig fmt: builtin calls and array access 2021-02-03 22:12:11 -07:00
Andrew Kelley
f5279cbada zig fmt: implement top-level fields 2021-02-03 17:02:12 -07:00
Rocknest
2d447b57cc fix typo in comment 2021-02-02 20:07:08 -08:00
Andrew Kelley
1a83b29bea zig fmt: implement if, call, field access, assignment 2021-02-02 21:05:53 -07:00
Michael Dusan
8661a13b74 fix superfluous fmt specifier in update_glibc 2021-02-02 10:00:13 -05:00
Frank Denis
7a01d396ee siphash: update the link to the SipHash paper 2021-02-02 11:17:14 +02:00
Andrew Kelley
0c6b98b825 zig fmt: implement simple test with doc comments 2021-02-01 21:31:41 -07:00
Andrew Kelley
272a0ab359 zig fmt: implement "line comment followed by top-level comptime" 2021-02-01 20:11:55 -07:00
Andrew Kelley
20554d32c0 zig fmt: start reworking with new memory layout
* start implementation of ast.Tree.firstToken and lastToken
 * clarify some ast.Node doc comments
 * reimplement renderToken
2021-02-01 17:23:49 -07:00
Michael Dusan
70a7c14ca6 update update_glibc to format strings with "{s}" 2021-02-01 16:57:41 -05:00
Andrew Kelley
102d954220 Merge pull request #7827 from Snektron/spirv-setup
Stage 2: SPIR-V setup
2021-02-01 12:49:51 -08:00
Jonathan Marler
06b29c8546 std.json large number support 2021-02-01 12:40:49 -08:00
Martin Wickham
1032a69321 Dupe strings on all public api points for std.build 2021-02-01 12:31:24 -08:00
Ryan Liptak
5e81b048a0 docs: Clarify that @field can work on declarations 2021-02-01 12:29:50 -08:00
Andrew Kelley
1517ed0a5e Merge pull request #7895 from Luukdegram/wasm-control-flow
stage2: wasm control flow
2021-02-01 12:29:22 -08:00
Luuk de Gram
c0685458a2 Define wasm constants
Update link.Wasm.zig to use std.wasm for its constants

Make opcodes u8 and non-exhaustive

Update test and rename 'spec' to 'wasm'
2021-02-01 12:28:25 -08:00
Cameron Conn
683d3f7242 Don't read more bytes than exist in MsfStream (#7839) 2021-02-01 15:27:39 -05:00
joachimschmidt557
446ebddb93 stage2 ARM: save function arguments to stack for debugging
This changes genArg to copy registers to the stack for better
debugging. Thus, it requires genSetStack to be implemented in order for
genArg to work.
2021-02-01 12:17:24 -08:00
Vincent Rischmann
16905d96f7 Fixes for std.Thread.Condition (#7883)
* thread/condition: fix PthreadCondition compilation

* thread/condition: add wait, signal and broadcast

This is like std.Thread.Mutex which forwards calls to `impl`; avoids
having to call `cond.impl` every time.

* thread/condition: initialize the implementation
2021-02-01 15:16:39 -05:00
Andrew Kelley
11f6916f9b Merge pull request #7892 from Vexu/stage2-cbe
Stage2 cbe: more control flow
2021-02-01 12:15:52 -08:00
Andrew Kelley
66c0fe4f90 Merge pull request #7922 from daurnimator/comptime-json-fields
std.json support for comptime fields
2021-02-01 12:11:36 -08:00
Frank Denis
a03f9548d3 std/math/big/int: normalize after a right shift
After a right shift, top limbs may be all zero. However, without
normalization, the number of limbs is not going to change.

In order to check if a big number is zero, we used to assume that the
number of limbs is 1. Which may not be the case after right shifts,
even if the actual value is zero.

- Normalize after a right shift
- Add a test for that issue
- Check all the limbs in `eqlZero()`. It may not be necessary if
callers always remember to normalize before calling the function.
But checking all the limbs is very cheap and makes the function less
bug-prone.
2021-02-01 12:10:01 -08:00
Veikka Tuominen
75acfcf0ea stage2: reimplement switch 2021-02-01 15:45:11 +02:00
Veikka Tuominen
3ec5c9a3bc stage2 cbe: implement not and some bitwise ops 2021-02-01 08:48:24 +02:00
Veikka Tuominen
106520329e stage2 cbe: implement switchbr 2021-02-01 08:48:22 +02:00
Veikka Tuominen
258f3ec5ec stage2 cbe: block results 2021-02-01 08:47:25 +02:00
Veikka Tuominen
bdfe3aeab8 stage2 cbe: condbr and breaks 2021-02-01 08:47:25 +02:00
Veikka Tuominen
6ca0ff90b6 stage2 cbe: use AutoIndentingStream 2021-02-01 08:47:25 +02:00
Veikka Tuominen
81c512f35b stage2 cbe: loop instruction 2021-02-01 08:47:25 +02:00
Andrew Kelley
bf8fafc37d stage2: tokenizer does not emit line comments anymore
only std.zig.render cares about these, and it can find them in the
original source easily enough.
2021-01-31 21:57:48 -07:00
Andrew Kelley
bf76501b5d Merge pull request #7847 from ziglang/astgen-rl-rework
stage2: rework astgen result locations
2021-01-31 20:15:08 -08:00
Andrew Kelley
0f5eda973e stage2: delete astgen for switch expressions
The astgen for switch expressions did not respect the ZIR rules of only
referencing instructions that are in scope:

  %14 = block_comptime_flat({
    %15 = block_comptime_flat({
      %16 = const(TypedValue{ .ty = comptime_int, .val = 1})
    })
    %17 = block_comptime_flat({
      %18 = const(TypedValue{ .ty = comptime_int, .val = 2})
    })
  })
  %19 = block({
    %20 = ref(%5)
    %21 = deref(%20)
    %22 = switchbr(%20, [%15, %17], {
      %15 => {
        %23 = const(TypedValue{ .ty = comptime_int, .val = 1})
        %24 = store(%10, %23)
        %25 = const(TypedValue{ .ty = void, .val = {}})
        %26 = break("label_19", %25)
      },
      %17 => {
        %27 = const(TypedValue{ .ty = comptime_int, .val = 2})
        %28 = store(%10, %27)
        %29 = const(TypedValue{ .ty = void, .val = {}})
        %30 = break("label_19", %29)
      }
    }, {
      %31 = unreachable_safe()
    }, special_prong=else)
  })

In this snippet you can see that the comptime expr referenced %15 and
%17 which are not in scope. There also was no test coverage for runtime
switch expressions.

Switch expressions will have to be re-introduced to follow these rules
and with some test coverage. There is some usable code being deleted in
this commit; it will be useful to reference when re-implementing switch
later.

A few more improvements to do while we're at it:
 * only use .ref result loc on switch target if any prongs obtain the
   payload with |*syntax|
   - this improvement should be done to if, while, and for as well.
   - this will remove the needless ref/deref instructions above
 * remove switchbr and add switch_block, which is both a block and a
   switch branch.
   - similarly we should remove loop and add loop_block.

This commit introduces a "force_comptime" flag into the GenZIR
scope. The main purpose of this will be to choose the "comptime"
variants of certain key zir instructions, such as function calls and
branches. We will be moving away from using the block_comptime_flat
ZIR instruction, and eventually deleting it.

This commit also contains miscellaneous fixes to this branch that bring
it to the state of passing all the tests.
2021-01-31 21:09:22 -07:00
Andrew Kelley
de85c4ac42 astgen: rework for loops 2021-01-31 21:09:22 -07:00
Andrew Kelley
9f4ff80108 astgen: rework while 2021-01-31 21:09:22 -07:00
Andrew Kelley
e9e6cc2171 astgen: rework orelse/catch 2021-01-31 21:09:22 -07:00
Andrew Kelley
6c8985fcee astgen: rework labeled blocks 2021-01-31 21:09:22 -07:00
Andrew Kelley
588171c30b sema: after block gets peer type resolved, insert type coercions
on the break instruction operands. This involves a new TZIR instruction,
br_block_flat, which represents a break instruction where the operand is
the result of a flat block. See the doc comments on the instructions for
more details.

How it works: when adding break instructions in semantic analysis, the
underlying allocation is slightly padded so that it is the size of a
br_block_flat instruction, which allows the break instruction to later
be converted without removing instructions inside the parent body. The
extra type coercion instructions go into the body of the br_block_flat,
and backends are responsible for dispatching the instruction correctly
(it should map to the same function calls for related instructions).
2021-01-31 21:09:22 -07:00
Andrew Kelley
06bb360dd2 astgen: respect a const local's type annotation 2021-01-31 21:09:22 -07:00
Andrew Kelley
2f992e1bb3 astgen: const locals that end up being rvalues do not alloc
Local variable declarations now detect whether the result location for the
initialization expression consumes the result location as a pointer. If
it does, then the local is emitted as a LocalPtr. Otherwise it is
emitted as a LocalVal.

This results in clean, straightforward ZIR code for semantic analysis.
2021-01-31 21:09:22 -07:00
Andrew Kelley
093cbeb018 astgen: @as with block_ptr result location 2021-01-31 21:09:22 -07:00
Andrew Kelley
b7452fe35f stage2: rework astgen result locations
Motivating test case:

```zig
export fn _start() noreturn {
    var x: u64 = 1;
    var y: u32 = 2;
    var thing: u32 = 1;
    const result = if (thing == 1) x else y;
    exit();
}
```

The main idea here is for astgen to output ideal ZIR depending on
whether or not the sub-expressions of a block consume the result
location. Here, neither `x` nor `y` consume the result location of the
conditional expression block, and so the ZIR should communicate the
result of the condbr using break instructions, not with the result
location pointer.

With this commit, this is accomplished:

```
  %22 = alloc_inferred()
  %23 = block({
    %24 = const(TypedValue{ .ty = type, .val = bool})
    %25 = deref(%18)
    %26 = const(TypedValue{ .ty = comptime_int, .val = 1})
    %27 = cmp_eq(%25, %26)
    %28 = as(%24, %27)
    %29 = condbr(%28, {
      %30 = deref(%4)
      < there is no longer a store instruction here >
      %31 = break("label_23", %30)
    }, {
      %32 = deref(%11)
      < there is no longer a store instruction here >
      %33 = break("label_23", %32)
    })
  })
  %34 = store_to_inferred_ptr(%22, %23) <-- the store is only here
  %35 = resolve_inferred_alloc(%22)
```

However if the result location gets consumed, the break instructions
change to break_void, and the result value is communicated only by the
stores, not by the break instructions.

Implementation:

 * The GenZIR scope that conditional branches uses now has an optional
   result location pointer field and a count of how many times the
   result location ended up being an rvalue (not consumed).
 * When rvalue() is called on a result location for a block, it
   increments this counter. After generating the branches of a block,
   astgen for the conditional branch checks this count and if it is 2
   then the store_to_block_ptr instructions are elided and it calls
   rvalue() using the block result (which will account for peer type
   resolution on the break operands).

astgen has many functions disabled until they can be reworked with these
new semantics. That will be done before merging the branch.

There are some new rules for astgen to follow regarding result locations
and what you are allowed/required to do depending on which one is passed
to expr(). See the updated doc comments of ResultLoc for details.

I also changed naming conventions of stuff in this commit, sorry about
that.
2021-01-31 21:09:22 -07:00
daurnimator
e0a04e7f67 allow more complex comptime fields in std.json 2021-02-01 01:01:50 +11:00
daurnimator
f88bb56ee5 std.json union handling should bubble up AllocationRequired 2021-02-01 01:00:15 +11:00
daurnimator
33c0a01b08 std.json support for comptime fields
Closes #6231
2021-01-31 23:41:32 +11:00
Veikka Tuominen
fdc875ed00 Merge pull request #7750 from tadeokondrak/6609-tagtype-tag
Remove @TagType; std.meta.TagType -> std.meta.Tag
2021-01-31 12:37:12 +02:00
Andrew Kelley
4dca99d3f6 stage2: rework AST memory layout
This is a proof-of-concept of switching to a new memory layout for
tokens and AST nodes. The goal is threefold:

 * smaller memory footprint
 * faster performance for tokenization and parsing
 * most importantly, a proof-of-concept that can be also applied to ZIR
   and TZIR to improve the entire compiler pipeline in this way.

I had a few key insights here:

 * Underlying premise: using less memory will make things faster, because
   of fewer allocations and better cache utilization. Also using less
   memory is valuable in and of itself.
 * Using a Struct-Of-Arrays for tokens and AST nodes, saves the bytes of
   padding between the enum tag (which kind of token is it; which kind
   of AST node is it) and the next fields in the struct. It also improves
   cache coherence, since one can peek ahead in the tokens array without
   having to load the source locations of tokens.
 * Token memory can be conserved by only having the tag (1 byte) and byte
   offset (4 bytes) for a total of 5 bytes per token. It is not necessary
   to store the token ending byte offset because one can always re-tokenize
   later, but also most tokens the length can be trivially determined from
   the tag alone, and for ones where it doesn't, string literals for
   example, one must parse the string literal again later anyway in
   astgen, making it free to re-tokenize.
 * AST nodes do not actually need to store more than 1 token index because
   one can poke left and right in the tokens array very cheaply.

So far we are left with one big problem though: how can we put AST nodes
into an array, since different AST nodes are different sizes?

This is where my key observation comes in: one can have a hash table for
the extra data for the less common AST nodes! But it gets even better than
that:

I defined this data that is always present for every AST Node:

 * tag (1 byte)
   - which AST node is it
 * main_token (4 bytes, index into tokens array)
   - the tag determines which token this points to
 * struct{lhs: u32, rhs: u32}
   - enough to store 2 indexes to other AST nodes, the tag determines
     how to interpret this data

You can see how a binary operation, such as `a * b` would fit into this
structure perfectly. A unary operation, such as `*a` would also fit,
and leave `rhs` unused. So this is a total of 13 bytes per AST node.
And again, we don't have to pay for the padding to round up to 16 because
we store in struct-of-arrays format.

I made a further observation: the only kind of data AST nodes need to
store other than the main_token is indexes to sub-expressions. That's it.
The only purpose of an AST is to bring a tree structure to a list of tokens.
This observation means all the data that nodes store are only sets of u32
indexes to other nodes. The other tokens can be found later by the compiler,
by poking around in the tokens array, which again is super fast because it
is struct-of-arrays, so you often only need to look at the token tags array,
which is an array of bytes, very cache friendly.

So for nearly every kind of AST node, you can store it in 13 bytes. For the
rarer AST nodes that have 3 or more indexes to other nodes to store, either
the lhs or the rhs will be repurposed to be an index into an extra_data array
which contains the extra AST node indexes. In other words, no hash table needed,
it's just 1 big ArrayList with the extra data for AST Nodes.

Final observation, no need to have a canonical tag for a given AST. For example:
The expression `foo(bar)` is a function call. Function calls can have any
number of parameters. However in this example, we can encode the function
call into the AST with a tag called `FunctionCallOnlyOneParam`, and use lhs
for the function expr and rhs for the only parameter expr. Meanwhile if the
code was `foo(bar, baz)` then the AST node would have to be `FunctionCall`
with lhs still being the function expr, but rhs being the index into
`extra_data`. Then because the tag is `FunctionCall` it means
`extra_data[rhs]` is the "start" and `extra_data[rhs+1]` is the "end".
Now the range `extra_data[start..end]` describes the list of parameters
to the function.

Point being, you only have to pay for the extra bytes if the AST actually
requires it. There's no limit to the number of different AST tag encodings.

Preliminary results:

 * 15% improvement on cache-misses
 * 28% improvement on total instructions executed
 * 26% improvement on total CPU cycles
 * 22% improvement on wall clock time

This is 1/4 items on the checklist before this can actually be merged:

 * [x] parser
 * [ ] render (zig fmt)
 * [ ] astgen
 * [ ] translate-c
2021-01-30 20:16:59 -07:00
Andrew Kelley
766b315b38 std.GeneralPurposeAllocator: logging improvements
It now uses the log scope "gpa" instead of "std".

Additionally, there is a new config option `verbose_log` which enables
info log messages for every allocation. Can be useful when debugging.
This option is off by default.
2021-01-30 20:15:26 -07:00
Andrew Kelley
0808d98e10 add std.MultiArrayList
Also known as "Struct-Of-Arrays" or "SOA". The purpose of this data
structure is to provide a similar API to ArrayList but instead of
the element type being a struct, the fields of the struct are in N
different arrays, all with the same length and capacity.

Having this abstraction means we can put them in the same allocation,
avoiding overhead with the allocator. It also saves a tiny bit of
overhead from the redundant capacity and length fields, since each
struct element shares the same value.

This is an alternate implementation to #7854.
2021-01-30 20:12:13 -07:00
Tadeo Kondrak
0b5f3c2ef9 Replace @TagType uses, mostly with std.meta.Tag 2021-01-30 22:26:44 +02:00
rgreenblatt
78d2f2b819 FromWriteFileStep for all LibExeObjStep types 2021-01-30 17:50:41 +02:00
Tadeo Kondrak
1637d8ac80 remove @TagType 2021-01-30 13:19:58 +02:00
Tadeo Kondrak
b7767eb834 std.meta: rename TagPayloadType to TagPayload 2021-01-30 13:19:52 +02:00
Tadeo Kondrak
68ec54f386 std.meta: rename TagType to Tag 2021-01-30 13:19:52 +02:00
Dmitry Atamanov
290efc0747 Improve error messages in std.fmt (#7898) 2021-01-30 13:12:44 +02:00
Michael Dusan
f9b85c6e50 stage1: add error for slice.len incr beyond bounds
comptime direct slice.len increment dodges bounds checking but
we can emit an error for it, at least in the simple case.

- promote original assert to compile-error
- add test case

closes #7810
2021-01-30 11:19:25 +02:00
Martin Wickham
3d4eeafb47 Fill out more cases for std.meta.sizeof 2021-01-30 11:13:20 +02:00
Asherah Connor
e8740a90b9 complete {Z} deprecation in std.fmt.formatIntValue
formatZigEscapes doesn't exist any more.
2021-01-29 20:46:39 +02:00
root
236db6232f Fix interger overflow when calling joinZ with empty slices 2021-01-27 12:01:18 +02:00
Evan Haas
1ed8c54cd3 translate-c: add wide string literal support
Adds support for wide, UTF-16, and UTF-32 string literals. If used to initialize
an incomplete array, the same logic as narrow strings is used. Otherwise they
are translated as global "anonymous" arrays of the relevant underlying char type.
A dot is used in the name to ensure the generated names do not conflict with any
other names in the translated program.

For example:

```c
void my_fn() {
    const uint32_t *foo = U"foo";
}
```

becomes:
```zig
const @"zig.UTF32_string_2" = [4]c_uint{
    '\u{66}',
    '\u{6f}',
    '\u{6f}',
    0,
};
pub export fn my_fn() void {
    var foo: [*c]const u32 = &@"zig.UTF32_string_2";
}
```
2021-01-26 21:13:06 -08:00
Luuk de Gram
cc46c1b902 Add tests, fix locals that are created in blocks like loops, and handle all breaks correctly 2021-01-26 19:47:15 +01:00
Jakub Konka
79730e6f5c macho: add arm64 relocation type enum 2021-01-26 08:11:31 +01:00
Joran Dirk Greef
881ecdc72f Add MAX_RW_COUNT limit to std.os.pread()
Fixes: https://github.com/ziglang/zig/issues/7805
2021-01-25 10:41:38 -08:00
Koakuma
09450419d3 Fix f128 NaN check on big-endian hosts
On big-endian hosts, zig_f128_isNaN() takes the high and low halves
from the wrong element, resulting in buggy NaN detection behavior.
This fixes it.
2021-01-25 10:40:23 -08:00
Timon Kruiper
e23bc1f76a render: fix bug when rendering struct initializer with length 1
This crashed the compiler when running translate-c. See the added test.
2021-01-25 10:40:00 -08:00
Andrew Kelley
4ca1f4ec2e Merge pull request #7846 from LemonBoy/filtertest
stage1: don't filter test blocks with empty label
2021-01-25 10:39:11 -08:00
Evan Haas
57b2176e28 translate-c: Improve array support
1. For incomplete arrays with initializer list (`int x[] = {1};`) use the
initializer size as the array size.

2. For arrays initialized with a string literal translate it as an array
of character literals instead of `[*c]const u8`

3. Don't crash if an empty initializer is used for an incomplete array.

4. Add a test for multi-character character constants

Additionally lay some groundwork for supporting wide string literals.

fixes #4831 #7832 #7842
2021-01-25 10:37:23 -08:00
Joran Dirk Greef
68a040aec7 linux: add fallocate() to io_uring 2021-01-25 10:34:20 -08:00
Timon Kruiper
9238d12537 windows: make sure to handle PATH_NOT_FOUND when deleting files
Fixes #7879
2021-01-25 10:33:08 -08:00
Andrew Kelley
0cfa39304b zig cc: recognize more coff linker options
Related: #7874
2021-01-24 14:30:28 -07:00
Andrew Kelley
b56e916fa1 Merge branch 'FireFox317-deadlock-windows-fix'
Merges #7861
2021-01-24 12:22:51 -07:00
Andrew Kelley
2b321c25ce std.Progress: call refreshWithHeldLock as appropriate 2021-01-24 12:22:17 -07:00
Timon Kruiper
4f7d76f19c fix windows bug in Progress.zig
This bug caused the compiler to deadlock when multiple c objects
were build in parallel.

Thanks @kprotty for finding this bug!
2021-01-24 12:20:51 -07:00
Andrew Kelley
15278b7f4b Merge pull request #7856 from ziglang/lto
add LTO support
2021-01-24 11:09:48 -08:00
Luuk de Gram
a0d81caec9 Nested conditions and loops support 2021-01-24 14:38:35 +01:00
Luuk de Gram
ccef167e9d Define wasm constants
Update link.Wasm.zig to use std.wasm for its constants

Make opcodes u8 and non-exhaustive

Update test and rename 'spec' to 'wasm'
2021-01-24 10:54:51 +01: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
ab4f3aee3d stage2: wasm arch does not support -mred-zone flags 2021-01-22 23:35:32 -07:00
Andrew Kelley
3647784d05 stage2: add missing frexpl.c to mingw c source file list 2021-01-22 23:35:13 -07:00
LemonBoy
134f5fd3d6 std: Update test "" to test where it makes sense 2021-01-22 15:46:58 +01:00
LemonBoy
ac004e1bf1 stage1: Allow nameless test blocks
Nameless blocks are never filtered, the test prefix is still applied.
2021-01-22 15:46:58 +01:00
Jakub Konka
843d91e75d Bring back stack trace printing on ARM Darwin
This temporary patch fixes a segfault caused by miscompilation
by the LLD when generating stubs for initialization of thread local
storage. We effectively bypass TLS in the default panic handler
so that no segfault is generated and the stack trace is correctly
reported back to the user.

Note that, this is linked directly to a bigger issue with LLD
ziglang/zig#7527 and when resolved, we only need to remove the
`comptime` code path introduced with this patch to use the default
panic handler that relies on TLS.

Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2021-01-21 23:20:42 +01:00
LemonBoy
fc5ae1c409 stage1: don't filter test blocks with empty label
The common pattern of including a file containing all the tests in a
empty-label test block breaks down when using --test-filter.
2021-01-21 09:48:57 +01:00
Evan Haas
bea791b639 translate-c: fix variadic function calls
1702b413 introduced a bug with variadic function calls - trying to access the
paramType of non-existent parameters.
2021-01-20 22:26:18 -08:00
Jakub Konka
58344e0017 Merge pull request #7829 from kubkon/macho-safer
stage2 macho: make int casts fallible where necessary
2021-01-20 17:28:31 +01:00
Andrew Kelley
8098b3f84c stage2: implement TZIR printing for call instruction 2021-01-19 21:09:46 -07:00
Rafael Ristovski
41e6aa78bb zig cc: Support reading input from stdin
This fixes #6271, which allows using `zig cc` with meson.
2021-01-19 17:23:44 -08:00
Andrew Kelley
072d1e088c stage2: fix anonymous Decl ty/val wrong arena
string literals and error set types were allocating the ty/val fields of
the anonymous Decl into the owner Decl's arena, rather than the
new anonymous Decl's arena as intended. This caused use of undefined
value later on in the pipeline.
2021-01-19 16:25:55 -07:00
Andrew Kelley
1af31baf0b stage2: -Dlog enables all logging, log scopes can be set at runtime
Previously you had to recompile if you wanted to change the log scopes
that get printed. Now, log scopes can be set at runtime, and -Dlog
controls whether all logging is available at runtime.

Purpose here is a nicer development experience. Most likely stage2
developers will always want -Dlog enabled and then pass --debug-log
scopes when debugging particular issues.
2021-01-19 15:49:08 -07:00
Jakub Konka
a26ab9afee Backport Elf changes from d5d0619 2021-01-19 22:54:34 +01:00
Jakub Konka
0e56d4cc02 stage2: converge x86_64 and aarch64 tests on macOS 2021-01-19 22:39:49 +01:00
Jakub Konka
5d4401ceec macho: fix overflowing u64 range 2021-01-19 22:39:49 +01:00
Jakub Konka
e726868b02 macho: reuse existing names from the string table 2021-01-19 22:39:49 +01:00
Jakub Konka
7d3aa58e16 macho: make int casts safer 2021-01-19 22:39:49 +01:00
Andrew Kelley
287f640cc9 stage2: ELF: fix crash when only 1 function and it gets updated 2021-01-19 14:08:43 -07:00
Andrew Kelley
d5d0619aac stage2: ELF: avoid multiplication for ideal capacity
ideal capacity is now determined by e.g.
x += x / f
rather than
x = x * b / a

This turns a multiplication into an addition, making it less likely to
overflow the integer. This commit also introduces padToIdeal() which
does saturating arithmetic so that no overflow is possible when
calculating ideal capacity.

closes #7830
2021-01-19 13:47:51 -07:00
Robin Voetter
1055344673 SPIR-V: Use free list for result id generation 2021-01-19 15:28:17 +01:00
Robin Voetter
801732aebd SPIR-V: OpMemoryModel and basic capability generation 2021-01-19 15:28:17 +01:00
Robin Voetter
71ac82ecb0 SPIR-V: Make emitting binary more efficient 2021-01-19 15:28:17 +01:00
Robin Voetter
02c138fe70 SPIR-V: Add glsl450 and vulkan spir-v operating system definitions 2021-01-19 15:28:17 +01:00
Robin Voetter
b2b87b5900 SPIR-V: Linking and codegen setup 2021-01-19 15:28:17 +01:00
Robin Voetter
ab607d455e SPIR-V: Initial architecture definitions and setup 2021-01-19 15:28:17 +01:00
Robin Voetter
9a6babf482 SPIR-V: Add generated specification 2021-01-19 15:28:17 +01:00
Robin Voetter
fd33530aef SPIR-V: Spec generator 2021-01-19 15:28:17 +01:00
Jakub Konka
d5b0a963d1 Merge pull request #7818 from kubkon/macho-more-cleanup
Macho more cleanup
2021-01-19 08:58:51 +01:00
Andrew Kelley
30a824cb9e astgen: eliminate rlWrapPtr and all its callsites
The following AST avoids unnecessary derefs now:
 * error set decl
 * field access
 * array access
 * for loops: replace ensure_indexable and deref on the len_ptr with a
   special purpose ZIR instruction called indexable_ptr_len.

Added an error note when for loop operand is the wrong type.

I also accidentally implemented `@field`.
2021-01-19 00:38:53 -07:00
Andrew Kelley
7e56028bc7 Merge branch 'stage2: rework ZIR/TZIR for optionals and error unions'
closes #7730
closes #7662
2021-01-18 19:29:53 -07:00
Andrew Kelley
ecc246efa2 stage2: rework ZIR/TZIR for optionals and error unions
* fix wrong pointer const-ness when unwrapping optionals
 * allow grouped expressions and orelse as lvalues
 * ZIR for unwrapping optionals: no redundant deref
   - add notes to please don't use rlWrapPtr, this function should be
     deleted
 * catch and orelse: better ZIR for non-lvalue: no redundant deref;
   operate entirely on values. lvalue case still works properly.
   - properly propagate the result location into the target expression
 * Test harness: better output when tests fail due to compile errors.
 * TZIR: add instruction variants. These allow fewer TZIR instructions to
   be emitted from zir_sema. See the commit diff for per-instruction
   documentation.
   - is_null
   - is_non_null
   - is_null_ptr
   - is_non_null_ptr
   - is_err
   - is_err_ptr
   - optional_payload
   - optional_payload_ptr
 * TZIR: removed old naming convention instructions:
   - isnonnull
   - isnull
   - iserr
   - unwrap_optional
 * ZIR: add instruction variants. These allow fewer ZIR instructions to
   be emitted from astgen. See the commit diff for per-instruction
   documentation.
   - is_non_null
   - is_null
   - is_non_null_ptr
   - is_null_ptr
   - is_err
   - is_err_ptr
   - optional_payload_safe
   - optional_payload_unsafe
   - optional_payload_safe_ptr
   - optional_payload_unsafe_ptr
   - err_union_payload_safe
   - err_union_payload_unsafe
   - err_union_payload_safe_ptr
   - err_union_payload_unsafe_ptr
   - err_union_code
   - err_union_code_ptr
 * ZIR: removed old naming convention instructions:
   - isnonnull
   - isnull
   - iserr
   - unwrap_optional_safe
   - unwrap_optional_unsafe
   - unwrap_err_safe
   - unwrap_err_unsafe
   - unwrap_err_code
2021-01-18 19:29:18 -07:00
g-w1
3c2a9220ed stage2: fix orelse at comptime
There was just some untested code that did not work. .isnull -> .isnonnull
and I had to add a .ref resultloc to make types match up.
2021-01-18 19:29:18 -07:00
Jakub Konka
a2ebe3c82c macho: add missing DWARF line no update in codegen 2021-01-18 22:26:23 +01:00
Jakub Konka
e32131cfae stage2 macho: cleanup indirect symbol table writes
Also, force rewriting of code signature padding at every update so
that we take into account possible section relocs and expansion of
the last preceeding section, e.g., the string table.

This commit also tweak the logic responsible for managing debug lines
in `DebugSymbols`. In particular, in case we update the same function,
we'd previously incorrectly create a cycle adding pointer to the same
`SrcFn` to itself.
2021-01-18 22:26:23 +01:00
joachimschmidt557
6c7e66613d stage2 AArch64: implement jump 2021-01-18 22:22:53 +01:00
Andrew Kelley
1a05b54520 update wasm backend to match new Module API
Fixes a logical merge conflict that I didn't notice before.
2021-01-18 14:12:05 -07:00
Andrew Kelley
46dd058d59 Merge pull request #7797 from Luukdegram/wasm-refactor
stage2: wasm - Refactor codegen for wasm similar to other backends
2021-01-18 12:35:52 -08:00
Andrew Kelley
0353c9601a Merge pull request #7814 from LemonBoy/fix-7760
std: Fixed pipe2 fallback
2021-01-18 11:49:42 -08:00
Evan Haas
c3dadfa95b translate-c: Add Wide, UTF-16, and UTF-32 character literals
Add support for L'<wchar_t>', u'<char16_t>', and U'<char32_t>'. Currently
this just translates wide char literals to \u{NNNNNN} escape codes
(e.g. U'💯' -> '\u{1f4af}')

Another approach would be to emit UTF-8 encoded character literals
directly, but in my opinion this approaches Unicode-complete because it
would require knowledge of which Unicode codepoints have graphical
representations for the emitted source to be readable.

We could also just emit integer literals, but the current method makes
it clear that we have translated a wide character literal and not just
an integer constant.
2021-01-18 11:05:51 -08:00
Julian Maingot
384ccaa27a stage2: use %type not @type for libc stubs
Missed a couple places last time so just doing the rest.
2021-01-18 11:04:33 -08:00
Julian Maingot
4c5f69a065 update error return doc
Docs were out of sync with code
2021-01-18 11:04:33 -08:00
Zander Khan
ce22c70586 Change compareFn to fn (a: T, b: T) std.math.Order 2021-01-18 19:02:11 +00:00
Jakub Konka
61b8d42d5c Merge pull request #7808 from joachimschmidt557/stage2-aarch64
Stage2 AArch64: Fix genSetStack
2021-01-18 20:01:44 +01:00
LemonBoy
6418f9ae91 std: Add missing cast when calling fcntl w/ constant args
comptime_int arguments are a big no no.
2021-01-18 18:02:09 +01:00
LemonBoy
f33bac2b12 std: define pipe2 only for os that support it 2021-01-18 17:24:26 +01:00
LemonBoy
9d18df142c std: Fixed pipe2 fallback
Use both F_SETFD and F_SETFL depending on what flag we're setting.

Closes #7760
2021-01-18 14:52:35 +01:00
joachimschmidt557
458011f21f stage2 AArch64: update function prologue and epilogue to include stack
offsets
2021-01-17 23:12:04 +01:00
joachimschmidt557
ea6f3e3fd1 stage2 AArch64: add add/subtract (immediate) instructions 2021-01-17 22:40:14 +01:00
joachimschmidt557
c6cb02c226 stage2 AArch64: fix stack offsets in genSetStack 2021-01-17 22:22:47 +01:00
Jakub Konka
8118336585 macho: refactor undef symbol handling
Now, we don't erroneously write to the string table on every
write of global and undef symbols.
2021-01-17 21:01:52 +01:00
Jakub Konka
3562edf137 macho: improve x86_64 tests; clean fixups on error
When codegen ends in failure, we need to manually clean up any fixups
that may have been gathered during that `codegen.generateSymbol` call.
Otherwise, we will end trapping.
2021-01-17 16:01:16 +01:00
Zander Khan
5bfd9238de Remove resize. Adding uninitialized memory at the end of the items would break the heap property. 2021-01-17 14:43:38 +00:00
Zander Khan
9a09ebb1b9 Replace shrink with shrinkAndFree and shrinkRetainingCapacity 2021-01-17 14:41:20 +00:00
Jakub Konka
b25cf7db02 stage2 aarch64: add basic function pro/epilogue
Fix typo in `nop` implementation.
Simplify `aarch64` macOS tests.
2021-01-17 14:57:53 +01:00
Jakub Konka
e292f33de7 stage2 aarch64: add basic genSetStack 2021-01-17 14:57:36 +01:00
Andrew Kelley
44135ea84e Merge branch 'stage2 error notes'
Closes #7555

There was still some extra work @Vexu did in that PR having to do with
adding more compile errors and notes for switch expressions, but that
can be added in a follow-up commit.
2021-01-17 00:16:10 -07:00
Andrew Kelley
8deb21c58a stage2: add compile error for label redefinition
Also fix incorrectly destroying notes.

This work is based on Vexu's patch in #7555.
2021-01-17 00:15:25 -07:00
Andrew Kelley
629d3bea1b stage2: slight cleanup of Module by calling astgen functions 2021-01-16 23:24:00 -07:00
Andrew Kelley
8c9ac4db97 stage2: implement error notes and regress -femit-zir
* Implement error notes
   - note: other symbol exported here
   - note: previous else prong is here
   - note: previous '_' prong is here
 * Add Compilation.CObject.ErrorMsg. This object properly converts to
   AllErrors.Message when the time comes.
 * Add Compilation.CObject.failure_retryable. Properly handles
   out-of-memory and other transient failures.
 * Introduce Module.SrcLoc which has not only a byte offset but also
   references the file which the byte offset applies to.
 * Scope.Block now contains both a pointer to the "owner" Decl and the
   "source" Decl. As an example, during inline function call, the
   "owner" will be the Decl of the caller and the "source" will be the
   Decl of the callee.
 * Module.ErrorMsg now sports a `file_scope` field so that notes can
   refer to source locations in a file other than the parent error
   message.
 * Some instances where a `*Scope` was stored, now store a
   `*Scope.Container`.
 * Some methods in the `Scope` namespace were moved to the more specific
   type, since there was only an implementation for one particular tag.
   - `removeDecl` moved to `Scope.Container`
   - `destroy` moved to `Scope.File`
 * Two kinds of Scope deleted:
   - zir_module
   - decl
 * astgen: properly use DeclVal / DeclRef. DeclVal was incorrectly
   changed to be a reference; this commit fixes it. Fewer ZIR
   instructions processed as a result.
   - declval_in_module is renamed to declval
   - previous declval ZIR instruction is deleted; it was only for .zir
     files.
 * Test harness: friendlier diagnostics when an unexpected set of errors
   is encountered.
 * zir_sema: fix analyzeInstBlockFlat by properly calling resolvingInst
   on the last zir instruction in the block.

Compile log implementation:
 * Write to a buffer rather than directly to stderr.
 * Only keep track of 1 callsite per Decl.
 * No longer mutate the ZIR Inst struct data.
 * "Compile log statement found" errors are only emitted when there are
   no other compile errors.

-femit-zir and support for .zir source files is regressed. If we wanted
to support this again, outputting .zir would need to be done as yet
another backend rather than in the haphazard way it was previously
implemented.

For parsing .zir, it was implemented previously in a way that was not
helpful for debugging. We need tighter integration with the test harness
for it to be useful; so clearly a rewrite is needed. Given that a
rewrite is needed, and it was getting in the way of progress and
organization of the rest of stage2, I regressed the feature.
2021-01-16 22:51:01 -07:00
Andrew Kelley
8436134499 std.ArrayHashMap: add "AssertDiscard" function variants
* Add `swapRemoveAssertDiscard`
 * Add `orderedRemoveAssertDiscard`
 * Deprecate `removeAssertDiscard`
2021-01-16 22:49:20 -07:00
Andrew Kelley
1f65828ec6 Merge pull request #7716 from koachan/sparc64-libs
stage1: SPARCv9 f128 enablement
2021-01-16 12:10:03 -08:00
joachimschmidt557
d2a297c2b3 stage2 ARM: add extra load/store instructions 2021-01-16 12:06:31 -08:00
joachimschmidt557
fbd5fbe729 stage2 AArch64: add very basic return values 2021-01-16 12:05:38 -08:00
Zander Khan
e1ab425bce Fix slice length when updating 2021-01-16 18:43:13 +00:00
Zander Khan
c6986f29f9 Fix update might change an element no longer in the queue 2021-01-16 18:11:26 +00:00
Zander Khan
4600b489a6 Rename heap to queue in tests for consistency 2021-01-16 18:09:44 +00:00
Zander Khan
4d09803414 Fix edge cases in fromOwnedSlice 2021-01-16 18:06:44 +00:00
Zander Khan
a162a21947 Ensure we cannot remove an item outside the current length of the queue 2021-01-16 17:52:14 +00:00
Zander Khan
ecee1cae45 Remove magic number 2021-01-16 17:48:55 +00:00
Zander Khan
94c47855ec Add missing import 2021-01-16 17:48:29 +00:00
Zander Khan
349ccc0bd0 Add license to top of file 2021-01-16 17:48:14 +00:00
Luuk de Gram
6a87ce0b62 Generate correct opcode for 'addGen' depending on type 2021-01-16 18:22:20 +01:00
Luuk de Gram
6c19aeddca Add tests and move tests to wasm's own file 2021-01-16 14:58:04 +01:00
Zander Khan
a727a508cd std: Add Priority Dequeue 2021-01-16 12:01:06 +00:00
Luuk de Gram
4b2538f72c Cleanup and 'add' instruction for bigger test area 2021-01-15 23:27:38 +01:00
Luuk de Gram
bb74f72e97 stage2: refactor wasm backend - similar to the other backends 2021-01-15 23:27:38 +01:00
Jakub Konka
b204ea0349 macho: ensure that strtab always follows symtab
In rare occassions, it may happen that string table is allocated free
space preceeding symbol table. This is an error in the eyes of the `dyld`
dynamic loader and thus has to forbidden by the linker.
2021-01-15 23:22:28 +01:00
Guillaume Ballet
f7d7cb6268 crypto: add legacy keccak hash functions 2021-01-15 12:36:38 -08:00
Evan Haas
1702b413f7 translate-c: ensure bools are cast to int when necessary
Fixes two scenarios where @boolToInt() calls were missing:

1. Boolean expression cast to different-size int (char, long, etc)
2. Boolean expression used as parameter for function with int argument
2021-01-15 12:35:54 -08:00
Andrew Kelley
35686262f5 Merge pull request #7785 from ziglang/std-thread-primitives
organize std lib concurrency primitives and add RwLock
2021-01-15 12:31:17 -08:00
Koakuma
1d67ab8823 Fix _Qp_cmp definition 2021-01-15 19:07:39 +07:00
Koakuma
b531caac02 Fix f128 codegen on BE hosts 2021-01-15 19:07:38 +07:00
Koakuma
bbb58b10f6 Add compiler-rt stub for SPARC CPUs 2021-01-15 19:07:38 +07:00
Jakub Konka
2faf8c53d2 macho: use target arch page_size for codesig
It turns out I was wrong and we can set the page size to the actual
page size used by the target architecture when dividing the binary
into chunks and calculating a hash of each chunk for embedding within
the adhoc code signature. This shaves of a considerable amount of bytes
since we divide the code signature section by at least 2x.

I've also unified the `write` interface of `CodeSignature` struct to
follow that used in every other bit of `MachO`; namely, the functions
now accept a writer instead of a buffer, therefore, there is no need
to manually track where to write each struct field anymore.
2021-01-15 08:16:47 +01:00
Andrew Kelley
19f893c6bb std.Thread: avoid compile errors for single-threaded OS's 2021-01-14 22:42:29 -07:00
Andrew Kelley
ad301d687a fix namespace of kernel32 function calls 2021-01-14 21:42:49 -07:00
Andrew Kelley
9e1aeda3bf std.Thread.StaticResetEvent: call spinLoopHint appropriately 2021-01-14 21:34:30 -07:00
Andrew Kelley
9698ea3173 std.Thread.Mutex: restore the "Held" API
so that std.Thread.Mutex.Dummy can be used as a drop in replacement.
2021-01-14 21:28:22 -07:00
Andrew Kelley
a9667b5a85 organize std lib concurrency primitives and add RwLock
* move concurrency primitives that always operate on kernel threads to
   the std.Thread namespace
 * remove std.SpinLock. Nobody should use this in a non-freestanding
   environment; the other primitives are always preferable. In
   freestanding, it will be necessary to put custom spin logic in there,
   so there are no use cases for a std lib version.
 * move some std lib files to the top level fields convention
 * add std.Thread.spinLoopHint
 * add std.Thread.Condition
 * add std.Thread.Semaphore
 * new implementation of std.Thread.Mutex for Windows and non-pthreads Linux
 * add std.Thread.RwLock

Implementations provided by @kprotty
2021-01-14 20:41:37 -07:00
Asherah Connor
affb57aad9 use interfaces 2021-01-15 10:34:53 +11:00
Asherah Connor
9168b217b2 fix SectionHeaderIterator impl 2021-01-14 17:52:06 +11:00
Asherah Connor
32d69d70cf expose phdr, shdr parsing 2021-01-14 15:30:28 +11:00
Asherah Connor
49ab6bb429 std.elf: actually pass the pointer 2021-01-14 14:38:52 +11:00
Asherah Connor
1cea88917c std.elf: call it Header.parse 2021-01-14 14:38:52 +11:00
Asherah Connor
e6cdf9cebf std.elf: make Header pub 2021-01-14 14:38:52 +11:00
Asherah Connor
23fb19fe41 std.elf: expose parsing decoupled from std.fs.File 2021-01-14 14:38:52 +11:00
Asherah Connor
2b0e3ee228 std.os.uefi.protocols.FileProtocol: fix and expose get_position, set_position (#7762) 2021-01-13 21:46:22 -05:00
Andrew Kelley
ec1541de26 Merge pull request #7746 from kubkon/macho-extern-fn
macho: extern functions come to MachO!
2021-01-13 15:11:35 -08:00
Jakub Konka
2128149325 macho: update DebugSymbols to include DATA_CONST seg 2021-01-13 23:56:05 +01:00
Jakub Konka
4ffa8952cc macho: add x86_64 tests 2021-01-13 23:55:56 +01:00
Jakub Konka
2ea0901dd6 macho: properly populate offset into lazy bind info 2021-01-13 23:55:48 +01:00
Jakub Konka
f0d7ec6f33 macho: add x86_64 support 2021-01-13 23:55:37 +01:00
Jakub Konka
1b91a9f4c8 macho: bring back lld cc hot-fix 2021-01-13 23:55:28 +01:00
Jakub Konka
7d40aaad2b macho: document more code + add test case 2021-01-13 23:55:18 +01:00
Jakub Konka
b86d0e488b macho: refactor writing and managing externs 2021-01-13 23:55:06 +01:00
Jakub Konka
21c7217e09 macho: memorize start of stubs in helper 2021-01-13 23:54:56 +01:00
Jakub Konka
44a052a65f macho: write out stubs for new externs only 2021-01-13 23:54:46 +01:00
Jakub Konka
2f7cd71193 macho: fully working PoC with main and exit 2021-01-13 23:54:31 +01:00
Jakub Konka
bb691ea16b macho: first working draft of externs on macOS 2021-01-13 23:54:22 +01:00
Jakub Konka
6d2a6513f9 macho: write out binding info 2021-01-13 23:54:11 +01:00
Jakub Konka
5ae82956aa macho: write out rebase info 2021-01-13 23:54:01 +01:00
Jakub Konka
f44732c1b0 macho: populate stubs and stub_helper 2021-01-13 23:53:46 +01:00
Jakub Konka
51a13f8ea6 macho: add missing data sections 2021-01-13 23:53:36 +01:00
Jakub Konka
3d07f057b1 macho: prealloc DATA_CONST and DATA segments 2021-01-13 23:53:25 +01:00
Jakub Konka
5487dd13ea stage2: lay the groundwork in prep for extern fn
This commit lays the groundwork in preparation for implementing
handling of extern functions in various backends.
2021-01-13 14:51:23 -08:00
Jay Petacat
a021c7b1b2 Move fmt.testFmt to testing.expectFmt 2021-01-12 18:13:29 -08:00
Bill Nagel
2c79d669a7 add missing ECONNRESET from getsockoptError 2021-01-12 18:11:58 -08:00
Andrew Kelley
70c608add8 Merge pull request #7577 from semarie/emutls
implement emutls inside compiler_rt.zig
2021-01-12 17:54:02 -08:00
Andrew Kelley
e564d2ca3c Merge pull request #7714 from mikdusan/target-macos
macos: reimplement OS version detection
2021-01-12 16:45:50 -08:00
Bill Nagel
1e2be14b6b define nfds_t for windows 2021-01-12 16:37:58 -08:00
LemonBoy
65b7d2b4e1 stage1: Resolve alignment earlier in @alignCast
Fixes #7744
2021-01-12 16:36:51 -08:00
Andrew Kelley
ffc8a43dfb ci: stop directly pushing web page stuff to s3
This is now handled by the www.ziglang.org repo deploy script.
2021-01-12 17:27:36 -07:00
Andrew Kelley
23c6cca24d ci: give the updated website content to the website repo
and use master branch not hugo-redesign branch
2021-01-12 13:26:52 -07:00
Andrew Kelley
166e9ea689 ci: add stdDocs to downloads/index.json for master branch 2021-01-12 12:52:59 -07:00
Sébastien Marie
d7aa7dbab2 implement emutls in compiler_rt 2021-01-12 05:39:46 +00:00
Sébastien Marie
ebf2a7e9b9 add pthread_key functions 2021-01-12 05:39:46 +00:00
Andrew Kelley
8ea2b40e5f std.event.Loop: fix race condition when starting the time wheel
closes #7572
2021-01-11 22:23:03 -07:00
Andrew Kelley
0edde40c25 Merge 'Add support for no red zone'
Merges #7511
2021-01-11 22:07:47 -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
Lee Cannon
8932c2d745 Added support for no red zone 2021-01-11 22:07:14 -07:00
Michael Dusan
4c3de99253 more fixups
- clarify comments
- `NativeTargetInfo.detect()` propagate macOS errors
- `macos.detect()` drop `std.log` usage
2021-01-11 20:58:31 -05:00
Michael Dusan
f2be1fb23e macos: reimplement OS version detection
The macOS version is now obtained by parsing `SystemVersion.plist`.

Test cases added for plist files that date back to '2005 Panther and up
to the recent '2020 Big Sur 11.1 release of macOS.

Thus we are now able to reliably identify 10.3...11.1 and higher.

- drop use of kern.osproductversion sysctl
- drop use of kern.osversion sysctl (fallback)
- drop kern.osversion tests
- add `lib.std.zig.system.detect()`
- add minimalistic parser for `SystemVersion.plist`
- add test cases for { 10.3, 10.3.9, 10.15.6, 11.0, 11.1 }

closes #7569
2021-01-11 19:54:56 -05:00
Andrew Kelley
56c03881eb Merge branch 'rohlem-fix-GetFinalPathNameByHandle-before-win10_rs4'
Merges #7379
2021-01-11 17:48:33 -07:00
Rohlem
c96272f618 std.os.windows.GetFinalPathNameByHandle: remove intermediate buffers
... and mem.copy operations. Requires slightly larger input buffers than result length. Add helper functions std.mem.alignInBytes and std.mem.alignInSlice.
2021-01-11 17:48:19 -07:00
Rohlem
f301a8467c std.os.windows.GetFinalPathNameByHandle: remove QueryInformationFile code path 2021-01-11 17:48:18 -07:00
Rohlem
cb20503990 std.os.windows.GetFinalPathNameByHandle: address non-structural review comments 2021-01-11 17:48:18 -07:00
Rohlem
64c5f4979e std.os.windows.GetFinalPathNameByHandle: replace kernel32 by ntdll call
Removes the call to kernel32.GetFinalPathNameByHandleW in favor of NtQueryObject, which means we can reuse the other codepath's logic for DOS naming.
2021-01-11 17:48:18 -07:00
Rohlem
964bbcd0b1 introduce std.os.windows.QueryObjectName 2021-01-11 17:48:18 -07:00
Rohlem
09dc651476 std.os.windows.GetFinalPathNameByHandle: add test 2021-01-11 17:48:18 -07:00
Rohlem
450e467201 std.os.windows.GetFinalPathNameByHandle: reintroduce kernel32 for compatibility
The NtQueryInformationFile with .FileNormalizedNameInformation is only available in Windows 10 1803 (rs4) and later, however there is probably still another route we can go via ntdll.
2021-01-11 17:48:18 -07:00
Rohlem
4b280ac7e9 add std.zig.system.windows version check utility functions 2021-01-11 17:48:17 -07:00
Rohlem
2922a48309 move windows runtime version detection into std.zig.system.windows 2021-01-11 17:48:16 -07:00
Jonathan Knezek
fc10c9c4ce Add std.fmt.formatDuration and std.fmt.duration (#7297)
`formatDuration` works on a writer, and `duration` wraps a u64 to allow pleasant injection into format strings.
2021-01-11 19:15:56 -05:00
Andrew Kelley
025f1559a0 Merge pull request #7200 from Vexu/arr
Type coercion for pointers to anon literals
2021-01-11 16:09:28 -08:00
Andrew Kelley
4f5fa90d6d Merge pull request #7195 from Aransentin/master
A win32-api proposal, implemented for user32.zig
2021-01-11 16:02:40 -08:00
Andrew Kelley
483c057a77 Merge branch 'clean up writeFileAllUnseekable by using readers'
closes #7156
2021-01-11 16:52:29 -07:00
Andrew Kelley
d68adc5382 std.EarlyEOFReader: rename to LimitedReader 2021-01-11 16:51:56 -07:00
daurnimator
01d1a8a783 std: use fifo.pump in writeFileAllUnseekable 2021-01-11 16:48:56 -07:00
daurnimator
e873668d38 std: add LimitedReader: reader that returns EOF early 2021-01-11 16:48:30 -07:00
daurnimator
8695b9fbe7 std: use reader.skipBytes to avoid infinite loop in writeFileAllUnseekable
skipBytes correctly handles EOF for us
2021-01-11 16:47:48 -07:00
daurnimator
0ab8ae944c std: reader.skipBytes's num_bytes should be a u64 2021-01-11 16:47:48 -07:00
Vincent Rischmann
3468872d83 os/bits/linux: add the termios cc bits 2021-01-11 15:39:36 -08:00
Andrew Kelley
ec9158305d Merge pull request #7124 from LemonBoy/netstuff1
std: Decouple network streams from fs.File
2021-01-11 15:35:00 -08:00
Andrew Kelley
29c9d5896c Merge branch 'Stage2 begin implementing container types' 2021-01-11 16:25:21 -07:00
Andrew Kelley
5cc2e500e6 Merge branch 'SpexGuy-fix-comptime-cityhash'
I commented out the comptime test though since it was causing OOM on the
CI server.

closes #7331
2021-01-11 13:58:31 -07:00
Andrew Kelley
0c8e2c987d std CityHash: disable memory-expensive tests for now 2021-01-11 13:58:06 -07:00
Martin Wickham
21213127ec Modify cityhash to work at comptime 2021-01-11 13:52:52 -07:00
Andrew Kelley
73b17474d7 Merge pull request #7134 from alexnask/fix_std_fs_watch
The std.fs.Watch rewrite PR
2021-01-11 12:45:36 -08:00
LemonBoy
34720da3d0 Apparently unix sockets are supported on Windows
Starting from Windows 10 build 17063.
2021-01-11 21:43:15 +01:00
LemonBoy
d0beb4badb Let the kernel pick a random port
Avoid errors if the socket enters the TIME_WAIT state and we need to
re-execute this test before the OS releases it.

This problem was not really a problem before since the accept()-ed
socket was never closed on the server-side.
2021-01-11 21:43:14 +01:00
LemonBoy
676d7fc63c std: Add a small test for i/o on unix sockets 2021-01-11 21:43:13 +01:00
LemonBoy
89d6317b93 std: Decouple network streams from fs.File
The overlap between files and sockets is minimal and lumping them
together means supporting only a small subset of the functionalities
provided by the OS.
Moreover the socket and file handles are not always interchangeable: on
Windows one should use Winsock's close() call rather than the one used
for common files.
2021-01-11 21:43:09 +01:00
Travis
cc2981edfc update path.join to recognize any separators that isSep does 2021-01-11 11:15:34 -08:00
Andrew Kelley
1295525a7a Merge branch 'AdamGoertz-master'
closes #5080
closes #6887
2021-01-10 19:04:22 -07:00
Andrew Kelley
169810b20f zig fmt 2021-01-10 19:04:10 -07:00
Adam Goertz
0f32de77c9 impl lossyCast #5080 2021-01-10 19:02:41 -07:00
Timon Kruiper
e1d8073d2f stage2: add support for loops in LLVM backend
A simple `while(true) {}` loop generates the following LLVMIR:
```
define i32 @main() {
Entry:
  br label %Loop

Loop:                                 ; preds = %Loop, %Entry
  br label %Loop
}
```

Also implement TZIR printing for loops and add a corresponding test.
2021-01-10 17:47:34 -08:00
Vincent Rischmann
2117489e05 debug: don't fail printLineInfo if the source file is not readable
Without this dumping a stacktrace fails with this:

    Unable to dump stack trace: AccessDenied
2021-01-10 17:46:15 -08:00
joachimschmidt557
a7da90071e stage2: fix bug in genArg
When an argument is unused in the function body, still increment
arg_index so we still select the correct arguments in the args slice.
2021-01-10 00:41:02 -08:00
Andrew Kelley
29928af600 Merge pull request #7729 from jayschwa/remove-deprecated-stream
Remove deprecated stream aliases
2021-01-09 13:04:08 -08:00
Jay Petacat
a0ad2dee6a builtin: Add zig_version
This will enable code to perform version checks and make it easier to
support multiple versions of Zig.

Within the SemVer implementation, an intermediate value needed to be
coerced to a slice to workaround a comptime bug.

Closes #6466
2021-01-09 12:50:39 -08:00
Andrew Kelley
5c49a137d5 Merge pull request #7725 from FireFox317/even-more-llvm
stage2: initial implementation of control flow in LLVM backend + TZIR printing
2021-01-09 12:32:10 -08:00
xackus
e4b8148e9c Fix system library path detection on linux
Uses the NativeTargetInfo results instead of std.Target.current.
2021-01-08 20:07:59 -07:00
LemonBoy
eb696e453f stage2: Implicitly enable --eh_frame_hdr when compiling c/c++ files
Matches what Clang/GCC driver do.

Closes #7711
2021-01-08 19:01:05 -08:00
Sobeston
95e66a915b added mem.containsAtLeast 2021-01-08 18:12:30 -08:00
Jakub Konka
7e0e27e738 libstd: add missing MachO rebase opcodes in macho.zig 2021-01-08 23:41:51 +01:00
Jay Petacat
e72472d953 io: FindByteOutStream to FindByteWriter
See #4917
2021-01-08 16:54:56 -05:00
Jay Petacat
1595ce273e Remove deprecated stream aliases 2021-01-08 16:54:56 -05:00
Timon Kruiper
56c059077c stage2: add initial impl of control flow in LLVM backend
The following TZIR instrutions have been implemented in the backend:
- all cmp operators (lt, lte, gt, gte, eq, neq)
- block
- br
- condbr

The following LLVMIR is generated for a simple assert function:
```
define void @assert(i1 %0) {
Entry:
  %1 = alloca i1, align 1
  store i1 %0, i1* %1, align 1
  %2 = load i1, i1* %1, align 1
  %3 = xor i1 %2, true
  br i1 %3, label %Then, label %Else

Then:                                             ; preds = %Entry
  call void @llvm.debugtrap()
  unreachable

Else:                                             ; preds = %Entry
  br label %Block

Block:                                            ; preds = %Else
  ret void
}
```

See tests for more examples.
2021-01-08 19:30:52 +01:00
Timon Kruiper
3715ed7b54 stage2: implement TZIR printing for block and condbr
Zig code:
```
fn assert(ok: bool) void {
    if (!ok) unreachable;
}
```

TZIR:
```
Module.Function(name=assert):
  @0: void = {};
  %0: bool = arg(ok)
  %1: void = dbg_stmt()
  %2: void = block(
    %3: bool = not(%0)
    %4: noreturn = condbr(%3,
    then:
      %5: void = breakpoint()
      %6: noreturn = unreach()
    else:
      %7: noreturn = br(%2, @0)
    )
  )
  %8: noreturn = retvoid()
```
2021-01-08 12:13:27 +01:00
Julius Putra Tanu Setiaji
2b3b355a23 Add compileError message for StringHashMap in AutoHashMap 2021-01-07 23:51:53 -08:00
Andrew Kelley
3fdffe85c0 Merge pull request #7720 from Snektron/sockopt
Some sockopt stuff
2021-01-07 23:50:34 -08:00
Jonathan Marler
31802c6c68 remove z/Z format specifiers
Zig's format system is flexible enough to add custom formatters.  This PR removes the new z/Z format specifiers that were added for printing Zig identifiers and replaces them with custom formatters.
2021-01-07 23:49:22 -08:00
Jay Petacat
a9b505fa77 Reduce use of deprecated IO types
Related: #4917
2021-01-07 23:48:58 -08:00
Michael Dusan
8e9a1ac364 builder: propagate env_map for child processes 2021-01-07 23:48:24 -08:00
Jakub Konka
70771283c5 Want native headers when linking with frameworks
This PR ensures we use system libc headers and system search paths for
framework headers when linking against frameworks and compiling natively
on macOS.
2021-01-07 23:47:37 -08:00
Robin Voetter
ec7adeda2b Add EPERM to std.os.setsockopt 2021-01-08 02:34:42 +01:00
Robin Voetter
83fad7d4f7 Add IP_ constants 2021-01-08 01:35:52 +01:00
Andrew Kelley
c7666ff885 ci: import the update-download-page from www repo 2021-01-07 16:49:13 -07:00
Andrew Kelley
d8eba037a4 ci: fix path to update-download-page.zig script 2021-01-07 15:49:43 -07:00
Andrew Kelley
aa2422e830 ci: add github.com's public key for the ssh clone 2021-01-07 12:28:55 -07:00
Timon Kruiper
36950815a4 stage2 test: make sure to pass the dynamic linker to Compilation
Because this was not set, the `-dynamic-path` argument was not passed
to LLD when linking an ELF binary. This would still generate a valid glibc
binary, however when executing would result in a segfault.
2021-01-07 11:37:52 +01:00
Andrew Kelley
87aa052e23 ci: pass --override-lib-dir to emit std lib docs
Otherwise we get errors from conflicting std libs.
2021-01-07 02:58:27 -07:00
Andrew Kelley
ee1b370404 ci: don't use ninja on linux
I got this error when re-running the cmake line setting
-DZIG_EXECUTABLE:

```
ninja: warning: multiple rules generate zig1.o. builds involving
this target will not be correct; continuing anyway
[-w dupbuild=warn]
```

But it works fine with make.
2021-01-07 00:38:48 -07:00
Andrew Kelley
a279cf81b2 ci: add missing target/mcpu args to zig cc
In the previous commit, I forgot to add these.
2021-01-07 00:18:28 -07:00
Andrew Kelley
ce5222d945 ci: rework linux script
* no longer depend on apt.llvm.org, instead we rely on a zig-bootstrap
   tarball with pre-built Zig, LLVM, LLD, and Clang. Similar to the
   Windows Dev Kit but for Linux. This also makes the script no longer
   depend on Docker, libxml2, or GCC.
 * remove bash retry logic; it was only needed for flaky apt.llvm.org
   and isn't needed for the other resources we download.
 * build and upload the experimental std lib automatically generated
   docs. langref.html is moved to docs/langref.html because the std lib
   docs are in docs/std/.
 * the superfluous "zig" directory in $prefix/lib/zig/std/std.zig is
   removed from the tarball.
 * update_download_page makes a commit in the www.ziglang.org repository
   updating data/releases.json so that repository can manage deploys.
2021-01-06 23:40:17 -07:00
Jonathan Marler
f1ef0a80f1 fix LRESULT and LPARAM typedefs
LRESULT and LPARAM are currently typedef'd as ?*c_void, however, they are supposed to be typedef'd as LONG_PTR which is equivalent to isize in Zig.
2021-01-06 16:41:40 -08:00
Andrew Kelley
5ee0431527 stage2: update to new ArrayListHashMap API 2021-01-06 17:40:25 -07:00
Andrew Kelley
2f58efcc1f std.SpinLock: flatten and remove init/deinit
structs which are intended to be directly initialized and support static
initialization should not have init/deinit methods.
2021-01-06 17:36:06 -07:00
Andrew Kelley
d7d905696c Merge pull request #7622 from tetsuo-cpp/array-hash-map-improvements
std: Support equivalent ArrayList operations in ArrayHashMap
2021-01-06 16:32:23 -08:00
Andrew Kelley
76870a2265 Merge pull request #7700 from FireFox317/more-stage2-stuff-llvm
stage2: improvements to LLVM backend
2021-01-06 16:06:32 -08:00
BinaryWarlock
148c887ace spinlock: Default SpinLock.state to .Unlocked to allow default struct initialization
std.Mutex, which is struct initialized, is possibly defined to be std.SpinLock.
2021-01-06 15:54:30 -08:00
Andreas Karlsson
50af87a9e3 Fix example code in comments for asc and desc 2021-01-06 15:53:53 -08:00
joachimschmidt557
be6ac82ee1 stage2 ARM: fix stack offsets for genSetReg and genSetStack 2021-01-06 15:53:10 -08:00
joachimschmidt557
480d6182ad stage2 ARM: fix offsets in exitlude jump relocations 2021-01-06 15:53:10 -08:00
Frank Denis
5afd6204e8 Azure CI: update MSYS version 2021-01-06 15:52:34 -08:00
Andrew Kelley
efe94a9a12 stage2: C backend: support unused Decls 2021-01-06 16:47:09 -07:00
Timon Kruiper
b1cfa923be stage2: rename and move files related to LLVM backend 2021-01-06 10:52:20 +01:00
Timon Kruiper
31d1ec4c2f stage2: make use of llvm.Context in LLVM backend
This for example allows for multiple LLVM instances to run in parallel.

Also rename some functions in llvm_bindings.zig.

Fixes #7688
2021-01-06 10:52:20 +01:00
Timon Kruiper
5d5db833f2 stage2: hoist alloca instructions to top of function in LLVM backend
This way the generated code only has to setup the stack size at the
beginning of a function and this improves codegen.

Fixes #7689

```
fn foo() void {}

export fn hello(z: i8) void {
    var x: i16 = undefined;
    foo();
    var y: i32 = 1;
    y += z;
}
```
llvm-ir:
```
define void @hello(i8 %0) {
Entry:
  %1 = alloca i8, align 1
  %2 = alloca i16, align 2
  %3 = alloca i32, align 4
  store i8 %0, i8* %1, align 1
  %4 = load i8, i8* %1, align 1
  store i16 undef, i16* %2, align 2
  call void @foo()
  store i32 1, i32* %3, align 4
  %5 = load i32, i32* %3, align 4
  %6 = sext i8 %4 to i32
  %7 = add nsw i32 %5, %6
  store i32 %7, i32* %3, align 4
  ret void
}
```
2021-01-06 10:52:20 +01:00
Timon Kruiper
1149cd593e stage2: rename *const llvm.ValueRef to *const llvm.Value in LLVM backend
The same has been done for all the other LLVM types.
2021-01-06 10:52:19 +01:00
Timon Kruiper
70f6d16ae2 stage2: add initial impl for generating global decls in LLVM backend
Also adds support for extern functions, simple pointer and simple array
types and values.

A simple hello world now compiles:
`zig build-exe example.zig -fLLVM -lc`
```
extern fn puts(s: [*:0]const u8) c_int;
export fn main() c_int {
    _ = puts("hello world!");
    return 0;
}
```
2021-01-06 10:52:07 +01:00
Andrew Kelley
91e3431d4a stage2 test harness: don't try to run non-native C backend tests 2021-01-05 20:44:19 -07:00
g-w1
ab5f7b5156 stage2: add compile log statement 2021-01-05 18:43:41 -07:00
Andrew Kelley
38572ee894 Merge branch 'stage2-rework-cbe'
Reworks the C backend and -femit-h to properly participate in
incremental compilation.

closes #7602
2021-01-05 17:42:16 -07:00
Andrew Kelley
3e39d0c44f minor fixups from moving identifiers and files around 2021-01-05 17:41:22 -07:00
Andrew Kelley
1a2dd85570 stage2: C backend: re-implement emit-h
and also mark functions as `extern "C"` as appropriate to support c++
compilers.
2021-01-05 17:41:14 -07:00
Andrew Kelley
cd95444e47 stage2: C backend: remove format() hackery
All C backend tests passing now, except for emit-h tests. Next task in
the branch is to restore emit-h.
2021-01-05 17:41:14 -07:00
Andrew Kelley
58cfaa5982 stage2: C backend: adjust spaces around functions 2021-01-05 17:41:14 -07:00
Andrew Kelley
e1811f72eb stage2: link.C: use pwritev 2021-01-05 17:41:14 -07:00
Andrew Kelley
7b8cede61f stage2: rework the C backend
* std.ArrayList gains `moveToUnmanaged` and dead code
   `ArrayListUnmanaged.appendWrite` is deleted.
 * emit_h state is attached to Module rather than Compilation.
 * remove the implementation of emit-h because it did not properly
   integrate with incremental compilation. I will re-implement it
   in a follow-up commit.
 * Compilation: use the .codegen_failure tag rather than
   .dependency_failure tag for when `bin_file.updateDecl` fails.

C backend:
 * Use a CValue tagged union instead of strings for C values.
 * Cleanly separate state into Object and DeclGen:
   - Object is present only when generating a .c file
   - DeclGen is present for both generating a .c and .h
 * Move some functions into their respective Object/DeclGen namespace.
 * Forward decls are managed by the incremental compilation frontend; C
   backend no longer renders function signatures based on callsites.
   For simplicity, all functions always get forward decls.
 * Constants are managed by the incremental compilation frontend. C
   backend no longer has a "constants" section.
 * Participate in incremental compilation. Each Decl gets an ArrayList
   for its generated C code and it is updated when the Decl is updated.
   During flush(), all these are joined together in the output file.
 * The new CValue tagged union is used to clean up using of assigning to
   locals without an additional pointer local.
 * Fix bug with bitcast of non-pointers making the memcpy destination
   immutable.
2021-01-05 17:41:14 -07:00
Noam Preil
9360e5887c integrate CBE with Compilation.update pipeline (closes #7589)
* CBE buffers are only valid during a flush()
* the file is reopened and truncated during each flush()
* CBE now explicitly ignores updateDecl and deleteDecl
* CBE updateDecl is gone
* test case is enabled
2021-01-05 17:41:14 -07:00
xackus
6c4924408b std.c add syslog 2021-01-05 13:09:40 -08:00
xackus
1640c357f4 freebsd, netbsd, dragonfly: add struct timeval 2021-01-05 13:07:25 -08:00
Alex Cameron
d92ea56884 std: Support equivalent ArrayList operations in ArrayHashMap 2021-01-06 00:55:51 +11:00
Alex Cameron
89286376c6 std: Rename ArrayList shrink => shrinkAndFree 2021-01-06 00:55:51 +11:00
Andrew Kelley
3e8aaee829 std: skip more tests on Windows to save CI memory
I've enabled only the tests that check things specific to Windows that
are not tested by other systems.
2021-01-04 22:25:04 -07:00
Andrew Kelley
16896a9d8b ci: skip crypto tests on windows
Trying to buy us more time on the Windows CI.
2021-01-04 15:57:54 -07:00
Andrew Kelley
66e5e92a3e Merge pull request #7592 from LemonBoy/fix-7188
Allow variable captures on multi-prong switch arms
2021-01-04 14:23:01 -08:00
Evan Haas
d95724454c Allow dollar sign $ in identifiers in translate-c
In strictly conforming C, identifiers cannot container dollar signs.
However GCC and Clang allow them by default, so translate-c should
handle them. See http://gcc.gnu.org/onlinedocs/cpp/Tokenization.html
I encountered this in the wild in windows.h

Fixes #7585
2021-01-04 14:14:04 -08:00
Felix (xq) Queißner
819f2a01a1 Fixes missing error prong in std.os.send. 2021-01-04 14:03:39 -08:00
J.C. Moyer
fc3508b7e8 Fix off-by-one error in SinglyLinkedList.len() and add associated tests 2021-01-04 14:03:21 -08:00
xackus
a93c123f83 std.c: add some noalias 2021-01-04 14:02:42 -08:00
Andrew Kelley
2fe8a48215 ci: omit stage2 backend from stage1 on Windows
to avoid out-of-memory on the CI runs.
2021-01-04 14:59:18 -07:00
Andrew Kelley
462c1d8c74 stage2: add more perf tracing points 2021-01-04 14:33:32 -07:00
Andrew Kelley
fc38b42521 Revert "Fix #7296:"
This broke build scripts that wanted to refer to `exe_dir` or
`install_path`.

There has also been some pushback and discussion on this breaking
change. I think it should be re-evaluated.

This reverts commit a1a1929cf4.
2021-01-04 13:49:17 -07:00
Andrew Kelley
ef2fa67ef0 Merge branch 'g-w1-stage2-evalbranch'
closes #7682
2021-01-04 13:40:51 -07:00
Andrew Kelley
7e64dc4221 stage2: improvements to @setEvalBranchQuota
* extract magic number into a constant
 * properly use result location casting for the operand
 * naming convention for ZIR instructions
2021-01-04 13:40:01 -07:00
g-w1
638f93ebdc stage2: implementation of @setEvalBranchQuota:
`@setEvalBranchQuota` can be called before the comptime/inline call
stack is created.

For example:

```zig
@setEvalBranchQuota(100);
comptime {
    while (true) {}
}
```

Here we need to set the branch_quota before the comptime block creates a
scope for the branch_count.
2021-01-04 12:42:52 -07:00
joachimschmidt557
aa0906e9aa stage2 x86_64: fix bug in Function.gen
Previously, the x86_64 backend would remove code for exitlude relocs
if the jump amount were 0. This causes issues as earlier jumps rely on
the jump being present at the same address.
2021-01-03 19:54:12 -08:00
Frank Denis
4400d2d7ab std/crypto: add BLAKE2-160 types and tests 2021-01-03 19:53:30 -08:00
daurnimator
e4c4a0a5f6 Improve uring definitions 2021-01-03 19:52:20 -08:00
Andrew Kelley
53a0b7997d Merge pull request #7681 from kubkon/stage2-aarch64-fn-args
stage2: basic fn args for aarch64
2021-01-03 19:51:38 -08:00
Andrew Kelley
c8e44d82bd stage2: remove the Cache deadlock detection code
It's more trouble than it's worth; it didn't even catch the most recent
incident because it was across process boundaries anyway.
2021-01-03 20:34:51 -07:00
Andrew Kelley
404dc9692e stage2: fix Cache debug deadlock code memory leak 2021-01-03 20:34:51 -07:00
Andrew Kelley
5c92e24a29 drone ci: skip compile error tests to save time
These are covered by other CI scripts and we're up against Drone CI time
limits.
2021-01-03 20:10:07 -07:00
Andrew Kelley
f6644255f5 Merge pull request #7598 from FireFox317/more-llvm-stage2
stage2: More improvements to self-hosted LLVM backend
2021-01-03 16:09:14 -08:00
Evan Haas
5cc131030c Static function declarations with no prototype should not be variadic
If a static function is defined with no argument list and no prototype
is given, it should be treated as a function that takes no arguments
rather than as a variadic function.

Fixes #7594
2021-01-03 15:08:32 -08:00
Jakub Konka
807dc56fd6 stage2: add aarch64 stage2 tests
Fix missing string format specifier in Mach-O used to generate
path to debug symbols bundle.
2021-01-03 23:20:09 +01:00
Jakub Konka
2a410baa2b stage2: implement basic function params aarch64
Implement missing `.register` prong for `aarch64` `genSetReg`.
2021-01-03 23:03:20 +01:00
Timon Kruiper
0151f3b76a stage2: Add support for testing LLVM enabled builds in test-stage2
To make sure that we don't have to rebuild libc for every case, we now
have a seperate cache directory for the global cache, which remains
the same between test runs.

Also make sure to destory the Compilation before executing a child process,
otherwise the compiler deadlocks. (#7596)
2021-01-03 21:13:38 +01:00
Timon Kruiper
a926c91814 stage2: enable building test-stage2 with LLVM backend enabled
We can now run `zig build test-stage2 -Denable-llvm`.
2021-01-03 17:39:43 +01:00
Timon Kruiper
7e5aacab69 stage2: add some missing deallocations in Compilation.zig 2021-01-03 17:39:43 +01:00
Timon Kruiper
3c05c60acc stage2: Output the LLVM object files in the cache directory
Also make sure to properly free everything.
2021-01-03 17:39:43 +01:00
Timon Kruiper
0008bef1e6 stage2: add support for integers in LLVM backend
Also adds support for simple operators, like add and subtract.
The intcast and bitcast instruction also have been implemented.

Linking with libc also works, so we can now generate working executables!

`zig build-exe example.zig -fLLVM -lc`:
```
fn add(a: i32, b: i32) i32 {
    return a + b;
}

export fn main() c_int {
    var a: i32 = -5;
    const x = add(a, 7);
    var y = add(2, 0);
    y -= x;
    return y;
}
```
2021-01-03 17:39:30 +01:00
Timon Kruiper
e095ebf312 stage2: make use of proper LLVM intrinsic APIs in LLVM backend 2021-01-03 17:23:30 +01:00
Timon Kruiper
da545d6a31 stage2: implement argument passing and returning in LLVM backend
Furthermore add the Not instruction.

The following now works:
```
export fn _start() noreturn {
    var x: bool = true;
    var other: bool = foo(x);
    exit();
}

fn foo(cond: bool) bool {
    return !cond;
}

fn exit() noreturn {
    unreachable;
}
```
2021-01-03 17:23:30 +01:00
Timon Kruiper
47a4d43e41 stage2: Add code generation for Load instruction in LLVM backend
The following now works:
```
export fn _start() noreturn {
    var x: bool = true;
    var y: bool = x;
    exit();
}

fn exit() noreturn {
    unreachable;
}
```
2021-01-03 17:23:30 +01:00
Timon Kruiper
19cfd310b0 stage2: implement register allocation in LLVM self-hosted backend
A HashMap has been added which store the LLVM values used in a function.
Together with the alloc and store instructions the following now works:
```
export fn _start() noreturn {
    var x: bool = true;
    exit();
}

fn exit() noreturn {
    unreachable;
}
```
2021-01-03 17:23:30 +01:00
Timon Kruiper
a5dab15ede stage2: clear err_msg after it has been added to module.failed_decls 2021-01-03 17:23:30 +01:00
Timon Kruiper
0ed04aac8b stage2: fix building self-hosted compiler with -Dstatic-llvm
This supersedes c81ae52ee0
2021-01-03 17:23:30 +01:00
Frank Denis
5aac2fc281 std/crypto: properly support arbitrary output sizes
Fixes #7657
2021-01-02 22:32:57 -08:00
Andrew Kelley
683814190b Merge pull request #7612 from g-w1/do-7296
Implement #7296
2021-01-02 22:05:31 -08:00
Andrew Kelley
d8f3f14532 Merge pull request #7647 from ziglang/stage2-comptime-fn-call
stage2: comptime function calls and inline function calls
2021-01-02 22:01:51 -08:00
Andrew Kelley
654832253a stage2: support recursive inline/comptime functions
zir.Inst no longer has an `analyzed_inst` field. This is previously how
we mapped ZIR to their TZIR counterparts, however with the way inline
and comptime function calls work, we can potentially have the same ZIR
structure being analyzed by multiple different analyses, such as during
a recursive inline function call. This would cause the `analyzed_inst`
field to become clobbered. So instead, we use a table to map the
instructions to their semantically analyzed counterparts. This will help
with multi-threaded compilation as well.

Scope.Block.Inlining is split into 2 different layers of "sharedness".
The first layer is shared by the whole inline/comptime function call
stack. It contains the callsite where something is being inlined and the
branch count/quota. The second layer is different per function call but
shared by all the blocks within the function being inlined.

Add support for debug dumping br and brvoid TZIR instructions.

Remove the "unreachable code" error. It was happening even for this case:

```zig
if (comptime_condition) return;
bar(); // error: unreachable code
```

We will need smarter logic for when it is legal to emit this compile
error.

Remove the ZIR test cases. These are redundant with other higher level
Zig source tests we have, and maintaining support for ZIRModule as a
first-class top level abstraction is getting in the way of clean
compiler design for the main use case. We will have ZIR/TZIR based test
cases someday to help with testing optimization passes and ZIR to TZIR
analysis, but as is, these test cases are not accomplishing that, and
they are getting in the way.
2021-01-02 22:42:07 -07:00
g-w1
3d151fbfc8 fix 7665:
only add self exe path when testing
2021-01-02 20:35:44 -08:00
Andrew Kelley
50a530196c stage2: fix handling compile error in inline fn call
* scopes properly inherit inlining information
 * compile errors of inline function calls are properly attached to the
   caller rather than the callee.
   - added a test case for this
 * --watch still opens a repl if compile errors happen.
2021-01-02 19:11:56 -07:00
Andrew Kelley
006e7f6805 stage2: re-use ZIR for comptime and inline calls
Instead of freeing ZIR after semantic analysis, we keep it around so
that it can be used for comptime calls, inline calls, and generic
function calls. ZIR memory is now managed by the Decl arena.

Debug dump() functions are conditionally compiled; only available in
Debug builds of the compiler.

Add a test for an inline function call.
2021-01-02 19:11:55 -07:00
Andrew Kelley
9362f382ab stage2: implement function call inlining in the frontend
* remove the -Ddump-zir thing. that's handled through --verbose-ir
 * rework Fn to have an is_inline flag without requiring any more memory
   on the heap per function.
 * implement a rough first version of dumping typed zir (tzir) which is
   a lot more helpful for debugging than what we had before. We don't
   have a way to parse it though.
 * keep track of whether the inline-ness of a function changes because
   if it does we have to go update callsites.
 * add compile error for inline and export used together.

inline function calls and comptime function calls are implemented the
same way. A block instruction is set up to capture the result, and then
a scope is set up that has a flag for is_comptime and some state if the
scope is being inlined.

when analyzing `ret` instructions, zig looks for inlining state in the
scope, and if found, treats `ret` as a `break` instruction instead, with
the target block being the one set up at the inline callsite.

Follow-up items:
 * Complete out the debug TZIR dumping code.
 * Don't redundantly generate ZIR for each inline/comptime function
   call. Instead we should add a new state enum tag to Fn.
 * comptime and inlining branch quotas.
 * Add more test cases.
2021-01-02 19:11:19 -07:00
Andrew Kelley
fea8659b82 stage2: comptime function calls
* Function calls that happen in a comptime scope get called at
   compile-time. We do this by putting the parameters in place as
   constant values and then running regular function analysis on the
   body.
 * Added `Scope.Block.dump()` for debugging purposes.
 * Fixed some code to call `identifierTokenString` rather than
   `tokenSlice`, making it work for `@""` syntax.
 * Implemented `Value.copy` for big integers.

Follow-up issues to tackle:
 * Adding compile errors to the callsite instead of the callee Decl.
 * Proper error notes for "called from here".
   - Related: #7555
 * Branch quotas.
 * ZIR support?
2021-01-02 19:10:11 -07:00
Andrew Kelley
fb37c1b091 Merge branch 'LemonBoy-revive-6680'
closes #6870
2021-01-02 19:03:37 -07:00
Andrew Kelley
974c008a0e convert more {} to {d} and {s} 2021-01-02 19:03:14 -07:00
LemonBoy
5b981b1be7 Remove some unwanted changes
Leftovers after a long rebase.
2021-01-02 17:12:58 -07:00
LemonBoy
608a73efb1 Decrement max_depth when printing slice elements 2021-01-02 17:12:57 -07:00
LemonBoy
04f37dcd8e stage2: Use {z} instead of {s} in generated Zig code 2021-01-02 17:12:57 -07:00
LemonBoy
1fbe89dc2e langref: Update langref to use {s} 2021-01-02 17:12:57 -07:00
LemonBoy
d2f6fa1608 Fix more stray uses of {} for formatting strings 2021-01-02 17:12:57 -07:00
LemonBoy
1ca2deca33 std: Disable the special casing of {} for u8 slices/arrays
Unless {s} is specified the contents won't be treated as a string.
2021-01-02 17:12:57 -07:00
LemonBoy
4420afe64d tests: Use {s} instead of {} when formatting strings 2021-01-02 17:12:57 -07:00
LemonBoy
1c13ca5a05 stage2: Use {s} instead of {} when formatting strings 2021-01-02 17:12:57 -07:00
LemonBoy
dd973fb365 std: Use {s} instead of {} when printing strings 2021-01-02 17:12:57 -07:00
LemonBoy
5a06fdfa55 Use same brace pairs for arrays/slices/vectors 2021-01-02 17:12:57 -07:00
LemonBoy
d4a8fc8b67 Small cleanup 2021-01-02 17:12:57 -07:00
data-man
2b5e93fd3e Add formatting for arrays 2021-01-02 17:12:57 -07:00
LemonBoy
6f53653db1 std: Refactor the slice formatting code
Also fix the `*` specifier for more types, print an error message if we
can't show the value address.
2021-01-02 17:12:57 -07:00
ryuukk
5275280ede Formatting fix 2021-01-02 17:12:57 -07:00
ryuukk
1d97747665 Pretty print Slices
This code is adapted from pixelherodev paste from IRC

I have added a new fmt option to handle printing slice values ``{v}`` or ``{V}``

While i think it can be made the default, i want your opinion about it

```zig
    var slicea = [0]u32{};
    var sliceb = [3]u32{ 1, 2, 3 };

    std.log.info("Content: {v}", .{slicea});
    std.log.info("Content: {v}", .{sliceb});
```

will print:

```
info: Content: []
info: Content: [1, 2, 3]
```

Question:

Should we drop ``{v}`` and make it the default behavior?
2021-01-02 17:12:57 -07:00
Cameron Conn
db1e97d4b1 Improve documentation for ArrayList, ArrayListUnmanaged, etc. (#7624)
* Improve ArrayList & co documentation

- Added doc comments about the validity of references to elements in
an ArrayList and how they may become invalid after resizing operations.
- This should help users avoid footguns in future.

* Improve ArrayListUnmanaged & co's documentation

- Port improved documentation from ArrayList and ArrayList aligned to
  their unmanaged counterparts.
- Made documentation for ArrayListUnmanaged & co more inclusive and
  up-to-date.
- Made documentation more consistent with `ArrayList`.

* Corrections on ArrayList documentation.

- Remove incorrect/unpreferred wording on ArrayList vs
  ArrayListUnmanaged.
- Fix notes about the alignment of ArrayListAligned
- Be more verbose with warnings on when pointers are invalidated.
- Copy+paste a few warnings

* add warning to replaceRange

* revert changes to append documentation
2021-01-02 19:06:51 -05:00
LemonBoy
1856dfea6b stage1: Use correct format specifier for size_t parameters
Use `Iu` on Windows, the integer width depends on the target being
a 32bit or a 64bit one.
2021-01-02 16:04:34 -08:00
Sizhe Zhao
af8eab546e Fix usage message 2021-01-02 16:03:41 -08:00
Andrew Kelley
44c9bf559b std: disable a couple tests on windows
They are passing but we're hitting OOM on the Windows CI server. This is
to buy us more time until stage2 rescues us from the CI memory crisis.
2021-01-02 12:21:19 -07:00
Jakub Konka
5a6579611f Merge pull request #7506 from kubkon/fix-6923
zig cc: detect framework include paths when native
2021-01-02 20:08:37 +01:00
Jakub Konka
763d807377 Duplicate OSAtomic.h between aarch64 and x86_64
The reason this is required is for two reasons: 1) the libc
targeting `aarch64` macOS is slightly newer than that targeting
`x86_64`, and 2) `OSAtomic.h` uses relative imports rather than
system-wide imports for accompanying headers which clearly is an
oversight on Apple's part. Until such time when `libkern` headers
between `x86_64` and `aarch64` are identical, this will require a
manual intervention to duplicate the relevant headers between the
respective architectures.
2021-01-02 15:30:14 +01:00
Jakub Konka
91a35e1a92 Detect native iframework dirs on macOS
This commit adds default search paths for system frameworks
on macOS while also adding `-isysroot` for OS versions at least BigSur.
Since BigSur (11.0.1), neither headers nor libs exist in standard
root locations (`/usr/include`, `/System/Library/Frameworks`). Instead, they
are now exclusively part of the installed developer toolchain (either
via XCode.app or CLT), and specifying `-isysroot` allows us to keep
using universal search paths such as `/System/Library/Frameworks` while
only changing the include flag from `-iframework` to
`-iframeworkwithsysroot`.
2021-01-02 15:29:05 +01:00
Sébastien Marie
a9c75a2b48 openbsd: add pollfd interface 2021-01-01 20:05:19 -08:00
Andrew Kelley
ca0b03f7b5 Merge branch 'jayschwa-ci-deep-clone'
closes #7629
2021-01-01 21:03:35 -07:00
Andrew Kelley
ec8c25fd8f Restore the reverted semantic versioning commits
restore "Comply with semantic versioning pre-release format"
restore "stage2: SemVer compliance for development builds"
restore "Remove 'g' prefix from commit hash in Zig semver"

This reverts commit d96d8639e5.
This reverts commit e8810f5794.
This reverts commit 9afe5859a3.
2021-01-01 21:02:32 -07:00
Jay Petacat
993f4b5a06 ci: fix git describe
git describe is used for version string creation, but it had to be
reverted in commit 69da6ba because it was broken in CI builds.
Azure Pipelines and Drone perform shallow clones by default.
This change reconfigures them to fetch history and tags. It adds tens of
seconds, which is negligible compared to overall build and test time.

Related: #6466, #6509, #7601
2021-01-01 20:41:39 -07:00
Isaac Freund
d3ecbbebd3 std/build: assert that install paths are relative
If absolute paths are passed they will work unless $DESTDIR is set,
which causes subtly broken build.zig's.
2021-01-01 18:57:23 -08:00
Andrew Kelley
3dafc5b9a3 Merge branch 'daurnimator-meta.fields'
closes #7420
2021-01-01 16:01:27 -07:00
daurnimator
bbab5e19b4 std: loop in trailer flags can be indexing operation 2021-01-01 15:48:48 -07:00
daurnimator
4387e50d4f std: use FieldEnum from TrailerFlags 2021-01-01 15:48:48 -07:00
daurnimator
9c97a07f18 std: have std.meta.fieldInfo take an enum rather than a string 2021-01-01 15:48:46 -07:00
daurnimator
73bf2e1525 std: add std.meta.FieldEnum 2021-01-01 15:48:04 -07:00
joachimschmidt557
c5ec096b2f stage2 AArch64: add logical (shifted register) instructions 2021-01-01 14:43:12 -08:00
Andrew Kelley
6c0c275b27 Merge branch 'LemonBoy-panicthreadid'
closes #6869
2021-01-01 14:57:03 -07:00
Andrew Kelley
c24540d263 std.debug: adjust panic message
also extern "c" instead of extern "pthread"
2021-01-01 14:56:26 -07:00
LemonBoy
c9756ca0e1 std: Show the panicking thread ID
Annotate the panic message with the thread ID to know who's the culprit.
2021-01-01 14:54:53 -07:00
Sizhe Zhao
3bce5b2f30 Fix ssize_t definition 2021-01-01 13:47:18 -08:00
Andrew Kelley
99203e4177 Merge pull request #7578 from vrischmann/walker
fix segfault in std.fs.Walker
2021-01-01 13:28:01 -08:00
Andrew Kelley
4cc374c639 Merge pull request #7634 from daurnimator/packed-init-all-to
Add PackedIntArray .initAllTo function
2021-01-01 13:23:18 -08:00
Andrew Kelley
dfacac916f Merge pull request #7565 from joachimschmidt557/stage2-arm
stage2 ARM: add conditional branches
2021-01-01 13:19:11 -08:00
Jakub Konka
5dfeb6cbc8 macho: unblock stage2 on 32bit platforms (#7632)
* macho: unblock stage2 on 32bit platforms

Unblocks compilation of stage2 on 32bit platforms, and fixes #7630.

* Use libstd convention: reads - usize, writes - u64
2021-01-01 21:28:52 +01:00
Andrew Kelley
1cef0be01b Merge pull request #7640 from daurnimator/use-markInvalidUserInput
Don't process.exit() on invalid option use .markInvalidUserInput
2021-01-01 11:48:36 -08:00
daurnimator
aa631cfd1f Build errors should be followed by two newlines 2021-01-02 04:13:08 +11:00
daurnimator
b3c9dfc9cc Don't process.exit() on invalid option use .markInvalidUserInput 2021-01-02 04:09:59 +11:00
daurnimator
ad1780959d std/build.zig: use (existing) warn function alias 2021-01-02 04:01:21 +11:00
daurnimator
03e2c53747 Add workaround in PackedIntArray .initAllTo for #7635 2021-01-02 01:10:47 +11:00
daurnimator
31ba9d569b Add PackedIntArray .initAllTo function 2021-01-02 00:52:47 +11:00
joachimschmidt557
a2ab2fb9b0 stage2 ARM: Add simple tests for conditional branching 2021-01-01 12:22:17 +01:00
joachimschmidt557
c52ca0b178 stage2 ARM: implement genSetReg with compare_flags 2021-01-01 12:22:16 +01:00
joachimschmidt557
85e1b47c40 stage2 ARM: implement genCondBr for compare_flags 2021-01-01 12:22:16 +01:00
joachimschmidt557
4d2919a1ee stage2 ARM: implement genCondBr 2021-01-01 12:22:14 +01:00
g-w1
33e53d7294 update .gitignore to include /release/ and /debug/ 2020-12-31 21:30:25 -05:00
g-w1
a1a1929cf4 Fix #7296:
* makes '$build_root/{install,debug}/' the default prefix. This makes it not '$pwd/zig-cache/'.
2020-12-31 20:02:07 -05:00
Andrew Kelley
93bb1d93cd Merge pull request #7616 from ziglang/stage2-inferred-vars
stage2: inferred local variables
2020-12-31 16:28:08 -08:00
Andrew Kelley
982acc22fd stage2: compile error for invalid var type 2020-12-31 17:25:42 -07:00
Andrew Kelley
79a9391414 stage2: no Payload for Type.Tag.inferred_alloc
Simpler, less memory usage. The Value has all the info needed.
2020-12-31 16:51:40 -07:00
Frank Denis
6c2e0c2046 Year++ 2020-12-31 15:45:24 -08:00
Andrew Kelley
69da6ba14d Merge branch 'revert-semver'
Updating the download page is stuck because in all cases
`zig version` is outputting 0.8.0 rather than e.g.
0.8.0-dev.716+fbf269cc4.

See #6466
2020-12-31 16:41:54 -07:00
Andrew Kelley
d96d8639e5 Revert "Comply with semantic versioning pre-release format"
This reverts commit bbe2cca1ae.
2020-12-31 16:41:42 -07:00
Andrew Kelley
e8810f5794 Revert "stage2: SemVer compliance for development builds"
This reverts commit 4af763d401.
2020-12-31 16:41:35 -07:00
Andrew Kelley
9afe5859a3 Revert "Remove 'g' prefix from commit hash in Zig semver"
This reverts commit 02438aabe3.
2020-12-31 16:41:24 -07:00
Jakub Konka
fbf269cc47 More MachO.zig fixes ensuring 32bit compat
Partial resolution to #7614.
2020-12-31 14:57:08 +01:00
LemonBoy
102e45e04f stage1: Remove stray brace in rarely-tested code path
This should fix #7614 or part of it.
2020-12-31 14:35:19 +01:00
Jakub Konka
707b81ec37 Make sure MachO.zig compiles on 32bit hosts
This should fix #7614 or part of it.
2020-12-31 14:30:53 +01:00
Jakub Konka
46ea7a704c Merge pull request #7608 from kubkon/macho-dsym
macho: add preliminary support for DWARF debugging symbols
2020-12-31 11:38:13 +01:00
Andrew Kelley
7deb1f4f6c stage2: type inference for local var 2020-12-31 02:42:48 -07:00
Jakub Konka
0fd3015e55 macho: sentinel can be 4 byte long 2020-12-31 10:19:04 +01:00
Jakub Konka
9369176332 macho: advance VM address of DWARF sections when relocating 2020-12-31 10:19:04 +01:00
Jakub Konka
ea4ff34e13 macho: put all DWARF-related logic into DebugSymbols 2020-12-31 10:19:04 +01:00
Jakub Konka
d189614647 macho: move updateDeclLineNumber logic to DebugSymbols 2020-12-31 10:19:04 +01:00
Jakub Konka
60b3c4ae3c macho: refactor and fix stage2 tests 2020-12-31 10:19:04 +01:00
Jakub Konka
364691fa1f macho: add decl line and file info to subprogram 2020-12-31 10:19:04 +01:00
Jakub Konka
fa28f7006d macho: fix bundle name to .dSYM 2020-12-31 10:19:04 +01:00
Jakub Konka
9318656ce2 macho: use 32bit DWARF format 2020-12-31 10:19:04 +01:00
Jakub Konka
2875a7335a macho: add Elf dwarf sections 2020-12-31 10:19:04 +01:00
Jakub Konka
d4725cb40b macho: prealloc space for debug sections in dSym 2020-12-31 10:19:04 +01:00
Jakub Konka
3174508903 macho: write symbol and string tables to dSym 2020-12-31 10:19:04 +01:00
Jakub Konka
d9ce7a021b macho: copy snapshots of segment commands 2020-12-31 10:19:04 +01:00
Jakub Konka
a7bae1b857 macho: write matching UUID to dSym bundle 2020-12-31 10:19:04 +01:00
Jakub Konka
cf94341910 macho: write Mach-O dSym header 2020-12-31 10:19:04 +01:00
Jakub Konka
bd99a87dc2 macho: create dSym bundle next to final artefact
macOS requires the debug symbols to either be part of the intermediate
object file `whatever.o` or a companion `whatever.dSym` bundle. The
former case seems ill-suited for our needs since it subscribes to
the old-fashioned compilation strategy using intermediate compilation
units; the latter is what we need however on macOS the debug symbols
unlike in Elf are not part of the final artefact; rather they sit
next to it in its own Mach-O file.
2020-12-31 10:19:04 +01:00
Jakub Konka
0ff56e8bb1 macho: add and populate UUID load command 2020-12-31 10:19:04 +01:00
Jakub Konka
e1451f92f8 macho: move findFreeSpace into SegmentCommand
One exception will be treatment of the __LINKEDIT segment which
will be handled separately inside MachO directly since it doesn't
include any sections.
2020-12-31 10:19:04 +01:00
Andrew Kelley
595397dbeb Merge pull request #7601 from jayschwa/stage2-semver
stage2: SemVer compliance for development builds
2020-12-31 01:15:18 -08:00
Andrew Kelley
a46d24af1c stage2: inferred local variables
This patch introduces the following new things:

Types:
 - inferred_alloc
   - This is a special value that tracks a set of types that have been stored
     to an inferred allocation. It does not support most of the normal type queries.
     However it does respond to `isConstPtr`, `ptrSize`, `zigTypeTag`, etc.
   - The payload for this type simply points to the corresponding Value
     payload.

Values:
 - inferred_alloc
   - This is a special value that tracks a set of types that have been stored
     to an inferred allocation. It does not support any of the normal value queries.

ZIR instructions:
 - store_to_inferred_ptr,
   - Same as `store` but the type of the value being stored will be used to infer
     the pointer type.
 - resolve_inferred_alloc
   - Each `store_to_inferred_ptr` puts the type of the stored value into a set,
     and then `resolve_inferred_alloc` triggers peer type resolution on the set.
     The operand is a `alloc_inferred` or `alloc_inferred_mut` instruction, which
     is the allocation that needs to have its type inferred.

Changes to the C backend:
 * Implements the bitcast instruction. If the source and dest types
   are both pointers, uses a cast, otherwise uses memcpy.
 * Tests are run with -Wno-declaration-after-statement. Someday we can
   conform to this but not today.

In ZIR form it looks like this:

```zir
fn_body main { // unanalyzed
  %0 = dbg_stmt()
=>%1 = alloc_inferred()
  %2 = declval_in_module(Decl(add))
  %3 = deref(%2)
  %4 = param_type(%3, 0)
  %5 = const(TypedValue{ .ty = comptime_int, .val = 1})
  %6 = as(%4, %5)
  %7 = param_type(%3, 1)
  %8 = const(TypedValue{ .ty = comptime_int, .val = 2})
  %9 = as(%7, %8)
  %10 = call(%3, [%6, %9], modifier=auto)
=>%11 = store_to_inferred_ptr(%1, %10)
=>%12 = resolve_inferred_alloc(%1)
  %13 = dbg_stmt()
  %14 = ret_type()
  %15 = const(TypedValue{ .ty = comptime_int, .val = 3})
  %16 = sub(%10, %15)
  %17 = as(%14, %16)
  %18 = return(%17)
} // fn_body main
```

I have not played around with very many test cases yet. Some interesting
ones that I want to look at before merging:

```zig
var x = blk: {
  var y = foo();
  y.a = 1;
  break :blk y;
};
```

In the above test case, x and y are supposed to alias.

```zig
var x = if (bar()) blk: {
  var y = foo();
  y.a = 1;
  break :blk y;
} else blk: {
  var z = baz();
  z.b = 1;
  break :blk z;
};
```

In the above test case, x, y, and z are supposed to alias.

I also haven't tested with `var` instead of `const` yet.
2020-12-31 01:54:02 -07:00
Luna
7550af0d4c ci: freebsd: use py37-s3cmd 2020-12-31 08:18:06 +01:00
Andrew Kelley
3f7d9b5fc1 stage2: rework Value Payload layout
This is the same as the previous commit but for Value instead of Type.

Add `Value.castTag` and note that it is preferable to call than
`Value.cast`. This matches other abstractions in the codebase.

Added a convenience function `Value.Tag.create` which really cleans up
the callsites of creating `Value` objects.

`Value` tags can now share payload types. This is in preparation for
another improvement that I want to do.
2020-12-30 21:41:02 -08:00
Andrew Kelley
133da8692e stage2: rework Type Payload layout
Add `Type.castTag` and note that it is preferable to call than
`Type.cast`. This matches other abstractions in the codebase.

Added a convenience function `Type.Tag.create` which really cleans up
the callsites of creating `Type` objects.

`Type` payloads can now share types. This is in preparation for another
improvement that I want to do.
2020-12-30 21:41:02 -08:00
Jay Petacat
02438aabe3 Remove 'g' prefix from commit hash in Zig semver 2020-12-30 20:57:50 -06:00
LemonBoy
2622575fde std: Remove duplicated code
Make osRequiresLibC call Os.requiresLibC, let's keep a single list of OS
that require the libc to be linked in.
2020-12-30 14:45:39 -08:00
LemonBoy
daed2ba2a0 std: Add more standard type definitions for FreeBSD
Closes #7550
2020-12-30 10:25:43 -08:00
LemonBoy
2561168adb std: Clean up some tests
No functional changes, remove some dead code.
2020-12-30 09:42:21 +01:00
LemonBoy
88634f0481 stage1: Allow variable capture for multi-prong switch arms
Handle the multi-prong case as we do with range cases.

Closes #7188
2020-12-30 09:42:20 +01:00
Jay Petacat
4af763d401 stage2: SemVer compliance for development builds
This matches the behavior of CMake builds. These changes should have
been in PR #6509, but were missed.
2020-12-29 23:25:58 -06:00
Isaac Freund
3634d44d08 std: fix Reader.readUntilDelimiterOrEofAlloc() API
The current API does not allow the user to distinguish between EOF and
an empty line. Reader.readUntilDelimiterOrEof() gets this API right so
update readUntilDelimiterOrEofAlloc() to match it. Returning an optional
here additionally makes calling this in a loop much cleaner.

Remove readUntilDelimiterOrEofArrayList() as it no longer needed to
implement readUntilDelimiterOrEof() and has the same API issues
described without a clear way to fix them.
2020-12-29 19:09:36 -08:00
Andrew Kelley
3d79ae2be3 stage2 tests: improve C backend testing
Add -Werror -pedantic -std=c89 to make sure our outputted C code is
squeaky clean.

Allow garbage to be printed to stderr for Execution tests because
wasmtime is printing a bogus warning, causing the CI to fail.
2020-12-29 20:01:18 -07:00
Andrew Kelley
d18b6785bb stage2: C backend improvements
* Module: improve doc comments
 * C backend: improve const-correctness
 * C backend: introduce renderTypeAndName
 * C backend: put `static` on functions when appropriate
 * C backend: fix not handling errors in genBinOp
 * C backend: handle more IR instructions
   - alloc, store, boolean comparisons, ret_ptr
 * C backend: call instruction properly stores its result
 * test harness: ensure execution tests have empty stderr
2020-12-29 17:56:30 -07:00
LemonBoy
1ac512df70 stage1: Let LLVM legalize the overflowing ops on vectors
LLVM is smart enough to produce tight overflow checking sequences.

On x86_64 a simple v4u32 addition is turned from:

```
  c5 e9 d4 d4                  	vpaddq	%xmm4, %xmm2, %xmm2
  c5 f1 d4 cb                  	vpaddq	%xmm3, %xmm1, %xmm1
  c5 f8 28 e9                  	vmovaps	%xmm1, %xmm5
  c4 e3 55 18 ea 01            	vinsertf128	$1, %xmm2, %ymm5, %ymm5
  c5 f0 c6 da 88               	vshufps	$136, %xmm2, %xmm1, %xmm3
  c5 c8 57 f6                  	vxorps	%xmm6, %xmm6, %xmm6
  c4 e3 55 0c ee aa            	vblendps	$170, %ymm6, %ymm5, %ymm5
  c4 e3 7d 19 ec 01            	vextractf128	$1, %ymm5, %xmm4
  c4 e2 69 29 d4               	vpcmpeqq	%xmm4, %xmm2, %xmm2
  c5 e9 ef d0                  	vpxor	%xmm0, %xmm2, %xmm2
  c4 e2 71 29 cd               	vpcmpeqq	%xmm5, %xmm1, %xmm1
  c5 f1 ef c0                  	vpxor	%xmm0, %xmm1, %xmm0
  c5 f9 6b c2                  	vpackssdw	%xmm2, %xmm0, %xmm0
  c5 f8 50 c0                  	vmovmskps	%xmm0, %eax
  84 c0                        	testb	%al, %al
```

into:

```
  c5 f9 fe c9                  	vpaddd	%xmm1, %xmm0, %xmm1
  c4 e2 71 3f c0               	vpmaxud	%xmm0, %xmm1, %xmm0
  c5 f1 76 c0                  	vpcmpeqd	%xmm0, %xmm1, %xmm0
  c5 f8 50 c0                  	vmovmskps	%xmm0, %eax
  34 0f                        	xorb	$15, %al
  0f 95 c1                     	setne	%cl
  f6 c1 01                     	testb	$1, %cl
```
2020-12-29 14:28:39 -07:00
Jay Petacat
bbe2cca1ae Comply with semantic versioning pre-release format
Example version: 0.8.0-dev.460+g81b343a16

From a semantic versioning perspective, development builds will now be
considered distinct from a tagged release. The number of commits added
since the last tag is included in the pre-release component.

Updates #6466
2020-12-29 13:17:08 -08:00
Andrew Kelley
8078d8cd3f std.ChildProcess: fix max_output_bytes handling
The previous logic had a false positive of returning an error when in
fact the maximum number of output bytes had not been exceeded.
2020-12-29 14:02:12 -07:00
Andrew Kelley
0b46c27333 zig test: release Compilation Cache locks
before executing child process. This fixes a deadlock when the test
wanted to obtain the same lock on compiler_rt.o that was held by the
process building the test binary itself.
2020-12-29 11:47:29 -07:00
Andrew Kelley
e54fd25781 Merge branch 'LemonBoy-cprocess'
This is a partial merge of #6750. I took the Posix code paths and
dropped the Windows code paths, and then did the improvements noted in
the comments.

The Windows implementation is still TODO.
2020-12-29 11:16:28 -07:00
Andrew Kelley
717cf00fe0 std.ChildProcess: improvements to collectOutputPosix
* read directly into the ArrayList buffers.
 * respect max_output_bytes

 * std.ArrayList:
   - make `allocatedSlice` public.
   - add `unusedCapacitySlice`.

I removed the Windows implementation of this stuff; I am doing a partial
merge of LemonBoy's patch with the understanding that a later patch can
add the Windows implementation after it is vetted.
2020-12-29 11:13:00 -07:00
LemonBoy
892b37cdae std: Use WINAPI instead of .Stdcall 2020-12-29 10:40:28 -07:00
LemonBoy
b297c2eae9 std: Fix compilation on FreeBSD/Darwin 2020-12-29 10:40:26 -07:00
LemonBoy
1667c937a0 std: Uniform polling logic for Windows and Unix
Keep polling until there are enough open handles, if the child process
terminates closing the handles or explicitly closes them we just quit
polling and wait for the process handle to signal the termination
condition.
2020-12-29 10:40:00 -07:00
LemonBoy
2c16a96686 std: Fix poll definitions for FreeBSD/Darwin 2020-12-29 10:40:00 -07:00
LemonBoy
dc810eb73b std: Avoid deadlocking in ChildProcess.exec
Reading stdin&stderr at different times may lead to nasty deadlocks (eg.
when stdout is read before stderr and the child process doesn't write
anything onto stdout).

Implement a polling mechanism to make sure this won't happen: we read
data from stderr/stdout as it becomes ready and then it's copied into an
ArrayList provided by the user, avoiding any kind of blocking read.
2020-12-29 10:40:00 -07:00
Andrew Kelley
1590ed9d6a stage2 tests: pass cwd to child process to fix exe path
Previous commit broke the tests for non-Windows because we were
intending to change the cwd when running the child process. However, for
Windows we don't support passing a directory handle for cwd when
spawning child processes yet. However on Linux we do. This commit
reverts the previous one but then fixes things for all systems by
passing both cwd_dir and cwd to the child process.
2020-12-29 00:33:08 -07:00
Andrew Kelley
7e1e771f02 stage2 tests: fix incorrect path used for execution binary 2020-12-28 23:06:47 -08:00
Andrew Kelley
79a5151155 Revert "stage2: fix compilation of self-hosted compiler with -Denable-llvm"
This broke compiling with -Dstage1 on Windows, because it added the
cpp_source_files to the compilation multiple times.

This reverts commit c81ae52ee0.
2020-12-28 22:41:29 -08:00
Frank Denis
8ab870cf56 std/crypto: increment the correct words for vectorized salsa20
Add a test for this by the way.

Fixes #7579
2020-12-28 21:28:39 -08:00
Andrew Kelley
1dd5c032bf stage2 tests: better failure reporting for failed execution 2020-12-28 22:21:25 -07:00
Andrew Kelley
a62353fb4b fix zig test with regards to passing parameters 2020-12-28 22:15:07 -07:00
Andrew Kelley
e0a78d10cc stage2: better error message for root zig source file not found
closes #6777
closes #6893
2020-12-28 21:49:40 -07:00
Andrew Kelley
78dcd1b23e std.process: update arg iterator tests
These tests asserted there were no args passed to the test binary, but
now there is an arg intentionally passed to the test binary, so the test
case needed to be updated.
2020-12-28 21:09:47 -07:00
Andrew Kelley
3b5dd48f99 Merge branch 'hello-c-backend' into master
This branch introduces a new kind of test into the stage2 test harness:
Zig code that compiles into C code with the C backend, and then the
resulting C code gets run and output compared against the expected
result.

This branch also implements extern functions in the frontend so that we
can have a "hello world" C backend test that passes.
2020-12-28 20:32:53 -07:00
Andrew Kelley
813d3308cc stage2: update C backend test cases for new output 2020-12-28 20:32:13 -07:00
Andrew Kelley
bbe66572e1 stage2: C backend: handle string literals more gracefully 2020-12-28 20:15:17 -07:00
Andrew Kelley
7561fca435 stage2: improve test harness to support executing generated C code 2020-12-28 20:01:17 -07:00
Andrew Kelley
7ca9f3bc7b zig test: std.testing.zig_exe_path is now available
it will be set to the path of the zig executable which is running
`zig test`.
2020-12-28 20:00:34 -07:00
Andrew Kelley
a54ccd8537 stage2: C backend: implement @breakpoint and clean up test harness 2020-12-28 18:43:01 -07:00
Andrew Kelley
37f04d66be stage2: C backend: properly render type of array decls 2020-12-28 18:24:55 -07:00
Andrew Kelley
52056b156b stage2: C backend: pointer cast decl refs if necessary 2020-12-28 17:46:50 -07:00
Andrew Kelley
87c6341b61 stage2: add extern functions
and improve the C backend enough to support Hello World (almost)
2020-12-28 17:15:29 -07:00
Andrew Kelley
2df2f0020f Merge pull request #7498 from FireFox317/stage2-llvm
stage2: add initial impl of LLVM backend in self-hosted compiler
2020-12-28 15:07:21 -08:00
Timon Kruiper
ec3aedffb1 stage2: add initial implementation of func arguments in LLVM backend
The following works:
```
export fn _start() noreturn {
    assert(true);
    exit();
}

fn assert(cond: bool) void {}

fn exit() noreturn {
    unreachable;
}
```
2020-12-28 21:20:49 +01:00
Timon Kruiper
4a32d4f288 stage2: refactor (simplify) code structure of llvm_backend.zig 2020-12-28 21:20:49 +01:00
Timon Kruiper
09cf043efd stage2: add missing asserts and early returns for LLVM backend 2020-12-28 21:20:49 +01:00
Timon Kruiper
6b8d28312c stage2: fix building self-hosted without llvm-backend enabled. 2020-12-28 21:20:49 +01:00
Timon Kruiper
b059bb84b8 stage2: add LLVM codegen windows support to the self-hosted compiler
The following example generates a valid `main.exe`:
`zig build-exe main.zig -fLLVM -target x86_64-windows-gnu --subsystem console`

```
export fn wWinMainCRTStartup() noreturn {
    foo();
    exit();
}

fn foo() void {}

fn exit() noreturn {
    unreachable;
}
```
2020-12-28 21:20:46 +01:00
Timon Kruiper
071417161d stage2: add initial impl of LLVM backend in self-hosted compiler 2020-12-28 21:19:40 +01:00
Timon Kruiper
4a0d64300b stage2: rename llvm.zig to llvm_bindings.zig
Putting functions in this file will create functions like
`llvm.function`, and the compiler thinks these are llvm intrinsics.
2020-12-28 21:15:13 +01:00
Timon Kruiper
c81ae52ee0 stage2: fix compilation of self-hosted compiler with -Denable-llvm 2020-12-28 21:15:13 +01:00
Andrew Kelley
f75d4cbe56 Revert "stage2: add compile log statement (#7191)"
The addition of `addDeclErr` introduced a memory leak at every call
site, and I also would like to push back on having more than 1
compilation error per `Decl`.

This reverts commit 1634d45f1d.
2020-12-28 11:24:53 -07:00
Vincent Rischmann
9c53564af1 fs: fix segfault in Walker.next
`top` might point to invalid memory after a call to self.stack.append
which causes a segfault.

Prevent this by recomputing `top`.

Fixes #7560
2020-12-28 18:14:27 +01:00
Vincent Rischmann
399c428cb0 fs: add a test for the walker
Written like this it triggers the segfault reported in #7560
2020-12-28 18:14:27 +01:00
Isaac Freund
7ed499ec45 std/heap: fix documentation of raw_c_allocator
This is not in fact safe to use with GeneralPurposeAllocator as GPA
requires align(page_size) but raw_c_allocator provides only
@alignOf(std.c.max_align_t).
2020-12-28 16:15:04 +02:00
g-w1
c234761edd stage2: make Alloc(Inferred) have mutabality info (#7570) 2020-12-28 15:42:22 +02:00
LemonBoy
fffb0904f8 stage1: Prevent crash with some lazy pointer types
Make sure the child element is not undefined, let's catch this problem
early on.

Closes #7568
2020-12-28 15:27:31 +02:00
Veikka Tuominen
8aab1e2e8a Merge pull request #7483 from indocomsoft/autohashmap
Make hasUniqueRepresentation false for slices
2020-12-28 01:13:23 +02:00
Veikka Tuominen
3fb0288d87 Merge pull request #7563 from ifreund/alloc-sent-cleanup
std: add test for createNullDelimitedEnvMap(), clean up sentinel handling for argv/environ
2020-12-28 01:08:12 +02:00
frmdstryr
dd86e9d78c Update event loop sendto error to SendToError 2020-12-28 01:00:23 +02:00
Veikka Tuominen
d96f5b38a3 Merge pull request #7556 from Vexu/translate-c
some fixes
2020-12-28 00:55:44 +02:00
Veikka Tuominen
5acfaa35d3 Merge pull request #7557 from g-w1/stage2-hookup-compilerror
stage2: compileError builtin for zig code
2020-12-28 00:54:44 +02:00
Isaac Freund
8000262e07 std: clean up sentinel handling for argv/environ 2020-12-27 14:23:59 +01:00
Isaac Freund
4d1096976a std: add test for createNullDelimitedEnvMap() 2020-12-27 14:23:59 +01:00
Andrew Kelley
4cc4b54d25 std.event.Loop: fix regression with ResetEvent 2020-12-26 19:40:10 -07:00
Andrew Kelley
8fc765387f Merge pull request #7449 from kristoff-it/macos-termios
add termios bits for darwin
2020-12-26 17:13:17 -08:00
Isaac Freund
988ddd1bed std: add c._exit() and use in ChildProcess
This issue with atexit() functions after forking isn't isolated to linux
I'm sure, the proper way to do this when linking libc is to use _exit(2)
2020-12-26 16:51:55 -08:00
Andrew Kelley
e5894221f7 Merge pull request #7553 from ziglang/fix-the-damn-deadlock
Fix the damn deadlock
2020-12-26 16:33:38 -08:00
Andrew Kelley
cb290ed6c9 stage2: Cache deadlock debugging only for safe build modes 2020-12-26 17:33:15 -07:00
Andrew Kelley
3366e4caf3 ci: put Drone CI back to normal
Surely this time all the problems have been fixed
2020-12-26 13:55:38 -07:00
Andrew Kelley
3f9588ca29 std: do not call malloc() between fork() and execv()
We were violating the POSIX standard which resulted in a deadlock on
musl v1.1.24 on aarch64 alpine linux, uncovered with the new ThreadPool
usage in the stage2 compiler.

std.os execv functions that accept an Allocator parameter are removed
because they are footguns. The POSIX standard does not allow calls to
malloc() between fork() and execv() and since it is common to both
(1) call execv() after fork() and (2) use std.heap.c_allocator,
Programmers are encouraged to go through the `std.process` API
instead, causing some dissonance when combined with `std.os` APIs.

I also slapped a big warning message on all the relevant doc comments.
2020-12-26 13:50:26 -07:00
g-w1
af80240678 make compileError use an UnOp since its operand is just a *Inst 2020-12-26 12:01:14 -05:00
g-w1
d6e9862049 add test for @compileError in zig code, not only zir 2020-12-26 11:34:15 -05:00
g-w1
7f512f2236 fix test cases to use str zir inst instead of just a quoted string 2020-12-26 11:22:16 -05:00
g-w1
504c78c022 change zir definition to use *Inst instead of []const u8 2020-12-26 11:13:13 -05:00
Julius Putra Tanu Setiaji
f9506e9155 Handle unions in autoHash 2020-12-26 19:43:15 +08:00
Veikka Tuominen
795770bcb4 stage1: const_values_equal error union, improve remaining "TODO" panics 2020-12-26 13:29:48 +02:00
Veikka Tuominen
50e8c3882a translate-c: demote variadic functions to declarations 2020-12-26 13:02:17 +02:00
Veikka Tuominen
641bf4c46e Merge pull request #7552 from Vexu/stage2-continue
stage2 continue
2020-12-26 12:26:16 +02:00
lithdew
d20174ad88 builder: implement sanitize_thread option 2020-12-26 11:56:50 +02:00
Julius Putra Tanu Setiaji
d9133b9ae0 Also check whether structs contain slices 2020-12-26 12:58:52 +08:00
Julius Putra Tanu Setiaji
1df601d581 Make hasUniqueRepresentation false for slices 2020-12-26 11:57:09 +08:00
Andrew Kelley
ed39ff202b stage2: Cache: fix resource management of the deadlock debug code 2020-12-25 19:02:15 -07:00
Andrew Kelley
c452bb1322 ci: build in Debug mode to help find the deadlock 2020-12-25 18:39:13 -07:00
Andrew Kelley
c7834f274d stage2: Cache: add debug deadlock detection code 2020-12-25 18:38:49 -07:00
g-w1
1634d45f1d stage2: add compile log statement (#7191) 2020-12-26 02:40:49 +02:00
g-w1
939bd52c8a remove '||=' from stage1
It seems depreciated.
2020-12-26 02:39:34 +02:00
Andrew Kelley
864a5442f1 Merge pull request #7542 from g-w1/build-diff-large
remove `git diff` feature from build.zig
2020-12-25 16:39:23 -08:00
Veikka Tuominen
a50759325c stage2: add error for unused labels 2020-12-26 02:36:12 +02:00
Veikka Tuominen
40aad4f47e stage2: break and continue out of loops 2020-12-26 02:26:53 +02:00
g-w1
ec102951cb remove git diff dirty changes feature from build.zig 2020-12-25 17:18:44 -05:00
Sébastien Marie
c99c6c0a68 openbsd: add commonly used libc wrappers for pledge(2) and unveil(2) 2020-12-25 16:43:14 +02:00
Sébastien Marie
bc11528b8b openbsd: define sem_t as optional pointer on opaque {} 2020-12-25 16:20:22 +02:00
Vexu
1780132d7c fix tests 2020-12-25 14:58:14 +02:00
Vexu
0bc82a9070 stage1: validate pointer attributes when coercing anon literals 2020-12-25 14:58:13 +02:00
Vexu
990eccf282 stage1: implement type coercion of pointer to anon list to array/struct/union/slice 2020-12-25 14:57:46 +02:00
Vexu
ed028fd660 stage1: implement type coercion of anon list to array 2020-12-25 14:57:46 +02:00
Evan Haas
830bc41b1f Correctly cast bool to signed int in translate-c
Previously casting a bool to an int would result in the following Zig code:

    @intCast(c_int, @bitCast(i1, @intCast(u1, @boolToInt(b))));

This is incorrect if `b` is true, since bitcasting a `u1` with the value 1
to an `i1` will result in the value -1. Instead, generate the following code:

    @as(c_int, @boolToInt(b));

Since @boolToInt returns a `u1`, this is only disallowed if the destination
type is one-bit and signed, which can only happen if it's a bitfield
(currently not supported by translate-c)
2020-12-25 14:38:31 +02:00
g-w1
1322a73141 make if the diff too large just default to dirty_diff_too_big as the diff 2020-12-24 18:28:13 -05:00
Andrew Kelley
9f33984119 Merge pull request #7520 from ziglang/tsan
add support for TSAN
2020-12-24 15:17:52 -08:00
Andrew Kelley
6ab9268a90 stage2: re-use compiler runtime libs across opt modes and strip flag
Previously Zig would need to recompile runtime libs if you changed the
values of --strip or -O. Now, unless the `debug_compiler_runtime_libs`
flag is set (which is currently not exposed to the CLI), Zig will always
choose ReleaseFast or ReleaseSmall for compiler runtime libraries.

When the main application chooses ReleaseFast or ReleaseSmall, that
value is propagated to compiler runtime libraries. Otherwise a decision
is made based on the target, which is currently ReleaseSmall for
freestanding WebAssembly and ReleaseFast for everything else.

Ultimately the purpose of this commit is to have Debug and ReleaseSafe
builds of applications still get optimized builds of, e.g. libcxx and
libunwind, as well as to spend less time unnecessarily rebuilding compiler
runtime libraries.
2020-12-24 14:11:58 -07:00
Andrew Kelley
894434988d libunwind: fix compile errors and warnings for 32-bit arm 2020-12-24 13:31:41 -07:00
LemonBoy
e18abab55a stage1: Create a new declaration scope for union enum types
Making the enum type share the scope with the parent union means every
declaration "bleeds" into the enum scope.
Let's mint a fresh empty scope for the enum type.

Thanks to @Vexu for the test case.

Closes #7532
2020-12-24 15:57:12 +02:00
Veikka Tuominen
83646df2cc Merge pull request #7531 from Vexu/orphanage
Move ArrayListSentineled to std lib orphanage
2020-12-24 10:59:37 +02:00
Andrew Kelley
ed26b3204a stage2: tsan forces linking libc 2020-12-24 01:18:48 -07:00
Andrew Kelley
4d8c5dd4be stage1: add tsan LLVM passes when appropriate 2020-12-24 01:18:48 -07:00
Andrew Kelley
a4b134746f zig cc: support both ubsan and tsan at the same time 2020-12-24 01:18:48 -07:00
Andrew Kelley
3002856a7f libunwind: add __gcc_personality_v0 symbol 2020-12-24 01:18:48 -07:00
Andrew Kelley
8219d92987 stage2: fix Cache deadlock and build more of TSAN
* rename is_compiler_rt_or_libc to skip_linker_dependencies
   and set it to `true` for all sub-Compilations. I believe
   this resolves the deadlock we were experiencing on Drone
   CI and on some users' computers. I will remove the CI workaround in
   a follow-up commit.
 * enabling TSAN automatically causes the Compilation to link against
   libc++ even if not requested, because TSAN depends on libc++.
 * add -fno-rtti flags where appropriate when building TSAN objects.
   Thanks Firefox317 for pointing this out.
 * TSAN support: resolve all the undefined symbols. We are still seeing
   a dependency on __gcc_personality_v0 but will resolve this one in a
   follow-up commit.
 * static libs do not try to build libc++ or libc++abi.
2020-12-24 01:18:48 -07:00
Andrew Kelley
42b4a48bc9 WIP start adding support for TSAN 2020-12-24 01:18:47 -07:00
Andrew Kelley
0fd68f49e2 Merge pull request #7519 from ziglang/more-pthreads-integration
More pthreads integration
2020-12-24 00:15:33 -08:00
Andrew Kelley
87e4f7376a Revert "std.valgrind: add helgrind functions"
This reverts commit f2ab9512af.

I did it wrong and didn't end up using these.
2020-12-24 01:14:41 -07:00
Andrew Kelley
c2b1c88953 std: fix compile errors introduced in previous commit 2020-12-23 20:49:38 -07:00
Andrew Kelley
177377b6e3 rework std.ResetEvent, improve std lib Darwin integration
* split std.ResetEvent into:
   - ResetEvent - requires init() at runtime and it can fail. Also
     requires deinit().
   - StaticResetEvent - can be statically initialized and requires no
     deinitialization. Initialization cannot fail.
 * the POSIX sem_t implementation can in fact fail on initialization
   because it is allowed to be implemented as a file descriptor.
 * Completely define, clarify, and explain in detail the semantics of
   these APIs. Remove the `isSet` function.
 * `ResetEvent.timedWait` returns an enum instead of a possible error.
 * `ResetEvent.init` takes a pointer to the ResetEvent instead of
   returning a copy.
 * On Darwin, `ResetEvent` is implemented using Grand Central Dispatch,
   which is exposed by libSystem.

stage2 changes:
 * ThreadPool: use a single, pre-initialized `ResetEvent` per worker.
 * WaitGroup: now requires init() and deinit() and init() can fail.
   - Add a `reset` function.
   - Compilation initializes one for the work queue in creation and
     re-uses it for every update.
   - Rename `stop` to `finish`.
   - Simplify the implementation based on the usage pattern.
2020-12-23 16:57:18 -08:00
frmdstryr
577b57784a Return encoded slice from base64 encode 2020-12-24 01:27:21 +02:00
Veikka Tuominen
7154882423 Merge pull request #7447 from LemonBoy/fix-7445
std: non-byte-multiple sized integers have no definite representation
2020-12-24 00:25:52 +02:00
Veikka Tuominen
e79acc24d3 std: clenup, fixes, fmt 2020-12-24 00:23:29 +02:00
Andrew Kelley
5377b7fb97 put the drone CI workaround back in
this branch does not solve it
2020-12-23 13:36:21 -08:00
Andrew Kelley
f4d82f0ad6 std.Progress: work around time going backwards 2020-12-23 13:36:21 -08:00
Andrew Kelley
485ec0884f restore std.ResetEvent.isSet functionality 2020-12-23 13:36:21 -08:00
Andrew Kelley
a368c0d099 std: add Darwin and FreeBSD sem_t bits 2020-12-23 13:36:21 -08:00
Andrew Kelley
b2e1bce240 minor code readability changes 2020-12-23 13:36:21 -08:00
Andrew Kelley
f2ab9512af std.valgrind: add helgrind functions 2020-12-23 13:36:21 -08:00
Andrew Kelley
78ab1f609a apply kprotty's WaitGroup fix 2020-12-23 13:36:21 -08:00
Andrew Kelley
19459840fe std.ResetEvent: pthreads sem_t cannot be statically initialized
because it is allowed for the implementation to use a file descriptor,
which would require making a syscall at runtime.
2020-12-23 13:36:21 -08:00
Andrew Kelley
028af97df4 std.ResetEvent: use sem_t when linking against pthreads 2020-12-23 13:36:21 -08:00
Andrew Kelley
829c00a77f kprotty ThreadPool and WaitGroup patch 2020-12-23 13:36:21 -08:00
Andrew Kelley
4eb4d26fa1 std.Mutex: integrate with pthreads
When using pthreads for threading, std.Mutex uses pthread_mutex_t as the
implementation. This integrates better with tooling.
2020-12-23 13:36:21 -08:00
Sébastien Marie
6e2622661c openbsd: implement segfault handling on openbsd x86_64 2020-12-23 20:47:06 +02:00
Koakuma
588e828759 float_*_ieee597: only swap bytes when targeting different endianness than native
float_*_ieee597 functions should fill the buffer with the target endianness,
instead of always filling it in LE ordering.
2020-12-23 20:22:43 +02:00
xackus
1d3ceac770 stage1: LLVMSetModuleInlineAsm is deprecated 2020-12-23 20:21:47 +02:00
xackus
0a6ba6f666 gdb pretty printers for slices and optionals 2020-12-23 20:21:47 +02:00
Loris Cro
9bb0da6100 added comments, removed useless comptime keywords 2020-12-23 17:28:59 +01:00
Loris Cro
8c00c7473c add termios bits for darwin 2020-12-23 17:28:59 +01:00
Eleanor Bartle
49ca51fc3a Clarify condusing wording regarding % and /
Previous wording made it seem like any signed or floating-point value would be allowed at comptime, whereas negative values do not work with `%`, and negative integers do not work with `/`.
2020-12-23 17:05:37 +02:00
Veikka Tuominen
e5aab62228 move ArrayListSentineled to std lib orphanage 2020-12-23 16:24:22 +02:00
Alex Cameron
ca282184ae Implement parsing for multi-arg Clang options. 2020-12-23 15:03:11 +02:00
g-w1
51a904677c update depreciated code (#7502)
* `zig env`:

* fix depreciated interface, update outStream -> writer
* make code more readable by updating `anytype` -> `std.fs.File.Writer`
2020-12-23 13:01:29 +02:00
xackus
4128eea00c std.c: add fmemopen 2020-12-23 12:58:21 +02:00
Veikka Tuominen
ce7dcf2294 Merge pull request #7507 from joachimschmidt557/stage2-arm
stage2 ARM: implement basic binary bitwise operations
2020-12-23 12:17:40 +02:00
daurnimator
53a8e73205 Add sincosf function (#7267)
* Add sincosf function

* also add sincos

Co-authored-by: Veikka Tuominen <git@vexu.eu>
2020-12-23 11:18:15 +02:00
Andreas Linz
7e63f7ad03 Truncate user and group ids for 64 bit Linux systems (#7466)
* Truncate user and group ids

Calls to `getuid`, `getgid` and their `eid` variants fail to compile on
64bit Linux systems because the return value of the syscall is of
`usize` and needs to be truncated to fit the size of `uid_t` that is 32
bit.

Thanks to @FireFox317 for figuring this out in Zig's Discord channel!

* Add a regression test for user and group ids

* Replace @truncate with @intCast

This should be safe because `uid_t` will be 32-bit.

* Add missing import for getauxval

* Add missing package names

* Revert "Add missing import for getauxval"

This reverts commit 38f93dc89effdf657f2b81a56b96527ce4083f52.

* Skip user and group test if builtin.link_libc
2020-12-23 11:16:27 +02:00
Sébastien Marie
4420dabdf5 openbsd: fix siginfo_t struct definition
`_proc` struct part contains an union for kill/cld parts.

see [siginfo_t](77c6c13150/sys/sys/siginfo.h (L132))
2020-12-23 11:08:55 +02:00
Alex Cameron
60020fd545 Enable segfault handling on FreeBSD. 2020-12-23 11:02:05 +02:00
Matt Sicker
d9fe7ea815 Fix Gimli hash on 16n byte inputs 2020-12-23 10:59:14 +02:00
Matthew Knight
55b998c98d Add c_longdouble mapping for bpf (#7504) 2020-12-23 01:33:43 +02:00
tgschultz
ab6183e119 Added std.io.counting_reader 2020-12-23 01:27:12 +02:00
g-w1
cb3198af2a stage2: @TypeOf (#7475)
* stage2: add @TypeOf

* stage2: discriminate on what type of @builtinCall in nodeMayNeedMemoryLocation

* merge upstream into my stash

* add type equality to make easier to test and defer free the types

* remove addDeclErr, I dont know why I added it, its from a different branch that im working on

* add tests

* update error message to match stage1

* use ComptimeStringMap and update which nodes don't need memory from vexu's suggestions

* fix typo

Co-authored-by: Veikka Tuominen <git@vexu.eu>

* make @TypeOf(single_arg) go to .typeof zir inst and add test for that

* unioninit, as, reduce change mayneedmemorylocation

Co-authored-by: Veikka Tuominen <git@vexu.eu>
2020-12-23 01:26:36 +02:00
g-w1
ea18f894f5 Peer type resolution with unsigned ints and larger signed ints 2020-12-23 00:05:42 +02:00
Veikka Tuominen
03113d9246 Merge pull request #7111 from tetsuo-cpp/emit-h
Implement emit-h
2020-12-23 00:01:22 +02:00
Veikka Tuominen
ba2f2e1393 Merge pull request #7476 from ifreund/pkgs
stage2: free Package resources, print package path on --pkg-begin failure
2020-12-23 00:00:37 +02:00
Evan Haas
ccdb81fb31 Improve handling of C compiler intrinsics in translate-c
C compiler intrinsics can only appear as part of a function call. When called
they are implicitly cast to a function pointer; treat this as a non-null
pointer so that it emits as a regular Zig function call.

Put `pub usingnamespace @import("std").c.builtins;` at the top of translated
C files so that they will have access to builtin functions defined there.

Fixes #6707
2020-12-22 23:59:30 +02:00
luna
6a75cfd0f6 cast sendto to SendError inside send (#7481)
* cast sendto to SendError inside send

* remove WouldBlock from SendToError

* add missing ENOTCONN mapping

* remove SystemResources duplicate

* move NetworkUnreachable to SendError

* add NetworkSubsystemFailed to SendError

* Use zig's implicit error set casting

Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2020-12-22 16:47:11 -05:00
Alex Cameron
9849e894d5 Add emit_h path to compilation hash. 2020-12-23 01:14:35 +11:00
Alex Cameron
0771aac48b Don't use emit-h in test cases for other backends. 2020-12-23 01:14:35 +11:00
Alex Cameron
e834d0369a Make sure emit-h is off by default. 2020-12-23 01:14:35 +11:00
Alex Cameron
58bd6c5f8e Add tests for emit-h functionality. 2020-12-23 01:14:35 +11:00
Noam Preil
8d6066e09c Fix a dumb 2020-12-23 01:14:35 +11:00
Noam Preil
8538053940 Add header test harness 2020-12-23 01:14:35 +11:00
Noam Preil
ac33b10b5e CBE: Improve formatting 2020-12-23 01:14:35 +11:00
Noam Preil
37438dd789 CBE: add support for bool,u32 2020-12-23 01:14:35 +11:00
Noam Preil
15a148db01 Fix memory leak 2020-12-23 01:14:35 +11:00
Alex Cameron
c87da2f45a Remove redundant emit_h member in Compilation struct. 2020-12-23 01:14:35 +11:00
Alex Cameron
aba273d731 Enable emit-h by default for obj and lib compilation. 2020-12-23 01:14:35 +11:00
Alex Cameron
40f0275e7c Implement emit-h 2020-12-23 01:14:35 +11:00
Jakub Konka
43dbe86226 Merge pull request #7516 from kubkon/macho-better-space-alloc
macho: space preallocation, and various cleanups and fixes
2020-12-22 14:23:55 +01:00
Jakub Konka
34663abc90 macho: pad out LINKEDIT upto specified filesize 2020-12-22 10:57:58 +01:00
Jakub Konka
f106a46fd2 macho: enable binding and lazy binding info writes 2020-12-21 23:16:00 +01:00
Jakub Konka
3f21f9155f macho: write only bits that changed
Refactor use of `log` to not include an additional newline char.
2020-12-21 19:59:40 +01:00
joachimschmidt557
45a88be573 stage2 ARM: add test cases for binary bitwise operations 2020-12-21 19:24:23 +01:00
joachimschmidt557
82236a5029 stage2 ARM: implement basic binary bitwise operations 2020-12-21 19:24:21 +01:00
Jakub Konka
de5421a0a6 macho: deduplicate symbol table relocation codepath 2020-12-21 18:31:26 +01:00
Jakub Konka
a1b3606f0e macho: dynamically preallocate space for LINKEDIT sections as well 2020-12-21 17:03:55 +01:00
Vexu
286077fec8 stage1: add missing error check on inferred struct field ptr 2020-12-21 12:40:51 +02:00
Andrew Kelley
4918605176 Merge pull request #7462 from ziglang/parallel-c-objects
Introduce a ThreadPool and parallel execution of some of the compilation work items
2020-12-20 21:19:05 -05:00
Andrew Kelley
1d94a68936 add an option to compile zig in single-threaded mode
And enable it for Drone CI. I hate to do this, but I need to make
progress on other fronts.
2020-12-20 15:37:58 -07:00
Andrew Kelley
10d30838d1 update WaitGroup to yet another version 2020-12-20 15:08:59 -07:00
Andrew Kelley
fbcffe9d5d std.Progress: fix atomic ordering semantics
thx king protty
2020-12-20 15:08:59 -07:00
Andrew Kelley
4e621d4260 workaround for std lib AutoResetEvent bug 2020-12-20 15:08:59 -07:00
Andrew Kelley
e00b6db2aa update stage2 test harness to new std.Progress API 2020-12-20 15:08:59 -07:00
Andrew Kelley
aa6ef10cc6 std.Progress: make the API thread-safe
We generally get away with atomic primitives, however a lock is required
around the refresh function since it traverses the Node graph, and we
need to be sure no references to Nodes remain after end() is called.
2020-12-20 15:08:59 -07:00
Andrew Kelley
b2f8631a3c ThreadPool: delete dead code
If this errdefer did get run it would constitute a race condition. So I
deleted the dead code for clarity.
2020-12-20 15:08:59 -07:00
Andrew Kelley
32fd637e57 stage2: replace WaitGroup with a trivially auditable one 2020-12-20 15:08:59 -07:00
Andrew Kelley
0d1cd0d482 use kprotty's ThreadPool implementation (v5) 2020-12-20 15:08:59 -07:00
Andrew Kelley
01d33855c7 stage2: protect mutable state from data races in updateCObject 2020-12-20 15:08:59 -07:00
Andrew Kelley
4964bb3282 std: move serialization to the std lib orphanage
std-lib-orphanage commit 633792839f6f838fa864cde6af015413ee713404
2020-12-20 15:08:06 -07:00
LemonBoy
84549b4267 stage1: Fix for generic fn monomorphization
Don't use the instantiation argument types to build the function
parameter array.

f416535768 worked around the problem, this
commit solves it.
2020-12-19 19:45:48 -05:00
Vincent Rischmann
dd7b816d98 builder: implement float options 2020-12-20 01:24:59 +02:00
Jakub Konka
3f7dbde92a macho: bring back allocatedSize function 2020-12-19 23:51:39 +01:00
Jakub Konka
6712575e04 macho: preallocate space for linkedit hidden sections; 2020-12-19 23:37:21 +01:00
Jakub Konka
ca1d03fe77 macho: fix findFreeSpace start value 2020-12-19 19:44:13 +01:00
Jakub Konka
c89f4781bd macho: add missing dirty markers 2020-12-19 12:19:20 +01:00
Jakub Konka
f32681033d macho: auto-coerce to slice 2020-12-19 12:19:10 +01:00
Jakub Konka
99578e828b macho: move findFreeSpace back to MachO struct
However, adding a twist where `findFreeSpace` accepts a `SegmentCommand`
as argument meaning we want to look for free space specifically within
that segment and nowhere else.
2020-12-19 12:19:00 +01:00
Jakub Konka
6a021d845a macho: find free space even for __text section 2020-12-19 12:18:49 +01:00
Jakub Konka
f33b644c4f macho: redo how we allocate within a segment
Firstly, we preallocate segments offset and sizes, and then
when adding sections, we find the free space within each segment.
Currently, this applies to any segment that is not __LINKEDIT
segment since this requires special treatment.
2020-12-19 12:18:35 +01:00
Jakub Konka
b090451646 Merge pull request #7318 from kubkon/cc-macho
stage1: cross compile to x86_64 and arm64 macOS from anywhere with LLVM
2020-12-19 12:13:03 +01:00
Jakub Konka
3f81ddb735 macho: address review comments 2020-12-19 09:59:38 +01:00
Andrew Kelley
506af7e52e Merge pull request #7482 from ziglang/tlcsprng
std: introduce a thread-local CSPRNG for general use
2020-12-18 23:57:46 -05:00
Andrew Kelley
f416535768 work around compiler bug regarding generic function slice alignment
See #7495
2020-12-18 18:30:06 -07:00
Andrew Kelley
53987c932c std.crypto.random: introduce fork safety
Everybody gets what they want!

 * AT_RANDOM is completely ignored.
 * On Linux, MADV_WIPEONFORK is used to provide fork safety.
 * On pthread systems, `pthread_atfork` is used to provide fork safety.
 * For systems that do not have the capability to provide fork safety,
   the implementation falls back to calling getrandom() every time.
 * If madvise is unavailable or returns an error, or pthread_atfork
   fails for whatever reason, it falls back to calling getrandom() every
   time.
 * Applications may choose to opt-out of fork safety.
 * Applications may choose to opt-in to unconditionally calling
   getrandom() for every call to std.crypto.random.fillFn.
 * Added `std.meta.globalOption`.
 * Added `std.os.madvise` and related bits.
 * Bumped up the size of the main thread TLS buffer. See the comment
   there for justification.
 * Simpler hot path in TLS initialization.
2020-12-18 15:54:01 -07:00
Andrew Kelley
2b8dcc76eb take advantage of std.os.linux.getauxval 2020-12-18 12:22:46 -07:00
Andrew Kelley
d9368d7012 update test-stack-traces because start.zig updated 2020-12-18 12:22:46 -07:00
Andrew Kelley
2e4b409f31 std: tlcsprng: cleanups & improvements
* get rid of the pointless fences
 * make seed_len 16 instead of 32, which is accurate since it was
   already padding the rest anyway; now we do 1 pad instead of 2.
 * secureZero to clear the AT_RANDOM auxval
 * add a flag root source files can use to disable the start code. This
   is in case people want to opt out of the initialization when they
   don't depend on it.
2020-12-18 12:22:46 -07:00
Andrew Kelley
228a0937a2 memory fences to make sure TLS init happens 2020-12-18 12:22:46 -07:00
Andrew Kelley
7dab3ae135 update guess number standalone test 2020-12-18 12:22:46 -07:00
Andrew Kelley
4dcd1e6059 start code: overwrite AT_RANDOM after we use it 2020-12-18 12:22:46 -07:00
Andrew Kelley
013efaf139 std: introduce a thread-local CSPRNG for general use
std.crypto.random

* cross platform, even freestanding
* can't fail. on initialization for some systems requires calling
  os.getrandom(), in which case there are rare but theoretically
  possible errors. The code panics in these cases, however the
  application may choose to override the default seed function and then
  handle the failure another way.
* thread-safe
* supports the full Random interface
* cryptographically secure
* no syscall required to initialize on Linux (AT_RANDOM)
* calls arc4random on systems that support it

`std.crypto.randomBytes` is removed in favor of `std.crypto.random.bytes`.

I moved some of the Random implementations into their own files in the
interest of organization.

stage2 no longer requires passing a RNG; instead it uses this API.

Closes #6704
2020-12-18 12:22:46 -07:00
LemonBoy
ce65533985 std: Properly fix the TLS alignment problem
ad05509 introduced a fix for the wrong problem, the logic to align the
start of main_thread_tls_buffer was already there but was flawed.

Fix it for good and avoid wasting too many bytes for alignment purposes.
2020-12-18 14:22:30 -05:00
Andrew Kelley
ad05509930 std: align(16) main_thread_tls_buffer
Before this change, thread local variables were landmines if LLVM
decided to optimize any writes to them using vector instructions.
2020-12-17 22:58:56 -07:00
Alexandros Naskos
16144a7a37 Add EV_ERROR to FreeBSD bits 2020-12-17 22:58:05 +02:00
Isaac Freund
fa09c3a5e7 stage2: print package path on --pkg-begin failure
This makes it much easier for the user to figure out what has gone wrong
than dumping an error return trace.
2020-12-17 20:03:15 +01:00
Isaac Freund
c102eb83e6 stage2: free Package resources
Without this commit we leak file descriptors and memory
2020-12-17 19:32:40 +01:00
Tau
9b86dde7b9 Add baudrate constants
This adds the missing baudrate constants for linux where I've used them
directly.
2020-12-17 19:17:10 +02:00
Luuk de Gram
d73f46b57c Fix StackFallbackAllocator 2020-12-17 19:09:29 +02:00
Josh Holland
e93cb22541 Improve documentation for string slices.
Closes #7454.
2020-12-17 19:01:13 +02:00
Dmitry Atamanov
e16997a66c Add process_madvise to Linux syscalls (#7450) 2020-12-17 18:58:09 +02:00
LemonBoy
135f4791e5 std: Don't hash undefined bits
auto_hash must be extra careful when hashing integers whose bit size is
not a multiple of 8 as, when reinterpreted with mem.asBytes, may contain
undefined non-zero bits too.
2020-12-17 12:00:48 +01:00
Alexandros Naskos
85cc3f24a0 Only check for evented mode in windows.OpenFile when in async mode 2020-12-17 11:08:21 +02:00
Jakub Konka
b42ef0e6ea macho: refactor calculating LEB128 sizes 2020-12-17 10:04:53 +01:00
Jakub Konka
3e9e79378d macho: deduplicate libc headers between macos arch 2020-12-17 10:04:53 +01:00
Jakub Konka
2d5d661703 macho: no need to parse symbol/string tables 2020-12-17 10:04:53 +01:00
Jakub Konka
ae535111a4 macho: cleanup (lazy) binding info tables 2020-12-17 10:04:53 +01:00
Jakub Konka
5e913c9c2c macho: move (lazy)binding tables into imports module 2020-12-17 10:04:53 +01:00
Jakub Konka
46b2a08d06 macho: parse binding info into a table of entries 2020-12-17 10:04:53 +01:00
Jakub Konka
77e545892e macho: do not error out on unknown load commands
Also, do not try to fixup missing libSystem for dylibs.
2020-12-17 10:04:53 +01:00
Jakub Konka
b099fdff93 macho: parse symbol and string tables 2020-12-17 10:04:53 +01:00
Jakub Konka
f5a0b9315b macho: calculate next available dylib ordinal 2020-12-17 10:04:53 +01:00
Jakub Konka
cc2592969d macho: clean up formatting 2020-12-17 10:04:53 +01:00
Jakub Konka
3971522fee macos: add unfiltered aarch64 libc headers 2020-12-17 10:04:53 +01:00
Jakub Konka
2e7883c597 lld+macho: lld xcomp to x86_64 macos now works 2020-12-17 10:04:53 +01:00
Jakub Konka
eb528a9cbc lld+macho: add missing LC_LOAD_DYLIB cmd 2020-12-17 10:04:53 +01:00
Andrew Kelley
6dfe9cc83e zig cc: default to a.exe on windows
This matches Clang. Thanks to Abner Coimbre for pointing this out.
2020-12-16 21:37:15 -07:00
Andrew Kelley
8975fa5b38 stage2: add test_evented_io to cache hash 2020-12-16 19:22:48 -07:00
Andrew Kelley
8f1408578c update the CPU target features and models
Rather than directly pasting the output from the
target-details-generator tool, we have to look at the diff line by line
and decide how to incorporate the changes.

The baseline abstraction is something that Zig provides.

The changes to x86 appear to be incorrect. After LLVM commit
3ad09fd03c51823aeb0bcbd7898aada33e9228d6 the CPU features are stored in
a different data layout in their tables, and so we need to update the
target details extraction tool to match.
2020-12-16 17:25:48 -07:00
Andrew Kelley
bbb3403b5d stage1: apply LLVM ssp attributes globally
instead of per-function. Otherwise LLVM asserts with:
"stack protected callee but caller requested no stack protector"
2020-12-16 15:45:32 -07:00
Andrew Kelley
da54e7cd00 update clang.zig and translate-c for the clang C++ API changes 2020-12-16 14:29:27 -07:00
Andrew Kelley
755c558026 Merge remote-tracking branch 'origin/master' into llvm12 2020-12-16 14:24:36 -07:00
Jakub Konka
f59069f3d0 Update clang options
llvm commit b2851aea80e5a8f0cfd6c3c5a56a6b00fb28c6b6
2020-12-16 18:38:11 +01:00
Jakub Konka
4b62f1bd93 Update changes due to different CPU feature sets
llvm commit b2851aea80e5a8f0cfd6c3c5a56a6b00fb28c6b6
2020-12-16 18:25:25 +01:00
Jakub Konka
1c40a4df09 Update zig_llvm.cpp and other bits
Include updates to corresponding zig sources

llvm commit b2851aea80e5a8f0cfd6c3c5a56a6b00fb28c6b6
2020-12-16 18:13:58 +01:00
Jakub Konka
6f3ed2f71f Update target details
llvm commit b2851aea80e5a8f0cfd6c3c5a56a6b00fb28c6b6
zig-llvm-target-details-generator commit
4299674ecabeb668b0d84285cd1b41a652a391b1
2020-12-16 18:13:52 +01:00
Jakub Konka
38bf94280b Update libcxxabi
llvm commit b2851aea80e5a8f0cfd6c3c5a56a6b00fb28c6b6
2020-12-16 12:19:09 +01:00
Jakub Konka
f9a11fbfaf Update libcxx
llvm commit b2851aea80e5a8f0cfd6c3c5a56a6b00fb28c6b6
2020-12-16 12:18:55 +01:00
Jakub Konka
1e66ac5755 Update libunwind
llvm commit b2851aea80e5a8f0cfd6c3c5a56a6b00fb28c6b6
2020-12-16 12:18:43 +01:00
Jakub Konka
8612dac225 Update clang headers
llvm commit b2851aea80e5a8f0cfd6c3c5a56a6b00fb28c6b6
2020-12-16 12:18:33 +01:00
Jakub Konka
83ff94406e Update clang drivers
llvm commit b2851aea80e5a8f0cfd6c3c5a56a6b00fb28c6b6
2020-12-16 12:18:14 +01:00
data-man
d877eb0e8d Fix typo in math.order 2020-12-16 12:14:44 +02:00
Veikka Tuominen
d3a57b96a9 translate-c: detect parenthesized string literals 2020-12-16 12:13:23 +02:00
Jakub Konka
9c2d8056ce Update LLVM version numbers in CMake 2020-12-16 09:37:32 +01:00
Alexandros Naskos
aa6654a4b3 Fix compilation for MacOS 2020-12-16 00:47:41 +02:00
Andrew Kelley
b3c1ced2c3 Merge pull request #7431 from LemonBoy/fix-7426
stage1: Fix crash in can_mutate_comptime_var_state
2020-12-15 15:07:49 -05:00
Christian Wesselhoeft
b3f4802aa0 mingw-w64: add .def files for xaudio2_8 2020-12-15 15:00:39 -05:00
luna
0c33624a45 create SendToError (#7417)
* add SendToError

* remove error catch

* add missing SendToError entries

* add mappings to new errors for posix

* map windows sendto() errors
2020-12-15 14:56:42 -05:00
LemonBoy
5f7352b5b5 stage2: Add -include libc-symbols.h when building crtn.S
This -include is added for nearly every file in glibc's makefiles.
2020-12-15 14:53:46 -05:00
Sébastien Marie
96e3222796 openbsd: crt0.o file is different when build static or dynamic mode
it is a first step for support static *and* dynamic mode for openbsd
2020-12-15 14:53:23 -05:00
Sébastien Marie
8bf5a3a5c1 openbsd: correct few structs
- addrinfo: addr and canonname are switched (wrong layout)
- addrinfo, Flock, msghdr struct: use proper c_xxx type instead of fixed size. it should help using struct on all architectures supported by openbsd
2020-12-15 14:49:42 -05:00
Sebastien Marie
7cd6c25c8f openbsd: link with required system libraries (#7380)
* openbsd: use -lpthread when linking

and while compiling zig stage2, use c++ and c++abi too
2020-12-15 14:45:48 -05:00
LemonBoy
8a2ab60fca stage1: Don't skip steps when analyzing union types
Don't cut any corner and properly run the type trough every single step
even though it has no fields (or, better, the sum of the size of all its
fields is zero).

Fix the logic to consider an explicit non-zero-sized tag enough to treat
the type as sized.

Closes #7451
2020-12-15 14:40:21 -05:00
LemonBoy
9e5869262a std: Bool has no definite representation too
The padding bits are undefined.
2020-12-14 20:06:46 +01:00
LemonBoy
44556bfebe std: non-byte-multiple sized integers have no definite representation
Closes #7445
2020-12-14 20:06:46 +01:00
Alexandros Naskos
da007f318b Implement std.fs.Watch on Windows
Use unmanaged containers in std.fs.Watch
2020-12-14 21:03:50 +02:00
Alexandros Naskos
5112ab8233 Fixed std.fs.Watch implementation on Linux
Added .Deleted event to std.fs.Watch on Linux
2020-12-14 21:00:54 +02:00
LemonBoy
bbfa3550a0 Add a test case
Co-authored-with: Vexu <git@vexu.eu>
2020-12-14 17:39:35 +01:00
data-man
8591f30b0d Add missed Linux syscalls 2020-12-14 18:22:28 +02:00
Jakub Konka
91e8be385c Merge pull request #7411 from LemonBoy/sigaction-smoke
std: Improve sigaction interface
2020-12-14 17:16:55 +01:00
LemonBoy
a471a57560 std: Fix formatting of type values
Closes #7429
2020-12-13 23:21:23 -05:00
Isaac Freund
343249efd8 stage2: use %type not @type for libc stubs
Apparently ARM uses @ for comments. Everything seems to accept % here
though.
2020-12-13 23:19:23 -05:00
Andrew Kelley
481ce7361e bump version to 0.7.0 => 0.7.1
The official tag is in the 0.7.x branch.
2020-12-13 12:53:31 -07:00
LemonBoy
d9e9390550 Fix compilation error on OpenBSD 2020-12-13 20:36:47 +01:00
LemonBoy
bb72b0e800 Fix compilation error on FreeBSD 2020-12-13 20:36:34 +01:00
LemonBoy
561565fa81 stage1: Fix crash in can_mutate_comptime_var_state
No lazy value can mutate global state, no need to resolve them.

Closes #7426
2020-12-13 20:27:04 +01:00
LemonBoy
97ba3d9a66 std: Drop struct prefixes in FreeBSD siginfo
I'm not sure this prefix-free style is a good idea, but let's roll with
it for the moment.
2020-12-13 19:45:11 +01:00
Alex Cameron
7515922907 Fix Sigaction struct on FreeBSD. 2020-12-13 19:37:13 +01:00
LemonBoy
3a759fdb17 Disable sigaction test on i386 because of #7427 2020-12-13 19:35:40 +01:00
LemonBoy
3375a580be std: Update more siginfo bits for BSDs 2020-12-13 19:28:38 +01:00
LemonBoy
fc70db5ab5 std: Fixes for siginfo test on macos
Xnu's sigaction() only supports fetching a limited set of sa_flags, test
SA_SIGINFO instead of SA_RESETHAND as that's supported everywhere.

Add another check to make sure SA_RESETHAND works.

Co-authored-by: Jakub Konka <kubkon@jakubkonka.com>
2020-12-13 19:17:04 +01:00
Andrew Kelley
4fd27719b4 Merge pull request #7406 from ifreund/dyn-musl2
stage2: support dynamically linking musl libc
2020-12-12 18:46:07 -05:00
Isaac Freund
1d8f33ca98 stage2: link musl dynamically by default if native
If targeting the native OS and the system libc is musl, link against it
dynamically by default.
2020-12-13 00:40:35 +01:00
Isaac Freund
078a64f8d9 std.CrossTarget: add isNativeAbi() 2020-12-13 00:40:35 +01:00
Isaac Freund
307d98dc35 stage2: support dynamically linking musl libc 2020-12-13 00:40:35 +01:00
Andrew Kelley
6b7ddfbafe glibc: do not provide -lcrypt
glibc is dropping this functionality moving forward.

This is a partial revert of commit
97c0e1cc41
2020-12-12 12:42:33 -07:00
LemonBoy
629cc6cf28 std: Further siginfo refinements
* Define siginfo and sigaction for Darwin
* Define sigaction/handler union for maximum libc compatibility
* Minor correction to some type definitions
2020-12-12 16:44:10 +01:00
LemonBoy
1d9b28403a std: Correct check in signal test
Ooops.
2020-12-12 15:34:26 +01:00
LemonBoy
beae3cea17 std: Improve sigaction interface
Add a smoke test to prevent regressions.
2020-12-12 13:57:25 +01:00
Andrew Kelley
d569e37cb5 std.fs.path.extension: different behavior for ending dot
extension("a.") now returns "." instead of "".

This matches both Python and Node.js standard library behavior as well
as my personal opinion on how this function should be defined.

Apologies for missing this in the code review.
2020-12-11 18:20:57 -07:00
Andrew Kelley
6ab5bebed1 stage2: proper file extension stripping
Previously it used mem.split on "." and took the first iterated item.
Now it uses fs.path.extension and strips off that number of bytes.

Closes #7404
2020-12-11 17:42:13 -07:00
Andrew Kelley
52bc1442d6 std.fs.path.extension: add additional API guarantee
Added:

The returned slice is guaranteed to have its pointer
within the start and end pointer address range of `path`,
even if it is length zero.
2020-12-11 17:41:34 -07:00
Andrew Kelley
1852dc7e13 Merge pull request #7098 from MasterQ32/std.fs.path.extension
Implements std.fs.path.extension
2020-12-11 19:32:21 -05:00
Andrew Kelley
c4f53d1ef6 fix deadlock with build-exe on an object for windows
The steps to repro this issue are:

zig build-obj hello.zig -target x86_64-windows-msvc
zig build-exe hello.obj -target x86_64-windows-msvc --subsystem console
-lkernel32 -lntdll

What was happening is that the main Compilation added a work item to
produce kernel32.lib. Then it added a sub-Compilation to build zig's
libc, which ended up calling a function with extern "kernel32", which
caused the sub-Compilation to also try to produce kernel32.lib. The main
Compilation and sub-Compilation do not coordinate about the set of
import libraries that they will be trying to build, so this caused a
deadlock.

This commit solves the problem by disabling the extern "foo" feature
from working when building compiler_rt or libc. Zig's linker code is now
responsible for putting the appropriate import libs on the linker line,
if any for compiler_rt and libc.

Related: #5825
2020-12-11 18:34:34 -05:00
Andrew Kelley
5b56f4e48a mingw-w64: add .def files for xinput1_4
closes #7398
2020-12-11 11:12:23 -07:00
Andrew Kelley
a1d3886ff0 mingw-w64: add support for -lwldap32
closes #7395
2020-12-11 00:50:28 -07:00
LemonBoy
fa6449dac0 zig fmt: Fix alignment of initializer elements
Resetting `column_counter` is not needed as the effective column number
is calculated by taking that value modulo `row_size`.

Closes #7289
2020-12-11 02:34:44 -05:00
Andrew Kelley
64a590a311 stage2: detect redundant C/C++ source files
Cache exposes BinDigest.

Compilation gains a set of a BinDigest for every C/C++ source file. We
detect when the same source/flags have already been added and emit a
compile error. This prevents a deadlock in the caching system.

Closes #7308
2020-12-11 02:33:09 -05:00
Andrew Kelley
0d00938016 update contributing docs 2020-12-10 20:17:07 -07:00
Andrew Kelley
f7d600675c CLI: improved local cache directory logic
Previously, when choosing the local cache directory, if there was no
root source file, an explicitly chosen path, or other clues, zig would
choose cwd + zig-cache/ as the local cache directory.

This can be problematic if Zig is invoked with the CWD set to a
read-only directory, or a directory unrelated to the actual source files
being compiled. In the real world, we see this when using `zig cc` with
CGo, which for some reason changes the current working directory to the
read-only go standard library path before running the C compiler.

This commit conservatively chooses to use the global cache directory
as the local cache directory when there is no other reasonable choice,
and no longer will rely on the cwd path to choose a local cache directory.

As a reminder, the --cache-dir CLI flag and ZIG_LOCAL_CACHE_DIR
environment variable are available for overriding the decision. For the
zig build system, it will always choose the directory that build.zig is
+ zig-cache/.

Closes #7342
2020-12-10 16:17:02 -07:00
antlilja
26399b5249 Added global-cache argument to build system + removed extra args.
* Field global_cache_root was added to Builder struct along with
mandatory argument for build_runner.zig. Logic for using the custom
global cache was also added.

* The arguments --cache-dir and --global-cache-dir are no longer passed
directly through to build_runner.zig and are instead only passed through the
mandatory cache_root and global_cache_root arguments.
2020-12-10 18:06:19 -05:00
Andrew Kelley
a3de27ef3b Merge pull request #7372 from LemonBoy/atomicint
Improvements for std.atomic.{Int,Bool}
2020-12-10 16:13:36 -05:00
Evan Haas
55cac65f95 Support casting enums to all int types.
In C, enums are represented as signed integers, so casting from an enum to an integer
should use the "cast integer to integer" translation code path. Previously it used the
"cast enum to generic non-enum" code path, because enums were not being treated as integers.
Ultimately this can produce zig code that fails to compile if the destination type does not
support the full range of enum values (e.g. translated C code that casts an enum value to an
unsigned integer would fail to compile since enums are signed integers, and unsigned integers
cannot represent the full range of values that signed ones can).

One interesting thing that came up during testing is that the implicit enum-to-int cast that
occurs when an enum is used in a boolean expression was parsed as an (int) by some versions of
the zig compiler, and an (unsigned int) cast by others. Specifically, the following code:

```c
	enum Foo {Bar, Baz};
	// ...
	enum Foo foo = Bar;
	if (0 || foo) {
		// do something
	}
```

When tested on MacOS, Linux, and Windows using a compiler built from the Windows Zig Compiler
Dev Kit, the above code would emit a cast to c_uint:

`if (false or (@bitCast(c_uint, @enumToInt(foo)) != 0)) {}`

However when tested on Windows with a Zig compiler built using MSVC, it produces:

`if (false or (@bitCast(c_int, @enumToInt(foo)) != 0)) {}`

In this particular case I don't think it matters, since a c_int and c_uint will have the same
representation for zero, but I'm not sure if this is ultimately the result of
implementation-defined behavior or something else.

Because of this, I added explicit casts in the `translate_c.zig` tests, to ensure that the
emitted zig source exactly matches across platforms. I also added a behavior test in
`run_translated_c.zig` that uses the old implicit casts from `translate_c.zig` to ensure
that the emitted Zig code behaves the same as the C code regardless of what cast is used.
2020-12-10 15:47:56 -05:00
Andrew Kelley
5a5389128d Merge pull request #7369 from jorangreef/io_uring_timeout
Add io_uring TIMEOUT and TIMEOUT_REMOVE operations:
2020-12-10 15:45:38 -05:00
Vexu
afc21a2f1c make std.json.unescapeString pub 2020-12-10 21:19:41 +02:00
Vexu
73016212a3 translate-c: support referencing c containers in macros 2020-12-10 14:45:48 +02:00
Joran Dirk Greef
b5a9fd9f98 Skip timeout_remove test where not supported by the kernel 2020-12-10 11:34:20 +02:00
LemonBoy
88e3a7d6dc std: Fix misuse of atomic.Int 2020-12-10 09:23:48 +01:00
LemonBoy
5e91cc2fe3 std: Validate the atomic ordering parameter in atomic.Int 2020-12-10 09:23:48 +01:00
LemonBoy
5844511408 std: prevent instantiation of atomic.Int with non-integral types 2020-12-10 09:23:48 +01:00
LemonBoy
ef7db9717e std: introduce meta.traits.is{Integral,Float} 2020-12-10 09:23:48 +01:00
Jakub Konka
23c1b7faee Merge pull request #7368 from kubkon/macho-trie-cleanup
stage2: MachO export trie cleanup
2020-12-10 08:32:59 +01:00
Joran Dirk Greef
dd3eac2eb1 Debug CI io_uring unsupported op 2020-12-10 08:36:33 +02:00
Michael Dusan
8951f72fa3 Merge pull request #7375 from mikdusan/qemu
ci linux: bump qemu-5.2.0
2020-12-10 00:05:14 -05:00
Andrew Kelley
cb896a6573 CLI: infer --name based on first C source file or object
Previously, --name would only be inferred if there was exactly 1 C
source file or exactly 1 object. Now it will be inferred if there is at
least one of either.
2020-12-09 21:20:13 -07:00
Timon Kruiper
4c51adeb0d Do not keep the build.zig cache manifest file locked.
This allows to have multiple instances of `zig build` at the same
time. For example when you have a long running `zig build run` and
then want to run `zig build somethingelse`.
2020-12-09 22:16:04 -05:00
Michael Dusan
ae0af5e5a6 ci linux: bump qemu-5.2.0 2020-12-09 21:31:31 -05:00
Andrew Kelley
7c93d9aacb mingw-w64: patch to silence implicit-function-declaration warnings
Closes #7356

I did this as a patch to the source rather than passing flags so that
it would intentionally be reverted when we update to the next release of
mingw-w64. At this time if any warnings are still emitted we should find
out why and make sure upstream is aware of the problem.
2020-12-09 16:12:03 -07:00
Andrew Kelley
6e636064e6 MoveFileEx can return ACCESS_DENIED
I observed this on Windows 10, trying to use MoveFileEx with
MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH
to overwrite a running executable.
2020-12-09 15:03:17 -07:00
Jakub Konka
44e2f210bb lld+macho: clean up error message when padding insufficient 2020-12-09 20:36:58 +01:00
Jakub Konka
184c0f3c4e stage2+macho: write code signature only when targeting aarch64 2020-12-09 20:36:58 +01:00
Jakub Konka
601600dec9 macho: parsing Trie now takes a reader and returns bytes read 2020-12-09 20:36:58 +01:00
Jakub Konka
a283404053 macho: split writing Trie into finalize and const write 2020-12-09 20:36:58 +01:00
Jakub Konka
a579f8ae8d macho: add generic terminal info nullable struct to a node 2020-12-09 20:36:58 +01:00
Jakub Konka
4c3e6c5bff macho: cleanup export trie generation and parsing
Now, ExportTrie is becoming usable for larger linking contexts such
as linking in multiple object files, or relinking dylibs, etc.
2020-12-09 20:36:58 +01:00
Andrew Kelley
ae3fd86dcc Merge pull request #7367 from kubkon/aarch64-stp-ldp
stage2: add aarch64 load/store pair of registers instructions
2020-12-09 14:31:08 -05:00
Andrew Kelley
f291194834 Merge pull request #7362 from Vexu/std
zig fmt improvement and small miscellaneous fixes
2020-12-09 14:29:15 -05:00
Martin Wickham
676e416c86 Fix operator precedence documentation 2020-12-09 14:26:29 -05:00
Andrew Kelley
5ff0f364a5 Merge pull request #7366 from LemonBoy/fix-7346
Some compiler-rt fixes
2020-12-09 14:19:58 -05:00
LemonBoy
3f0a4ffbf4 langref: Update setEvalBranchQuota prototype 2020-12-09 20:15:58 +01:00
Joran Dirk Greef
349d32dc2c Add io_uring TIMEOUT and TIMEOUT_REMOVE operations:
ring.timeout() to queue a IORING_OP_TIMEOUT operation
ring.timeout_remove() to queue a IORING_OP_TIMEOUT_REMOVE operation

io_uring_prep_timeout() to prep a IORING_OP_TIMEOUT sqe
io_uring_prep_timeout_remove() to prep a IORING_OP_TIMEOUT_REMOVE sqe
2020-12-09 19:06:28 +02:00
Jakub Konka
2082c27557 stage2+aarch64: clean up offset helper structs 2020-12-09 17:21:21 +01:00
Jakub Konka
e91dbab256 stage2+aarch64: fix stage2 tests 2020-12-09 17:21:17 +01:00
Jakub Konka
eca0727417 stage2+aarch64: use stp and ldp to navigate MachO jump table 2020-12-09 17:20:58 +01:00
Jakub Konka
21dae538ca stage2+aarch64: add load and store pair of registers instructions 2020-12-09 17:20:14 +01:00
LemonBoy
2f4f7ace7a stage1: Resolve some constants to u32, not usize
The latter may be smaller than a u32, use a u32 explicitly.
2020-12-09 17:01:18 +01:00
LemonBoy
6f220bb7ca std: explicitly cast indices to usize
This is needed for platforms where usize=u16, eg. MSP430.
2020-12-09 16:48:41 +01:00
LemonBoy
afd491c07e compiler-rt: Fix compilation of clzsi for armv6 targets 2020-12-09 16:48:02 +01:00
LemonBoy
518168edb2 compiler-rt: Avoid exposing atomic builtins when not supported
Let's a void any kind of compilation/LLVM errors for niche targets such
as AVR/MSP430 or ARM v6m. By not exporting any atomic builtin anymore
the user is free to provide their own implementation (that disable the
IRQs) or to provide the --single-threaded switch and forget about this.
2020-12-09 16:33:53 +01:00
Vexu
7e30e83900 small fixes and zig fmt 2020-12-09 13:54:26 +02:00
Vexu
be71994fb1 zig fmt: improve var decl initializer formatting 2020-12-09 13:47:22 +02:00
Lee Cannon
3599fb9bfc Fixes #7352 - ignore zig fmt ignore zig-cache 2020-12-09 12:11:52 +02:00
Andrew Kelley
391d81a380 Merge pull request #7355 from ziglang/lld-child-process
invoke LLD as a child process rather than a library
2020-12-09 02:26:13 -05:00
Andrew Kelley
7dd4afb224 stage2: link: properly implement passthrough mode for LLD child proc
passthrough mode does not mean always exit - it just means to pass
through stdio and exit if the child process exits, without doing any
special error reporting.
2020-12-08 22:37:01 -07:00
Andrew Kelley
4592fd26b9 add std.testing.expectStringEndsWith 2020-12-08 21:59:24 -07:00
Andrew Kelley
72f6c6e634 invoke LLD as a child process rather than a library
Closes #3825
2020-12-08 20:00:16 -07:00
xackus
21550bb7cd std.json: unreachable -> expect in tests 2020-12-08 19:16:17 -05:00
LemonBoy
8ac711596d stage1: Validate the specified cc for lazy fn types
Closes #7337
2020-12-08 19:09:25 -05:00
antlilja
8f646daed6 Change tag returned by zigTagType for c_longdouble to Float.
Function was returning Int before.
2020-12-09 01:18:27 +02:00
Andrew Kelley
2759313263 add support for environment variables to control cache directories
This commit adds:

ZIG_LOCAL_CACHE_DIR corresponding to --cache-dir
ZIG_GLOBAL_CACHE_DIR corresponding to --global-cache-dir
ZIG_LIB_DIR corresponding to --override-lib-dir

The main use case is for `zig cc` where we are bound by clang's CLI
options and need alternate channels to pass these configuration options.
2020-12-08 14:39:17 -07:00
antlilja
c796c4528e Add option to override default stack size in build system. 2020-12-08 16:18:16 -05:00
Nathanaël Courant
81890e30e2 Fix general purpose allocator incorrectly modifying total_requested_bytes in some cases 2020-12-08 15:53:34 -05:00
Andrew Kelley
58c8ad8ea8 tests: run-translated-c now respects -Dtarget 2020-12-08 13:46:05 -07:00
Andrew Kelley
24cbf1c706 always use codeview (pdb) when object_format is PE/COFF
Previously, when mixing Zig and C/C++ code for windows-gnu targets, zig
would get codeview format but the C/C++ code would not get any debug
info. Now, C/C++ code properly emits debug info in codeview format and
everything just works.
2020-12-08 13:31:39 -07:00
Andrew Kelley
a482b82e2d stage2: only patch up LLD binaries on aarch64-macos
The code is a bit fragile so it was causing CI failures on x86_64-macos.
Also the patch up code is only needed for aarch64-macos, so we were
doing unnecessary work.
2020-12-08 12:47:48 -07:00
Andrew Kelley
97c0e1cc41 glibc: additionally provide -lcrypt
also remove redundant "util" string matching.
2020-12-08 13:17:57 -05:00
Nathan Michaels
1847d0cfc2 Implement msp430 mapping for c_longdouble. (#7333) 2020-12-08 13:09:00 -05:00
Andrew Kelley
a01d55e801 Merge pull request #7309 from ziglang/build-stage1-with-only-zig
ability to build stage1 using only a zig tarball
2020-12-07 23:54:34 -05:00
Andrew Kelley
1afea36a16 update readme installation instructions
The readme now links to the wiki for instructions on building from
source. I plan to make many updates to the wiki soon as I start to
provide tarballs for working on the compiler.
2020-12-07 17:50:14 -07:00
Andrew Kelley
88dc688bbf restore the option to build with cmake
restore cmake to be capable of figuring out the zig version

restore config.h and config.zig. config.h is used to detect whether we
should propagate cmake configuration information to build.zig; however
it can be overridden with -Dstatic-llvm.

fix not passing -DZIG_LINK_MODE with zig build.

when using the cmake build path, build.zig no longer tries to call
llvm-config. Instead it relies 100% on the LLVM_LIBRARIES cmake variable.

build.zig logic reworked and simplified.
2020-12-07 17:27:09 -07:00
Andrew Kelley
211ac00f83 build: -lversion -luuid on windows and -DNDEBUG=1 for clang sources 2020-12-07 17:27:09 -07:00
Andrew Kelley
76e306ad0f fix wrong entrypoint, undefined package, and wrong build option 2020-12-07 17:27:09 -07:00
Andrew Kelley
5a65caa2a3 ability to build stage1 using only a zig tarball
The main idea here is that there are now 2 ways to get a stage1 zig
binary:

 * The cmake path. Requirements: cmake, system C++ compiler, system
   LLVM, LLD, Clang libraries, compiled by the system C++ compiler.

 * The zig path. Requirements: a zig installation, system LLVM, LLD,
   Clang libraries, compiled by the zig installation.

Note that the former can be used to now take the latter path.

Removed config.h.in and config.zig.in. The build.zig script no longer is
coupled to the cmake script.

cmake no longer tries to determine the zig version. A build with cmake
will yield a stage1 zig binary that reports 0.0.0+zig0. This is going to
get reverted.

`zig build` now accepts `-Dstage1` which will build the stage1 compiler,
and put the stage2 backend behind a feature flag.

build.zig is simplified to only support the use case of enabling LLVM
support when the LLVM, LLD, and Clang libraries were built by zig. This
part is probably sadly going to have to get reverted to make package
maintainers happy.

Zig build system addBuildOption supports a couple new types.

The biggest reason to make this change is that the zig path is an
attractive option for doing compiler development work on Windows. It
allows people to work on the compiler without having MSVC installed,
using only a .zip file that contains Zig + LLVM/LLD/Clang libraries.
2020-12-07 17:27:09 -07:00
Luna
5f7b97e84c add AddressFamilyNotSupported to SendError 2020-12-07 16:40:03 -05:00
antlilja
5c60558796 Utilize std.fmt.parseUnsigned in main.zig.
* Remove function parseAnyBaseInt.
* Replace calls to parseAnyBaseInt to calls to std.fmt.parseUnsigned
with radix 0.
* Replace calls to parseInt where the type is unsigned with calls to
parseUnsigned. Note that the functionality of these arguments haven't
changed, they still retain the original radix specified.
2020-12-07 16:38:52 -05:00
xackus
85dc039632 std.c: freeing null is a no-op 2020-12-07 16:33:27 -05:00
g-w1
6294c1136c stage2: variable shadowing detection (#6969) 2020-12-06 19:36:49 +02:00
Veikka Tuominen
0268f54fcf Merge pull request #7313 from LemonBoy/booo
Fix a few unsound optimizations on single-element union/enum
2020-12-06 19:31:07 +02:00
LemonBoy
b45d2968e5 Add some test cases for the previous commits 2020-12-05 20:14:04 +01:00
LemonBoy
97f36d93f4 stage1: Don't fold single-element enums too aggressively
When the tag type is not a zero-sized type (eg. `enum(i32)`) we
absolutely need to avoid constant-folding this values. Doing so masked
any invalid input and, since the folding was not even applied
consistently, introduced some hard to catch errors.
2020-12-05 20:14:04 +01:00
LemonBoy
0f7954831a stage1: Initialize single-element union tag correctly
Use the field value instead of defaulting to zero.
2020-12-05 18:58:54 +01:00
LemonBoy
865d6df03e stage1: Fix constant folding of single-element enums
Fill in the correct value instead of leaving everything uninitialized.
This problem can be noticed in behavior/union.zig but it's masked by
some other "optimization" kicking in at the wrong time, the following
commits will address that.
2020-12-05 18:58:37 +01:00
Andrew Kelley
2ed1ed9b32 stage2: introduce Module.failed_root_source_file
Use case:

zig build-exe non_existent_file.zig

Previous behavior:

error.FileNotFound, followed by an error return trace

Behavior after this commit:

error: unable to read non_existent_file.zig: FileNotFound
(end of stderr, exit code 1)

This turns AllErrors.Message into a tagged union which now has the
capability to represent both "plain" errors as well as source-based
errors (with file, line, column, byte offset). The "no entry point found"
error has moved to be a plain error message.
2020-12-04 17:21:55 -07:00
Andrew Kelley
1c5606af9f update to latest clang C headers 2020-12-04 15:39:16 -07:00
LemonBoy
fd8fa55129 std: Add a few helpers for matching ascii strings (#7300)
* startsWithIgnoreCase
* endsWithIgnoreCase
2020-12-04 15:27:28 -05:00
LemonBoy
ac443b941d std: Restore file locking test on Windows
Make it even more robust wrt timing problems.

Closes #7010
2020-12-04 12:24:50 -08:00
Jakub Konka
b390ced356 macho: specify -install_name as full dylib's name
This then allows for proper resolution of names via runpath search
path list, i.e., `-rpath @loader_path` will correctly resolve
to `@rpath/libxxx.dylib (...)` in the linked binary.
2020-12-04 12:23:49 -08:00
Andrew Kelley
a90de4eef5 Merge pull request #7301 from LemonBoy/more-ci-stuff
Make the CI script more robust
2020-12-04 12:15:55 -08:00
Jakub Konka
c4853ba7ea Version-gate appending -syslibroot flag to lld
This commit version-gates appending `-syslibroot` flag to lld. This
is predicated upon the fact that for versions of macOS lower than
11, lld would fail to find and link against frameworks with this
flag specified.

Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2020-12-04 11:37:55 -08:00
LemonBoy
55838bc291 ci: Use eval to make retry() work for pipelines too 2020-12-04 17:31:27 +01:00
Jakub Konka
b6b7a6401c Merge pull request #7293 from kubkon/fix-7030
stage1: allow idx 0 err to be put into error_name_table
2020-12-04 16:29:38 +01:00
LemonBoy
2282eb1be1 ci: Use -nv flag for wget
-nv, --no-verbose   turn off verboseness, without being quiet
2020-12-04 13:11:45 +01:00
LemonBoy
77031baf98 ci: Prevent some more CI failures
Many times the CI pipeline fails in the early stages because the APT
repo for LLVM is being updated.
Add a retry mechanism for some more APT commands.
2020-12-04 13:11:45 +01:00
Jakub Konka
e3db2be899 Add minimal standalone test case 2020-12-04 12:43:58 +01:00
Andrew Kelley
58241364cb add more mingw-w64 .def files
closes #7268
2020-12-03 18:03:34 -07:00
Andrew Kelley
afaef36194 stage1: compile error for pointer arithmetic on ptr-to-array
See #2018
2020-12-03 17:07:13 -07:00
Isaac Yonemoto
fd18252a71 makes the implementation public 2020-12-03 15:14:59 -08:00
Andrew Kelley
ddaf915389 add @cImport files to Compilation cache manifest
closes #7007
2020-12-03 16:07:38 -07:00
Jakub Konka
54706dd229 Allow idx 0 err to be put into error_name_table
This way, in the very situation where a function has a return type
an error union such as `anyerror!void` but doesn't have any erroneous
paths, calling `@errorName` on the unpacked error (which will never
be triggered) will not trip up the static analyzer.
2020-12-03 23:31:35 +01:00
Andrew Kelley
ecf7dfcd3a Merge pull request #7273 from kubkon/lld-codesig-poc
lld+macho: patch lld output on Apple Silicon by calculating and embedding adhoc code signature
2020-12-03 13:41:31 -08:00
Jakub Konka
d3be499270 lld+macho: address review comments 2020-12-03 21:57:26 +01:00
Isaac Yonemoto
a2cd9dc3bd Gpa mutex configurable (#7234)
* makes the mutex for the gpa configurable

* fixed logic, added test

* updates docstring; pushes logic to one place, better duck-type
2020-12-03 15:49:35 -05:00
Koakuma
5317f00e04 Fix floating point parsing on BE systems (#7256)
* Fix floating point parsing on BE systems

* Load the appropriate endian.h files for macOS and BSD

* Add endian definition for Windows and extra check for ldshape selection

* Fix endian macro definition for macOS

Apparently their macros are defined without a leading __.

* Define new macro for endian checking purposes

This is gross and I really do not like the lack of standardization
around this part, but what can I do?
2020-12-03 15:47:06 -05:00
Miles Alan
7bbd369fbb std/event: Fix import path for WaitGroup 2020-12-03 12:43:55 -08:00
Jakub Konka
a8e543bd6b Merge pull request #7280 from leecannon/master
Add `readUntilDelimiterOrEofArrayList` & `readUntilDelimiterOrEofAlloc`
2020-12-03 21:03:48 +01:00
Timon Kruiper
ac85e1f2c8 stage2: make sure to emit the ZIR instructions of exported functions
Previously the emitted ZIR code would not have the ZIR instructions
of the exported functions.
2020-12-03 11:46:35 -08:00
Lee Cannon
f598245836 Make zig fmt happy with multiline arguments for readAllArrayListAligned 2020-12-03 10:24:49 +00:00
Andrew Kelley
5b6cbd2e7c stage2: don't pass -l arguments when building .a or .o files
See #7094
2020-12-02 20:17:51 -07:00
LemonBoy
cb63ecd6e9 std: Add nosuspend around stderr.print calls 2020-12-02 16:34:51 -08:00
Vexu
d4c167f3cd std.build: addBuildOption special handling for SemanticVersion 2020-12-02 16:33:27 -08:00
Andrew Kelley
41387e1822 stage2: linkAsArchive: respect disable_lld_caching
Closes #7274
Closes #6943
2020-12-02 16:37:32 -07:00
Andrew Kelley
6d91ebce45 wire up -Dskip-non-native to stage2 tests 2020-12-02 15:52:07 -07:00
Andrew Kelley
463186e856 stage2: wire up -Dskip-non-native
The purpose of this is to save time in the edit-compile-test cycle when
working on stage2 code.
2020-12-02 14:52:56 -07:00
Andrew Kelley
f842327147 Merge pull request #7277 from LemonBoy/thread-posix
std: make the use of pthread_join POSIX-compliant
2020-12-02 13:47:40 -08:00
Jakub Konka
5cba16c707 macho:use mem.asBytes and meta.eql in commands.zig
This commit addresses comments suggesting a cleaner approach
at converting an `extern` struct to its byte representation using
`mem.asBytes`, and to use `meta.eql` in place of more fragile
`mem.eql(u8, ...)` for comparison of two `extern` structs.

Thanks LemonBoy!
2020-12-02 18:40:31 +01:00
Mathieu Guay-Paquet
4c8632e244 fix the tinyest typo 2020-12-02 19:08:25 +02:00
Lee Cannon
76f3921544 Add readUntilDelimiterOrEofArrayList & readUntilDelimiterOrEofAlloc 2020-12-02 12:55:54 +00:00
LemonBoy
471e26425a ci: Retry apt-get install at most three times
Try harder instead of failing after the first invocation fails.
2020-12-02 12:14:11 +01:00
Jakub Konka
0fba2f7175 lld: fix using incorrect path for the final artefact 2020-12-02 11:21:52 +01:00
LemonBoy
f8cef32f27 std: make the use of pthread_join POSIX-compliant
Applications supplying their own custom stack to pthread_create are not
allowed to free the allocated memory after pthread_join returns as,
according to the specification, the thread is not guaranteed to be dead
after the join call returns.

Avoid this class of problems by avoiding the use of a custom stack
altogether, let pthread handle its own resources.

Allocations made on the child stack are now done on the C heap.

Thanks @semarie for noticing the problem on OpenBSD and suggesting a
fix.

Closes #7275
2020-12-02 10:59:35 +01:00
daurnimator
db0cb54f4e Localhost is special (#6955)
* std: always return loopback address when looking up localhost

* std: also return Ipv6 loopback

* std: remove commented out obsolete code
2020-12-01 19:13:59 -05:00
LemonBoy
c91c4dc256 stage2: Create cache manifest before calling final
If we enter the `if` because `comp.disable_c_depfile` is false the `man`
object has no manifest and calling .final on it will trip an assertion.

Closes #7096
2020-12-01 16:52:28 -07:00
Andrew Kelley
5b5097a22a stage2: add -femit-foo=bar args to the cache hash
Closes #6979
Closes #7036
2020-12-01 16:35:27 -07:00
Jakub Konka
3e2d1ccaad lld+macho: rename final artefact in main.zig 2020-12-02 00:03:07 +01:00
Jakub Konka
b58a2a4de6 lld+macho: move parsing logic into MachO 2020-12-01 23:39:07 +01:00
Alexandros Naskos
8d6eff5cb9 Add package names and paths to the zig root module cache hash.
Add package names to the stage1 cache hash and package files to the
stage1 manifest file.
2020-12-01 13:56:36 -08:00
Timon Kruiper
8cbcc61c4d Make sure to include the root_name in the cache.
This fixes a bug where the caching system did not notice when the
--name flag changed.
2020-12-01 10:38:33 -08:00
Andrew Kelley
c7028ce0c6 COFF linking: fix incorrectly passing .dll instead of .lib
commit 9d1816111d used the "output path"
as the path for passing shared library artifact paths to the Zig CLI.
For Windows, this was incorrect because it would pass the .dll instead
of the .lib file. This commit passes the "output lib path" instead,
which makes it pass the .lib path in case of a .dll on Windows.

This way the linker does not complain and say, "bad file type. Did you
specify a DLL instead of an import library?"
2020-12-01 11:28:44 -07:00
Jakub Konka
ed18046518 macho: dynamically calculate code signature padding 2020-12-01 18:03:31 +01:00
Jakub Konka
abb697e751 macho: unify code signature between stage1 and stage2 2020-12-01 18:03:04 +01:00
Jakub Konka
1f7fb560ab lld: use commands.LoadCommand in self-hosted linker 2020-12-01 10:49:31 +01:00
Jakub Konka
de66b65677 lld: start unifying load command logic 2020-12-01 10:49:31 +01:00
Jakub Konka
0ef3071db6 lld: copy+rename to please the kernel 2020-12-01 10:49:31 +01:00
Jakub Konka
c25b3593e7 lld: add code signature to lld output 2020-12-01 10:49:31 +01:00
Jakub Konka
545721ccd1 lld: add code signature padding 2020-12-01 10:49:31 +01:00
Jakub Konka
e8ffae60a2 lld: parse output lld file 2020-12-01 10:49:31 +01:00
Andrew Kelley
02e12ede46 update to latest fetch-them-macos-headers
commit 1efc3a7f584dd75a5783756e168af74cdf6bb727
2020-11-30 20:20:31 -08:00
Isaac Freund
92ec24f77c std/os: remove unneeded error from accept errorset
POSIX compliant fnctl cannot return EPERM when getting/setting the given
flags. See the specification here:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/fcntl.html
2020-11-30 20:00:26 -08:00
Andrew Kelley
21565ca991 restore -target wasm32-freestanding-musl for C headers
See #5854

Some tiny tweaks too:
 * Use `wasm-freestanding-musl` instead of `wasm32-freestanding-musl`,
   making it pointer-size-agnostic.
 * Fix trying to build non-existent wasm musl start files.
2020-11-30 20:44:36 -07:00
Andrew Kelley
429a219f42 stage2: fix not detecting all dynamic libraries
Positional shared library arguments were not being detected as causing
dynamic linking, resulting in invalid linker lines. LLD did not have an
error message for this when targeting x86_64-linux but it did emit an
error message when targeting aarch64-linux, which is how I noticed the
problem.

This surfaced an error having to do with fifo.pipe() in the cat example
which I did not diagnose but solved the issue by doing the revamp that
was already overdue for that example.

It appears that the zig-window project was exploiting the previous
behavior for it to function properly, so this prompts the question, is
there some kind of static/dynamic executable hybrid that the compiler
should recognize? Unclear - but we can discuss that in #7240.
2020-11-30 20:25:28 -07:00
Andrew Kelley
c55984b58f Merge branch 'alexnask-fix_6868' into master
Closes #7139
Closes #6868
2020-11-30 18:12:07 -07:00
Andrew Kelley
9d1816111d build system: pass dyn lib artifacts as positionals 2020-11-30 18:12:00 -07:00
Alexandros Naskos
f7d0a32045 Switched OBJECT_NAME_INVALID handling to unreachable in faccessatW 2020-11-30 18:08:27 -07:00
Alexandros Naskos
beb9d33d6d Disallow absolute paths passed as system libraries
Added OBJECT_NAME_INVALID handling in faccessatW
2020-11-30 18:08:27 -07:00
Andrew Kelley
8c9919ec7b fix regression on wasm targets
The previous commit broke wasm targets because the linking step would
look for the compiler-rt lib in the wrong place. Fixed in this commit.
2020-11-30 17:46:10 -07:00
Andrew Kelley
205af5b148 Merge branch 'alexnask-bundle_compiler_rt' into master
Closes #7013
Closes #6817
2020-11-30 16:40:25 -07:00
Andrew Kelley
ff9798eb26 rework the bundle compiler-rt feature
* it is now -fcompiler-rt and -fno-compiler-rt to override the (quite
   reasonable) default of bundling compiler-rt only for executables and
   dynamic libraries.
   - the build.zig API is still called bundle_compiler_rt however it is
     now an optional bool instead of a bool. leaving it as `null` means
     to use the compiler default.
 * renamed some internal identifiers to make the source more readable
 * additionally support -fcompiler-rt when doing build-obj for ELF files
   since that target already supports linking multiple objects into one.
   - includes an error message when attempting this for non-ELF. in the
     future this could additionally be supported with a more advanced
     implementation that does not rely on the linker.
 * properly populate the linker cache hash
2020-11-30 16:35:00 -07:00
Alexandros Naskos
2fae28b6af Added bundle-compiler-rt flag 2020-11-30 14:31:41 -07:00
Andrew Kelley
51d7c14ce1 update to latest fetch-them-macos-headers
commit 09b70199e738bfa86c55cd3a848287229a207982

closes #7261
2020-11-30 13:18:34 -08:00
Andrew Kelley
50a336fff8 move std.SegmentedList to the std-lib-orphanage
I spent a long time working on this data structure, and I still think
it's a neat idea, but it has no business being in the std lib.

I'm aware of the few remaining references to SegmentedList that exist in
the std lib, but they are dead code, and so I'm leaving the dead
references as a clue that the code is dead. Cleaning up dead code will
be a separate effort that involves code coverage tools to make sure we
find it all.

std-lib-orphanage commit: 2c36a7894c689ecbaf63d5f489bb0c68773410c4

closes #7190
2020-11-30 13:04:26 -07:00
Jonathan Marler
b587a42233 add std.os.shutdown function for sockets 2020-11-30 11:25:03 -08:00
Michael Freundorfer
baa075ac8c Fix WindowsDynLib.openW trying to strip the \??\ prefix when it does not exist 2020-11-30 11:12:33 -08:00
Rageoholic
0369b65082 Switch to using unicode when parsing the command line on windows (#7241)
* Switch to using unicode when parsing the command line on windows

* Apply changes by LemonBoy and *hopefully* fix tests on MIPs

Co-authored-by: LemonBoy <LemonBoy@users.noreply.github.com>

* Fix up next and skip

* Move comment to more relevant place

Co-authored-by: LemonBoy <LemonBoy@users.noreply.github.com>
2020-11-30 13:47:01 -05:00
Jonathan Marler
b8f09f773a fix memory leak in BufMap 2020-11-30 10:40:16 -08:00
Andrew Kelley
4808a0261f macOS headers: add memory.h
it's provided by macOS LibC and apparently there is code in the wild
that depends on it. all it does is #include <string.h>

closes #7249
2020-11-29 17:41:16 -08:00
Andrew Kelley
52b24d5725 stage1: add some code comments for ConstValSpecial 2020-11-29 18:02:13 -07:00
Andrew Kelley
3fb0cc0a14 CLI: add missing usage help text 2020-11-29 16:32:24 -07:00
Andrew Kelley
263f25fea6 Merge pull request #7116 from joachimschmidt557/stage2-arm
stage2 ARM: add basic arithmetic instructions
2020-11-29 10:43:29 -08:00
LemonBoy
df99cfdf1e stage1: Fix typeInfo generation for arrays w/o sentinel
ZigTypeIdOptional types have a different way of specifying their payload
value depending on whether the child type is a pointer or not (plus some
other special cases).

Fixes #7251
2020-11-29 10:39:10 -08:00
LemonBoy
c80d196094 stage1: Add missing bitcast when rendering var ptr
Some types require this extra bitcast, eg. structs or unions with extra
padding fields inserted by the compiler.

Fixes #7250
2020-11-29 10:37:06 -08:00
Jonathan Marler
48660371a2 std.meta: add assumeSentinel 2020-11-29 10:36:02 -08:00
Andrew Kelley
e701ac1a51 Merge pull request #7237 from koachan/sparc64-longdouble_fork
Add "long double" mapping and implement fork() on Linux/sparc64
2020-11-29 10:33:43 -08:00
LemonBoy
89ee4b8621 std: Avoid deadlock in the signal handler
stderr_mutex may still be held when we reach the signal handler, grab
our own stderr handle to print the error messages and avoid deadlocking.

Closes #7247
2020-11-29 10:31:06 -08:00
joachimschmidt557
ceebcb2b4d stage2 ARM: add test case for addition 2020-11-28 23:26:17 +01:00
joachimschmidt557
2ad2636588 stage2 ARM: use strb + implement genBoolOp 2020-11-28 18:19:22 +01:00
joachimschmidt557
f06f0ebcda stage2 ARM: Implement genNot 2020-11-28 18:19:22 +01:00
joachimschmidt557
85a3991a43 stage2 codegen: use switch in genBoolOp 2020-11-28 18:19:22 +01:00
joachimschmidt557
27c5c97f21 stage2 ARM: genAdd, genSub for simple cases 2020-11-28 18:19:19 +01:00
Koakuma
f10bff9ffb Add a comment to explain the fork return values on sparc64 2020-11-28 13:24:24 +07:00
christian-stephen
abc729a5f9 Add readAllArrayListAligned to Reader which can accept an arbitrary alignment 2020-11-27 17:00:50 -08:00
Andrew Kelley
9268972ff9 Merge branch 'kubkon-elf-soname-opt-in' into master
closes #7162
2020-11-27 17:54:22 -07:00
Andrew Kelley
c3b0182f31 restore sonames by default when using zig cli
Before this commit, the branch regressed this case:

zig build-lib foo.zig -dynamic
readelf -d libfoo.so
 x000000000000000e (SONAME) Library soname: [libfoo.so]

Now it works again, but it preserves the property that using `zig cc`
has the SONAME off by default to match C compilers.
2020-11-27 17:49:55 -07:00
Jakub Konka
dd522c0c97 stage2 elf: fix glibc to always specify soname 2020-11-27 15:42:39 -07:00
Jakub Konka
375bab8460 stage2 elf: refactor override_soname to soname 2020-11-27 15:42:39 -07:00
Jakub Konka
12efefeba5 stage2 elf: make -soname an opt-in and not opt-out
As discussed with LemonBoy, it makes more sense to have the `-soname`
an opt-in option rather than opt-out, which is especially true if
we are to align `zig cc` with `cc` to a greater degree.
2020-11-27 15:42:39 -07:00
Andrew Kelley
9e4360c335 Merge pull request #7198 from LemonBoy/freebsd-lock
std: Fix file locking logic for BSD targets
2020-11-27 14:35:30 -08:00
LemonBoy
f91df39ad2 stage1: Fix crash in *[N]T to []T conversion with zst
Prevent the crash by not making the codegen try to access the
non-existing ptr field in the slice.

Closes #6951
2020-11-27 14:33:26 -08:00
Jakub Konka
3bc1c719bd Merge pull request #7231 from kubkon/stage2-arm-macos
stage2: Hello, Silicon!\n
2020-11-27 21:49:06 +01:00
Jakub Konka
5ed76268c9 stage2 macho: apply more review comments 2020-11-27 20:55:34 +01:00
Jakub Konka
02baaac506 Update src/codegen.zig
Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2020-11-27 20:31:26 +01:00
Koakuma
41c40f4bbe Fix fork() on Linux/sparc64
fork() on Linux/sparc64 seems to return its result in two registers,
with %o0 always holding the current process' PID, and the parent/child
status returned in %o1. Add some glue code to convert those into
the libc-style return value.
2020-11-27 23:02:22 +07:00
Koakuma
cf2ee4ae2c Add sparc64 long double mapping 2020-11-27 18:51:50 +07:00
g-w1
daf6c0da5b CONTRIBUTING: src-self-hosted -> src 2020-11-26 16:40:57 -08:00
Jakub Konka
ebb2f20815 stage2 macho: Dir.copyFile does the rename for us! 2020-11-26 21:12:20 +01:00
Jakub Konka
a8f8d82215 stage2 macho: use Dir.copyFile instead of manual create+copy 2020-11-26 20:21:53 +01:00
LemonBoy
21c488ce68 stage1: Force union member types to be resolved
No test case because I couldn't reduce the huuuge test case.
Fixes the problem discovered by @ifreund.
2020-11-26 10:49:47 -08:00
Jakub Konka
f125c4f5c7 stage2 macho: enable end-to-end incremental linking tests on aarch64 2020-11-26 11:50:09 +01:00
Jakub Konka
7e8f7da3ec stage2 macho: rename inodes to prevent SIGKILL 2020-11-26 11:50:09 +01:00
Jakub Konka
64eae8f392 stage2 macho: move PIE fixups to link file; fix tests 2020-11-26 11:50:09 +01:00
Jakub Konka
c749b78df5 stage2 macho: add orr and orn instructions 2020-11-26 11:50:09 +01:00
Jakub Konka
10942e3f86 stage2 macho: Hello, Silicon! 2020-11-26 11:50:09 +01:00
Jakub Konka
2cd84b1b3f stage2 macho: refactor PIE generation on x86_64 2020-11-26 11:50:09 +01:00
Jakub Konka
ef5132c508 stage2 macho: first, rough draft at trampolining 2020-11-26 11:50:09 +01:00
Jakub Konka
80b1041c21 stage2 macho: use RIP-relative for memory-set regs x86_64 2020-11-26 11:50:09 +01:00
Jakub Konka
59fe3d447d stage2 macho: make file structure compatible with codesign tool 2020-11-26 11:50:09 +01:00
Jakub Konka
e7db372864 stage2 macho: cleanup logs 2020-11-26 11:50:09 +01:00
Jakub Konka
cd79c6dda1 stage2 macho: fix issues with codesigning 2020-11-26 11:50:09 +01:00
Jakub Konka
a6e93da717 stage2 macho: generate a code sig (not valid yet) 2020-11-26 11:50:09 +01:00
Jakub Konka
9dcf7ee9c9 stage2 macho: add info about __TEXT segment 2020-11-26 11:50:09 +01:00
Jakub Konka
79381dc4fb stage2 macho: add empty CodeDirectory blob 2020-11-26 11:50:09 +01:00
Jakub Konka
d14cd59ef0 stage2 macho: move code signature logic into struct 2020-11-26 11:50:09 +01:00
Jakub Konka
3ac804628f stage2 macho: write out constants in CS 2020-11-26 11:50:09 +01:00
Jakub Konka
2bd963ad6a stage2 macho: don't pad out holes between sections 2020-11-26 11:50:09 +01:00
Jakub Konka
403dc50ff7 stage2 macho: preallocate empty code sig space 2020-11-26 11:50:09 +01:00
Jakub Konka
bbc4ee3f17 stage2 macho: refactor 2020-11-26 11:50:09 +01:00
Jakub Konka
a2e0e33249 stage2 macho: bring back incremental symbol commits 2020-11-26 11:50:09 +01:00
Jakub Konka
e1b65ff8d2 stage2 macho: cleanup minimum version command 2020-11-26 11:50:09 +01:00
Jakub Konka
be0d5571d2 stage2 macho: revert required alignment always at 4 2020-11-26 11:50:09 +01:00
Jakub Konka
e8dd62accd stage2 macho: fix incorrect rebase 2020-11-26 11:50:09 +01:00
Jakub Konka
2972f630a4 stage2 macho: start reverting some tweaks 2020-11-26 11:50:09 +01:00
Jakub Konka
4e3520a2f7 stage2 macho: make page size target cpu arch dependent 2020-11-26 11:50:09 +01:00
Jakub Konka
8450e6f156 stage2 macho: pages need to be 16kb aligned! 2020-11-26 11:50:09 +01:00
Jakub Konka
4a3d757f3e stage2 MachO: reduce size of __TEXT segment 2020-11-26 11:50:09 +01:00
Jakub Konka
7a407246ed stage2 MachO: remove discontinuities between segments 2020-11-26 11:50:09 +01:00
Jakub Konka
6ac7e99dad Write local symbols when flushing 2020-11-26 11:50:09 +01:00
Jakub Konka
b3fdfe5ca0 stage2 MachO: clean up segment protection flags 2020-11-26 11:50:09 +01:00
Jakub Konka
7dd5ce2527 stage2 macOS: make exe flagged as pie 2020-11-26 11:50:09 +01:00
Jakub Konka
1bec531cf2 stage2 MachO: add source version load cmd 2020-11-26 11:50:09 +01:00
Jakub Konka
72310db1da stage2 MachO: add min OS version load cmd 2020-11-26 11:50:09 +01:00
Isaac Freund
58365c4e79 std/os: fix prctl constants 2020-11-25 15:45:55 -08:00
Andrew Kelley
a06afa4579 Merge pull request #6411 from LemonBoy/fff
More std.fmt goodness
2020-11-25 15:43:19 -08:00
daurnimator
b7b3c1dfae std: use mem.asBytes in Ip4Address.parse so it works at comptime 2020-11-25 15:40:46 -08:00
Frank Denis
83abb32247 std/crypto - edwards25519 precomp: prefer doublings over adds
Doublings are a little bit faster than additions, so use them half
the time during precomputations.
2020-11-25 15:37:43 -08:00
LemonBoy
58c2bec589 stage1: Fix ICE when generating struct fields with padding
Make gen_const_ptr_struct_recursive aware of the possible presence of
some trailing padding by always bitcasting the pointer to its expected
type.

Not an elegant solution but makes LLVM happy and is consistent with how
the other callsites are handling this case.

Fixes #5398
2020-11-25 15:36:33 -08:00
Andrew Kelley
500fbdad57 update stack trace test with new start.zig line number 2020-11-25 00:40:50 -07:00
Andrew Kelley
479f259ea4 make start code more versatile
* always align the stack to 16. I saw an instance on x86_64 linux where
   it was needed.

 * detect at runtime if being interpreted by a dynamic loader and if so
   avoid clobbering the fs register.
2020-11-24 19:51:24 -07:00
LemonBoy
8ed7561422 std: Re-enable the use of O_EXLOCK/O_SHLOCK on macos 2020-11-24 10:23:54 +01:00
Jonathan Marler
a1fb10b766 fix for GCC 9.2: -Wno-maybe-uninitialized 2020-11-23 17:55:48 -08:00
Frank Denis
70c8cabb34 Update the minimum cmake version we require
Recent versions of cmake complain about it:

<<
  CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required):
  Compatibility with CMake < 2.8.12 will be removed from a future version of
  CMake.
>>

We don't require anything from version 2.8.5, and version 2.8.12 was
released in 2011, so it is very unlikely that anyone still uses 2.8.5.
2020-11-23 12:44:54 -08:00
LemonBoy
26d20e39fc std: Close dangling fd on error
This patch was already submitted for openFileZ, createFileZ was left
unpatched.
2020-11-23 18:00:05 +01:00
LemonBoy
0d4f05bb8a std: Remove O_NONBLOCK flag after locking
We only need O_NONBLOCK when O_SHLOCK/O_EXLOCK are used and we don't
want open() to block, don't let this bit leak to the user fd.
2020-11-23 18:00:05 +01:00
LemonBoy
f8ddc3d873 std: Fix file locking logic for BSD targets 2020-11-23 18:00:05 +01:00
Andrew Kelley
9d2fe1682f Merge pull request #7204 from LemonBoy/piecrash
Fix logic for detecting _DYNAMIC symbol
2020-11-23 08:55:34 -08:00
LemonBoy
3e22077d46 Fix the ELF base calculation
Find the effective ELF load address in dl_iterate_phdr by computing the
difference between the in-memory phdr and its p_vaddr specified in the
ELF file.

This makes the dl_iterate_phdr test pass and restores the stack traces.
2020-11-23 15:06:07 +01:00
LemonBoy
0a84f85945 Minor code cleanup in start_pie.zig
Thanks @daurnimator for catching this.
2020-11-23 12:36:40 +01:00
LemonBoy
bfa7e5c743 Update stack_traces test 2020-11-23 12:36:03 +01:00
LemonBoy
560043dadf Fix logic for detecting _DYNAMIC symbol
Prevent spurious crashes for non-PIE executables.
2020-11-23 12:00:12 +01:00
Andrew Kelley
c7170e4a54 Support PIE (Position Independent Executables)
Closes #4503
Revives #3960
Merges branch 'pie' into master
2020-11-22 17:30:34 -07: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
Andrew Kelley
55ab50efbd Merge branch 'piepiepie' of https://github.com/LemonBoy/zig into pie
Conflicts:
 lib/std/dynamic_library.zig (fixed in this commit)
 src/all_types.hpp
 src/codegen.cpp
 src/link.cpp
 src/main.cpp

Will manually apply the diffs to these deleted files to the new zig
code in a followup commit.
2020-11-22 12:39:44 -07:00
Vexu
98d5bfbd4d update grammar in langref 2020-11-22 21:30:09 +02:00
Aransentin
c8723beda8 UnregisterClassW needs WINAPI as well 2020-11-22 14:58:10 +00:00
Aransentin
6fd536a50c Fixed bugs, style suggestions 2020-11-22 14:51:32 +00:00
Jens Goldberg
bbc2c7c268 Ensure the dynamic function has the same type as the static one
Co-authored-by: daurnimator <quae@daurnimator.com>
2020-11-22 14:24:36 +00:00
Aransentin
fcf3f61c28 user32 cleanup, added wrappers and additional functions 2020-11-22 13:00:57 +00:00
Žiga Željko
2fbe9519ac std: add support for ppoll 2020-11-21 14:06:04 -08:00
LemonBoy
a2e9554699 std: Add test for meta.declarations on opaque{} 2020-11-21 14:03:49 -08:00
Andrew Kelley
7dcda5b0e8 Merge pull request #7182 from LemonBoy/externnnn
Initial implementation of @extern builtin
2020-11-21 09:41:49 -08:00
LemonBoy
ccdaf946b9 Rename back to extern, extend a stage1 parser hack
Make it recognize extern/export symbols prefixed by @ as a builtin
rather than stand-alone keywords.
2020-11-21 09:48:21 +01:00
Andrew Kelley
bf0cc32aa6 Merge pull request #7165 from LemonBoy/ppc64final
Make the PPC64 port usable
2020-11-20 17:40:17 -08:00
Isaac Freund
8cf319d206 std/os: define and use dev_t for linux x86_64 2020-11-20 17:35:52 -08:00
Sébastien Marie
87eb498d89 openbsd: malloc_usable_size is unavailable on OpenBSD 2020-11-20 17:31:29 -08:00
Isaac Freund
f473b3e87c std/os: add time_t definiton for x86_64 linux 2020-11-20 17:23:43 -08:00
LemonBoy
6029114f84 stage1: Resolve usingnamespace decls when calling @typeInfo
Closes #7176
2020-11-20 17:01:23 -08:00
LemonBoy
9b7d9c72b0 stage1: Initial implementation of @extern 2020-11-20 22:32:43 +01:00
LemonBoy
2193bbfd93 Skip f16 to f128 conversion test for ppc64
As for aarch64 we're waiting for LLVM to emit calls to the specific
builtins that implement this conversion.
2020-11-20 08:38:11 +01:00
LemonBoy
f2b4e6b2e7 Better coverage in @splat tests
Cover more common and uncommon cases.
2020-11-20 08:38:10 +01:00
LemonBoy
9c5eea9f40 stage2: Use correct ppc generic feature set 2020-11-20 08:38:10 +01:00
LemonBoy
e374ae3598 std: Use newfstatat on PPC64
One more variation in the syscall table, hooray!
2020-11-20 08:38:10 +01:00
LemonBoy
4e2a4e194b std: Use correct clone() stub
The previous clone() definition was written for 32bit PPC targets,
trying to execute it on a PPC64 machine lead to countless crashes.

Use the clone() definition kindly lifted from Musl libc.
2020-11-20 08:38:10 +01:00
LemonBoy
3da6b1218a std: Implement named arguments & runtime width/precision 2020-11-20 08:36:47 +01:00
LemonBoy
6b39167fdc std: Rewrite the fmt parser
Turn the FSM parser into a linear one so that's easier to implement new
features and/or more error checking without adding more and more states.
Functionally-speaking the two parsers are at feature parity.
2020-11-20 08:36:10 +01:00
Andrew Kelley
73be59433f Merge pull request #6928 from data-man/reduce_tests
Add more tests for reduce
2020-11-19 17:48:18 -08:00
Jakub Konka
c25cb39d17 Merge pull request #7160 from semarie/openbsd-getdents
openbsd: getdents could return invalid entry with d_fileno==0
2020-11-20 00:23:57 +01:00
Isaac Freund
a5691ee363 std.meta.declarations: support opaque {} 2020-11-19 15:04:38 -08:00
Andrew Kelley
473cb1fd74 Merge pull request #6390 from LemonBoy/reboot-3970
std.fmt meets UTF-8
2020-11-19 14:58:11 -08:00
LemonBoy
d526b0ffb0 std: Disable _only_ the flaky part of the ResetEvent test
The remaining part is working just fine as it's not time-dependent.
2020-11-19 15:46:20 -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
Andrew Kelley
647c6e0d09 tfw you can't even disable a test without getting the logic wrong 2020-11-19 13:28:54 -07:00
LemonBoy
60638f0c82 Nicer code for the error code path 2020-11-19 18:16:23 +01:00
Veikka Tuominen
cf819b95fe Merge pull request #6829 from tadeokondrak/error-unsupported-callconv
stage1: Compile error instead of falling back to C for unsupported cc
2020-11-19 19:03:08 +02:00
Tadeo Kondrak
25ec2dbc1e Add builtin.Signedness, use it instead of is_signed 2020-11-19 18:59:21 +02:00
Sébastien Marie
b174942e6a openbsd, netbsd: getdents: entry with d_fileno==0 should be skipped 2020-11-19 13:55:46 +00:00
Sébastien Marie
7579ce180f Iterator: rename freebsd_entry to bsd_entry to reflect that nextBsd is not freebsd only 2020-11-19 13:54:47 +00:00
Sébastien Marie
ad2ff9e65d darwin: getdents: entry with d_ino==0 should be skipped 2020-11-19 13:54:29 +00:00
Vexu
3a28b659bd add compile-error tests for unsupported calling convention 2020-11-19 14:25:46 +02:00
Tadeo Kondrak
51b362c350 stage1: Check calling convention correctly for subsystem detection 2020-11-19 14:18:35 +02:00
Tadeo Kondrak
c002a5026a Update code to not use unsupported calling conventions for target 2020-11-19 14:01:07 +02:00
Tadeo Kondrak
6b9dc82fa5 stage1: Compile error instead of falling back to C for unsupported cc 2020-11-19 13:59:11 +02:00
LemonBoy
2b7781d82a stage1: Fix undefined assignment for bitfields
Prevents silent memory corruption.

Closes #7055
2020-11-18 21:49:39 -08:00
Andrew Kelley
13cccdd92c add std.heap.raw_c_allocator
This API does what `std.heap.c_allocator` previously did. See the new
doc comments for more details.
2020-11-18 22:09:34 -07:00
Andrew Kelley
02a4e5a4bf Merge pull request #6385 from LemonBoy/callocator
std: Make C allocator respect the required alignment
2020-11-18 20:16:57 -08:00
breakin
6d3c176c12 Change seed for Murmur2_64 from u32 to u64 2020-11-18 17:05:38 -08:00
Veikka Tuominen
2418c8206a Merge pull request #7154 from daurnimator/std.atomic
std.atomic.{Int,Bool}
2020-11-18 21:48:17 +02:00
pfg
cf7de64f1a stage1: improve error for missing a number type on a runtime var 2020-11-18 21:45:51 +02:00
Jakub Konka
663e112773 std: add chdir smoke test 2020-11-18 15:37:44 +01:00
Lee Cannon
64feae3ac3 Move utf8->utf16 up one level into os.zig 2020-11-18 15:37:44 +01:00
Lee Cannon
dbbe709dc7 use else in err switch 2020-11-18 15:37:44 +01:00
Lee Cannon
32c998e03c Switch to RtlSetCurrentDirectory_U 2020-11-18 15:37:44 +01:00
Lee Cannon
80b1e82b1b Implement chdir and chdirZ for Windows 2020-11-18 15:37:44 +01:00
Veikka Tuominen
a6470088c6 Merge pull request #6434 from daurnimator/fifo.pump
std: add LinearFifo(...).pump(src_reader, dest_writer)
2020-11-18 16:35:13 +02:00
Veikka Tuominen
ee1d21bbef Merge pull request #6649 from Rocknest/verparse
make Version.parse less strict
2020-11-18 16:06:52 +02:00
daurnimator
767dd772c0 std: add std.atomic.Bool 2020-11-19 00:58:13 +11:00
daurnimator
d89d6374be std: add tests for std.atomic.Int 2020-11-19 00:57:54 +11:00
daurnimator
8fa29bc0a2 std: fix missing operation argument to @atomicRmw 2020-11-19 00:57:35 +11:00
daurnimator
eb4d93ece3 std: some more docs for std.atomic.Int 2020-11-19 00:44:38 +11:00
daurnimator
513e8161dd std: mark std.atomic.Int as extern so it can be used in public ABIs 2020-11-19 00:41:43 +11:00
daurnimator
c492ef97fd std: expose all atomic operations from std.atomic.Int 2020-11-18 15:36:40 +02:00
Vexu
da84ef2a9c make help in commands more consistent
Closes #7101

Co-authored-by: pfg <pfg@pfg.pw>
2020-11-18 13:58:27 +02:00
frmdstryr
a39d3155b4 Change error when runtime value passed to comptime arg 2020-11-18 13:33:45 +02:00
LemonBoy
129ccad434 stage1: Reject undefined values when taking union ptr
The code rightfully assumes the union_val object to be fully initialized.

Closes #7019
2020-11-18 13:21:36 +02:00
Alexandros Naskos
252924ae33 Added std.meta.fieldNames 2020-11-18 13:16:56 +02:00
Veikka Tuominen
6d5b76a75d Merge pull request #7005 from jshholland/deprecate-span
Remove ArrayList.span
2020-11-18 13:14:48 +02:00
Timon Kruiper
66d6930b5c Allow Zig to be built with clang 11 and -Werror
This was brought to the horizon when using zig-bootstrap to cross compile
Zig for windows-gnu.
2020-11-18 13:09:44 +02:00
LemonBoy
bef140c0a2 stage1: Add architecture-specific clobbers to asm()
We're basically following Clang's lead, add the necessary clobbers to
minimize the risk of generating wrong code.
2020-11-18 13:08:04 +02:00
Veikka Tuominen
1e1a490600 Merge pull request #7084 from xackus/mem-volatile
std.mem: make sliceAsBytes, etc. respect volatile
2020-11-18 13:06:35 +02:00
xackus
27b73cc395 std: make meta.IntType a compile error
the function signature changed
also update langref
2020-11-18 12:57:49 +02:00
Jakub Konka
39336fd2e9 stage2 aarch64: assert register is 64bits in PCrel
Thanks @joachimschmidt557 for pointing out this fix!
2020-11-18 10:12:39 +01:00
Jakub Konka
5ff8dd179e stage2 aarch64: add PC relative address instructions 2020-11-18 08:46:52 +01:00
g-w1
a0226ab05b std: openDirAbsolute and accessAbsolute (#7082)
* add more abosolutes

* added wrong files

* adding 2 tests and changing the function signatures because of lazy analysis not checking them

* fix a bug that got uncovered by lazy eval

* Add compile error when using WASI with openDirAbsolute and accessAbsolute

* typo
2020-11-18 08:42:35 +01:00
Andrew Kelley
238718b93a disable the flaky ResetEvent test
See #7009
2020-11-17 18:08:10 -07:00
Frank Denis
9c2b014ea8 std/crypto: use NAF for multi-scalar edwards25519 multiplication
Transforming scalars to non-adjacent form shrinks the number of
precomputations down to 8, while still processing 4 bits at a time.

However, real-world benchmarks show that the transform is only
really useful with large precomputation tables and for batch
signature verification. So, do it for batch verification only.
2020-11-17 17:07:32 -08:00
Frank Denis
0d9c474ecf std/crypto: implement the Hash-To-Curve standard for Edwards25519
https://github.com/cfrg/draft-irtf-cfrg-hash-to-curve

This is quite an important feature to have since many other standards
being worked on depend on this operation.

Brings a couple useful arithmetic operations on field elements by the way.

This PR also adds comments to the functions we expose in 25519/field
so that they can appear in the generated documentation.
2020-11-17 17:06:38 -08:00
LemonBoy
fa27420b72 stage1: Fix asyncCall with non-abi-aligned arguments
Make the code used to calculate the variable slot index into the frame
match what's done during the structure layout calculation.

Prevents a few nasty LLVM errors when such types are passed around.
2020-11-17 15:55:12 -08:00
Andrew Kelley
af4727814b cli: make -h, --help consistent in usage text and parsing
also trivial fixes in the general usage text
2020-11-17 16:53:45 -07:00
Felix (xq) Queißner
b3af2f68b3 Changes behaviour from std.fs.path.extension from returning null to returning "". 2020-11-18 00:03:34 +01:00
Vexu
bace1181b2 stage2: handle opaque containers 2020-11-18 00:52:56 +02:00
Andrew Kelley
2eee0582f8 macOS libc headers: downgrade to 10.15.7 (Catalina)
See ziglang/fetch-them-macos-headers#2 for more details. The path
forward looks like one of the following:

 * Ony provide headers for the oldest supported macOS (currently 10.13
   but soon to be bumped to 10.14).
 * Provide headers for multiple versions, and select based on the Zig
   target OS version range minimum.
 * Don't try to provide macOS headers.

If we don't tackle the version problem, we would have to re-introduce
the ability to detect and depend on native system headers if we wanted
to support C/C++ code that used newer OS definitions.

This patch also adds support for `#include <mach/mach_time.h>`.

Also related: #5236
2020-11-17 11:40:24 -08:00
Vexu
c1e19f4c0a stage2: initial container astgen 2020-11-17 21:19:49 +02:00
Alexandros Naskos
21a77f7ac3 Merge pull request #7032 from GuoxinYin/master
Add -h alias for --help
2020-11-17 15:52:39 +02:00
data-man
86b86bef23 Added links to the relevant issue 2020-11-17 14:41:05 +05:00
Andrew Kelley
e6bfa377d1 std.crypto.isap: fix callsites of secureZero 2020-11-16 18:10:41 -07:00
Andrew Kelley
8b3c1ed734 Merge branch 'johnLate-issue-6724-cmake' into master
closes #7078
closes #6724
2020-11-16 18:03:06 -07:00
Andrew Kelley
3348cb915f cmake: add the correct set of zig stage2 sources 2020-11-16 17:57:22 -07:00
johnLate
77d67aa662 CMake: try to avoid compilation for install target
This is andrewrk's patch from ziglang#6724 (rebased)

CMake: Fix dependency problem

I don't know whether the error was expected cmake behavior or a bug.
This change seems to fix the issue. See ziglang#6724 for details.
2020-11-16 17:45:13 -07:00
Frank Denis
f9d209787b std/crypto: add ISAPv2 (ISAP-A-128a) AEAD
We currently have ciphers optimized for performance, for
compatibility, for size and for specific CPUs.

However we lack a class of ciphers that is becoming increasingly
important, as Zig is being used for embedded systems, but also as
hardware-level side channels keep being found on (Intel) CPUs.

Here is ISAPv2, a construction specifically designed for resilience
against leakage and fault attacks.

ISAPv2 is obviously not optimized for performance, but can be an
option for highly sensitive data, when the runtime environment cannot
be trusted.
2020-11-16 16:02:19 -08:00
Jonathan Marler
4df75645ce start.zig: call wWinMain with root's type
I have an alternative set of windows bindings I'm working on: https://github.com/marler8997/zig-os-windows.  So I'm declaring my wWinMain function with my own HINSTANCE type rather than the one from std.os.windows.  This change allows start to call wWinMain using any pointer type.
2020-11-16 16:01:18 -08:00
tgschultz
48d60834fd Move leb128 and remove trivial *mem functions as discussed in #5588 (#6876)
* Move leb128 out of debug and remove trivial *mem functions as discussed in #5588

* Turns out one of the *Mem functions was used by MachO. Replaced with trivial use of FixedBufferStream.
2020-11-16 18:51:54 -05:00
Andrew Kelley
d9c36cb250 Merge pull request #6878 from frmdstryr/multiline-string-comments
Support comments in multiline string literals
2020-11-16 14:05:15 -08:00
heidezomp
9ea4ddae97 linuxWaitFd: make NetworkSubsystemFailed error unreachable
This error from os.poll is Windows-specific, so unreachable on Linux.
2020-11-16 14:03:19 -08:00
Alex Cameron
a2582df5b2 Prevent double file close in MachO linking 2020-11-16 13:59:27 -08:00
Frank Denis
0c520cd32d Enable loop interleaving when unrolling is enabled
This mimics clang's default behavior.
2020-11-16 13:40:52 -08:00
Andrew Kelley
ba967ae9a1 Merge pull request #7002 from jedisct1/timingSafeEqlMinimal
Add mem.timingSafeEql() for constant-time array comparison
2020-11-16 13:39:31 -08:00
Jakub Konka
8f47e8feb6 stage2 aarch64: add NOP instruction 2020-11-16 13:37:38 -08:00
Jakub Konka
cd4b54fd38 libstd: add more MachO consts and structs 2020-11-16 13:37:07 -08:00
LemonBoy
36c869dc14 std: Make windows.ReadFile allow short reads
Make it behave like the read() wrapper for unix systems.
Reading the whole buffer breaks some use-cases like buffered readers
over sockets.

Closes #7121
2020-11-16 13:35:06 -08:00
xackus
109a3ebcca std.mem: make args comptime, fix test names 2020-11-16 12:50:05 +01:00
Alexandros Naskos
6e2e747b0b Merge pull request #7112 from LemonBoy/fix-7104
stage1: Fix generation of pass-by-value args in async fns
2020-11-16 09:12:42 +02:00
Vexu
f173d078c7 stage2: outline container types 2020-11-15 13:03:48 +02:00
Frank Denis
7b9af0592d Azure Pipelines CI: update msys2 to the current version 2020-11-15 00:27:18 +01:00
LemonBoy
7ebbc717c0 stage1: Fix generation of pass-by-value args in async fns
The mismatch between the argument slot type in the frame structure and
the one used in the store operation made the generated code write
garbage over the nearby fields.

Fixes #7104
2020-11-14 15:30:06 +01:00
xackus
92e45ee3a1 std.mem: make sliceAsBytes, etc. respect volatile 2020-11-14 13:59:29 +01:00
xackus
c814fdbfaf std.mem: improve doc comments 2020-11-14 13:59:29 +01:00
Felix (xq) Queißner
0bbf170514 Adapts to @andrewrk​s comment to include dot. 2020-11-14 11:01:47 +01:00
Andrew Kelley
bf03ae7acc std.fs.path.dirname: return null when input path is root
This intentionally diverges from the unix dirname command, as well as
Python and Node.js standard libraries, which all have this edge case
return the input path, unmodified. This is a footgun, and nobody should
have ever done it this way.

Even the man page contradicts the behavior. It says:
"strip last component from file name". Now consider, if you
remove the last item from an array of length 1, then you
have now an array of length 0. After you strip the last component, there
should be no components remaining. Clearly, returning the input parameter
unmodified in this case does not match the documented behavior. This is
my justification for taking a stand on this API design.

closes #6746
closes #6727
closes #6584
closes #6592
closes #6602
2020-11-13 17:36:49 -07:00
LemonBoy
211feea914 stage1: Disambiguate Wasm imports with same name
Closes #7088
2020-11-13 16:32:42 -05:00
LemonBoy
c4fd3fc270 stage1: Resolve ErrorUnion children types
Since the code is accessing the abi_size field compute the full type
size for both err_set_type and payload_type, not only for the latter.
2020-11-13 14:28:40 -07:00
Sébastien Marie
ab4b34f75f openbsd: skip tests using Dir.realpath 2020-11-13 12:30:14 -05:00
LemonBoy
b52a28a802 stage1: Ask LLVM to produce compact code in ReleaseSize mode
Let's follow what Clang does for -Oz and apply the `minsize` and
`optsize` attributes by default.

Closes #7048
Supersedes #7077
2020-11-13 12:25:13 -05:00
Vexu
643f526cd1 stage2: add zir instructions for creating container types 2020-11-13 17:32:52 +02:00
Felix (xq) Queißner
2ced0316eb Makes @haze happy. 2020-11-13 13:54:41 +01:00
Felix (xq) Queißner
f51064f79e Respects leading . and ignores it. 2020-11-13 12:48:01 +01:00
Felix (xq) Queißner
2554273805 Implements std.fs.path.extension. 2020-11-13 11:53:51 +01:00
Jakub Konka
51717314e4 Merge pull request #6900 from joachimschmidt557/stage2-aarch64
Add stage2 AArch64 backend
2020-11-12 20:41:15 +01:00
joachimschmidt557
c6d46a9b82 stage2 ARM & AArch64: ensure correct function alignment 2020-11-12 16:24:51 +01:00
Andrew Kelley
2d42532fec main: clean up the error message for missing positional args 2020-11-11 19:35:07 -07:00
joachimschmidt557
b17859b568 stage2 AArch64: add Linux Hello World test 2020-11-11 23:29:18 +01:00
Hubert Jasudowicz
bf73db71f5 std: Fix code model argument 2020-11-11 21:28:10 +02:00
Veikka Tuominen
93844a5ef9 Merge pull request #7061 from Vexu/std
std: fix HashMap.putAssumeCapacity
2020-11-11 18:50:34 +02:00
Jakub Konka
5b92d0ea45 stage2 aarch64: add macOS incremental test 2020-11-11 15:36:47 +01:00
Vexu
08270d72b4 ensure TypeInfo payload is not undefined 2020-11-11 16:04:46 +02:00
g-w1
61c51f0ac9 Add error for missing positional arguments in zig build-*
Closes #6938
2020-11-11 15:54:08 +02:00
LemonBoy
5872ae5111 stage1: Fix crash in comptime struct generation
Using the gen_index rather than the src_index is needed to handle
structures containing zero-sized or comptime only types.

Closes #7027
2020-11-11 15:35:19 +02:00
Jakub Konka
a6bc19ea2a stage2 aarch64: add genCall for aarch64 MachO 2020-11-11 14:34:53 +01:00
Jakub Konka
993eb22a77 stage2 aarch64: add .memory prong in genSetReg 2020-11-11 14:34:53 +01:00
Jakub Konka
f512676d0b stage2 aarch64: add str instruction 2020-11-11 14:34:53 +01:00
Jakub Konka
f1960302d1 stage2 aarch64: add ldr instruction + smoke tests 2020-11-11 14:34:53 +01:00
joachimschmidt557
ca0016a225 stage2 ARM: start implementing genCall for ELF + genSetReg immediates 2020-11-11 14:34:53 +01:00
joachimschmidt557
aa9df72f71 stage2 AArch64: MoveWideImmediate instructions + test coverage 2020-11-11 14:34:53 +01:00
joachimschmidt557
4c8f69241a stage2 aarch64: add more instructions 2020-11-11 14:34:53 +01:00
joachimschmidt557
3c75d723ac stage2 aarch64: add codegen/aarch64.zig 2020-11-11 14:34:53 +01:00
Jakub Konka
4ef6864a15 Add move wide with zero (movz) instruction 2020-11-11 14:34:53 +01:00
Jakub Konka
d601b0f4eb Add basic genSetReg for aarch64 2020-11-11 14:34:53 +01:00
Jakub Konka
68bb1e91aa Add testcase for serializing svc #0x80 2020-11-11 14:34:53 +01:00
Jakub Konka
d542e88706 Implement genAsm on aarch64
Add remaining PCS info: param and return registers in procedure calls.
2020-11-11 14:34:53 +01:00
joachimschmidt557
5ad501c00b stage2 aarch64: add codegen/aarch64.zig 2020-11-11 14:34:53 +01:00
Jonas Carpay
c9dc30daf7 Fix backticked code in langref 2020-11-11 15:34:01 +02:00
Vexu
ae6f3291c0 std: fix HashMap.clearRetainingCapacity 2020-11-11 14:05:43 +02:00
Vexu
f70160f89c std: fix HashMap.putAssumeCapacity 2020-11-11 13:57:08 +02:00
LemonBoy
f0b1b74d21 stage1: Avoid resolving type entry in [0]T
The logic was already there but this rule was only applied in some
places, apply it in the remaining code paths.

Closes #7058
2020-11-11 13:53:24 +02:00
Andrew Kelley
8b9195282e Merge pull request #7044 from semarie/openbsd-simples
Simple sets of commits for OpenBSD support
2020-11-10 18:06:30 -05:00
Andrew Kelley
6904cd828e add missing -m<os>-version-min CLI args to clang
This fixes some code generation issues when targeting macOS and
compiling C/C++ code.
2020-11-10 15:24:10 -07:00
Andrew Kelley
3110b21c4b std.Target: bump default version max for macos 2020-11-10 15:24:10 -07:00
LemonBoy
4d4ab1e69a stage1: Fix comparison of unions containing zero-sized types
The code tried to be too smart and skipped the equality (returning true)
if the payload type was zero-sized.
This optimization is completely wrong when the union payload is a
metatype!

Fixes #7047
2020-11-10 17:21:49 -05:00
Sébastien Marie
678bd4fc89 "ResetEvent" test seems to have a too short timeout: the test is failing randomly on OpenBSD
raise the timeout to 100ms to be sure that if it fails (timeout is returned) it is due to a real problem.
the test shouldn't be longer: it will wait more time only on failure.
2020-11-10 05:29:53 +00:00
Sébastien Marie
9d306e5c77 openbsd: mutex or cond destroy function could return EINVAL 2020-11-10 05:26:35 +00:00
Sébastien Marie
8784c7b581 openbsd: proper implementation for Thread.cpuCount() 2020-11-10 05:25:59 +00:00
Sébastien Marie
20b19d0092 openbsd: add time definitions for gettimeofday() 2020-11-10 05:24:56 +00:00
Sébastien Marie
e4bc595bc6 openbsd: add sockets constants 2020-11-10 05:24:03 +00:00
Sébastien Marie
17276df488 openbsd: add dlfcn.h definitions for dlopen() 2020-11-10 05:23:13 +00:00
Andrew Kelley
06a3a69e6f main: updateModule returns an error when there are any compile errors
closes #6976
2020-11-09 20:51:09 -07:00
daurnimator
73f3f01670 Fix json parser close tracking (#6865)
* std: fix json parsing with unmatched closing tokens

* std: fix swapped json parsing errors
2020-11-09 18:29:02 -05:00
xackus
15dbab9a0c std: json: fix misleading endianness conversion 2020-11-09 18:27:07 -05:00
LemonBoy
e00356d6b1 stage1: Print correct error message for vector @intCast 2020-11-09 18:24:48 -05:00
Frank Denis
427a212e38 Don't prevent compilation on platforms where debug info is unsupported
We don't support debug information on platforms that are not tier-1,
but it shouldn't be a hard error that completely prevents compilation.
2020-11-09 18:22:50 -05:00
Alexandros Naskos
fc67e5f843 Windows TLS startup symbols are already provided by libcrt when linking against libc 2020-11-09 17:46:46 -05:00
Jakub Konka
0bc9fd5e8e Merge pull request #7035 from ziglang/macos-posix-headers
macOS libc headers: add POSIX headers
2020-11-09 23:41:55 +01:00
Andrew Kelley
83a1523b1a std.ResetEvent: disable flaky test on Windows
See #7009
2020-11-09 15:33:40 -07:00
Jakub Konka
db2ac8ae49 macOS libc headers: add objc/message.h and runtime.h 2020-11-09 19:57:07 +01:00
Jakub Konka
09cc61bfe4 Add more missing libc headers used by frameworks
See
76f22c3905.
2020-11-09 18:47:09 +01:00
Jakub Konka
267116d626 macOS libc headers: add mach/clock.h
LLVM depends on it.
2020-11-09 15:02:03 +01:00
data-man
99932042dc Fix reduce documentation 2020-11-09 11:47:43 +01:00
Andrew Kelley
9af53f8e02 langref: add 0.7.0 link 2020-11-09 00:37:35 -07:00
Andrew Kelley
e78e0f57be macos: avoid --export-dynamic when using system linker 2020-11-08 23:04:38 -08:00
Andrew Kelley
b0cbd0ad2d macos libc headers: add more
these new files are generated by recursively including:

sysexits.h
mach/mach.h
sys/attr.h
sys/mount.h
crt_externs.h
execinfo.h

all of which are depended on by LLVM libraries.
2020-11-08 21:12:18 -08:00
Andrew Kelley
cd221b9df9 macOS libc headers: add sys/sysctl.h
libcxx depends on it
2020-11-08 20:26:33 -08:00
Andrew Kelley
16b7be34a1 macOS libc headers: add sys/param.h
libcxx depends on it
2020-11-08 20:21:29 -08:00
Andrew Kelley
1213e26ba8 macOS libc headers: add mach-o/dyld.h
libcxx depends on it
2020-11-08 20:21:29 -08:00
Andrew Kelley
25e78bd007 add copyfile.h
libcxx depends on it
2020-11-08 20:21:29 -08:00
Andrew Kelley
fdd775b3bf macOS libc headers: add xlocale.h and Block.h
These are both included by libcxx.
2020-11-08 20:21:29 -08:00
Andrew Kelley
eed5814d75 macOS libc headers: add POSIX headers 2020-11-08 20:21:29 -08:00
Andrew Kelley
4d67c3d887 macOS: depend on bundled headers even for native
This is an alternate fix for #6773. Reverts
872bc787b5.
2020-11-08 18:51:12 -07:00
Alexandros Naskos
4236518e3a Merge pull request #7033 from jedisct1/bump0.7
Bump Zig version to 0.7.0
2020-11-09 00:52:51 +02:00
Frank Denis
9bc3442e41 Bump Zig version to 0.7.0 2020-11-08 23:50:44 +01:00
Andrew Kelley
0c90ccc297 Release 0.7.0 2020-11-08 12:02:09 -07:00
Guoxin Yin
7b8cb002cb fix issue 6798 2020-11-09 02:58:45 +08:00
Guoxin Yin
b6c85df55a fix issue 6798 2020-11-09 02:48:17 +08:00
Frank Denis
7f9e3e419c Use @reduce 2020-11-07 20:30:13 +01:00
Frank Denis
bd07154242 Add mem.timingSafeEql() for constant-time array comparison
This is a trivial implementation that just does a or[xor] loop.

However, this pattern is used by virtually all crypto libraries and
in practice, even without assembly barriers, LLVM never turns it into
code with conditional jumps, even if one of the parameters is constant.

This has been verified to still be the case with LLVM 11.0.0.
2020-11-07 20:18:43 +01:00
joachimschmidt557
03ae77b8b0 stage2 ARM: miscellaneous improvements 2020-11-07 17:27:23 +01:00
Josh Holland
a1ec5448c7 make ArrayList.span into a compile error 2020-11-07 11:15:47 +00:00
Josh Holland
c25b157dda remove deprecated uses of ArrayList.span 2020-11-07 11:15:44 +00:00
Alexandros Naskos
5430642fa0 Merge pull request #7008 from xackus/minor-fixes
change debug.assert to testing.expect in tests
2020-11-07 11:34:51 +02:00
Andrew Kelley
67ea47babd Revert "update runtime safety test case - unsigned-signed vector cast"
This reverts commit 663f0b399c.

The behavior appears to be inconsistent between running locally and on
the CI.

I suspect it could be based on what vector CPU features are available.
2020-11-06 18:58:10 -07:00
Andrew Kelley
663f0b399c update runtime safety test case - unsigned-signed vector cast
now it returns "integer cast truncated bits" instead of "attempt to cast
negative value to unsigned integer" which I think is correct.
2020-11-06 17:15:05 -07:00
Andrew Kelley
ceaa569bfa disable flaky file locking test on Windows
See #7010
2020-11-06 17:00:51 -07:00
Andrew Kelley
c923f74fc9 std.ResetEvent: disable flaky test on macOS
See #7009
2020-11-06 16:46:30 -07:00
xackus
c9fa57541b remove outdated comment 2020-11-06 22:58:58 +01:00
xackus
5c8f7f81cd change debug.assert to testing.expect in tests 2020-11-06 22:48:54 +01:00
Andrew Kelley
e5fab3ba68 update musl sources to 1.2.1 2020-11-06 14:13:57 -07:00
Andrew Kelley
dba94f453a update musl headers to 1.2.1 2020-11-06 13:53:47 -07:00
Andrew Kelley
008dd90f1f update process_headers tool 2020-11-06 13:51:33 -07:00
Jay Petacat
030f00391a std: Introduce SemanticVersion data structure
This will parse, format, and compare version strings following the
SemVer 2 specification. See: https://semver.org

Updates #6466
2020-11-06 15:07:48 -05:00
Andrew Kelley
d1b1f053b0 Merge pull request #6941 from LemonBoy/floateqapprox
std: Implement more useful approxEq semantics
2020-11-06 14:09:31 -05:00
LemonBoy
b9391c9564 std: Make file locking tests less fragile 2020-11-06 14:02:11 -05:00
Jeremy Huffman
9f1639a6bb Fix std.ResetEvent.timedWait on darwin/macOS. (#6914) 2020-11-06 14:01:52 -05:00
Andrew Kelley
a9e09a8be4 Merge pull request #6990 from kubkon/system-linker-hack
Re-enable system linker hack
2020-11-06 13:22:03 -05:00
Alexandros Naskos
a1a16a941e Merge pull request #7001 from Vexu/translate-c
Translate-c: fix macro functions with no arguments
2020-11-06 19:22:56 +02:00
Jakub Konka
ab69b89d52 Address review comments 2020-11-06 11:57:53 +01:00
Vexu
79549e0ac1 translate-c: fix macro functions with no arguments 2020-11-06 12:48:52 +02:00
Jakub Konka
b7c3ebcb9e Rely on ZIG_SYSTEM_LINKER_HACK instead of input flags 2020-11-06 11:34:51 +01:00
Andrew Kelley
c9551652b0 Merge pull request #6978 from LemonBoy/statshit
Decouple kernel and libc stat definitions
2020-11-05 17:27:22 -05:00
Andrew Kelley
cf7505da1f Merge pull request #6974 from daurnimator/prctl-cleanup
prctl improvements
2020-11-05 17:25:24 -05:00
LemonBoy
78840c4ab2 stage1: Make sure union(enum(T)) is valid
The T type should be wide enough to fit values in the  0...num field
range.

Closes #6988
2020-11-05 17:24:04 -05:00
Andrew Kelley
f85d719952 Merge pull request #6895 from jorangreef/fallocate
linux: add fallocate()
2020-11-05 17:23:00 -05:00
Frank Denis
e7b60b219b std/crypto: don't constrain Gimli hash output to a fixed length
As documented in the comment right above the finalization function,
Gimli can be used as a XOF, i.e. the output doesn't have a fixed
length.

So, allow it to be used that way, just like BLAKE3.
2020-11-05 17:21:19 -05:00
Frank Denis
2e354c387e math.shl/math.shr: add support for vectors 2020-11-05 17:20:54 -05:00
Frank Denis
73aef46f7d std.crypto: namespace constructions a bit more
With the simple rule that whenever we have or will have 2 similar
functions, they should be in their own namespace.

Some of these new namespaces currently contain a single function.

This is to prepare for reduced-round versions that are likely to
be added later.
2020-11-05 17:20:25 -05:00
Frank Denis
4417206230 Now that they support vectors, use math.rot{l,r} 2020-11-05 17:19:48 -05:00
Andrew Kelley
34502b9c4d Merge pull request #6991 from alexnask/upgrade_mingw-w64
Upgrade mingw-w64 to version 8.0.0
2020-11-05 17:18:01 -05:00
Alexandros Naskos
3e1639c53b Fixed mingw-w64 8.0.0 compilation
Reaplied mingw-w64 header patch
2020-11-05 20:04:25 +02:00
Jakub Konka
e0e3ceac19 Re-enable system linker hack
It is now possible to force linking with system linker `ld` instead
of the LLVM `lld` linker when building natively on the target. This
can be done at each stage by specifying `--system-linker-hack` flag,
and can be useful on platforms where `lld` fails to operate properly
such as macOS 11 Big Sur on ARM64 where every binary/dylib is expected
to be codesigned.

Some example invocations for each stage of compilation of Zig
toolchain:

```
cmake .. -DCMAKE_PREFIX_PATH=/path/to/llvm -DSYSTEM_LINKER_HACK=1
```

```
build/zig build test --system-linker-hack
```

```
build/zig build --prefix $(pwd)/stage2 -Denable-llvm
--system-linker-hack
```

```
build/zig build-exe hello.zig --system-linker-hack
```
2020-11-05 18:35:51 +01:00
Alexandros Naskos
708962d51e Updated mingw-w64 to version 8.0.0 2020-11-05 18:59:36 +02:00
LemonBoy
53c1624074 std: Make utf8CountCodepoints much faster
Make the code easier for the optimizer to work with and introduce a fast
path for ASCII sequences.

Introduce a benchmark harness to start tracking the performance of ops
on utf8.
2020-11-05 16:10:34 +01:00
LemonBoy
3a1f515e09 Address review comments 2020-11-05 16:10:34 +01:00
LemonBoy
1982e0c18a Fix typo in documentation 2020-11-05 16:10:34 +01:00
LemonBoy
0316ac959c Make std.formatBuf UTF-8 aware 2020-11-05 16:10:34 +01:00
LemonBoy
675de8d6b7 Clean up the unicode codepoint formatter a bit 2020-11-05 16:10:34 +01:00
LemonBoy
44533f10fe std: Introduce std.unicode.utf8ValidCodepoint 2020-11-05 16:10:34 +01:00
LemonBoy
6c4efab106 std: Introduce std.unicode.utf8CountCodepoints 2020-11-05 16:10:33 +01:00
LemonBoy
2cce23062b Update the API and add add error-recovery path 2020-11-05 16:10:33 +01:00
data-man
678ecc94ca Add 'u' specifier to std.format 2020-11-05 16:10:33 +01:00
LemonBoy
e749ab1d63 Fix typo, remove debug leftover, rename few fns 2020-11-05 16:10:15 +01:00
LemonBoy
53433cdea2 Implement a fallback mechanism for posix_memalign
Do the alignment dance by ourselves whenever posix_memalign is not
available.
Don't try to use malloc as it has too many edge cases, figuring out
whether a block of memory is manually aligned by the mechanism above or
is directly coming from malloc becomes too hard to be valuable.
2020-11-05 16:10:15 +01:00
LemonBoy
4664eae1e4 stage1: Fix type mapping for c_longdouble
A quick and dirty job to let the compiler use the correct size and
alignment.
2020-11-05 16:10:15 +01:00
LemonBoy
806097c165 std: Make C allocator respect the required alignment
Use posix_memalign where available and the _aligned_{malloc,free} API on
Windows.

Closes #3783
2020-11-05 16:10:15 +01:00
LemonBoy
ff14451b4a std: Implement more useful approxEq semantics
Comparisons with absolute epsilons are usually useful when comparing
numbers to zero, for non-zero numbers it's advised to switch to relative
epsilons instead to obtain meaningful results (check [1] for more
details).

The new API introduces approxEqAbs and approxEqRel, where the former
aliases and deprecated the old `approxEq`, allowing the user to pick the
right tool for the job.

The documentation is meant to guide the user in the choice of the
correct alternative.

[1] https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
2020-11-05 16:08:49 +01:00
LemonBoy
cca6b11138 Label WASI stat as kernel_stat
We're using WASI syscalls, it makes sense to put the kernel_ prefix.
2020-11-05 12:44:43 +01:00
LemonBoy
0e95fa455c std: Split kernel&libc definitions of stat struct
There's no guarantee for the kernel definition to be ABI compatible with
the libc one (and vice versa).
There's also no guarantee of ABI compatibility between musl/glibc.

Fun, isn't it?
2020-11-05 09:38:50 +01:00
Alexandros Naskos
17837affd2 Merge pull request #6982 from Rageoholic/master
Fix CoInitializeEx so it can take a null pointer
2020-11-05 09:00:03 +02:00
rageoholic
e5100605e9 Add missing LONG_PTR type 2020-11-04 18:30:48 -06:00
rageoholic
04267fb1ba Fix CoInitializeEx so it can take a null pointer 2020-11-04 16:53:05 -06:00
Frank Denis
bb14bd35bd Update wasmtime to version 0.20
The version we were using in CI is now getting quite old, and we
want to make sure that the code we produce is compatible with
current versions of Wasmtime.
2020-11-04 20:28:54 +01:00
LemonBoy
346a686b9d std: Correct stack_t definition for mips 2020-11-04 15:55:06 +01:00
LemonBoy
f313c88428 std: Fix pipe syscall stub for sparc64 2020-11-04 15:54:38 +01:00
data-man
df4fd94525 remove f128 tests, disable min/max for NaNs 2020-11-04 17:42:57 +05:00
daurnimator
b42ffbe9e8 std: use PR enum as only location of opcode numbers 2020-11-04 22:39:35 +11:00
daurnimator
b90fb1e96b std: add PR enum for the prctl opcode 2020-11-04 22:32:57 +11:00
daurnimator
02252f3f07 std: workaround #280 in prctl 2020-11-04 22:23:59 +11:00
Frank Denis
342ba960f7 sparc64 has a 8Kb page size 2020-11-03 17:29:20 -05:00
Andrew Kelley
ede41759be std.fs.File.writeFileAll: support unseekable files
With this commit, the function tries to use more efficient syscalls, and
then falls back to non-positional reads.

The motivating use case for this change is to support something like the
following:

try io.getStdOut().writeFileAll(dest_file, .{});
2020-11-03 15:25:43 -07:00
Frank Denis
37bc6ee54a std.meta: test that const and mut variables have different addresses
We are checking that two identical, constant values, are stored at
different addresses.

But sharing a unique location doesn't look like something the compiler
wouldn't do.

It may make more sense to check that a const variable and a mutable
variable set to the same value have different addresses.
2020-11-03 16:52:51 -05:00
Andrew Kelley
f2cb63c2e1 Merge pull request #6956 from jedisct1/more-gimli-be-fixes
Another big-endian fix for Gimli
2020-11-03 11:22:54 -05:00
Jakub Konka
5060497174 Merge pull request #6921 from xackus/gimmeMoreOfThoseSweetSweetFileDescriptors
stage2: ask for more file descriptors
2020-11-03 10:07:39 +01:00
Frank Denis
8d7c160fb4 Make Gimli test vector look like the python implementation 2020-11-03 09:13:14 +01:00
Joran Dirk Greef
8193f55820 Support 32-bit big-endian targets 2020-11-03 06:03:38 +02:00
Frank Denis
d764636d21 Another big-endian fix for Gimli
We read and write bytes directly from the state, but in the init
function, we potentially endian-swap them.

Initialize bytes in native format since we will be reading them
in native format as well later.

Also use the public interface in the "permute" test rather than an
internal interface. The state itself is not meant to be accessed directly,
even in tests.
2020-11-03 02:01:48 +01:00
xackus
e023a5fe5d force comptime on isDarwin 2020-11-03 00:58:35 +01:00
Jakub Konka
8dda64fa3e Fix Darwin codepath
On Darwin, according to the man pages for setrlimit(), when adjusting
max number of open fds, the reported hard max by getrlimit() is only
theoretical, while the actual maximum, set in the kernel, is hardcoded
in the header file. Therefore, the reported max has to be adjusted
as `min(OPEN_MAX, lim.max)`.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-11-03 00:38:43 +01:00
xackus
06b4526a3e fix freebsd compilation 2020-11-02 23:18:55 +01:00
Andrew Kelley
b30a765b95 fix cmake logic for checking LLVM version 2020-11-02 12:16:10 -07:00
LemonBoy
35a8d90e55 std: Make parseInt/parseUnsigned detect the radix 2020-11-02 14:13:06 -05:00
Andrew Kelley
00ceb592ef Merge pull request #6932 from kubkon/fix-6318
macOS: fix linking issues on BigSur
2020-11-02 13:41:32 -05:00
LemonBoy
be26c3bf4e stage1: Fix *WithOverflow intrinsics with u0 values
Closes #5369
2020-11-02 13:40:00 -05:00
Frank Denis
ad9655db3a Fix Gimli for big-endian targets 2020-11-02 13:38:20 -05:00
Andrew Kelley
061ff11b2b Merge pull request #6927 from LemonBoy/mipsbe-std
Fixes for stdlib for mips BE targets
2020-11-02 13:37:24 -05:00
Jakub Konka
6ecefd5903 Add std.Target.current.isDarwin() to exclude non-macs in comptime 2020-11-02 19:31:07 +01:00
Alex Cameron
ecdd636605 Fix file descriptor leak in fs.openFileZ. 2020-11-02 13:28:29 -05:00
Isaac Freund
50ba018223 std/ascii: add spaces array
This may be combined with std.mem.trim to form a proper replacement for
the now deprecated std.fmt.trimWhitespace().
2020-11-02 13:20:58 -05:00
Jakub Konka
f42ebd1b0a Update src/Compilation.zig
Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2020-11-02 18:56:08 +01:00
Jakub Konka
7f5c96378d Refactor the code according to Andrew's suggestions 2020-11-02 18:38:09 +01:00
Jakub Konka
317c555a5c Fix linking issues on BigSur
This commit fixes linking issue on macOS 11 BigSur by appending
a prefix path to all lib and framework search paths known as
`-syslibroot`.

The reason this is needed is that in macOS 11, the system libraries
and frameworks are no longer readily available in the filesystem.
Instead, the new macOS ships with a built-in dynamic linker cache
of all system-provided libraries, and hence, when linking with either
`lld.ld64` or `ld64`, it is required to pass in `-syslibroot [dir]`.
The latter can usually be obtained by invoking `xcrun --show-sdk-path`.
With this commit, Zig will do this automatically when compiling natively
on macOS. However, it also provides a flag `-syslibroot` which can be
used to overwrite the automtically populated value.

To summarise, with this change, the user of Zig is not required to
generate and append their own syslibroot path. Standard invocations
such as `zig build-exe hello.zig` or `zig build` for projects will
work out of the box. The only missing bit is `zig cc` and `zig c++`
since the addition of the `-syslibroot` option would be a mismatch
between the values provided by `clang` itself and Zig's wrapper.
2020-11-02 17:06:09 +01:00
data-man
ae73e0911d Remove min/max tests for NaNs 2020-11-02 20:40:41 +05:00
data-man
f0610d99f1 Add more tests for reduce 2020-11-02 16:48:59 +05:00
LemonBoy
dc872a221d std: Fix syscall stubs passing 64bit offsets for BE targets 2020-11-02 12:11:07 +01:00
LemonBoy
76e9a4ae83 std: Fix std.unicode test cases for BE targets 2020-11-02 11:48:06 +01:00
LemonBoy
02efc2236a std: Fix json utf{8,16} decoding on BE targets
Byteswap some values when LE ordering is required.
2020-11-02 11:46:50 +01:00
LemonBoy
4fd1ec78e9 std: Re-enable union behaviour test for mips targets 2020-11-02 11:46:26 +01:00
LemonBoy
307496fcd7 std: Re-enable ArrayHashMap test for mips targets 2020-11-02 11:46:07 +01:00
Joran Dirk Greef
78e9e131e0 Pending #5127 2020-11-02 12:37:55 +02:00
Joran Dirk Greef
067bd7e424 Switch back to writing Zig 2020-11-02 09:55:25 +02:00
Joran Dirk Greef
9dec310826 Debug unhandled errno 2020-11-02 09:52:42 +02:00
Andrew Kelley
909aae8153 Merge pull request #6792 from koachan/sparc64-linux
Initial sparc64-linux bringup
2020-11-01 22:14:56 -05:00
Andrew Kelley
af60931a48 Merge pull request #6888 from jcmoyer/issues/6874
Update std.fmt docs and add test for null terminated slices with embedded null bytes
2020-11-01 18:30:09 -05:00
xackus
7703f4c60a stage2: ask for more file descriptors 2020-11-01 23:32:25 +01:00
LemonBoy
445d808bae std: Fix early overflow in time calculation
Closes #6867
2020-11-01 17:06:14 -05:00
Andrew Kelley
2e1cef7508 Merge branch 'LemonBoy-morereduce' 2020-11-01 14:39:56 -07:00
Andrew Kelley
f4ed5d7d48 langref tidy html fixup 2020-11-01 14:39:45 -07:00
LemonBoy
577b994507 docs: Add @reduce documentation 2020-11-01 14:30:31 -07:00
LemonBoy
0d6a7088dc stage1: Implement Add/Mul reduction operators 2020-11-01 14:30:31 -07:00
LemonBoy
6f3d6c1f45 std: Fix expectWithinEpsilon with negative values 2020-11-01 14:30:31 -07:00
LemonBoy
2957433b25 stage1: Fix comptime comparison of NaNs 2020-11-01 14:30:31 -07:00
Jakub Konka
d530e7f9c7 Make std.fmt.bufPrintIntToSlice public
Deprecate `std.fmt.trim` and `std.fmt.isWhiteSpace` in favour of
`std.mem` alternatives.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-11-01 15:48:50 -05:00
xackus
6418284680 std: add {set,get}rlimit bits and improve test 2020-11-01 15:47:46 -05:00
frmdstryr
36f1788762 Add missing arg 2020-11-01 15:40:42 -05:00
Frank Denis
c387f1340f std/crypto: make Hkdf functions public 2020-11-01 18:27:11 +02:00
Joran Dirk Greef
c910f03a7b Swap endianness 2020-11-01 13:14:32 +02:00
Joran Dirk Greef
a67f140d2f Add test 2020-11-01 11:55:27 +02:00
Joran Dirk Greef
2dd8613adc "The Traveling Wilburys' - Handle With Care"
Both `offset` and `len` are `off_t`.

Like the rest of the std lib we assume that `_FILE_OFFSET_BITS == 64`
is always true, so that `off_t` is a `u64`.

When passing to 32-bit kernels, we split these into two `u32`
parameters.
2020-11-01 11:49:08 +02:00
Joran Dirk Greef
2fdb30a571 Add definitions for FALLOC_FL_ mode flags 2020-11-01 11:47:09 +02:00
Joran Dirk Greef
888af655e0 Add libc signature 2020-11-01 11:46:08 +02:00
Veikka Tuominen
9ca9819488 Merge pull request #6883 from Vexu/translate-c
translate-c: correctly handle pointers to opaque demoted structs
2020-10-31 15:25:14 +02:00
Joran Dirk Greef
8fd88fdb31 linux: add fallocate() 2020-10-31 13:39:33 +02:00
Vexu
28a0583b84 run zig fmt on src/ and test/ 2020-10-31 12:21:49 +02:00
Veikka Tuominen
7c8d9cfa40 Merge pull request #6660 from Vexu/stage2
Stage2 switch and package imports
2020-10-31 09:39:28 +02:00
Vexu
3ff381385a translate-c: correctly handle pointers to opaque demoted structs 2020-10-31 09:30:13 +02:00
J.C. Moyer
788900c35c Add test for null terminated slices with embedded null bytes 2020-10-30 23:58:23 -04:00
J.C. Moyer
b38dea37c7 Update doc comments to reflect current behavior 2020-10-30 23:58:23 -04:00
Travis
bb6e39e274 remove extra space in .** error message 2020-10-30 21:26:05 +02:00
Andrew Kelley
e59f44712d Merge pull request #6875 from jorangreef/mips_syscalls
Add more mips syscall numbers
2020-10-30 13:31:12 -04:00
frmdstryr
1d22591299 Add tests and fix \n between comments 2020-10-30 11:20:16 -04:00
frmdstryr
5dd36ee6ce Add support for comments in multiline string literal 2020-10-30 10:52:30 -04:00
Veikka Tuominen
80dd432137 Merge pull request #6858 from travv0/no-star-after-dot-star
don't allow a token starting with an asterisk directly following .*
2020-10-30 16:08:04 +02:00
Vexu
22ec5e0859 stage2: fix typo in liveness; add comptime switch test 2020-10-30 15:58:13 +02:00
Vexu
4ed2c52fb7 stage2: switch put swap condbr and block
condbr is noreturn so having the other way around caused
subsequent cases to be eliminated as dead
2020-10-30 15:58:13 +02:00
Vexu
e2e0b6272b stage2: return same hash for different representations of same value 2020-10-30 15:58:13 +02:00
Vexu
3cc68bd913 stage2: switch liveness analysis 2020-10-30 15:58:13 +02:00
Vexu
769d5a9c43 stage2: switch comptime execution 2020-10-30 15:58:13 +02:00
Vexu
12e4c648cc stage2: implement switch validation for integers 2020-10-30 15:58:13 +02:00
Vexu
4155d2ae24 stage2: switch ranges and multi item prongs 2020-10-30 15:58:13 +02:00
Vexu
3c96d79953 stage2: disallow switching on floats 2020-10-30 15:58:13 +02:00
Vexu
7db17a2d89 stage2: redesign switchbr
Switchbr now only  handles single item prongs.
Ranges and multi item prongs are checked with
condbrs after the switchbr.
2020-10-30 15:58:12 +02:00
Vexu
95467f3249 stage2: dump generated zir with --verbose-ir 2020-10-30 15:58:12 +02:00
Vexu
570f610341 stage2: fix test harness tmp path handling 2020-10-30 15:58:12 +02:00
Vexu
2020ca640e stage2: switch emit zir 2020-10-30 15:58:12 +02:00
Vexu
11998d2972 stage2: basic switch analysis 2020-10-30 15:58:12 +02:00
Vexu
2c12f4a993 stage2: implement Value.eql for void, null and types 2020-10-30 15:58:12 +02:00
Vexu
7e2774367e stage2: implement Value.hash 2020-10-30 15:58:12 +02:00
Vexu
27d233cef7 stage2: basic switch validation 2020-10-30 15:58:11 +02:00
Vexu
ad32e46bce stage2: switch astgen 2020-10-30 15:58:11 +02:00
Vexu
a1d7f0053d stage2: support imports inside packages 2020-10-30 15:58:11 +02:00
Vexu
8421b8a898 stage2: detect import outside file path 2020-10-30 15:58:11 +02:00
Joran Dirk Greef
ab1ed93ad9 Add close_range, faccessat2 and process_madvise 2020-10-30 12:39:01 +02:00
Joran Dirk Greef
9423ed1671 Add more mips syscall numbers
As per: lib/libc/musl/arch/mips/bits/syscall.h.in

...and as promised: https://github.com/ziglang/zig/pull/6356#issuecomment-696023349

Thanks @daurnimator again for the help with #6356.
2020-10-30 11:53:45 +02:00
Koakuma
891c6ddd5f Select stat struct type based on whether we are linking with libc 2020-10-30 11:46:33 +07:00
zhaozg
72343ffd06 fix #3237: resolve undefined symbol _DllMainCRTStartup 2020-10-29 20:09:22 -04:00
LemonBoy
490cafe2c5 stage1: Error out when trying to execute unreachable
Closes #6802
2020-10-29 20:06:52 -04:00
Andrew Kelley
f4bb8be9fc Merge pull request #6654 from joachimschmidt557/stage2-arm
stage2 ARM: more stuff
2020-10-29 18:29:24 -04:00
Andrew Kelley
aaff66b8ed Merge pull request #6866 from LemonBoy/fix-zlib
Fix zlib EOB condition
2020-10-29 18:23:36 -04:00
Andrew Kelley
a41c0b63bb Merge pull request #6356 from jorangreef/io_uring
std: add io_uring library
2020-10-29 18:20:38 -04:00
Travis
f51ccf0d1f panic when empty string passed as dest_rel_path to addInstallFileWithDir
causes the creation of a file instead of the directory that's meant to
be created
2020-10-29 15:22:39 -04:00
Frank Denis
26793453a7 std/crypto/blake2b: allow the initial output length to be set
BLAKE2 includes the expected output length in the initial state.

This length is actually distinct from the actual output length
used at finalization.

BLAKE2b-256/128 is thus not the same as BLAKE2b-128.

This behavior can be a little bit surprising, and has been "fixed"
in BLAKE3.

In order to support this, we may want to provide an option to set the
length used for domain separation.

In Zig, there is another reason to allow this: we assume that the
output length is defined at comptime.

But BLAKE2 doesn't have a fixed output length. For an output length that
is not known at comptime, we can't take the full block size and
truncate it due to the reason above.

What we can do now is set that length as an option to get the correct
initial state, and truncate the output if necessary.
2020-10-29 15:18:37 -04:00
wozeparrot
32e65c3f96 make addBuildOption append type (#6801)
* add addBuildOption test
2020-10-29 15:16:47 -04:00
Andrew Kelley
3a0e8c2b45 Merge pull request #6838 from LemonBoy/netstuff
std: Add basic smoke test for net functionality
2020-10-29 15:10:29 -04:00
Travis
f54605ecc2 add missing Invalid_periodasterisks case in docgen 2020-10-29 14:02:08 -05:00
Andrew Kelley
844eb932f4 Merge pull request #6841 from ifreund/fix-event-loop
std/event: fix poll error set handling
2020-10-29 14:41:18 -04:00
Frank Denis
e59dd7eecf std/crypto/x25519: return encoded points directly + ed->mont map
Leverage result location semantics for X25519 like we do everywhere
else in 25519/*

Also add the edwards25519->curve25519 map by the way since many
applications seem to use this to share the same key pair for encryption
and signature.
2020-10-29 14:39:58 -04:00
Timon Kruiper
ad6e095ef6 stage2.Elf: fix off by one error in writeOffsetTableEntry
The code was using the length of the local symbols, which also
includes the null symbol. Fix this by using the offset table instead,
which only keeps track of the symbols that end up in the got.
2020-10-29 14:38:48 -04:00
LemonBoy
4fb896f16e stage1: Fix bug in internal string slicing (#6843)
Closes #6456
2020-10-29 14:38:13 -04:00
=
6f3c84834d Changed macosx to macos in support os to better relfect the output of zig targets 2020-10-29 14:35:29 -04:00
Frank Denis
5764c550ed std/crypto: vectorize Salsa20
20% faster on x86_64, slower on aarch64 as usual :/
2020-10-29 14:34:58 -04:00
Jakub Konka
17575019a0 Set page size to 16KB for aarch64 macos
With this tweak, `test-std` pass on Apple Silicon + BigSur.
2020-10-29 14:21:43 -04:00
Frank Denis
bb3dfd2708 std/math: add support for vectors to rotl()/rotr() 2020-10-29 14:17:46 -04:00
Vexu
a63fd34c50 return a valid node even if invalid deref was used 2020-10-29 19:20:15 +02:00
Travis
d7f9128b5d add error message to zig side of tokenizing/parsing 2020-10-29 12:03:45 -05:00
Travis
960b5b518f updated zig tokenizer to handle .*** and added tests 2020-10-29 12:03:45 -05:00
Travis
3c7a49c494 add missing case for TokenizeStateSawDotStar at eof 2020-10-29 12:03:45 -05:00
Travis
069aee1495 don't allow a token starting with an asterisk directly following .* 2020-10-29 12:03:45 -05:00
LemonBoy
20fba0933f std/deflate: Avoid reading past end of stream
Use a conservative (and slower) approach in the Huffman decoder fast
path.

Closes #6847
2020-10-29 17:16:03 +01:00
Koakuma
5125eb77bd Use the *_stat type as self 2020-10-29 21:37:45 +07:00
LemonBoy
b3314a8be6 stage1: Fix small bug in pointer type analysis
A flag meant to catch recursively-defined types was never reset, leading
the compiler to generate wrong answers when asked for its
type/alignment.

Closes #6850
2020-10-29 15:41:45 +02:00
Veikka Tuominen
85dd5746bd Merge pull request #6678 from s-ol/doc-type-aware
generated docs improvements: add vector, fntype, anytype type-printing; bool, function value-printing
2020-10-29 15:19:02 +02:00
LemonBoy
fe6cc0c3ba std: Better handling of type values in expectEqual 2020-10-29 15:13:44 +02:00
LemonBoy
88eb3ae8e5 std: Better handling of type values in expectEqual 2020-10-29 11:10:21 +01:00
Andrew Kelley
81f5e1e667 ci: freebsd: skip non-native tests to save time 2020-10-28 22:59:23 -07:00
Andrew Kelley
fd3da3348c ci: macos: rebuild zig1.o with stage1
see #6830 for details.
2020-10-28 16:31:59 -07:00
s-ol
6e96352b90 docs: link to functions in getValueText and getCallHtml 2020-10-29 00:10:22 +01:00
LemonBoy
7bc9531698 stage1: Correctly generated optional constant values
Closes #6799
2020-10-28 21:56:28 +02:00
Frank Denis
0adc144f88 std/crypto: adjust aesni parallelism to CPU models
Intel keeps changing the latency & throughput of the aes* and clmul
instructions every time they release a new model.

Adjust `optimal_parallel_blocks` accordingly, keeping 8 as a safe
default for unknown data.
2020-10-28 21:44:00 +02:00
Frank Denis
ea45897fcc PascalCase *box names, remove unneeded comptime & parenthesis
Also rename (salsa20|chacha20)Internal() to a better name.

And sort reexported crypto.* names
2020-10-28 21:43:15 +02:00
LemonBoy
6d2f103bfb stage1: Fix crash in comptime struct value copy
Comptime fields are never materialized in the ZigValue so pay attention
when iterating over the fields array.

Fixes #6800
2020-10-28 21:13:32 +02:00
Koakuma
3a58b2330c Update stack traces testcases 2020-10-28 17:46:26 +07:00
Jakub Konka
1a171a143a Merge pull request #6842 from kubkon/aarch64-macos-fix
std: Apple Silicon: no fstat$INODE64 symbol found
2020-10-28 11:38:46 +01:00
Jakub Konka
4f50958407 Clean up exporting of symbols on Darwin 2020-10-28 10:36:19 +01:00
LemonBoy
7f46672193 More fixups for Windows targets
* Use closeSocket on sockets instead of plain old close, the latter
  doesn't work on them.
* Use winsocket2 everywhere, mingw has no BSD sockets.
2020-10-28 10:03:23 +01:00
Jakub Konka
bda9a159aa Apple Silicon: no fstat$INODE64 symbol found
It seems that Apple has finally got rid of the 32bit versions of
`fstat` and `fstatat`, and instead, only 64bit versions are available
on BigSur and Apple Silicon.

The tweak in this commit is required to make Zig stage1 compile on
BigSur + aarch64.
2020-10-27 22:47:53 +01:00
Andrew Kelley
e1ca6946be rename ZigClangFloatingLiteral_getValueAsApproximateDouble 2020-10-27 14:16:43 -07:00
johnLate
1ea0d40e5e std.os.c.accept/accept4: allow null for addr and len
See ziglang#6832.
2020-10-27 21:52:47 +01:00
johnLate
23c28c72b7 std.os.linux.accept/accept4: allow null for addr and len
std.os.accept already wants to allow null, which matches `man 3p accept`:

>  address     Either a null pointer, or a pointer to a sockaddr structure
>              where the address of the connecting  socket  shall  be  re‐
>              turned.
>
>  address_len Either  a  null pointer, if address is a null pointer, or a
>              pointer to a socklen_t object which on input specifies  the
>              length  of  the  supplied sockaddr structure, and on output
>              specifies the length of the stored address.

Fixes ziglang#6832.
2020-10-27 21:52:47 +01:00
LemonBoy
8044ed4c66 std: Add basic smoke test for net functionality 2020-10-27 21:52:47 +01:00
Isaac Freund
504f259c24 std/event: fix zig fmt regression 2020-10-27 21:40:22 +01:00
Isaac Freund
1b34365ca1 std/event: fix poll error set handling
This has been broken since 127fa80
2020-10-27 21:28:31 +01:00
Koakuma
2b87cc7ed3 starting_stack_ptr -> argc_argv_ptr to reflect actual use 2020-10-27 22:46:18 +07:00
Žiga Željko
7c2bde1f07 std/crypto: API cleanup 2020-10-26 19:19:34 -04:00
Andrew Kelley
e2caf57527 Merge branch 'frmdstryr-import-empty-file' 2020-10-26 16:07:46 -07:00
Andrew Kelley
435c8ad703 non-hacky workaround for the empty file bug
See #3328
2020-10-26 16:06:14 -07:00
Andrew Kelley
c1ae9f40c7 stage1: support "native" as the OS string in -target
This should help for bootstrapping purposes, intending to fix the macOS
CI.
2020-10-26 15:48:48 -07:00
frmdstryr
1ce0994897 Fix @import of empty file 2020-10-26 13:29:32 -07:00
Andrew Kelley
e83334274f add regression test for already fixed bug
closes #6781
2020-10-26 13:18:44 -07:00
data-man
194e29adfc Format null type in std.fmt 2020-10-26 15:40:48 -04:00
Andrew Kelley
a0f4606f32 ci: still build zig even though we are using (older) zig cc 2020-10-26 10:50:43 -07:00
Yanis Zafirópulos
c6747e1063 Copy editing :) 2020-10-26 18:39:34 +01:00
Frank Denis
74a1175d9d std/*: add missing MIT license headers 2020-10-26 17:41:29 +01:00
mlarouche
e3fed3c814 Temp Fix for deadlock in C compilation, found and tested on Windows 2020-10-25 21:33:46 -04:00
johnLate
0a619c68a6 fix type mismatch in std.net.StreamServer
Parameter in std.os.listen is u31.

Fixes ziglang#6775
2020-10-25 21:18:24 -04:00
dec05eba
c0fa5963ee Make lastIndexOf use the same cut-off between BMH as indexOf
Also update test to use a string longer than 52 characters
to test both BMH and linear path.
2020-10-25 21:17:22 -04:00
Frank Denis
72064eba23 std/crypto: vectorize BLAKE3
Gives a ~40% speedup on x86_64.

However, the generic code remains faster on aarch64.

This is still processing only one block at a time for now.

I'm pretty confident that processing more blocks per round
will eventually give a substantial performance improvement on
all platforms with vector units.
2020-10-25 21:13:14 -04:00
Frank Denis
1b4ab749cf std/crypto: add the bcrypt password hashing function
The bcrypt function intentionally requires quite a lot of CPU cycles
to complete.

In addition to that, not having its full state constantly in the
CPU L1 cache causes a massive performance drop.

These properties slow down brute-force attacks against low-entropy
inputs (typically passwords), and GPU-based attacks get little
to no advantages over CPUs.
2020-10-25 21:11:40 -04:00
Sébastien Marie
2a0a11aa66 openbsd: make dl_phdr_info cross arches
introduce Addr and Half definition to std.elf, and use them for dl_phdr_info
2020-10-25 20:46:28 -04:00
Andrew Kelley
0088efc4b2 Merge pull request #6809 from jedisct1/salsa
std/crypto: add (X)Salsa20 and NaCl boxes
2020-10-25 20:34:35 -04:00
Andrew Kelley
bbd1e122d4 ci: skip compile error tests on freebsd to save time 2020-10-25 17:29:10 -07:00
Frank Denis
0c7a99b38d Move ed25519 key pairs to a KeyPair structure 2020-10-25 21:55:05 +01:00
Frank Denis
28fb97f188 Add (X)Salsa20 and NaCl boxes
The NaCl constructions are available in pretty much all programming
languages, making them a solid choice for applications that require
interoperability.

Go includes them in the standard library, JavaScript has the popular
tweetnacl.js module, and reimplementations and ports of TweetNaCl
have been made everywhere.

Zig has almost everything that NaCl has at this point, the main
missing component being the Salsa20 cipher, on top on which NaCl's
secretboxes, boxes, and sealedboxes can be implemented.

So, here they are!

And clean the X25519 API up a little bit by the way.
2020-10-25 18:04:12 +01:00
Koakuma
cbc8750502 Separate libc stat and kernel stat definitions 2020-10-25 23:52:08 +07:00
Koakuma
3ce9428e3d Various formatting fixes 2020-10-25 21:53:16 +07:00
Koakuma
5474d43389 Zero %i6 to terminate backchain 2020-10-25 21:51:01 +07:00
Koakuma
1a362ea5b0 Fix sparc64 bits definitions 2020-10-25 21:38:39 +07:00
Koakuma
785153d756 Fix SA_* constants for sparc64 2020-10-25 20:39:32 +07:00
Koakuma
f018201009 Predict error-less path on syscalls 2020-10-25 20:07:18 +07:00
joachimschmidt557
7b4f3c7cfc stage2 ARM: genSetStack and genSetReg from stack 2020-10-25 12:51:19 +01:00
joachimschmidt557
7d14426da4 stage2 ARM: enable backpatching return statement 2020-10-25 12:51:19 +01:00
joachimschmidt557
0e16328636 stage2 ARM: add multiply and multiply long instructions 2020-10-25 12:51:19 +01:00
joachimschmidt557
7391087df1 stage2 ARM: better immediate loading feat. movw and movt 2020-10-25 12:51:19 +01:00
Vincent Rischmann
59af275680 test runner: use the correct number in leak report 2020-10-25 11:28:36 +02:00
Sébastien Marie
3115d2f2cd readd original code from #6638. realpathZ() is expected to take a [*:0]const u8 2020-10-25 10:02:10 +01:00
Koakuma
2e7a4758b3 Add back ppc input/output/clobber definitions
Accidentally removed when rebasing, this adds it back.
2020-10-25 13:39:22 +07:00
Koakuma
1d3abb761d "zig fmt" on lib/std/os/linux.zig 2020-10-25 13:38:08 +07:00
Jakub Konka
872bc787b5 cc: fix regression on macOS after adding libc headers
Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-10-24 17:32:50 +02:00
Koakuma
e7369ada93 Fix boolean operator in if clause 2020-10-24 21:33:40 +07:00
Koakuma
73e62f22ec Fix sigaction(2) call on sparc64 2020-10-24 20:05:37 +07:00
Koakuma
792526c0bd Fix sparc64 argument loading 2020-10-24 20:05:36 +07:00
Koakuma
cdbf66e36e Add sparc64-specific values for the various SA_ and SIG_ constants 2020-10-24 20:05:34 +07:00
Koakuma
268516d5d9 Fix constants 2020-10-24 20:04:18 +07:00
Koakuma
238f253de9 Move comptime out 2020-10-24 20:03:41 +07:00
Koakuma
cefbe4e7be Use correct names for generic SPARC targets
LLVM calls generic sparc32 CPUs "v8" and generic sparc64 CPUs "v9".
2020-10-24 20:03:41 +07:00
Koakuma
341eec71fd Add clone(2) implementation
This implementation kindly provided by @LemonBoy at GitHub
https://github.com/ziglang/zig/pull/6187#issuecomment-682635168
2020-10-24 20:03:41 +07:00
Koakuma
300cfbf252 Add TLS implementation for sparc64 2020-10-24 20:03:40 +07:00
Koakuma
6146f81c6e Add pipe(2) support 2020-10-24 20:03:37 +07:00
Koakuma
dba009fd21 Account for the delay slot 2020-10-24 20:01:32 +07:00
Koakuma
c29da84c0e Add sp loading 2020-10-24 20:01:29 +07:00
Koakuma
23433fb317 Fix register naming 2020-10-24 19:59:05 +07:00
Koakuma
206f96d474 Add sparc64 linux C ABI 2020-10-24 19:59:04 +07:00
Koakuma
de06b0a635 Add sparc64 linux bits 2020-10-24 19:59:04 +07:00
Koakuma
e5a11020cc Add sparc64 syscall interface 2020-10-24 19:59:04 +07:00
Frank Denis
91a1c20e74 Fix a typo (s/multple/multiple/) 2020-10-24 07:57:34 +02:00
s-ol
300b617140 generated docs: add FnFrame type support
See #3404
2020-10-23 15:44:32 +02:00
Timon Kruiper
4b48fccadd When checking a cache hit, make sure to handle a (re)moved source file
When a file cannot be found in the cache, it is not a hit.

Closes #6729
2020-10-23 01:01:37 -04:00
Andrew Kelley
3af9025a1d Merge pull request #6719 from jedisct1/ed25519-batch
std/crypto/25519: add support for batch Ed25519 signature verification
2020-10-23 00:58:53 -04:00
Andrew Kelley
392e6da8a3 update stack trace test case 2020-10-22 21:57:30 -07:00
Andrew Kelley
59c26c79e8 Merge branch 'BarabasGitHub-improve-windows-networking' 2020-10-22 17:45:31 -07:00
Andrew Kelley
569f7ce49e Merge branch 'improve-windows-networking'
of https://github.com/BarabasGitHub/zig into
BarabasGitHub-improve-windows-networking

Conflicts:
 lib/std/os.zig

This commit resolves conflicts with the changes to std.os which removed
the EAGAIN error handling interactions with the event loop. The solution
to the conflict was to apply EAGAIN => return error.WouldBlock into the
improved windows networking branch.
2020-10-22 16:59:15 -07:00
DixiE
79ec08fe2f Fix Compiler Error When Using wWinMain Entry-Point
The fix for #6715 introduced a new compiler error when attempting to use
wWinMain as the application entry-point.

The Windows API often relies on implicit casts between signed and
unsigned variables. In this case, wWinMain returns an INT despite the
fact this value is intended to feed into ExitProcess, which expects a
UINT, so I've restored the bitcast from #5613.
2020-10-22 19:50:06 -04:00
Paul Espinosa
ddd39b994b Use std.testing.expect in language reference samples
In this commit, the code samples in the language reference have been changed to
use `std.testing.expect` rather than `std.debug.assert` when they are
written in `test` code. This will teach Zig learners best practices when
they write their own test code.

Not all uses of `std.debug.assert` have been replaced. There are examples where
using `assert` fits the context of the sample.

Using `std.debug.assert` in test code can lead to errors if running tests in
ReleaseFast mode. In ReleaseFast mode, the `unreachable` in `assert` is
undefined behavior. It is possible that `assert` always causes `zig test` to
pass thus possibly leading to incorrect test code outcomes. The goal is to
prevent incorrect code from passing test cases.

Closes #5836
2020-10-22 15:54:57 -07:00
chwayne
1e13e8e817 Make argsAlloc/ArgIterator return zero-sentinel strings (#6720) 2020-10-22 17:52:48 -04:00
xackus
2ee79f149b std: reference more declarations in std.build 2020-10-22 17:44:23 -04:00
Andrew Kelley
e02655798f Merge pull request #6743 from LemonBoy/someppc64stuff
Some ppc64 stuff
2020-10-22 17:39:26 -04:00
Andrew Kelley
e6ac082437 Merge pull request #6744 from LemonBoy/intcast-vec
stage1: Implement `@intCast` between vectors
2020-10-22 17:36:18 -04:00
Andrew Kelley
78199a684f stage2 LLD .ar linking: fix wrong object file path
closes #6721
closes #6722
2020-10-22 14:33:46 -07:00
s-ol
bf982cd4e9 generated docs: add anyframe type support
See  #3404
2020-10-22 16:05:59 +02:00
s-ol
c81e8c2125 generated docs: add vector type support
See  #3404
2020-10-22 16:05:59 +02:00
Andrew Kelley
198d1438ea ci: fix regression from not building docs
0e4f7a8e3f forgot to build the docs,
causing CI failures
2020-10-22 01:18:55 -07:00
Frank Denis
047599928a Add a benchmark for signature verifications 2020-10-22 09:58:26 +02:00
Frank Denis
2d9befe9bf Implement multiscalar edwards25519 point multiplication 2020-10-22 09:58:26 +02:00
Frank Denis
0fb6fdd7eb Support variable-time edwards25519 scalar multiplication
This is useful to save some CPU cycles when the scalar is public,
such as when verifying signatures.
2020-10-22 09:58:26 +02:00
Frank Denis
ff658abe79 std/crypto/25519: use Barrett reduction for scalars (mod l) 2020-10-22 09:58:26 +02:00
Frank Denis
8e79b3cf23 std/crypto/25519: add support for batch Ed25519 signature verification 2020-10-22 09:58:26 +02:00
LemonBoy
0c355bef9e std: Slim down the error code path in initStaticTLS
Calling @panic made the executable ~30x times bigger, use a simple
`abort()` and let the user figure out what went wrong.

Supporting ARMv6 (and earlier?) platforms is not a priority.

Closes #6676
2020-10-21 23:35:06 -04:00
heidezomp
1e07487904 Fix std.net.connectUnixSocket in evented I/O mode
The event loop constant was missing.
2020-10-21 23:32:12 -04:00
Andrew Kelley
ce5035c07d Merge branch 'kubkon-macos-libc'
closes #6752
closes #5031
2020-10-21 19:59:12 -07:00
Andrew Kelley
11a9eff36e add another copyright notice to macos stdint.h 2020-10-21 19:58:47 -07:00
Andrew Kelley
b61733a4b8 readme: rewrite the license section 2020-10-21 19:55:35 -07:00
Jakub Konka
7d0acacfc3 Add minimal set of macOS libc headers
Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-10-21 19:45:21 -07:00
LemonBoy
44f8e6a534 stage1: Fix edge case in Union ZigValue generation
Unions that passed the one_possible_value check were incorrectly
generated, none of their internal fields were initialized.

Fixes #6758
2020-10-21 22:42:03 -04:00
frmdstryr
52879b50d9 Update enable-valgrind flag to fvalgrind 2020-10-21 22:41:11 -04:00
Frank Denis
0e4f7a8e3f MSVC CI: run tests individually (#6751)
This slightly reduces the amount of peak RSS needed, buying us more time until stage2 is shipping.
2020-10-21 22:40:41 -04:00
xackus
36d586336c std docs: print bool values 2020-10-20 23:27:12 +03:00
LemonBoy
90f7034b69 std: Implement featureSetHasAny/featureSetHasAll
Introduce two helper functions to avoid writing short novels only to check for more
than a single feature.
2020-10-20 23:23:43 +03:00
Rocknest
a123378141 langref: fix equations 2020-10-20 23:22:08 +03:00
John Burton
33c4ad7f3a Add missing std in dump function json.zig
Add missing std to use of std.io.getStdErr in the function dump
so that it compiles.
2020-10-20 13:39:38 +03:00
LemonBoy
475fc2934b Update langref errors 2020-10-20 10:05:44 +02:00
LemonBoy
39e34081ca Update the stack-traces tests 2020-10-19 20:09:43 +02:00
LemonBoy
2f465761bb stage1: Implement @intCast between vectors
Explicit and implicit integer casts on vector types are now supported
and follow the same rules as their scalar counterparts.

Implicit float casts are accidentally supported, `@floatCast` is still
not vector-aware.
2020-10-19 20:05:09 +02:00
LemonBoy
96fe971051 std: Minor changes to startup code
* Smaller startup sequence for ppc64
* Terminate the frame-pointer chain when executing _start
* Make the stack traces work on ppc64
* Make the stack traces coloured on ppc64, some ioctls numbers are
  different and the whole set of constants should be audited.
2020-10-19 15:15:43 +02:00
Nathan Bourgeois
3ab4d112e0 Update Documentation to use -O instead 2020-10-19 13:00:04 +03:00
Frank Denis
6ddb05d996 Darwin has arc4random(), too 2020-10-18 18:24:36 +02:00
Jakub Konka
b28992de71 Disable build.zig tests on WASI since rely on cwd()
Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-10-18 18:20:43 +02:00
Jakub Konka
dc68aab6fb Merge pull request #6728 from Snektron/std-build-dupePkg-fix
Fix invalid call to dupePkg in build.zig
2020-10-18 15:29:51 +02:00
Robin Voetter
3d857f7808 add addPackage test 2020-10-18 13:35:24 +02:00
Robin Voetter
29c580304b Fix invalid call to dupePkg in build.zig 2020-10-18 13:20:19 +02:00
Andrew Kelley
919dcc5104 coff: link in CRT for DLLs that want -lc
see #5748
closes #5870
2020-10-17 20:35:44 -07:00
Jesse Rudolph
e821a57683 add Builder.dupePkg()
mimics the duplication of strings in `Builder` for `Pkg`. This
ensures the lifetime of the memory backing strings in a `Pkg`
struct and the `Pkg.dependencies` slice is not shorter than the
`Builder` that the data is associated with.
2020-10-17 22:35:36 -04:00
Andrew Kelley
b0684bf084 std.mem: expose the simpler linear functions
The new defaults that came in with
644400054c are nice, however, it is still
possible that someone knows their inputs are always small and wants to
use the simpler implementations. We keep the default to make the choice
at runtime, but expose the linear functions in the public interface of
std.mem.

Also improved the doc comments.
2020-10-17 19:24:52 -07:00
Andrew Kelley
644400054c Merge pull request #6259 from dec05eba/master
Use boyer-moore-horspool algorithm for indexOfPos and lastIndexOf unless the haystack or needle is very small
2020-10-17 21:38:50 -04:00
Nathan Bourgeois
e55244c4c6 BYOS support for system.isatty(fd: fd_t); (#6686) 2020-10-17 21:13:10 -04:00
Felix (xq) Queißner
b014bc77c8 Fixes std.meta.Tuple and std.meta.ArgsTuple for zero-sized types (like void). 2020-10-17 21:10:01 -04:00
LemonBoy
2a256d5ea0 stage1: Fix type-checking of unary neg for vector types
Validate the vector element type as done for the scalar case.

Fixes #6708
2020-10-17 21:08:39 -04:00
Andrew Kelley
e51bc19e4a Merge pull request #6394 from Vexu/fmt
std.fmt add specifier for printing Zig identifiers
2020-10-17 21:06:54 -04:00
Andrew Kelley
71ac5b1515 Merge branch 'semarie-openbsd-minimal' 2020-10-17 17:53:47 -07:00
Andrew Kelley
05b1a7414e code cleanups
* in selfExePath, return errors instead of defaulting to bogus data
 * less invasive edits to the logic of link/Elf.zig
 * less indentation
2020-10-17 17:52:09 -07:00
Andrew Kelley
03f7cffce9 Merge branch 'openbsd-minimal' of https://github.com/semarie/zig into semarie-openbsd-minimal 2020-10-17 17:34:43 -07:00
Andrew Kelley
9052e0b137 Merge pull request #6713 from jprudil/close-6697
Make std.meta.Int accept a signedness parameter
2020-10-17 18:55:25 -04:00
Frank Denis
fa17447090 std/crypto: make the whole APIs more consistent
- use `PascalCase` for all types. So, AES256GCM is now Aes256Gcm.
- consistently use `_length` instead of mixing `_size` and `_length` for the
constants we expose
- Use `minimum_key_length` when it represents an actual minimum length.
Otherwise, use `key_length`.
- Require output buffers (for ciphertexts, macs, hashes) to be of the right
size, not at least of that size in some functions, and the exact size elsewhere.
- Use a `_bits` suffix instead of `_length` when a size is represented as a
number of bits to avoid confusion.
- Functions returning a constant-sized slice are now defined as a slice instead
of a pointer + a runtime assertion. This is the case for most hash functions.
- Use `camelCase` for all functions instead of `snake_case`.

No functional changes, but these are breaking API changes.
2020-10-17 18:53:08 -04:00
Andrew Kelley
0011def2b2 fix compilation error when building with io_mode evented
The merge of #5613 introduced a regression when building with io_mode
evented, fixed in this commit.

closes #6715
2020-10-17 15:46:36 -07:00
Vexu
e8ca1b254d std: remove renderStringLiteral in favor of std.fmt specifier 2020-10-17 23:20:38 +03:00
Sebastien Marie
35a7247a2c Merge branch 'master' into openbsd-minimal 2020-10-17 17:38:23 +02:00
Jan Prudil
132813849c Convert remaining call sites 2020-10-17 14:50:26 +02:00
Jan Prudil
aadccc4206 Make std.meta.Int accept a signedness parameter 2020-10-17 14:09:59 +02:00
Vexu
2c294676b5 use new format specifier in translate-c and std lib 2020-10-17 10:27:19 +03:00
Vexu
8d38a91ca8 std.fmt: add specifier for Zig identifiers 2020-10-17 10:26:59 +03:00
Andrew Kelley
245d98d32d Merge pull request #6291 from pixelherodev/cbe_arithmetic
CBE: addition and subtraction
2020-10-17 01:00:38 -04:00
Andrew Kelley
9241c1b772 Merge branch 'nmichaels-zbs-doc'
closes #5800
2020-10-16 21:33:04 -07:00
Andrew Kelley
9ca8bcb4d9 langref cleanups
* move the opaque section to after struct, enum, union, and add
   hyperlinks
 * improve the introduction of the zig build system. don't link to the
   wiki.
 * update to the latest zig init-exe example code
 * rename headers to avoid redundant words such as "zig"
 * simplify example code
2020-10-16 21:29:33 -07:00
Nathan Michaels
eb80cc2b9e Add some basic examples for the Zig Build System. 2020-10-16 21:29:22 -07:00
Andrew Kelley
6850e54cc0 Merge branch 'vegecode-byteOffsetOf_fix'
closes #5713
2020-10-16 21:25:42 -07:00
vegecode
2545f44db0 byteOffsetOf add fields to non-packet struct to maintain symmetry 2020-10-16 20:04:42 -07:00
vegecode
0456b2145d byteOffsetOf rounds up using bit offset in host integer 2020-10-16 20:04:42 -07:00
Juha Syrjälä
79ef96b6a4 Add support for zig build run -- arg1 arg1 in file created by init-exe 2020-10-16 21:29:24 -04:00
Andrew Kelley
8a2d12d707 Merge pull request #6393 from onebsv1/priority-queue-update
Adding a function to update the priority of an element
2020-10-16 21:26:04 -04:00
LemonBoy
d44486b274 std: Add libssp implementation for GNU/Windows targets
Unlike glibc and musl, MinGW provides no libssp symbols leading to
countless compile errors if FORTIFY_SOURCE is defined.

Add a (incomplete) implementation of libssp written in Zig so that
linking succeeds.

Closes #6492
2020-10-16 21:22:14 -04:00
Andrew Kelley
2aff27d922 Merge branch '6604'
closes #6604
2020-10-16 18:15:31 -07:00
Andrew Kelley
5c16022c81 rename WaitpidRet to WaitPidResult 2020-10-16 18:14:39 -07:00
stf
3921cb0d8d std.os.waitpid: also return pid of child
closes #6581
2020-10-16 17:26:50 -07:00
Isaac Freund
0e4c3934a0 zig fmt: write modified files to stdout not stderr 2020-10-16 20:23:18 -04:00
Andrew Kelley
8364417c8f trivial refactor to remove redundant function call 2020-10-16 16:15:50 -07:00
Jakub Konka
fe127a3691 Add llvm-config detection when dynlinking clang 2020-10-16 19:14:42 -04:00
Jakub Konka
abd72781a3 Allow linking with dynamic libraries in main CLI 2020-10-16 19:14:42 -04:00
Frank Denis
0b4a5254fa Vectorize Gimli 2020-10-16 18:41:11 -04:00
LemonBoy
f78380b936 stage1: Don't ask LLVM to emit misaligned memcpy
Pay close attention to the RHS type alignment when rendering an
assignment op as it may differ from the LHS pointer one.

This problem was noticed when debugging a CI failure in #6648: due to
sheer luck the misalignment caused a segfault on macos that was also
reproduced locally.

I tried to write a small test case but it turned out to be a daunting
task as I couldn't manage to trigger the problem consistently (and stop
the optimizer from simplifying everything). Patches welcome.
2020-10-16 18:39:48 -04:00
LemonBoy
2a62d4b20b stage1: Expand undefined struct/arrays when indexed
Fixes #6693
2020-10-16 17:13:38 +03:00
Andrew Kelley
996a2284dd Merge branch 'AnthonyYoManz-5002-fix-entrypoint-with-winmain'
closes #5002
closes #5613
2020-10-15 19:39:44 -07:00
Andrew Kelley
d87bd3d8af fixups regarding windows wide strings
* remove GetModuleHandleA from kernel32.zig. use of A functions
   considered harmful.
 * make it a compile error to expose WinMain instead of wWinMain. same
   thing.
 * start code declares wWinMainCRTStartup instead of WinMainCRTStartup
   when it has the choice.
2020-10-15 19:37:55 -07:00
Andrew Kelley
c7c38e7279 Merge branch '5002-fix-entrypoint-with-winmain' of https://github.com/AnthonyYoManz/zig into AnthonyYoManz-5002-fix-entrypoint-with-winmain 2020-10-15 18:22:12 -07:00
Frank Denis
51a3d0603c std.rand: set DefaultCsprng to Gimli, and require a larger seed
`DefaultCsprng` is documented as a cryptographically secure RNG.

While `ISAAC` is a CSPRNG, the variant we have, `ISAAC64` is not.
A 64 bit seed is a bit small to satisfy that claim.

We also saw it being used with the current date as a seed, that
also defeats the point of a CSPRNG.

Set `DefaultCsprng` to `Gimli` instead of `ISAAC64`, rename
the parameter from `init_s` to `secret_seed` + add a comment to
clarify what kind of seed is expected here.

Instead of directly touching the internals of the Gimli implementation
(which can change/be architecture-specific), add an `init()` function
to the state.

Our Gimli-based CSPRNG was also not backtracking resistant. Gimli
is a permutation; it can be reverted. So, if the state was ever leaked,
future secrets, but also all the previously generated ones could be
recovered. Clear the rate after a squeeze in order to prevent this.

Finally, a dumb test was added just to exercise `DefaultCsprng` since
we don't use it anywhere.
2020-10-15 20:57:16 -04:00
Andrew Kelley
f701459f04 Merge pull request #6685 from ifreund/bufprint0
std/fmt: rename allocPrint0() to allocPrintZ(), add bufPrintZ()
2020-10-15 20:51:25 -04:00
Frank Denis
cb44f27104 std/crypto/hmac: remove HmacBlake2s256 definition
HMAC is a generic construction, so we allow it to be instantiated
with any hash function.

In practice, HMAC is almost exclusively used with MD5, SHA1 and SHA2,
so it makes sense to define some shortcuts for them.

However, defining `HmacBlake2s256` is a bit weird (and why
specifically that one, and not other hash functions we also support?).
There would be nothing wrong with that construction, but it's not
used in any standard protocol and would be a curious choice.

BLAKE2 being a keyed hash function, it doesn't need HMAC to be used as
a MAC, so that also doesn't make it a good example of a possible hash
function for HMAC.

This commit doesn't remove the ability to use a Hmac(Blake2s256) type
if, for some reason, applications really need this, but it removes
HmacBlake2s256 as a constant.
2020-10-15 20:50:34 -04:00
Andrew Kelley
a66449c1ed Merge pull request #6616 from fengb/darwin-rusage
Darwin rusage
2020-10-15 20:49:54 -04:00
Andrew Kelley
ee0ba9ec7d Merge branch 'g-w1-master'
closes #6627
2020-10-15 17:44:26 -07:00
Andrew Kelley
09a250c531 adjust error message of zig run with no args
previously it said "one source file" which was not correct
2020-10-15 17:44:10 -07:00
g-w1
dfce396cf8 friendly error message for zig run with no args 2020-10-15 17:43:44 -07:00
Tadeo Kondrak
e892ee17e6 std: move std.meta.refAllDecls to std.testing 2020-10-15 20:34:22 -04:00
Andrew Kelley
0da027f078 Merge branch 'g-w1-zig-test-zig-run-execve'
closes #6653
2020-10-15 17:19:47 -07:00
Andrew Kelley
43c2ce10a1 fixups
* extract logic into a `os_can_execve` and use it in the other place
   that we execve
 * outdent some code by introducing `run_or_test` variable
 * delete unnecessary and wasteful memory management logic
 * better error message for when execve fails
 * add comment to explain why we do not execve for `zig test`
2020-10-15 17:18:40 -07:00
g-w1
1c36680928 stage2: use execve where available for zig test and zig run
closes #6531
2020-10-15 16:54:50 -07:00
Andrew Kelley
e17297102a Merge branch 'kubkon-enable-stage2-macos-tests'
closes #6661
2020-10-15 16:48:44 -07:00
Andrew Kelley
d91e75f5ca getExternalExecutor fixups regarding dynamic linker
* std.Target.standardDynamicLinkerPath: macOS has a dynamic linker
 * no need to override the default dynamic linker in the macos
   CrossTarget initialization in the tests
 * in getExternalExecutor, when validating the dynamic linker path, take
   into account the standard dynamic linker path.
2020-10-15 16:44:16 -07:00
Clayton Voges
8c4031fd87 replaced inStream() with reader()
`inStream()` is now deprecated and deserves replacing.
2020-10-15 19:30:21 -04:00
Jakub Konka
0e1afee732 Enable stage2 end-to-end tests on macOS run natively
This commit enables stage2 end-to-end tests to run natively on macOS
(where and when applicable). Since QEMU on macOS doesn't support
the same type of architecture emulation as it does on linux (i.e.,
there is no `qemu-x86_64` for instance), this commit ensures that we
specify a path to dynamic linker on macOS (`/usr/lib/dyld`) which
is then checked for existence in `std.CrossTarget.getExternalExecutor()`
function, and if exists, we can run the test natively.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-10-15 15:59:16 -07:00
Frank Denis
f3667e8a80 std/crypto/25519: do cofactored ed25519 verification
This is slightly slower but makes our verification function compatible
with batch signatures. Which, in turn, makes blockchain people happy.
And we want to make our users happy.

Add convenience functions to substract edwards25519 points and to
clear the cofactor.
2020-10-15 18:49:10 -04:00
LemonBoy
ab585c680b stage1: Off-by-one error in int to float conversion
The base is 2^64 and not 2^64-1.

Closes #6683
2020-10-15 21:25:59 +03:00
Isaac Freund
7b150dd05e docs: snake_case enums/unions in langref examples
This follows the accepted change to the style guide:
https://github.com/ziglang/zig/issues/2101
2020-10-15 18:55:57 +03:00
Isaac Freund
d52035f401 std/fmt: add bufPrintZ() 2020-10-15 12:21:19 +02:00
Isaac Freund
b259696cfb std/fmt: rename allocPrint0() to allocPrintZ()
This is consistent with other standard library functions working with
null terminated pointers/slices.
2020-10-15 12:21:14 +02:00
Andrew Kelley
3b4432d9a6 Merge pull request #6655 from kprotty/timers
Integrate std.time.sleep with the event loop
2020-10-14 21:49:45 -04:00
Andrew Kelley
2f52f95b92 Merge pull request #6669 from ifreund/color-fixes
std/build: support --color
2020-10-14 21:35:43 -04:00
Matthew Knight
352976ed23 Event Channel: updated linked list node initialization (#6652)
fixed node init method
2020-10-14 21:33:53 -04:00
Andrew Kelley
aa5ff867a2 Merge branch 'jedisct1-tbd-dylib'
closes #6681
2020-10-14 18:24:21 -07:00
Andrew Kelley
816304e7e1 add .tbd to usage text 2020-10-14 18:22:50 -07:00
Frank Denis
c0e9d3fb86 Classify .tbd files as shared libraries
On macOS, a .tbd ("text-based dylib definition") file is a shared library
stub, allowing symbols to be defined only once for all the architectures
the library was compiled for.

.tbd files can be linked like .dylib files.
2020-10-14 18:19:57 -07:00
Andrew Kelley
477798b37e ci: macos: unset ZIG_LIBC before testing
otherwise cross compiling gets incorrectly affected by the environment
variable.
2020-10-14 17:59:29 -07:00
Andrew Kelley
540364e6c1 ci: macos: update to new cache tarball
This tarball contains LLVM, Clang, LLD, Zig, and libz.a for macOS. This
is everything we need for the CI to produce a working Zig executable.
2020-10-14 17:36:43 -07:00
Andrew Kelley
bf8cc73cf3 ci: macos: take advantage of zig-bootstrap 2020-10-14 02:25:51 -07:00
Andrew Kelley
0f4386875f stage2: support ZIG_LIBC env var and detect self as system C compiler 2020-10-14 02:05:56 -07:00
Jakub Konka
68b31c59a6 Merge pull request #6650 from kubkon/macho-incremental
stage2: enable incremental MachO linking
2020-10-14 08:20:33 +02:00
Rocknest
548fd6e87b force comptime on comptimePrint 2020-10-14 01:03:01 -04:00
Andrew Kelley
3811602ad7 Merge pull request #6643 from jedisct1/chacha-vec
std/crypto: add a vectorized ChaCha20 implementation
2020-10-14 00:52:36 -04:00
LemonBoy
0570df69b1 stage1: Fix missing runtime safety check for intToPtr
Elide the alignment check if the pointer alignment is one, the null
check must be preserved as it depends on the pointer type.

Fixes #6667
2020-10-14 00:05:50 -04:00
Isaac Freund
6ba1fdf7e0 stage2: use meta.stringToEnum for Color parsing
This requires renaming the variants to be snake_case, which is the new
recommended style anyways.
2020-10-13 20:17:30 +02:00
Isaac Freund
f01c3150c1 std/build: support --color 2020-10-13 20:06:03 +02:00
Jakub Konka
adfd298e44 Do not rewrite paths to dyld and libSystem unless changed 2020-10-13 08:38:17 +02:00
Jakub Konka
951721343f Reuse text blocks; enable all incremental tests 2020-10-13 08:38:17 +02:00
Jakub Konka
cf2aea7b41 Enable incremental testcase for macOS 2020-10-13 08:38:17 +02:00
Jakub Konka
ecd480fe93 Fix writing of load cmds headers *after* symtab update 2020-10-13 08:38:17 +02:00
Jakub Konka
fc660af077 Update allocateTextBlock to use node free list 2020-10-13 08:38:17 +02:00
Jakub Konka
78ec7b671d Add mechanism for growing/shrinking text blocks 2020-10-13 08:38:17 +02:00
Jakub Konka
0b77152faa Add local and offset free lists 2020-10-13 08:38:17 +02:00
Andrew Kelley
ea45ee5484 cmake: remove all the LLVM 10 workarounds 2020-10-12 22:35:06 -07:00
Andrew Kelley
9e05f42fee ci: macos: set the cross compile cmake option
This should avoid invoking llvm-config to work around a symbol
not found inside libstdc++, and plus it's technically more correct
anyway.
2020-10-12 22:32:14 -07:00
Andrew Kelley
92926c4331 ci: no space in vmImage I guess 2020-10-12 21:58:46 -07:00
Andrew Kelley
461792f9de ci: update to macos 10.15 image 2020-10-12 21:53:13 -07:00
Andrew Kelley
68e6da7c00 CI: enable all the freebsd tests 2020-10-12 20:51:16 -07:00
Andrew Kelley
27b04d5905 disable the failing std lib freebsd tests
enable std lib freebsd tests on the CI

See #1759
2020-10-12 20:08:23 -07:00
Andrew Kelley
74e3ffa9b4 ci: update llvm 10 => 11 2020-10-12 18:38:28 -07:00
Andrew Kelley
c19dcafa17 Merge remote-tracking branch 'origin/master' into llvm11 2020-10-12 17:57:35 -07:00
Vignesh Rajagopalan
2ab0c7391a Rename .macosx to .macos 2020-10-12 18:56:25 -04:00
Rocknest
39841d5e2c remove workaround 2020-10-12 15:18:50 +03:00
kprotty
12508025a4 Add more comments & cleanup AutoResetEvent 2020-10-11 19:16:07 -05:00
kprotty
e9a4c3dd82 fix DelayQueue typos 2020-10-11 14:21:36 -05:00
kprotty
aa53f6d0b5 integrate std.time.sleep with the event loop 2020-10-11 14:18:19 -05:00
kprotty
a42c0f88e0 AutoResetEvent 2020-10-11 14:17:51 -05:00
Rocknest
47d7bf1a0e add a test for Version.parse 2020-10-11 16:30:51 +03:00
Rocknest
cd4200ccef make Version.parse less strict 2020-10-11 16:29:19 +03:00
Sébastien Marie
161eb4a000 initialize std.os.argv in stage1 compiler. it is needed for selfExePath under OpenBSD 2020-10-11 12:25:16 +00:00
Sébastien Marie
a6dc2b7fcc openbsd: selfExePath adjustements 2020-10-11 12:23:52 +00:00
Sébastien Marie
4c4211ea8e merge netbsd and openbsd cases 2020-10-11 10:22:28 +00:00
Sébastien Marie
9ff51f22b4 openbsd: address link/Elf.zig comments
- restore correct behaviour on Android target for appending "crtend_android.o"
- some nits
2020-10-11 10:12:40 +00:00
Sébastien Marie
97ec9fdd79 opensd: selfExePath: do not rely on environment as it could be inherited 2020-10-11 08:23:37 +00:00
Sébastien Marie
78a7543056 openbsd: use mem.span() + mem.indexOf() instead of defining custom function 2020-10-11 08:23:37 +00:00
Sébastien Marie
f33a610c84 add minimal openbsd support 2020-10-11 08:23:36 +00:00
Frank Denis
9f109ba0eb Simpler ChaCha20 vector code 2020-10-10 22:45:41 +02:00
Frank Denis
459128e059 Use an array of comptime_int for shuffle masks
Suggested by @LemonBoy - Thanks!
2020-10-10 22:45:41 +02:00
Frank Denis
9b386bda33 std/crypto: add a vectorized ChaCha20 implementation
Brings a 30% speed boost on x86_64 even though we still process only
one block at a time for now.

Only enabled on x86_64 since the non-vectorized implementation seems
to currently perform better on some architectures (at least on aarch64).

But the non-vectorized implementation still gets a little speed boost
as well (~17%) with these changes.
2020-10-10 22:45:41 +02:00
Jakub Konka
53c63bdb73 Update WASI preopens doc section to use GPA
Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-10-10 20:07:16 +02: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
LemonBoy
a31b70c4b8 std: Add/Fix/Change parts of big.int
* Add an optimized squaring routine under the `sqr` name.
  Algorithms for squaring bigger numbers efficiently will come in a
  PR later.
* Fix a bug where a multiplication was done twice if the threshold for
  the use of Karatsuba algorithm was crossed. Add a test to make sure
  this won't happen again.
* Streamline `pow` method, take a `Const` parameter.
* Minor tweaks to `pow`, avoid bit-reversing the exponent.
2020-10-09 22:16:48 -04:00
Andrew Kelley
fbc6a00b0a Merge branch 'mlarouche-Fix_6500' 2020-10-09 16:49:05 -07:00
Andrew Kelley
9f8f446435 fixups to previous commit
* std.fs.Dir.readFile: add doc comments to explain what it means when
   the returned slice has the same length as the supplied buffer.
 * introduce readSmallFile / writeSmallFile to abstract over the
   decision to use symlink or file contents to store data.
2020-10-09 16:45:39 -07:00
mlarouche
57912964af Use regular file for caching stage 1 hash digest instead of symlink, fix zig build caching on Windows
Fix #6500
2020-10-09 16:50:43 -04:00
Jakub Konka
04b0ffdd13 Merge pull request #6577 from kubkon/macho-trie
stage2: add export trie generation in MachO linker
2020-10-09 17:41:52 +02:00
Jakub Konka
8dc4023615 Apply nitpick: top-level doc comments
Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-10-09 17:40:37 +02:00
Josh Wolfe
bc6904eccc include compiler_rt and c for wasm static libraries 2020-10-09 01:54:42 -04:00
Andrew Kelley
1951ecb228 add a code of conduct
this has always been the rules, they are just written down now.

also link to ziglearn.org in the readme
2020-10-08 22:48:16 -07:00
Andrew Kelley
a4828f6d0f std.c (darwin) update to new opaque syntax
This was an undetected conflict between

76a195473d and
95a37373e9
2020-10-08 22:45:39 -07:00
Andrew Kelley
76a195473d Merge pull request #6516 from LemonBoy/fastfilecopy
std: Make file copy ops use zero-copy mechanisms
2020-10-08 20:14:47 -04:00
Andrew Kelley
4053b95d8e run update_clang_options on llvm 11 rc6 2020-10-08 16:13:37 -07:00
Andrew Kelley
8b7539bd95 Merge remote-tracking branch 'origin/master' into llvm11
Conflicts:
  src/clang.zig

Master branch renamed an enum; this branch gave it an explicit tag type
and explicitly initialized values. This commit combines the changes
together.
2020-10-08 15:47:45 -07:00
Andrew Kelley
b02341d6f5 Merge pull request #6614 from jedisct1/aes-arm
std/crypto/aes: add AES hardware acceleration on aarch64
2020-10-08 18:09:40 -04:00
Frank Denis
1bc2b68916 ghash: add pmull support on aarch64 2020-10-08 18:09:23 -04:00
Benjamin Feng
9de0f15b8e Rename ix_rss -> ixrss 2020-10-08 15:31:36 -05:00
Benjamin Feng
fd3f676cdb Pull in Darwin definitions for rusage 2020-10-08 15:19:52 -05:00
Jakub Konka
ba41e599bf Clean up writing the trie into ULEB128 byte stream
Prealloc as much as possible to improve alloc performance.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-10-08 19:53:23 +02:00
Jakub Konka
5f86505cf7 Fix ULEB128 encoding of trie
Use algorithm described in official Apple `ld64` implementation.
Link: https://opensource.apple.com/source/ld64/ld64-123.2.1/src/abstraction/MachOTrie.hpp

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-10-08 19:53:03 +02:00
Frank Denis
60d1e675d2 aes/aesni is not based on a Go implementation, only aes/soft is
Don't blame them for our bugs :)
2020-10-08 14:55:11 +02:00
Frank Denis
f39dc00ed4 std/crypto/aes: add AES hardware acceleration on aarch64 2020-10-08 14:55:08 +02:00
Tadeo Kondrak
83eda21488 zig_clang/translate_c: Use opaque declarations in Zig 2020-10-08 12:29:59 +03:00
Tadeo Kondrak
0e57f220fb stage1: Disallow arrays in function parameters or return types
Closes #6535.
2020-10-08 04:17:32 -04:00
xavier
eb33394d14 notice more kinds of optimization flags and debug flags
Closes #6091
2020-10-07 18:43:05 -04:00
Jakub Konka
ea44d12d1b Add writeULEB128Mem test and couple fixes
Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-10-07 23:54:51 +02:00
xavier
a0a834a2f2 restore ability to do comptime math
until https://github.com/ziglang/zig/issues/6168 is implemented,
partially revert 0bd53dd203
in order to restore the ability to use std.math in comptime functions.
2020-10-07 17:04:48 -04:00
Andrew Kelley
95a37373e9 Merge pull request #6421 from tadeokondrak/opaque-syntax
Add opaque syntax that allows declarations
2020-10-07 16:58:50 -04:00
Andrew Kelley
3c43eeceab Merge pull request #6595 from tadeokondrak/comptime-print-0
std.fmt.comptimePrint: Return null terminated string
2020-10-07 16:55:03 -04:00
Jakub Konka
b5b25d38a8 Fix improper reuse of global symbols in MachO
Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-10-07 20:34:40 +02:00
Jakub Konka
bdab4f53c1 Move trie structure into its own file-module
Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-10-07 20:34:34 +02:00
Jakub Konka
b13b36a71d Approach using array list for auto mem mgmt
Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-10-07 20:33:47 +02:00
Jakub Konka
e76fb8d8c8 Add incomplete writing of trie to bytes buffer
Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-10-07 20:33:28 +02:00
Tadeo Kondrak
e9bca9de3c std.fmt.comptimePrint: Properly null-terminate result and add test 2020-10-07 11:43:23 -06:00
Jakub Konka
f0a73df8e7 Add prototype for export trie generation in MachO linker
Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-10-07 18:31:02 +02:00
Jakub Konka
07c33dfc95 Remove obsolete addPadding fn and callsites from MachO linker
This is no longer needed due to the way writing to the output
file is structured.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-10-07 17:18:37 +02:00
LemonBoy
03762da2af New review round 2020-10-07 11:13:26 +02:00
Loris Cro
53dee08af9 add WaitGroup to std.event
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-10-07 04:34:09 -04:00
Tadeo Kondrak
0a6863a267 Remove .Cold calling convention.
This isn't a stable, defined calling convention, so it shouldn't be
grouped in with the others.

Closes https://github.com/ziglang/zig/issues/6556
2020-10-07 04:31:20 -04:00
pfg
ae161863db stage1: improve error messages for missing try statements 2020-10-07 03:50:11 -04:00
Andrew Kelley
b5a36f676b Merge remote-tracking branch 'origin/master' into llvm11
Conflicts:
  cmake/Findllvm.cmake

The llvm11 branch changed 10's to 11's and master branch added the
"using LLVM_CONFIG_EXE" help message, so the resolution was to merge
these changes together.

I also added a check to make sure LLVM is built with AVR enabled, which
is no longer an experimental target.
2020-10-07 00:46:05 -07:00
Andrew Kelley
f2d374e846 Merge branch 'FireFox317-fix-32-bit-target' 2020-10-07 00:42:58 -07:00
Andrew Kelley
b2b0bf0506 fixups for the previous commit
* std.fs.File.copyRange and copyRangeAll return u64 instead of usize -
   the returned value is how much of the `len` is transferred, so the
   types should match. This removes the need for an `@intCast`.
 * fix typo that removed a subtraction
 * Fix the size of codegen.AnyMCValue which gave me a compile error when
   I tried to build self-hosted for i386-linux.
 * restore the coercion to u64 of syms_sect.sh_info. We want to make
   sure the multiplication happens with 64 bits and not the smaller type
   used by the ELF format.
 * fix another offset parameter in link/Elf.zig to be u64 instead of usize
 * add a nice little TODO note to help out Jakub
 * FmtError already has FileTooBig in it; we just need to return it.
2020-10-07 00:39:13 -07:00
Timon Kruiper
bd7eab573a Fix building the zig compiler for 32-bit targets 2020-10-06 23:39:58 -07:00
Noam Preil
7d69e1d84e Rename variables in resolvePeerTypes for clarity 2020-10-07 02:36:04 -04:00
Noam Preil
de093879cc Fix peer type resolution 2020-10-07 02:31:47 -04:00
Tadeo Kondrak
49e68bdcf3 std.fmt.comptimePrint: Return null terminated string 2020-10-06 22:21:06 -06:00
Tadeo Kondrak
bf4bfe54ac Update compile error test for field access of opaque type 2020-10-06 22:08:30 -06:00
Tadeo Kondrak
6b8ae6fffb langref: update for opaque {} syntax 2020-10-06 22:08:29 -06:00
Tadeo Kondrak
0a56390230 stage1: use size_t over int as index in resolve_opaque_type 2020-10-06 22:08:28 -06:00
Tadeo Kondrak
d71f339395 stage1: disallow fields in opaque types 2020-10-06 22:08:27 -06:00
Tadeo Kondrak
d5b8172a82 translate_c: emit opaque {} instead of @Type(.Opaque) 2020-10-06 22:08:26 -06:00
Tadeo Kondrak
2b4b03d301 Update zig files for opaque type syntax 2020-10-06 22:08:25 -06:00
Tadeo Kondrak
069fbb3c01 Add opaque type syntax 2020-10-06 22:08:24 -06:00
Timon Kruiper
d6d05fc84d Update the list of libraries that llvm11 uses 2020-10-06 20:07:40 -04:00
Frank Denis
fb63a2cfae std/crypto: faster (mod 2^255-19) square root computation
251 squarings, 250 multiplications -> 251 squarings, 11 multiplications
2020-10-06 19:48:26 -04:00
travisstaloch
dd4771a5d2 cache-hash: add test_filter and test_name_prefix (#6583) 2020-10-06 19:36:14 -04:00
LemonBoy
87807d53dd stage2: Fix arg processing for zig run
* Stop parsing arguments after `--`
* Calculate the correct index for the first argument after `--`
2020-10-06 19:31:57 -04:00
Noam Preil
7b88215a49 Replace error message with unreachable 2020-10-06 15:09:57 -04:00
Noam Preil
a2e1639d6d Peer type resolution: comptime_int decay to other int 2020-10-06 15:09:57 -04:00
Noam Preil
ea7b2750c8 CBE: addition and subtraction 2020-10-06 15:09:57 -04:00
Noam Preil
e06ba9e86e CBE: properly resolve Insts 2020-10-06 15:09:57 -04:00
Noam Preil
9ef6c0a035 CBE: utilize per-function arena allocator 2020-10-06 15:09:56 -04:00
Noam Preil
9979719a9d Stage2 peer type resolution: comptime_int + other_int_type 2020-10-06 15:09:56 -04:00
Noam Preil
ce29fc0947 Make indentation adjustable (hardcode 4 spaces for now) 2020-10-06 15:09:56 -04:00
LemonBoy
1f7ec0de70 Address review comments & fix compilation errors 2020-10-06 11:57:23 +02:00
LemonBoy
a419a1aabc Move copy_file to fs namespace
Now it is a private API.
Also handle short writes in copy_file_range fallback implementation.
2020-10-06 09:38:59 +02:00
Vexu
58502b8bfe translate-c: respect C operator precedence in macros 2020-10-05 22:26:11 -04:00
Noah Altunian
c507c7862e Fix spelling in code comment
Changed **an handle** -> **a handle**.
2020-10-05 22:25:07 -04:00
Andrew Kelley
41aa5edaaf Merge pull request #6580 from jedisct1/aesgcm
std/crypto: Add support for AES-GCM
2020-10-05 22:20:29 -04:00
Timon Kruiper
75db8d9e2c Fix cross-compiling the zig compiler
zig0 is only used for building objects, thus it has no options like
`build-exe/obj`. But when cross-compiling, we have a working zig
compiler on the host, thus we need to pass `build-obj` to the zig compiler.
2020-10-05 22:18:42 -04:00
Isaac Freund
0741505d6d std/zig: handle underscore in kernel version
On some distros (e.g. Void Linux) the release field of the tsname
struct may contain an underscore followed by a revision number at the
end. (e.g. 5.8.12_2).
2020-10-05 22:17:28 -04:00
LemonBoy
dbc11be038 std: Fix two bugs in bigint pow
* Correctly scan all the exponent bits, this caused the incorrect result
  to be computed for exponents being powers of two.
* Allocate enough limbs to make llmulacc stop whining.
2020-10-05 22:16:26 -04:00
Frank Denis
06c16f44e7 std/crypto: Add support for AES-GCM
Already pretty fast on platforms with AES-NI, even though GHASH
reduction hasn't been optimized yet, and we don't do stitching either.
2020-10-06 00:00:33 +02:00
Frank Denis
d343b75e7f ghash & poly1305: fix handling of partial blocks and add pad()
pad() aligns the next input to the first byte of a block, which is
useful to implement the IETF version of ChaCha20Poly1305 and AES-GCM.
2020-10-05 23:50:38 +02:00
Andrew Kelley
7f7e2d608a Revert "revert adding std.event.Loop.runDetached"
This reverts commit 70f3767903.

After discussion, I can see the value provided here, specifically with
avoiding the footgun of defer { suspend { free(@frame()); } }.

However the doc comments are updated to explain the semantics directly,
rather than basing them on the behavior of another programming language.
2020-10-05 14:41:51 -07:00
Andrew Kelley
939b4860ef Merge pull request #6472 from alexnask/add_some_frees
Add a few missing deallocations of temporaries to stage1
2020-10-05 04:56:58 -04:00
LemonBoy
22b5e47839 stage1: Implement @reduce builtin for vector types
The builtin folds a Vector(N,T) into a scalar T using a specified
operator.

Closes #2698
2020-10-05 04:51:45 -04:00
joachimschmidt557
7c5a24e08c Turn zig fmt back on in various src/ files 2020-10-05 04:48:58 -04:00
Alexandros Naskos
9952a072cc Remove MSVC 2015 from supported compilers in README 2020-10-05 03:55:41 -04:00
Joran Dirk Greef
e9ba12f456 Test the range of user_data bits 2020-10-05 09:36:07 +02:00
Andrew Kelley
55ac973953 fix each-lib-rpath functionality
It was regressed in 2 ways from the merge of #6250:
 * it was not being enabled by default when the target OS is native.
 * we were testing the libfoo.so file path existence with bogus format
   string ('{}' instead of '{s}') and so it ended up being something
   like "libstd.HashMap(K,V,...).Entry.so" instead of "libfoo.so". Using
   {} rather than {s} is a footgun, be careful!

Previous functionality is now restored.

closes #6523
2020-10-04 23:16:46 -07:00
Andrew Kelley
d5d48c6f4e Merge pull request #6496 from xackus/rlimit
std: implement {get, set}rlimit for linux
2020-10-05 01:54:38 -04:00
Andrew Kelley
682a29aefd ci: stop testing mingw builds
Zig supports both Linux and Windows natively. Those are the main use
cases we are focusing on. Happy to accept mingw patches if they are
non-invasive, but we will not be hampering progress on the main use
cases with failing mingw CI builds.
2020-10-04 21:51:41 -07:00
Timon Kruiper
e94a06ac29 Build.zig: Skip copying files that are used internally by the compiler
Before this it was trying to copy all the files from the zig-cache dir
to the output dir, but in the current compiler architecture the cache
dir is also used for internal compiler files.
2020-10-05 00:31:21 -04:00
Felix (xq) Queißner
dce74c31cc Depending on system libs only enforces libraries to require dynamic linking, but neither static libs nor object files. 2020-10-05 00:27:42 -04:00
Andrew Kelley
33bc1ebe37 build system: implement computeOutFilenames using std.zig.binNameAlloc
See #6552 #6553 #6483

Also fixes a regression introduced in
1d777e9958 of not converting an integer to
a string for a command line parameter.
2020-10-04 20:10:47 -07:00
Jan200101
d0a4110d34 Allow specifying build version using cmake 2020-10-04 21:40:48 -04:00
Alexandros Naskos
65991092f7 Correctly set uid and gid to void instead of null on wasi 2020-10-04 21:21:25 -04:00
Andrew Kelley
1d777e9958 add --image-base support
Based on #6121 by Jay Petacat.
2020-10-04 17:59:44 -07:00
Andrew Kelley
da596b7e4f Merge pull request #6255 from joachimschmidt557/stage2-arm
stage2 ARM: more instructions, return values, parameters
2020-10-04 19:49:18 -04:00
Andrew Kelley
6aa668e020 Merge pull request #6476 from kubkon/macho-exe
Link basic MachO executables with stage2
2020-10-04 19:05:45 -04:00
Andrew Kelley
302a69f127 Merge pull request #6295 from Vexu/stage2
Stage2: basic imports
2020-10-04 18:00:21 -04:00
xackus
1b4296831a simplify api and add smoke test 2020-10-04 23:57:49 +02:00
xackus
4ec26be424 implement {get, set}rlimit for linux 2020-10-04 23:56:10 +02:00
Joran Dirk Greef
9be2941091 Split openat/close test into two separate tests
If an older kernel fails the `openat` test because of `AT_FDCWD`
then we don't want to skip the `close` test.
2020-10-04 17:48:05 +02:00
Joran Dirk Greef
958ff087f2 Use const wherever possible 2020-10-04 16:57:04 +02:00
Joran Dirk Greef
72bdfa5bdd Skip openat test only for older kernels that do not fully support AT_FDCWD 2020-10-04 16:05:52 +02:00
Jakub Konka
c4054f8e0a Refactor flushing of MachO exe
This commit refactors free space analysis (and VM analysis) somewhat.
This is still far from perfect, but at least it's not using any
hardcoded values.

This commit also reorganizes different flushing bits here and there,
so that bit common to Exe and Obj are put in the common path, while
Exe-specific are behind an appropriate switch/if statement.
2020-10-04 15:31:47 +02:00
Jakub Konka
737a8bf204 Redo local symbols and offsets tracking to match Elf's approach 2020-10-04 15:31:47 +02:00
Jakub Konka
2ba23abd9d Add missing ensureCapacity call in codegen 2020-10-04 15:31:47 +02:00
Jakub Konka
f8dd48bcd2 Fix after rebase and enable stage2 tests for macOS
Also, rewrites codegen section to store symbol address in a register
to then later invoke `callq` on the register.
2020-10-04 15:31:47 +02:00
Jakub Konka
5a7105401c First hacked together, working MachO exe! 2020-10-04 15:31:47 +02:00
Jakub Konka
635984abc7 Move writing symbol table and export trie into functions 2020-10-04 15:31:47 +02:00
Jakub Konka
ccf9bba61f Write out LC_DYSYMTAB together with dyld_stub_binder undef symbol 2020-10-04 15:31:47 +02:00
Jakub Konka
a927f24201 Generate more MachO exe boilerplate
* Convert draft to generate all relevant segments and sections in right places
* Do not prealloc space in text blocks until we can NOP
* Write out LC_LOAD_DYLINKER command
* Add LC_LOAD_DYLIB command in order to specify to load libSystem
* Redo update decl exports (similar to Elf globals, globals need to be contiguous in
  memory)
2020-10-04 15:31:47 +02:00
Jakub Konka
57a81bb559 Re-draft required elements for minimal MachO binary 2020-10-04 15:31:47 +02:00
Joran Dirk Greef
9091fcbe9d Improve openat/accept test debugging 2020-10-04 15:11:09 +02:00
Joran Dirk Greef
6a53f4be4b Add openat(), close(), connect(), send(), recv(), as well as tests
Removes non-essential .hardlink_with_next_sqe() and .drain_previous_sqes().
2020-10-04 13:15:39 +02:00
Joran Dirk Greef
3d2de6cfba Use load relaxed semantics when reading the SQPOLL wakeup flag 2020-10-04 13:14:57 +02:00
Joran Dirk Greef
69a55fc560 Allow for advanced non-sequential SQE allocation schemes
Decouples SQE queueing and SQE prepping methods to allow for non-sequential
SQE allocation schemes as suggested by @daurnimator.

Adds essential SQE prepping methods from liburing to reduce boilerplate.

Removes non-essential .link_with_next_sqe() and .use_registered_fd().
2020-10-04 13:01:41 +02:00
Joran Dirk Greef
e32c7d06e5 Limit entries to u12, add errors for invalid entries, use mem.zeroInit 2020-10-04 12:49:48 +02:00
Joran Dirk Greef
61ec6cb6d3 Expose available kernel features 2020-10-04 12:48:08 +02:00
Jakub Konka
0e2d858d69 Revert back to original Win CI install script
Since msys2/MSYS2-packages#2050 was fixed, we can now revert back to the
original install script.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-10-04 11:53:07 +02:00
Alexandros Naskos
23cd3b3331 Merge branch 'master' of https://github.com/ziglang/zig into add_some_frees 2020-10-04 10:39:26 +03:00
Andrew Kelley
8170a3d574 Merge pull request #6463 from jedisct1/ghash
std/crypto: add GHASH implementation
2020-10-04 02:46:36 -04:00
Andrew Kelley
5fda4fe4c8 Merge pull request #6454 from jedisct1/hkdf
std/crypto: implement the HKDF construction
2020-10-04 02:45:54 -04:00
LemonBoy
538d485782 std: Add pow(a,b) for big ints
Implemented following Knuth's "Evaluation of Powers" chapter in TAOCP,
some extra complexity is needed to make sure there's no aliasing and
avoid allocating too many limbs.

A brief example to illustrate why the last point is important:
consider 10^123, since 10 is well within the limits of a single limb we
can safely say that the result will surely fit in:

⌈log2(10)⌉ bit * 123 = 492 bits = 7 limbs

A naive calculation using only the number of limbs yields:

1 limb * 123 = 123 limbs

The space savings are noticeable.
2020-10-04 02:24:40 -04:00
Andrew Kelley
2de53592a1 stage1: better value for builtin.link_mode
Now it is Dynamic unless -DZIG_STATIC=on is passed to cmake.

This partially addresses #6469.
2020-10-03 23:15:45 -07:00
John Sullivan
ab7ea53541 cmake: add option to use llvm-config to find cross-target llvm deps 2020-10-04 00:41:32 -04:00
Alexandros Naskos
52ba2c3a43 Reintroduce progress bar when compiling C files 2020-10-03 22:11:29 -04:00
Tadeo Kondrak
9917b0576a stage0: check for some more required parameters 2020-10-03 21:32:32 -04:00
Tadeo Kondrak
cbdd825056 stage1: delete unused os code 2020-10-03 21:31:08 -04:00
Tadeo Kondrak
26546af1b8 Revert "Include dbg.h to third-party libs"
This reverts commit c8b4cc2ff9.

This includes many C++ standard library headers:

  #include <algorithm>
  #include <chrono>
  #include <ctime>
  #include <iomanip>
  #include <ios>
  #include <iostream>
  #include <memory>
  #include <sstream>
  #include <string>
  #include <tuple>
  #include <type_traits>
  #include <vector>

which adds more than a second of compile time for each file that
includes the header:

  ir.cpp before: 8.041s
  ir.cpp after: 6.847s
2020-10-03 21:29:29 -04:00
Andrew Kelley
d1e779cea8 ci: update azure msys base installer
hopefully resolves the CI failures
2020-10-03 17:33:51 -07:00
Andrew Kelley
b306149b22 zig run foo.c is perfectly valid 2020-10-03 17:27:09 -07:00
Andrew Kelley
a2b86777b5 fix alignment in CLI usage text 2020-10-03 17:21:45 -07:00
Andrew Kelley
0e7523c7d7 stage1 main(): catch unreachable in debug builds for easier troubleshooting
Fixup to 2a3393eff8
2020-10-03 17:16:19 -07:00
Andrew Kelley
70f3767903 revert adding std.event.Loop.runDetached
I'd like to discuss this before adding it. I think this is the wrong
direction to go with this API.
2020-10-03 17:13:22 -07:00
Alexandros Naskos
f3397fad68 Merge pull request #6519 from LemonBoy/fix-6497
stage2: Build libunwind for non-msvc Windows targets
2020-10-04 01:23:35 +03:00
LemonBoy
3b40b68210 stage2: Build libunwind for non-msvc Windows targets
Closes #6497
2020-10-03 20:47:06 +02:00
LemonBoy
8b4f5f039d Alternative strategy to avoid calling stat()
This is an optimization as it avoids an extra syscall, but it's also a
workaround for fstat being not available on Windows.
2020-10-03 19:51:22 +02:00
Joran Dirk Greef
c5b4fcaa1c Add IORING_FEAT_POLL_32BITS 2020-10-03 17:43:08 +02:00
Alexandros Naskos
4396373ccb Merge pull request #6503 from kristoff-it/fix-darwin-symlink-exe
fix symlink path not being resolved in darwin
2020-10-03 18:29:44 +03:00
Joran Dirk Greef
a9b107045f Use load acquire semantics when reading the SQPOLL wakeup flag
Ensures that the wakeup flag is read after the tail pointer has been
written. It's important to use memory load acquire semantics for the
flags read, otherwise the application and the kernel might not agree on
the consistency of the wakeup flag, leading to I/O starvation.

Refs: 6768ddcc56
Refs: https://github.com/axboe/liburing/issues/219
2020-10-03 14:34:42 +02:00
Joran Dirk Greef
95def89c23 Handle EBADFD (ring fd in bad state) in enter() 2020-10-03 14:34:01 +02:00
joachimschmidt557
fb58fb2d8d stage2 ARM: add testcases for non-leaf fns, parameters, return values 2020-10-03 12:52:04 +02:00
LemonBoy
0f248e0988 std: Make file copy ops use zero-copy mechanisms
Use copy_file_range on Linux (if available), fcopyfile on Darwin,
sendfile on *BSDs (and on Linux kernels without copy_file_range).
2020-10-03 12:31:17 +02:00
Loris Cro
276598346a provide the full buffer length to _NSGetExecutablePath
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-10-03 12:03:22 +02:00
Alexandros Naskos
e31cc80130 Merge pull request #6427 from tadeokondrak/enums-explicit-tag-type-extern-allowed
Allow enums with explicit extern-allowed tag types in extern types
2020-10-03 12:51:39 +03:00
Alexandros Naskos
b5034bd776 Merge pull request #6506 from FireFox317/stage2-cli
Print error when running `zig test/run` without a source file
2020-10-03 12:47:49 +03:00
Timon Kruiper
539e90e26d Print error when running zig test/run without a source file
Closes #6498
2020-10-02 19:59:00 +02:00
joachimschmidt557
cfe486e388 stage2 ARM: Add push, pop alias instructions; non-leaf functions
Non-leaf functions now work. Combined with simple parameters and return
types, this allows more complicated programs than Hello World to be
correctly compiled.
2020-10-02 19:39:17 +02:00
joachimschmidt557
35b228630c stage2 ARM: Add stm, ldm variants and misc. additions 2020-10-02 19:39:17 +02:00
joachimschmidt557
0a54f04dbc stage2 ARM: start adding more instructions, return values, parameters 2020-10-02 19:39:17 +02:00
Loris Cro
f841ea77e2 make symlink buffer null-terminated
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-10-02 19:33:14 +02:00
Loris Cro
a2074c1ec3 fix symlink path not being resolved in darwin
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-10-02 17:06:29 +02:00
Alexandros Naskos
e9434ff8f4 Merge pull request #6430 from jedisct1/llvm-config
Print the llvm-config path on configuration error
2020-10-02 17:02:08 +03:00
Alexandros Naskos
55eb7c16c0 Merge pull request #6494 from IridescentRose/emit-reloc-patch
Emit reloc patch
2020-10-02 17:00:47 +03:00
Alexandros Naskos
cd4c1ea790 Merge pull request #6491 from markfirmware/patch-2
Fixes --linker-script unrecognized
2020-10-02 17:00:22 +03:00
Alexandros Naskos
006b780d44 Merge pull request #6484 from LemonBoy/winshit
Some windows fixes
2020-10-02 15:05:44 +03:00
Alexandros Naskos
e207031837 Merge pull request #6402 from tadeokondrak/@Type(.Fn)
Implement @Type for Fn
2020-10-02 09:44:27 +03:00
Tadeo Kondrak
65016dff32 Add test for implicit extern-allowed enum tag type in extern struct 2020-10-01 18:10:20 -06:00
Tadeo Kondrak
cae49b1b9d Add tests for enums with explicit extern-allowed tag types in extern types 2020-10-01 18:09:47 -06:00
Tadeo Kondrak
61ce72a38c Allow enums with explicit extern-allowed tag types in extern types
Closes https://github.com/ziglang/zig/issues/1467
2020-10-01 18:09:15 -06:00
Tadeo Kondrak
183d1d4ba1 Switch TypeInfo.Fn.alignment to comptime_int from u29
All integers in TypeInfo are intentionally comptime_int:
https://github.com/ziglang/zig/issues/1683
2020-10-01 18:01:41 -06:00
Tadeo Kondrak
96a151d4b8 Skip @Type/@typeInfo Fn/BoundFn tests on wasm32/wasm64 2020-10-01 18:01:40 -06:00
Tadeo Kondrak
e18fdc12b0 stage1: Implement @Type for Fn and BoundFn 2020-10-01 18:01:38 -06:00
Tadeo Kondrak
97ab720d84 stage1: Add alignment to TypeInfo.Fn 2020-10-01 17:59:42 -06:00
Alexandros Naskos
0228887b94 Merge pull request #6428 from tadeokondrak/alignment-typeinfo-struct-union
Add alignment field to TypeInfo.UnionField and TypeInfo.StructField
2020-10-02 02:56:18 +03:00
Nathan
84b6d2a80a Resolved additional formatting issues. 2020-10-01 18:03:34 -04:00
Nathan
5e3ce11b18 Resolve name and format issues. 2020-10-01 17:47:32 -04:00
Alexandros Naskos
a4fe438d39 std.fmt.comptimePrint: bufPrint cannot return an error 2020-10-02 00:39:19 +03:00
Alexandros Naskos
49c0cd6e8e Merge pull request #6481 from MasterQ32/stage1_error_return_trace
Adds error return trace printing to stage1
2020-10-02 00:22:24 +03:00
Tadeo Kondrak
362c87f1aa Update std.meta.ArgsTuple for alignment in StructField/UnionField 2020-10-01 15:06:24 -06:00
Tadeo Kondrak
ec8f0777f2 Update std.meta.Tuple for alignment in StructField/UnionField 2020-10-01 15:06:23 -06:00
Tadeo Kondrak
e187ac09cb Update compile error tests for alignment in StructField/UnionField 2020-10-01 15:06:21 -06:00
Nathan
1bc197bc02 Merge 2020-10-01 17:06:15 -04:00
Nathan Bourgeois
4566b27373 Patch in emit relocs support 2020-10-01 17:04:04 -04:00
Tadeo Kondrak
a12203d2be Switch TypeInfo alignment fields from u29 to comptime_int 2020-10-01 15:01:28 -06:00
Tadeo Kondrak
70c507911a Update @Type tests for alignment field in UnionField and StructFIeld 2020-10-01 15:01:27 -06:00
Tadeo Kondrak
c2ee66108c Add tests for alignment field in UnionField and StructFIeld 2020-10-01 15:01:26 -06:00
Tadeo Kondrak
d81648ce8c Add alignment field to TypeInfo.UnionField and TypeInfo.StructField
Closes https://github.com/ziglang/zig/issues/6122
2020-10-01 15:01:25 -06:00
Tadeo Kondrak
77df5dae7f Make builtin.TypeInfo.Pointer.alignment u29 instead of comptime_int 2020-10-01 15:01:24 -06:00
Alexandros Naskos
5acf2a5068 Merge pull request #6419 from tadeokondrak/std.fmt.comptimePrint
std.fmt: add comptimePrint
2020-10-01 23:59:00 +03:00
Nathan Bourgeois
5c84f9dad4 Patch in emit relocs support 2020-10-01 15:57:19 -04:00
markfirmware
1296e4a857 Update build.zig 2020-10-01 15:27:08 -04:00
markfirmware
8acfcf4e0d Update build.zig
Fixes #6477
2020-10-01 13:15:35 -04:00
Alexandros Naskos
bf0afaa876 std.event.Loop.runDetached should be pub 2020-10-01 16:50:05 +03:00
Alexandros Naskos
beda6f2299 Merge pull request #6455 from kristoff-it/event-loop-go
add runDetached to event loop
2020-10-01 15:57:02 +03:00
LemonBoy
212171643c stage2: Add missing defines for building dllcrt2.o
Closes #6482
2020-10-01 11:39:22 +02:00
LemonBoy
1b2d50737a mingw: Add user32.def for 32bit Windows
Closes #6479
2020-10-01 11:27:59 +02:00
Alexandros Naskos
b358c28171 Merge pull request #6461 from tadeokondrak/type-enum-invalid-tag-type
stage1: Fix @Type(.Enum) with invalid tag_type
2020-10-01 11:19:02 +03:00
Felix (xq) Queißner
2a3393eff8 Adds error return trace printing to stage1. 2020-10-01 09:40:03 +02:00
Frank Denis
97fd0974b9 ghash: add pclmul support on x86_64 2020-10-01 02:05:11 +02:00
Frank Denis
8161de7fa4 Implement ghash aggregated reduction
Performance increases from ~400 MiB/s to 450 MiB/s at the expense of
extra code. Thus, aggregation is disabled on ReleaseSmall.

Since the multiplication cost is significant compared to the reduction,
aggregating more than 2 blocks is probably not worth it.
2020-10-01 02:05:07 +02:00
Frank Denis
f1ad94437b ghash & poly1305: use pointer to slices for keys and output 2020-10-01 02:04:30 +02:00
Frank Denis
58873ed3f9 std/crypto: add GHASH implementation
GHASH is required to implement AES-GCM.

Optimized implementations for CPUs with instructions for carry-less
multiplication will be added next.
2020-10-01 02:04:30 +02:00
Alexandros Naskos
4eb390b157 Merge pull request #6457 from Snektron/fix-arraylistunmanaged
Fix std.ArrayListUnmanaged + improve test coverage
2020-10-01 00:09:45 +03:00
Andrew Kelley
718a659773 std: skip some tests that stage1 leaks too much memory with
We can restore these when we have self-hosted available.

This is intended to address #6467
2020-09-30 12:37:00 -07:00
Alexandros Naskos
82f0ede3ad Added some c_allocator.deallocate calls 2020-09-30 19:59:49 +03:00
Vexu
6d3858dc8a stage2: use directory handles for imports 2020-09-30 18:03:10 +03:00
Alexandros Naskos
cb5d290f33 Added a few ZigList deinit calls 2020-09-30 17:09:18 +03:00
Vexu
d819da4350 stage2: support multiple files in tests 2020-09-30 17:00:57 +03:00
Vexu
e246fe0f5b stage2: detect changes in imported files 2020-09-30 17:00:55 +03:00
Vexu
e2cf2e015b stage2: struct type field access 2020-09-30 16:59:09 +03:00
Vexu
7d910b024b stage2: very basic imports 2020-09-30 16:59:08 +03:00
Vexu
20ae15917c stage2: add import builtin stub 2020-09-30 16:56:45 +03:00
Tadeo Kondrak
e903b00eec stage1: Fix @Type(.Enum) with invalid tag_type
Fixes https://github.com/ziglang/zig/issues/6459
2020-09-30 07:02:38 -06:00
Andrew Kelley
7067764ed3 Merge remote-tracking branch 'origin/master' into llvm11
The changes to install_files.h needed to put into src/libcxx.zig
2020-09-30 02:55:41 -07:00
Andrew Kelley
fe117d9961 Merge pull request #6250 from ziglang/stage2-zig-cc
move `zig cc`, `zig translate-c`, `zig libc`, main(), and linking from stage1 to stage2
2020-09-30 04:28:19 -04:00
Andrew Kelley
3249e5d952 MachO: add the same workaround for no -r LLD flag support
This is the MachO equivalent for the code added to COFF for doing the
file copy when the input and output are both just one object file.
2020-09-30 01:04:30 -07:00
Andrew Kelley
2a893efae1 fix incorrect dylib filename pattern in the previous commit 2020-09-30 00:53:55 -07:00
Andrew Kelley
870af49074 std.zig.binNameAlloc: take into account version for macos dylibs 2020-09-30 00:36:20 -07:00
Ryan Liptak
bd449b184a Add deleteDir test with exception for not-empty directory on Windows
Re-adds the test that was added and then reverted in https://github.com/ziglang/zig/pull/6397, but with the test for https://github.com/ziglang/zig/issues/5537 skipped for now since that issue is no longer fixed.
2020-09-30 02:35:17 -04:00
Andrew Kelley
14d6d07af2 fix the cli test expected string to support native path separators 2020-09-30 01:31:08 -04:00
Andrew Kelley
839bdfdc93 link.Coff: skip redundant (and invalid) copy to same path 2020-09-29 21:48:50 -07:00
Andrew Kelley
7bffa6f1fb clean up call to std.fs.rename
Thanks Ryan Liptak!
2020-09-29 21:47:37 -07:00
Andrew Kelley
1572cd4d76 different strategy to fix compiler_rt.zig and c.zig
with respect to std.builtin.link_libc.

The commit 27e008eb29 did not solve the
problem because although it got std.builtin.link_libc to be true for
compiler_rt.zig and c.zig, it had other unintentional side effects which
broke the build for -lc -target foo-linux-musl.

This commit introduces a new flag to Compilation to allow setting this
comptime flag to true without introducing other side effects to
compilation and linking.
2020-09-29 18:32:41 -07:00
Ryan Liptak
254ee89def Windows: Handle ACCESS_DENIED in DeviceIoControl
This was causing the Dir.readLink test to fail for me locally with error.Unexpected NTSTATUS=0xc0000022. Not sure if PRIVILEGE_NOT_HELD is actually possible or not.
2020-09-29 20:54:45 -04:00
Andrew Kelley
402f967ed5 move std.http to the standard library orphanage
I want to take the design of this in a different direction. I think this
abstraction is too high level. I want to start bottom-up.

std-lib-orphanage commit 179ae67d61455758d71037434704fd4a17a635a9
2020-09-29 17:40:37 -07:00
Andrew Kelley
af64fd2f42 Merge remote-tracking branch 'origin/master' into stage2-zig-cc
This merges in the revert that fixes the broken Windows build of master
branch.
2020-09-29 17:26:09 -07:00
Andrew Kelley
27e008eb29 fix not passing std.builtin.link_libc to compiler_rt.zig and c.zig
comment reproduced here:

This is so that compiler_rt and libc.zig libraries know whether they
will eventually be linked with libc. They make different decisions
about what to export depending on whether another libc will be linked
in. For example, compiler_rt will not export the __chkstk symbol if it
knows libc will provide it, and likewise c.zig will not export memcpy.
2020-09-29 17:24:21 -07:00
Andrew Kelley
f69650a478 update wasm to use ".o.wasm" extension for objects
This is convenient for debugging purposes, as well as simplifying the
caching system since executable basenames will not conflict with their
corresponding object files.
2020-09-29 17:01:05 -07:00
Frank Denis
d75d6e7f77 Remove unused var, sort std.crypto.* 2020-09-30 01:39:55 +02:00
Frank Denis
6eaba61ef5 std/crypto: implement the HKDF construction 2020-09-30 01:39:55 +02:00
Andrew Kelley
d1cea16f5c move std.BloomFilter to the standard library orphanage 2020-09-29 16:39:05 -07:00
Jakub Konka
bb636cb3bf Revert "Fix for Windows: std.os.windows.DeleteFile()" 2020-09-29 19:35:44 -04:00
Andrew Kelley
63685190da move std.rb to the standard library orphanage
https://github.com/ziglang/std-lib-orphanage/

This code is not used by anything else in the standard library or by the
compiler or any of its tools and therefore it's a great candidate
to be maintained by a third party.
2020-09-29 16:01:51 -07:00
Andrew Kelley
b811a99af9 Merge remote-tracking branch 'origin/master' into stage2-zig-cc 2020-09-29 14:53:48 -07:00
Andrew Kelley
0da7c4b0c8 improve stage2 COFF LLD linking
* change some {} to be {s} to gain type safety
 * fix libraries being libfoo.lib instead of foo.lib for COFF
 * when linking mingw-w64, add the "always link" libs so that we
   generate DLL import .lib files for them as the linker code relies on.
 * COFF LLD linker does not support -r so we do a file copy as an
   alternative to the -r thing that ELF linking does.
   I will file an issue for the corresponding TODO upon merging this
   branch, to look into an optimization that possibly elides this copy
   when the source and destination are both cache directories.
 * add a CLI error message when trying to link multiple objects into one
   and using COFF object format.
2020-09-29 14:48:12 -07:00
Andrew Kelley
56c5b665a1 Merge pull request #6448 from LemonBoy/some-vec-fixes
Some vector fixes
2020-09-29 15:19:09 -04:00
Andrew Kelley
a1ae3f92c1 Merge pull request #6442 from jedisct1/aegis
std/crypto: add the AEGIS AEADs
2020-09-29 15:18:06 -04:00
Andrew Kelley
65b03092e3 Merge pull request #6450 from jedisct1/gimli-opt
std/crypto: make Gimli 60% faster
2020-09-29 15:16:52 -04:00
Andrew Kelley
7c0ee42385 CI: TERM=dumb to source hut 2020-09-29 12:10:38 -07:00
Andrew Kelley
d8fa8b5455 use Allocator.allocSentinel now that the stage1 bug is fixed
Thanks @LemonBoy!
2020-09-29 12:06:35 -07:00
Robin Voetter
4102ba37dd Fix std.ArrayListUnmanaged + improve test coverage 2020-09-29 19:49:13 +02:00
Alexandros Naskos
3b478631fb Merge pull request #6415 from MasterQ32/args-tuple
Implements std.meta.ArgsTuple.
2020-09-29 20:28:56 +03:00
Frank Denis
8d67f15d36 aegis: add test vectors, and link to the latest version of the spec 2020-09-29 17:10:04 +02:00
Frank Denis
bb1c6bc376 Add AEGIS-256 as well 2020-09-29 17:10:04 +02:00
Frank Denis
9f274e1f7d std/crypto: add the AEGIS128L AEAD
Showcase that Zig can be a great option for high performance cryptography.

The AEGIS family of authenticated encryption algorithms was selected for
high-performance applications in the final portfolio of the CAESAR
competition.

They reuse the AES core function, but are substantially faster than the
CCM, GCM and OCB modes while offering a high level of security.

AEGIS algorithms are especially fast on CPUs with built-in AES support, and
the 128L variant fully takes advantage of the pipeline in modern Intel CPUs.

Performance of the Zig implementation is on par with libsodium.
2020-09-29 17:10:04 +02:00
Alexandros Naskos
d27a34f05c Merge branch 'master' into args-tuple 2020-09-29 16:19:44 +03:00
Alexandros Naskos
3342e28784 Merge pull request #6416 from MasterQ32/meta-tuple
Implements std.meta.Tuple(), implements #4607 in userland.
2020-09-29 15:59:27 +03:00
Alexandros Naskos
c98d55626d Merge pull request #6453 from kristoff-it/fix-futures
Fix std.event.Future
2020-09-29 15:56:21 +03:00
Loris Cro
16f0419700 add runDetached to event loop
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-09-29 14:53:36 +02:00
Frank Denis
56d820087d gimli: make permute a constant, remove leading underscore 2020-09-29 14:01:08 +02:00
Frank Denis
4194714965 Don't unroll the gimli permutation on release-small 2020-09-29 13:23:04 +02:00
Loris Cro
a45a4230bc Fix std.event.Future
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-09-29 11:18:35 +02:00
Andrew Kelley
3efdd7b2ad don't try to build musl crti.o crtn.o when it's not needed
such as on RISC-V
2020-09-29 01:30:35 -07:00
Frank Denis
613f8fe83f Use mem.copy() instead of manual iterations 2020-09-29 10:23:00 +02:00
Andrew Kelley
d3a99c7bd5 add CLI options for darwin frameworks and -ffunction-sections
and add missing usage help text
2020-09-29 00:50:20 -07:00
Andrew Kelley
cfbcb41160 stage2: add CLI option for -fstack-report 2020-09-29 00:34:53 -07:00
Andrew Kelley
750b00c642 Merge remote-tracking branch 'origin/master' into stage2-zig-cc 2020-09-29 00:27:48 -07:00
Andrew Kelley
fa6d150441 stage2: MachO LLD Linking 2020-09-29 00:26:18 -07:00
Andrew Kelley
41f6627521 stage2: infer --strip on wasm builds 2020-09-29 00:25:48 -07:00
Andrew Kelley
af6c3a3934 mingw: better -D arg for processing def.in files
Thanks @LemonBoy
2020-09-29 00:24:54 -07:00
Andrew Kelley
9d0da1612e langref: use general purpose allocator in the wasi example 2020-09-29 00:24:17 -07:00
Andrew Kelley
ed06a78f35 stage2: WASM LLD linking 2020-09-28 23:20:14 -07:00
Andrew Kelley
73167e80f8 stage2: fix Cache not calling ftruncate in writeManifest
this led to a corrupt cache when the number of files got smaller. it is
now fixed.
2020-09-28 22:40:50 -07:00
Andrew Kelley
ef9582a1ec zig test and zig run do not try to run foreign binaries 2020-09-28 22:19:00 -07:00
Andrew Kelley
29fd130093 std.ChildProcess: bypass libc exit() in fork child error case
Comment reproduced here:

If we're linking libc, some naughty applications may have
registered atexit handlers which we really do not want to
run in the fork child. I caught LLVM doing this and it
caused a deadlock instead of doing an exit syscall. In
the words of Avril Lavigne, "Why'd you have to go and
make things so complicated?"
2020-09-28 22:17:50 -07:00
Andrew Kelley
5fed42d70a the stage1 backend cache stores inferred link libs
So that we properly learn about extern "foo" functions called even when
we get a stage1 cache hit.
2020-09-28 20:55:52 -07:00
Andrew Kelley
ada19c498d stage2: building DLL import lib files 2020-09-28 19:20:58 -07:00
Andrew Kelley
412a2f966e store stage1 flags in a trailing byte in the hash id symlink
When we get a cache hit for a stage1 compilation, we need to know about
some of the flags such as have_winmain or have_dllmain to know which
subsystem to infer during linking.

To do this, we append a hex-encoded byte into the intentionally-dangling
symlink which contains the cache hash digest rather than a filename. The
hex-encoded byte contains the flags we need to infer the subsystem
during linking.
2020-09-28 15:42:09 -07:00
Frank Denis
868a46eb43 std/crypto: make gimli slightly faster
Before:
       gimli-hash:        120 MiB/s
       gimli-aead:        130 MiB/s

After:
       gimli-hash:        195 MiB/s
       gimli-aead:        208 MiB/s

Also fixes in-place decryption by the way.

If the input & output buffers were the same, decryption used to fail.

Return on decryption error in the benchmark to detect similar issues
in future AEADs even in non release-fast mode.
2020-09-29 00:29:20 +02:00
Andrew Kelley
a0c0f9ead5 Merge pull request #6441 from kprotty/lock
New std.event.Lock implementation
2020-09-28 17:30:36 -04:00
LemonBoy
5c6cd5e2c9 stage{1,2}: Fix parsing of range literals
stage1 was unable to parse ranges whose starting point was written in
binary/octal as the first dot in '...' was incorrectly interpreted as
decimal point.

stage2 forgot to reset the literal type to IntegerLiteral when it
discovered the dot was not a decimal point.

I've only stumbled across this bug because zig fmt keeps formatting the
ranges without any space around the ...
2020-09-28 14:16:26 -04:00
LemonBoy
cbbcf60968 stage1: Allow comparison with comptime-known vectors
Since comptime_{int,float} vectors are not allowed (thanks $DEITY) we
can use the element type infos to determine the minimum operand size.
2020-09-28 17:16:57 +02:00
LemonBoy
56b52dd0a3 stage1: Detect OOB access of vector value
Fixes #5710
2020-09-28 17:16:12 +02:00
kprotty
468a4bf0b4 address some review changes 2020-09-28 07:25:51 -05:00
Felix (xq) Queißner
c2d60bc5b5 Follows @tadeokondrak remark about taking []const type. 2020-09-28 12:24:22 +02:00
Felix (xq) Queißner
55dfe729b4 Changes comptime block to test. 2020-09-28 11:44:55 +02:00
Felix (xq) Queißner
9331466998 Changes comptime block to test. 2020-09-28 11:42:39 +02:00
Andrew Kelley
91a73a177b stage2: building mingw-w64 and COFF LDD linking
still TODO is the task of creating import .lib files for DLLs on the fly
both for -lfoo and for e.g. `extern "kernel32"`
2020-09-28 00:06:06 -07:00
Jakub Konka
e60939bfaa Merge pull request #6397 from suirad/fix-5537
Fix for Windows: std.os.windows.DeleteFile()
2020-09-27 21:59:29 +02:00
kprotty
a31d9f92f2 new std.event.Lock implementation 2020-09-27 14:05:38 -05:00
Andrew Kelley
8794ce6f79 Merge pull request #6293 from LakeByTheWoods/fmt_fixes
zig fmt fixes
2020-09-27 05:49:38 -04:00
Ian Simonson
eab51b7785 Make LinearFifo not crash when discarding from empty buffer
Previously if a LinearFifo was empty and discard was called
an unsigned overflow would occur. However it is safe to perform
this overflow as a bitwise & operation with 0xFFFFFFFFFFFFFF is a noop
2020-09-27 05:46:39 -04:00
Woze Parrrot
ed357f9897 uefi system_table 2020-09-27 03:15:18 -04:00
Andrew Kelley
a9082b4ec5 stage2: add CLI support for --subsystem 2020-09-26 22:37:19 -07:00
daurnimator
4786eaedda test/standalone/cat: use fifo.pump() 2020-09-27 15:06:44 +10:00
daurnimator
cffab89730 test/standalone/cat: fix leaks 2020-09-27 15:06:31 +10:00
daurnimator
ed5c778c10 test/standalone/cat: update to new std library 2020-09-27 15:00:41 +10:00
daurnimator
a1abbb8eac std: add LinearFifo(...).pump(src_reader, dest_writer) 2020-09-27 14:43:44 +10:00
Andrew Kelley
4b403c7eac fix non-ELF linkAsArchive 2020-09-26 21:23:12 -07:00
Andrew Kelley
b6556c944b fix another round of regressions in this branch
* std.log: still print error messages in ReleaseSmall builds.
   - when start code gets an error code from main, it uses std.log.err
     to report the error. this resulted in a test failure because
     ReleaseSmall wasn't printing `error: TheErrorCode` when an error
     was returned from main. But that seems like it should keep working.
     So I changed the std.log defaults. I plan to follow this up with a
     proposal to change the names of and reduce the quantity of the
     log levels.
 * warning emitted when using -femit-h when using stage1 backend; fatal
   log message when using -femit-h with self-hosted backend (because the
   feature is not yet available)
 * fix double `test-cli` build steps in zig's build.zig
 * update docgen to use new CLI
 * translate-c uses `-x c` and generates a temporary basename with a
   `.h` extension. Otherwise clang reports an error.
 * --show-builtin implies -fno-emit-bin
 * restore the compile error for using an extern "c" function without
   putting -lc on the build line. we have to know about the libc
   dependency up front.
 * Fix ReleaseFast and ReleaseSmall getting swapped when passing the
   value to the stage1 backend.
 * correct the zig0 CLI usage text.
 * update test harness code to the new CLI.
2020-09-26 21:03:38 -07:00
Andrew Kelley
fe4c348f57 stage2: zig translate-c supports --enable-cache
This matches master branch behavior and makes the test-translate-c tests
pass.
2020-09-26 16:48:02 -07:00
Andrew Kelley
26f2f9bf1c stage2: implement -fno-emit-bin
we are now passing the cli tests
2020-09-26 12:42:07 -07:00
Andrew Kelley
9b83112a1f fix _fbsd suffix appended to lld LDM option twice 2020-09-26 11:26:46 -07:00
Frank Denis
99c5d2d590 Print the llvm-config path on configuration error
This is helpful on systems with multiple LLVM installations.

For example, OpenBSD ships with LLVM in the base system, but without
support for extra targets.

A full LLVM version can be installed using the ports system, but even
when it is, `cmake` is not going to pick it up unless `/usr/local` is
explicitly added to the `cmake` search paths.

Having the full `llvm-config` path printed on error is helpful to
understand that the detected LLVM version was not the expected one.
2020-09-26 17:10:33 +02:00
Andrew Kelley
a23b1b4254 stage2: building musl: fix typo in replacing path separators 2020-09-26 02:34:57 -07:00
Andrew Kelley
1337f0bc6a move to stage1-specific cache manifest emission of extra stuff 2020-09-26 02:34:18 -07:00
Andrew Kelley
56086d11a4 stage0: update CLI to match stage2 2020-09-26 02:16:10 -07:00
Andrew Kelley
819625d274 fix logic for choosing when dynamic linking is required
When building object files or static libraries, link_mode can still be
static even if the OS needs libc for syscalls.
2020-09-26 01:58:16 -07:00
Andrew Kelley
6af2990549 implement -femit-asm, -femit-docs, -femit-llvm-ir, etc
These CLI options are now forwarded to the stage1 backend.

We're not going to support the -mllvm CLI option any longer. As a
compromise, we unconditionally tell LLVM to output intel x86 syntax when
using -femit-asm.

Simplify stage1 logic; it no longer has the concept of an output
directory. --output-dir is no longer a valid CLI option. cmake uses
the `-femit-bin=[path]` option.

Note the changes to test/cli.zig. This breaks the CLI API that Godbolt
is using so we're going to want to open a PR to help them upgrade to the
new CLI for the upcoming Zig 0.7.0 release.
2020-09-26 01:47:27 -07: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
Andrew Kelley
aded86e690 std.ArrayHashMap: count and iterator are not deprecated
These APIs allow one to write code that is agnostic of whether it is
using an ArrayHashMap or a HashMap, which can be valuable. Specify
intent precisely: if you only need the count of the items, it makes
sense to have a function for that.
2020-09-25 20:50:40 -07:00
Andrew Kelley
21b407b17f update test case for init-exe with respect to new template
Now it uses std.log.info instead of std.debug.print
2020-09-25 18:21:21 -07:00
Andrew Kelley
70d7d7e919 stage2: disable lld caching when output dir is owned by user
Normally when using LLD to link, Zig uses a file named "lld.id" in the
same directory as the output binary which contains the hash of the link
operation, allowing Zig to skip linking when the hash would be unchanged.
In the case that the output binary is being emitted into a directory which
is externally modified - essentially anything other than zig-cache - then
this flag would be set to disable this machinery to avoid false positives.

 * Better defaults when using -fno-LLVM
 * Fix compiler_rt and libc static libraries were getting a .zig
   extension instead of .a extension.
 * when using the stage1 backend, put the object file next to the
   stage1.id file in the cache directory. this prevents an object file
   from polluting the cwd when using zig from the CLI.
2020-09-25 18:01:35 -07:00
Suirad
43cd9eb110 Add clarification comment 2020-09-25 18:11:31 -05:00
Suirad
f78652484a Stdlib fix for os.windows.deleteFile to fail with
a proper error when attempting to delete a directory that isnt empty
2020-09-25 18:09:05 -05:00
Andrew Kelley
670e7d456c add some tracy calls 2020-09-25 14:47:09 -07:00
Andrew Kelley
a502604702 Merge pull request #6412 from kristoff-it/generalize-event-loop
Make os.zig not depend on the event loop
2020-09-25 17:26:44 -04:00
Loris Cro
dc01ef7388 Remove noop check
Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2020-09-25 23:21:20 +02:00
Andrew Kelley
812e482bef ELF linking supports root src directory to be cwd 2020-09-25 13:37:10 -07:00
Tadeo Kondrak
236af776fd std.fmt: add comptimePrint 2020-09-25 12:53:35 -06:00
Alexandros Naskos
288198e51d Merge pull request #6413 from LemonBoy/fix-5116
Make ArenaAllocator try to resize first
2020-09-25 19:47:50 +03:00
Loris Cro
8d01133bd0 update doc comments
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-09-25 18:42:24 +02:00
LemonBoy
bd9003ed5b std: ArenaAllocator tries to resize before allocating
Closes #5116
2020-09-25 10:58:07 +02:00
Felix (xq) Queißner
7f68b14377 Implements std.meta.Tuple(), implements #4607 in userland. 2020-09-25 09:27:00 +02:00
Felix (xq) Queißner
93291cc472 Implements std.meta.ArgsTuple. 2020-09-25 09:16:43 +02:00
Andrew Kelley
495d18a205 std.log: better default for printing logs
* prefix with the message level
 * if the scope is not default, also prefix with the scope

This makes the stack trace test pass, with no changes to the
test case, because errors returned from main() now print
`error: Foo` just like they do in master branch.
2020-09-25 00:02:52 -07:00
Andrew Kelley
30dfdfdbd0 fix a round of regressions in this branch
* Don't try to generate C header files yet since it will only cause a
   crash saying the feature is unimplemented.
 * Rename the CLI options for release modes to use the `-O` prefix to
   match C compiler precedent. Options are now `-ODebug`,
   `-OReleaseFast`, `-OReleaseSafe`, `-OReleaseSmall`. The optimization
   mode matches the enum tags of std.builtin.Mode. It is planned to, at
   some point, rename std.builtin.Mode to std.builtin.OptimizationMode
   and modify the tags to be lower case to match the style convention.
   - Update build.zig code to support this new CLI.
 * update std.zig.binNameAlloc to support an optional Version and update
   the implementation to correctly deal with dynamic library version
   suffixes.
2020-09-24 23:50:15 -07:00
Andrew Kelley
f8b3543cab I think this test is still flakey
re-opens #4922
2020-09-24 22:57:03 -07:00
Josh Wolfe
1a8669eada build.zig: addBuildOptionArtifact 2020-09-25 01:53:38 -04:00
Andrew Kelley
7964341c76 zig build: update to use new --version flag instead of legacy flags 2020-09-24 22:18:53 -07:00
Andrew Kelley
5440ca8eb7 --main-pkg-path properly resolves the relative root src file path 2020-09-24 22:15:40 -07:00
Andrew Kelley
67463c4357 correct @cImport caching to handle "unhit" case
if you hit() you have to unhit() to get the same digest if you don't
end up treating it as a hit.
2020-09-24 21:52:37 -07:00
Andrew Kelley
4f0850fe28 don't delete C import .c source from zig-cache
preventing CacheUnavailable error when doing `@cImport`
2020-09-24 21:13:01 -07:00
Andrew Kelley
054fafd7d9 stage2: implement @cImport
Also rename Cache.CacheHash to Cache.Manifest
2020-09-24 16:22:45 -07:00
Loris Cro
c196c27af8 recvfrom
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-09-24 22:06:41 +02:00
Loris Cro
419aea54cb sendto
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-09-24 22:06:41 +02:00
Loris Cro
7fec5b3def pwritev
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-09-24 22:06:41 +02:00
Loris Cro
7a07c62a07 pwrite
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-09-24 22:06:21 +02:00
Loris Cro
18f6629bd8 writev
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-09-24 22:06:03 +02:00
Loris Cro
9075f8e5a1 write
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-09-24 22:05:41 +02:00
Loris Cro
59ecdaea12 preadv
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-09-24 22:04:43 +02:00
Loris Cro
bd9f2369d5 pread
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-09-24 22:04:05 +02:00
Loris Cro
bc35435ca6 readv
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-09-24 22:03:12 +02:00
Loris Cro
08364ac773 read
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-09-24 22:00:55 +02:00
Loris Cro
730428bfd6 connect
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-09-24 21:56:27 +02:00
Loris Cro
e85c89630e accept
Signed-off-by: Loris Cro <kappaloris@gmail.com>
2020-09-24 21:56:27 +02:00
Frank Denis
bd89bd6fdb Revamp crypto/aes
* Reorganize crypto/aes in order to separate parameters, implementations and
modes.
* Add a zero-cost abstraction over the internal representation of a block,
so that blocks can be kept in vector registers in optimized implementations.
* Add architecture-independent aesenc/aesdec/aesenclast/aesdeclast operations,
so that any AES-based primitive can be implemented, including these that don't
use the original key schedule (AES-PRF, AEGIS, MeowHash...)
* Add support for parallelization/wide blocks to take advantage of hardware
implementations.
* Align T-tables to cache lines in the software implementations to slightly
reduce side channels.
* Add an optimized implementation for modern Intel CPUs with AES-NI.
* Add new tests (AES256 key expansion).
* Reimplement the counter mode to work with any block cipher, any endianness
and to take advantage of wide blocks.
* Add benchmarks for AES.
2020-09-24 13:16:00 -04:00
Ogromny
bba4576281 Fix typo in documentation 2020-09-24 13:14:03 -04:00
Andrew Kelley
1123c90987 stage2: print the test command after it fails 2020-09-23 23:13:18 -07:00
Frank Denis
c8cd6145ac Move PBKDF2 to a pwhash category, clarify what that category is
Password hashing functions are not general-purpose KDFs, and KDFs
don't have to satisfy the same properties as a PHF.

This will allow fast KDFs such as the HKDF construction to be in a
category of their own, while clarifying what functions are suitable
for using passwords as inputs.
2020-09-24 00:02:31 -04:00
Isaac Freund
72f4cdb2b4 docs: update implementation status for @Type() 2020-09-24 00:01:57 -04:00
Andrew Kelley
0f3111379b Merge pull request #6399 from FireFox317/async-fix
Eventloop: Fix deadlock in linux event loop implementation
2020-09-24 00:01:22 -04:00
Andrew Kelley
7bbd152dcc nobody likes my std.process.cleanExit idea
it's appropriate for the self-hosted compiler though, so this commit
moves it from std lib to stage2 src code.
2020-09-23 20:52:33 -07:00
Andrew Kelley
b08fd0e8fc stage2: building musl libc from source 2020-09-23 20:48:47 -07:00
Frank Denis
274c55b780 ZIG_WORKAROUND_4799 is not required with LLVM 10.0.1
That paragraph used to contradict the following one.
2020-09-23 22:05:43 -04:00
Andrew Kelley
64deb46859 stage2: capture LLD stderr into a buffer 2020-09-23 15:21:40 -07:00
Andrew Kelley
90b320d0e9 use ascii range for the --watch REPL prompt 2020-09-23 14:50:52 -07:00
Jakub Konka
0fcee6e11c Merge pull request #6373 from notCalle/workaround-6087
Workaround MacOS build failure due to #6087
2020-09-23 20:59:09 +02:00
Andrew Kelley
b183b612c9 stage2: don't build libunwind on OS's that don't need it 2020-09-23 11:15:27 -07:00
Andrew Kelley
f4dde4d109 test_runner: fix missing newline in log 2020-09-23 11:15:10 -07:00
Andrew Kelley
02886a8b93 stage2: support rpaths 2020-09-23 11:01:15 -07:00
Andrew Kelley
c0b774fbc6 stage2: support passing extra C flags to C source files
closes #3508
2020-09-23 10:22:44 -07:00
Andrew Kelley
d03fcc73fc stage2: implement --main-pkg-path 2020-09-23 09:56:30 -07:00
Andrew Kelley
15b2bae517 fix trying to link libc for static libs and objects 2020-09-23 09:41:55 -07:00
Timon Kruiper
bbff6bd675 Eventloop: Enable basic event loop test, fixed by previous commit
Closes #4922
2020-09-23 18:38:28 +02:00
Calle Englund
94024a9fae Update macOS build instructions with workaround 2020-09-23 16:26:35 +02:00
Timon Kruiper
0eed7ec9d5 Eventloop: Fix deadlock in linux event loop implementation
A simple empty main with evented-io would not quit, because some
threads were still waiting to be resumed (by the os). The os.write to
the eventfd only wakes up one thread and thus there are multiple writes
needed to wake up all the other threads.
2020-09-23 11:41:31 +02:00
Andrew Kelley
800a4a6ceb eliminate dependency of libzigcpp.a on libzigstage1.a
This allows us to create a build of self-hosted with LLVM extensions
enabled but without the stage1 backend.
2020-09-23 00:00:24 -07:00
Andrew Kelley
fc88d36dae stage2: link_libc=true on OS's that require it for syscalls 2020-09-22 23:31:32 -07:00
Andrew Kelley
0638a020cf stage2: implement --pkg-begin and --pkg-end CLI args 2020-09-22 23:00:33 -07:00
Andrew Kelley
c2b1cd7c45 stage2: implement zig build
As part of this:

 * add std.process.cleanExit. closes #6395
   - use it in several places
 * adjust the alignment of text in `zig build --help` menu
 * Cache: support the concept of "unhit" so that we properly keep track
   of the cache when we find out using the secondary hash that the cache
   "hit" was actually a miss. Use this to fix false negatives of caching
   of stage1 build artifacts.
 * fix not deleting the symlink hash for stage1 build artifacts causing
   false positives.
 * implement support for Package arguments in stage1 build artifacts
 * update and add missing usage text
 * add --override-lib-dir and --enable-cache CLI options
   - `--enable-cache` takes the place of `--cache on`
 * CLI supports -femit-bin=foo combined with --enable-cache to do an
   "update file" operation. --enable-cache without that argument
   will build the output into a cache directory and then print the path
   to stdout (matching master branch behavior).
 * errors surfacing from main() now print "error: Foo" instead of
   "error: error.Foo".
2020-09-22 22:18:19 -07:00
Andrew Kelley
250664bea4 build runner: allow for a bit longer -D options
so they can display in the --help menu without getting squished.
2020-09-22 14:56:52 -07:00
Andrew Kelley
dacd36ca9b stage2: implement using the global cache dir 2020-09-22 14:08:08 -07:00
Andrew Kelley
e2d1f9874d Merge remote-tracking branch 'origin/master' into llvm11 2020-09-22 11:41:21 -07:00
Bhargav Srinivasan
84406d98e4 removing redundant assert 2020-09-22 05:12:21 -07:00
Bhargav Srinivasan
778bb4b324 return not found error correctly 2020-09-22 03:50:28 -07:00
Bhargav Srinivasan
983830a4ae replace linearSearch with mem.indexOfScalar, return not found error, factor out siftUp from addUnchecked, use compareFn to decide siftUp/siftDown 2020-09-22 03:46:13 -07:00
Bhargav Srinivasan
a5140cc902 implemented efficient heapreplace 2020-09-22 02:12:35 -07:00
Bhargav Srinivasan
1345f87f4e items are not sorted, using linear search 2020-09-22 01:50:22 -07:00
Bhargav Srinivasan
69f0fc513a sorry, local compiler using different version of zig 2020-09-22 01:36:41 -07:00
Bhargav Srinivasan
f083ea88d8 using binary search function from std.sort 2020-09-22 01:05:33 -07:00
Andrew Kelley
bf9a16a037 stage2: implement zig init-lib and zig init-exe 2020-09-21 23:28:34 -07:00
Bhargav Srinivasan
26de64be13 adding a function to update the priority of an element 2020-09-21 23:09:22 -07:00
Andrew Kelley
877e4248fc stage2: implement building & linking against libcxx and libcxxabi 2020-09-21 22:38:45 -07:00
Andrew Kelley
974333faaf stage2: fix linking libc trying to depend on itself 2020-09-21 21:42:27 -07:00
Andrew Kelley
0c70bb4fce Merge remote-tracking branch 'origin/master' into stage2-zig-cc 2020-09-21 21:16:46 -07:00
Andrew Kelley
afac5d2895 fix regressed stage2 test harness 2020-09-21 21:14:01 -07:00
Andrew Kelley
ead50ea665 stage2: implement zig run and zig test 2020-09-21 21:01:04 -07:00
Andrew Kelley
528832bd3a rename src-self-hosted/ to src/ 2020-09-21 18:38:55 -07:00
Andrew Kelley
b9f61d4015 stage1: resolve builtin.zig path when bootstrapping 2020-09-21 18:26:24 -07:00
Andrew Kelley
61c54b2d49 Cache integration for stage1 zig code compilation 2020-09-21 18:21:49 -07:00
Andrew Kelley
b8861a94dd stage2: building compiler_rt and libc static archive with stage1
* add CLI support for verbose debugging options
 * implement building compiler_rt and libc static archive using stage1
   C++ backend
 * add function_sections  and link_libcpp to root cache hash.
 * cleanups to use the new Directory.join method.
 * Package supports being initialized directly and cleaned up create()
   method.
 * fix classifyFileExt incorrectly saying .zir is .zig. Thanks
   @Rocknest!
 * unify updateSubCompilation implementations
2020-09-21 16:33:29 -07:00
Andrew Kelley
bd1465a3fe cmake: output better message when building self-hosted
Thanks @bfredl!
2020-09-21 16:32:56 -07:00
Andrew Kelley
561ed38f12 ci: drop the cmake patch for linux
hopefully they've solved the polly plugin thing by now on apt.llvm.org.
2020-09-21 12:40:19 -07:00
Vexu
ced061fcbf stage2: update uses of DepTokenizer 2020-09-21 15:23:41 -04:00
Vexu
b759308fb3 stage2: DepTokenizer print errors 2020-09-21 15:23:41 -04:00
Vexu
f27bc79121 stage2: DepTokenizer add target resolver 2020-09-21 15:23:41 -04:00
Vexu
302e156523 stage2: make DepTokenizer non-allocating 2020-09-21 15:23:41 -04:00
Joran Dirk Greef
5f99d2c240 Define SPLICE, PROVIDE_BUFFERS, REMOVE_BUFFERS and TEE opcodes and flags 2020-09-21 20:15:14 +02:00
Joran Dirk Greef
2d8df2b745 Use @intCast instead of @truncate 2020-09-21 12:03:52 +02:00
Joran Dirk Greef
7719abbf54 Add flags to queue_fsync() signature as per liburing 2020-09-21 11:09:37 +02:00
Joran Dirk Greef
57603fd26d Use @intCast instead of @truncate on io_uring_enter() result 2020-09-21 11:09:09 +02:00
Joran Dirk Greef
575ed941d7 Cache mask instead of dereferencing mask pointer 2020-09-21 11:07:11 +02:00
Joran Dirk Greef
843c104fc9 Add io_uring syscalls to os.bits.linux.mips.SYS
As per lib/libc/musl/arch/mips/bits/syscall.h.in:

```c
```
2020-09-21 10:39:58 +02:00
Joran Dirk Greef
a853f00410 Add IORING_FEAT_FAST_POLL 2020-09-20 19:51:23 +02:00
Joran Dirk Greef
77903f8d4e Test structs and offsets 2020-09-20 18:45:44 +02:00
Joran Dirk Greef
e51728a1b4 Make enter(), flush_sq(), sq_ring_needs_enter(), cq_ring_needs_flush() public
These will also be needed by any custom helpers
2020-09-20 15:54:31 +02:00
Joran Dirk Greef
40293a0643 Add safety checks 2020-09-20 15:41:22 +02:00
Joran Dirk Greef
f22eea82c4 Fix opcode support detection for read/write test 2020-09-20 15:33:48 +02:00
Joran Dirk Greef
b672dc7abf Use os.fd_t instead of i32 and assert against c_int for syscall safety 2020-09-20 14:59:40 +02:00
Joran Dirk Greef
abebacda32 Handle all possible syscall errors and bring errors in line with os.zig 2020-09-20 14:21:44 +02:00
LemonBoy
58ee5f4e61 std: Fix metadata corruption in HeapAllocator
HeapAllocator stores the pointer returned by HeapAlloc right after the
data block and, after the recent allocator refactoring, the space for
this pointer was not taken into account in the calculation of the final
block size.

Fixes #5830
2020-09-20 01:21:29 -04:00
Joran Dirk Greef
4bc1b7a7ac Fix io_uring_sqe to use the names of the first member of each union
Now we're really future-proof... no more `opflags` creeping in.

When anonymous unions land, we can start using `accept_flags` etc.

Until then, code using this struct won't break when the kernel adds features.

Refs: https://github.com/ziglang/zig/issues/6349
Refs: https://github.com/ziglang/zig/issues/985
2020-09-19 18:50:24 +02:00
Joran Dirk Greef
92407bfcd7 Upgrade check_errno() to an exhaustive switch (safer) 2020-09-19 18:29:50 +02:00
Joran Dirk Greef
ba18420b27 Zero the SQE slot and assign, instead of initializing with default values 2020-09-19 18:17:06 +02:00
Joran Dirk Greef
e7ae6f2fad Remove default values from io_uring_sqe struct 2020-09-19 18:14:41 +02:00
Joran Dirk Greef
f4df2f091a Allow the kernel to drive feature detection 2020-09-19 17:31:39 +02:00
Joran Dirk Greef
64ae9a6a87 Rename to error.SubmissionQueueFull 2020-09-19 16:54:44 +02:00
Joran Dirk Greef
c1f9d10b6a Remove unused import aliases 2020-09-19 16:51:35 +02:00
Joran Dirk Greef
9fabae2a28 Return error.UnsupportedKernel for ENOSYS 2020-09-19 16:47:05 +02:00
Joran Dirk Greef
0d8c6a960f Remove dangling @import from std 2020-09-19 16:45:52 +02:00
Joran Dirk Greef
cb591285d7 Use linux.IORING_SQ_CQ_OVERFLOW 2020-09-19 16:20:21 +02:00
Joran Dirk Greef
31533eb743 Move to std/os/linux 2020-09-19 16:18:04 +02:00
Joran Dirk Greef
873d1c80b3 Add splice_fd_in to io_uring_sqe and future-proof for anonymous unions 2020-09-19 16:15:17 +02:00
Joran Dirk Greef
09f2f4aeb3 Fix std @import 2020-09-19 15:14:47 +02:00
Joran Dirk Greef
b2a54b9581 Test IORING_REGISTER_FILES but avoid sparse fd sets 2020-09-19 15:07:10 +02:00
Joran Dirk Greef
5df0d284d0 Do not register /dev/zero as an fd when testing queue_readv() 2020-09-19 14:29:23 +02:00
Joran Dirk Greef
ee5931908e @ptrCast fds.ptr to *const c_void for io_uring_register() 2020-09-19 13:25:59 +02:00
Andrew Kelley
2ef68631cb stage2 now supports using stage1 as a backend for compiling zig code
* move stage2.cpp code into zig0.cpp for simplicity
 * add -ftime-report and some more CLI options to stage2
 * stage2 compites the llvm cpu features string
 * classifyFileExt understands more file extensions
 * correction to generateBuiltinZigSource using the wrong allocator
   (thanks dbandstra!)
 * stage2 is now able to build hello.zig into hello.o using stage1 as a
   library however it fails linking due to missing compiler-rt
 * remove dead code
 * simplify zig0 builtin.zig source
 * fix not resolving builtin.zig source path causing duplicate imports
 * fix stage1.h not being valid C code
 * fix stage2.h not being valid C code
2020-09-18 22:48:28 -07:00
LemonBoy
f92d01c8a8 stage1: Fix edge case in casting between optional types
Closes #6370
2020-09-18 22:12:22 -04:00
zenith391
4fbf9f7f79 Add "emit_docs" field to LibExeObjStep. 2020-09-19 00:39:43 +03:00
Calle Englund
d08842887f Workaround MacOS build failure due to #6087 2020-09-18 17:03:50 +02:00
Lachlan Easton
4496a6c9cc zig fmt: Special case un-indent comma after multiline string in param list 2020-09-18 20:34:00 +10:00
Lachlan Easton
1aacedf6e1 zig fmt: Fix regression in ArrayInitializers 2020-09-18 20:34:00 +10:00
Lachlan Easton
40b6e86a99 zig fmt: fix #6171 2020-09-18 20:34:00 +10:00
Lachlan Easton
c06674e701 zig fmt: Small cleanup 2020-09-18 20:34:00 +10:00
Lachlan Easton
206a8cf670 zig fmt: fix comments and multiline literals in function args 2020-09-18 20:34:00 +10:00
Lachlan Easton
291482a031 zig fmt: Don't consider width of expressions containing multiline string literals when calculating padding for array initializers. fixes #3739
Changes some of the special casing for multiline string literals.
2020-09-18 20:34:00 +10:00
Lachlan Easton
e1bd271192 zig fmt: Allow trailing comments to do manual array formatting. close #5948 2020-09-18 20:34:00 +10:00
Lachlan Easton
9f0821e688 zig fmt: Fix erroneously commented out code, add passing test case to close #5722 2020-09-18 20:34:00 +10:00
Lachlan Easton
ea6181aaf6 zig fmt: Add test for nesting if expressions 2020-09-18 20:34:00 +10:00
Andrew Kelley
333b12a8f9 std: start: use std.log instead of stderr
When main returns an error code.
2020-09-18 01:58:16 -07:00
Andrew Kelley
dc79651e6a stage2: add CLI for zig translate-c 2020-09-18 01:33:32 -07:00
Andrew Kelley
a9b18023a4 stage2: implement --show-builtin
This takes the place of `zig builtin`. This is an improvement over the
command because now the generated source will correctly show LinkMode
and OutputMode, whereas before it was always stuck as Static and Obj,
respectively.
2020-09-17 23:27:24 -07:00
Andrew Kelley
dc478687d9 delete all stage1 c++ code not directly related to compiling stage2
Deleted 16,000+ lines of c++ code, including:
 * an implementation of blake hashing
 * the cache hash system
 * compiler.cpp
 * all the linking code, and everything having to do with building
   glibc, musl, and mingw-w64
 * much of the stage1 compiler internals got slimmed down since it
   now assumes it is always outputting an object file.

More stuff:
 * stage1 is now built with a different strategy: we have a tiny
   zig0.cpp which is a slimmed down version of what stage1 main.cpp used
   to be. Its only purpose is to build stage2 zig code into an object
   file, which is then linked by the host build system (cmake) into
   stage1. zig0.cpp uses the same C API that stage2 now has access to,
   so that stage2 zig code can call into stage1 c++ code.
   - stage1.h is
   - stage2.h is
   - stage1.zig is the main entry point for the Zig/C++
     hybrid compiler. It has the functions exported from Zig, called
     in C++, and bindings for the functions exported from C++, called
     from Zig.
 * removed the memory profiling instrumentation from stage1.
   Abandon ship!
 * Re-added the sections to the README about how to build stage2 and
   stage3.
 * stage2 now knows as a comptime boolean whether it is being compiled
   as part of stage1 or as stage2.
   - TODO use this flag to call into stage1 for compiling zig code.
 * introduce -fdll-export-fns and -fno-dll-export-fns and clarify
   its relationship to link_mode (static/dynamic)
 * implement depending on LLVM to detect native target cpu features when
   LLVM extensions are enabled and zig lacks CPU feature detection for
   that target architecture.
 * C importing is broken, will need some stage2 support to function
   again.
2020-09-17 18:29:38 -07:00
Ryan Liptak
fbde15fdf4 Fix compile error in os.renameatW
Introduced in 5e3fa0e94f

Whoops!
2020-09-17 18:49:06 -04:00
Andrew Kelley
f125288c9b Merge pull request #6336 from Rocknest/pbkdf2
Some changes to #6326 (pbkdf2)
2020-09-17 17:31:58 -04:00
Ryan Liptak
5e3fa0e94f Add rename to std.fs API
- Moves fs.rename functions to fs.renameAbsolute to match other functions outside of fs.Dir
- Adds fs.Dir.rename that takes two paths relative to the given Dir
- Adds fs.rename that takes two separate Dir's that the given paths are relative to (for renaming across directories without having to make the second path relative to a single directory)
- Fixes FileNotFound error return in std.os.windows.MoveFileExW
- Returns error.RenameAcrossMountPoints from renameatW
  + Matches the RenameAcrossMountPoints error return in renameatWasi/renameatZ
2020-09-17 17:22:26 -04:00
Andrew Kelley
3672a18799 Merge pull request #6360 from LemonBoy/some-fmt-fixes
Two std.fmt fixes
2020-09-17 16:17:15 -04:00
Joran Dirk Greef
8b030a6599 Use x.y for C-style x->y instead of x.*.y 2020-09-17 20:29:56 +02:00
Joran Dirk Greef
e33c466daf Use std.builtin 2020-09-17 19:56:57 +02:00
Joran Dirk Greef
d966fe6319 Add IORING_SQ_CQ_OVERFLOW to std/os/bits/linux.zig 2020-09-17 19:53:34 +02:00
Joran Dirk Greef
21c81360ba Remove comment 2020-09-17 19:44:53 +02:00
Joran Dirk Greef
ac1d9f716a Use != 0 for bitwise flag conditions 2020-09-17 19:37:17 +02:00
LemonBoy
b7f9f779af translate-c: Fix formatting of non-printable chars
The two octets in hex notation must be aligned to the right and padded
on the left, not the other way around.
2020-09-17 09:27:24 +02:00
Andrew Kelley
bc01887376 stage2: verify -Wl zig cc behavior 2020-09-16 20:28:51 -07:00
Andrew Kelley
01a7affb87 stage2: ask for a higher open fd limit
Here's the doc comment from the commit:

For one example of why this is handy, consider the case of building musl libc.
We keep a lock open for each of the object files in the form of a file descriptor
until they are finally put into an archive file. This is to allow a zig-cache
garbage collector to run concurrently to zig processes, and to allow multiple
zig processes to run concurrently with each other, without clobbering each other.

This code is disabled until #6361 is implemented (getrlimit/setrlimit
are not yet added to the standard library).
2020-09-16 20:18:06 -07:00
Andrew Kelley
07eb2c65f6 stage2: don't add unused args to assembly compilations 2020-09-16 19:24:09 -07:00
Andrew Kelley
17d40ecb49 stage2: building libunwind.a
and put glibc shared objects on the elf linker line
2020-09-16 17:18:13 -07:00
LemonBoy
27adb82fda std: Respect user-specified alignment when formatting ints
This implementation tries to do the right thing (TM) by treating the
sign as part of the number itself, therefore the alignment parameter
applies to both the sign and the digits.

In other words the format string `{:>4}` with -1 as input will not
output `-  1` but `  -1`.

And let's default to right alignment for everything as that's what users
want, especially when printing numbers. Many implementations use
different defaults for numeric vs non-numeric types, let's strive for a
consistent behaviour here.
2020-09-17 00:53:08 +02:00
Andrew Kelley
17f094ec5b stage2: build glibc shared objects using assembly files
closes #6358
2020-09-16 14:33:13 -07:00
Andrew Kelley
3256b3c485 stage2: glibc shared objects use ok file to detect cache hits 2020-09-16 13:41:53 -07:00
Andrew Kelley
670260aab6 stage2: std.log.err is an error not a warning 2020-09-16 13:41:28 -07:00
Andrew Kelley
883dcb8b18 stage2 Cache: use hex instead of base64 for file paths 2020-09-16 12:31:42 -07:00
Andrew Kelley
a863d899e1 ci: undo mangled autocrlf files before building 2020-09-16 11:58:26 -07:00
Andrew Kelley
80d8515e3a ci: disable git autocrlf
See also commit
2c8495b4bb
2020-09-16 10:49:43 -07:00
Joran Dirk Greef
491a434b01 Check kernel support for single_mmap, accept, and read/write 2020-09-16 19:36:29 +02:00
Tadeo Kondrak
2962be8135 stage1: fix @Type(.Union) not resolving its tag type
Fixes https://github.com/ziglang/zig/issues/6339
2020-09-16 20:34:01 +03:00
Joran Dirk Greef
6f09796ff2 Add short license and copyright notice 2020-09-16 18:51:21 +02:00
Joran Dirk Greef
b340bbfc1d std: add io_uring library
This brings io_uring helper methods to Zig for kernels >= 5.4.

We follow liburing's design decisions so that anyone who is comfortable with
liburing (https://unixism.net/loti/ref-liburing/index.html) will feel at home.

Thanks to @daurnimator for the first draft.

Refs: https://github.com/ziglang/zig/pull/3083
Signed-off-by: Joran Dirk Greef <joran@coil.com>
2020-09-16 15:07:13 +02:00
LemonBoy
bb9a4ad6e9 std: Fix {*} printing of non-pointer types
Fixes a regression introduced in #6246.
Adds a test to make sure this won't happen again.
2020-09-16 13:45:54 +02:00
Andrew Kelley
95941c4e70 stage2: building glibc shared objects
* caching system: use 16 bytes siphash final(), there was a bug in the
   std lib that wasn't catching undefined values for 18 bytes. fixed in
   master branch.
 * fix caching system unit test logic to not cause error.TextBusy on windows
 * port the logic from stage1 for building glibc shared objects
 * add is_native_os to the base cache hash
 * fix incorrectly freeing crt_files key (which is always a reference to
   global static constant data)
 * fix 2 use-after-free in loading glibc metadata
 * fix memory leak in buildCRTFile (errdefer instead of defer on arena)
2020-09-16 03:02:46 -07:00
Andrew Kelley
281fc10ec5 std.crypto siphash: fix assertion on the size of output buffer
the logic was backwards
2020-09-16 02:24:36 -07:00
Nathan Michaels
7801a6d17f Fix a typo. 2020-09-15 22:49:53 -04:00
Andrew Kelley
da0fde59b6 stage2: update to new LibCInstallation API 2020-09-15 18:08:52 -07:00
Andrew Kelley
16bd0c63b4 Merge remote-tracking branch 'origin/master' into stage2-zig-cc
Pulling in the changes to libc_installation.zig
2020-09-15 18:04:37 -07:00
Andrew Kelley
99a2fc2cde stage2: implement .d file parsing for C objects 2020-09-15 18:02:42 -07:00
Rocknest
c35703825f Add an error set 2020-09-16 01:58:48 +03:00
Andrew Kelley
a0b43ff3b3 stage2: eliminate one failure path in building c object 2020-09-15 15:24:34 -07:00
Andrew Kelley
f82b1831f7 std: handle sharing violation when deleting a file on windows 2020-09-15 15:24:13 -07:00
Andrew Kelley
7ccfb08a93 ci: update the on_master_success secret to lavatech 2020-09-15 15:08:35 -07:00
Samrat Man Singh
ca85e367f4 Use std.log in LibcInstallation parse instead of taking stderr 2020-09-15 18:03:55 -04:00
Andrew Kelley
c803d334d0 update the zen of zig 2020-09-15 13:40:01 -07:00
Andrew Kelley
b2860aa3e4 stage2: add missing import to libc_installation.zig 2020-09-15 12:52:58 -07:00
Andrew Kelley
b3cc36857e Merge pull request #6340 from Vexu/fix
Fixes
2020-09-15 14:28:16 -04:00
LemonBoy
c1c3212500 std: Fix typo in ELF section header iterator
The code accidentally used the phdr offset instead of the shdr one while
iterating over the section headers.

Fixes #6338
2020-09-15 18:14:06 +03:00
Andrew Kelley
1da9e0fcaf stage2: building glibc libc_nonshared.a CRT file 2020-09-15 00:41:02 -07:00
Andrew Kelley
4fa8cc7369 stage2: don't depend on windows SDK C++ code when unavailable 2020-09-15 00:40:33 -07:00
Andrew Kelley
6e9396e32b integrate target features into building assembly code
This brings us up to par from what stage1 does. There will still be an
open issue for completing this.
2020-09-14 23:03:13 -07:00
Andrew Kelley
1ad60c4386 integrate target features into building C source files 2020-09-14 22:57:08 -07:00
Andrew Kelley
5d8fec3d4c Merge remote-tracking branch 'origin/master' into stage2-zig-cc 2020-09-14 21:57:01 -07:00
Andrew Kelley
6acd903a95 stage2: support for machine code model CLI 2020-09-14 21:22:11 -07:00
Andrew Kelley
5e39ab4600 ci: disable some freebsd tests to save time 2020-09-14 21:11:34 -07:00
Andrew Kelley
0e94530c51 stage2: refactor 2 CObject fields to use CSourceFile 2020-09-14 19:52:36 -07:00
Andrew Kelley
29d9743f9d Revert "disable sourcehut freebsd CI checks"
This reverts commit 40cb712d13.

Thanks to Ava & Luna of Lavatech, we don't need to resort to this, they
have graciously given zig a SourceHut instance to use that gives us 8GB
RAM.
2020-09-14 19:43:26 -07:00
Andrew Kelley
a8ae324130 Merge branch 'ci-freebsd'
Thanks to Ave & Luna for providing this service that lets us have enough
ram to properly test FreeBSD.
2020-09-14 19:38:36 -07:00
Andrew Kelley
44ef270de1 ci: use hut.lavatech.top for updating the download page 2020-09-14 19:37:59 -07:00
Andrew Kelley
558e22b2d0 ci: update freebsd to use hut.lavatech.top instead of sr.ht 2020-09-14 18:45:30 -07:00
Andrew Kelley
01c24c4509 ci: enable std lib tests for freebsd 2020-09-14 18:22:16 -07:00
Andrew Kelley
dffdb2844e track all TODO comments in BRANCH_TODO file
Before merging, do this for every item in the file:
 * solve the issue, or
 * convert the task to a github issue and update the comment
   to link to the issue (and remove "TODO" text from the comment).
Then delete the file.

Related: #363
2020-09-14 18:06:19 -07:00
Andrew Kelley
26798018b7 stage2: implement writing archive files 2020-09-14 15:28:09 -07:00
Vexu
a3624e94f8 translate-c: determine sizeof using std.meta.sizeof 2020-09-14 23:53:38 +03:00
Vexu
29fd0c6d61 fix meta.cast behavior; add exhaustive tests 2020-09-14 23:21:26 +03:00
Andrew Kelley
40cb712d13 disable sourcehut freebsd CI checks
Drew won't give us enough RAM for stage1 to build stage2. We'll still
have freebsd builds available on releases but we're going to lose
freebsd CI testing for master branch builds until we fully switch over
to stage2 (and have lower memory usage).

Let me know if anyone wants to run a SourceHut instance and give zig
access to run on slightly more powerful machines. We need about 8 GiB
RAM to run the CI test suite for now.

After we're fully self hosted I expect to re-enable this.
2020-09-14 11:10:38 -07:00
Andrew Kelley
778bb4bc9c move std.cache_hash from std to stage2
The API is pretty specific to the implementationt details of the
self-hosted compiler. I don't want to have to independently support
and maintain this as part of the standard library, and be obligated
to not make breaking changes to it with changes to the implementation of
stage2.
2020-09-14 11:05:51 -07:00
Andrew Kelley
04f6a26955 fix stage1 regressions in this branch
also prepare for supporting linking into archives
2020-09-14 10:42:29 -07:00
Andrew Kelley
c58e9951ef revert bogus enum keywords in zig_llvm.h 2020-09-14 10:31:34 -07:00
Veikka Tuominen
d073836894 Merge pull request #6172 from tadeokondrak/@Type(.Union)
Implement @Type for Union
2020-09-14 16:43:49 +03:00
Andrew Kelley
c49435f76b Merge pull request #6331 from mattnite/bpf-helper-defs
BPF: helper definitions
2020-09-14 04:00:00 -04:00
Andrew Kelley
f2e380380e stage2: building glibc Scrt1.o 2020-09-14 00:24:03 -07:00
Andrew Kelley
060c91b97f stage2: namespace cache dir with C source path
This is not strictly necessary but it increases the likelihood of cache
hits because foo.c and bar.c now will have different cache directories
and can be updated independently without clobbering each other's cache
data.
2020-09-13 23:28:28 -07:00
Andrew Kelley
0379d7b431 stage2: don't bother building glibc when only doing build-obj 2020-09-13 23:04:15 -07:00
Andrew Kelley
e5aef96293 stage2: CRT files retain locks on the build artifacts 2020-09-13 22:54:16 -07:00
Andrew Kelley
97ea5da18d stage2: fix bad include path for glibc abi-note.S 2020-09-13 22:38:50 -07:00
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
Rocknest
988fc6f9d1 flip condition 2020-09-14 02:27:09 +03:00
Rocknest
73863cf72b fix build 2020-09-13 23:59:36 +03: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
Rocknest
f6195be997 fix ref 2020-09-13 23:31:59 +03: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
Rocknest
d75cbb01db Reference all crypto declarations 2020-09-13 23:00:33 +03:00
Rocknest
b6385870d0 Convert asserts to errors, make sure nothing overflows 2020-09-13 22:39:54 +03:00
Rocknest
a6d947191e Merge pull request #2 from rnapier/pbkdf2
Pbkdf2
2020-09-13 22:09:45 +03: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
Rob Napier
85366771ea pbkdf2 offset into dk should be usize, not u64. 2020-09-13 12:36:32 -04:00
Matt Knight
cb5f76bb1c got booleans wrong 2020-09-13 09:24:56 -07:00
Rocknest
dcd229be92 Merge pull request #1 from rnapier/pbkdf2
Pbkdf2
2020-09-13 19:11:29 +03:00
Rob Napier
2f9c9662ba Use comptime to expose public method to doc system 2020-09-13 11:17:58 -04:00
Rob Napier
8a1a40276f Extract kdf.zig to provide namespace documentation 2020-09-13 11:08:06 -04:00
Rob Napier
257c5b5348 Explicitly reference std.crypto.kdf in test case 2020-09-13 10:50:46 -04:00
Rob Napier
0f85b85acb Improve doc text 2020-09-13 09:59:36 -04:00
Matt Knight
b043a31889 added helper definitions 2020-09-12 23:45:35 -07:00
Rob Napier
17156e1775 pbkdf2 "very large dklen test" should just check for crashes 2020-09-12 18:33:53 -04:00
Rob Napier
3f450b7e93 Replace Hash function with Prf. Correct offset bit-width. 2020-09-12 18:17:04 -04:00
Rob Napier
37db93e426 Review comments from pbkdf2.zig
Move block definitions inside while loop.
Use usize for offset. (This still crashes on overflow)
Remove unneeded slice syntax.
Add slow test for Very large dkLen
2020-09-12 15:03:42 -04: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
Rob Napier
c2b02d01d5 Add crypto.kdf.pbkdf2 2020-09-11 17:10:27 -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
Bas van den Berg
127fa80090 implement poll for windows with WSAPoll (only available on vista and higher) 2020-09-10 20:20:27 +02: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
Bas van den Berg
f5b9e445aa Handle some WSA errors 2020-09-09 18:55:45 +02: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
Andrew Kelley
71687b30a2 work around stage1 invalid LLVM IR 2020-09-09 09:28:05 -07:00
Andrew Kelley
503ba7b27c start moving zig cc to stage2
* build.zig: repair the ability to link against llvm, clang, and lld
 * move the zig cc arg parsing logic to stage2
   - the preprocessor flag is still TODO
   - the clang arg iterator code is improved to use slices instead of
     raw pointers because it no longer has to deal with an extern
     struct.
 * clean up error printing with a `fatal` function and use log API
   for messages rather than std.debug.print
 * add support for more CLI options to stage2 & update usage text
   - hooking up most of these new options is TODO
 * clean up the way libc and libc++ are detected via command line
   options. target information is used to determine if any of the libc
   candidate names are chosen.
 * add native library directory detection
 * implement the ability to invoke clang from stage2
 * introduce a build_options.have_llvm so we can comptime branch
   on whether LLVM is linked in or not.
2020-09-09 09:28:05 -07:00
Vexu
749417a1f3 translate-c: check for builtin typedef macro identifiers
Closes #6292
2020-09-09 16:29:16 +03:00
Lachlan Easton
601331833a Add passing test. close #5343 2020-09-09 21:54:42 +10:00
Lachlan Easton
283d441c19 zig fmt: fix #3978, fix #2748 2020-09-09 21:54:42 +10:00
Jakub Konka
7d487a4162 Merge pull request #6289 from kubkon/macho
macho: fix bug where __text section would get overwritten
2020-09-09 09:00:24 +02:00
Zachary Meadows
edc40157eb Switch type of HashMap's count from usize to u32 (#6262) 2020-09-09 00:33:14 -04:00
Jakub Konka
edbfd04ec1 Do not pad out text blocks
It seems MachO does not like padding between text block in __text
section. Unlike in Elf, there is no size information in symbol
struct `nlist_64`.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-09-08 22:00:31 +02:00
Jakub Konka
9306dbd619 Fix bug where __text section would get overwritten
Fixes a bug where the last written load command would accidentally
override the beginning of the __text section. Also defines missing
MachO constants and relocation structs/enums.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-09-08 20:55:06 +02:00
Mark Barbone
42b1b6be90 Add resize for arena allocator 2020-09-08 13:04:14 -04:00
Jens Goldberg
5bf3e54018 Add the Linux TCP socket options 2020-09-08 13:00:07 -04:00
Andrew Kelley
f6f0e09456 Merge pull request #6267 from mattnite/btf
BPF: add BTF
2020-09-08 12:59:31 -04:00
xackus
b8b68cb279 std: clean up bitrotten imports in crypto 2020-09-08 12:54:28 -04:00
Andrew Kelley
8716fde7bc ci: skip non native builds on windows to save time 2020-09-08 09:53:41 -07:00
Timon Kruiper
61cd9099e2 Zlib: Make deinit function public 2020-09-08 12:21:49 -04:00
Bas van den Berg
44f877d18b change socklen_t to u32 and add appropriate casts when calling WSA 2020-09-08 12:24:39 +02:00
Bas van den Berg
857613fb65 add unreachable 2020-09-08 12:16:03 +02:00
Bas van den Berg
9094d6cbb8 fix identation with zig-fmt 2020-09-08 12:15:44 +02:00
Bas
4a6ca735d9 Merge branch 'master' into improve-windows-networking 2020-09-08 11:56:59 +02:00
Andrew Kelley
389c260252 Merge branch 'LemonBoy-zlib-cool'
closes #6277
closes #213
2020-09-07 15:16:32 -07:00
Andrew Kelley
c15f39212e build.zig: ignore the compression test files 2020-09-07 15:15:48 -07:00
LemonBoy
2328f40b7a std: Add DEFLATE and zlib decompressors 2020-09-07 14:59:46 -07:00
Matt Knight
a496f94be9 added map create, update, delete, and prog load 2020-09-07 15:42:41 -04:00
Matthew Knight
db7a238297 BPF: add some more documentation (#6268)
* added documentation for ringbuffers, which context type maps to which program type, and added some formatting
2020-09-07 15:41:29 -04:00
Andrew Kelley
f96f3265b5 Merge pull request #6265 from mattnite/bpf-finish-insns
BPF: Implement rest of pseudo instructions
2020-09-07 15:39:42 -04:00
Matt Knight
b878a64a5f added license comments 2020-09-07 12:26:41 -07:00
Andrew Kelley
52b8239a22 Merge remote-tracking branch 'origin/master' into llvm11 2020-09-07 11:17:42 -07:00
Vincent Rischmann
533bfc68bf big int: fix Managed.dump() 2020-09-07 20:44:01 +03:00
Peter Spiess-Knafl
eca20b5e03 Fix compile when using EFI target (Fixes #6275) 2020-09-07 20:40:11 +03:00
Matt Knight
cf3194804e changed enums to lower case 2020-09-07 07:17:21 -07:00
Tadeo Kondrak
acdf1f0bde @Type for union fixes 2020-09-07 06:23:50 -06:00
Tadeo Kondrak
771f35c593 Use less inefficient method of replacing TypeInfo.UnionField.enum_field 2020-09-07 06:23:27 -06:00
Tadeo Kondrak
ac19ccf595 Update standard library for removal of TypeInfo.UnionField.enum_field 2020-09-07 06:23:26 -06:00
Tadeo Kondrak
ff2ed966bb Implement @Type for Union
This removes TypeInfo.UnionField.enum_field, which is redundant with
TypeInfo.Union.tag_type.
2020-09-07 06:23:24 -06:00
Matt Knight
e7547eeefa fixed missing 'packed' keyword 2020-09-06 22:31:35 -07:00
Matt Knight
caaa9ad2af added btf 2020-09-06 21:44:16 -07:00
Matt Knight
67817b230f fixed improper builtin import 2020-09-06 17:09:25 -07:00
Matt Knight
cf06817768 improved compile error message 2020-09-06 16:21:05 -07:00
Andrew Kelley
d7268cbb24 Merge pull request #6232 from LemonBoy/fix-readall
std: Don't trust stat() size in readAllAlloc fns
2020-09-06 19:19:57 -04:00
Matt Knight
a993c7dd1b removed redundant pseudo insn 2020-09-06 16:19:49 -07:00
Matt Knight
295f09eadc implemented and testing op codes for instructions documented in the unofficial bpf insn reference 2020-09-06 16:12:27 -07:00
Daniel Ludwig
a8a806e925 std.ChildProcess: use "\Device\Null" on Windows 2020-09-06 18:25:33 -04:00
dec05eba
ff58f09b68 Use better haystack size and needle size for cutoff between linear and BMH 2020-09-06 16:23:18 +02:00
Andrew Kelley
32a77a6047 Merge pull request #6239 from pfgithub/patch-1
Support allocating 0 bit types
2020-09-06 01:16:33 -04:00
dec05eba
8af1f8ba1a Add comment to clearify why the first/last element in preprocess is
skipped
2020-09-05 21:15:44 +02:00
dec05eba
0a016e8fc2 Fix indexOf and lastIndexOf with empty needle 2020-09-05 16:55:32 +02:00
dec05eba
f93498d2d8 Fix start index if @sizeOf(T) > 1 2020-09-05 15:31:22 +02:00
dec05eba
3a6e6bd538 Check if the type has unique bit representation to see if it can be compared byte-wise 2020-09-05 15:20:48 +02:00
dec05eba
db51821a97 Remove type size check, looks like its not needed
Add check if the type is float. Float byte comparison doesn't work
because +0.0 and -0.0 are considered equal but their byte
representations are not equal.
2020-09-05 14:56:59 +02:00
dec05eba
997451da03 Make preprocess function take comptime sized slice 2020-09-05 14:25:44 +02:00
dec05eba
a394a6300c Fix lastIndexOf and add tests that do not fallback to linear search
Use sliceAsBytes to convert []const T to []const u8.
Cleanup.
2020-09-05 14:17:38 +02:00
Veikka Tuominen
41bbadbb9a Merge pull request #6246 from Vexu/field
Remove deprecated fields on `type`
2020-09-05 13:58:02 +03:00
dec05eba
f65f3d24f8 Only use boyer-moore-horsepool for types that are power of 2 2020-09-05 12:57:05 +02:00
dec05eba
d012507a8f Use boyer-moore-horspool with all types of T 2020-09-05 12:02:18 +02:00
dec05eba
e297b4815c Create skipping table
Also fallback to naive implementation if haystack is small
or if the needle is small or if sizeof type is not 1.
2020-09-05 11:24:05 +02:00
dec05eba
50c52e0135 Use boyer-moore-horspool algorithm for indexOfPos and lastIndexOf 2020-09-05 11:22:12 +02:00
Andrew Kelley
cff14dc2c6 Merge pull request #6247 from alexnask/stage2_pe
Added a basic Portable Executable linker to stage2
2020-09-04 16:05:58 -04:00
Andrew Kelley
209a3da4f7 provide default implementation of std.log on freestanding
closes #6252
2020-09-04 13:00:10 -07:00
Vexu
09c861b829 update rest of tests 2020-09-04 22:49:14 +03:00
yettinmoor
0c43b6ef5c document how to escape curly braces in fmt.format 2020-09-04 22:11:09 +03:00
Vexu
6b2f4fd20d langref: atomic ops are allowed on pointers
Closes #6217
2020-09-04 22:02:39 +03:00
LemonBoy
3c8e1bc25b std: Fix for 32bit systems 2020-09-04 12:48:36 +02:00
LemonBoy
90743881cf std: Minor changes to the fs module
* Add a size_hint parameter to the read{toEnd,File}AllocOptions fns
* Rename readAllAlloc{,Options} to readToEndAlloc{,Options} as they
  don't rewind the file before reading
* Fix missing rewind in test case
2020-09-04 10:17:00 +02:00
Andrew Kelley
338f155a02 Merge remote-tracking branch 'origin/master' into llvm11 2020-09-03 23:52:19 -07:00
Alexandros Naskos
e9807418e7 Added .pe ObjectFormat
MachO linker no longer collects unused dwarf debug information
2020-09-04 05:22:26 +03:00
Alexandros Naskos
e9b137f23a Completed basic PE linker for stage2
Added std.coff.MachineType
Added image characteristic and section flag valued to std.coff
Added std.Target.Cpu.Arch.toCoffMachine
Fixed stage2 --watch flag on windows
2020-09-04 05:15:03 +03:00
Alexandros Naskos
fe0ad8d6e9 Write PE section table 2020-09-04 05:12:27 +03:00
Alexandros Naskos
fac9a4e286 Start working on PE/COFF linking. 2020-09-04 05:12:26 +03:00
pfg
abe672956e Test 0 bit allocation 2020-09-03 16:33:47 -07:00
Felix (xq) Queißner
88724b2a89 Introduces a space after the ellipsis for test and progress. 2020-09-03 18:07:30 -04:00
Andrew Kelley
1034459170 Merge pull request #6243 from ifreund/uid-gid-cleanup
std: clean up usage of uid_t/gid_t, add seteuid/setegid to std.os
2020-09-03 18:05:59 -04:00
Andrew Kelley
17f36566de stage2: upgrade Scope.Container decls from ArrayList to HashMap 2020-09-03 15:02:38 -07:00
Andrew Kelley
f2bbd8a548 Merge pull request #6242 from Vexu/stage2
Stage2: slicing and split container scope from file scope
2020-09-03 17:22:57 -04:00
Jakub Konka
dac1cd7750 Write out simple Mach-O object file
This commit adds enough Mach-O linker implementation to write out simple
Mach-O object file. Be warned however, the object file is largely incomplete:
misses relocation info, debug symbols, etc. However, it seemed like a
good starting to get the basic understanding right.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-09-03 16:43:47 -04:00
Lachlan Easton
2a58e30bd5 std meta: fix use of alignOf in meta.cast 2020-09-03 14:11:04 -04:00
Andrew Kelley
39a80cf59e Merge pull request #6238 from Aransentin/master
Add the "sync" family of functions
2020-09-03 14:07:36 -04:00
Kenta Iwasaki
50e3906951 os: return error.SocketNotListening for EINVAL on accept (#6226) 2020-09-03 13:57:08 -04:00
LemonBoy
969547902b std: Fix silent overflow in float parsing code
A u64 can only hold 19 decimal digits, adjust the limit.
2020-09-03 18:14:19 +03:00
Vexu
1df0f3ac24 update uses of deprecated type field access 2020-09-03 18:10:40 +03:00
Vexu
4eeeda0f52 remove deprecated fields from types 2020-09-03 16:49:20 +03:00
Isaac Freund
d0d6647fdb std: add seteuid/setegid to std.os
Currently these are only implemented for linux.
2020-09-03 15:22:43 +02:00
Isaac Freund
01a365f1b0 std: ensure seteuid/setegid do not change saved id 2020-09-03 15:16:26 +02:00
Isaac Freund
e8a2aecd2f std: fix linux uid_t, use uid_t/gid_t in std.os
- correct uid_t from i32 to u32 on linux
- define uid_t and gid_t for OSes missing definitions
- use uid_t/gid_t instead of plain u32s throughout std.os
2020-09-03 15:08:37 +02:00
Vexu
6f0126e957 stage2: split Scope.Container from Scope.File 2020-09-03 15:06:45 +03:00
Vexu
1174cb1517 stage2: fix tokenizer float bug 2020-09-03 15:05:47 +03:00
Vexu
6ab0ac161e stage2: slice return type analysis 2020-09-03 15:05:47 +03:00
Vexu
2a628fd401 stage2: astgen slice 2020-09-03 15:05:46 +03:00
Vexu
ff7c6e1e3c stage2: astgen orelse 2020-09-03 15:05:43 +03:00
Vexu
9a59cdcd41 stage2: various small type fixes 2020-09-03 15:05:10 +03:00
Bas van den Berg
0a40a61548 os.send(to) and os.recv(from) functions made to work on windows. 2020-09-03 13:23:48 +02:00
Jens Goldberg
68818983ae Split the sync tests into sync and fsync 2020-09-03 09:52:26 +00:00
Jens Goldberg
e747d2ba17 Add C declarations and tests for the sync functions 2020-09-03 07:49:18 +00:00
pfg
bf1d83482b "Support" allocating 0 bit types 2020-09-02 22:28:37 -07:00
daurnimator
fb3c5b84ed std: add fmt option to escape non-printable characters 2020-09-02 19:18:36 -04:00
Andrew Kelley
c86108dd63 Merge pull request #6229 from LemonBoy/fix-6054
ir: Typecheck the sentinel value in *[N:S1]T to [S2]T casts
2020-09-02 19:13:21 -04:00
Aransentin
25f6663304 Add the sync functions 2020-09-02 22:16:40 +00:00
Andrew Kelley
405c7215a8 Merge pull request #6194 from LakeByTheWoods/fmt_indentation
Refactor zig fmt indentation. Remove indent from rendering code
2020-09-02 18:14:28 -04:00
Bas van den Berg
d80554cedf Made some changes and additions to the networking to make it work on windows. 2020-09-02 23:53:29 +02:00
Lachlan Easton
bb848dbeee zig fmt: Patch rename stream to ais (auto indenting stream) & other small refactors 2020-09-02 20:16:28 +10:00
LemonBoy
5f31d54064 std: ArrayList.initCapacity now respects the specified cap
Don't use the user-supplied cap as starting point for a resize. Doing so
overallocates memory and thus negates the whole point of specifying a
precise cap value.
2020-09-02 11:11:57 +02:00
LemonBoy
73a8c9beaa std: Don't trust stat() size in readAllAlloc fns
Some files such as the ones in /proc report a st_size of zero, try to
read the file anyway if we hit that case.
2020-09-02 11:11:57 +02:00
Andrew Kelley
12ce6eb8f6 stage2: support dbg_stmt at comptime 2020-09-02 00:09:24 -07:00
Sahnvour
90ace40e07 Merge pull request #5999 from Sahnvour/hashmap
New hashmap implementation
2020-09-02 08:52:32 +02:00
Tadeo Kondrak
1b2154dfe2 builtin: Add TypeInfo.StructField.is_comptime 2020-09-02 00:17:59 -04:00
Sahnvour
575fbd5e35 hash_map: rename to ArrayHashMap and add new HashMap implementation 2020-09-02 00:17:50 +02:00
Andrew Kelley
3f7cb14b26 Merge pull request #6225 from ziglang/stage2-comptime
stage2: introduce the ability for Scope.Block to be comptime
2020-09-01 15:44:45 -04:00
Andrew Kelley
4c13d020db stage2: proper split of requireRuntimeBlock and requireFunctionBlock
* improve the ZIR generated of variable decls
   - utilize the same ZIR for the type and init value when possible
   - init value gets a result location with the variable type.
     no manual coercion is required.
 * no longer use return instructions to extract values out of comptime
   blocks. Instead run the analysis and then look at the corresponding
   analyzed instruction, relying on the comptime mechanism to report
   errors when something could not be comptime evaluated.
2020-09-01 12:39:47 -07:00
pwzk
baa734c42a Fixing dylib search path 2020-09-01 13:53:12 -04:00
LemonBoy
dd4994a4e4 std: Fix C-string with missing NUL terminator
Spotted thanks to the stricter conversion rules.
2020-09-01 18:45:35 +02:00
LemonBoy
c51b871c45 ir: Typecheck the sentinel value in *[N:S1]T to [S2]T casts
Closes #6054
2020-09-01 17:29:10 +02:00
Lachlan Easton
7841c9b7d1 zig fmt: Fix merge errors 2020-09-01 21:59:27 +10:00
Lachlan Easton
671b3abe5d Merge remote-tracking branch 'ziglang/master' into fmt_indentation 2020-09-01 18:41:23 +10:00
Andrew Kelley
717b0e8275 stage2: introduce the ability for Scope.Block to be comptime
This gives zir_sema analysis the ability to check if the current scope
is expected to be comptime.
2020-08-31 23:34:58 -07:00
Lachlan Easton
bc24b86d82 zig fmt: Fix regression not covered by testing 2020-09-01 13:19:34 +10:00
Andrew Kelley
c354f074fa Merge remote-tracking branch 'origin/master' into llvm11 2020-08-31 15:49:44 -07:00
Andrew Kelley
26140678a5 ci: skip compile error tests on Windows
We're up against the 6 hour limit so this is a time-saving workaround.
Compile error tests are generally not OS-specific so the coverage from
the other platforms should be sufficient.
2020-08-31 14:54:05 -07:00
Jan200101
2148336a81 follow filesystem hierarchy standard when adding lib directories 2020-08-31 17:44:43 -04:00
Andrew Kelley
8dc58a4e94 Merge pull request #6208 from tadeokondrak/remove-@OpaqueType
Remove @OpaqueType
2020-08-31 17:44:03 -04:00
Andrew Kelley
4e97cf50d2 readme: link to wiki page for installing from a package manager 2020-08-31 14:41:01 -07:00
Andrew Kelley
212fe21d68 zen of zig: reword the last one a little bit 2020-08-31 14:40:08 -07:00
Andrew Kelley
0d94cb932f Merge pull request #6197 from LemonBoy/fix-6049
gpa: Fix bookkeeping logic
2020-08-31 17:38:17 -04:00
Tadeo Kondrak
82273f1a2a translate_c: fix shadowing on nested blocks 2020-08-31 20:29:57 +03:00
Lachlan Easton
029ec456bc zig fmt: Set indent_delta to 2 when rendering inline asm 2020-08-31 23:39:50 +10:00
Lachlan Easton
5aca3baea6 zig fmt: Remove dynamic stack from auto-indenting-stream 2020-08-31 23:39:50 +10:00
LemonBoy
29de809a92 gpa: Don't leak memory when the upper bound is hit 2020-08-31 12:35:25 +02:00
Andrew Kelley
400d8d0b82 Merge pull request #6212 from ziglang/update-glibc
Update to glibc 2.32
2020-08-31 03:32:21 -04:00
Tadeo Kondrak
96e46cdd6e std.zig.render: specify when rewrite should be removed 2020-08-30 23:45:47 -06:00
Tadeo Kondrak
c51de3c266 std.zig.render: rewrite @OpaqueType() to @Type(.Opaque) 2020-08-30 23:41:40 -06:00
Andrew Kelley
43ac5e5dac Merge pull request #6184 from tadeokondrak/TrailerFlags-update
std.meta.TrailerFlags: use @Type to improve API
2020-08-31 01:00:23 -04:00
Andrew Kelley
19d5dfba5f update glibc ABI files to 2.32 2020-08-30 21:28:11 -07:00
Andrew Kelley
dd8cc6b0f1 update glibc headers to 2.32 2020-08-30 21:27:30 -07:00
Andrew Kelley
eeadd55d15 fix tools/process_headers.zig regression
When upgrading to the new std lib HashMap API, the process_headers code
regressed because something that was supposed to be a pointer ended up
being a copy of a value. This resulted in the modification of a field
not being picked up.

Also switch from Sha256 to Blake3 while we're at it.
2020-08-30 21:24:41 -07:00
Tadeo Kondrak
a2c47d2b0b Remove @OpaqueType 2020-08-30 19:02:23 -06:00
Tadeo Kondrak
d3e5105ecc std.zig.ast: make getTrailer/setTrailer private and add getters/setters 2020-08-30 17:18:25 -06:00
daurnimator
1bb30c5e22 std.ChildProcess: pass CLOEXEC when creating error pipe 2020-08-30 14:21:14 -04:00
Jakub Konka
04361dd461 Add more missing MachO constants and structs
Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-08-30 09:47:36 +02:00
Andrew Kelley
427e2d689d Merge pull request #6189 from katesuyu/div-ceil
std: Add std.math.divCeil
2020-08-30 01:09:39 -04:00
Sahnvour
ac85befbb4 handle lack of privilege to create symbolic links on windows 2020-08-30 06:52:53 +02:00
LemonBoy
e355bcce36 compiler-rt: Add missing floatdisf routine
Add __floatdisf and __aeabi_l2f

Closes #6188
2020-08-30 00:28:18 -04:00
LemonBoy
ff4fde767f std: Open the eventfd fd with CLOEXEC flag
Make sure the fd we use to communicate with the parent process is not
leaked to the child process.

Closes #5966
2020-08-30 00:22:54 -04:00
Lachlan Easton
50c8a53188 Use ArrayList instead of fixed array for auto_indenting_stream 2020-08-30 10:32:21 +10:00
Lachlan Easton
7d950210a6 zig fmt review comments 2020-08-30 10:28:17 +10:00
LemonBoy
f20305d249 gpa: Fix bookkeeping logic
The backing allocator may return a block that's actually bigger than the
one required by the user, use the correct quantity when keeping track of
the allocation ceiling.

Closes #6049
2020-08-29 20:51:30 +02:00
wozeparrot
00301bbdd3 fix SimpleTextInputProtocol 2020-08-29 20:24:59 +03:00
Kate Tsuyu
e496485af4 std.math.divCeil: fix expectEqual argument order 2020-08-29 03:07:36 -04:00
Kate Tsuyu
552e2bf758 std.math.divCeil: use expectEqual for tests 2020-08-29 02:32:54 -04:00
Kate Tsuyu
340871f061 std.math.divCeil: move compile error back down 2020-08-29 00:37:10 -04:00
Kate Tsuyu
49e67ce0e8 std.math.divCeil: move compile error to top 2020-08-29 00:31:49 -04:00
Kate Tsuyu
933bfcff64 std.math.divCeil: support comptime_int/float 2020-08-29 00:21:17 -04:00
Lachlan Easton
a72b9d403d Refactor zig fmt indentation. Remove indent from rendering code and have a stream handle automatic indentation 2020-08-29 13:35:00 +10:00
joachimschmidt557
3750cc06fd Improve io.Reader.skipBytes and add tests 2020-08-28 19:42:36 +02:00
Kate Tsuyu
f577d12fbc std.math.divCeil: conform to more test cases 2020-08-28 11:20:42 -04:00
Kate Tsuyu
14b6fb88fb std.math.divCeil: handle floats correctlier 2020-08-28 09:55:50 -04:00
Kate Tsuyu
aacfef17d5 std.math.divCeil: handle floats correctly 2020-08-28 09:48:40 -04:00
Kate Tsuyu
9dfb917c20 std: Add std.math.divCeil 2020-08-28 08:58:51 -04:00
Tadeo Kondrak
e4b61aa527 std.meta.TrailerFlags fixes 2020-08-27 16:02:00 -06:00
Tadeo Kondrak
3c87872dc5 stage2: Update to new std.meta.TrailerFlags API 2020-08-27 15:21:19 -06:00
Tadeo Kondrak
ce8a3ef2de std.zig: Update to new std.meta.TrailerFlags API 2020-08-27 15:21:18 -06:00
Tadeo Kondrak
f94583076e std.meta.TrailerFlags: use @Type to improve API
- Use an enum of all field names instead of string literals
- Create a struct type with all fields optional instead of relying on
anonymous struct literals

This should provide better type inference, compile errors, and a
(subjectively) cleaner API.
2020-08-27 15:11:33 -06:00
Veikka Tuominen
f6cedfaaca Merge pull request #6160 from extrasharp/keyword-documentation
Add Keyword Reference section
2020-08-27 16:12:18 +03:00
Asherah Connor
dc7608da97 ensure main return type is not i8
Avoids a compile error from start.zig:

	/home/kivikakk/zig/build/lib/zig/std/start.zig:265:28: error:
	expected type 'u8', found 'i8'
			    return result;
				   ^
	/home/kivikakk/zig/build/lib/zig/std/start.zig:265:28: note:
	unsigned 8-bit int cannot represent all possible signed 8-bit
	values
			    return result;
2020-08-27 15:03:56 +03:00
Cléo Rebert
fc001110b4 Added edge case test to mem.count
Some implementations break on this edge case. Thought relevant to add it.
2020-08-27 04:12:28 -04:00
Andrew Kelley
5fed721290 Merge branch 'Vexu-stage2'
closes #6175
2020-08-26 19:53:49 -07:00
Andrew Kelley
b0995cb9f9 stage2: correct logic for analyzeIsNull 2020-08-26 19:53:36 -07:00
Vexu
cc26cb9b23 stage2: codegen needed for basic for loop 2020-08-26 19:50:56 -07:00
Vexu
fb28349349 stage2: astgen catch 2020-08-26 19:50:56 -07:00
Vexu
bf014d529a stage2: array access astgen 2020-08-26 19:50:56 -07:00
Vexu
bcd04089eb stage2: add helpful error message for invalid for operands 2020-08-26 19:50:56 -07:00
Vexu
b1aa2857ff stage2: astgen for loops 2020-08-26 19:50:56 -07:00
Sobeston
7d0bb0774e std.mem.count 2020-08-26 17:37:05 -04:00
Andrew Kelley
091d693c53 Merge pull request #6164 from jedisct1/cryptobench
Improve crypto benchmarks
2020-08-26 17:30:31 -04:00
Frank Denis
ad18078d53 forceEval() -> doNotOptimizeAway() 2020-08-26 10:50:34 +02:00
Frank Denis
0bd53dd203 Rename blackBox, move it to std.mem.forceEval() 2020-08-26 10:50:34 +02:00
Frank Denis
ff2e82f382 Rename at to tag in AEADs 2020-08-26 10:50:34 +02:00
Frank Denis
b8729ca1a0 Improve crypto benchmarks
- 1MiB objects on the stack doesn't play well with wasmtime.
Reduce these to 512KiB so that the webassembly benchmarks can run.
- Pass expected results to a blackBox() function. Without this, in
release-fast mode, the compiler could detected unused return values,
and would produce results that didn't make sense for siphash.
- Add AEAD constructions to the benchmarks.
- Inline chacha20Core() makes it 4 times faster.
- benchmarkSignatures() -> benchmarkSignature() for consistency.
2020-08-26 10:50:34 +02:00
Andrew Kelley
3abf9e1457 Merge pull request #6163 from ziglang/stage2-condbr
stage2: codegen for conditional branching
2020-08-26 04:02:43 -04:00
Andrew Kelley
0c5faa61ae stage2: codegen: fix reuseOperand not doing death bookkeeping 2020-08-26 01:00:04 -07:00
Andrew Kelley
237d9a105d stage2: support debug dumping zir as a build option
So that it's not needed to manually comment and uncomment the debug
code.
2020-08-25 22:44:18 -07:00
Andrew Kelley
e97157f71c stage2: codegen for conditional branching
* Move branch-local register and stack allocation metadata to the
   function-local struct. Conditional branches clone this data in order
   to restore it after generating machine code for a branch.
   Branch-local data is now only the instruction table mapping *ir.Inst
   to MCValue.
 * Implement conditional branching
   - Process operand deaths
   - Handle register and stack allocation metadata
 * Avoid storing unreferenced or void typed instructions into
   the branch-local instruction table.
 * Fix integer types reporting the wrong value for hasCodeGenBits.
 * Remove the codegen optimization for eliding length-0 jumps. I need to
   reexamine how this works because it was causing invalid jumps to be
   emitted.
2020-08-25 22:44:18 -07:00
Andrew Kelley
b68fa9970b stage2 codegen: Rework genCondBr
so that the arch-independent logic isn't buried and duplicated.
2020-08-25 22:44:18 -07:00
Jakub Konka
982ab7df6c Merge pull request #6161 from kubkon/macho-text
Add (empty) __TEXT segment load command
2020-08-26 07:03:58 +02:00
Jakub Konka
55dc81ba2a Hardcode runtime (libSystem) version to minimum possible
While we try to work out what the correlation between the OS and runtime
versions is, this commit hardcodes the latter to the minimum (compat)
version of 1.0.0.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-08-26 06:30:54 +02:00
Andrew Kelley
4971400bdc Merge remote-tracking branch 'origin/master' into llvm11 2020-08-25 20:00:57 -07:00
Andrew Kelley
3e24e95892 std.rand: promote normal comments to doc comments 2020-08-25 19:51:40 -07:00
Andrew Kelley
b498eebfd4 std.math.big: fix use-after-free
When there is parameter aliasing, the ensureCapacity calls can cause the
Const parameters to become dangling pointers.

See #6167
2020-08-25 19:49:40 -07:00
Andrew Kelley
973e6c978c std: clean up GeneralPurposeAllocator memset code
The freeSlot function was only called once so I inlined the logic and
utilized some of the other locals that were in scope.
2020-08-25 19:48:39 -07:00
Andrew Kelley
96368b9f39 update libunwind to llvm 11rc2 2020-08-25 14:13:14 -07:00
Andrew Kelley
a8f0f37adb Merge remote-tracking branch 'origin/master' into llvm11 2020-08-25 14:12:48 -07:00
Andrew Kelley
6fb105fdd7 std: GeneralPurposeAllocator: set freed bytes to undefined
Helps catch use-after-free. Caught a couple issues in the self-hosted
compiler.
2020-08-25 13:36:40 -07:00
Andrew Kelley
ea6a076065 stage2: fix use-after-free in elf linker code 2020-08-25 13:36:15 -07:00
Andrew Kelley
84d50c892d stage2: astgen: kill the "lvalue" ResultLoc tag 2020-08-24 16:13:10 -07:00
Andrew Kelley
b30c538076 Merge branch 'Vexu-stage2'
closes #6148
2020-08-24 15:42:30 -07:00
Andrew Kelley
16d54c70eb stage2: getErrorValue takes advantage of HashMap getOrPut API 2020-08-24 15:41:59 -07:00
Vexu
5de9aac749 stage2: error set types 2020-08-24 15:36:42 -07:00
Vexu
bc1d55a1d1 stage2: fix field access of array pointers 2020-08-24 15:36:42 -07:00
Vexu
1520e084cb stage2: implement accessing error values 2020-08-24 15:36:42 -07:00
Vexu
e9b15ac9a0 stage2: error set declarations 2020-08-24 15:36:42 -07:00
Vexu
16d7db59ed stage2: anyframe and error union types 2020-08-24 15:36:42 -07:00
Vexu
d62c12e077 stage2: astgen prefix ops 2020-08-24 15:36:42 -07:00
extrasharp
d4b1ed1bc9 Add "table-wrapper" div 2020-08-24 17:29:53 -05:00
Andrew Kelley
fd9f509d6d Revert "Merge pull request #6137 from Jan200101/update/glibc-2.32"
This reverts commit bb9c3118ed, reversing
changes made to 7015d84e0c.

This is missing quite a few headers
2020-08-24 15:19:34 -07:00
Rocknest
140c599559 Fix & update windows version stuff (#6157)
* Update windows version constants
* Add docs
2020-08-24 16:47:44 -04:00
Jakub Konka
43b6d0e4b1 Add (empty) __TEXT segment load command
Also, link against `libSystem` by default when targeting macOS.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-08-24 21:18:27 +02:00
extrasharp
4d1710c899 Make changes 2020-08-24 13:12:23 -05:00
extrasharp
7d6ed1cd85 Add Keyword Reference section 2020-08-24 11:11:42 -05:00
Jakub Konka
9745e7b512 Clean up draft for merging into upstream
Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-08-24 17:59:44 +02:00
Jakub Konka
1698e6d7a7 Link against libSystem when generating Mach-O exe
This is required when generating an exe on macOS.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-08-24 17:59:44 +02:00
Jakub Konka
2516db9645 Specify path to dyld in Mach-O
This is required since an exec on macOS always has to link against
libSystem.dylib.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-08-24 17:59:44 +02:00
Vexu
c1ee9efb7c fix error note using invalid source node
Closes #6153
2020-08-24 15:24:00 +03:00
Vexu
9589dc4c95 add error checks to @Type 2020-08-24 11:13:43 +03:00
Andrew Kelley
4d7013f7d3 Merge pull request #6146 from daurnimator/no_ctty
Use O_NOCTTY open flag
2020-08-23 23:26:58 -04:00
Andrew Kelley
385786eedc Merge pull request #6097 from joachimschmidt557/stage2-arm
Start working on stage2 ARM backend
2020-08-23 23:07:23 -04:00
LiterallyVoid
4bbea3422a Fix unused argument error when formatting std.Target 2020-08-23 22:47:57 -04:00
Andrew Kelley
bb9c3118ed Merge pull request #6137 from Jan200101/update/glibc-2.32
Update to glibc 2.32
2020-08-23 22:47:13 -04:00
Luna
7015d84e0c remove licensing comments from init-exe/init-lib 2020-08-23 22:45:18 -04:00
joachimschmidt557
4f2618e75b stage2: Add Hello World test for ARM backend 2020-08-23 23:13:41 +02:00
joachimschmidt557
b2254023e4 stage2: Implement setReg, call, ret, asm for ARM
These changes enable a Hello World example. However, all implemented
codegen is not yet feature-complete.

- asm only supports 'svc #0' at the moment
- call only supports leaf functions at the moment
- setReg uses a naive method at the moment
2020-08-23 22:33:47 +02:00
joachimschmidt557
1c53c07053 stage2: Implement genBreakpoint for ARM 2020-08-23 22:29:00 +02:00
joachimschmidt557
f31cee5393 Start working on stage2 ARM backend
- add codegen/arm.zig with some basic functionality (load/store,
  data processing, branching, software interrupts)
2020-08-23 22:27:46 +02:00
daurnimator
129d3e274d std: use O_NOCTTY flag 2020-08-24 02:28:31 +10:00
daurnimator
23a81b4396 std: refactor fs.openFileZ flag handling 2020-08-24 02:27:26 +10:00
Jan200101
53a2431713 update glibc abi list for 2.32 2020-08-22 22:43:01 +02:00
Jan200101
c61ea4cdb7 update glibc headers to 2.32 2020-08-22 22:42:58 +02:00
Andrew Kelley
4e63cae369 Merge branch 'pixelherodev-spu_ii'
closes #6096
2020-08-22 13:38:54 -07:00
Andrew Kelley
54f3b0a560 stage2: clean up SPU Mk II code
* move SPU code from std to self hosted compiler
 * change std lib comments to be descriptive rather than prescriptive
 * avoid usingnamespace
 * fix case style of error codes
 * remove duplication of producer_string
 * generalize handling of less than 64 bit arch pointers
 * clean up SPU II related test harness code
2020-08-22 13:36:08 -07:00
Noam Preil
24efbf5ddf Codegen: Move REX assert to comptime 2020-08-22 12:45:29 -07:00
Noam Preil
ad9df43e49 Tests: limit SPU-II cycle count 2020-08-22 12:45:29 -07:00
Noam Preil
f448b518f8 SPU-II: use undefined1 as breakpoint 2020-08-22 12:45:29 -07:00
Noam Preil
222e23c678 Linker: make defaults read-only 2020-08-22 12:45:29 -07:00
Noam Preil
096c5d5e4b Tests: implement SPU-II harness 2020-08-22 12:45:29 -07:00
Noam Preil
fa1d18a155 Linker: fix GOT production on 16-bit targets 2020-08-22 12:45:29 -07:00
Noam Preil
f2796239ba SPU-II: Fix logging in interp, remove JIT-compat code 2020-08-22 12:45:29 -07:00
Noam Preil
3a9af0c88b SPU-II: Ignore @breakpoint for now 2020-08-22 12:45:29 -07:00
Noam Preil
f2fef240a1 SPU-II: Test harness skeleton 2020-08-22 12:45:29 -07:00
Noam Preil
f18636fa58 SPU-II: Add common definitions 2020-08-22 12:45:29 -07:00
Noam Preil
8c321f0cf5 SPU-II: Fix linking 2020-08-22 12:45:29 -07:00
Noam Preil
cdefc6acba SPU-II: Implement function calls 2020-08-22 12:45:29 -07:00
Noam Preil
d005ff16c6 SPU-II: undefined0 inline asm 2020-08-22 12:45:29 -07:00
Noam Preil
803a1025bb Targets: add SPU Mark II architecture 2020-08-22 12:45:29 -07:00
Andrew Kelley
29051a0674 stage2: codegen: fix crash
I forgot to do -Denable-qemu -Denable-wasmtime when testing yesterday,
sorry about that.

In reuseOperand, the code assumed a re-used register would be tracked in
the register table but that is not always the case.
2020-08-22 12:44:45 -07:00
Frank Denis
2d402157d9 Improve documentation on siphash recommended parameters 2020-08-22 15:12:54 -04:00
Frank Denis
f540dc1b7e cache_hash: hash function change
This makes the `cache_hash` hash function easier to replace.

BLAKE3 would be a natural fit for hashing large files, but:
- second preimage resistance is not necessary for the cache_hash use cases
- our BLAKE3 implementation is currently very slow

Switch to SipHash128, which gives us an immediate speed boost.
2020-08-22 15:10:33 -04:00
Matthew Knight
0fa3cfdb4a Bpf: move under os/linux instead of bits (#6126)
* moved bpf syscall, added some bpf instructions and tests

* had to move bpf out of bits so that a freestanding target could import it

* removed line

* fixed imports
2020-08-22 15:08:01 -04:00
Jan200101
9605e5363b update update_glibc and process_headers to latest zig 2020-08-22 16:38:03 +03:00
Jakub Konka
69de1a51cd Add entry_point_command struct to Mach-O definitions
The `entry_point_command` is a replacement for `thread_command`, and
is used for main executables to specify the location of `main()`
entry point.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-08-22 04:14:27 -04:00
Andrew Kelley
55d7c399c1 Merge pull request #6119 from tadeokondrak/@Type(.Enum)
Implement @Type for Enum
2020-08-22 03:21:46 -04:00
Tadeo Kondrak
a049c31f21 Remove TypeInfo.Error.value 2020-08-22 03:20:12 -04:00
Frank Denis
e919744c7a Promote hash/siphash to crypto/siphash
SipHash *is* a cryptographic function, with a 128-bit security level.

However, it is not a regular hash function: a secret key is required,
and knowledge of that key allows collisions to be quickly computed offline.

SipHash is therefore more suitable to be used as a MAC.

The same API as other MACs was implemented in addition to functions directly
returning an integer.

The benchmarks have been updated accordingly.

No changes to the SipHash implementation itself.
2020-08-22 02:47:50 -04:00
Isaac Freund
9ab4281856 std: remove init functions from linked list nodes
These functions are rather useless and redundant as initializing the
struct directly is just as easy:

var node = TailQueue(u32).Node{ .data = 42 };
2020-08-22 02:47:39 -04:00
Andrew Kelley
f18b92ef3a stage2: implement spilling registers to the stack 2020-08-21 23:36:21 -07:00
Tadeo Kondrak
351701bcad @Type for Enum fix: use correct decls_scope 2020-08-21 17:45:30 -06:00
Andrew Kelley
f9bd049c89 Merge remote-tracking branch 'origin/master' into llvm11 2020-08-21 14:50:37 -07:00
Tadeo Kondrak
c31e8701d7 Update compile-errors test for @Type(.Enum) changes 2020-08-21 15:00:23 -06:00
Andrew Kelley
dad7af0b37 Merge pull request #6116 from jedisct1/polyfast
Make poly1305 faster
2020-08-21 16:52:33 -04:00
Tadeo Kondrak
5a5956bd20 Implement @Type for Enum 2020-08-21 14:31:24 -06:00
Andrew Kelley
89b6c47e04 stage2: decouple codegen.zig from ELF
See #6113 for an alternate way of doing this that we didn't end up
following.

Closes #6079.

I also took the opportunity here to extract C.zig and Elf.zig from
link.zig.
2020-08-21 13:25:59 -07:00
Isaac Freund
37ad9f38dc std: sync TailQueue with new SinglyLinkedList API
The API of SinglyLinkedList was changed in 93384f7, removing the init
function as well as the redundant allocation helper functions.

This commit makes parallel changes to the API of TailQueue in order to
keep the standard library consistent.
2020-08-21 15:59:50 -04:00
Andrew Kelley
a2f1f01e77 Merge branch 'mattnite-bpf-insn'
closes #6090
2020-08-21 11:41:25 -07:00
Matt Knight
80fabe1850 fixed bpf namespace 2020-08-21 11:40:35 -07:00
Matt Knight
bc1536f4bf decided to split up loading of 64-bit immediates 2020-08-21 11:40:35 -07:00
Matt Knight
7f1378909b moved bpf syscall, added some bpf instructions and tests 2020-08-21 11:40:35 -07:00
Frank Denis
0fe6677736 No need to keep a 128-bit carry around 2020-08-21 20:33:16 +02:00
Frank Denis
2fc2ebd920 Force myself to use unusual integer sizes a little bit more :) 2020-08-21 19:43:06 +02:00
Frank Denis
c9218f1719 Make poly1305 faster 2020-08-21 16:30:52 +02:00
Jakub Konka
243b5c7a88 Add macosx end-to-end smoke test
This test case will grow as the linker gets more functionality.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-08-21 09:41:05 +02:00
Andrew Kelley
e0a38f7f3e stage2: make the cache dir if it doesn't already exist 2020-08-20 23:53:34 -07:00
Andrew Kelley
6bbb168f66 Merge branch 'Vexu-stage2'
closes #6107
2020-08-20 17:26:05 -07:00
Andrew Kelley
73d16d015e stage2: reorganize tests
The main test cases are now in `test/stage2/test.zig` which can then
call addCases on other files if it wants to organize things differently.
2020-08-20 17:25:09 -07:00
Andrew Kelley
56ea04cb6d stage2: don't test compile errors of ZIR 2020-08-20 17:19:26 -07:00
Andrew Kelley
7d6d4b1473 stage2: move all tests to compare_output.zig 2020-08-20 17:15:01 -07:00
Andrew Kelley
f54b2e2da6 add missing mutability check in simplePtrType 2020-08-20 17:08:01 -07:00
Vexu
6a053ffcc8 stage2: comptime decl 2020-08-20 16:42:48 -07:00
Vexu
d312d64c9a stage2: slice types 2020-08-20 16:42:48 -07:00
Vexu
9568248450 stage2: complex pointer types 2020-08-20 16:42:48 -07:00
Vexu
ebfe723f3c stage2: implement rest of simple pointer types 2020-08-20 16:42:48 -07:00
Frank Denis
eef111fe78 Fix missing init() update in std/build/write_file.zig 2020-08-20 19:21:10 -04:00
Andrew Kelley
21106b9c9f Merge pull request #6095 from jedisct1/crypto-reorg
Breaking: sort std/crypto functions into categories
2020-08-20 19:01:22 -04:00
Frank Denis
3edace34d3 Update tools/process_headers.zig 2020-08-21 00:57:29 +02:00
Frank Denis
fc55cd458a Hash functions now accept an option set
- This avoids having multiple `init()` functions for every combination
of optional parameters
- The API is consistent across all hash functions
- New options can be added later without breaking existing applications.
  For example, this is going to come in handy if we implement parallelization
  for BLAKE2 and BLAKE3.
- We don't have a mix of snake_case and camelCase functions any more, at
least in the public crypto API

Support for BLAKE2 salt and personalization (more commonly called context)
parameters have been implemented by the way to illustrate this.
2020-08-21 00:51:14 +02:00
Andrew Kelley
9cfcd0c296 Merge pull request #6103 from Vexu/extern
Disallow extern variables with initializers.
2020-08-20 18:35:31 -04:00
heidezomp
1ca49b92c6 add UTIME_NOW and UTIME_OMIT constants for use in utimensat/futimens
copied from lib/libc/include/generic-musl/sys/stat.h
2020-08-20 17:02:58 -04:00
Frank Denis
adf3d00e87 Remove explicit comptime 2020-08-20 23:02:10 +02:00
Frank Denis
446597bd3c Remove the reset() function from hash functions
Justification:
- reset() is unnecessary; states that have to be reused can be copied
- reset() is error-prone. Copying a previous state prevents forgetting
  struct members.
- reset() forces implementation to store sensitive data (key, initial state)
  in memory even when they are not needed.
- reset() is confusing as it has a different meaning elsewhere in Zig.
2020-08-20 23:02:10 +02:00
Frank Denis
f92a5d7944 Repair crypto/benchmark; add BLAKE2b256
Some MACs have a 64-bit output
2020-08-20 23:02:10 +02:00
Frank Denis
3bed749b1c Add truncated SHA512 variants 2020-08-20 23:02:10 +02:00
Frank Denis
6f9ea9eaef Breaking: sort std/crypto functions into categories
Instead of having all primitives and constructions share the same namespace,
they are now organized by category and function family.

Types within the same category are expected to share the exact same API.
2020-08-20 23:02:05 +02:00
Andrew Kelley
776bfb0ee6 Merge pull request #6099 from tadeokondrak/@Type(.Struct)
Implement @Type for structs
2020-08-20 16:57:10 -04:00
Andrew Kelley
3aeeb21b82 update libunwind to llvm11rc2 2020-08-20 13:36:44 -07:00
Andrew Kelley
1a4059ed88 allow running the stage2 tests in release mode 2020-08-20 13:16:04 -07:00
Andrew Kelley
4a69b11e74 add license header to all std lib files
add SPDX license identifier
copyright ownership is zig contributors
2020-08-20 16:07:04 -04:00
Vexu
717e2a365d correct llvm linkage conversion
when weakly exporting external declaration we need to pass LLVMExternalWeakLinkage
2020-08-20 17:12:26 +03:00
Vexu
d25674a51e disallow extern variables with initializers 2020-08-20 11:35:33 +03:00
Vexu
a553947a51 translate-c: correctly put static and extern local variables in global scope 2020-08-20 10:45:55 +03:00
Jakub Konka
83b0e52079 Merge pull request #6102 from kubkon/macho-pagezero
Write page zero as first segment for Mach-O exes
2020-08-20 09:34:33 +02:00
Jakub Konka
ad79b80524 Apply suggestions from code review
Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2020-08-20 09:14:37 +02:00
Vexu
adc5bce5e8 translate-c: correct translation of global variables
* externs with intializers are translated as exports
* non extern without explicit initialization are zero initalized
2020-08-20 10:08:27 +03:00
Jakub Konka
9164daaa39 Write page zero as first segment for Mach-O exes
According to the Mach-O file format reference, the first
load command should be a `__PAGEZERO` segment command. The
segment is located at virtual memory location 0, has no protection
rights, and causes acccesses to NULL to immediately crash.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-08-20 08:33:40 +02:00
Andrew Kelley
91de5c212f Merge branch 'strangebug-fix/std-dbg-warn-hangs-windows'
closes #5407
2020-08-19 20:53:32 -07:00
Andrew Kelley
23c427b5fb windows: match the same error code for EBADF 2020-08-19 20:51:06 -07:00
StrangeBug
59711becc7 Add handler for INVALID_HANDLE to prevent infinite loop when stderr is not available. 2020-08-19 20:49:25 -07:00
Andrew Kelley
b1c7334355 Merge pull request #5745 from lun-4/ebadf-error
map EBADF to error values for read and write
2020-08-19 23:46:22 -04:00
Andrew Kelley
a30950706f Merge branch 'Vexu-stage2'
closes #6093
2020-08-19 17:59:37 -07:00
Andrew Kelley
9ec9c0f5e5 optimize the memory layout of Module.Fn and Module.Var
`is_pub` added to `Fn` would cost us an additional 8
bytes of memory per function, which is a real bummer
since it's only 1 bit of information.

If we wanted to really remove this, I suspect we could
make this a function isPub() which looks at the AST of
the corresponding Decl and finds if the FnProto AST node
has the pub token. However I saw an easier approach -

The data of whether something is pub or not is actually
a property of a Decl anyway, not a function, so we can
look at moving the field into Decl. Indeed, doing this,
we see that Decl already has deletion_flag: bool which
is hiding in the padding bytes between the enum (1 byte)
and the following u32 field (generation). So if we put
the is_pub bool there, it actually will take up no
additional space, with 1 byte of padding remaining.

This was an easy reworking of the code since any
func.is_pub could be changed simply to func.owner_decl.is_pub.

I also modified `Var` to make the init value non-optional
and moved the optional bit to a has_init: bool field. This is worse from
the perspective of control flow and safety, however it makes
`@sizeOf(Var)` go from 32 bytes to 24 bytes. The more code we can fit
into memory at once, the more justified we are in using the compiler as
a long-running process that does incremental updates.
2020-08-19 17:52:22 -07:00
Vexu
5fdcb1a792 stage2: emit zir variable fix, array type and enum literal support 2020-08-19 16:12:29 -07:00
Vexu
9801047bdb stage2: handle var attributes 2020-08-19 16:12:29 -07:00
Vexu
ab8a9a6605 stage2: fix astgen of decl ref, add test for global consts 2020-08-19 16:12:29 -07:00
Vexu
338a495648 stage2: implement global variables 2020-08-19 16:12:29 -07:00
Tadeo Kondrak
8126421d07 Small fixes for @Type(.Struct) 2020-08-19 16:36:22 -06:00
Vincent Rischmann
b0846b6ecb builder: implement integer options 2020-08-19 17:41:43 -04:00
Tadeo Kondrak
759485cc32 Update compile-errors test for @Type(.Struct) 2020-08-19 15:26:03 -06:00
Tadeo Kondrak
b46d764fd9 Implement @Type for structs without decls support 2020-08-19 14:55:42 -06:00
Tadeo Kondrak
0f677810ea Remove offset field from TypeInfo.StructField
This isn't needed with @bitOffsetOf/@byteoffsetOf and complicates
@Type handling.
2020-08-19 14:55:40 -06:00
dbandstra
a237283d90 fixes and improvements for parseCharLiteral 2020-08-19 16:30:42 -04:00
Andrew Kelley
083c0f1ceb stage2 codegen: proper abstraction for re-using dying operands
closes #6064
2020-08-18 23:11:56 -07:00
Andrew Kelley
dc35b8641b stage2: Module enumerates the possible top level decls 2020-08-18 23:11:56 -07:00
Jakub Konka
5fe878cd42 Merge pull request #6085 from kubkon/macho-header
Write out Mach-O header
2020-08-19 07:50:11 +02:00
Jakub Konka
ffdeb6af91 Update src-self-hosted/link/MachO.zig
Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2020-08-19 07:43:33 +02:00
Nathan Michaels
4237f1afc7 Change std.debug.warn to std.log.info in init-exe template. (#5941) 2020-08-18 22:47:38 -04:00
Andrew Kelley
771f40204e Merge pull request #6086 from Vexu/stage2
Stage2: more astgen stuff
2020-08-18 22:02:55 -04:00
Andrew Kelley
626d94c2a1 Merge pull request #6088 from ifreund/s2-wasm-rework
stage2/wasm: do incremental compilation in-memory
2020-08-18 21:37:20 -04:00
Isaac Freund
6242ae35f3 stage2/wasm: implement function calls
During codegen we do not yet know the indexes that will be used for
called functions. Therefore, we store the offset into the in-memory
code where the index is needed with a pointer to the Decl and use this
data to insert the proper indexes while writing the binary in the flush
function.
2020-08-19 02:05:13 +02:00
Isaac Freund
fe3aa4ccd0 stage2/wasm: do incremental compilation in-memory
Before this commit the wasm backend worked similarly to elf. As
functions were generated they were written directly to the output file
and existing code was shifted around in the file as necessary. This
approach had several disadvantages:

- Large amounts of padding in the output were necessary to avoid
expensive copying of data within the file.
- Function/type/global/etc indexes were required to be known at the time
of preforming codegen, which severely limited the flexibility of where
code could be placed in the binary
- Significant complexity to track the state of the output file through
incremental updates

This commit takes things in a different direction. Code is incrementally
compiled into in-memory buffers and the entire binary is rewritten using
these buffers on flush. This has several advantages:

- Significantly smaller resulting binaries
- More performant resulting binaries due to lack of indirection
- Significantly simpler compiler code
- Indexes no longer need to be known before codegen. We can track where
Decls must be referenced by index insert the proper indexes while
writing the code in the flush() function. This is not yet implemented
but is planned for the next commit.

The main disadvantage is of course increased memory usage in order to
store these buffers of generated code.
2020-08-19 02:05:01 +02:00
Isaac Freund
741fb8d306 stage2/link: clarify comments on calling order 2020-08-18 19:47:20 -04:00
Andrew Kelley
1de2c647df Merge remote-tracking branch 'origin/master' into llvm11 2020-08-18 15:32:42 -07:00
Andrew Kelley
15bcfcd368 stage2: fix use-after-free when printing ZIR 2020-08-18 15:25:01 -07:00
Andrew Kelley
31b58acdae stage2: minor cleanup 2020-08-18 15:11:24 -07:00
Andrew Kelley
f950f5452b test_runner: don't assume the GeneralPurposeAllocator config
This allows changing the config in only 1 location (std.testing)
2020-08-18 15:10:31 -07:00
Andrew Kelley
583b843803 std.heap.GeneralPurposeAllocator: add never_unmap config option
This is a temporary debugging trick you can use to turn segfaults into more helpful
logged error messages with stack trace details. The downside is that every allocation
will be leaked!
2020-08-18 15:09:48 -07:00
Andrew Kelley
5547abd2d1 build: -Dforce-link-libc now also applies to test-stage2 2020-08-18 15:08:43 -07:00
Jakub Konka
34e628a0a0 Fix compile error
Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-08-18 23:35:31 +02:00
Jakub Konka
e4b3da2720 Write out Mach-O header
This commit write out Mach-O header in the linker's `flush`
method. The header currently only populates the magic number,
filetype, and cpu info.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-08-18 23:35:31 +02:00
Veikka Tuominen
d139e44cfa Merge pull request #5495 from xackus/fix_5314
stage1: fix non-exhaustive enums with one field
2020-08-18 23:55:44 +03:00
Andrew Kelley
e2c741f1e7 std.cache_hash: additionally use file size to detect modifications
I have observed on Linux writing and reading the same file many times
without the mtime changing, despite the file system having nanosecond
granularity (and about 1 millisecond worth of nanoseconds passing between
modifications). I am calling this a Linux Kernel Bug and adding file
size to the cache hash manifest as a mitigation. As evidence, macOS does
not exhibit this behavior.

This means it is possible, on Linux, for a file to be added to the cache
hash, and, if it is updated with the same file size, same inode, within
about 1 millisecond, the cache system will give us a false positive,
saying it is unmodified. I don't see any way to improve this situation
without fixing the bug in the Linux kernel.

closes #6082
2020-08-18 12:44:00 -07:00
Vexu
e4aefc6d0f stage2: split ref from lvalue and add compile error for invalid assignments 2020-08-18 22:42:35 +03:00
Vexu
2b45e23477 stage2: character literals and multiline strings 2020-08-18 20:10:18 +03:00
Andrew Kelley
bdb8c49418 stage1: update compile error tests
follow-up to 56c81c713f
2020-08-18 08:44:34 -07:00
Vexu
e0b01bd4a9 stage2: enum literals 2020-08-18 14:28:33 +03:00
Vexu
31d8efc6b3 stage2: validate param and variable types 2020-08-18 13:57:09 +03:00
Vexu
7c15c9428e stage2: array types 2020-08-18 12:36:00 +03:00
Vexu
3eb8f7be10 stage2: astgen bool and/or 2020-08-18 11:38:56 +03:00
Andrew Kelley
c0517bf1f6 std.cache_hash: temporary workaround for mtime precision on linux
See #6082
2020-08-18 01:30:57 -07:00
Andrew Kelley
56c81c713f stage1: let \r\n slide 2020-08-18 01:29:34 -07:00
Vexu
0977e41407 stage2: ensure discarded error union payload is void 2020-08-18 10:36:57 +03:00
Soren
60ea87340e Fix opaque structs and C++ mangling 2020-08-18 00:31:29 -04:00
Frank Denis
8d60047697 ristretto255: add uniform string->element map & fast equivalence check 2020-08-18 00:31:02 -04:00
Eleanor Bartle
fa8935426b Cleaned up RISC-V instruction creation, added 32-bit immediates (#6077)
* Implemented all R-type arithmetic/logical instructions

* Implemented all I-type arithmetic/logical instructions

* Implemented all load and store instructions

* Implemented all of RV64I except FENCE
2020-08-18 00:30:00 -04:00
Andrew Kelley
3cc1f8b624 Merge pull request #6056 from ifreund/wasm-backend
stage2: add a wasm backend
2020-08-18 00:28:05 -04:00
Andrew Kelley
ce8b9c0c5c std.cache_hash: don't trust mtime granularity to be better than 1ms
I empirically observed mtime not changing when rapidly writing the same
file name within the same millisecond of wall clock time, despite the
mtime field having nanosecond precision.

I believe this fixes the CI test failures.
2020-08-17 21:26:33 -07:00
Ashish Shekar
27cb23cbc5 Handle singular param count word in error messages (#6073) 2020-08-17 22:18:29 -04:00
Matthew Knight
d605af511a added bpf() syscall and some supporting structs (#6061)
* added bpf syscall and some supporting structs

* moved bpf to bits and added flags
2020-08-17 22:17:04 -04:00
Andrew Kelley
e26dda5308 Merge branch 'Sergeeeek-master'
closes #5394
closes #4427
2020-08-17 18:57:34 -07:00
Andrew Kelley
4462c60639 stage2: implement compiler id hash and add it to zig env 2020-08-17 18:56:27 -07:00
Andrew Kelley
a916f63940 std.cache_hash: fix bug parsing inode
This resulted in false negatives cache misses.
2020-08-17 18:49:33 -07:00
Andrew Kelley
18ac998767 zig env: add global_cache_dir field 2020-08-17 17:52:13 -07:00
Andrew Kelley
502d413621 simplify zig info and rename it to zig env
also add version to it
2020-08-17 17:06:43 -07:00
Isaac Freund
9f44284ad5 stage2/wasm: add basic test cases 2020-08-18 01:47:03 +02:00
Sergey Poznyak
80e70735fb add zig info command 2020-08-17 16:35:32 -07:00
Andrew Kelley
044e3ca592 Merge branch 'lun-4-signalfd-libc'
closes #6071
2020-08-17 16:20:23 -07:00
Andrew Kelley
ae2c88754d std: signalfd: fix the types of things; add test 2020-08-17 16:19:57 -07:00
Luna
293b07df12 add signalfd to std.c.linux 2020-08-17 16:05:35 -07:00
Luna
2deb07a001 rename signalfd4 to signalfd 2020-08-17 16:05:35 -07:00
Isaac Freund
f9963909a1 stage2/wasm: only free types after func overwrite
Functions which are free'd are not immediately removed from the binary
as this would cause a shifting of function indexes. Instead, they hang
around until they can be overwritten by a new function. This means that
the types associated with these dead functions must also remain until
the function is overwritten to avoid a type mismatch.
2020-08-18 01:01:13 +02:00
Isaac Freund
60fb50ee5a stage2/wasm: write exports on flush, cleanup
Exports now have a dirty flag and are rewritten on flush if this flag
has been set.

A couple other minor changes have been made based on Andrew's review.
2020-08-18 01:01:13 +02:00
Isaac Freund
97300896ed stage2/wasm: implement trivial codegen
We now generate code for returning constants of any of the basic types.
2020-08-18 01:01:04 +02:00
Isaac Freund
3370b5f109 stage2/wasm: implement basic container generation
Thus far, we only generate the type, function, export, and code
sections. These are sufficient to generate and export simple functions.

Codegen is currently hardcoded to `i32.const 42`, the main goal of this
commit is to create infrastructure for the container format which will
work with incremental compilation.
2020-08-18 00:32:58 +02:00
Andrew Kelley
96a27557e2 stage2 test harness: at least build all compare output tests
This should have been removed with an earlier commit that improved the
test harness.
2020-08-17 15:27:41 -07:00
Veikka Tuominen
d8fb377e2a Merge pull request #6060 from Vexu/stage2
Stage2: more optionals stuff
2020-08-18 00:15:36 +03:00
Andrew Kelley
624e643872 Merge pull request #6046 from heidezomp/std-log-scoped-part2
std.log: (breaking) remove scope parameter from logging functions
2020-08-17 16:59:27 -04:00
Andrew Kelley
c00d3d47f0 Merge branch 'jedisct1-xchacha20'
closes #6074
2020-08-17 13:56:13 -07:00
Frank Denis
5fabb44aeb Export crypto.aead 2020-08-17 13:55:40 -07:00
Frank Denis
cd591a9b25 No need for an explicit deref 2020-08-17 13:54:01 -07:00
Frank Denis
795033c35f std/crypto: XChaCha20, detached modes and standard AEAD API
* Factor redundant code in std/crypto/chacha20

* Add support for XChaCha20, and the XChaCha20-Poly1305 construction.

XChaCha20 is a 24-byte version of ChaCha20, is widely implemented
and is on the standards track:
https://tools.ietf.org/html/draft-irtf-cfrg-xchacha-03

* Add support for encryption/decryption with the authentication tag
detached from the ciphertext

* Add wrappers with an API similar to the Gimli AEAD type, so that
we can use and benchmark AEADs with a common API.
2020-08-17 13:54:01 -07:00
Vexu
2948f2d262 fix cast from invalid non-exhaustive enum to union 2020-08-17 20:48:22 +03:00
Vexu
1e835e0fcc disallow '_' prong when switching on non-exhaustive tagged union
A tagged union cannot legally be initiated to an invalid enumeration
2020-08-17 20:47:31 +03:00
xackus
65185016f1 stage1: fix non-exhaustive enums with one field 2020-08-17 20:45:34 +03:00
Vexu
13b2f1e90b address review feedback 2020-08-17 19:21:03 +03:00
Jakub Konka
5cb96681d9 Move Mach-O to link/MachO.zig submodule
Remove `ptrWidth` since as of Catalina, all apps are 64bits only.

Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-08-17 18:16:29 +02:00
Jakub Konka
e23fc3905f Add skeleton for MachO support in stage2
This commit adds an empty skeleton for MachO format support in stage2.
2020-08-17 18:16:29 +02:00
Vexu
ece4a2fc51 stage2: astgen for if and while with error unions 2020-08-17 14:28:04 +03:00
Vexu
db77b6b4e7 stage2: astgen for if and while with optionals 2020-08-17 14:28:04 +03:00
Vexu
012fac255f stage2: fix optimization causing wrong optional child types 2020-08-17 14:26:32 +03:00
Vexu
c52513e25b stage2: astgen for ptr types and address of 2020-08-17 14:24:56 +03:00
Andrew Kelley
6b141620a6 Merge pull request #6048 from pixelherodev/cleanup
Some minor cleanup and error handling
2020-08-17 01:41:52 -04:00
Isaac Freund
fc850aad61 stage2: fix signed <-> unsigned Value casts 2020-08-17 01:40:46 -04:00
Andrew Kelley
addeff889a Merge branch 'jedisct1-25519'
closes #6050
2020-08-16 22:35:39 -07:00
Frank Denis
7f9a227abf deinline edwards25519.{add,dbl} 2020-08-16 22:35:28 -07:00
Frank Denis
37ae246405 Inline Fe.{sub,mul,sq} for a performance boost in release-safe mode 2020-08-16 22:35:28 -07:00
Frank Denis
ab6ffa8a3c Work around sqrtRatioM1() issue in release-safe mode 2020-08-16 22:35:28 -07:00
Frank Denis
08dfbee961 Benchmark signatures 2020-08-16 22:35:27 -07:00
Frank Denis
5ab69633b7 Constify the ladder 2020-08-16 22:35:27 -07:00
Frank Denis
d86cde5752 Add comment, use @truncate 2020-08-16 22:35:27 -07:00
Frank Denis
bcef123d90 Address more review issues 2020-08-16 22:35:27 -07:00
Frank Denis
263c444738 Move loop decrements into continuations
Suggested by @daurnimator
2020-08-16 22:35:27 -07:00
Frank Denis
ed558bfbaa Address @daurnimator feedback 2020-08-16 22:35:27 -07:00
Frank Denis
dd8f7b396c Rename the field and scalar modules
Suggested by @kubkon
2020-08-16 22:35:27 -07:00
Frank Denis
c483bf4f97 Update lib/std/crypto/25519/ristretto255.zig
Co-authored-by: Jakub Konka <kubkon@jakubkonka.com>
2020-08-16 22:35:27 -07:00
Frank Denis
739b68938c Update lib/std/crypto/25519/field25519.zig
Co-authored-by: Jakub Konka <kubkon@jakubkonka.com>
2020-08-16 22:35:27 -07:00
Frank Denis
6af9bc8c68 Initialize structures directly
Suggested by @kubkon, thanks!
2020-08-16 22:35:27 -07:00
Frank Denis
5f9953f41f Remove mem.timingSafeEqual() for now
This requires assembly implementations, and is not needed for
signature verification.

Thanks @daurnimator
2020-08-16 22:35:27 -07:00
Frank Denis
3f0d80f25e Improve curve25519-based crypto
This is a rewrite of the x25519 code, that generalizes support for
common primitives based on the same finite field.

- Low-level operations can now be performed over the curve25519 and
edwards25519 curves, as well as the ristretto255 group.
- Ed25519 signatures have been implemented.
- X25519 is now about twice as fast.
- mem.timingSafeEqual() has been added for constant-time comparison.

Domains have been clearly separated, making it easier to later add
platform-specific implementations.
2020-08-16 22:35:27 -07:00
Frank Denis
f46e375bbe std/crypto: gimli.Aead.decrypt()'s ad should be const 2020-08-17 07:16:06 +02:00
Noam Preil
3ca8c42e7a Astgen: further cleanup 2020-08-16 20:36:33 -04:00
Noam Preil
93619a5e4e Module: panic when encountering unimplemented node 2020-08-16 20:32:51 -04:00
Noam Preil
34923e071e CBE: minor doc change 2020-08-16 20:32:50 -04:00
Noam Preil
692f38c250 astgen: minor cleanup 2020-08-16 20:32:50 -04:00
Andrew Kelley
8d8d568854 stage2: implement zig version 2020-08-15 20:04:08 -04:00
Andrew Kelley
66d76cc4f9 stage2: codegen for labeled blocks 2020-08-15 17:03:05 -07:00
Andrew Kelley
2cd19c05d0 stage1: remove buggy "unable to inline function" compile error
We still want this compile error but I'm giving up on implementing it
correctly in stage1. It's been buggy and has false positives sometimes.

I left the test cases there, but commented out, so that when we go
through the stage1 compile error cases and get coverage for them in
stage2 we can reactivate the test cases.

closes #2154
2020-08-15 09:53:39 -07:00
Andrew Kelley
0f3f96c850 stage2: astgen for labeled blocks and labeled breaks 2020-08-15 00:52:25 -07:00
Andrew Kelley
f356cba704 stage2: populate some of the astgen switch possibilities
Idea here is simply to entice people to contribute astgen code :)
2020-08-14 22:50:00 -04:00
Andrew Kelley
b49d3672f3 stage2 astgen for LabeledBlock 2020-08-14 22:50:00 -04:00
Andrew Kelley
9a5a1013a8 std.zig.ast: extract out Node.LabeledBlock from Node.Block
This is part of an ongoing effort to reduce size of in-memory AST. This
enum flattening pattern is widespread throughout the self-hosted
compiler.

This is a API breaking change for consumers of the self-hosted parser.
2020-08-14 22:50:00 -04:00
Michael Dusan
c12a262503 Merge pull request #6051 from mikdusan/qemu
ci linux: bump qemu-5.1.0
2020-08-14 17:54:22 -04:00
Andrew Kelley
7a39a038db stage2: proper semantic analysis of improper returning of implicit void 2020-08-14 13:08:55 -07:00
Michael Dusan
05f80311bc ci linux: bump qemu-5.1.0 2020-08-14 14:38:54 -04:00
Andrew Kelley
5f7c7191ab stage2: astgen for non-labeled blocks 2020-08-14 11:28:40 -07:00
Andrew Kelley
4adc052f0b langref: fix html error
thanks tidy
2020-08-14 09:33:45 -07:00
Andrew Kelley
28a9da8bfc stage2: implement while loops (bool condition)
* introduce a dump() function on Module.Fn which helpfully prints to
   stderr the ZIR representation of a function (can be called before
   attempting to codegen it). This is a debugging tool.
 * implement x86 codegen for loops
 * liveness: fix analysis of conditional branches. The logic was buggy
   in a couple ways:
   - it never actually saved the results into the IR instruction (fixed now)
   - it incorrectly labeled operands as dying when their true death was
     after the conditional branch ended (fixed now)
 * zir rendering is enhanced to show liveness analysis results. this
   helps when debugging liveness analysis.
 * fix bug in zir rendering not numbering instructions correctly

closes #6021
2020-08-13 20:32:32 -07:00
Andrew Kelley
576581bd7b stage1: fix enums having wrong debug info
It wasn't wrong info, but e.g. GDB couldn't handle non-power-of-two
enum tags. Now we tell debug info that enum tags are always power of two
size.

closes #4526
closes #5432
2020-08-13 20:32:32 -07:00
Andrew Kelley
fc402bdbbb stage2: zir_sema for loops
Also remove the "repeat" instruction and make it implied to be at the
end of a Loop body.
2020-08-13 20:32:32 -07:00
Dmitry Atamanov
a9590f3bf8 Support tuples in mem.len and trait.isIndexable (#5897) 2020-08-14 01:14:32 +03:00
Veikka Tuominen
f5b99abc93 Merge pull request #6045 from Vexu/block
Add error for unused/duplicate labels.
2020-08-14 01:04:05 +03:00
Maks S
50139aa232 langref: explain why comptime_float cannot be divided by comptime_int
Co-authored-by: Andrew Kelley <andrew@ziglang.org>
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2020-08-13 22:08:37 +03:00
Andrew Kelley
6e0fb06010 Merge branch 'Vexu-stage2'
closes #6042
2020-08-13 10:05:20 -07:00
Andrew Kelley
ec4953504a stage2: implement safety checks at the zir_sema level 2020-08-13 10:04:46 -07:00
Vexu
13e472aa2a translate-c: add return if one is needed 2020-08-13 18:40:14 +03:00
heidezomp
16d118a8d9 update std and src-self-hosted for std.log breaking change 2020-08-13 17:14:15 +02:00
Vexu
6b2ce9d1e9 stage2: split unwrap_optional to safe and unsafe verions 2020-08-13 08:12:17 -07:00
Vexu
4a40282391 stage2: implement unwrap optional 2020-08-13 08:12:17 -07:00
Vexu
5c1fe58613 stage2: gen optional types 2020-08-13 08:12:17 -07:00
Vexu
75eaf15740 stage2: add optional types 2020-08-13 08:12:17 -07:00
heidezomp
2439f67061 std.log: update documentation and example for scoped logging 2020-08-13 17:12:16 +02:00
heidezomp
a8e0f667c6 std.log: (breaking) remove scope parameter from logging functions
The logging functions in std.log don't take a scope parameter anymore,
but use the .default scope. To provide your own scope, use the logging
functions in std.log.scoped(.some_other_scope).

As per nmichaels' suggestion: https://github.com/ziglang/zig/pull/6039#issuecomment-673148971
2020-08-13 16:50:38 +02:00
Vexu
c5368ba20c translate-c: ensure generated labels are unique 2020-08-13 15:27:29 +03:00
Koakuma
cb06d62603 Add "ppc" prefix to number-modeled CPUs (#6006)
This is to prevent "expected token 'Symbol', found 'IntLiteral'" errors
when building zig files.
2020-08-13 14:30:38 +03:00
Jakub Konka
3e2e6baee5 Add std.os.getFdPath and std.fs.Dir.realpath
`std.os.getFdPath` is very platform-specific and can be used to query
the OS for a canonical path to a file handle. Currently supported hosts
are Linux, macOS and Windows.

`std.fs.Dir.realpath` (and null-terminated, plus WTF16 versions) are
similar to `std.os.realpath`, however, they resolve a path wrt to this
`Dir` instance.

If the input pathname argument turns out to be an absolute path, this
function reverts to calling `realpath` on that pathname completely
ignoring this `Dir`.
2020-08-13 07:08:39 +02:00
Andrew Kelley
e043396b24 Merge branch 'pixelherodev-cbe'
closes #6007
2020-08-12 22:00:14 -07:00
Andrew Kelley
eec53d67ab stage2: anyerror -> explicit error set 2020-08-12 21:59:40 -07:00
Noam Preil
1eb5aaa4b5 CBE: renderValue pays attention to Type, not Tag 2020-08-12 21:58:21 -07:00
Noam Preil
5a166cead8 CBE: fix handling of IR dependencies 2020-08-12 21:58:21 -07:00
Noam Preil
dbd1e42ef2 CBE: Sorta working intcasts? 2020-08-12 21:58:21 -07:00
Noam Preil
78fe86dcd2 CBE: support unreachable on GCC 2020-08-12 21:58:21 -07:00
Noam Preil
d3eec7d46b CBE: working parameters 2020-08-12 21:58:21 -07:00
Noam Preil
4d778e630a Tests: print generated C on test failure 2020-08-12 21:58:21 -07:00
Noam Preil
dd1f1487e4 CBE: Use zig_noreturn instead of noreturn to avoid namespace conflict 2020-08-12 21:58:21 -07:00
Noam Preil
b59e2c1e00 CBE: improve noreturn definition, support noreturn on MSVC 2020-08-12 21:58:21 -07:00
Andrew Kelley
de4f3f11f7 stage2: astgen for while loops
See #6021
2020-08-12 21:13:16 -07:00
Andrew Kelley
30db5b1fb2 Merge pull request #6039 from heidezomp/std-log-scoped
std.log: add scoped logging struct
2020-08-12 18:26:35 -04:00
Vexu
3734881577 add error for unused/duplicate block labels 2020-08-13 01:13:17 +03:00
heidezomp
bf2ed0f571 std.log: don't state in docs that messages are logged to stderr
Since the logger implementation can be overridden, the messages might
not be logged to stderr at all.
2020-08-12 15:54:21 +02:00
heidezomp
25607079f0 std.log: add documentation for scoped logging
* Add short documentation to std.log.scoped and std.log.default
 * Update the module documentation and example to explain the difference
   between using explicit scopes, using a scoped logging namespace, and
   using the default namespace
2020-08-12 15:37:56 +02:00
heidezomp
7db2c11537 std.log: add scoped logging struct
* Add a std.log.scoped function that returns a scoped logging struct
 * Add a std.log.default struct that logs using the .default scope

Implementation of daurnimator's proposal:
https://github.com/ziglang/zig/issues/5943#issuecomment-669043489

Note that I named the function "scoped" instead of "scope" so as not to
clash with the scope parameter that is used everywhere; this seemed a
better solution to me than renaming the scope parameter to "s" or
"log_scope" or the like.
2020-08-12 14:03:02 +02:00
Josias
67d684d89a docs: Fix reference to General Purpose Allocator 2020-08-12 05:08:41 -04:00
Andrew Kelley
8282f4271c stage2: basic support for parameters .debug_info
see #6014
2020-08-11 22:23:32 -07:00
Andrew Kelley
a2a5cea286 stage2: emit DW_TAG_subprogram for function Decls
these have the virtual address range, return type, and name.
2020-08-11 19:02:21 -07:00
Andrew Kelley
7612931c80 stage2: set up per-Decl .debug_info 2020-08-11 14:07:06 -07:00
Andrew Kelley
60ce5edaf9 GeneralPurposeAllocator: default to store more stack frames in test mode
Now tests will by default store 8 stack frames per allocation rather
than the normal default of 4.
2020-08-11 14:05:28 -07:00
Andrew Kelley
3ccfd58bb6 std.mem.Allocator: fix not passing return_address
This makes collected stack traces omit less useful frames. For user
applications which only store a fixed number of stack frames this can
make a big difference.
2020-08-11 14:04:08 -07:00
Maciej Walczak
6febe7e977 copy_file_range linux syscall (#6010) 2020-08-11 15:49:43 -04:00
Vexu
2b28cebf64 translate-c: use mangled name when macro translation fails
Closes #6009
2020-08-11 12:24:45 +03:00
Vexu
cf5932b236 translate-c: convert int to bool if bool is expected 2020-08-11 12:24:45 +03:00
Vexu
dfcac3cd76 translate-c: always add extern token for functions without body 2020-08-11 12:24:45 +03:00
Andrew Kelley
20510d209b GeneralPurposeAllocator: use std.log instead of std.debug.print
`std.builtin.StackTrace` gains a `format` function.

GeneralPurposeAllocator uses `std.log.err` instead of directly printing
to stderr. Some errors are recoverable.

The test runner is modified to fail the test run if any log messages of
"err" or worse severity are encountered.

self-hosted is modified to always print log messages of "err" severity
or worse even if they have not been explicitly enabled.

This makes GeneralPurposeAllocator available on the freestanding target.
2020-08-11 02:01:32 -04:00
joachimschmidt557
900a897e90 Update tools/process_headers.zig to latest zig 2020-08-10 21:09:23 -04:00
Andrew Kelley
6325d6a486 Merge pull request #5993 from kubkon/getpathnamebyhandle
Implement std.os.windows.GetPathNameByHandle using NT routines only
2020-08-10 20:09:45 -04:00
Andrew Kelley
bc176fb739 Merge pull request #6002 from MasterQ32/zig_fmt_align_fix
Fixes floating point alignment in std.fmt.format
2020-08-10 20:09:11 -04:00
Andrew Kelley
56e1080ba3 std: dwarf_bits correction 2020-08-10 17:05:39 -07:00
Jakub Konka
901bf0a2e2 Convert prefix from u8 to u16 programmatically 2020-08-10 20:44:22 +02:00
Jakub Konka
73b9f65746 Validate DOS path before returning
And some other minor refactors which address more review comments.
2020-08-10 16:39:02 +02:00
Felix Queißner
6701046cdd Uses getWritten instead of .pos + slicing
Co-authored-by: Joachim Schmidt <joachim.schmidt557@outlook.com>
2020-08-09 17:40:58 +02:00
Felix (xq) Queißner
ada06e2996 Makes formatFloatValue not return error.NoSpaceLeft anymore. 2020-08-09 14:09:02 +02:00
Felix (xq) Queißner
06a1184c92 Fixes double alignment 2020-08-09 12:48:26 +02:00
Jakub Konka
cd8e6b66d0 Address some review comments 2020-08-09 10:47:52 +02:00
Andrew Kelley
fd47839064 stage2: fix crash on empty source file 2020-08-08 18:19:48 -07:00
Andrew Kelley
069a6f2432 Merge pull request #5998 from ziglang/general-purpose-allocator
std: introduce GeneralPurposeAllocator
2020-08-08 20:20:15 -04:00
Andrew Kelley
f98cffc615 std: general purpose allocator: use AutoHashMap
As pointed out by Sahnvour, AutoHashMap is both more convenient and will
have better performance in this case.
2020-08-08 15:59:03 -07:00
Andrew Kelley
5b57e35ce0 fix general purpose allocator test cases on Windows
The tests are cleverly testing some alignment stuff, but were getting
thwarted by Windows choosing to allocate 64K aligned pages.
2020-08-08 13:46:18 -07:00
Andrew Kelley
4d0f83e23e GeneralPurposeAllocator: naming convention refactor 2020-08-08 13:05:04 -07:00
Andrew Kelley
a2f8c23a96 std.heap.page_allocator: Windows support for growing without remapping 2020-08-08 13:04:30 -07:00
Andrew Kelley
cb9405cdbd don't collect stack trace frames in release safe mode by default
We don't pass no-omit-frame-pointer in release safe by default, so it
also makes sense to not try to collect stack trace frames by default in
release safe mode.
2020-08-08 12:04:19 -07:00
Andrew Kelley
051aadd781 std lib general purpose allocator: disable stack tracing on mips
Sadly, trying to collect stack frames goes into an infinite loop on
mips. This sets the default number of stack frames to collect to 0 on
mips.
2020-08-08 02:38:32 -07:00
Andrew Kelley
72b5ceed66 update langref in light of new general purpose allocator 2020-08-08 02:15:34 -07:00
Andrew Kelley
88ac0c1287 restore previous behavior of allowing std.testing.allocator
even outside of unit tests
2020-08-08 01:21:08 -07:00
Andrew Kelley
1b1921f0e2 stage1: deal with WebAssembly not supporting @returnAddress()
This makes `@returnAddress()` return 0 for WebAssembly (when not using
the Emscripten OS) and avoids trying to capture stack traces for the
general purpose allocator on that target.
2020-08-08 01:00:29 -07:00
Andrew Kelley
9f5a7d5922 utilize math.ceilPowerOfTwo 2020-08-08 00:39:46 -07:00
Andrew Kelley
cd6cdd0a75 std.mem.Allocator: add return_address to the interface
The high level Allocator interface API functions will now do a
`@returnAddress()` so that stack traces captured by allocator
implementations have a return address that does not include the
Allocator overhead functions. This makes `4` a more reasonable default
for how many stack frames to capture.
2020-08-08 00:34:13 -07:00
Andrew Kelley
0347df82e8 improvements & fixes for general purpose allocator integration
* std.Mutex API is improved to not have init() deinit(). This API is
   designed to support static initialization and does not require any
   resource cleanup. This also happens to work around some kind of
   stage1 behavior that wasn't letting the new allocator mutex code
   get compiled.
 * the general purpose allocator now returns a bool from deinit()
   which tells if there were any leaks. This value is used by the test
   runner to fail the tests if there are any.
 * self-hosted compiler is updated to use the general purpose allocator
   when not linking against libc.
2020-08-07 23:26:58 -07:00
Andrew Kelley
cc17f84ccc std: introduce GeneralPurposeAllocator
`std.GeneralPurposeAllocator` is now available. It is a function that
takes a configuration struct (with default field values) and returns an
allocator. There is a detailed description of this allocator in the
doc comments at the top of the new file.

The main feature of this allocator is that it is *safe*. It
prevents double-free, use-after-free, and detects leaks.

Some deprecation compile errors are removed.

The Allocator interface gains `old_align` as a new parameter to
`resizeFn`. This is useful to quickly look up allocations.

`std.heap.page_allocator` is improved to use mmap address hints to avoid
obtaining the same virtual address pages when unmapping and mapping
pages. The new general purpose allocator uses the page allocator as its
backing allocator by default.

`std.testing.allocator` is replaced with usage of this new allocator,
which does leak checking, and so the LeakCheckAllocator is retired.

stage1 is improved so that the `@typeInfo` of a pointer has a lazy value
for the alignment of the child type, to avoid false dependency loops
when dealing with pointers to async function frames.

The `std.mem.Allocator` interface is refactored to be in its own file.

`std.Mutex` now exposes the dummy mutex with `std.Mutex.Dummy`.

This allocator is great for debug mode, however it needs some work to
have better performance in release modes. The next step will be setting
up a series of tests in ziglang/gotta-go-fast and then making
improvements to the implementation.
2020-08-07 22:45:45 -07:00
Andrew Kelley
30bace66d4 refactor now that stage1 supports anon default struct field inits 2020-08-07 22:45:45 -07:00
Andrew Kelley
ab483281d3 stage1: elide @intToPtr alignment safety check for 1-byte alignment 2020-08-07 23:36:36 -04:00
Isaac Freund
2fc18b5278 stage2: make link data in Decl into unions
This will allow for implementation of non-Elf backends without wasting
memory.
2020-08-07 19:25:06 -04:00
Jakub Konka
310aa87198 Fix alignment issue 2020-08-07 23:21:06 +02:00
Jakub Konka
bdda8fa7a8 Redo GetFinalPathNameByHandle using DeviceIoControl
This commit reimagines `std.os.windows.GetFinalPathNameByHandle`
using `DeviceIoControl` to query the OS mount manager for the DOS
(symlink) paths for the given NT volume name. In particular,
it uses `IOCTL_MOUNTMGR_QUERY_POINTS` ioctl opcode to query the
manager for the available moount points.
2020-08-07 11:33:05 +02:00
Jakub Konka
e8abfef2aa Add docs 2020-08-06 23:56:37 +02:00
Jakub Konka
2628a8846e Use NtQueryInformationFile unless unavailable
Favour newer API which uses `NtQueryInformationFile` with class flags
`FileNormalizedNameInformation` and `FileVolumeNameInformation`
instead of lower-level `NtQueryObject`. `NtQueryObject` is still
used as a fallback in case the former are unavailable.
2020-08-06 23:56:37 +02:00
Jakub Konka
747d46f22c Initial draft of GetFinalPathNameByHandle
This commit proposes an initial draft of `GetPathNameByHandle` function
which wraps NT syscalls and strives to emulate (currently only
partially) the `kernel32.GetFinalPathNameByHandleW` function.
2020-08-06 23:56:37 +02:00
Andrew Kelley
a2bb246db4 Revert "std.fmt.format: small optimization to avoid runtime bloat"
This reverts commit 11d38a7e52.

The benefits of this commit are not enough to justify the compromise
that it made.

closes #5977
2020-08-05 13:30:43 -07:00
Andrew Kelley
c4b9f5e52f Merge branch 'pixelherodev-elf-refactor'
closes #5976
2020-08-05 11:27:37 -07:00
Noam Preil
a85452b2c2 Codegen: 16-bit pointers 2020-08-05 11:25:43 -07:00
Noam Preil
a5b76d2474 Stage2: minor File.ELF refactor 2020-08-05 11:25:08 -07:00
Andrew Kelley
cf4936bcb0 std.os tests: improve robustness of "symlink with relative paths" 2020-08-04 23:45:53 -07:00
Andrew Kelley
d159ba9295 zig fmt 2020-08-04 23:04:20 -07:00
Andrew Kelley
f23fb3087b zig build: fix addBuildOption for []const u8 and ?[]const u8 2020-08-04 22:55:45 -07:00
Andrew Kelley
2139697ce5 zig build: fix addBuildOption for []const u8 and ?[]const u8 2020-08-04 22:54:59 -07:00
Andrew Kelley
316b4bde6a update target CPU features from llvm 10 to 11rc1 2020-08-04 21:46:49 -07:00
Andrew Kelley
8824491fc7 stage2: add missing newlines to cli error messages 2020-08-04 18:38:42 -07:00
Andrew Kelley
e2b9e2137e update clang command line options data from 10 to 11rc1 2020-08-04 18:03:04 -07:00
Andrew Kelley
4269868d6a update install files for LLVM 11rc1 2020-08-04 17:52:26 -07:00
Andrew Kelley
372062b4fe libunwind: update from LLVM 10 to 11rc1 2020-08-04 17:39:29 -07:00
Andrew Kelley
42da1d385d libcxxabi: upgrade from llvm 10 to 11rc1 2020-08-04 17:30:57 -07:00
Andrew Kelley
54b67c2025 libcxx: update from LLVM 10 to 11rc1 2020-08-04 17:26:02 -07:00
Andrew Kelley
16513fee6c update C lib/include/ files from clang 10 to 11rc1 2020-08-04 17:17:48 -07:00
Andrew Kelley
c6e0df6213 Merge remote-tracking branch 'origin/master' into llvm11 2020-08-04 17:09:40 -07:00
Andrew Kelley
d61a9e37ae stage2 tests: fix qemu logic
I made two mistakes in the previous commit; it was not actually using
the argv that we built, and also the qemu logic was unconditionally
skipping the test.

Now I have verified that when mangling the RISC-V "hello world" test and
then using -Denable-qemu, we get a test failure.
2020-08-04 15:39:59 -07:00
Andrew Kelley
e4eb4396c2 Merge branch 'pfgithub-stage2-testing-Copy-2' 2020-08-04 15:32:41 -07:00
Andrew Kelley
c594f8dc26 stage2 tests: support the -Denable-qemu options and friends 2020-08-04 15:32:16 -07:00
Andrew Kelley
02d09d1328 codegen: introduce toCanonicalReg to clean up x86-specific logic 2020-08-04 15:31:54 -07:00
pfg
ea3cc777cc stage2: riscv test case 2020-08-04 14:38:33 -07:00
pfg
e3352db986 stage2: riscv correctly aligned functions 2020-08-04 14:38:33 -07:00
pfg
0b53a2d996 stage2: riscv 0 argument non-nested function calls 2020-08-04 14:38:33 -07:00
pfg
1fd99ed324 stage2: riscv hello world 2020-08-04 14:38:33 -07:00
pfg
52ae2b10aa stage2: starting on a riscv64 backend 2020-08-04 14:38:33 -07:00
Andrew Kelley
952a397b0e Merge pull request #5978 from ziglang/stage2-dwarf-incr
self-hosted: line number debug information
2020-08-04 20:53:47 +00:00
Andrew Kelley
331f6a07a9 stage2: fix ZIR support and C back end 2020-08-04 12:15:47 -07:00
Andrew Kelley
b7a883b7d1 stage2: link: fix not freeing debug line free list 2020-08-04 12:15:47 -07:00
Andrew Kelley
ca19c42b74 stage2: fix updating debug line info not resizing properly 2020-08-04 12:15:47 -07:00
Andrew Kelley
7d70774fde stage2: fix memory leak with exported decl name 2020-08-04 12:15:47 -07:00
Andrew Kelley
0d696a48da stage2 .debug_line: handle Decl line numbers changing 2020-08-04 00:22:11 -07:00
Andrew Kelley
30ee08dfc2 stage2: stop needlessly re-analyzing unchanged functions 2020-08-03 23:47:54 -07:00
Andrew Kelley
cb25d8e4bc stage2 .debug_line: handle Decl deletes and updates 2020-08-03 23:13:54 -07:00
Andrew Kelley
9b3a70c8aa stage2: move link.File.ELF.SrcFn field from Module.Fn to Module.Decl
SrcFn represents the function in the linked output file, if the
`Decl` is a function. This is stored here and not in `Fn` because `Decl`
survives across updates but `Fn` does not.

TODO Look into making `Fn` a longer lived structure and moving this field there
to save on memory usage.
2020-08-03 22:22:47 -07:00
Andrew Kelley
0c598100d8 stage2: fix use-after-free of export symbol name 2020-08-03 22:07:21 -07:00
Andrew Kelley
edfede575c self-hosted: add build option for log scopes
Now you can enable a set of log scopes by passing -Dlog=<scope>
2020-08-03 21:56:21 -07:00
Andrew Kelley
a33efc74ed stage2 codegen: revert the unneeded is_stmt stuff 2020-08-03 21:09:58 -07:00
Andrew Kelley
d624bf8059 stage2 .debug_line stepping with gdb is working 2020-08-03 21:01:06 -07:00
Andrew Kelley
ac10841fa9 stage2 .debug_line: simpler strategy for incremental compilation
See #5963
2020-08-03 19:14:09 -07:00
Vexu
4ab2f947f9 translate-c: recognize other type trait expressions
Closes #5979
2020-08-04 00:48:29 +03:00
Andrew Kelley
4e023c6fa8 stage2: dwarf: fix standard opcode length of LNS_fixed_advance_pc 2020-08-03 00:54:30 -07:00
Andrew Kelley
eccbb03063 downgrade .debug_info to DWARFv4
gdb, notice me senpai
2020-08-03 00:42:08 -07:00
Andrew Kelley
bf85d3db3f downgrade .debug_line to DWARFv4
apparently gdb 8.3.1 which is still a commonly distributed version of gdb,
does not support v5.
2020-08-03 00:34:12 -07:00
Andrew Kelley
659603c621 codegen: emit .debug_line ops for IR instructions 2020-08-02 21:28:06 -07:00
Andrew Kelley
42d331b58a .debug_line: avoid DW_FORM_strp to work around readelf/gdb
These tools do not support DWARFv5 yet apparently.
2020-08-02 20:22:41 -07:00
Andrew Kelley
1ce6e201aa .debug_line: don't rely on header_length field
Empirically, debug info consumers do not respect this field, or otherwise
consider it to be an error when it does not point exactly to the end of the header.
Therefore we rely on the NOP jump at the beginning of the Line Number Program for
padding rather than this field.

llvm-dwarfdump says the line number data is fine; gdb and
binutils-readelf crap out.
2020-08-02 19:57:42 -07:00
Andrew Kelley
1a3f250f19 .debug_line incremental compilation initial support
Supports writing the first function. Still TODO is:
 * handling the .debug_line header growing too large
 * adding a new file to an existing compilation
 * adding an additional function to an existing file
 * handling incremental updates
 * adding the main IR debug ops for IR instructions

There are also issues to work out:
 * readelf --debug-dump=rawline is saying there is no .debug_str section
   even though there is
 * readelf --debug-dump=decodedline is saying the file index 0 is bad
   and reporting some other kind of corruption.
2020-08-02 19:25:26 -07:00
Andrew Kelley
ba6e5cbfd2 stage2: add the .debug_line header and associated data types
* the .debug_line header is written properly
 * link.File.Elf gains:
   - SrcFn, which is now a field in Module.Fn
   - SrcFile, which is now a field in Module.Scope.File
 * link.File.Elf gets a whole *Package field rather than only
   root_src_dir_path.
 * the fields first_dbg_line_file and last_dbg_line_file tell where the
   Line Number Program begins and ends, which alows moving files when
   the header gets too big, and allows appending files to the end.
 * codegen is passed a buffer for emitting .debug_line
   Line Number Program opcodes for functions.

See #5963

There is some work-in-progress code here, but I need to go make some
experimental changes to changing how to represent source locations and I
want to do that in a separate commit.
2020-08-02 12:02:43 -07:00
Andrew Kelley
c0654d2db2 std.dwarf: add LNCT constants from DWARF v5 2020-08-02 11:09:39 -07:00
Andrew Kelley
d4bb2b1513 std: add function for writing fixed width ULEB128 2020-08-02 11:09:35 -07:00
Isaac Freund
6123201f06 stage2: move format-specific code to link.File.X
This makes the code outside of link.File.Elf less elf-specific and will
allow for easier implementation of other formats such as wasm.
2020-08-02 18:07:10 +00:00
S0urc3C0de
5ae88e919b Add rdynamic option to build.zig 2020-08-02 17:50:06 +00:00
Vexu
6bba7c702b add compile error for alignCasting zero sized types 2020-08-02 17:49:16 +00:00
Andrew Kelley
35391f1709 Merge pull request #5968 from haliucinas/blake2
Blake2 improvements
2020-08-02 17:47:06 +00:00
Andrew Kelley
6df35c5877 Merge pull request #5960 from kubkon/windows-dir-refactor
Refactor out file and dir creation routines in Windows
2020-08-02 17:41:47 +00:00
Jakub Konka
4b0ab0c186 Apply suggestions from code review
Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2020-08-02 19:36:49 +02:00
Jay Petacat
cf15b4c269 elf: Iterate over headers w/o need for allocator 2020-08-01 16:01:48 +00:00
Mantas Jonytis
1df33936d6 remove unnecessary operations 2020-08-01 17:15:53 +03:00
Mantas Jonytis
8286cc77f8 implement keyed blake2 2020-08-01 16:56:11 +03:00
Mantas Jonytis
36ed4623a8 make blake2 public 2020-08-01 16:05:20 +03:00
Mantas Jonytis
42dd737c9e compute blake2 at compile time 2020-08-01 16:00:22 +03:00
Mantas Jonytis
1ae40146e6 blake2b: off-by-one on update 2020-08-01 15:31:46 +03:00
Mantas Jonytis
eee9abe1b4 add more blake2b test cases 2020-08-01 15:31:36 +03:00
Mantas Jonytis
b1cf0196df blake2s: off-by-one on update 2020-08-01 15:15:45 +03:00
Mantas Jonytis
fad87bef9a add more blake2s tests 2020-08-01 15:15:04 +03:00
Jakub Konka
f6ae2505d9 Fix opening NUL device on Windows 2020-07-31 19:16:04 +02:00
Jakub Konka
4d9eff4bdb Add prelim openW and openatW
Added POSIX functions targeting Windows pass `open` and `openat`
smoke tests.
2020-07-31 16:41:25 +02:00
Jakub Konka
a694f575ad Add some os.open and os.openat smoke tests 2020-07-31 16:33:02 +02:00
Jakub Konka
390194431e Use NtCreateFile directly in ReadLink
This shaves off one syscall (we use one instead of two if we were to
use `windows.OpenFile` wrapper). Clean up flag generation in `OpenFile`.
Hopefully, we're in a much better place to *almost* support `openW`
and `openatW`.
2020-07-31 16:32:21 +02:00
Jakub Konka
8981b18fee Move delete file logic into windows.DeleteFile fn
This way, we can remove more `kernel32` calls such as `RemoveDirectoryW`
or `DeleteFileW`, and use `std.os.windows.DeleteFile` instead which
is purely NT-based.
2020-07-31 16:31:51 +02:00
Jakub Konka
66bbe4ec4c Refactor internal Win routines to reuse OpenFile
This covers mainly `ReadLink` and `CreateSymolicLink` functions.
2020-07-31 16:31:44 +02:00
Jakub Konka
a89d5cfc3e Remove CreateDirectoryW and CreateFileW calls
Replace them with `std.os.windows.OpenFile` instead. To allow
creation/opening of directories, `std.os.windows.OpenFileOptions`
now features a `.expect_dir: bool` member which is meant to emualate
POSIX's `O_DIRECTORY` flag.
2020-07-31 16:31:23 +02:00
Sam Tebbs
0d31877444 Print } as format argument in enum build option (#5953)
Co-authored-by: Veikka Tuominen <git@vexu.eu>
Co-authored-by: Joachim Schmidt <joachim.schmidt557@outlook.com>
2020-07-31 11:37:40 +03:00
Andrew Kelley
0962cc5a32 stage2: implement .debug_aranges DWARF 2020-07-31 01:16:34 -07:00
Andrew Kelley
9d0872a625 std.ArrayList: add appendNTimesAssumeCapacity 2020-07-31 01:16:17 -07:00
Andrew Kelley
acd0dabab2 stage2: add some tracy calls to link.zig functions 2020-07-30 23:51:14 -07:00
Andrew Kelley
f1c1b8c02d stage2: add DWARF info for the main compilation unit 2020-07-31 06:48:17 +00:00
Vexu
f962315363 fix missing parser error for missing comma before eof
Closes #5952
2020-07-30 13:10:55 +03:00
Vexu
1f8f434b9c compiler_rt: add floatditf 2020-07-29 18:03:44 +03:00
Jakub Konka
547e520359 Split DeviceIoControl path into two fn call paths
As discussed in the previous commit, it would be better to avoid
function pointers to syscalls and explicitly split the control
path into two function calls instead. This commit addresses that
for `std.os.windows.DeviceIoControl`.
2020-07-29 14:17:49 +02:00
Andrew Kelley
b3b00ec62f Merge branch 'more-stage2-locals' 2020-07-29 02:29:46 -07:00
Andrew Kelley
8899e6e334 stage2: codegen: fix off-by-one stack variable offsets 2020-07-29 02:29:37 -07:00
Andrew Kelley
606f157a6b stage2: register-aliasing-aware codegen
* unify duplicated register allocation codepath
 * support the x86_64 concept of register aliasing
 * slightly improved memset codegen, supports sizes 1, 2, 4, 8
2020-07-29 02:29:37 -07:00
Andrew Kelley
1bbfa36b76 stage2: improved codegen
* multiple returns jump to one canonical function exitlude. This is in
   preparation for the defer feature.
 * simple elision of trivial jump relocs.
 * omit prelude/exitlude for naked calling convention functions.
 * fix not switching on arch for prelude/exitlude
 * fix swapped registers when setting stack mem from a register
2020-07-29 02:29:37 -07:00
Andrew Kelley
64a1a280ef stage2: fix superfluous returnvoid ZIR 2020-07-29 02:29:37 -07:00
Andrew Kelley
4beff80b2f stage2: codegen handles undefined values
* `optimize_mode` is passed to `link.File` and stored there
 * improve the debugging function `Module.dumpInst`
 * get rid of `Value.the_one_possible_value` in favor of a few more
   specific values for different types. This is less buggy, one less
   footgun.
 * `Type.onePossibleValue` now returns a `?Value` instead of `bool`.
 * codegen handles undefined values. `undef` is a new `MCValue` tag.
   It uses 0xaa values depending on optimization mode. However
   optimization mode does not yet support scope overrides.
 * link.zig: move the `Options` field from `File.Elf` and `File.C` to
   the base struct.
   - fix the Tag enum to adhere to style conventions
 * ZIR now supports emitting undefined values.
 * Fix the logic of comptime math to properly compare against zero using
   the `compareWithZero` function.
2020-07-29 02:29:37 -07:00
Andrew Kelley
2b8e7deeda stage2: add ZIR emitType support for simple pointer types 2020-07-29 02:29:37 -07:00
Andrew Kelley
99d2d9bf64 stage2: fix format() of mutable pointer types 2020-07-29 02:29:37 -07:00
Andrew Kelley
cb3e8e323d stage2: x86_64 codegen for movs to/from stack variables 2020-07-29 02:29:37 -07:00
Andrew Kelley
5ccee4c986 stage2: more progress towards mutable local variables
* implement sema for runtime deref, store pointer, coerce_to_ptr_elem,
   and store
 * identifiers support being lvalues, except for decls is still TODO
 * codegen supports load, store, ref, alloc
 * introduce more MCValue union tags to support pointers
 * add load, ref, store typed IR instructions
 * add Type.isVolatilePtr
2020-07-29 02:29:36 -07:00
Andrew Kelley
11d38a7e52 std.fmt.format: small optimization to avoid runtime bloat
When there are no format parameters, it simply calls `writeAll`. This
has the effect of no longer emitting a compile error for using `{}` and
not having any parameters, however, at this point in the development
process of Zig I think that tradeoff is worthwhile.

On the other hand, it might be OK to simply define formatting to work
this way. It's a common pattern to use the formatting function's format
string `"like this", .{}` instead of `"{}", .{"like this"}`, which can
lead to accidentally putting control characters in the formatting
string, however, with this change that works just fine.
2020-07-29 02:29:36 -07:00
Jakub Konka
4fdfaf69c8 Add Zig wrapper for kernel32.DeviceIoControl
This commit adds a Zig wrapper for `kernel32.DeviceIoControl` which
applies ReactOS logic for deciding whether to use
`ntdll.NtDeviceIoControlFile` or `ntdll.NtFsControlFile` based on the
value of passed `IO_CONTROL_CODE`. The decision logic is based on the
logic found in ReactOS found in the following [link].

Thanks to Daurnimator for finding this bit in ReactOS!

[link]: https://doxygen.reactos.org/d3/d74/deviceio_8c.html
2020-07-29 01:19:10 +00:00
Felix (xq) Queißner
606b6462ce Fixes atomicSymLink looping when new_path already exists. 2020-07-28 17:04:46 +00:00
Andrew Kelley
d726c2a2d3 self-hosted: beginnings of stack allocation
Comment out non-x86_64 architectures for now in codegen.zig, because
they all have compile errors for their codepaths anyway, and it was
bloating the compilation speed and memory usage when stage1 tried to
build self-hosted. Here's the panic message:

"Backend architectures that don't have good support yet are commented
out, to improve compilation performance. If you are interested in one
of these other backends feel free to uncomment them. Eventually these
will be completed, but stage1 is slow and a memory hog."

This is a workaround to lower the time it takes to build self-hosted
with stage1 as well as use less memory. It should fix the CI.

Additionally:
 * Add `single_mut_pointer` support to `Type`
 * Trivial implementation of stack allocation in codegen.zig. It does
   not deal with freeing yet, and it's missing the stack pointer
   adjustment prologue.
 * Add the `alloc` IR instruction and semantic analysis for `alloc` ZIR
   instruction.
2020-07-28 01:43:04 -07:00
Andrew Kelley
c37f273cb0 stage1: hot path for resolving types of primitives
This is an attempt to save memory when building self-hosted.

before:
Total bytes allocated: 5.941 GiB, deallocated: 2.259 GiB, remaining: 3.681 GiB

after:
Total bytes allocated: 5.933 GiB, deallocated: 2.253 GiB, remaining: 3.680 GiB
2020-07-28 00:00:35 -07:00
Andrew Kelley
0965724e31 self-hosted: refactor some code out of Module.zig into zir_sema.zig
This makes sense from an organizational point of view, as explained by
this new doc comment at the top of the new file:

//! Semantic analysis of ZIR instructions.
//! This file operates on a `Module` instance, transforming untyped ZIR
//! instructions into semantically-analyzed IR instructions. It does type
//! checking, comptime control flow, and safety-check generation. This is the
//! the heart of the Zig compiler.
//! When deciding if something goes into this file or into Module, here is a
//! guiding principle: if it has to do with (untyped) ZIR instructions, it goes
//! here. If the analysis operates on typed IR instructions, it goes in Module.

Before:
   4009 src-self-hosted/Module.zig

After:
   2776 src-self-hosted/Module.zig
   1128 src-self-hosted/zir_sema.zig

This should be sufficient to avoid the situation we have in stage1 where
ir.cpp is 32,516 lines.
2020-07-27 22:44:18 -07:00
Vexu
5f0bde6358 add helpful error note for when function cannot return an error
This has caused frequent confusion since it looks like you are handling
errors correctly with a try but you forgot to change your return type.
2020-07-28 04:24:52 +00:00
Andrew Kelley
b8e22d2002 stage2: implement integer return values 2020-07-27 18:59:13 -07:00
Andrew Kelley
3e0a46281c stage2: fix function calls always having void return type 2020-07-27 18:59:13 -07:00
Jay Petacat
1c2e65fe1d std.elf: Fix read functions for 32-bit targets
The buffer index was declared as `u64`, which overflows `usize` on a
32-bit target.

The following example program failed to compile for 32-bit targets:

```zig
const std = @import("std");

pub fn main() !void {
    const alloc = std.testing.allocator;
    const file = std.io.getStdIn();
    _ = try std.elf.readAllHeaders(alloc, file);
}
```

```
lib/zig/std/elf.zig:543:36: error: expected type 'usize', found 'u64'
        const len = file.pread(buf[i .. buf.len - i], offset + i) catch |err| switch (err) {
                                   ^
lib/zig/std/elf.zig:543:36: note: unsigned 32-bit int cannot represent all possible unsigned 64-bit values
        const len = file.pread(buf[i .. buf.len - i], offset + i) catch |err| switch (err) {
                                   ^
lib/zig/std/elf.zig:543:35: note: referenced here
        const len = file.pread(buf[i .. buf.len - i], offset + i) catch |err| switch (err) {
                                  ^
lib/zig/std/elf.zig:348:5: note: referenced here
    try preadNoEof(file, &hdr_buf, 0);
    ^
lib/zig/std/elf.zig:392:19: note: referenced here
        .header = try readHeader(file),
```
2020-07-28 01:36:26 +00:00
Andrew Kelley
488df7f1d1 stage2: astgen for all arithmetic and assignments 2020-07-27 17:09:47 -07:00
Andrew Kelley
bd9b3fe1e6 Merge pull request #5511 from jessrud/arraylist-replaceRange
add replaceRange() function to ArrayList
2020-07-27 20:04:19 +00:00
zigazeljko
bf273b7aec Add comment explaining --stack-first option 2020-07-27 19:51:58 +00:00
Felix (xq) Queißner
fb9d5529da Adds support for RunStep to use the result of a WriteFileStep. 2020-07-27 19:46:15 +00:00
Jakub Konka
f0ed2ed67f Replace DeviceIoControl with FsControlFile
This commit replaces `windows.DeviceIoControl` with
`windows.FsControlFile` which is a wrapper around the NT-based
syscall `ntdll.NtFsControlFile`.
2020-07-27 19:45:23 +00:00
Ashok Gautham
d1755e7f16 Add meta viewport to fix mobile rendering, add missing <code> block
Co-authored-by: Vexu <git@vexu.eu>
2020-07-27 17:10:55 +03:00
frmdstryr
fa4a9ab51f Use writer for LinearFifo instead of deprecated outStream 2020-07-27 17:05:39 +03:00
Vexu
e7007fa7bd translate-c: use ArrayList for macro tokens 2020-07-27 15:38:56 +03:00
Henrik Laxhuber
9f6401c692 Fix a use of appendToken to appendIdentifier in translate-c 2020-07-27 13:43:49 +03:00
Henrik Laxhuber
442025481c Fix parsing of unsigned in translate-c.
Previously, `unsigned` was parsed as the shorthand for `unsigned int`.
This commit introduces code to parse `unsigned short`, `unsigned int`,
`unsigned long`, and `unsigned long long`.

There is a comment in the code about std.c.parse` - Im not
familiar with zig internals, but it seems like this is a separate
C parsing implementation. In the long run, it probably makes
sense to merge both implementations, so this commit should be
regarded as a quick fix that doesn't address an apparently
underlying issue.
2020-07-27 13:43:49 +03:00
joachimschmidt557
616355807f Fix bug in big.int.Mutable.toManaged() and add tests
Fixes #5918
2020-07-27 07:16:44 +00:00
Andrew Kelley
5139aa7ba4 Merge pull request #5932 from Sahnvour/hash
new trait `hasUniqueRepresentation` and hashmap speedup
2020-07-27 07:12:54 +00:00
Jonathan Marler
6cc72af03d Provide Ip4Address and Ip6Address in addition to Address 2020-07-27 07:11:07 +00:00
Sahnvour
f67ce1e35f make use of hasUniqueRepresentation to speed up hashing facilities, fastpath in getAutoHashFn is particularly important for hashmap performance
gives a 1.18x speedup on gotta-go-fast hashmap bench
2020-07-26 23:04:33 +02:00
Sahnvour
345cb3200c improve autoHash type switch
floats shouldn't be autoHash'd as they have multiple representations for some values, preventing it by default is safer
2020-07-26 22:04:10 +02:00
Sahnvour
7ae1b3a6b3 add trait hasUniqueRepresentation 2020-07-26 22:01:33 +02:00
Andrew Kelley
c95091e5a5 run zig fmt on std.testing 2020-07-25 23:33:15 -07:00
Andrew Kelley
09b0ad494b stage2: remove superfluous else => unreachable 2020-07-25 23:32:30 -07:00
Andrew Kelley
40d81a8364 Merge pull request #5678 from antlilja/float-testing
Add functions for testing floats with margins and epsilons to standard library
2020-07-26 05:54:30 +00:00
Andrew Kelley
a36772ee64 Merge pull request #5693 from antlilja/switch-unreachable-else
Add error message for unreachable else prong in switch
2020-07-26 05:46:18 +00:00
meme
f050150ffa Add memory replacement routines
* Added `replace` for simple pre-allocated search-and-replace
* Added `replacementSize` for calculating ahead-of-time buffer sizes for
performing a safe search-and-replace
* Added `replaceOwned` for automatically allocating and performing
replacement
2020-07-26 05:42:38 +00:00
Andrew Kelley
9b75091fd4 ci: update msys2 installer 2020-07-25 22:21:52 -07:00
Andrew Kelley
41a8b6f57b llvm11: link against libClangToolingCore
This is needed to successfully link against llvm, clang, and lld 11.
2020-07-24 17:08:39 -07:00
Andrew Kelley
2475f653fd stage1: add missing math.h includes 2020-07-24 17:02:03 -07:00
Andrew Kelley
bd121f3af4 update clang drivers from llvm 10 to 11 2020-07-24 17:01:52 -07:00
Andrew Kelley
c8ea8cf5df update LLVM C++ API wrappers from llvm 10 to 11 2020-07-24 16:49:57 -07:00
Andrew Kelley
cd91e17b73 update LLVM 10 version numbers to 11 2020-07-24 16:49:43 -07:00
Andrew Kelley
995fd7314c Revert "Support taking extern pointers at comptime"
This reverts commit d3ebd42865.

This caused a build failure on multiple targets.
2020-07-24 14:06:44 -07:00
daurnimator
978a38ee40 std: fix json parsing into unions 2020-07-24 20:35:47 +00:00
yvt
d3ebd42865 Support taking extern pointers at comptime
This commit makes it possible to obtain pointers to `extern` variables
at comptime.

 - `ir_get_var_ptr` employs several checks to determine if the given
   variable is eligible for obtaining its pointer at comptime. This
   commit alters these checks to consider `extern` variables, which have
   runtime values, as eligible.

 - After this change, it's now possible for `render_const_val` to be
   called for `extern` variables. This commit modifies
   `render_const_val` to suppress the value generation for `extern`
   variables.

 - `do_code_gen` now creates `ZigValue::llvm_global` of `extern`
   variables before iterating through module-level variables so that
   other module-level variables can refer to them.

This solution is incomplete since there are several cases still
failing:

 - `global_var.array[n..m]`
 - `&global_var.array[i]`
 - `&global_var.inner_struct.value`
 - `&global_array[i]`

Closes #5349
2020-07-24 13:33:17 -07:00
Michael Dusan
3b26e50863 macOS: macho ld64.lld fixes
* bring `construct_linker_job_macho` to parity with
   `construct_linker_job_elf`
 * macho now sets `-error-limit`
 * macho on macOS now sets `-macosx_version_min` and `-sdk_version`
   to `10.13` when running `zig0`
 * macho now detects when `-l` prefix is not needed
 * macho on macOS detects system libraries in a case-insensitive manner
 * macho now ads user-specified libraries to linker command-line args
   when condition `is_native_os != true`
 * re-ordered some macho args positions to match elf positions

closes #5059
closes #5067
2020-07-24 20:01:18 +00:00
Andrew Kelley
df1a2ecd3b Merge pull request #5891 from Luukdegram/stage2-substraction
Stage2: Substraction support
2020-07-24 18:29:52 +00:00
Luuk de Gram
3019ab9391 Fix resolvepeertype() int signess and feedback improvements 2020-07-24 17:51:24 +02:00
Luuk de Gram
470264a4f5 Restructuring and f32/f64 support 2020-07-24 17:16:48 +02:00
Luuk de Gram
97e92d868e Rebase and skeleton for float support 2020-07-24 17:16:48 +02:00
Luuk de Gram
ee7fbb9548 Restructured arithmetic operations 2020-07-24 17:16:48 +02:00
Luuk de Gram
198c09197b Fixed test case 2020-07-24 17:16:48 +02:00
Luuk de Gram
9d79741fd0 Stage2: Add support for substraction 2020-07-24 17:16:48 +02:00
Jakub Konka
a1d72fad81 Use -c flag in all s3cmd occurrences on Win 2020-07-24 14:35:48 +02:00
Jakub Konka
937c02f185 Re-apply temp msys2 python fix
Tweak `windows_upload` script to manually specify the config path
to `s3cmd`.
2020-07-24 09:19:51 +02:00
Jakub Konka
b7353240c7 Refactor macOS build script in Azure
We don't really want to rebuild the cache in Azure...
2020-07-24 06:29:50 +00:00
Andrew Kelley
56a21b7ec3 ci: undo the recent changes. maybe upstream fixed it 2020-07-23 23:26:24 -07:00
Andrew Kelley
aac6e8c418 self-hosted: AST flattening, astgen improvements, result locations, and more
* AST: flatten ControlFlowExpression into Continue, Break, and Return.
 * AST: unify identifiers and literals into the same AST type: OneToken
 * AST: ControlFlowExpression uses TrailerFlags to optimize storage
   space.
 * astgen: support `var` as well as `const` locals, and support
   explicitly typed locals. Corresponding Module and codegen code is not
   implemented yet.
 * astgen: support result locations.
 * ZIR: add the following instructions (see the corresponding doc
   comments for explanations of semantics):
   - alloc
   - alloc_inferred
   - bitcast_result_ptr
   - coerce_result_block_ptr
   - coerce_result_ptr
   - coerce_to_ptr_elem
   - ensure_result_used
   - ensure_result_non_error
   - ret_ptr
   - ret_type
   - store
   - param_type
 * the skeleton structure for result locations is set up. It's looking
   pretty clean so far.
 * add compile error for unused result and compile error for discarding
   errors.
 * astgen: split builtin calls up to implemented manually, and implement
   `@as`, `@bitCast` (and others) with respect to result locations.
 * add CLI support for hex and raw object formats. They are not
   supported by the self-hosted compiler yet, and emit errors.
 * rename `--c` CLI to `-ofmt=[objectformat]` which can be any of the
   object formats. Only ELF and C are supported so far. Also added missing
   help to the help text.
 * Remove hard tabs from C backend test cases. Shame on you Noam, you
   are grounded, you should know better, etc. Bad boy.
 * Delete C backend code and test case that relied on comptime_int
   incorrectly making it all the way to codegen.
2020-07-23 23:05:26 -07:00
Andrew Kelley
b4d383a478 ci: looks like s3cmd wants a new path for the config file
Thanks Jakub Konka for exploring this.
2020-07-23 10:58:07 -07:00
heidezomp
32a6759a7a Fix std.log example to make the log handler print the newline
Follow up from #5910
2020-07-22 22:08:08 +00:00
luna
a6626802f9 Add signalfd support (#5322)
* add signalfd_siginfo to linux bits

* Cast sigaddset's shift value to u5

* linux: add signalfd4

* os: add signalfd
2020-07-22 17:26:27 -04:00
Andrew Kelley
9505bb74cd Merge pull request #5879 from kubkon/readlink-win
Implement readlink on Windows
2020-07-22 17:59:40 +00:00
joachimschmidt557
c6bd8e8c53 Make the default log handler print a newline
Closes #5907
2020-07-22 17:02:27 +00:00
Jakub Konka
aa6fcaf76f Add missing cross-platform Dir.readLink fns 2020-07-22 08:51:23 +02:00
Jakub Konka
65581b37cb Enable std.os.symlinkat tests on Windows 2020-07-22 08:51:23 +02:00
Jakub Konka
3d41d3fb6e Draft out ReadLinkW using NT primitives 2020-07-22 08:51:23 +02:00
Jakub Konka
4887350bf4 Finish drafting CreateSymolicLink using NT calls 2020-07-22 08:51:23 +02:00
Jakub Konka
99f0e64fa0 Draft out dir symlinks branch 2020-07-22 08:51:23 +02:00
Jakub Konka
c53bcd027f Start drafting CreateSymbolicLink using ntdll syscalls 2020-07-22 08:51:23 +02:00
Jakub Konka
2c9c13f624 Add various build fixes
Fix WASI build, fix atomicSymlink by using `cwd().symLink`, add
`Dir.symLink` on supported targets.
2020-07-22 08:51:22 +02:00
Jakub Konka
e0b77a6b77 Ensure Dir.deleteTree does not dereference symlinks
Otherwise, the behaviour can lead to unexpected results, resulting
in removing an entire tree that's not necessarily under the root.
Furthermore, this change is needed if are to properly handle dir
symlinks on Windows. Without explicitly requiring that a directory
or file is opened with `FILE_OPEN_REPARSE_POINT`, Windows automatically
dereferences all symlinks along the way. This commit adds another
option to `OpenDirOptions`, namely `.no_follow`, which defaults to
`false` and can be used to specifically open a directory symlink on
Windows or call `openat` with `O_NOFOLLOW` flag in POSIX.
2020-07-22 08:51:22 +02:00
Jakub Konka
3c8ceb674e Fix Windows build 2020-07-22 08:51:22 +02:00
Jakub Konka
fc7d87fef1 Move symlink to fs.symlinkAbsolute with SymlinkFlags
This way `std.fs.symlinkAbsolute` becomes cross-platform and we can
legally include `SymlinkFlags` as an argument that's only used on
Windows. Also, now `std.os.symlink` generates a compile error on
Windows with a message to instead use `std.os.windows.CreateSymbolicLink`.
Finally, this PR also reshuffles the tests between `std.os.test` and
`std.fs.test`.
2020-07-22 08:51:22 +02:00
Jakub Konka
dd366d316d Fix more compilation errors on other hosts 2020-07-22 08:51:22 +02:00
Jakub Konka
08e7ac3028 Fix compilation on other hosts 2020-07-22 08:51:22 +02:00
Jakub Konka
22362568cf Refactor 2020-07-22 08:51:22 +02:00
Jakub Konka
3ab5e6b1a9 Ensure we use Win32 prefix in Win32 calls 2020-07-22 08:51:22 +02:00
Jakub Konka
cc9c5c5b0e Handle relative/absolute symlinks; add more tests 2020-07-22 08:51:22 +02:00
Jakub Konka
a8a02dfbfa Add smoke test for dir symlinks 2020-07-22 08:51:22 +02:00
Jakub Konka
30f1176a54 Add SymlinkFlags needed to create symlinks to dirs on Win 2020-07-22 08:51:22 +02:00
Jakub Konka
4894de2b32 Fix readlink smoke test 2020-07-22 08:51:22 +02:00
Jakub Konka
99e3e29e2e Refactor 2020-07-22 08:51:22 +02:00
Jakub Konka
c47cb8d09f Fix unlinkatW to allow file symlink deletion on Windows 2020-07-22 08:51:22 +02:00
Jakub Konka
ae8abedbed Use NtCreateFile to get handle to reparse point 2020-07-22 08:51:22 +02:00
Jakub Konka
d17c9b3591 Fix incorrect byte format of REPARSE_DATA_BUFFER struct 2020-07-22 08:51:22 +02:00
Jakub Konka
9b00dc941b Use windows.CreateFileW to open the reparse point 2020-07-22 08:51:22 +02:00
Jakub Konka
49b5815364 Add windows.ReadLink similar to OpenFile but for reparse points only 2020-07-22 08:51:22 +02:00
Jakub Konka
92d11fd4e9 Debug readlinkW using OpenFile 2020-07-22 08:51:22 +02:00
Jakub Konka
791795a63a Finish symlink implementation on Windows 2020-07-22 08:51:22 +02:00
Jakub Konka
515c663cd6 Add readlink smoke test 2020-07-22 08:51:22 +02:00
Jakub Konka
cc83d92b0b Start drafting out os.readlink on Windows 2020-07-22 08:51:22 +02:00
Jakub Konka
9225763f8b Add temporary fix to the CI on Win
Here's the [thread](https://github.com/msys2/MSYS2-packages/issues/2050)
for reference.
2020-07-22 06:49:24 +00:00
Andrew Kelley
25a01a16e0 Merge pull request #5905 from Vexu/stage2-float
Stage2: floats
2020-07-21 22:35:05 +00:00
Hiroki Noda
68e0632aa5 Use function attribute "frame-pointer" 2020-07-21 21:03:02 +00:00
Vexu
dd89297388 stage2: actually implement float casting 2020-07-21 22:34:14 +03:00
Vexu
c29c79b17a stage2: remove some dead code, fix build on aarch64 2020-07-21 22:34:14 +03:00
Vexu
7e7d1df4da stage2: add floatCast to zir and ir 2020-07-21 22:34:12 +03:00
Vexu
7b52dbbf83 stage2: implement some casts for numbers 2020-07-21 22:29:29 +03:00
Vexu
da217fadeb stage2: astgen for floats and other primitive literals 2020-07-21 22:29:28 +03:00
Vexu
e77ca6af70 stage2: add float values 2020-07-21 22:29:28 +03:00
Vexu
fd2f034e31 fix comptime comparisons of different sized floats 2020-07-21 22:29:15 +03:00
Andrew Kelley
8ee629aa4c stage2: ability for ZIR to map multiple tags to the same type 2020-07-21 12:13:15 -07:00
Andrew Kelley
7a1a924788 stage2: AST: (breaking) flatten out suffix operations 2020-07-21 10:52:24 -07:00
Andrew Kelley
1ac28eed83 stage2 AST: rename OptionalUnwrap to OrElse
preparing to flatten suffix operations AST
2020-07-21 10:46:47 -07:00
Andrew Kelley
1cfe43d563 Merge pull request #5888 from pfgithub/stage-2-testing-Copy
stage2: period and suffixop
2020-07-21 17:42:46 +00:00
purringChaos
094223d634 Fix log.zig example. 2020-07-21 18:53:30 +03:00
Andrew Kelley
4abf119d95 Merge branch 'register-allocation' 2020-07-20 13:12:25 -07:00
Andrew Kelley
ef91b11295 stage2: register allocator processes operand deaths
also rework the IR data structures
2020-07-20 13:12:20 -07:00
Andrew Kelley
a8065a05a5 stage2: fix implementation of liveness operandDies() 2020-07-20 13:12:20 -07:00
Andrew Kelley
896472c20e stage2: implement register copying 2020-07-20 13:12:20 -07:00
Andrew Kelley
ef9aeb6ac4 stage2: codegen: refactor to always have comptime arch 2020-07-20 13:12:20 -07:00
Anthony Arian
3658dd5e89 Merge branch 'master' of https://github.com/ziglang/zig into 5002-fix-entrypoint-with-winmain 2020-07-20 10:25:54 +01:00
Vexu
596ca6cf70 allow non-pointer extern opaque variables 2020-07-18 16:45:07 +03:00
Vexu
78962eeeda fix floatCast type check regression
Closes #5900
2020-07-18 10:22:15 +03:00
data-man
39915ae086 Add trait.isTuple 2020-07-17 17:55:55 +03:00
Vexu
a1e78d0b06 add is_tuple field to struct typeinfo
part of #4335
2020-07-17 00:15:34 +03:00
pfg
86922b8d08 stage2: support @"identifier" syntax 2020-07-16 14:08:36 -07:00
Andrew Kelley
cc3bceea3d Merge pull request #5889 from Vexu/translate-c
Translate-c support initializer lists in macros
2020-07-16 19:03:03 +00:00
Vexu
5e88a7a427 add behavior tests fro macro translations 2020-07-16 17:10:52 +03:00
Vexu
06c08e5219 std.mem.zeroes use std.mem.set instead of @memset
stage1 comptime is not smart enough to remeber the size of the casted
item which leads to out of bounds errors.
2020-07-16 17:05:14 +03:00
data-man
3cdc0f104e Vectors clarification in docs 2020-07-16 16:22:28 +03:00
Vexu
37647375dc translate-c: support initializer list expr macros 2020-07-16 16:20:47 +03:00
Vexu
8fe076daaf std.mem.zeroInit support initiating with tuples 2020-07-16 16:00:42 +03:00
pfg
83a0073b68 stage2: period and suffixop 2020-07-16 04:22:05 -07:00
pfg
01ab167ce3 stage2: change large switch → inline for loop 2020-07-16 10:32:24 +00:00
Andrew Kelley
e079fdeee7 Merge pull request #5885 from ziglang/stage2-locals
self-hosted compiler local consts
2020-07-16 05:57:32 +00:00
Andrew Kelley
d29dd5834b stage2: local consts
These are now supported enough that this example code hits the
limitations of the register allocator:

fn add(a: u32, b: u32) void {
    const c = a + b; // 7
    const d = a + c; // 10
    const e = d + b; // 14
    assert(e == 14);
}
// error: TODO implement copyToNewRegister

So now the next step is to implement register allocation as planned.
2020-07-15 22:36:35 -07:00
Andrew Kelley
af12596e8d stage2: breaking AST memory layout modifications
InfixOp is flattened out so that each operator is an independent AST
node tag. The two kinds of structs are now Catch and SimpleInfixOp.

Beginning implementation of supporting codegen for const locals.
2020-07-15 19:39:18 -07:00
haze
82562b205f On darwin, only add the self exe to the cache hash for compiler id (#5880)
Now that Big Sur does not have system libraries on the filesystem, zig can no longer read them and add them to the cache hash for the compiler id.
This changes it so that only the first library path returned by os_self_exe_shared_libs is added to the cache hash under Darwin. I looked into methods on getting the system version to keep parity with older versions, but @fengb reported that this works on Catalina (a version behind Big Sur)

Signed-off-by: Haze Booth <isnt@haze.cool>
2020-07-15 22:37:04 -04:00
Andrew Kelley
f119092273 stage2: breaking AST memory layout modifications
ast.Node.Id => ast.Node.Tag, matching recent style conventions.

Now multiple different AST node tags can map to the same AST node data
structures. In this commit, simple prefix operators now all map top
SimplePrefixOp.

`ast.Node.castTag` is now preferred over `ast.Node.cast`.

Upcoming: InfixOp flattened out.
2020-07-15 18:15:59 -07:00
Andrew Kelley
e70d6d19f5 stage2: extract AST=>ZIR code to separate file 2020-07-15 15:42:02 -07:00
Andrew Kelley
6b103324d2 Merge pull request #5872 from ziglang/ast-flatten-2
stage2: introduce the concept of "trailer flags" to the AST
2020-07-15 18:34:06 +00:00
Andrew Kelley
c5b7322319 TrailerFlags test: fix bad alignment assumption on 32-bit 2020-07-15 04:04:04 -07:00
Andrew Kelley
804b51b179 stage2: VarDecl and FnProto take advantage of TrailerFlags API
These AST nodes now have a flags field and then a bunch of optional
trailing objects. The end result is lower memory usage and consequently
better performance. This is part of an ongoing effort to reduce the
amount of memory parsed ASTs take up.

Running `zig fmt` on the std lib:
 * cache-misses: 2,554,321 => 2,534,745
 * instructions: 3,293,220,119 => 3,302,479,874
 * peak memory: 74.0 MiB => 73.0 MiB

Holding the entire std lib AST in memory at the same time:

  93.9 MiB => 88.5 MiB
2020-07-15 02:07:30 -07:00
Andrew Kelley
eac6280241 add std.meta.TrailerFlags API
This is useful for saving memory when allocating an object that has many
optional components. The optional objects are allocated sequentially in
memory, and a single integer is used to represent each optional object
and whether it is present based on each corresponding bit.
2020-07-14 17:19:17 -07:00
Andrew Kelley
a7c3cec65f follow up from previous commit for generic methods 2020-07-14 15:29:07 -07:00
Andrew Kelley
4696cd3e09 fix ability to call methods on enums with pointer-to-self
closes #3218
2020-07-14 14:38:40 -07:00
Andrew Kelley
67273cbe76 Merge pull request #5868 from ziglang/stage2-improvements
Stage2 improvements
2020-07-14 09:24:43 +00:00
Andrew Kelley
a92990f993 stage2: implement enough for assert() function to codegen 2020-07-14 02:24:12 -07:00
Andrew Kelley
135580c162 stage2: fix liveness analysis of Call instructions 2020-07-13 23:48:54 -07:00
Andrew Kelley
5da5ded743 stage2: detect unreferenced non-volatile asm and NOT 2020-07-13 23:48:26 -07:00
~nue
03f14c3102 Added octal formatting fo fmt functions. (#5867)
* Added octal formatting (specifier "o") to `formatIntValue` function.
* Added octal specifier test case in `fmt.zig` (under the "int.specifier" case)
2020-07-14 02:27:58 -04:00
Andrew Kelley
4f5e065d6e stage2: add ZIR support for BoolNot 2020-07-13 20:47:47 -07:00
Andrew Kelley
14cef9dd3d stage2 parser: split out PrefixOp into separate AST Nodes
This is part of a larger effort to improve the memory layout of AST
nodes of the self-hosted parser to reduce wasted memory. Reduction of
wasted memory also translates to improved performance because of fewer
memory allocations, and fewer cache misses.

Compared to master, when running `zig fmt` on the std lib:

 * cache-misses: 801,829 => 768,624
 * instructions: 3,234,877,167 => 3,232,075,022
 * peak memory: 81480 KB => 75964 KB
2020-07-13 20:13:51 -07:00
Nathan Michaels
bc900cdeaf Document top-level doc comments, per #2288. 2020-07-13 22:57:23 +00:00
Andrew Kelley
fabdef44a8 Merge pull request #5831 from paulespinosa/langref-hello-world-more
Explain Language Ref's Hello World
2020-07-13 22:45:32 +00:00
Paul Espinosa
a8d8ce9733 Use Writer for Language Reference Hello World Example
`OutStream` has been deprecated, so the "Hello, World!" example has been
updated to use `Writer`.
2020-07-13 22:41:57 +00:00
Andrew Kelley
204f61d7f5 stage2: Module: use StringHashMapUnmanaged 2020-07-13 15:34:31 -07:00
Andrew Kelley
75a720565b Merge branch 'stage2-condbr' 2020-07-13 00:32:12 -07:00
Andrew Kelley
c94652a2fd stage2: add new test case 2020-07-13 00:31:55 -07:00
Andrew Kelley
08154c0deb stage2: add retvoid support to CBE 2020-07-13 00:28:11 -07:00
Andrew Kelley
25b1c00c72 stage2: add implicit return void where applicable 2020-07-13 00:08:21 -07:00
Andrew Kelley
c306392b44 stage2: codegen: more branching support 2020-07-13 00:08:21 -07:00
Andrew Kelley
b75a51f94b stage2: implement function calling convention for calls 2020-07-13 00:08:21 -07:00
Andrew Kelley
8fe63d5042 stage2: peer type resolution with noreturn 2020-07-13 00:08:21 -07:00
Andrew Kelley
1cab40d783 Merge pull request #5864 from pixelherodev/cbe
CBE: get basic returns working
2020-07-13 07:07:27 +00:00
Noam Preil
8d6cadee16 CBE: Code cleanup 2020-07-13 01:49:04 -04:00
Noam Preil
4a46248198 CBE: Only generate (void) for calls whose return values are ignored 2020-07-13 01:49:04 -04:00
Noam Preil
a124b027b4 CBE: Use hasCodeGenBits instead of checking against void and noreturn 2020-07-13 01:49:04 -04:00
Noam Preil
3bad1c16cc Get basic return test working 2020-07-13 01:49:04 -04:00
pixelherodev
2c882b2e65 CBE: Make C an ObjectFormat instead of a special bool (#5849) 2020-07-12 22:56:31 -04:00
Vexu
dff1ac1089 check for invalid sentinel when creating pointer with @Type 2020-07-13 00:29:53 +00:00
Isaac Freund
ef17af1270 std: add mem.joinZ
currently the only options are doing a second allocation and copying or
implementing this yourself.
2020-07-12 22:17:40 +00:00
xackus
5b570bceb5 document a few functions in std.mem 2020-07-12 21:55:49 +00:00
Andrew Kelley
7adbc11403 Merge pull request #5857 from daurnimator/use-unmanaged
Use unmanaged datastructures from std.http.headers
2020-07-12 21:46:26 +00:00
Sam Tebbs
873e187f05 Make allocator test functions public 2020-07-12 21:45:25 +00:00
Jakub Konka
eea7271c4e Fix incorrect continue condition in PreopeonList
Also, check for overflow on incremented file descriptors. Previously,
we'd trigger a panic if we exceeded the `fd_t` resolution. Now, instead,
we throw an `error.Overflow` to signal that there can be no more
file descriptors available from the runtime. This way we give the user
the ability to still be able to check if their desired preopen exists
in the list or not.
2020-07-12 21:02:33 +00:00
daurnimator
91235b9371 std: don't store allocator inside of std.http.HeaderEntry 2020-07-13 00:38:59 +10:00
daurnimator
f7e4014c82 std: use *Unmanaged data structures in http.Headers object 2020-07-13 00:34:58 +10:00
daurnimator
4b48266bb7 std: add StringHashMapUnmanaged 2020-07-13 00:34:02 +10:00
Vexu
e1a5e061ca revert accidental format of tests
these test the tokenizers handling of EOF and formatting makes them useless
2020-07-12 11:27:50 +03:00
Vexu
bfe9d4184f fix alignment parsing in stage1 2020-07-12 07:35:34 +00:00
Andrew Kelley
fe08a4d065 Merge pull request #5846 from Vexu/anytype
Rename 'var' type to 'anytype'
2020-07-12 07:35:01 +00:00
Andrew Kelley
2dcb70a6be Merge pull request #5847 from Vexu/decl
Take advantage of new HashMap API's preserving order
2020-07-12 07:31:48 +00:00
Andrew Kelley
f23987db7d Sponsors Button => ZSF
Zig Software Foundation
2020-07-11 18:33:56 -04:00
Vexu
be1507a7af update compile error tests and some doc comments 2020-07-12 00:54:07 +03:00
Vexu
3e095d8ef3 use 'anytype' in translate-c 2020-07-11 22:04:38 +03:00
Vexu
1a989ba39d fix parser tests and add test for anytype conversion 2020-07-11 21:20:50 +03:00
Vexu
e85fe13e44 run zig fmt on std lib and self hosted 2020-07-11 20:41:19 +03:00
Vexu
9907116478 use typeInfo instead of hardcoded tables in std.Target 2020-07-11 20:11:20 +03:00
Vexu
2e6688ae27 Add test for @typeInfo declarations showing up in declaration order
Both the stage1 and std lib HashMap implementations now preserve insertion order
2020-07-11 19:51:20 +03:00
Vexu
8110639c79 add 'anytype' to stage1 and langref 2020-07-11 17:41:33 +03:00
Vexu
c2fb4bfff3 add 'anytype' to self-hosted parser 2020-07-11 17:41:16 +03:00
Paul Espinosa
b45a2d72c8 Introduce Error Union and Use Writer
This commit edits the "Hello, World!" introduction. It introduces Error Union
Types. Also, it changes `outStream` to `writer` in the code example and description.
2020-07-11 18:08:00 +07:00
Vexu
2e037fd827 use correct cast function when doing @floatCast at comptime 2020-07-11 11:36:28 +03:00
Paul
e57458a94f Update doc/langref.html.in
Co-authored-by: Joachim Schmidt <joachim.schmidt557@outlook.com>
2020-07-11 09:10:08 +07:00
Paul
50df1334f3 Update doc/langref.html.in
Co-authored-by: Joachim Schmidt <joachim.schmidt557@outlook.com>
2020-07-11 09:09:57 +07:00
Paul
656b640e79 Update doc/langref.html.in
Co-authored-by: Joachim Schmidt <joachim.schmidt557@outlook.com>
2020-07-11 09:09:43 +07:00
Paul
5afa7f2545 Update doc/langref.html.in
Co-authored-by: Joachim Schmidt <joachim.schmidt557@outlook.com>
2020-07-11 09:09:07 +07:00
Josh Wolfe
eddc68ad94 remove stray allocator parameter 2020-07-10 06:27:07 +00:00
Andrew Kelley
02619edf41 Revert "use correct cast function when doing @floatCast at comptime"
This reverts commit 2e1bdd0d14.

Test failures
2020-07-09 23:24:21 -07:00
Vexu
2e1bdd0d14 use correct cast function when doing @floatCast at comptime
Closes #5832
2020-07-09 21:25:55 +03:00
Paul Espinosa
f510f38592 Explain Language Ref's Hello World
To introduce the Zig programming language, the "Hello, world!" code sample now has
documentation to explain some of the features shown in the code sample
and contains links to those features in the rest of the documentation.

Writing style goals:
* Balance writing style to keep beginner and experience programmers interested.
* Be concise: allow the rest of the documentation to clarify language features.
2020-07-09 21:32:51 +07:00
Andrew Kelley
a489ea0b2f Merge branch 'register-allocation' 2020-07-08 21:03:28 -07:00
Andrew Kelley
bf56cdd9ed start to make test runner aware of logging
by default the test runner will only print logs with "warning" or
higher. this can be configured via the std.testing API.

See #5738 for future plans
2020-07-08 21:01:13 -07:00
Andrew Kelley
7bd0500589 Merge remote-tracking branch 'origin/master' into register-allocation 2020-07-08 20:46:06 -07:00
Andrew Kelley
8e425c0c8d stage2: if AST=>ZIR 2020-07-08 20:33:33 -07:00
Andrew Kelley
0e1c7209e8 Merge pull request #5822 from pixelherodev/cbe
CBE cleanup
2020-07-09 03:32:34 +00:00
Ryan Liptak
12a7dedb1f langref: Expand "if error union with optional" test case
Follow-up to #5818, closes #5819
2020-07-09 03:30:35 +00:00
xackus
2064e84cdd ci: check langref.html for html errors 2020-07-08 19:34:44 +00:00
Ryan Liptak
f77c968cf8 langref: Add test case for "if error union with optional"
This is an edge case that isn't too uncommon but is rather confusing to try to deduce without documentation, since it feels like `else` is being overloaded in this scenario and there's no obvious 'correct' behavior here. This just adds a test demonstrating how Zig currently behaves in this scenario.
2020-07-08 19:32:15 +00:00
Paul Espinosa
eeae3a8f9d Rename langref's Index to Contents (TOC)
The language reference's Index is a list of the documentation's contents in
order of appearance. This commit renames "Index" to "Contents" as in table of
contents. It also renames the HTML/CSS identifiers from "index" to "toc".
2020-07-08 19:31:38 +00:00
Noam Preil
d060be8804 CBE: Don't expose openCFile, always close file after an update 2020-07-08 14:10:11 -04:00
Noam Preil
6b48634166 CBE: Emit asm decls for now, but rename to make them valid 2020-07-08 14:05:07 -04:00
Andrew Kelley
6fbb5f0a81 Merge pull request #5816 from pixelherodev/cbe
Beginnings of C backend
2020-07-08 10:45:17 +00:00
Andrew Kelley
be0546d877 stage2: implement compare operator AST->ZIR 2020-07-08 07:04:43 +00:00
Andrew Kelley
5e60872060 stage2 misc fixes 2020-07-08 06:56:20 +00:00
Andrew Kelley
8849604131 stage2: proper indenting when printing ZIR text 2020-07-08 05:44:51 +00:00
Andrew Kelley
ab9df5b04b stage2: machine code for condbr jumps 2020-07-08 05:35:41 +00:00
Noam Preil
9d92d62525 CBE: Only try to use GNU attribute when __GNUC__is set 2020-07-08 00:33:44 -04:00
Noam Preil
e2aad33d4e Stage2: facepalm. 2020-07-08 00:11:41 -04:00
Noam Preil
9aaffe00d3 CBE: Cleanup unimplementeds 2020-07-07 23:59:55 -04:00
Noam Preil
089c056dbe CBE: Improve resource cleanup 2020-07-07 23:24:30 -04:00
Noam Preil
7a6104929b CBE: truncate output file 2020-07-07 23:19:25 -04:00
Noam Preil
173e671241 CBE: Some cleanup 2020-07-07 23:11:17 -04:00
Vexu
5667a21b1e fix missing check on extern variables with no type 2020-07-08 03:09:41 +00:00
Noam Preil
b91cf15972 CBE: Move standards determination to generated code 2020-07-07 22:57:34 -04:00
Noam Preil
5461c482d0 CBE: Integrate into stage2 via --c-standard 2020-07-07 21:54:34 -04:00
Noam Preil
64bf130182 CBE: working asm Inputs and Outputs; std{int,def}.h auto-inclusion 2020-07-07 21:35:42 -04:00
Noam Preil
cf09b335d8 CBE: Working function call w/ no args or return value 2020-07-07 19:35:33 -04:00
Andrew Kelley
597a363673 Merge pull request #5755 from kubkon/dir-iter-tests
[libstd]: add Dir.Iterator tests
2020-07-07 23:13:58 +00:00
Noam Preil
cf86aa8772 Fix a dumb in tests 2020-07-07 18:43:25 -04:00
Jakub Konka
417c928952 Add comment about memory invalidation in Iterator.next on Win 2020-07-08 00:03:45 +02:00
Noam Preil
6ece36a051 Working translation of empty function 2020-07-07 17:51:59 -04:00
Noam Preil
2f28ecf946 CBE: Get test more useful 2020-07-07 17:06:07 -04:00
Noam Preil
aaaebfe97f Detect unexpected compilation errors in tests 2020-07-07 16:47:39 -04:00
Noam Preil
a17200dab1 CBE skeleton 2020-07-07 16:40:14 -04:00
Noam Preil
b4c571301b Stage2: Refactor in preparation for C backend 2020-07-07 14:55:44 -04:00
Andrew Kelley
b55d0193e4 stage2: progress towards Block and CondBr codegen 2020-07-07 08:01:54 +00:00
Andrew Kelley
4d01385e14 fix liveness analysis and not correctly propagating link errors
We still flush the ELF file even when there are compile errors.
2020-07-07 03:48:20 +00:00
Noam Preil
0db0258fb2 Remove old comment 2020-07-06 17:54:06 -04:00
Vexu
485231deae fix HashMap.clone() 2020-07-06 16:51:53 +03:00
Andrew Kelley
12737c9a30 stage2: codegen skeleton for cmp and sub 2020-07-06 09:21:57 +00:00
Andrew Kelley
8be8ebd698 stage2: skeleton codegen for x64 ADD
also rework Module to take advantage of the new hash map implementation.
2020-07-06 06:10:44 +00:00
Andrew Kelley
ad2ed457dd std: expose unmanaged hash maps
These are useful when you have many of them in memory, and already have
the allocator stored elsewhere.
2020-07-06 06:10:03 +00:00
Andrew Kelley
a2fd8f72c1 std: add new array list functions 2020-07-06 06:09:47 +00:00
Andrew Kelley
8fb392dbb4 stage2: implement liveness analysis 2020-07-05 23:20:08 +00:00
Andrew Kelley
abcd4ea5d8 Merge pull request #5793 from pfgithub/stage-2-testing
stage2 + operator and @as builtin
2020-07-05 22:58:05 +00:00
Alluet
a0a93f2091 Rewrite std.fmt.parseInt 2020-07-05 22:56:06 +00:00
Andrew Kelley
682fccaaf0 Merge branch 'emekoi-windowsver-fix'
closes #5011
2020-07-05 22:44:46 +00:00
Andrew Kelley
86ef3202dd add doc comment for std.Target.Os.WindowsVersion 2020-07-05 22:44:25 +00:00
emekoi
68be229917 added custom format method for WindowsVersion 2020-07-05 22:43:10 +00:00
Jonathan Marler
27c1e0b453 Fix issue 5757: increase branch quota for formatting enums 2020-07-05 22:27:50 +00:00
Andrew Kelley
dcca5cf1a9 Merge pull request #5797 from xackus/intcast-runtime-safety
stage1: `@intcast` runtime safety for unsigned -> signed of same bit count
2020-07-05 22:24:25 +00:00
Andrew Kelley
289eab9177 Merge pull request #5786 from ziglang/std-hash-map
reimplement std.HashMap
2020-07-05 21:12:20 +00:00
Andrew Kelley
3a89f214aa update more HashMap API usage 2020-07-05 21:11:42 +00:00
Andrew Kelley
3c8b13d998 std hash map: do the pow2 improvement again
it's a noticeable speedup
2020-07-05 21:11:42 +00:00
Andrew Kelley
632acffcbd update std lib to new hash map API 2020-07-05 21:11:42 +00:00
Andrew Kelley
b3b6ccba50 reimplement std.HashMap
* breaking changes to the API. Some of the weird decisions from before
   are changed to what would be more expected.
   - `get` returns `?V`, use `getEntry` for the old API.
   - `put` returns `!void`, use `fetchPut` for the old API.
 * HashMap now has a comptime parameter of whether to store hashes with
   entries. AutoHashMap has heuristics on whether to set this parameter.
   For example, for integers, it is false, since equality checking is
   cheap, but for strings, it is true, since equality checking is
   probably expensive.
 * The implementation has a separate array for entry_index /
   distance_from_start_index. Entries no longer has holes; it is an
   ArrayList, and iteration is simpler and more cache coherent.
   This is inspired by Python's new dictionaries.
 * HashMap is separated into an "unmanaged" and a "managed" API. The
   unmanaged API is where the actual implementation is; the managed API
   wraps it and provides a more convenient API, storing the allocator.
 * Memory usage: When there are less than or equal to 8 entries, HashMap
   now incurs only a single pointer-size integer as overhead, opposed to
   using an ArrayList.
 * Since the entries array is separate from the indexes array, the holes
   in the indexes array take up less room than the holes in the entries
   array otherwise would. However the entries array also allocates
   additional capacity for appending into the array.
 * HashMap now maintains insertion order. Deletion performs a "swap
   remove". It's now possible to modify the HashMap while iterating.
2020-07-05 21:11:42 +00:00
xackus
b8553b4813 compiler-rt: fix bugs uncovered by previous commit 2020-07-05 20:44:08 +02:00
xackus
51f8c306d9 stage1: add missing runtime safety for @intCast unsigned -> signed of same bit count 2020-07-05 17:58:21 +02:00
pfg
4a63189bf1 stage2: add and @as tests 2020-07-04 15:30:17 -07:00
pfg
d4456d92f5 stage2: builtin @as 2020-07-04 15:16:46 -07:00
pfg
1d52438bd5 stage2: InfixOp add 2020-07-04 15:16:46 -07:00
joachimschmidt557
0ae1157e45 std.mem.dupe is deprecated, move all references in std
Replaced all occurences of std.mem.dupe in stdlib with
Allocator.dupe/std.mem.dupeZ -> Allocator.dupeZ
2020-07-04 21:40:06 +03:00
heidezomp
672b4d5c24 zig build --help: Consistent capitalization/punctuation 2020-07-04 13:00:53 +00:00
pfg
65aac13257 don't try to find config_h if it's not needed 2020-07-04 12:50:37 +00:00
Andrew Kelley
70dca0a0c6 Merge pull request #5779 from ziglang/stage1-hash-map
stage1 HashMap: store hash & do robin hood hashing
2020-07-03 17:11:54 +00:00
Andrew Kelley
f281b928d9 cmake: add -DZIG_WORKAROUND_POLLY_SO
to work around #4799 until a newer llvm version is released.
2020-07-03 04:48:48 +00:00
Andrew Kelley
72cd11dd60 Merge branch 'timotheecour-pr_fix_4799'
closes #5092
2020-07-03 04:43:21 +00:00
Andrew Kelley
14e07e9a72 clean up readme 2020-07-03 04:43:05 +00:00
Timothee Cour
9a7f05378f fix https://github.com/ziglang/zig/issues/4799 2020-07-03 04:40:25 +00:00
Andrew Kelley
22f0a103c3 stage1 HashMap: linear scan for < 16 entries 2020-07-03 03:50:35 +00:00
Andrew Kelley
df2c27eb48 stage1 HashMap: store hash & do robin hood hashing
This adds these two fields to a HashMap Entry:

uint32_t hash
uint32_t distance_from_start_index

Compared to master branch, standard library tests compiled 8.4% faster
and took negligible (0.001%) more memory to complete. The amount of
memory used is still down from before 8b82c40104 which moved indexes
to be stored separately from entries.

So, it turns out, keeping robin hood hashing plus separating indexes
did result in a performance improvement. What happened previously is
that the gains from separating indexes balanced out the losses from
removing robin hood hashing, resulting in a wash.

This also serves as an inspiration for adding a benchmark to
std.AutoHashMap and improving the implementation.
2020-07-02 22:38:55 +00:00
Jakub Konka
e7d02eae4d Update lib/std/fs/test.zig
Co-authored-by: Joachim Schmidt <joachim.schmidt557@outlook.com>
2020-07-02 20:54:57 +02:00
Ian Simonson
70cc1751ca Translate-c fix rhs not cast on array access
Closes #5671. Checks if the rhs is integral and of
differing or the same signedness. If they are different
does an @intCast to the lhs type
2020-07-02 14:05:12 +00:00
Jakub Konka
b5badd1122 Fix memory corruption in Dir.Iterator test 2020-07-02 10:35:44 +02:00
Jakub Konka
64bd134818 Add Dir.Iterator tests
This commit adds some `std.fs.Dir.Iterator` tests.
2020-07-02 10:35:44 +02:00
Andrew Kelley
8b82c40104 stage1: reimplement HashMap
The indexes are stored separately using an array of
uint8_t, uint16_t, uint32_t, or size_t, depending on the number of
entries in the map.

Entries only contain a key and a value, no longer have
distance_from_start_index or is_used.

In theory this should be both faster and use less memory.

In practice it seems to have little to no effect. For the standard
library tests, vs master branch, the time had no discernable
difference, and it shaved off only 13 MiB of peak rss usage.
2020-07-02 04:53:26 +00:00
luna
e2cfc65909 Merge branch 'master' into ebadf-error 2020-07-02 00:49:56 -03:00
Andrew Kelley
6f98ef09e3 Merge pull request #5717 from squeek502/fs-dir-file-ops
Add tests for using file operations on directories
2020-07-01 23:20:50 +00:00
Andrew Kelley
d2a4e5e226 Merge pull request #5749 from kubkon/wasi-notcapable
[libstd]: handle ENOTCAPABLE in WASI
2020-07-01 23:12:26 +00:00
Alexandros Naskos
30ae7f7573 Corrected default value field initialization in std.zeroInit 2020-07-01 23:09:08 +00:00
Chris Watson
b8d5b3e611 Add documentation for @src() builtin 2020-07-01 22:22:30 +00:00
CodeMyst
7eed220924 in docs removed "path can be absolute" for imports 2020-07-01 22:12:44 +00:00
Andrew Kelley
f69875d85c build: -Dlib-files-only prevents self-hosted compiler from being built
closes #5756
2020-07-01 21:57:04 +00:00
Shawn Anastasio
51fcf949f9 Implement std.start for powerpc64le
This is a bit hacky since we end up doing more than just grabbing
the stack pointer in the inline assembly block. Ideally _start would
be implemented in pure asm for powerpc64le, but this will do for now.

Still to be implemented is powerpc, powerpc64, and powerpc64 (ELFv2)
support. The latter will just require correctly determing target ABI
for powerpc64 and enabling the existing powerpc64le implementation for
it.
2020-07-01 16:13:14 -05:00
Shawn Anastasio
8574861ca0 Implement required ABI bits for powerpc{,64,64le} 2020-07-01 16:12:27 -05:00
Shawn Anastasio
15371775d1 Implement clone() for powerpc64{,le}
Implementation borrowed from musl, as most (all?) of the other
ones seem to be.
2020-07-01 16:11:26 -05:00
Shawn Anastasio
ec0d775524 Implement std.os for powerpc64{,le} 2020-07-01 16:10:49 -05:00
antlilja
dcc406deff Add new error message for unreachable else prongs
* Adds error message for types: enum, int and bool
* Adds compile error tests
2020-07-01 16:09:36 +02:00
Jakub Konka
8306826d53 Map ENOTCAPABLE into error.AccessDenied instead of error.NotCapable
This is direct result of review comments left by andrewrk and
daurnimator. It makes sense to map `ENOTCAPABLE` into a more generic
`error.AccessDenied`.
2020-06-30 18:21:38 +02:00
Jakub Konka
5bc99dd7e8 Fix more compilation errors 2020-06-29 21:42:11 +02:00
Luna
3f5b2d6c51 std.os: map EBADF to errors on WASI read/write syscalls 2020-06-29 16:23:58 -03:00
Jakub Konka
b96882c57a Fix compilation errors 2020-06-29 18:09:22 +02:00
Jakub Konka
bf8bf528c6 Handle ENOTCAPABLE in WASI
This commit adds `error.NotCapable` enum value and makes sure that
every applicable WASI syscall that can return `ENOTCAPABLE` errno
remaps it to `error.NotCapable.
2020-06-29 17:10:01 +02:00
Jonathan Marler
67e97a1f0f ArenaAllocator: use full capacity 2020-06-29 05:12:30 -04:00
Jonathan Marler
35e8876c23 Revert "arena_allocator: refactor and use full capacity"
This reverts commit e120b07a52.
2020-06-29 05:12:30 -04:00
Andrew Kelley
1eed0cf0f3 zig fmt and delete unused type 2020-06-28 19:45:10 -04:00
Andrew Kelley
aa92446365 stage2: implement function parameters
In codegen.zig, the std.Target.Cpu.Arch is now generally available as a
comptime value where needed. This is a tradeoff that causes the compiler
binary to be more bloated, but gives us higher performance, since the
optimizer can optimize per architecture (which is usually how compilers
are designed anyway, with different code per-architecture), and it also
allows us to use per-architecture types, such as a Register enum that is
specific to the comptime-known architecture.

Adds abiSize method to Type.
2020-06-28 19:45:10 -04:00
Jonathan Marler
e120b07a52 arena_allocator: refactor and use full capacity 2020-06-28 18:40:15 -04:00
Jonathan Marler
c2eead9629 Fix issue 5741, use after free 2020-06-28 18:05:18 -04:00
Luna
f47c6d3c6b std.os: make EBADF return error for read and write 2020-06-28 18:40:43 -03:00
Ryan Liptak
74c245aea9 Disable wasi 'readFileAlloc on a directory' assertion for now 2020-06-28 13:56:00 -07:00
Jonathan Marler
374e3e42e0 WasmPageAllocator: fix bug not aligning allocations 2020-06-28 14:25:39 -04:00
Andrew Kelley
581d16154b Merge pull request #5696 from alexnask/async_call_tuple
@asyncCall now takes arguments as a tuple instead of varargs
2020-06-28 01:00:58 -04:00
Andrew Kelley
ac6bf53069 stage2: clean up test harness, implement symbol collision detection (#5708)
* Clean up test harness
* Stage2/Testing: Add convenience wrappers
* Add a `compiles` wrapper case
* fix incremental compilation after error
* exported symbol collision detection
* function redefinition detection for Zig code
* handle missing function names
* Stage2/Testing: Simplify incremental compilation tests
* Stage2/Testing: Update documentation
* Stage2/TestHarness: Improve progress reporting
* Disable test
* Improve Tranform failure output
2020-06-27 21:54:11 -04:00
Noam Preil
80b70470c0 Stage2/Module: Add symbol -> export lookup table 2020-06-27 21:50:59 -04:00
Noam Preil
ffca1569d1 Return instead of branch 2020-06-27 21:39:39 -04:00
Noam Preil
38d2c5cdf1 Rename type -> extension 2020-06-27 21:39:04 -04:00
Noam Preil
1861c25142 Improve Tranform failure output 2020-06-27 21:15:23 -04:00
Noam Preil
97c41e7152 Disable test 2020-06-27 21:10:44 -04:00
Noam Preil
54148a8c88 Stage2/TestHarness: Improve progress reporting 2020-06-27 20:01:20 -04:00
Andrew Kelley
0cfe8e5d6f Merge pull request #5064 from marler8997/newAllocator
new allocator interface
2020-06-27 18:21:00 -04:00
Jonathan Marler
a728436992 new allocator interface after Andrew Kelley review 2020-06-27 08:57:35 -06:00
Noam Preil
ab307a22f6 Stage2: remove clearErrors, fix ZIR export collision detection 2020-06-27 07:17:20 -04:00
Ryan Liptak
626b5eccab Move fs-specific tests from os/test.zig to fs/test.zig
The moved tests do not use `std.os` directly and instead use `std.fs` functions, so it makes more sense for them to be in `fs/test.zig`
2020-06-27 10:17:08 +00:00
Ryan Liptak
12aca758c6 Dir.deleteFile: Fix symlink behavior when translating EPERM to EISDIR 2020-06-26 17:12:02 -07:00
Ryan Liptak
505bc9817a Implement Dir.deleteFile in terms of deleteFileZ/deleteFileW
Reduces duplicate code, consistent with other fn/fnZ/fnW implementations
2020-06-26 16:08:26 -07:00
Ryan Liptak
14c3c47fb7 fs.deleteFile: Translate to error.IsDir when appropriate on POSIX systems
Linux deviates from POSIX and returns EISDIR while other POSIX systems return EPERM. To make all platforms consistent in their errors when calling deleteFile on a directory, we have to do a stat to translate EPERM (AccessDenied) to EISDIR (IsDir).
2020-06-26 16:00:43 -07:00
Jonathan Marler
dc9648f868 new allocator interface 2020-06-26 13:34:48 -06:00
Andrew Kelley
bb55889ce0 README: add link to troubleshooting build issues wiki page
See #5673
2020-06-26 15:10:30 -04:00
Noam Preil
52787f2c9b Fix a dumb 2020-06-26 06:52:29 -04:00
Noam Preil
6d536168b0 Stage2/Testing: Update documentation 2020-06-26 06:51:35 -04:00
Noam Preil
0e952a9f3a Stage2/Testing: Simply incremental compilation tests 2020-06-26 05:00:53 -04:00
Noam Preil
c8f60b2e2f Stage2: handle missing function names 2020-06-26 04:36:17 -04:00
Noam Preil
6510888039 Stage2: function redefinition detection for Zig code 2020-06-26 04:05:41 -04:00
Noam Preil
4a17e008da Stage2: exported symbol collision detection 2020-06-26 03:17:13 -04:00
Noam Preil
e5a3cb8d71 Stage2: fix incremental compilation after error 2020-06-26 03:16:36 -04:00
Noam Preil
53fead580e Add a compiles wrapper case 2020-06-26 03:09:56 -04:00
Ryan Liptak
0e3d74df8a Add tests for using file operations on directories 2020-06-26 00:06:23 -07:00
Noam Preil
649da2df52 Stage2/Testing: Add convenience wrappers 2020-06-26 02:42:02 -04:00
Andrew Kelley
130c7fd23b self-hosted: working towards conditional branching test case
New features:
 * Functions can have parameters in semantic analysis. Codegen
   is not implemented yet.
 * Support for i8, i16, i32, i64, u8, u16, u32, u64 primitive
   identifiers.
 * New ZIR instructions: arg, block, and breakvoid

Implementation details:

 * Move Module.Body to ir.Body
 * Scope.Block gains a parent field and an optional Label field
 * Fix bug in integer type equality comparison.

Here's the test case I'm working towards:

```
@void = primitive(void)
@i32 = primitive(i32)
@fnty = fntype([@i32, @i32], @void)

@0 = str("entry")
@1 = export(@0, "entry")

@entry = fn(@fnty, {
  %0 = arg(0)
  %1 = arg(1)
  %2 = add(%0, %1)
  %3 = int(7)
  %4 = block("if", {
    %neq = cmp(%2, neq, %3)
    %5 = condbr(%neq, {
      %6 = unreachable()
    }, {
      %7 = breakvoid("if")
    })
  })
  %11 = returnvoid()
})
```

$ ./zig-cache/bin/zig build-obj test.zir
test.zir:9:12: error: TODO implement function parameters for Arch.x86_64

That's where I left off.
2020-06-26 02:30:14 -04:00
Andrew Kelley
e820678ca1 Merge pull request #5588 from tgschultz/leb128-output
LEB128 overhaul and output
2020-06-25 19:10:31 -04:00
Andrew Kelley
061c8be049 Merge pull request #5684 from squeek502/fs-file-dir-ops
Add tests for using directory operations on files
2020-06-25 19:08:30 -04:00
data-man
77bb2dc094 Use writer in benchmarks 2020-06-25 19:07:25 -04:00
Ryan Liptak
dcdbb7006c Add tests for using directory operations on files 2020-06-25 03:49:58 -07:00
Ryan Liptak
f50ed94174 Windows: Fix fs.Dir.openDir not handling STATUS_NOT_A_DIRECTORY
Now correctly returns error.NotDir
2020-06-25 03:49:58 -07:00
Andrew Kelley
41c6cc9001 Merge pull request #5677 from kubkon/fstatat
[libstd]: implement fstatat in WASI plus fix on macOS
2020-06-25 00:01:38 -04:00
arbrk1
78d8931647 Fix issue #5618 (#5685)
* fix issue #5618

* A test for the issue #5618 added.
Also inserted a comma in the neighboring test to make it more zigfmt-friendly.
2020-06-24 23:58:50 -04:00
Alexandros Naskos
2fde8249b7 Fixed crash when resolving peer types of *[N:s]const T and [*:s]const T 2020-06-24 23:58:02 -04:00
Noam Preil
c88edbc46f OOM -> catch unreachable 2020-06-24 23:34:58 -04:00
Noam Preil
5d7e981f95 Clean up test harness 2020-06-24 22:43:18 -04:00
Andrew Kelley
d337469e44 Merge pull request #5583 from ziglang/zig-ast-to-zir
self-hosted: hook up Zig AST to ZIR
2020-06-24 22:37:58 -04:00
Code Hz
7875649c24 Pdb.openFile use []const u8 instead of []u8 2020-06-24 22:27:30 -04:00
Andrew Kelley
20b4a2cf2c self-hosted: add compare output test for new AST->ZIR code 2020-06-24 21:28:42 -04:00
Andrew Kelley
5aa3f56773 self-hosted: fix test regressions
I'm allowing incremental compilation of ZIR modules to be broken. This
is not a real use case of ZIR, and the feature requires a lot of code
duplication with incremental compilation of Zig AST (which works great).
2020-06-24 20:28:52 -04:00
Andrew Kelley
fd7a97b3b2 fix memory leak of anonymous decl name 2020-06-24 16:20:02 -04:00
Andrew Kelley
e42b7702eb Merge remote-tracking branch 'origin/master' into zig-ast-to-zir 2020-06-24 15:36:59 -04:00
Alexandros Naskos
129a4fb251 Copy union const values correctly 2020-06-24 15:21:58 -04:00
Jakub Konka
d40e367b73 Reformat using if-else where appropriate 2020-06-24 21:00:21 +02:00
Jakub Konka
c63b23d684 Use fstatat on macOS (otherwise uses 32bit) 2020-06-24 21:00:21 +02:00
Jakub Konka
be78b7b648 Implement fstatat targeting WASI
Also, add more informative `@compileError` in a few `std.os` functions
that would otherwise yield a cryptic compile error when targeting
WASI. Finally, enhance docs in a few places and add test case for
`fstatat`.
2020-06-24 21:00:21 +02:00
Andrew Kelley
2c7fc1c5c5 Merge branch 'marler8997-fixAzureMsys2'
closes #5688
closes #5679
2020-06-24 14:53:02 -04:00
Andrew Kelley
489c31b6f5 azure ci: install tar and xz with pacman 2020-06-24 14:52:34 -04:00
Jonathan Marler
3a2cc5decf azure-pipelines: fix msys2 install 2020-06-24 14:33:01 -04:00
antlilja
e60be30824 Remove unreachable else prongs 2020-06-24 19:03:32 +02:00
Alexandros Naskos
ff2ddcf38d Updated @asyncCall docs 2020-06-24 19:01:38 +03:00
Alexandros Naskos
7f342451b6 Fixed @asyncCall in runtime safety test 2020-06-24 18:43:11 +03:00
antlilja
fd50696359 Store else node in IrInstSrcCheckSwitchProngs
* Remove have_else_prong (bool)
* Add else_prong (AstNode*)
2020-06-24 17:36:24 +02:00
Alexandros Naskos
eefcd04462 Small fixes, fixed tests, added test for argument tuple type 2020-06-24 16:56:24 +03:00
Alexandros Naskos
50b70bd77f @asyncCall now requires an argument tuple 2020-06-24 14:07:39 +03:00
Andrew Kelley
14aa08fcd3 self-hosted: restore ZIR functionality 2020-06-24 03:46:32 -04:00
Andrew Kelley
3aab6012c4 Revert "building mingw-w64 for windows ARM looks in lib64/lib32 for .def files"
This reverts commit 93f0bcb649.

This is not correct (from #mingw-w64 IRC):

<andrewrk> is there no .def file for ntdll on arm 64 bit?
<andrewrk> or does mingw-w64-crt/lib64/ntdll.def apply to both x86_64
and aarch64?
<wbs> andrewrk: there's none at the moment (as apps rarely link directly
against ntdll, and I didn't want to guess needlessly around that one
originally when I added arm64 support, before I actually had a real
arm64 windows device)
<wbs> andrewrk: but I guess I could/should complete that now
<wbs> (if you need one right now, the libarm32 one probably is the
closest match)
2020-06-24 02:08:08 -04:00
Andrew Kelley
93f0bcb649 building mingw-w64 for windows ARM looks in lib64/lib32 for .def files 2020-06-24 01:59:19 -04:00
Andrew Kelley
b1b7708cc8 self-hosted: hook up incremental compilation to .zig source code 2020-06-23 23:29:51 -04:00
Andrew Kelley
a1a1f94a0d Merge pull request #5681 from kubkon/refactor-wasi-preopens
[libstd]: refactor std.fs.wasi.PreopenList.find()
2020-06-23 22:23:20 -04:00
Andrew Kelley
d9c1d8fed3 self-hosted: improve handling of anonymous decls
* anonymous decls have automatically generated names and symbols, and
   participate in the same memory management as named decls.
 * the Ref instruction is deleted
 * the DeclRef instruction now takes a `[]const u8` and DeclRefStr takes
   an arbitrary string instruction operand.
 * introduce a `zir.Decl` type for ZIR Module decls which holds
   content_hash and name - fields that are not needed for `zir.Inst`
   which are created as part of semantic analysis. This improves the
   function signatures of Module.zig and lowers memory usage.
 * the Str instruction is now defined to create an anonymous Decl and
   reference it.
2020-06-23 19:53:32 -04:00
Jakub Konka
5fed725e0a Remove some leftover debugging checks 2020-06-23 23:59:32 +02:00
Jakub Konka
66e5205047 Refactor PreopenList.find()
This commit generalizes `std.fs.wasi.PreopenList.find(...)` allowing
search by `std.fs.wasi.PreopenType` union type rather than by dir
name. In the future releases of WASI, it is expected to have more
preopen types (or capabilities) than just directories. This commit
aligns itself with that vision.

This is a potentially breaking change. However, since `std.fs.wasi.PreopenList`
wasn't made part of any Zig release yet, I think we should be OK
to introduce those changes without pointing to any deprecations.
2020-06-23 21:54:36 +02:00
antlilja
0de35af98b Add duplicate checking for switch on types
* Add compile error tests
2020-06-23 15:17:04 -04:00
antlilja
46106b018c Add expectWithinEpsilon + test 2020-06-23 18:08:15 +02:00
antlilja
2fc2355fc3 Add expectWithinMargin and test 2020-06-23 18:05:32 +02:00
Andrew Kelley
6938245fcc Merge remote-tracking branch 'origin/master' into zig-ast-to-zir 2020-06-22 23:22:17 -04:00
Vexu
7b68385d7d self-hosted: astGenIntegerLiteral support other bases 2020-06-22 23:19:12 -04:00
Vexu
d98aed6eff self-hosted: generalize astGenBuiltinCall 2020-06-22 23:19:12 -04:00
Andrew Kelley
78c6d39cd4 Merge pull request #5667 from cartr/windows-arguments-unclosed-quote
In std.process.ArgIteratorWindows, don't treat unclosed quotes like they're escaped
2020-06-22 20:07:43 -04:00
Jakub Konka
923c0feda1 Add std.fs.File.readAllAlloc tests
This commit adds some unit tests for `std.fs.File.readAllAlloc`
function. It also updates the docs of `Reader.readNoEof`
which were outdated, and swaps `inStream()` for  `reader()` in
`File.readAllAlloc` with the former being deprecated.
2020-06-22 20:03:21 -04:00
Andrew Kelley
6ff6ac866d Merge pull request #5666 from kubkon/symlinkat-readlinkat
[libstd]: enhance std.os.{symlinkat, readlinkat} coverage
2020-06-22 20:02:27 -04:00
Andrew Kelley
44bd0a2670 Merge pull request #5662 from shtanton/meta-cast
Adds std.meta.cast and uses it to simplify translate-c
2020-06-22 19:54:30 -04:00
prime31
65ef74e2cd try allocation of pointer type when parsing (#5665)
* `try` allocation of pointer type when parsing

* fixes pointer destroy compile error
2020-06-22 17:30:02 +03:00
Carter Sande
7cb41a415a ArgIteratorWindows: simplify quote state tracking 2020-06-22 03:03:30 -07:00
Carter Sande
8faa85ac19 ArgIteratorWindows: don't treat unclosed quotes like they're escaped 2020-06-22 03:03:20 -07:00
Jakub Konka
c950f0c6c3 Enhance std.os.readlinkat coverage
Adds Windows stub (still needs to be implemented on Windows),
adds WASI implementation, adds unit test testing basic chain of
ops: create file -> symlink -> readlink.
2020-06-22 09:40:06 +02:00
Jakub Konka
64078ca924 Enhance std.os.symlinkat coverage
Fixes `std.os.symlinkat` compile errors, adds Windows stub (still
needs to be implemented), adds WASI implementation.
2020-06-22 09:14:51 +02:00
Charlie Stanton
8c15cfe3da Compacts switch statements and string literal 2020-06-21 21:48:12 +01:00
xackus
d907f574e0 stage1: fix concat of sliced str literals 2020-06-21 14:57:12 -04:00
Robin Voetter
8696e52a3d Make unary minus for unsigned types a compile error (#5654)
* Make unary minus for unsigned types a compile error

* Add unreachable when generating unsigned negate
2020-06-21 14:55:44 -04:00
Andrew Kelley
126f5702df Merge pull request #5655 from squeek502/zig-fmt-cli-test
Add zig fmt to cli tests
2020-06-21 14:54:58 -04:00
Charlie Stanton
6f47513009 Adds std.meta.cast and uses it to simplify translate-c 2020-06-21 18:24:59 +01:00
Alexandros Naskos
b70c38c33c Close source file after reading it in zig fmt 2020-06-21 12:22:16 -04:00
Ryan Liptak
399f6b77c4 Add 'no changes' test to zig fmt cli test 2020-06-20 22:21:23 -07:00
Ryan Liptak
b216d8de88 Simplify unformatted code in zig fmt cli test 2020-06-20 22:20:23 -07:00
Ryan Liptak
b5f90244a4 temporary: Add test-cli step for only running cli tests 2020-06-20 22:02:56 -07:00
Ryan Liptak
ca9d8a1337 Add zig fmt test to cli tests for both files and directories
Should catch basic `zig fmt` regressions that were previously going uncaught and breaking things
2020-06-20 22:02:55 -07:00
Nameless
56220449ab Add errors to windows.WSAStartup and WSACleanup 2020-06-21 00:13:06 -04:00
Andrew Kelley
edea7a46e5 Merge branch 'DrDeano-master'
closes #5648
2020-06-20 23:06:04 -04:00
Andrew Kelley
faf783e595 implement new stat functionality for WASI 2020-06-20 22:09:47 -04:00
Andrew Kelley
225f196842 std.fs: fix shadowing stat with a local variable 2020-06-20 20:43:56 -04:00
Andrew Kelley
64dfd1883e zig fmt: avoid unnecessary file system access
zig fmt previously would write a temp file, and then either rename it
into place if necessary, or unlink it if nothing was changed. Now zig
fmt renders into a memory buffer, and only writes the temp file and
renames it into place if anything changed.

Based on the performance testing I did this actually did not have much
of an impact, however it's likely that on other operating systems and
other hard drives this could make a big difference.
2020-06-20 20:14:33 -04:00
Andrew Kelley
0a9672fb86 rework zig fmt to avoid unnecessary realpath() calls
* add `std.fs.Dir.stat`
 * zig fmt checks for sym link loops using inodes instead of using
   realpath
2020-06-20 19:46:14 -04:00
Andrew Kelley
da549a72e1 zig fmt 2020-06-20 18:39:15 -04:00
Andrew Kelley
d87cd06296 rework zig fmt to use less syscalls and open fds
* `std.fs.Dir.Entry.Kind` is moved to `std.fs.File.Kind`
 * `std.fs.File.Stat` gains the `kind` field, so performing a stat() on
   a File now tells what kind of file it is. On Windows this only will
   distinguish between directories and files.
 * rework zig fmt logic so that in the case of opening a file and
   discovering it to be a directory, it closes the file descriptor
   before re-opening it with O_DIRECTORY, using fewer simultaneous open
   file descriptors when walking a directory tree.
 * rework zig fmt logic so that it pays attention to the kind of
   directory entries, and when it sees a sub-directory it attempts to
   open it as a directory rather than a file, reducing the number of
   open() syscalls when walking a directory tree.
2020-06-20 18:27:37 -04:00
DrDeano
bc0ca73887 Moved the check for formatting a directory
The original check for a directory was for the `readAllAlloc` so move the check from open to read. This in turn fixes the fmt step in the build script for directories.
2020-06-20 17:25:12 -04:00
data-man
5229f6ec68 Use writer in std.fmt 2020-06-20 18:23:57 +00:00
Veikka Tuominen
aa894cea2c Merge pull request #5645 from Sobeston/patch-7
langref - document that This works on enums too
2020-06-20 11:34:07 +00:00
Sebastian
8527718350 langref - document that This works on enums too 2020-06-20 12:16:57 +01:00
Eleanor NB
605769ec25 Replaced all occurrences of std.debug.warn in the docs with std.debug.print 2020-06-19 19:03:37 -04:00
Haze Booth
237c5429b0 Don't attempt to use io from thin air 2020-06-19 02:06:27 -04:00
Andrew Kelley
c9a0ec25e0 self-hosted: add Tracy integration
This tool helps give an intuitive picture of performance. This will help
us understand where to improve the code.
2020-06-18 21:55:37 -04:00
Andrew Kelley
0d18eda1d6 Merge pull request #5348 from ifreund/std-log
Introduce std.log
2020-06-18 21:40:06 -04:00
Andrew Kelley
c70633eacd Merge pull request #5203 from tadeokondrak/@type-for-even-more-types
implement @typeInfo for Frame and implement @Type for Frame, EnumLiteral, and ErrorSet
2020-06-18 21:25:03 -04:00
Andrew Kelley
b9e3df92db Merge branch 'deingithub-fmt-mode-thingybob'
closes #5617
closes #5616
2020-06-18 21:09:32 -04:00
Andrew Kelley
f7bcc8e040 rework zig fmt to only make one allocation
taking advantage of the fstat size
2020-06-18 21:08:30 -04:00
Cassidy Dingenskirchen
8b49487c33 Fix fs.File.mode() not returning mode_t on windows 2020-06-18 20:41:40 -04:00
Cassidy Dingenskirchen
b30642a86a Fix zig fmt clobbering a file's mode 2020-06-18 20:41:40 -04:00
Michael Rees
bd17a373cc Add std.unicode.Utf8Iterator.peek 2020-06-18 20:35:03 -04:00
Andrew Kelley
5ea0f589c9 Merge pull request #5625 from antlilja/master
Improve support for f128 and comptime_float operations
2020-06-18 20:32:43 -04:00
Vexu
caaa26c9f0 reference emit_raw in std lib tests 2020-06-18 20:17:53 -04:00
Andrew Kelley
355319fb67 zig cc: add missing cxxabi include path 2020-06-18 18:17:26 -04:00
Andrew Kelley
7e44302260 stage2: explicit hash and equality function for the DeclTable 2020-06-18 17:12:56 -04:00
Andrew Kelley
81f766eecd self-hosted parser: make a function pointer comptime 2020-06-18 17:12:56 -04:00
Andrew Kelley
46b57748a5 stage1: stop emitting memset to undefined when safety is off 2020-06-18 17:12:56 -04:00
Andrew Kelley
02f688d710 remove std.debug.warn debugging logs 2020-06-18 17:12:56 -04:00
Andrew Kelley
7e58c56ca7 self-hosted: implement Decl lookup
* Take advantage of coercing anonymous struct literals to struct types.
 * Reworks Module to favor Zig source as the primary use case.
   Breaks ZIR compilation, which will have to be restored in a future commit.
 * Decl uses src_index rather then src, pointing to an AST Decl node
   index, or ZIR Module Decl index, rather than a byte offset.
 * ZIR instructions have an `analyzed_inst` field instead of Module
   having a hash table.
 * Module.Fn loses the `fn_type` field since it is redundant with
   its `owner_decl` `TypedValue` type.
 * Implement Type and Value copying. A ZIR Const instruction's TypedValue
   is copied to the Decl arena during analysis, which allows freeing the
   ZIR text instructions post-analysis.
 * Don't flush the ELF file if there are compilation errors.
 * Function return types allow arbitrarily complex expressions.
 * AST->ZIR for function calls and return statements.
2020-06-18 17:12:56 -04:00
Andrew Kelley
b4eac0414a stage2: hook up Zig AST to ZIR
* Introduce the concept of anonymous Decls
 * Primitive Hello, World with inline asm works
 * There is still an unsolved problem of how to manage ZIR instructions
   memory when generating from AST. Currently it leaks.
2020-06-18 17:12:56 -04:00
Andrew Kelley
4a38799631 make file and fn_name fields of SourceLocation also null-terminated
One of the main motivating use cases for this language feature is
tracing/profiling tools, which expect null-terminated strings for these
values. Since the data is statically allocated, making them
additionally null-terminated comes at no cost.

This prevents the requirement of compile-time code to convert to
null-termination, which could increase the compilation time of
code with tracing enabled.

See #2029
2020-06-18 17:09:10 -04:00
Andrew Kelley
e54ed9f638 Merge pull request #5628 from Vexu/src
Implement @src
2020-06-18 16:23:56 -04:00
Vexu
14acc65675 add tests for @src 2020-06-18 21:11:34 +03:00
Vexu
a5379aa3ee implement @src 2020-06-18 21:11:09 +03:00
Isaac Freund
c3e0224792 Add std.debug.print for "printf debugging" 2020-06-17 18:36:44 +02:00
antlilja
eb7fad28f8 Improve f128 standard library support
* Add functions: floor128, ceil128, trunc128 and round128
* Add corresponding tests
2020-06-17 18:18:45 +02:00
antlilja
1157ee1307 Improve builtin op support for f128/comptime_float
* Add support for fabs, floor, ceil, trunc and round
* Add behavior tests
2020-06-17 17:35:45 +02:00
Isaac Freund
8e5393a779 Deprecate std.debug.warn 2020-06-17 02:14:52 +02:00
Isaac Freund
0bd067d19a Introduce std.log
std.log provides 8 log levels and corresponding logging functions. It
allows the user to override the logging "backend" by defining root.log
and to override the default log level by defining root.log_level.

Logging functions accept a scope parameter which allows the implementer
of the logging "backend" to filter logging by library as well as level.

Using the standardized syslog [1] log levels ensures that std.log will
be flexible enough to work for as many use-cases as possible. If we were
to stick with only 3/4 log levels, std.log would be insufficient for
large and/or complex projects such as a kernel or display server.

[1]: https://tools.ietf.org/html/rfc5424#section-6.2.1
2020-06-17 02:14:52 +02:00
Andrew Kelley
9781342042 Merge pull request #5607 from daurnimator/cleanup-debug-stderr
std: clean up debug stderr variables
2020-06-16 18:27:44 -04:00
Jonathan Marler
f0b8791da7 ArrayList(u8) support writer interface 2020-06-16 18:26:54 -04:00
Andrew Kelley
593db7e8d0 Merge pull request #5608 from alexnask/windows_utf16_dir
Use PathSpace and wide FS calls on windows in stage1
2020-06-16 18:26:02 -04:00
Jakub Konka
04c3fae720 Remove obsolete branch in ir_analyze_cast
Branch handling `*[N]T` to `E![]T` is already handled in a more complete
branch handling `*[N]T` to `[]T` *and* `*[N]T` to `E![]T` so it seems
safe to remove this one.
2020-06-16 18:24:45 -04:00
tgschultz
38e69a9e6a Added test to ensure minimum number of bytes is emitted for writes 2020-06-16 16:20:59 +00:00
tgschultz
a0160d776f Code cleanup, documentation added, read*Mem functions now take *[]const u8 2020-06-16 16:20:59 +00:00
tgschultz
00ec81b0dc Overhauled leb128:
handles integers < 8 bits
    incorrect overflow bugs fixed
    simplified *mem implementations
    added wrte* functions
    added thurough write/read testing
2020-06-16 16:20:59 +00:00
tgschultz
928d3ee9ea Code cleanup, documentation added, read*Mem functions now take *[]const u8 2020-06-16 16:20:58 +00:00
tgschultz
e94eba5df5 Overhauled leb128:
handles integers < 8 bits
    incorrect overflow bugs fixed
    simplified *mem implementations
    added wrte* functions
    added thurough write/read testing
2020-06-16 16:20:58 +00:00
tgschultz
7f24860737 Code cleanup, documentation added, read*Mem functions now take *[]const u8 2020-06-16 16:20:58 +00:00
tgschultz
8978fe94cf Overhauled leb128:
handles integers < 8 bits
    incorrect overflow bugs fixed
    simplified *mem implementations
    added wrte* functions
    added thurough write/read testing
2020-06-16 16:20:58 +00:00
Andrew Kelley
f595545c10 Merge pull request #5422 from pixelherodev/error_tests
[Stage2/Testing] ZIR tests for expected errors
2020-06-16 03:50:56 -04:00
Noam Preil
a99e61ebaa Stage2/Testing: Code cleanup 2020-06-15 21:47:42 -04:00
Noam Preil
afec3e72f4 Stage2/Testing: Enable another test 2020-06-15 20:42:22 -04:00
Noam Preil
7d1c9a69cc Stage2/Testing: Remove dead code 2020-06-15 20:33:43 -04:00
Noam Preil
adb21f1caf Stage2/Testing: Add error tests to ZIRCase 2020-06-15 20:33:43 -04:00
Noam Preil
7ee0462f5f Stage2/Testing: Fix transformation tests 2020-06-15 20:33:39 -04:00
Noam Preil
1e5945d0a9 Stage2/Testing: remove ZIRTransformCase 2020-06-15 20:33:39 -04:00
Noam Preil
71dca252a5 Stage2/Testing: Rename stage -> update 2020-06-15 20:33:32 -04:00
Noam Preil
b6bd51ed69 Stage2/Testing: Move Transformation case to ZIRCase 2020-06-15 20:33:25 -04:00
Noam Preil
e77fc7fe7e Stage2/Testing: Fix error specification 2020-06-15 20:33:17 -04:00
Noam Preil
6dce317fe3 Stage2/Testing: Fix error tests 2020-06-15 20:33:07 -04:00
Noam Preil
d4fd7c6a01 Stage2/Testing: Staged test harness draft design 2020-06-15 20:32:54 -04:00
DixiE
68fe3e116d Update Stack Trace For start.zig Changes 2020-06-15 23:33:58 +01:00
Noam Preil
2ed07a36f8 [Stage2/Testing] Attempt to call nakedcc function 2020-06-15 17:52:21 -04:00
Noam Preil
bf8b3a4394 [Stage2/Testing] Handle decl and export errors 2020-06-15 17:51:43 -04:00
Noam Preil
68cc068a3a [Stage2/Testing] Make API more friendly 2020-06-15 17:51:43 -04:00
Noam Preil
bebc1f49cf [Stage2/Testing] Add (failing) test 2020-06-15 17:51:43 -04:00
Noam Preil
2d1d012f11 [Stage2/Testing] Reduce test 2020-06-15 17:51:43 -04:00
Noam Preil
e030414c16 [Stage2/Testing] Always finish case, note all errs 2020-06-15 17:51:43 -04:00
Noam Preil
f2399db3ef [Stage2/Testing] Don't rely on update erroring 2020-06-15 17:51:42 -04:00
Noam Preil
67414be86b [Stage2/Testing] Print name of failed test 2020-06-15 17:51:42 -04:00
Noam Preil
c92816fbef [Stage2/Testing] ZIR tests for expected errors 2020-06-15 17:51:29 -04:00
Anthony Arian
5e48ed4a8d Implement WinMain Callers that Pass Valid Params 2020-06-15 22:46:16 +01:00
Andrew Kelley
2bb3e1aff4 stage1: implement type coercion of anon struct literal to struct
closes #3672
2020-06-15 16:52:18 -04:00
Alexandros Naskos
2c8a3aaf85 Use _wfopen instead of fopen on windows 2020-06-15 22:21:01 +03:00
Alexandros Naskos
242246f793 UTF16 create process, utf8->utf16 fix 2020-06-15 21:51:53 +03:00
Alexandros Naskos
c34bdff4bb Use more wide functions on windows 2020-06-15 18:38:41 +03:00
daurnimator
af592f0ddd std: remove std.debug.getStderrStream
Rather than migrate to new 'writer' interface, just remove it
2020-06-15 23:51:25 +10:00
daurnimator
ce30357532 std: clean up debug stderr variables
- stderr_file_writer was unused
  - stderr_stream was a pointer to a stream, rather than a stream
  - other functions assumed that getStderrStream has already been called
2020-06-15 23:48:33 +10:00
Alexandros Naskos
3b0b56b81a Switched more Windows FS calls to their wide versions 2020-06-15 16:15:10 +03:00
Alexandros Naskos
037c72fe67 Convert paths to UTF-16 before calling CreateDirectory on windows 2020-06-15 15:52:59 +03:00
Vexu
e7207bc267 add workaround for #5599 2020-06-14 20:13:02 +03:00
Carter Sande
09cded209d Add strict_align to pre-v6 ARM targets
This matches GCC's and Clang's default behavior for these targets.
2020-06-12 13:43:12 -04:00
Andrew Kelley
866651a5a3 Merge pull request #5589 from kubkon/preopens-example
Add doc example for extracting WASI preopens
2020-06-12 13:40:30 -04:00
Alexandros Naskos
1bc92b1fde Fix formatting of floating point values with the B and Bi specifiers 2020-06-12 13:38:12 -04:00
Cassidy Dingenskirchen
57f1ed5325 Fix a few std.sort.sort invocations 2020-06-12 13:33:31 -04:00
Veikka Tuominen
7d8fd45267 Merge pull request #5595 from ifreund/doc-arraylist-fix
docs: fix mention of deprecated ArrayList.span()
2020-06-12 19:10:47 +03:00
Isaac Freund
a254297953 docs: fix mention of deprecated ArrayList.span() 2020-06-12 17:58:43 +02:00
Jakub Konka
200f9ea6fb Add unit test for std.fs.wasi.PreopenList 2020-06-11 23:00:02 +02:00
Jakub Konka
c7721bb368 Add custom format method for Preopen struct 2020-06-11 22:31:08 +02:00
Jakub Konka
e4a8598ddd Add doc example for extracting WASI preopens 2020-06-11 22:30:02 +02:00
Jonathan Marler
a282ac7a91 Support Reader for InStream 2020-06-09 13:36:17 -04:00
Andrew Kelley
4302f276ed Merge branch 'kubkon-wasm-instrinsics'
closes #5507
2020-06-09 00:22:43 -04:00
Jakub Konka
42c95a64d6 Update langref.html.in 2020-06-09 00:22:34 -04:00
Jakub Konka
660eef9a43 Document the builtins 2020-06-09 00:22:34 -04:00
Jakub Konka
52b97eeef1 Return u32 in @wasmMemorySize instead of i32 2020-06-09 00:22:34 -04:00
Jakub Konka
057d97c093 Return should be i32 due to error signaling in memory.grow
Also, fix tests.
2020-06-09 00:22:34 -04:00
Jakub Konka
3f0a3cea6e Fix builtins to return and accept u32 instead of i32 2020-06-09 00:22:34 -04:00
Jakub Konka
8ffa8ed9a8 Expose full llvm intrinsic 2020-06-09 00:22:34 -04:00
Jakub Konka
73a3bfd1dd Add basic tests for the new builtins 2020-06-09 00:22:34 -04:00
Jakub Konka
146be2a8cb Use builtins in std.heap.WasmAllocator 2020-06-09 00:22:17 -04:00
Jakub Konka
601e831f1d Add builtin for llvm.wasm.memory.grow.i32 intrinsic
This will allow the developer to request additional memory pages
from the runtime to be allocated for the Wasm app. Typical usage:

```zig
var wasm_pages = @wasmMemorySize();
@wasmMemoryGrow(1);
@import("std").debug.assert((wasm_pages + 1) == @wasmMemorySize());
```
2020-06-09 00:22:17 -04:00
Jakub Konka
ce3f0077cf Add builtin for llvm.wasm.memory.size.i32 instrinsic
This will allow the developer to poll the runtime for currently
allocated memory in the number of Wasm pages. Typical usage:

```zig
var wasm_pages = @wasmMemorySize();
@import("std").debug.assert(wasm_pages > 0);
```
2020-06-09 00:22:17 -04:00
Jonathan Marler
12051b02f1 fix memory errors 2020-06-09 00:17:22 -04:00
Andrew Kelley
9ee98f103b Merge pull request #5539 from mikdusan/issue5474
stage1: fix constness in some corner cases
2020-06-09 00:12:57 -04:00
Jonathan Marler
7481582774 support Writer instead of OutStream
Start implementing https://github.com/ziglang/zig/issues/4917 which is to rename instream/outstream to reader/writer.  This first change allows code to use Writer/writer instead of OutStream/outStream, but still maintains the old outstream names with "Deprecated" comments.
2020-06-08 22:59:28 -04:00
Michael Dusan
f5b584cc13 Merge pull request #5567 from mikdusan/qemu
ci linux: bump qemu-5.0.0-49ee115552
2020-06-08 22:12:14 -04:00
Andrew Kelley
d2278f2156 Merge pull request #5566 from ziglang/stage2-garbage-collect-decls
Stage2 garbage collect decls
2020-06-08 18:29:12 -04:00
Jakub Konka
0ff5d7b24e Add option for overriding the stack size
This commit adds a `--stack [size]` link-time option to zig compiler
allowing the user to override the default stack size set for the
specified executable/library format. This is currently limited to
ELF, COFF and Wasm however (i.e., Mach-O is excluded).
2020-06-08 17:44:06 -04:00
Jakub Konka
cde7c75676 Increase default Wasm stack to 1MB
This commit increases the default Wasm stack to 1MB from the default
of 1 Wasm page which equal 64KB. This seems like a reasonable default
size while at the same time not overly large. Also, Rust lang seems
to be favouring this default as well: [rust-lang#50083].

[rust-lang#50083]: https://github.com/rust-lang/rust/pull/50083
2020-06-08 17:29:14 -04:00
xackus
0d40cb6255 stage1: fix crash on slice byte reinterpretation 2020-06-08 17:19:06 -04:00
Andrew Kelley
05d284c842 update sort callsite to new API 2020-06-08 16:33:35 -04:00
Michael Dusan
c2f547f91f ci linux: bump qemu-5.0.0-49ee115552
update qemu to upstream with mremap patch
2020-06-08 16:20:39 -04:00
Andrew Kelley
47090d234e stage2: add passing test for compile error in unreferenced cycle 2020-06-08 15:16:40 -04:00
Andrew Kelley
9ea4965ceb self-hosted: remove deleted Decls from failed_decls 2020-06-08 15:16:40 -04:00
Andrew Kelley
91930a4ff0 stage2: fix not re-loading source file for updates after errors 2020-06-08 15:16:40 -04:00
Andrew Kelley
cf654b52d6 stage2: -femit-zir respects decl names and supports cycles 2020-06-08 15:16:40 -04:00
Andrew Kelley
d4d954abd2 std.sort: give comparator functions a context parameter 2020-06-08 15:16:40 -04:00
Noam Preil
c405844b0a [Stage2/x86] Fix 8-bit register order 2020-06-08 02:28:39 -04:00
Andrew Kelley
37695ed81e Merge pull request #5556 from iansimonson/try_other_addresses
tcpConnectToHost try all addresses in AddressList
2020-06-07 13:53:12 -04:00
Ian Simonson
a6d1ef64d7 tcpConnectToHost try all addresses in AddressList
The AddressList returned can contain more than one item
e.g. the ipv4 and ipv6 addresses for a given hostname.
Previously if a server had multiple addresses but
was not listening on one of them Zig would give up
immediately.

Now on std.os.ConnectError.ConnectionRefused Zig will
try the next address in the list. Zig still gives up on
all other errors as they are related to the system and
system resources rather than whether the remote server
is listening on a particular address.
2020-06-07 22:39:35 +10:00
Ian Simonson
983f93c840 Test case for tcpConnectToHost fix 2020-06-07 22:39:35 +10:00
Veikka Tuominen
499df9680c Merge pull request #5531 from Vexu/translate-c
Translate-c don't crash on complex switches
2020-06-05 10:41:56 +03:00
Michael Dusan
c0c9d11d8c stage1: fix constness in some corner cases
- for one-possible-value types, ir_analyze_struct_field_ptr()
  no longer hardcodes const/volatile

- when slicing arrays, ir_analyze_instruction_slice()
  no longer consults ConstValSpecialStatic

closes #5474
2020-06-05 00:49:57 -04:00
Ryan Liptak
f839d34baa std.os.windows.OpenFile: Handle FILE_IS_A_DIRECTORY status
Fixes #5533
2020-06-04 22:53:23 -04:00
Ryan Liptak
95a5f6bf2d Windows: Handle ERROR_DIRECTORY in std.fs.deleteDirAbsolute when called on a file path
ERROR_DIRECTORY (267) is returned from kernel32.RemoveDirectoryW if the path is not a directory. Note also that os.DirectDirError already includes NotDir

Before: error.Unexpected: GetLastError(267): The directory name is invalid.
After: error: NotDir
2020-06-04 22:52:53 -04:00
Ryan Liptak
f7b6957fb4 Windows: Fix std.fs.Dir.deleteDir() deleting files
Would previously delete files, now correctly returns error.NotDir. Fixes #5536
2020-06-04 22:51:58 -04:00
Vexu
c27a8bd6be translate-c: don't crash on complex switches 2020-06-04 14:22:27 +03:00
Vexu
fd067fbe8b add workaround for #5525 2020-06-04 13:11:23 +03:00
Jesse Rudolph
3fba076f92 demonstrate start + len > new_items.len 2020-06-03 06:29:50 -05:00
Jesse Rudolph
c0a0193c0a add replaceRange() function to ArrayList
generalizes functionality of ArrayList.insertSlice() to overwrite
a range of elements in the list and to grow or shrink the list as needed
to accommodate size difference of the replacing slice and the range
of existing elements.
2020-06-02 17:00:01 -05:00
Andrew Kelley
6524a64bda stage2: fix referencing decls which appear later in the file 2020-06-02 17:43:51 -04:00
Andrew Kelley
14d235dd6e Merge branch 'lun-4-resolve-ip6'
closes #4864
2020-06-02 15:31:14 -04:00
Andrew Kelley
7fd937fef4 cleanups
* improve docs
 * add TODO comments for things that don't have open issues
 * remove redundant namespacing of struct fields
 * guard against ioctl returning EINTR
 * remove the general std.os.ioctl function in favor of the specific
   ioctl_SIOCGIFINDEX function. This allows us to have a more precise
   error set, and more type-safe API.
2020-06-02 15:28:46 -04:00
Luna
0d091dc923 Replace os.linux to os.system 2020-06-02 14:56:19 -04:00
Luna
6623efd7d4 Change ioctl's request type to i32 2020-06-02 14:56:19 -04:00
Luna
6d3d1152ea Add declaration for libc ioctl 2020-06-02 14:56:19 -04:00
Luna
7c71054286 Replace syscall3 to os.ioctl 2020-06-02 14:56:19 -04:00
Luna
09c01ea7b9 Use resolveIp when looking up addresses on linux 2020-06-02 14:56:19 -04:00
Luna
c8468bed42 Add std.os.ioctl 2020-06-02 14:56:19 -04:00
Luna
c7b790ded6 net.test: only call resolveIp6 when os is linux 2020-06-02 14:56:06 -04:00
Luna
15efe03d1f Add tests for overflow 2020-06-02 14:56:06 -04:00
Luna
b72c862725 Use IFNAMESIZE for scope id value 2020-06-02 14:56:06 -04:00
Luna
aebf28eba3 Make ifru fields sentinel-terminated 2020-06-02 14:56:06 -04:00
Luna
c60daa255f Replace C types in declarations 2020-06-02 14:56:06 -04:00
Luna
2fa9cf51ff Plug resolveIp6 into IPv6 tests 2020-06-02 14:56:06 -04:00
Luna
64e55a74de Add validation for scope ids 2020-06-02 14:56:06 -04:00
Luna
10ea2db5cb Replace C shorts by integer types 2020-06-02 14:56:06 -04:00
Luna
11a06d4341 Remove warn() calls 2020-06-02 14:56:06 -04:00
Luna
cb649b769c Fix ifreq definition 2020-06-02 14:56:06 -04:00
Luna
c50ac9a764 Change Unsupported to InterfaceNotFound 2020-06-02 14:56:06 -04:00
Luna
38109d48a3 Make interface name null-terminated before syscall 2020-06-02 14:56:06 -04:00
Luna
5919831529 Stop using mem.len on array 2020-06-02 14:56:06 -04:00
Luna
901aab8761 Add ioctl errors 2020-06-02 14:56:06 -04:00
Luna
2c641c93da Only resolve scope id when needed 2020-06-02 14:56:06 -04:00
Luna
f02f4c0880 Fix typo and add if_nametoindex 2020-06-02 14:56:06 -04:00
Luna
9c200035f3 Add some interface structs to linux bits 2020-06-02 14:56:06 -04:00
Luna
b816303122 Add basics of resolveIp6
Instead of streaming the scope id digits to an u32, we keep a [32]u8 in
the stack and fill it up with the characters we get for scope id.
2020-06-02 14:56:05 -04:00
Andrew Kelley
bae0c9b554 std.HashMap: allow ensureCapacity with a zero parameter 2020-06-02 14:41:45 -04:00
Veikka Tuominen
40a1cfed53 Merge pull request #5510 from jessrud/arraylist-fix
pass allocator to self.resize() in appendNTimes()
2020-06-02 18:13:55 +03:00
Jesse Rudolph
100aa6fbaf pass allocator to self.resize() in appendNTimes() 2020-06-02 09:59:13 -05:00
Alexandros Naskos
aa1a727284 Allow carriare return in comments 2020-06-02 00:56:05 -04:00
Andrew Kelley
c6764fd254 Merge pull request #5475 from marler8997/windowsDns
support name resolution on windows
2020-06-01 15:33:05 -04:00
Andrew Kelley
8f4bc77260 Merge pull request #5449 from data-man/more_traits
Add more traits
2020-06-01 14:50:01 -04:00
Andrew Kelley
f9b220ec2c Merge branch 'brodeuralexis-zero-init-helper'
closes #5472
2020-06-01 14:47:55 -04:00
Andrew Kelley
109c0b9d96 rename std.mem.defaultInit to std.mem.zeroInit 2020-06-01 14:47:18 -04:00
Alexis Brodeur
c0e5eca6f2 Add initialization helper
When using C libraries, C99 designator list initialization is often
times used to initialize data structure.

While `std.mem.zeroes` and manually assigning to each field can
achieve the same result, it is much more verbose then the equivalent
C code:

```zig
usingnamespace @cImport({
    @cInclude("sokol_app.h");
});

// Using `std.mem.zeroes` and manual assignment.
var app_desc = std.mem.zeroes(sapp_desc);
app_desc.init_cb = init;
app_desc.frame_cb = frame;
app_desc.cleanup_cb = cleanup;
app_desc.width = 400;
app_desc.height = 300;
app_desc.window_name = "no default init";

// Using `std.mem.defaultInit`.
var app_desc = std.mem.defaultInit(sapp_desc, .{
    .init_cb = init,
    .frame_cb = frame,
    .cleanup_cb = cleanup,
    .width = 400,
    .height = 300,
    .window_name = "default init"
});
```

The `std.mem.defaultInit` aims to solve this problem by zero
initializing all fields of the given struct to their zero, or default
value if any.  Each field mentionned in the `init` variable is then
assigned to the corresponding field in the struct.

If a field is a struct, and an initializer for it is present, it is
recursively initialized.
2020-06-01 14:45:35 -04:00
Sebastian
937dcad0b3 fixed timestamp() 2020-06-01 14:43:13 -04:00
Alexandros Naskos
215a0d61ab Fix evented builds on windows with runtime safety on 2020-06-01 14:22:45 -04:00
Veikka Tuominen
078e4afdaf Merge pull request #5500 from Vexu/fix
Fix std.zig rejecting literal tabs in comments
2020-06-01 17:24:30 +03:00
Veikka Tuominen
eb687810cf Merge pull request #4976 from xackus/std-lib-docs
std lib docs: fix null and int values
2020-06-01 14:50:05 +03:00
Veikka Tuominen
8c5c860b00 Merge pull request #5443 from data-man/mem_len_vectors
Support vectors in mem.len
2020-06-01 14:44:38 +03:00
Vexu
a47257d9b0 fix std.zig rejecting literal tabs in comments 2020-06-01 14:37:36 +03:00
Jonathan Marler
0d32f4acf7 enable dns test on windows 2020-05-31 11:58:50 -06:00
Veikka Tuominen
f5eb31a55a Merge pull request #5491 from xackus/fix_5487
stage1: fix unresolved inferred error sets
2020-05-31 20:48:04 +03:00
daurnimator
f5167f73e8 deps/SoftFloat-3e/: commit with LF line endings
`git add --renormalize .`

For text files, git expects that all files are commited with LF line endings,
it then (optionally) swaps to CRLF on checkout depending on .gitattributes and
git config.
2020-05-31 12:18:31 -04:00
Jonathan Marler
58fb5b29b6 more windows network fixes
* support posix SOCK_NONBLOCK and SOCK_CLOEXEC flags on windows
* fix bugs in os.socket and os.connect to return at the correct place
2020-05-31 10:07:51 -06:00
Veikka Tuominen
899d79f8f0 Merge pull request #5478 from vrischmann/fix-iouring
linux: fix IOSQE_BIT decl and io_uring_sqe flags
2020-05-31 16:59:04 +03:00
Veikka Tuominen
30b2bc86b9 Merge pull request #5477 from alexnask/patch-1
Fix WSARecvFrom signature
2020-05-31 16:49:08 +03:00
Veikka Tuominen
21544267ee Merge pull request #5481 from kubkon/typo-packedintarray
Fix typo in PackedIntArray tests
2020-05-31 16:48:19 +03:00
xackus
250dd9ac21 stage1: fix unresolved inferred error sets 2020-05-31 15:04:34 +02:00
Veikka Tuominen
557d75d58a Merge pull request #5480 from Vexu/fix
Fix zig fmt out of bounds on empty file
2020-05-31 13:50:03 +03:00
Jakub Konka
13c405127d Fix typo in PackedIntArray tests
Both `PackedIntArray` and `PackedIntSlice` tests defined `max_bits`
but didn't use it in the predicate in the inline while loop.
2020-05-30 23:17:55 +02:00
Vexu
010c58e303 fix zig fmt out of bounds on empty file 2020-05-30 23:07:51 +03:00
Jonathan Marler
2bae91e769 convert getaddrinfo rc to enum before switching on it 2020-05-30 09:56:52 -06:00
Vincent Rischmann
636d3ba780 linux: fix IOSQE_BIT decl and io_uring_sqe flags 2020-05-30 16:05:46 +02:00
Alexandros Naskos
dbdacb0938 Fix WSARecvFrom signature
The lpFromLen should be a pointer.
2020-05-30 16:46:32 +03:00
Jonathan Marler
2eaab1e65e more windows network support, including dns 2020-05-29 22:38:48 -06:00
foobles
51682717d7 Support equality comparison for optional to non-optional (?T ==/!= T)
extracted function ir_try_evaluate_bin_op_const
extracted type_is_self_comparable function
renamed ir_try_evaluate_bin_op_const to ir_try_evaluate_bin_op_cmp_const
implemented analysis of ?T == T
added ir_set_cursor_at_end_and_append_basic_block_gen
use build_br_gen and ir_set_cursor_at_end_and_append_block_gen
added ir_append_basic_block_gen
removed include of all_types in ir.cpp
extracted compile-time and runtime evaluation of cmp_optional_non_optional to separate functions

closes #5390
closes #1332
2020-05-29 18:46:09 -04:00
Andrew Kelley
f107d654e0 Merge branch 'gereeter-reduced-path-max'
closes #4837
2020-05-29 18:41:40 -04:00
Andrew Kelley
89a97a7a27 cleanups 2020-05-29 18:30:09 -04:00
Jonathan S
c209da1589 Document the failure to improve selfExe{,Dir}PathAlloc 2020-05-29 18:27:39 -04:00
Jonathan S
0674b51453 In getCwdAlloc, geometrically allocate larger buffers to find an appropriate size. 2020-05-29 18:27:39 -04:00
Jonathan S
ab3931fa95 Prefer Files to paths in std.debug. Additionally [breaking] add a flags parameter to openSelfExe and stop exporting openElfDebugInfo.
This should save a call to readlink in openSelfDebugInfo and support executables in overlong paths on Linux.
2020-05-29 18:27:39 -04:00
Jonathan S
631633b252 Document and reduce usage of MAX_PATH_BYTES, lifting arbitrary buffer size requirements 2020-05-29 18:23:06 -04:00
Veikka Tuominen
4c8b937fb0 Merge pull request #5184 from alexnask/typeof_extern_call
Extern functions are now evaluated to undefined values at comptime in TypeOf calls.
2020-05-30 01:11:22 +03:00
Andrew Kelley
65c3833ec2 Merge pull request #5388 from kubkon/wasi-args-iter
Add ArgIteratorWasi and integrate it with ArgIterator
2020-05-29 15:55:14 -04:00
Noam Preil
e9f344dcd4 Add include dirs to translate-c (close #5098) 2020-05-29 13:39:16 -04:00
Noam Preil
3b4e29f1ad [CI] Use ninja on Azura and Drone 2020-05-29 13:34:15 -04:00
Noam Preil
834e8ac2dc [Stage2/Codegen] Extract REX 2020-05-29 13:33:09 -04:00
Jakub Konka
6e347e6180 Fix args iterator test 2020-05-29 17:12:19 +02:00
Jakub Konka
6f48842ddb Make ArgIterator.init() a compile error in WASI
Given that the previous design would require the use of a default
allocator to have `ArgIterator.init()` work in WASI, and since in
Zig we're trying to avoid default allocators, I've changed the design
slightly in that now `init()` is a compile error in WASI, and instead
in its message it points to `initWithAllocator(*mem.Allocator)`.
The latter by virtue of requiring an allocator as an argument can
safely be used in WASI as well as on other OSes (where the allocator
argument is simply unused). When using `initWithAllocator` it is then
natural to remember to call `deinit()` after being done with the
iterator. Also, to make use of this, I've also added `argsWithAllocator`
function which is equivalent to `args` minus the requirement of supplying
an allocator and being fallible.

Finally, I've also modified the WASI only test `process.ArgWasiIterator`
to test all OSes.
2020-05-29 10:48:03 +02:00
Jakub Konka
f1a4e1a70f Add ArgIteratorWasi and integrate it with ArgIterator
This commit pulls WASI specific implementation of args extraction
from the runtime from `process.argsAlloc` and `process.argsFree`
into a new iterator struct `process.ArgIteratorWasi`. It also
integrates the struct with platform-independent `process.ArgIterator`.
2020-05-29 10:48:03 +02:00
data-man
dc4fea983d Use tuples in multiTrait 2020-05-28 23:10:44 -04:00
Dmitry Atamanov
0328537ca6 Support stringify for vectors (#5441)
* use array's pointer
2020-05-28 23:10:16 -04:00
Walter Mays
8630ae7523 Remove reliance on hashing algorithm for iterator reset test. 2020-05-28 23:09:21 -04:00
Andrew Kelley
1e0de896b8 Merge pull request #5452 from squeek502/comptime-string-map
Add std.ComptimeStringMap based on the tokenizer optimization in #5442
2020-05-28 23:06:40 -04:00
Timon Kruiper
6e89692d81 C ABI: Add C support for passing structs of floats to an extern function
Currently this does not handle returning these structs yet.

Related: #1481
2020-05-28 22:56:33 -04:00
Andrew Kelley
34101127c6 Merge pull request #5463 from kubkon/link-issue-wasm-vector
Link issue to the failing test case: miscompiled Vector in wasm
2020-05-28 22:55:07 -04:00
Andrew Kelley
dadc4327e1 Merge branch 'stage2-vaddr-alloc' 2020-05-28 22:45:59 -04:00
Andrew Kelley
5d77fede89 remove debug log statements 2020-05-28 22:43:16 -04:00
Andrew Kelley
0bd89979fd stage2: handle deletions and better dependency resolution
* Deleted decls are deleted; unused decls are also detected as deleted.
   Cycles are not yet detected.
 * Re-analysis is smarter and will not cause a re-analysis of dependants
   when only a function body is changed.
2020-05-28 22:42:13 -04:00
Jakub Konka
4f24ab9cfc Fix skipping condition (skip when wasm32) 2020-05-29 00:06:26 +02:00
Jakub Konka
3dbe376c77 Link issue to the failing test case targeting wasm 2020-05-28 23:32:17 +02:00
Andrew Kelley
3eed7a4dea stage2: first pass at recursive dependency resolution 2020-05-28 12:19:00 -04:00
data-man
c91786caf3 zig fmt 2020-05-28 16:41:15 +05:00
data-man
f9bdf325d3 Added tests with tuple 2020-05-28 16:39:00 +05:00
Andrew Kelley
c7ca1fe6f7 self-hosted: introduce a virtual address allocation scheme
The binary file abstraction changed its struct named "Decl" to
"TextBlock" and it now represents an allocated slice of memory in
the .text section. It has two new fields: prev and next, making it
a linked list node. This allows a TextBlock to find its neighbors.

The ElfFile struct now has free_list and last_text_block fields.
Doc comments for free_list are reproduced here:

A list of text blocks that have surplus capacity. This list can have false
positives, as functions grow and shrink over time, only sometimes being added
or removed from the freelist.

A text block has surplus capacity when its overcapacity value is greater than
minimum_text_block_size * alloc_num / alloc_den. That is, when it has so
much extra capacity, that we could fit a small new symbol in it, itself with
ideal_capacity or more.

Ideal capacity is defined by size * alloc_num / alloc_den.

Overcapacity is measured by actual_capacity - ideal_capacity. Note that
overcapacity can be negative. A simple way to have negative overcapacity is to
allocate a fresh text block, which will have ideal capacity, and then grow it
by 1 byte. It will then have -1 overcapacity.

The last_text_block keeps track of the end of the .text section.

Allocation, freeing, and resizing decls are all now more sophisticated,
and participate in the virtual address allocation scheme. There is no
longer the possibility for virtual address collisions.
2020-05-27 15:23:27 -04:00
Veikka Tuominen
2ae9e06363 Merge pull request #5448 from Vexu/translate-c
Translate-c use correct scope in for loop condition
2020-05-27 17:00:31 +03:00
Vexu
cd5b7b9e1d translate-c: use correct scope in for loop condition 2020-05-27 14:14:17 +03:00
Ryan Liptak
3cac0a5614 Not sure how a tab snuck in there 2020-05-26 23:26:19 -07:00
Ryan Liptak
b683498ae8 Use ComptimeStringMap in std.meta.stringToEnum when feasible 2020-05-26 23:10:13 -07:00
Ryan Liptak
dfafafac7b std.ComptimeStringMap: Add support for void value type (i.e. a set) 2020-05-26 23:10:12 -07:00
Ryan Liptak
62cfc68d2f Use std.ComptimeStringMap in the C tokenizer 2020-05-26 23:10:08 -07:00
Ryan Liptak
a9dd79d293 Use std.ComptimeStringMap in zig's tokenizer
Should have no performance change, the implementation was just made generic/re-usable
2020-05-26 21:36:58 -07:00
Ryan Liptak
0865e5d360 Add std.ComptimeStringMap 2020-05-26 21:34:55 -07:00
Jakub Konka
e61e8c94be Reenable zig parser tests disabled targeting Wasm
I'm not sure why I disabled them when landing extended Wasm/WASI
support, but they pass the parser tests just fine now, so I'm gonna
go ahead and re-enable them.
2020-05-26 21:01:54 -04:00
data-man
78a1f6976d Add more traits 2020-05-27 04:00:38 +05:00
Andrew Kelley
ba41a9d5d7 different strategy for tokenizing keywords
throughput: 279 MiB/s => 347 MiB/s
2020-05-26 18:59:49 -04:00
data-man
b6e1670d2b Use ccache (optionally) 2020-05-26 16:04:40 -04:00
Walter Mays
e1186c88ea Remove unimplemented init call from ArrayListUnmanaged. 2020-05-26 15:59:56 -04:00
Andrew Kelley
ef42ef9ce8 Merge pull request #5440 from kubkon/align-fn-error-wasm
Make align expr on fns a compile error in Wasm
2020-05-26 15:49:19 -04:00
data-man
49dd2cbd9a Support vectors in mem.len 2020-05-27 00:00:19 +05:00
Dmitry Atamanov
dd62f63c04 fmt padding correction (#5403)
* Make .Left as default
2020-05-26 20:53:51 +03:00
Walter Mays
19a04d8ebd Add writeToSlice method to SegmentedList. (#5405) 2020-05-26 13:04:25 -04:00
foobles
cb6bc5bdb5 Add caller location tracking for asserts (ir_assert, src_assert, ir_assert_gen) (#5393) 2020-05-26 12:55:31 -04:00
Andrew Kelley
57b78fff73 Merge branch 'daurnimator-pretty-print-non-exhaustive-enums'
closes #4693
2020-05-26 12:15:37 -04:00
Andrew Kelley
62fefe8648 std.fmt: non-exhaustive enums: avoid the loop when it's not necessary 2020-05-26 12:15:08 -04:00
daurnimator
5cdeac3b0e std: in fmt, use tag names of non-exhaustive enums when available 2020-05-26 12:00:33 -04:00
daurnimator
292d515e91 std: allow specifiying enums to be formatted as numbers 2020-05-26 12:00:33 -04:00
Jakub Konka
08b0cae777 Add matching compile error test 2020-05-26 18:00:08 +02:00
Jakub Konka
015c899297 Make align expr on fns a compile error in Wasm
In Wasm, specifying alignment of function pointers makes little sense
since function pointers are in fact indices to a Wasm table, therefore
any alignment check on those is invalid. This can cause unexpected
behaviour when checking expected alignment with `@ptrToInt(fn_ptr)`
or similar. This commit proposes to make `align` expressions a
compile error when compiled to Wasm architecture.

Some references:
[1] [Mozilla: WebAssembly Tables](https://developer.mozilla.org/en-US/docs/WebAssembly/Understanding_the_text_format#WebAssembly_tables)
[2] [Sunfishcode's Wasm Ref Manual](https://github.com/sunfishcode/wasm-reference-manual/blob/master/WebAssembly.md#indirect-call)
2020-05-26 17:17:32 +02:00
data-man
d10e407977 More vector support in std.meta 2020-05-26 10:56:29 -04:00
Alexandros Naskos
d88db4d34b Changed test name to reflect it only fixes #4328 2020-05-26 12:36:02 +03:00
Veikka Tuominen
4b8077ea8e Merge pull request #5383 from Vexu/fix
Fix missing compile error on while/for missing block
2020-05-26 11:13:09 +03:00
Andrew Kelley
49f3defe5b Merge branch 'leroycep-feature-cache-hash-zig'
closes #4635
2020-05-25 21:04:10 -04:00
Andrew Kelley
7c8d0cc678 fix pwrite on 32-bit linux 2020-05-25 19:59:39 -04:00
Andrew Kelley
a83aab5209 fix std lib tests for WASI 2020-05-25 19:46:28 -04:00
Andrew Kelley
cda102be02 improvements to self-hosted cache hash system
* change miscellaneous things to more idiomatic zig style
 * change the digest length to 24 bytes instead of 48. This is
   still 70  more bits than UUIDs. For an analysis of probability of
   collisions, see:
   https://en.wikipedia.org/wiki/Universally_unique_identifier#Collisions
 * fix the API having the possibility of mismatched allocators
 * fix some error paths to behave properly
 * modify the guarantees about when file contents are loaded for input files
 * pwrite instead of seek + write
 * implement isProblematicTimestamp
 * fix tests with regards to a working isProblematicTimestamp function.
   this requires sleeping until the current timestamp becomes
   unproblematic.
 * introduce std.fs.File.INode, a cross platform type abstraction
   so that cache hash implementation does not need to reach into std.os.
2020-05-25 19:29:03 -04:00
Vexu
e07b467c7c fix missing compile error on while/for missing block 2020-05-25 23:25:06 +03:00
Andrew Kelley
69ff89fd12 stage2 parser: heuristics to pre-allocate token arrays
throughput: 72.2 MiB/s => 75.3 MiB/s

I also tried the idea from the deleted comment in this commit and it
made the throughput worse.
2020-05-25 15:12:23 -04:00
Andrew Kelley
6d5ec184ab stage2 parser: heuristics to pre-allocate token arrays
throughput: 72.2 MiB/s => 75.3 MiB/s
2020-05-25 15:02:02 -04:00
LeRoyce Pearson
72716ecc3a Fix improper initialization of CacheHashFiles 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
c3c332c9ec Add max_file_size argument 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
5a1c6a3627 Set manifest's maximum size to Andrew's recommendation 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
be69e8e871 Remove non-null assertion in CacheHash.release()
People using the API as intended would never trigger this assertion
anyway, but if someone has a non standard use case, I see no reason
to make the program panic.
2020-05-25 13:48:43 -04:00
LeRoyce Pearson
e6a37ed941 Change null pointer test to addFilePost test 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
42007307be Make if statement more idiomatic 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
2c59f95e87 Don't use iterate when opening manifest directory 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
1ffff1bb18 Add test case for fix in previous commit 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
0fa89dc51d Fix read from null pointer in CacheHash.hit
It occured when the manifest file was manually edited to include an extra
file. Now it will simply copy the file name in the manifest file
2020-05-25 13:48:43 -04:00
LeRoyce Pearson
f13c67bcfe Return an index from CacheHash.addFile
This makes it possible for the user to retrieve the contents of the
file without running into data races.
2020-05-25 13:48:43 -04:00
LeRoyce Pearson
4d62d97076 Update code using deprecated ArrayList APIs 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
b429f4607c Make addFilePost* functions' documentation more clear 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
e7657f2938 Make CacheHash.release return an error
If a user doesn't care that the manifest failed to be written, they can
simply ignore it. The program will still work; that particular cache
item will simply not be cached.
2020-05-25 13:48:43 -04:00
LeRoyce Pearson
967b9825a7 Add "no file inputs" test
It checks whether the cache will respond correctly to inputs that don't
initially depend on filesystem state. In that case, we have to check
for the existence of a manifest file, instead of relying on reading the
list of entries to tell us if the cache is invalid.
2020-05-25 13:48:43 -04:00
LeRoyce Pearson
4254d389d3 Add test checking file changes invalidate cache 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
b67a9f2281 Switch to using testing.expect* in tests 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
d457919ff5 Make CacheHash cleanup consistent (always call release)
Instead of releasing the manifest file when an error occurs, it is
only released when when `CacheHash.release` is called. This maps better
to what a zig user expects when they do `defer cache_hash.release()`.
2020-05-25 13:48:43 -04:00
LeRoyce Pearson
05edfe983c Add addFilePost and addFilePostFetch functions 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
af730c64bd Put base64 alphabet into a named constant 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
d770dae1b8 Add documentation to CacheHash API 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
67d6432d10 Check for problematic timestamps 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
73d2747084 Open file with exclusive lock 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
204aa7dc1a Remove unnecessary contents field from File
It was causing a segfault on `mipsel` architecture, not sure why other
architectures weren't affected.
2020-05-25 13:48:43 -04:00
LeRoyce Pearson
c88ece3679 Remove error union from CacheHash.final 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
dfb53beb52 Check if inode matches inode from manifest 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
7917f25b0a Update cache_hash to zig master 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
16c5499098 Remove up files created in test at end of test 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
fffd59e6c4 Remove file handle from CacheHash
A file handle is not the same thing as an inode index number.
Eventually the inode will be checked as well, but there needs to be
a way to get the inode in `std` first.
2020-05-25 13:48:43 -04:00
LeRoyce Pearson
21d7430696 Replace ArrayList in write_manifest with an array 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
061c1fd9ab Use readAllAlloc
Now that the memory leak mentioned in #4656 has been fixed.
2020-05-25 13:48:43 -04:00
LeRoyce Pearson
4f709d224a Make hash digest same size as in the c API 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
8e4b80522f Return base64 digest instead of using an out variable 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
e75a6e5144 Rename cache_file -> addFile 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
50cbf1f3aa Add slice and array support to add method 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
fde188aadc Make type specific add functions
Basically, move type specific code into their own functions instead
of making `add` a giant function responsible for everything.
2020-05-25 13:48:43 -04:00
LeRoyce Pearson
4173dbdce9 Rename cache functions to add 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
27bf1f781b Store fs.Dir instead of path to dir 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
55a3925ab7 Rename CacheHashFile -> File 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
c8062321b3 Use fs.File 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
86fe88bbcb Use std.fs.base64_encoder in std.cache_hash 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
8c8813a5cf Add filesystem base64 decoder 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
ce5b2286f1 Support caching bools; make caching values infallible 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
de341b8fb8 Fix memory leak in cache_hash 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
8a77c1c637 Add cache method; add support for caching integers 2020-05-25 13:48:43 -04:00
LeRoyce Pearson
3158dc424e Partially implement cache hash API in zig 2020-05-25 13:48:43 -04:00
data-man
0ecdbdb3cb Support comptime floats in std.fmt 2020-05-25 12:48:59 -04:00
Andrew Kelley
0fd77c2de3 Merge pull request #5431 from alexnask/build_step_ids
Added and id and a cast function to build steps
2020-05-25 11:24:15 -04:00
Alexandros Naskos
65d827183b Added custom build step id, made tests.zig steps use it 2020-05-25 11:36:12 +03:00
Alexandros Naskos
d268e0cf2e Added and id and a cast function to build steps 2020-05-25 11:20:31 +03:00
Andrew Kelley
3052fd84c8 fix regression in std.os.windows.fromSysTime 2020-05-25 00:37:47 -04:00
Andrew Kelley
c693c3ae50 Merge branch 'leroycep-feature-nano-timestamp'
closes #5237
2020-05-24 21:40:23 -04:00
Andrew Kelley
53d011fa1a (breaking) std.time fixups and API changes
Remove the constants that assume a base unit in favor of explicit
x_per_y constants.

nanosecond calendar timestamps now use i128 for the type. This affects
fs.File.Stat, std.time.nanoTimestamp, and fs.File.updateTimes.

calendar timestamps are now signed, because the value can be less than
the epoch (the user can set their computer time to whatever they wish).

implement std.os.clock_gettime for Windows when clock id is
CLOCK_CALENDAR.
2020-05-24 21:40:08 -04:00
LeRoyce Pearson
c6e7d0fcfd Use better names for darwin timestart 2020-05-24 21:40:08 -04:00
LeRoyce Pearson
b85a191398 Fix compile errors for MacOS 2020-05-24 21:40:08 -04:00
LeRoyce Pearson
2dfe798217 Use once to init _timestart in thread safe way 2020-05-24 21:40:08 -04:00
LeRoyce Pearson
7586ce0023 Implement a faster way to get nanoseconds on darwin 2020-05-24 21:40:08 -04:00
LeRoyce Pearson
bb46894115 Add std.time.nanoTimestamp function 2020-05-24 21:40:08 -04:00
Jethro Nederhof
4b1a846471 target: Implement running OS version detection for FreeBSD (#5416)
* target: Implement OS version detection for FreeBSD

Fixes #4582

* freebsd version: handle errors explicitly
2020-05-24 20:52:13 -04:00
Noam Preil
07472fb453 [Stage2/Codegen] Properly handle arch in genCall 2020-05-24 20:49:29 -04:00
data-man
db0c30446a Supports vectors in mem.zeroes 2020-05-24 20:48:29 -04:00
data-man
b13dd3cf61 Treat vectors as indexable 2020-05-24 20:44:17 -04:00
Andrew Kelley
dd05f2be80 run zig fmt on std lib 2020-05-24 10:04:09 -04:00
Andrew Kelley
1c0b7ddda8 fix regression in AST node iteration
the new iteration code caused an integer underflow for function
prototypes with no parameters. now fixed.
2020-05-24 10:03:26 -04:00
Andrew Kelley
2ff3995a70 Merge pull request #5378 from ziglang/speed-up-stage2-parsing
improve std.zig.parse performance using flat arrays for AST nodes and tokens
2020-05-24 09:44:08 -04:00
Andrew Kelley
8a3cd82b85 translate-c: fix a use-after-free bug 2020-05-23 23:15:58 -04:00
Andrew Kelley
882921b5dd Merge pull request #5415 from jethron/freebsd-bits
Freebsd bits
2020-05-23 20:54:09 -04:00
Andrew Kelley
2952604d5d update docgen to new ast API 2020-05-23 20:40:09 -04:00
Andrew Kelley
c432811d96 fix regression in compile errors 2020-05-23 20:27:09 -04:00
Andrew Kelley
f771545a7e revert std.zig.ast iterator changes back to master branch API 2020-05-23 20:14:38 -04:00
Jethro Nederhof
f83fd47b14 os/bits/freebsd audit 2020-05-24 10:08:43 +10:00
Jethro Nederhof
b504169fef FreeBSD: missing networking constants 2020-05-24 10:08:43 +10:00
Andrew Kelley
c78a2e2e8d translate-c: emit local typedefs 2020-05-23 19:59:26 -04:00
Andrew Kelley
395786fd50 translate-c: fix regression in param name mangling 2020-05-23 19:28:14 -04:00
Andrew Kelley
88f5e3a60d translate-c: fix regression in switch statement 2020-05-23 17:58:35 -04:00
Andrew Kelley
f67b8c68a0 translate-c: fix regression on array initialization 2020-05-23 17:52:46 -04:00
Andrew Kelley
32c27daae4 translate-c: fix decl statement regression 2020-05-23 17:50:35 -04:00
Andrew Kelley
46f50ee76c translate-c: fix regression in do-while loop 2020-05-23 17:25:13 -04:00
Andrew Kelley
8f6d7b3208 std: update singly linked list tests to new API 2020-05-23 16:38:43 -04:00
Andrew Kelley
1a90a5e63a translate-c is building again, but I have 1 @panic in there 2020-05-23 16:24:03 -04:00
Andrew Kelley
e072692e1f update translate-c to new AST API 2020-05-23 12:48:17 -04:00
Noam Preil
63aa9ffedc [Stage2/Codegen] Typo fix 2020-05-22 15:34:32 -04:00
Noam Preil
a52d1476b7 [Stage2/Codegen] Document x64 register enum layout 2020-05-22 15:32:33 -04:00
Greg Anders
64955deb72 Add poll definitions for Darwin 2020-05-22 13:21:34 -04:00
Andrew Kelley
8df0841d6a stage2 parser: token ids in their own array
To prevent cache misses, token ids go in their own array, and the
start/end offsets go in a different one.

perf measurement before:
         2,667,914      cache-misses:u
     2,139,139,935      instructions:u
       894,167,331      cycles:u

perf measurement after:
         1,757,723      cache-misses:u
     2,069,932,298      instructions:u
       858,105,570      cycles:u
2020-05-22 12:34:12 -04:00
Andrew Kelley
295bca9b5f stage2 parser: don't append doc comments to the list
The DocComment AST node now only points to the first doc comment token.
API users are expected to iterate over the following tokens directly.

After this commit there are no more linked lists in use in the
self-hosted AST API.

Performance impact is negligible. Memory usage slightly reduced.
2020-05-22 00:28:59 -04:00
Andrew Kelley
1dac9e71b5 std.testing: fix a crash when printing diffs 2020-05-22 00:27:51 -04:00
Andrew Kelley
8252c8b9d6 stage2 parser: different multiline string literal parsing strategy
and using flat memory rather than singly linked list

roughly equivalent performance, slightly reduced memory usage, better
API.
2020-05-21 23:25:15 -04:00
Andrew Kelley
19de259936 stage2 parser: arrays and structs directly in memory after the node
Slightly reduced memory usage. Roughly the same API and perf.
2020-05-21 22:52:45 -04:00
Andrew Kelley
9377af934f stage2 parser: SwitchCase uses intrusive array instead of linkedlist
no perf impact, but the API is better
2020-05-21 22:28:30 -04:00
Andrew Kelley
d37b81d43b stage2 parser performance/API improvements
* Extract Call ast node tag out of SuffixOp; parameters go in memory
   after Call.
 * Demote AsmInput and AsmOutput from AST nodes to structs inside the
   Asm node.
 * The following ast nodes get their sub-node lists directly following
   them in memory:
   - ErrorSetDecl
   - Switch
   - BuiltinCall
 * ast.Node.Asm gets slices for inputs, outputs, clobbers instead of
   singly linked lists

Performance changes:

throughput: 72.7 MiB/s => 74.0 MiB/s
maxrss: 72 KB => 69 KB (nice)
2020-05-21 22:01:16 -04:00
Andrew Kelley
32ecb416f3 fix compile errors when setting NodeIndex/TokenIndex to u32 2020-05-21 00:30:08 -04:00
Andrew Kelley
e694cd265a more progress on updating translate-c 2020-05-21 00:14:55 -04:00
Andrew Kelley
d57d9448aa stage2 parsing: rework block statements AST memory layout
block statements are now directly following the Block AST node rather
than a singly linked list. This had negligible impact on performance:

throughput: 72.3 MiB/s => 72.7 MiB/s

however it greatly improves the API since the statements are laid out in
a flat array in memory.
2020-05-20 23:47:04 -04:00
Andrew Kelley
3c5d581ce3 update translate-c to the new fn params AST node API 2020-05-20 23:28:31 -04:00
Andrew Kelley
140dc2f43e stage1: fix false positive redeclared variable compile error 2020-05-20 23:13:02 -04:00
Andrew Kelley
688aa114e4 Revert "stage2 parser: elide memcpy of large initialization lists"
This reverts commit 84df1d4f3d.

Not worth the complexity! Always memcpy initialization lists into the
arena.
2020-05-20 22:42:43 -04:00
Andrew Kelley
84df1d4f3d stage2 parser: elide memcpy of large initialization lists
throughput: 71.4 MiB/s => 72.9 MiB/s
2020-05-20 22:41:18 -04:00
Andrew Kelley
44aeb38328 make rand function public, fixes crypto benchmark 2020-05-20 21:27:08 -04:00
Andrew Kelley
897f23f20f stage2 parser: split off some SuffixOp AST nodes into separate tags
These SuffixOp nodes have their own ast.Node tags now:
 * ArrayInitializer
 * ArrayInitializerDot
 * StructInitializer
 * StructInitializerDot

Their sub-expression lists are general-purpose-allocator allocated
and then copied into the arena after completion of parsing.

throughput: 72.9 MiB/s => 74.4 MiB/s
maxrss: 68 KB => 72 KB

The API is also nicer since the sub expression lists are now flat arrays
instead of singly linked lists.
2020-05-20 19:18:14 -04:00
Andrew Kelley
7c2c0e36f8 stage2 parser: different memory layout of ParamDecl
Instead of being its own node, it's a struct inside FnProto.
Instead of FnProto having a SinglyLinkedList of ParamDecl nodes,
ParamDecls are appended directly in memory after the FnProto.

throughput: 72.2 MiB/s => 72.9 MiB/s
maxrss: 70 KB => 68 KB

Importantly, the API is improved as well since the data is arranged
linearly in memory.
2020-05-20 17:39:54 -04:00
Andrew Kelley
5db9f306ba update translate-c for new Root and ContainerDecl AST 2020-05-20 16:54:21 -04:00
Andrew Kelley
ad4b591db1 small bump to ArenaAllocator minimum alloc size
self-hosted parser benchmark:
throughput: 69.4 MiB/s => 72.2 MiB/s
2020-05-20 16:30:28 -04:00
Andrew Kelley
64c149ca19 fields and decls: ArrayList appending, memcpy to ast arena
This makes fields and decl ast nodes part of the Root and ContainerDecl
AST nodes.

Surprisingly, it's a performance regression from using a singly-linked
list for these nodes:

throughput: 76.5 MiB/s => 69.4 MiB/s

However it has much better memory usage:

maxrss: 392 KB => 77 KB

It's also better API for consumers of the parser, since it is a flat
list in memory.
2020-05-20 16:13:02 -04:00
Andrew Kelley
b1bcdc96ca arena allocator: smaller minimum allocation size 2020-05-20 16:11:55 -04:00
Andrew Kelley
8c10178a1e golly jeepers it's taking a long time to update translate-c 2020-05-20 13:53:53 -04:00
Andrew Kelley
4617c5907a fix zig fmt test regressions 2020-05-20 00:19:00 -04:00
Andrew Kelley
82225f6568 zig fmt parser tests are compiling again 2020-05-19 23:08:48 -04:00
Noam Preil
70239802c9 [Stage2/Codegen] Fix a typo 2020-05-19 22:27:22 -04:00
Andrew Kelley
93384f7428 use singly linked lists for std.zig.parse
std.ast uses a singly linked list for lists of things. This is a
breaking change to the self-hosted parser API.

std.ast.Tree has been separated into a private "Parser" type which
represents in-progress parsing, and std.ast.Tree which has only
"output" data. This means cleaner, but breaking, API for parse results.
Specifically, `tokens` and `errors` are no longer SegmentedList but a
slice.

The way to iterate over AST nodes has necessarily changed since lists of
nodes are now singly linked lists rather than SegmentedList.

From these changes, I observe the following on the
self-hosted-parser benchmark from ziglang/gotta-go-fast:

throughput: 45.6 MiB/s => 55.6 MiB/s
maxrss: 359 KB => 342 KB

This commit breaks the build; more updates are necessary to fix API
usage of the self-hosted parser.
2020-05-19 21:22:52 -04:00
Andrew Kelley
ed137d25ef Merge branch 'stage2-fn-calls' 2020-05-19 13:56:06 -04:00
Andrew Kelley
8d3cca7fc2 stage2: function calls using the global offset table
so far they don't support parameters or return values
2020-05-19 13:51:46 -04:00
Andrew Kelley
8d812dba30 stage2: set up a trampoline table for functions
However there does not appear to be an x86 encoding for calling an
immediate address. So there's no point of setting this up. We should
just emit an indirect call to the got addr.
2020-05-19 13:33:36 -04:00
Andrew Kelley
1cde0edff4 json: properly stringify error sets
I did this wrong originally in
feade9ef00
2020-05-18 19:23:40 -04:00
Andrew Kelley
fe28d73271 Merge pull request #5303 from kubkon/dir-fns
Add/fix missing WASI functionality to pass libstd tests
2020-05-18 19:00:25 -04:00
Ryan Liptak
a80ad0782d CMake: Make fallthrough support version check specific to GCC 2020-05-18 18:19:00 -04:00
Jakub Konka
cd8daa533a Undo accidentally checked-in changes to fs/test.zig 2020-05-18 22:22:27 +02:00
Jakub Konka
57719006bb Always return false for ANSI escape codes compat in WASI 2020-05-18 21:17:49 +02:00
Jakub Konka
3d267bab71 Re-enable refAllDecls gen and check in std.zig 2020-05-18 21:05:29 +02:00
Alexandros Naskos
75a4c02880 Updated test 2020-05-18 19:28:26 +03:00
Alexandros Naskos
400a91e1c6 Add TypeOf resolution of dereferences and struct fields of undefined values 2020-05-18 19:15:44 +03:00
Jakub Konka
34f84c3608 Narrow down behaviour test cases; this removes wasmtime-enabled check in tests 2020-05-18 17:56:17 +02:00
Jakub Konka
2a59ecd7ec Integrate getTestDir with tmpDir logic 2020-05-18 17:10:49 +02:00
Jakub Konka
f26ab568aa Remove obsolete runtime panics from sleep impl 2020-05-18 17:10:17 +02:00
Jakub Konka
5186711a96 Change to Self from *const Self/*Self where possible 2020-05-18 17:10:06 +02:00
Jakub Konka
fae4af9e1c Make mode_t a 0-byte type in WASI 2020-05-18 17:09:52 +02:00
Jakub Konka
40812063cc Disable tests requiring Wasmtime be default; require -Denable-wasmtime flag otherwise 2020-05-18 16:12:03 +02:00
Jakub Konka
bd9a616586 Skip WASI tests in drone and on FreeBSD 2020-05-18 16:10:54 +02:00
Jakub Konka
14510f412d Download and unpack wasmtime on Linux 2020-05-18 16:10:32 +02:00
Jakub Konka
be796e40a3 Run WASI tests on Linux only 2020-05-18 16:10:14 +02:00
Jakub Konka
d43c08a3e5 Add/fix missing WASI functionality to pass libstd tests
This rather large commit adds/fixes missing WASI functionality
in `libstd` needed to pass the `libstd` tests. As such, now by
default tests targeting `wasm32-wasi` target are enabled in
`test/tests.zig` module. However, they can be disabled by passing
the `-Dskip-wasi=true` flag when invoking the `zig build test`
command. When the flag is set to `false`, i.e., when WASI tests are
included, `wasmtime` with `--dir=.` is used as the default testing
command.

Since the majority of `libstd` tests were relying on `fs.cwd()`
call to get current working directory handle wrapped in `Dir`
struct, in order to make the tests WASI-friendly, `fs.cwd()`
call was replaced with `testing.getTestDir()` function which
resolved to either `fs.cwd()` for non-WASI targets, or tries to
fetch the preopen list from the WASI runtime and extract a
preopen for '.' path.

The summary of changes introduced by this commit:
* implement `Dir.makeDir` and `Dir.openDir` targeting WASI
* implement `Dir.deleteFile` and `Dir.deleteDir` targeting WASI
* fix `os.close` and map errors in `unlinkat`
* move WASI-specific `mkdirat` and `unlinkat` from `std.fs.wasi`
  to `std.os` module
* implement `lseek_{SET, CUR, END}` targeting WASI
* implement `futimens` targeting WASI
* implement `ftruncate` targeting WASI
* implement `readv`, `writev`, `pread{v}`, `pwrite{v}` targeting WASI
* make sure ANSI escape codes are _not_ used in stderr or stdout
  in WASI, as WASI always sanitizes stderr, and sanitizes stdout if
  fd is a TTY
* fix specifying WASI rights when opening/creating files/dirs
* tweak `AtomicFile` to be WASI-compatible
* implement `os.renameatWasi` for WASI-compliant `os.renameat` function
* implement sleep() targeting WASI
* fix `process.getEnvMap` targeting WASI
2020-05-18 16:09:49 +02:00
Andrew Kelley
feade9ef00 std.json: support stringify for anyerror 2020-05-17 17:07:27 -04:00
Veikka Tuominen
2a5c0ef7f0 Merge pull request #5164 from daurnimator/in_stream-helpers
A couple of helpers for streams that I've found helpful
2020-05-17 22:02:10 +03:00
Andrew Kelley
16f100b82e Merge pull request #5307 from ziglang/self-hosted-incremental-compilation
rework self-hosted compiler for incremental builds
2020-05-17 13:53:27 -04:00
Andrew Kelley
b0968abccb update ZIR compare output test to test incremental updates 2020-05-17 13:49:22 -04:00
Andrew Kelley
9a22c8b6ca Merge pull request #5057 from xackus/opaque-param
stage1: fix assert fail on opaque fn ptr param
2020-05-17 12:48:56 -04:00
Noam Preil
03ed9e4173 Fix compilation with GCC 5 2020-05-17 12:18:53 -04:00
Andrew Kelley
88c8ff6e37 move some files around 2020-05-17 12:08:47 -04:00
Noam Preil
e198eec76a Document register functions 2020-05-17 12:03:01 -04:00
Noam Preil
773281c1f4 Remove trailing whitespace 2020-05-17 12:03:01 -04:00
Noam Preil
e2196a458f Minor cleanup 2020-05-17 12:03:01 -04:00
Noam Preil
497eb31820 Fix the dumb in x86 too 2020-05-17 12:03:01 -04:00
Noam Preil
638554544a Fix a dumb (thanks daurminator!) 2020-05-17 12:03:01 -04:00
Noam Preil
13ea698a40 rework x64 genSetReg 2020-05-17 12:03:01 -04:00
Veikka Tuominen
241984987b Merge pull request #5367 from Vexu/fix
Fix zig fmt regression
2020-05-17 17:43:25 +03:00
Vexu
28d449b38d fix zig fmt regression 2020-05-17 15:13:19 +03:00
Vincent Rischmann
e5ffb94911 linux: remove duplicated fields 2020-05-17 02:42:59 -04:00
Andrew Kelley
54820a3005 fix source not being loaded when printing errors 2020-05-16 20:23:15 -04:00
Andrew Kelley
017ecc5148 self hosted repl: close executables between updates
This allows the executable to be executed
2020-05-16 15:44:20 -04:00
Andrew Kelley
f2ceb023f4 Merge pull request #5217 from wozeparrot/master
build.zig recursive dep support
2020-05-16 14:24:51 -04:00
Vexu
eda03354dc Merge pull request #5358 from Vexu/parser
Fix infinite loop with invalid comptime
2020-05-16 20:49:37 +03:00
Andrew Kelley
b0375978ba self-hosted: remove zig libc command for now
Since it depends on the C++ Windows SDK code. For now, self-hosted is
staying pure self hosted, no C/C++ components.
2020-05-16 13:25:39 -04:00
Andrew Kelley
cf34480f2a Merge pull request #5231 from kubkon/wasi-preopens
Add mechanism for extracting preopens from the runtime
2020-05-16 12:49:08 -04:00
Felix (xq) Queißner
7dc29fdee1 Creates std.ascii.control_code that contains the C0 control codes as named constants. 2020-05-16 12:46:44 -04:00
data-man
6647c3f054 Fixes fmt padding for some types 2020-05-16 12:45:43 -04:00
Michael Dusan
e05923f34b macos: use realpath$DARWIN_EXTSN
macOS 10.15 Catalina causes an ancient variant of `realpath` to fail,
likely due to 10.15's evolving security model.

closes #5325
2020-05-16 12:41:53 -04:00
Andrew Kelley
79462bb591 Merge pull request #5354 from DrDeano/master
Add enum to addBuildOption
2020-05-16 12:40:06 -04:00
Vexu
081ffe24cf fix infinite loop with invalid comptime 2020-05-16 19:23:59 +03:00
Andrew Kelley
cd5f69794d cross compile the stage2 tests for the target that they work for 2020-05-16 12:19:31 -04:00
Vexu
74f7d710bb Merge pull request #5032 from LakeByTheWoods/redo_translate_c
Translate C: Redo Add comment containing c source location for failed decls.
2020-05-16 17:37:19 +03:00
DrDeano
72b72faa0b Add Enum Option 2020-05-16 15:36:18 +01:00
DrDeano
b2cb8beed9 Add enum to addBuildOptions 2020-05-16 15:35:42 +01:00
Vexu
d061e5854a Merge pull request #5020 from jinroh/docs/search-perf
docs: search perf
2020-05-16 16:43:41 +03:00
Vexu
758de71d97 Merge pull request #5353 from Vexu/parser
Self-hosted parser fixes
2020-05-16 15:56:03 +03:00
Vexu
3e375ee2b9 translate-c use tagName for token id 2020-05-16 14:17:50 +03:00
Vexu
092f726eec Merge pull request #5175 from daurnimator/multi-out-stream
std: add io.MultiOutStream
2020-05-16 13:43:50 +03:00
Vexu
e2a0f5741d Merge pull request #5189 from zigazeljko/patch-1
Split AES struct into AESEncrypt and AESDecrypt
2020-05-16 13:20:14 +03:00
Vexu
6c10075dd3 Merge pull request #5350 from yvt/test-global-linkage
Enable the test `standalone/global_linkage`
2020-05-16 13:10:01 +03:00
Vexu
5ac684ec50 fix building translate-c 2020-05-16 13:05:43 +03:00
Vexu
a05011d403 move ParamType to Node.ParamDecl 2020-05-16 12:54:51 +03:00
Vexu
ed62081d38 recover from missing semicolon after if stmt 2020-05-16 12:29:01 +03:00
Vexu
6ca0def499 recover from invalid global error set access 2020-05-16 12:09:34 +03:00
Andrew Kelley
69a5f0d797 Merge remote-tracking branch 'origin/master' into self-hosted-incremental-compilation 2020-05-16 01:26:18 -04:00
Andrew Kelley
a286b5de38 build.zig: -Dlib-files-only skips installing self-hosted 2020-05-16 01:22:56 -04:00
Andrew Kelley
294bfb3321 stage2 zir tests passing 2020-05-15 23:54:13 -04:00
Andrew Kelley
f2feb4e47a move Module to its own file 2020-05-15 21:44:33 -04:00
Andrew Kelley
64f4ef7556 update ZIR test cases 2020-05-15 21:29:52 -04:00
Andrew Kelley
5135238f86 ZIR: emit proper string literals 2020-05-15 19:11:00 -04:00
Andrew Kelley
8980f150e9 fix memory leaks of one of the ZIR test cases 2020-05-15 18:54:48 -04:00
Vexu
b2f16d4484 fix infinite loop with mismatced bracket 2020-05-15 23:50:47 +03:00
Andrew Kelley
e1d4b59c5b self-hosted: update main.zig
After this commit there are no more bit rotted files.
The testing program that was in ir.zig has been moved to main.zig
Unsupported command line options have been deleted, or error messages
added.

The compiler repl is available from the build-exe, build-lib,
build-obj commands with the --watch option.

The main zig build script now builds the self-hosted compiler
unconditionally. Linking against LLVM is behind a -Denable-llvm
flag that defaults to off.
2020-05-15 15:20:42 -04:00
yvt
b747d4d1ce Enable the test standalone/global_linkage
This test was added to the source tree in c39d7a6, but has never been
referenced from anywhere.
2020-05-16 02:05:55 +09:00
Vexu
a00fd6e254 properly handle extra closing braces at top level 2020-05-15 14:30:49 +03:00
Vexu
f8b99331a2 Merge pull request #5336 from Vexu/parser
Make self-hosted parser more error tolerant
2020-05-15 14:15:30 +03:00
Vexu
440189a04a cleanup* remove unecessary error* properly handle ReturnTypeInvalid in ast.zig functions* assert that the tree is clean in render.zig* simplify parser recovery with top level decls 2020-05-15 11:35:37 +03:00
Andrew Kelley
ebb81ebe59 fix the global offset table code and updating decl exports 2020-05-15 01:22:04 -04:00
Andrew Kelley
81a01bd481 fix codegen of sentinel-terminated arrays and .got alignment
we now have an exit(0) program working
2020-05-14 16:34:04 -04:00
Andrew Kelley
0986dcf1cf self-hosted: fix codegen and resolve some analysis bugs 2020-05-14 13:20:27 -04:00
Vexu
c77fee0344 fix infinite loop
findToken wasn't as generic as I thought it was
2020-05-14 19:56:55 +03:00
Vexu
c4552ee8ed store rparen in ReturnType.Invalid
This is useful for getting a partial function signature
2020-05-14 17:18:14 +03:00
Vexu
a32e240540 improve recovery from invalid container members
Instead of trying to find the end of the block or the next comma/semicolon
we no try to find the next token that can start a container member.
2020-05-14 12:09:40 +03:00
Vexu
89f2923a8a recover from missing semicolon 2020-05-14 11:19:50 +03:00
Vexu
ac319b2734 remove useless nosuspend parsing
nosuspend cannot be used in a type expression and
all other use casesare covered by PrimaryExpr
2020-05-14 11:19:14 +03:00
Andrew Kelley
fb947c365e work around stage1 compiler bug
breaking from inside the block with defers in scope triggered
broken LLVM module found: Terminator found in the middle of a basic
block!
2020-05-13 22:20:31 -04:00
Andrew Kelley
6a2425c38c self-hosted: fix the rest of the compile errors 2020-05-13 22:12:38 -04:00
Andrew Kelley
080022f6c6 self-hosted: fix compile errors, except for codegen.zig 2020-05-13 20:06:01 -04:00
Vexu
c3b76d0913 recover from invalid builtin/async call 2020-05-14 00:16:56 +03:00
Vexu
1f81887a78 recover after invalid inline/extern 2020-05-13 23:35:58 +03:00
Vexu
ad71d959d7 correctly recover from invalid top level declarations 2020-05-13 23:28:04 +03:00
Vexu
2296906e2a modernize std.zig.tokenizer 2020-05-13 23:08:42 +03:00
Vexu
23c5ff94e9 improve recovery on top level declarations 2020-05-13 20:42:18 +03:00
Vexu
4b898893e2 Merge pull request #5254 from ifreund/top-level-struct-file-names
Apply naming conventions of structs to files
2020-05-13 19:28:14 +03:00
Vexu
118db892be Merge pull request #5321 from gpanders/ascii-case-sensitive
Add helper functions and docstrings to ascii.zig
2020-05-13 19:04:53 +03:00
Vexu
76681e6b96 Make PriorityQueue.Iterator public
The `iterator` function was already public but these seem to have been forgotten.
2020-05-13 18:38:03 +03:00
Vexu
be2b8d58ef Merge pull request #5337 from DrDeano/master
Make StackIterator next public
2020-05-13 18:32:01 +03:00
DrDeano
2589f7207b Make StackIterator next public 2020-05-13 16:21:15 +01:00
Vexu
3715226b9f Merge pull request #5332 from jwmerrill/patch-1
Fix comment typo RFC8529 -> RFC8259
2020-05-13 18:04:27 +03:00
Vexu
afab095b61 translate-c remove error set from checkForBuiltinTypedef 2020-05-13 17:53:15 +03:00
Vexu
cefc04348e continue parsing on invalid and token 2020-05-13 17:36:06 +03:00
Vexu
be392777b7 continue parsing after missing commas and invalid statements 2020-05-13 17:21:27 +03:00
Vexu
91358f3092 continue parsing on extra qualifier errors 2020-05-13 16:51:23 +03:00
Andrew Kelley
a3da584248 self-hosted: ir: implement separated analysis of Decl and Fn 2020-05-12 23:59:46 -04:00
Jason Merrill
706311cad9 Fix comment typo RFC8529 -> RFC8259
Ref: https://tools.ietf.org/html/rfc8259
2020-05-12 19:11:05 -07:00
Andrew Kelley
e3a0fac1a7 self-hosted: link: global offset table support for decls 2020-05-12 20:11:47 -04:00
Andrew Kelley
fda0eef9fb clear progress indicator before printing errors 2020-05-12 16:43:50 -04:00
Vexu
df22c7dfef std.zig attempt to continue parsing on error 2020-05-12 22:37:39 +03:00
Vexu
fa57463bb9 make parser testError take a list of expected errors 2020-05-12 21:44:08 +03:00
Vexu
80d0c2f166 Merge pull request #5118 from xackus/fix-json-writestream
fix json.WriteStream.emitJson
2020-05-12 17:44:06 +03:00
Greg Anders
c6420820b0 Remove redundant ASCII functions
The `matchCase` variants are simply duplicates of the `eql` and
`indexOf` functions found in std.mem.
2020-05-12 08:38:15 -06:00
Vexu
08e2e690d7 Merge pull request #5275 from strangebug/docs-markdown-links
Add support for external links and URL to markdown parser.
2020-05-12 15:35:50 +03:00
Vexu
29b3be4f2f Merge pull request #5319 from Vexu/float-fix
Fix intToFloat on comptime_floats
2020-05-12 15:20:03 +03:00
Vexu
b1ebaba408 std.json properly handle comptime int/float 2020-05-12 15:15:21 +03:00
Andrew Kelley
619159cf48 self-hosted: rework the memory layout of ir.Module and related types
* add TypedValue.Managed which represents a Type, a Value, and some
   kind of memory management strategy.
 * introduce an analysis queue
 * flesh out how incremental compilation works with respect to exports
 * ir.text.Module is only capable of one error message during parsing
 * link.zig no longer has a decl table map and instead has structs that
   exist directly on ir.Module.Decl and ir.Module.Export
 * implement primitive .text block allocation
 * implement linker code for updating Decls and Exports
 * implement null Type

Some supporting std lib changes:
 * add std.ArrayList.appendSliceAssumeCapacity
 * add std.fs.File.copyRange and copyRangeAll
 * fix std.HashMap having modification safety on in ReleaseSmall builds
 * add std.HashMap.putAssumeCapacityNoClobber
2020-05-12 01:02:48 -04:00
Greg Anders
9f496c0777 Add helper functions and docstrings to ascii.zig
* Add an upper case variant of `allocLowerString`
  * Add case-sensitive variants of `eqlIgnoreCase`, `indexOfIgnoreCase`,
    and `indexOfIgnoreCasePos`
  * Add and update docstrings on functions
2020-05-11 19:36:41 -06:00
Vexu
7456389ef3 Merge pull request #5308 from xiongxin/master
mem.eql need slice type
2020-05-12 01:41:51 +03:00
Vexu
7aee8a93eb Merge pull request #5315 from xackus/fix-bigint_fits_in_bits
stage1: detect underflow in bigint_fits_in_bits
2020-05-12 01:25:24 +03:00
Vexu
0847b47bf8 fix @intToFloat on comptime_floats 2020-05-12 00:24:09 +03:00
Vexu
3e3c651b67 Merge pull request #5316 from marler8997/pubSockLen
make Address.getOsSockLen pub
2020-05-11 20:10:59 +03:00
Jonathan Marler
832f6c1228 make Address.getOsSockLen pub 2020-05-11 09:11:05 -06:00
xackus
204f8daeed stage1: detect underflow in bigint_fits_in_bits 2020-05-11 14:06:37 +02:00
熊鑫
0363f3c6f3 mem.eql need slice type 2020-05-10 20:35:21 +08:00
Andrew Kelley
a32d3a85d2 rework self-hosted compiler for incremental builds
* introduce std.ArrayListUnmanaged for when you have the allocator
   stored elsewhere
 * move std.heap.ArenaAllocator implementation to its own file. extract
   the main state into std.heap.ArenaAllocator.State, which can be
   stored as an alternative to storing the entire ArenaAllocator, saving
   24 bytes per ArenaAllocator on 64 bit targets.
 * std.LinkedList.Node pointer field now defaults to being null
   initialized.
 * Rework self-hosted compiler Package API
 * Delete almost all the bitrotted self-hosted compiler code. The only bit
   rotted code left is in main.zig and compilation.zig
 * Add call instruction to ZIR
 * self-hosted compiler ir API and link API are reworked to support
   a long-running compiler that incrementally updates declarations
 * Introduce the concept of scopes to ZIR semantic analysis
 * ZIR text format supports referencing named decls that are declared
   later in the file
 * Figure out how memory management works for the long-running compiler
   and incremental compilation. The main roots are top level
   declarations. There is a table of decls. The key is a cryptographic
   hash of the fully qualified decl name. Each decl has an arena
   allocator where all of the memory related to that decl is stored.
   Each code block has its own arena allocator for the lifetime of
   the block. Values that want to survive when going out of scope in
   a block must get copied into the outer block. Finally, values must
   get copied into the Decl arena to be long-lived.
 * Delete the unused MemoryCell struct. Instead, comptime pointers are
   based on references to Decl structs.
 * Figure out how caching works. Each Decl will store a set of other
   Decls which must be recompiled when it changes.

This branch is still work-in-progress; this commit breaks the build.
2020-05-10 02:05:54 -04:00
Haze Booth
e79d7e0ded Remove fs.File artifact from connectUnixSocket 2020-05-09 12:29:27 -04:00
Vexu
d4d509090b make std.build.getInstallPath public
Closes  #5299
2020-05-09 00:31:11 +03:00
Vexu
453df1cc1e Merge pull request #4892 from Sobeston/patch-4
mem.zeroes - add sentinel terminated array support
2020-05-08 22:37:27 +03:00
Vexu
336ddb5b76 std: add test for mem.zeroes on sentinel terminated arrays 2020-05-08 19:03:27 +03:00
Vexu
f2d3266075 Merge pull request #4932 from Qix-/fix-private-access
Fix private access
2020-05-08 18:21:15 +03:00
Vexu
f1e5a4f163 Merge pull request #5296 from daurnimator/osx-RTLD
std: fix RTLD_ constants on OSX
2020-05-08 18:05:04 +03:00
daurnimator
45f7c78bfc std: fix RTLD_ constants on OSX 2020-05-08 22:34:18 +10:00
Vexu
10abffcd98 fix more private member access 2020-05-08 15:10:38 +03:00
Josh Junon
b6dc7fc9ff publicize member functions affected by #4909 2020-05-08 14:26:28 +03:00
Josh Junon
4a5c58dd35 fix private member checking for non-canonical invocations (fixes #4909) 2020-05-08 14:26:13 +03:00
Josh Junon
fbf081a306 add failing test for #4909 2020-05-08 14:26:13 +03:00
xackus
2c9effc101 stage1: handle all cases of invalid struct field default value 2020-05-07 16:39:16 -04:00
Andrew Kelley
3aa259d119 Merge branch 'kristoff-it-macos-kqueue'
closes #5286
2020-05-07 13:41:26 -04:00
Loris Cro
35a59b5b0f remove readable check when opening a socket connection 2020-05-07 13:41:17 -04:00
Loris Cro
7e8b859095 fix oneshot flag erroneusly set as filter_flag 2020-05-07 13:41:17 -04:00
Loris Cro
a78ac96134 fix crash in single-threaded builds 2020-05-07 13:41:02 -04:00
xackus
79bf4003da stage1: add ZigList gdb pretty printing 2020-05-07 12:43:22 -04:00
Andrew Kelley
ba43492c0e Merge pull request #5268 from tadeokondrak/remove-callconv-redundant-syntax
Remove syntax redundant with callconv
2020-05-07 12:42:26 -04:00
Jens Goldberg
20c1696865 Removed GetModuleHandleA from user32
GetModuleHandleA is an kernel32 function and already defined there, it doesn't belong in user32.
2020-05-07 12:38:46 -04:00
Jens Goldberg
25810bc1e6 Removed duplicate WM_ACTIVATE 2020-05-07 12:38:46 -04:00
Vexu
54b2a6ec41 Merge pull request #5287 from marler8997/fixAllocWithPayload
fix copy/paste error in AllocWithOptionaPayload
2020-05-07 12:39:57 +03:00
Jonathan Marler
0a76e11617 add failAllocator to enable some regression tests 2020-05-06 23:56:48 -06:00
Jonathan Marler
0c7397b49f fix copy/paste error in AllocWithOptionaPayload 2020-05-06 23:08:08 -06:00
Timon Kruiper
b336dda076 Standard library: Fix a regression in loop.waitUntilFdWritableOrReadable
This broke async io on linux.
Regressed in 8ebcca6734
2020-05-06 13:14:06 -04:00
Vexu
9c422c28f6 Merge pull request #5281 from data-man/hash_vector_nocopy
Optimization of vectors hashing
2020-05-06 18:12:35 +03:00
data-man
3c4abacba6 Optimization of vectors hashing 2020-05-06 17:08:49 +05:00
Vexu
0e30edd8d0 std: handle ConnectionTimedOut in switch
regression from #5266
closes #5270
2020-05-06 12:52:26 +03:00
Vexu
06e6d39c6c Merge pull request #5257 from matt1795/scoped-typedef
Add scoped typedef to translate-c
2020-05-06 12:28:30 +03:00
Vexu
c0b269bf46 translate-c: small patch to fix bultin type detection 2020-05-06 11:48:46 +03:00
Matthew Knight
52f0adb305 checkForBuiltinTypedef now returns a string 2020-05-05 23:26:00 -07:00
Lann
eb4fa63d3d Remove reference to import type (#5279)
* Remove reference to import type
* Improve language in `@This()` doc
2020-05-05 19:13:35 -04:00
Andrew Kelley
ae080b5c21 readme: remove the part about stage2 until it's done 2020-05-05 15:26:36 -04:00
Andrew Kelley
ad43155f25 Merge branch 'haze-hb/test-evented-io-build-zig'
closes #5274
2020-05-05 15:18:34 -04:00
Andrew Kelley
6f3d76f61e simplify test-evented-io build setting 2020-05-05 15:18:04 -04:00
Haze Booth
a39cb034ea Add setUseTestEventedIO for test steps in build.zig 2020-05-05 15:16:54 -04:00
Andrew Kelley
b13a02ed1a avoid unnecessary fcntl syscalls when setting socket flags 2020-05-05 12:50:50 -04:00
Andrew Kelley
0a2104689b fix incorrect flags being set in os.setSockFlags
fixes networking stuff on darwin
2020-05-05 12:45:39 -04:00
Tadeo Kondrak
84a0a9688c update docs/tests for async/extern fn removal 2020-05-05 10:31:32 -06:00
StrangeBug
54088fe6e1 Add support for external links and URL to markdown parser. 2020-05-05 18:09:32 +02:00
Tadeo Kondrak
6745a6f6f6 zig fmt 2020-05-05 09:38:02 -06:00
Tadeo Kondrak
d0e996405b add zig fmt fix for async/extern fn 2020-05-05 09:37:59 -06:00
Tadeo Kondrak
7ada59f873 remove nakedcc/stdcallcc/async fn/extern fn fnproto 2020-05-05 09:37:28 -06:00
Jakub Konka
81d824bf80 Clear PreopenList on every populate call 2020-05-05 17:23:49 +02:00
Andrew Kelley
e6955688ac Merge pull request #5272 from tadeokondrak/noasync-to-nosuspend
Noasync to nosuspend
2020-05-05 11:21:02 -04:00
Jakub Konka
07a968b344 Add docs 2020-05-05 17:05:30 +02:00
Vexu
fde6d28c23 Merge pull request #5273 from haze/hb/fix-posix-errorunion-thread-spawn-result
Update ErrorUnion thread spawn result to return null instead of 0
2020-05-05 16:20:05 +03:00
Jakub Konka
558bb24601 Move preopen and path wasi helpers to std.fs.wasi module
Previously, the path and preopens helpers were prototyped in `std.os.wasi`
module, but since they are higher-level abstraction over wasi, they belong in
`std.fs.wasi` module.
2020-05-05 15:08:52 +02:00
Jakub Konka
d4c33129cf Shuffle things around; add PreopenList.findByPath method
This commit removes `std.os.openatWasi` function, and renames it to
`std.os.wasi.openat`. Additionally, the added `PreopenList.findByPath`
method allows querying the list for a matching preopen by path.
2020-05-05 15:08:52 +02:00
Jakub Konka
dd238352a4 Encapsulate getPreopens inside PreopenList 2020-05-05 15:08:52 +02:00
Jakub Konka
fc77e393fd Remove obsolete PATH_MAX const 2020-05-05 15:08:52 +02:00
Jakub Konka
b8112b3d17 Simplify File constructors 2020-05-05 15:08:52 +02:00
Jakub Konka
8bce1b6981 Refactor resolve_preopen into getPreopens function
This commit refactors `std.os.wasi.resolve_preopen` into a (higher-level)
`std.os.wasi.getPreopens` funtion which returns a slice with _all_
preopens at any given time. This fn allows the WASI module to
inquire at any given time for all preopens provided by the runtime.

This commit also makes `cwd()` a compile error on WASI.
2020-05-05 15:08:52 +02:00
Jakub Konka
05fb3e79fe Make std.fs.cwd() return preopen for "." if exists
This commit adds WASI specific impl of `std.fs.cwd()` in which we
emulate the `cwd` behaviour by inquiring the runtime for a "."
preopen if available. This is OK for simple relative ops, but will
not work for any ops which require absolute paths.
2020-05-05 15:08:52 +02:00
Jakub Konka
8e1cd69717 Implement std.fs.Dir.openFileWasi
It seems that `std.os.openZ` is too POSIX-specific, so I think it
should not be a point of entry for WASI `open` call. I figure
WASI should be treated as a separate "os" that's _not_ POSIX
especially given the incoming changes in the ephemeral snapshot.
2020-05-05 15:08:52 +02:00
Jakub Konka
d7ca220121 Start drafting out openZ 2020-05-05 15:08:52 +02:00
Tadeo Kondrak
fdfdac4939 update comments for nosuspend 2020-05-05 05:55:27 -06:00
Tadeo Kondrak
2c9204032d update tests for nosuspend 2020-05-05 05:55:26 -06:00
Tadeo Kondrak
af00afed98 zig fmt 2020-05-05 05:55:25 -06:00
Tadeo Kondrak
b957dc29a4 Rename noasync to nosuspend in C++ compiler 2020-05-05 05:17:34 -06:00
Tadeo Kondrak
8d5636ebe4 Rename noasync to nosuspend in self-hosted, add rewriter 2020-05-05 05:17:33 -06:00
Haze Booth
4cb4097b08 Update ErrorUnion thread spawn result to return null instead of 0 2020-05-05 04:15:43 -04:00
Matthew Knight
db4833d4d6 moved duplicated code to common functions 2020-05-04 23:45:31 -07:00
Vexu
f127dee474 Merge pull request #5267 from Vexu/const-call
Fix missing compile error on call assigned to const
2020-05-04 21:45:15 +03:00
Jonathan Marler
75b699b2c6 os.zig: add ETIMEDOUT error case to read function
According to documentation ETIMEDOUT (110) is a valid error code for the read function.  I just had my long-running  (been running for about 7 weeks) network program crash because it did not handle the ETIMEDOUT error code from "read".
2020-05-04 13:48:34 -04:00
Vexu
85fd484f07 std: fix blake3 assignment to constant 2020-05-04 14:45:36 +03:00
Vexu
adc444ceeb fix missing compile error on call assigned to const 2020-05-04 14:28:58 +03:00
xackus
887bf8ba93 stage1: remove unneeded switch 2020-05-04 06:51:51 +02:00
xackus
0db9e90e8f stage1: fix assert fail on opaque fn ptr param 2020-05-04 06:51:37 +02:00
Cato
9b788b765c Pass filtered_sock_type to system.socket. Cover PermissionDenied error 2020-05-03 15:35:36 -04:00
daurnimator
277d088558 std: use async for MultiOutStream 2020-05-03 18:33:04 +10:00
Matthew Knight
c5198bd76f added scoped typedef to translate-c 2020-05-02 20:22:43 -07:00
data-man
c8b4cc2ff9 Include dbg.h to third-party libs 2020-05-02 18:29:02 -04:00
Andrew Kelley
1b201f460f Merge branch 'ninjacato-tomerge-darwin-fix-accept-sockets'
closes #5251
2020-05-02 17:38:17 -04:00
Andrew Kelley
8a8beefa36 solve the problem with Darwin shims in std.os instead
* implement SOCK_NONBLOCK and SOCK_CLOEXEC Darwin shims in std.os
 * revert changes to std.net
 * remove os.accept and rename os.accept4 to os.accept
2020-05-02 17:36:28 -04:00
Isaac Freund
3a397795be Apply naming conventions of structs to files 2020-05-02 23:28:44 +02:00
Tadeo Kondrak
a62e9bc8e5 Implement @Type for ErrorSet 2020-05-02 14:39:32 -06:00
Tadeo Kondrak
647901b4a8 Constify TypeInfo 2020-05-02 14:39:31 -06:00
Tadeo Kondrak
ca6db2d008 Implement @Type() for EnumLiteral and FnFrame 2020-05-02 14:39:28 -06:00
Tadeo Kondrak
1696e943ac Implement @typeInfo for @Frame()
Closes https://github.com/ziglang/zig/issues/3066
2020-05-02 14:39:27 -06:00
Cato
07bee9da42 Fixed Darwin-incompatible socket flags and unavailable system calls 2020-05-02 16:37:39 -04:00
Andrew Kelley
03a7124543 Merge pull request #5249 from ziglang/FireFox317-windows-evented-io
fix behavior test with --test-evented-io on windows
2020-05-02 16:29:58 -04:00
Andrew Kelley
b7914d901c add test coverage for top level fields
closes #2022
2020-05-02 14:53:20 -04:00
Andrew Kelley
7998e2b0f4 Merge remote-tracking branch 'origin/master' into FireFox317-windows-evented-io 2020-05-02 14:16:59 -04:00
Chris Heyes
8ebcca6734 Get evented io code paths to build on macOS (#5233)
* Get evented io code paths to build on macOS
* Use mode_t instead of usize where appropriate
2020-05-02 14:14:46 -04:00
Andrew Kelley
5656f5090d fs.File: improve handling async I/O on Windows
Before it was possible for .intended_io_mode = .blocking,
.capable_io_mode = .evented, and then the implementation would put a
request on the fs thread, which is the wrong behavior. Now it always
calls the appropriate WriteFile/ReadFile function, passing the intended
io mode directly as a parameter.

This makes the behavior tests pass on Windows with --test-evented-io.
2020-05-02 14:09:17 -04:00
Michael Dusan
33705d06bb Merge pull request #5250 from mikdusan/qemu
ci linux: bump qemu-5.0.0-z2
2020-05-02 09:46:40 -04:00
Michael Dusan
5fb8d7dcdc ci linux: bump qemu-5.0.0-z2
closes #5245
see 1b41e31a5c
2020-05-02 04:39:36 -04:00
Andrew Kelley
9dac8a5be9 update windows impl of child process to new File API 2020-05-02 04:31:26 -04:00
nycex
77376a54bf correct usages of std.fs.dir.DeleteFileError (#5058)
* correct usages of std.fs.dir.DeleteFileError

* test std.fs.createFileAbsolute() and std.fs.deleteFileAbsolute()
2020-05-02 04:19:07 -04:00
Andrew Kelley
428065da30 Merge pull request #5243 from niacat/kern-arand
Avoid reading from /dev/urandom on NetBSD
2020-05-02 04:16:24 -04:00
Andrew Kelley
6546c74825 child process: no need to remove O_CLOEXEC before execve 2020-05-02 03:38:05 -04:00
Andrew Kelley
92f3e9c92a remove last use of share_with_child_process 2020-05-02 01:54:36 -04:00
Andrew Kelley
beebcbb677 Merge remote-tracking branch 'origin/master' into FireFox317-windows-evented-io 2020-05-02 01:53:24 -04:00
Andrew Kelley
43f7856bac fix regressions in windows std lib tests 2020-05-02 01:25:22 -04:00
Andrew Kelley
2272a07ca0 std.event.Loop: promote the fs thread to be available for all OS's 2020-05-02 00:41:19 -04:00
Andrew Kelley
45bce27b8f cleanup and fixes. behavior tests passing with evented I/O 2020-05-01 23:17:28 -04:00
Michael Dusan
3dbe02e2d8 Merge pull request #5247 from mikdusan/housekeeping
stage1: cleanup
2020-05-01 20:57:56 -04:00
Andrew Kelley
988031c07c Merge branch 'windows-evented-io' of https://github.com/FireFox317/zig into FireFox317-windows-evented-io 2020-05-01 19:02:16 -04:00
Michael Dusan
09d6dc1ce6 stage1: cleanup
- remove unused IrInstSrcOptionalUnwrapPtr.initializing
2020-05-01 18:01:21 -04:00
Andrew Kelley
3386bb896d Merge pull request #5192 from ziglang/stage2-tests
add ZIR compare output test case to test suite
2020-05-01 17:35:52 -04:00
Andrew Kelley
94b0d0e802 std.progress: handle error from FillConsoleOutputAttribute
I observed this returning an error. Fall back to not doing
terminal stuff if an error occurs here.

See #5244
2020-05-01 15:14:44 -04:00
Cato Auestad
5418efa1e5 Added socket bits for Darwin 2020-05-01 14:28:33 -04:00
Andrew Kelley
ec6ef86219 fix off-by-one error in sizeInBaseUpperBound 2020-05-01 13:33:46 -04:00
nia
74ad315360 In init_rand avoid reading from /dev/urandom on NetBSD/FreeBSD
Use the KERN_ARND sysctl instead.
2020-05-01 17:23:27 +01:00
nia
14a954f350 Add arc4random_buf() in NetBSD libc, use it to implement getrandom() 2020-05-01 17:22:27 +01:00
Andrew Kelley
4044a77621 update std.meta.IntType => std.meta.Int 2020-05-01 06:49:30 -04:00
Andrew Kelley
b70e6da914 back to stage2 tests passing 2020-05-01 06:47:56 -04:00
Andrew Kelley
8766821157 rework std.math.big.Int
Now there are 3 types:
 * std.math.big.int.Const
   - the memory is immutable, only stores limbs and is_positive
   - all methods operating on constant data go here
 * std.math.big.int.Mutable
   - the memory is mutable, stores capacity in addition to limbs and
     is_positive
   - methods here have some Mutable parameters and some Const
     parameters. These methods expect callers to pre-calculate the
     amount of resources required, and asserts that the resources are
     available.
 * std.math.big.int.Managed
   - the memory is mutable and additionally stores an allocator.
   - methods here perform the resource calculations for the programmer.
   - this is the high level abstraction from before

Each of these 3 types can be converted to the other ones.

You can see the use case for this in the self-hosted compiler, where we
only store limbs, and construct the big ints as needed.

This gets rid of the hack where the allocator was optional and the
notion of "fixed" versions of the struct. Such things are now modeled
with the `big.int.Const` type.
2020-05-01 06:47:56 -04:00
Andrew Kelley
1d202008d8 add ZIR transform test case 2020-05-01 06:47:20 -04:00
Andrew Kelley
751903ba8f zir: add breakpoint() instruction and object file ability 2020-05-01 06:47:20 -04:00
Andrew Kelley
f89dbe6c4e link: introduce the concept of output mode and link mode 2020-05-01 06:47:20 -04:00
Andrew Kelley
28729efe29 ZIR: implement return instruction 2020-05-01 06:47:20 -04:00
Andrew Kelley
6b0f7de247 ZIR: add cmp and condbr instructions 2020-05-01 06:47:20 -04:00
Andrew Kelley
fb67a7260d link: recognize that Windows does not have POSIX fs modes 2020-05-01 06:47:20 -04:00
Andrew Kelley
56a024bbfc disable stage2 zir tests on not-yet-supported archs 2020-05-01 06:47:20 -04:00
Andrew Kelley
6e6d0eb690 disable stage2 zir tests on not-yet-supported OS's 2020-05-01 06:47:20 -04:00
Andrew Kelley
2bae942800 add ZIR compare output test case to test suite 2020-05-01 06:47:20 -04:00
Jakub Konka
b23a87953a Fast-forward std.os.bits.wasi to match preview1 snapshot ABI
`wasi_snapshot_preview1` introduced a couple of ABI changes. This
commit fast-forwards the types and consts defined in `std.os.bits.wasi`
to match those changes.
2020-04-30 13:28:50 -04:00
wozeparrot
9d79f39844 switch anyerror to OutOfMemory 2020-04-30 12:14:17 -04:00
Vexu
7192ca14b7 Merge pull request #5216 from alexnask/windows_ansi_codes
Progress will now use ANSI escape codes on windows for terminals that support them
2020-04-30 18:35:55 +03:00
Vexu
155029b709 Merge pull request #5223 from iansimonson/translate_c_bool_to_int
Translate-C convert bools to int in complex expressions
2020-04-30 18:28:38 +03:00
Ian Simonson
a2c3ebb756 Use transCreateNodeInfixOp instead of maybeSuppressResult 2020-04-30 19:10:10 +10:00
Vexu
e72f45475d Merge pull request #4683 from LakeByTheWoods/parser_test
Add visible newlines to parser_test output when there's a failure.
2020-04-30 12:04:23 +03:00
Vexu
611bd8e9f4 Merge pull request #5213 from tadeokondrak/evented-readv-fix
Fix std.event.Loop.readv
2020-04-30 11:00:27 +03:00
Vexu
87c9696121 move printWithVisibleNewlines to testing.expectEqualStrings 2020-04-30 10:34:18 +03:00
Vexu
2d06e731ec rename diffIndex to indexOfDiff 2020-04-30 10:33:50 +03:00
Jakub Konka
611a1436f0 Update WASI snapshot to preview1
This commit updates the WASI imports to use `wasi_snapshot_preview1`
instead of the old `wasi_unstable`. There are some minor ABI
differences between the two, however, the main motivator for using
the latest "stable" snapshot (aka preview1) is that, at least in
Wasmtime, there has been a lot of improvement work put into preview1
and unfortunately I might add, the improvements were not (in full)
backported to `wasi_unstable` snapshot.

Also, this commit removes the optional bound on the pointer to
`environ_get` syscall.
2020-04-30 01:52:12 -04:00
Ian Simonson
e6fa0beb33 Translate-C convert bools to int in complex expressions
Pre-requisite for having a test case for #5062
In complex C statements which are outside of macros,
it is valid C to perform e.g. a bitor between an
integer and a boolean `5 | (8 == 9)`

Currently this results in a zig error after translating
as `c_int | bool` is invalid Zig.

Detects if a sub-expression of a numeric operator is
boolean and if so converts it to int
2020-04-30 12:48:27 +10:00
Michael Dusan
a08675723c Merge pull request #5219 from mikdusan/qemu
ci linux: bump qemu 5.0.0-rc4 → 5.0.0
2020-04-29 19:20:20 -04:00
Michael Dusan
e97181e362 ci linux: bump qemu 5.0.0-rc4 → 5.0.0 2020-04-29 17:01:12 -04:00
Alexandros Naskos
61ba52b9e3 Add unreachable branch 2020-04-29 20:07:23 +03:00
wozeparrot
bfb40972a9 build.zig recursive dep support 2020-04-29 12:54:06 -04:00
Alexandros Naskos
273d2de099 Progress will now use ANSI escape codes on windows for terminals that support it 2020-04-29 19:49:02 +03:00
Tadeo Kondrak
07c1be80c2 Fix std.event.Loop.readv 2020-04-29 04:33:29 -06:00
Vexu
15141d865a Merge pull request #5210 from tadeokondrak/IntType-to-Int
std.meta.IntType -> std.meta.Int
2020-04-29 11:01:19 +03:00
Tadeo Kondrak
350b2adacd std.meta.IntType -> std.meta.Int 2020-04-28 19:11:31 -06:00
Tadeo Kondrak
eb183ad9fe rename std.meta.IntType to std.meta.Int
Closes https://github.com/ziglang/zig/issues/5194
2020-04-28 19:11:18 -06:00
Andrew Kelley
5929e5ca0e Merge pull request #5196 from tadeokondrak/@vector-to-@type-vector
`@Vector` -> `@Type(.Vector)`
2020-04-28 16:25:40 -04:00
Andrew Kelley
03dd1fca94 Merge pull request #5195 from tadeokondrak/opaquetype-to-type-opaque
@OpaqueType -> `@Type(.Opaque)
2020-04-28 16:21:07 -04:00
Vexu
db25c78413 Merge pull request #5201 from tadeokondrak/mangle-field-names-locally
Mangle field names with a local counter in records (translate-c)
2020-04-28 23:18:36 +03:00
Tadeo Kondrak
0cf129689e Fix/add translate-c tests for previous commit 2020-04-28 08:45:52 -06:00
Tadeo Kondrak
83d2d7ab8a Mangle field names with a local counter in records
See https://github.com/ifreund/river/issues/17 for an issue that occurs
because the field names are mangled globally. When using the generated
bindings, you have no choice but to use the unstable names or redeclare
the entire struct. This commit changes the behaviour to use a local
counter per record declaration, so the names are predictable each time.
2020-04-28 08:45:51 -06:00
Tadeo Kondrak
0673a8d576 Update language reference for std.meta.Vector 2020-04-28 00:47:14 -06:00
Tadeo Kondrak
f977155fdb @Vector -> std.meta.Vector 2020-04-28 00:47:13 -06:00
Tadeo Kondrak
ee5b358d71 add std.meta.Vector to replace @Vector 2020-04-28 00:24:46 -06:00
Tadeo Kondrak
249938dde0 Validate vector types for @Vector 2020-04-28 00:24:45 -06:00
Tadeo Kondrak
2ef0795bfb Update language reference for recent @Type changes 2020-04-28 00:02:14 -06:00
Tadeo Kondrak
17e41f6cd3 @OpaqueType -> @Type(.Opaque) 2020-04-28 00:02:13 -06:00
wozeparrot
01605a7742 add missing const to pkg dependencies 2020-04-27 18:29:55 -04:00
Andrew Kelley
ecdf75d04e Merge pull request #5187 from ziglang/squeek502-windows-fmt-relative
zig fmt: Fix relative paths with . and .. on Windows as well as forward slashes
2020-04-27 18:28:53 -04:00
Žiga Željko
130435a17a Split AES struct into AESEncrypt and AESDecrypt 2020-04-28 04:52:42 +08:00
Tadeo Kondrak
45f4a1124f implement @Type() for more types 2020-04-27 14:37:18 -04:00
Andrew Kelley
1e04e85200 std: support / in Windows paths 2020-04-27 13:39:06 -04:00
Andrew Kelley
41e17106cd zig fmt: still print the relative path
The previous commit made zig fmt print absolute paths; this commit keeps
the absolute path resolution but still prints the relative paths to
stdout.
2020-04-27 13:38:19 -04:00
Ryan Liptak
fdff381a56 fmt: Fix relative paths with . and .. on Windows
This is a band-aid fix due to NtCreateFile failing on paths with . or .. in them.
2020-04-27 13:35:59 -04:00
Auguste Rame
0df82889cf Fix issue with std.json incorrectly replacing forward slashes with a backslash (#5167)
* fix breaking typo in json.zig

* add tests
2020-04-27 12:22:43 -04:00
George Roman
a17eb15e11 Add missing state to C object cache 2020-04-27 12:21:48 -04:00
Alexandros Naskos
37fa418a94 Cleaned up code, added a testcase for an extern member function call 2020-04-27 18:07:18 +03:00
Alexandros Naskos
908b908481 Added tests. 2020-04-27 15:22:15 +03:00
Alexandros Naskos
179423ec27 Extern functions can now be evaluated to undefined values in TypeOfs 2020-04-27 02:33:21 +03:00
Andrew Kelley
c22b54c9d8 stage2 zir: remove dead code
this was part of the live coding stream and I forgot to delete it before
committing
2020-04-26 17:37:04 -04:00
Henry Nelson
83b0f9c6f7 Fix unfortunate typo 2020-04-26 17:33:04 -04:00
Andrew Kelley
6aeceec1f2 add CLI option -Bsymbolic for binding global references locally 2020-04-26 15:30:52 -04:00
Nick Appleton
28c31a8429 Fix f64 variants of math.cosh and math.sinh to accept negative inputs. (#5172)
* add tests for negative inputs to cosh32 and cosh64. fix bug in cosh64 for negative inputs.

* fix problem with negative input with f64 sinh and add tests
2020-04-26 14:03:19 -04:00
daurnimator
122b992a95 std: add io.MultiOutStream 2020-04-27 02:50:32 +10:00
Andrew Kelley
d44c9bdbd9 ir: elemptr and add instructions 2020-04-26 01:20:58 -04:00
Andrius Mitkus
6481b02fdc std: fix posix Thread.spawn to accept all startFn types 2020-04-25 16:15:25 -04:00
George Roman
0c037a8561 Pass each target feature flag separately 2020-04-25 15:54:02 -04:00
daurnimator
1d6e53756b std: add in_stream.isBytes 2020-04-25 20:42:13 +10:00
daurnimator
b531c0e676 std: add instream.readBytesNoEof function 2020-04-25 20:38:46 +10:00
LemonBoy
a7a8c433d0 stage1: Prevent the creation of illegal ptr types
Closes #5140
2020-04-24 15:55:32 -04:00
Andrew Kelley
7634e67ba5 Merge pull request #5158 from ziglang/zir-to-elf
beginnings of (non-LLVM) self-hosted machine code generation and linking
2020-04-24 15:37:21 -04:00
Andrew Kelley
9ebf25d145 link: change default executable mode to 0o777
Jonathan S writes:

On common systems with a 022 umask, this will still result in a
file created with 755 permissions, but it works appropriately if the
system is configured more leniently. (As another data point, C's fopen
seems to open files with the 666 mode.)
2020-04-24 15:36:08 -04:00
Timon Kruiper
c829f2f7b7 Add mips support to standard library 2020-04-24 15:28:55 -04:00
Andrew Kelley
058937e44d bug fixes to make it work 2020-04-24 02:09:30 -04:00
Andrew Kelley
229e99ca37 codegen: write the updated code size to PT_LOAD section header 2020-04-23 23:53:52 -04:00
Andrew Kelley
2d35f71fa9 codegen rdx set immediate 2020-04-23 20:30:20 -04:00
Andrew Kelley
757d13d784 codegen supports embedded-in-code constants
also coerce no longer requires a bitcast
2020-04-23 20:23:16 -04:00
Andrew Kelley
0ac502f372 codegen for setting rax and rdi registers 2020-04-23 19:40:17 -04:00
Andrew Kelley
63b54bcf51 codegen for inline assembly 2020-04-23 18:58:47 -04:00
Andrew Kelley
99ec614b71 codegen for const ints and string literals 2020-04-23 17:46:01 -04:00
Andrew Kelley
24a01eed90 basics of writing ELF and machine code generation 2020-04-23 16:41:20 -04:00
xackus
ebbd137a0e fix json.WriteStream.emitJson 2020-04-23 22:14:23 +02:00
xackus
a9eb4a6740 stage1: fix crash on accessing an array of size zero with runtime index 2020-04-23 12:45:32 -04:00
LemonBoy
e6428f9401 stage1: Fix bitcast of immediate to ptr type (#5131)
Consider a (legal according to the `@bitCast` rules) conversion from u16
to [2]u8: since the former is a scalar and the latter is a pointer
(arrays are represented at pointers in the codegen phase) we have to
allocate a temporary slot on the stack and then bitcast the resulting
pointer to the desired destination type.

Beware that this means the lifetime of the resulting value is the same
of the function it's contained in and for all intents and purposes
should be regarded as a local (eg. it should not escape).

Closes #4395
Closes #5121
2020-04-23 12:44:16 -04:00
Andrew Kelley
a3dfe36ca1 zir-to-elf skeleton 2020-04-22 23:42:58 -04:00
Michael Dusan
58d5c37409 Merge pull request #5139 from mikdusan/qemu-5.0.0-rc4
Qemu 5.0.0 rc4
2020-04-22 20:41:16 -04:00
Michael Dusan
79809a0e54 ci: bump static-qemu 5.0.0-rc3 → 5.0.0-rc4 2020-04-22 18:02:50 -04:00
Michael Dusan
9a06f966cd Merge pull request #5125 from mikdusan/kern.osproductversion
macos: add fallback version detection
2020-04-22 15:57:29 -04:00
Andrew Kelley
e8545db9d4 Merge pull request #5130 from ziglang/stage2-ir
beginnings of non-LLVM self-hosted backend
2020-04-22 14:42:46 -04:00
LemonBoy
b5e72c0148 stage1: Prevent the creation of illegal pointer types
Changing the pointer length from Unknown to Single/C now resets the
sentinel value too.

Closes #5134
2020-04-22 14:40:57 -04:00
Andrew Kelley
173a143dd0 Merge pull request #5133 from LemonBoy/win-progress
Progressbar for Windows
2020-04-22 12:52:48 -04:00
LemonBoy
0a2519fafb stage2: Allow \t in string literals
Lift the ban on literal tab chars in string literals as they have
nothing to do with code formatting.
2020-04-22 12:48:45 -04:00
LemonBoy
155e631aa6 std: Implement progress for Windows
Use the Win32 API instead of using the VT escape sequences.
2020-04-22 12:58:02 +02:00
LemonBoy
395b530387 stage1: Another hack for the C ABI compatibility
Applying the wrong ABI is slightly better than using the Zig ABI, the
whole thing is so wrong it should be burned to the ground.
2020-04-22 12:52:24 +02:00
Andrew Kelley
1eda2ada9a std.math.big.Int: don't rely on the allocator when printing 2020-04-22 03:49:50 -04:00
Andrew Kelley
d58233b361 ir: improve ZIR emission enough to emit hello world 2020-04-22 03:08:50 -04:00
Andrew Kelley
b1a86040dd ir: emit zir for fntype 2020-04-22 00:26:37 -04:00
Andrew Kelley
993e654554 emit zir skeleton 2020-04-22 00:04:52 -04:00
Andrew Kelley
2e6ccec100 ir: analyze asm instruction 2020-04-21 22:19:32 -04:00
Andrew Kelley
8d3e4147d5 ir: analyze deref instruction 2020-04-21 21:33:55 -04:00
Andrew Kelley
2c11acf807 ir: analyze fieldptr instruction 2020-04-21 21:14:56 -04:00
Andrew Kelley
c12bc8652e ir: analyze ptrtoint 2020-04-21 20:34:40 -04:00
Andrew Kelley
2cdbb5f472 ir: analyze int casting 2020-04-21 19:48:59 -04:00
Michael Dusan
3df0a3a528 macos: add fallback version detection
Fallback to sysctl `kern.osversion` when `kern.osproductversion` is not
available (prior to 10.13.4) .

The mapping from `sw_vers -buildVersion` to `-productVersion` is
formulaic from 10.8 to 10.15 and older is handled with switch.

closes #5119
2020-04-21 18:37:03 -04:00
elucent
48dc3b6fe9 Added peer type resolution for [*]T and *[N]T. 2020-04-21 18:09:03 -04:00
Michael Dusan
412aac8a70 cleanup: IrBasicBlockGen
remove unused param from `ir_ref_inst_gen`
2020-04-21 18:07:48 -04:00
Michael Dusan
73677e178d cleanup: IrBasicBlockGen
remove unused members { parent, index, ref_count }
2020-04-21 18:07:48 -04:00
Haze Booth
78e2a203e3 Remove std.lazyInit 2020-04-21 18:04:37 -04:00
Andrew Kelley
0746028a2a ir: analyze int instruction 2020-04-21 17:54:00 -04:00
Andrew Kelley
69878207e7 ir: analyze as instruction 2020-04-21 17:33:41 -04:00
Andrew Kelley
25679b63eb ir: analyze primitive instruction 2020-04-21 17:11:42 -04:00
Andrew Kelley
8671e8d6d4 ir: analyze fntype instruction 2020-04-21 17:06:09 -04:00
Andrew Kelley
22e7ca5613 ir: analysis of fn instruction 2020-04-21 16:06:15 -04:00
Andrew Kelley
9a2ea5ca42 ir: comptime coerceArrayPtrToSlice 2020-04-21 13:50:04 -04:00
Andrew Kelley
fb63ba2577 ir: type coercion skeleton 2020-04-21 13:24:25 -04:00
Andrew Kelley
8e0bcaca9b ir: analyze str instruction 2020-04-21 01:20:01 -04:00
Andrew Kelley
4c7507cceb ir: semantic analysis skeleton 2020-04-21 00:56:30 -04:00
LemonBoy
aca6b70184 stage1: Handle errors when generating block IR
Closes #5005
2020-04-20 22:39:34 -04:00
Robin Voetter
32e5248820 Remove old-style @typeOf compatibility 2020-04-20 22:38:29 -04:00
Andrew Kelley
cc1c2bd568 simplify ZIR spec; separate parsing/rendering from analysis 2020-04-20 19:21:03 -04:00
LemonBoy
5eaf948e62 stage1: Fix wrong union access
Thanks to @frett27 on irc for reporting the compiler would segfault when
run on ARM.
2020-04-20 13:43:14 -04:00
Andrew Kelley
af4ccf34c1 ir: render keyword parameters 2020-04-19 23:59:00 -04:00
Andrew Kelley
f7786d0ca8 ir: render function body 2020-04-19 23:39:34 -04:00
Andrew Kelley
e74c5a7c24 ir: nice rendering of string literal constants 2020-04-19 20:44:18 -04:00
Andrew Kelley
91ca0e4b02 implement rendering escaped zig string literals 2020-04-19 20:33:15 -04:00
Andrew Kelley
ded6e0326d ir: rendering skeleton 2020-04-19 20:04:11 -04:00
Andrew Kelley
1f3eeb5443 ir: parse type noreturn 2020-04-19 19:31:50 -04:00
Andrew Kelley
104ae419e4 ir: parse export instruction 2020-04-19 19:31:50 -04:00
Andrew Kelley
f020999ca3 ir: parse asm instructions 2020-04-19 19:31:50 -04:00
Andrew Kelley
82e294cf09 ir: parse deref instruction 2020-04-19 19:31:50 -04:00
Andrew Kelley
730dd887e4 ir: parse string literals as parameters 2020-04-19 19:31:50 -04:00
Andrew Kelley
bd37c8d8ed ir: parse ptrtoint 2020-04-19 19:31:50 -04:00
Andrew Kelley
49e2f3ca36 ir: more foolproof way to organize instruction parsing 2020-04-19 19:31:50 -04:00
Andrew Kelley
4cb203db92 ir: parsing integer literals 2020-04-19 19:31:50 -04:00
Andrew Kelley
7127c07f68 ir: parse types 2020-04-19 19:31:50 -04:00
Andrew Kelley
59154a1c51 ir: parse fn body 2020-04-19 19:31:50 -04:00
Andrew Kelley
018daa028e rework types and values data layout 2020-04-19 19:31:50 -04:00
Andrew Kelley
f92ccf365b generic ir parsing framework 2020-04-19 19:31:50 -04:00
Andrew Kelley
bd4280decf beginnings of zig ir parser 2020-04-19 19:31:50 -04:00
LemonBoy
328eb8ed8d stage1: Fix signed multiplication overflow
Spotted thanks to UBSan
2020-04-19 06:46:33 -04:00
Andrew Kelley
051620dcaf Merge pull request #5097 from Vexu/field
Disallow declarations between fields
2020-04-19 03:52:53 -04:00
xackus
d415ffd7d9 fix uninitialized ZigValue 2020-04-19 03:49:36 -04:00
Vexu
b6fe839248 update std lib to decls being disallowed between fields 2020-04-18 23:56:05 +03:00
Vexu
fff00c3bbb disallow declarations between container fields 2020-04-18 23:56:03 +03:00
LemonBoy
6c907a3509 std: Introduce the Once synchronization primitive
The Once object allows the user to execute a function just once in a
thread-safe way.
2020-04-18 15:48:32 -04:00
Andrew Kelley
44ff55091f Merge branch 'cshenton-patch-1'
closes #5085
2020-04-18 14:42:49 -04:00
Andrew Kelley
3817420d42 ziggurat uses @truncate instead of & 0xff
This makes it work on 32-bit targets.

closes #2939
2020-04-18 14:41:33 -04:00
Andrew Kelley
ca38b18879 rand: ref the decls so they get tested 2020-04-18 14:41:25 -04:00
Charles Shenton
e073c8a2b1 Update ziggurat.zig to use random.int(u64)
Ziggurat rng was using deprecated `random.scalar(u64)` which was causing compile errors on calls to public facing stdlib APIs (randExp) on 0.6+, this fixed those errors.
2020-04-18 14:39:36 -04:00
Andrew Kelley
6b2274fd99 Merge pull request #5088 from Vexu/varargs-fix
Add error for non-exter variadic functions
2020-04-18 14:35:35 -04:00
Christian Wesselhoeft
344f4d9bc5 std.os.readv: Add missing iov_count declaration 2020-04-18 14:32:52 -04:00
Vexu
4f02cf32b4 fix typeInfo tests 2020-04-18 11:39:52 +03:00
Andrew Kelley
986aa42d3e update cmake, update readme, in response to the dynamic linking fiasco 2020-04-17 18:41:21 -04:00
Vexu
1afaf42525 add error for non-exter variadic functions 2020-04-17 22:02:49 +03:00
Vexu
c026a9f6d2 fix missing compile errors on builtin cast functions 2020-04-17 14:22:20 -04:00
LemonBoy
8e96922f31 stage1: Fix several bugs in constant generation
The codegen would sometimes change the LLVM type for some constants to
an unnamed structure in order to accomodate extra padding. This is fine
as long as the alignment of each field is still respected and it was not
the case for structure types, leading to ill-formed constants being
generated.

Optional types suffer from this to a lower extent as their layout is
quite lucky, the only missing piece was the tail padding.

Closes #4530
Closes #4594
Closes #4295
Closes my will to live
2020-04-17 13:42:23 -04:00
LemonBoy
a4b1242f0a build: Create the output directory if it doesn't exist
Fixes #5054
2020-04-17 05:12:42 -04:00
LemonBoy
4872311364 debug: Minor QOL improvements for osx
* Handle FileNotFound errors when searching for .o files
* Use the STAB symbol name when everything else fails
2020-04-16 16:21:54 -04:00
Andrius Mitkus
157f566f2d std: make math.clamp work for common uses, remove automatic bounds swapping 2020-04-16 16:19:12 -04:00
Layne Gustafson
480deacbab CC: fix binary dupe with no -o 2020-04-15 12:52:35 -04:00
joachimschmidt557
3fd38429e4 Enable formatting in std.big.Int.format 2020-04-15 12:51:43 -04:00
Vexu
0276d9ddc5 Merge pull request #5046 from Vexu/translate-c
Translate-c correct invalid shortcut
2020-04-15 18:06:38 +03:00
Vexu
ca3bf6e6ad translate-c cleanup and zig fmt 2020-04-15 15:15:32 +03:00
Vexu
a016fb8c62 translate-c: correct invalid shortcut 2020-04-15 15:14:10 +03:00
Jakub
1e23a3cd91 Added gdi32.zig and More user32 definitions 2020-04-14 16:20:48 -04:00
foobles
022a71ca7d Shift error message now says "fixed-width integer type" instead of just "integer type" (#5028)
* error message of ir_analyze_bit_shift now more accurate/specific

* fixed compile error test to match bit shift error message
2020-04-14 16:19:45 -04:00
markfirmware
5974a88794 Update emit_raw.zig 2020-04-14 16:19:01 -04:00
Andrew Kelley
fc48c232e5 cli: add c++ subcommand to --help menu
closes #5034
2020-04-14 13:38:18 -04:00
Lachlan Easton
0122f2cff6 Translate C: Redo Add comment containing c source location for failed decls. 2020-04-14 22:13:43 +10:00
Andrew Kelley
448f8c2eb8 langref: add link to 0.6.0 version 2020-04-13 21:33:08 -04:00
LemonBoy
ce21a784a4 stage1: More fixes for BE targets
* Fix packed struct alignment
* Adjust some tests
2020-04-13 17:35:14 -04:00
Andrew Kelley
cf750a58d5 Release 0.6.0 2020-04-13 13:36:30 -04:00
daurnimator
d29ed2a785 std: fix StreamSource to disallow writing to a const buffer 2020-04-13 13:26:13 -04:00
Pierre Guilleminot
f31e0d9834 docs: use String.repeat for dom templates 2020-04-13 14:03:44 +02:00
daurnimator
b702964ae2 std: fix os.fstatat definition (#5016) 2020-04-13 00:45:39 -04:00
Andrew Kelley
b8796be79d disable flaky event loop test
See #4922
2020-04-12 23:02:39 -04:00
Michael Dusan
e009c1596e Merge pull request #5014 from nmeum/@panic-path
Update documentation of @panic
2020-04-12 18:21:06 -04:00
Pierre Guilleminot
297452cf67 improve search perf: trim search results 2020-04-12 23:17:20 +02:00
Pierre Guilleminot
f76d59ef76 improve search perf: batching dom list mutations 2020-04-12 23:13:57 +02:00
Heppoko
a3b2de1d1e fix file protocol structure definitions (#5015) 2020-04-12 16:45:11 -04:00
emekoi
0744d93ed5 added CI job for mingw 2020-04-12 16:44:29 -04:00
Sören Tempel
6f5a7b8457 Update documentation of @panic
The default panic handler implementation was moved to `builtin.zig`.
2020-04-12 13:08:50 +02:00
daurnimator
8e9e126d41 std: add some basic windows user32 definitions 2020-04-12 02:28:52 -04:00
Michael Dusan
20b2457388 only use -nostdinc++ on c++ files
This is a follow-up to d27ef1aaef
and avoids compiler warnings:

    warning: argument unused during compilation: '-nostdinc++'
2020-04-12 01:03:27 -04:00
Andrew Kelley
d27ef1aaef Zig treats -lstdc++ identically to -lc++
Thanks to Michael Dusan for figuring out what was happening here.

closes #5012
2020-04-12 00:50:16 -04:00
Andrew Kelley
f79faf9008 cmake: allow not finding some clang libs
partial revert of aaf99371b2
because it broke the build for some people
2020-04-11 22:09:17 -04:00
xackus
dbc00e2424 ArrayList: remove old (before span) API 2020-04-11 20:40:34 -04:00
Andrew Kelley
3c34c313cf revert Translate C: Add comment containing c source location for failed decls
This reverts 0db108101a.

Unfortunately this caused a regression. Closes #5007.
2020-04-11 17:56:48 -04:00
Andrew Kelley
4ceaa0595a move fs tests to separate file; disable flaky test
See #5006
2020-04-11 17:50:38 -04:00
Andrew Kelley
c236cbff39 Merge pull request #5003 from emekoi/fix-mingw
fix compilation under mingw
2020-04-11 16:43:38 -04:00
Andrew Kelley
eefe6956fd clarify what "not valid" means 2020-04-11 16:43:19 -04:00
emekoi
de08d283da fix compilation under mingw 2020-04-11 15:18:54 -05:00
emekoi
1a4f46ae7d add note about @tagName for non-exhaustive enums 2020-04-11 01:01:37 -05:00
Andrew Kelley
a6e288d5fe Merge pull request #4711 from leroycep/feature-file-locks
Add lock option to File.OpenFlags and File.CreateFlags
2020-04-10 15:00:45 -04:00
Timon Kruiper
121307679b Fix generated docs of user code
fff3c1fff4 broke the docs generation for
own user code. This adds a workaround, because all the code in docs/main.js
is relying on the fact that the root package of the main package is the
root package itself.
2020-04-10 14:59:51 -04:00
LemonBoy
72dca05f5c debug: Fix parsing of DWARF info for BE machines
Tested with ppc32
2020-04-10 14:59:19 -04:00
Vexu
1b1cbd9358 Merge pull request #4973 from SuperAuguste/nameless-fields
Nameless fields
2020-04-10 21:31:32 +03:00
Auguste Rame
df14578c9d Merge branch 'master' into nameless-fields 2020-04-10 11:49:50 -04:00
Vexu
732c0cb58c Merge pull request #4985 from Vexu/assignment-error
Add missing error message for invalid assignment
2020-04-10 18:26:45 +03:00
Andrew Kelley
4871345545 update readme instructions for homebrew 2020-04-10 01:29:04 -04:00
Andrew Kelley
e857190dab put the previous commit behind cmake option ZIG_PREFER_CLANG_CPP_DYLIB
Without this, building from source caused:

CommandLine Error: Option 'mc-relax-all' registered more than once!
LLVM ERROR: inconsistency in registered CommandLine options

This is due to LLVM static libs compiled in multiple times. But without
the LLVM static libs on the linker line, it caused undefined symbol
linker errors.

So our hands are tied. Homebrew users will have to specify
`-DZIG_PREFER_CLANG_CPP_DYLIB`.
2020-04-10 01:25:15 -04:00
Andrew Kelley
aaf99371b2 look for clang-cpp shared lib when it exists
See #4799
2020-04-10 00:38:19 -04:00
Lachlan Easton
daff072af2 Add visible newlines to parser_test output when there's a failure.
Also print first line that differs between expected and result.
2020-04-10 10:38:36 +10:00
Andrew Kelley
543031db35 Merge pull request #4982 from MageJohn/fix/binarySearch
sort.binarySearch: fix integer underflow (#4980)
2020-04-09 14:58:07 -04:00
joachimschmidt557
f1360bee1c Update docgen to new ArrayList API 2020-04-09 14:57:14 -04:00
Vexu
f60e7348d5 add error message for invalid assignment 2020-04-09 11:50:32 +03:00
Yuri Pieters
f5f77089b7 sort.binarySearch: Remove unneeded edge case check 2020-04-09 09:13:47 +01:00
Andrew Kelley
beae932e0f Merge pull request #4975 from Vexu/param-reassign
Fix missing compile error on assign to slice and array parameters
2020-04-08 21:02:50 -04:00
markfirmware
c3afaa1f58 Update langref.html.in 2020-04-08 21:00:43 -04:00
Michael Dusan
57a2c5a63c ci: bump static-qemu 5.0.0-rc1 → 5.0.0-rc2 2020-04-08 21:00:17 -04:00
Yuri Pieters
b7e72cc421 sort.binarySearch: test for regresson of #4980 2020-04-09 02:00:08 +01:00
Yuri Pieters
447dc2bb90 sort.binarySearch: fix integer underflow (#4980)
When the key was smaller than any value in the array, an error was
ocurring with the mid being zero and having 1 subtracted from it.
2020-04-09 01:58:57 +01:00
LeRoyce Pearson
5951211d3f Reduce file lock test sleep time 2020-04-08 18:03:52 -06:00
Andrew Kelley
c45ba49b8b fix formatted printing warning
needed to use ZIG_PRI_u64 instead of %lu
2020-04-08 19:30:18 -04:00
LeRoyce Pearson
d4161e1667 Close file1 in nonblocking lock test 2020-04-08 16:42:11 -06:00
LeRoyce Pearson
772bb1ade3 Disable open flock flags on darwin
The tests were put into a deadlock, and it seems that darwin doesn't
support `O_SYNC`, though it supports `O_NONBLOCK`. It shouldn't block
even with that, but I'm not sure why else it would fail.
2020-04-08 16:38:58 -06:00
Andrew Kelley
d5087ccbc8 cmake: expose ZIG_TARGET_MCPU option 2020-04-08 17:41:51 -04:00
Andrew Kelley
29ea425ca2 Merge branch 'LakeByTheWoods-translate_ptr_int'
closes #4688
2020-04-08 14:11:16 -04:00
Lachlan Easton
d7902707bc Translate C: Allow casting literal ints to pointers 2020-04-08 14:11:01 -04:00
Vexu
7b5fb79b5b Translate C: Put an alignCast in c style pointer casts to allow opaque types to cast properly in C macros
Translate C: add test case for aligning opaque types in pointer casts
2020-04-08 14:11:01 -04:00
LeRoyce Pearson
d0d7895d33 Return error from else
That removes the other switch cases (`error.WouldBlock` here) from the
error set, I think.
2020-04-08 08:37:17 -06:00
Vexu
b1e44adcba move array and struct const checks to more appropriate places 2020-04-08 14:32:02 +03:00
LeRoyce Pearson
45d6fb9e36 Catch error.WouldBlock as unreachable 2020-04-08 00:39:17 -06:00
Andrew Kelley
b3aef49eea zig provides shlwapi.lib for *-windows-gnu
closes #3711
2020-04-08 01:21:00 -04:00
LeRoyce Pearson
858aefac7f Add OpenFileW share_access_nonblocking parameter 2020-04-07 21:26:46 -06:00
Phil Schumann
b109186dd5 std/zig/parse_string_literal.zig: add hex+unicode escapes (#4678) 2020-04-07 20:27:18 -04:00
LeRoyce Pearson
317f06dc77 Add lock_nonblocking flag for creating or opening files
Also, make windows share delete access. Rationale: this is how it works
on Unix systems, mostly because locks are (usually) advisory on Unix.
2020-04-07 18:00:12 -06:00
LeRoyce Pearson
117d15ed7a Fix file locking on windows
The share_access bitfield was being ORed with what was supposed to be
parts of the default value, meaning that the share_access would be
more permissive than expected.
2020-04-07 16:49:37 -06:00
LeRoyce Pearson
71c5aab3e7 Make lock option an enum
For some reason, this breaks file locking on windows. Not sure if this is
a problem with wine.
2020-04-07 16:49:30 -06:00
xackus
66b2477ab6 fix lazy value in ir_analyze_instruction_elem_ptr 2020-04-07 18:22:17 -04:00
xackus
721c76b53c refactor common pattern into a function 2020-04-07 23:37:33 +02:00
xackus
bf46117f13 std lib docs: fix null and int values 2020-04-07 23:37:01 +02:00
Vexu
ff0f97a1bc fix missing compile error on assign to slice and array parameters 2020-04-08 00:27:14 +03:00
Andrew Kelley
ed23dad487 fix the new runtime-safety tests
Thanks to Vexu's work in e62671f643, compile errors were identified in
these test cases! This commit fixes them to use `const` as appropriate.
2020-04-07 16:05:42 -04:00
SuperAuguste
116c76cf82 fix tests 2020-04-07 15:19:28 -04:00
SuperAuguste
882aa86843 more fixes 2020-04-07 15:08:46 -04:00
Andrew Kelley
4d290758bb fix compile errors in some std.Target functions
The `ve` architecture needed to be added to a couple switch statements.
2020-04-07 15:06:58 -04:00
xackus
b7f116a774 langref: small updates 2020-04-07 14:54:53 -04:00
Andrew Kelley
22dbeab29d Merge pull request #4857 from LemonBoy/fix-4777
Rewrite the bound checks in slice operator
2020-04-07 14:51:25 -04:00
LemonBoy
cc0fca9d83 stage1: Respect the specified name for extern var
Extend the logic used for function definitions to variables.

Closes #4947
2020-04-07 14:48:37 -04:00
Vexu
adaf7ad672 Merge pull request #4684 from LakeByTheWoods/comment_failed_decls
Translate C: Add comment containing c source location for failed decls
2020-04-07 21:47:32 +03:00
SuperAuguste
f21ac0220a msvc fix 2020-04-07 14:39:24 -04:00
Andrew Kelley
87a7ea4c42 Merge pull request #4971 from Vexu/const-ref
Fix missing const on address of literal
2020-04-07 14:24:50 -04:00
joachimschmidt557
1ee59c5c31 move big.rational.gcd to big.int.gcd 2020-04-07 13:43:15 -04:00
SuperAuguste
9298d38cee remove debug statement 2020-04-07 13:33:01 -04:00
SuperAuguste
94841d0292 Nameless struct field consistency 2020-04-07 13:26:17 -04:00
Andrew Kelley
a20f3e3f02 Merge pull request #4972 from mneumann/dragonfly-fix-compile
Fix compile on Dragonfly
2020-04-07 13:04:37 -04:00
Michael Neumann
2b9cef1e04 Add missing constants for DragonFly 2020-04-07 17:23:20 +02:00
Michael Neumann
7a829a7015 Fix paths to find llvm/clang on DragonFly 2020-04-07 17:13:33 +02:00
Vexu
95fefcd4c9 fix broken tests 2020-04-07 16:56:48 +03:00
Vexu
e62671f643 fix missing const on address of literal 2020-04-07 15:25:44 +03:00
LeRoyce Pearson
28d71c97d1 Fix compile error on darwin 2020-04-06 23:19:39 -06:00
LeRoyce Pearson
20597c8596 Only call os.flock on systems that lack openat locks 2020-04-06 22:28:43 -06:00
LeRoyce Pearson
49886d2e45 Remove return value from os.flock() 2020-04-06 22:07:27 -06:00
LeRoyce Pearson
798207ec80 Merge branch 'master' into feature-file-locks 2020-04-06 21:51:57 -06:00
Andrew Kelley
ab05766674 Merge pull request #4966 from ziglang/bootstrap-windows
cmake: improvements to cross-compiling for Windows
2020-04-06 23:16:31 -04:00
Andrew Kelley
fc662ddd54 mingw-w64: add 32-bit version.def
fixes -lversion on 32-bit windows builds
2020-04-06 20:31:00 -04:00
Andrew Kelley
41cb49eb58 stage1 fixes to support building with 32-bit mingw-w64 2020-04-06 20:30:34 -04:00
Andrew Kelley
9ed00b3829 provide ___mb_cur_max_func for i386-windows-gnu 2020-04-06 19:26:31 -04:00
Andrew Kelley
64d0960244 zig cc: recognize a few more linker options
* `--major-image-version`
 * `--minor-image-version`
 * `--stack`
2020-04-06 19:13:36 -04:00
Andrew Kelley
15ab61b2a0 cmake: improvements to cross-compiling for Windows
* don't unconditionally pass -lz3 for mingw builds. If mingw builds
   require this then the llvm-config executable should put it as part of
   --system-libs. If there is a bug and it does not do that, and we need
   a workaround, then the workaround should be an explicit cmake option.
 * don't link libstage2.a against -lntdll. This causes zig to set
   `builtin.link_mode == .Dynamic` and include the TLS definitions,
   which then collide with the mingw-w64 symbols. This should probably
   be addressed separately, but for now this solves the problem and
   there is no reason to link a static library against a DLL.
 * Findllvm.cmake no longer treats the libraries as "optional" and will
   emit a cmake error if one is not found. Additionally, the
   not-required LLVM library LLVMTableGen is omitted.
2020-04-06 18:38:09 -04:00
Andrew Kelley
afa24ccd99 fix the build on Windows
Workaround for issue #2668

Zig std lib currently does not allow forward slashes in Windows path
names.
2020-04-06 18:35:49 -04:00
LemonBoy
0a936c1d76 Add some tests for the runtime safety checks 2020-04-06 20:14:06 +02:00
LemonBoy
a59d31bd28 ir: Support tuple multiplication 2020-04-06 14:03:43 -04:00
Andrew Kelley
e4eb817f79 libc_installation.zig: don't special-case based on C ABI
Whether the C ABI is mingw-w64 or msvc, detection of native libc paths
should be the same. In the future we may want to allow passing a C ABI
parameter to detectNativeCPaths() but for now we have the same behavior
regardless.
2020-04-06 13:33:32 -04:00
Andrew Kelley
96ed544665 build.zig supports specifying config.h location explicitly
also it does not try to run llvm-config executable when -Dlib-files-only

This fixes cross-compiling using the bootstrap repository.
2020-04-06 13:07:19 -04:00
LemonBoy
a0b73c9f02 compiler-rt: Separate max size allowed for load/store and CAS
The v6m ISA has no way to express a CAS loop natively without turning
off the interrupts or using the kernel cmpxchg harness.

On such a platform the user has to provide a few __sync_* builtins to
satisfy the linker.
2020-04-06 12:52:53 -04:00
Vexu
c5ced0d74a Merge pull request #4939 from SuperAuguste/master
translate-c: Properly translate C multicharacter literals
2020-04-06 10:31:17 +03:00
Andrew Kelley
701c03d083 zig uses mingw-w64 to provide -lpsapi 2020-04-05 23:06:47 -04:00
Andrew Kelley
28d9696617 use mingw-w64 to provide -luuid if requested 2020-04-05 23:06:47 -04:00
SuperAuguste
6106cf4419 fixes 2020-04-05 19:06:43 -04:00
Benjamin Feng
cb98984ae6 Generate clearer size mismatch error message 2020-04-05 18:38:19 -04:00
Andrew Kelley
05b587fcde Merge branch 'LemonBoy-vec-div'
closes #4737
2020-04-05 18:34:47 -04:00
Andrew Kelley
e84b9b70ff annotate disabled tests with github issue links 2020-04-05 18:34:32 -04:00
Andrew Kelley
5597b11a52 add runtime safety tests for SIMD integer division 2020-04-05 18:34:31 -04:00
LemonBoy
f6cdc94a50 ir: Fix error checking for vector ops
The extra logic that's needed was lost during a refactoring, now it
should be fine.
2020-04-05 18:34:31 -04:00
LemonBoy
0f964e1910 I'm getting tired of this shit LLVM 2020-04-05 18:34:31 -04:00
LemonBoy
91a8e3b47b tests: Chop away some flaky tests 2020-04-05 18:34:31 -04:00
LemonBoy
fe77c38247 ir: Remove unused and commented out code 2020-04-05 18:34:31 -04:00
LemonBoy
eff7555d5d std: Delete a hack in the feature set code
Now that bitwise not works on vectors we can simplify the code.
2020-04-05 18:34:31 -04:00
LemonBoy
d2d97e55cc ir: Support shift left/right on vectors 2020-04-05 18:34:31 -04:00
LemonBoy
2485f30046 ir: Support bitwise not on vectors 2020-04-05 18:34:31 -04:00
LemonBoy
54ffcf95a8 ir: Support div/mod/rem on vector types
Closes #4050
2020-04-05 18:34:31 -04:00
Andrew Kelley
e2dc63644a type_has_one_possible_value takes comptime struct fields into account
Before, type_has_one_possible_value would return false for the value
`.{1}`. But actually, that type is a tuple with a single comptime field.
Such a type, in fact, has one possible value.

This plus the corresponding adjustment to get_the_one_possible_value
solves #3878.
2020-04-05 17:09:01 -04:00
Vexu
6ef15fc8d0 Merge pull request #4901 from phase/feature/translate-c-remassign
translate-c: RemAssign and DivAssign
2020-04-05 21:05:18 +03:00
Andrew Kelley
607b2661a0 Merge pull request #4942 from daurnimator/tidy-atomics
Tidy up compiler_rt/atomics
2020-04-05 11:13:31 -04:00
daurnimator
4daec63aea .gitattributes: deps/SoftFloat-3e/*.txt lines are crlf terminated 2020-04-05 11:03:31 -04:00
daurnimator
d4d2180148 Convert .gitattributes to use unix line endings 2020-04-05 11:03:31 -04:00
Michaël Larouche
c4a5f519f2 Do not parse native_libc.txt anymore when linking on native target, always run detection of libc.
Fixes #4772
2020-04-05 11:01:35 -04:00
Jadon Fowler
ae376e0758 translate-c: remove unneeded semicolon
Signed-off-by: Jadon Fowler <j@jadon.io>
2020-04-05 10:44:42 -04:00
daurnimator
e9e43ed0d3 compiler_rt/atomics: be consistent with const value 2020-04-05 14:08:25 +10:00
daurnimator
f947444362 Tidy up compiler_rt/atomics 2020-04-05 14:06:12 +10:00
SuperAuguste
027e2a1673 fix multichar literals in translate_c 2020-04-04 17:56:25 -04:00
xackus
cd20e0cc67 rename mem.separate to mem.split 2020-04-04 17:37:51 -04:00
Andrew Kelley
e5d479b06e detect an endless loop when trying to detect native libc installation
closes #4810
2020-04-04 15:03:22 -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
d02838b71a add libutil to zig's glibc support 2020-04-04 14:43:51 -04:00
Andrew Kelley
dc7e8b2fdc build.zig: better detection of using outside zig executable
As pointed out by gereeter, dirname("/") successfully returns "/" again.
So checking for null is not sufficient.
2020-04-04 14:05:49 -04:00
Felix (xq) Queißner
12cdea4525 Adds some documentation to std.atomic.Queue. 2020-04-04 13:47:07 -04:00
Andrew Kelley
cf8728aabd Merge pull request #4935 from LemonBoy/stage1-eb
Big-endian fixes for stage1
2020-04-04 13:45:49 -04:00
Andrew Kelley
d73808f3ff remove zig BUILD_INFO hack
Rather than stuffing configuration information into the Zig binary, the
build script reads it from config.h. This solves a problem for package
maintainers and improves the use case of deterministic builds.

closes #3758
2020-04-04 11:57:28 -04:00
LemonBoy
ad2ebc87f2 stage1: Byteswap floats when serializing them 2020-04-04 16:55:24 +02:00
LemonBoy
084c62f5d1 stage1: Fix serialization of ZigValue on BE machines 2020-04-04 14:06:32 +02:00
Jadon Fowler
391ee996a5 translate-c: account for signedness when translating div & mod
Signed-off-by: Jadon Fowler <j@jadon.io>
2020-04-04 02:16:30 -04:00
Andrew Kelley
e89c42655c Merge pull request #4868 from xackus/new-arraylist-api
new ArrayList API
2020-04-03 22:31:15 -04:00
Michael Dusan
1568470c44 Merge pull request #4891 from mikdusan/issue4207
add compiler-error test: coerce
2020-04-03 21:04:22 -04:00
Michael Dusan
8b6a06eefe add compiler-error test: coerce
Issue fixed by an unknown commit.

closes #4207
2020-04-03 19:11:51 -04:00
Michael Dusan
db4c06ce60 stage1: add compile errors for sentinel slicing
closes #3963
2020-04-03 19:05:30 -04:00
Andrew Kelley
f1425fd9da gitattributes: note that libcxxabi is vendored 2020-04-03 18:36:42 -04:00
Andrew Kelley
a2cad9a3d9 add issue links to disabled test cases 2020-04-03 18:36:13 -04:00
Andrew Kelley
7beea47178 Merge branch 'LemonBoy-compiler-rt-atomics'
closes #4924
2020-04-03 16:08:52 -04:00
Andrew Kelley
e03cbb117e compiler-rt: don't forget to export these functions 2020-04-03 16:07:32 -04:00
LemonBoy
ed69821f5b compiler-rt: Add the __atomic family of builtins
The implementation was checked against a few files using std::atomic and
compiled using zig c++.

Closes #4887
2020-04-03 16:04:44 -04:00
Andrew Kelley
cf52f3f99a zig cc: add -allow-shlib-undefined alias 2020-04-03 13:45:16 -04:00
Andrew Kelley
11b50e3ad8 change the default ABI of riscv64-linux-musl
Before, this would cause a link failure when mixing Zig and C code for
RISC-V targets.

Now, the ABIs match and Zig and C code can be mixed successfully.

I will file a follow-up issue for the ability to deal more explicitly
with ABIs.

closes #4863
2020-04-03 13:13:09 -04:00
markfirmware
203d6554b1 Update fmt.zig 2020-04-03 12:12:40 -04:00
Ryan Liptak
08a9ab4d8c Update all remaining uses of &outStream().stream 2020-04-03 12:12:23 -04:00
LemonBoy
dc54e50db2 std: Fix one more sentinel buffer overrun 2020-04-03 12:03:36 +02:00
LemonBoy
aa5865b9be std: Fix oob slicing operator 2020-04-03 10:58:39 +02:00
LemonBoy
855edd2949 ir: Rewrite the bound checks in slice operator
Closes #4777
2020-04-03 10:58:39 +02:00
LeRoyce Pearson
ea32a7d2bc Fix compile errors about adding error.FileLocksNotSupported 2020-04-03 00:27:34 -06:00
LeRoyce Pearson
4dd0822a36 Add LOCK_* constants to BSD os/bits 2020-04-02 23:50:12 -06:00
LeRoyce Pearson
733f1c25bd Fix compile errors in stage2 2020-04-02 23:39:25 -06:00
LeRoyce Pearson
ea6525797d Use flock instead of fcntl to lock files
`flock` locks based on the file handle, instead of the process id.
This brings the file locking on unix based systems closer to file
locking on Windows.
2020-04-02 22:57:02 -06:00
LeRoyce Pearson
e7cf3f92a9 Add FileLocksNotSupported error to OpenError 2020-04-02 22:12:45 -06:00
LeRoyce Pearson
f757f0ea59 Merge branch 'master' into feature-file-locks 2020-04-02 21:47:41 -06:00
LeRoyce Pearson
35c462caf0 Merge branch 'master' into feature-file-locks 2020-04-02 21:46:48 -06:00
Jay Petacat
0dbf8aaab8 crypto: fix benchmark compile error (#4919) 2020-04-02 23:46:46 -04:00
Andrew Kelley
048da6f631 ci: enable riscv64-linux tests
Thanks to Michael Dusan's work in
deef063bbf these tests can be enabled.
2020-04-02 21:44:03 -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
e7f555ca55 stage1: fix build for i386-linux 2020-04-02 19:07:52 -04:00
Timon Kruiper
b5526d0b3b Fix multiplication overflow in hash_const_val
In some cases the compiler was actually emitting an 64 bit signed
multiplication, instead of a 32 bit unsigned one.
2020-04-02 17:51:04 -04:00
Andrew Kelley
5314641e11 zig cc: support more linker args 2020-04-02 17:29:22 -04:00
Andrew Kelley
c1778bd41f zig cc: support --version-script linker arg
See #4784
2020-04-02 16:59:08 -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
4aa797b6bb Merge branch 'ilmaria-master'
closes #4608
2020-04-02 15:06:50 -04:00
Andrew Kelley
8bf7cffe29 slight modification of the semantics of std.os.getenvW
Now, this function first attempts a case-sensitive lookup.
If no match is found, and `key` is ASCII, then it attempts a
second case-insensitive lookup.

It is not planned to support full Unicode case-insensitivity
on Windows, and in fact relying on non-ASCII case-insensitive
environment variables is fundamentally problematic.
2020-04-02 15:04:42 -04:00
Ilmari Autio
ba1a8b64c4 make std.os.getenvW case insensitive
partially addresses #4603

Fixing std.process.getEnvMap is NOT included in this commit.
2020-04-02 13:01:32 -04:00
Andrew Kelley
503c420797 Merge pull request #4908 from daurnimator/fifo-refactor
Modernize LinearFifo for new stream conventions
2020-04-02 12:13:44 -04:00
Michael Dusan
deef063bbf use static-qemu linux-x86_64 tarball
- no longer install qemu via apt-get
- wget hosted tarball, extract and prepend to path
2020-04-02 11:04:40 -04:00
xackus
7a28c644aa new ArrayList API: fix everything else 2020-04-02 16:12:08 +02:00
xackus
d3ab0eb28d new ArrayList API: fix ArrayList.shrink 2020-04-02 15:15:20 +02:00
xackus
93a20f2e82 new ArrayList API: fix std.ArrayListSentineled 2020-04-02 15:14:28 +02:00
xackus
dd570dbc0d new ArrayList API, fix enough std lib to test 2020-04-02 15:14:18 +02:00
daurnimator
34524a1792 std: add LinearFifo().inStream 2020-04-02 21:14:15 +11:00
daurnimator
2a031c8825 std: LinearFifo matches ArrayList in always having outStream method 2020-04-02 21:07:44 +11:00
Michael Dusan
f6d384450f add compile-error test: bitcast
Issue fixed by an unknown commit.

closes #3818
2020-04-01 18:07:45 -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
Timon Kruiper
eefb0a36c0 Fix CrossTarget.parse test on platforms where abi != gnu
Closes #4902
2020-04-01 18:05:49 -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
LemonBoy
6695fa4f32 ir: Fix comparison of ?T values
The code assumed that every ?T had a pointer child type T, add some more
checks to make sure the type is effectively a pointer.

Closes #4789
2020-04-01 15:56:38 -04:00
Michael Dusan
212e2354b8 stage1: make C++ switch fallthrough an error
Make fallthrough an error when compiler supports it. This requires a new
macro that is defined with such compilers to be used as a statement, at
all fallthrough sites:

    switch (...) {
        case 0:
            ...
            ZIG_FALLTHROUGH;
        case 1:
            ...
            break;
        default:
            ...
            break;
    }

If we ever move to C++17 as minimal requirement, then the macro can be
replaced with `[[fallthrough]];` at statement sites.
2020-04-01 15:56:00 -04:00
Andrew Kelley
0f1f56bb69 Merge pull request #4896 from FireFox317/fix-arm32-stuff
fix some nullptr dereferences on arm-linux-musleabhif
2020-04-01 15:55:31 -04:00
Andrew Kelley
c211b8f91d fix regressions from previous commit 2020-04-01 15:02:31 -04:00
Timon Kruiper
d33766e6c7 Make sure that ZigTypeVector and ZigTypeArray have the same memory layout
Throughout the stage1 code it is assumed that these have the same layout,
but that was not the case. This caused an issue on 32-bit hardware.
2020-04-01 20:50:13 +02:00
Timon Kruiper
ae6965a4e7 Fix undefined behavior when shift amount is 64 2020-04-01 20:50:09 +02:00
Timon Kruiper
d9cf779b47 Fix some nullptr dereferences on arm-linux-musleabhif 2020-04-01 20:38:32 +02:00
Jadon Fowler
b9cb1e0d83 translate-c: add tests for div & rem assignment
Signed-off-by: Jadon Fowler <j@jadon.io>
2020-04-01 14:28:21 -04:00
Jadon Fowler
a255b0f842 translate-c: translate DivAssign & RemAssign
Closes #4790

Signed-off-by: Jadon Fowler <j@jadon.io>
2020-04-01 14:23:26 -04:00
Andrew Kelley
c2e8788259 Merge branch 'daurnimator-less-buffer'
closes #4665
2020-04-01 13:44:19 -04:00
Andrew Kelley
2e806682f4 (breaking) std.Buffer => std.ArrayListSentineled(u8, 0)
This new name (and the fact that it is a function returning a type) will
make it more clear which use cases are better suited for ArrayList and
which are better suited for ArrayListSentineled.

Also for consistency with ArrayList,
 * `append` => `appendSlice`
 * `appendByte` => `append`

Thanks daurnimator for pointing out the confusion of std.Buffer.
2020-04-01 13:30:07 -04:00
Andrew Kelley
553f0e0546 fixups and revert a few things 2020-04-01 11:56:39 -04:00
daurnimator
7eb938c909 Use length field as passed in stage2 libc_installation instead of relying on zero termination 2020-04-01 10:36:38 -04:00
daurnimator
e535057364 std: use std.ArrayList(u8).OutStream instead of std.Buffer.OutStream 2020-04-01 10:36:38 -04:00
daurnimator
3fb030e78a std: use std.ArrayList(u8) instead of std.Buffer in src-self-hosted/translate_c.zig 2020-04-01 10:36:38 -04:00
daurnimator
37e6a64690 std: use Buffer.outStream in std/child_process.zig 2020-04-01 10:36:38 -04:00
daurnimator
ecbc235403 std: use std.ArrayList(u8) instead of std.Buffer in std/build.zig 2020-04-01 10:36:38 -04:00
daurnimator
bb5383cf00 std: don't return sentinel slices from cross_target functions 2020-04-01 10:36:38 -04:00
daurnimator
0ee2462a31 std: add std.ArrayList(u8).outStream() 2020-04-01 10:36:38 -04:00
Andrew Kelley
e8a1e2a1d8 Merge pull request #4894 from LemonBoy/netbsd-p2
More NetBSD bits
2020-04-01 10:24:54 -04:00
Andrew Kelley
0628c2e2ba Merge pull request #4895 from vrischmann/fix-io-tests
Fix io tests
2020-04-01 10:21:27 -04:00
Andrew Kelley
d23f9a164e Remove unneeeded address-of operator 2020-04-01 10:21:17 -04:00
Vincent Rischmann
748b2c72a3 io: fix COutStream test 2020-04-01 13:13:47 +02:00
LemonBoy
5047cd3d78 Workaround for #4789 2020-04-01 12:46:16 +02:00
Vincent Rischmann
f46121b8fc io: fix serialization compilation and tests 2020-04-01 12:37:02 +02:00
Vincent Rischmann
eddf491bf4 io: fix PeekStream compilation 2020-04-01 12:26:49 +02:00
Vincent Rischmann
318abaad02 io: test all files under std/io 2020-04-01 12:24:09 +02:00
LemonBoy
4209ab90a8 std: Use the versioned libc symbols if needed
Many symbols on NetBSD and some on OSX require the definition of an
alias.
2020-04-01 12:23:18 +02:00
LemonBoy
070ace4b22 std: Fix more NetBSD bits
Fix some more libc definitions.
2020-04-01 12:11:19 +02:00
Sebastian
92a423739d mem.zeroes - add sentinel terminated array support 2020-04-01 10:08:29 +01:00
Michaël Larouche
a5af78c376 Fix porting of zlib alder32 with large input 2020-03-31 20:08:42 -04:00
Michael Dusan
e3d12471a2 add compile-error test for #2687
Issue fixed by an unknown commit.

closes #2687
2020-03-31 20:08:00 -04:00
Timon Kruiper
9e019ed26b Fix possible unaligned ptr from getauxval
This caused SIGILL on armv7a-linux
2020-03-31 15:26:06 -04:00
Andrew Kelley
c7a3796734 ci: export master branch version for update-download-page 2020-03-31 14:54:13 -04:00
Bodie Solomon
9bb76f8ce0 Use correct compiler flags in MSVC bootstrap builds of Zig
https://github.com/ziglang/zig/issues/4877

The CMake build of Zig from C++ uses hand-set compiler flags which are
not compatible with the Microsoft C/C++ Optimizing Compiler (cl.exe)
used by Visual Studio.

This commit attempts to conform them to match the Clang/GCC options
under MSVC builds.

Note that CL does not have a concept of C99 or "-O3", and may imply
other optimizations in "/O2" than are implied by Clang/GCC "-O3".

Visual Studio 2019 documentation for cl.exe's optimization options:
https://docs.microsoft.com/en-us/cpp/build/reference/o-options-optimize-code?view=vs-2019

Visual Studio 2019 doc for cl.exe's C++ standard options:
https://docs.microsoft.com/en-us/cpp/build/reference/std-specify-language-standard-version?view=vs-2019
2020-03-31 14:23:34 -04:00
Andrew Kelley
d34a3c66b3 Merge pull request #4543 from daurnimator/cleanup-json
std.json improvements
2020-03-31 12:07:25 -04:00
Andrew Kelley
28b7306a31 Merge pull request #4880 from daurnimator/use-spanZ
Take advantage of mem.spanZ accepting null
2020-03-31 11:57:31 -04:00
Andrew Kelley
d9d8c42426 remove unnecessary inline
works around a bug triggered by previous commit
2020-03-31 11:18:11 -04:00
Andrew Kelley
47a0e3ec5e Merge pull request #4871 from boothby/issue4769
Address bugs when //, /// or //! are immediately followed by EOF
2020-03-31 10:56:21 -04:00
daurnimator
3cf302a71d Tidy up some mem.spanZ use-sites now that null is accepted 2020-04-01 01:50:34 +11:00
Andrew Kelley
6d25e45123 Merge branch 'LemonBoy-more-cache' 2020-03-31 10:49:06 -04:00
Andrew Kelley
0e372ccff5 clean up the duplicate export logic for __clear_cache 2020-03-31 10:48:48 -04:00
daurnimator
b1eb831aba std: fix mem.span* when an optional pointer is passed 2020-04-01 01:44:55 +11:00
LemonBoy
e9c49f423d compiler-rt: More clear_cache implementations 2020-03-31 10:36:12 -04:00
Tetralux
d57b5205c6 Fix std.fifo.LinearFifo
- Fix undeclared variable in 'writeItem'
- Clarify docs of `read` regarding bytes vs. items
- Normalize 'writeable' to 'writable' (the more common parlance)
2020-03-31 10:18:58 -04:00
daurnimator
63409cf422 std: linux syscall numbers are now an extensible enum 2020-03-31 10:16:20 -04:00
Andrew Kelley
839d85e440 fixes to 32-bit handling, to support 32-bit arm 2020-03-31 10:10:31 -04:00
daurnimator
7a3d700fd9 std: introduce json.WriteStream.stringify 2020-04-01 00:13:00 +11:00
daurnimator
42cabe4366 std: use json.StringifyOptions.Whitespace from json.WriteStream 2020-04-01 00:12:59 +11:00
daurnimator
a32d88f12c std: add support to std.json.stringify for null literals 2020-04-01 00:12:59 +11:00
daurnimator
62fbb6b874 std: allow picking between serialising []u8 as string or array 2020-04-01 00:12:59 +11:00
daurnimator
edf487b126 std: add options to std.json.stringfy to control escaping 2020-04-01 00:12:59 +11:00
daurnimator
17f5d04bed std: use json.stringify logic in some json.WriteStream code paths 2020-04-01 00:12:59 +11:00
daurnimator
5a053247e2 std: use stringify from Value.dump; remove other dump helpers 2020-04-01 00:12:59 +11:00
daurnimator
e88543a504 std: add jsonStringify trait to json Value objects 2020-04-01 00:07:31 +11:00
daurnimator
48e7c6cca6 std: add whitespace control to json.stringify 2020-03-31 23:57:00 +11:00
daurnimator
3a0875d9e8 std: have json tests take options parameter 2020-03-31 23:19:24 +11:00
Ali Ahmed
45dc2587a3 Fix Readme to point to llvm for brew commands
* Homebrew has updated llvm to point to llvm@10
2020-03-30 23:21:40 -04:00
Andrew Kelley
1df85d1509 Merge branch 'FireFox317-clear-cache' 2020-03-30 23:15:33 -04:00
Andrew Kelley
83ff94b1cc compiler-rt: don't export __clear_cache when no impl available 2020-03-30 23:15:07 -04:00
Kelly Boothby
1111d3ad13 fixed bugs hitting EOF immediately after //, /// or //! 2020-03-30 18:30:03 -07:00
Kelly Boothby
44aadaff59 added unit tests to demonstrate #4769 and related bugs 2020-03-30 18:29:48 -07:00
Timon Kruiper
f6f03cd90f compiler-rt: implement clear_cache for arm32-linux 2020-03-31 00:29:41 +02: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
6408766d6b linking: remove check for target_supports_libunwind
I'm not sure why this was ever there. Maybe it was working around a
problem with LLVM 9. Anyway this fixes linking C++ code for 32 bit
arm and riscv.
2020-03-30 15:50:53 -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
Andrew Kelley
b980568c81 add peer type resolution for mixed-const []T and *[N]T
closes #4766

This commit also fixes the implementation of some utility functions for
adjusting properties of pointer types. Previously these functions would
incorrectly drop vector, sentinel, and inference metadata.
2020-03-30 13:02:50 -04:00
Sebastian
ef419dd72d mem.zeroes .Array improvements
Before (when given an array with many elements):
```
zig\std\mem.zig:345:13: error: evaluation exceeded 1000
backwards branches
            for (array) |*element| {
            ^
```
related to https://github.com/ziglang/zig/issues/4847#issuecomment-605721461
2020-03-30 11:16:25 -04:00
daurnimator
3be720a729 std: mem span functions can take an optional pointer 2020-03-30 11:04:58 -04:00
LemonBoy
c1cc1ebc35 ir: Avoid constant-folding ptr to sentinels
Constant-folding the pointers to the expected sentinel value have some
big problems: it hides the real content of the array, makes the pointer
to the sentinel point to a completely different memory region and treats
it like a const value even when the underlying array is mutable.

Fixes #4840
2020-03-30 11:03:56 -04:00
daurnimator
8cad453495 std: fix compile error since WinsockError was changed 2020-03-30 11:02:06 -04:00
Brian Cain
607892a30d Create an "LLD_LIBDIRS" var to override lld loc 2020-03-30 11:01:36 -04:00
LemonBoy
1ef6f068f5 compiler-rt: Implement all the shift builtins
* Unify all the code paths with a generic function
* Add some EABI aliases

Closes #4853
2020-03-30 10:58:47 -04:00
daurnimator
9bc8a1e1d0 std: add some missing errnos on linux 2020-03-30 10:55:18 -04:00
daurnimator
356ef3840f std: update for linux 5.6 release 2020-03-30 10:55:18 -04:00
Michael Raymond
de9933761c std.zig.render: fix newlines before DocComments 2020-03-29 22:41:39 -04:00
Andrew Kelley
b717df786b Merge pull request #4845 from xackus/fix-parseFloat
fix overflow in parseFloat and cleanup
2020-03-29 22:40:32 -04:00
Andrew Kelley
f9f7deaeda linking against c++ does not trigger system library directories 2020-03-29 20:58:59 -04:00
xackus
6809222d32 cleanup parse_float.zig 2020-03-29 20:52:25 +02:00
Andrew Kelley
5aa2812507 linking is now aware -lm is provided by mingw-w64 2020-03-29 13:17:21 -04:00
Andrew Kelley
c70471fae6 enable now-passing test cases
These can now be enabled thanks to bug fixes that landed in
LLVM 10.
2020-03-29 10:34:12 -04:00
Andrew Kelley
38a1af5d4f zig cc: -O0 also counts as debug mode 2020-03-29 10:34:12 -04:00
xackus
d1202b1f66 fix overflow in parseFloat 2020-03-29 11:50:41 +02:00
Andrew Kelley
86795c03f9 Merge pull request #4844 from layneson/translatec_string_concat
Support string concatenation in Translate-C
2020-03-29 00:31:50 -04:00
Sebastian
2b0d66736a tcpConnectToHost - fixed compilation error
before:
```
std\net.zig:403:23: error: type '@TypeOf(std.net.getAddressList).ReturnType.ErrorSet!*std.net.AddressList' does not support field access
    const addrs = list.addrs.toSliceConst();
                      ^
```
2020-03-28 21:34:50 -04:00
Layne Gustafson
a55897106e Add macro string concat tests 2020-03-28 20:40:26 -04:00
Layne Gustafson
2a05ca1c94 Conv macro string concat to ++ 2020-03-28 20:40:13 -04:00
LeRoyce Pearson
457f557c37 Merge branch 'master' into feature-file-locks 2020-03-28 17:24:19 -06:00
Andrew Kelley
f9db21f03e Merge pull request #4838 from squeek502/for-linker
zig cc: Add support for -Xlinker, --for-linker, --for-linker=, -z
2020-03-28 12:03:35 -04:00
Luna
2028b4ce91 Fix typo in Serializer declaration 2020-03-28 12:01:29 -04:00
LemonBoy
d788b0cd8b std: Minor changes to TLS handling
* Always allocate an info block per-thread so that libc can store
  important stuff there.
* Respect ABI-mandated alignment in more places.
* Nicer code, use slices/pointers instead of raw addresses whenever
  possible.
2020-03-28 11:20:38 -04:00
Ryan Liptak
cc7c670851 Sync clang_options_data.zig with update_clang_options
Some of the recent c++ related options were added to update_clang_options but didn't make it into clang_options_data.zig
2020-03-28 00:39:33 -07: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
12e1c6e21c Merge pull request #4835 from squeek502/export-dynamic
-rdynamic/--export-dynamic fixes
2020-03-28 02:16:09 -04:00
Andrew Kelley
69aa09948b cmake: support cross compiling 2020-03-27 23:43:21 -04:00
Andrew Kelley
107b5196f6 Merge pull request #4827 from ziglang/zig-cpp
support compiling and linking c++ code
2020-03-27 22:35:13 -04:00
Andrew Kelley
a258741084 initial support of response files
See #4833

It doesn't support comments or quotes yet.
2020-03-27 22:24:40 -04:00
Andrew Kelley
e803490a56 cmake: support finding a cross compiled llvm 2020-03-27 22:24:15 -04:00
Michael Dusan
33819ecfbc windows: don't hard-code forward-slash paths
`zig targets` -> unable to list targets: BadPathName
2020-03-27 21:28:52 -04:00
Andrew Kelley
0d7bd9f3ce Merge pull request #4832 from LemonBoy/watwatwat
Fix the weird-ass crash on AArch64
2020-03-27 21:28:16 -04:00
Ryan Liptak
e7847f8d42 zig cc: Add --export-dynamic linker flag support 2020-03-27 17:42:02 -07:00
Ryan Liptak
1a95f1c2e0 Fix -rdynamic not sending --export-dynamic to the ELF linker 2020-03-27 17:36:43 -07:00
Michael Dusan
547ba8eb20 Merge pull request #4813 from mikdusan/cmake3.17
cmake: address new warnings from cmake-3.17
2020-03-27 19:15:50 -04:00
LemonBoy
ddda50a38d ci: Delete workaround for #4822 2020-03-27 20:13:23 +01:00
LemonBoy
0512be227c compiler-rt: Fix __floatunditf
This builtin converts a u64 into a f128, not a u128 into a f128.

Fixes some weird-ass crashes that happened only on AArch64 systems.
2020-03-27 20:10:59 +01:00
LeRoyce Pearson
c7f4e68464 Merge branch 'master' into feature-file-locks 2020-03-27 11:32:33 -06:00
Andrew Kelley
f407109070 zig c++: get it working with musl and mingw-w64 2020-03-27 12:38:52 -04:00
Timon Kruiper
67e51311c3 fix behavior test with --test-evented-io on windows
also make simple file operations work asynchronously on windows
2020-03-27 17:03:06 +01: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
ed0dbe1a64 add libc++ and libc++abi sources
upstream: LLVM 10
2020-03-26 22:41:26 -04:00
Andrew Kelley
aec4967f36 Merge pull request #4814 from gereeter/reduced-path-max
In AtomicFile, work relative to the destination's parent directory
2020-03-26 20:32:06 -04:00
Andrew Kelley
463b90b977 ci: fix aarch64 linux
This patch adds a workaround for #4822, disables one failing langref
example, and enables the rest of the test suite.

You win some, you lose some.
2020-03-26 19:42:28 -04:00
Jonathan S
cf4cbea88e Factor out arbitrary constant 12 to AtomicFile.RANDOM_BYTES 2020-03-26 15:07:40 -05:00
Andrew Kelley
ab20b351ce update compile error tests 2020-03-26 14:07:19 -04:00
Andrew Kelley
0d4354324c fix behavior tests compile error on i386-linux 2020-03-26 12:54:59 -04:00
Andrew Kelley
ddd98a7f10 prevent ptr cast from forcing alignment resolution unnecessarily 2020-03-26 12:34:16 -04:00
Jonathan S
a779a96d38 In AtomicFile, work relative to the destination's parent directory. This is more robust against concurrent filesystem reorganization and avoids path length issues. 2020-03-25 23:22:36 -05:00
Andrew Kelley
f7f563ea53 Revert "Merge pull request #4807 from LemonBoy/tls-touchups"
This reverts commit ee6fda2297, reversing
changes made to f313ab18ae.

This caused a test failure:

```
behavior.misc.test "behavior-arm-linux-none-Debug-bare-multi thread local variable"...test failure
/home/vsts/work/1/s/lib/std/testing.zig:191:14: 0x4608f in std.testing.expect (test)
    if (!ok) @panic("test failure");
             ^
/home/vsts/work/1/s/test/stage1/behavior/misc.zig:616:11: 0x53e93 in behavior.misc.test "behavior-arm-linux-none-Debug-bare-multi thread local variable" (test)
    expect(S.t == 1235);
          ^
```
2020-03-25 21:12:24 -04:00
Andrew Kelley
5ec6a0ea02 fix an invalid free having to do with bound functions
this should fix the drone CI failure
2020-03-25 21:00:02 -04:00
Andrew Kelley
fae6cf0961 improved handling of native system directories
* `-isystem` instead of `-I` for system include directories
   fixes a problem with native system directories interfering with zig's
   bundled libc.
 * separate Stage2Target.is_native into Stage2Target.is_native_os and
   Stage2Target.is_native_cpu.
2020-03-25 20:34:15 -04:00
Michael Dusan
dd66fbb96a Merge pull request #4811 from mikdusan/fix4634
self-hosted: use fs.selfExePathAlloc
2020-03-25 19:49:52 -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
Benjamin Feng
9dbfee49d7 Carry-over stream error to JSON.stringify 2020-03-25 18:54:04 -04:00
Andrew Kelley
ee6fda2297 Merge pull request #4807 from LemonBoy/tls-touchups
std: Minor changes to TLS handling
2020-03-25 18:53:04 -04:00
Michael Dusan
9cc593ca78 cmake: address new warnings from cmake-3.17
Match package-name case from CMakeLists.txt .

New warning sample:

    The package name passed to `find_package_handle_standard_args` (LLVM) does
    not match the name of the calling package (llvm).  This can lead to
    problems in calling code that expects `find_package` result variables
    (e.g., `_FOUND`) to follow a certain pattern.
2020-03-25 18:43:28 -04:00
Michael Dusan
d554070de1 self-hosted: use fs.selfExePathAlloc
- add fs.selfExePathAlloc
- use fs.selfExePathAlloc instead of fs.selfExeDirPathAlloc
- remove redundant code from fs.selfExeDirPath

closes #4634
2020-03-25 18:40:28 -04:00
Andrew Kelley
f313ab18ae zig cc: freestanding target implies -nostdlib 2020-03-25 12:28:41 -04:00
Andrew Kelley
6cbe589b51 zig cc: support -T linker script option 2020-03-25 12:05:48 -04:00
Andrew Kelley
3869e80331 Merge pull request #4793 from LemonBoy/netbsd-forever
Netbsd forever
2020-03-25 10:19:49 -04:00
LemonBoy
abcd9ac9d0 Use const instead of var 2020-03-25 12:37:44 +01:00
LemonBoy
a34f67aa66 std: Minor changes to TLS handling
* Always allocate an info block per-thread so that libc can store
  important stuff there.
* Respect ABI-mandated alignment in more places.
* Nicer code, use slices/pointers instead of raw addresses whenever
  possible.
2020-03-25 12:08:50 +01:00
LemonBoy
778dbc17ac std: Fix setsockopt definition
* Add socketpair definition
2020-03-24 16:06:25 -04:00
Andrew Kelley
cbaede7f55 Merge pull request #4795 from LemonBoy/divtf3
Add __divtf3 to compiler-rt
2020-03-24 14:51:51 -04:00
LemonBoy
3ccf99c0bd std: Slim duplicate logic for some calls 2020-03-24 19:47:18 +01:00
LemonBoy
cc774c603b compiler-rt: Add __divtf3 2020-03-24 18:08:53 +01:00
LemonBoy
4e95662a4a std: Add qNaN constants 2020-03-24 18:08:53 +01:00
Andrew Kelley
39589cffe0 compiler-rt: fix __clear_cache on aarch64 darwin 2020-03-24 11:51:13 -04:00
Andrew Kelley
03013e5176 compiler-rt: aarch64 implementation of __clear_cache 2020-03-24 10:33:23 -04:00
Andrew Kelley
93c7fa105f Merge remote-tracking branch 'origin/llvm10'
LLVM 10 was released today
2020-03-24 09:57:09 -04:00
LeRoyce Pearson
1a6c3aeec9 Block until file is unlocked on windows 2020-03-23 23:20:17 -06:00
LeRoyce Pearson
8bec1304c3 Fix compile error on windows 2020-03-23 22:34:00 -06:00
LeRoyce Pearson
113b217593 Merge branch 'master' into feature-file-locks 2020-03-23 21:39:16 -06:00
Joachim Schmidt
5acc8afb5f Use math.Order for comparing bigints instead of i8 (#4791) 2020-03-23 23:16:57 -04:00
LeRoyce Pearson
0b93932a21 Add O_SHLOCK and O_EXLOCK to freebsd and netbsd 2020-03-23 21:07:50 -06:00
LeRoyce Pearson
5b278fb606 Use locking open flags if they are defined 2020-03-23 20:59:09 -06:00
LemonBoy
c3f93be00c std: Tell pthread the guard page size is zero
On NetBSD this is needed to avoid crashes in pthread_join as the default
value for the guard page size is not ignored even though a custom stack
address is specified.
2020-03-23 23:26:34 +01:00
LemonBoy
d6739b1397 std: Fix undefined field error 2020-03-23 23:26:21 +01:00
LemonBoy
b21d3535a5 std: Fix parameters for pthread_attr_setstack
The guard page size shouldn't be taken into account, pthread is only
interested in the usable area.
2020-03-23 20:12:10 +01:00
LemonBoy
09a5f172f8 std: Different thread stack allocation for NetBSD
* NetBSD is stricter than other OSs and doesn't allow mprotect to mark a
  non-accessible region as RW
* Fix mprotect call over the whole stack, oops
2020-03-23 19:50:29 +01:00
LemonBoy
cda73c3c18 std: Add missing C bits and defines for NetBSD 2020-03-23 18:55:45 +01:00
LemonBoy
761602e3e8 std: Use getdents on all the BSDs
* Use the correct versioned libc calls to avoid nasty surprises
2020-03-23 18:54:14 +01:00
LemonBoy
336ed03f0f debug: Accept relative paths in mapWholeFile 2020-03-23 18:51:49 +01:00
LemonBoy
27344464ed std: Add missing C defines for NetBSD 2020-03-23 18:47:40 +01:00
LemonBoy
2f21c8f5ba stage1: Link pthread on NetBSD 2020-03-23 18:47:39 +01:00
LemonBoy
bab66235b9 stage1: Remove fflush on file open for reading
On NetBSD this caused the libuserland compilation to fail.

Closes #3719
2020-03-23 17:17:28 +00:00
Andrew Kelley
dc44fe053c zig cc: detect dynamic linker argument 2020-03-23 12:39:18 -04:00
Andrew Kelley
e643b414e4 zig cc: recognize .S and .C as source file extensions 2020-03-23 11:34:16 -04:00
LemonBoy
0cd953d40e ir: Prevent crash when slicing hardcoded pointer
Closes #4780
2020-03-23 09:13:52 -04:00
Andrew Kelley
13d04f9963 Merge pull request #4741 from momumi/master
allow `_` separators in number literals (stage 1)
2020-03-23 00:54:54 -04:00
Andrew Kelley
94f7c56001 riscv: add -mrelax arg for C to work around upstream issue
See #4485
2020-03-22 21:47:19 -04:00
Andrew Kelley
e5e5196d8e Merge remote-tracking branch 'origin/master' into llvm10 2020-03-22 20:48:21 -04:00
momumi
2d18178c27 minor fixes and more tests for _ separators
* Make the tokenizer spit out an Invalid token on the first invalid
  character found in the number literal.
* More parsing and tokenizer tests for number literals
* fix invalid switch statement in ir.zig
2020-03-23 09:21:34 +10:00
Andrew Kelley
7ffdf59c44 Merge pull request #4774 from ziglang/zig-cc
ability to use `zig cc` as a drop-in C compiler
2020-03-22 19:20:02 -04:00
LemonBoy
9d19d9008e debug: Correct version check in debug_line parser
Version 3 is similar to version 2 plus more opcodes.
2020-03-22 19:19:41 -04:00
LemonBoy
6a89751025 ir: Implement cast from anon struct to union 2020-03-22 19:06:22 -04:00
Andrew Kelley
3bded9cf29 disable failing stack trace test for aarch64 2020-03-22 18:54:19 -04:00
Andrew Kelley
380c276deb ci: disable qemu-riscv64 tests due to qemu being too old 2020-03-22 17:36:58 -04:00
Andrew Kelley
f9992850a5 simplify cmake logic for finding clang
which fixes the build on windows
2020-03-22 17:35:06 -04:00
Andrew Kelley
87b8b69eb0 update stack trace test expected output 2020-03-22 17:07:24 -04:00
Andrew Kelley
10223eaea0 ci: workaround for apt.llvm.org packaging bug 2020-03-22 17:03:53 -04:00
Andrew Kelley
40f4101802 ci: fix ubuntu package name for lld 2020-03-22 15:44:39 -04:00
Andrew Kelley
8d1659bb39 ci: again fix the cache tarball URLs 2020-03-22 15:35:54 -04:00
Andrew Kelley
adf5af1bc5 ci: update cache tarball URLs 2020-03-22 15:14:46 -04:00
Andrew Kelley
23c263776c Merge remote-tracking branch 'origin/master' into llvm10 2020-03-22 15:09:29 -04:00
momumi
8de45e5143 update parsing of int literals in self-hosted
* update std.math.big.Int.setString() to ignore underscores and make it
  case insensitive
* fix issue in ir.zig with leading zeroes in integer literals
2020-03-22 13:59:14 +10:00
dbandstra
a8fa1ecd89 fix build.zig addBuildOption function for stream refactor 2020-03-21 23:18:09 -04:00
momumi
29324e6f39 fix formatting in tokenizer tests 2020-03-22 12:41:11 +10:00
Andrew Kelley
2b65dc1032 zig cc: detect optimization and debug flags 2020-03-21 22:30:46 -04:00
LemonBoy
dc79f181a5 ir: Disallow comparison between enum literal and untagged enum
Closes #4770
2020-03-21 20:54:05 -04:00
momumi
138dab4524 add number _ separators for stage 2 tokenizer 2020-03-22 10:35:19 +10: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
4d9b458f8f zig cc: support .cc and .cxx extensions 2020-03-21 16:51:43 -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
Andrew Kelley
a4eaeee720 ability to use zig cc as a drop-in C compiler
The basics are working
2020-03-21 15:39:39 -04:00
Andrew Kelley
beea478acc Merge pull request #4764 from LemonBoy/fix-1265
ir: Allow errdefer with payload
2020-03-21 14:19:52 -04:00
LemonBoy
28dbc58837 Address review comments 2020-03-21 09:54:49 +01:00
LemonBoy
128e70ff3a ir: Allow errdefer with payload
Closes #1265
2020-03-21 09:54:49 +01:00
Andrew Kelley
153c6cf92e ci: disable test-gen-h on sr.ht and drone 2020-03-20 21:33:37 -04:00
Andrew Kelley
3a2c490889 "generate .h files" feature is no longer supported in stage1 2020-03-20 18:33:36 -04:00
Andrew Kelley
8429ddecf8 Merge branch 'glibc-add-ld' 2020-03-20 15:48:57 -04:00
Andrew Kelley
7438d0fc31 glibc: include ld symbols and proper soname for ld 2020-03-20 14:39:05 -04:00
Andrew Kelley
ef69e4efa0 Merge branch 'mt-panic' of https://github.com/LemonBoy/zig into glibc-add-ld 2020-03-20 13:02:19 -04:00
Andrew Kelley
245dc9d930 include ld symbols when generating glibc dummy objects
closes #4748
2020-03-20 12:59:37 -04:00
LemonBoy
541e763010 ir: Peer type resolution between ?[]T and *[N]T
Closes #4767
2020-03-20 12:23:05 -04:00
Andrew Kelley
53b5aa812b Merge remote-tracking branch 'origin/master' into llvm10 2020-03-19 22:19:24 -04:00
Andrew Kelley
28a6c136e9 revert std.mem.span to prefer len over sentinel; add spanZ 2020-03-19 19:30:09 -04:00
Andrew Kelley
dc04e97098 Merge pull request #4752 from ziglang/slice-array
slicing with comptime start and end indexes results in pointer-to-array
2020-03-19 18:06:16 -04:00
Andrew Kelley
160367e0dd fix compile error for reading past end of pointer casted array 2020-03-19 17:23:53 -04:00
Andrew Kelley
6b6f2fcf96 std.net: remove the hack from earlier in the branch 2020-03-19 15:09:52 -04:00
Andrew Kelley
f614d94faa update std lib to take advantage of slicing with comptime indexes 2020-03-19 14:48:47 -04:00
Andrew Kelley
555a2c0328 (breaking) std.fs.copyFile now integrates with Dir
Removed:
 * `std.fs.updateFile`
 * `std.fs.updateFileMode`
 * `std.fs.copyFile`
 * `std.fs.copyFileMode`

Added:
 * `std.fs.Dir.copyFile`
 * `std.fs.copyFileAbsolute`
 * `std.fs.updateFileAbsolute`

Moved:
 * `std.fs.Dir.UpdateFileOptions` => `std.fs.CopyFileOptions`

Deprecated:
 * `std.fs.deleteDir`
 * `std.fs.deleteDirC`
 * `std.fs.deleteDirW`
 * `std.fs.readLink`
 * `std.fs.readLinkC`
2020-03-19 14:43:41 -04:00
Andrew Kelley
1d7861a36e fix incorrect sentinel check 2020-03-19 13:18:14 -04:00
Andrew Kelley
8ddf9d84ff add behavior tests for slicing with comptime indexes 2020-03-19 11:17:46 -04:00
Andrew Kelley
f824658e13 slicing sentinel-terminated slice without end
now results in a sentinel-terminated slice.
2020-03-19 10:54:20 -04:00
Andrew Kelley
61266d2621 test & docs fixups to work with new semantics 2020-03-19 09:53:55 -04:00
Andrew Kelley
7fa88cc0a6 std lib fixups for new semantics
std lib tests are passing now
2020-03-19 09:53:55 -04:00
Andrew Kelley
b5dba702ff fixes to std.meta
behavior tests are passing now
2020-03-19 09:53:55 -04:00
Andrew Kelley
2164b511cc partial revert of an improvement this branch made
because it uncovered a result location bug, and I need to get this
branch merged before going into a result location rabbit hole.

also fix the result type of slicing when the indexes are runtime known
and the result should be sentinel terminated.
2020-03-19 09:53:55 -04:00
Andrew Kelley
8688c43745 when result loc is a slice, avoid evaluating lazy start..end
This prevents lazy values from being unnecessarily evaluated.
2020-03-19 09:53:55 -04:00
Andrew Kelley
e947f0c740 0-bit array type does not resolve child type 2020-03-19 09:53:55 -04:00
Andrew Kelley
72a261b4d3 fix runtime slice of pointer not setting length 2020-03-19 09:53:55 -04:00
Andrew Kelley
4435b05b6b fix regression when slicing 0-bit pointers 2020-03-19 09:53:55 -04:00
Andrew Kelley
2b4134459d fix alignment when slicing with comptime start and end index 2020-03-19 09:53:54 -04:00
Andrew Kelley
8ea0a00f40 improve std lib code for the new semantics 2020-03-19 09:53:54 -04:00
Andrew Kelley
8d0ac6dc4d @ptrCast supports casting a slice to pointer 2020-03-19 09:53:54 -04:00
Andrew Kelley
c896c5001f fix slice of string literal having the wrong type 2020-03-19 09:53:54 -04:00
Andrew Kelley
0707be8de8 fixes in semantic analysis needed to support this feature 2020-03-19 09:53:54 -04:00
Andrew Kelley
2182d28cb0 slicing with comptime start and end results in array
implements #863
2020-03-19 09:53:51 -04:00
LemonBoy
e3c92d0532 ir: More changes to sentinel-terminated const arrays
* Don't add an extra slot for the sentinel. Most of the code keeps using
  the constant value from the type descriptor, let's harmonize all the
  code dealing with sentinels.

* Properly write out sentinel values when reinterpreting pointers at
  comptime.

* Allow the reading of the 0th element in a `[0:S]T` type.
2020-03-19 09:53:30 -04:00
Andrew Kelley
7a361751e5 Merge branch 'LemonBoy-travbug'
closes #4747
2020-03-18 16:42:58 -04:00
Andrew Kelley
46ffc798b6 fix swapped logic for Windows
Remove `std.fs.deleteTree`. Callers instead should use
`std.fs.cwd().deleteTree`.

Add `std.fs.deleteTreeAbsolute` for when the caller has an absolute
path.
2020-03-18 16:42:47 -04:00
Andrew Kelley
27affde592 (breaking) clarify openDir API
* remove deprecated `std.fs.Dir` APIs
 * `std.fs.Dir.openDir` now takes a options struct with bool fields for
   `access_sub_paths` and `iterate`. It's now much more clear how
   opening directories works.
 * fixed the std lib and various zig code calling the wrong openDir
   function.
 * the runtime safety check for dir flags is removed in favor of the
   cheaper option of putting a comment on the same line as handling
   EBADF / ACCESS_DENIED, since that will show up in stack traces.
2020-03-18 16:10:57 -04:00
LemonBoy
c45fe2759f build: Fix silly bug in directory traversal 2020-03-18 13:45:52 -04:00
LemonBoy
e15605e1c1 std: Safety check for iterate()
Calling iterate() on a Dir object returned by openDirTraverse is always
an error.
2020-03-18 13:45:52 -04:00
LemonBoy
4843c3b4c3 std: Introduce fnctl wrapper 2020-03-18 13:45:52 -04:00
Andrew Kelley
b1537b525f Merge branch 'LemonBoy-fix-4749'
Closes #4750
Closes #4749
2020-03-18 11:16:25 -04:00
LemonBoy
11a4ce42c1 zig fmt: Respect trailing commas in error set declarations
The logic is not perfect as it doesn't take into account the presence of
doc comments, but it's an improvement over the status quo.
2020-03-18 11:15:22 -04:00
Andrew Kelley
63a4dbc30d array sentinel does not count towards type_has_one_possible_value 2020-03-18 11:11:41 -04:00
LemonBoy
1479c28b49 ir: Correct ABI size calculation for arrays
Zero-length array with a sentinel may not have zero size.

Closes #4749
2020-03-18 11:10:45 -04:00
LemonBoy
013ada1b59 std: More type checks for Thread startFn return type
Closes #4756
2020-03-18 10:37:35 -04:00
Andrew Kelley
dbde5df568 clean up some self-hosted bitrot + don't assume libstdc++
closes #4682

The self-hosted compiler is still bit rotted and still not compiling
successfully yet. I have a more serious rework of the code in a
different branch.
2020-03-17 23:03:45 -04:00
LeRoyce Pearson
613956cc47 Remove fcntlFlock and replace with plain fcntl 2020-03-17 21:02:19 -06:00
LeRoyce Pearson
32c5825030 Match netbsd's flock fields with others 2020-03-17 20:54:38 -06:00
LeRoyce Pearson
b773a8b175 Make fcntlFlock follow conventions of os.zig 2020-03-17 20:53:43 -06:00
Jonathan Marler
7251eb1681 fix a couple sockfds to be fd_t rather than i32
Using i32 causes compile errors on Windows because it uses *c_void rather than i32 for it's fd_t type.
2020-03-17 12:46:07 -04:00
LeRoyce Pearson
4532f5ecad Change fcntl params to ?*c_void
As recommended by LemonBoy
2020-03-16 21:50:52 -06:00
Timon Kruiper
6a15d668ee Change the default stdin behavior of RunStep to .Inherit
This behaves the same as stdout and stderr behavior which also
default to .inherit. Also adds a field to RunStep to change the behavior.

Since this is a breaking change, previous behavior can be restored by doing:
`RunStep.stdin_behavior = .Ignore`.
2020-03-16 17:23:53 -04:00
LemonBoy
582991a5a8 build: Expose function-sections switch 2020-03-16 13:06:50 -04:00
Andrew Kelley
a2432b6755 Merge pull request #4735 from ziglang/renameat
zig build system: correctly handle multiple output artifacts
2020-03-15 17:28:12 -04:00
Andrew Kelley
a27a8561e9 adjust renameatW to always supply dest root dir
this fixes tests for wine
2020-03-15 17:26:29 -04:00
Andrew Kelley
7e45a3ef6a fix typo in new mem.len test 2020-03-15 15:57:51 -04:00
Andrew Kelley
e369789062 fix std.os.renameatW
Ask for DELETE access when opening the source file.

Additionally, when the source and dest dir are the same, pass null
for RootDirectory.
2020-03-15 15:47:42 -04:00
Andrew Kelley
6c2b23593b fix std.mem.span handling of sentinel-terminated arrays
previously this function would use the array length, but now it scans
the array looking for the first sentinel that occurs.
2020-03-15 15:46:56 -04:00
Andrew Kelley
701aaf0ddf renameatW: handle more windows nt status codes 2020-03-15 14:46:09 -04:00
Andrew Kelley
0a69a10f2a Merge pull request #4740 from Vexu/cleanup
Cleanup and a fix in self-hosted parser
2020-03-15 14:18:33 -04:00
momumi
880d8fc380 fix Serializer to work with new OutStream API 2020-03-15 14:17:16 -04:00
momumi
47f7e66580 add more test cases for invalid number literals 2020-03-15 23:42:29 +10:00
momumi
925f710852 make parsing 0.0_e1 an error 2020-03-15 13:05:24 +10:00
momumi
7aac21c6f5 allow _ separators in number literals (stage 1)
* Underscores `_` may be placed between two digits in a int/float literal
* Consecutive underscores are not allowed
* Fixed parsing bug in exponents of hexadecimal float literals.
  Exponents should always be base 10, but hex characters would be parsed
  inside the exponent and everything after them would be ignored. eg:
  `0x1.0p1ab1` would be parsed as `0x1.0p1`.
2020-03-15 12:38:35 +10:00
LeRoyce Pearson
819537d70a Skip file lock test in single threaded mode 2020-03-14 20:36:26 -06:00
LeRoyce Pearson
947abb7626 Fix compile error on windows 2020-03-14 17:13:46 -06:00
Vexu
57f9f07558 use anon literals in ast.zig and parse.zig 2020-03-15 01:11:58 +02:00
Vexu
5e5dee829d remove .Cancel correct merge err set parsing 2020-03-15 01:02:33 +02:00
LeRoyce Pearson
49128c86f8 Extract run_lock_file_test 2020-03-14 15:31:54 -06:00
Andrew Kelley
a77386eb98 for build-obj with only 1 C file, name .o file after root_out_name 2020-03-14 17:11:51 -04:00
LeRoyce Pearson
7ab77685a8 Make lock tests more flexible 2020-03-14 14:57:56 -06:00
LeRoyce Pearson
873c7a59e9 Add multiple read lock test 2020-03-14 13:29:49 -06:00
LeRoyce Pearson
72eb9933fd Call std.os.waitpid instead of std.os.linux.waitpid 2020-03-14 11:34:38 -06:00
LeRoyce Pearson
43ccc2d81e Add note about mandatory locks on linux 2020-03-14 10:12:46 -06:00
LeRoyce Pearson
43c4faba55 Add test to check that locking works 2020-03-14 10:12:46 -06:00
LeRoyce Pearson
a636b59cb5 Add lock option to CreateFlags 2020-03-14 10:12:46 -06:00
LeRoyce Pearson
4eff48b12e Add flock command paramter to os.fcntlFlock
Also, replace `os.fcntlFlockBlocking` with `os.fcntlFlock`
2020-03-14 10:12:46 -06:00
LeRoyce Pearson
f66a607607 Define Flock for all posix systems 2020-03-14 10:12:46 -06:00
LeRoyce Pearson
e1868029e9 Implement blocking file locking API for windows 2020-03-14 10:12:46 -06:00
LeRoyce Pearson
9af0590a28 Add fnctlFlock system call, use it to lock files 2020-03-14 10:12:46 -06:00
LeRoyce Pearson
3110060351 Add lock to fs.File.OpenFlags 2020-03-14 10:12:46 -06:00
Andrew Kelley
4a8e766ef5 fix mismatch between expected and actual output name 2020-03-14 01:26:49 -04:00
Andrew Kelley
faa3c40b54 fix docgen, which relied on stdout being path to binary 2020-03-14 00:46:40 -04:00
Andrew Kelley
66d7370fac special case when doing build-obj with just one source file
When building an object file from only one source file, instead of
having a two-stage cache system, we special case it and use the cache
directory that the .o file is output to as the final cache directory for
all the build artifacts.

When there are more than 1 source file, the linker has to merge objects
into one, and so the two stage approach makes sens. But in the case of
only one source file, this prevents needlessly copying the object file.

This commit fixes an issue with the previous one, where zig with cache
enabled would print a directory that actually did not have any build
artifacts in it.
2020-03-13 23:59:36 -04:00
Andrew Kelley
66e76a0209 zig build system: correctly handle multiple output artifacts
Previously the zig build system incorrectly assumed that the only build
artifact was a binary. Now, when you enable the cache, only the output
dir is printed to stdout, and the zig build system iterates over the
files in that directory, copying them to the output directory.

To support this change:

 * Add `std.os.renameat`, `std.os.renameatZ`, and `std.os.renameatW`.
 * Fix `std.os.linux.renameat` not compiling due to typos.
 * Deprecate `std.fs.updateFile` and `std.fs.updateFileMode`.
 * Add `std.fs.Dir.updateFile`, which supports using open directory
   handles for both the source and destination paths, as well as an
   options parameter which allows overriding the mode.
 * Update `std.fs.AtomicFile` to support operating based on an open
   directory handle. Instead of `std.fs.AtomicFile.init`, use
   `std.fs.Dir.atomicFile`.
 * `std.fs.AtomicFile` deinit() better handles the situation when the
    rename fails but the temporary file still exists, by still
    attempting to remove the temporary file.
 * `std.fs.Dir.openFileWindows` is moved to `std.os.windows.OpenFileW`.
 * `std.os.RenameError` gains the error codes `NoDevice`,
   `SharingViolation`, and `PipeBusy` which have been observed from
   Windows.

Closes #4733
2020-03-13 21:22:08 -04:00
Andrew Kelley
75bda408cd update stack traces test expectations 2020-03-13 17:50:29 -04:00
Noam Preil
eb4d313dbc Fix compilation with --no-emit-bin 2020-03-13 15:40:29 -04:00
Andrew Kelley
656ba530d8 Merge remote-tracking branch 'origin/master' into llvm10 2020-03-13 15:17:53 -04:00
LemonBoy
2501e80500 Even better idle waiting method 2020-03-13 19:20:18 +01:00
LemonBoy
e496ef26da Nicer idle wait loop
Trying to acquire twice the same mutex generates an idle loop.
2020-03-13 18:40:18 +01:00
LemonBoy
edcf8e0636 std: Multithreaded-aware panic handler
Gracefully handle the case of several threads panicking at the same
time.
2020-03-13 17:55:40 +01:00
Andrew Kelley
3eff77bfb5 Merge branch 'fengb-format-stream' 2020-03-13 12:07:06 -04:00
Andrew Kelley
4905102901 fix all the TODOs from the pull request
* `std.Buffer.print` is removed; use `buffer.outStream().print`
 * `std.fmt.count` returns a `u64`
 * `std.Fifo.print` is removed; use `fifo.outStream().print`
 * `std.fmt.bufPrint` error is renamed from `BufferTooSmall`
   to `NoSpaceLeft` to match `std.os.write`.
 * `std.io.FixedBufferStream.getWritten` returns mutable buffer
   if the buffer is mutable.
2020-03-13 12:02:58 -04:00
Andrew Kelley
2dd920ee39 Merge branch 'format-stream' of https://github.com/fengb/zig into fengb-format-stream 2020-03-13 11:31:11 -04:00
Andrew Kelley
a9297f2267 Merge pull request #4716 from LemonBoy/sys-misc
Introduce std.fs.file.setEndPos
2020-03-13 11:18:08 -04:00
LemonBoy
de53537f10 Add NtDll-based ftruncate implementation 2020-03-13 08:45:37 +01:00
Andrew Kelley
5dd3c8eed6 Merge pull request #4727 from nrdmn/uefi3
std/os/uefi: various improvements and some refactoring
2020-03-12 20:58:29 -04:00
Andrew Kelley
2f06971a7e Merge pull request #4725 from ziglang/update-musl
Upgrade musl libc to 1.2.0
2020-03-12 19:56:38 -04:00
Andrew Kelley
f51bec321b Merge pull request #4707 from Vexu/small-atomics
Support atomic operations with bools and non power of two integers
2020-03-12 18:55:16 -04:00
Nick Erdmann
f44530302e std/os/uefi: file protocol improvements 2020-03-12 23:23:21 +01:00
Nick Erdmann
92beb13914 std/os/uefi: status reform 2020-03-12 23:23:12 +01:00
Nick Erdmann
6c368b9e73 std/os/uefi: device path protocol improvements 2020-03-12 23:23:02 +01:00
Nick Erdmann
9f475dae14 std/os/uefi: Add shell parameters protocol 2020-03-12 23:22:49 +01:00
Nick Erdmann
52eb4129de std/os/uefi: loaded image protocol improvements 2020-03-12 23:22:08 +01:00
Nick Erdmann
e617e8a798 std/os/uefi: require guid output function be comptime 2020-03-12 23:22:08 +01:00
Nick Erdmann
7c12f93734 std/os/uefi: boot services and runtime services improvements
- Several function signatures added
- Add getNextVariableName sentinel termination annotation
2020-03-12 23:22:08 +01:00
Andrew Kelley
6e25ac2a2b stage1: update musl libc building code for v1.2.0 2020-03-12 17:45:55 -04:00
Andrew Kelley
edd6643a26 update musl src files to v1.2.0 2020-03-12 17:17:57 -04:00
Vexu
71d776c3be add note to disabled tests, improve comptime cmpxchg 2020-03-12 22:42:01 +02:00
Andrew Kelley
205c413962 update musl headers to v1.2.0 2020-03-12 16:26:14 -04:00
Vexu
6dde769279 Simplify stores, use sext for signed ints 2020-03-12 22:02:58 +02:00
LemonBoy
bd0b51477a Address review comments 2020-03-12 19:40:42 +01:00
Andrew Kelley
aa49f972d6 Merge pull request #4720 from Vexu/translate-c
Translate-c treat C bools as ints
2020-03-12 14:00:07 -04:00
daurnimator
8a22c50c08 Remove unused static_crt_dir field from libc config 2020-03-12 12:27:45 -04:00
Benjamin Feng
4aae55b4cc Replace fmt with new fmtstream 2020-03-12 10:41:09 -05:00
Benjamin Feng
ed7f30e1cd Migrate last vestiges of fmt 2020-03-12 10:41:09 -05:00
Benjamin Feng
786216ca5a Slap in workaround for Fifo 2020-03-12 10:41:09 -05:00
Benjamin Feng
6a53fe7c93 Handle potential downcast when translating stream size 2020-03-12 10:41:09 -05:00
Benjamin Feng
0059d9ee3e Convert fmt.bufPrint / fmt.allocPrint 2020-03-12 10:41:09 -05:00
Benjamin Feng
4023ed56d4 Convert translate-c to fmtstream 2020-03-12 10:41:09 -05:00
Benjamin Feng
8dd078b99a Convert Buffer to use fmtstream 2020-03-12 10:41:09 -05:00
Benjamin Feng
2429fdd73b Convert JSON to fmtstream 2020-03-12 10:41:09 -05:00
Benjamin Feng
0fbccec000 Convert builtin to fmtstream 2020-03-12 10:41:04 -05:00
Andrew Kelley
214af69814 ci: remove workaround for FreeBSD upstream bug 2020-03-12 11:40:44 -04:00
Vexu
ce19638cd4 disable test on mipsel 2020-03-12 17:31:10 +02:00
Benjamin Feng
c11d1055b8 Integrated outstreams with new formatter 2020-03-12 10:26:28 -05:00
Benjamin Feng
7364e965f4 Force error coercion of custom formatters 2020-03-12 10:26:28 -05:00
Benjamin Feng
d2e4aafd64 Fixup allocPrint 2020-03-12 10:26:27 -05:00
Vexu
02c491e42a translate-c fix order of tokens 2020-03-12 17:14:01 +02:00
Vexu
710b05b153 support @atomicRmw at comptime 2020-03-12 16:46:16 +02:00
Benjamin Feng
1c18ab01a4 Add back max_depth test 2020-03-12 09:25:13 -05:00
Benjamin Feng
f51c8f26c1 Apply explicit error type 2020-03-12 09:19:32 -05:00
Benjamin Feng
78d12762a9 Re-enable a bunch of tests 2020-03-12 09:15:49 -05:00
Benjamin Feng
8241b96f78 Re-enable testFmt 2020-03-12 09:06:12 -05:00
Benjamin Feng
e1e9ff9546 Get formatIntBuf working 2020-03-12 09:06:10 -05:00
Benjamin Feng
278b9ec1aa Blind translation 2020-03-12 09:04:18 -05:00
Benjamin Feng
ae3fb6df00 Copy fmtstream 2020-03-12 08:58:36 -05:00
Vexu
dda711ba0d translate-c treat c bools as ints 2020-03-12 14:40:47 +02:00
LemonBoy
11df0d0cf8 std: Add setEndPos to fs.file
Allow the user to shrink/grow the file size as needed.
2020-03-12 09:43:45 +01:00
LemonBoy
89d7fc773d std: Fix pwrite invocation on 32bit architectures 2020-03-12 09:43:45 +01:00
Andrew Kelley
f58705b4a6 fix zig targets not reporting native info 2020-03-12 00:33:06 -04:00
Heppokoyuki
3f1c8e3d58 fix bug 2020-03-12 00:29:30 -04:00
Andrew Kelley
75e9a722db Merge pull request #4714 from mikdusan/target
fix -target and -mcpu issues
2020-03-11 21:47:56 -04:00
Andrew Kelley
3ded862cdf Merge pull request #4713 from Heppokoyuki/uefi-file-protocols
UEFI library improvements
2020-03-11 21:44:50 -04:00
Michael Dusan
bfebc11d06 fix zig-cache to treat cpu-features as raw-bytes
- add Stage2Target.cache_hash_len
- add cache_mem(ch, ptr, len)
- update call sites to use { ptr, len }
2020-03-11 19:33:12 -04:00
Michael Dusan
c988167377 update/apply CPU features when -mcpu native
- fix: features were not applied if cpu is specified as native
2020-03-11 19:33:11 -04:00
Michael Dusan
e0fe0f7f1e parse CPU features when --target is null
- fixes case where features are not parsed when `-target` is null
- `zig builtin -mcpu native+bogus` should return error/list of valid features
2020-03-11 19:33:10 -04:00
Andrew Kelley
895f67cc6d Merge pull request #4710 from ziglang/io-stream-iface
rework I/O stream abstractions
2020-03-11 18:54:52 -04:00
Andrew Kelley
571f3ed161 fix stray warn() in runtime safety test 2020-03-11 18:45:09 -04:00
Andrew Kelley
06d2f53ece windows: detect HANDLE_EOF in ReadFile 2020-03-11 17:39:53 -04:00
Andrew Kelley
3657a54618 fix regressions in elf parsing code 2020-03-11 17:34:12 -04:00
Andrew Kelley
6892865ba7 FixedBufferStream: match file semantics more by clamping pos 2020-03-11 16:14:12 -04:00
Andrew Kelley
04626c176b Merge remote-tracking branch 'origin/master' into io-stream-iface 2020-03-11 15:47:07 -04:00
Andrew Kelley
431d76c023 add std.io.StreamSource and fixes to emitRaw 2020-03-11 15:40:34 -04:00
Andrew Kelley
c71991c869 fix compilation errors for emitRaw 2020-03-11 14:34:13 -04:00
Andrew Kelley
51c6bb92b1 Merge pull request #4709 from LemonBoy/implement-2096
Stricter shift left/right safety checks
2020-03-11 14:22:40 -04:00
Andrew Kelley
d96b6c0d9f fix footguns in File readAll functions 2020-03-11 13:06:30 -04:00
Heppokoyuki
58941927c4 refactor 2020-03-12 00:24:00 +09:00
Heppokoyuki
02ba1d8fe1 add file protocols 2020-03-12 00:24:00 +09:00
Vexu
9262f065f5 Move abi size checking to codegen 2020-03-11 16:48:18 +02:00
Vexu
ec906a9771 fix codegen, update docs 2020-03-11 13:55:52 +02:00
Vexu
1f66435a6b support cmpxchg at comptime 2020-03-11 12:02:05 +02:00
Vexu
64e60d8ae2 special case atomic operations on zero bit types 2020-03-11 10:29:15 +02:00
Vexu
21809c3300 support non power of two integers in atomic ops 2020-03-11 09:24:53 +02:00
Andrew Kelley
ed13cffca4 rework some old ELF parsing code and start to fix emitRaw 2020-03-10 22:01:58 -04:00
Andrew Kelley
bd14a81e30 fix std.ChildProcess on Windows 2020-03-10 21:09:49 -04:00
Andrew Kelley
d882a30587 fix stage2 lib on windows 2020-03-10 20:51:30 -04:00
Andrew Kelley
2bff0dda79 fix regressions found by test suite 2020-03-10 20:22:30 -04:00
Andrew Kelley
9abee660dc fix stack trace code not opening files in forced blocking mode 2020-03-10 19:28:05 -04:00
Andrew Kelley
cd26d3b0bb fix regressions caused earlier in this branch 2020-03-10 18:54:24 -04:00
LemonBoy
2f1052a313 std: Fix broken tests 2020-03-10 23:50:04 +01:00
Andrew Kelley
18f1fef142 update standard library to new I/O streams API 2020-03-10 18:44:30 -04:00
Michael Dusan
83f6f730cd std: simplify format enum-literals 2020-03-10 18:09:41 -04:00
LemonBoy
4ab13a359d ir: Fix shift code for u0 operands 2020-03-10 23:04:49 +01:00
Vexu
ee5b00a8b9 use atomic bools in std lib 2020-03-10 22:54:47 +02:00
Vexu
8dc188ebe0 support atomic operations with bools 2020-03-10 22:33:32 +02:00
Andrew Kelley
b6fbd524f1 (breaking) improve and simplify fixed buffer streams API 2020-03-10 16:31:04 -04:00
LemonBoy
300fceac6e ir: Implement more safety checks for shl/shr
The checks are now valid on types whose size is not a power of two.

Closes #2096
2020-03-10 20:54:05 +01:00
Andrew Kelley
ba0e3be5cf (breaking) rework stream abstractions
The main goal here is to make the function pointers comptime, so that we
don't have to do the crazy stuff with async function frames.

Since InStream, OutStream, and SeekableStream are already generic
across error sets, it's not really worse to make them generic across the
vtable as well.

See #764 for the open issue acknowledging that using generics for these
abstractions is a design flaw.

See #130 for the efforts to make these abstractions non-generic.

This commit also changes the OutStream API so that `write` returns
number of bytes written, and `writeAll` is the one that loops until the
whole buffer is written.
2020-03-10 15:32:32 -04:00
Vexu
1ad831a0ef fix zig fmt on noasync block 2020-03-10 15:27:11 -04:00
Jonathan Marler
90c232bbe8 add allocSentinel function 2020-03-10 15:03:59 -04:00
Andrew Kelley
9c4dc7b1bb Merge pull request #4703 from Vexu/translate-c
Translate-c improvements
2020-03-10 12:56:17 -04:00
LemonBoy
3e93dce0a1 std: Fix detection of Linux kernel version 2020-03-10 12:55:35 -04:00
Vexu
cb4c488cbd translate-c support struct field alignment 2020-03-10 15:57:57 +02:00
Vexu
4cace8f7c3 properly mangle shadowed primitive types 2020-03-10 15:52:54 +02:00
Vexu
baec74645d translate-c add daurnimator's pointer check to macro cast 2020-03-10 15:52:03 +02:00
Andrew Kelley
675f01f176 Merge pull request #4590 from xackus/fix-4587
fix failed assert on generic fn opaque return type
2020-03-09 22:10:57 -04:00
LemonBoy
1f44b29724 ir: Fix codegen of ?*T types where T is zero-sized
* Fix codegen for optional types that decay to a pointer, the type
  behaves as a boolean
* Fix comptime evaluation of zero-sized arrays, always initialize the
  internal array elements

Closes #4673
2020-03-09 22:08:56 -04:00
Andrew Kelley
638d5c3aca Merge pull request #4700 from Vexu/noasync
Implement new noasync syntax
2020-03-09 18:36:01 -04:00
xackus
e7cc456421 better error messages and more tests 2020-03-09 22:33:18 +01:00
Andrew Kelley
52c01840ce Merge branch 'LemonBoy-fix-4527'
closes #4531
2020-03-09 14:24:51 -04:00
Andrew Kelley
7db6da7cb8 lazy_cmp_zero only resolves type is zero bits for alignof 2020-03-09 14:24:04 -04:00
LemonBoy
14bbb82832 ir: Fix lazy comparison between @alignOf and zero
Closes #4527
2020-03-09 14:05:38 -04:00
daurnimator
648f94c027 std: add some definitions for netlink sockets 2020-03-09 13:02:38 -04:00
Andrew Kelley
6ab156ce7d Merge pull request #4695 from leroycep/feature-inode-stat
Expose file inode number on posix and file index on windows
2020-03-09 13:01:26 -04:00
Ryan Liptak
9b1b44b41c Windows: Fix std.fs.realpath/os.realpathW for directories 2020-03-09 12:59:17 -04:00
Vexu
3fd2cd4367 add LemonBoy's test 2020-03-09 18:43:09 +02:00
Vexu
03c1431f9c disallow resume and suspend in noasync scopes 2020-03-09 15:51:51 +02:00
Vexu
3618256c97 implement noasync scopes 2020-03-09 12:33:24 +02:00
Vexu
6f8d732599 update parsers to new noasync syntax 2020-03-09 12:23:30 +02:00
Lachlan Easton
0db108101a Translate C: Add comment containing c source location for failed decls 2020-03-09 18:10:41 +11:00
LeRoyce Pearson
25d9ab95dd Use os.ino_t for everything
Also, define ino_t for windows
2020-03-08 21:52:36 -06:00
LeRoyce Pearson
cb84875eed Define ino_t for systems not yet defining it
Also, use ino_t instead of u64 in fs.File.INode
2020-03-08 18:31:18 -06:00
LemonBoy
e2fd289a33 ir: Create usize result_loc for array subscript expr
Allow the subscript expression to infer the resulting type.

Closes #4169
2020-03-08 18:52:44 -04:00
LemonBoy
06d0dac0fb ir: Prevent crash in compiler error
Anonymous containers have no struct_field->type AstNode set, let's
always use the field node itself to make the error messages consistent.

Closes #4691
2020-03-08 18:12:50 -04:00
LeRoyce Pearson
e1c1ca9903 Add documentation about Stat.inode 2020-03-08 15:47:50 -06:00
LeRoyce Pearson
55077435bf Expose file inode (linux) and file index (windows) 2020-03-08 15:19:02 -06:00
xackus
7782c76bee fix failed assert on generic fn opaque return type 2020-03-08 18:05:45 +01:00
Andrew Kelley
f90fe1f8f2 Merge pull request #4687 from daurnimator/fix-typo
Fix grammar from "C pointers cannot point opaque types"
2020-03-08 12:44:56 -04:00
Andrew Kelley
a5cb19c0ac Merge pull request #4690 from Vexu/translate-c
Translate-c fixes
2020-03-08 12:43:49 -04:00
LemonBoy
2b1316954f std: One more cpuid fix
Don't read from stale eax value, rework the logic a bit so that's clear
what's going on.
2020-03-08 12:43:32 -04:00
Vexu
692a974c3e translate-c reject structs with VLAs 2020-03-08 12:11:37 +02:00
Vexu
5aa993cd61 translate-c fix nested loops without blocks. 2020-03-08 11:26:53 +02:00
daurnimator
c8050a931c Strip trailing whitespace from src/ir.cpp 2020-03-08 19:18:25 +11:00
daurnimator
b85bb152bf Fix grammar in error message 2020-03-08 19:18:06 +11:00
Andrew Kelley
9e60c89601 Revert "Translate C: Group generated casts"
This reverts commit 895672b3f9.
2020-03-08 03:53:06 -04:00
Andrew Kelley
8b80cb3072 Revert "translate-c remove redundant grouping, fix nested loops without blocks."
This reverts commit abe7305e16.
2020-03-08 03:52:52 -04:00
Jared Miller
cf38ce9701 Implement UTF-8 to UTF-16LE literal conversion 2020-03-07 19:21:28 -05:00
Andrew Kelley
6ac76bc25e add missing errors to std.os.windows.CreateDirectoryError 2020-03-07 19:13:21 -05:00
Andrew Kelley
0720f338d4 add std.event.Loop pread and faccessat
progress towards std lib tests passing with evented I/O mode
2020-03-07 19:13:21 -05:00
LemonBoy
c5885f012a std: Fix version detection on x86
Call xgetbv only if X{SAVE,RESTORE} and AVX are detected.

Closes #4670
2020-03-07 18:53:34 -05:00
Andrew Kelley
c25d9417d3 fix std.fs.makeDirAbsolute
closes #4671
2020-03-07 15:14:47 -05:00
Andrew Kelley
96c07674fc Merge remote-tracking branch 'origin/master' into llvm10 2020-03-07 12:18:41 -05:00
Michael Dusan
bc75c0de6c stage1: fix compile error on macOS Xcode 11.4 2020-03-07 12:16:56 -05:00
Vexu
abe7305e16 translate-c remove redundant grouping, fix nested loops without blocks. 2020-03-07 12:14:44 -05:00
Lachlan Easton
895672b3f9 Translate C: Group generated casts
Translate C: Put an alignCast in c style pointer casts to allow opaque types to cast properly in C macros

Translate C: add test case for aligning opaque types in pointer casts

Translate C: Fix @typeId -> @typeInfo

Add test case to run_translated_c for casting from pointer to opaque type
2020-03-07 03:26:42 -05:00
Andrew Kelley
80ff549e26 fix detectNativeCpuAndFeatures including foreign asm 2020-03-06 21:03:23 -05:00
Andrew Kelley
54799ccaf8 Merge branch 'alichay-master'
Closes #4627
2020-03-06 20:47:34 -05:00
Andrew Kelley
e0d5f94a70 simplify the inline assembly 2020-03-06 20:02:08 -05:00
Andrew Kelley
49817c6add cleanup CPU model & feature detection
Add std.Target.Cpu.Model.generic which is even more empty than baseline.
CPU model and feature detection uses this rather than baseline.

Rename cpu_detected to cpu_detection_unimplemented and flip the logic.
It can be relied on by stage2.zig to decide whether the LLVM workaround
is needed without also checking the CrossTarget.

Move the CPU detection to after the OS detection, and use the detected
OS for the CPU detection. This is relevant because operating systems
sometimes emulate certain CPU features, so knowing the OS and version is
relevant for determining CPU features.

Prepare for #4592 by passing the CPU arch to the detection code, instead
of having it rely on Target.current.

The CPU model & feature detection logic is modified. Before:

 * Detect actual features
 * Use as hint when detecting CPU model
 * Populate dependencies of CPU model features
 * Merge that into the actual features set

After:

 * Detect actual features
 * Use as hint when detecting CPU model
 * Add known CPU model features to actual features
 * Detect actual features again, overriding known CPU model features
 * Populate dependencies
2020-03-06 19:47:03 -05:00
alichay
f199182567 Cleaned up CPU detection and fixed incorrect detection bits. 2020-03-06 18:52:09 -05:00
alichay
e24f29bbad Added self-hosted x86 CPU detection. 2020-03-06 18:52:09 -05:00
Andrew Kelley
7f975bf09f Merge branch 'daurnimator-less-buffer'
Closes #4405
Closes #4656
2020-03-06 18:49:26 -05:00
Andrew Kelley
231a4b8fde fixups & make some API decisions
Removed:
  std.io.InStream.readUntilDelimiterBuffer

Deprecated:
  std.ArrayList.toSlice
  std.ArrayList.toSliceConst
  std.ArrayList.at
  std.ArrayList.ptrAt
  std.ArrayList.setOrError
  std.ArrayList.set
  std.ArrayList.swapRemoveOrError
  std.Buffer.toSlice
  std.Buffer.toSliceConst
  std.io.InStream.readFull => std.io.InStream.readAll
  std.io.InStream.readAllBuffer

New:
  std.ArrayList.span
  std.ArrayList.expandToCapacity
  std.Buffer.span
  std.io.InStream.readUntilDelimiterArrayList
2020-03-06 18:49:13 -05:00
daurnimator
4114b63d75 std: use std.ArrayList instead of std.Buffer in std/fmt.zig tests 2020-03-06 18:49:13 -05:00
daurnimator
1cbf352cfb Remove unused std.Buffer imports 2020-03-06 18:49:13 -05:00
daurnimator
5c0d6ef5ec std: use ArrayList instead of Buffer from std/process.zig 2020-03-06 18:49:12 -05:00
daurnimator
d136c795af Fix bug where stdout was checked instead of stderr 2020-03-06 18:49:12 -05:00
daurnimator
8f627593eb Use in_stream.readAllAlloc where sensible 2020-03-06 18:49:12 -05:00
daurnimator
bcf56c32eb std: use ArrayList rather than Buffer for in_stream helper functions
Buffer's behaviour of retaining a trailing 0 isn't helpful here
2020-03-06 18:49:12 -05:00
daurnimator
fd23decbd9 std: add ArrayList.eql for parity with std.Buffer 2020-03-06 18:49:12 -05:00
daurnimator
119ac13eda std: add .startsWith and .endsWith to std.ArrayList 2020-03-06 18:49:10 -05:00
Andrew Kelley
fa46bcb368 stage1: make get_optional_type more robust
Now it will emit a compile error rather than crashing when the child
type has not been resolved properly.

Introduces `get_optional_type2` which should be used generally inside
ir.cpp.

Fix some std lib compile errors noticed by the provided test case.

Thanks @LemonBoy for the test case. Closes #4377.

Fixes #4374.
2020-03-06 18:30:30 -05:00
Vexu
83d27f71ef translate-c more macro ops 2020-03-06 17:34:37 -05:00
Andrew Kelley
7df9169081 Merge pull request #4651 from LemonBoy/fix-4645
std: Nicer way to access the PEB
2020-03-06 17:33:05 -05:00
Andrew Kelley
3163a16617 ?HMODULE instead of HMODULE 2020-03-06 16:57:59 -05:00
Andrew Kelley
0e5b48d1a2 fix @embedFile docs 2020-03-06 16:01:26 -05:00
Andrew Kelley
3dc8cb12e8 ir: remove pointless and misleading code in @embedFile 2020-03-06 15:55:18 -05:00
LemonBoy
2e04b61275 std: Work around unexported NtCurrentTeb
Apparently NtCurrentTeb is only exported for i386 and some other
platforms but not for x86_64 nor AArch64. Let's go with the flow and
provide our own NtCurrentTeb like the Windows headers do.

Thank you Microsoft.
2020-03-06 09:17:14 +01:00
LemonBoy
b9a1d67637 std: Nicer way to access the PEB
Use the NtCurrentTeb API instead of using some inline asm, this is much
nicer and also more portable.

Closes #4645
2020-03-06 09:06:26 +01:00
Vexu
eaccfffe56 translate-c: default initialize non-extern variables to undefined 2020-03-06 00:06:45 -05:00
Andrew Kelley
6b069f5c8c Revert "put FreeBSD CI in timeout for misbehavior"
This reverts commit c0c9303bd6.

Thanks to commit c08444b33f we can now
re-enable FreeBSD in the CI.
2020-03-05 23:37:29 -05:00
Michael Dusan
d31b65e762 std: fix sendfile on macOS and FreeBSD
- fix std.os.sendfile/FreeBSD use correct in/out fd_t
- fix std.os.sendfile/macOS use correct in/out fd_t
- undo 1141bfb21b (no longer needed)
- fix c.freebsd.sendfile use off_t value
- fix c.freebsd.sendfile decl correct in/out fd_t
- fix c.darwin.sendfile decl correct in/out fd_t

fix signature param names
2020-03-05 20:46:28 -05:00
Michael Dusan
428677ea36 stage1: fix regression
- regression was introduced by 371c21aa70
2020-03-05 20:45:01 -05:00
Michael Dusan
c08444b33f srht: workaround FreeBSD fiasco 2020-03-05 19:47:28 -05:00
Andrew Kelley
01c722c21c Revert "Allow constant struct val to reallocate its fields when resolving an inferred struct field with a comptime value."
This reverts commit debcc79d56.

This caused a regression when building self-hosted
2020-03-05 17:19:01 -05:00
Michaël Larouche
f5954dad83 Fix crash when freeing empty string as null-terminated sentinel 2020-03-05 17:08:12 -05:00
Michael Dusan
1091fee242 std: format enum-literals 2020-03-05 16:03:12 -05:00
Alexandros Naskos
debcc79d56 Allow constant struct val to reallocate its fields when resolving an inferred struct field with a comptime value. 2020-03-05 15:48:03 -05:00
Andrew Kelley
c92957da0e Merge branch 'update-mingw-w64'
closes #3713
2020-03-05 15:41:33 -05:00
Andrew Kelley
20ac253859 reapply mingw-w64 header patches
Fix compilation w/ clang
f83bb3dd9e
2020-03-05 15:41:28 -05:00
Andrew Kelley
c0242f2310 update mingw-w64 source files to v7.0.0 2020-03-05 15:41:28 -05:00
Andrew Kelley
8e5913cfee update mingw-w64 headers to v7.0.0 2020-03-05 15:41:28 -05:00
Michael Dusan
1aae5bebe9 Merge pull request #4641 from mikdusan/housekeeping
stage1: housekeeping
2020-03-05 14:58:02 -05:00
Michael Dusan
371c21aa70 stage1: housekeeping
- use consistent allocator in `realloc_const_vals_ptrs()`
- unexport `create_fn_raw()`
2020-03-05 12:17:47 -05:00
Vexu
ad27041de9 translate-c demote struct to opaque if unable to translate type 2020-03-05 10:55:32 -05:00
Andrew Kelley
b7614e63f5 Merge pull request #4636 from Vexu/translate-c
Translate-c macro comma operator
2020-03-05 10:38:51 -05:00
Andrew Kelley
d7dc7d7a50 Merge pull request #4633 from daurnimator/4632-i1
Fix formatting of i1 values
2020-03-05 10:33:02 -05:00
Vexu
e063854563 translate-c correct assumption about macros 2020-03-05 12:23:32 +02:00
Vexu
8088bdc6d5 translate-c macro comma operator 2020-03-05 11:22:50 +02:00
daurnimator
e9c3b65bf4 std: use testing.expectEqual in math.absCast tests 2020-03-05 16:02:26 +11:00
daurnimator
488ba1560f std: fix math.absCast on i1 2020-03-05 16:00:19 +11:00
daurnimator
4f58bfe1a8 std: fix formatting of i1 integers 2020-03-05 15:52:19 +11:00
daurnimator
d5359ea541 std: use testing.expectEqualSlices from tests 2020-03-05 15:51:21 +11:00
Andrew Kelley
378bf1c3b7 Merge branch 'LemonBoy-fix-439' 2020-03-04 18:05:34 -05:00
Andrew Kelley
116e2a93f1 update docs for @TypeOf 2020-03-04 18:05:14 -05:00
Andrew Kelley
3e3d464884 @TypeOf avoids heap allocation for only 1 parameter 2020-03-04 17:43:23 -05:00
LemonBoy
2e3e8d0c74 ir: Adapt ir_print for the new @TypeOf format 2020-03-04 17:21:10 -05:00
LemonBoy
e029032251 std: Use @TypeOf(x,y) as return value for max 2020-03-04 17:21:10 -05:00
LemonBoy
0c310f0fbf ir: Implement @TypeOf with multiple arguments
Closes #439
2020-03-04 17:21:10 -05:00
Andrew Kelley
24fc69acad Merge pull request #4573 from alexnask/tuple_concat
Allow concatenation of tuples that contain a mix of runtime and comptime values
2020-03-04 17:09:43 -05:00
Andrew Kelley
f247a90541 get_codegen_ptr_type returns possible error
And fix most of the fallout. This also makes optional pointers not
require resolving zero bits, because the comptime value struct layout no
longer depends on whether the type has zero bits.

Thanks to @LemonBoy for the behavior test case

Closes #4357
Closes #4359
2020-03-04 17:04:59 -05:00
Andrew Kelley
3178807657 Merge remote-tracking branch 'origin/master' into llvm10 2020-03-04 15:35:46 -05:00
Andrew Kelley
6cbd1ac51a zig is now aware of DragonflyBSD versions 2020-03-04 15:34:32 -05:00
Andrew Kelley
3ff2381042 update glibc source files to 2.31
This is mostly minor modifications to license text.
2020-03-04 14:59:09 -05:00
pfg
e3b37fc9c1 Generated documentation mobile support 2020-03-04 10:47:21 -05:00
Timon Kruiper
e095475d92 Fix docs generation
Commit edb210905d caused the docs generation
to fail, because all the type information in pass1 was already freed in
`zig_llvm_emit_output`.
2020-03-04 09:59:21 -05:00
Andrew Kelley
1cf3209cb8 Merge pull request #4623 from ziglang/update-glibc
Update glibc to 2.31
Closes #4459.
2020-03-04 09:01:19 -05:00
Andrew Kelley
447a89cd4d update self-hosted zig targets to print correct glibc availability 2020-03-04 01:05:42 -05:00
Andrew Kelley
b21d44f26a update glibc abilists for 2.31 2020-03-04 00:07:15 -05:00
Andrew Kelley
cd33c5bfe8 zig build: update InstallRawStep to new std.fs API
closes #4622
2020-03-04 00:00:42 -05:00
Andrew Kelley
74fef9db6e update update_glibc tool to latest zig 2020-03-03 22:52:03 -05:00
Andrew Kelley
67480cd515 update glibc headers to 2.31 2020-03-03 22:46:57 -05:00
Andrew Kelley
3841acf7ef update process_headers tool to latest zig 2020-03-03 22:40:41 -05:00
Andrew Kelley
8aaab75af0 docs: remove reference to deprecated builtins
closes #3959
2020-03-03 22:14:29 -05:00
Andrew Kelley
c0c9303bd6 put FreeBSD CI in timeout for misbehavior
FreeBSD is dealing with some weird upstream bug right now. We can try to
re-enable this when it is fixed.
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=244549

very naughty
2020-03-03 21:32:01 -05:00
Andrew Kelley
3b235cfa80 std.zig.CrossTarget: fix compile errors
closes #4620
2020-03-03 21:09:32 -05:00
Andrew Kelley
f6f0b019be Merge pull request #4618 from ziglang/daurnimator-paths
improvements to std.fs, std.os
2020-03-03 17:05:14 -05:00
Andrew Kelley
1141bfb21b Darwin can return EBADF for sendfile on non-files 2020-03-03 16:52:32 -05:00
Andrew Kelley
c4f81586f1 update docgen to new std.fs API 2020-03-03 16:01:09 -05:00
Andrew Kelley
55dfedff42 update cli test to new std.fs API 2020-03-03 15:58:14 -05:00
Andrew Kelley
4a67dd04c9 breaking changes to std.fs, std.os
* improve `std.fs.AtomicFile` to use sendfile()
   - also fix AtomicFile cleanup not destroying tmp files under some
     error conditions
 * improve `std.fs.updateFile` to take advantage of the new `makePath`
   which no longer needs an Allocator.
 * rename std.fs.makeDir to std.fs.makeDirAbsolute
 * rename std.fs.Dir.makeDirC to std.fs.Dir.makeDirZ
 * add std.fs.Dir.makeDirW and provide Windows implementation of
   std.os.mkdirat. std.os.windows.CreateDirectory is now implemented
   by calling ntdll, supports an optional root directory handle,
   and returns an open directory handle. Its error set has a few more
   errors in it.
 * rename std.fs.Dir.changeTo to std.fs.Dir.setAsCwd
 * fix std.fs.File.writevAll and related functions when len 0 iovecs
   supplied.
 * introduce `std.fs.File.writeFileAll`, exposing a convenient
   cross-platform API on top of sendfile().
 * `NoDevice` added to std.os.MakeDirError error set.
 * std.os.fchdir gets a smaller error set.
 * std.os.windows.CloseHandle is implemented with ntdll call rather than
   kernel32.
2020-03-03 15:23:27 -05:00
daurnimator
1ca5f06762 Update callers of fs.makePath 2020-03-03 13:25:43 -05:00
daurnimator
695b0976c3 std: move makePath to be a Dir method 2020-03-03 13:25:43 -05:00
daurnimator
a19a30bb17 std: move null byte check into toPosixPath
Note that windows NT paths *can* contain nulls
2020-03-03 13:25:43 -05:00
daurnimator
d8f966a04b std: fix fs.makePath
The previous behaviour of using path.resolve has unexpected behaviour around symlinks.
This more simple implementation is more correct and doesn't require an allocator
2020-03-03 13:25:43 -05:00
daurnimator
bfc569bc98 std: add os.fstatat 2020-03-03 13:25:43 -05:00
daurnimator
627618a38d std: add Dir.changeDir as wrapper around fchdir 2020-03-03 13:25:43 -05:00
daurnimator
dfb420e6d7 std: add fs.Dir.makeDir 2020-03-03 13:25:43 -05:00
daurnimator
88e27f01c8 std: add mkdirat 2020-03-03 13:25:40 -05:00
Andrew Kelley
582db68a15 remove superfluous comptime keyword 2020-03-03 12:01:17 -05:00
LemonBoy
a6fb6dcfc9 linux: Correct pread64 syscall for ARM/MIPS
Closes #4615
2020-03-03 11:59:16 -05:00
Andrew Kelley
226b801830 Merge pull request #4612 from ziglang/os-read-write-sendfile
std.os read/write functions + sendfile
2020-03-03 10:15:37 -05:00
Andrew Kelley
9d6cc75ce3 disable sendfile test on mips 2020-03-03 09:49:46 -05:00
Andrew Kelley
66e6f5586e enable f128 test on windows 2020-03-03 09:49:08 -05:00
Andrew Kelley
d1cb16aace Merge remote-tracking branch 'origin/master' into llvm10 2020-03-03 09:44:13 -05:00
Andrew Kelley
3418a332ab Revert "work around LLVM 10 llvm-config giving absolute path to libz.so"
This reverts commit 73256dda91.

No longer needed with latest release/10.x branch.
2020-03-03 09:17:37 -05:00
Andrew Kelley
387418277a Merge pull request #4601 from alexnask/fix_3997
Allow wrapping in VDSO lookup
2020-03-03 09:15:40 -05:00
Alexandros Naskos
7559418305 Added comment justifying wrapping operations 2020-03-03 12:41:11 +02:00
Andrew Kelley
a66c72749a more macos fixes 2020-03-03 03:10:56 -05:00
Ryan Liptak
d7579a2fcb Fix std.os.unlinkatW for absolute paths
RootDirectory can't be set in ObjectAttributes if ObjectName is an absolute path.

Fixes #4606
2020-03-03 03:07:12 -05:00
Andrew Kelley
859fc856d3 fix macosx and freebsd build failures 2020-03-03 02:57:11 -05:00
Andrew Kelley
c81345c8ae breaking: std.os read/write functions + sendfile
* rework os.sendfile and add macosx support, and a fallback
   implementation for any OS.
 * fix sendto compile error
 * std.os write functions support partial writes. closes #3443.
 * std.os pread / pwrite functions can now return `error.Unseekable`.
 * std.fs.File read/write functions now have readAll/writeAll variants
   which loop to complete operations even when partial reads/writes
   happen.
 * Audit std.os read/write functions with respect to Linux returning
   EINVAL for lengths greater than 0x7fff0000.
 * std.os read/write shim functions do not unnecessarily loop. Since
   partial reads/writes are part of the API, the caller will be forced
   to loop anyway, and so that would just be code bloat.
 * Improve doc comments
 * Add a non-trivial test for std.os.sendfile
 * Fix std.os.pread on 32 bit Linux
 * Add missing SYS_sendfile bit on aarch64
2020-03-03 02:25:26 -05:00
Terin Stock
bd287dd194 std: implement sendfile on linux
This changset adds a `sendfile(2)` syscall bindings to the linux bits
component. Where available, the `sendfile64(2)` syscall will be
transparently called.

A wrapping function has also been added to the std.os to transform
errno returns to Zig errors.

Change-Id: I86769fc4382c0771e3656e7b21137bafd99a4411
2020-03-02 12:54:50 -05:00
Alexandros Naskos
a48cd1cf58 Allow wrapping in VDSO lookup 2020-03-02 11:44:21 +02:00
Alexandros Naskos
b838122cc0 Merge branch 'master' of https://github.com/ziglang/zig into tuple_concat 2020-03-02 00:55:19 +02:00
Alexandros Naskos
78e4daaa03 Removed unused variable 2020-03-02 00:54:57 +02:00
xackus
00be934569 short std.builtin enum literals in std lib 2020-03-01 13:57:41 -05:00
Andrew Kelley
3c14327011 Merge branch 'daurnimator-fmt-sentinel-pointers'
closes #3972
2020-03-01 13:53:13 -05:00
Andrew Kelley
ef3d761da5 breaking: std.mem.len no longer takes a type argument
also update fmt code to use std.mem.span.
2020-03-01 13:21:39 -05:00
Andrew Kelley
5b26128bac add new functions to std.mem and deprecate others
add std.mem.Span
add std.mem.span
add std.mem.length
add std.mem.indexOfSentinel

deprecate std.mem.len
deprecate std.mem.toSlice
deprecate std.mem.toSliceConst
2020-03-01 13:07:55 -05:00
Andrew Kelley
4505857e30 revert changes outside std.fmt 2020-03-01 13:07:31 -05:00
daurnimator
0b0de22fd1 std: format contents of sentinel terminated many pointers
std: add std.meta.Sentinel to get sentinel of a type
2020-03-01 13:04:29 -05:00
Andrew Kelley
b99c6d56da stage1: fix compilation on 32-bit arm 2020-03-01 03:27:09 -05:00
Andrew Kelley
ae99fabfe4 Merge pull request #4585 from LemonBoy/fix-4581
target: Implement OS version detection for Windows
2020-03-01 02:53:51 -05:00
Andrew Kelley
f082e253b5 fix native OS version detection on macOS
closes #4583
2020-03-01 01:17:50 -05:00
Andrew Kelley
2246812184 use an explicit error set to fix a compilation error
this function has conditionally compiled out code in it about looking
for native glibc.
2020-02-29 22:20:44 -05:00
Andrew Kelley
6fcf6716be std.Thread.cpuCount on Windows uses the PEB
rather than calling GetSystemInfo from kernel32.dll. Also remove
OutOfMemory from the error set.
2020-02-29 22:13:09 -05:00
Andrew Kelley
d951e0402a Merge pull request #4586 from daurnimator/windows-PEB
Fill out windows PEB definition
2020-02-29 22:05:56 -05:00
Andrew Kelley
48cef8d5be refactor std.zig.system.NativeTargetInfo functions
to make them a bit easier to test.
2020-02-29 21:31:03 -05:00
Andrew Kelley
c903b76010 Merge pull request #4589 from LemonBoy/fix-4583
target: Implement OS version detection for OSX
2020-02-29 20:39:29 -05:00
LemonBoy
845af5c552 Handle one more error 2020-02-29 23:11:36 +01:00
LemonBoy
3b29a72b3b Use .len instead of @sizeOf 2020-02-29 23:08:57 +01:00
LemonBoy
84549b3955 target: Implement OS version detection for OSX
Closes #4583
2020-02-29 21:46:07 +01:00
LemonBoy
278f0f8fa9 Change how the build-id is checked
Address review comment by @rocksnest
2020-02-29 18:31:03 +01:00
Andrew Kelley
3c7f030a60 add CrossTarget.getObjectFormat
closes #4588

thanks Michaël Larouche for the suggested fix
2020-02-29 12:27:13 -05:00
daurnimator
d0c22619f5 Complete windows PEB_LDR_DATA definition 2020-03-01 02:10:29 +11:00
LemonBoy
5822220435 Address review comments 2020-02-29 14:19:13 +01:00
daurnimator
513076ee9c Fill out PEB definition 2020-03-01 00:12:08 +11:00
LemonBoy
f072b0c056 target: Implement OS version detection for Windows
Closes #4581
2020-02-29 12:02:40 +01:00
Andrew Kelley
7e6b68a534 std.Target.standardDynamicLinkerPath: delete bad doc comment 2020-02-29 02:08:26 -05:00
Andrew Kelley
7617610400 Merge pull request #4550 from ziglang/os-version-ranges
introduce operating system version ranges as part of the target; self-host native dynamic linker detection and native glibc version detection
2020-02-29 01:57:06 -05:00
Alexandros Naskos
1b41f2d77e C pointer slices are no longer allowzero (#4462)
* Slices from C pointers are no longer allowzero but instead insert a runtime assertion.

* Added a test, fixed code for cases with non-allowzero C pointers

* Create new type when flipping allow_zero, sometimes we get a cached value back from adjust_ptr_len.

* Added comments, changed panic message

* Added runtime safety test.
2020-02-29 01:36:42 -05:00
Andrew Kelley
3cba603eae fix crash when building docgen 2020-02-29 01:05:11 -05:00
Andrew Kelley
1aef0bef75 std.Target.Os.WindowsVersion: non-exhaustive enum 2020-02-28 19:24:52 -05:00
Andrew Kelley
e683eee415 fix CrossTarget.isNative, setGnuLibCVersion, zigTriple 2020-02-28 19:18:27 -05:00
Andrew Kelley
4bc893c346 update test to newer API 2020-02-28 19:05:14 -05:00
Andrew Kelley
7e3bb00a0e don't choose native ld path when os is non native 2020-02-28 18:48:19 -05:00
Andrew Kelley
4591236ae1 CrossTarget.cpu_model: communicate intent precisely 2020-02-28 18:31:46 -05:00
Andrew Kelley
aa13f339d4 fix handling of CrossTarget.cpu_model 2020-02-28 18:09:33 -05:00
Andrew Kelley
8691d3c50d improve std.zig.system.NativeTargetInfo.detect
It now takes a std.zig.CrossTarget parameter, and only resolves
native things, leaving explicitly overridden things alone.
2020-02-28 17:23:16 -05:00
Andrew Kelley
a5a53a182a fix typo from other commit
d2535c003c
2020-02-28 16:06:06 -05:00
Andrew Kelley
bee4007ec9 fix crash with multiple comptime fn calls and...
...default initialized array to undefined

closes #4578
2020-02-28 15:49:19 -05:00
Andrew Kelley
578dc16910 fix compiler crash when comptime parsing targets 2020-02-28 15:41:30 -05:00
Andrew Kelley
500dde32d5 dynamic_linker becomes a field of std.zig.CrossTarget 2020-02-28 14:51:56 -05:00
Andrew Kelley
07f52119de implement native OS version detection for linux 2020-02-28 14:51:56 -05:00
Andrew Kelley
ef24f2dd93 remove special darwin os version min handling
now it is integrated with zig's target OS range.
2020-02-28 14:51:56 -05:00
Andrew Kelley
d45ea4d89d stage1: make get_native_target go through self-hosted 2020-02-28 14:51:56 -05:00
Andrew Kelley
3683ba87ac complete the native target detection based on /usr/bin/env 2020-02-28 14:51:56 -05:00
Andrew Kelley
fd006c1c74 std.zig.system.NativeTargetInfo.detect: almost no Allocator 2020-02-28 14:51:55 -05:00
Andrew Kelley
60f2f3457d getStandardDynamicLinkerPath renamed and no allocator
* `std.Target.getStandardDynamicLinkerPath` =>
   `std.Target.standardDynamicLinkerPath`
 * it now takes a pointer to fixed size array rather than an allocator
 * `std.zig.system.NativeTargetInfo.detect` now supports reading
   PT_INTERP from /usr/bin/env
2020-02-28 14:51:55 -05:00
Andrew Kelley
662b5f7c60 update docs to latest Target API 2020-02-28 14:51:55 -05:00
Andrew Kelley
f89a1844bf don't error out for targets with unknown standard dynamic linker path 2020-02-28 14:51:55 -05:00
Andrew Kelley
70bf8874d7 update docgen to new Target API 2020-02-28 14:51:55 -05:00
Andrew Kelley
3c3316d4ba update tests to new Target API 2020-02-28 14:51:55 -05:00
Andrew Kelley
2536e4c70c WASI has no dynamic linker 2020-02-28 14:51:55 -05:00
Andrew Kelley
bafa895561 compiler-rt: inline at call site to workaround a bug
The bug is #2154
2020-02-28 14:51:55 -05:00
Andrew Kelley
36aa3c8e7f fix __stack_chk_guard emitted even when not linking libc 2020-02-28 14:51:55 -05:00
Andrew Kelley
6226726571 fix builder.findProgram test 2020-02-28 14:51:55 -05:00
Andrew Kelley
2387f48d5c fix incorrect builtin import code for windows 2020-02-28 14:51:54 -05:00
Andrew Kelley
7927764cc2 mips: implement Target.getStandardDynamicLinkerPath 2020-02-28 14:51:54 -05:00
Andrew Kelley
34d2700af4 clean up CrossTarget.getExternalExecutor 2020-02-28 14:51:54 -05:00
Andrew Kelley
622b5b62c2 fix not setting the dynamic linker path when cross compiling 2020-02-28 14:51:54 -05:00
Andrew Kelley
0912484c4f improve the "external executor" detection logic 2020-02-28 14:51:54 -05:00
Andrew Kelley
cebcacd872 fix standardTargetOptions and improve init-exe to use it 2020-02-28 14:51:54 -05:00
Andrew Kelley
cf233bad58 fix target parsing 2020-02-28 14:51:54 -05:00
Andrew Kelley
c8669a4cf8 improve debug info for optionals 2020-02-28 14:51:54 -05:00
Andrew Kelley
dbe4d72bcf separate std.Target and std.zig.CrossTarget
Zig now supports a more fine-grained sense of what is native and what is
not. Some examples:

This is now allowed:
-target native

Different OS but native CPU, default Windows C ABI:
-target native-windows
This could be useful for example when running in Wine.

Different CPU but native OS, native C ABI.
-target x86_64-native -mcpu=skylake

Different C ABI but otherwise native target:
-target native-native-musl
-target native-native-gnu

Lots of breaking changes to related std lib APIs.
Calls to getOs() will need to be changed to getOsTag().
Calls to getArch() will need to be changed to getCpuArch().

Usage of Target.Cross and Target.Native need to be updated to use
CrossTarget API.

`std.build.Builder.standardTargetOptions` is changed to accept its
parameters as a struct with default values. It now has the ability to
specify a whitelist of targets allowed, as well as the default target.
Rather than two different ways of collecting the target, it's now always
a string that is validated, and prints helpful diagnostics for invalid
targets. This feature should now be actually useful, and contributions
welcome to further improve the user experience.

`std.build.LibExeObjStep.setTheTarget` is removed.
`std.build.LibExeObjStep.setTarget` is updated to take a CrossTarget
parameter.

`std.build.LibExeObjStep.setTargetGLibC` is removed. glibc versions are
handled in the CrossTarget API and can be specified with the `-target`
triple.

`std.builtin.Version` gains a `format` method.
2020-02-28 14:51:54 -05:00
Andrew Kelley
87b9e744dd update std lib to new Target API 2020-02-28 14:51:54 -05:00
Andrew Kelley
d4f375c46b stage1: remove get_self_libc_path
and glibc_detect_native_version
2020-02-28 14:51:53 -05:00
Andrew Kelley
4616af0ca4 introduce operating system version ranges as part of the target
* re-introduce `std.build.Target` which is distinct from `std.Target`.
   `std.build.Target` wraps `std.Target` so that it can be annotated as
   "the native target" or an explicitly specified target.
 * `std.Target.Os` is moved to `std.Target.Os.Tag`. The former is now a
   struct which has the tag as well as version range information.
 * `std.elf` gains some more ELF header constants.
 * `std.Target.parse` gains the ability to parse operating system
   version ranges as well as glibc version.
 * Added `std.Target.isGnuLibC()`.
 * self-hosted dynamic linker detection and glibc version detection.
   This also adds the improved logic using `/usr/bin/env` rather than
   invoking the system C compiler to find the dynamic linker when zig
   is statically linked. Related: #2084
   Note: this `/usr/bin/env` code is work-in-progress.
 * `-target-glibc` CLI option is removed in favor of the new `-target`
   syntax. Example: `-target x86_64-linux-gnu.2.27`

closes #1907
2020-02-28 14:51:53 -05:00
Andrew Kelley
fba39ff331 restructuring std.Target for OS version ranges, pass 1 2020-02-28 14:51:50 -05:00
Michael Dusan
68dbba212d Merge pull request #4576 from mikdusan/housekeeping
stage1: housekeeping
2020-02-28 10:22:28 -05:00
Michael Dusan
a6087a7bc1 stage1: housekeeping 2020-02-28 08:30:43 -05:00
Alexandros Naskos
11848fcb5f Removed unused variable 2020-02-28 03:48:30 +02:00
Alexandros Naskos
261c94629e Added test 2020-02-28 02:52:09 +02:00
Alexandros Naskos
c020bc27ac More fixes, removed debug prints 2020-02-28 02:43:33 +02:00
Alexandros Naskos
95a1d2feb4 Fixed tuple concatenation with runtime and comptime values. 2020-02-28 02:19:17 +02:00
Andrew Kelley
c39d7a6326 fix exported variable not respecting linkage 2020-02-27 11:51:43 -05:00
LemonBoy
2696c8b42d ir: Robust checking for init expr type
Closes #3979
2020-02-27 10:40:22 -05:00
LemonBoy
6a0927d8c1 debug: Fix end-of-stream condition in DWARF parser 2020-02-26 21:02:54 -05:00
LemonBoy
fd1eade4ca ir: Allow empty inferred error sets
Closes #4564
2020-02-26 21:02:22 -05:00
Andrew Kelley
0a88352689 fix behavior tests with --test-evented-io 2020-02-26 13:17:38 -05:00
Andrew Kelley
2b33e27e1c arm baseline CPU is v7a rather than v6m
v6m is thumb-mode and the baseline should probably be an 'a' variant.
2020-02-26 12:37:13 -05:00
Andrew Kelley
e4180de2e9 update test expectations 2020-02-26 11:59:23 -05:00
Andrew Kelley
6291e8e492 Merge branch 'Vexu-tagname'
closes #4559
closes #3991
2020-02-26 11:21:30 -05:00
Andrew Kelley
62de32a18c call deinit on the hashmaps introduced in the prev commit 2020-02-26 11:21:10 -05:00
Vexu
22432b15e3 add test for @intToEnum 2020-02-26 11:19:40 -05:00
Vexu
215797749d fix @intToEnum on extern enums 2020-02-26 11:19:40 -05:00
Vexu
d505ea6caf fix @tagName on extern and non-exhaustive enums 2020-02-26 11:19:39 -05:00
Andrew Kelley
c4a2734aa0 Merge pull request #4561 from LemonBoy/fix-4536-1
Resend of #4552
2020-02-26 11:11:28 -05:00
Andrew Kelley
aa2aad229c Merge pull request #4497 from LemonBoy/do-do-do
The great stack-trace race (Part 1 of N)
2020-02-26 11:10:38 -05:00
LemonBoy
d2535c003c ir: Fix regression with self-referencing containers 2020-02-26 10:05:04 +01:00
Andrew Kelley
a55e536391 fix typo in previous commit
oops, forgot to actually run the test
2020-02-25 21:32:03 -05:00
Andrew Kelley
e75598af3d add test case to catch regression from previous commit
Once this test case is passing, previous commit can be re-added.

Closes #4560
2020-02-25 21:24:27 -05:00
Andrew Kelley
dad62a7e27 Revert "ir: Fix sizeOf comparison with ptr to zst"
This reverts commit 89812217b4.

This caused #4560
2020-02-25 21:23:35 -05:00
LemonBoy
e9bac8be6b ir: Fix array to slice conversion for zero-sized arrays
Closes #3848
2020-02-25 17:40:01 -05:00
LemonBoy
55ea855e2c ir: Various fixes for comptime ptr handling
* Correctly fold ptrToInt on optional types
* Generate null as ConstPtrSpecialNull in intToPtr
* Correctly stop ptrToInt on ?*T where T is zero-sized

Closes #4535
2020-02-25 17:38:56 -05:00
LemonBoy
89812217b4 ir: Fix sizeOf comparison with ptr to zst
Closes #4536
2020-02-25 17:36:54 -05:00
Andrew Kelley
f33bf48af7 Merge remote-tracking branch 'origin/master' into llvm10 2020-02-25 16:30:40 -05:00
Michael Dusan
416a547cdb Merge pull request #4515 from mikdusan/stage1-gen-constants
stage1: free more heap after analysis
2020-02-25 10:57:47 -05:00
LemonBoy
b46efcde82 ir: Fix sizeOf comparison with ptr to zst
Closes #4536
2020-02-25 12:48:08 +01:00
Andrew Kelley
26b2e5fda8 Merge branch 'vegecode-formatted-print-to-std.Buffer'
closes #4385
2020-02-24 22:34:24 -05:00
Andrew Kelley
7cfe854359 clean up std.Buffer.print 2020-02-24 22:34:06 -05:00
vegecode
6fa143355f Add formatted printing directly into std.Buffer 2020-02-24 22:30:23 -05:00
Andrew Kelley
5503f3f7c4 Merge pull request #4544 from BarabasGitHub/zeroes-for-non-extern-types
implement zeroes for non extern structs and native types
2020-02-24 22:01:56 -05:00
Andrew Kelley
61a50a23e8 Merge pull request #4547 from Vexu/deprecate
Remove deprecated builtins
2020-02-24 21:57:29 -05:00
Andrew Kelley
544bc42fd9 expose --verbose-llvm-cpu-features to zig build 2020-02-24 20:11:33 -05:00
Vexu
d56115ef41 remove @IntType and @ArgType (mostly) from the compiler 2020-02-25 01:27:34 +02:00
Vexu
538d9a5dd8 remove uses of @ArgType and @IntType 2020-02-24 23:39:03 +02:00
Vexu
3458fb891d remove @typeId, @memberCount, @memberName and @memberType from the compiler 2020-02-24 23:21:11 +02:00
Bas van den Berg
f7aa4f5280 Processed review comments. Updated documentation, used the typinfo for field access, generate compile error on allowzero and set C poitners to null 2020-02-24 22:15:04 +01:00
Vexu
45da72c5b6 remove usages of @typeId, @memberCount, @memberName and @memberType 2020-02-24 23:09:01 +02:00
Bas van den Berg
195195d238 vectors do not support iterating, do not support them (for now) 2020-02-24 20:50:51 +01:00
Bas van den Berg
0972b2a8fe implement zeroes for non extern structs and native types 2020-02-24 20:38:33 +01:00
Andrew Kelley
1d06c82c3b Merge pull request #4516 from xackus/remove-bytes-to-slice
remove @bytesToSlice, @sliceToBytes from the language
2020-02-24 13:51:47 -05:00
J.W
5275b01202 hashing algorithms: fix logic and index out of bounds 2020-02-24 13:43:54 -05:00
Heide Onas Auri
907c5589ae std.time.Timer.lap: only read system time once (#4533)
Calling Timer.lap queried the system time twice; once to compute the lap
time and once to reset the timer. This can lead to time discrepancies
between actual and computed durations when summing the result of
Timer.lap in a loop. This commit fixes that.

also fix Timer.read to not require a pointer
2020-02-23 18:25:52 -05:00
LemonBoy
08047cd6d7 correct test expectations 2020-02-23 22:47:48 +01:00
xackus
9c35f680f7 nuke @bytesToSlice, @sliceToBytes in stage1 2020-02-23 19:03:55 +01:00
xackus
7664c3bc11 remove @bytesToSlice, @sliceToBytes from tests, docs 2020-02-23 18:03:50 +01:00
Andrew Kelley
cfe1fbad0f Merge pull request #4304 from daurnimator/auto-json
Add "automatic" JSON facilities
2020-02-23 11:25:15 -05:00
frmdstryr
597648231b Format decmial 0.0 with no precision as just 0 2020-02-23 11:17:06 -05:00
Andrew Kelley
d1243bf272 Merge pull request #4525 from ziglang/environ
update std lib to integrate with libc for environ
2020-02-23 01:38:03 -05:00
Andrew Kelley
94c3dbf9e3 remove no-longer-valid defer 2020-02-23 01:07:19 -05:00
Andrew Kelley
767f041068 std.process: fix typo 2020-02-22 17:49:52 -05:00
Andrew Kelley
cfffb9c5e9 improve handling of environment variables on Windows
std.os.getenv and std.os.getenvZ have nice compile errors when not linking
libc and using Windows.

std.os.getenvW is provided as a Windows-only API that does not require
an allocator. It uses the Process Environment Block.
std.process.getEnvVarOwned is improved to be a simple wrapper on top of
std.os.getenvW.

std.process.getEnvMap is improved to use the Process Environment Block
rather than calling GetEnvironmentVariableW.

std.zig.system.NativePaths uses process.getEnvVarOwned instead of
std.os.getenvZ, which works on Windows as well as POSIX.
2020-02-22 17:35:36 -05:00
Andrew Kelley
936d0b18b1 update std lib to integrate with libc for environ
closes #3511
2020-02-22 15:59:13 -05:00
Andrew Kelley
0cd89e9176 std.os.execvpeZ_expandArg0: fix not restoring argv[0]
This function expands argv[0] into the absolute path resolved with PATH
environment variable before making the execve syscall. However, in case
the execve fails, e.g. with ENOENT, it did not restore argv to how it
was before it was passed in. This resulted in the caller performing an
invalid free.

This commit also adds verbose debug info when native system C compiler
detection fails. See #4521.
2020-02-22 13:56:02 -05:00
LemonBoy
495e894225 delete extra code, more forgiveness 2020-02-22 12:44:21 +01:00
LemonBoy
41bca1ce76 unification: windows debug info 2020-02-22 12:05:50 +01:00
LemonBoy
c060cae3ce unification: osx debug info 2020-02-22 11:51:45 +01:00
Andrew Kelley
dca19b6757 fix regression in detecting native glibc version
closes #4519
2020-02-21 20:48:50 -05:00
Andrew Kelley
6305ce828b fix regression in standardTargetOptions 2020-02-21 19:22:50 -05:00
Andrew Kelley
570973761a add regression test for already fixed bug
closes #3586
2020-02-21 15:31:00 -05:00
Andrew Kelley
6aecc268fd remove the allocator from std.event.Loop
closes #3539
2020-02-21 15:20:36 -05:00
Andrew Kelley
dff7ca6784 annotate TODO comment with bug tracker link 2020-02-21 14:20:07 -05:00
Andrew Kelley
10e0b07135 Merge pull request #4509 from ziglang/sub-architecture-annihilation
sub-architecture annihilation
2020-02-21 14:19:20 -05:00
xackus
783e8ad031 remove @bytesToSlice, @sliceToBytes from std lib 2020-02-21 19:46:53 +01:00
xackus
fdae5f5a07 implement bytesAsSlice, sliceAsBytes 2020-02-21 19:40:29 +01:00
Andrew Kelley
71573584cd std.Target.parse gives parsing diagnostics 2020-02-21 13:34:55 -05:00
Andrew Kelley
7da7fbb912 update ARM cpu models to correctly include the sub-arch 2020-02-21 12:29:27 -05:00
Andrew Kelley
61c67a9833 remove sub-arch from stage1 2020-02-21 11:47:34 -05:00
Andrew Kelley
ab56d3e18c fix std.Target unit tests 2020-02-21 11:07:56 -05:00
LemonBoy
8df4d7e4f4 unsure 2020-02-21 12:11:04 +01:00
Andrew Kelley
a391a82e49 fix zig build adding invalid cli args 2020-02-21 01:58:40 -05:00
Andrew Kelley
7b8b4d200c fix not initializing some ZigTarget fields 2020-02-21 01:54:00 -05:00
Michael Dusan
770631cc79 stage1: free more heap after analysis
- immediately free dangling IrInstGenConst after analysis
- fixup mem::List params `&Allocator` → `*Allocator`
2020-02-20 21:05:37 -05:00
Andrew Kelley
2de7d0b10c fix zig build, ABI ABI, and update tests to new Target layout 2020-02-20 18:50:20 -05:00
Andrew Kelley
903127f36c Merge remote-tracking branch 'origin/master' into sub-architecture-annihilation 2020-02-20 18:36:04 -05:00
Andrew Kelley
0f016b368d support -mcpu=baseline, both in stage1 and stage2
See e381a42de9 for more details.
This is set up so that if we wish to make "baseline" depend on the
OS in the future, it is possible to do that.
2020-02-20 18:31:17 -05:00
Andrew Kelley
e381a42de9 quick fix: add -mcpu=baseline support to zig0
When the build.zig logic to build libzigstage2 was converted to a cmake
command, it neglected to use baseline CPU features rather than compiling
with native features.

This adds a hard coded flag `-mcpu=baseline` which can be used to detect
the native target, but mark it as non-native so that it does not get the
CPU features specific to the host used to compile libzigstage2.

Full `-mcpu` support is happening in the upcoming pull request #4509,
and so this "quick fix" will be cleaned up in that branch, before it is
merged to master.

closes #4506
2020-02-20 17:02:29 -05:00
Andrew Kelley
b0d2ebe529 remove std.io.readLine
This was deceptive. It was always meant to be sort of a "GNU readline"
sort of thing where it provides a Command Line Interface to input text.
However that functionality did not exist and it was basically a red
herring for people trying to read line-delimited input from a stream.

In this commit the API is deleted, so that people can find the proper
API more easily.

A CLI text input abstraction would be useful but may not even need to be
in the standard library. As you can see in this commit, the guess_number
CLI game gets by just fine by using `std.fs.File.read`.
2020-02-20 15:30:00 -05:00
Andrew Kelley
33c69d5cb6 arm: clarify which CPU features are sub-architectures
versus which ones are instruction sets.
2020-02-20 15:27:42 -05:00
LemonBoy
a4d0d7f1de soldier on 2020-02-20 20:48:54 +01:00
LemonBoy
342a274948 tidy interface, const correctness 2020-02-20 20:18:51 +01:00
LemonBoy
ce2efbdca6 Correctly count all the loaded modules on Windows 2020-02-20 19:41:29 +01:00
LemonBoy
d5b583008a sudoku 2020-02-20 19:41:29 +01:00
LemonBoy
fabab58528 less hideous 2020-02-20 19:41:29 +01:00
LemonBoy
b9c02e4076 elvis entered the building 2020-02-20 19:41:29 +01:00
LemonBoy
2a350cf174 osx 2020-02-20 19:41:29 +01:00
LemonBoy
b3f728585a windows widestring 2020-02-20 19:41:29 +01:00
LemonBoy
463f704431 wide 2020-02-20 19:41:29 +01:00
LemonBoy
99649794e9 win 2020-02-20 19:41:29 +01:00
LemonBoy
b0b60cd468 tmp 2020-02-20 19:41:29 +01:00
LemonBoy
3620b67c26 debug: Split the DWARF stuff in its own file 2020-02-20 19:41:28 +01:00
Andrew Kelley
3d53a95718 Merge branch 'LemonBoy-fix-4508' 2020-02-20 12:40:11 -05:00
Andrew Kelley
ec889d5888 NO_MEDIA_IN_DEVICE => return error.NoDevice 2020-02-20 12:39:46 -05:00
Andrew Kelley
9c3eff9193 Revert "arm: clean up the messy sub-architecture & CPU features"
This reverts commit 96f45c27b6.
2020-02-20 12:18:32 -05:00
LemonBoy
ae16a6773f std: Handle NO_MEDIA_IN_DEVICE error in openFileWindows
Closes #4507
2020-02-20 13:25:45 +01:00
LemonBoy
a385547786 ir: Compile error on result_loc type mismatch w/ slicing
Closes #4508
2020-02-20 13:14:19 +01:00
Michael Dusan
c49ab049c5 Merge pull request #4511 from mikdusan/stage1-verbose-ir
stage1/ir_print: show GenConst in trailing fahsion
2020-02-20 02:48:03 -05:00
Michael Dusan
81cc52d4af stage1/ir_print: show GenConst in trailing fahsion 2020-02-20 00:51:36 -05:00
Andrew Kelley
3c76e5e33d update tls in std lib for lack of sub-arch 2020-02-19 22:09:35 -05:00
Andrew Kelley
7c298c8c17 fix generation of builtin import 2020-02-19 22:09:25 -05:00
Andrew Kelley
884d150408 stage1 main: fix cli parsing of architecture 2020-02-19 22:09:05 -05:00
Andrew Kelley
c33cd370fc fix unit test for Target.parse
I think this is working correctly. Without also removing sse2 from the
feature set, sse gets added back into the set because sse2 is part of
the x86_64 baseline (which is the cpu provided) and sse2 depends on sse.
2020-02-19 21:55:25 -05:00
Andrew Kelley
ef2d237f2f this is not the proper way to support this feature 2020-02-19 21:51:24 -05:00
Andrew Kelley
84f1893c18 remove the concept of "sub-architecture"
in favor of CPU features. Also rearrange the `std.Target`
data structure.

 * note: `@import("builtin")` was already deprecated in favor of
   `@import("std").builtin`.
 * `std.builtin.arch` is now deprecated in favor of
   `std.builtin.cpu.arch`.
 * `std.Target.CpuFeatures.Cpu` is now `std.Target.Cpu.Model`.
 * `std.Target.CpuFeatures` is now `std.Target.Cpu`.
 * `std.Target` no longer has an `arch` field. Instead it has a
   `cpu` field, which has `arch`, `model`, and `features`.
 * `std.Target` no longer has a `cpu_features` field.
 * `std.Target.Arch` is moved to `std.Target.Cpu.Arch` and
   it is an enum instead of a tagged union.
 * `std.Target.parseOs` is moved to `std.Target.Os.parse`.
 * `std.Target.parseAbi` is moved to `std.Target.Abi.parse`.
 * `std.Target.parseArchSub` is only for arch now and moved
    to `std.Target.Cpu.Arch.parse`.
 * `std.Target.parse` is improved to accept CPU name and features.
 * `std.Target.Arch.getBaselineCpuFeatures` is moved to
   `std.Target.Cpu.baseline`.
 * `std.Target.allCpus` is renamed to `std.Target.allCpuModels`.
 * `std.Target.defaultAbi` is moved to `std.Target.Abi.default`.
 * Significant cleanup of aarch64 and arm CPU features, resulting in
   the needed bit count for cpu feature set going from 174 to 138.
 * Add `std.Target.Cpu.Feature.Set.addFeatureSet` for merging
   feature sets together.

`-target-feature` and `-target-cpu` are removed in favor of
`-mcpu`, to conform to established conventions, and it gains
additional power to support cpu features. The syntax is:
-mcpu=name+on1+on2-off1-off2

closes #4261
2020-02-19 21:30:36 -05:00
Andrew Kelley
96f45c27b6 arm: clean up the messy sub-architecture & CPU features 2020-02-19 19:11:20 -05:00
Andrew Kelley
4c6f207aff clean up arm CPU features
* remove "cpu features" that are actually just processors
 * rename `v8` to `v8a`. this matches the corresponding
   change to target/aarch64.zig
 * rename types in preparation for removing sub-architecture
   from `std.Target`.

I have other files changed in my dirty working tree, but about to make
some changes to arm.zig that I don't want batched with this commit.
2020-02-19 18:12:06 -05:00
Bas
1483ae37f2 Add an appendValues method to ArrayList to append a value n times. (#4460) 2020-02-19 11:33:35 -05:00
daurnimator
e270db956c std: tagged unions are broken on arm64 2020-02-19 23:17:04 +11:00
daurnimator
d989396a34 std: add json.parse to automatically decode json into a struct 2020-02-19 23:16:35 +11:00
daurnimator
5a20604820 std: add json.stringify to encode arbitrary values to JSON 2020-02-19 23:01:12 +11:00
Andrew Kelley
c664692bdd make the CLI support depending on system headers and libraries
(include and lib search paths)

The detection of native system paths is self-hosted.

closes #2041
2020-02-19 01:24:34 -05:00
Andrew Kelley
63383a8af8 consistent capitalization of error message 2020-02-19 01:24:19 -05:00
Andrew Kelley
c5ca0fe237 Merge branch 'pixelherodev-emit'
Closes #4418
2020-02-18 22:01:08 -05:00
Andrew Kelley
d7968c6d33 improvements which allow zig to emit multiple things at once
example: zig build-obj test.zig -femit-llvm-ir -femit-asm

this will generate all three: test.o test.s test.ll
2020-02-18 21:59:43 -05:00
Noam Preil
dba12cd693 Rename produce_* bools to emit_* to match CLI 2020-02-18 18:59:45 -05:00
Noam Preil
9c98c73e73 Disable binary generation when deprecated --emit is used 2020-02-18 18:59:45 -05:00
Noam Preil
2502cb242a Improve support for generating LLVM IR/asm files 2020-02-18 18:59:45 -05:00
Andrew Kelley
cbc4e59e68 Merge branch 'LemonBoy-c8c8c8c8'
closes #4502
2020-02-18 18:45:25 -05:00
Andrew Kelley
30194f27fb update new test case to take into account lazy @typeInfo 2020-02-18 18:27:18 -05:00
LemonBoy
eb5e6259aa docs: Fix wrong extern fn definition 2020-02-18 18:18:29 -05:00
LemonBoy
a6b74cdd38 stage1: Make the parser reject extern fn with body 2020-02-18 18:18:29 -05:00
LemonBoy
95a71e29f8 zig fmt: Fix callconv rewriting for extern + string
Closes #4473
2020-02-18 18:18:15 -05:00
Andrew Kelley
ccca4b5a5e Merge pull request #4474 from LemonBoy/saukerkraut
Patches
2020-02-18 18:15:11 -05:00
Andrew Kelley
7f92d0d4a4 Merge branch 'daurnimator-use-fifo-from-stdio'
closes #3763
2020-02-18 16:48:58 -05:00
Andrew Kelley
a8d7652001 avoid a @ptrCast with an array literal 2020-02-18 16:48:26 -05:00
daurnimator
3632f31ec2 std: use LinearFifo to implement io.BufferedOutStreamCustom 2020-02-18 16:47:03 -05:00
daurnimator
dd75cc214d std: let PeekStream have static/dynamic variants
This completes a TODO in the existing implementation
2020-02-18 16:47:03 -05:00
daurnimator
38ad7daebb std: use LinearFifo to implement io.PeekStream 2020-02-18 16:47:03 -05:00
daurnimator
bdff2f43bd std: use LinearFifo to implement io.BufferedInStreamCustom 2020-02-18 16:47:03 -05:00
Andrew Kelley
662996e4a8 Merge branch 'FireFox317-lazy-typeinfo-decls'
Closes #4435
Closes #3893
Closes #2584
2020-02-18 15:34:22 -05:00
Andrew Kelley
d056c7732b fix std.meta.refAllDecls 2020-02-18 15:34:13 -05:00
Andrew Kelley
dd58278dbe add behavior test for previous commit 2020-02-18 15:28:14 -05:00
Timon Kruiper
7560fc716d Makes the declaration slice resolve lazely when using @typeInfo
This way all the declarations in a container won't be resolved untill
the user actually uses the decls slice in the builtin TypeInfo union.
2020-02-18 15:26:37 -05:00
Andrew Kelley
e8a84927ab Merge pull request #4478 from ziglang/self-host-libc-detection
self-hosted libc and dynamic linker detection
2020-02-17 22:45:49 -05:00
Andrew Kelley
35f0cb049e stage2: fix invalid iteration code in std.ast.Node.Asm
closes #4480
2020-02-17 20:25:02 -05:00
Andrew Kelley
99520c4e69 target_os_requires_libc implies dynamic linking 2020-02-17 19:49:19 -05:00
Andrew Kelley
5a4e8c779a smarter detectNativeDynamicLinker logic
The current target's ABI cannot be relied on for this.
For example, we may build the zig compiler for target
riscv64-linux-musl and provide a tarball for users to
download. A user could then run that zig compiler on
riscv64-linux-gnu. This use case is well-defined and
supported by Zig. But that means that we must detect
the system ABI here rather than
relying on `std.Target.current`.
2020-02-17 19:26:32 -05:00
Andrew Kelley
b53afc510c update dl_iterate_phdr test case to new API 2020-02-17 17:22:32 -05:00
Andrew Kelley
8fe636dafd fix ABI mismatch of ZigTarget in stage2 glue code 2020-02-17 16:49:30 -05:00
Andrew Kelley
9b02cab3da fix glibc not forcing dynamic link 2020-02-17 16:37:22 -05:00
Andrew Kelley
a959e98273 target requiring PIC does not imply dynamic linking
Related: #3237
2020-02-17 16:16:58 -05:00
Andrew Kelley
4b91e4c91f fix dynamic linker detection on windows (where there isn't one) 2020-02-17 16:03:01 -05:00
Andrew Kelley
e26f063b22 support the concept of a target not having a dynamic linker 2020-02-17 15:46:53 -05:00
Andrew Kelley
2f9c5c0644 self-host dynamic linker detection 2020-02-17 15:23:59 -05:00
Andrew Kelley
c784c52819 fix backwards warning of zig libc
crt_dir is only not required for darwin
2020-02-17 01:15:43 -05:00
Andrew Kelley
44c14749a1 expand argv[0] when spawning system C compiler
Some C compilers, such as Clang, are known to rely on
argv[0] to find the path to their own executable,
without even bothering to resolve PATH. This results
in the message:

error: unable to execute command: Executable "" doesn't exist!

So we tell ChildProcess to expand argv[0] to the absolute path
to give them a helping hand.
2020-02-17 00:58:30 -05:00
Andrew Kelley
64365bc5d7 enable behavior and std lib tests for RISC-V 64-bit
closes #3338
2020-02-17 00:06:19 -05:00
Andrew Kelley
a5d47be5ad stage1 os_update_file additionally compares src and dest size
prevents problems when source is created and then immediately copied to
dest.
2020-02-16 22:50:04 -05:00
Andrew Kelley
d5860cbade fix os_update_file implementation on Windows 2020-02-16 22:34:40 -05:00
Andrew Kelley
364a284eb3 stage1 os: handle errors from read/write
not sure why the CI is complaining about these now and not in master
branch. but this is a slight code improvement anyway
2020-02-16 21:35:12 -05:00
Andrew Kelley
a26800c099 stage1: don't copy unchanged output files
when both `--cache on` and `--output-dir` parameters
are provided. This prevents re-linking `zig` with every
`make` even when `libzigstage2.a` was unchanged.
2020-02-16 21:10:03 -05:00
Andrew Kelley
5c54d7bee7 add missing implementations of libc installation to detect msvc paths 2020-02-16 19:58:27 -05:00
Andrew Kelley
20f3b0efff rename libuserland to libstage2 2020-02-16 19:16:08 -05:00
Andrew Kelley
c25742010d add the dummy libc paths back in 2020-02-16 19:02:26 -05:00
Andrew Kelley
7eb0a3edce remove libc dependency of zig0 building libstage2
Rather than `zig0 build ...` the build now does
`zig0 build-lib ...`, avoiding the requirement of linking the build
script, and thus avoiding the requirement of finding native libc,
for systems where libc is the system ABI.
2020-02-16 18:57:34 -05:00
Andrew Kelley
39ee46a6c1 fix building zig0 -> zig on macos 2020-02-16 17:35:35 -05:00
Andrew Kelley
8173fbfb66 implement os.faccessat for Windows 2020-02-16 17:10:43 -05:00
LemonBoy
6b74fd2e12 ir: Avoid invalidating the decl_table iterator
Collect the declarations to resolve first and run resolve_top_level_decl
on them later.

Closes #4310
2020-02-16 21:14:30 +01:00
LemonBoy
59a243ce24 std: Remove now-superflous hack 2020-02-16 19:53:53 +01:00
LemonBoy
096f79260b ir: Prevent crash when indexing undefined ptr to array
Closes #4471
2020-02-16 19:53:53 +01:00
Andrew Kelley
4b02a39aa9 self-hosted libc detection
* libc_installation.cpp is deleted.
   src-self-hosted/libc_installation.zig is now used for both stage1 and
   stage2 compilers.
 * (breaking) move `std.fs.File.access` to `std.fs.Dir.access`. The API
   now encourages use with an open directory handle.
 * Add `std.os.faccessat` and related functions.
 * Deprecate the "C" suffix naming convention for null-terminated
   parameters. "C" should be used when it is related to libc. However
   null-terminated parameters often have to do with the native system
   ABI rather than libc. "Z" suffix is the new convention. For example,
   `std.os.openC` is deprecated in favor of `std.os.openZ`.
 * Add `std.mem.dupeZ` for using an allocator to copy memory and add a
   null terminator.
 * Remove dead struct field `std.ChildProcess.llnode`.
 * Introduce `std.event.Batch`. This API allows expressing concurrency
   without forcing code to be async. It requires no Allocator and does
   not introduce any failure conditions. However it is not thread-safe.
 * There is now an ongoing experiment to transition away from
   `std.event.Group` in favor of `std.event.Batch`.
 * `std.os.execvpeC` calls `getenvZ` rather than `getenv`. This is
   slightly more efficient on most systems, and works around a
   limitation of `getenv` lack of integration with libc.
 * (breaking) `std.os.AccessError` gains `FileBusy`, `SymLinkLoop`, and
   `ReadOnlyFileSystem`. Previously these error codes were all reported
   as `PermissionDenied`.
 * Add `std.Target.isDragonFlyBSD`.
 * stage2: access to the windows_sdk functions is done with a manually
   maintained .zig binding file instead of `@cImport`.
 * Update src-self-hosted/libc_installation.zig with all the
   improvements that stage1 has seen to src/libc_installation.cpp until
   now. In addition, it now takes advantage of Batch so that evented I/O
   mode takes advantage of concurrency, but it still works in blocking
   I/O mode, which is how it is used in stage1.
2020-02-16 13:25:30 -05:00
Andrew Kelley
5e37fc0746 more user-friendly error message for some clang diagnostics
See #4455
2020-02-16 01:45:48 -05:00
Andrew Kelley
7f7d1fbe5a Implement noasync awaits
Note that there is not yet runtime safety for this.

See #3157
2020-02-16 01:44:52 -05:00
Andrew Kelley
cb3a818699 zig fmt: support noasync await 2020-02-16 01:44:52 -05:00
Andrew Kelley
72805fd66e fix taking address of temporary async frame 2020-02-16 01:44:49 -05:00
Michael Dusan
652efe38b4 Merge pull request #4467 from mikdusan/translate-c-error
translate-c: change OutOfMemory → ASTUnitFailure
2020-02-15 15:45:02 -05:00
Michael Dusan
8583038640 translate-c: change OutOfMemory → ASTUnitFailure
- return a better error when no diagnostics are available
2020-02-15 05:14:31 -05:00
Vexu
b15958c557 fix c tokenizer bug 2020-02-14 18:57:57 -05:00
Andrew Kelley
9e1afdc234 Merge pull request #4454 from LemonBoy/capture-reform
Payload captures no longer alias the original value
2020-02-14 14:39:00 -05:00
Andrew Kelley
058f38220a enable passing freebsd tests
See #3210 and #4455
2020-02-14 12:00:38 -05:00
Andrew Kelley
816b69a344 update clang drivers to llvm10.0.0rc2 2020-02-14 10:47:40 -05:00
Andrew Kelley
f4317e4387 update libunwind to llvm10.0.0rc2 2020-02-14 10:44:23 -05:00
Andrew Kelley
2289036a40 update libcxx to llvm10.0.0rc2 2020-02-14 10:34:21 -05:00
Andrew Kelley
74619cc045 update clang C headers to 10.0.0rc2 2020-02-14 10:30:06 -05:00
Andrew Kelley
a8b36fbe34 Merge remote-tracking branch 'origin/master' into llvm10 2020-02-14 10:27:44 -05:00
LemonBoy
1c8ac2a0c1 test: Add test cases for the new capture behavior 2020-02-14 15:59:28 +01:00
Andrew Kelley
40b9db7cad Merge pull request #4451 from daurnimator/use-testing.allocator
Migrate (more) tests from FixedBufferAllocator to testing.allocator
2020-02-14 09:40:08 -05:00
Vexu
9206f8a8cd translate-c improve macro cast translation 2020-02-14 09:36:44 -05:00
xackus
7396b144ba modernize std.meta 2020-02-14 09:35:38 -05:00
LemonBoy
3038290a46 ir: Make all the payload captures do a copy
The payload doesn't alias anymore the same memory it comes from and is
instead a fresh copy of the original object.
2020-02-14 15:30:20 +01:00
daurnimator
6ea6d5a4bd std: use testing.allocator in tests 2020-02-14 19:15:09 +11:00
daurnimator
ca41567924 std: use testing.allocator in big int tests 2020-02-14 18:59:40 +11:00
daurnimator
f20ba7c32c std: increase memory available to testing allocator 2020-02-14 18:59:25 +11:00
daurnimator
b61e53cc40 std: bigint.deinit() shouldn't need a mutable pointer 2020-02-14 18:59:07 +11:00
Andrew Kelley
fb6b94f80f cmake: remove case mismatch detection on build mode
See discussion here for context:
c6df5deb34 (comments)

Michael - I appreciate what you did here, making the configure script
work better for people in practice. When it was checking the build type
against a whitelist, I think it was worth it. However, now that we are
supporting systems which use non-standard cmake build modes, I don't
think this case-mismatch detection thing is worth it. It's starting to
get to the point where it's a lot of complication for very little
benefit. Besides, cmake is not case sensitive. If we support
non-standard build modes, then we would need to support a hypothetical
build mode of `release` (lower case).

So let's just remove this and rely on people to use the build system
correctly (like they will have to do when building any cmake project
from source).
2020-02-13 20:47:44 -05:00
Felix (xq) Queißner
cf67d30cdc Makes ArenaAllocator.deinit() not require a mutable reference. 2020-02-13 16:19:34 -05:00
LemonBoy
a090a5e3bc ir: Don't crash when converting undefined ptrs 2020-02-13 16:18:24 -05:00
Andrew Kelley
e8dfc5e7f6 Merge pull request #4442 from fengb/testing-allocator-calls
Migrate tests from FixedBufferAllocator to testing.allocator
2020-02-13 16:17:21 -05:00
Andrew Kelley
de23c57133 Merge branch 'LemonBoy-revive-3904'
closes #3904
closes #4448
2020-02-13 16:14:10 -05:00
Andrew Kelley
cdba521a06 annotate skipped test with issue link 2020-02-13 16:13:53 -05:00
data-man
948a463cf1 fmt: vector formatting 2020-02-13 16:12:54 -05:00
Andrew Kelley
1675d4f82b Merge pull request #4443 from LemonBoy/werkzeug
A train of small patches
2020-02-13 13:12:18 -05:00
Vexu
fa377dbd15 fix c tokenizer bug 2020-02-13 12:21:28 -05:00
LemonBoy
f93c219f30 Minor changes for a test case 2020-02-13 12:13:56 +01:00
LemonBoy
c5260f7f86 ir: Allow implicit conversion between vector types
Only valid when the number of elements match and the types are
compatible.

Fixes #4334
2020-02-13 12:13:56 +01:00
data-man
4578d13b49 Vector comparison in meta and testing 2020-02-13 12:13:55 +01:00
Michael Dusan
1fb70497d2 Merge pull request #4441 from mikdusan/stage1-cmake
stage1: limit cmake checks on build type
2020-02-12 21:04:34 -05:00
Michael Dusan
08666a057a Merge pull request #4439 from vegecode/custom-format-comment-issue
Correct comment to include comptime attribute on format output fn par…
2020-02-12 18:35:39 -05:00
Benjamin Feng
a81ae1223d Convert a lot of json tests to use testing.allocator 2020-02-12 17:17:56 -06:00
Benjamin Feng
699c50a375 Switch a bunch of FBA to use testing.allocator 2020-02-12 17:17:56 -06:00
Michael Dusan
471662f7c9 stage1: limit cmake checks on build type
Various maintainers pass custom build types and we don't need to check
those. We are interested only in checking and diagnosing common errors
for Zig project supported types.

Check is now limited to look for case-mismatch only on the well-known
values { Debug, Release, RelWithDebInfo, MinSizeRel }.
2020-02-12 17:23:48 -05:00
LemonBoy
55304128c0 Fix rendering of empty arrays 2020-02-12 23:10:53 +01:00
LemonBoy
327d40e7a3 Fix a UAF when verbose-llvm-ir is specified
The g->module is long gone when codegen_link is called.
2020-02-12 23:10:08 +01:00
vegecode
d06bfc2e2a Correct comment to include comptime attribute on format output fn parameter
Without comptime, printing custom type through the stream interface fails
2020-02-12 13:16:32 -06:00
Andrew Kelley
ab4ea5d3cf Merge pull request #4433 from LemonBoy/ohno
Trivial patchset
2020-02-11 13:12:42 -05:00
LemonBoy
6c05f0949a ir: Fix erroneous error message for ptr casts
Don't blindly throw an error if two integer types are checked for
compatibility.

Bug reported in #4430
2020-02-11 17:03:11 +01:00
LemonBoy
b81c5be451 riscv: Remove 'relax' from the baseline cpu features
LLD doesn't implement relaxations at the moment.
2020-02-11 17:03:11 +01:00
LemonBoy
f8fd8c481a test: Skip the atomic-on-fp test for riscv64 2020-02-11 17:03:10 +01:00
LemonBoy
ea8755fda9 compiler-rt: Export the AEABI builtins when targeting thumb 2020-02-11 15:24:18 +01:00
Michael Dusan
e624c86289 Merge pull request #4389 from mikdusan/stage1-mem
stage1: memory/report overhaul
2020-02-10 23:08:33 -05:00
Michael Dusan
edb210905d stage1: memory/report overhaul
- split util_base.hpp from util.hpp
- new namespaces: `mem` and `heap`
- new `mem::Allocator` interface
- new `heap::CAllocator` impl with global `heap::c_allocator`
- new `heap::ArenaAllocator` impl
- new `mem::TypeInfo` extracts names without RTTI
- name extraction is enabled w/ ZIG_ENABLE_MEM_PROFILE=1
- new `mem::List` takes explicit `Allocator&` parameter
- new `mem::HashMap` takes explicit `Allocator&` parameter
- add Codegen.pass1_arena and use for all `ZigValue` allocs
- deinit Codegen.pass1_arena early in `zig_llvm_emit_output()`
2020-02-10 21:08:08 -05:00
Timon Kruiper
2618366055 Add cast between [*c]T and ?[*:0]T on fn parameter
Fixes #4176
2020-02-10 19:43:58 -05:00
LemonBoy
3237528a59 fmt: Pass the fmt string to the inner formatters 2020-02-10 19:43:11 -05:00
Andrew Kelley
3170ead9eb compile error instead of abort for unimplemented @typeInfo
of `@Frame(func)`. Closes #3995
2020-02-10 19:14:54 -05:00
Andrew Kelley
702398dd0e Revert "windows: remove the 'A' versions of psapi functions"
This reverts commit 1cdefeb10b.

See #4426
2020-02-10 12:30:20 -05:00
Andrew Kelley
1cdefeb10b windows: remove the 'A' versions of psapi functions
See #534
2020-02-10 12:03:11 -05:00
Vexu
ae5ba369e1 translate-c float fixes 2020-02-10 11:02:29 -05:00
Andrew Kelley
70a4794c57 fix compiler assertion when duplicating fields...
...in nested anonymous struct literals

closes #4391
2020-02-10 10:57:40 -05:00
Andrew Kelley
cdc5070f21 Merge remote-tracking branch 'origin/master' into llvm10 2020-02-10 00:26:33 -05:00
Andrew Kelley
014f66e6de Merge pull request #4404 from ziglang/async-std
a big step towards std lib integration with async I/O
2020-02-10 00:22:59 -05:00
Andrew Kelley
27575d19c8 avoid conflict with master branch 2020-02-09 22:44:23 -05:00
Andrew Kelley
acdf4048b4 allow local variable address detection to regress
See #3180 for a more comprehensive plan to catch this problem. More
sophisticated control flow analysis is needed to provide compile errors
for returning local variable addresses from a function.
2020-02-09 22:40:36 -05:00
Andrew Kelley
5ea79bfc4a fix not checking type of return pointer
Thanks to Vexu for the test cases.

Closes #3422
Closes #3646
Closes #3224
Closes #3327
Closes #3269
2020-02-09 22:34:34 -05:00
Andrew Kelley
04ee3b01a1 fix defer interfering with return value spill 2020-02-09 17:19:28 -05:00
Andrew Kelley
3b622f4494 fix off-by-one error in std.unicode.utf8ToUtf16LeWithNull
and fix larger-than-one-byte sentinels when being freed

Thank you to João Pedro for identifying both problems and
providing example code to solve them.

closes #4413
2020-02-09 14:56:19 -05:00
LemonBoy
c4d0f97b4c compiler_rt: Fix clzsi2 implementation for Thumb1
The LUT contains the number of bits set, not the number of leading zeros
as we're subtracting from the total number of bits in a word.

Closes #4415
2020-02-09 14:12:01 -05:00
Andrew Kelley
5b10d9f917 std: fix bitrotted evented code 2020-02-08 16:24:26 -05:00
Andrew Kelley
6ae36807b7 solve recursion in std.atomic.Queue.dump
by adding a maximum depth
2020-02-08 16:22:53 -05:00
Andrew Kelley
24d197b037 solve previous commit a better way 2020-02-08 15:28:12 -05:00
Andrew Kelley
d80db3546c Revert "properly spill optional payload capture value"
This reverts commit 80ba21b83c.
2020-02-08 15:07:12 -05:00
Andrew Kelley
80ba21b83c properly spill optional payload capture value 2020-02-08 14:59:33 -05:00
Andrew Kelley
884804dbc3 fix async runtime function call resolves target fn frame 2020-02-08 13:45:31 -05:00
Andrew Kelley
c48831512b std lib typo fixups 2020-02-08 01:38:01 -05:00
Andrew Kelley
eddca50059 fix regression in docgen
I used the wrong function here
2020-02-08 00:03:06 -05:00
Jared Miller
b55bc5eb26 Add wWinMain and wWinMainCRTStartup to fix #4376 2020-02-07 22:52:40 -05:00
Andrew Kelley
0e7461d4a3 Merge pull request #4408 from LemonBoy/mmap-i386-fix
handle SIGBUS, fix mmap on i386 linux
2020-02-07 22:51:43 -05:00
Andrew Kelley
877f39d227 fix async function call resolves target fn frame 2020-02-07 22:48:31 -05:00
Andrew Kelley
39ee1f4b97 fix invalid behavior tests from prev commit
and fix "no-op casts" from incorrectly spilling
2020-02-07 16:31:52 -05:00
LemonBoy
a779450fef linux/i386: Make syscall6 more robust and correct
LLVM10 exposed a subtle flaw in the previous implementation that made
the mmap tests fail.
2020-02-07 22:13:05 +01:00
Andrew Kelley
4a60689309 more carefully calculate llvm field indexes
more correctly solves #4403
2020-02-07 14:54:58 -05:00
Andrew Kelley
9e5b248991 remove workarounds for Windows native CPU features
bug fixed in LLVM 10

closes #508
2020-02-07 12:41:46 -05:00
Andrew Kelley
3fce8008cc skip self-hosted for now as we work towards async I/O
1. behavior tests with --test-evented-io
 2. std lib tests with --test-evented-io
 3. fuzz test evented I/O a bit, make it robust
 4. make sure it works on all platforms (kqueue, Windows IOCP,
    epoll/other)
 5. restart efforts on self-hosted
2020-02-07 12:30:16 -05:00
Andrew Kelley
7f4cce3345 add fcntl support on darwin 2020-02-07 12:11:15 -05:00
pwzk
eff50abce6 Fixing library search path 2020-02-07 12:08:41 -05:00
Andrew Kelley
a1576225ca Merge pull request #4409 from LemonBoy/llvm-10-fpchanges
LLVM10 changes
2020-02-07 11:47:18 -05:00
Andrew Kelley
71873e7133 implement os.pipe2 for darwin 2020-02-07 11:28:42 -05:00
LemonBoy
e3447e67fe riscv64: Enable some more tests
Closes #3338
2020-02-07 17:21:28 +01:00
LemonBoy
8d6536b50c codegen: Use the new frame-pointer fn attributes
no-frame-pointer-elim and no-frame-pointer-elim-non-leaf have been
deprecated for a while in favour of the newer (and clearer)
frame-pointer attribute.

Starting with LLVM10 the old attributes are silently ignored, leading to
no stack traces in debug mode.
2020-02-07 17:08:21 +01:00
LemonBoy
7a58ec81ec std: Add a few tests for mmap/munmap 2020-02-07 16:07:12 +01:00
LemonBoy
be02616c86 debug: Show a nice error message on SIGBUS 2020-02-07 16:06:33 +01:00
Andrew Kelley
0b5bcd2f56 more std lib async I/O integration
* `zig test` gainst `--test-evented-io` parameter and gains the ability
   to seamlessly run async tests.
 * `std.ChildProcess` opens its child process pipe with O_NONBLOCK when
   using evented I/O
 * `std.io.getStdErr()` gives a File that is blocking even in evented
   I/O mode.
 * Delete `std.event.fs`. The functionality is now merged into `std.fs`
   and async file system access (using a dedicated thread) is
   automatically handled.
 * `std.fs.File` can be configured to specify whether its handle is
   expected to block, and whether that is OK to block even when in
   async I/O mode. This makes async I/O work correctly for e.g. the
   file system as well as network.
 * `std.fs.File` has some deprecated functions removed.
 * Missing readv,writev,pread,pwrite,preadv,pwritev functions are added
   to `std.os` and `std.fs.File`. They are all integrated with async
   I/O.
 * `std.fs.Watch` is still bit rotted and needs to be audited in light
   of the new async/await syntax.
 * `std.io.OutStream` integrates with async I/O
 * linked list nodes in the std lib have default `null` values for
   `prev` and `next`.
 * Windows async I/O integration is enabled for reading/writing file
   handles.
 * Added `std.os.mode_t`. Integer sizes need to be audited.
 * Fixed #4403 which was causing compiler to crash.

This is working towards:

./zig test ../test/stage1/behavior.zig --test-evented-io

Which does not successfully build yet. I'd like to enable behavioral
tests and std lib tests with --test-evented-io in the test matrix in the
future, to prevent regressions.
2020-02-06 18:05:50 -05:00
Andrew Kelley
786700249e build: fix handling disabling .h file generation 2020-02-06 13:46:59 -05:00
LemonBoy
cfcaf09cce debug: Improve the frame-walking strategy
Clean up the code a bit and introduce a few checks meant to avoid
overshooting the end of the frame chain.
The code is now stable enough not to cause panics during the call frame
walking.
2020-02-06 11:25:40 -05:00
Andrew Kelley
5cf30b6791 Merge pull request #4369 from daurnimator/gimli
std.crypto.gimli enhancements
2020-02-05 18:13:28 -05:00
Andrew Kelley
e1f4f44dff std: improve non-libc dynamic library loading
this is a cherry-pick of
5076f2d4f6
from the llvm10 branch
2020-02-05 18:10:26 -05:00
Andrew Kelley
80ae434b66 Merge pull request #4397 from LemonBoy/fixes
Fixes
2020-02-05 17:04:40 -05:00
Andrew Kelley
704cd977bd ability to run tests in evented I/O mode
This adds `--test-evented-io` as a CLI parameter.

see #3117
2020-02-05 16:53:29 -05:00
Andrew Kelley
84323504ac std.fmt.format: comptime output parameter 2020-02-05 16:52:18 -05:00
Andrew Kelley
378d733439 Merge pull request #4345 from Rocknest/open-di
Fix double close in openElfDebugInfo
2020-02-05 15:56:56 -05:00
Andrew Kelley
5076f2d4f6 std: improve non-libc dynamic library loading 2020-02-05 15:31:09 -05:00
LemonBoy
8c55c4550a std: Rename isAbsoluteW to isAbsoluteWindowsW 2020-02-05 20:39:14 +01:00
LemonBoy
9d41ff335c std: Make TCSA enum ABI-compliant 2020-02-05 20:37:00 +01:00
LemonBoy
21932a0ef2 Fix edge case in cast between fn with varargs
* Prevent the next_param_index to become greater than the param_count
  one as it's expected by every other function.
* Fix a typo in a error message.

Closes #4381
2020-02-05 20:31:18 +01:00
Andrew Kelley
40b1fecace Merge pull request #4363 from Vexu/trans-std-c
Use std.c.tokenizer in translate-c
2020-02-05 14:29:39 -05:00
Vexu
f196ddd251 translate c type names 2020-02-05 17:52:46 +02:00
Rocknest
f30feab1b9 Link the issue in doc comment 2020-02-05 17:19:00 +02:00
Rocknest
a56183197d Fix double close in openElfDebugInfo 2020-02-05 17:18:30 +02:00
Michael Dusan
b022db16ec Merge pull request #4394 from mikdusan/fix-cmake-regression
stage1: fix cmake regression
2020-02-05 10:01:16 -05:00
Michael Dusan
d0a9da74ef stage1: fix cmake regression
- add `None` as a valid CMAKE_BUILD_TYPE
- this is a legitimate setting used by packagers

regression was caused by c6df5deb34
2020-02-05 08:24:50 -05:00
daurnimator
ef4ecaa462 std: add AEAD modes for gimli 2020-02-06 00:21:26 +11:00
daurnimator
b495512175 add gimli to crypto hash benchmark 2020-02-06 00:16:00 +11:00
daurnimator
5a095a3f08 std: add Gimli based PRNG to std.rand 2020-02-06 00:16:00 +11:00
Vexu
1f49460dcb fix regressions in comments and string prefixes 2020-02-05 08:35:30 +02:00
Michael Dusan
25cbee0b84 Merge pull request #4390 from mikdusan/cherry-pick
stage1: guard against case-mismatched build types
2020-02-04 22:34:46 -05:00
Michael Dusan
c6df5deb34 stage1: guard against case-mismatched build types
- zig CMakeLists.txt CMAKE_BUILD_TYPE string comparisons are case-sensitive
- cmake itself is unclear about how tolerant it is for case-mismatches
- add CMAKE_BUILD_TYPE guard in CMakeLists.txt to force exact matches
2020-02-04 20:39:05 -05:00
LemonBoy
3e7c02edc1 std: Fix edge case in isAbsolute fn family
* Empty strings are not considered absolute paths.
* Refactor some common code.

Closes #4382
2020-02-04 15:52:38 -05:00
Andrew Kelley
1530e82b6b re-apply: these are not real CPU features
The commit 70ee818d21
(update target CPUs and features with llvm10's data)
accidentally reverted 6793af8d8b.

This un-reverts it.
2020-02-04 15:16:44 -05:00
Andrew Kelley
73256dda91 work around LLVM 10 llvm-config giving absolute path to libz.so 2020-02-04 15:04:11 -05:00
nofmal
a697de3eac Add basic linux termios implementation 2020-02-04 14:09:57 -05:00
Andrew Kelley
a9df637fb1 fix undef clang library symbols when linking self-hosted 2020-02-04 03:39:40 -05:00
Andrew Kelley
d0b12d7726 Merge remote-tracking branch 'origin/master' into llvm10 2020-02-03 17:30:38 -05:00
Andrew Kelley
0fdcd5c4cb Merge pull request #4337 from LemonBoy/stdlib-bsearch
stdlib: Add binary search function
2020-02-03 16:53:00 -05:00
LemonBoy
1658becb62 fmt: Fix one more edge case in container formatting 2020-02-03 16:03:48 -05:00
LemonBoy
db3aea3a0b Change API for binarySearch fn 2020-02-03 21:51:03 +01:00
Andrew Kelley
5504f155aa Merge pull request #4366 from jayschwa/blake3
crypto: Add BLAKE3 hashing algorithm
2020-02-03 15:13:50 -05:00
Michaël Larouche
9b11e5e1f1 Add InstallRawStep to Zig build system that does a similar job to llvm-objcopy. To use it, do 'exe.installRaw("kernel.bin");' where exe is a LibExeObjStep
Part of #2826
2020-02-03 15:07:34 -05:00
Jay Petacat
cb2c14e03f blake3: Workaround issue #4373 with named types 2020-02-02 18:44:50 -05:00
LemonBoy
958f00f1c7 Don't generate any type info for void return types
Closely matches what the LLVM debug emitter expects, the generated DWARF
infos are now standard-compliant.
2020-02-02 15:30:12 -05:00
Andrew Kelley
a795c36d7b Merge pull request #4352 from LemonBoy/fix-4349
fmt: Respect trailing commas in field declarations
2020-02-02 15:27:53 -05:00
frmdstryr
32291ab702 Add support for dependent packages when using build.zig 2020-02-02 15:21:27 -05:00
Jay Petacat
923e567c6d blake3: Replace &arr with arr[0..] for slice args 2020-02-02 14:59:36 -05:00
Jay Petacat
b143fc0d32 blake3: Name and const pointer refinements 2020-02-02 14:42:57 -05:00
Jay Petacat
d098e212ad blake3: Convert *const [n]u8 types to [n]u8
I do not see many cases of constant pointers to arrays in the stdlib.
In fact, this makes the code run a little faster, probably because Zig
automatically converts to pointers where it makes sense.
2020-02-02 14:08:10 -05:00
Vexu
35c40f0a70 fix regressions 2020-02-02 10:49:51 +02:00
Jay Petacat
4b86c1e3bb crypto: Add BLAKE3 hashing algorithm
This is a translation of the [official reference implementation][1] with
few other changes. The bad news is that the reference implementation is
designed for simplicity and not speed, so there's a lot of room for
performance improvement. The good news is that, according to the crypto
benchmark, the implementation is still fast relative to the other
hashing algorithms:

```
         md5: 430 MiB/s
        sha1: 386 MiB/s
      sha256: 191 MiB/s
      sha512: 275 MiB/s
    sha3-256: 233 MiB/s
    sha3-512: 137 MiB/s
     blake2s: 464 MiB/s
     blake2b: 526 MiB/s
      blake3: 576 MiB/s
    poly1305: 1479 MiB/s
    hmac-md5: 653 MiB/s
   hmac-sha1: 553 MiB/s
 hmac-sha256: 222 MiB/s
      x25519: 8685 exchanges/s
```

[1]: https://github.com/BLAKE3-team/BLAKE3
2020-02-01 23:03:23 -05:00
Vexu
3b23929be5 use std.c.tokenizer in translate-c 2020-02-02 01:40:46 +02:00
daurnimator
4f2652d504 Winsock errors can be an enum 2020-02-01 14:29:16 -05:00
LemonBoy
0bf91cce58 windows: Minor changes to psapi prototypes 2020-02-01 13:43:46 -05:00
LemonBoy
e548195fd5 fmt: Use left brace position instead of the right one
Fix a typo and add a test case.
2020-02-01 15:28:23 +01:00
LemonBoy
f34abbf260 fmt: Handle declarations in line with the opening brace 2020-02-01 14:43:31 +01:00
LemonBoy
3640c682a2 Run zig fmt 2020-02-01 11:32:53 +01:00
LemonBoy
8309ee8752 fmt: Respect trailing comma for field declarations
Closes #4349
2020-02-01 11:28:21 +01:00
Andrew Kelley
e6a812c827 Merge pull request #4340 from daurnimator/ntstatus-as-enum
Windows error codes as non-exhaustive enums
2020-01-31 18:27:17 -05:00
LemonBoy
dee7804a81 fmt: Fix logic to find the argument list closing )
Closes #4341
2020-01-31 18:25:58 -05:00
Andrew Kelley
a62b4f268a Merge pull request #4347 from LemonBoy/psapi
windows: Add psapi API
2020-01-31 18:25:25 -05:00
LemonBoy
c910aa8555 windows: Add GetCurrentProcess definition 2020-02-01 00:01:09 +01:00
LemonBoy
9ffc13b6c4 windows: Add psapi API
Export both the "old-style" definitions from psapi and the "new-style"
ones from kernel32.
2020-01-31 23:50:26 +01:00
daurnimator
ab46713fa6 std: update for linux 5.5 release 2020-01-31 10:18:17 -05:00
daurnimator
a351350b88 std: format non-exhaustive enums 2020-01-31 22:33:56 +11:00
daurnimator
b9f720365c Turn win32 errors into a non-exhaustive enum 2020-01-31 22:33:55 +11:00
daurnimator
7cf0b02ab4 NTSTATUS is a non-exhaustive enum 2020-01-31 22:33:17 +11:00
LemonBoy
176bc53858 translate-c: Fix translation of fn pointers
Closes #4332
2020-01-30 21:33:50 -05:00
meme
1e78070a40 build: Fix missing dupe
- Strange memory corruption issues occur when allocated memory is passed to the builder and it is `defer`'d and freed
- Instead, `dupe` the string as is done in other handlers, this fixes the issue
2020-01-30 20:57:31 -05:00
Andrew Kelley
644a344715 self-hosted: add missing arch switch prong 2020-01-30 18:45:25 -05:00
Andrew Kelley
a475877007 fix translate-c regression
clang.zig had incorrect enum for builtin types
2020-01-30 18:43:54 -05:00
Andrew Kelley
c5df0b3e9d set llvm cpu features to null for exynosm1,exynosm2
llvm dropped support for these features
2020-01-30 18:43:28 -05:00
LemonBoy
fd8d8afb24 stdlib: Add binary search function 2020-01-31 00:40:43 +01:00
LemonBoy
d27678fe83 fmt: Refactor the arg fetching code
* Error out if the requested index is out-of-bound
* Tidy-up all the arg-related variables in a struct
2020-01-30 18:07:02 -05:00
Andrew Kelley
17c8f108a4 drop @newStackCall
this was causing unrelated behavior tests to fail.

if this commit is reverted, the docs are good, but `@newStackCall` is
already deprecated in favor of `@call`, supplying the `stack` property.
2020-01-30 17:51:55 -05:00
Andrew Kelley
13f7824266 Merge pull request #4326 from LemonBoy/fix-4181
Generate compilable code for array inits
2020-01-30 16:12:23 -05:00
Andrew Kelley
4d2fed6232 zig fmt behavior tests 2020-01-30 16:10:08 -05:00
Andrew Kelley
58c97b3561 fix llvm assertion with debug info for vectors 2020-01-30 15:30:38 -05:00
Andrew Kelley
7b5f4a8d10 fix llvm assertion with debug info for vectors 2020-01-30 15:30:03 -05:00
LemonBoy
979c69d6b2 Amend some failing test cases 2020-01-30 19:53:35 +01:00
LemonBoy
c944865fc7 Generate compilable code for array inits
The compiler still doesn't like too much the newfangled anonymous arrays
so let's use the old-style declarations.

Closes #4181
2020-01-30 19:45:08 +01:00
Shawn Landden
cbd42e44d6 rb: fix rb.Node.getLast() that never worked 2020-01-30 12:05:57 -05:00
Andrew Kelley
70ee818d21 update target CPUs and features with llvm10's data
based on zig-llvm-target-details-generator
commit 3aef1b9b4415ed3acfaea4ce8bc233e213548f71
2020-01-30 11:31:41 -05:00
Andrew Kelley
14d9582e9a ci: don't rely on sourcehut's pkg system 2020-01-30 10:23:00 -05:00
Andrew Kelley
65b1a4953f Merge pull request #4324 from fengb/testing-allocator
Remove debug.global_allocator in favor of testing.allocator
2020-01-30 10:01:40 -05:00
Andrew Kelley
e3a383a661 Merge pull request #4239 from shawnl/rb
rb: **breaking** change API to be thread-safe
2020-01-30 09:45:35 -05:00
Andrew Kelley
0303e7bd8e Merge pull request #4319 from Rocknest/windows-traces
Bring windows segfault handler on par with linux
2020-01-30 09:26:39 -05:00
LemonBoy
e77a102e24 Small DWARF fixups
* Clang doesn't seem to emit a DW_AT_low_pc together with DW_AT_ranges
  for asm files.
* Keep reading the other CUs if the lookup fails.
2020-01-30 09:11:02 -05:00
Rocknest
a5f18c2b2a Fix one more edge case 2020-01-30 10:00:28 +02:00
Benjamin Feng
9c196efa2a Add explicit error message for too many frees 2020-01-30 01:12:21 -06:00
Rocknest
94f29ae117 Remove intCast's 2020-01-30 08:53:38 +02:00
Benjamin Feng
46d84a1b63 Convert a few more page_allocator 2020-01-30 00:27:44 -06:00
Benjamin Feng
c1fb97aef6 Remove unnecessary allocator from mutex 2020-01-30 00:27:44 -06:00
Benjamin Feng
184128fd9e Fix testing.allocator wiring 2020-01-30 00:27:44 -06:00
Andrew Kelley
c75f65d38c std.Target: add ve arch 2020-01-29 23:58:28 -05:00
Andrew Kelley
a63a2fdf76 update zig_clang bindings to release/10.x 2020-01-29 23:50:24 -05:00
Andrew Kelley
c7fa71d233 update clang driver to release/10.x branch
upstream commit 967658150edb2cbb860c19ce54ac1e216bdc8461
2020-01-29 23:38:21 -05:00
Andrew Kelley
a95dce15ae Merge remote-tracking branch 'origin/master' into llvm10 2020-01-29 23:33:12 -05:00
Benjamin Feng
5c8e85f388 Fix BufMap value leak 2020-01-29 22:22:01 -06:00
Benjamin Feng
b7a236d68e Convert a bunch of page_allocator to testing.allocator 2020-01-29 22:22:01 -06:00
Benjamin Feng
ad93ad3e60 Fix errant reference to page_allocator 2020-01-29 22:22:01 -06:00
Benjamin Feng
837877ea37 Update docs to reflect new testing.allocator usage 2020-01-29 22:22:01 -06:00
Benjamin Feng
898ef82d65 Patch in arena to cleanup leaks 2020-01-29 22:22:00 -06:00
Benjamin Feng
b077f3ab7d Promoted "leak_count_allocator" to the main testing.allocator 2020-01-29 22:22:00 -06:00
Benjamin Feng
70ad84c820 Use defer/panic to better account for test failure 2020-01-29 17:38:52 -06:00
Benjamin Feng
0c137934cb Move FailingAllocator to testing 2020-01-29 17:38:42 -06:00
Rocknest
b1884b3a62 Fix aarch64 2020-01-30 01:17:34 +02:00
Andrew Kelley
7ebc624a15 Merge branch 'LemonBoy-fix-4259' 2020-01-29 17:21:29 -05:00
Andrew Kelley
f97b398b65 simplify int/float comparison 2020-01-29 17:20:41 -05:00
Rocknest
c0c9c601d4 Fix off-by-one error 2020-01-29 23:48:52 +02:00
LemonBoy
fe4ef7b461 Fix comptime float-int comparisons
Closes #4259
2020-01-29 16:37:55 -05:00
Benjamin Feng
ffd30dbe28 Fix stage1 test 2020-01-29 15:30:13 -06:00
Rocknest
4a4d6f2be9 Reorganize definitions 2020-01-29 23:15:17 +02:00
Valentin Anger
d448c3d38a Add support for code model selection 2020-01-29 16:09:07 -05:00
LemonBoy
59bc1d2721 Fix edge case in switch with single else
ir_gen_switch_expr doesn't set the switch_br field at all if there are
zero cases, detect this situation and handle it gracefully.

Closes #4322
2020-01-29 16:05:14 -05:00
Benjamin Feng
c4e6e5fad6 Add explicit free to docs 2020-01-29 14:47:17 -06:00
Benjamin Feng
aa9caf5064 Create leak_count_allocator 2020-01-29 14:37:01 -06:00
Rocknest
b7cd60a354 Changing stuff and seeing what happens 2020-01-29 21:09:00 +02:00
Andrew Kelley
4fad16284e Merge pull request #4320 from fengb/while-spills
Add async spills to while captured variables
2020-01-29 13:37:58 -05:00
Benjamin Feng
4d134a01f5 Move debug.global_allocator to testing.allocator 2020-01-29 12:21:29 -06:00
Andrew Kelley
34706dad3f fix typo in doc comment 2020-01-29 12:25:25 -05:00
Andrew Kelley
0cc2489d22 Merge pull request #4317 from Vexu/std-c
Add (unfinished) C parser to std lib
2020-01-29 12:13:53 -05:00
LemonBoy
534014f84e translate-c: Handle fn protos wrapped in parenthesis
Closes #4289
2020-01-29 12:06:53 -05:00
LemonBoy
1ba4554855 Correct dl_iterate_phdr address
The base should be zero so that p_vaddr + dlpi_addr = p_vaddr
2020-01-29 12:05:36 -05:00
Benjamin Feng
9a0a378e2f Add test cases for suspend in while loops 2020-01-29 10:01:51 -06:00
Benjamin Feng
a4ac7980b4 Add a spill to while error union 2020-01-29 10:01:51 -06:00
Rocknest
3500b41bfe Add an advanced segfault handler on windows 2020-01-29 17:27:53 +02:00
Vexu
abd1a7c91c std-c add todos to unfinished parsing functioins 2020-01-29 12:12:28 +02:00
Benjamin Feng
2f239e3dbd Add a spill to while optional 2020-01-28 23:36:43 -06:00
LemonBoy
3ec37c979e Build compiler_rt/c with optimizations if possible 2020-01-28 19:28:39 -05:00
Andrew Kelley
13259acbc3 std.sort.insertionSort: remove superfluous block 2020-01-28 16:22:09 -05:00
Andrew Kelley
76fba5baf9 Merge pull request #4152 from ziglang/ir-clean-up-vars
pay off some result location technical debt with regards to "mem slots"
2020-01-28 16:21:41 -05:00
Andrew Kelley
3ed52e5453 fix build.zig logic for -target-cpu and -target-feature
fix a false negative for detecting the ability to emit these flags.
it matters for stage0/stage1 on aarch64
2020-01-28 14:54:34 -05:00
Andrew Kelley
504ce86ac9 fix more compile error test regressions 2020-01-28 14:17:25 -05:00
Andrew Kelley
793d81c4e8 fix result locations not handling undefined correctly 2020-01-28 13:33:51 -05:00
Andrew Kelley
86da9346e4 fix error message column/line number regressions 2020-01-28 13:25:49 -05:00
Andrew Kelley
e0000c47bd fix regression of storing optional with 0-bit payload 2020-01-28 12:32:39 -05:00
Andrew Kelley
5c55a9b4e8 fix compile error regression with struct containing itself 2020-01-28 11:52:48 -05:00
Andrew Kelley
287d3c37e1 fix 0-bit child type coerced to optional return ptr result location
by un-special-casing 0 bit types in result locations
2020-01-28 11:39:36 -05:00
Andrew Kelley
8710fdbf39 fix line, column numbers of compile errors 2020-01-27 22:05:27 -05:00
Zac
926a7adb3a Update langref.html.in
Fix typo
2020-01-27 21:39:29 -05:00
Andrew Kelley
ae20574d5e add missing spill for for loops with pointer elems 2020-01-27 21:30:11 -05:00
Andrew Kelley
c58633ef17 fix assertion with var debug loc not initialized 2020-01-27 20:56:24 -05:00
Andrew Kelley
9d59cdb8c1 fix auto created variables not having correct alignment 2020-01-27 19:42:32 -05:00
Andrew Kelley
d8e2549996 remove invalid use of allowzero in std.crypto.murmur 2020-01-27 19:42:13 -05:00
Andrew Kelley
37ab960492 fix not handling undefined u0 correctly 2020-01-27 18:59:46 -05:00
Andrew Kelley
b38b967844 fix triple level result location with bitcast sandwich
...passed as tuple element
2020-01-27 18:26:39 -05:00
Andrew Kelley
b96872ef2f @bitCast result location: fix passing invalid alignment
when the value has 0 bits
2020-01-27 17:45:29 -05:00
Andrew Kelley
c0fee9dfc7 fix nested bitcast passed as tuple element 2020-01-27 17:30:39 -05:00
Andrew Kelley
e2778c03e0 Merge branch 'master' into ir-clean-up-vars 2020-01-27 13:32:39 -05:00
Andrew Kelley
d896500259 Merge branch 'LemonBoy-fix-4274' 2020-01-27 09:52:49 -05:00
Andrew Kelley
f41e50dc08 Merge branch 'fx-4274' of https://github.com/LemonBoy/zig into LemonBoy-fix-4274 2020-01-27 09:52:31 -05:00
Andrew Kelley
4591389497 Merge pull request #4300 from LemonBoy/debug-windows
More debug fixes - This time Windows gets a treat
2020-01-27 09:46:39 -05:00
LemonBoy
d5c2a20d8e Unify the two DWARF interpreters
* Let's consolidate the special-cased DWARF interpreter for OSX with the
  general purpose one

* Drop the assumption that all the debug data is contained in a single
  contiguous slice of memory. This is a good news for freestanding
  targets and paves the way for supporting compressed debug sections.
2020-01-27 09:46:20 -05:00
LemonBoy
7336b750bd Fix stack-trace address calculation on Windows
Let's always subtract 1 from the return address so that we're sure to be
inside the callee.

Fixes some edge case where the stack trace skipped the first entry.
2020-01-27 13:12:01 +01:00
LemonBoy
f8e015c85f Handle S_GPROC32 symbols in PDB files
Fixes some incomplete stack traces on Windows.
2020-01-27 13:10:35 +01:00
Andrew Kelley
518dbd30cb Merge pull request #4133 from daurnimator/4087-free-sets-undefined
Sets memory to undefined when freed from allocator
2020-01-26 18:52:43 -05:00
Andrew Kelley
51ac8eb08e fix regression in windows stack traces tty detection 2020-01-26 18:28:52 -05:00
Andrew Kelley
96e5f476c3 Merge pull request #4264 from ziglang/layneson-cpus_and_features
Add support for target details (CPUs and their supported features)
2020-01-26 09:57:25 -05:00
Andrew Kelley
3839ea8978 fix debug info code not being freestanding compatible
in stack tracing code, the idea was to detect the tty settings at the
top of the stack and pass the information down. somewhere along the way
this got changed so that setTtyColor was assuming the global stderr_file
was related to the output stream the stack trace was being printed to.

now, tty_color is changed to tty_config, and it is an enum rather than a
bool, telling how tty colors are expected to be handled. windows is
still incorrectly looking at stderr_file.
2020-01-26 09:55:04 -05:00
Andrew Kelley
d9fb6c2054 fix compilation error 2020-01-26 00:55:04 -05:00
Andrew Kelley
9dffc369f1 Merge remote-tracking branch 'origin/master' into layneson-cpus_and_features 2020-01-25 23:25:29 -05:00
Andrew Kelley
4e9b1f5479 Merge pull request #4290 from ziglang/split-ir-structs
split IrInstruction into IrInst, IrInstSrc, IrInstGen
2020-01-25 23:24:41 -05:00
Andrew Kelley
32f0039b43 fix memory profiling 2020-01-25 22:02:10 -05:00
Andrew Kelley
6aac423964 split IrInstruction into IrInst, IrInstSrc, IrInstGen
This makes it so that less memory is used for IR instructions, as well
as catching bugs when one expected one kind of instruction and received
the other.
2020-01-25 21:49:32 -05:00
LemonBoy
aaa2f9ab2f Fix handling of DW_LNE_end_sequence
The DWARF specification states that LNE_end_sequence should just reset
the state machine, it's not an error.
2020-01-25 20:03:50 -05:00
LemonBoy
8516ee392c Fix parsing of DW_AT_Ranges debug entry
Follow the specification about what the base address is and how it can
be changed by some entries in the list itself.
2020-01-25 16:12:11 -05:00
Feix Weiglhofer
a4a9330648 translate-c: Don't make const parameters mutable. (#4273)
* translate-c: Remove arg-prefix from const parameters.
* translate-c: Add unittest for const parameters.
2020-01-24 15:32:32 -05:00
Michael Dusan
aa75df36df Merge pull request #4279 from mikdusan/create-global-cache
stage1: make sure to create native_libc.txt dir
2020-01-24 00:31:18 -05:00
Tadeo Kondrak
3d8328abce Don't include stdbool.h for void and unreachable
Fixes https://github.com/ziglang/zig/issues/4272
2020-01-23 23:24:45 -05:00
Michael Dusan
b54040d394 stage1: make sure to create native_libc.txt dir
- fix regression from #4186
2020-01-23 21:59:28 -05:00
Andrew Kelley
800ead2810 update target info to llvm 10
the branch builds now
2020-01-23 17:31:25 -05:00
Andrew Kelley
79fb486017 link: update to llvm 10 API 2020-01-23 17:28:13 -05:00
Andrew Kelley
72589dbffe zig_clang builds with llvm 10 2020-01-23 17:22:13 -05:00
Andrew Kelley
32dafbdadc zig_clang: update StmtClass to llvm 10 2020-01-23 16:52:40 -05:00
LemonBoy
8d9b8ab930 More error checking for unresolved TLDs
Closes #4274
2020-01-23 22:40:12 +01:00
Andrew Kelley
3588f99719 zig_clang: update TypeClass enum 2020-01-23 14:35:12 -05:00
Andrew Kelley
fbfda7f00e fix incorrect list of sub-arches for aarch64
tests use older sub-arch that works in the older qemu
2020-01-23 13:02:45 -05:00
Andrew Kelley
c86589a738 disable f128 compiler_rt tests failing on windows
These were never working with native CPU features. In this branch,
we fix native CPU features not being enabled on Windows, and regress
f128 language features. In the llvm10 branch, all this is fixed,
and the tests are re-enabled.
2020-01-23 02:05:24 -05:00
Andrew Kelley
1a08c0d40b new test case 2020-01-23 00:46:44 -05:00
Andrew Kelley
ead7d15772 use an older arm64 sub-arch for test suite
hopefully this avoids the older qemu version crashing
2020-01-23 00:41:46 -05:00
Michael Dusan
357f42da6c compiler_rt: fix mulsi3 test typo 2020-01-22 20:17:38 -05:00
Andrew Kelley
fb8e681ea8 update zig_llvm.h and zig_llvm.cpp to llvm 10 2020-01-22 18:43:30 -05:00
Andrew Kelley
9845264a0b aarch64: less feature-full baseline CPU 2020-01-22 18:40:34 -05:00
LemonBoy
a284be3f69 Fix unsafe cast in translate_c
Fixes #4250
2020-01-22 17:58:57 -05:00
Andrew Kelley
211e1b1ced ci: update to llvm 10 2020-01-22 17:54:58 -05:00
Andrew Kelley
0c477f3c79 fix std.Target.Arch.parseCpuFeatureSet unit test 2020-01-22 17:47:18 -05:00
Andrew Kelley
74872263cc lib/headers: update to clang 10.x C headers
upstream revision: 3cce3790072249cbe51b96cea26bc78019c11fd0
2020-01-22 17:42:44 -05:00
Andrew Kelley
3227aec848 fix not respecting sub-arch feature 2020-01-22 17:35:57 -05:00
Andrew Kelley
b94525c45b Merge pull request #4263 from LemonBoy/debug-thing
Refactor some debug stuff
2020-01-22 17:32:48 -05:00
Andrew Kelley
48c7e6c48b std.Target.CpuFeatures is now a struct with both CPU and feature set
Previously it was a tagged union which was one of:
 * baseline
 * a specific CPU
 * a set of features

Now, it's possible to have a CPU but also modify the CPU's feature set
on top of that. This is closer to what LLVM does.

This is more correct because Zig's notion of CPUs (and LLVM's) is not
exact CPU models. For example "skylake" is not one very specific model;
there are several different pieces of hardware that match "skylake" that
have different feature sets enabled.
2020-01-22 17:13:31 -05:00
LemonBoy
69c72e24d4 compiler-rt: Port __mulsi3 builtin 2020-01-22 13:04:45 -05:00
Andrew Kelley
97b2ac598b Merge remote-tracking branch 'origin/master' into llvm10 2020-01-22 12:12:36 -05:00
Andrew Kelley
c6bfece1d5 Revert "tests: use an older aarch64 sub-arch"
This reverts commit 4640ef589e.

This attempted workaround did not have the desired effect.
2020-01-21 22:24:40 -05:00
Andrew Kelley
cbe9a51518 don't trust llvm's GetHostCPUName
comment from this commit reproduced here:

I have observed the CPU name reported by LLVM being incorrect. On
the SourceHut build services, LLVM 9.0 reports the CPU as "athlon-xp",
which is a 32-bit CPU, even though the system is 64-bit and the reported
CPU features include, among other things, +64bit.
So the strategy taken here is that we observe both reported CPU, and the
reported CPU features. The features are trusted more; but if the features
match exactly the features of the reported CPU, then we trust the reported CPU.
2020-01-21 22:02:13 -05:00
Andrew Kelley
830e0ba2d2 enable native CPU feature for windows; disable failing tests
See #508. These can be re-enabled when we upgrade to LLVM 10.
2020-01-21 21:46:06 -05:00
Andrew Kelley
4640ef589e tests: use an older aarch64 sub-arch
to avoid an illegal instruction error with the older qemu
version that is available on the CI server.
2020-01-21 21:02:33 -05:00
Andrew Kelley
6e6ec3d71d put hack back in to disable windows native cpu features
See #508. This can be removed when we upgrade to LLVM 10.
2020-01-21 21:01:36 -05:00
Andrew Kelley
68b6867e76 lazily compute the full cpu features dependencies 2020-01-21 20:11:36 -05:00
Andrew Kelley
92559cd02c hit a comptime limitation with computing dense sets 2020-01-21 19:40:44 -05:00
LemonBoy
b8601e9252 Adjust tests & work around a nasty ICE 2020-01-21 23:17:02 +01:00
LemonBoy
59d0dda080 Make writeByteNTimes faster and leaner 2020-01-21 20:58:02 +01:00
LemonBoy
bc82e0f3d3 Refactor some code in the debug output 2020-01-21 20:51:57 +01:00
Andrew Kelley
15d5cab569 fix target_triple_zig to emit zig-compatible triples 2020-01-21 12:25:22 -05:00
Andrew Kelley
91ecce3bc0 fix cache of cpu features 2020-01-21 12:14:43 -05:00
Andrew Kelley
6793af8d8b these are not real cpu features 2020-01-21 12:14:36 -05:00
Andrew Kelley
327ad0ae89 target_triple_llvm: emit none instead of unknown 2020-01-21 03:05:56 -05:00
Andrew Kelley
1f7babbc80 properly forward baseline target cpu features to llvm 2020-01-21 03:01:20 -05:00
Andrew Kelley
0abaee79af fix self-hosted compiler regression 2020-01-21 01:51:21 -05:00
Andrew Kelley
5974f95cb7 add cpus and cpu features to zig targets 2020-01-21 01:48:25 -05:00
Andrew Kelley
0c2dde2fda add libc and glibcs to self-hosted zig targets 2020-01-21 01:31:27 -05:00
Andrew Kelley
39759b90fc make zig targets show native cpu name and features 2020-01-21 01:22:37 -05:00
Andrew Kelley
e640d01535 fixups to arch data, support any number of cpu features 2020-01-21 00:34:54 -05:00
Andrew Kelley
6118b11afa Revert "aarch64: remove CPU features that are actually just CPUs"
This reverts commit 6dd514ac8a.

This strategy won't work for arm 32-bit; instead need to try to figure
out how to get more bits into the bit set.
2020-01-20 23:15:07 -05:00
Andrew Kelley
89e107ee4e uncomment all the archs in target.zig 2020-01-20 23:14:35 -05:00
Andrew Kelley
6dd514ac8a aarch64: remove CPU features that are actually just CPUs 2020-01-20 22:49:26 -05:00
Andrew Kelley
6e88883edf import data from llvm 9 2020-01-20 22:21:45 -05:00
Andrew Kelley
f3dd9bbdac improve zig targets 2020-01-20 13:40:25 -05:00
Andrew Kelley
bf82929557 fix std.Target.Arch.parseCpuFeatureSet 2020-01-20 12:41:18 -05:00
LemonBoy
c522699f28 Fix ICE in build addAssemblyFile 2020-01-20 12:24:55 -05:00
Nathan Michaels
0000de4fee Handle {s} format for C strings. (#4219)
* Handle {s} format for C strings.

* Fix "cstr" test to actually use c strings.
2020-01-20 12:23:43 -05:00
daurnimator
5cc4932461 std: allocator interface sets freed memory to undefined 2020-01-21 03:17:40 +11:00
daurnimator
65013d8599 std: fix bug in http.headers where .put captures user-held variable 2020-01-21 03:17:36 +11:00
Andrew Kelley
8f29d14073 stage1 is building. zig targets now self-hosted 2020-01-20 01:42:31 -05:00
Andrew Kelley
20af858601 some fixes 2020-01-19 21:06:41 -05:00
Andrew Kelley
e3b5e91878 do the x86 arch 2020-01-19 20:54:05 -05:00
Andrew Kelley
a313f15384 figure out zig0/stage1 and scanning for native CPU 2020-01-19 20:54:05 -05:00
Andrew Kelley
a867b43366 progress towards merging
see BRANCH_TODO file
2020-01-19 20:54:04 -05:00
Layne Gustafson
c15623428e Pass target_details to child CodeGens 2020-01-19 20:53:20 -05:00
Layne Gustafson
430077df1b Allow target details with no LLVM support 2020-01-19 20:53:20 -05:00
Layne Gustafson
62e4cc06fe Pass target details to c compiler 2020-01-19 20:53:20 -05:00
Layne Gustafson
35c681b7b1 Fix sentinel mismatch in llvm strings
Previously, buffers were used with toOwnedSlice() to create c strings
for LLVM cpu/feature strings. However, toOwnedSlice() shrinks the
string memory to the buffer's length, which cuts off the null terminator.
Now toSliceConst() is used instead, and the buffer is not deinited
so that the string memory is not freed.
2020-01-19 20:53:20 -05:00
Layne Gustafson
8902f3ca32 Enable 64bit feature for riscv64 2020-01-19 20:53:20 -05:00
Layne Gustafson
de8a5cf5f5 Remove features/cpus not in LLVM v9 2020-01-19 20:53:20 -05:00
Layne Gustafson
a5c9397539 No allocations for n.t. empty strings 2020-01-19 20:53:20 -05:00
Layne Gustafson
40ff359486 Only enable requested features 2020-01-19 20:53:20 -05:00
Layne Gustafson
ebb6f15bba Make sure llvm strings are null-terminated 2020-01-19 20:53:20 -05:00
Layne Gustafson
fd17a9962b Add defaut feature support 2020-01-19 20:53:20 -05:00
Layne Gustafson
03dd376b55 Add builtin.zig support 2020-01-19 20:53:19 -05:00
Layne Gustafson
c61856ebcf Add TargetDetails abstraction 2020-01-19 20:53:19 -05:00
Layne Gustafson
79a2747de4 Add llvm_name to feature defs 2020-01-19 20:53:19 -05:00
Layne Gustafson
e4ecdefa9a Rename subfeatures -> dependencies 2020-01-19 20:53:19 -05:00
Layne Gustafson
51372200d3 Filter out non-features 2020-01-19 20:53:19 -05:00
Layne Gustafson
c1798cb632 Add build.zig cpu and feature options 2020-01-19 20:53:19 -05:00
Layne Gustafson
b3324f1901 Add cpu/feature to cache hash 2020-01-19 20:53:19 -05:00
Layne Gustafson
bd6ef21f85 Add cpu/feature specification to cmndline 2020-01-19 20:53:19 -05:00
Layne Gustafson
c8f1e0d6d8 Remove llvm_name from features 2020-01-19 20:53:19 -05:00
Layne Gustafson
c131e50ea7 Switch CPU/features to simple format 2020-01-19 20:53:18 -05:00
Layne Gustafson
9d66bda264 Fix spacing in main.cpp 2020-01-19 20:53:18 -05:00
Layne Gustafson
5bc4690d85 Make targets cmd able to list CPUs and features 2020-01-19 20:53:18 -05:00
Layne Gustafson
21908e100e Fix CPU and feature defs 2020-01-19 20:53:18 -05:00
Layne Gustafson
8ac138a318 Add parseArchTag and fix parseArchSub 2020-01-19 20:53:18 -05:00
Layne Gustafson
8f191e0166 Update term feature deps -> subfeatures 2020-01-19 20:53:18 -05:00
Layne Gustafson
0f46c12f78 Create initial target details infrastructure 2020-01-19 20:53:15 -05:00
Shawn Landden
ad15a73240 rb: type Tree.sort with SortError 2020-01-19 23:35:56 +04:00
Vexu
ad327fed05 std-c redo scoping, do string concatanation in parser 2020-01-19 20:44:55 +02:00
LemonBoy
7a1cde7206 Fix wrong error code being returned in enum analisys
Fixes the assertion failure seen in #4233
2020-01-19 13:28:27 -05:00
Andrew Kelley
e491b2f5a7 Merge pull request #4231 from LemonBoy/more-builtin-work1
More patches for compiler-rt
2020-01-19 13:27:36 -05:00
Shawn Landden
4ab9678b95 rb: add sort() that re-sorts tree with new compare function
You can also specify the same compare function, but after updating the
context that the function will use (connected to the rb.Tree) before.
2020-01-19 22:10:21 +04:00
Shawn Landden
e190082922 rb: *breaking* make API thread-safe
use @fieldParentPtr to access your context fields, which lie if you
struct that contains a rb.Tree member (without a pointer).

Also simplifies the init() function so rb.Tree can be initialized in a single line,
without having to use "undefined".
2020-01-19 22:09:56 +04:00
Shawn Landden
de07ca77e7 rb: just use @include("std")
we already have to use --override-std-dir
when running std tests, and having it this way
makes it much easier to run just the tests of this file.
2020-01-19 22:05:38 +04:00
LemonBoy
861724bcf0 Fix some tests broken by the renamed files 2020-01-19 09:31:45 +01:00
Andrew Kelley
7bb4c855ad Merge pull request #4222 from LemonBoy/eutwouwth
Prevent crash with empty non-exhaustive enum
2020-01-18 19:25:23 -05:00
LemonBoy
5fbc1c2812 Nuke some more code 2020-01-19 00:12:27 +01:00
LemonBoy
3247fd7862 Export MSVC builtins inconditionally 2020-01-19 00:12:27 +01:00
LemonBoy
ae31da9334 Minor cleanup 2020-01-19 00:12:26 +01:00
LemonBoy
6b056d1fb9 Nuke some repeated code 2020-01-19 00:12:25 +01:00
LemonBoy
7d94e712f1 Remove useless wrappers around f32/f64 aeabi builtins 2020-01-19 00:12:18 +01:00
LemonBoy
fa52c9e36e Small cleanups 2020-01-19 00:11:45 +01:00
Sebastian
405b8e9eee fixed typo - "path" lead to undeclared identifier 2020-01-18 17:56:53 -05:00
Andrew Kelley
f47b7a0437 Merge pull request #4220 from LemonBoy/fix-4214
Allow @tagName on enum literals
2020-01-18 17:55:21 -05:00
daurnimator
72ec445677 std: turn EAI_ constants into a non-exhaustive enum 2020-01-18 17:46:44 -05:00
daurnimator
9e6e1e58bb std: use non-exhaustive enums from crc module
Un-reverts PR #3118
2020-01-18 17:42:45 -05:00
LemonBoy
b0f753e21d Fix edge case in tagName handling of unions
Closes #4226
2020-01-18 20:16:15 +01:00
LemonBoy
f456b88bae Get rid of some dead logic 2020-01-18 19:24:04 +01:00
LemonBoy
c53d94e512 Prevent crash with empty non-exhaustive enum 2020-01-18 15:13:21 +01:00
LemonBoy
5f2bac010d Allow @tagName on enum literals
Closes #4214
2020-01-18 09:55:18 +01:00
Michael Dusan
b72f858194 Merge pull request #4215 from mikdusan/cmake-install
cmake: support `make` and `make install`
2020-01-17 21:35:29 -05:00
Michael Dusan
b9f4ac86ef cmake: support make and make install
(2nd attempt to get this right)
2020-01-17 19:39:43 -05:00
Andrew Kelley
b5ac079f88 Merge pull request #4191 from Vexu/non-exhaustive-enums
Implement non-exhaustive enums
2020-01-17 14:26:12 -05:00
Michaël Larouche
d9be6e5dc6 Port clzsi2 from compiler_rt, required for using std.fmt.format on some ARM architecture. 2020-01-17 14:25:22 -05:00
Michael Dusan
d53e8a5751 Revert "cmake: support make and make install"
This reverts commit cd062b08d0.
2020-01-17 14:24:54 -05:00
Vexu
39f92a9ee4 improve behavior test 2020-01-17 09:50:20 +02:00
Michael Dusan
9348609e6a Merge pull request #4208 from mikdusan/contributing
doc: update contributing
2020-01-17 02:49:25 -05:00
Michael Dusan
af9eb7ac13 doc: update contributing 2020-01-17 02:47:47 -05:00
Michael Dusan
ab2cb435e5 Merge pull request #4209 from mikdusan/cmake-install
cmake: fix install lib path message
2020-01-17 02:45:32 -05:00
Michael Dusan
97cca1376a cmake: fix install lib path message 2020-01-17 00:53:41 -05:00
Andrew Kelley
396d57c498 fix failing array test by improving copy_const_val 2020-01-16 21:58:53 -05:00
Andrew Kelley
8f336b3970 revert one part of ir get_elem_ptr analysis
this reverts one part of 4c3bfeca. it solves some behavior regressions
but introduces new ones. This change was incorrect to make however,
and this commit takes the code in a better direction.
2020-01-16 21:58:52 -05:00
Andrew Kelley
6a8c9f7306 fix regression with optionals and globals 2020-01-16 21:58:52 -05:00
Andrew Kelley
b952b84486 relax language requirements regarding else unreachable 2020-01-16 21:58:52 -05:00
Andrew Kelley
8bf425957b fix regressions double implicit casting return ptr 2020-01-16 21:58:52 -05:00
Andrew Kelley
e48157c3cb fix regression with inferred struct fields 2020-01-16 21:58:52 -05:00
Andrew Kelley
fb8da16a60 fix regressions in get_elem_ptr related to undefined 2020-01-16 21:58:52 -05:00
Andrew Kelley
d0b055d69e fix implicit cast regression 2020-01-16 21:58:52 -05:00
Andrew Kelley
96d64a40a6 fix regression with var ptrs not being const 2020-01-16 21:58:52 -05:00
Andrew Kelley
b6c8fead00 fix regression in global const alignment 2020-01-16 21:58:51 -05:00
Andrew Kelley
fbcee58cfc zig ir.cpp details: remove the mem_slot mechanism
Previously, there was hacky code to deal with result locations and how
they work with regards to comptime values and runtime values. In
addition, there was a hacky "mem_slot" mechanism that managed the memory
for local variables, and acted differently depending on comptime vs
runtime situations. All that is deleted in this commit, and as a result,
result locations code has one less complication.

Importantly, this means that a comptime result location is now passed to
a function when it is evaluated at comptime.

This test causes many regressions, and some of the behavior tests are
disabled (commented out) in this commit. Future commits will re-enable
the tests before merging the branch.
2020-01-16 21:58:47 -05:00
Michael Dusan
0240fd9140 Merge pull request #4206 from mikdusan/cmake-install
cmake: support `make` and `make install`
2020-01-16 21:40:05 -05:00
Andrew Kelley
7e674d6761 zig_llvm: update CodeGenFileType usage 2020-01-16 21:32:07 -05:00
Michael Dusan
cd062b08d0 cmake: support make and make install
- `make` or `ninja` will not build but not install
- `make install` or `ninja install` will build __and__ install

Only for build system generator Visual Studio, specify the following
to disable installation of lib files:

    ZIG_SKIP_INSTALL_LIB_FILES=ON
2020-01-16 18:56:13 -05:00
Vexu
6c8f01dcde correct field count 2020-01-16 22:52:10 +02:00
Andrew Kelley
56f433b3d9 update clang drivers to llvm 10.x (ac446302c) 2020-01-16 14:03:38 -05:00
Vexu
bac27731e3 add struct field default value to typeinfo 2020-01-16 13:22:30 -05:00
Vexu
df03fcf5f0 implement @bitSizeOf 2020-01-16 13:13:45 -05:00
Andrew Kelley
ba4cc03b4f remove embedded LLD
we no longer have any patches against upstream LLD
2020-01-16 13:09:45 -05:00
Andrew Kelley
fbe6af81fd Merge remote-tracking branch 'origin/master' into llvm10 2020-01-16 13:01:36 -05:00
LemonBoy
f609ce4f65 Minor changes to the ARM builtin fns 2020-01-16 12:50:53 -05:00
LemonBoy
7e5e767ba0 Fix regression in char printing
Closes #4014
2020-01-16 12:17:16 -05:00
LemonBoy
0267afa9c0 Fix garbled error messages from clang 2020-01-16 12:16:30 -05:00
Vexu
6450736c5f translate-c default enum tag type to c_int 2020-01-16 12:50:44 +02:00
Vexu
cb257b4e11 allow non-exhaustive enums with no fields 2020-01-16 09:23:26 +02:00
Vexu
d84569895c turn panics into compile errors, require at least 1 field in non-exhaustive enum 2020-01-16 09:04:11 +02:00
Andrew Kelley
8a792db2d8 Merge pull request #4187 from LemonBoy/builtin-rearrange
Some needed work on builtins
2020-01-15 18:39:50 -05:00
Vexu
02e5cb1cd4 add non-exhaustive enum to langref 2020-01-15 23:05:52 +02:00
Vexu
5c2238fc4a small fixes
* error for '_' prong on exhaustive enum
* todo panic for `@tagName`  on non-exhaustive enum
* don't require '_' field on tagged unions
2020-01-15 22:09:19 +02:00
Vexu
c57784aa15 add is_exhaustive field to typeinfo 2020-01-15 21:50:12 +02:00
Vexu
f3d174aa61 require size for non-exhaustive enums 2020-01-15 21:38:11 +02:00
Vexu
0ea96c11ef disallow multiline strings in test and library names 2020-01-15 14:20:48 -05:00
LemonBoy
e8012740b9 Fix off-by-one error (and missing store op) 2020-01-15 20:03:41 +01:00
Vexu
b971c7d0ff update tests and translate-c 2020-01-15 20:58:42 +02:00
Michael Dusan
0a41051955 stage1: move local native_libc.txt to global
Automatic creation of `native_libc.txt` now occurs only in global
cache. Manual creation/placement into local cache is supported.

closes #3975
2020-01-15 13:42:12 -05:00
Vexu
6fd0dddf18 implement non-exhaustive enums 2020-01-15 20:24:59 +02:00
LemonBoy
ede28755b6 Fix test case 2020-01-15 18:41:07 +01:00
LemonBoy
c5cfc9bf68 Move definition of __aeabi_read_tp 2020-01-15 17:50:51 +01:00
LemonBoy
5d5345728a Fix div builtins to use the correct calling convention 2020-01-15 17:50:51 +01:00
LemonBoy
109e5f8a5a Remove unnecessary logic 2020-01-15 17:50:51 +01:00
LemonBoy
44e3796285 Rearrange some builtin functions placement 2020-01-15 12:48:28 +01:00
Andrew Kelley
8d9d4a0658 Merge pull request #4182 from LemonBoy/mjeiorw
A bunch of patches
2020-01-15 04:28:54 -05:00
LemonBoy
c85afff5a8 Correct l_name field type 2020-01-14 23:11:10 +01:00
LemonBoy
49771f356f Make sure @export symbol name is not empty 2020-01-14 21:23:11 +01:00
LemonBoy
c1f3766f1c Correct dlpi_name field type 2020-01-14 21:15:33 +01:00
LemonBoy
158d98a7f2 Print sentinel value in ir_print 2020-01-14 21:13:55 +01:00
Michaël Larouche
7ee0e779af Fix std.child_process.ChildProcess.spawnWindow when looking in PATH environment variable, it applied cwd+app_name instead of just using the app_name 2020-01-14 15:12:30 -05:00
LemonBoy
505b9db909 Fix codegen error for some union initializers
Closes #3377
2020-01-14 14:57:03 -05:00
Vexu
af2ede4d96 fix crash on multiline library name 2020-01-14 13:10:52 -05:00
LemonBoy
50754ba336 Fix ICE when BoundFn are passed as parameters
Closes #4022
Closes #3699
2020-01-14 13:09:23 -05:00
Shritesh
4c87281b5c [docs] Add libc dependency to sentinel-term ptr example
Fixes "dependency on library c must be explicitly specified in the build command" error
2020-01-14 13:07:08 -05:00
Hersh Krishna
e7917d099d Add clamp function to math module 2020-01-14 13:06:46 -05:00
Vexu
28daddae81 std-c todos and small fixes 2020-01-14 16:18:32 +02:00
Andrew Kelley
d3e67d9921 Merge pull request #4172 from LemonBoy/swish
Two switch-related patches
2020-01-13 18:01:19 -05:00
LemonBoy
cae93c860b Allow switching on pointer types
Closes #4074
2020-01-13 22:18:49 +01:00
LemonBoy
84930fec27 Validate switch range endpoints 2020-01-13 21:45:16 +01:00
Andrew Kelley
b9f37ffe19 fix outdated comment 2020-01-13 14:48:43 -05:00
Andrew Kelley
4f9739189e add an extra assert 2020-01-13 14:48:43 -05:00
Andrew Kelley
c774c9376a Merge pull request #3957 from xackus/stage2_parser_3799
stage2 parser: fix segfault on extern block
2020-01-13 13:38:31 -05:00
Emilio G. Cota
2be12b24bc doc/langref: mention that x is the sentinel in [N:x]T
Without looking at the example it is not possible to know
whether N or x is the sentinel value. Fix it.
2020-01-13 11:49:46 -05:00
Andrew Kelley
4d4852ad31 Merge pull request #4162 from LemonBoy/fix-4020
Fix @call being too eager to resolve the fn argument
2020-01-13 11:48:54 -05:00
LemonBoy
54b11f66a9 Fix compiler-error regression 2020-01-13 08:49:32 +01:00
Michael Dusan
d08009556e Merge pull request #4161 from mikdusan/stage1-builtin-debugtrap
prefer C++ compiler builtins for BREAKPOINT
2020-01-12 18:28:10 -05:00
LemonBoy
34cdcb13c0 Fix @call being too eager to resolve the fn argument
Closes #4020
2020-01-12 23:51:18 +01:00
Michael Dusan
25b1ae0a5f prefer C++ compiler builtins for BREAKPOINT
Fix breakpoints on macOS to trap EXC_BREAKPOINT with correct
source location when using lldb. Old behavior with `raise(SIGTRAP)`
traps SIGTRAP and incorrect source location.

Fix breakpoints on archlinux to trap SIGILL with correct source
location when using gdb. Old behavior with `raise(SIGTRAP)`
traps SIGTRAP and (sometimes) incorrect source location with
very shallow (break in main) stack.

when building stage1:
- w/ clang, use `__builtin_debugtrap()`
- w/ gcc, use `__builtin_trap()`
- else use `raise(SIGTRAP)`
2020-01-12 16:41:11 -05:00
LemonBoy
c96131f30c Propagate errors in for loop bodies
Closes #3819
2020-01-12 12:49:12 -05:00
hryx
c4770e7aa5 docs: update grammar to remove C strings and add anon literals 2020-01-12 04:35:45 -05:00
Michael Dusan
a6f6d8d2f7 Merge pull request #4139 from mikdusan/stage1-relative-path-errors
strip cwd from compile error paths
2020-01-11 19:21:54 -05:00
Michael Dusan
fc20a58993 strip cwd from compile error paths
closes #43138
2020-01-11 16:45:57 -05:00
data-man
860d88037a Correct TypeId docs 2020-01-11 15:59:00 -05:00
LemonBoy
34ae1d9aa8 Fix unsafe cast in translate_c
* Handle EmptyDecls to clean up the generated code

Closes #4143
2020-01-11 15:51:10 -05:00
Jonathan Marler
0827e298ed Add WaitForSingleObject function to std.os.windows 2020-01-11 15:49:48 -05:00
LemonBoy
95619ecb8c Stop dropping errors from clang
* Refactor the error-writing code to be more compact and flexible
2020-01-11 15:48:32 -05:00
Vexu
4c0776b2a5 std-c parse switch 2020-01-11 21:48:12 +02:00
xackus
5880eb3a75 stage2 parser: document undefined and clean up 2020-01-10 22:48:51 +01:00
LemonBoy
9cc7fb66bc Don't special-case builtin too much
Let's use the usual declaration-searching mechanism that resolves the
`usingnamespace` declarations on the go instead of directly peeking into
the symbol table.

Fixes #4134
2020-01-10 16:44:15 -05:00
LemonBoy
84e98405de Inform the debugger about the effective type sizes
Makes every debugger happy and closes #2685
2020-01-10 16:42:49 -05:00
xackus
f81529fab1 stage2 parser: fix segfault on extern block 2020-01-10 22:35:41 +01:00
LemonBoy
570ffc470e Handle forward-declared functions
Closes #4130
2020-01-10 16:34:40 -05:00
Andrew Kelley
e06a6b9645 Merge pull request #4129 from daurnimator/windows-child_process
Fix windows child process creation
2020-01-10 03:00:25 -05:00
travisstaloch
3f98756f85 Fix translation of signed array indices (#4113)
* cast only if the index is long long or signed
* cast long long to usize rather than c_uint

closes #4075
2020-01-10 00:08:24 -05:00
daurnimator
03e1241b88 std: avoid an allocation in inner loop 2020-01-10 15:03:51 +11:00
daurnimator
6fb636050f std: fix off by one error in windows process creation 2020-01-10 15:00:14 +11:00
Andrew Kelley
ae324985a6 clean up a TODO in self-hosted 2020-01-09 15:31:49 -05:00
Andrew Kelley
5e345ff0ee Merge pull request #3955 from LemonBoy/fix-1528
Pointer arithmetic affects the alignment factor
2020-01-09 13:53:56 -05:00
LemonBoy
5ab5de89c0 New @export() handling
Use a struct as second parameter to be future proof (and also allows to
specify default values for the parameters)

Closes #2679 as it was just a matter of a few lines of code.
2020-01-09 13:43:06 -05:00
Rocknest
4613e4d15f Fix C struct with function pointer member and typedefs mistranslated (#4122)
fixes #4118
2020-01-09 13:38:31 -05:00
Ryan Liptak
834218d789 Fix remaining variadic formatted prints
Used a series of regex searches to try to find as many instances of the old pattern as I could and update them.
2020-01-09 13:36:44 -05:00
daurnimator
d7333d8798 std: fix LoggingAllocator, add simple test 2020-01-09 13:34:46 -05:00
LemonBoy
c51b79c56e Correct alignment calculation for runtime addends 2020-01-09 11:56:45 +01:00
LemonBoy
27b290f312 Propagate more failures upwards
Fixes #4112
2020-01-08 17:25:00 -05:00
LemonBoy
7ea7842ed0 Fix calculation of new alignment factor 2020-01-08 21:02:05 +01:00
LemonBoy
7fe13f4a86 Pointer alignment fixes for the stdlib 2020-01-08 20:03:03 +01:00
LemonBoy
e134e6c994 Pointer arithmetic affects the alignment factor
Closes #1528
2020-01-08 20:03:03 +01:00
data-man
02ace4569e Correct @mulAdd's doc 2020-01-08 13:56:16 -05:00
Nathan Michaels
38ce7f64e3 Add removeIndex function to PriorityQueue (#4070)
It's awkward to use, but lets me cancel events in an event queue.

Co-authored-by: Dmitry Atamanov <data-man@users.noreply.github.com>
2020-01-08 13:55:47 -05:00
Andrew Kelley
0ebb07f95d Merge pull request #4101 from LemonBoy/moremerwio
More translate-c fixes
2020-01-08 13:37:02 -05:00
LemonBoy
6a72eb1541 Use abort() instead of assert()
Let's see if the Windows/MacOS CI like this more...
2020-01-08 10:31:11 +01:00
LemonBoy
5b34697b21 Cast integer literals to their specified type 2020-01-08 10:19:04 +01:00
LemonBoy
fd7e69a2c0 More translate-c fixes
* Translate OpaqueValueExpr
* Translate BinaryConditionalOperator
* Fix translation of boolean->int casts
* Reoder some tokens to avoid rendering errors
2020-01-08 08:43:37 +01:00
LemonBoy
2a5c622e65 Fix crash with unresolved loc
Fixes #4099
2020-01-07 18:16:17 -05:00
Vexu
e21ea5bd95 std-c parser loops 2020-01-08 00:00:14 +02:00
Andrew Kelley
9f064bcf74 Merge pull request #4091 from xackus/json_copy_strings
json: implement copy_strings=false
2020-01-07 16:42:14 -05:00
Vexu
83b4163591 std-c parser declaratorIsFunction and small fixes 2020-01-07 23:25:38 +02:00
Andrew Kelley
7b73c7fe12 Merge branch 'std-utf16-sentinel-terminated' of https://github.com/daurnimator/zig 2020-01-07 16:13:34 -05:00
Andrew Kelley
e2e9be5dea Merge branch 'dcao-master'
closes #3981
2020-01-07 16:02:58 -05:00
Andrew Kelley
af390b75db cleanups related to --eh-frame-hdr 2020-01-07 16:02:38 -05:00
David Cao
8e57dd57ca add --eh-frame-hdr conditionally 2020-01-07 15:58:40 -05:00
David Cao
599213463d add --eh-frame-hdr arg for linking 2020-01-07 15:58:39 -05:00
Vexu
8b713ce889 std-c parser add options 2020-01-07 22:43:44 +02:00
Rocknest
437c6a4b7e Make markdown parser more safe (#4105)
Fixes #3722
2020-01-07 15:26:21 -05:00
LemonBoy
3607d9ee68 Fix crash in struct initializer evaluation
Closes #4100
2020-01-07 15:06:22 -05:00
mogud
688d02176c build support list options 2020-01-07 13:59:53 -05:00
emekoi
156e43b463 added -- to pass args to zig build commands 2020-01-07 13:59:16 -05:00
LemonBoy
e81b505960 Use the correct calling convention for AEABI intrinsics 2020-01-07 13:42:47 -05:00
Andrew Kelley
4e4ba6c3e1 test harness: show annotated case name when translate-c test fails 2020-01-07 13:40:17 -05:00
Vexu
dbc0457068 std-c declaration parsing 2020-01-07 20:15:57 +02:00
xackus
814b54d798 json tests: don't use debug allocator 2020-01-07 19:03:11 +01:00
hryx
2933a8241a json: disallow overlong and out-of-range UTF-8
Fixes #2379

= Overlong (non-shortest) sequences

UTF-8's unique encoding scheme allows for some Unicode codepoints
to be represented in multiple ways. For any of these characters,
the spec forbids all but the shortest form. These disallowed longer
sequences are called "overlong". As an interesting side effect of
this rule, the bytes C0 and C1 never appear in valid UTF-8.

= Codepoint range

UTF-8 disallows representation of codepoints beyond U+10FFFF,
which is the highest character which can be encoded in UTF-16.
Because a 4-byte sequence is capable of resulting in such characters,
they must be explicitly rejected. This rule also has an interesting
side effect, which is that bytes F5 to FF never appear.

= References

Detecting an overlong version of a codepoint could get gnarly, but
luckily The Unicode Consortium did the hard work by creating this
handy table of valid byte sequences:

https://unicode.org/versions/corrigendum1.html

I thought this mapped nicely to the parser's state machine, so I
rearranged the relevant states to make use of it.
2020-01-07 12:07:44 -05:00
Vexu
4184d4c66a std-c parser record and enum specifiers 2020-01-07 19:05:46 +02:00
Vexu
df12c1328e std-c parser typing improvements 2020-01-07 16:05:13 +02:00
via
9390e8b848 Preserve packed attribute in C translated struct (#4085)
* Preserve packed attribute in C translated struct

* Add tests for packed C struct
2020-01-07 02:36:07 -05:00
Andrew Kelley
8492c46ade add test case for already fixed bug
closes #2655
2020-01-06 23:03:07 -05:00
LemonBoy
8c640b3e60 Prevent bitCast to enum types
Stop the user from creating invalid enum values.
2020-01-06 19:36:17 -05:00
LemonBoy
7e7d0e1ffa Better handling of decayed arrays to pointers 2020-01-06 19:32:53 -05:00
Timon Kruiper
0deab8fd3b Add std.mem.zeroes to the standard library
This zero initializes the type passed in. Can be used to zero
initialize c structs.
2020-01-06 19:24:17 -05:00
Andrew Kelley
baaef7ed97 Merge pull request #4083 from LemonBoy/better-stdbool
Better _Bool translation
2020-01-06 19:21:55 -05:00
Andrew Kelley
bf678a12df Merge branch 'LemonBoy-c-anon-stuff'
closes #4081
2020-01-06 19:18:05 -05:00
LemonBoy
62413da9d3 Add run-translated-c test & fix one more edge case 2020-01-06 19:17:47 -05:00
LemonBoy
2da9e0060b Add explanation about weird clang behavior on windows 2020-01-06 19:17:47 -05:00
LemonBoy
1dc25d7550 Translate anonymous union/struct 2020-01-06 19:17:47 -05:00
Tadeo Kondrak
f83b02a581 translate-c: use @intToPtr to cast away qualifiers 2020-01-06 19:09:49 -05:00
LemonBoy
e3a63b4e5a Add more compiler-rt functions for ARM platform 2020-01-06 19:08:15 -05:00
Andrew Kelley
d3d77138ec remove redundant license file 2020-01-06 19:05:42 -05:00
Andrew Kelley
633b6bf920 Merge branch 'LemonBoy-cc-work' 2020-01-06 18:53:17 -05:00
Andrew Kelley
c0e8837ce9 update docs with regards to callconv 2020-01-06 18:26:20 -05:00
Andrew Kelley
be2483c576 fix test suite regressions 2020-01-06 18:20:31 -05:00
Andrew Kelley
5ada610e09 update translate-c and tests for new extern/callconv syntax 2020-01-06 17:54:16 -05:00
Andrew Kelley
3b5c71d2a5 fix regression with @TypeInfo 2020-01-06 17:13:45 -05:00
Andrew Kelley
53913acaf7 zig fmt and update extern fn to callconv(.C) 2020-01-06 15:34:50 -05:00
Andrew Kelley
5951b79af4 remove stdcallcc, extern, nakedcc from stage1; zig fmt rewrites 2020-01-06 15:23:05 -05:00
Andrew Kelley
0a9daeb37e Merge branch 'cc-work' of https://github.com/LemonBoy/zig into LemonBoy-cc-work 2020-01-06 14:07:56 -05:00
Colin Svingen
4e6ad8efd9 Removes proc_raise from WASI implementation 2020-01-06 14:04:55 -05:00
xackus
6bebf741f9 json: implement copy_strings=false 2020-01-06 19:59:54 +01:00
Vexu
3ed6d7d245 std-c parser declarator 2020-01-06 20:06:17 +02:00
LemonBoy
eca294cd23 Add run-translated-c test 2020-01-06 00:18:26 +01:00
LemonBoy
cd39f6df95 Better _Bool translation 2020-01-06 00:12:18 +01:00
Andrew Kelley
c30106c906 add test case to cover already-solved bug
closes #2401
2020-01-05 17:42:03 -05:00
LemonBoy
6ff70d3c31 Better InitListExpr translation 2020-01-05 17:39:29 -05:00
Vexu
d5d52af26e std-c parse pointer 2020-01-06 00:06:33 +02:00
Andrew Kelley
5888d84ea3 Merge branch 'data-man-rusage'
closes #3854
2020-01-05 17:03:31 -05:00
Andrew Kelley
fee9318b17 std.os.getrusage: add C extern fn and reserved field
* add reserved field to match musl struct definition so that
   it will work with musl libc.
 * add libc getrusage so that it will work with libc

what's not done in this branch is:
 * test coverage. See #1629, which should also aim to provide
   general test coverage for the std lib.
 * rusage struct bits for non-linux operating systems
2020-01-05 16:57:14 -05:00
data-man
2f6b045fb1 Add std.os.getrusage 2020-01-05 16:52:36 -05:00
Andrew Kelley
62bebda270 add "Improving Translate-C" section to CONTRIBUTING.md 2020-01-05 15:42:55 -05:00
Andrew Kelley
d7bff05098 Merge pull request #4064 from ziglang/fix-4054
use @intCast instead of @as for shift rhs
2020-01-05 15:01:21 -05:00
Andrew Kelley
a0ca34979e Merge pull request #4053 from ziglang/test-run-translated-c
add test harness for "run translated C" tests
2020-01-05 14:50:02 -05:00
Vexu
5feeff7123 std-c improve error reporting and decl parsing 2020-01-05 20:25:52 +02:00
Vexu
795a503999 std-c tokenizer always add newline token 2020-01-05 20:25:51 +02:00
Vexu
f934f9b419 std-c parser fndef and static assert 2020-01-05 20:25:51 +02:00
Vexu
46f292982d std-c parser DeclSpec 2020-01-05 20:25:51 +02:00
Vexu
25f7f66b8f std-c type parsing 2020-01-05 20:25:51 +02:00
Vexu
dccf1247b2 std-c ifstmt compoundstmt and errors 2020-01-05 20:25:51 +02:00
Vexu
a20c0b31de std-c parser and ast organization 2020-01-05 20:25:51 +02:00
Vexu
73a53fa263 std-c outline parser 2020-01-05 20:25:50 +02:00
Vexu
e1b01d32f0 std-c ast base 2020-01-05 20:25:50 +02:00
Vexu
2183c4bb44 std-c tokenizer string concatenation 2020-01-05 20:25:50 +02:00
Vexu
a5d1fb1e49 std-c tokenizer line continuation, tests and fixes 2020-01-05 20:25:50 +02:00
Vexu
c221593d7d std-c tokenizer better special case handling 2020-01-05 20:25:50 +02:00
Vexu
472ca947c9 std-c tokenizer add tests 2020-01-05 20:25:50 +02:00
Vexu
d75697a6a3 std-c tokenizer keywords 2020-01-05 20:25:50 +02:00
Vexu
26bf410b06 std-c finish tokenizer 2020-01-05 20:25:49 +02:00
Vexu
f14a5287e9 std-c tokenizer strings, floats and comments 2020-01-05 20:25:49 +02:00
Vexu
05acc0b0c1 std-c tokenizer more stuff 2020-01-05 20:25:49 +02:00
Vexu
04b7cec42e std-c tokenizer base 2020-01-05 20:25:49 +02:00
Andrew Kelley
242f5d10d5 fix test-gen-h and test-compile-errors regression 2020-01-05 13:08:18 -05:00
Andrew Kelley
157b8e6889 fix test-stack-traces regression 2020-01-05 02:35:52 -05:00
Haze Booth
2e5342512f remove @TypeOf() hacks for comptime_int/comptime_float 2020-01-05 02:33:23 -05:00
Andrew Kelley
a690a5085d rework and improve some of the zig build steps
* `RunStep` moved to lib/std/build/run.zig and gains ability to compare
   output and exit code against expected values. Multiple redundant
   locations in the test harness code are replaced to use `RunStep`.
 * `WriteFileStep` moved to lib/std/build/write_file.zig and gains
   ability to write more than one file into the cache directory, for
   when the files need to be relative to each other. This makes
   usage of `WriteFileStep` no longer problematic when parallelizing
   zig build.
 * Added `CheckFileStep`, which can be used to validate that the output
   of another step produced a valid file. Multiple redundant locations
   in the test harness code are replaced to use `CheckFileStep`.
 * Added `TranslateCStep`. This exposes `zig translate-c` to the build
   system, which is likely to be rarely useful by most Zig users;
   however Zig's own test suite uses it both for translate-c tests and
   for run-translated-c tests.
 * Refactored ad-hoc code to handle source files coming from multiple
   kinds of sources, into `std.build.FileSource`.
 * Added `std.build.Builder.addExecutableFromWriteFileStep`.
 * Added `std.build.Builder.addExecutableSource`.
 * Added `std.build.Builder.addWriteFiles`.
 * Added `std.build.Builder.addTranslateC`.
 * Added `std.build.LibExeObjStep.addCSourceFileSource`.
 * Added `std.build.LibExeObjStep.addAssemblyFileFromWriteFileStep`.
 * Added `std.build.LibExeObjStep.addAssemblyFileSource`.
 * Exposed `std.fs.base64_encoder`.
2020-01-05 02:19:22 -05:00
Andrew Kelley
508a8980ba Merge pull request #4072 from LemonBoy/misc-stuff
Miscellaneous translate-c patches
2020-01-04 20:03:47 -05:00
LemonBoy
a712ea333b Fix translation of for loop init
Closes #4067
2020-01-04 11:49:43 +01:00
LemonBoy
51e430fac0 Fix edge case in hex-literal translation 2020-01-04 11:06:28 +01:00
Josh Wolfe
ac867cc45f fix tests 2020-01-03 20:55:47 -07:00
Andrew Kelley
14fcfe2981 translate-c supports --cache on
this will be used to provide a zig build step
2020-01-03 22:11:19 -05:00
Andrew Kelley
6ea193946d Merge pull request #3950 from nmichaels/master
Document std.Mutex.
2020-01-03 20:05:03 -05:00
Josh Wolfe
7838031b43 use @intCast instead of @as for shift rhs 2020-01-03 16:41:32 -07:00
LemonBoy
b91eaba38c Correct evaluation of optional type alignment
The lazy logic was too oversimplified and produced a different result
than the one computed later causing all kinds of problems.

Closes #4013
2020-01-03 17:41:55 -05:00
Andrew Kelley
3f19bc5d01 Merge pull request #4058 from LemonBoy/awful
builtin calls formatting - take II
2020-01-03 17:40:34 -05:00
LemonBoy
e6485282d3 Better logic for last-param rendering 2020-01-03 11:49:42 +01:00
LemonBoy
7b375a1c4a Revert "Revert "Trailing comma is respected for builtin calls""
This reverts commit f83411b0b1.
2020-01-03 10:17:40 +01:00
Haze Booth
f40b6b85f1 Remove translate-c-2 from zig help 2020-01-03 02:17:08 -05:00
Andrew Kelley
695c8f756b add test harness for "run translated C" tests 2020-01-03 00:26:12 -05:00
Andrew Kelley
f83411b0b1 Revert "Trailing comma is respected for builtin calls"
This reverts commit afd0290918.

This caused test failures.
2020-01-02 21:53:25 -05:00
LemonBoy
e9536ca10f Fix edge case in C tokenizer
Closes #4042
2020-01-02 16:44:30 -05:00
LemonBoy
afd0290918 Trailing comma is respected for builtin calls 2020-01-02 16:43:39 -05:00
Andrew Kelley
a90fa45ae1 Merge pull request #4027 from ziglang/fix-float-ops
fix float ops with respect to vectors
2020-01-02 16:10:41 -05:00
Andrew Kelley
fe21d84c94 Merge pull request #4040 from Vexu/translate-c-cast-fixes
Translate c cast fixes
2020-01-02 14:57:48 -05:00
LemonBoy
b0fa2ff853 Translate struct/union initializer expressions 2020-01-02 14:16:39 -05:00
Andrew Kelley
213ff939f1 fix comptime vector float ops and add test coverage
also rename `@ln` to `@log` to match libc convention.
2020-01-02 14:01:48 -05:00
LemonBoy
d09bd3d86c Fix more tests 2020-01-02 19:01:38 +01:00
LemonBoy
435528a7c5 Use the LLVM C++ API 2020-01-02 18:57:09 +01:00
LemonBoy
e99209baf0 Add transform test 2020-01-02 18:57:08 +01:00
LemonBoy
0ccac79c8e Implement Thiscall CC 2020-01-02 18:57:08 +01:00
LemonBoy
08a26fea09 translate-c tests 2020-01-02 18:57:07 +01:00
LemonBoy
0ec64d4c0c Integrate callconv into translate-c-2 2020-01-02 18:53:21 +01:00
LemonBoy
271fc6a247 Catch more errors during the type resolution phase
Returning the uninitialized/stale error condition made the compiler turn
a blind eye to some problems.
2020-01-02 18:53:20 +01:00
LemonBoy
563d9ebfe5 Implement the callconv() annotation 2020-01-02 18:53:16 +01:00
Andrew Kelley
197509e1ec Merge LemonBoy's translate-c branch for linksection/align
closes #4034
2020-01-02 12:35:19 -05:00
LemonBoy
d908ca4823 Translate align attribute 2020-01-02 12:33:19 -05:00
LemonBoy
8e89bdfe99 Translate linksection attribute 2020-01-02 12:32:51 -05:00
Vexu
0f1595e72c translate-c use @enumToInt for global enum values 2020-01-02 18:38:20 +02:00
Andrew Kelley
7bd80f2071 translate-c tests: print clang compile errors on nonzero exit code 2020-01-02 11:12:21 -05:00
Vexu
386270425f translate-c use canonical type in casts 2020-01-02 17:49:14 +02:00
Vexu
3dd067fa2b translate-c fix increment rendering issues 2020-01-02 10:47:14 -05:00
LemonBoy
de894f2bde Prefer simple ptrCast between opaque types
Closes #4031
2020-01-02 10:42:26 -05:00
LemonBoy
1e61e5f404 Don't ptrCast a result-location assignment to _
After #4010 doing `_ = @bitCast(...)` triggered a nonsensical compiler
error.
2020-01-02 10:41:11 -05:00
Vexu
f35a963ac5 translate-c properly handle unused var-args 2020-01-02 10:39:52 -05:00
Andrew Kelley
cb56b26900 fix float ops with respect to vectors
also remove the redundant type parameter
2020-01-01 23:27:43 -05:00
Andrew Kelley
576320e6d5 Merge pull request #4025 from ziglang/Vexu-stage-2-cimport
Use self hosted translate-c for cImport
2020-01-01 22:46:46 -05:00
Andrew Kelley
88c5e2a96e translate-c: don't export inline functions 2020-01-01 20:54:17 -05:00
Andrew Kelley
5ba143e7e3 avoid trying to translate microsoft's stdio.h inline functions
...for now. See #515
2020-01-01 20:33:07 -05:00
Andrew Kelley
a3f741e9b8 translate-c: avoid producing duplicate macro errors
This input file, for example, would produce duplicate identifiers
in the translated Zig code:

```
  #define bar err(
  #define bar err(
```
2020-01-01 20:29:35 -05:00
Andrew Kelley
365a6124d9 translate-c: fix regression from previous commit
This made macros which had an error being processed emit multiple times,
causing the self-hosted compiler to fail to build.
2020-01-01 19:58:41 -05:00
Andrew Kelley
ec09b9e5f0 translate-c: prevent name clashing of macros declared after locals 2020-01-01 19:23:46 -05:00
Andrew Kelley
9298b9a4aa translate-c: prevent name clashing of globals declared after locals 2020-01-01 18:53:08 -05:00
Andrew Kelley
dc28526c6c translate-c: improve support of integer casting
Widening and truncating integer casting to different signedness
works better now. For example `(unsigned long)-1` is now translated
to zig code that compiles correctly.
2020-01-01 18:10:43 -05:00
Andrew Kelley
5575e2a168 std.mem.compare: breaking API changes
* `std.mem.Compare` is now `std.math.Order` and the enum tags
   renamed to follow new style convention.
 * `std.mem.compare` is renamed to `std.mem.order`.
 * new function `std.math.order`
2020-01-01 18:08:40 -05:00
Vexu
1b64a5f5f0 fix segfault in bit shift safety check 2020-01-01 13:11:42 -05:00
Andrew Kelley
7b62d5dfd8 translate-c: propagate scope properly in nested assignment 2019-12-31 21:01:49 -05:00
Andrew Kelley
0fb3e6608c Merge branch 'lun-4-linux-memfd-create'
Closes #3687
2019-12-31 20:41:30 -05:00
Andrew Kelley
42945a269a translate-c: better mangling strategy
Block-local identifiers have block-local mangling numbers, and more
consistent mangling is applied within blocks. Parameters, for example,
are treated the same as other block-local variables, and are not mangled
unless they conflict with another name in scope.
2019-12-31 20:39:33 -05:00
Andrew Kelley
0c8ec369f0 std.os.memfd_create: add error.SystemOutdated 2019-12-31 17:57:20 -05:00
Andrew Kelley
5749f706ef translate-c: non-wrapping operator for pointer arithmetic
According to C11 6.5.6.8, pointer arithmetic may not overflow. In fact,
it may not even go more than 1 past the end of an object, or UB occurs.

This is the same as Zig pointer arithmetic semantics, and so the
`+` and `+=` operators rather than `+%` and `+%=` are appropriate for
C-translated pointer arithmetic.
2019-12-31 17:33:55 -05:00
Andrew Kelley
39ee3bc0ec Merge branch 'stage-2-cimport' of https://github.com/Vexu/zig into Vexu-stage-2-cimport 2019-12-31 16:55:41 -05:00
Andrew Kelley
c8c65b0168 translate-c: add pub to failed-to-translate macros 2019-12-31 16:54:41 -05:00
Andrew Kelley
8186211404 improvements to memfd_create
* move test from std/io/test.zig to std/os/test.zig
 * do glibc version check, and make direct system call if
   glibc is too old
 * disable test when not linking libc, to avoid not working
   with outdated qemu version on the CI server. see #4019
2019-12-31 16:34:14 -05:00
Luna
a153a972ad io.test: close memfd at end of test 2019-12-31 15:58:03 -05:00
Luna
13c9faaa2d c.linux: add memfd_create 2019-12-31 15:58:03 -05:00
Luna
f0cbf63e1a os: use system for memfd_create
- os: update flags type for memfd_create
2019-12-31 15:58:03 -05:00
Luna
997812e8fb os: add memfd_create
currently only linux is supported
2019-12-31 15:58:03 -05:00
Andrew Kelley
25051832b3 std.fmt.format: add helpful compile error for non-tuple args 2019-12-31 13:13:13 -05:00
mogud
d972d1c942 generate header in separate folder 2019-12-31 02:25:57 -05:00
Andrew Kelley
86ba8c06bf Merge branch 'lun-4-net-reuseaddr-opt'
Closes #3820
2019-12-30 19:36:43 -05:00
Andrew Kelley
99f6f8ead9 update setsockopt error set according to POSIX
In the code review I accidentally encouraged Luna to remove some
handling of errors that are possible according to POSIX, but I think how
Luna had it before was better, so I fixed it, and now the branch should
be good to merge.
2019-12-30 19:35:05 -05:00
Luna
22f6297157 std.os: update error set for setsockopt 2019-12-30 19:26:30 -05:00
Luna
0d852effe3 std.net: use mem.toBytes 2019-12-30 19:26:30 -05:00
Luna
50e6a27c29 std.net: fix setsockopt call 2019-12-30 19:26:30 -05:00
Luna
5efc0ea89e std.os: make setsockopt receive a slice as option 2019-12-30 19:26:30 -05:00
Luna
ea8f496970 std.c: c_uint -> u32 for sockopt functions 2019-12-30 19:26:30 -05:00
Luna
3ccbf3cfc2 move parameters on sockopt functions to c_uint
this makes them consistent with the linux syscalls
2019-12-30 19:26:30 -05:00
Luna
d423bb3808 std.c: add setsockopt 2019-12-30 19:26:30 -05:00
Luna
0e67568bca net: fix Options
- os: fix typos on setsockopt
2019-12-30 19:26:30 -05:00
Luna
4a4d2c0d80 os: add setsockopt
- net: use os.setsockopt()
2019-12-30 19:26:29 -05:00
Luna
631eb6783d add StreamServer.Options.reuse_address
this uses a bad direct interface with std.os.linux, this should add
setsockopt to std.os.
2019-12-30 19:26:29 -05:00
Andrew Kelley
73e535e112 Merge pull request #3683 from Vexu/atomic-float
Support floats with some atomic operations
2019-12-30 19:19:05 -05:00
LemonBoy
cbfd66f68a Don't crash when parsing invalid files 2019-12-30 19:17:19 -05:00
Andrew Kelley
a05150e92d fix comparing comptime_int against undefined literal
closes #4004
2019-12-30 19:08:57 -05:00
Andrew Kelley
a3d04b9228 update readme tagline 2019-12-30 18:17:13 -05:00
Andrew Kelley
8f8a32d297 Merge pull request #4007 from daurnimator/json-cleanup
std.json: cleanups
2019-12-30 18:13:20 -05:00
LemonBoy
28a8ded95a Resolve more types as needed
Closes #3994
2019-12-30 17:45:09 -05:00
LemonBoy
c1ee846c22 Fix ptrCast of zero-sized type
Closes #2431
2019-12-30 17:43:58 -05:00
Andrew Kelley
34b4538d7b Merge pull request #4011 from lukechampine/chacha20poly1305
crypto: Implement ChaCha20-Poly1305 AEAD (fixed)
2019-12-30 17:39:46 -05:00
lukechampine
ab093228f9 Fix segfault by not reassigning to function parameter 2019-12-30 13:53:09 -05:00
lukechampine
d1a570a4b8 chacha: Fix open docstring 2019-12-30 13:35:16 -05:00
lukechampine
d6ca2323cf chacha: Use error set instead of bool 2019-12-30 13:35:13 -05:00
lukechampine
1953b60599 chacha20poly1305: Return false on short ciphertext 2019-12-30 13:35:05 -05:00
lukechampine
ae7bb4ecc0 chacha20poly1305: verify tag in constant time 2019-12-30 13:34:57 -05:00
lukechampine
fbe7d8c1cb crypto: Add chacha20poly1305 2019-12-30 13:34:53 -05:00
daurnimator
42727c73f9 std: fix typo in comment 2019-12-31 03:06:33 +11:00
daurnimator
ef3a01a367 std: json.unescapeString doesn't need to take an allocator 2019-12-31 02:26:09 +11:00
daurnimator
04a2a4a7cb std: track decoded string length in std.json tokenizer 2019-12-31 02:26:06 +11:00
daurnimator
0def92cff4 std: use enum literals in std.json 2019-12-30 23:47:33 +11:00
daurnimator
80d37a13c0 std: use a union(enum) for std.json.Token 2019-12-30 23:47:29 +11:00
daurnimator
51943ff432 std: meta.TagPayloadType takes the tag type of the union 2019-12-30 23:09:18 +11:00
daurnimator
17cc511ea4 std: fmt std/json.zig 2019-12-30 22:34:19 +11:00
Haze Booth
c70a673c6e array literal address of fix 2019-12-30 05:48:27 -05:00
Andrew Kelley
e0c7d12043 update std/json.zig to latest language changes
fixes regression from 54231e832b
2019-12-29 19:00:27 -05:00
Benoit Giannangeli
fb2f0cc497 ArrayList: ptrAt function returns pointer to item at given index 2019-12-29 18:46:59 -05:00
Andrew Kelley
54231e832b Merge pull request #3648 from xackus/json-unescape
breaking: JSON unescape
2019-12-29 18:31:10 -05:00
data-man
6af39aa49a Fixes #3966 2019-12-29 18:19:03 -05:00
Andrew Kelley
6b960331ee Merge pull request #3968 from daurnimator/sigprocmask
Clean up linux sigprocmask, raise
2019-12-29 18:03:09 -05:00
Vexu
950eb81304 translate-c-2 macro comparision ops 2019-12-29 20:19:30 +02:00
Vexu
ca211617bd update c_tokenzier tests to new api 2019-12-29 20:04:19 +02:00
frmdstryr
6df9e9fe47 Cleanup c_tokenizer.zig tests 2019-12-29 19:50:58 +02:00
frmdstryr
fcc82a219a Add macro ops 2019-12-29 19:50:45 +02:00
Vexu
55348c9b93 translate-c-2 bug fixes
- fix use of undefined value
- fix parenexprclass result not being suppressed
- add an error and a TODO for access of an anonymous field
2019-12-29 19:23:36 +02:00
Vexu
621629e20d translate-c-2 fix assertion failure rendering do while 2019-12-29 17:09:31 +02:00
Vexu
f5e7d2d00c translate-c fix bugs
Thanks @daurnimator
2019-12-29 14:01:59 +02:00
Vexu
59cc7072e2 translate-c-2 use intCast in most places 2019-12-29 11:04:59 +02:00
Vexu
1a3633d786 fix stage2 build 2019-12-29 11:04:58 +02:00
Vexu
3f7bab7373 fix translate-c taking ages 2019-12-29 11:04:58 +02:00
Vexu
fceda07f94 use self hosted translate-c for cimports 2019-12-29 11:04:45 +02:00
Marc Tiehuis
bda355d976 Merge pull request #3992 from ForLoveOfCats/BigIntToStringLeak
Add missing deferred deinits to `math.big.Int.toString`
2019-12-29 14:47:59 +13:00
daurnimator
2662e50d27 std: sentinel terminated pointers for utf16 apis 2019-12-29 10:35:05 +11:00
Andrew Kelley
cb02125415 Merge pull request #3987 from daurnimator/std.unicode-fixes
std.unicode fixes
2019-12-28 18:13:50 -05:00
Andrew Kelley
48bf00bf34 Merge pull request #3993 from Vexu/translate-c
Translate-c-2 macro conditional operator and better error reporting
2019-12-28 18:12:06 -05:00
Vexu
1e52b7d690 translate-c-2 improve macro errors 2019-12-28 23:38:07 +02:00
Vexu
aea46dcd7e translate-c-2 macro conditional operator 2019-12-28 22:32:18 +02:00
ForLoveOfCats
b28824ef66 Add missing deferred deinits to math.big.Int.toString (mem leak fix) 2019-12-28 15:31:32 -05:00
Andrew Kelley
68aa221995 Merge pull request #3986 from LemonBoy/translate-c-stuff
Two small translate-c(-2) patches
2019-12-28 14:26:37 -05:00
MateuszOkulus
6c3ccea29b Make it more obvious that ifs are expressions 2019-12-28 14:26:10 -05:00
daurnimator
edb5deb39c std: unicode codepoints are 21 bits 2019-12-28 16:49:59 +11:00
daurnimator
ab6065407d std: simplify utf8ToUtf16Le
Also faster, on my machine unicode/throughput_test.zig now gives e.g.
> original utf8ToUtf16Le: elapsed: 1048 ns (0 ms)
> new utf8ToUtf16Le: elapsed: 971 ns (0 ms)
2019-12-28 16:49:59 +11:00
daurnimator
5843a6e3bc std: optimise utf8ByteSequenceLength
Also tested (but not as fast):
```zig
pub fn utf8ByteSequenceLength(first_byte: u8) !u3 {
    const len = @clz(u8, ~first_byte);
    if (len == 0) return 1;
    if (len < 4) return @intCast(u3, len);
    return error.Utf8InvalidStartByte;
}
```
2019-12-28 14:39:38 +11:00
daurnimator
8b72eedc76 std: add warm up phase to benchmark
In my tests, whatever ran first was getting much better numbers.
Additionally, add alignment requirements so that comparison is fair.
2019-12-28 14:39:38 +11:00
daurnimator
a81c0ba2e7 std: fix unicode encoding of astral plane codepoints to utf16 2019-12-28 14:39:38 +11:00
LemonBoy
6070ffc28e Fix crash with forward-declared enums
Closes #3754
2019-12-28 00:57:37 +01:00
LemonBoy
a38704d012 Fix crash in translate-c w/ parameterless fn 2019-12-28 00:50:17 +01:00
Vexu
2252951066 disable test on arm 2019-12-23 11:55:00 +02:00
Vexu
ab7fc33c83 add zig llvm wrapper for atomicrmw 2019-12-23 11:55:00 +02:00
Vexu
8bb1e04449 support some atomic operations with floats 2019-12-23 11:54:47 +02:00
Andrew Kelley
25e71216c4 Merge pull request #3974 from kprotty/event_broadcast
ResetEvent fixes & broadcast notify
2019-12-22 23:39:13 -05:00
kprotty
1c5a1284e3 typo fix 2019-12-22 21:45:26 -06:00
kprotty
b8fabb3426 ResetEvent: broadcast by default 2019-12-22 21:45:26 -06:00
Andrew Kelley
ad92227516 report compile errors instead of crashing when frame is invalid 2019-12-22 17:09:11 -05:00
Andrew Kelley
28dbdba37e Merge pull request #3935 from Vexu/translate-c-2
Translate-c-2 the rest
2019-12-22 16:12:56 -05:00
Vexu
9d31b65b34 translate-c-2 various fixes
- make non-namespaced enums ints
- fix .used compound assignments not being grouped
- fix macro calls with casts producing invalid Zig
2019-12-22 14:38:06 +02:00
daurnimator
95c83388e4 std: use pid_t where appropriate 2019-12-22 20:20:58 +11:00
daurnimator
59348240d7 std: use wrappers from raise() rather than raw syscalls 2019-12-22 20:20:58 +11:00
daurnimator
6de4bd850c std: add tkill and tgkill for linux 2019-12-22 20:20:58 +11:00
daurnimator
c31afc3736 std: remove high level linux sigprocmask wrappers 2019-12-22 20:20:58 +11:00
daurnimator
9577ff1c90 std: use simpler sigset_t definition 2019-12-22 20:20:53 +11:00
Jethro Nederhof
ba1d213f48 freebsd: add missing OS and libc bits 2019-12-22 02:27:23 -05:00
daurnimator
96c9c38b35 std: sigprocmask set is optional 2019-12-22 12:03:03 +11:00
Andrew Kelley
bc95c63cf2 Merge pull request #3940 from ziglang/sentinel-slicing
fix std.mem.addNullByte and implement sentinel slicing
2019-12-21 14:11:16 -05:00
Andrew Kelley
290dc5d95b zig fmt support for slice sentinel syntax 2019-12-21 14:03:36 -05:00
Andrew Kelley
ce444771c5 fix incorrect @typeInfo for sentinels 2019-12-21 13:25:05 -05:00
LemonBoy
333eec557f Initial support for static PIE executables 2019-12-21 17:34:05 +01:00
Nathan Michaels
45339aec02 Fix wording on deinit. 2019-12-21 01:30:55 -05:00
Andrew Kelley
8d73703d52 fix safety for sentinel-slicing floats 2019-12-20 18:28:59 -05:00
Andrew Kelley
8918cb06fc sentinel slicing improvements
* add runtime safety for slicing pointers, arrays, and slices.
 * slicing without a sentinel value results in non-sentineled slice
 * improved `std.debug.panic` handling of panic-during-panic
2019-12-20 18:28:59 -05:00
Andrew Kelley
26f3c2d061 fix std.mem.addNullByte and implement sentinel slicing
see #3770
2019-12-20 18:28:56 -05:00
Vexu
40f607d195 translate-c-2 fix macro regression 2019-12-20 22:48:40 +02:00
LemonBoy
51cbd96820 Fix sentinel value of opaque pointers in typeInfo
Fixes #3888
2019-12-20 15:48:34 -05:00
LemonBoy
f077c3c4cc Fix comptime evaluation of runtime array access
Fix #3951
2019-12-20 15:47:43 -05:00
Andrew Kelley
9daa7e1e19 CI: update llvm apt sources to correct ubuntu version
In the pipelines.yml file we request Ubuntu 18.04 Bionic Beaver, but in
the script we were still using the Xenial apt.llvm.org sources.
2019-12-20 13:40:07 -05:00
Vexu
949f2369c1 translate-c-2 fix bugs found translating SDL 2019-12-20 20:22:22 +02:00
Vexu
9437d99ae2 translate-c-2 final small fixes 2019-12-20 18:51:44 +02:00
Vexu
e0046b737e translate-c-2 improve macro escape sequences 2019-12-20 13:50:34 +02:00
Vexu
daeb939210 translate-c-2 fix switch range 2019-12-20 11:35:21 +02:00
Nathan Michaels
33b5dbb82c Document std.Mutex.
Not sure what the build platform is for the generated documentation,
and it's worth thinking about how best to deal with this pattern. It
might be worth figuring out how to rewrite this to have a single
definition of the public API with the implementation chosen at compile
time.
2019-12-19 23:42:27 -05:00
Vexu
d172a7335c translate-c-2 copy parametrs to stack 2019-12-20 00:12:08 +02:00
Vexu
b7f18164f9 translate-c-2 add missing casts 2019-12-19 21:30:51 +02:00
Vexu
61482be153 translate-c-2 improve macro fn ptr caller 2019-12-19 20:58:48 +02:00
Vexu
f837c7c9cd translate-c-2 compound assign 2019-12-19 16:13:28 +02:00
Vexu
6cd402f1b4 translate-c-2 increments worst-case 2019-12-19 10:48:32 +02:00
Vexu
809deb6ec0 translate-c-2 unary operators common case 2019-12-19 09:56:00 +02:00
Vexu
e4c47e80b4 translate-c-2 unaryexprortypetrait + fixes 2019-12-19 08:28:36 +02:00
Vexu
122a9bad39 translate-c-2 fix some casts 2019-12-19 01:38:42 +02:00
Vexu
d54c288bd3 translate-c-2 function calls 2019-12-18 23:56:39 +02:00
Vexu
c2666c48a4 translate-c-2 array access 2019-12-18 22:57:53 +02:00
Vexu
cf7a5b7a4a translate-c-2 member access 2019-12-18 22:29:42 +02:00
Vexu
e65b9e8f7b translate-c-2 stmt expr 2019-12-18 21:20:38 +02:00
Vexu
62bfff5e87 translate-c-2 fix expression grouping bugs 2019-12-18 13:32:19 +02:00
Vexu
f54e7d6c99 translate-c-2 update @kavika13's work to removal of TransResult 2019-12-18 12:47:35 +02:00
Vexu
90eed4172d Merge remote-tracking branch 'kavika13/master' into translate-c-2 2019-12-18 09:51:40 +02:00
Andrew Kelley
4d54e9a4fb Merge pull request #3918 from kprotty/lock_fix
Synchronization primitive improvements
2019-12-17 20:04:02 -05:00
Vexu
21bc3353b8 translate-c-2 character literals and more test fixes 2019-12-18 01:04:01 +02:00
kprotty
c912296443 SpinLock: loopHint & yield distinction 2019-12-17 15:38:00 -06:00
kprotty
26e08d5701 ResetEvent: use futex on linux when possible 2019-12-17 15:38:00 -06:00
kprotty
ac5ba27c2b Mutex: fix lock/spin bugs, improve perf slightly & more specialization 2019-12-17 15:38:00 -06:00
kprotty
e67ce444e7 ResetEvent: simpler interface + fix tests 2019-12-17 15:38:00 -06:00
kprotty
947db78622 Spinlock: remove Backoff & improve yielding 2019-12-17 15:38:00 -06:00
Vexu
6d7025d0c5 translate-c-2 various fixes to get more tests passing 2019-12-17 23:28:13 +02:00
LemonBoy
d8499f7abe Make sure the fields array is always non-null
Fixes #3497
2019-12-17 15:45:22 -05:00
Nathan Michaels
f389e5e61f Clarify allowzero's interaction with optional pointers. 2019-12-17 15:44:34 -05:00
Raul Leal
62c817420d [#3844 + #3767] update std.c and std.os.linux to use null-terminated pointer types (#3900)
* #3844 update std.c functions to use null-terminated pointer types

* check linux functions

* fix callsites

* fix io test

* Add allocPrintCstr function to remove other cast
2019-12-17 15:43:49 -05:00
Vexu
a6960b89ed translate-c-2 fix container type resolution 2019-12-17 22:05:07 +02:00
Vexu
65531c73a9 translate-c-2 switch 2019-12-17 17:19:28 +02:00
Vexu
0283ab8a1a translate-c-2 conditional operator 2019-12-17 12:06:28 +02:00
Vexu
daa22d42b0 translate-c-2 floats 2019-12-17 11:28:56 +02:00
Vexu
9cda93a24e translate-c-2 don't shadow primitive types 2019-12-17 10:20:02 +02:00
Andrew Kelley
b242c2ac10 avoid using undefined value
closes #3933
2019-12-16 22:47:19 -05:00
Vexu
ab6fe57462 translate-c-2 for loops 2019-12-17 01:40:06 +02:00
Vexu
d54bcb2b62 translate-c-2 break and continue 2019-12-16 23:54:16 +02:00
Andrew Kelley
b1abe4a172 Revert "added -- to pass args to zig build commands"
This reverts commit d4e56ae6ae.

This broke the build
2019-12-16 16:36:42 -05:00
Dmitry Atamanov
744133acb1 Fixes utf8ToUtf16Le (#3923) 2019-12-16 16:27:26 -05:00
emekoi
d4e56ae6ae added -- to pass args to zig build commands 2019-12-16 16:24:54 -05:00
Andrew Kelley
13cdc137e6 Merge pull request #3570 from ziglang/c-sanitize-undef
use -fsanitize=undefined for C code in safe build modes
2019-12-16 16:17:52 -05:00
LemonBoy
de0d8885b4 Fix alignment query on unresolved types
Fixes #3919
2019-12-16 15:54:06 -05:00
Vexu
6a3d48353b translate-c-2 while loops 2019-12-16 22:10:17 +02:00
Andrew Kelley
839b3a61ad expose the ability to disable C sanitization
and disable C sanitization when building libcs.
Empirically, they seem to trigger undef-sanitization.
2019-12-16 13:51:21 -05:00
Andrew Kelley
f8cd981c04 use -fsanitize=undefined for C code in safe build modes
closes #3569
2019-12-16 13:06:02 -05:00
Henry Wu
170de5ecae generated docs: log trace instead of error
When the error occurred for getValueText it could potentially omit
useful documentation since the page stops rendering.
2019-12-16 12:40:38 -05:00
xackus
cb5a5ebb20 langref table of contents in a separate column on large displays 2019-12-16 12:25:56 -05:00
Andrew Kelley
b3cbf290c8 remove misleading documentation 2019-12-16 12:07:05 -05:00
Andrew Kelley
496f271d17 Merge branch 'shawnl-lessThan'
* always allow integer comparison operations no matter the
   bit width, signedness, or comptime-ness of operands.
   closes #2133
 * implement comparisons for vectors, which returns vector of
   bools.

closes #3001
2019-12-16 11:39:13 -05:00
Andrew Kelley
1cad0acc7e add behavior test for vector comparison 2019-12-16 11:22:28 -05:00
Vexu
e3f1bfe483 translate-c-2 if statements 2019-12-16 18:19:37 +02:00
Vexu
626562555e translate-c-2 wors-case assign 2019-12-16 18:19:37 +02:00
Vexu
d9527edfe0 translate-c-2 comma operator 2019-12-16 18:19:24 +02:00
Andrew Kelley
9468d63819 allow comparison of any numeric types 2019-12-16 11:09:10 -05:00
Lachlan Easton
fe0e8c87b7 Tokenizer: Copy optional tokens prior to being set to null #3737 (#3910)
* Tokenizer: Copy optional tokens prior to being set to null #3737

* Add TODO comments, reminder to audit copying optional pattern.
2019-12-16 11:01:02 -05:00
Andrew Kelley
0f09ff4923 Merge pull request #3916 from Vexu/translate-c-2
Translate-c-2 macros
2019-12-16 10:55:32 -05:00
Andrew Kelley
650acc5e3d Merge pull request #3922 from LemonBoy/eventfd-err
More eventfd stuff
2019-12-16 10:45:09 -05:00
Vexu
04dc0bd0e4 translate-c-2 variable aliasing 2019-12-16 12:45:00 +02:00
LemonBoy
9d9b0720f5 Fix for the error codepath in ChildProcess 2019-12-16 10:57:29 +01:00
LemonBoy
c257f892fd Revert "Revert "Use eventfd in ChildProcess on Linux""
This reverts commit 2c7a2aefbf.
2019-12-16 10:56:53 +01:00
Merlyn Morgan-Graham
0c03fe48b3 Fix compile errors after rebasing on master (missing switch->else) 2019-12-16 01:37:53 -08:00
Merlyn Morgan-Graham
89ef635b35 Add boolean and, boolean or binary ops in translate-c-2 2019-12-16 01:34:05 -08:00
Merlyn Morgan-Graham
acff2d407b Add bit shift binary ops in translate-c-2 2019-12-16 01:34:04 -08:00
Merlyn Morgan-Graham
c8c89648b0 Add comparison and bitwise binary ops in translate-c-2 2019-12-16 01:34:04 -08:00
Vexu
a37caaa528 translate-c-2 parameter name aliasing 2019-12-16 10:39:31 +02:00
Shawn Landden
143603b39f std: lessThan and greaterThan between signed and unsigned
It is a deviation from C, but I think we should consider making this the behavior
of the operators. See #2133
2019-12-16 01:41:26 -05:00
Andrew Kelley
2c7a2aefbf Revert "Use eventfd in ChildProcess on Linux"
This reverts commit b169f7b0d5.

This caused `integer cast truncated bits` at
std/child_process.zig:801:12

Can be reproduced on my machine simply by running `make`.
2019-12-16 01:39:41 -05:00
Vexu
620bf695e8 organize tests 2019-12-16 07:43:18 +02:00
Vexu
0f38410ea6 improve extern enum 2019-12-15 19:28:53 -05:00
Vexu
ab60c8e28f c tokenizer escape sequences 2019-12-16 00:55:50 +02:00
Vexu
9f0e83a571 translate-c-2 macro functions 2019-12-15 23:46:35 +02:00
LemonBoy
59de23dfa0 Don't assume TLS storage has a fixed address
Fixes #3433
2019-12-15 16:23:42 -05:00
LemonBoy
b169f7b0d5 Use eventfd in ChildProcess on Linux
Closes #819
2019-12-15 14:43:37 -05:00
LemonBoy
f1407b4b7e Generate the fn pointers into the correct address space
Fixes #3645
2019-12-15 14:42:53 -05:00
LemonBoy
19ddbd9e9e Make sure the address is aligned for intToPtr ops
Closes #773
2019-12-15 14:41:05 -05:00
Vexu
ed2a19dcec translate-c-2 macro cast 2019-12-15 21:32:30 +02:00
Vexu
57170f9eb6 translate-c-2 macro inline fn 2019-12-15 19:28:34 +02:00
Vexu
75218d4765 translate-c-2 macros 2019-12-15 14:44:11 +02:00
Vexu
c3724a6e72 translate-c-2 c tokenizer 2019-12-15 10:30:38 +02:00
Andrew Kelley
cf0d300dde Merge pull request #3908 from Vexu/translate-c-2
Translate-c-2 enums
2019-12-14 21:13:42 -05:00
Vexu
e57e3602e7 translate-c-2 implement enums 2019-12-14 23:24:47 +02:00
Vexu
1a967db083 add default initializers to all ast.Node base values 2019-12-14 20:40:56 +02:00
Andrew Kelley
33d9dda558 Merge pull request #3906 from Vexu/translate-c-2
Translate-c-2 structs and unions
2019-12-14 13:12:39 -05:00
Vexu
1f84586836 translate-c-2 avoid collisions with zig keywords 2019-12-14 17:00:10 +02:00
Vexu
4dae70e702 translate-c-2 container aliases 2019-12-14 13:40:33 +02:00
Vexu
a4ac6d15c4 translate-c-2 array initializer expr 2019-12-14 10:49:25 +02:00
Vexu
e4ca1f441b translate-c-2 record type 2019-12-14 02:00:01 +02:00
Andrew Kelley
21a85d4fb6 Merge pull request #3896 from Vexu/translate-c-2
Translate-c self-hosted var decl and remove translate mode
2019-12-13 15:48:10 -05:00
Vexu
45abfa9e71 revert removal of translate mode in stage 1 2019-12-13 19:06:32 +02:00
Vexu
41a67126a5 translate-c-2 typedef 2019-12-13 17:40:37 +02:00
Vexu
eb057ef41c translate-c-2 dont eval init expr 2019-12-13 15:07:10 +02:00
Andrew Kelley
e54c49be9b uncomment a now-passing behavior test 2019-12-12 19:45:33 -05:00
Andrew Kelley
1e4bae6692 update stack traces tests 2019-12-12 19:43:04 -05:00
Jonathan Marler
4cb4148b35 Document sentinel type in langref 2019-12-12 19:01:22 -05:00
Andrew Kelley
7699b5b997 Merge branch 'Xe-expose-callMain'
closes #3891
2019-12-12 18:56:39 -05:00
Andrew Kelley
fff3c1fff4 un-special-case startup code in the std lib
Previously, the compiler had special logic to determine whether to
include the startup code, which was in `std/special/start.zig`. Now,
the file is moved to `std/start.zig`, and there is no special logic
in the compiler. Instead, the standard library unconditionally imports
the `start.zig` file, which then has a `comptime` block that does the
logic of determining what, if any, start symbols to export. Instead of
`start.zig` being in its own special package, it is just another normal
file that is part of the standard library.

`std.builtin.TestFn` is now part of the standard library rather than
specially generated by the compiler.
2019-12-12 18:33:44 -05:00
Christine Dodrill
b37acc4d68 allow custom OS entrypoint
Also:

 * Expose `std.start.callMain`.
 * Other fixes added to fix issues found in development.
2019-12-12 16:00:23 -05:00
Andrew Kelley
81f1f72197 ci: skip non native tests for aarch64
We've been hitting timeouts on this service. Once zig build gains
parallel processing support, we can probably enable more tests.
2019-12-12 15:11:59 -05:00
Vexu
0795f17db2 translate-c-2 incompleteArray 2019-12-12 21:39:04 +02:00
Vexu
48ac84db1b translate-c-2 translate apvalue 2019-12-12 20:35:40 +02:00
Vexu
c759a77aa0 fix dot init parsing 2019-12-12 13:06:48 -05:00
Vexu
3bca025091 update tests 2019-12-12 18:18:43 +02:00
Vexu
ef361161e2 translate-c-2 add var decl 2019-12-12 16:12:19 +02:00
Vexu
69dee57d95 remove concept of translate mode 2019-12-12 14:26:24 +02:00
Andrew Kelley
d08dc21116 Merge pull request #3886 from kavika13/master
Add function params, parens handling, and some infix operators to self-hosted translate-c
2019-12-11 18:40:35 -05:00
Christine Dodrill
b375f6e027 lib/std/io: let the bring-your-own OS package handle stdio (#3887) 2019-12-11 18:37:52 -05:00
Merlyn Morgan-Graham
12171dba92 Add function parameters to self-hosted translate-C 2019-12-10 23:52:40 -08:00
Merlyn Morgan-Graham
5e8186a8ce Fix access of undefined field when calling ast.Tree.dump 2019-12-10 23:52:40 -08:00
Merlyn Morgan-Graham
fe415dae04 Add paren expression statements to self-hosted translate-C 2019-12-10 23:52:40 -08:00
Merlyn Morgan-Graham
3e4f5de33c Add rem binary operator to self-hosted translate-C 2019-12-10 23:52:40 -08:00
Merlyn Morgan-Graham
79fe7e6515 Add mul and div binary operators to self-hosted translate-C 2019-12-10 23:52:40 -08:00
Andrew Kelley
7c1dbfab72 self-hosted: manually parse args 2019-12-11 02:08:33 -05:00
Andrew Kelley
c3d8b1ffeb remove iterator API from std.ArrayList
This is not a meaningful abstraction. Use a for loop on the result
of `toSlice` or `toSliceConst`.

An iterator can be implemented on top of ArrayList by applications which
want additional functionality, such as removing elements while
iterating.

Closes #3037.
2019-12-10 15:08:10 -05:00
frmdstryr
f30af12bea Add hotpath for BufferedOutStream (#3858)
* Add hotpath for BufferedOutStream
2019-12-10 13:44:59 -05:00
Heppokoyuki
5ada11449a fix con_in difinition and add EFI_SIMPLE_TEXT_INPUT_PROTOCOL difinition 2019-12-10 13:25:28 -05:00
Andrew Kelley
0d99744acc Merge branch 'emekoi-dynlib-load'
closes #2598
2019-12-10 13:24:01 -05:00
Andrew Kelley
fdc3132126 fix windows dynamic lib loading test 2019-12-10 13:21:37 -05:00
Andrew Kelley
3ef8460d06 fix load dynamic library API when linking libc 2019-12-10 12:56:05 -05:00
Andrew Kelley
80882bda59 load dynamic library test: update API usage code 2019-12-10 12:48:10 -05:00
Andrew Kelley
fd6b7b160d improve dynamic library API 2019-12-10 12:28:28 -05:00
emekoi
29fd727b79 fixed windows dynamic library loading and added loading for darwin 2019-12-10 11:41:54 -05:00
Andrew Kelley
9561e7c6b9 Merge branch 'Snektron-typeOf-to-TypeOf'
closes #3875
closes #1348
2019-12-10 11:13:39 -05:00
Robin Voetter
30715560c8 Rename @typeOf to @TypeOf in the language reference 2019-12-10 11:09:41 -05:00
Robin Voetter
8c096707b7 Additional replacements of @typeOf with @TypeOf 2019-12-10 11:09:41 -05:00
Robin Voetter
4b4fbe3887 Replace @typeOf with @TypeOf in all zig source
This change was mostly made with `zig fmt` and this also modified some whitespace. Note that in some files, `zig fmt` produced incorrect code, so the change was made manually.
2019-12-10 11:09:41 -05:00
Robin Voetter
f0ee0688f2 Replace typeOf with TypeOf in stage0 2019-12-10 11:09:30 -05:00
Robin Voetter
c519bb02df Fix usage of freed memory in zig fmt 2019-12-10 11:09:29 -05:00
Robin Voetter
d568db2386 Remove misplaced dot 2019-12-10 11:09:29 -05:00
Robin Voetter
23b901d45a Add typeOf/TypeOf render test 2019-12-10 11:09:29 -05:00
Robin Voetter
20a3011def Add typeOf/TypeOf substition in zig fmt 2019-12-10 11:09:29 -05:00
Andrew Kelley
cd4d638d10 Merge pull request #3830 from fengb/wasm-page-allocator
WasmPageAllocator
2019-12-10 10:58:50 -05:00
xackus
c27d06596b fix integers parsed as floats 2019-12-10 10:30:41 -05:00
dbandstra
3388c777fa print call in build.zig needs to use a tuple argument 2019-12-10 10:18:57 -05:00
Andrew Kelley
2a7103ca34 ci: update macos to fresh llvm+clang tarball cache 2019-12-10 01:32:45 -05:00
Andrew Kelley
e6c01e49d8 remove no-longer-needed workaround for var args
See #557
2019-12-09 16:21:16 -05:00
Andrew Kelley
a3f6a58c77 remove var args from the language
closes #208
2019-12-09 15:27:27 -05:00
Andrew Kelley
f205d23e65 implement async function call with @call
this removes the last usage of var args in zig std lib
2019-12-09 15:27:26 -05:00
Andrew Kelley
69b587c1d3 add regression cases for now-passing tests
closes #2749
2019-12-09 15:23:51 -05:00
Andrew Kelley
5d82744f1c ability to give comptime and non-comptime types to same parameter 2019-12-09 13:30:53 -05:00
Andrew Kelley
640e09183d Merge pull request #3873 from ziglang/format-no-var-args
std.fmt.format: tuple parameter instead of var args
2019-12-09 10:51:47 -05:00
Andrew Kelley
8b3c0bbeee update docgen to new format API 2019-12-09 00:18:01 -05:00
Andrew Kelley
d571fad20e update tests to new format API 2019-12-09 00:05:21 -05:00
Andrew Kelley
03396b3caa update docs to new fmt API 2019-12-08 23:46:50 -05:00
Andrew Kelley
5f9467d78f update formatted printing when linking libc 2019-12-08 23:39:30 -05:00
Andrew Kelley
7a4f704258 windows-specific fixes 2019-12-08 23:26:19 -05:00
Andrew Kelley
fe4963412f update self-hosted compiler to new format API 2019-12-08 23:17:03 -05:00
Andrew Kelley
8b2622cdd5 std.fmt.format: tuple parameter instead of var args 2019-12-08 22:53:51 -05:00
Andrew Kelley
5874cb04bd implement tuple concatenation 2019-12-08 22:44:41 -05:00
Benjamin Feng
608d36ad8c Rewrite WasmPageAllocator tests to be less flaky on environment 2019-12-08 21:22:07 -06:00
Andrew Kelley
6504c5098e tuple detection does not require AST node 2019-12-08 18:39:52 -05:00
LemonBoy
d5e788072d Make array types (quasi-)lazy
Fixes #3843
2019-12-08 17:29:59 -05:00
Andrew Kelley
1cb19d1a46 fix anon struct literal field initialized with fn call 2019-12-08 17:28:34 -05:00
emekoi
c2342dab0b fixed BREAKPOINT macro on mingw 2019-12-08 17:18:44 -05:00
Andrew Kelley
d57370d3ca Merge branch 'comptime-fields'
closes #3677
2019-12-08 12:27:02 -05:00
Andrew Kelley
64d700bfa6 zig fmt: support comptime fields 2019-12-08 12:26:20 -05:00
Andrew Kelley
fe8d65556d add syntax for comptime struct fields 2019-12-08 12:26:20 -05:00
Andrew Kelley
119ed128c0 implement comptime struct fields 2019-12-08 12:26:20 -05:00
LemonBoy
19c1b5a33a Fix for @Type not picking up the sentinel value
The code converted the whole TypeInfo payload into an optional type
instead of using the "sentinel" field value.

Fixes #3828
2019-12-08 10:28:29 -05:00
Josh Wolfe
05fc4d34a9 documentation for mutable HashMap KV pointers 2019-12-07 13:22:23 -05:00
Andrew Kelley
edebe0586b remove compile error for peer result comptime_int and null
closes #2763
2019-12-07 13:03:43 -05:00
Benjamin Feng
e91522b875 Add back comptime check for wasm 2019-12-06 17:27:11 -06:00
Andrew Kelley
ecb77af534 add regression test for fixed bug
closes #3742
2019-12-06 17:20:27 -05:00
data-man
80a72c225c Crypto benchmark fixes 2019-12-06 17:14:10 -05:00
data-man
008e42f483 getStdOut fixes 2019-12-06 16:41:02 -05:00
Benjamin Feng
5a004ed834 Actually use const conventional as the comment indicates 2019-12-06 15:16:07 -06:00
Andrew Kelley
525b1e8fb4 Merge pull request #3856 from ziglang/builtin-call
introduce `@call` and remove other builtin calls
2019-12-06 15:49:47 -05:00
Andrew Kelley
656cc33f8d allow calling with a new stack to regress a bit
Calling with a new stack, with a runtime-known stack pointer (e.g.
not a global variable) is regressed with this branch. It is now a
compile-error, due to the Runtime Hint system not being smart enough
to mix a compile-time modifier field with a runtime stack field.
I'm OK with this regression because this feature is flawed (see #3268)
and may be deleted from the language.
2019-12-06 15:25:00 -05:00
Andrew Kelley
71b7f4b47f remove @newStackCall from zig 2019-12-06 14:52:09 -05:00
Andrew Kelley
343987cd05 remove @inlineCall from zig 2019-12-06 14:12:01 -05:00
Andrew Kelley
d28aa38db7 Merge branch 'LemonBoy-fix-3842'
closes #3855
closes #3842
2019-12-06 12:28:26 -05:00
Andrew Kelley
b1895da9b8 add behavioral test case for previous commit 2019-12-06 12:27:56 -05:00
LemonBoy
f64cff3e16 Fix misinterpretation of sentinel constant value
Fixes #3842
2019-12-06 12:27:52 -05:00
Andrew Kelley
e41495de9d private linkage for unnamed internal constants 2019-12-05 23:13:42 -05:00
Benjamin Feng
eb495d934b Add WasmPageAllocator tests 2019-12-05 21:54:57 -06:00
Andrew Kelley
105ef560b3 Merge pull request #3853 from xackus/doc-fixes
Docs: assembly example printing garbage and minor html fixes
2019-12-05 20:43:10 -05:00
Benjamin Feng
f2b0dbea74 Resolve tests to work with or skip WasmPageAllocator 2019-12-05 19:31:49 -06:00
Benjamin Feng
694616adb5 Standardize around bigger slices 2019-12-05 18:43:51 -06:00
Benjamin Feng
7d1c4fe4dc Switch bitmask to enums 2019-12-05 18:01:49 -06:00
Andrew Kelley
ef83358eb6 remove @noInlineCall from zig 2019-12-05 17:37:29 -05:00
Andrew Kelley
1f602fe8c5 implement @call
closes #3732
2019-12-05 17:07:15 -05:00
xackus
cb96a096cb docs: fix duplicate closing tag generation 2019-12-05 22:56:56 +01:00
xackus
71354498c9 docs: add html lang and minor fixes 2019-12-05 22:40:58 +01:00
xackus
ba78d71b09 docs: fix assembly example 2019-12-05 22:40:47 +01:00
Vexu
bfb15f1c9f fix casts 2019-12-05 15:47:06 -05:00
frmdstryr
1baaf9a503 Increase io.BufferedInStream readByte speed by ~75% 2019-12-05 10:16:50 -05:00
Andrew Kelley
8829b5316b Merge pull request #3849 from Vexu/fix-fmt
Fix zig fmt c pointer return type
2019-12-05 10:14:31 -05:00
Vexu
d40ad92668 use enum literals in render.zig 2019-12-05 14:50:51 +02:00
Vexu
10cc8cad86 fix zig fmt of c pointers 2019-12-05 14:50:46 +02:00
Benjamin Feng
30da6d49f4 Fix freeing memory across bounds 2019-12-04 22:43:02 -06:00
Benjamin Feng
86ae75363e Strip out an unnecessary memset 2019-12-04 21:41:01 -06:00
Benjamin Feng
5784985bb8 Use raw PackedIo to shave ~150b 2019-12-04 21:22:36 -06:00
Benjamin Feng
a910a6c871 Rejuggle how offsets are calculated 2019-12-04 18:12:25 -06:00
Andrew Kelley
bef3769bb7 std.fmt.ParseUnsignedError is now public 2019-12-04 18:44:22 -05:00
Andrew Kelley
10e172b1d7 add other OS and fix regression in build-exe for freestanding 2019-12-04 14:42:40 -05:00
Andrew Kelley
44e896f613 Merge pull request #3844 from Snektron/sort-improvements
Small sort improvements
2019-12-04 14:25:00 -05:00
Vexu
137cb32f5e add docs for function parameters 2019-12-04 14:14:47 -05:00
Robin Voetter
841a37ab59 Add std.sort.argMax and std.sort.argMin 2019-12-04 18:20:55 +01:00
Robin Voetter
0159fa284a Make std.sort.min and std.sort.max return ?T 2019-12-04 18:10:20 +01:00
Robin Voetter
65f57e4499 Make std.sort.max accept const slices and add tests 2019-12-04 16:42:18 +01:00
Robin Voetter
6bb0ee0bc4 Add std.sort.isSorted 2019-12-04 16:41:32 +01:00
Benjamin Feng
a6f838aab2 Remove redundant alloc 2019-12-04 00:10:37 -06:00
Benjamin Feng
01e73bba8d Tighten recycled search 2019-12-04 00:08:09 -06:00
Benjamin Feng
baffaf7986 Extract setBits 2019-12-04 00:07:52 -06:00
Benjamin Feng
b33211ed51 Implement block-based skipping 2019-12-03 17:24:50 -06:00
Andrew Kelley
38791ac616 Merge branch 'Vexu-build-start'
closes #3810
closes #3793
closes #3798
2019-12-03 17:26:26 -05:00
Andrew Kelley
521744bb91 correct the calling convention of WinMainCRTStartup 2019-12-03 16:55:27 -05:00
Andrew Kelley
e3ebaab3c7 fix zig builtin 2019-12-03 13:57:13 -05:00
Andrew Kelley
8db4d2332e correct startup logic for exporting libc main 2019-12-03 13:10:26 -05:00
Andrew Kelley
a91f552393 WinMainCRTStartup implies defaulting to console subsystem 2019-12-03 12:52:28 -05:00
Andrew Kelley
6a046c1bcd activate start code when pub main exists
and rename LinkType->LinkMode, OutType->OutputMode
2019-12-03 12:50:42 -05:00
Vexu
ffd21c586d fix tests 2019-12-03 12:50:42 -05:00
Vexu
621c08e692 exported main must be pub 2019-12-03 12:50:42 -05:00
Vexu
20bcdab462 correct caching and add test for missing fn name 2019-12-03 12:50:41 -05:00
Vexu
a0ca30ce01 move more startup code to std lib 2019-12-03 12:50:18 -05:00
LemonBoy
fd7c7be33c Pick up WinMain with proper CC 2019-12-03 12:49:08 -05:00
Andrew Kelley
0d48b60794 Merge pull request #3837 from yvt/patch-as
Replace the remaining uses of the legacy cast syntax with `@as`
2019-12-03 10:26:07 -05:00
yvt
29f25cf059 Update process_headers.zig to use @as 2019-12-03 20:05:07 +09:00
yvt
3c6c317424 Update the docs to use @as 2019-12-03 19:56:50 +09:00
Benjamin Feng
45e0441278 Fix bugs 2019-12-02 22:04:09 -06:00
LemonBoy
26c8930b95 Accept comptime-known expression for asm 2019-12-02 19:53:06 -05:00
Andrew Kelley
b7be57766b Merge pull request #3715 from daurnimator/towards-afd
Misc windows additions+fixes
2019-12-02 16:12:55 -05:00
Andrew Kelley
55202a021a add missing license files 2019-12-02 16:02:03 -05:00
Andrew Kelley
6a36c549a8 add extra LICENSE file for clarification 2019-12-02 15:11:11 -05:00
Andrew Kelley
ad214c7aa0 bring your own OS layer in the std lib
closes #3784
2019-12-02 15:02:17 -05:00
Andrew Kelley
dcbd5ad155 remove upstream support for Zen hobby OS
The new plan to support hobby operating systems is #3784.

And what kind of name is "Zen" anyway? There's already a
[Zen programming language](http://zenlang.sourceforge.net/)
and that's just confusing.
2019-12-02 12:01:49 -05:00
Benjamin Feng
f32555aa08 Work around __heap_base for now 2019-12-02 09:59:20 -06:00
Benjamin Feng
ba38a6d122 Get stuff vaguely working 2019-12-02 09:59:20 -06:00
Benjamin Feng
eb1628b033 Initialize memory segments 2019-12-02 09:59:20 -06:00
Benjamin Feng
eff926b454 Brain dump new wasm allocator 2019-12-02 09:59:20 -06:00
Andrew Kelley
fc1373a85d ci: update sr.ht to use alpine/latest, more reliable 2019-12-02 10:48:12 -05:00
Andrew Kelley
b6127b0fe9 add some null-termination annotations
closes #3797
2019-12-02 01:13:46 -05:00
Andrew Kelley
6d8550a7df fix crash assigning optional struct with anon literal
closes #3827
2019-12-02 01:09:06 -05:00
Andrew Kelley
fecd540826 Merge pull request #3787 from ziglang/remove-array-type-coercion
Remove array type coercion and fix result location bugs
2019-12-02 00:03:41 -05:00
Andrew Kelley
e7ee6647a1 fix invalid check for fn_inline property 2019-12-01 23:56:28 -05:00
Andrew Kelley
3644e85091 fix regressions on windows 2019-12-01 21:31:00 -05:00
Andrew Kelley
37caa56fbc fix docs regressions 2019-12-01 21:27:55 -05:00
Andrew Kelley
c32e50f505 fix regressions in compile error tests 2019-12-01 20:53:24 -05:00
Andrew Kelley
4af5c38674 fixes for self-hosted compiler 2019-12-01 19:22:03 -05:00
Andrew Kelley
080316cd4f fix assigning to an unwrapped optional field in an inline loop 2019-12-01 18:55:35 -05:00
Andrew Kelley
c2cee40aec add advanced IR debugging support
and use it to improve copy_const_val with regards to parent backrefs
2019-12-01 17:09:11 -05:00
Andrew Kelley
8524404f71 this test isn't passing in master branch either 2019-12-01 16:39:30 -05:00
Andrew Kelley
78811ff4ac Merge remote-tracking branch 'origin/kill-ConstGlobalRefs' into remove-array-type-coercion 2019-12-01 09:58:32 -05:00
Andrew Kelley
b36c07a95a Merge remote-tracking branch 'origin/master' into remove-array-type-coercion 2019-12-01 09:56:01 -05:00
Andrew Kelley
4b6740e19d sometimes free stuff from Zig IR pass 1
Total bytes used in stage1 std lib tests:
3.418 -> 3.198 GiB (saving 225 MiB)

There's still this from pass 1 not getting freed:
Const: 6909049 items, 72 bytes each, total 474.407 MiB

This is due to 2 things hanging on to references to IrAnalyze pointers:
 * ZigVar->owner_exec->analysis
 * LazyValue->ira

The LazyValue one could be solved by memoizing the results after the
lazy value is resolved, and then it could unref the IrAnalyze.

ZigVars that are determined to be comptime const, could have their
const_value set to that value, instead of using the mem_slot_index
mechanism. This would prevent an IrAnalyze ref in some cases.
2019-12-01 01:13:21 -05:00
Andrew Kelley
b5df18c8fd inline ConstGlobalRefs into ZigValue
Having ConstGlobalRefs be a pointer in ZigValue was a hack that caused
plenty of bugs. It was used to work around difficulties in type coercing
array values into slices.

However, after #3787 is merged, array values no longer type coerce into
slices, and so this provided an opportunity to clean up the code.

This has the nice effect of reducing stage1 peak RAM usage during the
std lib tests from 3.443 GiB to 3.405 GiB (saving 39 MiB).

There is one behavior test failing in this branch, which I plan to debug
after merging #3787.
2019-12-01 00:29:16 -05:00
Andrew Kelley
5026b1aad5 free IrAnalyze sometimes
Total bytes used in stage1 std lib tests:
3.443 GiB -> 3.418 GiB
2019-11-30 23:57:48 -05:00
Andrew Kelley
951dc451d6 Merge pull request #3808 from LemonBoy/i386-for-ya
linux-i386 support
2019-11-30 22:00:00 -05:00
Andrew Kelley
11b8d3ce9d Merge branch 'std.fs.File' 2019-11-30 18:37:00 -05:00
Andrew Kelley
2e7350140d further clarify std.fs function docs 2019-11-30 18:36:47 -05:00
Andrew Kelley
034ccb4e4e add missing error code handling on Windows 2019-11-30 16:58:32 -05:00
LemonBoy
cdeafe777a Eat shit and die mips 2019-11-30 21:36:16 +01:00
Andrew Kelley
413f9a5cfc move std.fs.Dir.cwd to std.fs.cwd
update to non-deprecated std.fs APIs throughout the codebase

Related: #3811
2019-11-30 15:35:27 -05:00
LemonBoy
6f105b5ae7 Implement target_dynamic_linker for mips 2019-11-30 21:14:32 +01:00
Andrew Kelley
d039fed831 introduce std.fs.Dir.openFile and std.fs.Dir.createFile
These functions have flags parameters which cover all the use cases. The
other functions are now deprecated.
2019-11-30 13:32:11 -05:00
LemonBoy
d0c6728d59 Eat shit and die glibc 2019-11-30 18:55:22 +01:00
LemonBoy
e1e06e6766 linux-i386 support 2019-11-30 16:13:33 +01:00
Andrew Kelley
85e1e3b95f Merge pull request #3284 from Sahnvour/export_variables
Improved support for exporting variables
2019-11-30 00:25:52 -05:00
Andrew Kelley
b220be7a33 more test regression fixes 2019-11-29 23:04:19 -05:00
Andrew Kelley
f980c29306 fix typo in error note for integer casting 2019-11-29 22:33:55 -05:00
Andrew Kelley
d87b13f2f7 fix windows std lib regressions 2019-11-29 21:55:27 -05:00
Andrew Kelley
6936243ee1 fix self-hosted compiler regressions 2019-11-29 21:49:08 -05:00
Andrew Kelley
7278c51ddd fix empty result location for parameters not working 2019-11-29 21:36:12 -05:00
Andrew Kelley
559bd27b08 fix @bitCast result coercing to error union by returning 2019-11-29 19:58:00 -05:00
Andrew Kelley
815b4cfd9d fix return result loc as peer result loc in inferred error set function 2019-11-29 18:21:21 -05:00
Andrew Kelley
a438a615e6 docs: this statement was in the wrong section 2019-11-29 12:41:07 -05:00
Andrew Kelley
2ab7f31e99 std.math: remove constants that should be expressions
All four of these can be represented in fewer characters with
expressions, which will be guaranteed to happen at compile-time, and
have the same or better precision.

The other math constants here which depend on function calls could be
similarly removed if and when #425 is solved. However I left them for
now since Zig does not eagerly evaluate functions with comptime parameters.
2019-11-29 10:48:46 -05:00
Andrew Kelley
bcdb3a9006 more progress 2019-11-28 00:02:53 -05:00
Quetzal Bradley
a6c9c5f767 implement correct buffer wrapping logic in std.event.Channel 2019-11-27 23:09:24 -05:00
Michael Dusan
ca61a5f0b7 Windows: fix test/standalone/shared_library
- on Windows use first found env var { "Path", "PATH" }

Bug Description: `build test` results in the following error on in
a msys64 shell with "PATH" env var instead of "Path":

    error while loading shared libraries: mathtest.dll:
    cannot open shared object file: No such file or directory
2019-11-27 19:24:06 -05:00
Felix Queißner
f0d6447569 Implements std.testing.expectEqual for tagged unions. (#3773) 2019-11-27 16:35:32 -05:00
Andrew Kelley
0f2a9af4aa Merge pull request #3769 from MCRusher/initcapacity-for-buffer-arraylist
Add initCapacity for buffer & arraylist
2019-11-27 13:40:39 -05:00
Andrew Kelley
83c664eaa0 Merge pull request #3780 from Vexu/stage2-async-review
Update use of async functions in self hosted compiler
2019-11-27 13:38:49 -05:00
Andrew Kelley
bf3ac66150 remove type coercion from array values to references
* Implements #3768. This is a sweeping breaking change that requires
   many (trivial) edits to Zig source code. Array values no longer
   coerced to slices; however one may use `&` to obtain a reference to
   an array value, which may then be coerced to a slice.

 * Adds `IrInstruction::dump`, for debugging purposes. It's useful to
   call to inspect the instruction when debugging Zig IR.

 * Fixes bugs with result location semantics. See the new behavior test
   cases, and compile error test cases.

 * Fixes bugs with `@typeInfo` not properly resolving const values.

 * Behavior tests are passing but std lib tests are not yet. There
   is more work to do before merging this branch.
2019-11-27 03:37:50 -05:00
Vexu
4d8a8e65df add more workarounds 2019-11-27 10:17:37 +02:00
Andrew Kelley
63300a21dd Merge branch 'kprotty-event_lock'
closes #3751
2019-11-26 21:08:25 -05:00
daurnimator
8a71f77c4a std: lie about windows socklen_t signed-ness 2019-11-27 13:01:34 +11:00
daurnimator
edc84e7ef7 std: add more winsock functions 2019-11-27 13:01:33 +11:00
daurnimator
19f26578c0 std: windows sockaddr constants come from ws2_32 2019-11-27 13:01:32 +11:00
daurnimator
8aa3d6019c std: add windows.USHORT definition 2019-11-27 13:01:30 +11:00
daurnimator
254c79125b std: fix WSAIoctl definition
zig automatically passes functions as pointers
2019-11-27 13:01:28 +11:00
daurnimator
d99f0a2b8f std: IO_STATUS_BLOCK's status member is an NTSTATUS; add union 2019-11-27 13:01:10 +11:00
daurnimator
1537d4701e std: fix definition of NtDeviceIoControlFile 2019-11-27 13:01:09 +11:00
daurnimator
a453c99ba9 std: add comments for some nt status codes 2019-11-27 13:01:08 +11:00
daurnimator
2c6788d7de std: add windows.closesocket 2019-11-27 13:01:07 +11:00
daurnimator
6b5b0e6cd6 std: fix windows.GetOverlappedResult 2019-11-27 13:01:05 +11:00
daurnimator
ce9966a39b std: improved windows.DeviceIoControl 2019-11-27 13:01:04 +11:00
daurnimator
b05a5a3e52 std: add CreateEvent for windows 2019-11-27 13:01:03 +11:00
daurnimator
78c0d33eb7 std: add WaitForMultipleObjects for windows 2019-11-27 13:01:02 +11:00
daurnimator
21ca54f560 std: add alertable argument for windows.WaitForSingleObject 2019-11-27 13:00:59 +11:00
kprotty
ff445814cb remove wait timeout test cases 2019-11-26 20:40:28 -05:00
kprotty
056b5a26c9 ResetEvent: get abstime based on std.time 2019-11-26 20:40:28 -05:00
kprotty
ca2d566ec8 replace ThreadParker with ResetEvent + WordLock mutex 2019-11-26 20:40:27 -05:00
kprotty
a0955990dc fix ResetEvent windows bugs 2019-11-26 20:40:04 -05:00
kprotty
ef208fee3c Definition fixups & ResetEvent test cases 2019-11-26 20:40:04 -05:00
kprotty
9bce97a479 Start on ResetEvent 2019-11-26 20:40:04 -05:00
Andrew Kelley
8ecd6c4d8c add compiler note for bad int coercion
closes #3724
2019-11-26 19:50:52 -05:00
syscall0
a6ef83cccf Fix build system crash when compiling windows dll 2019-11-26 15:40:31 -05:00
Vexu
0d55075de4 fix command functions not being async pointers 2019-11-26 22:38:05 +02:00
Vexu
798d05dd02 add workaround for #3190 2019-11-26 22:11:04 +02:00
Vexu
379d547603 add missing cast to generic function call result 2019-11-26 14:32:37 -05:00
Vexu
0e405c5fc5 add missing cast to call result type 2019-11-26 14:32:34 -05:00
Andrew Kelley
7de138ad7c std.elf: breaking improvements to the API
and also integration with std.Target.Arch
2019-11-26 14:25:35 -05:00
Benjamin Feng
aca1367533 Optimize binary search algorithm 2019-11-26 13:09:58 -05:00
Vexu
128034481a solve recursion in self hosted 2019-11-26 18:25:29 +02:00
Vexu
36849d8a7b fixes and cleanup in self hosted 2019-11-26 11:52:12 +02:00
Andrew Kelley
76f21852f6 Merge branch 'gereeter-o_path'
closes #3743
2019-11-25 23:46:59 -05:00
Jonathan S
ec569ff26a Or in O_DIRECTORY in openDirFlagsC to capture the fact that it is intended for opening directories 2019-11-25 23:46:48 -05:00
Jonathan S
8baf226d69 Add missing shortening of os.windows. 2019-11-25 23:46:48 -05:00
Jonathan S
4014a8e4b4 Avoid deprecated cwd-based functions for opening directories, preferring to open explicitly relative to Dir.cwd(). 2019-11-25 23:46:48 -05:00
Jonathan S
001334266a Don't pass FILE_LIST_DIRECTORY in openDirTraverseW. 2019-11-25 23:46:48 -05:00
Jonathan S
51c5740879 Use a specific access mask in Dir.openDirListW instead of a generic one. Untested.
The actual desired access mask in this case seems quite confusing and badly documented. The previous combination of `GENERIC_READ` and `SYNCHRONIZE` seems both illegal and redundant according to the [`ntifs.h` documentation](https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/ntifs/nf-ntifs-ntcreatefile), which specifies that `GENERIC_READ` should not be used for directories and includes `SYNCHRONIZE`. `winnt.h` contains a number of relevant-sounding flags such as `FILE_ADD_FILE`, `FILE_ADD_SUBDIRECTORY`, and `FILE_DELETE_CHILD` that do not show up in documentation at all. These are equal in value to file-specific flags that are documented as flags you should not specify when opening a directory.
2019-11-25 23:46:47 -05:00
Jonathan S
07120c8745 Use O_PATH where available in std.fs.Dir.openPathTraverse. 2019-11-25 23:46:47 -05:00
Jonathan S
17bc1f62a5 Split std.fs.Dir.openDir into openDirList and openDirTraverse to clarify what directories can be iterated. Closes ziglang/zig#3741.
The Windows-inspired nomenclature of "List" and "Traverse" was chosen over POSIX-style "Read" and "Path" (from `O_PATH`) for clarity. Using "Path" makes it look like the function is manipulating strings, and the generic "Read" ending isn't useful when there is no generic read method. Even in implementation details, `read` is never used.

Actual exploitation of the difference between the two functions will come in a later commit.
2019-11-25 23:46:47 -05:00
Michael Dusan
f96d818770 Merge pull request #3776 from mikdusan/stage1-intern-housekeeping
stage1: fix bad intern counting
2019-11-25 23:12:55 -05:00
daurnimator
c0cb676745 std: refactor std/debug.zig DwarfInfo operations to be methods 2019-11-25 22:49:46 -05:00
Michael Dusan
d20df7df09 stage1: fix bad intern counting 2019-11-25 20:41:17 -05:00
Andrew Kelley
f8a2dec243 docs: update references to wasm_allocator 2019-11-25 19:30:41 -05:00
Michael Dusan
6b7e1085e3 Merge pull request #3774 from mikdusan/stage1-intern-housekeeping
stage1: consolodate interning
2019-11-25 19:19:32 -05:00
Michael Dusan
fe254ea309 stage1: avoid building empty memory_profiling.cpp
During build an empty .o on macOS/Xcode emits warning:

    ranlib: file: zig_cpp/libcompiler.a(memory_profiling.cpp.o) has no symbols
    ranlib: file: zig_cpp/libcompiler.a(memory_profiling.cpp.o) has no symbols
2019-11-25 19:08:36 -05:00
Andrew Kelley
80f79cc9e8 Merge branch 'fengb-wasi-run-tests'
closes #3730
2019-11-25 18:46:35 -05:00
Andrew Kelley
4261fa3c49 move logic to the appropriate layers; add new compile error 2019-11-25 18:46:17 -05:00
Andrew Kelley
659c1bdeee Merge branch 'wasi-run-tests' of https://github.com/fengb/zig into fengb-wasi-run-tests 2019-11-25 17:53:26 -05:00
Andrew Kelley
cb38bd0a14 rename std.heap.direct_allocator to std.heap.page_allocator
std.heap.direct_allocator is still available for now but it is marked
deprecated.
2019-11-25 17:25:06 -05:00
Michael Dusan
6c89f96df1 stage1: consolodate interning
- merge const_void_val → intern.x_void
- move const_zero_byte → intern.zero_byte
- wrap intern access
2019-11-25 17:18:56 -05:00
Andrew Kelley
35d65cceb8 Merge pull request #3502 from mikdusan/stage1-mem-diet
unembed ConstExprValue from IrInstruction and intern 1-possible-value types
2019-11-25 16:01:13 -05:00
Michael Dusan
a647a88dfc const interning for 1-possible-value types 2019-11-25 15:04:49 -05:00
Michael Dusan
8f3e972da6 unembed ZigValue from IrInstruction 2019-11-25 15:04:39 -05:00
Michael Dusan
acd95546b7 rename ConstExprValue → ZigValue 2019-11-25 15:04:29 -05:00
Andrew Kelley
6b241d7b5d ci: --no-mime-magic 2019-11-25 14:58:45 -05:00
Andrew Kelley
bdf3680be1 zig fmt 2019-11-25 13:53:13 -05:00
Andrew Kelley
8a4c2d3b07 zig fmt fixes for sentinel-terminated pointers
closes #3771
2019-11-25 13:53:06 -05:00
Andrew Kelley
a061ef42c1 Merge pull request #3761 from Vexu/event.fs
Update event.fs to new event loop
2019-11-25 12:31:23 -05:00
Vexu
7dba5ea9cf update event.fs.watch 2019-11-25 17:57:44 +02:00
Andrew Kelley
5a98dd42b3 Merge pull request #3728 from ziglang/null-terminated-pointers
sentinel-terminated pointers
2019-11-25 02:20:08 -05:00
daurnimator
69b780647a std: update for linux 5.4 2019-11-25 02:07:23 -05:00
Andrew Kelley
321726465d fix freebsd regression 2019-11-25 02:00:47 -05:00
Andrew Kelley
d2cb740dd9 add missing null terminator in windows file path helper function 2019-11-25 01:10:30 -05:00
Andrew Kelley
29e438fd1f more sentinel-terminated pointers std lib integration
See #3767
2019-11-25 00:43:36 -05:00
Andrew Kelley
15d415e10b make std.mem.toSlice use null terminated pointers
and fix the fallout
2019-11-24 21:21:05 -05:00
Andrew Kelley
34b1ebefaa Merge remote-tracking branch 'origin/master' into null-terminated-pointers 2019-11-24 20:28:46 -05:00
Andrew Kelley
b9f88c3552 fix compile errors for array sentinels mismatching 2019-11-24 20:25:14 -05:00
Andrew Kelley
ce96323ba1 update cli test 2019-11-24 19:24:52 -05:00
Andrew Kelley
7eb5acdc80 fix casting [N:x]T to [N]T memcpying too many bytes 2019-11-24 18:57:07 -05:00
Andrew Kelley
217a5090ff fix compile error regressions 2019-11-24 18:10:31 -05:00
Andrew Kelley
8309b6188d Merge pull request #3644 from daurnimator/bytefifo
Improvements to std.fifo
2019-11-24 17:33:53 -05:00
daurnimator
1a84bcefb6 std: fix mismatched doc-comment/argument names in fifo.rewind 2019-11-25 09:26:33 +11:00
daurnimator
94485b2a58 std: clean up fifo.readableSliceMut 2019-11-25 09:26:33 +11:00
daurnimator
b4091e3aec std: fifo.deinit didn't need to take a pointer 2019-11-25 09:26:33 +11:00
daurnimator
3062e0e932 std: add fifo.writeItem 2019-11-25 09:26:33 +11:00
daurnimator
c393969a20 std: fix bug in fifo.unget if rewinding doesn't wrap around 2019-11-25 09:26:33 +11:00
daurnimator
61179a4d52 std: follow zig standard library convention and have fifo.read number of items 2019-11-25 09:26:33 +11:00
daurnimator
6037f89212 std: fifo rename from FixedSizeFifo to LinearFifo 2019-11-25 09:26:33 +11:00
daurnimator
cd749e0416 std: fifo now has 3 modes: Static, Slice and Dynamic 2019-11-25 09:26:32 +11:00
daurnimator
c0e47cb645 std: fix fifo for non-u8 types 2019-11-25 09:26:32 +11:00
daurnimator
e810f485ab std: add optimization to fifo if size is power of two 2019-11-25 09:26:32 +11:00
daurnimator
01b2a56225 std: move auto_align constant to top of comptime function
At a later point in time this might be made into a parameter
2019-11-25 09:26:32 +11:00
daurnimator
52645d06e1 std: fix unfinished doc-comment in fifo 2019-11-25 09:26:32 +11:00
Andrew Kelley
c96d565166 add compile error for incompatible pointer sentinels 2019-11-24 17:02:56 -05:00
Andrew Kelley
4018034708 add test cases for arbitrary pointer sentinels 2019-11-24 16:52:32 -05:00
Andrew Kelley
09ec720dab fix comptime @ptrCast of pointers to arrays 2019-11-24 16:25:26 -05:00
Sahnvour
6ebd26f3db removed unnecessary backslashes in windows' libc paths 2019-11-24 21:33:58 +01:00
Sahnvour
696567d9d7 export: check variable type
also fixed existing occurrences
2019-11-24 21:33:58 +01:00
Sahnvour
912c1c24c3 simple test for exporting variables in static libs 2019-11-24 21:33:58 +01:00
Sahnvour
1bde3b6821 gen-h: register the need for stdbool.h and stdint.h when exploring types recursively
otherwise they wouldn't be included when only a struct contains them
2019-11-24 21:33:58 +01:00
Sahnvour
49156e3980 gen-h: add a pass for exported variables 2019-11-24 21:33:58 +01:00
Sahnvour
104b6f1629 refactored gen_h_file to improve maintainability and output
- extracted functions
- factorised extern "C" into a block containing all function prototypes instead of writing macros all over the place
- using intermediate buffers instead of writing directly to the output file
2019-11-24 21:33:58 +01:00
Andrew Kelley
f7574f44c1 add test for struct with var field 2019-11-24 15:20:15 -05:00
Andrew Kelley
44b1dc6db8 add type coercion: [:x]T to [*:x]T 2019-11-24 15:17:55 -05:00
syscall0
eea8b10463 Call DllMain entry point if declared 2019-11-24 14:46:22 -05:00
schroffl
6109e49c5b Fix FixedSizeFifo buffer type
Update the `.buf` property to be a slice of the type that is given as a parameter.
2019-11-24 14:42:56 -05:00
Andrew Kelley
2b1faa1f20 Merge pull request #3748 from Vexu/modernize-stage2
Updates and cleanup in self hosted compiler
2019-11-24 14:40:16 -05:00
Vexu
20f5f56986 uncomment event.fs.watch 2019-11-24 17:42:20 +02:00
Vexu
ab534cc9f1 update event.fs to use global event loop 2019-11-24 17:39:08 +02:00
Vexu
0cbf00a3ec self hosted compiler: final small fixes to get it compiling 2019-11-24 10:24:47 +02:00
Andrew Kelley
4c7b52503b all tests passing 2019-11-24 02:14:21 -05:00
MCRusher
17abb7ef7f Adds initCapacity() to buffer and arraylist
array_list.zig:
- adds ArrayList.initCapacity(*Allocator,usize) to allow preallocation of a block at initialization to reduce future allocations.
- adds a test for ArrayList.initCapacity() that ensures ArrayList.len() is unchanged and that at least the requested amount is allocated for.
buffer.zig:
- adds Buffer.initCapacity(*Allocator,usize), based off of ArrayList.initCapacity(), to preallocate a buffer before use.
note: contrary to Buffer.initSize(0) and then Buffer.list.ensureCapacity(200) (the presumed current method), this only allocates once instead of twice.
- adds Buffer.capacity to check usable allocated space, not including the null byte.
note: returns 0 when Buffer has only a null byte or when initNull() was used before without resize()/replaceContents().
- adds a test "Buffer.initCapacity" which ensures that Buffer.append()'s with [added size <= Buffer.capacity()-Buffer.len()] do not cause a reallocation to occur.
- adds a test "Buffer.initSize" which ensures that Buffer.initSize() behaves as expected, also combined with Buffer.append().
- adds a doc comment to Buffer.initSize() that makes its function and distinction from Buffer.initCapacity() clearer.
2019-11-23 23:49:55 -05:00
MCRusher
d49e0a7b90 Added initCapacity, capacity, and 2 tests.
Added Buffer.initCapcity() to buffer to allow preallocation of a block of memory to reduce future allocations. Uses the added ArrayList.initCapacity() function to achieve this.

Added Buffer.capacity() to track current usable allocation size, not counting null byte, and returning 0 if empty or created with Buffer.initNull()

Added a test for initCapacity() that shows that no further allocation is performed for an append of size smaller than or equal to capacity when initCapacity is used.

Added a test for initSize(), since it did not exist already.

Also added a comment to better explain the difference between initSize() and initCapacity()

note: forgot in the first commit but thanks to mikdusan for helping me brainstorm, through the process, and for drawing up a draft diff which I tweaked.
2019-11-23 23:08:33 -05:00
MCRusher
10e6cde083 Added initCapacity and relevant test
Added ArrayList.initCapcity() as a way to preallocate a block of memory to reduce future allocations.

Added a test "std.ArrayList.initCapacity" that ensures initCapacity adds no elements and increases capacity by at least the requested amount
2019-11-23 22:54:33 -05:00
Andrew Kelley
2dd20aa04a langref: update for sentinel-terminated types 2019-11-23 22:29:12 -05:00
Andrew Kelley
00878a15d7 zig fmt: support sentinel-terminated pointer syntax 2019-11-23 22:21:25 -05:00
Andrew Kelley
f25182f46d structs can have fields with type var
behavior tests passing now
2019-11-23 17:51:37 -05:00
Vexu
010494d8af only test stage2 on linux 2019-11-23 23:45:54 +02:00
Vexu
89310dad56 Merge branch 'master' into modernize-stage2 2019-11-23 23:01:28 +02:00
Vexu
b9ef36094c re-enable stage2 tests 2019-11-23 22:57:34 +02:00
Vexu
6c64f079fa add workaround to child_process.zig 2019-11-23 22:06:51 +02:00
Vexu
d40f204ec0 self hosted compiler: small miscellaneous fixes 2019-11-23 21:57:24 +02:00
Michael Dusan
29d7b5a80c remove UTF BOM 2019-11-23 14:17:55 -05:00
Vexu
7fa59565d3 fix small regressions in std.event 2019-11-23 14:01:00 -05:00
Vexu
133579d7c0 fix casts 2019-11-23 19:36:26 +02:00
Vexu
03cc81665b Merge branch 'master' into modernize-stage2 2019-11-23 19:13:48 +02:00
Andrew Kelley
7597735bad update the stage1 implementation to the new proposal
See #3731
2019-11-23 04:45:35 -05:00
Andrew Kelley
ad0871ea4b Merge branch 'Vexu-missing-cast'
Closes #3336
Closes #3718
2019-11-21 23:25:02 -05:00
Vexu
4e6c1b676b add cast to not hit #2561 2019-11-21 23:21:51 -05:00
Vexu
4d9318cee0 fix missing implicit cast in return instruction 2019-11-21 23:21:51 -05:00
Vexu
0b63573674 improve broken llvm module error message 2019-11-21 23:21:14 -05:00
Vexu
0e8a53514e add missing error set to ChildProsess.SpawnError 2019-11-21 23:21:14 -05:00
Timon Kruiper
94299d16d1 Stage1: Add compile error for an empty switch on a integer 2019-11-22 04:00:47 +00:00
Andrew Kelley
6b623b5ea2 update docs for null terminated stuff 2019-11-21 20:43:42 -05:00
Andrew Kelley
fd6020c4e2 update tests, better error messages, update self-hosted tokenizer 2019-11-21 20:43:41 -05:00
Andrew Kelley
cf2fe2536e better error message when null termination does not match 2019-11-21 20:43:41 -05:00
Andrew Kelley
47f06be369 string literals are now null terminated
this also deletes C string literals from the language, and then makes
the std lib changes and compiler changes necessary to get the behavior
tests and std lib tests passing again.
2019-11-21 20:43:41 -05:00
Andrew Kelley
21f344b3b9 add null terminated pointers and arrays to self-hosted
as well as `@typeInfo` and `@Type`
2019-11-21 20:43:41 -05:00
Andrew Kelley
1aa978f32e implement null terminated pointers 2019-11-21 20:43:41 -05:00
Andrew Kelley
e3404e3c78 Merge branch 'std.fs.Dir.openRead' 2019-11-21 20:41:30 -05:00
Andrew Kelley
cd5f4de2a6 std: remove O_LARGEFILE from OS bits when the OS does not define it 2019-11-21 20:34:55 -05:00
Benjamin Feng
0f0d01a037 Replace magic numbers with named constants 2019-11-21 18:41:02 -06:00
Andrew Kelley
bf1cbebea1 improve std.fs.selfExePath and related functions on Windows 2019-11-21 18:51:12 -05:00
Andrew Kelley
cd37c1a377 add std.fs.Dir.openRead
This is progress towards file system APIs that encourage avoiding
Time Of Check, Time Of Use bugs.
2019-11-21 17:07:29 -05:00
Andrew Kelley
874b34a30f self-hosted tokenizer handles \r in string literals 2019-11-20 21:03:17 -05:00
Andrew Kelley
ed619245e9 remove dead code shebang support from self-hosted tokenizer 2019-11-20 20:18:19 -05:00
Benjamin Feng
d27721f58c Add .enable_wasmtime build flag 2019-11-20 12:06:21 -06:00
Benjamin Feng
218f9ff34e Work around WASI's nonexistent @returnAddress() 2019-11-19 20:55:55 -06:00
Benjamin Feng
b88bb93af3 WASI isatty 2019-11-19 20:17:00 -06:00
Benjamin Feng
14e9c7d1f2 WASI clock functions 2019-11-19 19:44:19 -06:00
Benjamin Feng
c3d93cd9f2 WASI time_t / timespec 2019-11-19 16:12:26 -06:00
Benjamin Feng
747529e96b Use wasm_allocator 2019-11-19 00:31:40 -06:00
Johan Bolmsjö
ad77e93415 std.testing.expectEqual: show differing pointer values
Show differing pointer values when comparing pointers instead of the
content they point to.

It's confusing for a test to say "expected S{.x = 1}, found S{.x = 1}"
as illustrated below when it was the pointers that differed.

There seems to be different rules for when a pointer is dereferenced by
the printing routine depending on its type. I don't fully grok this but
it's also illustrated below.

    const std = @import("std");

    const S = struct { x: u32 };

    // before: ...expected S{ .x = 1 }, found S{ .x = 1 }
    // after:  ...expected S@7ffcd20b7798, found S@7ffcd20b7790
    test "compare_ptr_to_struct" {
        var a = S{.x = 1};
        var b = S{.x = 1};
        std.testing.expectEqual(&a, &b);
    }

    // before: ...expected u32@7fff316ba31c, found u32@7fff316ba318
    // after:  ...expected u32@7ffecec622dc, found u32@7ffecec622d8
    test "compare_ptr_to_scalar" {
        var a: u32 = 1;
        var b: u32 = 1;
        std.testing.expectEqual(&a, &b);
    }
2019-11-19 06:22:34 +00:00
dbandstra
b3539b40a6 add std.math.tau constant (equivalent to 2 * pi) 2019-11-19 06:20:20 +00:00
frmdstryr
aa4e92f3b3 Make StreamServer return address of accecpted client 2019-11-19 01:06:04 +00:00
daurnimator
ed956b5812 translate-c: add support for MacroQualified definitions 2019-11-19 01:05:17 +00:00
Andrew Kelley
0c33ebb38e add regression test case. closes #2980 2019-11-18 19:59:03 -05:00
Andrew Kelley
9eed0d3603 add regression test case. closes #2889 2019-11-18 19:54:37 -05:00
Andrew Kelley
828abe046f add regression test case. closes #3007 2019-11-18 19:51:49 -05:00
Andrew Kelley
21aed86a4a add regression test case
closes #3097
2019-11-18 17:31:35 -05:00
Andrew Kelley
4dd3f42972 Merge pull request #3695 from daurnimator/towards-afd
Windows definitions
2019-11-17 23:17:48 +00:00
Andrew Kelley
57b8614a5a Merge pull request #3697 from Vexu/container-docs
Implement container level doc comments
2019-11-17 22:31:12 +00:00
daurnimator
4e28d7a5f7 fix bug on empty error union 2019-11-17 22:29:49 +00:00
Andrew Kelley
8e3370367b Merge pull request #3705 from daurnimator/fix-std.valgrind
std: fix outdated valgrind module
2019-11-17 22:29:17 +00:00
LemonBoy
924dd674e2 Catch invalid type from peer resolution
Fixes #3703
2019-11-17 22:25:14 +00:00
Vexu
6cddf9d723 properly parse anon literal in array 2019-11-17 22:24:21 +00:00
daurnimator
d870a68e68 std: add a couple of tests to valgrind module 2019-11-17 14:16:09 +11:00
daurnimator
7d582d0a00 std: fix missing @ptrToInt in valgrind.memcheck 2019-11-17 14:14:57 +11:00
daurnimator
41c72bb54c std: fix use of old syntax in std.valgrind.memcheck 2019-11-17 14:14:57 +11:00
daurnimator
cc76494c42 std: use enum literals in valgrind module 2019-11-17 14:14:57 +11:00
daurnimator
4a3bb557f1 std: fix outdated valgrind module 2019-11-17 14:14:57 +11:00
Vexu
314cb707fc fix containerdoccomment not handled in docgen.zig 2019-11-15 18:44:29 +02:00
Vexu
977b613881 add container doc comments to generated docs 2019-11-15 15:17:59 +02:00
Vexu
e509d21f39 implemented container doc comments in stage 1 2019-11-15 15:02:51 +02:00
daurnimator
431eeb5e20 std: add pieces for WSAIoctl on windows 2019-11-15 10:31:52 +11:00
daurnimator
3b8afe31a0 std: add NtDeviceIoControlFile definition for windows 2019-11-15 10:31:51 +11:00
daurnimator
6469900e79 std: add WSAStartup and WSACleanup for windows 2019-11-15 10:31:47 +11:00
Andrew Kelley
8c4784f9c1 remove no longer correct comment 2019-11-14 12:38:30 -05:00
LemonBoy
a11da37734 Update discriminant value also for zero-sized unions
Fixes #3681
2019-11-14 17:07:20 +00:00
Vexu
b92f42d1f4 implemented container doc comments in stage 2 2019-11-14 16:25:06 +02:00
Andrew Kelley
d89f39d719 rework layout of struct type fields
This removes the remaining hack in the implementation of anonymous
struct literals, and they can now therefore now have greater than 16
fields/elements.
2019-11-14 03:52:39 -05:00
Andrew Kelley
f2f698a888 rework comptime struct value layout, removing 1/2 hacks
in the implementation of anonymous struct literals
2019-11-14 03:52:36 -05:00
daurnimator
4cf535a01b std: add WSASocketW for windows 2019-11-14 17:09:22 +11:00
daurnimator
d9d3268cc1 std: add DeviceIoControl and GetOverlappedResult for windows 2019-11-14 17:09:21 +11:00
daurnimator
f4c6cc3270 std: add winsock some definitions 2019-11-14 17:09:19 +11:00
daurnimator
a832b35c19 std: add windows socket constants
Taken from https://docs.microsoft.com/en-us/windows/win32/api/winsock2/nf-winsock2-wsasocketw
2019-11-14 17:09:17 +11:00
daurnimator
be86e41d97 std: add CTL_CODE function for windows 2019-11-14 17:09:16 +11:00
daurnimator
4830415071 std: add FILE_ANY_ constants for windows 2019-11-14 17:00:09 +11:00
daurnimator
0270545edb std: add windows ioctl transfer types 2019-11-14 17:00:07 +11:00
daurnimator
ef6cec983c std: add windows FILE_DEVICE_ defines 2019-11-14 17:00:05 +11:00
Vexu
b83ce08a3b add compile error for @atomicRmw on enum not being an .Xchg 2019-11-13 18:48:31 +00:00
Andrew Kelley
c806de8ae7 README: update the short description of what zig is 2019-11-13 13:44:19 -05:00
Andrew Kelley
0237e7a701 std.io.getStdOut and related fns no longer can error
Thanks to the Windows Process Environment Block, it is possible to
obtain handles to the standard input, output, and error streams without
possibility of failure.
2019-11-13 04:01:40 +00:00
Andrew Kelley
8bae70454d Merge pull request #3675 from Vexu/atomic-store
Add @atomicStore builtin
2019-11-13 03:06:55 +00:00
Andrew Kelley
32b37e695a fix anonymous struct literal assigned to variable
closes #3667
2019-11-12 21:57:25 -05:00
Andrew Kelley
37318bf151 fn parameters participate in result location semantics
See #3665
2019-11-12 18:55:17 -05:00
Vexu
41914321b4 fix comptime atomicStore and add tests 2019-11-13 01:32:16 +02:00
Vexu
f0c94d95dd use @atomicStore in std lib 2019-11-13 00:52:15 +02:00
Vexu
110ef2e528 add @atomicStore builtin 2019-11-13 00:25:44 +02:00
Sahnvour
956ba8b0e7 Merge pull request #3447 from Sahnvour/vcpkg
build: initial support for using vcpkg libraries
2019-11-12 20:16:01 +01:00
Andrew Kelley
e32b4829f4 Merge pull request #3670 from Vexu/atomics-enum
Support atomic operations with enums
2019-11-12 17:45:29 +00:00
Andrew Kelley
710ccacfa3 fix assertion failure in ptrToInt
found by building pluto
2019-11-12 12:21:20 -05:00
Vexu
5194fc57d1 use enum with atomics in std lib 2019-11-12 17:55:54 +02:00
Vexu
7e5b234b8b support atomic operations with enums 2019-11-12 17:13:33 +02:00
Andrew Kelley
45d2fd9b9d fix assertion failure in init_const_undefined
found this from building my tetris game
2019-11-11 22:11:28 -05:00
Andrew Kelley
bf8870a60b fix unresolved type making it to codegen
found this trying to build oxid
2019-11-11 22:11:22 -05:00
Andrew Kelley
5502160bd2 Merge pull request #3652 from ziglang/anon-container-lit
implement anonymous struct literals and anonymous list literals
2019-11-12 01:40:31 +00:00
Andrew Kelley
0c315e7f76 update docs for anonymous struct/list literals 2019-11-11 19:57:57 -05:00
Andrew Kelley
b9482fc32d implement fully anonymous list literals 2019-11-11 19:00:39 -05:00
Andrew Kelley
a33b9aec72 add test for missing const in slice with nested array type 2019-11-11 18:01:27 -05:00
Andrew Kelley
ca2a788a24 fully anonymous struct literals 2019-11-11 17:50:41 -05:00
xackus
6d3b95a708 Stricter tests for non-streaming parser 2019-11-11 23:41:53 +01:00
xackus
f9b7d6d75d Fix bugs in JSON parser
Make comments into documentation where appropriate
2019-11-11 23:25:54 +01:00
xackus
371747d8fb json: surrogate pair support
test json.Parser with tests used for json.Streaming parser
(some don't pass yet)
2019-11-11 22:06:00 +01:00
Andrew Kelley
1bca8e693d fix anon literal used with return result loc 2019-11-11 13:18:16 -05:00
Andrew Kelley
d4e6a6d5e2 zig fmt: support anon struct and anon list init syntax 2019-11-11 13:12:45 -05:00
Andrew Kelley
725b6ee634 add behavior test case for anonymous list literal syntax 2019-11-11 13:12:21 -05:00
Andrew Kelley
b4ad3e71af add behavior test case for anon union literal 2019-11-11 13:12:21 -05:00
Andrew Kelley
5b27943498 implement anon struct literal syntax
This implements stage1 parser support for anonymous struct literal
syntax (see #685), as well as semantic analysis support for anonymous
struct literals and anonymous list literals (see #208). The semantic
analysis works when there is a type coercion in the result location;
inferring the struct type based on the values in the literal is not
implemented yet. Also remaining to do is zig fmt support for this new
syntax and documentation updates.
2019-11-11 13:11:58 -05:00
Andrew Kelley
de30438ed2 stage1 parser code for anon container lit 2019-11-11 13:11:58 -05:00
xackus
739f716108 minor fixes 2019-11-11 19:06:35 +01:00
Andrew Kelley
ae0a219d1f stop accepting deprecated use keyword
closes #2591
2019-11-11 13:02:39 -05:00
Felix Queißner
cd5c9c8998 Fix missing @as cast in std.fmt.formatInt (#3650) 2019-11-10 23:08:24 +00:00
xackus
f6d124418f Fix and document 2019-11-10 22:26:42 +01:00
xackus
6d0cdf7cd7 Unescape JSON strings 2019-11-10 22:05:03 +01:00
Andrew Kelley
d44a69689e std.ChildProcess.spawn has a consistent error set
across targets. Also fix detection of pkg-config not
installed on Windows when using zig build.
2019-11-10 15:40:27 -05:00
Andrew Kelley
891e2149b0 Merge pull request #3635 from lun-4/unify-unix-sockets
std.net: add unix socket support to Address and StreamServer
2019-11-10 20:40:19 +00:00
Luna
c8a8da2804 remove builtin.os check in Address.initUnix 2019-11-10 16:44:18 -03:00
Luna
d1eabe81a9 add sockaddr_un to os/bits/windows 2019-11-10 14:38:33 -03:00
Luna
d99ecef943 replace panic to unreachable
- remove error.UnsupportedOS from StreamServer.listen
2019-11-10 14:17:39 -03:00
Luna
2d02920a90 use hasDecl instead of switch on builtin.os 2019-11-10 14:04:52 -03:00
dimenus
98e37537d1 minor fix due to recent directory handling API changes 2019-11-10 16:34:31 +00:00
Luna
25423eb453 add errors/panics for unsupported OSes 2019-11-10 10:50:22 -03:00
Luna
e4704f68f8 use at-as 2019-11-09 15:10:39 -03:00
Luna
fc2e8f92b2 Merge remote-tracking branch 'upstream/master' into unify-unix-sockets 2019-11-09 15:07:09 -03:00
Luna
348c0232a5 miscellaneous fixes
- make connextUnixSocket use std.net.Address
 - fix StreamServer.listen giving wrong protocol for unix sockets
2019-11-09 14:53:48 -03:00
LemonBoy
d18b5f8b53 Fix initialization of union references
Fixes #3532
2019-11-09 12:20:34 -05:00
Luna
05ae21b78e make StreamServer.listen family-agnostic
- rename Address.parseUnix to Address.initUnix
2019-11-09 12:51:33 -03:00
Luna
f4d8dc278b rename TcpServer -> StreamServer
- add AF_UNIX support to getOsSockLen
2019-11-09 12:40:56 -03:00
Sahnvour
def5462d05 build: initial support for using vcpkg libraries 2019-11-09 12:37:38 +01:00
Luna
c2325053a8 add Address.parseUnix and Address.format support for AF_UNIX 2019-11-08 21:44:17 -03:00
dimenus
8c8078513e missed cast in std/target.zig 2019-11-08 19:19:08 -05:00
Andrew Kelley
6d5abf87ec Merge pull request #3628 from ziglang/as-builtin
implement `@as` builtin and fix result location semantics with regards to type coercion
2019-11-08 18:30:07 -05:00
Luna
9458620e18 replace Address.parse Address.parseIp 2019-11-08 19:59:30 -03:00
Luna
5d05cfcfe6 rename IpAddress to Address, add Address.unix 2019-11-08 19:35:04 -03:00
Andrew Kelley
f7b1e02158 fix type cast in windows child process code 2019-11-08 17:05:20 -05:00
Andrew Kelley
3cf5c2c62b fix regressed tests and update docs to use "type coercion" 2019-11-08 15:57:25 -05:00
Andrew Kelley
3834d3dac0 passing std lib tests 2019-11-08 15:57:25 -05:00
Andrew Kelley
aef04aff0c initial docs for @as 2019-11-08 15:57:25 -05:00
Andrew Kelley
aa0daea541 update more of the std lib to use @as 2019-11-08 15:57:25 -05:00
Andrew Kelley
a2acc27872 behavior tests passing 2019-11-08 15:57:25 -05:00
Andrew Kelley
8954a1bae5 more regressions fixed 2019-11-08 15:57:25 -05:00
Andrew Kelley
fa34dfcce7 fix result loc of cast not finding parent 2019-11-08 15:57:24 -05:00
Andrew Kelley
e0db54e89d update the codebase to use @as 2019-11-08 15:57:24 -05:00
Andrew Kelley
2a6fbbd8fb introduce @as builtin for type coercion
This commit also hooks up type coercion (previously called implicit
casting) into the result location mechanism, and additionally hooks up
variable declarations, maintaining the property that:

    var a: T = b;

is semantically equivalent to:

    var a = @as(T, b);

See #1757
2019-11-08 15:57:24 -05:00
Andrew Kelley
6d28b28ccc Merge branch 'kprotty-adaptive_lock' 2019-11-08 02:09:51 -05:00
Andrew Kelley
2723ffc2b2 fixups and zig fmt 2019-11-08 01:52:23 -05:00
Andrew Kelley
fbbcf2f30d Merge branch 'adaptive_lock' of https://github.com/kprotty/zig into kprotty-adaptive_lock 2019-11-08 01:21:22 -05:00
kprotty
e2189b6e5d cleanup getEventHandle 2019-11-07 19:37:53 -06:00
kprotty
43900011f7 handle NtCreateKeyedEvent failure by spinning to ensure correctness 2019-11-07 18:56:43 -06:00
Andrew Kelley
9b0536e6f4 ci: add srht oauth token to drone cloud script 2019-11-07 19:00:52 -05:00
kprotty
fe8c1cf804 missing os declaration 2019-11-07 17:14:08 -06:00
kprotty
bb4abfdc78 Use system instead of builtin.link_libc 2019-11-07 16:36:33 -06:00
kprotty
12e68cbeb6 pthread_sched_yield -> sched_yield 2019-11-07 16:33:25 -06:00
Vexu
86d9563d15 self hosted compiler: various small fixes 2019-11-08 00:18:14 +02:00
kprotty
f41e58d015 fix SpinLock.yield for pull/3626 2019-11-07 15:51:20 -06:00
kprotty
b5d84635f2 remove WaitOnAddress backend in std.ThreadParker 2019-11-07 15:46:57 -06:00
kprotty
b535e86cc0 move SpinLock definitions around 2019-11-07 15:32:20 -06:00
Andrew Kelley
e2a0bea65f ci: bump ubuntu from 16.04 to 18.04 2019-11-07 16:18:42 -05:00
Vexu
bca672372a self hosted compiler: move functions to util.zigto avoid defining llvm instricts. 2019-11-07 23:03:57 +02:00
Vexu
459a364a33 allow Group to optionally manage function frames' memory 2019-11-07 13:26:49 -05:00
Vexu
3858a526e3 make callMainAsync async 2019-11-07 13:18:47 -05:00
kprotty
92dac89d01 lock the mutex on pthread_cond_signal() 2019-11-07 09:23:02 -06:00
Vexu
56ea07f4fc self hosted compiler: comment out event.fs stuff 2019-11-07 10:30:56 +02:00
Vexu
7a24334199 self hosted compiler: small fixes to imports and declarations 2019-11-07 10:30:56 +02:00
Vexu
c6076a1360 self hosted compiler: use enum literals 2019-11-07 10:30:56 +02:00
Vexu
7000316113 self hosted compiler: fix calling convention in type.zig 2019-11-07 10:30:47 +02:00
Vexu
9394d14815 self hosted compiler: unify Target and std.Target 2019-11-07 10:30:47 +02:00
Vexu
6dd4a276de self hosted compiler: update to new std.event 2019-11-07 10:30:37 +02:00
Vexu
110e575497 self hosted compiler: replace Promise with Frame and AnyFrame 2019-11-07 10:30:21 +02:00
Vexu
cb20093614 self hosted compiler: remove await async pattern 2019-11-07 10:30:11 +02:00
Vexu
b06e5b8c68 self hosted compiler: fix internal build info 2019-11-07 10:29:58 +02:00
Vexu
8edf27343f self hosted compiler: fix zig_llvm.h function signature 2019-11-07 10:29:44 +02:00
Shawn Landden
2e52fafac5 correctly use llvm undef in release modes 2019-11-07 02:51:04 -05:00
Andrew Kelley
697c4ffd41 Merge branch 'LemonBoy-fix-more-things'
closes #3621
2019-11-07 02:46:20 -05:00
LemonBoy
cf6fb89ced Add small tokenizer test case for #3468 2019-11-07 02:46:10 -05:00
LemonBoy
528908a06e Fix ptrCast of array references to fn
Closes #3607
2019-11-07 02:46:10 -05:00
Andrew Kelley
c7fd414dab Merge pull request #3618 from nrdmn/uefi
UEFI improvements
2019-11-06 23:19:46 -05:00
Nick Erdmann
78b54d9c96 std/os/uefi: protocol handling improvements 2019-11-07 03:06:06 +01:00
Nick Erdmann
cef51eaffb std/os/uefi: snp, mnp, ip6, and udp6 support 2019-11-07 02:53:53 +01:00
Nick Erdmann
f4767186dd std/os/uefi: loading images 2019-11-07 02:53:53 +01:00
Andrew Kelley
6ee3cabe5c allow type coercion from *[0]T to E![]const T
This is an unambiguous, safe cast.
2019-11-06 20:44:15 -05:00
kprotty
7045f1e875 skip std.ThreadParker test on single-threaded 2019-11-06 17:23:44 -06:00
shiimizu
7277670843 Add error when too few arguments are provided to std.fmt 2019-11-06 18:22:33 -05:00
Sebastian Keller
f81f36e2ff std.json.Value: added dumpStream(), utilize WriteStream for dump() 2019-11-06 18:21:52 -05:00
Vexu
ac6f0d245d fix NodeErrorSetDecl rendering 2019-11-06 18:15:39 -05:00
Vexu
4530adbd33 use global event loop in std.event types 2019-11-06 15:17:40 -05:00
Andrew Kelley
913f7d0450 improve the start code for evented I/O
When evented I/O is being used, prevent event loop from terminating
at least until main() has returned.
2019-11-06 15:08:29 -05:00
Brendan Hansknecht
c1e8fdf812 add token for parsing pointer dereference 2019-11-06 14:03:21 -05:00
Sebastian Keller
dd4e9fb16b Fixed a leak in the json parser.
parseString() created a copy of the string using the wrong allocator.
Instead of using the ArenaAllocator, it was using the allocator passed
into Parser.init(). This lead to a leak as the copied string was not
freed when the ArenaAllocator was deinited.
2019-11-06 14:00:36 -05:00
Vexu
6b61fcddfa fix translate-c arrow deref 2019-11-06 13:58:55 -05:00
kprotty
4dbfc48ab3 Disable asm("yield") for arm in SpinLock.yieldCpu() because of CI 2019-11-05 16:16:03 -06:00
kprotty
c9db420a09 Adaptive Mutex:
- uses std.ThreadParker
- supports static initialization (deprecates StaticallyInitializedMutex)
2019-11-05 16:14:43 -06:00
kprotty
465ebf494d ThreadParker implementation 2019-11-05 15:58:58 -06:00
kprotty
14209cf615 make SpinLock.Backoff pub 2019-11-05 13:43:17 -06:00
Andrew Kelley
9bc4f8ea77 zig build: addIncludeDir does -I instead of -isystem 2019-11-05 14:32:17 -05:00
Andrew Kelley
cb8af1c6d4 Merge branch 'vector-element-access'
This introduces the concept of vector index being part of a pointer
type. This avoids vectors having well-defined in-memory layout, and
allows vectors of any integer bit width to work the same way.

When a vector is indexed with a scalar, this is vector element access,
which this branch implements. When a vector is indexed with a vector,
this is gather/scatter, which is not implemented in this branch.

closes #3575
closes #3580
2019-11-05 13:40:57 -05:00
Andrew Kelley
9a08de93b6 fix incorrect type name on bit field pointers 2019-11-05 13:37:43 -05:00
Andrew Kelley
9b4a529164 fix initialization of vector in a struct field 2019-11-05 12:36:39 -05:00
Andrew Kelley
cbaa10fc3b implement storing vector elements via runtime index 2019-11-05 12:11:57 -05:00
Andrew Kelley
70be308c43 implement loading vector elements via runtime index 2019-11-05 12:11:40 -05:00
Andrew Kelley
76d188551e implement store of vector element with comptime index 2019-11-05 12:11:18 -05:00
Andrew Kelley
ece8d6c2fa comptime load of vector element 2019-11-05 12:11:18 -05:00
Andrew Kelley
55e54d98c4 runtime load vector element with comptime index 2019-11-05 12:11:16 -05:00
Vexu
a26e9fa723 add special formatting for ipv4-mapped ipv6 addresses 2019-11-05 12:05:34 -05:00
LemonBoy
71e209521a Mark type fields as CT
Fixes #3276
2019-11-05 12:05:01 -05:00
Andrew Kelley
4e9ab0306a Merge pull request #3587 from LemonBoy/fix-things
Bunch'o'fixes
2019-11-05 11:44:07 -05:00
Shawn Landden
1c22cb5e51 fix noreturn function that may return.
we do not want undefined behavior here in --release-fast
and --release-small modes
2019-11-05 11:38:32 -05:00
Shawn Landden
55685ae780 remove duplicate isNan implementation 2019-11-05 11:34:33 -05:00
lukechampine
3d907b2943 crypto: Add support for AES-CTR 2019-11-05 11:33:11 -05:00
kprotty
84e370d0b2 Move hybrid yielding into its own struct 2019-11-05 09:31:29 -06:00
kprotty
0d4f4aad9e adaptive SpinLock 2019-11-05 08:16:08 -06:00
daurnimator
1657bead46 std: Add fifo useful for buffers 2019-11-04 17:44:01 -05:00
data-man
42ccdc2765 Replace AES variables to constants 2019-11-04 17:43:14 -05:00
Andrew Kelley
ce70a9be24 Merge pull request #3589 from Vexu/ipv6-improvements
Ipv6 improvements
2019-11-04 15:22:14 -05:00
Andrew Kelley
6c17282062 std.os.read can fail with ConnectionResetByPeer 2019-11-04 14:40:30 -05:00
Andrew Kelley
aaf50970a8 Merge pull request #3574 from lukechampine/aes
crypto: Add AES implementation
2019-11-04 14:39:40 -05:00
LemonBoy
9170dcb73f Fix #3558
Finding a suitable test case is left as an exercise to the reader.
2019-11-04 20:33:41 +01:00
LemonBoy
c47211cc60 Prevent crash when slicing undefined ptr to slice
Fixes #3534
2019-11-04 20:33:41 +01:00
LemonBoy
2b4bf1e7ce Fix crash in #3483
The bytesToSlice is still not evaluated at comptime but at least it
doesn't crash anymore.
2019-11-04 20:33:40 +01:00
LemonBoy
61825062aa Correctly process errors for invalid types in fn call
Fixes #3544
2019-11-04 20:33:40 +01:00
LemonBoy
c8b6e55299 Make the leb module available to non-std code 2019-11-04 20:33:40 +01:00
Luke Champine
eb95afbc66 remove speculative AES TODOs 2019-11-04 13:59:26 -05:00
Andrew Kelley
5db77e3c66 Merge pull request #3588 from daurnimator/tiny-std-fixes
Tiny std fixes
2019-11-04 13:25:37 -05:00
Brendan Hansknecht
52207f22de Add karatsuba to big ints 2019-11-04 13:20:03 -05:00
Vexu
6e786b60d4 support ipv4-mapped ipv6 addresses 2019-11-04 19:54:36 +02:00
Vexu
32ac1b5927 improve ipv6 parsing and formatting 2019-11-04 19:00:58 +02:00
daurnimator
c8463ce9b0 std: Add definitions for (deprecated) futimes and utimes C functions 2019-11-05 02:19:25 +11:00
daurnimator
6e635c6406 std: close is OSX specific 2019-11-05 02:16:30 +11:00
LemonBoy
2f740fa19f Fix cmpxchg trying to execute at CT
Fixes #3582
2019-11-04 09:54:13 +01:00
Andrew Kelley
711520d935 ci: workaround PATH apparently not working 2019-11-04 00:07:27 -05:00
kprotty
bb6ad1a6c2 Remove StaticallyInitializedMutex 2019-11-03 21:09:51 -06:00
Andrew Kelley
b7747653f2 ci: more fixes for update_download_page script 2019-11-03 22:01:59 -05:00
Andrew Kelley
0860b1919b ci: work around pip install permission denied 2019-11-03 21:44:39 -05:00
Andrew Kelley
1a820067d0 ci: hail mary running git.exe in the windows bat file 2019-11-03 18:58:54 -05:00
Andrew Kelley
96984e3033 ci: avoid leaking oauth access token 2019-11-03 14:55:21 -05:00
Andrew Kelley
629b91da61 ci: use heredoc and alpine/edge for faster sr.ht job 2019-11-03 14:20:35 -05:00
Andrew Kelley
5001faa690 ci: stop assuming that azure will complete last
Each of the 3 CI services now trigger a sr.ht build via
the on_master_success script. The sr.ht build checks if all builds have
completed successfully by trying to download the JSON file for the
particular version. If all builds have completed successfully then this
sr.ht job will update the download page.
2019-11-03 14:00:28 -05:00
Michael Dusan
10046f9a52 stage1: add linux XDG Base Directory support
- define zig global cache based on XDG spec:

    if env XDG_CACHE_HOME {
        "$XDG_CACHE_HOME/zig"
    } else {
        "$HOME/.cache/zig"
    }

- old definition "$HOME/.local/share/zig" is retired
- closes #3573
2019-11-02 18:30:07 -04:00
Luna
2e0dd5733f add FileNotFound to os.ConnectError error set 2019-11-02 15:49:15 -04:00
Luna
d535bf2c7d add FileNotFound error to os.connect 2019-11-02 15:49:15 -04:00
Andrew Kelley
f749bf0942 std.os: fix sendto, poll, recvfrom when linking libc
Thank you to Brendan Hansknecht for this patch.
2019-11-02 15:15:56 -04:00
lukechampine
f403aa6cee crypto: Add AES implementation 2019-11-01 22:42:25 -04:00
Andrew Kelley
d6dec80261 startup code respects root source file's event_loop if present 2019-10-31 14:21:04 -04:00
Andrew Kelley
081c62fc00 fix regression in std.os.dirent64 on linux 2019-10-31 13:56:15 -04:00
Tse
00382f6dae DragonFlyBSD tidyup 2019-10-31 13:53:32 -04:00
Andrew Kelley
790d439ce2 util.cpp: canonicalize the order of includes 2019-10-31 13:47:20 -04:00
Andrew Kelley
d3d3e4e374 startup code sets up event loop if I/O mode is declared evented 2019-10-31 11:41:39 -04:00
Andrew Kelley
788848e123 std.net: fix reference to incorrect constant name 2019-10-30 23:03:49 -04:00
Andrew Kelley
61d5a0bf48 Merge branch 'std.net' 2019-10-30 21:30:16 -04:00
Andrew Kelley
6a15e8a7a7 add comments to disabled tests linking to the tracking issue 2019-10-30 21:29:45 -04:00
Tse
33cc204481 DragonFlyBSD support 2019-10-30 21:21:58 -04:00
Henry Wu
7c73503451 generated docs: move color to box-shadow CSS prop 2019-10-30 21:20:02 -04:00
Andrew Kelley
7b7ba51642 fix os.sockaddr being a union instead of a struct 2019-10-30 20:57:20 -04:00
Andrew Kelley
d7f15aa2cb Merge remote-tracking branch 'origin/master' into std.net 2019-10-30 20:43:56 -04:00
Andrew Kelley
c52ee6efca canonicalize std.os IPPROTO constants 2019-10-30 20:41:28 -04:00
Andrew Kelley
0de862e8ba make std.net more portable
* Delete `std.net.TmpWinAddr`. I don't think that was ever meant to
   be a real thing.
 * Delete `std.net.OsAddress`. This abstraction was not helpful.
 * Rename `std.net.Address` to `std.net.IpAddress`. It is now an extern
   union of IPv4 and IPv6 addresses.
 * Move `std.net.parseIp4` and `std.net.parseIp6` to the
   `std.net.IpAddress` namespace. They now return `IpAddress` instead of
   `u32` and `std.net.Ip6Addr`, which is deleted.
 * Add `std.net.IpAddress.parse` which accepts a port and parses either
   an IPv4 or IPv6 address.
 * Add `std.net.IpAddress.parseExpectingFamily` which additionally
   accepts a `family` parameter.
 * `std.net.IpAddress.initIp4` and `std.net.IpAddress.initIp6` are
   improved to directly take the address fields instead of a weird
   in-between type.
 * `std.net.IpAddress.port` is renamed to `std.net.IpAddress.getPort`.
 * Added `std.net.IpAddress.setPort`.
 * `os.sockaddr` struct on all targets is improved to match the
   corresponding system struct. Previously I had made it a union of
   sockaddr_in, sockaddr_in6, and sockaddr_un. The new abstraction for
   this is now `std.net.IpAddress`.
 * `os.sockaddr` and related bits are added for Windows.
 * `os.sockaddr` and related bits now have the `zero` fields default
   to zero initialization, and `len` fields default to the correct size.
   This is enough to abstract the differences across targets, and so
   no more switch on the target OS is needed in `std.net.IpAddress`.
 * Add the missing `os.sockaddr_un` on FreeBSD and NetBSD.
 * `std.net.IpAddress.initPosix` now takes a pointer to `os.sockaddr`.
2019-10-30 20:22:05 -04:00
Andrew Kelley
618ee5b63a fixes for macos and 32 bit arches 2019-10-30 14:43:55 -04:00
Andrew Kelley
24b3da871d fix regressions 2019-10-30 12:49:37 -04:00
Andrew Kelley
f5ff36271b Merge branch 'testAddresses' of https://github.com/marler8997/zig into std.net 2019-10-30 12:33:47 -04:00
Andrew Kelley
0fb1388031 std.net: enable test for resolving DNS 2019-10-30 12:16:47 -04:00
Nathan Michaels
1f0bcefe4a Document PriorityQueue. 2019-10-30 01:05:00 -04:00
Andrew Kelley
16397241f6 fix std.net tests and std.net.TcpServer docs 2019-10-30 00:50:30 -04:00
Andrew Kelley
b3c80418a8 fix regression in behavior tests 2019-10-30 00:40:17 -04:00
Andrew Kelley
d5e438b36e rename std.net.Server to TcpServer and simplify it 2019-10-30 00:34:30 -04:00
Andrew Kelley
c3d816a98e std lib networking improvements, especially non-blocking I/O
* delete the std/event/net directory
 * `std.event.Loop.waitUntilFdReadable` and related functions
   no longer have possibility of failure. On Linux, they fall
   back to poll() and then fall back to sleep().
 * add some missing `noasync` decorations in `std.event.Loop`
 * redo the `std.net.Server` API. it's quite nice now, but
   shutdown does not work cleanly. There is a race condition with
   close() that I am actively working on.
 * move `std.io.OutStream` to its own file to match `std.io.InStream`.
   I started working on making `write` integrated with evented I/O,
   but it got tricky so I backed off and filed #3557. However
   I did integrate `std.os.writev` and `std.os.pwritev` with evented I/O.
 * add `std.Target.stack_align`
 * move networking tests to `lib/std/net/test.zig`
 * add `std.net.tcpConnectToHost` and `std.net.tcpConnectToAddress`.
 * rename `error.UnknownName` to `error.UnknownHostName` within the
   context of DNS resolution.
 * add `std.os.readv`, which is integrated with evented I/O.
 * `std.os.preadv`, is now integrated with evented I/O.
 * `std.os.accept4` now asserts that ENOTSOCK and EOPNOTSUPP never
    occur (misuse of API), instead of returning errors.
 * `std.os.connect` is now integrated with evented I/O.
   `std.os.connect_async` is gone. Just use `std.os.connect`.
 * fix false positive dependency loop regarding async function frames
 * add more compile notes to help when dependency loops occur
   in determining whether a function is async.
 * ir: change an assert to ir_assert to make it easier to find
   workarounds for when such an assert is triggered. In this case
   it was trying to parse an IPv4 address at comptime.
2019-10-29 22:59:30 -04:00
lukechampine
48b5dc0516 inline path separator loop 2019-10-29 21:32:02 -04:00
Andrew Kelley
8d3b7689ad std.net: port the RFC 3484/6724 destination...
...address selection from musl libc
2019-10-29 16:10:14 -04:00
Andrew Kelley
9ade31faaf implement CNAME expansion 2019-10-29 14:03:39 -04:00
Jonathan Marler
4e0c2ed443 Add tests for ip address formatting 2019-10-29 00:27:45 -06:00
Andrew Kelley
67058b9b70 basic DNS address resolution for linux without libc 2019-10-29 02:19:22 -04:00
Andrew Kelley
d5865f5319 move libc/linux bits around 2019-10-28 15:29:50 -04:00
Andrew Kelley
845be4ea3e fix regression in translate-c 2019-10-28 15:29:50 -04:00
Andrew Kelley
f4c244b3d0 partial no-libc implementation of std.net.getAddressList 2019-10-28 15:29:50 -04:00
Andrew Kelley
4b80e376e3 std.net.getAddressList 2019-10-28 15:29:50 -04:00
Andrew Kelley
4f594527c0 detect async fn recursion and emit compile error 2019-10-28 15:10:48 -04:00
Andrew Kelley
a3222b5ff1 remove dead tls code 2019-10-28 15:10:12 -04:00
Andrew Kelley
b37c009683 Merge pull request #3541 from xackus/language_server
* fix json parser crashing on empty input

* make implicit cast of tagged unions to enums easier to find in docs
2019-10-28 15:08:33 -04:00
Timon Kruiper
03603ea353 Std docs: Fix a js error that would cause some function to be not rendered 2019-10-28 15:06:55 -04:00
Andrew Kelley
f2d0d9820d synchronize the target features for compiling C code
d91fc0fdd8 changed zig's behavior to
disable the SSE feature when cross compiling for i386-freestanding.

This commit does the same when compiling C Code.
2019-10-28 14:37:32 -04:00
Nathan Michaels
6fdeaac338 Add some documentation for standard library things. (#3540)
* Add some documentation for standard library things.

Added a bunch of descriptions for array_list.
Added some usage notes for failing_allocator.
Documented some of mem.Allocator.
2019-10-28 03:57:23 -04:00
xackus
36fa5fabc6 rename error and specify it in function 2019-10-27 21:52:28 +01:00
xackus
eeb6536c85 better test name for empty string
Co-Authored-By: Andrew Kelley <andrew@ziglang.org>
2019-10-27 21:41:52 +01:00
xackus
8960e8090e make implicit cast of tagged unions to enums easier to find in docs 2019-10-27 21:35:22 +01:00
Andrew Kelley
8af6c7e34c Merge pull request #3522 from SebastianKeller/WriteJson
Added 'writeJson' to write_stream.zig:
2019-10-27 15:53:24 -04:00
Sebastian Keller
78b00c0b51 Added test for 'emitJson' 2019-10-27 20:49:42 +01:00
Sebastian Keller
ac705a7bb6 Unified public api 2019-10-27 20:15:48 +01:00
Henry Wu
f756d875b1 generated docs: vertically align fns with comments 2019-10-27 15:11:36 -04:00
Andrew Kelley
4a57913ca0 std.target: use mem instead of std.mem 2019-10-27 14:27:20 -04:00
Benoit Giannangeli
73c4a5f186 lib/std/target.zig: Added missing 'mem' constant 2019-10-27 14:26:25 -04:00
xackus
a0abd3be85 fix json parser crashing on empty input
remove unreachable code
2019-10-27 10:45:54 +01:00
Andrew Kelley
05003d533a Merge pull request #3537 from lun-4/fix/accept4
fix std.os.accept4
2019-10-26 21:31:38 -04:00
Luna
d4e41c5bc6 std: make addr_size parameter be a pointer to socklen_t
removes ptrCast
2019-10-26 22:05:17 -03:00
Luna
bf16fc210b fix std.os.accept4
- add WouldBlock to list of errors in AcceptError
 - ptrCast addr_size to the system's socklen_t, instead of assuming it's
    usize
2019-10-26 22:00:50 -03:00
Andrew Kelley
fafd1fd480 ci: disable test-compare-output on aarch64 2019-10-26 18:48:42 -04:00
Noam Preil
d91fc0fdd8 Don't use SSE on freestanding 2019-10-26 16:46:43 -04:00
Noam Preil
b8305b5648 Don't save/restore stack on newStackCall to noreturn function 2019-10-26 16:45:46 -04:00
Andrew Kelley
ee21bab253 ci: -Dskip-release for aarch64 to hit 1 hour time limit 2019-10-26 13:14:54 -04:00
Timon Kruiper
d04c58816d Translate-c: Fix a segfault when to many errors are emitted
This was already fixed when doing `@cImport`, but not yet when
running `zig translate-c`.
2019-10-26 13:09:23 -04:00
Andrew Kelley
05fd59e06a ci: enable more passing tests on aarch64-linux 2019-10-26 12:09:15 -04:00
Michael Dusan
3aeb1b115d stage1: fix compile error on macOS Xcode 11.2
src/codegen.cpp:7713:33: error: unused variable 'global_linkage_values' [-Werror,-Wunused-const-variable]
static const GlobalLinkageValue global_linkage_values[] = {
2019-10-25 17:49:01 -04:00
Andrew Kelley
e219f0c786 fix regression in zig run
changes in 1dcf540426 added a "double
free" of the progress node, causing a segfault for `zig run` when there
is a terminal attached. fixed.
2019-10-25 13:03:12 -04:00
Andrew Kelley
952aa7a9c1 ci: perform git config inside zig git repo dir 2019-10-25 04:26:22 -04:00
Andrew Kelley
c5e26b8673 ci: force git name-rev to be 9 on all targets 2019-10-25 03:27:00 -04:00
Andrew Kelley
aa2607a109 Merge branch 'ci-drone-cloud' 2019-10-24 21:41:14 -04:00
Andrew Kelley
6eba65bd7f ci: add aarch64 to download page 2019-10-24 21:40:26 -04:00
Andrew Kelley
bf5be65be6 disable not working stuff 2019-10-24 21:13:47 -04:00
Andrew Kelley
55c282ed51 os.dup2: handle EBAF 2019-10-24 21:13:05 -04:00
Andrew Kelley
f6367a0751 ci: build docs, fix PR logic 2019-10-24 20:47:50 -04:00
Andrew Kelley
695a746aa0 ci: use x86_64 namespaced docker image
I took a risk that docker had implemented namespacing with regards to
architectures correctly, but of course they didn't. So the CI docker
image for x86_64 was clobbered by an aarch64 image with the same name.

Now we're doing arch namespaces with the tag name, so here's the x86_64
one.
2019-10-24 20:46:07 -04:00
Andrew Kelley
551e70dcb2 ci: add s3 secrets to drone config 2019-10-24 19:46:11 -04:00
Andrew Kelley
43f5054a90 ci: drone tests only aarch64 with docker image 2019-10-24 19:46:11 -04:00
Andrew Kelley
79cb383f7d fix 32-bit build of translate_c.zig 2019-10-24 19:46:11 -04:00
Andrew Kelley
0e9f32d42b disable static build for now until the docker image is ready 2019-10-24 19:46:11 -04:00
Andrew Kelley
099532af87 add Drone Cloud CI configuration 2019-10-24 19:46:11 -04:00
Andrew Kelley
ad438a95c5 avoid passing -march=native when not supported
Clang does not support -march=native for all targets.
Arguably it should always work, but in reality it gives:
error: the clang compiler does not support '-march=native'
If we move CPU detection logic into Zig itelf, we will not need this,
instead we will always pass target features and CPU configuration explicitly.
For now, we simply avoid passing the flag when it is known to not be
supported.
2019-10-24 19:43:56 -04:00
Andrew Kelley
f8bd1cd3b1 implement partial C ABI support for aarch64 2019-10-24 19:13:21 -04:00
Sebastian Keller
6257b4c596 Shortened switch statement 2019-10-24 22:44:12 +02:00
Andrew Kelley
32c89531b1 Add missing compile error when ptr used instead of array
in array literals.

Fixes #3524
2019-10-24 16:23:33 -04:00
Sebastian Keller
b82b6a7093 Added 'writeJson' to write_stream.zig:
Small addition to make writing a json value easier
2019-10-24 14:23:36 +02:00
Andrew Kelley
345042ecbc Merge pull request #3519 from ziglang/move-builtin-types
move types from builtin to std
2019-10-24 02:25:22 -04:00
Andrew Kelley
60cd11bd4b get rid of std.os.foo.is_the_target
It had the downside of running all the comptime blocks and resolving
all the usingnamespaces of each system, when just trying to discover if
the current system is a particular one.

For Darwin, where it's nice to use `std.Target.current.isDarwin()`, this
demonstrates the utility that #425 would provide.
2019-10-24 01:14:52 -04:00
Andrew Kelley
8591731f2b refAllDecls in a test block to limit when it gets run 2019-10-24 00:32:18 -04:00
Andrew Kelley
17eb24a7e4 move types from builtin to std
* All the data types from `@import("builtin")` are moved to
  `@import("std").builtin`. The target-related types are moved
  to `std.Target`. This allows the data types to have methods, such as
  `std.Target.current.isDarwin()`.
 * `std.os.windows.subsystem` is moved to
   `std.Target.current.subsystem`.
 * Remove the concept of the panic package from the compiler
   implementation. Instead, `std.builtin.panic` is always the panic
   function. It checks for `@hasDecl(@import("root"), "panic")`,
   or else provides a default implementation.

This is an important step for multibuilds (#3028). Without this change,
the types inside the builtin namespace look like different types, when
trying to merge builds with different target settings. With this change,
Zig can figure out that, e.g., `std.builtin.Os` (the enum type) from one
compilation and `std.builtin.Os` from another compilation are the same
type, even if the target OS value differs.
2019-10-23 19:09:49 -04:00
Jonathan Marler
ef62452363 Handle TERM=dumb for stdout/stderr 2019-10-23 11:44:39 -04:00
Andrew Kelley
e98e5dda52 implement safety for resuming non-suspended function
closes #3469
2019-10-22 23:43:27 -04:00
Andrew Kelley
1dcf540426 main.cpp: fix not ending progress node for zig build 2019-10-22 23:32:06 -04:00
emekoi
cb8dacabd8 explicity linked ntdll on mingw-w64 2019-10-22 20:42:51 -04:00
Andrew Kelley
f65b1d4680 integrate stage1 progress display with semantic analysis 2019-10-22 17:52:12 -04:00
Maximilian Hunt
dc080573d1 Add documentation on function parameter type inference. 2019-10-22 15:28:21 -04:00
Andrew Kelley
0dbdb6329f Merge pull request #3503 from MasterQ32/markdown-renderer
Starts to implement markdown parser.
2019-10-22 15:26:42 -04:00
Felix Queißner
c71857703f Adds documentation for std.fmt.format grammar and customization. (#3474) 2019-10-22 14:58:27 -04:00
Felix Queißner
03f1ad5007 Merge branch 'master' of https://github.com/ziglang/zig into markdown-renderer 2019-10-22 20:29:25 +02:00
Andrew Kelley
e839250c51 Merge branch 'stratact-no-dir-allocators'
closes #2885
closes #2886
closes #2888
closes #3249
2019-10-21 23:54:29 -04:00
Andrew Kelley
a5cc758036 std.os.accept4: improve docs and integrate with evented I/O 2019-10-21 23:23:11 -04:00
Jonathan Marler
87b11617b5 Fix accept function API
The sockaddr pointer and size of the accept function points to a data structure that can only be determined at runtime.  The only requirement is that it must be large enough to hold 2 bytes for the address family value.  Typeical usage of the socket API is for UDP/TCP IPv4 and IPv6 sockets, which use sockaddr_in and sockaddr_in6.  And some sockets can actually support both simultaneously in which case the app may want to have access to the size of the returned sockaddr.  Operating systems can even support custom protocols where they use custom sockaddr data structures.  In this case the standard library would have no knowledge of the actual size of the sockaddr being passed into the accept function.  In this case the standard library should defer to the app to pass in the size of their structure.
2019-10-21 23:12:35 -04:00
Vexu
2550cb4638 remove pub syntax for container fields 2019-10-21 23:04:19 -04:00
Andrew Kelley
064377be9a test runner: restore previous behavior of printing all tests passed 2019-10-21 22:21:18 -04:00
Andrew Kelley
fc6f84f3f0 fix os.unlinkatW implementation 2019-10-21 20:58:53 -04:00
Andrew Kelley
65165554d0 test runner: restore previous behavior when...
...stderr does not support ansi escape codes
2019-10-21 20:50:47 -04:00
Andrew Kelley
9a82f00a4f add freebsd AT_* bits 2019-10-21 20:50:47 -04:00
Andrew Kelley
5917572e59 cleanup 2019-10-21 20:50:47 -04:00
Andrew Kelley
98c4365b66 darwin: add AT_* bits 2019-10-21 19:39:30 -04:00
Andrew Kelley
87f632b08a fs.Dir.openDir: use empty object name for "." on Windows 2019-10-21 19:19:49 -04:00
Andrew Kelley
859cbef8a4 test runner: refresh display before running test
This makes it so that when a test fails quickly, and writes output, it
will do so after the test name is printed.
2019-10-21 19:01:08 -04:00
Andrew Kelley
16a91e6a45 adjust test runner to print the test name when error occurs 2019-10-21 18:36:37 -04:00
Andrew Kelley
ef67c49785 [wip] use NtDll APIs on Windows to implement std.fs.Dir 2019-10-21 14:18:01 -04:00
LemonBoy
ddb87237de Fix crash with peer type resolution & error unions
Fixes #3353
2019-10-20 22:03:39 -04:00
Andrew Kelley
5b1a492012 breaking: improve std.fs directory handling API
* Added `std.c.unlinkat` and `std.os.unlinkat`.
 * Removed `std.fs.MAX_BUF_BYTES` (this declaration never made it to
   master branch)
 * Added `std.fs.Dir.deleteTree` to be used on an open directory handle.
 * `std.fs.deleteTree` has better behavior for both relative and
   absolute paths. For absolute paths, it opens the base directory
   and uses that handle for subsequent operations. For relative paths,
   it does a similar strategy, using the cwd handle.
 * The error set of `std.fs.deleteTree` is improved to no longer have
   these possible errors:
   - OutOfMemory
   - FileTooBig
   - IsDir
   - DirNotEmpty
   - PathAlreadyExists
   - NoSpaceLeft
 * Added `std.fs.Dir.posix_cwd` which is a statically initialized
   directory representing the current working directory.
 * The error set of `std.Dir.open` is improved to no longer have these
   possible errors:
   - FileTooBig
   - IsDir
   - NoSpaceLeft
   - PathAlreadyExists
   - OutOfMemory
 * Added more alternative functions to `std.fs` for when the path
   parameter is a null terminated string. This can sometimes be more
   effecient on systems which have an ABI based on  null terminated
   strings.
 * Added `std.fs.Dir.openDir`, `std.fs.Dir.deleteFile`, and
   `std.fs.Dir.deleteDir` which all operate on an open directory handle.
 * `std.fs.Walker.Entry` now has a `dir` field, which can be used to do
   operations directly on `std.fs.Walker.Entry.basename`, avoiding
   `error.NameTooLong` for deeply nested paths.
 * Added more docs to `std.os.OpenError`

This commit does the POSIX components for these changes. I plan to
follow up shortly with a commit for Windows.
2019-10-20 21:48:23 -04:00
LemonBoy
771dafbaba Resolve lazy slice start/end values
Fixes #3489
2019-10-20 14:49:25 -04:00
Felix Queißner
5456eb1107 Starts to implement markdown parser. Implemented: strong, emphasis, strikethrough, underline, code blocks, ulist, olist, paragraphs, headings. Planned: Links, Images, internal references. 2019-10-20 11:49:28 +02:00
Andrew Kelley
6948d7fce7 Merge pull request #3429 from Rocknest/docs-local
Design suggestion for generated docs
2019-10-19 16:43:39 -04:00
Andrew Kelley
dbb1eaefb5 Merge pull request #3473 from nrdmn/subsystem
Configurable PE Subsystem
2019-10-19 15:11:23 -04:00
stratact
e78d3750c5 Use 8192 sized buffers and remove allocator parameters 2019-10-19 14:04:51 -04:00
LemonBoy
6f7939a452 Prevent too eager constant-folding of switch expression
A pointer was wrongly assumed to be comptime-available causing the
analysis pass to assume its initial value was constant.

Fixes #3481
2019-10-19 13:48:26 -04:00
LemonBoy
bab93e7561 Fix crash when generating constant unions with single field 2019-10-19 13:47:49 -04:00
Andrew Kelley
63dfca9715 Merge pull request #3482 from ziglang/mem-usage-report
add -DZIG_ENABLE_MEM_PROFILE option and -fmem-report flag
2019-10-19 12:42:32 -04:00
Andrew Kelley
4e98512344 reduce the size of IrInstruction by 8 bytes on 64 bit targets
This brings the std lib tests down from 3.51 GiB memory usage
to 3.41 GiB, by making two fields that were 64 bits 32 bits.
This is a small thing; the bigger wins will come from the strategy
outlined in the previous commit.
2019-10-19 03:51:04 -04:00
Andrew Kelley
fa9f1d2396 add -DZIG_ENABLE_MEM_PROFILE option and -fmem-report flag
This can be used to find what's taking up memory in the compiler.
Here's an example of how to use it:

```
./zig test ../lib/std/std.zig --cache off -fmem-report
```

And here's the output I get for this on x86_64-linux-gnu today:

```
Const: 6462833 items, 152 bytes each, total 936.84 MiB
ConstGlobalRefs: 17236534 items, 24 bytes each, total 394.51 MiB
ResetResult: 1698108 items, 160 bytes each, total 259.11 MiB
ConstExprValue: 3118299 items, 80 bytes each, total 237.91 MiB
EndExpr: 1345395 items, 168 bytes each, total 215.56 MiB
Unknown_8: 27370821 items, 8 bytes each, total 208.82 MiB
VarPtr: 1127866 items, 168 bytes each, total 180.70 MiB
IrBasicBlock: 794834 items, 120 bytes each, total 90.96 MiB
LoadPtr: 554024 items, 160 bytes each, total 84.54 MiB
Unknown_64: 1245715 items, 64 bytes each, total 76.03 MiB
Unknown_40: 1879218 items, 40 bytes each, total 71.69 MiB
Unknown_72: 989117 items, 72 bytes each, total 67.92 MiB
Return: 423783 items, 160 bytes each, total 64.66 MiB
Unknown_168: 332480 items, 168 bytes each, total 53.27 MiB
Unknown_152: 336890 items, 152 bytes each, total 48.84 MiB
AddImplicitReturnType: 230819 items, 168 bytes each, total 36.98 MiB
Br: 217835 items, 168 bytes each, total 34.90 MiB
Unknown_184: 179529 items, 184 bytes each, total 31.50 MiB
FieldPtr: 179388 items, 184 bytes each, total 31.48 MiB
BinOp: 171004 items, 176 bytes each, total 28.70 MiB
LoadPtrGen: 173287 items, 168 bytes each, total 27.76 MiB
CondBr: 137864 items, 192 bytes each, total 25.24 MiB
Unknown_720: 30918 items, 720 bytes each, total 21.23 MiB
CallSrc: 99320 items, 216 bytes each, total 20.46 MiB
Unknown_160: 129243 items, 160 bytes each, total 19.72 MiB
Unknown_1: 19339456 items, 1 bytes each, total 18.44 MiB
CheckStatementIsVoid: 119838 items, 160 bytes each, total 18.29 MiB
Unknown_48: 371178 items, 48 bytes each, total 16.99 MiB
TestComptime: 101443 items, 160 bytes each, total 15.48 MiB
DeclVarSrc: 72578 items, 184 bytes each, total 12.74 MiB
StorePtr: 72776 items, 176 bytes each, total 12.22 MiB
ZigVar: 79201 items, 160 bytes each, total 12.09 MiB
Unknown_16: 770643 items, 16 bytes each, total 11.76 MiB
Phi: 60482 items, 184 bytes each, total 10.61 MiB
TestErrSrc: 66177 items, 168 bytes each, total 10.60 MiB
Unknown_240: 45164 items, 240 bytes each, total 10.34 MiB
ElemPtr: 58232 items, 184 bytes each, total 10.22 MiB
AllocaSrc: 60053 items, 176 bytes each, total 10.08 MiB
CallGen: 44873 items, 224 bytes each, total 9.59 MiB
SaveErrRetAddr: 63787 items, 152 bytes each, total 9.25 MiB
Unknown_112: 82283 items, 112 bytes each, total 8.79 MiB
AllocaGen: 51909 items, 176 bytes each, total 8.71 MiB
Unknown_24: 373599 items, 24 bytes each, total 8.55 MiB
ResultLocPeer: 113683 items, 72 bytes each, total 7.81 MiB
DeclRef: 36343 items, 168 bytes each, total 5.82 MiB
UnwrapErrPayload: 34603 items, 168 bytes each, total 5.54 MiB
Ref: 33414 items, 168 bytes each, total 5.35 MiB
Unknown_104: 53882 items, 104 bytes each, total 5.34 MiB
DeclVarGen: 32540 items, 168 bytes each, total 5.21 MiB
StructFieldPtr: 30449 items, 176 bytes each, total 5.11 MiB
UnwrapErrCode: 31508 items, 168 bytes each, total 5.05 MiB
Unknown_56: 90256 items, 56 bytes each, total 4.82 MiB
SpillBegin: 28722 items, 168 bytes each, total 4.60 MiB
SpillEnd: 28722 items, 160 bytes each, total 4.38 MiB
ResultLocReturn: 64573 items, 48 bytes each, total 2.96 MiB
PtrType: 14702 items, 184 bytes each, total 2.58 MiB
SliceType: 15005 items, 176 bytes each, total 2.52 MiB
Unknown_176: 13326 items, 176 bytes each, total 2.24 MiB
RefGen: 12881 items, 168 bytes each, total 2.06 MiB
UnOp: 12102 items, 176 bytes each, total 2.03 MiB
SwitchBr: 9453 items, 200 bytes each, total 1.80 MiB
TestErrGen: 11143 items, 160 bytes each, total 1.70 MiB
Unknown_32: 52359 items, 32 bytes each, total 1.60 MiB
CheckSwitchProngs: 9094 items, 184 bytes each, total 1.60 MiB
TypeOf: 9259 items, 160 bytes each, total 1.41 MiB
IntCast: 8772 items, 168 bytes each, total 1.41 MiB
OptionalUnwrapPtr: 8755 items, 168 bytes each, total 1.40 MiB
SwitchTarget: 9094 items, 160 bytes each, total 1.39 MiB
Cast: 8198 items, 176 bytes each, total 1.38 MiB
WidenOrShorten: 8448 items, 160 bytes each, total 1.29 MiB
ErrorUnion: 7613 items, 176 bytes each, total 1.28 MiB
SliceSrc: 6249 items, 192 bytes each, total 1.14 MiB
ErrWrapCode: 7133 items, 168 bytes each, total 1.14 MiB
TypeName: 7328 items, 160 bytes each, total 1.12 MiB
ImplicitCast: 5480 items, 176 bytes each, total 941.88 KiB
ResolveResult: 5638 items, 168 bytes each, total 924.98 KiB
ResultLocInstruction: 22696 items, 40 bytes each, total 886.56 KiB
BitCastSrc: 4947 items, 168 bytes each, total 811.62 KiB
CompileErr: 5148 items, 160 bytes each, total 804.38 KiB
ReturnPtr: 5305 items, 152 bytes each, total 787.46 KiB
Unreachable: 5038 items, 152 bytes each, total 747.83 KiB
TestNonNull: 4716 items, 160 bytes each, total 736.88 KiB
BitCastGen: 4431 items, 160 bytes each, total 692.34 KiB
PtrToInt: 4289 items, 160 bytes each, total 670.16 KiB
SliceGen: 3573 items, 192 bytes each, total 669.94 KiB
ArrayType: 4081 items, 168 bytes each, total 669.54 KiB
IntType: 3868 items, 168 bytes each, total 634.59 KiB
Unknown_88: 7213 items, 88 bytes each, total 619.87 KiB
Truncate: 3771 items, 168 bytes each, total 618.68 KiB
TypeInfo: 3740 items, 160 bytes each, total 584.38 KiB
SwitchVar: 3385 items, 176 bytes each, total 581.80 KiB
ContainerInitFields: 3223 items, 184 bytes each, total 579.13 KiB
ContainerInitList: 2309 items, 192 bytes each, total 432.94 KiB
PtrCastGen: 2626 items, 168 bytes each, total 430.83 KiB
BoolNot: 2457 items, 160 bytes each, total 383.91 KiB
FnProto: 2054 items, 184 bytes each, total 369.08 KiB
MergeErrSets: 1927 items, 176 bytes each, total 331.20 KiB
Unknown_136: 2486 items, 136 bytes each, total 330.17 KiB
Unknown_80: 4059 items, 80 bytes each, total 317.11 KiB
Bswap: 1670 items, 168 bytes each, total 273.98 KiB
TypeId: 1680 items, 160 bytes each, total 262.50 KiB
PtrCastSrc: 1371 items, 176 bytes each, total 235.64 KiB
ErrName: 1193 items, 160 bytes each, total 186.41 KiB
UnionTag: 1120 items, 160 bytes each, total 175.00 KiB
TagName: 1050 items, 160 bytes each, total 164.06 KiB
SizeOf: 942 items, 160 bytes each, total 147.19 KiB
MemberName: 871 items, 168 bytes each, total 142.90 KiB
Import: 881 items, 160 bytes each, total 137.66 KiB
PtrOfArrayToSlice: 758 items, 168 bytes each, total 124.36 KiB
UnionFieldPtr: 710 items, 176 bytes each, total 122.03 KiB
EnumToInt: 778 items, 160 bytes each, total 121.56 KiB
CheckRuntimeScope: 700 items, 168 bytes each, total 114.84 KiB
FieldParentPtr: 632 items, 184 bytes each, total 113.56 KiB
BoolToInt: 719 items, 160 bytes each, total 112.34 KiB
ResultLocPeerParent: 904 items, 104 bytes each, total 91.81 KiB
IntToPtr: 537 items, 168 bytes each, total 88.10 KiB
AlignOf: 561 items, 160 bytes each, total 87.66 KiB
AtomicRmw: 356 items, 208 bytes each, total 72.31 KiB
MemberCount: 441 items, 160 bytes each, total 68.91 KiB
Memset: 342 items, 176 bytes each, total 58.78 KiB
PopCount: 321 items, 168 bytes each, total 52.66 KiB
AlignCast: 251 items, 168 bytes each, total 41.18 KiB
IrInstruction *: 5230 items, 8 bytes each, total 40.86 KiB
IrBasicBlock *: 5230 items, 8 bytes each, total 40.86 KiB
TagType: 261 items, 160 bytes each, total 40.78 KiB
HasDecl: 234 items, 168 bytes each, total 38.39 KiB
OverflowOp: 191 items, 200 bytes each, total 37.30 KiB
Export: 209 items, 176 bytes each, total 35.92 KiB
SetCold: 219 items, 160 bytes each, total 34.22 KiB
ReturnAddress: 216 items, 152 bytes each, total 32.06 KiB
FromBytes: 178 items, 176 bytes each, total 30.59 KiB
SetRuntimeSafety: 188 items, 160 bytes each, total 29.38 KiB
OptionalWrap: 151 items, 168 bytes each, total 24.77 KiB
Clz: 143 items, 168 bytes each, total 23.46 KiB
ResizeSlice: 135 items, 168 bytes each, total 22.15 KiB
UnionInitNamedField: 106 items, 184 bytes each, total 19.05 KiB
Panic: 102 items, 160 bytes each, total 15.94 KiB
SwitchElseVar: 93 items, 168 bytes each, total 15.26 KiB
ToBytes: 89 items, 168 bytes each, total 14.60 KiB
IntToFloat: 78 items, 168 bytes each, total 12.80 KiB
Unknown_4360: 3 items, 4360 bytes each, total 12.77 KiB
ErrWrapPayload: 72 items, 168 bytes each, total 11.81 KiB
FloatOp: 62 items, 176 bytes each, total 10.66 KiB
FloatToInt: 47 items, 168 bytes each, total 7.71 KiB
FloatCast: 46 items, 168 bytes each, total 7.55 KiB
ErrToInt: 47 items, 160 bytes each, total 7.34 KiB
Asm: 33 items, 216 bytes each, total 6.96 KiB
ErrSetCast: 40 items, 168 bytes each, total 6.56 KiB
Memcpy: 34 items, 176 bytes each, total 5.84 KiB
AtomicLoad: 17 items, 184 bytes each, total 3.05 KiB
AwaitSrc: 16 items, 168 bytes each, total 2.62 KiB
Resume: 14 items, 160 bytes each, total 2.19 KiB
AwaitGen: 12 items, 176 bytes each, total 2.06 KiB
ArgType: 12 items, 168 bytes each, total 1.97 KiB
AnyFrameType: 12 items, 160 bytes each, total 1.88 KiB
SuspendFinish: 10 items, 160 bytes each, total 1.56 KiB
SuspendBegin: 10 items, 160 bytes each, total 1.56 KiB
Ctz: 9 items, 168 bytes each, total 1.48 KiB
FrameHandle: 8 items, 152 bytes each, total 1.19 KiB
SetEvalBranchQuota: 7 items, 160 bytes each, total 1.09 KiB
AssertZero: 7 items, 160 bytes each, total 1.09 KiB
UndeclaredIdent: 7 items, 160 bytes each, total 1.09 KiB
CmpxchgSrc: 5 items, 216 bytes each, total 1.05 KiB
CmpxchgGen: 5 items, 200 bytes each, total 1000.00 bytes
IntToEnum: 4 items, 168 bytes each, total 672.00 bytes
VectorType: 4 items, 168 bytes each, total 672.00 bytes
ErrorReturnTrace: 2 items, 160 bytes each, total 320.00 bytes
Breakpoint: 2 items, 152 bytes each, total 304.00 bytes
FrameAddress: 2 items, 152 bytes each, total 304.00 bytes
Unknown_4: 61 items, 4 bytes each, total 244.00 bytes
VectorToArray: 1 items, 168 bytes each, total 168.00 bytes
SetAlignStack: 1 items, 160 bytes each, total 160.00 bytes
Unknown_12: 2 items, 12 bytes each, total 24.00 bytes
ErrorTableEntry *: 0 items, 8 bytes each, total 0.00 bytes
AstNode *: 0 items, 8 bytes each, total 0.00 bytes
Total bytes used: 3.51 GiB
```

You can see that most of the memory is taken up by IR instructions,
as well as comptime values. This points toward 2 changes which will
greatly reduce memory usage:

 * Rework semantic analysis so that IR instructions can be freed.
   Currently the comptime value struct (ConstExprValue) is embedded
   directly into the IrInstruction struct. If this is made to be
   separate, at the very least pass 1 IR instructions can be freed.
   This includes `Const` which is the largest usage of memory currently.

 * Rework the ConstExprValue struct to no longer be a tagged union.
   For example, there's no need for an integer comptime value to be
   80 bytes.

From this you can also see that this eliminates some things from being
the culprit. Before doing this analysis, I considered whether doing
string interning would help. From the above output, you can see that all
strings in the compiler account for only 18 MiB, so string interning
would have been a dead end.
2019-10-19 03:23:23 -04:00
Nick Erdmann
c8dec5729c std/build: make subsystem configurable 2019-10-18 20:11:28 +02:00
Nick Erdmann
8774b1d947 std/os/windows: remove subsystem detection for uefi 2019-10-18 19:49:02 +02:00
Andrew Kelley
e42d86b657 Merge branch 'lun-4-progress-take-2'
closes #3362
2019-10-17 22:08:39 -04:00
Andrew Kelley
2d5b2bf1c9 improve progress reporting
* use erase rest of line escape code.
 * use `stderr.supportsAnsiEscapeCodes` rather than `isTty`.
 * respect `--color off`
 * avoid unnecessary recursion
 * add `Progress.log`
 * disable the progress std lib test since it's noisy and uses
   `time.sleep()`.
 * enable/integrate progress printing with the default test runner
2019-10-17 21:55:49 -04:00
Andrew Kelley
299991019d rework the progress module and integrate with stage1 2019-10-17 20:20:22 -04:00
Luna
a73c7bcaf9 add lib/std/progress.zig 2019-10-17 13:32:45 -04:00
Andrew Kelley
17aa8c3ee2 Merge branch 'musl-1.1.24'
closes #3463
2019-10-17 13:20:51 -04:00
Andrew Kelley
2aec35525d mipsel: fix padding on stat struct 2019-10-17 13:20:30 -04:00
Andrew Kelley
88b9579488 update musl src to v1.1.24 2019-10-17 11:55:43 -04:00
Andrew Kelley
1135c9523b update musl headers to v1.1.24 2019-10-17 11:47:57 -04:00
Andrew Kelley
0cb1c1696f Merge pull request #3467 from ziglang/windows-static-linking
Fully static stage1 compiler on windows
2019-10-16 23:35:07 -04:00
Andrew Kelley
93295f3b13 remove -DZIG_FORCE_EXTERNAL_LLD=ON
Looks like the patch we need is in llvm trunk, not llvm 9.
2019-10-16 21:16:06 -04:00
Andrew Kelley
f80c01f9d8 ref more math decls for better docs 2019-10-16 19:16:57 -04:00
Andrew Kelley
c03dc6665f update CI script for windows static builds 2019-10-16 19:08:41 -04:00
Sahnvour
63ecded3ce msvc: reduce inlining aggressivity to workaround a codegen bug in cl.exe cf. #3024 2019-10-16 19:04:50 -04:00
Sahnvour
5b51f41cee stage1: override cmake's default compilation flags to statically link the CRT on windows
we want to use /MT instead of /MD for a fully static executable
2019-10-16 19:04:50 -04:00
Rocknest
40d53a7bc5 Merge branch 'master' into docs-local 2019-10-17 01:57:29 +03:00
Rocknest
c95a9e9785 Cleanup 2019-10-17 01:54:39 +03:00
Rocknest
1c5dfaaca9 Changes from master 2019-10-17 01:35:10 +03:00
Andrew Kelley
7598a579ff turn comments into doc comments 2019-10-16 18:33:12 -04:00
Sebsatian Keller
1b07ff7be0 Add 'missing' consts to math.zig
The C library defines constants for log2e and sqrt2 etc. Those should also be available in zig.
2019-10-16 18:31:22 -04:00
Emeka Nkurumeh
700bb19a90 fix std.mem.AsBytesReturnType (#3442)
closes #3334
2019-10-16 18:15:52 -04:00
Andrew Kelley
45e5841281 Merge pull request #3464 from nrdmn/uefi
UEFI improvements
2019-10-16 18:14:32 -04:00
Andrew Kelley
09abd09ab8 add docs for std.fs.File.updateTimes 2019-10-16 18:13:40 -04:00
LemonBoy
6a549a7f0c Fix compilation of updateTimes on 32bit platforms
Add a test to avoid regressions.

Fixes #3412
2019-10-16 18:10:32 -04:00
Andrew Kelley
5181970807 improve docs and field names of Statx struct 2019-10-16 17:24:42 -04:00
Andrew Kelley
312880f102 Merge pull request #3439 from LemonBoy/statx
Add support for the statx syscall
2019-10-16 17:11:22 -04:00
Andrew Kelley
3af2202ea4 add -I command line parameter, same as clang 2019-10-16 15:51:13 -04:00
Nick Erdmann
e6eae25053 std/os/uefi: add documentation 2019-10-16 21:46:41 +02:00
Andrew Kelley
8cf3a4d586 [breaking] standardize std.os execve functions
* `std.os.execve` had the wrong name; it should have been
   `std.os.execvpe`. This is now corrected.
 * introduce `std.os.execveC` which does not look at PATH, and uses
   null terminated parameters, matching POSIX ABIs. It does not
   require an allocator.
 * fix typo nonsense doc comment in `std.fs.MAX_PATH_BYTES`.
 * introduce `std.os.execvpeC`, which is like `execvpe` except it
   uses null terminated parameters, matching POSIX ABIs, and thus
   does not require an allocator.
 * `std.os.execvpe` implementation is reworked to only convert
   parameters and then delegate to `std.os.execvpeC`.
 * `std.os.execvpeC` improved to handle `ENOTDIR`. See #3415
2019-10-16 15:24:48 -04:00
Nick Erdmann
77104da43e std/os/uefi: add Guid format() 2019-10-16 19:49:51 +02:00
Andrew Kelley
10f6176f3d only look for .defs when needed; remove samsrv.dll cross compiling support
previously zig would look for all the .defs even when not needed,
wasting time. also, we only had samsrv definitions for some architectures.
remove cross compiling support for this.
2019-10-16 13:12:35 -04:00
Andrew Kelley
5bfea3f1ea add more cross compiling support for windows system dlls 2019-10-16 12:43:57 -04:00
Andrew Kelley
f81d9d2c84 add cross compiling support for opengl32.dll 2019-10-16 12:16:35 -04:00
Andrew Kelley
1014cfdf3b generated docs: progress towards generic types being useful
See #3406
2019-10-16 01:49:02 -04:00
Andrew Kelley
47dfaf3d17 merge analysis dumps tool handles errors 2019-10-15 18:40:26 -04:00
Andrew Kelley
c7f994890c Merge branch 'dtw-waleee-fix-help-modal'
closes #3455
2019-10-15 18:38:12 -04:00
Andrew Kelley
e6ca61bdd1 generated docs: further clean up keyboard shortcut handling
now it's harder to introduce a bug when modifying keyboard shortcut
code.
2019-10-15 18:37:24 -04:00
dtw-waleee
725c873e81 fix small misstake, 'escape' v. 'Escape' 2019-10-15 18:19:13 -04:00
dtw-waleee
3e891c9c0b Fix keyboard layout issue with help-modal
Some keyboard layouts produces a different ev.which value in firefox
for ? than 191, eg. the Swedish QWERTY one produces 171. Chrome/chromium
doesn't have this issue.
2019-10-15 18:19:13 -04:00
tgschultz
6a629d3a9f Replaced setTag hack in Deserialize with @unionInit 2019-10-15 18:14:13 -04:00
Andrew Kelley
9050cd847a fix non-byte-aligned packed struct field...
...passed as generic fn parameter causing invalid LLVM IR.

closes #3460
2019-10-15 18:00:16 -04:00
Vexu
7495fd8cb9 fix struct align fmt 2019-10-15 17:58:02 -04:00
Andrew Kelley
f7f3dedb1d Merge pull request #3436 from LemonBoy/unpatch-lld
Assemble lib files using LLVM tools instead of lld
2019-10-13 17:55:36 -04:00
LemonBoy
b164e0ae55 Fix stack iteration stop condition 2019-10-13 17:49:47 -04:00
LemonBoy
230d27c1cd Adapt to clang API additions 2019-10-13 11:08:16 -04:00
Andrew Kelley
9439bf3809 Merge pull request #3446 from LemonBoy/riscv-things-x
More RISC-V stuff
2019-10-13 11:07:39 -04:00
Sahnvour
ae0628b30c ci: use parallel msbuild.exe processes for faster building on windows 2019-10-13 11:02:21 -04:00
LemonBoy
22e60df680 Propagate user-defined function alignment to LLVM IR 2019-10-13 14:19:36 +02:00
LemonBoy
b1f3f59d66 Fix fp-based backtracing on RISC-V
The fp points to the top of the frame instead of pointing to the old fp,
compensate this difference with an offset.
2019-10-13 12:13:41 +02:00
LemonBoy
ba711f1115 Add ELF architecture constant for RISC-V 2019-10-13 12:12:33 +02:00
LemonBoy
ead9630c13 Fix signedness for some fields in ARM stat definition 2019-10-12 20:52:10 +02:00
LemonBoy
40fc7a1fda Add support for the statx syscall 2019-10-12 20:51:51 +02:00
Rocknest
b175468159 Consistent margins 2019-10-12 19:17:35 +03:00
Andrew Kelley
bd3a633e4d Merge pull request #3441 from LemonBoy/llvm10
LLVM 10
2019-10-12 12:10:22 -04:00
LemonBoy
f77b0b90d8 Correctly mangle frameaddress intrinsic name 2019-10-12 16:47:51 +02:00
LemonBoy
3ea0a76fb6 More clang API changes 2019-10-12 16:25:51 +02:00
LemonBoy
fd4c8a40e9 Replace llvm::make_unique with std::make_unique 2019-10-12 16:18:44 +02:00
LemonBoy
6439759298 Add/shuffle several enum members to match Clang's API 2019-10-12 16:15:58 +02:00
LemonBoy
8a36064c96 Replace usage of createDriverOptTable 2019-10-12 15:27:57 +02:00
LemonBoy
935cce2414 Fix lld search path 2019-10-12 15:27:42 +02:00
LemonBoy
60cf3f8a8c Revert LLD patch
The source is now squeaky-clean again.
2019-10-12 10:57:11 +02:00
LemonBoy
2b624fea84 Add dlltool functionality
Don't need no patched lld --kill-at behaviour now.
2019-10-12 10:56:16 +02:00
Andrew Kelley
8b45921664 merge targets of generated docs 2019-10-11 18:14:06 -04:00
Andrew Kelley
30a555eed4 merge dumps tool: merging ast nodes
-fgenerate-docs is replaced ith -femit-docs
-fno-emit-bin is added to prevent outputting binary
2019-10-11 18:13:24 -04:00
LemonBoy
8aa20227ed Fix cross-compilation to i386-windows-msvc
Use Mingw's .def files to build a .lib when possible and show an error
otherwise.
2019-10-11 15:52:55 -04:00
Andrew Kelley
01b2c291d5 miscellaneous improvements to generated docs
* introduce std.json.WriteStream API for writing json
   data to a stream
 * add WIP tools/merge_anal_dumps.zig for merging multiple semantic
   analysis dumps into one. See #3028
 * add std.json.Array, improves generated docs
 * add test for `std.process.argsAlloc`, improves test coverage and
   generated docs
2019-10-10 23:25:40 -04:00
Andrew Kelley
7b20205e68 codegen.cpp: remove unused variable 2019-10-10 21:24:44 -04:00
Andrew Kelley
0e0976828a Merge pull request #3421 from LemonBoy/win32-mingw
Win32 mingw
2019-10-10 21:23:28 -04:00
Rocknest
b0cd64c019 Merge branch 'master' into docs-local 2019-10-11 04:09:01 +03:00
Rocknest
2bb2a2fcea Changes from master 2019-10-11 03:54:03 +03:00
Andrew Kelley
6082c14753 generated docs: add optional type support 2019-10-10 20:32:17 -04:00
Andrew Kelley
fa47172841 better debug info for integers
now we use ABI size * 8 instead of size_in_bits which makes
gdb work instead of hang
2019-10-10 19:22:15 -04:00
Andrew Kelley
bc393eefa1 generated docs: better rendering of unknown decls 2019-10-10 19:21:56 -04:00
Rocknest
352663a34c Merge branch 'master' into docs-local 2019-10-11 01:28:43 +03:00
Rocknest
429d5f2879 Changes from master 2019-10-11 00:48:54 +03:00
Rocknest
238ea85b7e Fix dark mode
Additionally introduces css variables
2019-10-11 00:39:08 +03:00
Andrew Kelley
d15a71afc9 generated docs: clean up type names and param names
closes #3410
2019-10-10 15:42:40 -04:00
LemonBoy
6cbb732b59 Extern unions should not trigger active field check
Fixes #3378
2019-10-10 13:57:48 -04:00
Andrew Kelley
4e81df12c3 generated docs: css: wider tables 2019-10-10 13:40:17 -04:00
Andrew Kelley
57fb550324 Merge branch 'Vexu-docs-union-enum' 2019-10-10 13:36:56 -04:00
Andrew Kelley
78d06ec4af Merge branch 'docs-union-enum' of https://github.com/Vexu/zig into Vexu-docs-union-enum 2019-10-10 13:36:37 -04:00
Rocknest
a34b697c0c Add transtition to search field 2019-10-10 18:55:14 +03:00
Rocknest
f597e0d092 Change layout and styles 2019-10-10 18:03:57 +03:00
Andrew Kelley
6330dfbea6 generated docs: better listing of functions 2019-10-10 11:03:16 -04:00
Andrew Kelley
b9d63551de Merge pull request #3420 from FireFox317/generated-docs-improvements
Generated docs: add parameter names to functions
2019-10-10 10:34:44 -04:00
Michael Dusan
3464351d1e stage1: fix ir_resolve_str() to return slice
`ir_resolve_str()` bug returns array expression even when when sliced
to a lesser length. Fix is to return array if slice.len == array.len,
otherwise return slice.

Bug report use-case is based on one builtin function. However, at least
the following builtins were exposed to the bug:

    `@byteOffsetOf`
    `@cDefine`
    `@cImport`
    `@cInclude`
    `@cUndef`
    `@compileError`
    `@embedFile`
    `@export`
    `@fieldParentPtr`
    `@hasDecl`
    `@hasField`
    `@import`
    `@unionInit`

closes #3384
2019-10-10 10:20:04 -04:00
Michael Dusan
fd94d78ffc cleanup: unused imports in test 2019-10-10 10:16:35 -04:00
Timon Kruiper
e34e3344d4 Generated docs: Add function paramater names 2019-10-10 15:23:24 +02:00
Timon Kruiper
4250d27fe5 Generated docs: store static container info in a containerDecl astNode
And then get the struct field astNodes through the containerDecl astNode.
The type of a struct field is still stored in the types array, but the
static information is in the astNodes.
2019-10-10 14:21:35 +02:00
LemonBoy
4de3f9d853 Fix stack-probe symbol redefinition 2019-10-10 09:38:57 +02:00
LemonBoy
dfcbca8d2f Add i386/mingw to the test rooster 2019-10-10 09:38:57 +02:00
LemonBoy
86e5bbffd7 Patch lld to have a more sensible kill-at implementation
Lift some code from llvm-dlltool, the lld code is meant to follow what
gnu ld does but that's not much useful for our purposes.

Also use the `--kill-at` option when generating the .lib files out of
mingw's .def files: this way our building process closely matches the
one use by the upstream and now finally generates files that allow both
C code and Zig code to link.
2019-10-10 09:38:57 +02:00
Vexu
2b55484f3f implement doc generation for union and enum 2019-10-10 10:27:12 +03:00
Andrew Kelley
12ed85d0d1 generated docs: better handle when root is std 2019-10-10 01:38:20 -04:00
Andrew Kelley
510b6443ba generated docs: avoid clobbering browser shortcut keys 2019-10-09 18:28:50 -04:00
Andrew Kelley
000a1df4a3 generated docs: add array type support
See #3404
2019-10-09 18:22:46 -04:00
Andrew Kelley
6d54e8fc3c generated docs: render values
also fix pressing enter in search box before search finishes

closes #3409
2019-10-09 18:09:35 -04:00
Andrew Kelley
13ae7d47b7 generated docs: refactor how type kinds work 2019-10-09 18:09:35 -04:00
Michael Dusan
42f2814d9a stage1: fix root top-level-struct typename
- during diagnostics the string representation for root was empty
  and now is `(root)`
- retrofitted all other namespace-qualified type naming to elide
  prefixing with root

closes #2032
2019-10-09 17:36:13 -04:00
LemonBoy
c9a3c945db Add a bunch of mingw lib32 .def files
Possibly incomplete, but enough to let the test suite compile & pass.
2019-10-09 22:44:36 +02:00
LemonBoy
b96fa89462 Compile the architecture-specific mingw sources 2019-10-09 22:44:36 +02:00
LemonBoy
9ae293ae3b Remove x86/Windows name mangling hack
Let's fix this properly by generating the correct lib files from the
mingw sources.
2019-10-09 22:44:36 +02:00
LemonBoy
f83bb3dd9e Fix compilation w/ clang
Clang pretends to be gcc 4.4 and that causes some re-definition errors.
The problem has been reported to the upstream some time ago but nothing
was done about it.
2019-10-09 22:44:35 +02:00
LemonBoy
a4b3e695af Shuffle around some stack-probing functions 2019-10-09 22:44:35 +02:00
Andrew Kelley
e0ab685467 generated docs: more verbose fields
also prevent docs making hyperlinks for integer types
2019-10-09 16:31:20 -04:00
Andrew Kelley
8d5e3a2f33 generated docs: separate section for namespaces
if a type is a struct with no fields, then it goes in the namespaces
section.
2019-10-09 15:52:55 -04:00
Andrew Kelley
c4e4fa2287 zig build: bump default max exec output size to 400 KB
closes #3415
2019-10-09 15:24:15 -04:00
Andrew Kelley
3ce83e879b generated docs: show error sets pages
also favicon, improve error sets css, syntax awareness of
noreturn
2019-10-09 15:23:13 -04:00
Andrew Kelley
a5714ddb97 add comments about why we choose pentium4 for i386 target
See #3389
2019-10-09 15:06:37 -04:00
Andrew Kelley
2286003666 improve names of error sets when using merge error sets operator 2019-10-09 13:35:19 -04:00
Timon Kruiper
8a547d9e81 Docs: adds docs comments to struct fields 2019-10-09 13:27:06 -04:00
Andrew Kelley
406b70aa56 Merge pull request #3390 from nrdmn/unicode_character_literals
unicode character literals
2019-10-09 13:25:41 -04:00
Andrew Kelley
f929a58d5f Merge pull request #3389 from LemonBoy/win32
Win32
2019-10-09 13:22:16 -04:00
Alva
0fc97015e2 Correct std.os.connect_async docs 2019-10-09 13:15:39 -04:00
Andrew Kelley
48f5b21e7c generated docs: functions in a table with descriptions 2019-10-09 00:24:58 -04:00
Andrew Kelley
71fb4ef8da generated docs: separate Error Sets from Types 2019-10-08 23:33:19 -04:00
Andrew Kelley
1586f244c4 generated docs: render var decls 2019-10-08 23:24:50 -04:00
Andrew Kelley
5e765356a7 generated docs: global vars in a table 2019-10-08 23:15:47 -04:00
Andrew Kelley
ca3250a57c generated docs: add global variables
See #3409
2019-10-08 22:39:12 -04:00
Andrew Kelley
cdaaf7c725 generated docs: consistent coloring 2019-10-08 19:04:35 -04:00
Andrew Kelley
e0f0e2aace generated docs: error sets in fn docs 2019-10-08 18:09:08 -04:00
Timon Kruiper
f74c29b49a Add initial support for struct fields in the docs 2019-10-08 17:29:03 -04:00
Christine Dodrill
1e59eb3c94 src/main: minor grammar fix in the help for zig builtin 2019-10-08 15:14:10 -04:00
Andrew Kelley
784a493dc7 generated docs: functions with inferred error sets display nicely
infrastructure in place for displaying error sets
2019-10-08 13:41:13 -04:00
Andrew Kelley
03a6b33a73 generated docs: bool type and fix error for some fns 2019-10-08 11:59:55 -04:00
Andrew Kelley
6814d6b332 generated docs: function parameters have links 2019-10-08 11:52:06 -04:00
Andrew Kelley
a55db08a7b generated docs contain generic instantiations and comptime calls 2019-10-08 00:15:16 -04:00
Andrew Kelley
ffc0c26b27 generated docs: highlight active package 2019-10-08 00:15:16 -04:00
Andrew Kelley
2e26aaa70c generated docs: prioritized sort ranking 2019-10-08 00:15:14 -04:00
Andrew Kelley
7688100b17 stage1: enable PIC for libuserland
we don't really have a way to determine whether the stage1
zig compiler requires PIC so to be safe we always enable it
when building libuserland.

fixes build on some configurations of alpine linux.
2019-10-08 00:06:28 -04:00
Andrew Kelley
15471531d0 generated docs: sort search results 2019-10-07 18:17:06 -04:00
Andrew Kelley
478e53911d generated docs: smart ignore case 2019-10-07 18:12:28 -04:00
Andrew Kelley
9df0d53981 generated docs: search cleanup 2019-10-07 18:00:01 -04:00
Andrew Kelley
4a97558ae8 generated docs: navigable search results 2019-10-07 17:46:22 -04:00
Andrew Kelley
d46234ef72 generated docs: keyboard shortcuts modal 2019-10-07 15:41:45 -04:00
Andrew Kelley
16de5a7228 generated docs: fix search stuff 2019-10-07 14:47:59 -04:00
Andrew Kelley
d70c30055e generated docs: better navigation 2019-10-07 14:29:01 -04:00
Andrew Kelley
9237461b24 generated docs: logo and basic search proof of concept 2019-10-07 13:57:01 -04:00
Andrew Kelley
2ccb48ddc3 generated docs: show doc comments on functions 2019-10-07 12:21:11 -04:00
Andrew Kelley
85b8854c41 move doc/ to docs/
fixes regression caused by 86171afb9b
2019-10-07 11:31:47 -04:00
Nick Erdmann
ae7392e504 unicode character literals 2019-10-07 08:18:16 +02:00
Matt Keeter
e706cc24f0 Fix typo in docs 2019-10-07 02:03:57 -04:00
Andrew Kelley
8e2c441b2e stage1 parser supports doc comments 2019-10-06 16:39:27 -04:00
Andrew Kelley
86171afb9b generated docs: docs/ instead of doc/
This appears to be more of a standard directory name.

See #21
2019-10-06 14:48:01 -04:00
LemonBoy
6a687bda76 Support for TLS on Win32 2019-10-06 16:45:51 +02:00
LemonBoy
93a49076f7 Initial support for i386-windows-msvc target 2019-10-06 14:27:36 +02:00
Andrew Kelley
571123465b generated docs: canonical package paths 2019-10-05 18:01:01 -04:00
Andrew Kelley
0e40fc46d1 generated docs: show public stuff only 2019-10-05 16:38:42 -04:00
Andrew Kelley
19c2474b34 generated docs: render functions 2019-10-05 16:38:42 -04:00
Michael Dusan
a82c6453c1 Merge pull request #3368 from mikdusan/issue.3367
fix: container member access `usingnamespace` decls fails
2019-10-05 15:47:07 -04:00
Andrew Kelley
edadccde54 generated docs: add navigation bar 2019-10-05 15:33:23 -04:00
Michael Dusan
a23a022820 fix container member access for fn/struct-fn
- decls brought in via `usingnamespace` were not always found
  because lookup was performed directly against decl_table and
  use_decls was never consulted
- fix to use find_container_decl() path instead
- closes #3367
2019-10-05 14:09:09 -04:00
Andrew Kelley
5aa1e78807 generated docs: navigable types 2019-10-05 13:29:35 -04:00
Andrew Kelley
f78d49c916 generated docs: navigable packages 2019-10-05 13:07:59 -04:00
Andrew Kelley
dca6e74fec proof of concept of stage1 doc generation
This commit adds `-fgenerate-docs` CLI option, and it outputs:
 * doc/index.html
 * doc/data.js
 * doc/main.js

In this strategy, we have 1 static html page and 1 static javascript
file, which loads the semantic analysis dump directly and renders it
using dom manipulation.

Currently, all it does is list the declarations. But there is a lot more
data available to work with. The next step would be making the
declarations hyperlinks, and handling page navigation.

Another strategy would be to generate a static site with no javascript,
based on the semantic analysis dump that zig now provides. I invite the
Zig community to take on such a project. However this version which
heavily relies on javascript will also be a direction explored.

I also welcome contributors to improve the html, css, and javascript of
what this commit started, as well as whatever improvements are necessary
to the static analysis dumping code to provide more information.

See #21.
2019-10-04 20:18:06 -04:00
Andrew Kelley
2f4dad04e0 langref: no viewport 2019-10-04 14:06:55 -04:00
Michael Dusan
81c6bd37aa stage1: fix compile error on macOS Xcode 11.1 2019-10-04 01:33:31 -04:00
Andrew Kelley
071af5c1d6 fix noreturn attribute for msvc 2019-10-03 22:51:00 -04:00
Andrew Kelley
eca2aa66fe Merge pull request #3372 from ziglang/dump-analysis
add -fdump-analysis to dump type information to json
2019-10-03 18:37:30 -04:00
Andrew Kelley
39d47b2c51 handle when std lib is unused 2019-10-03 18:05:44 -04:00
Andrew Kelley
59ac7b91da add -fdump-analysis to dump type information to json
This commit adds -fdump-analysis which creates
a `$NAME-analysis.json` file with all of the finished
semantic analysis that the stage1 compiler produced.
It contains types, packages, declarations, and files.

This is an initial implementation; some data will be
missing. However it's easy to improve the implementation,
which is in `src/dump_analysis.cpp`.

The next step for #21 will be to create Zig code which parses
this json file and creates user-facing HTML documentation.

This feature has other uses, however; for example, it could
be used for IDE integration features until the self-hosted
compiler is available.
2019-10-03 17:58:22 -04:00
LemonBoy
7640bec8e0 Fix pipe syscall for MIPS 2019-10-03 17:07:53 -04:00
Andrew Kelley
7481a4ad08 zig build: fix exe file ext to match target.cpp 2019-10-03 16:02:24 -04:00
Andrew Kelley
edef35bb57 docs: use the updated png favicon 2019-10-03 11:15:55 -04:00
Andrew Kelley
a7c9aa7ddb finish conversion of translate_c.cpp to use zig_clang.h
See #1964

translate_c.cpp now exclusively uses the clang API via zig_clang.h

shaves off 5 seconds from building zig when translate_c.cpp
(or any h files it uses) change.
2019-10-02 19:21:40 -04:00
Andrew Kelley
ce56ae8afe we have to use c++14 now for llvm10 2019-10-02 13:05:10 -04:00
Andrew Kelley
6f10e3fda6 llvm 9.0.0 => llvm 10.0.0 2019-10-02 02:11:46 -04:00
Andrew Kelley
f84086132f more conversion of translate_c.cpp to use zig_clang.h
Progress: 96%

See #1964
2019-10-02 02:02:31 -04:00
Andrew Kelley
a8d6954c23 fix tripping LLVM assertion in const unions 2019-10-01 17:41:03 -04:00
Andrew Kelley
c1a05f0581 translate-c: make trans_implicit_cast_expr use zig_clang.h
See #1964
2019-10-01 17:33:11 -04:00
LemonBoy
17f2af10b5 Correct signal bits for MIPS
Also enable the segfault handler for all the supported architectures
beside MIPS.
2019-10-01 13:58:58 -04:00
SamTebbs33
bed4bfa69a Replace code occurences of --override-std-dir with --override-lib-dir 2019-10-01 07:29:24 -04:00
Andrew Kelley
5026db1d31 langref: add 0.5.0 docs link 2019-09-30 12:13:51 -04:00
11285 changed files with 1181227 additions and 632119 deletions

View File

@@ -1,10 +1,7 @@
image: freebsd/latest
packages:
- cmake
- py27-s3cmd
- wget
secrets:
- 6c60aaee-92e7-4e7d-812c-114817689b4d
- 51bfddf5-86a6-4e01-8576-358c72a4a0a4
- 5cfede76-914e-4071-893e-e5e2e6ae3cea
sources:
- https://github.com/ziglang/zig
tasks:

21
.gitattributes vendored
View File

@@ -1,9 +1,12 @@
*.zig text eol=lf
*.txt text eol=lf
langref.html.in text eol=lf
deps/* linguist-vendored
lib/include/* linguist-vendored
lib/libc/* linguist-vendored
lib/libcxx/* linguist-vendored
lib/libunwind/* linguist-vendored
*.zig text eol=lf
*.txt text eol=lf
langref.html.in text eol=lf
deps/SoftFloat-3e/*.txt text eol=crlf
deps/** linguist-vendored
lib/include/** linguist-vendored
lib/libc/** linguist-vendored
lib/libcxx/** linguist-vendored
lib/libcxxabi/** linguist-vendored
lib/libunwind/** linguist-vendored
lib/tsan/** linguist-vendored

2
.github/FUNDING.yml vendored
View File

@@ -1 +1 @@
github: [andrewrk]
github: [ziglang]

3
.gitignore vendored
View File

@@ -10,6 +10,9 @@
# -andrewrk
zig-cache/
zig-out/
/release/
/debug/
/build/
/build-*/
/docgen_tmp/

File diff suppressed because it is too large Load Diff

75
CODE_OF_CONDUCT.md Normal file
View File

@@ -0,0 +1,75 @@
# Code of Conduct
Hello, and welcome! 👋
The Zig community is decentralized. Anyone is free to start and maintain their
own space for people to gather, and edit
[the Community wiki page](https://github.com/ziglang/zig/wiki/Community) to add
a link. There is no concept of "official" or "unofficial", however, each
gathering place has its own moderators and rules.
This is Andrew Kelley speaking. At least for now, I'm the moderator of the
ziglang organization GitHub repositories and the #zig IRC channel on Libera.chat.
**This document contains the rules that govern these two spaces only**.
The rules here are strict. This space is for focused, on topic, technical work
on the Zig project only. It is everyone's responsibility to maintain a positive
environment, especially when disagreements occur.
## Our Standards
Examples of behavior that contribute to creating a positive environment include:
* Using welcoming and inclusive language.
* Being respectful of differing viewpoints and experiences.
* Gracefully accepting constructive criticism.
* Helping another person accomplish their own goals.
* Showing empathy towards others.
* Showing appreciation for others' work.
* Validating someone else's experience, skills, insight, and use cases.
Examples of unacceptable behavior by participants include:
* Unwelcome sexual attention or advances, or use of sexualized language or
imagery that causes discomfort.
* Trolling, insulting/derogatory comments, and personal attacks. Anything
antagonistic towards someone else.
* Off-topic discussion of any kind - especially offensive or sensitive issues.
* Publishing others' private information, such as a physical or electronic
address, without explicit permission.
* Discussing this Code of Conduct or publicly accusing someone of violating it.
* Making someone else feel like an outsider or implying a lack of technical
abilities.
* Destructive behavior. Anything that harms Zig or another open-source project.
## Enforcement
If you need to report an issue you can contact me or Loris Cro, who are both
paid by the Zig Software Foundation, and so moderation of this space is part of
our job. We will swiftly remove anyone who is antagonizing others or being
generally destructive.
This includes Private Harassment. If person A is directly harassed or
antagonized by person B, person B will be blocked from participating in this
space even if the harassment didn't take place on one of the mediums directly
under rule of this Code of Conduct.
As noted, discussing this Code of Conduct should not take place on GitHub or IRC
because these spaces are for directly working on code, not for meta-discussion.
If you have any issues with it, you can contact me directly, or you can join one
of the community spaces that has different rules.
* Andrew Kelley <andrew@ziglang.org>
* Loris Cro <loris@ziglang.org>
## Conclusion
Thanks for reading the rules. Together, we can make this space welcoming and
inclusive for everyone, regardless of age, body size, disability, ethnicity,
sex characteristics, gender identity and expression, level of experience,
education, socio-economic status, nationality, personal appearance, race,
religion, or sexual identity and orientation.
Sincerely,
Andrew ✌️

View File

@@ -7,7 +7,10 @@ personal project. Here are some great examples:
* [Oxid](https://github.com/dbandstra/oxid) - arcade style game
* [TM35-Metronome](https://github.com/TM35-Metronome) - tools for modifying and randomizing Pokémon games
* [trOS](https://github.com/sjdh02/trOS) - tiny aarch64 baremetal OS thingy
* [River](https://github.com/ifreund/river/) - a dynamic tiling wayland compositor
More examples can be found on the
[Community Projects Wiki](https://github.com/ziglang/zig/wiki/Community-Projects).
Without fail, these projects lead to discovering bugs and helping flesh out use
cases, which lead to further design iterations of Zig. Importantly, each issue
@@ -51,23 +54,29 @@ knowledge of Zig internals.**
### Editing Source Code
First, build the Stage 1 compiler as described in [the Building section](#building).
First, build the Stage 1 compiler as described in
[Building Zig From Source](https://github.com/ziglang/zig/wiki/Building-Zig-From-Source).
One modification you may want to make is adding `-DZIG_SKIP_INSTALL_LIB_FILES=ON`
to the cmake line. If you use the build directory as a working directory to run
tests with, zig will find the lib files in the source directory, and they will not
be "installed" every time you run `make`. This will allow you to make modifications
directly to the standard library, for example, and have them effective immediately.
Note that if you already ran `make` or `make install` with the default cmake
settings, there will already be a `lib/` directory in your build directory. When
executed from the build directory, zig will find this instead of the source lib/
directory. Remove the unwanted directory so that the desired one can be found.
Zig locates lib files relative to executable path by searching up the
filesystem tree for a sub-path of `lib/zig/std/std.zig` or `lib/std/std.zig`.
Typically the former is an install and the latter a git working tree which
contains the build directory.
During development it is not necessary to perform installs when modifying
stage1 or userland sources and in fact it is faster and simpler to run,
test and debug from a git working tree.
- `make` is typically sufficient to build zig during development iterations.
- `make install` performs a build __and__ install.
- `msbuild -p:Configuration=Release INSTALL.vcxproj` on Windows performs a
build and install. To avoid install, pass cmake option `-DZIG_SKIP_INSTALL_LIB_FILES=ON`.
To test changes, do the following from the build directory:
1. Run `make install` (on POSIX) or
1. Run `make` (on POSIX) or
`msbuild -p:Configuration=Release INSTALL.vcxproj` (on Windows).
2. `bin/zig build test` (on POSIX) or `bin\zig.exe build test` (on Windows).
2. `$BUILD_DIR/zig build test` (on POSIX) or
`$BUILD_DIR/Release\zig.exe build test` (on Windows).
That runs the whole test suite, which does a lot of extra testing that you
likely won't always need, and can take upwards of 1 hour. This is what the
@@ -85,8 +94,8 @@ Another example is choosing a different set of things to test. For example,
not the other ones. Combining this suggestion with the previous one, you could
do this:
`bin/zig build test-std -Dskip-release` (on POSIX) or
`bin\zig.exe build test-std -Dskip-release` (on Windows).
`$BUILD_DIR/bin/zig build test-std -Dskip-release` (on POSIX) or
`$BUILD_DIR/Release\zig.exe build test-std -Dskip-release` (on Windows).
This will run only the standard library tests, in debug mode only, for all
targets (it will cross-compile the tests for non-native targets but not run
@@ -123,3 +132,74 @@ When developing on Linux, another option is available to you: `-Denable-wine`.
This will enable running behavior tests and std lib tests with Wine. It's
recommended for Linux users to install Wine and enable this testing option
when editing the standard library or anything Windows-related.
#### Testing WebAssembly using wasmtime
If you have [wasmtime](https://wasmtime.dev/) installed, take advantage of the
`-Denable-wasmtime` flag which will enable running WASI behavior tests and std
lib tests. It's recommended for all users to install wasmtime and enable this
testing option when editing the standard library and especially anything
WebAssembly-related.
#### Improving Translate-C
Please read the [Editing Source Code](#editing-source-code) section as a
prerequisite to this one.
`translate-c` is a feature provided by Zig that converts C source code into
Zig source code. It powers the `zig translate-c` command as well as
[@cImport](https://ziglang.org/documentation/master/#cImport), allowing Zig
code to not only take advantage of function prototypes defined in .h files,
but also `static inline` functions written in C, and even some macros.
This feature works by using libclang API to parse and semantically analyze
C/C++ files, and then based on the provided AST and type information,
generating Zig AST, and finally using the mechanisms of `zig fmt` to render
the Zig AST to a file.
The relevant tests for this feature are:
* `test/run_translated_c.zig` - each test case is C code with a `main` function. The C code
is translated into Zig code, compiled, and run, and tests that the expected output is the
same, and that the program exits cleanly. This kind of test coverage is preferred, when
possible, because it makes sure that the resulting Zig code is actually viable.
* `test/stage1/behavior/translate_c_macros.zig` - each test case consists of a Zig test
which checks that the relevant macros in `test/stage1/behavior/translate_c_macros.h`.
have the correct values. Macros have to be tested separately since they are expanded by
Clang in `run_translated_c` tests.
* `test/translate_c.zig` - each test case is C code, with a list of expected strings which
must be found in the resulting Zig code. This kind of test is more precise in what it
measures, but does not provide test coverage of whether the resulting Zig code is valid.
This feature is self-hosted, even though Zig is not fully self-hosted yet. In the Zig source
repo, we maintain a C API on top of Clang's C++ API:
* `src/zig_clang.h` - the C API that we maintain on top of Clang's C++ API. This
file does not include any Clang's C++ headers. Instead, C types and C enums are defined
here.
* `src/zig_clang.cpp` - a lightweight wrapper that fulfills the C API on top of the
C++ API. It takes advantage of `static_assert` to make sure we get compile errors when
Clang's C++ API changes. This one file necessarily does include Clang's C++ headers, which
makes it the slowest-to-compile source file in all of Zig's codebase.
* `src/clang.zig` - the Zig equivalent of `src/zig_clang.h`. This is a manually
maintained list of types and functions that are ABI-compatible with the Clang C API we
maintain. In theory this could be generated by running translate-c on `src/zig_clang.h`,
but that would introduce a dependency cycle, since we are using this file to implement
translate-c.
Finally, the actual source code for the translate-c feature is
`src/translate_c.zig`. This code uses the Clang C API exposed by
`src/clang.zig`, and produces Zig AST.
The steps for contributing to translate-c look like this:
1. Identify a test case you want to improve. Add it as a run-translated-c test
case (usually preferable), or as a translate-c test case.
2. Edit `src/translate_c.zig` to improve the behavior.
3. Run the relevant tests: `./zig build test-run-translated-c test-translate-c`

View File

@@ -1,6 +1,6 @@
The MIT License (Expat)
Copyright (c) 2015 Andrew Kelley
Copyright (c) 2015-2021, Zig contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal

112
README.md
View File

@@ -1,104 +1,44 @@
![ZIG](https://ziglang.org/zig-logo.svg)
A general-purpose programming language designed for **robustness**,
**optimality**, and **maintainability**.
A general-purpose programming language and toolchain for maintaining
**robust**, **optimal**, and **reusable** software.
## Resources
* [Introduction](https://ziglang.org/#Introduction)
* [Introduction](https://ziglang.org/learn/#introduction)
* [Download & Documentation](https://ziglang.org/download)
* [Chapter 0 - Getting Started | ZigLearn.org](https://ziglearn.org/)
* [Community](https://github.com/ziglang/zig/wiki/Community)
* [Contributing](https://github.com/ziglang/zig/blob/master/CONTRIBUTING.md)
* [Code of Conduct](https://github.com/ziglang/zig/blob/master/CODE_OF_CONDUCT.md)
* [Frequently Asked Questions](https://github.com/ziglang/zig/wiki/FAQ)
* [Community Projects](https://github.com/ziglang/zig/wiki/Community-Projects)
## Building from Source
## Installation
[![Build Status](https://dev.azure.com/ziglang/zig/_apis/build/status/ziglang.zig?branchName=master)](https://dev.azure.com/ziglang/zig/_build/latest?definitionId=1&branchName=master)
* [download a pre-built binary](https://ziglang.org/download/)
* [install from a package manager](https://github.com/ziglang/zig/wiki/Install-Zig-from-a-Package-Manager)
* [build from source](https://github.com/ziglang/zig/wiki/Building-Zig-From-Source)
* [bootstrap zig for any target](https://github.com/ziglang/zig-bootstrap)
Note that you can
[download a binary of master branch](https://ziglang.org/download/#release-master).
## License
### Stage 1: Build Zig from C++ Source Code
The ultimate goal of the Zig project is to serve users. As a first-order
effect, this means users of the compiler, helping programmers to write better
software. Even more important, however, are the end-users.
#### Dependencies
Zig is intended to be used to help **end-users** accomplish their goals. Zig
should be used to empower end-users, never to exploit them financially, or to
limit their freedom to interact with hardware or software in any way.
##### POSIX
However, such problems are best solved with social norms, not with software
licenses. Any attempt to complicate the software license of Zig would risk
compromising the value Zig provides.
* cmake >= 2.8.5
* gcc >= 5.0.0 or clang >= 3.6.0
* LLVM, Clang, LLD development libraries == 9.x, compiled with the same gcc or clang version above
- Use the system package manager, or [build from source](https://github.com/ziglang/zig/wiki/How-to-build-LLVM,-libclang,-and-liblld-from-source#posix).
Therefore, Zig is available under the MIT (Expat) License, and comes with a
humble request: use it to make software better serve the needs of end-users.
##### Windows
* cmake >= 3.15.3
* Microsoft Visual Studio. Supported versions:
- 2015 (version 14)
- 2017 (version 15.8)
- 2019 (version 16)
* LLVM, Clang, LLD development libraries == 9.x
- Use the [pre-built binaries](https://github.com/ziglang/zig/wiki/Building-Zig-on-Windows) or [build from source](https://github.com/ziglang/zig/wiki/How-to-build-LLVM,-libclang,-and-liblld-from-source#windows).
#### Instructions
##### POSIX
```
mkdir build
cd build
cmake ..
make install
```
##### MacOS
```
brew install cmake llvm@9
brew outdated llvm@9 || brew upgrade llvm@9
mkdir build
cd build
cmake .. -DCMAKE_PREFIX_PATH=$(brew --prefix llvm)
make install
```
##### Windows
See https://github.com/ziglang/zig/wiki/Building-Zig-on-Windows
### Stage 2: Build Self-Hosted Zig from Zig Source Code
*Note: Stage 2 compiler is not complete. Beta users of Zig should use the
Stage 1 compiler for now.*
Dependencies are the same as Stage 1, except now you can use stage 1 to compile
Zig code.
```
bin/zig build --prefix $(pwd)/stage2
```
This produces `./stage2/bin/zig` which can be used for testing and development.
Once it is feature complete, it will be used to build stage 3 - the final compiler
binary.
### Stage 3: Rebuild Self-Hosted Zig Using the Self-Hosted Compiler
*Note: Stage 2 compiler is not yet able to build Stage 3. Building Stage 3 is
not yet supported.*
Once the self-hosted compiler can build itself, this will be the actual
compiler binary that we will install to the system. Until then, users should
use stage 1.
#### Debug / Development Build
```
./stage2/bin/zig build --prefix $(pwd)/stage3
```
#### Release / Install Build
```
./stage2/bin/zig build install -Drelease
```
This project redistributes code from other projects, some of which have other
licenses besides MIT. Such licenses are generally similar to the MIT license
for practical purposes. See the subdirectories and files inside lib/ for more
details.

1126
build.zig

File diff suppressed because it is too large Load Diff

View File

@@ -3,35 +3,108 @@
set -x
set -e
BUILDDIR="$(pwd)"
sudo sh -c 'echo "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-9 main" >> /etc/apt/sources.list'
wget -O - http://apt.llvm.org/llvm-snapshot.gpg.key|sudo apt-key add -
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
sudo apt-get update -q
sudo apt-get install -y cmake s3cmd tidy
sudo apt-get remove -y llvm-*
sudo rm -rf /usr/local/*
sudo apt-get install -y libxml2-dev libclang-9-dev llvm-9 llvm-9-dev cmake s3cmd gcc-7 g++-7 qemu
ZIGDIR="$(pwd)"
ARCH="$(uname -m)"
TARGET="$ARCH-linux-musl"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.8.1-dev.94+535615117"
PREFIX="$HOME/$CACHE_BASENAME"
MCPU="baseline"
JOBS="-j$(nproc)"
rm -rf $PREFIX
cd $HOME
wget -nv "https://ziglang.org/deps/$CACHE_BASENAME.tar.xz"
tar xf "$CACHE_BASENAME.tar.xz"
QEMUBASE="qemu-linux-x86_64-5.2.0.1"
wget -nv "https://ziglang.org/deps/$QEMUBASE.tar.xz"
tar xf "$QEMUBASE.tar.xz"
export PATH="$(pwd)/$QEMUBASE/bin:$PATH"
# Bump to v0.23 once this issue is resolved:
# https://github.com/ziglang/zig/issues/8742
WASMTIME="wasmtime-v0.22.1-x86_64-linux"
wget -nv "https://github.com/bytecodealliance/wasmtime/releases/download/v0.22.1/$WASMTIME.tar.xz"
tar xf "$WASMTIME.tar.xz"
export PATH="$(pwd)/$WASMTIME:$PATH"
ZIG="$PREFIX/bin/zig"
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
cd $ZIGDIR
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git config core.abbrev 9
git fetch --unshallow || true
git fetch --tags
export CC=gcc-7
export CXX=g++-7
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release
make -j2 install
./zig build test -Denable-qemu
cmake .. \
-DCMAKE_INSTALL_PREFIX="$(pwd)/release" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
make $JOBS install
# Here we rebuild zig but this time using the Zig binary we just now produced to
# build zig1.o rather than relying on the one built with stage0. See
# https://github.com/ziglang/zig/issues/6830 for more details.
cmake .. -DZIG_EXECUTABLE="$(pwd)/release/bin/zig"
make $JOBS install
for step in test-toolchain test-std docs; do
release/bin/zig build $step -Denable-qemu -Denable-wasmtime
done
# Look for HTML errors.
tidy -qe ../zig-cache/langref.html
if [ "${BUILD_REASON}" != "PullRequest" ]; then
ARTIFACTSDIR="$BUILDDIR/artifacts"
mkdir "$ARTIFACTSDIR"
docker run -i --mount type=bind,source="$ARTIFACTSDIR",target=/z ziglang/static-base:llvm9-1 -j2 $BUILD_SOURCEVERSION
TARBALL="$(ls $ARTIFACTSDIR)"
mv "$DOWNLOADSECUREFILE_SECUREFILEPATH" "$HOME/.s3cfg"
s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$ARTIFACTSDIR/$TARBALL" s3://ziglang.org/builds/
# Produce the experimental std lib documentation.
mkdir -p release/docs/std
release/bin/zig test ../lib/std/std.zig \
--override-lib-dir ../lib \
-femit-docs=release/docs/std \
-fno-emit-bin
SHASUM=$(sha256sum $ARTIFACTSDIR/$TARBALL | cut '-d ' -f1)
BYTESIZE=$(wc -c < $ARTIFACTSDIR/$TARBALL)
mv ../LICENSE release/
mv ../zig-cache/langref.html release/docs/
# Remove the unnecessary bin dir in $prefix/bin/zig
mv release/bin/zig release/
rmdir release/bin
# Remove the unnecessary zig dir in $prefix/lib/zig/std/std.zig
mv release/lib/zig release/lib2
rmdir release/lib
mv release/lib2 release/lib
VERSION=$(release/zig version)
DIRNAME="zig-linux-$ARCH-$VERSION"
TARBALL="$DIRNAME.tar.xz"
mv release "$DIRNAME"
tar cfJ "$TARBALL" "$DIRNAME"
mv "$DOWNLOADSECUREFILE_SECUREFILEPATH" "$HOME/.s3cfg"
s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$TARBALL" s3://ziglang.org/builds/
SHASUM=$(sha256sum $TARBALL | cut '-d ' -f1)
BYTESIZE=$(wc -c < $TARBALL)
JSONFILE="linux-$GITBRANCH.json"
touch $JSONFILE
@@ -40,7 +113,7 @@ if [ "${BUILD_REASON}" != "PullRequest" ]; then
echo "\"size\": \"$BYTESIZE\"}" >>$JSONFILE
s3cmd put -P --add-header="Cache-Control: max-age=0, must-revalidate" "$JSONFILE" "s3://ziglang.org/builds/$JSONFILE"
s3cmd put -P "$JSONFILE" "s3://ziglang.org/builds/linux-$VERSION.json"
s3cmd put -P "$JSONFILE" "s3://ziglang.org/builds/$ARCH-linux-$VERSION.json"
# `set -x` causes these variables to be mangled.
# See https://developercommunity.visualstudio.com/content/problem/375679/pipeline-variable-incorrectly-inserts-single-quote.html
@@ -48,4 +121,5 @@ if [ "${BUILD_REASON}" != "PullRequest" ]; then
echo "##vso[task.setvariable variable=tarball;isOutput=true]$TARBALL"
echo "##vso[task.setvariable variable=shasum;isOutput=true]$SHASUM"
echo "##vso[task.setvariable variable=bytesize;isOutput=true]$BYTESIZE"
echo "##vso[task.setvariable variable=version;isOutput=true]$VERSION"
fi

131
ci/azure/macos_arm64_script Executable file
View File

@@ -0,0 +1,131 @@
#!/bin/sh
set -x
set -e
brew update && brew install s3cmd
ZIGDIR="$(pwd)"
HOST_ARCH="x86_64"
HOST_TARGET="$HOST_ARCH-macos-gnu"
HOST_MCPU="baseline"
HOST_CACHE_BASENAME="zig+llvm+lld+clang-$HOST_TARGET-0.8.0-dev.2703+c12704a33"
HOST_PREFIX="$HOME/$HOST_CACHE_BASENAME"
ARCH="aarch64"
TARGET="$ARCH-macos-gnu"
MCPU="apple_a14"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.8.0-dev.2703+c12704a33"
PREFIX="$HOME/$CACHE_BASENAME"
JOBS="-j2"
rm -rf $HOST_PREFIX $PREFIX
cd $HOME
wget -nv "https://ziglang.org/deps/$HOST_CACHE_BASENAME.tar.xz"
wget -nv "https://ziglang.org/deps/$CACHE_BASENAME.tar.xz"
tar xf "$HOST_CACHE_BASENAME.tar.xz"
tar xf "$CACHE_BASENAME.tar.xz"
cd $ZIGDIR
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git config core.abbrev 9
git fetch --unshallow || true
git fetch --tags
# Build host zig compiler in debug so that we can get the
# current version when packaging
ZIG="$HOST_PREFIX/bin/zig"
export CC="$ZIG cc -target $HOST_TARGET -mcpu=$HOST_MCPU"
export CXX="$ZIG c++ -target $HOST_TARGET -mcpu=$HOST_MCPU"
mkdir build.host
cd build.host
cmake .. \
-DCMAKE_INSTALL_PREFIX="$(pwd)/release" \
-DCMAKE_PREFIX_PATH="$HOST_PREFIX" \
-DCMAKE_BUILD_TYPE=Debug \
-DZIG_TARGET_TRIPLE="$HOST_TARGET" \
-DZIG_TARGET_MCPU="$HOST_MCPU" \
-DZIG_STATIC=ON
unset CC
unset CXX
make $JOBS install
# Build zig compiler cross-compiled for arm64
cd $ZIGDIR
ZIG="$ZIGDIR/build.host/release/bin/zig"
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
mkdir build
cd build
cmake .. \
-DCMAKE_INSTALL_PREFIX="$(pwd)/release" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_EXECUTABLE="$ZIG" \
-DZIG_STATIC=ON
unset CC
unset CXX
make $JOBS install
if [ "${BUILD_REASON}" != "PullRequest" ]; then
mv ../LICENSE release/
# We do not run test suite but still need langref.
mkdir -p release/docs
$ZIG run ../doc/docgen.zig -- $ZIG ../doc/langref.html.in release/docs/langref.html
# Produce the experimental std lib documentation.
mkdir -p release/docs/std
$ZIG test ../lib/std/std.zig \
--override-lib-dir ../lib \
-femit-docs=release/docs/std \
-fno-emit-bin
mv release/bin/zig release/
rmdir release/bin
VERSION=$(../build.host/release/bin/zig version)
DIRNAME="zig-macos-$ARCH-$VERSION"
TARBALL="$DIRNAME.tar.xz"
mv release "$DIRNAME"
tar cfJ "$TARBALL" "$DIRNAME"
mv "$DOWNLOADSECUREFILE_SECUREFILEPATH" "$HOME/.s3cfg"
s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$TARBALL" s3://ziglang.org/builds/
SHASUM=$(shasum -a 256 $TARBALL | cut '-d ' -f1)
BYTESIZE=$(wc -c < $TARBALL)
JSONFILE="macos-$GITBRANCH.json"
touch $JSONFILE
echo "{\"tarball\": \"$TARBALL\"," >>$JSONFILE
echo "\"shasum\": \"$SHASUM\"," >>$JSONFILE
echo "\"size\": \"$BYTESIZE\"}" >>$JSONFILE
s3cmd put -P --add-header="Cache-Control: max-age=0, must-revalidate" "$JSONFILE" "s3://ziglang.org/builds/$JSONFILE"
s3cmd put -P "$JSONFILE" "s3://ziglang.org/builds/$ARCH-macos-$VERSION.json"
# `set -x` causes these variables to be mangled.
# See https://developercommunity.visualstudio.com/content/problem/375679/pipeline-variable-incorrectly-inserts-single-quote.html
set +x
echo "##vso[task.setvariable variable=tarball;isOutput=true]$TARBALL"
echo "##vso[task.setvariable variable=shasum;isOutput=true]$SHASUM"
echo "##vso[task.setvariable variable=bytesize;isOutput=true]$BYTESIZE"
fi

View File

@@ -3,76 +3,60 @@
set -x
set -e
system_profiler SPHardwareDataType
brew install s3cmd gcc@8
brew update && brew install s3cmd
ZIGDIR="$(pwd)"
CACHE_BASENAME="llvm+clang-9.0.0-macos-x86_64-gcc8-release"
ARCH="x86_64"
TARGET="$ARCH-macos-gnu"
MCPU="baseline"
CACHE_BASENAME="zig+llvm+lld+clang-$TARGET-0.8.1-dev.94+535615117"
PREFIX="$HOME/$CACHE_BASENAME"
TMPDIR="$HOME/tmpz"
JOBS="-j2"
# I tried using the system default compiler (clang), but it couldn't statically link libc++.
# So we use gcc-8 from homebrew.
export CC=gcc-8
export CXX=g++-8
rm -rf $PREFIX
rm -rf $TMPDIR
mkdir $TMPDIR
cd $HOME
HAVE_CACHE="true"
wget -nv "https://ziglang.org/builds/$CACHE_BASENAME.tar.xz" || HAVE_CACHE="false"
if [ "${HAVE_CACHE}" = "true" ]; then
tar xf "$CACHE_BASENAME.tar.xz"
else
if [ "${BUILD_REASON}" == "PullRequest" ]; then
echo "Need cached llvm+clang for pull request builds."
exit 1
fi
cd $TMPDIR
wget https://zlib.net/zlib-1.2.11.tar.xz
tar xf zlib-1.2.11.tar.xz
cd zlib-1.2.11/
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=$PREFIX -DCMAKE_INSTALL_PREFIX=$PREFIX
make $JOBS install
rm $PREFIX/lib/libz*dylib
wget -nv "https://ziglang.org/deps/$CACHE_BASENAME.tar.xz"
tar xf "$CACHE_BASENAME.tar.xz"
cd $TMPDIR
wget https://releases.llvm.org/9.0.0/llvm-9.0.0.src.tar.xz
tar xf llvm-9.0.0.src.tar.xz
cd llvm-9.0.0.src/
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=$PREFIX -DCMAKE_PREFIX_PATH=$PREFIX -DCMAKE_BUILD_TYPE=Release -DLLVM_EXPERIMENTAL_TARGETS_TO_BUILD="AVR" -DLLVM_ENABLE_LIBXML2=OFF -DLLVM_ENABLE_TERMINFO=OFF
make $JOBS install
cd $TMPDIR
wget https://releases.llvm.org/9.0.0/cfe-9.0.0.src.tar.xz
tar xf cfe-9.0.0.src.tar.xz
cd cfe-9.0.0.src/
mkdir build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX=$PREFIX -DCMAKE_PREFIX_PATH=$PREFIX -DCMAKE_BUILD_TYPE=Release
make $JOBS install
cd $HOME
tar cfJ "$CACHE_BASENAME.tar.xz" "$CACHE_BASENAME"
cp "$DOWNLOADSECUREFILE_SECUREFILEPATH" "$HOME/.s3cfg"
s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$CACHE_BASENAME.tar.xz" "s3://ziglang.org/builds/$CACHE_BASENAME.tar.xz"
fi
ZIG="$PREFIX/bin/zig"
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
cd $ZIGDIR
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git config core.abbrev 9
git fetch --unshallow || true
git fetch --tags
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=$PREFIX -DCMAKE_INSTALL_PREFIX=$(pwd)/release -DZIG_STATIC=ON
cmake .. \
-DCMAKE_INSTALL_PREFIX="$(pwd)/release" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON
# Now cmake will use zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
make $JOBS install
release/bin/zig build test
# Here we rebuild zig but this time using the Zig binary we just now produced to
# build zig1.o rather than relying on the one built with stage0. See
# https://github.com/ziglang/zig/issues/6830 for more details.
cmake .. -DZIG_EXECUTABLE="$(pwd)/release/bin/zig"
make $JOBS install
for step in test-toolchain test-std docs; do
release/bin/zig build $step
done
if [ "${BUILD_REASON}" != "PullRequest" ]; then
mv ../LICENSE release/
@@ -81,7 +65,7 @@ if [ "${BUILD_REASON}" != "PullRequest" ]; then
rmdir release/bin
VERSION=$(release/zig version)
DIRNAME="zig-macos-x86_64-$VERSION"
DIRNAME="zig-macos-$ARCH-$VERSION"
TARBALL="$DIRNAME.tar.xz"
mv release "$DIRNAME"
tar cfJ "$TARBALL" "$DIRNAME"
@@ -99,7 +83,7 @@ if [ "${BUILD_REASON}" != "PullRequest" ]; then
echo "\"size\": \"$BYTESIZE\"}" >>$JSONFILE
s3cmd put -P --add-header="Cache-Control: max-age=0, must-revalidate" "$JSONFILE" "s3://ziglang.org/builds/$JSONFILE"
s3cmd put -P "$JSONFILE" "s3://ziglang.org/builds/macos-$VERSION.json"
s3cmd put -P "$JSONFILE" "s3://ziglang.org/builds/$ARCH-macos-$VERSION.json"
# `set -x` causes these variables to be mangled.
# See https://developercommunity.visualstudio.com/content/problem/375679/pipeline-variable-incorrectly-inserts-single-quote.html

12
ci/azure/on_master_success Executable file
View File

@@ -0,0 +1,12 @@
#!/bin/sh
# We do not set -x because this would leak the oauth access token.
set +x
set -e
sudo apt-get update -y
sudo apt-get install -y curl jq
OAUTH_TOKEN="$(cat "$DOWNLOADSECUREFILE_SECUREFILEPATH")"
./ci/srht/on_master_success "$VERSION" "$OAUTH_TOKEN"

View File

@@ -1,10 +1,8 @@
jobs:
- job: BuildMacOS
pool:
vmImage: 'macOS 10.14'
vmImage: 'macOS-10.15'
timeoutInMinutes: 360
steps:
- task: DownloadSecureFile@1
inputs:
@@ -12,12 +10,21 @@ jobs:
- script: ci/azure/macos_script
name: main
displayName: 'Build and test'
- job: BuildMacOS_arm64
pool:
vmImage: 'macOS-10.15'
timeoutInMinutes: 180
steps:
- task: DownloadSecureFile@1
inputs:
secureFile: s3cfg
- script: ci/azure/macos_arm64_script
name: main
displayName: 'Build'
- job: BuildLinux
pool:
vmImage: 'ubuntu-16.04'
vmImage: 'ubuntu-18.04'
timeoutInMinutes: 360
steps:
- task: DownloadSecureFile@1
inputs:
@@ -28,45 +35,44 @@ jobs:
- job: BuildWindows
pool:
vmImage: 'windows-2019'
timeoutInMinutes: 360
steps:
- powershell: |
(New-Object Net.WebClient).DownloadFile("https://github.com/msys2/msys2-installer/releases/download/2021-06-04/msys2-base-x86_64-20210604.sfx.exe", "sfx.exe")
.\sfx.exe -y -o\
del sfx.exe
displayName: Download/Extract/Install MSYS2
- script: |
git clone https://github.com/lazka/msys2-ci-base.git %CD:~0,2%\msys64
%CD:~0,2%\msys64\usr\bin\rm -rf %CD:~0,2%\msys64\.git
set PATH=%CD:~0,2%\msys64\usr\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem
%CD:~0,2%\msys64\usr\bin\pacman --noconfirm -Syyuu
displayName: Install and Update MSYS2
@REM install updated filesystem package first without dependency checking
@REM because of: https://github.com/msys2/MSYS2-packages/issues/2021
%CD:~0,2%\msys64\usr\bin\bash -lc "pacman --noconfirm -Sydd filesystem"
displayName: Workaround filesystem dash MSYS2 dependency issue
- script: |
%CD:~0,2%\msys64\usr\bin\bash -lc "pacman --noconfirm -Syuu"
%CD:~0,2%\msys64\usr\bin\bash -lc "pacman --noconfirm -Syuu"
displayName: Update MSYS2
- task: DownloadSecureFile@1
inputs:
secureFile: s3cfg
- script: ci/azure/windows_script.bat
- script: ci/azure/windows_msvc_script.bat
name: main
displayName: 'Build and test'
- job: UpdateDownloadPage
- job: OnMasterSuccess
dependsOn:
- BuildMacOS
- BuildMacOS_arm64
- BuildLinux
- BuildWindows
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'))
strategy:
maxParallel: 1
pool:
vmImage: 'ubuntu-16.04'
vmImage: 'ubuntu-18.04'
variables:
macos_tarball: $[ dependencies.BuildMacOS.outputs['main.tarball'] ]
macos_shasum: $[ dependencies.BuildMacOS.outputs['main.shasum'] ]
macos_bytesize: $[ dependencies.BuildMacOS.outputs['main.bytesize'] ]
linux_tarball: $[ dependencies.BuildLinux.outputs['main.tarball'] ]
linux_shasum: $[ dependencies.BuildLinux.outputs['main.shasum'] ]
linux_bytesize: $[ dependencies.BuildLinux.outputs['main.bytesize'] ]
windows_tarball: $[ dependencies.BuildWindows.outputs['main.tarball'] ]
windows_shasum: $[ dependencies.BuildWindows.outputs['main.shasum'] ]
windows_bytesize: $[ dependencies.BuildWindows.outputs['main.bytesize'] ]
version: $[ dependencies.BuildLinux.outputs['main.version'] ]
steps:
- task: DownloadSecureFile@1
inputs:
secureFile: s3cfg
- script: ci/azure/update_download_page
displayName: 'Update download page'
secureFile: oauth_token
- script: ci/azure/on_master_success
displayName: 'master branch success hook'

View File

@@ -1,41 +0,0 @@
#!/bin/sh
set -x
set -e
SRCDIR=$(pwd)
rm -rf .git
sudo apt-get update -y
sudo apt-get install -y s3cmd curl jq
cd "$HOME"
wget "https://ziglang.org/builds/$LINUX_TARBALL"
tar xf $LINUX_TARBALL
ZIGDIR=$(basename -s .tar.xz $LINUX_TARBALL)
ZIG="$ZIGDIR/zig"
LANGREF="$ZIGDIR/langref.html"
VERSION=$($ZIG version)
SRCTARBALLDIR="zig-$VERSION"
export SRC_TARBALL="$SRCTARBALLDIR.tar.xz"
mv "$SRCDIR" "$SRCTARBALLDIR"
tar cfJ "$SRC_TARBALL" "$SRCTARBALLDIR"
export SRC_SHASUM=$(sha256sum $SRC_TARBALL | cut '-d ' -f1)
export SRC_BYTESIZE=$(wc -c < $SRC_TARBALL)
# the freebsd build has to be there too
FREEBSD_JSON=$(curl --fail "https://ziglang.org/builds/freebsd-$VERSION.json" || exit 1)
export FREEBSD_TARBALL="$(echo "$FREEBSD_JSON" | jq .tarball -r)"
export FREEBSD_BYTESIZE="$(echo "$FREEBSD_JSON" | jq .size -r)"
export FREEBSD_SHASUM="$(echo "$FREEBSD_JSON" | jq .shasum -r)"
git clone https://github.com/ziglang/www.ziglang.org --depth 1
cd www.ziglang.org
export MASTER_DATE=$(date +%Y-%m-%d)
env
"../$ZIG" run update-download-page.zig
mv "$DOWNLOADSECUREFILE_SECUREFILEPATH" "$HOME/.s3cfg"
s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "../$SRC_TARBALL" s3://ziglang.org/builds/
s3cmd put -P "../$LANGREF" s3://ziglang.org/documentation/master/index.html --add-header="Cache-Control: max-age=0, must-revalidate"
s3cmd put -P www/download/index.html s3://ziglang.org/download/index.html --add-header="Cache-Control: max-age=0, must-revalidate"
s3cmd put -P www/download/index.json s3://ziglang.org/download/index.json --add-header="Cache-Control: max-age=0, must-revalidate"

View File

@@ -1,10 +0,0 @@
#!/bin/sh
set -x
set -e
pacman -Su --needed --noconfirm
pacman -S --needed --noconfirm wget p7zip python3-pip
pip install s3cmd
wget -nv "https://ziglang.org/deps/llvm%2bclang-9.0.0-win64-msvc-release.tar.xz"
tar xf llvm+clang-9.0.0-win64-msvc-release.tar.xz

View File

@@ -0,0 +1,11 @@
#!/bin/sh
set -x
set -e
pacman -Suy --needed --noconfirm
pacman -S --needed --noconfirm wget p7zip python3-pip tar xz
pip install s3cmd
wget -nv "https://ziglang.org/deps/llvm%2bclang%2blld-12.0.1-rc1-x86_64-windows-msvc-release-mt.tar.xz"
tar xf llvm+clang+lld-12.0.1-rc1-x86_64-windows-msvc-release-mt.tar.xz

View File

@@ -0,0 +1,35 @@
@echo on
SET "SRCROOT=%cd%"
SET "PREVPATH=%PATH%"
SET "PREVMSYSEM=%MSYSTEM%"
set "PATH=%CD:~0,2%\msys64\usr\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem"
SET "MSYSTEM=MINGW64"
bash -lc "cd ${SRCROOT} && ci/azure/windows_msvc_install" || exit /b
SET "PATH=%PREVPATH%"
SET "MSYSTEM=%PREVMSYSTEM%"
SET "ZIGBUILDDIR=%SRCROOT%\build"
SET "ZIGINSTALLDIR=%ZIGBUILDDIR%\dist"
SET "ZIGPREFIXPATH=%SRCROOT%\llvm+clang+lld-12.0.1-rc1-x86_64-windows-msvc-release-mt"
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64
REM Make the `zig version` number consistent.
REM This will affect the cmake command below.
git.exe config core.abbrev 9
git.exe fetch --unshallow
git.exe fetch --tags
mkdir %ZIGBUILDDIR%
cd %ZIGBUILDDIR%
cmake.exe .. -Thost=x64 -G"Visual Studio 16 2019" -A x64 "-DCMAKE_INSTALL_PREFIX=%ZIGINSTALLDIR%" "-DCMAKE_PREFIX_PATH=%ZIGPREFIXPATH%" -DCMAKE_BUILD_TYPE=Release -DZIG_OMIT_STAGE2=ON || exit /b
msbuild /maxcpucount /p:Configuration=Release INSTALL.vcxproj || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-toolchain -Dskip-non-native -Dskip-stage2-tests || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test-std -Dskip-non-native || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build docs || exit /b
set "PATH=%CD:~0,2%\msys64\usr\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem"
SET "MSYSTEM=MINGW64"
bash -lc "cd ${SRCROOT} && ci/azure/windows_upload" || exit /b

View File

@@ -1,28 +0,0 @@
@echo on
SET "SRCROOT=%cd%"
SET "PREVPATH=%PATH%"
SET "PREVMSYSEM=%MSYSTEM%"
set "PATH=%CD:~0,2%\msys64\usr\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem"
SET "MSYSTEM=MINGW64"
bash -lc "cd ${SRCROOT} && ci/azure/windows_install" || exit /b
SET "PATH=%PREVPATH%"
SET "MSYSTEM=%PREVMSYSTEM%"
SET "ZIGBUILDDIR=%SRCROOT%\build"
SET "ZIGINSTALLDIR=%ZIGBUILDDIR%\dist"
SET "ZIGPREFIXPATH=%SRCROOT%\llvm+clang-9.0.0-win64-msvc-release"
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvarsall.bat" x64
mkdir %ZIGBUILDDIR%
cd %ZIGBUILDDIR%
REM Here we use MinSizeRel instead of Release to work around https://github.com/ziglang/zig/issues/3024
cmake.exe .. -Thost=x64 -G"Visual Studio 16 2019" -A x64 "-DCMAKE_INSTALL_PREFIX=%ZIGINSTALLDIR%" "-DCMAKE_PREFIX_PATH=%ZIGPREFIXPATH%" -DCMAKE_BUILD_TYPE=MinSizeRel || exit /b
msbuild /p:Configuration=MinSizeRel INSTALL.vcxproj || exit /b
"%ZIGINSTALLDIR%\bin\zig.exe" build test || exit /b
set "PATH=%CD:~0,2%\msys64\usr\bin;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem"
SET "MSYSTEM=MINGW64"
bash -lc "cd ${SRCROOT} && ci/azure/windows_upload" || exit /b

View File

@@ -17,8 +17,8 @@ if [ "${BUILD_REASON}" != "PullRequest" ]; then
mv dist "$DIRNAME"
7z a "$TARBALL" "$DIRNAME"
mv "$DOWNLOADSECUREFILE_SECUREFILEPATH" "$HOME/.s3cfg"
s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$TARBALL" s3://ziglang.org/builds/
# mv "$DOWNLOADSECUREFILE_SECUREFILEPATH" "$HOME/.s3cfg"
s3cmd -c "$DOWNLOADSECUREFILE_SECUREFILEPATH" put -P --add-header="cache-control: public, max-age=31536000, immutable" "$TARBALL" s3://ziglang.org/builds/
SHASUM=$(sha256sum $TARBALL | cut '-d ' -f1)
BYTESIZE=$(wc -c < $TARBALL)
@@ -29,8 +29,8 @@ if [ "${BUILD_REASON}" != "PullRequest" ]; then
echo "\"shasum\": \"$SHASUM\"," >>$JSONFILE
echo "\"size\": \"$BYTESIZE\"}" >>$JSONFILE
s3cmd put -P --add-header="Cache-Control: max-age=0, must-revalidate" "$JSONFILE" "s3://ziglang.org/builds/$JSONFILE"
s3cmd put -P "$JSONFILE" "s3://ziglang.org/builds/windows-$VERSION.json"
s3cmd -c "$DOWNLOADSECUREFILE_SECUREFILEPATH" put -P --add-header="Cache-Control: max-age=0, must-revalidate" "$JSONFILE" "s3://ziglang.org/builds/$JSONFILE"
s3cmd -c "$DOWNLOADSECUREFILE_SECUREFILEPATH" put -P "$JSONFILE" "s3://ziglang.org/builds/x86_64-windows-$VERSION.json"
# `set -x` causes these variables to be mangled.
# See https://developercommunity.visualstudio.com/content/problem/375679/pipeline-variable-incorrectly-inserts-single-quote.html

50
ci/drone/drone.yml Normal file
View File

@@ -0,0 +1,50 @@
---
kind: pipeline
name: test-aarch64-linux-musl
platform:
arch: arm64
steps:
- name: build
image: ziglang/static-base:llvm12-aarch64-5
commands:
- ./ci/drone/linux_script_build
- name: test-1
depends_on:
- build
image: ziglang/static-base:llvm12-aarch64-5
commands:
- ./ci/drone/linux_script_test 1
- name: test-2
depends_on:
- build
image: ziglang/static-base:llvm12-aarch64-5
commands:
- ./ci/drone/linux_script_test 2
- name: test-3
depends_on:
- build
image: ziglang/static-base:llvm12-aarch64-5
commands:
- ./ci/drone/linux_script_test 3
- name: finalize
depends_on:
- build
- test-1
- test-2
- test-3
image: ziglang/static-base:llvm12-aarch64-5
environment:
SRHT_OAUTH_TOKEN:
from_secret: SRHT_OAUTH_TOKEN
AWS_ACCESS_KEY_ID:
from_secret: AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY:
from_secret: AWS_SECRET_ACCESS_KEY
commands:
- ./ci/drone/linux_script_finalize

22
ci/drone/linux_script_base Executable file
View File

@@ -0,0 +1,22 @@
#!/bin/sh
# https://docs.drone.io/pipeline/docker/syntax/workspace/
#
# Drone automatically creates a temporary volume, known as your workspace,
# where it clones your repository. The workspace is the current working
# directory for each step in your pipeline.
#
# Because the workspace is a volume, filesystem changes are persisted between
# pipeline steps. In other words, individual steps can communicate and share
# state using the filesystem.
#
# Workspace volumes are ephemeral. They are created when the pipeline starts
# and destroyed after the pipeline completes.
set -x
set -e
TRIPLEARCH="$(uname -m)"
DISTDIR="$DRONE_WORKSPACE/dist"
export ZIG_GLOBAL_CACHE_DIR="$DRONE_WORKSPACE/zig-cache"

59
ci/drone/linux_script_build Executable file
View File

@@ -0,0 +1,59 @@
#!/bin/sh
. ./ci/drone/linux_script_base
PREFIX="/deps/local"
ZIG="$PREFIX/bin/zig"
TARGET="$TRIPLEARCH-linux-musl"
MCPU="baseline"
export CC="$ZIG cc -target $TARGET -mcpu=$MCPU"
export CXX="$ZIG c++ -target $TARGET -mcpu=$MCPU"
# The `CMAKE_AR` parameter will consider any spaces to
# be part of the executable path rather than CLI args, so we have
# to create wrapper scripts for `zig ar` and zig ranlib`.
cat <<'ENDFILE' >$PREFIX/bin/ar
#!/bin/sh
/deps/local/bin/zig ar $@
ENDFILE
cat <<'ENDFILE' >$PREFIX/bin/ranlib
#!/bin/sh
/deps/local/bin/zig ranlib $@
ENDFILE
chmod +x $PREFIX/bin/ar
chmod +x $PREFIX/bin/ranlib
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git config core.abbrev 9
git fetch --unshallow || true
git fetch --tags
mkdir build
cd build
cmake .. \
-DCMAKE_INSTALL_PREFIX="$DISTDIR" \
-DCMAKE_PREFIX_PATH="$PREFIX" \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_AR="$PREFIX/bin/ar" \
-DCMAKE_RANLIB="$PREFIX/bin/ranlib" \
-DZIG_TARGET_TRIPLE="$TARGET" \
-DZIG_TARGET_MCPU="$MCPU" \
-DZIG_STATIC=ON \
-GNinja
# Now CMake will use Zig as the C/C++ compiler. We reset the environment variables
# so that installation and testing do not get affected by them.
unset CC
unset CXX
samu install
# Here we rebuild Zig but this time using the Zig binary we just now produced to
# build zig1.o rather than relying on the one built with stage0. See
# https://github.com/ziglang/zig/issues/6830 for more details.
cmake .. -DZIG_EXECUTABLE="$DISTDIR/bin/zig"
samu install

46
ci/drone/linux_script_finalize Executable file
View File

@@ -0,0 +1,46 @@
#!/bin/sh
. ./ci/drone/linux_script_base
if [ -n "$DRONE_PULL_REQUEST" ]; then
exit 0
fi
apk update
apk add py3-pip perl-utils jq curl
pip3 install s3cmd
cd build
mv ../LICENSE "$DISTDIR/"
# docs are disabled due to: https://github.com/ziglang/zig/issues/8597
#mv ../zig-cache/langref.html "$DISTDIR/"
mv "$DISTDIR/bin/zig" "$DISTDIR/"
rmdir "$DISTDIR/bin"
GITBRANCH="$DRONE_BRANCH"
VERSION="$("$DISTDIR/zig" version)"
DIRNAME="zig-linux-$TRIPLEARCH-$VERSION"
TARBALL="$DIRNAME.tar.xz"
mv "$DISTDIR" "$DIRNAME"
tar cfJ "$TARBALL" "$DIRNAME"
s3cmd put -P --add-header="cache-control: public, max-age=31536000, immutable" "$TARBALL" s3://ziglang.org/builds/
SHASUM=$(shasum -a 256 $TARBALL | cut '-d ' -f1)
BYTESIZE=$(wc -c < $TARBALL)
JSONFILE="tarball.json"
touch $JSONFILE
echo "{\"tarball\": \"$TARBALL\"," >>$JSONFILE
echo "\"shasum\": \"$SHASUM\"," >>$JSONFILE
echo "\"size\": \"$BYTESIZE\"}" >>$JSONFILE
s3cmd put -P "$JSONFILE" "s3://ziglang.org/builds/$TRIPLEARCH-linux-$VERSION.json"
if [ "$GITBRANCH" = "master" ]; then
# avoid leaking oauth token
set +x
cd "$DRONE_WORKSPACE"
./ci/srht/on_master_success "$VERSION" "$SRHT_OAUTH_TOKEN"
fi

46
ci/drone/linux_script_test Executable file
View File

@@ -0,0 +1,46 @@
#!/bin/sh
. ./ci/drone/linux_script_base
# only release-fast builds of test suite due to: https://github.com/ziglang/zig/issues/8597
#
# Some test suite components will be missing because they do not support
# forcing -OReleaseFast
#
# see `zig build --help` for the full list of test-* components
case "$1" in
1)
steps="\
test-stage2 \
test-fmt \
test-behavior"
;;
2)
steps="test-std"
;;
3)
steps="\
test-compiler-rt \
test-minilibc \
test-compare-output \
test-translate-c \
test-run-translated-c"
;;
'')
echo "error: expecting test group argument"
exit 1
;;
*)
echo "error: unknown test group: $1"
exit 1
;;
esac
# only release-fast builds of test suite due to: https://github.com/ziglang/zig/issues/8597
./build/zig build \
-Drelease \
-Dskip-debug \
-Dskip-release-small \
-Dskip-release-safe \
-Dskip-non-native \
$steps

View File

@@ -3,61 +3,47 @@
set -x
set -e
sudo pkg update -fq
sudo pkg install -y cmake py38-s3cmd wget curl jq samurai
ZIGDIR="$(pwd)"
CACHE_BASENAME="llvm+clang-9.0.0-freebsd-x86_64-release"
CACHE_BASENAME="zig+llvm+lld+clang-x86_64-freebsd-gnu-0.8.0-dev.2703+c12704a33"
PREFIX="$HOME/$CACHE_BASENAME"
JOBS="-j$(sysctl -n hw.ncpu)"
cd $HOME
wget -nv "https://ziglang.org/builds/$CACHE_BASENAME.tar.xz"
wget -nv "https://ziglang.org/deps/$CACHE_BASENAME.tar.xz"
tar xf "$CACHE_BASENAME.tar.xz"
cd $ZIGDIR
# Make the `zig version` number consistent.
# This will affect the cmake command below.
git config core.abbrev 9
git fetch --unshallow || true
git fetch --tags
# SourceHut reports that it is a terminal that supports escape codes, but it
# is a filthy liar. Here we tell Zig to not try to send any terminal escape
# codes to show progress.
export TERM=dumb
mkdir build
cd build
cmake .. -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=$PREFIX -DCMAKE_INSTALL_PREFIX=$(pwd)/release -DZIG_STATIC=ON
make $JOBS install
cmake .. \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_PREFIX_PATH=$PREFIX \
"-DCMAKE_INSTALL_PREFIX=$(pwd)/release" \
-DZIG_STATIC=ON \
-DZIG_TARGET_TRIPLE=x86_64-freebsd-gnu \
-GNinja
samu install
release/bin/zig build test-fmt
release/bin/zig build test-behavior
# This test is disabled because it triggers "out of memory" on the sr.ht CI service.
# See https://github.com/ziglang/zig/issues/3210
# release/bin/zig build test-std
release/bin/zig build test-compiler-rt
# This test is disabled because it triggers "out of memory" on the sr.ht CI service.
# See https://github.com/ziglang/zig/issues/3210
# release/bin/zig build test-compare-output
# This test is disabled because it triggers "out of memory" on the sr.ht CI service.
# See https://github.com/ziglang/zig/issues/3210
# release/bin/zig build test-standalone
release/bin/zig build test-stack-traces
release/bin/zig build test-cli
release/bin/zig build test-asm-link
release/bin/zig build test-runtime-safety
# This test is disabled because it triggers "out of memory" on the sr.ht CI service.
# See https://github.com/ziglang/zig/issues/3210
# release/bin/zig build test-translate-c
release/bin/zig build test-gen-h
# This test is disabled because it triggers "out of memory" on the sr.ht CI service.
# See https://github.com/ziglang/zig/issues/3210
# release/bin/zig build test-compile-errors
# This test is disabled because it triggers "out of memory" on the sr.ht CI service.
# See https://github.com/ziglang/zig/issues/3210
# release/bin/zig build docs
# Here we skip some tests to save time.
release/bin/zig build test -Dskip-compile-errors -Dskip-non-native
if [ -f ~/.s3cfg ]; then
mv ../LICENSE release/
# Enable when `release/bin/zig build docs` passes without "out of memory" or failures
#mv ../zig-cache/langref.html release/
mv ../zig-cache/langref.html release/
mv release/bin/zig release/
rmdir release/bin
@@ -80,5 +66,14 @@ if [ -f ~/.s3cfg ]; then
echo "\"size\": \"$BYTESIZE\"}" >>$JSONFILE
s3cmd put -P --add-header="Cache-Control: max-age=0, must-revalidate" "$JSONFILE" "s3://ziglang.org/builds/$JSONFILE"
s3cmd put -P "$JSONFILE" "s3://ziglang.org/builds/freebsd-$VERSION.json"
s3cmd put -P "$JSONFILE" "s3://ziglang.org/builds/x86_64-freebsd-$VERSION.json"
if [ "$GITBRANCH" = "master" ]; then
# avoid leaking oauth token
set +x
OAUTH_TOKEN="$(cat ~/.oauth_token)"
cd "$ZIGDIR"
./ci/srht/on_master_success "$VERSION" "$OAUTH_TOKEN"
fi
fi

737
ci/srht/index.html Normal file
View File

@@ -0,0 +1,737 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Releases ⚡ The Zig Programming Language</title>
<link rel="icon" href="/favicon.png">
<style>
body{
font-family: system-ui, -apple-system, Roboto, "Segoe UI", sans-serif;
line-height: 1.45;
margin-left: 0;
margin-right: 0;
}
p {
margin: 0.8em 0;
}
h1, h2, h3, h4 {
margin: 0.5em 0 0.5em;
line-height: 1.2;
font-weight: bold;
color: #666;
}
h1 a, h2 a, h3 a, h4 a {
text-decoration: none;
color: #666;
}
a.hdr {
visibility: hidden;
}
h1:hover > a.hdr, h2:hover > a.hdr, h3:hover > a.hdr, h4:hover > a.hdr, h5:hover > a.hdr {
visibility: visible;
}
h1 { font-size: 2.0em; }
h2 { font-size: 1.5em; }
h3 { font-size: 1.25em; }
h4 { font-size: 1.0em; }
a {
color: #2A6286;
}
a:not(:hover) {
text-decoration: none;
}
th, td {
padding: 0.6em;
text-align: left;
white-space: nowrap;
}
td {
font-size: 0.96em;
}
th {
border-bottom: 2px solid #f2f3f3;
}
tr:nth-child(even) {
background: #f2f3f3;
}
.container {
margin: 0 auto;
position: relative;
max-width: 1000px;
}
#navbar {
background-color: #737475;
padding: 5px 0;
border-top: 4px solid #f7a41d;
margin-bottom: 30px;
}
#navbar .navbar-item, #navbar .navbar-item:visited {
color: white;
padding-right: 5px;
padding-left: 5px;
}
.code {
font-family: monospace;
font-size: 0.8em;
}
#header-image {
background-image: url(https://ziglang.org/img/zig-logo-dark.svg);
background-repeat: no-repeat;
width: 340px;
height: 90px;
display: block;
padding: 0;
margin: 0;
}
@media (prefers-color-scheme: dark) {
body{
background-color:#111;
color: #bbb;
}
a {
color: #88f;
}
table, th, td {
border-color: grey;
}
tr:nth-child(even) {
background: #1e1e1e;
}
h1 a, h2 a, h3 a, h4 a, h5 a {
color: #aaa;
}
#header-image {
background-image: url(https://ziglang.org/img/zig-logo-light.svg);
}
}
</style>
</head>
<body>
<div class="container">
<a href="/"><span id="header-image"></span></a>
</div>
<nav id="navbar">
<div class="container">
<a href="/download/" class="navbar-item">Download &amp; Documentation</a>
<a href="https://github.com/ziglang/zig" class="navbar-item">Source Code</a>
<a href="/news/" class="navbar-item">News</a>
<a href="https://github.com/ziglang/zig/wiki/Community" class="navbar-item">Join a Community</a>
<a href="/zsf/" class="navbar-item">
<svg style="color: #ea4aaa; vertical-align: middle;fill: currentColor; margin-right: 5px" viewBox="0 0 12 16" version="1.1" width="12" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M9 2c-.97 0-1.69.42-2.2 1-.51.58-.78.92-.8 1-.02-.08-.28-.42-.8-1-.52-.58-1.17-1-2.2-1-1.632.086-2.954 1.333-3 3 0 .52.09 1.52.67 2.67C1.25 8.82 3.01 10.61 6 13c2.98-2.39 4.77-4.17 5.34-5.33C11.91 6.51 12 5.5 12 5c-.047-1.69-1.342-2.913-3-3z"></path></svg>Sponsor the Zig Software Foundation</a>
</div>
</nav>
<div class="container">
<h1>Releases</h1>
<p>You can also
<a href="https://github.com/ziglang/zig/wiki/Install-Zig-from-a-Package-Manager">install Zig from a package manager</a>.
</p>
<p>
There is a <a href="index.json">JSON version of this page</a>.
</p>
<h2 id="release-master">master</h2>
<ul>
<li>{{MASTER_DATE}}</li>
<li><a href="/documentation/master/">Language Reference</a></li>
<li><a href="/documentation/master/std/">Standard Library Documentation</a> (experimental)</li>
</ul>
<table>
<colgroup>
<col width="40%">
<col width="10%">
<col width="10%">
</colgroup>
<thead>
<tr>
<th>Filename</th>
<th>Kind</th>
<th>Size</th>
<th>Sha256</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://ziglang.org/builds/{{SRC_TARBALL}}">{{SRC_TARBALL}}</a></td>
<td>Source</td>
<td>{{SRC_BYTESIZE}}</td>
<td class="code">{{SRC_SHASUM}}</td>
</tr>
<tr>
<td><a href="https://ziglang.org/builds/{{X86_64_LINUX_TARBALL}}">{{X86_64_LINUX_TARBALL}}</a></td>
<td>Binary</td>
<td>{{X86_64_LINUX_BYTESIZE}}</td>
<td class="code">{{X86_64_LINUX_SHASUM}}</td>
</tr>
<tr>
<td><a href="https://ziglang.org/builds/{{AARCH64_LINUX_TARBALL}}">{{AARCH64_LINUX_TARBALL}}</a></td>
<td>Binary</td>
<td>{{AARCH64_LINUX_BYTESIZE}}</td>
<td class="code">{{AARCH64_LINUX_SHASUM}}</td>
</tr>
<tr>
<td><a href="https://ziglang.org/builds/{{X86_64_WINDOWS_TARBALL}}">{{X86_64_WINDOWS_TARBALL}}</a></td>
<td>Binary</td>
<td>{{X86_64_WINDOWS_BYTESIZE}}</td>
<td class="code">{{X86_64_WINDOWS_SHASUM}}</td>
</tr>
<tr>
<td><a href="https://ziglang.org/builds/{{X86_64_MACOS_TARBALL}}">{{X86_64_MACOS_TARBALL}}</a></td>
<td>Binary</td>
<td>{{X86_64_MACOS_BYTESIZE}}</td>
<td class="code">{{X86_64_MACOS_SHASUM}}</td>
</tr>
<tr>
<td><a href="https://ziglang.org/builds/{{AARCH64_MACOS_TARBALL}}">{{AARCH64_MACOS_TARBALL}}</a></td>
<td>Binary</td>
<td>{{AARCH64_MACOS_BYTESIZE}}</td>
<td class="code">{{AARCH64_MACOS_SHASUM}}</td>
</tr>
<tr>
<td><a href="https://ziglang.org/builds/{{X86_64_FREEBSD_TARBALL}}">{{X86_64_FREEBSD_TARBALL}}</a></td>
<td>Binary</td>
<td>{{X86_64_FREEBSD_BYTESIZE}}</td>
<td class="code">{{X86_64_FREEBSD_SHASUM}}</td>
</tr>
</tbody>
</table>
<h2 id="release-0.7.1">0.7.1</h2>
<ul>
<li>2020-12-13</li>
<li><a href="0.7.1/release-notes.html">Release Notes</a></li>
<li><a href="/documentation/0.7.1/">Language Reference</a></li>
<li><a href="/documentation/0.7.1/std">Standard Library Documentation</a> (experimental)</li>
</ul>
<table>
<colgroup>
<col width="40%">
<col width="10%">
<col width="10%">
</colgroup>
<thead>
<tr>
<th>Filename</th>
<th>Kind</th>
<th>Size</th>
<th>Sha256</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://ziglang.org/download/0.7.1/zig-0.7.1.tar.xz">zig-0.7.1.tar.xz</a></td>
<td>Source</td>
<td>11MiB</td>
<td class="code">2db3b944ab368d955b48743d9f7c963b8f96de1a441ba5a35e197237cc6dae44</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.1/zig-bootstrap-0.7.1.tar.xz">zig-bootstrap-0.7.1.tar.xz</a></td>
<td>Source</td>
<td>39MiB</td>
<td class="code">040f27c1fae4b0cac0a2782aecdb691f6a2f8e89db6a6ed35024c31c304fd9b2</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.1/zig-freebsd-x86_64-0.7.1.tar.xz">zig-freebsd-x86_64-0.7.1.tar.xz</a></td>
<td>Binary</td>
<td>38MiB</td>
<td class="code">e73c1dca35791a3183fdd5ecde0443ebbe180942efceafe651886034fb8def09</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.1/zig-linux-aarch64-0.7.1.tar.xz">zig-linux-aarch64-0.7.1.tar.xz</a></td>
<td>Binary</td>
<td>33MiB</td>
<td class="code">48ec90eba407e4587ddef7eecef25fec7e13587eb98e3b83c5f2f5fff2a5cbe7</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.1/zig-linux-armv7a-0.7.1.tar.xz">zig-linux-armv7a-0.7.1.tar.xz</a></td>
<td>Binary</td>
<td>35MiB</td>
<td class="code">5a0662e07b4c4968665e1f97558f8591f6facec45d2e0ff5715e661743107ceb</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.1/zig-linux-i386-0.7.1.tar.xz">zig-linux-i386-0.7.1.tar.xz</a></td>
<td>Binary</td>
<td>38MiB</td>
<td class="code">4882e052e5f83690bd0334bb4fc1702b5403cb3a3d2aa63fd7d6043d8afecba3</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.1/zig-linux-riscv64-0.7.1.tar.xz">zig-linux-riscv64-0.7.1.tar.xz</a></td>
<td>Binary</td>
<td>36MiB</td>
<td class="code">187294bfd35983348c3fe042901b42e67e7e36ab7f77a5f969d21c0051f4d21f</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.1/zig-linux-x86_64-0.7.1.tar.xz">zig-linux-x86_64-0.7.1.tar.xz</a></td>
<td>Binary</td>
<td>37MiB</td>
<td class="code">18c7b9b200600f8bcde1cd8d7f1f578cbc3676241ce36d771937ce19a8159b8d</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.1/zig-macos-x86_64-0.7.1.tar.xz">zig-macos-x86_64-0.7.1.tar.xz</a></td>
<td>Binary</td>
<td>35MiB</td>
<td class="code">845cb17562978af0cf67e3993f4e33330525eaf01ead9386df9105111e3bc519</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.1/zig-windows-i386-0.7.1.zip">zig-windows-i386-0.7.1.zip</a></td>
<td>Binary</td>
<td>52MiB</td>
<td class="code">a1b9a7421e13153e07fd2e2c93ff29aad64d83105b8fcdafa633dbe689caf1c0</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.1/zig-windows-x86_64-0.7.1.zip">zig-windows-x86_64-0.7.1.zip</a></td>
<td>Binary</td>
<td>53MiB</td>
<td class="code">4818a8a65b4672bc52c0ae7f14d014e0eb8caf10f12c0745176820384cea296a</td>
</tr>
</tbody>
</table>
<h2 id="release-0.7.0">0.7.0</h2>
<ul>
<li>2020-11-08</li>
<li><a href="0.7.0/release-notes.html">Release Notes</a></li>
<li><a href="/documentation/0.7.0/">Language Reference</a></li>
<li><a href="/documentation/0.7.0/std">Standard Library Documentation</a> (experimental)</li>
</ul>
<table>
<colgroup>
<col width="40%">
<col width="10%">
<col width="10%">
</colgroup>
<thead>
<tr>
<th>Filename</th>
<th>Kind</th>
<th>Size</th>
<th>Sha256</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-0.7.0.tar.xz">zig-0.7.0.tar.xz</a></td>
<td>Source</td>
<td>11MiB</td>
<td class="code">0efd2cf6c3b05723db80e9cf193bc55150bba84ca41f855a90f53fc756445f83</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-bootstrap-0.7.0.tar.xz">zig-bootstrap-0.7.0.tar.xz</a></td>
<td>Source</td>
<td>39MiB</td>
<td class="code">f073beaf5c53c8c57c0d374cbfcb332ef92ad703173edba0d9e0f2ed28401b72</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-freebsd-x86_64-0.7.0.tar.xz">zig-freebsd-x86_64-0.7.0.tar.xz</a></td>
<td>Binary</td>
<td>34MiB</td>
<td class="code">a0c926272ee4ae720034b4a6a1dc98399d76156dd84182554740f0ca8a41fc99</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-linux-aarch64-0.7.0.tar.xz">zig-linux-aarch64-0.7.0.tar.xz</a></td>
<td>Binary</td>
<td>32MiB</td>
<td class="code">f89933bac87d44be82325754ff88423020c81c7032a6fc41cfeb81e982eeab9b</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-linux-armv7a-0.7.0.tar.xz">zig-linux-armv7a-0.7.0.tar.xz</a></td>
<td>Binary</td>
<td>34MiB</td>
<td class="code">011c267e25a96ee160505a560c441daa045359a9d50e13ab1bada9d75c95db2d</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-linux-i386-0.7.0.tar.xz">zig-linux-i386-0.7.0.tar.xz</a></td>
<td>Binary</td>
<td>37MiB</td>
<td class="code">4bb2072cd363bcb1cbeb4872ff5cbc1f683b02d0cc1f90c46e3ea7422ce53222</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-linux-riscv64-0.7.0.tar.xz">zig-linux-riscv64-0.7.0.tar.xz</a></td>
<td>Binary</td>
<td>36MiB</td>
<td class="code">40dff81faa6f232ac40abbf88b9371f3cc932b6e09c423b94387c9ea580cb7be</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-linux-x86_64-0.7.0.tar.xz">zig-linux-x86_64-0.7.0.tar.xz</a></td>
<td>Binary</td>
<td>36MiB</td>
<td class="code">e619b1c6094c095b932767f527aee2507f847ea981513ff8a08aab0fd730e0ac</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-macos-aarch64-0.7.0.tar.xz">zig-macos-aarch64-0.7.0.tar.xz</a></td>
<td>Binary</td>
<td>33MiB</td>
<td class="code">338238035734db74ea4f30e500a4893bf741d38305c10952d5e39fa05bdb057d</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-macos-x86_64-0.7.0.tar.xz">zig-macos-x86_64-0.7.0.tar.xz</a></td>
<td>Binary</td>
<td>35MiB</td>
<td class="code">94063f9a311cbbf7a2e0a12295e09437182cf950f18cb0eb30ea9893f3677f24</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-windows-i386-0.7.0.zip">zig-windows-i386-0.7.0.zip</a></td>
<td>Binary</td>
<td>51MiB</td>
<td class="code">b1e520aacbfbd645ff3521b3eb4d44166d9a0288b8725e4b001f8b50a425eb2e</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.7.0/zig-windows-x86_64-0.7.0.zip">zig-windows-x86_64-0.7.0.zip</a></td>
<td>Binary</td>
<td>52MiB</td>
<td class="code">965f56c0a36f9cda2125e3a348bc654f7f155e2804c3667d231775ec228f8553</td>
</tr>
</tbody>
</table>
<h2 id="release-0.6.0">0.6.0</h2>
<ul>
<li>2020-04-13</li>
<li><a href="0.6.0/release-notes.html">Release Notes</a></li>
<li><a href="/documentation/0.6.0">Language Reference</a></li>
<li><a href="/documentation/0.6.0/std">Standard Library Documentation</a> (experimental)</li>
</ul>
<table>
<colgroup>
<col width="40%">
<col width="10%">
<col width="10%">
</colgroup>
<thead>
<tr>
<th>Filename</th>
<th>Kind</th>
<th>Size</th>
<th>Sha256</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-0.6.0.tar.xz">zig-0.6.0.tar.xz</a></td>
<td>Source</td>
<td>9.9MiB</td>
<td class="code">5d167dc19354282dd35dd17b38e99e1763713b9be8a4ba9e9e69284e059e7204</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-bootstrap-0.6.0.tar.xz">zig-bootstrap-0.6.0.tar.xz</a></td>
<td>Source</td>
<td>36.7MiB</td>
<td class="code">5e0e4dc878b3dd0c1852a442b174f0732e8c07869a8fcd226b71a93b89b381ab</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-freebsd-x86_64-0.6.0.tar.xz">zig-freebsd-x86_64-0.6.0.tar.xz</a></td>
<td>Binary</td>
<td>36MiB</td>
<td class="code">190ff79c1eb56805a315d7c7a51082e32f62926250c0702b36760c225e1634a3</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-linux-aarch64-0.6.0.tar.xz">zig-linux-aarch64-0.6.0.tar.xz</a></td>
<td>Binary</td>
<td>36MiB</td>
<td class="code">e7520efd42cfa02be48c2e430d08fe1f3cbb999d21d9f0d3ffd0febb976b2f41</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-linux-armv6kz-0.6.0.tar.xz">zig-linux-armv6kz-0.6.0.tar.xz</a></td>
<td>Binary</td>
<td>38MiB</td>
<td class="code">36b6493b3fed43eb1f0000e765798ad31a6bb7d7fd3f553ac1c3761dbc919b82</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-linux-armv7a-0.6.0.tar.xz">zig-linux-armv7a-0.6.0.tar.xz</a></td>
<td>Binary</td>
<td>38MiB</td>
<td class="code">946969abe357def95ca9cbbfcebfcf2d90cf967bcd3f48ee87662e32d91d8f35</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-linux-i386-0.6.0.tar.xz">zig-linux-i386-0.6.0.tar.xz</a></td>
<td>Binary</td>
<td>43MiB</td>
<td class="code">a97a2f9ae21575743cdd763c1917d49400d83fc562ef64582b18bade43eb24ce</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-linux-riscv64-0.6.0.tar.xz">zig-linux-riscv64-0.6.0.tar.xz</a></td>
<td>Binary</td>
<td>41MiB</td>
<td class="code">68ddee43f7503c8ae5f26a921f3602c34719a02ed2241f528c0b8b888cc14b38</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-linux-x86_64-0.6.0.tar.xz">zig-linux-x86_64-0.6.0.tar.xz</a></td>
<td>Binary</td>
<td>43MiB</td>
<td class="code">08fd3c757963630645441c2772362e9c2294020c44f14fce1b89f45de0dc1253</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-macos-x86_64-0.6.0.tar.xz">zig-macos-x86_64-0.6.0.tar.xz</a></td>
<td>Binary</td>
<td>41MiB</td>
<td class="code">17270360e87ddc49f737e760047b2fac49f1570a824a306119b1194ac4093895</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-windows-i386-0.6.0.zip">zig-windows-i386-0.6.0.zip</a></td>
<td>Binary</td>
<td>58MiB</td>
<td class="code">3b0a02618743e92175990dc6d1a787bb95ff62c4cda016f1c14c7786f575f8ca</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.6.0/zig-windows-x86_64-0.6.0.zip">zig-windows-x86_64-0.6.0.zip</a></td>
<td>Binary</td>
<td>47MiB</td>
<td class="code">c3b897832523e1026e10b2d8d55d7f895185c0a27a63681f3a23219c3f1c38f4</td>
</tr>
</tbody>
</table>
<h2 id="release-0.5.0">0.5.0</h2>
<ul>
<li>2019-09-30</li>
<li><a href="0.5.0/release-notes.html">Release Notes</a></li>
<li><a href="/documentation/0.5.0">Documentation</a></li>
</ul>
<table>
<colgroup>
<col width="40%">
<col width="10%">
<col width="10%">
</colgroup>
<thead>
<tr>
<th>Filename</th>
<th>Kind</th>
<th>Size</th>
<th>Sha256</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://ziglang.org/download/0.5.0/zig-0.5.0.tar.xz">zig-0.5.0.tar.xz</a></td>
<td>Source</td>
<td>10.4MiB</td>
<td class="code">55ae16960f152bcb9cf98b4f8570902d0e559a141abf927f0d3555b7cc838a31</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.5.0/zig-linux-x86_64-0.5.0.tar.xz">zig-linux-x86_64-0.5.0.tar.xz</a></td>
<td>Binary</td>
<td>39.0MiB</td>
<td class="code">43e8f8a8b8556edd373ddf9c1ef3ca6cf852d4d09fe07d5736d12fefedd2b4f7</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.5.0/zig-windows-x86_64-0.5.0.zip">zig-windows-x86_64-0.5.0.zip</a></td>
<td>Binary</td>
<td>42.8MiB</td>
<td class="code">58141323db8d84a5af62746be5f9140bc161ee760ef33dc91a887bf9ac021976</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.5.0/zig-macos-x86_64-0.5.0.tar.xz">zig-macos-x86_64-0.5.0.tar.xz</a></td>
<td>Binary</td>
<td>36.1MiB</td>
<td class="code">28702cc05745c7c0bd450487d5f4091bf0a1ad279b35eb9a640ce3e3a15b300d</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.5.0/zig-freebsd-x86_64-0.5.0.tar.xz">zig-freebsd-x86_64-0.5.0.tar.xz</a></td>
<td>Binary</td>
<td>32.1MiB</td>
<td class="code">9e1f4d36c3d584c0aa01f20eb4cd0a0eef3eee5af23e483b8414de55feab6ab6</td>
</tr>
</tbody>
</table>
<h2 id="release-0.4.0">0.4.0</h2>
<ul>
<li>2019-04-08</li>
<li><a href="0.4.0/release-notes.html">Release Notes</a></li>
<li><a href="/documentation/0.4.0">Documentation</a></li>
</ul>
<table>
<colgroup>
<col width="40%">
<col width="10%">
<col width="10%">
</colgroup>
<thead>
<tr>
<th>Filename</th>
<th>Kind</th>
<th>Size</th>
<th>Sha256</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://ziglang.org/download/0.4.0/zig-0.4.0.tar.xz">zig-0.4.0.tar.xz</a></td>
<td>Source</td>
<td>5.1MiB</td>
<td class="code">fec1f3f6b359a3d942e0a7f9157b3b30cde83927627a0e1ea95c54de3c526cfc</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.4.0/zig-linux-x86_64-0.4.0.tar.xz">zig-linux-x86_64-0.4.0.tar.xz</a></td>
<td>Binary</td>
<td>31.4MiB</td>
<td class="code">fb1954e2fb556a01f8079a08130e88f70084e08978ff853bb2b1986d8c39d84e</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.4.0/zig-windows-x86_64-0.4.0.zip">zig-windows-x86_64-0.4.0.zip</a></td>
<td>Binary</td>
<td>34.1MiB</td>
<td class="code">fbc3dd205e064c263063f69f600bedb18e3d0aa2efa747a63ef6cafb6d73f127</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.4.0/zig-macos-x86_64-0.4.0.tar.xz">zig-macos-x86_64-0.4.0.tar.xz</a></td>
<td>Binary</td>
<td>29.4MiB</td>
<td class="code">67c932982484d017c5111e54af9f33f15e8e05c6bc5346a55e04052159c964a8</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.4.0/zig-freebsd-x86_64-0.4.0.tar.xz">zig-freebsd-x86_64-0.4.0.tar.xz</a></td>
<td>Binary</td>
<td>26.0MiB</td>
<td class="code">3d557c91ac36d8262eb1733bb5f261c95944f9b635e43386e3d00a3272818c30</td>
</tr>
</tbody>
</table>
<h2 id="release-0.3.0">0.3.0</h2>
<ul>
<li>2018-09-28</li>
<li><a href="0.3.0/release-notes.html">Release Notes</a></li>
<li><a href="/documentation/0.3.0">Documentation</a></li>
</ul>
<table>
<colgroup>
<col width="40%">
<col width="10%">
<col width="10%">
</colgroup>
<thead>
<tr>
<th>Filename</th>
<th>Kind</th>
<th>Size</th>
<th>Sha256</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://ziglang.org/download/0.3.0/zig-0.3.0.tar.xz">zig-0.3.0.tar.xz</a></td>
<td>Source</td>
<td>2.2MiB</td>
<td class="code">d70af604f3a8622f3393d93abb3e056bf60351e32d121e6fa4fe03d8d41e1f5a</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.3.0/zig-linux-x86_64-0.3.0.tar.xz">zig-linux-x86_64-0.3.0.tar.xz</a></td>
<td>Binary</td>
<td>24.0MiB</td>
<td class="code">b378d0aae30cb54f28494e7bc4efbc9bfb6326f47bfb302e8b5287af777b2f3c</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.3.0/zig-windows-x86_64-0.3.0.zip">zig-windows-x86_64-0.3.0.zip</a></td>
<td>Binary</td>
<td>21.5MiB</td>
<td class="code">bb568c03950958f8bb3472139c3ab5ed74547c8c694ab50f404c202faf51baf4</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.3.0/zig-macos-x86_64-0.3.0.tar.xz">zig-macos-x86_64-0.3.0.tar.xz</a></td>
<td>Binary</td>
<td>22.6MiB</td>
<td class="code">19dec1f1943ab7be26823376d466f7e456143deb34e17502778a949034dc2e7e</td>
</tr>
</tbody>
</table>
<h2 id="release-0.2.0">0.2.0</h2>
<ul>
<li>2018-03-15</li>
<li><a href="0.2.0/release-notes.html">Release Notes</a></li>
<li><a href="/documentation/0.2.0">Documentation</a></li>
</ul>
<table>
<colgroup>
<col width="40%">
<col width="10%">
<col width="10%">
</colgroup>
<thead>
<tr>
<th>Filename</th>
<th>Kind</th>
<th>Size</th>
<th>Sha256</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://ziglang.org/download/0.2.0/zig-0.2.0.tar.xz">zig-0.2.0.tar.xz</a></td>
<td>Source</td>
<td>1.9MiB</td>
<td class="code">29c9beb172737f4d5019b88ceae829ae8bc6512fb4386cfbf895ae2b42aa6965</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.2.0/zig-linux-x86_64-0.2.0.tar.xz">zig-linux-x86_64-0.2.0.tar.xz</a></td>
<td>Binary</td>
<td>23.5MiB</td>
<td class="code">209c6fb745d42474c0a73d6f291c7ae3a38b6a1b6b641eea285a7f840cc1a890</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.2.0/zig-win64-0.2.0.zip">zig-win64-0.2.0.zip</a></td>
<td>Binary</td>
<td>20.6MiB</td>
<td class="code">4f8a2979941a1f081ec8e545cca0b72608c0db1c5a3fd377a94db40649dcd3d4</td>
</tr>
</tbody>
</table>
<h2 id="release-0.1.1">0.1.1</h2>
<ul>
<li>2017-10-17</li>
<li><a href="0.1.1/release-notes.html">Release Notes</a></li>
<li><a href="/documentation/0.1.1">Documentation</a></li>
</ul>
<table>
<colgroup>
<col width="40%">
<col width="10%">
<col width="10%">
</colgroup>
<thead>
<tr>
<th>Filename</th>
<th>Kind</th>
<th>Size</th>
<th>Sha256</th>
</tr>
</thead>
<tbody>
<tr>
<td><a href="https://ziglang.org/download/0.1.1/zig-0.1.1.tar.xz">zig-0.1.1.tar.xz</a></td>
<td>Source</td>
<td>1.62MiB</td>
<td class="code">ffca0cfb263485287e19cc997b08701fcd5f24b700345bcdc3dd8074f5a104e0</td>
</tr>
<tr>
<td><a href="https://ziglang.org/download/0.1.1/zig-win64-0.1.1.zip">zig-win64-0.1.1.zip</a></td>
<td>Binary</td>
<td>19.3MiB</td>
<td class="code">6fc88bef531af7e567fe30bf60da1487b86833cbee84c7a2f3e317030aa5b660</td>
</tr>
</tbody>
</table>
</div>
</body>
</html>

356
ci/srht/index.json Normal file
View File

@@ -0,0 +1,356 @@
{
"master": {
"version": "{{MASTER_VERSION}}",
"date": "{{MASTER_DATE}}",
"docs": "https://ziglang.org/documentation/master/",
"stdDocs": "https://ziglang.org/documentation/master/std/",
"src": {
"tarball": "https://ziglang.org/builds/{{SRC_TARBALL}}",
"shasum": "{{SRC_SHASUM}}",
"size": "{{SRC_BYTESIZE}}"
},
"x86_64-freebsd": {
"tarball": "https://ziglang.org/builds/{{X86_64_FREEBSD_TARBALL}}",
"shasum": "{{X86_64_FREEBSD_SHASUM}}",
"size": "{{X86_64_FREEBSD_BYTESIZE}}"
},
"x86_64-macos": {
"tarball": "https://ziglang.org/builds/{{X86_64_MACOS_TARBALL}}",
"shasum": "{{X86_64_MACOS_SHASUM}}",
"size": "{{X86_64_MACOS_BYTESIZE}}"
},
"aarch64-macos": {
"tarball": "https://ziglang.org/builds/{{AARCH64_MACOS_TARBALL}}",
"shasum": "{{AARCH64_MACOS_SHASUM}}",
"size": "{{AARCH64_MACOS_BYTESIZE}}"
},
"x86_64-windows": {
"tarball": "https://ziglang.org/builds/{{X86_64_WINDOWS_TARBALL}}",
"shasum": "{{X86_64_WINDOWS_SHASUM}}",
"size": "{{X86_64_WINDOWS_BYTESIZE}}"
},
"x86_64-linux": {
"tarball": "https://ziglang.org/builds/{{X86_64_LINUX_TARBALL}}",
"shasum": "{{X86_64_LINUX_SHASUM}}",
"size": "{{X86_64_LINUX_BYTESIZE}}"
},
"aarch64-linux": {
"tarball": "https://ziglang.org/builds/{{AARCH64_LINUX_TARBALL}}",
"shasum": "{{AARCH64_LINUX_SHASUM}}",
"size": "{{AARCH64_LINUX_BYTESIZE}}"
}
},
"0.7.1": {
"date": "2020-12-13",
"docs": "https://ziglang.org/documentation/0.7.1/",
"stdDocs": "https://ziglang.org/documentation/0.7.1/std/",
"notes": "https://ziglang.org/download/0.7.1/release-notes.html",
"src": {
"tarball": "https://ziglang.org/download/0.7.1/zig-0.7.1.tar.xz",
"shasum": "2db3b944ab368d955b48743d9f7c963b8f96de1a441ba5a35e197237cc6dae44",
"size": "10711824"
},
"bootstrap": {
"tarball": "https://ziglang.org/download/0.7.1/zig-bootstrap-0.7.1.tar.xz",
"shasum": "040f27c1fae4b0cac0a2782aecdb691f6a2f8e89db6a6ed35024c31c304fd9b2",
"size": "40232612"
},
"x86_64-freebsd": {
"tarball": "https://ziglang.org/download/0.7.1/zig-freebsd-x86_64-0.7.1.tar.xz",
"shasum": "e73c1dca35791a3183fdd5ecde0443ebbe180942efceafe651886034fb8def09",
"size": "39066808"
},
"aarch64-linux": {
"tarball": "https://ziglang.org/download/0.7.1/zig-linux-aarch64-0.7.1.tar.xz",
"shasum": "48ec90eba407e4587ddef7eecef25fec7e13587eb98e3b83c5f2f5fff2a5cbe7",
"size": "33780552"
},
"armv7a-linux": {
"tarball": "https://ziglang.org/download/0.7.1/zig-linux-armv7a-0.7.1.tar.xz",
"shasum": "5a0662e07b4c4968665e1f97558f8591f6facec45d2e0ff5715e661743107ceb",
"size": "35813504"
},
"i386-linux": {
"tarball": "https://ziglang.org/download/0.7.1/zig-linux-i386-0.7.1.tar.xz",
"shasum": "4882e052e5f83690bd0334bb4fc1702b5403cb3a3d2aa63fd7d6043d8afecba3",
"size": "39230912"
},
"riscv64-linux": {
"tarball": "https://ziglang.org/download/0.7.1/zig-linux-riscv64-0.7.1.tar.xz",
"shasum": "187294bfd35983348c3fe042901b42e67e7e36ab7f77a5f969d21c0051f4d21f",
"size": "37454812"
},
"x86_64-linux": {
"tarball": "https://ziglang.org/download/0.7.1/zig-linux-x86_64-0.7.1.tar.xz",
"shasum": "18c7b9b200600f8bcde1cd8d7f1f578cbc3676241ce36d771937ce19a8159b8d",
"size": "37848176"
},
"x86_64-macos": {
"tarball": "https://ziglang.org/download/0.7.1/zig-macos-x86_64-0.7.1.tar.xz",
"shasum": "845cb17562978af0cf67e3993f4e33330525eaf01ead9386df9105111e3bc519",
"size": "36211076"
},
"i386-windows": {
"tarball": "https://ziglang.org/download/0.7.1/zig-windows-i386-0.7.1.zip",
"shasum": "a1b9a7421e13153e07fd2e2c93ff29aad64d83105b8fcdafa633dbe689caf1c0",
"size": "54374983"
},
"x86_64-windows": {
"tarball": "https://ziglang.org/download/0.7.1/zig-windows-x86_64-0.7.1.zip",
"shasum": "4818a8a65b4672bc52c0ae7f14d014e0eb8caf10f12c0745176820384cea296a",
"size": "54909997"
}
},
"0.7.0": {
"date": "2020-11-08",
"docs": "https://ziglang.org/documentation/0.7.0/",
"stdDocs": "https://ziglang.org/documentation/0.7.0/std/",
"notes": "https://ziglang.org/download/0.7.0/release-notes.html",
"src": {
"tarball": "https://ziglang.org/download/0.7.0/zig-0.7.0.tar.xz",
"shasum": "0efd2cf6c3b05723db80e9cf193bc55150bba84ca41f855a90f53fc756445f83",
"size": "10683920"
},
"bootstrap": {
"tarball": "https://ziglang.org/download/0.7.0/zig-bootstrap-0.7.0.tar.xz",
"shasum": "f073beaf5c53c8c57c0d374cbfcb332ef92ad703173edba0d9e0f2ed28401b72",
"size": "40200436"
},
"x86_64-freebsd": {
"tarball": "https://ziglang.org/download/0.7.0/zig-freebsd-x86_64-0.7.0.tar.xz",
"shasum": "a0c926272ee4ae720034b4a6a1dc98399d76156dd84182554740f0ca8a41fc99",
"size": "34798992"
},
"aarch64-linux": {
"tarball": "https://ziglang.org/download/0.7.0/zig-linux-aarch64-0.7.0.tar.xz",
"shasum": "f89933bac87d44be82325754ff88423020c81c7032a6fc41cfeb81e982eeab9b",
"size": "33096140"
},
"armv7a-linux": {
"tarball": "https://ziglang.org/download/0.7.0/zig-linux-armv7a-0.7.0.tar.xz",
"shasum": "011c267e25a96ee160505a560c441daa045359a9d50e13ab1bada9d75c95db2d",
"size": "35157584"
},
"i386-linux": {
"tarball": "https://ziglang.org/download/0.7.0/zig-linux-i386-0.7.0.tar.xz",
"shasum": "4bb2072cd363bcb1cbeb4872ff5cbc1f683b02d0cc1f90c46e3ea7422ce53222",
"size": "38530596"
},
"riscv64-linux": {
"tarball": "https://ziglang.org/download/0.7.0/zig-linux-riscv64-0.7.0.tar.xz",
"shasum": "40dff81faa6f232ac40abbf88b9371f3cc932b6e09c423b94387c9ea580cb7be",
"size": "36759992"
},
"x86_64-linux": {
"tarball": "https://ziglang.org/download/0.7.0/zig-linux-x86_64-0.7.0.tar.xz",
"shasum": "e619b1c6094c095b932767f527aee2507f847ea981513ff8a08aab0fd730e0ac",
"size": "37154432"
},
"aarch64-macos": {
"tarball": "https://ziglang.org/download/0.7.0/zig-macos-aarch64-0.7.0.tar.xz",
"shasum": "338238035734db74ea4f30e500a4893bf741d38305c10952d5e39fa05bdb057d",
"size": "33739424"
},
"x86_64-macos": {
"tarball": "https://ziglang.org/download/0.7.0/zig-macos-x86_64-0.7.0.tar.xz",
"shasum": "94063f9a311cbbf7a2e0a12295e09437182cf950f18cb0eb30ea9893f3677f24",
"size": "35258328"
},
"i386-windows": {
"tarball": "https://ziglang.org/download/0.7.0/zig-windows-i386-0.7.0.zip",
"shasum": "b1e520aacbfbd645ff3521b3eb4d44166d9a0288b8725e4b001f8b50a425eb2e",
"size": "53390517"
},
"x86_64-windows": {
"tarball": "https://ziglang.org/download/0.7.0/zig-windows-x86_64-0.7.0.zip",
"shasum": "965f56c0a36f9cda2125e3a348bc654f7f155e2804c3667d231775ec228f8553",
"size": "53943784"
}
},
"0.6.0": {
"date": "2020-04-13",
"docs": "https://ziglang.org/documentation/0.6.0/",
"stdDocs": "https://ziglang.org/documentation/0.6.0/std/",
"notes": "https://ziglang.org/download/0.6.0/release-notes.html",
"src": {
"tarball": "https://ziglang.org/download/0.6.0/zig-0.6.0.tar.xz",
"shasum": "5d167dc19354282dd35dd17b38e99e1763713b9be8a4ba9e9e69284e059e7204",
"size": "10349552"
},
"bootstrap": {
"tarball": "https://ziglang.org/download/0.6.0/zig-bootstrap-0.6.0.tar.xz",
"shasum": "5e0e4dc878b3dd0c1852a442b174f0732e8c07869a8fcd226b71a93b89b381ab",
"size": "38469948"
},
"x86_64-freebsd": {
"tarball": "https://ziglang.org/download/0.6.0/zig-freebsd-x86_64-0.6.0.tar.xz",
"shasum": "190ff79c1eb56805a315d7c7a51082e32f62926250c0702b36760c225e1634a3",
"size": "36974604"
},
"aarch64-linux": {
"tarball": "https://ziglang.org/download/0.6.0/zig-linux-aarch64-0.6.0.tar.xz",
"shasum": "e7520efd42cfa02be48c2e430d08fe1f3cbb999d21d9f0d3ffd0febb976b2f41",
"size": "37090044"
},
"armv6kz-linux": {
"tarball": "https://ziglang.org/download/0.6.0/zig-linux-armv6kz-0.6.0.tar.xz",
"shasum": "36b6493b3fed43eb1f0000e765798ad31a6bb7d7fd3f553ac1c3761dbc919b82",
"size": "39133452"
},
"armv7a-linux": {
"tarball": "https://ziglang.org/download/0.6.0/zig-linux-armv7a-0.6.0.tar.xz",
"shasum": "946969abe357def95ca9cbbfcebfcf2d90cf967bcd3f48ee87662e32d91d8f35",
"size": "39143748"
},
"i386-linux": {
"tarball": "https://ziglang.org/download/0.6.0/zig-linux-i386-0.6.0.tar.xz",
"shasum": "a97a2f9ae21575743cdd763c1917d49400d83fc562ef64582b18bade43eb24ce",
"size": "44877640"
},
"riscv64-linux": {
"tarball": "https://ziglang.org/download/0.6.0/zig-linux-riscv64-0.6.0.tar.xz",
"shasum": "68ddee43f7503c8ae5f26a921f3602c34719a02ed2241f528c0b8b888cc14b38",
"size": "41993144"
},
"x86_64-linux": {
"tarball": "https://ziglang.org/download/0.6.0/zig-linux-x86_64-0.6.0.tar.xz",
"shasum": "08fd3c757963630645441c2772362e9c2294020c44f14fce1b89f45de0dc1253",
"size": "44766320"
},
"x86_64-macos": {
"tarball": "https://ziglang.org/download/0.6.0/zig-macos-x86_64-0.6.0.tar.xz",
"shasum": "17270360e87ddc49f737e760047b2fac49f1570a824a306119b1194ac4093895",
"size": "42573184"
},
"i386-windows": {
"tarball": "https://ziglang.org/download/0.6.0/zig-windows-i386-0.6.0.zip",
"shasum": "3b0a02618743e92175990dc6d1a787bb95ff62c4cda016f1c14c7786f575f8ca",
"size": "60446431"
},
"x86_64-windows": {
"tarball": "https://ziglang.org/download/0.6.0/zig-windows-x86_64-0.6.0.zip",
"shasum": "c3b897832523e1026e10b2d8d55d7f895185c0a27a63681f3a23219c3f1c38f4",
"size": "49065511"
}
},
"0.5.0": {
"date": "2019-09-30",
"docs": "https://ziglang.org/documentation/0.5.0/",
"notes": "https://ziglang.org/download/0.5.0/release-notes.html",
"src": {
"tarball": "https://ziglang.org/download/0.5.0/zig-0.5.0.tar.xz",
"shasum": "55ae16960f152bcb9cf98b4f8570902d0e559a141abf927f0d3555b7cc838a31",
"size": "10956132"
},
"x86_64-freebsd": {
"tarball": "https://ziglang.org/download/0.5.0/zig-freebsd-x86_64-0.5.0.tar.xz",
"shasum": "9e1f4d36c3d584c0aa01f20eb4cd0a0eef3eee5af23e483b8414de55feab6ab6",
"size": "33650744"
},
"x86_64-macos": {
"tarball": "https://ziglang.org/download/0.5.0/zig-macos-x86_64-0.5.0.tar.xz",
"shasum": "28702cc05745c7c0bd450487d5f4091bf0a1ad279b35eb9a640ce3e3a15b300d",
"size": "37898664"
},
"x86_64-windows": {
"tarball": "https://ziglang.org/download/0.5.0/zig-windows-x86_64-0.5.0.zip",
"shasum": "58141323db8d84a5af62746be5f9140bc161ee760ef33dc91a887bf9ac021976",
"size": "44871804"
},
"x86_64-linux": {
"tarball": "https://ziglang.org/download/0.5.0/zig-linux-x86_64-0.5.0.tar.xz",
"shasum": "43e8f8a8b8556edd373ddf9c1ef3ca6cf852d4d09fe07d5736d12fefedd2b4f7",
"size": "40895068"
}
},
"0.4.0": {
"date": "2019-04-08",
"docs": "https://ziglang.org/documentation/0.4.0/",
"notes": "https://ziglang.org/download/0.4.0/release-notes.html",
"src": {
"tarball": "https://ziglang.org/download/0.4.0/zig-0.4.0.tar.xz",
"shasum": "fec1f3f6b359a3d942e0a7f9157b3b30cde83927627a0e1ea95c54de3c526cfc",
"size": "5348776"
},
"x86_64-freebsd": {
"tarball": "https://ziglang.org/download/0.4.0/zig-freebsd-x86_64-0.4.0.tar.xz",
"shasum": "3d557c91ac36d8262eb1733bb5f261c95944f9b635e43386e3d00a3272818c30",
"size": "27269672"
},
"x86_64-macos": {
"tarball": "https://ziglang.org/download/0.4.0/zig-macos-x86_64-0.4.0.tar.xz",
"shasum": "67c932982484d017c5111e54af9f33f15e8e05c6bc5346a55e04052159c964a8",
"size": "30841504"
},
"x86_64-windows": {
"tarball": "https://ziglang.org/download/0.4.0/zig-windows-x86_64-0.4.0.zip",
"shasum": "fbc3dd205e064c263063f69f600bedb18e3d0aa2efa747a63ef6cafb6d73f127",
"size": "35800101"
},
"x86_64-linux": {
"tarball": "https://ziglang.org/download/0.4.0/zig-linux-x86_64-0.4.0.tar.xz",
"shasum": "fb1954e2fb556a01f8079a08130e88f70084e08978ff853bb2b1986d8c39d84e",
"size": "32876100"
}
},
"0.3.0": {
"date": "2018-09-28",
"docs": "https://ziglang.org/documentation/0.3.0/",
"notes": "https://ziglang.org/download/0.3.0/release-notes.html",
"src": {
"tarball": "https://ziglang.org/download/0.3.0/zig-0.3.0.tar.xz",
"shasum": "d70af604f3a8622f3393d93abb3e056bf60351e32d121e6fa4fe03d8d41e1f5a",
"size": "2335592"
},
"x86_64-macos": {
"tarball": "https://ziglang.org/download/0.3.0/zig-macos-x86_64-0.3.0.tar.xz",
"shasum": "19dec1f1943ab7be26823376d466f7e456143deb34e17502778a949034dc2e7e",
"size": "23712696"
},
"x86_64-windows": {
"tarball": "https://ziglang.org/download/0.3.0/zig-windows-x86_64-0.3.0.zip",
"shasum": "bb568c03950958f8bb3472139c3ab5ed74547c8c694ab50f404c202faf51baf4",
"size": "22524425"
},
"x86_64-linux": {
"tarball": "https://ziglang.org/download/0.3.0/zig-linux-x86_64-0.3.0.tar.xz",
"shasum": "b378d0aae30cb54f28494e7bc4efbc9bfb6326f47bfb302e8b5287af777b2f3c",
"size": "25209304"
}
},
"0.2.0": {
"date": "2018-03-15",
"docs": "https://ziglang.org/documentation/0.2.0/",
"notes": "https://ziglang.org/download/0.2.0/release-notes.html",
"src": {
"tarball": "https://ziglang.org/download/0.2.0/zig-0.2.0.tar.xz",
"shasum": "29c9beb172737f4d5019b88ceae829ae8bc6512fb4386cfbf895ae2b42aa6965",
"size": "1940832"
},
"x86_64-windows": {
"tarball": "https://ziglang.org/download/0.2.0/zig-win64-0.2.0.zip",
"shasum": "4f8a2979941a1f081ec8e545cca0b72608c0db1c5a3fd377a94db40649dcd3d4",
"size": "21076274"
},
"x86_64-linux": {
"tarball": "https://ziglang.org/download/0.2.0/zig-linux-x86_64-0.2.0.tar.xz",
"shasum": "209c6fb745d42474c0a73d6f291c7ae3a38b6a1b6b641eea285a7f840cc1a890",
"size": "22551928"
}
},
"0.1.1": {
"date": "2017-10-17",
"docs": "https://ziglang.org/documentation/0.1.1/",
"notes": "https://ziglang.org/download/0.1.1/release-notes.html",
"src": {
"tarball": "https://ziglang.org/download/0.1.1/zig-0.1.1.tar.xz",
"shasum": "ffca0cfb263485287e19cc997b08701fcd5f24b700345bcdc3dd8074f5a104e0",
"size": "1659716"
},
"x86_64-windows": {
"tarball": "https://ziglang.org/download/0.1.1/zig-win64-0.1.1.zip",
"shasum": "6fc88bef531af7e567fe30bf60da1487b86833cbee84c7a2f3e317030aa5b660",
"size": "19757776"
}
}
}

40
ci/srht/on_master_success Executable file
View File

@@ -0,0 +1,40 @@
#!/bin/sh
# This script must run on a lot of different platforms.
# It assumes that the following things are installed:
# * curl
# * jq
# * cat
# We do not set -x because this would leak the oauth access token.
set +x
set -e
VERSION="$1"
OAUTH_TOKEN="$2"
YML_FILE="tmp.yml"
cat <<EOF >"$YML_FILE"
image: alpine/latest
packages:
- py3-pip
- curl
- jq
- xz
secrets:
- 51bfddf5-86a6-4e01-8576-358c72a4a0a4
- 44e2bd57-1d07-42bf-925e-22a36119041d
sources:
- https://github.com/ziglang/zig
tasks:
- build: cd zig && ./ci/srht/update_download_page $VERSION
EOF
jq <$YML_FILE -sR '{
"manifest": .,
}' | curl \
-H Authorization:"token $OAUTH_TOKEN" \
-H Content-Type:application/json \
-X POST \
-d @- "https://builds.hut.lavatech.top/api/jobs"

View File

@@ -0,0 +1,104 @@
const std = @import("std");
const path = std.fs.path;
const mem = std.mem;
pub fn main() !void {
var arena = std.heap.ArenaAllocator.init(std.heap.page_allocator);
defer arena.deinit();
const allocator = &arena.allocator;
const out_dir = "out";
try std.fs.cwd().makePath(out_dir);
{
const out_file = out_dir ++ path.sep_str ++ "index.html";
const in_file = "index.html";
try render(allocator, in_file, out_file, .html);
}
{
const out_file = out_dir ++ path.sep_str ++ "index.json";
const in_file = "index.json";
try render(allocator, in_file, out_file, .plain);
}
}
fn render(
allocator: *mem.Allocator,
in_file: []const u8,
out_file: []const u8,
fmt: enum {
html,
plain,
},
) !void {
const in_contents = try std.fs.cwd().readFileAlloc(allocator, in_file, 1 * 1024 * 1024);
var vars = try std.process.getEnvMap(allocator);
var buffer = std.ArrayList(u8).init(allocator);
defer buffer.deinit();
const State = enum {
Start,
OpenBrace,
VarName,
EndBrace,
};
const writer = buffer.writer();
var state = State.Start;
var var_name_start: usize = undefined;
var line: usize = 1;
for (in_contents) |byte, index| {
switch (state) {
State.Start => switch (byte) {
'{' => {
state = State.OpenBrace;
},
else => try writer.writeByte(byte),
},
State.OpenBrace => switch (byte) {
'{' => {
state = State.VarName;
var_name_start = index + 1;
},
else => {
try writer.writeByte('{');
try writer.writeByte(byte);
state = State.Start;
},
},
State.VarName => switch (byte) {
'}' => {
const var_name = in_contents[var_name_start..index];
if (vars.get(var_name)) |value| {
const trimmed = mem.trim(u8, value, " \r\n");
if (fmt == .html and mem.endsWith(u8, var_name, "BYTESIZE")) {
const size = try std.fmt.parseInt(u64, trimmed, 10);
try writer.print("{:.1}", .{std.fmt.fmtIntSizeDec(size)});
} else {
try writer.writeAll(trimmed);
}
} else {
std.debug.warn("line {d}: missing variable: {s}\n", .{ line, var_name });
try writer.writeAll("(missing)");
}
state = State.EndBrace;
},
else => {},
},
State.EndBrace => switch (byte) {
'}' => {
state = State.Start;
},
else => {
std.debug.warn("line {d}: invalid byte: '0x{x}'", .{ line, byte });
std.process.exit(1);
},
},
}
if (byte == '\n') {
line += 1;
}
}
try std.fs.cwd().writeFile(out_file, buffer.items);
}

112
ci/srht/update_download_page Executable file
View File

@@ -0,0 +1,112 @@
#!/bin/sh
set -x
set -e
VERSION="$1"
SRCDIR="$(pwd)"
NATIVE_TARBALL="zig-linux-$(uname -m)-$VERSION.tar.xz"
# Check for all the builds being completed. It's expected that this script is run several times
# before they are all complete.
AARCH64_LINUX_JSON_URL="https://ziglang.org/builds/aarch64-linux-$VERSION.json"
X86_64_LINUX_JSON_URL="https://ziglang.org/builds/x86_64-linux-$VERSION.json"
X86_64_WINDOWS_JSON_URL="https://ziglang.org/builds/x86_64-windows-$VERSION.json"
AARCH64_MACOS_JSON_URL="https://ziglang.org/builds/aarch64-macos-$VERSION.json"
X86_64_MACOS_JSON_URL="https://ziglang.org/builds/x86_64-macos-$VERSION.json"
X86_64_FREEBSD_JSON_URL="https://ziglang.org/builds/x86_64-freebsd-$VERSION.json"
# If any of these fail, it's not really this job failing; rather we have detected
# that this job will be called again later when other jobs have completed.
curl --fail -I "$AARCH64_LINUX_JSON_URL" >/dev/null || exit 0
curl --fail -I "$X86_64_LINUX_JSON_URL" >/dev/null || exit 0
curl --fail -I "$X86_64_WINDOWS_JSON_URL" >/dev/null || exit 0
curl --fail -I "$AARCH64_MACOS_JSON_URL" >/dev/null || exit 0
curl --fail -I "$X86_64_MACOS_JSON_URL" >/dev/null || exit 0
curl --fail -I "$X86_64_FREEBSD_JSON_URL" >/dev/null || exit 0
# Without --user, this gave me:
# ERROR: Could not install packages due to an EnvironmentError: [Errno 13] Permission denied
pip3 install s3cmd --user
S3CMD="$HOME/.local/bin/s3cmd"
# This is the user when pushing to the website repo.
git config --global user.email "ziggy@ziglang.org"
git config --global user.name "Ziggy"
# Refresh this with `ssh-keyscan github.com` from a trusted Internet connection.
# We hard code the public key here to detect man-in-the-middle attacks.
echo "github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==" >> ~/.ssh/known_hosts
# We don't want the .git folder inside the tarball.
rm -rf .git
cd "$HOME"
wget "https://ziglang.org/builds/$NATIVE_TARBALL"
tar xf "$NATIVE_TARBALL"
ZIGDIR="$(pwd)/$(basename $NATIVE_TARBALL .tar.xz)"
ZIG="$ZIGDIR/zig"
LANGREF="$ZIGDIR/docs/langref.html"
SRCTARBALLDIR="zig-$VERSION"
export SRC_TARBALL="$SRCTARBALLDIR.tar.xz"
mv "$SRCDIR" "$SRCTARBALLDIR"
tar cfJ "$SRC_TARBALL" "$SRCTARBALLDIR"
export SRC_SHASUM=$(sha256sum $SRC_TARBALL | cut '-d ' -f1)
export SRC_BYTESIZE=$(wc -c < $SRC_TARBALL)
X86_64_WINDOWS_JSON=$(curl --fail "$X86_64_WINDOWS_JSON_URL" || exit 1)
export X86_64_WINDOWS_TARBALL="$(echo "$X86_64_WINDOWS_JSON" | jq .tarball -r)"
export X86_64_WINDOWS_BYTESIZE="$(echo "$X86_64_WINDOWS_JSON" | jq .size -r)"
export X86_64_WINDOWS_SHASUM="$(echo "$X86_64_WINDOWS_JSON" | jq .shasum -r)"
AARCH64_MACOS_JSON=$(curl --fail "$AARCH64_MACOS_JSON_URL" || exit 1)
export AARCH64_MACOS_TARBALL="$(echo "$AARCH64_MACOS_JSON" | jq .tarball -r)"
export AARCH64_MACOS_BYTESIZE="$(echo "$AARCH64_MACOS_JSON" | jq .size -r)"
export AARCH64_MACOS_SHASUM="$(echo "$AARCH64_MACOS_JSON" | jq .shasum -r)"
X86_64_MACOS_JSON=$(curl --fail "$X86_64_MACOS_JSON_URL" || exit 1)
export X86_64_MACOS_TARBALL="$(echo "$X86_64_MACOS_JSON" | jq .tarball -r)"
export X86_64_MACOS_BYTESIZE="$(echo "$X86_64_MACOS_JSON" | jq .size -r)"
export X86_64_MACOS_SHASUM="$(echo "$X86_64_MACOS_JSON" | jq .shasum -r)"
X86_64_LINUX_JSON=$(curl --fail "$X86_64_LINUX_JSON_URL" || exit 1)
export X86_64_LINUX_TARBALL="$(echo "$X86_64_LINUX_JSON" | jq .tarball -r)"
export X86_64_LINUX_BYTESIZE="$(echo "$X86_64_LINUX_JSON" | jq .size -r)"
export X86_64_LINUX_SHASUM="$(echo "$X86_64_LINUX_JSON" | jq .shasum -r)"
AARCH64_LINUX_JSON=$(curl --fail "$AARCH64_LINUX_JSON_URL" || exit 1)
export AARCH64_LINUX_TARBALL="$(echo "$AARCH64_LINUX_JSON" | jq .tarball -r)"
export AARCH64_LINUX_BYTESIZE="$(echo "$AARCH64_LINUX_JSON" | jq .size -r)"
export AARCH64_LINUX_SHASUM="$(echo "$AARCH64_LINUX_JSON" | jq .shasum -r)"
X86_64_FREEBSD_JSON=$(curl --fail "$X86_64_FREEBSD_JSON_URL" || exit 1)
export X86_64_FREEBSD_TARBALL="$(echo "$X86_64_FREEBSD_JSON" | jq .tarball -r)"
export X86_64_FREEBSD_BYTESIZE="$(echo "$X86_64_FREEBSD_JSON" | jq .size -r)"
export X86_64_FREEBSD_SHASUM="$(echo "$X86_64_FREEBSD_JSON" | jq .shasum -r)"
export MASTER_DATE="$(date +%Y-%m-%d)"
export MASTER_VERSION="$VERSION"
cd "$SRCTARBALLDIR/ci/srht"
"$ZIG" run update-download-page.zig
CIDIR="$(pwd)"
# Create index.json and index.html and update the website repo.
cd "$HOME"
git clone git@github.com:ziglang/www.ziglang.org.git
cd www.ziglang.org
WWWDIR="$(pwd)"
$S3CMD put -P --no-mime-magic --add-header="cache-control: public, max-age=31536000, immutable" "$HOME/$SRC_TARBALL" s3://ziglang.org/builds/
cd "$WWWDIR"
cp "$CIDIR/out/index.json" data/releases.json
mkdir -p content/documentation/master/std
cp "$LANGREF" content/documentation/master/index.html
cp "$ZIGDIR/docs/std/index.html" content/documentation/master/std/index.html
cp "$ZIGDIR/docs/std/data.js" content/documentation/master/std/data.js
cp "$ZIGDIR/docs/std/main.js" content/documentation/master/std/main.js
git add data/releases.json
git add content/
git commit -m "CI: update releases and docs"
git push origin master

View File

@@ -7,58 +7,50 @@
# CLANG_LIBRARIES
# CLANG_LIBDIRS
if(MSVC)
find_package(CLANG REQUIRED CONFIG)
find_path(CLANG_INCLUDE_DIRS NAMES clang/Frontend/ASTUnit.h
PATHS
/usr/lib/llvm/12/include
/usr/lib/llvm-12/include
/usr/lib/llvm-12.0/include
/usr/local/llvm120/include
/usr/local/llvm12/include
/mingw64/include
)
set(CLANG_LIBRARIES
clangFrontendTool
clangCodeGen
clangFrontend
clangDriver
clangSerialization
clangSema
clangStaticAnalyzerFrontend
clangStaticAnalyzerCheckers
clangStaticAnalyzerCore
clangAnalysis
clangASTMatchers
clangAST
clangParse
clangSema
clangBasic
clangEdit
clangLex
clangARCMigrate
clangRewriteFrontend
clangRewrite
clangCrossTU
clangIndex
if(ZIG_PREFER_CLANG_CPP_DYLIB)
find_library(CLANG_LIBRARIES
NAMES
clang-cpp-12.0
clang-cpp120
clang-cpp
PATHS
${CLANG_LIBDIRS}
/usr/lib/llvm/12/lib
/usr/lib/llvm/12/lib64
/usr/lib/llvm-12/lib
/usr/local/llvm120/lib
/usr/local/llvm12/lib
)
endif()
else()
find_path(CLANG_INCLUDE_DIRS NAMES clang/Frontend/ASTUnit.h
PATHS
/usr/lib/llvm/9/include
/usr/lib/llvm-9/include
/usr/lib/llvm-9.0/include
/usr/local/llvm90/include
/mingw64/include)
if(NOT CLANG_LIBRARIES)
macro(FIND_AND_ADD_CLANG_LIB _libname_)
string(TOUPPER ${_libname_} _prettylibname_)
find_library(CLANG_${_prettylibname_}_LIB NAMES ${_libname_}
PATHS
${CLANG_LIBDIRS}
/usr/lib/llvm/9/lib
/usr/lib/llvm-9/lib
/usr/lib/llvm-9.0/lib
/usr/local/llvm90/lib
/mingw64/lib
/c/msys64/mingw64/lib
c:\\msys64\\mingw64\\lib)
if(CLANG_${_prettylibname_}_LIB)
set(CLANG_LIBRARIES ${CLANG_LIBRARIES} ${CLANG_${_prettylibname_}_LIB})
endif()
string(TOUPPER ${_libname_} _prettylibname_)
find_library(CLANG_${_prettylibname_}_LIB NAMES ${_libname_}
PATHS
${CLANG_LIBDIRS}
/usr/lib/llvm/12/lib
/usr/lib/llvm-12/lib
/usr/lib/llvm-12.0/lib
/usr/local/llvm120/lib
/usr/local/llvm12/lib
/mingw64/lib
/c/msys64/mingw64/lib
c:\\msys64\\mingw64\\lib
)
if(CLANG_${_prettylibname_}_LIB)
set(CLANG_LIBRARIES ${CLANG_LIBRARIES} ${CLANG_${_prettylibname_}_LIB})
endif()
endmacro(FIND_AND_ADD_CLANG_LIB)
FIND_AND_ADD_CLANG_LIB(clangFrontendTool)
@@ -83,9 +75,10 @@ else()
FIND_AND_ADD_CLANG_LIB(clangRewrite)
FIND_AND_ADD_CLANG_LIB(clangCrossTU)
FIND_AND_ADD_CLANG_LIB(clangIndex)
FIND_AND_ADD_CLANG_LIB(clangToolingCore)
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(CLANG DEFAULT_MSG CLANG_LIBRARIES CLANG_INCLUDE_DIRS)
find_package_handle_standard_args(clang DEFAULT_MSG CLANG_LIBRARIES CLANG_INCLUDE_DIRS)
mark_as_advanced(CLANG_INCLUDE_DIRS CLANG_LIBRARIES CLANG_LIBDIRS)

View File

@@ -8,14 +8,16 @@
find_path(LLD_INCLUDE_DIRS NAMES lld/Common/Driver.h
PATHS
/usr/lib/llvm-9.0/include
/usr/local/llvm90/include
/usr/lib/llvm-12/include
/usr/local/llvm120/include
/usr/local/llvm12/include
/mingw64/include)
find_library(LLD_LIBRARY NAMES lld-9.0 lld90 lld
find_library(LLD_LIBRARY NAMES lld-12.0 lld120 lld
PATHS
/usr/lib/llvm-9.0/lib
/usr/local/llvm90/lib
/usr/lib/llvm-12/lib
/usr/local/llvm120/lib
/usr/local/llvm12/lib
)
if(EXISTS ${LLD_LIBRARY})
set(LLD_LIBRARIES ${LLD_LIBRARY})
@@ -24,8 +26,10 @@ else()
string(TOUPPER ${_libname_} _prettylibname_)
find_library(LLD_${_prettylibname_}_LIB NAMES ${_libname_}
PATHS
/usr/lib/llvm-9.0/lib
/usr/local/llvm90/lib
${LLD_LIBDIRS}
/usr/lib/llvm-12/lib
/usr/local/llvm120/lib
/usr/local/llvm12/lib
/mingw64/lib
/c/msys64/mingw64/lib
c:/msys64/mingw64/lib)
@@ -47,6 +51,6 @@ else()
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LLD DEFAULT_MSG LLD_LIBRARIES LLD_INCLUDE_DIRS)
find_package_handle_standard_args(lld DEFAULT_MSG LLD_LIBRARIES LLD_INCLUDE_DIRS)
mark_as_advanced(LLD_INCLUDE_DIRS LLD_LIBRARIES)

View File

@@ -7,119 +7,348 @@
# LLVM_LIBRARIES
# LLVM_LIBDIRS
find_program(LLVM_CONFIG_EXE
NAMES llvm-config-9 llvm-config-9.0 llvm-config90 llvm-config
find_path(LLVM_INCLUDE_DIRS NAMES llvm/IR/IRBuilder.h
PATHS
/usr/lib/llvm/12/include
/usr/lib/llvm-12/include
/usr/lib/llvm-12.0/include
/usr/local/llvm12/include
/usr/local/llvm120/include
/mingw64/include
)
if(ZIG_PREFER_CLANG_CPP_DYLIB)
find_library(LLVM_LIBRARIES
NAMES
LLVM-12.0
LLVM-12
LLVM-120
LLVM
PATHS
"/mingw64/bin"
"/c/msys64/mingw64/bin"
"c:/msys64/mingw64/bin"
"C:/Libraries/llvm-9.0.0/bin")
${LLVM_LIBDIRS}
/usr/lib/llvm/12/lib
/usr/lib/llvm/12/lib64
/usr/lib/llvm-12/lib
/usr/local/llvm12/lib
/usr/local/llvm120/lib
)
if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
message(FATAL_ERROR "unable to find llvm-config")
endif()
find_program(LLVM_CONFIG_EXE
NAMES llvm-config-12 llvm-config-12.0 llvm-config120 llvm-config12 llvm-config
PATHS
"/mingw64/bin"
"/c/msys64/mingw64/bin"
"c:/msys64/mingw64/bin"
"C:/Libraries/llvm-12.0.0/bin")
if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
message(FATAL_ERROR "unable to find llvm-config")
endif()
if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
message(FATAL_ERROR "unable to find llvm-config")
endif()
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --version
OUTPUT_VARIABLE LLVM_CONFIG_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
if("${LLVM_CONFIG_VERSION}" VERSION_LESS 9)
message(FATAL_ERROR "expected LLVM 9.x but found ${LLVM_CONFIG_VERSION}")
endif()
if("${LLVM_CONFIG_VERSION}" VERSION_EQUAL 10)
message(FATAL_ERROR "expected LLVM 9.x but found ${LLVM_CONFIG_VERSION}")
endif()
if("${LLVM_CONFIG_VERSION}" VERSION_GREATER 10)
message(FATAL_ERROR "expected LLVM 9.x but found ${LLVM_CONFIG_VERSION}")
endif()
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --targets-built
OUTPUT_VARIABLE LLVM_TARGETS_BUILT_SPACES
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE " " ";" LLVM_TARGETS_BUILT "${LLVM_TARGETS_BUILT_SPACES}")
function(NEED_TARGET TARGET_NAME)
list (FIND LLVM_TARGETS_BUILT "${TARGET_NAME}" _index)
if (${_index} EQUAL -1)
message(FATAL_ERROR "LLVM is missing target ${TARGET_NAME}. Zig requires LLVM to be built with all default targets enabled.")
endif()
endfunction(NEED_TARGET)
NEED_TARGET("AArch64")
NEED_TARGET("AMDGPU")
NEED_TARGET("ARM")
NEED_TARGET("BPF")
NEED_TARGET("Hexagon")
NEED_TARGET("Lanai")
NEED_TARGET("Mips")
NEED_TARGET("MSP430")
NEED_TARGET("NVPTX")
NEED_TARGET("PowerPC")
NEED_TARGET("RISCV")
NEED_TARGET("Sparc")
NEED_TARGET("SystemZ")
NEED_TARGET("WebAssembly")
NEED_TARGET("X86")
NEED_TARGET("XCore")
if(ZIG_STATIC_LLVM)
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --libfiles --link-static
OUTPUT_VARIABLE LLVM_LIBRARIES_SPACES
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE " " ";" LLVM_LIBRARIES "${LLVM_LIBRARIES_SPACES}")
if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
message(FATAL_ERROR "unable to find llvm-config")
endif()
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --system-libs --link-static
OUTPUT_VARIABLE LLVM_SYSTEM_LIBS_SPACES
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE " " ";" LLVM_SYSTEM_LIBS "${LLVM_SYSTEM_LIBS_SPACES}")
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --libdir --link-static
OUTPUT_VARIABLE LLVM_LIBDIRS_SPACES
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE " " ";" LLVM_LIBDIRS "${LLVM_LIBDIRS_SPACES}")
endif()
if(NOT LLVM_LIBRARIES)
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --libs
OUTPUT_VARIABLE LLVM_LIBRARIES_SPACES
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE " " ";" LLVM_LIBRARIES "${LLVM_LIBRARIES_SPACES}")
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --system-libs
OUTPUT_VARIABLE LLVM_SYSTEM_LIBS_SPACES
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE " " ";" LLVM_SYSTEM_LIBS "${LLVM_SYSTEM_LIBS_SPACES}")
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --libdir
OUTPUT_VARIABLE LLVM_LIBDIRS_SPACES
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE " " ";" LLVM_LIBDIRS "${LLVM_LIBDIRS_SPACES}")
endif()
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --includedir
OUTPUT_VARIABLE LLVM_INCLUDE_DIRS
COMMAND ${LLVM_CONFIG_EXE} --version
OUTPUT_VARIABLE LLVM_CONFIG_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
set(LLVM_LIBRARIES ${LLVM_LIBRARIES} ${LLVM_SYSTEM_LIBS})
if("${LLVM_CONFIG_VERSION}" VERSION_LESS 12)
message(FATAL_ERROR "expected LLVM 12.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
endif()
if("${LLVM_CONFIG_VERSION}" VERSION_EQUAL 13)
message(FATAL_ERROR "expected LLVM 12.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
endif()
if("${LLVM_CONFIG_VERSION}" VERSION_GREATER 13)
message(FATAL_ERROR "expected LLVM 12.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
endif()
elseif(ZIG_USE_LLVM_CONFIG)
find_program(LLVM_CONFIG_EXE
NAMES llvm-config-12 llvm-config-12.0 llvm-config120 llvm-config12 llvm-config
PATHS
"/mingw64/bin"
"/c/msys64/mingw64/bin"
"c:/msys64/mingw64/bin"
"C:/Libraries/llvm-12.0.0/bin")
if(NOT LLVM_LIBRARIES)
find_library(LLVM_LIBRARIES NAMES LLVM LLVM-9 LLVM-9.0)
if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
message(FATAL_ERROR "unable to find llvm-config")
endif()
if ("${LLVM_CONFIG_EXE}" STREQUAL "LLVM_CONFIG_EXE-NOTFOUND")
message(FATAL_ERROR "unable to find llvm-config")
endif()
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --version
OUTPUT_VARIABLE LLVM_CONFIG_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
if("${LLVM_CONFIG_VERSION}" VERSION_LESS 12)
message(FATAL_ERROR "expected LLVM 12.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
endif()
if("${LLVM_CONFIG_VERSION}" VERSION_EQUAL 13)
message(FATAL_ERROR "expected LLVM 12.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
endif()
if("${LLVM_CONFIG_VERSION}" VERSION_GREATER 13)
message(FATAL_ERROR "expected LLVM 12.x but found ${LLVM_CONFIG_VERSION} using ${LLVM_CONFIG_EXE}")
endif()
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --targets-built
OUTPUT_VARIABLE LLVM_TARGETS_BUILT_SPACES
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE " " ";" LLVM_TARGETS_BUILT "${LLVM_TARGETS_BUILT_SPACES}")
function(NEED_TARGET TARGET_NAME)
list (FIND LLVM_TARGETS_BUILT "${TARGET_NAME}" _index)
if (${_index} EQUAL -1)
message(FATAL_ERROR "LLVM (according to ${LLVM_CONFIG_EXE}) is missing target ${TARGET_NAME}. Zig requires LLVM to be built with all default targets enabled.")
endif()
endfunction(NEED_TARGET)
NEED_TARGET("AArch64")
NEED_TARGET("AMDGPU")
NEED_TARGET("ARM")
NEED_TARGET("AVR")
NEED_TARGET("BPF")
NEED_TARGET("Hexagon")
NEED_TARGET("Lanai")
NEED_TARGET("Mips")
NEED_TARGET("MSP430")
NEED_TARGET("NVPTX")
NEED_TARGET("PowerPC")
NEED_TARGET("RISCV")
NEED_TARGET("Sparc")
NEED_TARGET("SystemZ")
NEED_TARGET("WebAssembly")
NEED_TARGET("X86")
NEED_TARGET("XCore")
if(ZIG_STATIC_LLVM)
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --libfiles --link-static
OUTPUT_VARIABLE LLVM_LIBRARIES_SPACES
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE " " ";" LLVM_LIBRARIES "${LLVM_LIBRARIES_SPACES}")
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --system-libs --link-static
OUTPUT_VARIABLE LLVM_SYSTEM_LIBS_SPACES
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE " " ";" LLVM_SYSTEM_LIBS "${LLVM_SYSTEM_LIBS_SPACES}")
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --libdir --link-static
OUTPUT_VARIABLE LLVM_LIBDIRS_SPACES
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE " " ";" LLVM_LIBDIRS "${LLVM_LIBDIRS_SPACES}")
endif()
if(NOT LLVM_LIBRARIES)
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --libs
OUTPUT_VARIABLE LLVM_LIBRARIES_SPACES
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE " " ";" LLVM_LIBRARIES "${LLVM_LIBRARIES_SPACES}")
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --system-libs
OUTPUT_VARIABLE LLVM_SYSTEM_LIBS_SPACES
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE " " ";" LLVM_SYSTEM_LIBS "${LLVM_SYSTEM_LIBS_SPACES}")
execute_process(
COMMAND ${LLVM_CONFIG_EXE} --libdir
OUTPUT_VARIABLE LLVM_LIBDIRS_SPACES
OUTPUT_STRIP_TRAILING_WHITESPACE)
string(REPLACE " " ";" LLVM_LIBDIRS "${LLVM_LIBDIRS_SPACES}")
endif()
set(LLVM_LIBRARIES ${LLVM_LIBRARIES} ${LLVM_SYSTEM_LIBS})
if(NOT LLVM_LIBRARIES)
find_library(LLVM_LIBRARIES NAMES LLVM LLVM-12 LLVM-12.0)
endif()
link_directories("${CMAKE_PREFIX_PATH}/lib")
link_directories("${LLVM_LIBDIRS}")
else()
# Here we assume that we're cross compiling with Zig, of course. No reason
# to support more complicated setups.
macro(FIND_AND_ADD_LLVM_LIB _libname_)
string(TOUPPER ${_libname_} _prettylibname_)
find_library(LLVM_${_prettylibname_}_LIB NAMES ${_libname_}
PATHS
${LLVM_LIBDIRS}
/usr/lib/llvm/12/lib
/usr/lib/llvm-12/lib
/usr/lib/llvm-12.0/lib
/usr/local/llvm120/lib
/usr/local/llvm12/lib
/mingw64/lib
/c/msys64/mingw64/lib
c:\\msys64\\mingw64\\lib)
set(LLVM_LIBRARIES ${LLVM_LIBRARIES} ${LLVM_${_prettylibname_}_LIB})
endmacro(FIND_AND_ADD_LLVM_LIB)
# This list can be re-generated with `llvm-config --libfiles` and then
# reformatting using your favorite text editor. Note we do not execute
# `llvm-config` here because we are cross compiling.
FIND_AND_ADD_LLVM_LIB(LLVMWindowsManifest)
FIND_AND_ADD_LLVM_LIB(LLVMXRay)
FIND_AND_ADD_LLVM_LIB(LLVMLibDriver)
FIND_AND_ADD_LLVM_LIB(LLVMDlltoolDriver)
FIND_AND_ADD_LLVM_LIB(LLVMCoverage)
FIND_AND_ADD_LLVM_LIB(LLVMLineEditor)
FIND_AND_ADD_LLVM_LIB(LLVMXCoreDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMXCoreCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMXCoreDesc)
FIND_AND_ADD_LLVM_LIB(LLVMXCoreInfo)
FIND_AND_ADD_LLVM_LIB(LLVMX86Disassembler)
FIND_AND_ADD_LLVM_LIB(LLVMX86AsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMX86CodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMX86Desc)
FIND_AND_ADD_LLVM_LIB(LLVMX86Info)
FIND_AND_ADD_LLVM_LIB(LLVMWebAssemblyDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMWebAssemblyAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMWebAssemblyCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMWebAssemblyDesc)
FIND_AND_ADD_LLVM_LIB(LLVMWebAssemblyInfo)
FIND_AND_ADD_LLVM_LIB(LLVMSystemZDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMSystemZAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMSystemZCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMSystemZDesc)
FIND_AND_ADD_LLVM_LIB(LLVMSystemZInfo)
FIND_AND_ADD_LLVM_LIB(LLVMSparcDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMSparcAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMSparcCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMSparcDesc)
FIND_AND_ADD_LLVM_LIB(LLVMSparcInfo)
FIND_AND_ADD_LLVM_LIB(LLVMRISCVDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMRISCVAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMRISCVCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMRISCVDesc)
FIND_AND_ADD_LLVM_LIB(LLVMRISCVInfo)
FIND_AND_ADD_LLVM_LIB(LLVMPowerPCDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMPowerPCAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMPowerPCCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMPowerPCDesc)
FIND_AND_ADD_LLVM_LIB(LLVMPowerPCInfo)
FIND_AND_ADD_LLVM_LIB(LLVMNVPTXCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMNVPTXDesc)
FIND_AND_ADD_LLVM_LIB(LLVMNVPTXInfo)
FIND_AND_ADD_LLVM_LIB(LLVMMSP430Disassembler)
FIND_AND_ADD_LLVM_LIB(LLVMMSP430AsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMMSP430CodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMMSP430Desc)
FIND_AND_ADD_LLVM_LIB(LLVMMSP430Info)
FIND_AND_ADD_LLVM_LIB(LLVMMipsDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMMipsAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMMipsCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMMipsDesc)
FIND_AND_ADD_LLVM_LIB(LLVMMipsInfo)
FIND_AND_ADD_LLVM_LIB(LLVMLanaiDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMLanaiCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMLanaiAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMLanaiDesc)
FIND_AND_ADD_LLVM_LIB(LLVMLanaiInfo)
FIND_AND_ADD_LLVM_LIB(LLVMHexagonDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMHexagonCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMHexagonAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMHexagonDesc)
FIND_AND_ADD_LLVM_LIB(LLVMHexagonInfo)
FIND_AND_ADD_LLVM_LIB(LLVMBPFDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMBPFAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMBPFCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMBPFDesc)
FIND_AND_ADD_LLVM_LIB(LLVMBPFInfo)
FIND_AND_ADD_LLVM_LIB(LLVMAVRDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMAVRAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMAVRCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMAVRDesc)
FIND_AND_ADD_LLVM_LIB(LLVMAVRInfo)
FIND_AND_ADD_LLVM_LIB(LLVMARMDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMARMAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMARMCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMARMDesc)
FIND_AND_ADD_LLVM_LIB(LLVMARMUtils)
FIND_AND_ADD_LLVM_LIB(LLVMARMInfo)
FIND_AND_ADD_LLVM_LIB(LLVMAMDGPUDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMAMDGPUAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMAMDGPUCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMAMDGPUDesc)
FIND_AND_ADD_LLVM_LIB(LLVMAMDGPUUtils)
FIND_AND_ADD_LLVM_LIB(LLVMAMDGPUInfo)
FIND_AND_ADD_LLVM_LIB(LLVMAArch64Disassembler)
FIND_AND_ADD_LLVM_LIB(LLVMAArch64AsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMAArch64CodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMAArch64Desc)
FIND_AND_ADD_LLVM_LIB(LLVMAArch64Utils)
FIND_AND_ADD_LLVM_LIB(LLVMAArch64Info)
FIND_AND_ADD_LLVM_LIB(LLVMOrcJIT)
FIND_AND_ADD_LLVM_LIB(LLVMMCJIT)
FIND_AND_ADD_LLVM_LIB(LLVMJITLink)
FIND_AND_ADD_LLVM_LIB(LLVMOrcTargetProcess)
FIND_AND_ADD_LLVM_LIB(LLVMOrcShared)
FIND_AND_ADD_LLVM_LIB(LLVMInterpreter)
FIND_AND_ADD_LLVM_LIB(LLVMExecutionEngine)
FIND_AND_ADD_LLVM_LIB(LLVMRuntimeDyld)
FIND_AND_ADD_LLVM_LIB(LLVMSymbolize)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoPDB)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoGSYM)
FIND_AND_ADD_LLVM_LIB(LLVMOption)
FIND_AND_ADD_LLVM_LIB(LLVMObjectYAML)
FIND_AND_ADD_LLVM_LIB(LLVMMCA)
FIND_AND_ADD_LLVM_LIB(LLVMMCDisassembler)
FIND_AND_ADD_LLVM_LIB(LLVMLTO)
FIND_AND_ADD_LLVM_LIB(LLVMPasses)
FIND_AND_ADD_LLVM_LIB(LLVMCFGuard)
FIND_AND_ADD_LLVM_LIB(LLVMCoroutines)
FIND_AND_ADD_LLVM_LIB(LLVMObjCARCOpts)
FIND_AND_ADD_LLVM_LIB(LLVMHelloNew)
FIND_AND_ADD_LLVM_LIB(LLVMipo)
FIND_AND_ADD_LLVM_LIB(LLVMVectorize)
FIND_AND_ADD_LLVM_LIB(LLVMLinker)
FIND_AND_ADD_LLVM_LIB(LLVMInstrumentation)
FIND_AND_ADD_LLVM_LIB(LLVMFrontendOpenMP)
FIND_AND_ADD_LLVM_LIB(LLVMFrontendOpenACC)
FIND_AND_ADD_LLVM_LIB(LLVMExtensions)
FIND_AND_ADD_LLVM_LIB(LLVMDWARFLinker)
FIND_AND_ADD_LLVM_LIB(LLVMGlobalISel)
FIND_AND_ADD_LLVM_LIB(LLVMMIRParser)
FIND_AND_ADD_LLVM_LIB(LLVMAsmPrinter)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoDWARF)
FIND_AND_ADD_LLVM_LIB(LLVMSelectionDAG)
FIND_AND_ADD_LLVM_LIB(LLVMCodeGen)
FIND_AND_ADD_LLVM_LIB(LLVMIRReader)
FIND_AND_ADD_LLVM_LIB(LLVMAsmParser)
FIND_AND_ADD_LLVM_LIB(LLVMInterfaceStub)
FIND_AND_ADD_LLVM_LIB(LLVMFileCheck)
FIND_AND_ADD_LLVM_LIB(LLVMFuzzMutate)
FIND_AND_ADD_LLVM_LIB(LLVMTarget)
FIND_AND_ADD_LLVM_LIB(LLVMScalarOpts)
FIND_AND_ADD_LLVM_LIB(LLVMInstCombine)
FIND_AND_ADD_LLVM_LIB(LLVMAggressiveInstCombine)
FIND_AND_ADD_LLVM_LIB(LLVMTransformUtils)
FIND_AND_ADD_LLVM_LIB(LLVMBitWriter)
FIND_AND_ADD_LLVM_LIB(LLVMAnalysis)
FIND_AND_ADD_LLVM_LIB(LLVMProfileData)
FIND_AND_ADD_LLVM_LIB(LLVMObject)
FIND_AND_ADD_LLVM_LIB(LLVMTextAPI)
FIND_AND_ADD_LLVM_LIB(LLVMMCParser)
FIND_AND_ADD_LLVM_LIB(LLVMMC)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoCodeView)
FIND_AND_ADD_LLVM_LIB(LLVMDebugInfoMSF)
FIND_AND_ADD_LLVM_LIB(LLVMBitReader)
FIND_AND_ADD_LLVM_LIB(LLVMCore)
FIND_AND_ADD_LLVM_LIB(LLVMRemarks)
FIND_AND_ADD_LLVM_LIB(LLVMBitstreamReader)
FIND_AND_ADD_LLVM_LIB(LLVMBinaryFormat)
FIND_AND_ADD_LLVM_LIB(LLVMSupport)
FIND_AND_ADD_LLVM_LIB(LLVMDemangle)
endif()
link_directories("${CMAKE_PREFIX_PATH}/lib")
link_directories("${LLVM_LIBDIRS}")
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LLVM DEFAULT_MSG LLVM_LIBRARIES LLVM_INCLUDE_DIRS)
find_package_handle_standard_args(llvm DEFAULT_MSG LLVM_LIBRARIES LLVM_INCLUDE_DIRS)
mark_as_advanced(LLVM_INCLUDE_DIRS LLVM_LIBRARIES LLVM_LIBDIRS)

View File

@@ -0,0 +1,13 @@
if(MSVC)
set(CMAKE_C_FLAGS_DEBUG_INIT
"/D_DEBUG /MTd /Zi /Ob0 /Od /RTC1")
set(CMAKE_C_FLAGS_MINSIZEREL_INIT
"/MT /O1 /Ob1 /D NDEBUG")
set(CMAKE_C_FLAGS_RELEASE_INIT
"/MT /O2 /Ob1 /D NDEBUG")
set(CMAKE_C_FLAGS_RELWITHDEBINFO_INIT
"/MT /Zi /O2 /Ob1 /D NDEBUG")
endif()

View File

@@ -0,0 +1,13 @@
if(MSVC)
set(CMAKE_CXX_FLAGS_DEBUG_INIT
"/D_DEBUG /MTd /Zi /Ob0 /Od /RTC1")
set(CMAKE_CXX_FLAGS_MINSIZEREL_INIT
"/MT /O1 /Ob1 /D NDEBUG")
set(CMAKE_CXX_FLAGS_RELEASE_INIT
"/MT /O2 /Ob1 /D NDEBUG")
set(CMAKE_CXX_FLAGS_RELWITHDEBINFO_INIT
"/MT /Zi /O2 /Ob1 /D NDEBUG")
endif()

37
cmake/install.cmake Normal file
View File

@@ -0,0 +1,37 @@
message("-- Installing: ${CMAKE_INSTALL_PREFIX}/lib")
if(NOT EXISTS ${zig_EXE})
message("::")
message(":: ERROR: Executable not found")
message(":: (execute_process)")
message("::")
message(":: executable: ${zig_EXE}")
message("::")
message(FATAL_ERROR)
endif()
execute_process(COMMAND ${zig_EXE} ${ZIG_INSTALL_ARGS}
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}
RESULT_VARIABLE _result
)
if(_result)
message("::")
message(":: ERROR: ${_result}")
message(":: (execute_process)")
string(REPLACE ";" " " s_INSTALL_LIBSTAGE2_ARGS "${ZIG_INSTALL_ARGS}")
message("::")
message(":: argv: ${zig_EXE} ${s_INSTALL_LIBSTAGE2_ARGS}")
set(_args ${zig_EXE} ${ZIG_INSTALL_ARGS})
list(LENGTH _args _len)
math(EXPR _len "${_len} - 1")
message("::")
foreach(_i RANGE 0 ${_len})
list(GET _args ${_i} _arg)
message(":: argv[${_i}]: ${_arg}")
endforeach()
message("::")
message(FATAL_ERROR)
endif()

View File

@@ -1,37 +1,37 @@
License for Berkeley SoftFloat Release 3e
John R. Hauser
2018 January 20
The following applies to the whole of SoftFloat Release 3e as well as to
each source file individually.
Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 The Regents of the
University of California. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions, and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions, and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
License for Berkeley SoftFloat Release 3e
John R. Hauser
2018 January 20
The following applies to the whole of SoftFloat Release 3e as well as to
each source file individually.
Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 The Regents of the
University of California. All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions, and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions, and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the University nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@@ -1,21 +1,21 @@
Package Overview for Berkeley SoftFloat Release 3e
John R. Hauser
2018 January 20
Berkeley SoftFloat is a software implementation of binary floating-point
that conforms to the IEEE Standard for Floating-Point Arithmetic. SoftFloat
is distributed in the form of C source code. Building the SoftFloat sources
generates a library file (typically "softfloat.a" or "libsoftfloat.a")
containing the floating-point subroutines.
The SoftFloat package is documented in the following files in the "doc"
subdirectory:
SoftFloat.html Documentation for using the SoftFloat functions.
SoftFloat-source.html Documentation for building SoftFloat.
SoftFloat-history.html History of the major changes to SoftFloat.
Other files in the package comprise the source code for SoftFloat.
Package Overview for Berkeley SoftFloat Release 3e
John R. Hauser
2018 January 20
Berkeley SoftFloat is a software implementation of binary floating-point
that conforms to the IEEE Standard for Floating-Point Arithmetic. SoftFloat
is distributed in the form of C source code. Building the SoftFloat sources
generates a library file (typically "softfloat.a" or "libsoftfloat.a")
containing the floating-point subroutines.
The SoftFloat package is documented in the following files in the "doc"
subdirectory:
SoftFloat.html Documentation for using the SoftFloat functions.
SoftFloat-source.html Documentation for building SoftFloat.
SoftFloat-history.html History of the major changes to SoftFloat.
Other files in the package comprise the source code for SoftFloat.

View File

@@ -1,275 +0,0 @@
/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
|* *|
|* Option Parsing Definitions *|
|* *|
|* Automatically generated file, do not edit! *|
|* *|
\*===----------------------------------------------------------------------===*/
/////////
// Prefixes
#ifdef PREFIX
#define COMMA ,
PREFIX(prefix_0, {nullptr})
PREFIX(prefix_2, {"--" COMMA nullptr})
PREFIX(prefix_1, {"/" COMMA "-" COMMA "/?" COMMA "-?" COMMA nullptr})
PREFIX(prefix_3, {"/??" COMMA "-??" COMMA "/?" COMMA "-?" COMMA nullptr})
#undef COMMA
#endif // PREFIX
/////////
// Groups
#ifdef OPTION
//////////
// Options
OPTION(prefix_0, "<input>", INPUT, Input, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_0, "<unknown>", UNKNOWN, Unknown, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "align:", align, Joined, INVALID, INVALID, nullptr, 0, 0,
"Section alignment", nullptr, nullptr)
OPTION(prefix_1, "aligncomm:", aligncomm, Joined, INVALID, INVALID, nullptr, 0, 0,
"Set common symbol alignment", nullptr, nullptr)
OPTION(prefix_1, "allowbind:no", allowbind_no, Flag, INVALID, INVALID, nullptr, 0, 0,
"Disable DLL binding", nullptr, nullptr)
OPTION(prefix_1, "allowbind", allowbind, Flag, INVALID, INVALID, nullptr, 0, 0,
"Enable DLL binding (default)", nullptr, nullptr)
OPTION(prefix_1, "allowisolation:no", allowisolation_no, Flag, INVALID, INVALID, nullptr, 0, 0,
"Disable DLL isolation", nullptr, nullptr)
OPTION(prefix_1, "allowisolation", allowisolation, Flag, INVALID, INVALID, nullptr, 0, 0,
"Enable DLL isolation (default)", nullptr, nullptr)
OPTION(prefix_1, "alternatename:", alternatename, Joined, INVALID, INVALID, nullptr, 0, 0,
"Define weak alias", nullptr, nullptr)
OPTION(prefix_1, "appcontainer:no", appcontainer_no, Flag, INVALID, INVALID, nullptr, 0, 0,
"Image can run outside an app container (default)", nullptr, nullptr)
OPTION(prefix_1, "appcontainer", appcontainer, Flag, INVALID, INVALID, nullptr, 0, 0,
"Image can only be run in an app container", nullptr, nullptr)
OPTION(prefix_1, "base:", base, Joined, INVALID, INVALID, nullptr, 0, 0,
"Base address of the program", nullptr, nullptr)
OPTION(prefix_1, "Brepro", repro, Flag, INVALID, INVALID, nullptr, 0, 0,
"Use a hash of the executable as the PE header timestamp", nullptr, nullptr)
OPTION(prefix_2, "color-diagnostics=", color_diagnostics_eq, Joined, INVALID, INVALID, nullptr, 0, 0,
"Use colors in diagnostics; one of 'always', 'never', 'auto'", nullptr, nullptr)
OPTION(prefix_2, "color-diagnostics", color_diagnostics, Flag, INVALID, INVALID, nullptr, 0, 0,
"Use colors in diagnostics", nullptr, nullptr)
OPTION(prefix_1, "debug:", debug_opt, Joined, INVALID, INVALID, nullptr, 0, 0,
"Embed a symbol table in the image with option", nullptr, nullptr)
OPTION(prefix_1, "debugtype:", debugtype, Joined, INVALID, INVALID, nullptr, 0, 0,
"Debug Info Options", nullptr, nullptr)
OPTION(prefix_1, "debug", debug, Flag, INVALID, INVALID, nullptr, 0, 0,
"Embed a symbol table in the image", nullptr, nullptr)
OPTION(prefix_1, "def:", deffile, Joined, INVALID, INVALID, nullptr, 0, 0,
"Use module-definition file", nullptr, nullptr)
OPTION(prefix_1, "defaultlib:", defaultlib, Joined, INVALID, INVALID, nullptr, 0, 0,
"Add the library to the list of input files", nullptr, nullptr)
OPTION(prefix_1, "delay:", delay, Joined, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "delayload:", delayload, Joined, INVALID, INVALID, nullptr, 0, 0,
"Delay loaded DLL name", nullptr, nullptr)
OPTION(prefix_1, "demangle:no", demangle_no, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not demangle symbols in output", nullptr, nullptr)
OPTION(prefix_1, "demangle", demangle, Flag, INVALID, INVALID, nullptr, 0, 0,
"Demangle symbols in output (default)", nullptr, nullptr)
OPTION(prefix_1, "disallowlib:", disallowlib, Joined, INVALID, nodefaultlib, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "dll", dll, Flag, INVALID, INVALID, nullptr, 0, 0,
"Create a DLL", nullptr, nullptr)
OPTION(prefix_1, "driver:", driver, Joined, INVALID, INVALID, nullptr, 0, 0,
"Generate a Windows NT Kernel Mode Driver", nullptr, nullptr)
OPTION(prefix_1, "dynamicbase:no", dynamicbase_no, Flag, INVALID, INVALID, nullptr, 0, 0,
"Disable ASLR (default when /fixed)", nullptr, nullptr)
OPTION(prefix_1, "dynamicbase", dynamicbase, Flag, INVALID, INVALID, nullptr, 0, 0,
"Enable ASLR (default unless /fixed)", nullptr, nullptr)
OPTION(prefix_1, "editandcontinue", editandcontinue, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "entry:", entry, Joined, INVALID, INVALID, nullptr, 0, 0,
"Name of entry point symbol", nullptr, nullptr)
OPTION(prefix_1, "errorlimit:", errorlimit, Joined, INVALID, INVALID, nullptr, 0, 0,
"Maximum number of errors to emit before stopping (0 = no limit)", nullptr, nullptr)
OPTION(prefix_1, "errorreport:", errorreport, Joined, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "exclude-all-symbols", exclude_all_symbols, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "export-all-symbols", export_all_symbols, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "export:", export, Joined, INVALID, INVALID, nullptr, 0, 0,
"Export a function", nullptr, nullptr)
OPTION(prefix_1, "failifmismatch:", failifmismatch, Joined, INVALID, INVALID, nullptr, 0, 0,
"", nullptr, nullptr)
OPTION(prefix_1, "fastfail", fastfail, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "filealign:", filealign, Joined, INVALID, INVALID, nullptr, 0, 0,
"Section alignment in the output file", nullptr, nullptr)
OPTION(prefix_1, "fixed:no", fixed_no, Flag, INVALID, INVALID, nullptr, 0, 0,
"Enable base relocations (default)", nullptr, nullptr)
OPTION(prefix_1, "fixed", fixed, Flag, INVALID, INVALID, nullptr, 0, 0,
"Disable base relocations", nullptr, nullptr)
OPTION(prefix_1, "force:multipleres", force_multipleres, Flag, INVALID, INVALID, nullptr, 0, 0,
"Allow multiply defined resources when creating executables", nullptr, nullptr)
OPTION(prefix_1, "force:multiple", force_multiple, Flag, INVALID, INVALID, nullptr, 0, 0,
"Allow multiply defined symbols when creating executables", nullptr, nullptr)
OPTION(prefix_1, "force:unresolved", force_unresolved, Flag, INVALID, INVALID, nullptr, 0, 0,
"Allow undefined symbols when creating executables", nullptr, nullptr)
OPTION(prefix_1, "force", force, Flag, INVALID, INVALID, nullptr, 0, 0,
"Allow undefined and multiply defined symbols when creating executables", nullptr, nullptr)
OPTION(prefix_1, "functionpadmin:", functionpadmin_opt, Joined, INVALID, INVALID, nullptr, 0, 0,
"Prepares an image for hotpatching", nullptr, nullptr)
OPTION(prefix_1, "functionpadmin", functionpadmin, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "guard:", guard, Joined, INVALID, INVALID, nullptr, 0, 0,
"Control flow guard", nullptr, nullptr)
OPTION(prefix_1, "guardsym:", guardsym, Joined, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "heap:", heap, Joined, INVALID, INVALID, nullptr, 0, 0,
"Size of the heap", nullptr, nullptr)
OPTION(prefix_1, "help", help, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "highentropyva:no", highentropyva_no, Flag, INVALID, INVALID, nullptr, 0, 0,
"Disable 64-bit ASLR", nullptr, nullptr)
OPTION(prefix_1, "highentropyva", highentropyva, Flag, INVALID, INVALID, nullptr, 0, 0,
"Enable 64-bit ASLR (default on 64-bit)", nullptr, nullptr)
OPTION(prefix_1, "idlout:", idlout, Joined, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "ignore:", ignore, Joined, INVALID, INVALID, nullptr, 0, 0,
"Specify warning codes to ignore", nullptr, nullptr)
OPTION(prefix_1, "ignoreidl", ignoreidl, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "implib:", implib, Joined, INVALID, INVALID, nullptr, 0, 0,
"Import library name", nullptr, nullptr)
OPTION(prefix_1, "include:", incl, Joined, INVALID, INVALID, nullptr, 0, 0,
"Force symbol to be added to symbol table as undefined one", nullptr, nullptr)
OPTION(prefix_1, "includeoptional:", include_optional, Joined, INVALID, INVALID, nullptr, 0, 0,
"Add symbol as undefined, but allow it to remain undefined", nullptr, nullptr)
OPTION(prefix_1, "incremental:no", incremental_no, Flag, INVALID, INVALID, nullptr, 0, 0,
"Overwrite import library even if contents are unchanged", nullptr, nullptr)
OPTION(prefix_1, "incremental", incremental, Flag, INVALID, INVALID, nullptr, 0, 0,
"Keep original import library if contents are unchanged", nullptr, nullptr)
OPTION(prefix_1, "integritycheck:no", integritycheck_no, Flag, INVALID, INVALID, nullptr, 0, 0,
"No effect (default)", nullptr, nullptr)
OPTION(prefix_1, "integritycheck", integritycheck, Flag, INVALID, INVALID, nullptr, 0, 0,
"Set FORCE_INTEGRITY bit in PE header", nullptr, nullptr)
OPTION(prefix_1, "kill-at", kill_at, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "largeaddressaware:no", largeaddressaware_no, Flag, INVALID, INVALID, nullptr, 0, 0,
"Disable large addresses (default on 32-bit)", nullptr, nullptr)
OPTION(prefix_1, "largeaddressaware", largeaddressaware, Flag, INVALID, INVALID, nullptr, 0, 0,
"Enable large addresses (default on 64-bit)", nullptr, nullptr)
OPTION(prefix_1, "libpath:", libpath, Joined, INVALID, INVALID, nullptr, 0, 0,
"Additional library search path", nullptr, nullptr)
OPTION(prefix_1, "lib", lib, Flag, INVALID, INVALID, nullptr, 0, 0,
"Act like lib.exe; must be first argument if present", nullptr, nullptr)
OPTION(prefix_1, "linkrepro:", linkrepro, Joined, INVALID, INVALID, nullptr, 0, 0,
"Dump linker invocation and input files for debugging", nullptr, nullptr)
OPTION(prefix_1, "lldltocache:", lldltocache, Joined, INVALID, INVALID, nullptr, 0, 0,
"Path to ThinLTO cached object file directory", nullptr, nullptr)
OPTION(prefix_1, "lldltocachepolicy:", lldltocachepolicy, Joined, INVALID, INVALID, nullptr, 0, 0,
"Pruning policy for the ThinLTO cache", nullptr, nullptr)
OPTION(prefix_1, "lldmap:", lldmap_file, Joined, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "lldmap", lldmap, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "lldmingw", lldmingw, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "lldsavetemps", lldsavetemps, Flag, INVALID, INVALID, nullptr, 0, 0,
"Save temporary files instead of deleting them", nullptr, nullptr)
OPTION(prefix_1, "machine:", machine, Joined, INVALID, INVALID, nullptr, 0, 0,
"Specify target platform", nullptr, nullptr)
OPTION(prefix_1, "manifest:", manifest_colon, Joined, INVALID, INVALID, nullptr, 0, 0,
"NO disables manifest output; EMBED[,ID=#] embeds manifest as resource in the image", nullptr, nullptr)
OPTION(prefix_1, "manifestdependency:", manifestdependency, Joined, INVALID, INVALID, nullptr, 0, 0,
"Attributes for <dependency> element in manifest file; implies /manifest", nullptr, nullptr)
OPTION(prefix_1, "manifestfile:", manifestfile, Joined, INVALID, INVALID, nullptr, 0, 0,
"Manifest output path, with /manifest", nullptr, nullptr)
OPTION(prefix_1, "manifestinput:", manifestinput, Joined, INVALID, INVALID, nullptr, 0, 0,
"Additional manifest inputs; only valid with /manifest:embed", nullptr, nullptr)
OPTION(prefix_1, "manifestuac:", manifestuac, Joined, INVALID, INVALID, nullptr, 0, 0,
"User access control", nullptr, nullptr)
OPTION(prefix_1, "manifest", manifest, Flag, INVALID, INVALID, nullptr, 0, 0,
"Create .manifest file", nullptr, nullptr)
OPTION(prefix_1, "maxilksize:", maxilksize, Joined, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "merge:", merge, Joined, INVALID, INVALID, nullptr, 0, 0,
"Combine sections", nullptr, nullptr)
OPTION(prefix_1, "mllvm:", mllvm, Joined, INVALID, INVALID, nullptr, 0, 0,
"Options to pass to LLVM", nullptr, nullptr)
OPTION(prefix_1, "natvis:", natvis, Joined, INVALID, INVALID, nullptr, 0, 0,
"Path to natvis file to embed in the PDB", nullptr, nullptr)
OPTION(prefix_1, "no-color-diagnostics", no_color_diagnostics, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not use colors in diagnostics", nullptr, nullptr)
OPTION(prefix_1, "nodefaultlib:", nodefaultlib, Joined, INVALID, INVALID, nullptr, 0, 0,
"Remove a default library", nullptr, nullptr)
OPTION(prefix_1, "nodefaultlib", nodefaultlib_all, Flag, INVALID, INVALID, nullptr, 0, 0,
"Remove all default libraries", nullptr, nullptr)
OPTION(prefix_1, "noentry", noentry, Flag, INVALID, INVALID, nullptr, 0, 0,
"Don't add reference to DllMainCRTStartup; only valid with /dll", nullptr, nullptr)
OPTION(prefix_1, "nologo", nologo, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "nxcompat:no", nxcompat_no, Flag, INVALID, INVALID, nullptr, 0, 0,
"Disable data execution provention", nullptr, nullptr)
OPTION(prefix_1, "nxcompat", nxcompat, Flag, INVALID, INVALID, nullptr, 0, 0,
"Enable data execution prevention (default)", nullptr, nullptr)
OPTION(prefix_1, "opt:", opt, Joined, INVALID, INVALID, nullptr, 0, 0,
"Control optimizations", nullptr, nullptr)
OPTION(prefix_1, "order:", order, Joined, INVALID, INVALID, nullptr, 0, 0,
"Put functions in order", nullptr, nullptr)
OPTION(prefix_1, "out:", out, Joined, INVALID, INVALID, nullptr, 0, 0,
"Path to file to write output", nullptr, nullptr)
OPTION(prefix_1, "output-def:", output_def, Joined, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "pdb:", pdb, Joined, INVALID, INVALID, nullptr, 0, 0,
"PDB file path", nullptr, nullptr)
OPTION(prefix_1, "pdbaltpath:", pdbaltpath, Joined, INVALID, INVALID, nullptr, 0, 0,
"PDB file path to embed in the image", nullptr, nullptr)
OPTION(prefix_1, "pdbsourcepath:", pdb_source_path, Joined, INVALID, INVALID, nullptr, 0, 0,
"Base path used to make relative source file path absolute in PDB", nullptr, nullptr)
OPTION(prefix_1, "profile", profile, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "rsp-quoting=", rsp_quoting, Joined, INVALID, INVALID, nullptr, 0, 0,
"Quoting style for response files, 'windows' (default) or 'posix'", nullptr, nullptr)
OPTION(prefix_1, "safeseh:no", safeseh_no, Flag, INVALID, INVALID, nullptr, 0, 0,
"Don't produce an image with Safe Exception Handler", nullptr, nullptr)
OPTION(prefix_1, "safeseh", safeseh, Flag, INVALID, INVALID, nullptr, 0, 0,
"Produce an image with Safe Exception Handler (only for x86)", nullptr, nullptr)
OPTION(prefix_1, "section:", section, Joined, INVALID, INVALID, nullptr, 0, 0,
"Specify section attributes", nullptr, nullptr)
OPTION(prefix_1, "stack:", stack, Joined, INVALID, INVALID, nullptr, 0, 0,
"Size of the stack", nullptr, nullptr)
OPTION(prefix_1, "stub:", stub, Joined, INVALID, INVALID, nullptr, 0, 0,
"Specify DOS stub file", nullptr, nullptr)
OPTION(prefix_1, "subsystem:", subsystem, Joined, INVALID, INVALID, nullptr, 0, 0,
"Specify subsystem", nullptr, nullptr)
OPTION(prefix_1, "summary", summary, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "swaprun:cd", swaprun_cd, Flag, INVALID, swaprun, "cd\0", 0, 0,
"Make loader run output binary from swap instead of from CD", nullptr, nullptr)
OPTION(prefix_1, "swaprun:net", swaprun_net, Flag, INVALID, swaprun, "net\0", 0, 0,
"Make loader run output binary from swap instead of from network", nullptr, nullptr)
OPTION(prefix_1, "swaprun:", swaprun, Joined, INVALID, INVALID, nullptr, 0, 0,
"Comma-separated list of 'cd' or 'net'", nullptr, nullptr)
OPTION(prefix_1, "thinlto-emit-imports-files", thinlto_emit_imports_files, Flag, INVALID, INVALID, nullptr, 0, 0,
"Emit .imports files with -thinlto-index-only", nullptr, nullptr)
OPTION(prefix_1, "thinlto-index-only:", thinlto_index_only_arg, Joined, INVALID, INVALID, nullptr, 0, 0,
"-thinlto-index-only and also write native module names to file", nullptr, nullptr)
OPTION(prefix_1, "thinlto-index-only", thinlto_index_only, Flag, INVALID, INVALID, nullptr, 0, 0,
"Instead of linking, emit ThinLTO index files", nullptr, nullptr)
OPTION(prefix_1, "thinlto-object-suffix-replace:", thinlto_object_suffix_replace, Joined, INVALID, INVALID, nullptr, 0, 0,
"'old;new' replace old suffix with new suffix in ThinLTO index", nullptr, nullptr)
OPTION(prefix_1, "thinlto-prefix-replace:", thinlto_prefix_replace, Joined, INVALID, INVALID, nullptr, 0, 0,
"'old;new' replace old prefix with new prefix in ThinLTO outputs", nullptr, nullptr)
OPTION(prefix_1, "threads:no", threads_no, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not run the linker multi-threaded", nullptr, nullptr)
OPTION(prefix_1, "threads", threads, Flag, INVALID, INVALID, nullptr, 0, 0,
"Run the linker multi-threaded (default)", nullptr, nullptr)
OPTION(prefix_1, "throwingnew", throwingnew, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "timestamp:", timestamp, Joined, INVALID, INVALID, nullptr, 0, 0,
"Specify the PE header timestamp", nullptr, nullptr)
OPTION(prefix_1, "time", show_timing, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "tlbid:", tlbid, Joined, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "tlbout:", tlbout, Joined, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "tsaware:no", tsaware_no, Flag, INVALID, INVALID, nullptr, 0, 0,
"Create non-Terminal Server aware executable", nullptr, nullptr)
OPTION(prefix_1, "tsaware", tsaware, Flag, INVALID, INVALID, nullptr, 0, 0,
"Create Terminal Server aware executable (default)", nullptr, nullptr)
OPTION(prefix_1, "verbose:", verbose_all, Joined, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "verbose", verbose, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "version:", version, Joined, INVALID, INVALID, nullptr, 0, 0,
"Specify a version number in the PE header", nullptr, nullptr)
OPTION(prefix_2, "version", dash_dash_version, Flag, INVALID, INVALID, nullptr, 0, 0,
"Print version information", nullptr, nullptr)
OPTION(prefix_1, "wholearchive:", wholearchive_file, Joined, INVALID, INVALID, nullptr, 0, 0,
"Include all object files from this archive", nullptr, nullptr)
OPTION(prefix_1, "wholearchive", wholearchive_flag, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "WX:no", WX_no, Flag, INVALID, INVALID, nullptr, 0, 0,
"Don't treat warnings as errors", nullptr, nullptr)
OPTION(prefix_1, "WX", WX, Flag, INVALID, INVALID, nullptr, 0, 0,
"Treat warnings as errors", nullptr, nullptr)
OPTION(prefix_3, "", help_q, Flag, INVALID, help, nullptr, 0, 0, nullptr, nullptr, nullptr)
#endif // OPTION
#ifdef OPTTABLE_ARG_INIT
//////////
// Option Values
#endif // OPTTABLE_ARG_INIT

View File

@@ -1,201 +0,0 @@
/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
|* *|
|* Option Parsing Definitions *|
|* *|
|* Automatically generated file, do not edit! *|
|* *|
\*===----------------------------------------------------------------------===*/
/////////
// Prefixes
#ifdef PREFIX
#define COMMA ,
PREFIX(prefix_0, {nullptr})
PREFIX(prefix_1, {"-" COMMA nullptr})
PREFIX(prefix_2, {"-" COMMA "--" COMMA nullptr})
#undef COMMA
#endif // PREFIX
/////////
// Groups
#ifdef OPTION
OPTION(nullptr, "opts", grp_bundle, Group, INVALID, INVALID, nullptr, 0, 0,
"BUNDLE EXECUTABLE OPTIONS", nullptr, nullptr)
OPTION(nullptr, "opts", grp_dylib, Group, INVALID, INVALID, nullptr, 0, 0,
"DYLIB EXECUTABLE OPTIONS", nullptr, nullptr)
OPTION(nullptr, "outs", grp_kind, Group, INVALID, INVALID, nullptr, 0, 0,
"OUTPUT KIND", nullptr, nullptr)
OPTION(nullptr, "libs", grp_libs, Group, INVALID, INVALID, nullptr, 0, 0,
"LIBRARY OPTIONS", nullptr, nullptr)
OPTION(nullptr, "opts", grp_main, Group, INVALID, INVALID, nullptr, 0, 0,
"MAIN EXECUTABLE OPTIONS", nullptr, nullptr)
OPTION(nullptr, "obsolete", grp_obsolete, Group, INVALID, INVALID, nullptr, 0, 0,
"OBSOLETE OPTIONS", nullptr, nullptr)
OPTION(nullptr, "opts", grp_opts, Group, INVALID, INVALID, nullptr, 0, 0,
"OPTIMIZATIONS", nullptr, nullptr)
//////////
// Options
OPTION(prefix_0, "<input>", INPUT, Input, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_0, "<unknown>", UNKNOWN, Unknown, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "all_load", all_load, Flag, grp_libs, INVALID, nullptr, 0, 0,
"Forces all members of all static libraries to be loaded", nullptr, nullptr)
OPTION(prefix_1, "arch", arch, Separate, INVALID, INVALID, nullptr, 0, 0,
"Architecture to link", "<arch-name>", nullptr)
OPTION(prefix_1, "bundle_loader", bundle_loader, Separate, grp_bundle, INVALID, nullptr, 0, 0,
"The executable that will be loading this Mach-O bundle", "<path>", nullptr)
OPTION(prefix_1, "bundle", bundle, Flag, grp_kind, INVALID, nullptr, 0, 0,
"Create dynamic bundle", nullptr, nullptr)
OPTION(prefix_1, "compatibility_version", compatibility_version, Separate, grp_dylib, INVALID, nullptr, 0, 0,
"The dylib's compatibility version", "<version>", nullptr)
OPTION(prefix_1, "current_version", current_version, Separate, grp_dylib, INVALID, nullptr, 0, 0,
"The dylib's current version", "<version>", nullptr)
OPTION(prefix_1, "data_in_code_info", data_in_code_info, Flag, grp_opts, INVALID, nullptr, 0, 0,
"Force generation of a data in code load command", nullptr, nullptr)
OPTION(prefix_1, "dead_strip", dead_strip, Flag, grp_opts, INVALID, nullptr, 0, 0,
"Remove unreference code and data", nullptr, nullptr)
OPTION(prefix_1, "demangle", demangle, Flag, INVALID, INVALID, nullptr, 0, 0,
"Demangles symbol names in errors and warnings", nullptr, nullptr)
OPTION(prefix_1, "dependency_info", dependency_info, Separate, INVALID, INVALID, nullptr, 0, 0,
"Write binary list of files used during link", "<file>", nullptr)
OPTION(prefix_1, "dylib_compatibility_version", dylib_compatibility_version, Separate, INVALID, compatibility_version, nullptr, 0, 0, nullptr, "<version>", nullptr)
OPTION(prefix_1, "dylib_current_version", dylib_current_version, Separate, INVALID, current_version, nullptr, 0, 0, nullptr, "<version>", nullptr)
OPTION(prefix_1, "dylib_install_name", dylib_install_name, Separate, INVALID, install_name, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "dylib", dylib, Flag, grp_kind, INVALID, nullptr, 0, 0,
"Create dynamic library", nullptr, nullptr)
OPTION(prefix_1, "dynamic", dynamic, Flag, grp_kind, INVALID, nullptr, 0, 0,
"Create dynamic executable (default)", nullptr, nullptr)
OPTION(prefix_2, "error-limit", error_limit, Separate, INVALID, INVALID, nullptr, 0, 0,
"Maximum number of errors to emit before stopping (0 = no limit)", "<number>", nullptr)
OPTION(prefix_1, "execute", execute, Flag, grp_kind, INVALID, nullptr, 0, 0,
"Create main executable (default)", nullptr, nullptr)
OPTION(prefix_1, "export_dynamic", export_dynamic, Flag, grp_main, INVALID, nullptr, 0, 0,
"Preserves all global symbols in main executables during LTO", nullptr, nullptr)
OPTION(prefix_1, "exported_symbols_list", exported_symbols_list, Separate, grp_opts, INVALID, nullptr, 0, 0,
"Restricts which symbols will be exported", "<file-path>", nullptr)
OPTION(prefix_1, "exported_symbol", exported_symbol, Separate, grp_opts, INVALID, nullptr, 0, 0,
"Restricts which symbols will be exported", "<symbol>", nullptr)
OPTION(prefix_1, "e", entry, Separate, grp_main, INVALID, nullptr, 0, 0,
"entry symbol name", "<entry-name>", nullptr)
OPTION(prefix_1, "filelist", filelist, Separate, INVALID, INVALID, nullptr, 0, 0,
"file containing paths to input files", "<path>", nullptr)
OPTION(prefix_1, "flat_namespace", flat_namespace, Flag, grp_opts, INVALID, nullptr, 0, 0,
"Resolves symbols in any (transitively) linked dynamic libraries. Source libraries are not recorded: dyld will re-search all images at runtime and use the first definition found.", nullptr, nullptr)
OPTION(prefix_1, "force_load", force_load, Separate, grp_libs, INVALID, nullptr, 0, 0,
"Forces all members of specified static libraries to be loaded", "<library-path>", nullptr)
OPTION(prefix_1, "framework", framework, Separate, INVALID, INVALID, nullptr, 0, 0,
"Base name of framework searched for in -F directories", "<name>", nullptr)
OPTION(prefix_1, "function_starts", function_starts, Flag, grp_opts, INVALID, nullptr, 0, 0,
"Force generation of a function starts load command", nullptr, nullptr)
OPTION(prefix_1, "F", F, JoinedOrSeparate, grp_libs, INVALID, nullptr, 0, 0,
"Add directory to framework search path", "<dir>", nullptr)
OPTION(prefix_1, "image_base", image_base, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "install_name", install_name, Separate, grp_dylib, INVALID, nullptr, 0, 0,
"The dylib's install name", "<path>", nullptr)
OPTION(prefix_1, "ios_simulator_version_min", ios_simulator_version_min, Separate, grp_opts, INVALID, nullptr, 0, 0,
"Minimum iOS simulator version", "<version>", nullptr)
OPTION(prefix_1, "ios_version_min", ios_version_min, Separate, grp_opts, INVALID, nullptr, 0, 0,
"Minimum iOS version", "<version>", nullptr)
OPTION(prefix_1, "iphoneos_version_min", iphoneos_version_min, Separate, INVALID, ios_version_min, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "keep_private_externs", keep_private_externs, Flag, grp_opts, INVALID, nullptr, 0, 0,
"Private extern (hidden) symbols should not be transformed into local symbols", nullptr, nullptr)
OPTION(prefix_1, "lto_library", lto_library, Separate, INVALID, INVALID, nullptr, 0, 0,
"Ignored for compatibility with other linkers", "<path>", nullptr)
OPTION(prefix_1, "L", L, JoinedOrSeparate, grp_libs, INVALID, nullptr, 0, 0,
"Add directory to library search path", "<dir>", nullptr)
OPTION(prefix_1, "l", l, Joined, INVALID, INVALID, nullptr, 0, 0,
"Base name of library searched for in -L directories", "<libname>", nullptr)
OPTION(prefix_1, "macosx_version_min", macosx_version_min, Separate, grp_opts, INVALID, nullptr, 0, 0,
"Minimum Mac OS X version", "<version>", nullptr)
OPTION(prefix_1, "mark_dead_strippable_dylib", mark_dead_strippable_dylib, Flag, grp_dylib, INVALID, nullptr, 0, 0,
"Marks the dylib as having no side effects during initialization", nullptr, nullptr)
OPTION(prefix_1, "mllvm", mllvm, Separate, grp_opts, INVALID, nullptr, 0, 0,
"Options to pass to LLVM during LTO", "<option>", nullptr)
OPTION(prefix_1, "multi_module", multi_module, Flag, grp_obsolete, INVALID, nullptr, 0, 0,
"Unsupported way to build dylibs", nullptr, nullptr)
OPTION(prefix_1, "no_data_in_code_info", no_data_in_code_info, Flag, grp_opts, INVALID, nullptr, 0, 0,
"Disable generation of a data in code load command", nullptr, nullptr)
OPTION(prefix_1, "no_function_starts", no_function_starts, Flag, grp_opts, INVALID, nullptr, 0, 0,
"Disable generation of a function starts load command", nullptr, nullptr)
OPTION(prefix_1, "no_objc_category_merging", no_objc_category_merging, Flag, grp_opts, INVALID, nullptr, 0, 0,
"Disables the optimisation which merges Objective-C categories on a class in to the class itself.", nullptr, nullptr)
OPTION(prefix_1, "no_pie", no_pie, Flag, grp_main, INVALID, nullptr, 0, 0,
"Do not create Position Independent Executable", nullptr, nullptr)
OPTION(prefix_1, "no_version_load_command", no_version_load_command, Flag, grp_opts, INVALID, nullptr, 0, 0,
"Disable generation of a version load command", nullptr, nullptr)
OPTION(prefix_1, "objc_gc_compaction", objc_gc_compaction, Flag, grp_obsolete, INVALID, nullptr, 0, 0,
"Unsupported ObjC GC option", nullptr, nullptr)
OPTION(prefix_1, "objc_gc_only", objc_gc_only, Flag, grp_obsolete, INVALID, nullptr, 0, 0,
"Unsupported ObjC GC option", nullptr, nullptr)
OPTION(prefix_1, "objc_gc", objc_gc, Flag, grp_obsolete, INVALID, nullptr, 0, 0,
"Unsupported ObjC GC option", nullptr, nullptr)
OPTION(prefix_1, "order_file", order_file, Separate, grp_opts, INVALID, nullptr, 0, 0,
"re-order and move specified symbols to start of their section", "<file-path>", nullptr)
OPTION(prefix_1, "o", output, Separate, INVALID, INVALID, nullptr, 0, 0,
"Output file path", "<path>", nullptr)
OPTION(prefix_1, "path_exists", path_exists, Separate, INVALID, INVALID, nullptr, 0, 0,
"Used with -test_file_usage to declare a path", "<path>", nullptr)
OPTION(prefix_1, "pie", pie, Flag, grp_main, INVALID, nullptr, 0, 0,
"Create Position Independent Executable (for ASLR)", nullptr, nullptr)
OPTION(prefix_1, "preload", preload, Flag, grp_kind, INVALID, nullptr, 0, 0,
"Create binary for use with embedded systems", nullptr, nullptr)
OPTION(prefix_1, "print_atoms", print_atoms, Flag, INVALID, INVALID, nullptr, 0, 0,
"Emit output as yaml atoms", nullptr, nullptr)
OPTION(prefix_1, "rpath", rpath, Separate, INVALID, INVALID, nullptr, 0, 0,
"Add path to the runpath search path list for image being created", "<path>", nullptr)
OPTION(prefix_1, "r", relocatable, Flag, grp_kind, INVALID, nullptr, 0, 0,
"Create relocatable object file", nullptr, nullptr)
OPTION(prefix_1, "sdk_version", sdk_version, Separate, grp_opts, INVALID, nullptr, 0, 0,
"SDK version", "<version>", nullptr)
OPTION(prefix_1, "sectalign", sectalign, MultiArg, INVALID, INVALID, nullptr, 0, 3,
"Alignment for segment/section", "<segname> <sectname> <alignment>", nullptr)
OPTION(prefix_1, "sectcreate", sectcreate, MultiArg, INVALID, INVALID, nullptr, 0, 3,
"Create section <segname>/<sectname> from contents of <file>", "<segname> <sectname> <file>", nullptr)
OPTION(prefix_1, "seg1addr", seg1addr, Separate, INVALID, image_base, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "single_module", single_module, Flag, grp_obsolete, INVALID, nullptr, 0, 0,
"Default for dylibs", nullptr, nullptr)
OPTION(prefix_1, "source_version", source_version, Separate, grp_opts, INVALID, nullptr, 0, 0,
"Source version", "<version>", nullptr)
OPTION(prefix_1, "stack_size", stack_size, Separate, grp_main, INVALID, nullptr, 0, 0,
"Specifies the maximum stack size for the main thread in a program. Must be a page-size multiple. (default=8Mb)", nullptr, nullptr)
OPTION(prefix_1, "static", static, Flag, grp_kind, INVALID, nullptr, 0, 0,
"Create static executable", nullptr, nullptr)
OPTION(prefix_1, "syslibroot", syslibroot, Separate, grp_libs, INVALID, nullptr, 0, 0,
"Add path to SDK to all absolute library search paths", "<dir>", nullptr)
OPTION(prefix_1, "S", S, Flag, INVALID, INVALID, nullptr, 0, 0,
"Remove debug information (STABS or DWARF) from the output file", nullptr, nullptr)
OPTION(prefix_1, "test_file_usage", test_file_usage, Flag, INVALID, INVALID, nullptr, 0, 0,
"Only files specified by -file_exists are considered to exist. Print which files would be used", nullptr, nullptr)
OPTION(prefix_1, "twolevel_namespace", twolevel_namespace, Flag, grp_opts, INVALID, nullptr, 0, 0,
"Resolves symbols in listed libraries only. Source libraries are recorded in the symbol table.", nullptr, nullptr)
OPTION(prefix_1, "t", t, Flag, INVALID, INVALID, nullptr, 0, 0,
"Print the names of the input files as ld processes them", nullptr, nullptr)
OPTION(prefix_1, "undefined", undefined, Separate, grp_opts, INVALID, nullptr, 0, 0,
"Determines how undefined symbols are handled.", "<undefined>", nullptr)
OPTION(prefix_1, "unexported_symbols_list", unexported_symbols_list, Separate, grp_opts, INVALID, nullptr, 0, 0,
"Lists symbols that should not be exported", "<file-path>", nullptr)
OPTION(prefix_1, "unexported_symbol", unexported_symbol, Separate, grp_opts, INVALID, nullptr, 0, 0,
"A symbol which should not be exported", "<symbol>", nullptr)
OPTION(prefix_1, "upward-l", upward_l, Joined, INVALID, INVALID, nullptr, 0, 0,
"Base name of upward library searched for in -L directories", "<libname>", nullptr)
OPTION(prefix_1, "upward_framework", upward_framework, Separate, INVALID, INVALID, nullptr, 0, 0,
"Base name of upward framework searched for in -F directories", "<name>", nullptr)
OPTION(prefix_1, "upward_library", upward_library, Separate, INVALID, INVALID, nullptr, 0, 0,
"path to upward dylib to link with", "<path>", nullptr)
OPTION(prefix_1, "version_load_command", version_load_command, Flag, grp_opts, INVALID, nullptr, 0, 0,
"Force generation of a version load command", nullptr, nullptr)
OPTION(prefix_1, "v", v, Flag, INVALID, INVALID, nullptr, 0, 0,
"Print linker information", nullptr, nullptr)
OPTION(prefix_1, "Z", Z, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not search standard directories for libraries or frameworks", nullptr, nullptr)
#endif // OPTION
#ifdef OPTTABLE_ARG_INIT
//////////
// Option Values
#endif // OPTTABLE_ARG_INIT

View File

@@ -1,598 +0,0 @@
/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
|* *|
|* Option Parsing Definitions *|
|* *|
|* Automatically generated file, do not edit! *|
|* *|
\*===----------------------------------------------------------------------===*/
/////////
// Prefixes
#ifdef PREFIX
#define COMMA ,
PREFIX(prefix_0, {nullptr})
PREFIX(prefix_1, {"-" COMMA nullptr})
PREFIX(prefix_4, {"-" COMMA "--" COMMA nullptr})
PREFIX(prefix_3, {"--" COMMA nullptr})
PREFIX(prefix_2, {"--" COMMA "-" COMMA nullptr})
#undef COMMA
#endif // PREFIX
/////////
// Groups
#ifdef OPTION
//////////
// Options
OPTION(prefix_0, "<input>", INPUT, Input, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_0, "<unknown>", UNKNOWN, Unknown, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "(", anonymous_31, Flag, INVALID, start_group, nullptr, 0, 0,
"Alias for --start-group", nullptr, nullptr)
OPTION(prefix_1, ")", anonymous_12, Flag, INVALID, end_group, nullptr, 0, 0,
"Alias for --end-group", nullptr, nullptr)
OPTION(prefix_2, "allow-multiple-definition", allow_multiple_definition, Flag, INVALID, INVALID, nullptr, 0, 0,
"Allow multiple definitions", nullptr, nullptr)
OPTION(prefix_2, "allow-shlib-undefined", allow_shlib_undefined, Flag, INVALID, INVALID, nullptr, 0, 0,
"Allow unresolved references in shared libraries (default when linking a shared library)", nullptr, nullptr)
OPTION(prefix_2, "apply-dynamic-relocs", apply_dynamic_relocs, Flag, INVALID, INVALID, nullptr, 0, 0,
"Apply link-time values for dynamic relocations", nullptr, nullptr)
OPTION(prefix_2, "as-needed", as_needed, Flag, INVALID, INVALID, nullptr, 0, 0,
"Only set DT_NEEDED for shared libraries if used", nullptr, nullptr)
OPTION(prefix_2, "auxiliary=", auxiliary_eq, Joined, INVALID, auxiliary, nullptr, 0, 0,
"Set DT_AUXILIARY field to the specified name", nullptr, nullptr)
OPTION(prefix_2, "auxiliary", auxiliary, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "Bdynamic", Bdynamic, Flag, INVALID, INVALID, nullptr, 0, 0,
"Link against shared libraries (default)", nullptr, nullptr)
OPTION(prefix_2, "Bshareable", anonymous_29, Flag, INVALID, shared, nullptr, 0, 0,
"Alias for --shared", nullptr, nullptr)
OPTION(prefix_2, "Bstatic", Bstatic, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not link against shared libraries", nullptr, nullptr)
OPTION(prefix_2, "Bsymbolic-functions", Bsymbolic_functions, Flag, INVALID, INVALID, nullptr, 0, 0,
"Bind defined function symbols locally", nullptr, nullptr)
OPTION(prefix_2, "Bsymbolic", Bsymbolic, Flag, INVALID, INVALID, nullptr, 0, 0,
"Bind defined symbols locally", nullptr, nullptr)
OPTION(prefix_2, "build-id=", build_id_eq, Joined, INVALID, INVALID, nullptr, 0, 0,
"Generate build ID note", "[fast,md5,sha1,uuid,0x<hexstring>]", nullptr)
OPTION(prefix_2, "build-id", build_id, Flag, INVALID, INVALID, nullptr, 0, 0,
"Alias for --build-id=fast", nullptr, nullptr)
OPTION(prefix_1, "b", anonymous_16, Separate, INVALID, format, nullptr, 0, 0,
"Alias for --format", nullptr, nullptr)
OPTION(prefix_2, "call-graph-ordering-file=", call_graph_ordering_file_eq, Joined, INVALID, call_graph_ordering_file, nullptr, 0, 0,
"Layout sections to optimize the given callgraph", nullptr, nullptr)
OPTION(prefix_2, "call-graph-ordering-file", call_graph_ordering_file, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "call-graph-profile-sort", call_graph_profile_sort, Flag, INVALID, INVALID, nullptr, 0, 0,
"Reorder sections with call graph profile (default)", nullptr, nullptr)
OPTION(prefix_2, "call_shared", anonymous_1, Flag, INVALID, Bdynamic, nullptr, 0, 0,
"Alias for --Bdynamic", nullptr, nullptr)
OPTION(prefix_2, "check-sections", check_sections, Flag, INVALID, INVALID, nullptr, 0, 0,
"Check section addresses for overlaps (default)", nullptr, nullptr)
OPTION(prefix_2, "chroot", chroot, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "color-diagnostics=", color_diagnostics_eq, Joined, INVALID, INVALID, nullptr, 0, 0,
"Use colors in diagnostics", "[auto,always,never]", nullptr)
OPTION(prefix_2, "color-diagnostics", color_diagnostics, Flag, INVALID, INVALID, nullptr, 0, 0,
"Alias for --color-diagnostics=always", nullptr, nullptr)
OPTION(prefix_2, "compress-debug-sections=", compress_debug_sections_eq, Joined, INVALID, compress_debug_sections, nullptr, 0, 0,
"Compress DWARF debug sections", "[none,zlib]", nullptr)
OPTION(prefix_2, "compress-debug-sections", compress_debug_sections, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, "[none,zlib]", nullptr)
OPTION(prefix_2, "cref", cref, Flag, INVALID, INVALID, nullptr, 0, 0,
"Output cross reference table", nullptr, nullptr)
OPTION(prefix_2, "dc", anonymous_7, Flag, INVALID, define_common, nullptr, 0, 0,
"Alias for --define-common", nullptr, nullptr)
OPTION(prefix_2, "define-common", define_common, Flag, INVALID, INVALID, nullptr, 0, 0,
"Assign space to common symbols", nullptr, nullptr)
OPTION(prefix_2, "defsym=", defsym_eq, Joined, INVALID, defsym, nullptr, 0, 0,
"Define a symbol alias", "<symbol>=<value>", nullptr)
OPTION(prefix_2, "defsym", defsym, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, "<symbol>=<value>", nullptr)
OPTION(prefix_2, "demangle", demangle, Flag, INVALID, INVALID, nullptr, 0, 0,
"Demangle symbol names (default)", nullptr, nullptr)
OPTION(prefix_2, "dependent-libraries", dependent_libraries, Flag, INVALID, INVALID, nullptr, 0, 0,
"Process dependent library specifiers from input files (default)", nullptr, nullptr)
OPTION(prefix_2, "detect-odr-violations", anonymous_50, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "disable-new-dtags", disable_new_dtags, Flag, INVALID, INVALID, nullptr, 0, 0,
"Disable new dynamic tags", nullptr, nullptr)
OPTION(prefix_2, "disable-verify", disable_verify, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "discard-all", discard_all, Flag, INVALID, INVALID, nullptr, 0, 0,
"Delete all local symbols", nullptr, nullptr)
OPTION(prefix_2, "discard-locals", discard_locals, Flag, INVALID, INVALID, nullptr, 0, 0,
"Delete temporary local symbols", nullptr, nullptr)
OPTION(prefix_2, "discard-none", discard_none, Flag, INVALID, INVALID, nullptr, 0, 0,
"Keep all symbols in the symbol table", nullptr, nullptr)
OPTION(prefix_2, "dn", anonymous_3, Flag, INVALID, Bstatic, nullptr, 0, 0,
"Alias for --Bstatic", nullptr, nullptr)
OPTION(prefix_2, "dp", anonymous_8, Flag, INVALID, define_common, nullptr, 0, 0,
"Alias for --define-common", nullptr, nullptr)
OPTION(prefix_2, "dynamic-linker=", dynamic_linker_eq, Joined, INVALID, dynamic_linker, nullptr, 0, 0,
"Which dynamic linker to use", nullptr, nullptr)
OPTION(prefix_2, "dynamic-linker", dynamic_linker, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "dynamic-list=", dynamic_list_eq, Joined, INVALID, dynamic_list, nullptr, 0, 0,
"Read a list of dynamic symbols", nullptr, nullptr)
OPTION(prefix_2, "dynamic-list", dynamic_list, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "dy", anonymous_2, Flag, INVALID, Bdynamic, nullptr, 0, 0,
"Alias for --Bdynamic", nullptr, nullptr)
OPTION(prefix_1, "d", anonymous_6, Flag, INVALID, define_common, nullptr, 0, 0,
"Alias for --define-common", nullptr, nullptr)
OPTION(prefix_2, "EB", anonymous_69, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "eh-frame-hdr", eh_frame_hdr, Flag, INVALID, INVALID, nullptr, 0, 0,
"Request creation of .eh_frame_hdr section and PT_GNU_EH_FRAME segment header", nullptr, nullptr)
OPTION(prefix_2, "EL", anonymous_70, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "emit-relocs", emit_relocs, Flag, INVALID, INVALID, nullptr, 0, 0,
"Generate relocations in output", nullptr, nullptr)
OPTION(prefix_2, "enable-new-dtags", enable_new_dtags, Flag, INVALID, INVALID, nullptr, 0, 0,
"Enable new dynamic tags (default)", nullptr, nullptr)
OPTION(prefix_2, "end-group", end_group, Flag, INVALID, INVALID, nullptr, 0, 0,
"Ignored for compatibility with GNU unless you pass --warn-backrefs", nullptr, nullptr)
OPTION(prefix_2, "end-lib", end_lib, Flag, INVALID, INVALID, nullptr, 0, 0,
"End a grouping of objects that should be treated as if they were together in an archive", nullptr, nullptr)
OPTION(prefix_2, "entry=", entry_eq, Joined, INVALID, entry, nullptr, 0, 0,
"Name of entry point symbol", "<entry>", nullptr)
OPTION(prefix_2, "entry", entry, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, "<entry>", nullptr)
OPTION(prefix_2, "error-limit=", error_limit_eq, Joined, INVALID, error_limit, nullptr, 0, 0,
"Maximum number of errors to emit before stopping (0 = no limit)", nullptr, nullptr)
OPTION(prefix_2, "error-limit", error_limit, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "error-unresolved-symbols", error_unresolved_symbols, Flag, INVALID, INVALID, nullptr, 0, 0,
"Report unresolved symbols as errors", nullptr, nullptr)
OPTION(prefix_2, "exclude-libs=", exclude_libs_eq, Joined, INVALID, exclude_libs, nullptr, 0, 0,
"Exclude static libraries from automatic export", nullptr, nullptr)
OPTION(prefix_2, "exclude-libs", exclude_libs, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "execute-only", execute_only, Flag, INVALID, INVALID, nullptr, 0, 0,
"Mark executable sections unreadable", nullptr, nullptr)
OPTION(prefix_2, "export-dynamic-symbol=", export_dynamic_symbol_eq, Joined, INVALID, export_dynamic_symbol, nullptr, 0, 0,
"Put a symbol in the dynamic symbol table", nullptr, nullptr)
OPTION(prefix_2, "export-dynamic-symbol", export_dynamic_symbol, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "export-dynamic", export_dynamic, Flag, INVALID, INVALID, nullptr, 0, 0,
"Put symbols in the dynamic symbol table", nullptr, nullptr)
OPTION(prefix_1, "E", anonymous_14, Flag, INVALID, export_dynamic, nullptr, 0, 0,
"Alias for --export-dynamic", nullptr, nullptr)
OPTION(prefix_1, "e", anonymous_13, JoinedOrSeparate, INVALID, entry, nullptr, 0, 0,
"Alias for --entry", nullptr, nullptr)
OPTION(prefix_2, "fatal-warnings", fatal_warnings, Flag, INVALID, INVALID, nullptr, 0, 0,
"Treat warnings as errors", nullptr, nullptr)
OPTION(prefix_2, "filter=", filter_eq, Joined, INVALID, filter, nullptr, 0, 0,
"Set DT_FILTER field to the specified name", nullptr, nullptr)
OPTION(prefix_2, "filter", filter, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "fini=", fini_eq, Joined, INVALID, fini, nullptr, 0, 0,
"Specify a finalizer function", "<symbol>", nullptr)
OPTION(prefix_2, "fini", fini, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, "<symbol>", nullptr)
OPTION(prefix_2, "fix-cortex-a53-843419", fix_cortex_a53_843419, Flag, INVALID, INVALID, nullptr, 0, 0,
"Apply fixes for AArch64 Cortex-A53 erratum 843419", nullptr, nullptr)
OPTION(prefix_2, "force-bti", force_bti, Flag, INVALID, INVALID, nullptr, 0, 0,
"Force enable AArch64 BTI in PLT, warn if Input ELF file does not have GNU_PROPERTY_AARCH64_FEATURE_1_BTI property", nullptr, nullptr)
OPTION(prefix_2, "format=", format_eq, Joined, INVALID, format, nullptr, 0, 0,
"Change the input format of the inputs following this option", "[default,elf,binary]", nullptr)
OPTION(prefix_2, "format", format, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, "[default,elf,binary]", nullptr)
OPTION(prefix_1, "F", anonymous_15, Separate, INVALID, filter, nullptr, 0, 0,
"Alias for --filter", nullptr, nullptr)
OPTION(prefix_1, "f", anonymous_0, Separate, INVALID, auxiliary, nullptr, 0, 0,
"Alias for --auxiliary", nullptr, nullptr)
OPTION(prefix_2, "gc-sections", gc_sections, Flag, INVALID, INVALID, nullptr, 0, 0,
"Enable garbage collection of unused sections", nullptr, nullptr)
OPTION(prefix_2, "gdb-index", gdb_index, Flag, INVALID, INVALID, nullptr, 0, 0,
"Generate .gdb_index section", nullptr, nullptr)
OPTION(prefix_2, "gnu-unique", gnu_unique, Flag, INVALID, INVALID, nullptr, 0, 0,
"Enable STB_GNU_UNIQUE symbol binding (default)", nullptr, nullptr)
OPTION(prefix_1, "G", anonymous_71, JoinedOrSeparate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "g", anonymous_51, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "hash-style=", hash_style_eq, Joined, INVALID, hash_style, nullptr, 0, 0,
"Specify hash style (sysv, gnu or both)", nullptr, nullptr)
OPTION(prefix_2, "hash-style", hash_style, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "help", help, Flag, INVALID, INVALID, nullptr, 0, 0,
"Print option help", nullptr, nullptr)
OPTION(prefix_1, "h", anonymous_30, JoinedOrSeparate, INVALID, soname, nullptr, 0, 0,
"Alias for --soname", nullptr, nullptr)
OPTION(prefix_2, "icf=all", icf_all, Flag, INVALID, INVALID, nullptr, 0, 0,
"Enable identical code folding", nullptr, nullptr)
OPTION(prefix_2, "icf=none", icf_none, Flag, INVALID, INVALID, nullptr, 0, 0,
"Disable identical code folding (default)", nullptr, nullptr)
OPTION(prefix_2, "icf=safe", icf_safe, Flag, INVALID, INVALID, nullptr, 0, 0,
"Enable safe identical code folding", nullptr, nullptr)
OPTION(prefix_2, "ignore-data-address-equality", ignore_data_address_equality, Flag, INVALID, INVALID, nullptr, 0, 0,
"lld can break the address equality of data", nullptr, nullptr)
OPTION(prefix_2, "ignore-function-address-equality", ignore_function_address_equality, Flag, INVALID, INVALID, nullptr, 0, 0,
"lld can break the address equality of functions", nullptr, nullptr)
OPTION(prefix_2, "image-base=", image_base_eq, Joined, INVALID, image_base, nullptr, 0, 0,
"Set the base address", nullptr, nullptr)
OPTION(prefix_2, "image-base", image_base, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "init=", init_eq, Joined, INVALID, init, nullptr, 0, 0,
"Specify an initializer function", "<symbol>", nullptr)
OPTION(prefix_2, "init", init, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, "<symbol>", nullptr)
OPTION(prefix_2, "just-symbols=", just_symbols_eq, Joined, INVALID, just_symbols, nullptr, 0, 0,
"Just link symbols", nullptr, nullptr)
OPTION(prefix_2, "just-symbols", just_symbols, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "keep-unique=", keep_unique_eq, Joined, INVALID, keep_unique, nullptr, 0, 0,
"Do not fold this symbol during ICF", nullptr, nullptr)
OPTION(prefix_2, "keep-unique", keep_unique, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "library-path=", library_path_eq, Joined, INVALID, library_path, nullptr, 0, 0,
"Add a directory to the library search path", "<dir>", nullptr)
OPTION(prefix_2, "library-path", library_path, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, "<dir>", nullptr)
OPTION(prefix_2, "library=", library_eq, Joined, INVALID, library, nullptr, 0, 0,
"Root name of library to use", "<libName>", nullptr)
OPTION(prefix_2, "library", library, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, "<libName>", nullptr)
OPTION(prefix_2, "long-plt", anonymous_52, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "lto-aa-pipeline=", lto_aa_pipeline, Joined, INVALID, INVALID, nullptr, 0, 0,
"AA pipeline to run during LTO. Used in conjunction with -lto-newpm-passes", nullptr, nullptr)
OPTION(prefix_2, "lto-cs-profile-file=", lto_cs_profile_file, Joined, INVALID, INVALID, nullptr, 0, 0,
"Context sensitive profile file path", nullptr, nullptr)
OPTION(prefix_2, "lto-cs-profile-generate", lto_cs_profile_generate, Flag, INVALID, INVALID, nullptr, 0, 0,
"Perform context senstive PGO instrumentation", nullptr, nullptr)
OPTION(prefix_2, "lto-debug-pass-manager", lto_debug_pass_manager, Flag, INVALID, INVALID, nullptr, 0, 0,
"Debug new pass manager", nullptr, nullptr)
OPTION(prefix_2, "lto-new-pass-manager", lto_new_pass_manager, Flag, INVALID, INVALID, nullptr, 0, 0,
"Use new pass manager", nullptr, nullptr)
OPTION(prefix_2, "lto-newpm-passes=", lto_newpm_passes, Joined, INVALID, INVALID, nullptr, 0, 0,
"Passes to run during LTO", nullptr, nullptr)
OPTION(prefix_2, "lto-O", lto_O, Joined, INVALID, INVALID, nullptr, 0, 0,
"Optimization level for LTO", "<opt-level>", nullptr)
OPTION(prefix_2, "lto-partitions=", lto_partitions, Joined, INVALID, INVALID, nullptr, 0, 0,
"Number of LTO codegen partitions", nullptr, nullptr)
OPTION(prefix_2, "lto-sample-profile=", lto_sample_profile, Joined, INVALID, INVALID, nullptr, 0, 0,
"Sample profile file path", nullptr, nullptr)
OPTION(prefix_1, "L", anonymous_18, JoinedOrSeparate, INVALID, library_path, nullptr, 0, 0,
"Alias for --library-path", nullptr, nullptr)
OPTION(prefix_1, "l", anonymous_17, JoinedOrSeparate, INVALID, library, nullptr, 0, 0,
"Alias for --library", nullptr, nullptr)
OPTION(prefix_2, "Map=", Map_eq, Joined, INVALID, Map, nullptr, 0, 0,
"Print a link map to the specified file", nullptr, nullptr)
OPTION(prefix_2, "Map", Map, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "merge-exidx-entries", merge_exidx_entries, Flag, INVALID, INVALID, nullptr, 0, 0,
"Enable merging .ARM.exidx entries (default)", nullptr, nullptr)
OPTION(prefix_2, "mips-got-size=", mips_got_size_eq, Joined, INVALID, mips_got_size, nullptr, HelpHidden, 0,
"Max size of a single MIPS GOT. 0x10000 by default.", nullptr, nullptr)
OPTION(prefix_2, "mips-got-size", mips_got_size, Separate, INVALID, INVALID, nullptr, HelpHidden, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "mllvm=", mllvm_eq, Joined, INVALID, mllvm, nullptr, 0, 0,
"Additional arguments to forward to LLVM's option processing", nullptr, nullptr)
OPTION(prefix_2, "mllvm", mllvm, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "M", anonymous_25, Flag, INVALID, print_map, nullptr, 0, 0,
"Alias for --print-map", nullptr, nullptr)
OPTION(prefix_1, "m", m, JoinedOrSeparate, INVALID, INVALID, nullptr, 0, 0,
"Set target emulation", nullptr, nullptr)
OPTION(prefix_2, "nmagic", nmagic, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not page align sections, link against static libraries.", "<magic>", nullptr)
OPTION(prefix_2, "no-add-needed", anonymous_53, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "no-allow-multiple-definition", no_allow_multiple_definition, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not allow multiple definitions (default)", nullptr, nullptr)
OPTION(prefix_2, "no-allow-shlib-undefined", no_allow_shlib_undefined, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not allow unresolved references in shared libraries (default when linking an executable)", nullptr, nullptr)
OPTION(prefix_2, "no-apply-dynamic-relocs", no_apply_dynamic_relocs, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not apply link-time values for dynamic relocations (default)", nullptr, nullptr)
OPTION(prefix_2, "no-as-needed", no_as_needed, Flag, INVALID, INVALID, nullptr, 0, 0,
"Always set DT_NEEDED for shared libraries (default)", nullptr, nullptr)
OPTION(prefix_2, "no-call-graph-profile-sort", no_call_graph_profile_sort, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not reorder sections with call graph profile", nullptr, nullptr)
OPTION(prefix_2, "no-check-sections", no_check_sections, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not check section addresses for overlaps", nullptr, nullptr)
OPTION(prefix_2, "no-color-diagnostics", no_color_diagnostics, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not use colors in diagnostics", nullptr, nullptr)
OPTION(prefix_2, "no-copy-dt-needed-entries", anonymous_54, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "no-cref", no_cref, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not output cross reference table", nullptr, nullptr)
OPTION(prefix_2, "no-ctors-in-init-array", anonymous_55, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "no-define-common", no_define_common, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not assign space to common symbols", nullptr, nullptr)
OPTION(prefix_2, "no-demangle", no_demangle, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not demangle symbol names", nullptr, nullptr)
OPTION(prefix_2, "no-dependent-libraries", no_dependent_libraries, Flag, INVALID, INVALID, nullptr, 0, 0,
"Ignore dependent library specifiers from input files", nullptr, nullptr)
OPTION(prefix_2, "no-dynamic-linker", no_dynamic_linker, Flag, INVALID, INVALID, nullptr, 0, 0,
"Inhibit output of .interp section", nullptr, nullptr)
OPTION(prefix_2, "no-eh-frame-hdr", no_eh_frame_hdr, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not create .eh_frame_hdr section", nullptr, nullptr)
OPTION(prefix_2, "no-execute-only", no_execute_only, Flag, INVALID, INVALID, nullptr, 0, 0,
"Mark executable sections readable (default)", nullptr, nullptr)
OPTION(prefix_2, "no-export-dynamic", no_export_dynamic, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not put symbols in the dynamic symbol table (default)", nullptr, nullptr)
OPTION(prefix_2, "no-fatal-warnings", no_fatal_warnings, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not treat warnings as errors (default)", nullptr, nullptr)
OPTION(prefix_2, "no-gc-sections", no_gc_sections, Flag, INVALID, INVALID, nullptr, 0, 0,
"Disable garbage collection of unused sections (default)", nullptr, nullptr)
OPTION(prefix_2, "no-gdb-index", no_gdb_index, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not generate .gdb_index section (default)", nullptr, nullptr)
OPTION(prefix_2, "no-gnu-unique", no_gnu_unique, Flag, INVALID, INVALID, nullptr, 0, 0,
"Disable STB_GNU_UNIQUE symbol binding", nullptr, nullptr)
OPTION(prefix_2, "no-keep-memory", anonymous_56, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "no-merge-exidx-entries", no_merge_exidx_entries, Flag, INVALID, INVALID, nullptr, 0, 0,
"Disable merging .ARM.exidx entries", nullptr, nullptr)
OPTION(prefix_2, "no-mmap-output-file", anonymous_57, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "no-nmagic", no_nmagic, Flag, INVALID, INVALID, nullptr, 0, 0,
"Page align sections (default)", "<magic>", nullptr)
OPTION(prefix_2, "no-omagic", no_omagic, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not set the text data sections to be writable, page align sections (default)", "<magic>", nullptr)
OPTION(prefix_2, "no-pic-executable", anonymous_19, Flag, INVALID, no_pie, nullptr, 0, 0,
"Alias for --no-pie", nullptr, nullptr)
OPTION(prefix_2, "no-pie", no_pie, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not create a position independent executable (default)", nullptr, nullptr)
OPTION(prefix_2, "no-pipeline-knowledge", anonymous_58, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "no-print-gc-sections", no_print_gc_sections, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not list removed unused sections (default)", nullptr, nullptr)
OPTION(prefix_2, "no-print-icf-sections", no_print_icf_sections, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not list identical folded sections (default)", nullptr, nullptr)
OPTION(prefix_2, "no-rosegment", no_rosegment, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not put read-only non-executable sections in their own segment", nullptr, nullptr)
OPTION(prefix_2, "no-threads", no_threads, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not run the linker multi-threaded", nullptr, nullptr)
OPTION(prefix_2, "no-toc-optimize", no_toc_optimize, Flag, INVALID, INVALID, nullptr, 0, 0,
"(PowerPC64) Disable TOC related optimizations", nullptr, nullptr)
OPTION(prefix_2, "no-undefined-version", no_undefined_version, Flag, INVALID, INVALID, nullptr, 0, 0,
"Report version scripts that refer undefined symbols", nullptr, nullptr)
OPTION(prefix_2, "no-undefined", no_undefined, Flag, INVALID, INVALID, nullptr, 0, 0,
"Report unresolved symbols even if the linker is creating a shared library", nullptr, nullptr)
OPTION(prefix_2, "no-use-android-relr-tags", no_use_android_relr_tags, Flag, INVALID, INVALID, nullptr, 0, 0,
"Use SHT_RELR / DT_RELR* tags (default)", nullptr, nullptr)
OPTION(prefix_2, "no-warn-backrefs", no_warn_backrefs, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not warn about backward symbol references to fetch archive members (default)", nullptr, nullptr)
OPTION(prefix_2, "no-warn-common", no_warn_common, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not warn about duplicate common symbols (default)", nullptr, nullptr)
OPTION(prefix_2, "no-warn-ifunc-textrel", no_warn_ifunc_textrel, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not warn about using ifunc symbols with text relocations (default)", nullptr, nullptr)
OPTION(prefix_2, "no-warn-mismatch", anonymous_59, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "no-warn-symbol-ordering", no_warn_symbol_ordering, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not warn about problems with the symbol ordering file", nullptr, nullptr)
OPTION(prefix_2, "no-whole-archive", no_whole_archive, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not force load of all members in a static library (default)", nullptr, nullptr)
OPTION(prefix_2, "noinhibit-exec", noinhibit_exec, Flag, INVALID, INVALID, nullptr, 0, 0,
"Retain the executable output file whenever it is still usable", nullptr, nullptr)
OPTION(prefix_2, "non_shared", anonymous_4, Flag, INVALID, Bstatic, nullptr, 0, 0,
"Alias for --Bstatic", nullptr, nullptr)
OPTION(prefix_2, "nostdlib", nostdlib, Flag, INVALID, INVALID, nullptr, 0, 0,
"Only search directories specified on the command line", nullptr, nullptr)
OPTION(prefix_1, "N", anonymous_21, Flag, INVALID, omagic, nullptr, 0, 0,
"Alias for --omagic", nullptr, nullptr)
OPTION(prefix_1, "n", anonymous_20, Flag, INVALID, nmagic, nullptr, 0, 0,
"Alias for --nmagic", nullptr, nullptr)
OPTION(prefix_3, "oformat", oformat, Separate, INVALID, INVALID, nullptr, 0, 0,
"Specify the binary format for the output object file", "<format>", nullptr)
OPTION(prefix_3, "omagic", omagic, Flag, INVALID, INVALID, nullptr, 0, 0,
"Set the text and data sections to be readable and writable, do not page align sections, link against static libraries", "<magic>", nullptr)
OPTION(prefix_3, "opt-remarks-filename", opt_remarks_filename, Separate, INVALID, INVALID, nullptr, 0, 0,
"YAML output file for optimization remarks", nullptr, nullptr)
OPTION(prefix_3, "opt-remarks-format", opt_remarks_format, Separate, INVALID, INVALID, nullptr, 0, 0,
"The format used for serializing remarks (default: YAML)", nullptr, nullptr)
OPTION(prefix_3, "opt-remarks-passes", opt_remarks_passes, Separate, INVALID, INVALID, nullptr, 0, 0,
"Regex for the passes that need to be serialized to the output file", nullptr, nullptr)
OPTION(prefix_3, "opt-remarks-with-hotness", opt_remarks_with_hotness, Flag, INVALID, INVALID, nullptr, 0, 0,
"Include hotness information in the optimization remarks file", nullptr, nullptr)
OPTION(prefix_2, "orphan-handling=", orphan_handling_eq, Joined, INVALID, orphan_handling, nullptr, 0, 0,
"Control how orphan sections are handled when linker script used", nullptr, nullptr)
OPTION(prefix_2, "orphan-handling", orphan_handling, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_3, "output=", anonymous_22, Joined, INVALID, o, nullptr, 0, 0,
"Alias for -o", nullptr, nullptr)
OPTION(prefix_3, "output", anonymous_23, Separate, INVALID, o, nullptr, 0, 0,
"Alias for -o", nullptr, nullptr)
OPTION(prefix_1, "O", O, JoinedOrSeparate, INVALID, INVALID, nullptr, 0, 0,
"Optimize output file size", nullptr, nullptr)
OPTION(prefix_1, "o", o, JoinedOrSeparate, INVALID, INVALID, nullptr, 0, 0,
"Path to file to write output", "<path>", nullptr)
OPTION(prefix_2, "pac-plt", pac_plt, Flag, INVALID, INVALID, nullptr, 0, 0,
"AArch64 only, use pointer authentication in PLT", nullptr, nullptr)
OPTION(prefix_2, "pack-dyn-relocs=", pack_dyn_relocs_eq, Joined, INVALID, pack_dyn_relocs, nullptr, 0, 0,
"Pack dynamic relocations in the given format", "[none,android,relr,android+relr]", nullptr)
OPTION(prefix_2, "pack-dyn-relocs", pack_dyn_relocs, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, "[none,android,relr,android+relr]", nullptr)
OPTION(prefix_2, "pic-executable", anonymous_24, Flag, INVALID, pie, nullptr, 0, 0,
"Alias for --pie", nullptr, nullptr)
OPTION(prefix_2, "pic-veneer", pic_veneer, Flag, INVALID, INVALID, nullptr, 0, 0,
"Always generate position independent thunks (veneers)", nullptr, nullptr)
OPTION(prefix_2, "pie", pie, Flag, INVALID, INVALID, nullptr, 0, 0,
"Create a position independent executable", nullptr, nullptr)
OPTION(prefix_2, "plugin-opt=-fresolution=", plugin_opt_fresolution_eq, Joined, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "plugin-opt=-pass-through=", plugin_opt_pass_through_eq, Joined, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "plugin-opt=/", plugin_opt_slash, Joined, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "plugin-opt=cs-profile-generate", anonymous_46, Flag, INVALID, lto_cs_profile_generate, nullptr, 0, 0,
"Alias for -lto-cs-profile-generate", nullptr, nullptr)
OPTION(prefix_2, "plugin-opt=cs-profile-path=", anonymous_47, Joined, INVALID, lto_cs_profile_file, nullptr, 0, 0,
"Alias for -lto-cs-profile-file", nullptr, nullptr)
OPTION(prefix_2, "plugin-opt=debug-pass-manager", anonymous_41, Flag, INVALID, lto_debug_pass_manager, nullptr, 0, 0,
"Alias for -lto-debug-pass-manager", nullptr, nullptr)
OPTION(prefix_2, "plugin-opt=disable-verify", anonymous_42, Flag, INVALID, disable_verify, nullptr, 0, 0,
"Alias for -disable-verify", nullptr, nullptr)
OPTION(prefix_2, "plugin-opt=dwo_dir=", plugin_opt_dwo_dir_eq, Joined, INVALID, INVALID, nullptr, 0, 0,
"Directory to store .dwo files when LTO and debug fission are used", nullptr, nullptr)
OPTION(prefix_2, "plugin-opt=emit-llvm", plugin_opt_emit_llvm, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "plugin-opt=jobs=", anonymous_43, Joined, INVALID, thinlto_jobs, nullptr, 0, 0,
"Alias for -thinlto-jobs", nullptr, nullptr)
OPTION(prefix_2, "plugin-opt=lto-partitions=", anonymous_44, Joined, INVALID, lto_partitions, nullptr, 0, 0,
"Alias for -lto-partitions", nullptr, nullptr)
OPTION(prefix_2, "plugin-opt=mcpu=", plugin_opt_mcpu_eq, Joined, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "plugin-opt=new-pass-manager", anonymous_45, Flag, INVALID, lto_new_pass_manager, nullptr, 0, 0,
"Alias for -lto-new-pass-manager", nullptr, nullptr)
OPTION(prefix_2, "plugin-opt=obj-path=", plugin_opt_obj_path_eq, Joined, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "plugin-opt=O", anonymous_40, Joined, INVALID, lto_O, nullptr, 0, 0,
"Alias for -lto-O", nullptr, nullptr)
OPTION(prefix_2, "plugin-opt=sample-profile=", anonymous_48, Joined, INVALID, lto_sample_profile, nullptr, 0, 0,
"Alias for -lto-sample-profile", nullptr, nullptr)
OPTION(prefix_2, "plugin-opt=save-temps", anonymous_49, Flag, INVALID, save_temps, nullptr, 0, 0,
"Alias for -save-temps", nullptr, nullptr)
OPTION(prefix_2, "plugin-opt=thinlto-emit-imports-files", plugin_opt_thinlto_emit_imports_files, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "plugin-opt=thinlto-index-only=", plugin_opt_thinlto_index_only_eq, Joined, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "plugin-opt=thinlto-index-only", plugin_opt_thinlto_index_only, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "plugin-opt=thinlto-object-suffix-replace=", plugin_opt_thinlto_object_suffix_replace_eq, Joined, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "plugin-opt=thinlto-prefix-replace=", plugin_opt_thinlto_prefix_replace_eq, Joined, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "plugin-opt=thinlto", plugin_opt_thinlto, Joined, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "plugin-opt=", plugin_opt_eq, Joined, INVALID, plugin_opt, nullptr, 0, 0,
"specifies LTO options for compatibility with GNU linkers", nullptr, nullptr)
OPTION(prefix_2, "plugin-opt", plugin_opt, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "plugin=", plugin_eq, Joined, INVALID, plugin, nullptr, 0, 0,
"Ignored for compatibility with GNU linkers", nullptr, nullptr)
OPTION(prefix_2, "plugin", plugin, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "pop-state", pop_state, Flag, INVALID, INVALID, nullptr, 0, 0,
"Undo the effect of -push-state", nullptr, nullptr)
OPTION(prefix_2, "print-gc-sections", print_gc_sections, Flag, INVALID, INVALID, nullptr, 0, 0,
"List removed unused sections", nullptr, nullptr)
OPTION(prefix_2, "print-icf-sections", print_icf_sections, Flag, INVALID, INVALID, nullptr, 0, 0,
"List identical folded sections", nullptr, nullptr)
OPTION(prefix_2, "print-map", print_map, Flag, INVALID, INVALID, nullptr, 0, 0,
"Print a link map to the standard output", nullptr, nullptr)
OPTION(prefix_2, "print-symbol-order=", print_symbol_order_eq, Joined, INVALID, print_symbol_order, nullptr, 0, 0,
"Print a symbol order specified by --call-graph-ordering-file into the speficied file", nullptr, nullptr)
OPTION(prefix_2, "print-symbol-order", print_symbol_order, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "push-state", push_state, Flag, INVALID, INVALID, nullptr, 0, 0,
"Save the current state of -as-needed, -static and -whole-archive", nullptr, nullptr)
OPTION(prefix_1, "p", anonymous_60, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "Qy", anonymous_72, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "q", anonymous_11, Flag, INVALID, emit_relocs, nullptr, 0, 0,
"Alias for --emit-relocs", nullptr, nullptr)
OPTION(prefix_2, "relocatable", relocatable, Flag, INVALID, INVALID, nullptr, 0, 0,
"Create relocatable object file", nullptr, nullptr)
OPTION(prefix_2, "reproduce=", reproduce_eq, Joined, INVALID, reproduce, nullptr, 0, 0,
"Dump linker invocation and input files for debugging", nullptr, nullptr)
OPTION(prefix_2, "reproduce", reproduce, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "require-cet", require_cet, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "retain-symbols-file=", retain_symbols_file_eq, Joined, INVALID, retain_symbols_file, nullptr, 0, 0,
"Retain only the symbols listed in the file", "<file>", nullptr)
OPTION(prefix_2, "retain-symbols-file", retain_symbols_file, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, "<file>", nullptr)
OPTION(prefix_2, "rpath-link=", anonymous_62, Joined, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "rpath-link", anonymous_61, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "rpath=", rpath_eq, Joined, INVALID, rpath, nullptr, 0, 0,
"Add a DT_RUNPATH to the output", nullptr, nullptr)
OPTION(prefix_2, "rpath", rpath, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "rsp-quoting=", rsp_quoting_eq, Joined, INVALID, rsp_quoting, nullptr, 0, 0,
"Quoting style for response files", "[posix,windows]", nullptr)
OPTION(prefix_2, "rsp-quoting", rsp_quoting, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, "[posix,windows]", nullptr)
OPTION(prefix_1, "R", anonymous_27, JoinedOrSeparate, INVALID, rpath, nullptr, 0, 0,
"Alias for --rpath", nullptr, nullptr)
OPTION(prefix_1, "r", anonymous_26, Flag, INVALID, relocatable, nullptr, 0, 0,
"Alias for --relocatable", nullptr, nullptr)
OPTION(prefix_2, "save-temps", save_temps, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "script=", script_eq, Joined, INVALID, script, nullptr, 0, 0,
"Read linker script", nullptr, nullptr)
OPTION(prefix_2, "script", script, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "section-start=", section_start_eq, Joined, INVALID, section_start, nullptr, 0, 0,
"Set address of section", "<address>", nullptr)
OPTION(prefix_2, "section-start", section_start, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, "<address>", nullptr)
OPTION(prefix_2, "secure-plt", anonymous_63, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "shared", shared, Flag, INVALID, INVALID, nullptr, 0, 0,
"Build a shared object", nullptr, nullptr)
OPTION(prefix_2, "soname=", soname_eq, Joined, INVALID, soname, nullptr, 0, 0,
"Set DT_SONAME", nullptr, nullptr)
OPTION(prefix_2, "soname", soname, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "sort-common", anonymous_64, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "sort-section=", sort_section_eq, Joined, INVALID, sort_section, nullptr, 0, 0,
"Specifies sections sorting rule when linkerscript is used", nullptr, nullptr)
OPTION(prefix_2, "sort-section", sort_section, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "split-stack-adjust-size=", split_stack_adjust_size_eq, Joined, INVALID, split_stack_adjust_size, nullptr, 0, 0,
"Specify adjustment to stack size when a split-stack function calls a non-split-stack function", "<value>", nullptr)
OPTION(prefix_2, "split-stack-adjust-size", split_stack_adjust_size, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, "<value>", nullptr)
OPTION(prefix_2, "start-group", start_group, Flag, INVALID, INVALID, nullptr, 0, 0,
"Ignored for compatibility with GNU unless you pass --warn-backrefs", nullptr, nullptr)
OPTION(prefix_2, "start-lib", start_lib, Flag, INVALID, INVALID, nullptr, 0, 0,
"Start a grouping of objects that should be treated as if they were together in an archive", nullptr, nullptr)
OPTION(prefix_2, "static", anonymous_5, Flag, INVALID, Bstatic, nullptr, 0, 0,
"Alias for --Bstatic", nullptr, nullptr)
OPTION(prefix_2, "stats", anonymous_65, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "strip-all", strip_all, Flag, INVALID, INVALID, nullptr, 0, 0,
"Strip all symbols", nullptr, nullptr)
OPTION(prefix_2, "strip-debug", strip_debug, Flag, INVALID, INVALID, nullptr, 0, 0,
"Strip debugging information", nullptr, nullptr)
OPTION(prefix_2, "symbol-ordering-file=", symbol_ordering_file_eq, Joined, INVALID, symbol_ordering_file, nullptr, 0, 0,
"Layout sections to place symbols in the order specified by symbol ordering file", nullptr, nullptr)
OPTION(prefix_2, "symbol-ordering-file", symbol_ordering_file, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "sysroot=", sysroot_eq, Joined, INVALID, sysroot, nullptr, 0, 0,
"Set the system root", nullptr, nullptr)
OPTION(prefix_2, "sysroot", sysroot, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "S", anonymous_33, Flag, INVALID, strip_debug, nullptr, 0, 0,
"Alias for --strip-debug", nullptr, nullptr)
OPTION(prefix_1, "s", anonymous_32, Flag, INVALID, strip_all, nullptr, 0, 0,
"Alias for --strip-all", nullptr, nullptr)
OPTION(prefix_2, "target1-abs", target1_abs, Flag, INVALID, INVALID, nullptr, 0, 0,
"Interpret R_ARM_TARGET1 as R_ARM_ABS32 (default)", nullptr, nullptr)
OPTION(prefix_2, "target1-rel", target1_rel, Flag, INVALID, INVALID, nullptr, 0, 0,
"Interpret R_ARM_TARGET1 as R_ARM_REL32", nullptr, nullptr)
OPTION(prefix_2, "target2=", target2_eq, Joined, INVALID, target2, nullptr, 0, 0,
"Interpret R_ARM_TARGET2 as <type>, where <type> is one of rel, abs, or got-rel", "<type>", nullptr)
OPTION(prefix_2, "target2", target2, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, "<type>", nullptr)
OPTION(prefix_2, "Tbss=", Tbss_eq, Joined, INVALID, Tbss, nullptr, 0, 0,
"Same as --section-start with .bss as the sectionname", nullptr, nullptr)
OPTION(prefix_2, "Tbss", Tbss, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "Tdata=", Tdata_eq, Joined, INVALID, Tdata, nullptr, 0, 0,
"Same as --section-start with .data as the sectionname", nullptr, nullptr)
OPTION(prefix_2, "Tdata", Tdata, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "thinlto-cache-dir=", thinlto_cache_dir, Joined, INVALID, INVALID, nullptr, 0, 0,
"Path to ThinLTO cached object file directory", nullptr, nullptr)
OPTION(prefix_2, "thinlto-cache-policy=", thinlto_cache_policy_eq, Joined, INVALID, thinlto_cache_policy, nullptr, 0, 0,
"Pruning policy for the ThinLTO cache", nullptr, nullptr)
OPTION(prefix_2, "thinlto-cache-policy", thinlto_cache_policy, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "thinlto-jobs=", thinlto_jobs, Joined, INVALID, INVALID, nullptr, 0, 0,
"Number of ThinLTO jobs", nullptr, nullptr)
OPTION(prefix_2, "threads", threads, Flag, INVALID, INVALID, nullptr, 0, 0,
"Run the linker multi-threaded (default)", nullptr, nullptr)
OPTION(prefix_2, "toc-optimize", toc_optimize, Flag, INVALID, INVALID, nullptr, 0, 0,
"(PowerPC64) Enable TOC related optimizations (default)", nullptr, nullptr)
OPTION(prefix_2, "trace-symbol=", trace_symbol_eq, Joined, INVALID, trace_symbol, nullptr, 0, 0,
"Trace references to symbols", nullptr, nullptr)
OPTION(prefix_2, "trace-symbol", trace_symbol, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "trace", trace, Flag, INVALID, INVALID, nullptr, 0, 0,
"Print the names of the input files", nullptr, nullptr)
OPTION(prefix_4, "Ttext-segment=", anonymous_37, Joined, INVALID, Ttext, nullptr, 0, 0,
"Alias for --Ttext", nullptr, nullptr)
OPTION(prefix_4, "Ttext-segment", anonymous_36, Separate, INVALID, Ttext, nullptr, 0, 0,
"Alias for --Ttext", nullptr, nullptr)
OPTION(prefix_2, "Ttext=", Ttext_eq, Joined, INVALID, Ttext, nullptr, 0, 0,
"Same as --section-start with .text as the sectionname", nullptr, nullptr)
OPTION(prefix_2, "Ttext", Ttext, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "T", anonymous_28, JoinedOrSeparate, INVALID, script, nullptr, 0, 0,
"Alias for --script", nullptr, nullptr)
OPTION(prefix_1, "t", anonymous_34, Flag, INVALID, trace, nullptr, 0, 0,
"Alias for --trace", nullptr, nullptr)
OPTION(prefix_2, "undefined-glob=", undefined_glob_eq, Joined, INVALID, undefined_glob, nullptr, 0, 0,
"Force undefined symbol during linking", "<pattern>", nullptr)
OPTION(prefix_2, "undefined-glob", undefined_glob, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, "<pattern>", nullptr)
OPTION(prefix_2, "undefined-version", undefined_version, Flag, INVALID, INVALID, nullptr, 0, 0,
"Allow unused version in version script (default)", nullptr, nullptr)
OPTION(prefix_2, "undefined=", undefined_eq, Joined, INVALID, undefined, nullptr, 0, 0,
"Force undefined symbol during linking", "<symbol>", nullptr)
OPTION(prefix_2, "undefined", undefined, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, "<symbol>", nullptr)
OPTION(prefix_2, "unresolved-symbols=", unresolved_symbols_eq, Joined, INVALID, unresolved_symbols, nullptr, 0, 0,
"Determine how to handle unresolved symbols", nullptr, nullptr)
OPTION(prefix_2, "unresolved-symbols", unresolved_symbols, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "use-android-relr-tags", use_android_relr_tags, Flag, INVALID, INVALID, nullptr, 0, 0,
"Use SHT_ANDROID_RELR / DT_ANDROID_RELR* tags instead of SHT_RELR / DT_RELR*", nullptr, nullptr)
OPTION(prefix_1, "u", anonymous_38, JoinedOrSeparate, INVALID, undefined, nullptr, 0, 0,
"Alias for --undefined", nullptr, nullptr)
OPTION(prefix_2, "verbose", verbose, Flag, INVALID, INVALID, nullptr, 0, 0,
"Verbose mode", nullptr, nullptr)
OPTION(prefix_2, "version-script=", version_script_eq, Joined, INVALID, version_script, nullptr, 0, 0,
"Read a version script", nullptr, nullptr)
OPTION(prefix_2, "version-script", version_script, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "version", version, Flag, INVALID, INVALID, nullptr, 0, 0,
"Display the version number and exit", nullptr, nullptr)
OPTION(prefix_2, "vs-diagnostics", visual_studio_diagnostics_format, Flag, INVALID, INVALID, nullptr, 0, 0,
"Format diagnostics for Visual Studio compatiblity", nullptr, nullptr)
OPTION(prefix_1, "V", anonymous_39, Flag, INVALID, version, nullptr, 0, 0,
"Alias for --version", nullptr, nullptr)
OPTION(prefix_1, "v", v, Flag, INVALID, INVALID, nullptr, 0, 0,
"Display the version number", nullptr, nullptr)
OPTION(prefix_2, "warn-backrefs", warn_backrefs, Flag, INVALID, INVALID, nullptr, 0, 0,
"Warn about backward symbol references to fetch archive members", nullptr, nullptr)
OPTION(prefix_2, "warn-common", warn_common, Flag, INVALID, INVALID, nullptr, 0, 0,
"Warn about duplicate common symbols", nullptr, nullptr)
OPTION(prefix_2, "warn-execstack", anonymous_66, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "warn-ifunc-textrel", warn_ifunc_textrel, Flag, INVALID, INVALID, nullptr, 0, 0,
"Warn about using ifunc symbols with text relocations", nullptr, nullptr)
OPTION(prefix_2, "warn-once", anonymous_67, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "warn-shared-textrel", anonymous_68, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "warn-symbol-ordering", warn_symbol_ordering, Flag, INVALID, INVALID, nullptr, 0, 0,
"Warn about problems with the symbol ordering file (default)", nullptr, nullptr)
OPTION(prefix_2, "warn-unresolved-symbols", warn_unresolved_symbols, Flag, INVALID, INVALID, nullptr, 0, 0,
"Report unresolved symbols as warnings", nullptr, nullptr)
OPTION(prefix_2, "whole-archive", whole_archive, Flag, INVALID, INVALID, nullptr, 0, 0,
"Force load of all members in a static library", nullptr, nullptr)
OPTION(prefix_2, "wrap=", wrap_eq, Joined, INVALID, wrap, nullptr, 0, 0,
"Use wrapper functions for symbol", "<symbol>=<symbol>", nullptr)
OPTION(prefix_2, "wrap", wrap, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, "<symbol>=<symbol>", nullptr)
OPTION(prefix_1, "X", anonymous_10, Flag, INVALID, discard_locals, nullptr, 0, 0,
"Alias for --discard-locals", nullptr, nullptr)
OPTION(prefix_1, "x", anonymous_9, Flag, INVALID, discard_all, nullptr, 0, 0,
"Alias for --discard-all", nullptr, nullptr)
OPTION(prefix_1, "y", anonymous_35, JoinedOrSeparate, INVALID, trace_symbol, nullptr, 0, 0,
"Alias for --trace-symbol", nullptr, nullptr)
OPTION(prefix_1, "z", z, JoinedOrSeparate, INVALID, INVALID, nullptr, 0, 0,
"Linker option extensions", "<option>", nullptr)
#endif // OPTION
#ifdef OPTTABLE_ARG_INIT
//////////
// Option Values
#endif // OPTTABLE_ARG_INIT

View File

@@ -1,160 +0,0 @@
/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
|* *|
|* Option Parsing Definitions *|
|* *|
|* Automatically generated file, do not edit! *|
|* *|
\*===----------------------------------------------------------------------===*/
/////////
// Prefixes
#ifdef PREFIX
#define COMMA ,
PREFIX(prefix_0, {nullptr})
PREFIX(prefix_1, {"-" COMMA nullptr})
PREFIX(prefix_3, {"--" COMMA nullptr})
PREFIX(prefix_2, {"--" COMMA "-" COMMA nullptr})
#undef COMMA
#endif // PREFIX
/////////
// Groups
#ifdef OPTION
//////////
// Options
OPTION(prefix_0, "<input>", INPUT, Input, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_0, "<unknown>", UNKNOWN, Unknown, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "###", _HASH_HASH_HASH, Flag, INVALID, INVALID, nullptr, 0, 0,
"Print (but do not run) the commands to run for this compilation", nullptr, nullptr)
OPTION(prefix_2, "appcontainer", appcontainer, Flag, INVALID, INVALID, nullptr, 0, 0,
"Set the appcontainer flag in the executable", nullptr, nullptr)
OPTION(prefix_2, "Bdynamic", Bdynamic, Flag, INVALID, INVALID, nullptr, 0, 0,
"Link against shared libraries", nullptr, nullptr)
OPTION(prefix_2, "Bstatic", Bstatic, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not link against shared libraries", nullptr, nullptr)
OPTION(prefix_2, "build-id", anonymous_1, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "delayload=", delayload_eq, Joined, INVALID, delayload, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "delayload", delayload, Separate, INVALID, INVALID, nullptr, 0, 0,
"DLL to load only on demand", nullptr, nullptr)
OPTION(prefix_2, "disable-auto-image-base", anonymous_2, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "dynamicbase", dynamicbase, Flag, INVALID, INVALID, nullptr, 0, 0,
"Enable ASLR", nullptr, nullptr)
OPTION(prefix_2, "enable-auto-image-base", anonymous_3, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "enable-auto-import", anonymous_4, Flag, INVALID, INVALID, nullptr, 0, 0,
"Ignored; listed for libtool compatibility", nullptr, nullptr)
OPTION(prefix_2, "end-group", anonymous_5, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "entry", entry, Separate, INVALID, INVALID, nullptr, 0, 0,
"Name of entry point symbol", "<entry>", nullptr)
OPTION(prefix_2, "exclude-all-symbols", exclude_all_symbols, Flag, INVALID, INVALID, nullptr, 0, 0,
"Don't automatically export any symbols", nullptr, nullptr)
OPTION(prefix_2, "export-all-symbols", export_all_symbols, Flag, INVALID, INVALID, nullptr, 0, 0,
"Export all symbols even if a def file or dllexport attributes are used", nullptr, nullptr)
OPTION(prefix_1, "e", alias_entry_e, JoinedOrSeparate, INVALID, entry, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_3, "full-shutdown", anonymous_6, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "gc-sections", gc_sections, Flag, INVALID, INVALID, nullptr, 0, 0,
"Remove unused sections", nullptr, nullptr)
OPTION(prefix_2, "help", help, Flag, INVALID, INVALID, nullptr, 0, 0,
"Print option help", nullptr, nullptr)
OPTION(prefix_2, "high-entropy-va", anonymous_7, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "icf=", icf, Joined, INVALID, INVALID, nullptr, 0, 0,
"Identical code folding", nullptr, nullptr)
OPTION(prefix_2, "image-base", image_base, Separate, INVALID, INVALID, nullptr, 0, 0,
"Base address of the program", nullptr, nullptr)
OPTION(prefix_2, "insert-timestamp", insert_timestamp, Flag, INVALID, INVALID, nullptr, 0, 0,
"Include PE header timestamp", nullptr, nullptr)
OPTION(prefix_2, "kill-at", kill_at, Flag, INVALID, INVALID, nullptr, 0, 0,
"Remove @n from exported symbols", nullptr, nullptr)
OPTION(prefix_3, "large-address-aware", large_address_aware, Flag, INVALID, INVALID, nullptr, 0, 0,
"Enable large addresses", nullptr, nullptr)
OPTION(prefix_1, "L", L, JoinedOrSeparate, INVALID, INVALID, nullptr, 0, 0,
"Add a directory to the library search path", "<dir>", nullptr)
OPTION(prefix_1, "l", l, JoinedOrSeparate, INVALID, INVALID, nullptr, 0, 0,
"Root name of library to use", "<libName>", nullptr)
OPTION(prefix_2, "major-image-version", anonymous_8, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_3, "major-os-version=", major_os_version_eq, Joined, INVALID, major_os_version, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_3, "major-os-version", major_os_version, Separate, INVALID, INVALID, nullptr, 0, 0,
"Set the OS and subsystem major version", nullptr, nullptr)
OPTION(prefix_3, "major-subsystem-version=", major_subsystem_version_eq, Joined, INVALID, major_subsystem_version, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_3, "major-subsystem-version", major_subsystem_version, Separate, INVALID, INVALID, nullptr, 0, 0,
"Set the OS and subsystem major version", nullptr, nullptr)
OPTION(prefix_2, "Map=", map_eq, Joined, INVALID, map, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "Map", map, Separate, INVALID, INVALID, nullptr, 0, 0,
"Output a linker map", nullptr, nullptr)
OPTION(prefix_2, "minor-image-version", anonymous_9, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_3, "minor-os-version=", minor_os_version_eq, Joined, INVALID, minor_os_version, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_3, "minor-os-version", minor_os_version, Separate, INVALID, INVALID, nullptr, 0, 0,
"Set the OS and subsystem minor version", nullptr, nullptr)
OPTION(prefix_3, "minor-subsystem-version=", minor_subsystem_version_eq, Joined, INVALID, minor_subsystem_version, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_3, "minor-subsystem-version", minor_subsystem_version, Separate, INVALID, INVALID, nullptr, 0, 0,
"Set the OS and subsystem minor version", nullptr, nullptr)
OPTION(prefix_2, "mllvm", mllvm, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "m", m, JoinedOrSeparate, INVALID, INVALID, nullptr, 0, 0,
"Set target emulation", nullptr, nullptr)
OPTION(prefix_2, "no-gc-sections", no_gc_sections, Flag, INVALID, INVALID, nullptr, 0, 0,
"Don't remove unused sections", nullptr, nullptr)
OPTION(prefix_2, "no-insert-timestamp", no_insert_timestamp, Flag, INVALID, INVALID, nullptr, 0, 0,
"Don't include PE header timestamp", nullptr, nullptr)
OPTION(prefix_2, "no-seh", anonymous_10, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "no-whole-archive", no_whole_archive, Flag, INVALID, INVALID, nullptr, 0, 0,
"No longer include all object files for following archives", nullptr, nullptr)
OPTION(prefix_2, "nxcompat", anonymous_11, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_3, "out-implib=", out_implib_eq, Joined, INVALID, out_implib, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_3, "out-implib", out_implib, Separate, INVALID, INVALID, nullptr, 0, 0,
"Import library name", nullptr, nullptr)
OPTION(prefix_2, "output-def", output_def, Separate, INVALID, INVALID, nullptr, 0, 0,
"Output def file", nullptr, nullptr)
OPTION(prefix_1, "O", anonymous_0, Joined, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "o", o, JoinedOrSeparate, INVALID, INVALID, nullptr, 0, 0,
"Path to file to write output", "<path>", nullptr)
OPTION(prefix_2, "pdb=", pdb_eq, Joined, INVALID, pdb, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "pdb", pdb, Separate, INVALID, INVALID, nullptr, 0, 0,
"Output PDB debug info file, chosen implicitly if the argument is empty", nullptr, nullptr)
OPTION(prefix_2, "pic-executable", anonymous_12, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "plugin-opt=", anonymous_16, Joined, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "plugin-opt", anonymous_15, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "plugin=", anonymous_14, Joined, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "plugin", anonymous_13, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "require-defined=", require_defined_eq, Joined, INVALID, require_defined, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "require-defined", require_defined, Separate, INVALID, INVALID, nullptr, 0, 0,
"Force symbol to be added to symbol table as an undefined one", nullptr, nullptr)
OPTION(prefix_2, "shared", shared, Flag, INVALID, INVALID, nullptr, 0, 0,
"Build a shared object", nullptr, nullptr)
OPTION(prefix_2, "stack", stack, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "start-group", anonymous_18, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "strip-all", strip_all, Flag, INVALID, INVALID, nullptr, 0, 0,
"Omit all symbol information from the output binary", nullptr, nullptr)
OPTION(prefix_2, "strip-debug", strip_debug, Flag, INVALID, INVALID, nullptr, 0, 0,
"Omit all debug information, but keep symbol information", nullptr, nullptr)
OPTION(prefix_2, "subsystem=", subs_eq, Joined, INVALID, subs, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "subsystem", subs, Separate, INVALID, INVALID, nullptr, 0, 0,
"Specify subsystem", nullptr, nullptr)
OPTION(prefix_2, "sysroot", anonymous_17, Joined, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "S", alias_strip_S, Flag, INVALID, strip_debug, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "s", alias_strip_s, Flag, INVALID, strip_all, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "tsaware", anonymous_19, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "undefined=", undefined_eq, Joined, INVALID, undefined, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "undefined", undefined_long, Separate, INVALID, undefined, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "u", undefined, Separate, INVALID, INVALID, nullptr, 0, 0,
"Include symbol in the link, if available", nullptr, nullptr)
OPTION(prefix_2, "verbose", verbose, Flag, INVALID, INVALID, nullptr, 0, 0,
"Verbose mode", nullptr, nullptr)
OPTION(prefix_2, "version", version, Flag, INVALID, INVALID, nullptr, 0, 0,
"Display the version number and exit", nullptr, nullptr)
OPTION(prefix_1, "v", v, Flag, INVALID, INVALID, nullptr, 0, 0,
"Display the version number", nullptr, nullptr)
OPTION(prefix_2, "whole-archive", whole_archive, Flag, INVALID, INVALID, nullptr, 0, 0,
"Include all object files for following archives", nullptr, nullptr)
OPTION(prefix_2, "Xlink=", Xlink, Joined, INVALID, INVALID, nullptr, 0, 0,
"Pass <arg> to the COFF linker", "<arg>", nullptr)
#endif // OPTION
#ifdef OPTTABLE_ARG_INIT
//////////
// Option Values
#endif // OPTTABLE_ARG_INIT

View File

@@ -1,6 +0,0 @@
#define LLD_VERSION 9.0.0
#define LLD_VERSION_STRING "9.0.0"
#define LLD_VERSION_MAJOR 9
#define LLD_VERSION_MINOR 0
#define LLD_REVISION_STRING ""
#define LLD_REPOSITORY_STRING ""

View File

@@ -1,195 +0,0 @@
/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
|* *|
|* Option Parsing Definitions *|
|* *|
|* Automatically generated file, do not edit! *|
|* *|
\*===----------------------------------------------------------------------===*/
/////////
// Prefixes
#ifdef PREFIX
#define COMMA ,
PREFIX(prefix_0, {nullptr})
PREFIX(prefix_2, {"-" COMMA nullptr})
PREFIX(prefix_1, {"--" COMMA "-" COMMA nullptr})
#undef COMMA
#endif // PREFIX
/////////
// Groups
#ifdef OPTION
//////////
// Options
OPTION(prefix_0, "<input>", INPUT, Input, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_0, "<unknown>", UNKNOWN, Unknown, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "active-segments", active_segments, Flag, INVALID, INVALID, nullptr, 0, 0,
"Force segments to be active (default with unshared memory)", nullptr, nullptr)
OPTION(prefix_1, "allow-undefined-file=", allow_undefined_file, Joined, INVALID, INVALID, nullptr, 0, 0,
"Allow symbols listed in <file> to be undefined in linked binary", nullptr, nullptr)
OPTION(prefix_2, "allow-undefined-file", allow_undefined_file_s, Separate, INVALID, allow_undefined_file, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "allow-undefined", allow_undefined, Flag, INVALID, INVALID, nullptr, 0, 0,
"Allow undefined symbols in linked binary", nullptr, nullptr)
OPTION(prefix_1, "check-features", check_features, Flag, INVALID, INVALID, nullptr, 0, 0,
"Check feature compatibility of linked objects (default)", nullptr, nullptr)
OPTION(prefix_1, "color-diagnostics=", color_diagnostics_eq, Joined, INVALID, INVALID, nullptr, 0, 0,
"Use colors in diagnostics; one of 'always', 'never', 'auto'", nullptr, nullptr)
OPTION(prefix_1, "color-diagnostics", color_diagnostics, Flag, INVALID, INVALID, nullptr, 0, 0,
"Use colors in diagnostics", nullptr, nullptr)
OPTION(prefix_1, "compress-relocations", compress_relocations, Flag, INVALID, INVALID, nullptr, 0, 0,
"Compress the relocation targets in the code section.", nullptr, nullptr)
OPTION(prefix_1, "demangle", demangle, Flag, INVALID, INVALID, nullptr, 0, 0,
"Demangle symbol names", nullptr, nullptr)
OPTION(prefix_1, "disable-verify", disable_verify, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "emit-relocs", emit_relocs, Flag, INVALID, INVALID, nullptr, 0, 0,
"Generate relocations in output", nullptr, nullptr)
OPTION(prefix_1, "entry=", anonymous_1, Joined, INVALID, entry, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "entry", entry, Separate, INVALID, INVALID, nullptr, 0, 0,
"Name of entry point symbol", "<entry>", nullptr)
OPTION(prefix_1, "error-limit=", error_limit, Joined, INVALID, INVALID, nullptr, 0, 0,
"Maximum number of errors to emit before stopping (0 = no limit)", nullptr, nullptr)
OPTION(prefix_1, "export-all", export_all, Flag, INVALID, INVALID, nullptr, 0, 0,
"Export all symbols (normally combined with --no-gc-sections)", nullptr, nullptr)
OPTION(prefix_1, "export-dynamic", export_dynamic, Flag, INVALID, INVALID, nullptr, 0, 0,
"Put symbols in the dynamic symbol table", nullptr, nullptr)
OPTION(prefix_1, "export-table", export_table, Flag, INVALID, INVALID, nullptr, 0, 0,
"Export function table to the environment", nullptr, nullptr)
OPTION(prefix_1, "export=", export_eq, Joined, INVALID, export, nullptr, 0, 0,
"Force a symbol to be exported", nullptr, nullptr)
OPTION(prefix_1, "export", export, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "E", anonymous_2, Flag, INVALID, export_dynamic, nullptr, 0, 0,
"Alias for --export-dynamic", nullptr, nullptr)
OPTION(prefix_2, "e", anonymous_0, JoinedOrSeparate, INVALID, entry, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "fatal-warnings", fatal_warnings, Flag, INVALID, INVALID, nullptr, 0, 0,
"Treat warnings as errors", nullptr, nullptr)
OPTION(prefix_1, "features=", features, CommaJoined, INVALID, INVALID, nullptr, 0, 0,
"Comma-separated used features, inferred from input objects by default.", nullptr, nullptr)
OPTION(prefix_1, "gc-sections", gc_sections, Flag, INVALID, INVALID, nullptr, 0, 0,
"Enable garbage collection of unused sections", nullptr, nullptr)
OPTION(prefix_1, "global-base=", global_base, Joined, INVALID, INVALID, nullptr, 0, 0,
"Where to start to place global data", nullptr, nullptr)
OPTION(prefix_1, "help", help, Flag, INVALID, INVALID, nullptr, 0, 0,
"Print option help", nullptr, nullptr)
OPTION(prefix_1, "import-memory", import_memory, Flag, INVALID, INVALID, nullptr, 0, 0,
"Import memory from the environment", nullptr, nullptr)
OPTION(prefix_1, "import-table", import_table, Flag, INVALID, INVALID, nullptr, 0, 0,
"Import function table from the environment", nullptr, nullptr)
OPTION(prefix_1, "initial-memory=", initial_memory, Joined, INVALID, INVALID, nullptr, 0, 0,
"Initial size of the linear memory", nullptr, nullptr)
OPTION(prefix_2, "i", anonymous_3, Flag, INVALID, initial_memory, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "lto-O", lto_O, Joined, INVALID, INVALID, nullptr, 0, 0,
"Optimization level for LTO", "<opt-level>", nullptr)
OPTION(prefix_1, "lto-partitions=", lto_partitions, Joined, INVALID, INVALID, nullptr, 0, 0,
"Number of LTO codegen partitions", nullptr, nullptr)
OPTION(prefix_2, "L", L, JoinedOrSeparate, INVALID, INVALID, nullptr, 0, 0,
"Add a directory to the library search path", "<dir>", nullptr)
OPTION(prefix_2, "l", l, JoinedOrSeparate, INVALID, INVALID, nullptr, 0, 0,
"Root name of library to use", "<libName>", nullptr)
OPTION(prefix_1, "max-memory=", max_memory, Joined, INVALID, INVALID, nullptr, 0, 0,
"Maximum size of the linear memory", nullptr, nullptr)
OPTION(prefix_1, "merge-data-segments", merge_data_segments, Flag, INVALID, INVALID, nullptr, 0, 0,
"Enable merging data segments", nullptr, nullptr)
OPTION(prefix_1, "mllvm", mllvm, Separate, INVALID, INVALID, nullptr, 0, 0,
"Options to pass to LLVM", nullptr, nullptr)
OPTION(prefix_2, "m", anonymous_4, Flag, INVALID, max_memory, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "no-check-features", no_check_features, Flag, INVALID, INVALID, nullptr, 0, 0,
"Ignore feature compatibility of linked objects", nullptr, nullptr)
OPTION(prefix_1, "no-color-diagnostics", no_color_diagnostics, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not use colors in diagnostics", nullptr, nullptr)
OPTION(prefix_1, "no-demangle", no_demangle, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not demangle symbol names", nullptr, nullptr)
OPTION(prefix_1, "no-entry", no_entry, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not output any entry point", nullptr, nullptr)
OPTION(prefix_1, "no-export-dynamic", no_export_dynamic, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not put symbols in the dynamic symbol table (default)", nullptr, nullptr)
OPTION(prefix_1, "no-fatal-warnings", no_fatal_warnings, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "no-gc-sections", no_gc_sections, Flag, INVALID, INVALID, nullptr, 0, 0,
"Disable garbage collection of unused sections", nullptr, nullptr)
OPTION(prefix_1, "no-merge-data-segments", no_merge_data_segments, Flag, INVALID, INVALID, nullptr, 0, 0,
"Disable merging data segments", nullptr, nullptr)
OPTION(prefix_1, "no-pie", no_pie, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not create a position independent executable (default)", nullptr, nullptr)
OPTION(prefix_1, "no-print-gc-sections", no_print_gc_sections, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not list removed unused sections", nullptr, nullptr)
OPTION(prefix_1, "no-threads", no_threads, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not run the linker multi-threaded", nullptr, nullptr)
OPTION(prefix_1, "no-whole-archive", no_whole_archive, Flag, INVALID, INVALID, nullptr, 0, 0,
"Do not force load of all members in a static library (default)", nullptr, nullptr)
OPTION(prefix_2, "O", O, JoinedOrSeparate, INVALID, INVALID, nullptr, 0, 0,
"Optimize output file size", nullptr, nullptr)
OPTION(prefix_2, "o", o, JoinedOrSeparate, INVALID, INVALID, nullptr, 0, 0,
"Path to file to write output", "<path>", nullptr)
OPTION(prefix_1, "passive-segments", passive_segments, Flag, INVALID, INVALID, nullptr, 0, 0,
"Force segments to be passive (default with shared memory)", nullptr, nullptr)
OPTION(prefix_1, "pie", pie, Flag, INVALID, INVALID, nullptr, 0, 0,
"Create a position independent executable", nullptr, nullptr)
OPTION(prefix_1, "print-gc-sections", print_gc_sections, Flag, INVALID, INVALID, nullptr, 0, 0,
"List removed unused sections", nullptr, nullptr)
OPTION(prefix_1, "relocatable", relocatable, Flag, INVALID, INVALID, nullptr, 0, 0,
"Create relocatable object file", nullptr, nullptr)
OPTION(prefix_1, "reproduce=", reproduce_eq, Joined, INVALID, reproduce, nullptr, 0, 0,
"Dump linker invocation and input files for debugging", nullptr, nullptr)
OPTION(prefix_1, "reproduce", reproduce, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "r", anonymous_5, Flag, INVALID, relocatable, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "save-temps", save_temps, Flag, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "shared-memory", shared_memory, Flag, INVALID, INVALID, nullptr, 0, 0,
"Use shared linear memory", nullptr, nullptr)
OPTION(prefix_1, "shared", shared, Flag, INVALID, INVALID, nullptr, 0, 0,
"Build a shared object", nullptr, nullptr)
OPTION(prefix_1, "stack-first", stack_first, Flag, INVALID, INVALID, nullptr, 0, 0,
"Place stack at start of linear memory rather than after data", nullptr, nullptr)
OPTION(prefix_1, "strip-all", strip_all, Flag, INVALID, INVALID, nullptr, 0, 0,
"Strip all symbols", nullptr, nullptr)
OPTION(prefix_1, "strip-debug", strip_debug, Flag, INVALID, INVALID, nullptr, 0, 0,
"Strip debugging information", nullptr, nullptr)
OPTION(prefix_2, "S", anonymous_7, Flag, INVALID, strip_debug, nullptr, 0, 0,
"Alias for --strip-debug", nullptr, nullptr)
OPTION(prefix_2, "s", anonymous_6, Flag, INVALID, strip_all, nullptr, 0, 0,
"Alias for --strip-all", nullptr, nullptr)
OPTION(prefix_1, "thinlto-cache-dir=", thinlto_cache_dir, Joined, INVALID, INVALID, nullptr, 0, 0,
"Path to ThinLTO cached object file directory", nullptr, nullptr)
OPTION(prefix_1, "thinlto-cache-policy=", thinlto_cache_policy_eq, Joined, INVALID, thinlto_cache_policy, nullptr, 0, 0,
"Pruning policy for the ThinLTO cache", nullptr, nullptr)
OPTION(prefix_1, "thinlto-cache-policy", thinlto_cache_policy, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "thinlto-jobs=", thinlto_jobs, Joined, INVALID, INVALID, nullptr, 0, 0,
"Number of ThinLTO jobs", nullptr, nullptr)
OPTION(prefix_1, "threads", threads, Flag, INVALID, INVALID, nullptr, 0, 0,
"Run the linker multi-threaded", nullptr, nullptr)
OPTION(prefix_1, "trace-symbol=", trace_symbol_eq, Joined, INVALID, trace_symbol, nullptr, 0, 0,
"Trace references to symbols", nullptr, nullptr)
OPTION(prefix_1, "trace-symbol", trace_symbol, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "trace", trace, Flag, INVALID, INVALID, nullptr, 0, 0,
"Print the names of the input files", nullptr, nullptr)
OPTION(prefix_2, "t", anonymous_8, Flag, INVALID, trace, nullptr, 0, 0,
"Alias for --trace", nullptr, nullptr)
OPTION(prefix_1, "undefined=", undefined_eq, Joined, INVALID, undefined, nullptr, 0, 0,
"Force undefined symbol during linking", nullptr, nullptr)
OPTION(prefix_1, "undefined", undefined, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_2, "u", anonymous_10, JoinedOrSeparate, INVALID, undefined, nullptr, 0, 0, nullptr, nullptr, nullptr)
OPTION(prefix_1, "verbose", verbose, Flag, INVALID, INVALID, nullptr, 0, 0,
"Verbose mode", nullptr, nullptr)
OPTION(prefix_1, "version", version, Flag, INVALID, INVALID, nullptr, 0, 0,
"Display the version number and exit", nullptr, nullptr)
OPTION(prefix_2, "v", v, Flag, INVALID, INVALID, nullptr, 0, 0,
"Display the version number", nullptr, nullptr)
OPTION(prefix_1, "whole-archive", whole_archive, Flag, INVALID, INVALID, nullptr, 0, 0,
"Force load of all members in a static library", nullptr, nullptr)
OPTION(prefix_1, "wrap=", wrap_eq, Joined, INVALID, wrap, nullptr, 0, 0,
"Use wrapper functions for symbol", "<symbol>=<symbol>", nullptr)
OPTION(prefix_1, "wrap", wrap, Separate, INVALID, INVALID, nullptr, 0, 0, nullptr, "<symbol>=<symbol>", nullptr)
OPTION(prefix_2, "y", anonymous_9, JoinedOrSeparate, INVALID, trace_symbol, nullptr, 0, 0,
"Alias for --trace-symbol", nullptr, nullptr)
OPTION(prefix_2, "z", z, JoinedOrSeparate, INVALID, INVALID, nullptr, 0, 0,
"Linker option extensions", "<option>", nullptr)
#endif // OPTION
#ifdef OPTTABLE_ARG_INIT
//////////
// Option Values
#endif // OPTTABLE_ARG_INIT

4
deps/lld/.arcconfig vendored
View File

@@ -1,4 +0,0 @@
{
"repository.callsign" : "LLD",
"conduit_uri" : "https://reviews.llvm.org/"
}

View File

@@ -1 +0,0 @@
BasedOnStyle: LLVM

24
deps/lld/.gitignore vendored
View File

@@ -1,24 +0,0 @@
#==============================================================================#
# This file specifies intentionally untracked files that git should ignore.
# See: http://www.kernel.org/pub/software/scm/git/docs/gitignore.html
#==============================================================================#
#==============================================================================#
# File extensions to be ignored anywhere in the tree.
#==============================================================================#
# Temp files created by most text editors.
*~
# Merge files created by git.
*.orig
# Byte compiled python modules.
*.pyc
# vim swap files
.*.swp
# Mac OS X Finder layout info
.DS_Store
#==============================================================================#
# Directories to be ignored.
#==============================================================================#
# Sphinx build files.
docs/_build

View File

@@ -1,225 +0,0 @@
# Check if lld is built as a standalone project.
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
project(lld)
cmake_minimum_required(VERSION 3.4.3)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(LLD_BUILT_STANDALONE TRUE)
find_program(LLVM_CONFIG_PATH "llvm-config" DOC "Path to llvm-config binary")
if(NOT LLVM_CONFIG_PATH)
message(FATAL_ERROR "llvm-config not found: specify LLVM_CONFIG_PATH")
endif()
execute_process(COMMAND "${LLVM_CONFIG_PATH}"
"--obj-root"
"--includedir"
"--cmakedir"
"--src-root"
RESULT_VARIABLE HAD_ERROR
OUTPUT_VARIABLE LLVM_CONFIG_OUTPUT
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(HAD_ERROR)
message(FATAL_ERROR "llvm-config failed with status ${HAD_ERROR}")
endif()
string(REGEX REPLACE "[ \t]*[\r\n]+[ \t]*" ";" LLVM_CONFIG_OUTPUT "${LLVM_CONFIG_OUTPUT}")
list(GET LLVM_CONFIG_OUTPUT 0 OBJ_ROOT)
list(GET LLVM_CONFIG_OUTPUT 1 MAIN_INCLUDE_DIR)
list(GET LLVM_CONFIG_OUTPUT 2 LLVM_CMAKE_PATH)
list(GET LLVM_CONFIG_OUTPUT 3 MAIN_SRC_DIR)
set(LLVM_OBJ_ROOT ${OBJ_ROOT} CACHE PATH "path to LLVM build tree")
set(LLVM_MAIN_INCLUDE_DIR ${MAIN_INCLUDE_DIR} CACHE PATH "path to llvm/include")
set(LLVM_MAIN_SRC_DIR ${MAIN_SRC_DIR} CACHE PATH "Path to LLVM source tree")
file(TO_CMAKE_PATH ${LLVM_OBJ_ROOT} LLVM_BINARY_DIR)
if(NOT EXISTS "${LLVM_CMAKE_PATH}/LLVMConfig.cmake")
message(FATAL_ERROR "LLVMConfig.cmake not found")
endif()
include("${LLVM_CMAKE_PATH}/LLVMConfig.cmake")
list(APPEND CMAKE_MODULE_PATH "${LLVM_CMAKE_PATH}")
set(PACKAGE_VERSION "${LLVM_PACKAGE_VERSION}")
include_directories("${LLVM_BINARY_DIR}/include" ${LLVM_INCLUDE_DIRS})
link_directories(${LLVM_LIBRARY_DIRS})
set(LLVM_LIBRARY_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/lib${LLVM_LIBDIR_SUFFIX})
set(LLVM_RUNTIME_OUTPUT_INTDIR ${CMAKE_BINARY_DIR}/${CMAKE_CFG_INTDIR}/bin)
find_program(LLVM_TABLEGEN_EXE "llvm-tblgen" ${LLVM_TOOLS_BINARY_DIR} NO_DEFAULT_PATH)
include(AddLLVM)
include(TableGen)
include(HandleLLVMOptions)
if(LLVM_INCLUDE_TESTS)
include(FindPythonInterp)
if(NOT PYTHONINTERP_FOUND)
message(FATAL_ERROR
"Unable to find Python interpreter, required for testing.
Please install Python or specify the PYTHON_EXECUTABLE CMake variable.")
endif()
if(${PYTHON_VERSION_STRING} VERSION_LESS 2.7)
message(FATAL_ERROR "Python 2.7 or newer is required")
endif()
# Check prebuilt llvm/utils.
if(EXISTS ${LLVM_TOOLS_BINARY_DIR}/FileCheck${CMAKE_EXECUTABLE_SUFFIX}
AND EXISTS ${LLVM_TOOLS_BINARY_DIR}/not${CMAKE_EXECUTABLE_SUFFIX})
set(LLVM_UTILS_PROVIDED ON)
endif()
if(EXISTS ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
# Note: path not really used, except for checking if lit was found
set(LLVM_LIT ${LLVM_MAIN_SRC_DIR}/utils/lit/lit.py)
if(NOT LLVM_UTILS_PROVIDED)
add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/FileCheck utils/FileCheck)
add_subdirectory(${LLVM_MAIN_SRC_DIR}/utils/not utils/not)
set(LLVM_UTILS_PROVIDED ON)
set(LLD_TEST_DEPS FileCheck not)
endif()
set(UNITTEST_DIR ${LLVM_MAIN_SRC_DIR}/utils/unittest)
if(EXISTS ${UNITTEST_DIR}/googletest/include/gtest/gtest.h
AND NOT EXISTS ${LLVM_LIBRARY_DIR}/${CMAKE_STATIC_LIBRARY_PREFIX}gtest${CMAKE_STATIC_LIBRARY_SUFFIX}
AND EXISTS ${UNITTEST_DIR}/CMakeLists.txt)
add_subdirectory(${UNITTEST_DIR} utils/unittest)
endif()
else()
# Seek installed Lit.
find_program(LLVM_LIT
NAMES llvm-lit lit.py lit
PATHS "${LLVM_MAIN_SRC_DIR}/utils/lit"
DOC "Path to lit.py")
endif()
if(LLVM_LIT)
# Define the default arguments to use with 'lit', and an option for the user
# to override.
set(LIT_ARGS_DEFAULT "-sv")
if (MSVC OR XCODE)
set(LIT_ARGS_DEFAULT "${LIT_ARGS_DEFAULT} --no-progress-bar")
endif()
set(LLVM_LIT_ARGS "${LIT_ARGS_DEFAULT}" CACHE STRING "Default options for lit")
# On Win32 hosts, provide an option to specify the path to the GnuWin32 tools.
if(WIN32 AND NOT CYGWIN)
set(LLVM_LIT_TOOLS_DIR "" CACHE PATH "Path to GnuWin32 tools")
endif()
else()
set(LLVM_INCLUDE_TESTS OFF)
endif()
endif()
endif()
set(LLD_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(LLD_INCLUDE_DIR ${LLD_SOURCE_DIR}/include )
set(LLD_BINARY_DIR ${CMAKE_CURRENT_BINARY_DIR})
# Compute the LLD version from the LLVM version.
string(REGEX MATCH "[0-9]+\\.[0-9]+(\\.[0-9]+)?" LLD_VERSION
${PACKAGE_VERSION})
message(STATUS "LLD version: ${LLD_VERSION}")
string(REGEX REPLACE "([0-9]+)\\.[0-9]+(\\.[0-9]+)?" "\\1" LLD_VERSION_MAJOR
${LLD_VERSION})
string(REGEX REPLACE "[0-9]+\\.([0-9]+)(\\.[0-9]+)?" "\\1" LLD_VERSION_MINOR
${LLD_VERSION})
# Determine LLD revision and repository.
# TODO: Figure out a way to get the revision and the repository on windows.
if ( NOT CMAKE_SYSTEM_NAME MATCHES "Windows" )
execute_process(COMMAND ${CMAKE_SOURCE_DIR}/utils/GetSourceVersion ${LLD_SOURCE_DIR}
OUTPUT_VARIABLE LLD_REVISION)
execute_process(COMMAND ${CMAKE_SOURCE_DIR}/utils/GetRepositoryPath ${LLD_SOURCE_DIR}
OUTPUT_VARIABLE LLD_REPOSITORY)
if ( LLD_REPOSITORY )
# Replace newline characters with spaces
string(REGEX REPLACE "(\r?\n)+" " " LLD_REPOSITORY ${LLD_REPOSITORY})
# Remove leading spaces
STRING(REGEX REPLACE "^[ \t\r\n]+" "" LLD_REPOSITORY "${LLD_REPOSITORY}" )
# Remove trailing spaces
string(REGEX REPLACE "(\ )+$" "" LLD_REPOSITORY ${LLD_REPOSITORY})
endif()
if ( LLD_REVISION )
# Replace newline characters with spaces
string(REGEX REPLACE "(\r?\n)+" " " LLD_REVISION ${LLD_REVISION})
# Remove leading spaces
STRING(REGEX REPLACE "^[ \t\r\n]+" "" LLD_REVISION "${LLD_REVISION}" )
# Remove trailing spaces
string(REGEX REPLACE "(\ )+$" "" LLD_REVISION ${LLD_REVISION})
endif()
endif ()
# Configure the Version.inc file.
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/include/lld/Common/Version.inc.in
${CMAKE_CURRENT_BINARY_DIR}/include/lld/Common/Version.inc)
if (CMAKE_SOURCE_DIR STREQUAL CMAKE_BINARY_DIR)
message(FATAL_ERROR "In-source builds are not allowed. CMake would overwrite "
"the makefiles distributed with LLVM. Please create a directory and run cmake "
"from there, passing the path to this source directory as the last argument. "
"This process created the file `CMakeCache.txt' and the directory "
"`CMakeFiles'. Please delete them.")
endif()
list (APPEND CMAKE_MODULE_PATH "${LLD_SOURCE_DIR}/cmake/modules")
include(AddLLD)
option(LLD_USE_VTUNE
"Enable VTune user task tracking."
OFF)
if (LLD_USE_VTUNE)
find_package(VTune)
if (VTUNE_FOUND)
include_directories(${VTune_INCLUDE_DIRS})
list(APPEND LLVM_COMMON_LIBS ${VTune_LIBRARIES})
add_definitions(-DLLD_HAS_VTUNE)
endif()
endif()
option(LLD_BUILD_TOOLS
"Build the lld tools. If OFF, just generate build targets." ON)
if (MSVC)
add_definitions(-wd4530) # Suppress 'warning C4530: C++ exception handler used, but unwind semantics are not enabled.'
add_definitions(-wd4062) # Suppress 'warning C4062: enumerator X in switch of enum Y is not handled' from system header.
endif()
include_directories(BEFORE
${CMAKE_CURRENT_BINARY_DIR}/include
${CMAKE_CURRENT_SOURCE_DIR}/include
)
if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY)
install(DIRECTORY include/
DESTINATION include
FILES_MATCHING
PATTERN "*.h"
PATTERN ".svn" EXCLUDE
)
endif()
add_subdirectory(Common)
add_subdirectory(lib)
add_subdirectory(tools/lld)
if (LLVM_INCLUDE_TESTS)
add_subdirectory(test)
add_subdirectory(unittests)
endif()
add_subdirectory(docs)
add_subdirectory(COFF)
add_subdirectory(ELF)
add_subdirectory(MinGW)
add_subdirectory(wasm)

View File

@@ -1,22 +0,0 @@
This file is a list of the people responsible for ensuring that patches for a
particular part of LLD are reviewed, either by themself or by someone else.
They are also the gatekeepers for their part of LLD, with the final word on
what goes in or not.
The list is sorted by surname and formatted to allow easy grepping and
beautification by scripts. The fields are: name (N), email (E), web-address
(W), PGP key ID and fingerprint (P), description (D), and snail-mail address
(S). Each entry should contain at least the (N), (E) and (D) fields.
N: Rui Ueyama
E: ruiu@google.com
D: COFF, ELF backends (COFF/* ELF/*)
N: Lang Hames, Nick Kledzik
E: lhames@gmail.com, kledzik@apple.com
D: Mach-O backend
N: Sam Clegg
E: sbc@chromium.org
D: WebAssembly backend (wasm/*)

View File

@@ -1,48 +0,0 @@
set(LLVM_TARGET_DEFINITIONS Options.td)
tablegen(LLVM Options.inc -gen-opt-parser-defs)
add_public_tablegen_target(COFFOptionsTableGen)
if(NOT LLD_BUILT_STANDALONE)
set(tablegen_deps intrinsics_gen)
endif()
add_lld_library(lldCOFF
Chunks.cpp
DebugTypes.cpp
DLL.cpp
Driver.cpp
DriverUtils.cpp
ICF.cpp
InputFiles.cpp
LTO.cpp
MapFile.cpp
MarkLive.cpp
MinGW.cpp
PDB.cpp
SymbolTable.cpp
Symbols.cpp
Writer.cpp
LINK_COMPONENTS
${LLVM_TARGETS_TO_BUILD}
BinaryFormat
Core
DebugInfoCodeView
DebugInfoMSF
DebugInfoPDB
LibDriver
LTO
MC
Object
Option
Support
WindowsManifest
LINK_LIBS
lldCommon
${LLVM_PTHREAD_LIB}
DEPENDS
COFFOptionsTableGen
${tablegen_deps}
)

View File

@@ -1,922 +0,0 @@
//===- Chunks.cpp ---------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "Chunks.h"
#include "InputFiles.h"
#include "Symbols.h"
#include "Writer.h"
#include "SymbolTable.h"
#include "lld/Common/ErrorHandler.h"
#include "llvm/ADT/Twine.h"
#include "llvm/BinaryFormat/COFF.h"
#include "llvm/Object/COFF.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
using namespace llvm;
using namespace llvm::object;
using namespace llvm::support::endian;
using namespace llvm::COFF;
using llvm::support::ulittle32_t;
namespace lld {
namespace coff {
SectionChunk::SectionChunk(ObjFile *f, const coff_section *h)
: Chunk(SectionKind), file(f), header(h), repl(this) {
// Initialize relocs.
setRelocs(file->getCOFFObj()->getRelocations(header));
// Initialize sectionName.
StringRef sectionName;
if (Expected<StringRef> e = file->getCOFFObj()->getSectionName(header))
sectionName = *e;
sectionNameData = sectionName.data();
sectionNameSize = sectionName.size();
setAlignment(header->getAlignment());
hasData = !(header->Characteristics & IMAGE_SCN_CNT_UNINITIALIZED_DATA);
// If linker GC is disabled, every chunk starts out alive. If linker GC is
// enabled, treat non-comdat sections as roots. Generally optimized object
// files will be built with -ffunction-sections or /Gy, so most things worth
// stripping will be in a comdat.
live = !config->doGC || !isCOMDAT();
}
// SectionChunk is one of the most frequently allocated classes, so it is
// important to keep it as compact as possible. As of this writing, the number
// below is the size of this class on x64 platforms.
static_assert(sizeof(SectionChunk) <= 88, "SectionChunk grew unexpectedly");
static void add16(uint8_t *p, int16_t v) { write16le(p, read16le(p) + v); }
static void add32(uint8_t *p, int32_t v) { write32le(p, read32le(p) + v); }
static void add64(uint8_t *p, int64_t v) { write64le(p, read64le(p) + v); }
static void or16(uint8_t *p, uint16_t v) { write16le(p, read16le(p) | v); }
static void or32(uint8_t *p, uint32_t v) { write32le(p, read32le(p) | v); }
// Verify that given sections are appropriate targets for SECREL
// relocations. This check is relaxed because unfortunately debug
// sections have section-relative relocations against absolute symbols.
static bool checkSecRel(const SectionChunk *sec, OutputSection *os) {
if (os)
return true;
if (sec->isCodeView())
return false;
error("SECREL relocation cannot be applied to absolute symbols");
return false;
}
static void applySecRel(const SectionChunk *sec, uint8_t *off,
OutputSection *os, uint64_t s) {
if (!checkSecRel(sec, os))
return;
uint64_t secRel = s - os->getRVA();
if (secRel > UINT32_MAX) {
error("overflow in SECREL relocation in section: " + sec->getSectionName());
return;
}
add32(off, secRel);
}
static void applySecIdx(uint8_t *off, OutputSection *os) {
// Absolute symbol doesn't have section index, but section index relocation
// against absolute symbol should be resolved to one plus the last output
// section index. This is required for compatibility with MSVC.
if (os)
add16(off, os->sectionIndex);
else
add16(off, DefinedAbsolute::numOutputSections + 1);
}
void SectionChunk::applyRelX64(uint8_t *off, uint16_t type, OutputSection *os,
uint64_t s, uint64_t p) const {
switch (type) {
case IMAGE_REL_AMD64_ADDR32: add32(off, s + config->imageBase); break;
case IMAGE_REL_AMD64_ADDR64: add64(off, s + config->imageBase); break;
case IMAGE_REL_AMD64_ADDR32NB: add32(off, s); break;
case IMAGE_REL_AMD64_REL32: add32(off, s - p - 4); break;
case IMAGE_REL_AMD64_REL32_1: add32(off, s - p - 5); break;
case IMAGE_REL_AMD64_REL32_2: add32(off, s - p - 6); break;
case IMAGE_REL_AMD64_REL32_3: add32(off, s - p - 7); break;
case IMAGE_REL_AMD64_REL32_4: add32(off, s - p - 8); break;
case IMAGE_REL_AMD64_REL32_5: add32(off, s - p - 9); break;
case IMAGE_REL_AMD64_SECTION: applySecIdx(off, os); break;
case IMAGE_REL_AMD64_SECREL: applySecRel(this, off, os, s); break;
default:
error("unsupported relocation type 0x" + Twine::utohexstr(type) + " in " +
toString(file));
}
}
void SectionChunk::applyRelX86(uint8_t *off, uint16_t type, OutputSection *os,
uint64_t s, uint64_t p) const {
switch (type) {
case IMAGE_REL_I386_ABSOLUTE: break;
case IMAGE_REL_I386_DIR32: add32(off, s + config->imageBase); break;
case IMAGE_REL_I386_DIR32NB: add32(off, s); break;
case IMAGE_REL_I386_REL32: add32(off, s - p - 4); break;
case IMAGE_REL_I386_SECTION: applySecIdx(off, os); break;
case IMAGE_REL_I386_SECREL: applySecRel(this, off, os, s); break;
default:
error("unsupported relocation type 0x" + Twine::utohexstr(type) + " in " +
toString(file));
}
}
static void applyMOV(uint8_t *off, uint16_t v) {
write16le(off, (read16le(off) & 0xfbf0) | ((v & 0x800) >> 1) | ((v >> 12) & 0xf));
write16le(off + 2, (read16le(off + 2) & 0x8f00) | ((v & 0x700) << 4) | (v & 0xff));
}
static uint16_t readMOV(uint8_t *off, bool movt) {
uint16_t op1 = read16le(off);
if ((op1 & 0xfbf0) != (movt ? 0xf2c0 : 0xf240))
error("unexpected instruction in " + Twine(movt ? "MOVT" : "MOVW") +
" instruction in MOV32T relocation");
uint16_t op2 = read16le(off + 2);
if ((op2 & 0x8000) != 0)
error("unexpected instruction in " + Twine(movt ? "MOVT" : "MOVW") +
" instruction in MOV32T relocation");
return (op2 & 0x00ff) | ((op2 >> 4) & 0x0700) | ((op1 << 1) & 0x0800) |
((op1 & 0x000f) << 12);
}
void applyMOV32T(uint8_t *off, uint32_t v) {
uint16_t immW = readMOV(off, false); // read MOVW operand
uint16_t immT = readMOV(off + 4, true); // read MOVT operand
uint32_t imm = immW | (immT << 16);
v += imm; // add the immediate offset
applyMOV(off, v); // set MOVW operand
applyMOV(off + 4, v >> 16); // set MOVT operand
}
static void applyBranch20T(uint8_t *off, int32_t v) {
if (!isInt<21>(v))
error("relocation out of range");
uint32_t s = v < 0 ? 1 : 0;
uint32_t j1 = (v >> 19) & 1;
uint32_t j2 = (v >> 18) & 1;
or16(off, (s << 10) | ((v >> 12) & 0x3f));
or16(off + 2, (j1 << 13) | (j2 << 11) | ((v >> 1) & 0x7ff));
}
void applyBranch24T(uint8_t *off, int32_t v) {
if (!isInt<25>(v))
error("relocation out of range");
uint32_t s = v < 0 ? 1 : 0;
uint32_t j1 = ((~v >> 23) & 1) ^ s;
uint32_t j2 = ((~v >> 22) & 1) ^ s;
or16(off, (s << 10) | ((v >> 12) & 0x3ff));
// Clear out the J1 and J2 bits which may be set.
write16le(off + 2, (read16le(off + 2) & 0xd000) | (j1 << 13) | (j2 << 11) | ((v >> 1) & 0x7ff));
}
void SectionChunk::applyRelARM(uint8_t *off, uint16_t type, OutputSection *os,
uint64_t s, uint64_t p) const {
// Pointer to thumb code must have the LSB set.
uint64_t sx = s;
if (os && (os->header.Characteristics & IMAGE_SCN_MEM_EXECUTE))
sx |= 1;
switch (type) {
case IMAGE_REL_ARM_ADDR32: add32(off, sx + config->imageBase); break;
case IMAGE_REL_ARM_ADDR32NB: add32(off, sx); break;
case IMAGE_REL_ARM_MOV32T: applyMOV32T(off, sx + config->imageBase); break;
case IMAGE_REL_ARM_BRANCH20T: applyBranch20T(off, sx - p - 4); break;
case IMAGE_REL_ARM_BRANCH24T: applyBranch24T(off, sx - p - 4); break;
case IMAGE_REL_ARM_BLX23T: applyBranch24T(off, sx - p - 4); break;
case IMAGE_REL_ARM_SECTION: applySecIdx(off, os); break;
case IMAGE_REL_ARM_SECREL: applySecRel(this, off, os, s); break;
case IMAGE_REL_ARM_REL32: add32(off, sx - p - 4); break;
default:
error("unsupported relocation type 0x" + Twine::utohexstr(type) + " in " +
toString(file));
}
}
// Interpret the existing immediate value as a byte offset to the
// target symbol, then update the instruction with the immediate as
// the page offset from the current instruction to the target.
void applyArm64Addr(uint8_t *off, uint64_t s, uint64_t p, int shift) {
uint32_t orig = read32le(off);
uint64_t imm = ((orig >> 29) & 0x3) | ((orig >> 3) & 0x1FFFFC);
s += imm;
imm = (s >> shift) - (p >> shift);
uint32_t immLo = (imm & 0x3) << 29;
uint32_t immHi = (imm & 0x1FFFFC) << 3;
uint64_t mask = (0x3 << 29) | (0x1FFFFC << 3);
write32le(off, (orig & ~mask) | immLo | immHi);
}
// Update the immediate field in a AARCH64 ldr, str, and add instruction.
// Optionally limit the range of the written immediate by one or more bits
// (rangeLimit).
void applyArm64Imm(uint8_t *off, uint64_t imm, uint32_t rangeLimit) {
uint32_t orig = read32le(off);
imm += (orig >> 10) & 0xFFF;
orig &= ~(0xFFF << 10);
write32le(off, orig | ((imm & (0xFFF >> rangeLimit)) << 10));
}
// Add the 12 bit page offset to the existing immediate.
// Ldr/str instructions store the opcode immediate scaled
// by the load/store size (giving a larger range for larger
// loads/stores). The immediate is always (both before and after
// fixing up the relocation) stored scaled similarly.
// Even if larger loads/stores have a larger range, limit the
// effective offset to 12 bit, since it is intended to be a
// page offset.
static void applyArm64Ldr(uint8_t *off, uint64_t imm) {
uint32_t orig = read32le(off);
uint32_t size = orig >> 30;
// 0x04000000 indicates SIMD/FP registers
// 0x00800000 indicates 128 bit
if ((orig & 0x4800000) == 0x4800000)
size += 4;
if ((imm & ((1 << size) - 1)) != 0)
error("misaligned ldr/str offset");
applyArm64Imm(off, imm >> size, size);
}
static void applySecRelLow12A(const SectionChunk *sec, uint8_t *off,
OutputSection *os, uint64_t s) {
if (checkSecRel(sec, os))
applyArm64Imm(off, (s - os->getRVA()) & 0xfff, 0);
}
static void applySecRelHigh12A(const SectionChunk *sec, uint8_t *off,
OutputSection *os, uint64_t s) {
if (!checkSecRel(sec, os))
return;
uint64_t secRel = (s - os->getRVA()) >> 12;
if (0xfff < secRel) {
error("overflow in SECREL_HIGH12A relocation in section: " +
sec->getSectionName());
return;
}
applyArm64Imm(off, secRel & 0xfff, 0);
}
static void applySecRelLdr(const SectionChunk *sec, uint8_t *off,
OutputSection *os, uint64_t s) {
if (checkSecRel(sec, os))
applyArm64Ldr(off, (s - os->getRVA()) & 0xfff);
}
void applyArm64Branch26(uint8_t *off, int64_t v) {
if (!isInt<28>(v))
error("relocation out of range");
or32(off, (v & 0x0FFFFFFC) >> 2);
}
static void applyArm64Branch19(uint8_t *off, int64_t v) {
if (!isInt<21>(v))
error("relocation out of range");
or32(off, (v & 0x001FFFFC) << 3);
}
static void applyArm64Branch14(uint8_t *off, int64_t v) {
if (!isInt<16>(v))
error("relocation out of range");
or32(off, (v & 0x0000FFFC) << 3);
}
void SectionChunk::applyRelARM64(uint8_t *off, uint16_t type, OutputSection *os,
uint64_t s, uint64_t p) const {
switch (type) {
case IMAGE_REL_ARM64_PAGEBASE_REL21: applyArm64Addr(off, s, p, 12); break;
case IMAGE_REL_ARM64_REL21: applyArm64Addr(off, s, p, 0); break;
case IMAGE_REL_ARM64_PAGEOFFSET_12A: applyArm64Imm(off, s & 0xfff, 0); break;
case IMAGE_REL_ARM64_PAGEOFFSET_12L: applyArm64Ldr(off, s & 0xfff); break;
case IMAGE_REL_ARM64_BRANCH26: applyArm64Branch26(off, s - p); break;
case IMAGE_REL_ARM64_BRANCH19: applyArm64Branch19(off, s - p); break;
case IMAGE_REL_ARM64_BRANCH14: applyArm64Branch14(off, s - p); break;
case IMAGE_REL_ARM64_ADDR32: add32(off, s + config->imageBase); break;
case IMAGE_REL_ARM64_ADDR32NB: add32(off, s); break;
case IMAGE_REL_ARM64_ADDR64: add64(off, s + config->imageBase); break;
case IMAGE_REL_ARM64_SECREL: applySecRel(this, off, os, s); break;
case IMAGE_REL_ARM64_SECREL_LOW12A: applySecRelLow12A(this, off, os, s); break;
case IMAGE_REL_ARM64_SECREL_HIGH12A: applySecRelHigh12A(this, off, os, s); break;
case IMAGE_REL_ARM64_SECREL_LOW12L: applySecRelLdr(this, off, os, s); break;
case IMAGE_REL_ARM64_SECTION: applySecIdx(off, os); break;
case IMAGE_REL_ARM64_REL32: add32(off, s - p - 4); break;
default:
error("unsupported relocation type 0x" + Twine::utohexstr(type) + " in " +
toString(file));
}
}
static void maybeReportRelocationToDiscarded(const SectionChunk *fromChunk,
Defined *sym,
const coff_relocation &rel) {
// Don't report these errors when the relocation comes from a debug info
// section or in mingw mode. MinGW mode object files (built by GCC) can
// have leftover sections with relocations against discarded comdat
// sections. Such sections are left as is, with relocations untouched.
if (fromChunk->isCodeView() || fromChunk->isDWARF() || config->mingw)
return;
// Get the name of the symbol. If it's null, it was discarded early, so we
// have to go back to the object file.
ObjFile *file = fromChunk->file;
StringRef name;
if (sym) {
name = sym->getName();
} else {
COFFSymbolRef coffSym =
check(file->getCOFFObj()->getSymbol(rel.SymbolTableIndex));
file->getCOFFObj()->getSymbolName(coffSym, name);
}
std::vector<std::string> symbolLocations =
getSymbolLocations(file, rel.SymbolTableIndex);
std::string out;
llvm::raw_string_ostream os(out);
os << "relocation against symbol in discarded section: " + name;
for (const std::string &s : symbolLocations)
os << s;
error(os.str());
}
void SectionChunk::writeTo(uint8_t *buf) const {
if (!hasData)
return;
// Copy section contents from source object file to output file.
ArrayRef<uint8_t> a = getContents();
if (!a.empty())
memcpy(buf, a.data(), a.size());
// Apply relocations.
size_t inputSize = getSize();
for (size_t i = 0, e = relocsSize; i < e; i++) {
const coff_relocation &rel = relocsData[i];
// Check for an invalid relocation offset. This check isn't perfect, because
// we don't have the relocation size, which is only known after checking the
// machine and relocation type. As a result, a relocation may overwrite the
// beginning of the following input section.
if (rel.VirtualAddress >= inputSize) {
error("relocation points beyond the end of its parent section");
continue;
}
uint8_t *off = buf + rel.VirtualAddress;
auto *sym =
dyn_cast_or_null<Defined>(file->getSymbol(rel.SymbolTableIndex));
// Get the output section of the symbol for this relocation. The output
// section is needed to compute SECREL and SECTION relocations used in debug
// info.
Chunk *c = sym ? sym->getChunk() : nullptr;
OutputSection *os = c ? c->getOutputSection() : nullptr;
// Skip the relocation if it refers to a discarded section, and diagnose it
// as an error if appropriate. If a symbol was discarded early, it may be
// null. If it was discarded late, the output section will be null, unless
// it was an absolute or synthetic symbol.
if (!sym ||
(!os && !isa<DefinedAbsolute>(sym) && !isa<DefinedSynthetic>(sym))) {
maybeReportRelocationToDiscarded(this, sym, rel);
continue;
}
uint64_t s = sym->getRVA();
// Compute the RVA of the relocation for relative relocations.
uint64_t p = rva + rel.VirtualAddress;
switch (config->machine) {
case AMD64:
applyRelX64(off, rel.Type, os, s, p);
break;
case I386:
applyRelX86(off, rel.Type, os, s, p);
break;
case ARMNT:
applyRelARM(off, rel.Type, os, s, p);
break;
case ARM64:
applyRelARM64(off, rel.Type, os, s, p);
break;
default:
llvm_unreachable("unknown machine type");
}
}
}
void SectionChunk::addAssociative(SectionChunk *child) {
// Insert this child at the head of the list.
assert(child->assocChildren == nullptr &&
"associated sections cannot have their own associated children");
child->assocChildren = assocChildren;
assocChildren = child;
}
static uint8_t getBaserelType(const coff_relocation &rel) {
switch (config->machine) {
case AMD64:
if (rel.Type == IMAGE_REL_AMD64_ADDR64)
return IMAGE_REL_BASED_DIR64;
return IMAGE_REL_BASED_ABSOLUTE;
case I386:
if (rel.Type == IMAGE_REL_I386_DIR32)
return IMAGE_REL_BASED_HIGHLOW;
return IMAGE_REL_BASED_ABSOLUTE;
case ARMNT:
if (rel.Type == IMAGE_REL_ARM_ADDR32)
return IMAGE_REL_BASED_HIGHLOW;
if (rel.Type == IMAGE_REL_ARM_MOV32T)
return IMAGE_REL_BASED_ARM_MOV32T;
return IMAGE_REL_BASED_ABSOLUTE;
case ARM64:
if (rel.Type == IMAGE_REL_ARM64_ADDR64)
return IMAGE_REL_BASED_DIR64;
return IMAGE_REL_BASED_ABSOLUTE;
default:
llvm_unreachable("unknown machine type");
}
}
// Windows-specific.
// Collect all locations that contain absolute addresses, which need to be
// fixed by the loader if load-time relocation is needed.
// Only called when base relocation is enabled.
void SectionChunk::getBaserels(std::vector<Baserel> *res) {
for (size_t i = 0, e = relocsSize; i < e; i++) {
const coff_relocation &rel = relocsData[i];
uint8_t ty = getBaserelType(rel);
if (ty == IMAGE_REL_BASED_ABSOLUTE)
continue;
Symbol *target = file->getSymbol(rel.SymbolTableIndex);
if (!target || isa<DefinedAbsolute>(target))
continue;
res->emplace_back(rva + rel.VirtualAddress, ty);
}
}
// MinGW specific.
// Check whether a static relocation of type Type can be deferred and
// handled at runtime as a pseudo relocation (for references to a module
// local variable, which turned out to actually need to be imported from
// another DLL) This returns the size the relocation is supposed to update,
// in bits, or 0 if the relocation cannot be handled as a runtime pseudo
// relocation.
static int getRuntimePseudoRelocSize(uint16_t type) {
// Relocations that either contain an absolute address, or a plain
// relative offset, since the runtime pseudo reloc implementation
// adds 8/16/32/64 bit values to a memory address.
//
// Given a pseudo relocation entry,
//
// typedef struct {
// DWORD sym;
// DWORD target;
// DWORD flags;
// } runtime_pseudo_reloc_item_v2;
//
// the runtime relocation performs this adjustment:
// *(base + .target) += *(base + .sym) - (base + .sym)
//
// This works for both absolute addresses (IMAGE_REL_*_ADDR32/64,
// IMAGE_REL_I386_DIR32, where the memory location initially contains
// the address of the IAT slot, and for relative addresses (IMAGE_REL*_REL32),
// where the memory location originally contains the relative offset to the
// IAT slot.
//
// This requires the target address to be writable, either directly out of
// the image, or temporarily changed at runtime with VirtualProtect.
// Since this only operates on direct address values, it doesn't work for
// ARM/ARM64 relocations, other than the plain ADDR32/ADDR64 relocations.
switch (config->machine) {
case AMD64:
switch (type) {
case IMAGE_REL_AMD64_ADDR64:
return 64;
case IMAGE_REL_AMD64_ADDR32:
case IMAGE_REL_AMD64_REL32:
case IMAGE_REL_AMD64_REL32_1:
case IMAGE_REL_AMD64_REL32_2:
case IMAGE_REL_AMD64_REL32_3:
case IMAGE_REL_AMD64_REL32_4:
case IMAGE_REL_AMD64_REL32_5:
return 32;
default:
return 0;
}
case I386:
switch (type) {
case IMAGE_REL_I386_DIR32:
case IMAGE_REL_I386_REL32:
return 32;
default:
return 0;
}
case ARMNT:
switch (type) {
case IMAGE_REL_ARM_ADDR32:
return 32;
default:
return 0;
}
case ARM64:
switch (type) {
case IMAGE_REL_ARM64_ADDR64:
return 64;
case IMAGE_REL_ARM64_ADDR32:
return 32;
default:
return 0;
}
default:
llvm_unreachable("unknown machine type");
}
}
// MinGW specific.
// Append information to the provided vector about all relocations that
// need to be handled at runtime as runtime pseudo relocations (references
// to a module local variable, which turned out to actually need to be
// imported from another DLL).
void SectionChunk::getRuntimePseudoRelocs(
std::vector<RuntimePseudoReloc> &res) {
for (const coff_relocation &rel : getRelocs()) {
auto *target =
dyn_cast_or_null<Defined>(file->getSymbol(rel.SymbolTableIndex));
if (!target || !target->isRuntimePseudoReloc)
continue;
int sizeInBits = getRuntimePseudoRelocSize(rel.Type);
if (sizeInBits == 0) {
error("unable to automatically import from " + target->getName() +
" with relocation type " +
file->getCOFFObj()->getRelocationTypeName(rel.Type) + " in " +
toString(file));
continue;
}
// sizeInBits is used to initialize the Flags field; currently no
// other flags are defined.
res.emplace_back(
RuntimePseudoReloc(target, this, rel.VirtualAddress, sizeInBits));
}
}
bool SectionChunk::isCOMDAT() const {
return header->Characteristics & IMAGE_SCN_LNK_COMDAT;
}
void SectionChunk::printDiscardedMessage() const {
// Removed by dead-stripping. If it's removed by ICF, ICF already
// printed out the name, so don't repeat that here.
if (sym && this == repl)
message("Discarded " + sym->getName());
}
StringRef SectionChunk::getDebugName() const {
if (sym)
return sym->getName();
return "";
}
ArrayRef<uint8_t> SectionChunk::getContents() const {
ArrayRef<uint8_t> a;
cantFail(file->getCOFFObj()->getSectionContents(header, a));
return a;
}
ArrayRef<uint8_t> SectionChunk::consumeDebugMagic() {
assert(isCodeView());
return consumeDebugMagic(getContents(), getSectionName());
}
ArrayRef<uint8_t> SectionChunk::consumeDebugMagic(ArrayRef<uint8_t> data,
StringRef sectionName) {
if (data.empty())
return {};
// First 4 bytes are section magic.
if (data.size() < 4)
fatal("the section is too short: " + sectionName);
if (!sectionName.startswith(".debug$"))
fatal("invalid section: " + sectionName);
uint32_t magic = support::endian::read32le(data.data());
uint32_t expectedMagic = sectionName == ".debug$H"
? DEBUG_HASHES_SECTION_MAGIC
: DEBUG_SECTION_MAGIC;
if (magic != expectedMagic) {
warn("ignoring section " + sectionName + " with unrecognized magic 0x" +
utohexstr(magic));
return {};
}
return data.slice(4);
}
SectionChunk *SectionChunk::findByName(ArrayRef<SectionChunk *> sections,
StringRef name) {
for (SectionChunk *c : sections)
if (c->getSectionName() == name)
return c;
return nullptr;
}
void SectionChunk::replace(SectionChunk *other) {
p2Align = std::max(p2Align, other->p2Align);
other->repl = repl;
other->live = false;
}
uint32_t SectionChunk::getSectionNumber() const {
DataRefImpl r;
r.p = reinterpret_cast<uintptr_t>(header);
SectionRef s(r, file->getCOFFObj());
return s.getIndex() + 1;
}
CommonChunk::CommonChunk(const COFFSymbolRef s) : sym(s) {
// The value of a common symbol is its size. Align all common symbols smaller
// than 32 bytes naturally, i.e. round the size up to the next power of two.
// This is what MSVC link.exe does.
setAlignment(std::min(32U, uint32_t(PowerOf2Ceil(sym.getValue()))));
hasData = false;
}
uint32_t CommonChunk::getOutputCharacteristics() const {
return IMAGE_SCN_CNT_UNINITIALIZED_DATA | IMAGE_SCN_MEM_READ |
IMAGE_SCN_MEM_WRITE;
}
void StringChunk::writeTo(uint8_t *buf) const {
memcpy(buf, str.data(), str.size());
buf[str.size()] = '\0';
}
ImportThunkChunkX64::ImportThunkChunkX64(Defined *s) : ImportThunkChunk(s) {
// Intel Optimization Manual says that all branch targets
// should be 16-byte aligned. MSVC linker does this too.
setAlignment(16);
}
void ImportThunkChunkX64::writeTo(uint8_t *buf) const {
memcpy(buf, importThunkX86, sizeof(importThunkX86));
// The first two bytes is a JMP instruction. Fill its operand.
write32le(buf + 2, impSymbol->getRVA() - rva - getSize());
}
void ImportThunkChunkX86::getBaserels(std::vector<Baserel> *res) {
res->emplace_back(getRVA() + 2);
}
void ImportThunkChunkX86::writeTo(uint8_t *buf) const {
memcpy(buf, importThunkX86, sizeof(importThunkX86));
// The first two bytes is a JMP instruction. Fill its operand.
write32le(buf + 2,
impSymbol->getRVA() + config->imageBase);
}
void ImportThunkChunkARM::getBaserels(std::vector<Baserel> *res) {
res->emplace_back(getRVA(), IMAGE_REL_BASED_ARM_MOV32T);
}
void ImportThunkChunkARM::writeTo(uint8_t *buf) const {
memcpy(buf, importThunkARM, sizeof(importThunkARM));
// Fix mov.w and mov.t operands.
applyMOV32T(buf, impSymbol->getRVA() + config->imageBase);
}
void ImportThunkChunkARM64::writeTo(uint8_t *buf) const {
int64_t off = impSymbol->getRVA() & 0xfff;
memcpy(buf, importThunkARM64, sizeof(importThunkARM64));
applyArm64Addr(buf, impSymbol->getRVA(), rva, 12);
applyArm64Ldr(buf + 4, off);
}
// A Thumb2, PIC, non-interworking range extension thunk.
const uint8_t armThunk[] = {
0x40, 0xf2, 0x00, 0x0c, // P: movw ip,:lower16:S - (P + (L1-P) + 4)
0xc0, 0xf2, 0x00, 0x0c, // movt ip,:upper16:S - (P + (L1-P) + 4)
0xe7, 0x44, // L1: add pc, ip
};
size_t RangeExtensionThunkARM::getSize() const {
assert(config->machine == ARMNT);
return sizeof(armThunk);
}
void RangeExtensionThunkARM::writeTo(uint8_t *buf) const {
assert(config->machine == ARMNT);
uint64_t offset = target->getRVA() - rva - 12;
memcpy(buf, armThunk, sizeof(armThunk));
applyMOV32T(buf, uint32_t(offset));
}
// A position independent ARM64 adrp+add thunk, with a maximum range of
// +/- 4 GB, which is enough for any PE-COFF.
const uint8_t arm64Thunk[] = {
0x10, 0x00, 0x00, 0x90, // adrp x16, Dest
0x10, 0x02, 0x00, 0x91, // add x16, x16, :lo12:Dest
0x00, 0x02, 0x1f, 0xd6, // br x16
};
size_t RangeExtensionThunkARM64::getSize() const {
assert(config->machine == ARM64);
return sizeof(arm64Thunk);
}
void RangeExtensionThunkARM64::writeTo(uint8_t *buf) const {
assert(config->machine == ARM64);
memcpy(buf, arm64Thunk, sizeof(arm64Thunk));
applyArm64Addr(buf + 0, target->getRVA(), rva, 12);
applyArm64Imm(buf + 4, target->getRVA() & 0xfff, 0);
}
void LocalImportChunk::getBaserels(std::vector<Baserel> *res) {
res->emplace_back(getRVA());
}
size_t LocalImportChunk::getSize() const { return config->wordsize; }
void LocalImportChunk::writeTo(uint8_t *buf) const {
if (config->is64()) {
write64le(buf, sym->getRVA() + config->imageBase);
} else {
write32le(buf, sym->getRVA() + config->imageBase);
}
}
void RVATableChunk::writeTo(uint8_t *buf) const {
ulittle32_t *begin = reinterpret_cast<ulittle32_t *>(buf);
size_t cnt = 0;
for (const ChunkAndOffset &co : syms)
begin[cnt++] = co.inputChunk->getRVA() + co.offset;
std::sort(begin, begin + cnt);
assert(std::unique(begin, begin + cnt) == begin + cnt &&
"RVA tables should be de-duplicated");
}
// MinGW specific, for the "automatic import of variables from DLLs" feature.
size_t PseudoRelocTableChunk::getSize() const {
if (relocs.empty())
return 0;
return 12 + 12 * relocs.size();
}
// MinGW specific.
void PseudoRelocTableChunk::writeTo(uint8_t *buf) const {
if (relocs.empty())
return;
ulittle32_t *table = reinterpret_cast<ulittle32_t *>(buf);
// This is the list header, to signal the runtime pseudo relocation v2
// format.
table[0] = 0;
table[1] = 0;
table[2] = 1;
size_t idx = 3;
for (const RuntimePseudoReloc &rpr : relocs) {
table[idx + 0] = rpr.sym->getRVA();
table[idx + 1] = rpr.target->getRVA() + rpr.targetOffset;
table[idx + 2] = rpr.flags;
idx += 3;
}
}
// Windows-specific. This class represents a block in .reloc section.
// The format is described here.
//
// On Windows, each DLL is linked against a fixed base address and
// usually loaded to that address. However, if there's already another
// DLL that overlaps, the loader has to relocate it. To do that, DLLs
// contain .reloc sections which contain offsets that need to be fixed
// up at runtime. If the loader finds that a DLL cannot be loaded to its
// desired base address, it loads it to somewhere else, and add <actual
// base address> - <desired base address> to each offset that is
// specified by the .reloc section. In ELF terms, .reloc sections
// contain relative relocations in REL format (as opposed to RELA.)
//
// This already significantly reduces the size of relocations compared
// to ELF .rel.dyn, but Windows does more to reduce it (probably because
// it was invented for PCs in the late '80s or early '90s.) Offsets in
// .reloc are grouped by page where the page size is 12 bits, and
// offsets sharing the same page address are stored consecutively to
// represent them with less space. This is very similar to the page
// table which is grouped by (multiple stages of) pages.
//
// For example, let's say we have 0x00030, 0x00500, 0x00700, 0x00A00,
// 0x20004, and 0x20008 in a .reloc section for x64. The uppermost 4
// bits have a type IMAGE_REL_BASED_DIR64 or 0xA. In the section, they
// are represented like this:
//
// 0x00000 -- page address (4 bytes)
// 16 -- size of this block (4 bytes)
// 0xA030 -- entries (2 bytes each)
// 0xA500
// 0xA700
// 0xAA00
// 0x20000 -- page address (4 bytes)
// 12 -- size of this block (4 bytes)
// 0xA004 -- entries (2 bytes each)
// 0xA008
//
// Usually we have a lot of relocations for each page, so the number of
// bytes for one .reloc entry is close to 2 bytes on average.
BaserelChunk::BaserelChunk(uint32_t page, Baserel *begin, Baserel *end) {
// Block header consists of 4 byte page RVA and 4 byte block size.
// Each entry is 2 byte. Last entry may be padding.
data.resize(alignTo((end - begin) * 2 + 8, 4));
uint8_t *p = data.data();
write32le(p, page);
write32le(p + 4, data.size());
p += 8;
for (Baserel *i = begin; i != end; ++i) {
write16le(p, (i->type << 12) | (i->rva - page));
p += 2;
}
}
void BaserelChunk::writeTo(uint8_t *buf) const {
memcpy(buf, data.data(), data.size());
}
uint8_t Baserel::getDefaultType() {
switch (config->machine) {
case AMD64:
case ARM64:
return IMAGE_REL_BASED_DIR64;
case I386:
case ARMNT:
return IMAGE_REL_BASED_HIGHLOW;
default:
llvm_unreachable("unknown machine type");
}
}
MergeChunk *MergeChunk::instances[Log2MaxSectionAlignment + 1] = {};
MergeChunk::MergeChunk(uint32_t alignment)
: builder(StringTableBuilder::RAW, alignment) {
setAlignment(alignment);
}
void MergeChunk::addSection(SectionChunk *c) {
assert(isPowerOf2_32(c->getAlignment()));
uint8_t p2Align = llvm::Log2_32(c->getAlignment());
assert(p2Align < array_lengthof(instances));
auto *&mc = instances[p2Align];
if (!mc)
mc = make<MergeChunk>(c->getAlignment());
mc->sections.push_back(c);
}
void MergeChunk::finalizeContents() {
assert(!finalized && "should only finalize once");
for (SectionChunk *c : sections)
if (c->live)
builder.add(toStringRef(c->getContents()));
builder.finalize();
finalized = true;
}
void MergeChunk::assignSubsectionRVAs() {
for (SectionChunk *c : sections) {
if (!c->live)
continue;
size_t off = builder.getOffset(toStringRef(c->getContents()));
c->setRVA(rva + off);
}
}
uint32_t MergeChunk::getOutputCharacteristics() const {
return IMAGE_SCN_MEM_READ | IMAGE_SCN_CNT_INITIALIZED_DATA;
}
size_t MergeChunk::getSize() const {
return builder.getSize();
}
void MergeChunk::writeTo(uint8_t *buf) const {
builder.write(buf);
}
// MinGW specific.
size_t AbsolutePointerChunk::getSize() const { return config->wordsize; }
void AbsolutePointerChunk::writeTo(uint8_t *buf) const {
if (config->is64()) {
write64le(buf, value);
} else {
write32le(buf, value);
}
}
} // namespace coff
} // namespace lld

686
deps/lld/COFF/Chunks.h vendored
View File

@@ -1,686 +0,0 @@
//===- Chunks.h -------------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLD_COFF_CHUNKS_H
#define LLD_COFF_CHUNKS_H
#include "Config.h"
#include "InputFiles.h"
#include "lld/Common/LLVM.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/PointerIntPair.h"
#include "llvm/ADT/iterator.h"
#include "llvm/ADT/iterator_range.h"
#include "llvm/MC/StringTableBuilder.h"
#include "llvm/Object/COFF.h"
#include <utility>
#include <vector>
namespace lld {
namespace coff {
using llvm::COFF::ImportDirectoryTableEntry;
using llvm::object::COFFSymbolRef;
using llvm::object::SectionRef;
using llvm::object::coff_relocation;
using llvm::object::coff_section;
class Baserel;
class Defined;
class DefinedImportData;
class DefinedRegular;
class ObjFile;
class OutputSection;
class RuntimePseudoReloc;
class Symbol;
// Mask for permissions (discardable, writable, readable, executable, etc).
const uint32_t permMask = 0xFE000000;
// Mask for section types (code, data, bss).
const uint32_t typeMask = 0x000000E0;
// The log base 2 of the largest section alignment, which is log2(8192), or 13.
enum : unsigned { Log2MaxSectionAlignment = 13 };
// A Chunk represents a chunk of data that will occupy space in the
// output (if the resolver chose that). It may or may not be backed by
// a section of an input file. It could be linker-created data, or
// doesn't even have actual data (if common or bss).
class Chunk {
public:
enum Kind : uint8_t { SectionKind, OtherKind, ImportThunkKind };
Kind kind() const { return chunkKind; }
// Returns the size of this chunk (even if this is a common or BSS.)
size_t getSize() const;
// Returns chunk alignment in power of two form. Value values are powers of
// two from 1 to 8192.
uint32_t getAlignment() const { return 1U << p2Align; }
// Update the chunk section alignment measured in bytes. Internally alignment
// is stored in log2.
void setAlignment(uint32_t align) {
// Treat zero byte alignment as 1 byte alignment.
align = align ? align : 1;
assert(llvm::isPowerOf2_32(align) && "alignment is not a power of 2");
p2Align = llvm::Log2_32(align);
assert(p2Align <= Log2MaxSectionAlignment &&
"impossible requested alignment");
}
// Write this chunk to a mmap'ed file, assuming Buf is pointing to
// beginning of the file. Because this function may use RVA values
// of other chunks for relocations, you need to set them properly
// before calling this function.
void writeTo(uint8_t *buf) const;
// The writer sets and uses the addresses. In practice, PE images cannot be
// larger than 2GB. Chunks are always laid as part of the image, so Chunk RVAs
// can be stored with 32 bits.
uint32_t getRVA() const { return rva; }
void setRVA(uint64_t v) {
rva = (uint32_t)v;
assert(rva == v && "RVA truncated");
}
// Returns readable/writable/executable bits.
uint32_t getOutputCharacteristics() const;
// Returns the section name if this is a section chunk.
// It is illegal to call this function on non-section chunks.
StringRef getSectionName() const;
// An output section has pointers to chunks in the section, and each
// chunk has a back pointer to an output section.
void setOutputSectionIdx(uint16_t o) { osidx = o; }
uint16_t getOutputSectionIdx() const { return osidx; }
OutputSection *getOutputSection() const;
// Windows-specific.
// Collect all locations that contain absolute addresses for base relocations.
void getBaserels(std::vector<Baserel> *res);
// Returns a human-readable name of this chunk. Chunks are unnamed chunks of
// bytes, so this is used only for logging or debugging.
StringRef getDebugName() const;
// Return true if this file has the hotpatch flag set to true in the
// S_COMPILE3 record in codeview debug info. Also returns true for some thunks
// synthesized by the linker.
bool isHotPatchable() const;
protected:
Chunk(Kind k = OtherKind) : chunkKind(k), hasData(true), p2Align(0) {}
const Kind chunkKind;
public:
// Returns true if this has non-zero data. BSS chunks return
// false. If false is returned, the space occupied by this chunk
// will be filled with zeros. Corresponds to the
// IMAGE_SCN_CNT_UNINITIALIZED_DATA section characteristic bit.
uint8_t hasData : 1;
public:
// The alignment of this chunk, stored in log2 form. The writer uses the
// value.
uint8_t p2Align : 7;
// The output section index for this chunk. The first valid section number is
// one.
uint16_t osidx = 0;
// The RVA of this chunk in the output. The writer sets a value.
uint32_t rva = 0;
};
class NonSectionChunk : public Chunk {
public:
virtual ~NonSectionChunk() = default;
// Returns the size of this chunk (even if this is a common or BSS.)
virtual size_t getSize() const = 0;
virtual uint32_t getOutputCharacteristics() const { return 0; }
// Write this chunk to a mmap'ed file, assuming Buf is pointing to
// beginning of the file. Because this function may use RVA values
// of other chunks for relocations, you need to set them properly
// before calling this function.
virtual void writeTo(uint8_t *buf) const {}
// Returns the section name if this is a section chunk.
// It is illegal to call this function on non-section chunks.
virtual StringRef getSectionName() const {
llvm_unreachable("unimplemented getSectionName");
}
// Windows-specific.
// Collect all locations that contain absolute addresses for base relocations.
virtual void getBaserels(std::vector<Baserel> *res) {}
// Returns a human-readable name of this chunk. Chunks are unnamed chunks of
// bytes, so this is used only for logging or debugging.
virtual StringRef getDebugName() const { return ""; }
static bool classof(const Chunk *c) { return c->kind() != SectionKind; }
protected:
NonSectionChunk(Kind k = OtherKind) : Chunk(k) {}
};
// A chunk corresponding a section of an input file.
class SectionChunk final : public Chunk {
// Identical COMDAT Folding feature accesses section internal data.
friend class ICF;
public:
class symbol_iterator : public llvm::iterator_adaptor_base<
symbol_iterator, const coff_relocation *,
std::random_access_iterator_tag, Symbol *> {
friend SectionChunk;
ObjFile *file;
symbol_iterator(ObjFile *file, const coff_relocation *i)
: symbol_iterator::iterator_adaptor_base(i), file(file) {}
public:
symbol_iterator() = default;
Symbol *operator*() const { return file->getSymbol(I->SymbolTableIndex); }
};
SectionChunk(ObjFile *file, const coff_section *header);
static bool classof(const Chunk *c) { return c->kind() == SectionKind; }
size_t getSize() const { return header->SizeOfRawData; }
ArrayRef<uint8_t> getContents() const;
void writeTo(uint8_t *buf) const;
uint32_t getOutputCharacteristics() const {
return header->Characteristics & (permMask | typeMask);
}
StringRef getSectionName() const {
return StringRef(sectionNameData, sectionNameSize);
}
void getBaserels(std::vector<Baserel> *res);
bool isCOMDAT() const;
void applyRelX64(uint8_t *off, uint16_t type, OutputSection *os, uint64_t s,
uint64_t p) const;
void applyRelX86(uint8_t *off, uint16_t type, OutputSection *os, uint64_t s,
uint64_t p) const;
void applyRelARM(uint8_t *off, uint16_t type, OutputSection *os, uint64_t s,
uint64_t p) const;
void applyRelARM64(uint8_t *off, uint16_t type, OutputSection *os, uint64_t s,
uint64_t p) const;
void getRuntimePseudoRelocs(std::vector<RuntimePseudoReloc> &res);
// Called if the garbage collector decides to not include this chunk
// in a final output. It's supposed to print out a log message to stdout.
void printDiscardedMessage() const;
// Adds COMDAT associative sections to this COMDAT section. A chunk
// and its children are treated as a group by the garbage collector.
void addAssociative(SectionChunk *child);
StringRef getDebugName() const;
// True if this is a codeview debug info chunk. These will not be laid out in
// the image. Instead they will end up in the PDB, if one is requested.
bool isCodeView() const {
return getSectionName() == ".debug" || getSectionName().startswith(".debug$");
}
// True if this is a DWARF debug info or exception handling chunk.
bool isDWARF() const {
return getSectionName().startswith(".debug_") || getSectionName() == ".eh_frame";
}
// Allow iteration over the bodies of this chunk's relocated symbols.
llvm::iterator_range<symbol_iterator> symbols() const {
return llvm::make_range(symbol_iterator(file, relocsData),
symbol_iterator(file, relocsData + relocsSize));
}
ArrayRef<coff_relocation> getRelocs() const {
return llvm::makeArrayRef(relocsData, relocsSize);
}
// Reloc setter used by ARM range extension thunk insertion.
void setRelocs(ArrayRef<coff_relocation> newRelocs) {
relocsData = newRelocs.data();
relocsSize = newRelocs.size();
assert(relocsSize == newRelocs.size() && "reloc size truncation");
}
// Single linked list iterator for associated comdat children.
class AssociatedIterator
: public llvm::iterator_facade_base<
AssociatedIterator, std::forward_iterator_tag, SectionChunk> {
public:
AssociatedIterator() = default;
AssociatedIterator(SectionChunk *head) : cur(head) {}
AssociatedIterator &operator=(const AssociatedIterator &r) {
cur = r.cur;
return *this;
}
bool operator==(const AssociatedIterator &r) const { return cur == r.cur; }
const SectionChunk &operator*() const { return *cur; }
SectionChunk &operator*() { return *cur; }
AssociatedIterator &operator++() {
cur = cur->assocChildren;
return *this;
}
private:
SectionChunk *cur = nullptr;
};
// Allow iteration over the associated child chunks for this section.
llvm::iterator_range<AssociatedIterator> children() const {
return llvm::make_range(AssociatedIterator(assocChildren),
AssociatedIterator(nullptr));
}
// The section ID this chunk belongs to in its Obj.
uint32_t getSectionNumber() const;
ArrayRef<uint8_t> consumeDebugMagic();
static ArrayRef<uint8_t> consumeDebugMagic(ArrayRef<uint8_t> data,
StringRef sectionName);
static SectionChunk *findByName(ArrayRef<SectionChunk *> sections,
StringRef name);
// The file that this chunk was created from.
ObjFile *file;
// Pointer to the COFF section header in the input file.
const coff_section *header;
// The COMDAT leader symbol if this is a COMDAT chunk.
DefinedRegular *sym = nullptr;
// The CRC of the contents as described in the COFF spec 4.5.5.
// Auxiliary Format 5: Section Definitions. Used for ICF.
uint32_t checksum = 0;
// Used by the garbage collector.
bool live;
// Whether this section needs to be kept distinct from other sections during
// ICF. This is set by the driver using address-significance tables.
bool keepUnique = false;
// The COMDAT selection if this is a COMDAT chunk.
llvm::COFF::COMDATType selection = (llvm::COFF::COMDATType)0;
// A pointer pointing to a replacement for this chunk.
// Initially it points to "this" object. If this chunk is merged
// with other chunk by ICF, it points to another chunk,
// and this chunk is considered as dead.
SectionChunk *repl;
private:
SectionChunk *assocChildren = nullptr;
// Used for ICF (Identical COMDAT Folding)
void replace(SectionChunk *other);
uint32_t eqClass[2] = {0, 0};
// Relocations for this section. Size is stored below.
const coff_relocation *relocsData;
// Section name string. Size is stored below.
const char *sectionNameData;
uint32_t relocsSize = 0;
uint32_t sectionNameSize = 0;
};
// Inline methods to implement faux-virtual dispatch for SectionChunk.
inline size_t Chunk::getSize() const {
if (isa<SectionChunk>(this))
return static_cast<const SectionChunk *>(this)->getSize();
else
return static_cast<const NonSectionChunk *>(this)->getSize();
}
inline uint32_t Chunk::getOutputCharacteristics() const {
if (isa<SectionChunk>(this))
return static_cast<const SectionChunk *>(this)->getOutputCharacteristics();
else
return static_cast<const NonSectionChunk *>(this)
->getOutputCharacteristics();
}
inline void Chunk::writeTo(uint8_t *buf) const {
if (isa<SectionChunk>(this))
static_cast<const SectionChunk *>(this)->writeTo(buf);
else
static_cast<const NonSectionChunk *>(this)->writeTo(buf);
}
inline StringRef Chunk::getSectionName() const {
if (isa<SectionChunk>(this))
return static_cast<const SectionChunk *>(this)->getSectionName();
else
return static_cast<const NonSectionChunk *>(this)->getSectionName();
}
inline void Chunk::getBaserels(std::vector<Baserel> *res) {
if (isa<SectionChunk>(this))
static_cast<SectionChunk *>(this)->getBaserels(res);
else
static_cast<NonSectionChunk *>(this)->getBaserels(res);
}
inline StringRef Chunk::getDebugName() const {
if (isa<SectionChunk>(this))
return static_cast<const SectionChunk *>(this)->getDebugName();
else
return static_cast<const NonSectionChunk *>(this)->getDebugName();
}
// This class is used to implement an lld-specific feature (not implemented in
// MSVC) that minimizes the output size by finding string literals sharing tail
// parts and merging them.
//
// If string tail merging is enabled and a section is identified as containing a
// string literal, it is added to a MergeChunk with an appropriate alignment.
// The MergeChunk then tail merges the strings using the StringTableBuilder
// class and assigns RVAs and section offsets to each of the member chunks based
// on the offsets assigned by the StringTableBuilder.
class MergeChunk : public NonSectionChunk {
public:
MergeChunk(uint32_t alignment);
static void addSection(SectionChunk *c);
void finalizeContents();
void assignSubsectionRVAs();
uint32_t getOutputCharacteristics() const override;
StringRef getSectionName() const override { return ".rdata"; }
size_t getSize() const override;
void writeTo(uint8_t *buf) const override;
static MergeChunk *instances[Log2MaxSectionAlignment + 1];
std::vector<SectionChunk *> sections;
private:
llvm::StringTableBuilder builder;
bool finalized = false;
};
// A chunk for common symbols. Common chunks don't have actual data.
class CommonChunk : public NonSectionChunk {
public:
CommonChunk(const COFFSymbolRef sym);
size_t getSize() const override { return sym.getValue(); }
uint32_t getOutputCharacteristics() const override;
StringRef getSectionName() const override { return ".bss"; }
private:
const COFFSymbolRef sym;
};
// A chunk for linker-created strings.
class StringChunk : public NonSectionChunk {
public:
explicit StringChunk(StringRef s) : str(s) {}
size_t getSize() const override { return str.size() + 1; }
void writeTo(uint8_t *buf) const override;
private:
StringRef str;
};
static const uint8_t importThunkX86[] = {
0xff, 0x25, 0x00, 0x00, 0x00, 0x00, // JMP *0x0
};
static const uint8_t importThunkARM[] = {
0x40, 0xf2, 0x00, 0x0c, // mov.w ip, #0
0xc0, 0xf2, 0x00, 0x0c, // mov.t ip, #0
0xdc, 0xf8, 0x00, 0xf0, // ldr.w pc, [ip]
};
static const uint8_t importThunkARM64[] = {
0x10, 0x00, 0x00, 0x90, // adrp x16, #0
0x10, 0x02, 0x40, 0xf9, // ldr x16, [x16]
0x00, 0x02, 0x1f, 0xd6, // br x16
};
// Windows-specific.
// A chunk for DLL import jump table entry. In a final output, its
// contents will be a JMP instruction to some __imp_ symbol.
class ImportThunkChunk : public NonSectionChunk {
public:
ImportThunkChunk(Defined *s)
: NonSectionChunk(ImportThunkKind), impSymbol(s) {}
static bool classof(const Chunk *c) { return c->kind() == ImportThunkKind; }
protected:
Defined *impSymbol;
};
class ImportThunkChunkX64 : public ImportThunkChunk {
public:
explicit ImportThunkChunkX64(Defined *s);
size_t getSize() const override { return sizeof(importThunkX86); }
void writeTo(uint8_t *buf) const override;
};
class ImportThunkChunkX86 : public ImportThunkChunk {
public:
explicit ImportThunkChunkX86(Defined *s) : ImportThunkChunk(s) {}
size_t getSize() const override { return sizeof(importThunkX86); }
void getBaserels(std::vector<Baserel> *res) override;
void writeTo(uint8_t *buf) const override;
};
class ImportThunkChunkARM : public ImportThunkChunk {
public:
explicit ImportThunkChunkARM(Defined *s) : ImportThunkChunk(s) {}
size_t getSize() const override { return sizeof(importThunkARM); }
void getBaserels(std::vector<Baserel> *res) override;
void writeTo(uint8_t *buf) const override;
};
class ImportThunkChunkARM64 : public ImportThunkChunk {
public:
explicit ImportThunkChunkARM64(Defined *s) : ImportThunkChunk(s) {}
size_t getSize() const override { return sizeof(importThunkARM64); }
void writeTo(uint8_t *buf) const override;
};
class RangeExtensionThunkARM : public NonSectionChunk {
public:
explicit RangeExtensionThunkARM(Defined *t) : target(t) {}
size_t getSize() const override;
void writeTo(uint8_t *buf) const override;
Defined *target;
};
class RangeExtensionThunkARM64 : public NonSectionChunk {
public:
explicit RangeExtensionThunkARM64(Defined *t) : target(t) {}
size_t getSize() const override;
void writeTo(uint8_t *buf) const override;
Defined *target;
};
// Windows-specific.
// See comments for DefinedLocalImport class.
class LocalImportChunk : public NonSectionChunk {
public:
explicit LocalImportChunk(Defined *s) : sym(s) {
setAlignment(config->wordsize);
}
size_t getSize() const override;
void getBaserels(std::vector<Baserel> *res) override;
void writeTo(uint8_t *buf) const override;
private:
Defined *sym;
};
// Duplicate RVAs are not allowed in RVA tables, so unique symbols by chunk and
// offset into the chunk. Order does not matter as the RVA table will be sorted
// later.
struct ChunkAndOffset {
Chunk *inputChunk;
uint32_t offset;
struct DenseMapInfo {
static ChunkAndOffset getEmptyKey() {
return {llvm::DenseMapInfo<Chunk *>::getEmptyKey(), 0};
}
static ChunkAndOffset getTombstoneKey() {
return {llvm::DenseMapInfo<Chunk *>::getTombstoneKey(), 0};
}
static unsigned getHashValue(const ChunkAndOffset &co) {
return llvm::DenseMapInfo<std::pair<Chunk *, uint32_t>>::getHashValue(
{co.inputChunk, co.offset});
}
static bool isEqual(const ChunkAndOffset &lhs, const ChunkAndOffset &rhs) {
return lhs.inputChunk == rhs.inputChunk && lhs.offset == rhs.offset;
}
};
};
using SymbolRVASet = llvm::DenseSet<ChunkAndOffset>;
// Table which contains symbol RVAs. Used for /safeseh and /guard:cf.
class RVATableChunk : public NonSectionChunk {
public:
explicit RVATableChunk(SymbolRVASet s) : syms(std::move(s)) {}
size_t getSize() const override { return syms.size() * 4; }
void writeTo(uint8_t *buf) const override;
private:
SymbolRVASet syms;
};
// Windows-specific.
// This class represents a block in .reloc section.
// See the PE/COFF spec 5.6 for details.
class BaserelChunk : public NonSectionChunk {
public:
BaserelChunk(uint32_t page, Baserel *begin, Baserel *end);
size_t getSize() const override { return data.size(); }
void writeTo(uint8_t *buf) const override;
private:
std::vector<uint8_t> data;
};
class Baserel {
public:
Baserel(uint32_t v, uint8_t ty) : rva(v), type(ty) {}
explicit Baserel(uint32_t v) : Baserel(v, getDefaultType()) {}
uint8_t getDefaultType();
uint32_t rva;
uint8_t type;
};
// This is a placeholder Chunk, to allow attaching a DefinedSynthetic to a
// specific place in a section, without any data. This is used for the MinGW
// specific symbol __RUNTIME_PSEUDO_RELOC_LIST_END__, even though the concept
// of an empty chunk isn't MinGW specific.
class EmptyChunk : public NonSectionChunk {
public:
EmptyChunk() {}
size_t getSize() const override { return 0; }
void writeTo(uint8_t *buf) const override {}
};
// MinGW specific, for the "automatic import of variables from DLLs" feature.
// This provides the table of runtime pseudo relocations, for variable
// references that turned out to need to be imported from a DLL even though
// the reference didn't use the dllimport attribute. The MinGW runtime will
// process this table after loading, before handling control over to user
// code.
class PseudoRelocTableChunk : public NonSectionChunk {
public:
PseudoRelocTableChunk(std::vector<RuntimePseudoReloc> &relocs)
: relocs(std::move(relocs)) {
setAlignment(4);
}
size_t getSize() const override;
void writeTo(uint8_t *buf) const override;
private:
std::vector<RuntimePseudoReloc> relocs;
};
// MinGW specific; information about one individual location in the image
// that needs to be fixed up at runtime after loading. This represents
// one individual element in the PseudoRelocTableChunk table.
class RuntimePseudoReloc {
public:
RuntimePseudoReloc(Defined *sym, SectionChunk *target, uint32_t targetOffset,
int flags)
: sym(sym), target(target), targetOffset(targetOffset), flags(flags) {}
Defined *sym;
SectionChunk *target;
uint32_t targetOffset;
// The Flags field contains the size of the relocation, in bits. No other
// flags are currently defined.
int flags;
};
// MinGW specific. A Chunk that contains one pointer-sized absolute value.
class AbsolutePointerChunk : public NonSectionChunk {
public:
AbsolutePointerChunk(uint64_t value) : value(value) {
setAlignment(getSize());
}
size_t getSize() const override;
void writeTo(uint8_t *buf) const override;
private:
uint64_t value;
};
// Return true if this file has the hotpatch flag set to true in the S_COMPILE3
// record in codeview debug info. Also returns true for some thunks synthesized
// by the linker.
inline bool Chunk::isHotPatchable() const {
if (auto *sc = dyn_cast<SectionChunk>(this))
return sc->file->hotPatchable;
else if (isa<ImportThunkChunk>(this))
return true;
return false;
}
void applyMOV32T(uint8_t *off, uint32_t v);
void applyBranch24T(uint8_t *off, int32_t v);
void applyArm64Addr(uint8_t *off, uint64_t s, uint64_t p, int shift);
void applyArm64Imm(uint8_t *off, uint64_t imm, uint32_t rangeLimit);
void applyArm64Branch26(uint8_t *off, int64_t v);
} // namespace coff
} // namespace lld
namespace llvm {
template <>
struct DenseMapInfo<lld::coff::ChunkAndOffset>
: lld::coff::ChunkAndOffset::DenseMapInfo {};
}
#endif

232
deps/lld/COFF/Config.h vendored
View File

@@ -1,232 +0,0 @@
//===- Config.h -------------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLD_COFF_CONFIG_H
#define LLD_COFF_CONFIG_H
#include "llvm/ADT/StringMap.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Object/COFF.h"
#include "llvm/Support/CachePruning.h"
#include <cstdint>
#include <map>
#include <set>
#include <string>
namespace lld {
namespace coff {
using llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN;
using llvm::COFF::WindowsSubsystem;
using llvm::StringRef;
class DefinedAbsolute;
class DefinedRelative;
class StringChunk;
class Symbol;
class InputFile;
// Short aliases.
static const auto AMD64 = llvm::COFF::IMAGE_FILE_MACHINE_AMD64;
static const auto ARM64 = llvm::COFF::IMAGE_FILE_MACHINE_ARM64;
static const auto ARMNT = llvm::COFF::IMAGE_FILE_MACHINE_ARMNT;
static const auto I386 = llvm::COFF::IMAGE_FILE_MACHINE_I386;
// Represents an /export option.
struct Export {
StringRef name; // N in /export:N or /export:E=N
StringRef extName; // E in /export:E=N
Symbol *sym = nullptr;
uint16_t ordinal = 0;
bool noname = false;
bool data = false;
bool isPrivate = false;
bool constant = false;
// If an export is a form of /export:foo=dllname.bar, that means
// that foo should be exported as an alias to bar in the DLL.
// forwardTo is set to "dllname.bar" part. Usually empty.
StringRef forwardTo;
StringChunk *forwardChunk = nullptr;
// True if this /export option was in .drectves section.
bool directives = false;
StringRef symbolName;
StringRef exportName; // Name in DLL
bool operator==(const Export &e) {
return (name == e.name && extName == e.extName &&
ordinal == e.ordinal && noname == e.noname &&
data == e.data && isPrivate == e.isPrivate);
}
};
enum class DebugType {
None = 0x0,
CV = 0x1, /// CodeView
PData = 0x2, /// Procedure Data
Fixup = 0x4, /// Relocation Table
};
enum class GuardCFLevel {
Off,
NoLongJmp, // Emit gfids but no longjmp tables
Full, // Enable all protections.
};
// Global configuration.
struct Configuration {
enum ManifestKind { SideBySide, Embed, No };
bool is64() { return machine == AMD64 || machine == ARM64; }
llvm::COFF::MachineTypes machine = IMAGE_FILE_MACHINE_UNKNOWN;
size_t wordsize;
bool verbose = false;
WindowsSubsystem subsystem = llvm::COFF::IMAGE_SUBSYSTEM_UNKNOWN;
Symbol *entry = nullptr;
bool noEntry = false;
std::string outputFile;
std::string importName;
bool demangle = true;
bool doGC = true;
bool doICF = true;
bool tailMerge;
bool relocatable = true;
bool forceMultiple = false;
bool forceMultipleRes = false;
bool forceUnresolved = false;
bool debug = false;
bool debugDwarf = false;
bool debugGHashes = false;
bool debugSymtab = false;
bool showTiming = false;
bool showSummary = false;
unsigned debugTypes = static_cast<unsigned>(DebugType::None);
std::vector<std::string> natvisFiles;
llvm::SmallString<128> pdbAltPath;
llvm::SmallString<128> pdbPath;
llvm::SmallString<128> pdbSourcePath;
std::vector<llvm::StringRef> argv;
// Symbols in this set are considered as live by the garbage collector.
std::vector<Symbol *> gcroot;
std::set<std::string> noDefaultLibs;
bool noDefaultLibAll = false;
// True if we are creating a DLL.
bool dll = false;
StringRef implib;
std::vector<Export> exports;
std::set<std::string> delayLoads;
std::map<std::string, int> dllOrder;
Symbol *delayLoadHelper = nullptr;
bool saveTemps = false;
// /guard:cf
GuardCFLevel guardCF = GuardCFLevel::Off;
// Used for SafeSEH.
bool safeSEH = false;
Symbol *sehTable = nullptr;
Symbol *sehCount = nullptr;
// Used for /opt:lldlto=N
unsigned ltoo = 2;
// Used for /opt:lldltojobs=N
unsigned thinLTOJobs = 0;
// Used for /opt:lldltopartitions=N
unsigned ltoPartitions = 1;
// Used for /opt:lldltocache=path
StringRef ltoCache;
// Used for /opt:lldltocachepolicy=policy
llvm::CachePruningPolicy ltoCachePolicy;
// Used for /merge:from=to (e.g. /merge:.rdata=.text)
std::map<StringRef, StringRef> merge;
// Used for /section=.name,{DEKPRSW} to set section attributes.
std::map<StringRef, uint32_t> section;
// Options for manifest files.
ManifestKind manifest = No;
int manifestID = 1;
StringRef manifestDependency;
bool manifestUAC = true;
std::vector<std::string> manifestInput;
StringRef manifestLevel = "'asInvoker'";
StringRef manifestUIAccess = "'false'";
StringRef manifestFile;
// Used for /aligncomm.
std::map<std::string, int> alignComm;
// Used for /failifmismatch.
std::map<StringRef, std::pair<StringRef, InputFile *>> mustMatch;
// Used for /alternatename.
std::map<StringRef, StringRef> alternateNames;
// Used for /order.
llvm::StringMap<int> order;
// Used for /lldmap.
std::string mapFile;
// Used for /thinlto-index-only:
llvm::StringRef thinLTOIndexOnlyArg;
// Used for /thinlto-object-prefix-replace:
std::pair<llvm::StringRef, llvm::StringRef> thinLTOPrefixReplace;
// Used for /thinlto-object-suffix-replace:
std::pair<llvm::StringRef, llvm::StringRef> thinLTOObjectSuffixReplace;
uint64_t align = 4096;
uint64_t imageBase = -1;
uint64_t fileAlign = 512;
uint64_t stackReserve = 1024 * 1024;
uint64_t stackCommit = 4096;
uint64_t heapReserve = 1024 * 1024;
uint64_t heapCommit = 4096;
uint32_t majorImageVersion = 0;
uint32_t minorImageVersion = 0;
uint32_t majorOSVersion = 6;
uint32_t minorOSVersion = 0;
uint32_t timestamp = 0;
uint32_t functionPadMin = 0;
bool dynamicBase = true;
bool allowBind = true;
bool nxCompat = true;
bool allowIsolation = true;
bool terminalServerAware = true;
bool largeAddressAware = false;
bool highEntropyVA = false;
bool appContainer = false;
bool mingw = false;
bool warnMissingOrderSymbol = true;
bool warnLocallyDefinedImported = true;
bool warnDebugInfoUnusable = true;
bool incremental = true;
bool integrityCheck = false;
bool killAt = false;
bool repro = false;
bool swaprunCD = false;
bool swaprunNet = false;
bool thinLTOEmitImportsFiles;
bool thinLTOIndexOnly;
};
extern Configuration *config;
} // namespace coff
} // namespace lld
#endif

736
deps/lld/COFF/DLL.cpp vendored
View File

@@ -1,736 +0,0 @@
//===- DLL.cpp ------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file defines various types of chunks for the DLL import or export
// descriptor tables. They are inherently Windows-specific.
// You need to read Microsoft PE/COFF spec to understand details
// about the data structures.
//
// If you are not particularly interested in linking against Windows
// DLL, you can skip this file, and you should still be able to
// understand the rest of the linker.
//
//===----------------------------------------------------------------------===//
#include "DLL.h"
#include "Chunks.h"
#include "llvm/Object/COFF.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/Path.h"
using namespace llvm;
using namespace llvm::object;
using namespace llvm::support::endian;
using namespace llvm::COFF;
namespace lld {
namespace coff {
namespace {
// Import table
// A chunk for the import descriptor table.
class HintNameChunk : public NonSectionChunk {
public:
HintNameChunk(StringRef n, uint16_t h) : name(n), hint(h) {}
size_t getSize() const override {
// Starts with 2 byte Hint field, followed by a null-terminated string,
// ends with 0 or 1 byte padding.
return alignTo(name.size() + 3, 2);
}
void writeTo(uint8_t *buf) const override {
memset(buf, 0, getSize());
write16le(buf, hint);
memcpy(buf + 2, name.data(), name.size());
}
private:
StringRef name;
uint16_t hint;
};
// A chunk for the import descriptor table.
class LookupChunk : public NonSectionChunk {
public:
explicit LookupChunk(Chunk *c) : hintName(c) {
setAlignment(config->wordsize);
}
size_t getSize() const override { return config->wordsize; }
void writeTo(uint8_t *buf) const override {
if (config->is64())
write64le(buf, hintName->getRVA());
else
write32le(buf, hintName->getRVA());
}
Chunk *hintName;
};
// A chunk for the import descriptor table.
// This chunk represent import-by-ordinal symbols.
// See Microsoft PE/COFF spec 7.1. Import Header for details.
class OrdinalOnlyChunk : public NonSectionChunk {
public:
explicit OrdinalOnlyChunk(uint16_t v) : ordinal(v) {
setAlignment(config->wordsize);
}
size_t getSize() const override { return config->wordsize; }
void writeTo(uint8_t *buf) const override {
// An import-by-ordinal slot has MSB 1 to indicate that
// this is import-by-ordinal (and not import-by-name).
if (config->is64()) {
write64le(buf, (1ULL << 63) | ordinal);
} else {
write32le(buf, (1ULL << 31) | ordinal);
}
}
uint16_t ordinal;
};
// A chunk for the import descriptor table.
class ImportDirectoryChunk : public NonSectionChunk {
public:
explicit ImportDirectoryChunk(Chunk *n) : dllName(n) {}
size_t getSize() const override { return sizeof(ImportDirectoryTableEntry); }
void writeTo(uint8_t *buf) const override {
memset(buf, 0, getSize());
auto *e = (coff_import_directory_table_entry *)(buf);
e->ImportLookupTableRVA = lookupTab->getRVA();
e->NameRVA = dllName->getRVA();
e->ImportAddressTableRVA = addressTab->getRVA();
}
Chunk *dllName;
Chunk *lookupTab;
Chunk *addressTab;
};
// A chunk representing null terminator in the import table.
// Contents of this chunk is always null bytes.
class NullChunk : public NonSectionChunk {
public:
explicit NullChunk(size_t n) : size(n) { hasData = false; }
size_t getSize() const override { return size; }
void writeTo(uint8_t *buf) const override {
memset(buf, 0, size);
}
private:
size_t size;
};
static std::vector<std::vector<DefinedImportData *>>
binImports(const std::vector<DefinedImportData *> &imports) {
// Group DLL-imported symbols by DLL name because that's how
// symbols are layed out in the import descriptor table.
auto less = [](const std::string &a, const std::string &b) {
return config->dllOrder[a] < config->dllOrder[b];
};
std::map<std::string, std::vector<DefinedImportData *>,
bool(*)(const std::string &, const std::string &)> m(less);
for (DefinedImportData *sym : imports)
m[sym->getDLLName().lower()].push_back(sym);
std::vector<std::vector<DefinedImportData *>> v;
for (auto &kv : m) {
// Sort symbols by name for each group.
std::vector<DefinedImportData *> &syms = kv.second;
std::sort(syms.begin(), syms.end(),
[](DefinedImportData *a, DefinedImportData *b) {
return a->getName() < b->getName();
});
v.push_back(std::move(syms));
}
return v;
}
// Export table
// See Microsoft PE/COFF spec 4.3 for details.
// A chunk for the delay import descriptor table etnry.
class DelayDirectoryChunk : public NonSectionChunk {
public:
explicit DelayDirectoryChunk(Chunk *n) : dllName(n) {}
size_t getSize() const override {
return sizeof(delay_import_directory_table_entry);
}
void writeTo(uint8_t *buf) const override {
memset(buf, 0, getSize());
auto *e = (delay_import_directory_table_entry *)(buf);
e->Attributes = 1;
e->Name = dllName->getRVA();
e->ModuleHandle = moduleHandle->getRVA();
e->DelayImportAddressTable = addressTab->getRVA();
e->DelayImportNameTable = nameTab->getRVA();
}
Chunk *dllName;
Chunk *moduleHandle;
Chunk *addressTab;
Chunk *nameTab;
};
// Initial contents for delay-loaded functions.
// This code calls __delayLoadHelper2 function to resolve a symbol
// and then overwrites its jump table slot with the result
// for subsequent function calls.
static const uint8_t thunkX64[] = {
0x48, 0x8D, 0x05, 0, 0, 0, 0, // lea rax, [__imp_<FUNCNAME>]
0xE9, 0, 0, 0, 0, // jmp __tailMerge_<lib>
};
static const uint8_t tailMergeX64[] = {
0x51, // push rcx
0x52, // push rdx
0x41, 0x50, // push r8
0x41, 0x51, // push r9
0x48, 0x83, 0xEC, 0x48, // sub rsp, 48h
0x66, 0x0F, 0x7F, 0x04, 0x24, // movdqa xmmword ptr [rsp], xmm0
0x66, 0x0F, 0x7F, 0x4C, 0x24, 0x10, // movdqa xmmword ptr [rsp+10h], xmm1
0x66, 0x0F, 0x7F, 0x54, 0x24, 0x20, // movdqa xmmword ptr [rsp+20h], xmm2
0x66, 0x0F, 0x7F, 0x5C, 0x24, 0x30, // movdqa xmmword ptr [rsp+30h], xmm3
0x48, 0x8B, 0xD0, // mov rdx, rax
0x48, 0x8D, 0x0D, 0, 0, 0, 0, // lea rcx, [___DELAY_IMPORT_...]
0xE8, 0, 0, 0, 0, // call __delayLoadHelper2
0x66, 0x0F, 0x6F, 0x04, 0x24, // movdqa xmm0, xmmword ptr [rsp]
0x66, 0x0F, 0x6F, 0x4C, 0x24, 0x10, // movdqa xmm1, xmmword ptr [rsp+10h]
0x66, 0x0F, 0x6F, 0x54, 0x24, 0x20, // movdqa xmm2, xmmword ptr [rsp+20h]
0x66, 0x0F, 0x6F, 0x5C, 0x24, 0x30, // movdqa xmm3, xmmword ptr [rsp+30h]
0x48, 0x83, 0xC4, 0x48, // add rsp, 48h
0x41, 0x59, // pop r9
0x41, 0x58, // pop r8
0x5A, // pop rdx
0x59, // pop rcx
0xFF, 0xE0, // jmp rax
};
static const uint8_t thunkX86[] = {
0xB8, 0, 0, 0, 0, // mov eax, offset ___imp__<FUNCNAME>
0xE9, 0, 0, 0, 0, // jmp __tailMerge_<lib>
};
static const uint8_t tailMergeX86[] = {
0x51, // push ecx
0x52, // push edx
0x50, // push eax
0x68, 0, 0, 0, 0, // push offset ___DELAY_IMPORT_DESCRIPTOR_<DLLNAME>_dll
0xE8, 0, 0, 0, 0, // call ___delayLoadHelper2@8
0x5A, // pop edx
0x59, // pop ecx
0xFF, 0xE0, // jmp eax
};
static const uint8_t thunkARM[] = {
0x40, 0xf2, 0x00, 0x0c, // mov.w ip, #0 __imp_<FUNCNAME>
0xc0, 0xf2, 0x00, 0x0c, // mov.t ip, #0 __imp_<FUNCNAME>
0x00, 0xf0, 0x00, 0xb8, // b.w __tailMerge_<lib>
};
static const uint8_t tailMergeARM[] = {
0x2d, 0xe9, 0x0f, 0x48, // push.w {r0, r1, r2, r3, r11, lr}
0x0d, 0xf2, 0x10, 0x0b, // addw r11, sp, #16
0x2d, 0xed, 0x10, 0x0b, // vpush {d0, d1, d2, d3, d4, d5, d6, d7}
0x61, 0x46, // mov r1, ip
0x40, 0xf2, 0x00, 0x00, // mov.w r0, #0 DELAY_IMPORT_DESCRIPTOR
0xc0, 0xf2, 0x00, 0x00, // mov.t r0, #0 DELAY_IMPORT_DESCRIPTOR
0x00, 0xf0, 0x00, 0xd0, // bl #0 __delayLoadHelper2
0x84, 0x46, // mov ip, r0
0xbd, 0xec, 0x10, 0x0b, // vpop {d0, d1, d2, d3, d4, d5, d6, d7}
0xbd, 0xe8, 0x0f, 0x48, // pop.w {r0, r1, r2, r3, r11, lr}
0x60, 0x47, // bx ip
};
static const uint8_t thunkARM64[] = {
0x11, 0x00, 0x00, 0x90, // adrp x17, #0 __imp_<FUNCNAME>
0x31, 0x02, 0x00, 0x91, // add x17, x17, #0 :lo12:__imp_<FUNCNAME>
0x00, 0x00, 0x00, 0x14, // b __tailMerge_<lib>
};
static const uint8_t tailMergeARM64[] = {
0xfd, 0x7b, 0xb3, 0xa9, // stp x29, x30, [sp, #-208]!
0xfd, 0x03, 0x00, 0x91, // mov x29, sp
0xe0, 0x07, 0x01, 0xa9, // stp x0, x1, [sp, #16]
0xe2, 0x0f, 0x02, 0xa9, // stp x2, x3, [sp, #32]
0xe4, 0x17, 0x03, 0xa9, // stp x4, x5, [sp, #48]
0xe6, 0x1f, 0x04, 0xa9, // stp x6, x7, [sp, #64]
0xe0, 0x87, 0x02, 0xad, // stp q0, q1, [sp, #80]
0xe2, 0x8f, 0x03, 0xad, // stp q2, q3, [sp, #112]
0xe4, 0x97, 0x04, 0xad, // stp q4, q5, [sp, #144]
0xe6, 0x9f, 0x05, 0xad, // stp q6, q7, [sp, #176]
0xe1, 0x03, 0x11, 0xaa, // mov x1, x17
0x00, 0x00, 0x00, 0x90, // adrp x0, #0 DELAY_IMPORT_DESCRIPTOR
0x00, 0x00, 0x00, 0x91, // add x0, x0, #0 :lo12:DELAY_IMPORT_DESCRIPTOR
0x00, 0x00, 0x00, 0x94, // bl #0 __delayLoadHelper2
0xf0, 0x03, 0x00, 0xaa, // mov x16, x0
0xe6, 0x9f, 0x45, 0xad, // ldp q6, q7, [sp, #176]
0xe4, 0x97, 0x44, 0xad, // ldp q4, q5, [sp, #144]
0xe2, 0x8f, 0x43, 0xad, // ldp q2, q3, [sp, #112]
0xe0, 0x87, 0x42, 0xad, // ldp q0, q1, [sp, #80]
0xe6, 0x1f, 0x44, 0xa9, // ldp x6, x7, [sp, #64]
0xe4, 0x17, 0x43, 0xa9, // ldp x4, x5, [sp, #48]
0xe2, 0x0f, 0x42, 0xa9, // ldp x2, x3, [sp, #32]
0xe0, 0x07, 0x41, 0xa9, // ldp x0, x1, [sp, #16]
0xfd, 0x7b, 0xcd, 0xa8, // ldp x29, x30, [sp], #208
0x00, 0x02, 0x1f, 0xd6, // br x16
};
// A chunk for the delay import thunk.
class ThunkChunkX64 : public NonSectionChunk {
public:
ThunkChunkX64(Defined *i, Chunk *tm) : imp(i), tailMerge(tm) {}
size_t getSize() const override { return sizeof(thunkX64); }
void writeTo(uint8_t *buf) const override {
memcpy(buf, thunkX64, sizeof(thunkX64));
write32le(buf + 3, imp->getRVA() - rva - 7);
write32le(buf + 8, tailMerge->getRVA() - rva - 12);
}
Defined *imp = nullptr;
Chunk *tailMerge = nullptr;
};
class TailMergeChunkX64 : public NonSectionChunk {
public:
TailMergeChunkX64(Chunk *d, Defined *h) : desc(d), helper(h) {}
size_t getSize() const override { return sizeof(tailMergeX64); }
void writeTo(uint8_t *buf) const override {
memcpy(buf, tailMergeX64, sizeof(tailMergeX64));
write32le(buf + 39, desc->getRVA() - rva - 43);
write32le(buf + 44, helper->getRVA() - rva - 48);
}
Chunk *desc = nullptr;
Defined *helper = nullptr;
};
class ThunkChunkX86 : public NonSectionChunk {
public:
ThunkChunkX86(Defined *i, Chunk *tm) : imp(i), tailMerge(tm) {}
size_t getSize() const override { return sizeof(thunkX86); }
void writeTo(uint8_t *buf) const override {
memcpy(buf, thunkX86, sizeof(thunkX86));
write32le(buf + 1, imp->getRVA() + config->imageBase);
write32le(buf + 6, tailMerge->getRVA() - rva - 10);
}
void getBaserels(std::vector<Baserel> *res) override {
res->emplace_back(rva + 1);
}
Defined *imp = nullptr;
Chunk *tailMerge = nullptr;
};
class TailMergeChunkX86 : public NonSectionChunk {
public:
TailMergeChunkX86(Chunk *d, Defined *h) : desc(d), helper(h) {}
size_t getSize() const override { return sizeof(tailMergeX86); }
void writeTo(uint8_t *buf) const override {
memcpy(buf, tailMergeX86, sizeof(tailMergeX86));
write32le(buf + 4, desc->getRVA() + config->imageBase);
write32le(buf + 9, helper->getRVA() - rva - 13);
}
void getBaserels(std::vector<Baserel> *res) override {
res->emplace_back(rva + 4);
}
Chunk *desc = nullptr;
Defined *helper = nullptr;
};
class ThunkChunkARM : public NonSectionChunk {
public:
ThunkChunkARM(Defined *i, Chunk *tm) : imp(i), tailMerge(tm) {}
size_t getSize() const override { return sizeof(thunkARM); }
void writeTo(uint8_t *buf) const override {
memcpy(buf, thunkARM, sizeof(thunkARM));
applyMOV32T(buf + 0, imp->getRVA() + config->imageBase);
applyBranch24T(buf + 8, tailMerge->getRVA() - rva - 12);
}
void getBaserels(std::vector<Baserel> *res) override {
res->emplace_back(rva + 0, IMAGE_REL_BASED_ARM_MOV32T);
}
Defined *imp = nullptr;
Chunk *tailMerge = nullptr;
};
class TailMergeChunkARM : public NonSectionChunk {
public:
TailMergeChunkARM(Chunk *d, Defined *h) : desc(d), helper(h) {}
size_t getSize() const override { return sizeof(tailMergeARM); }
void writeTo(uint8_t *buf) const override {
memcpy(buf, tailMergeARM, sizeof(tailMergeARM));
applyMOV32T(buf + 14, desc->getRVA() + config->imageBase);
applyBranch24T(buf + 22, helper->getRVA() - rva - 26);
}
void getBaserels(std::vector<Baserel> *res) override {
res->emplace_back(rva + 14, IMAGE_REL_BASED_ARM_MOV32T);
}
Chunk *desc = nullptr;
Defined *helper = nullptr;
};
class ThunkChunkARM64 : public NonSectionChunk {
public:
ThunkChunkARM64(Defined *i, Chunk *tm) : imp(i), tailMerge(tm) {}
size_t getSize() const override { return sizeof(thunkARM64); }
void writeTo(uint8_t *buf) const override {
memcpy(buf, thunkARM64, sizeof(thunkARM64));
applyArm64Addr(buf + 0, imp->getRVA(), rva + 0, 12);
applyArm64Imm(buf + 4, imp->getRVA() & 0xfff, 0);
applyArm64Branch26(buf + 8, tailMerge->getRVA() - rva - 8);
}
Defined *imp = nullptr;
Chunk *tailMerge = nullptr;
};
class TailMergeChunkARM64 : public NonSectionChunk {
public:
TailMergeChunkARM64(Chunk *d, Defined *h) : desc(d), helper(h) {}
size_t getSize() const override { return sizeof(tailMergeARM64); }
void writeTo(uint8_t *buf) const override {
memcpy(buf, tailMergeARM64, sizeof(tailMergeARM64));
applyArm64Addr(buf + 44, desc->getRVA(), rva + 44, 12);
applyArm64Imm(buf + 48, desc->getRVA() & 0xfff, 0);
applyArm64Branch26(buf + 52, helper->getRVA() - rva - 52);
}
Chunk *desc = nullptr;
Defined *helper = nullptr;
};
// A chunk for the import descriptor table.
class DelayAddressChunk : public NonSectionChunk {
public:
explicit DelayAddressChunk(Chunk *c) : thunk(c) {
setAlignment(config->wordsize);
}
size_t getSize() const override { return config->wordsize; }
void writeTo(uint8_t *buf) const override {
if (config->is64()) {
write64le(buf, thunk->getRVA() + config->imageBase);
} else {
uint32_t bit = 0;
// Pointer to thumb code must have the LSB set, so adjust it.
if (config->machine == ARMNT)
bit = 1;
write32le(buf, (thunk->getRVA() + config->imageBase) | bit);
}
}
void getBaserels(std::vector<Baserel> *res) override {
res->emplace_back(rva);
}
Chunk *thunk;
};
// Export table
// Read Microsoft PE/COFF spec 5.3 for details.
// A chunk for the export descriptor table.
class ExportDirectoryChunk : public NonSectionChunk {
public:
ExportDirectoryChunk(int i, int j, Chunk *d, Chunk *a, Chunk *n, Chunk *o)
: maxOrdinal(i), nameTabSize(j), dllName(d), addressTab(a), nameTab(n),
ordinalTab(o) {}
size_t getSize() const override {
return sizeof(export_directory_table_entry);
}
void writeTo(uint8_t *buf) const override {
memset(buf, 0, getSize());
auto *e = (export_directory_table_entry *)(buf);
e->NameRVA = dllName->getRVA();
e->OrdinalBase = 0;
e->AddressTableEntries = maxOrdinal + 1;
e->NumberOfNamePointers = nameTabSize;
e->ExportAddressTableRVA = addressTab->getRVA();
e->NamePointerRVA = nameTab->getRVA();
e->OrdinalTableRVA = ordinalTab->getRVA();
}
uint16_t maxOrdinal;
uint16_t nameTabSize;
Chunk *dllName;
Chunk *addressTab;
Chunk *nameTab;
Chunk *ordinalTab;
};
class AddressTableChunk : public NonSectionChunk {
public:
explicit AddressTableChunk(size_t maxOrdinal) : size(maxOrdinal + 1) {}
size_t getSize() const override { return size * 4; }
void writeTo(uint8_t *buf) const override {
memset(buf, 0, getSize());
for (const Export &e : config->exports) {
uint8_t *p = buf + e.ordinal * 4;
uint32_t bit = 0;
// Pointer to thumb code must have the LSB set, so adjust it.
if (config->machine == ARMNT && !e.data)
bit = 1;
if (e.forwardChunk) {
write32le(p, e.forwardChunk->getRVA() | bit);
} else {
write32le(p, cast<Defined>(e.sym)->getRVA() | bit);
}
}
}
private:
size_t size;
};
class NamePointersChunk : public NonSectionChunk {
public:
explicit NamePointersChunk(std::vector<Chunk *> &v) : chunks(v) {}
size_t getSize() const override { return chunks.size() * 4; }
void writeTo(uint8_t *buf) const override {
for (Chunk *c : chunks) {
write32le(buf, c->getRVA());
buf += 4;
}
}
private:
std::vector<Chunk *> chunks;
};
class ExportOrdinalChunk : public NonSectionChunk {
public:
explicit ExportOrdinalChunk(size_t i) : size(i) {}
size_t getSize() const override { return size * 2; }
void writeTo(uint8_t *buf) const override {
for (Export &e : config->exports) {
if (e.noname)
continue;
write16le(buf, e.ordinal);
buf += 2;
}
}
private:
size_t size;
};
} // anonymous namespace
void IdataContents::create() {
std::vector<std::vector<DefinedImportData *>> v = binImports(imports);
// Create .idata contents for each DLL.
for (std::vector<DefinedImportData *> &syms : v) {
// Create lookup and address tables. If they have external names,
// we need to create hintName chunks to store the names.
// If they don't (if they are import-by-ordinals), we store only
// ordinal values to the table.
size_t base = lookups.size();
for (DefinedImportData *s : syms) {
uint16_t ord = s->getOrdinal();
if (s->getExternalName().empty()) {
lookups.push_back(make<OrdinalOnlyChunk>(ord));
addresses.push_back(make<OrdinalOnlyChunk>(ord));
continue;
}
auto *c = make<HintNameChunk>(s->getExternalName(), ord);
lookups.push_back(make<LookupChunk>(c));
addresses.push_back(make<LookupChunk>(c));
hints.push_back(c);
}
// Terminate with null values.
lookups.push_back(make<NullChunk>(config->wordsize));
addresses.push_back(make<NullChunk>(config->wordsize));
for (int i = 0, e = syms.size(); i < e; ++i)
syms[i]->setLocation(addresses[base + i]);
// Create the import table header.
dllNames.push_back(make<StringChunk>(syms[0]->getDLLName()));
auto *dir = make<ImportDirectoryChunk>(dllNames.back());
dir->lookupTab = lookups[base];
dir->addressTab = addresses[base];
dirs.push_back(dir);
}
// Add null terminator.
dirs.push_back(make<NullChunk>(sizeof(ImportDirectoryTableEntry)));
}
std::vector<Chunk *> DelayLoadContents::getChunks() {
std::vector<Chunk *> v;
v.insert(v.end(), dirs.begin(), dirs.end());
v.insert(v.end(), names.begin(), names.end());
v.insert(v.end(), hintNames.begin(), hintNames.end());
v.insert(v.end(), dllNames.begin(), dllNames.end());
return v;
}
std::vector<Chunk *> DelayLoadContents::getDataChunks() {
std::vector<Chunk *> v;
v.insert(v.end(), moduleHandles.begin(), moduleHandles.end());
v.insert(v.end(), addresses.begin(), addresses.end());
return v;
}
uint64_t DelayLoadContents::getDirSize() {
return dirs.size() * sizeof(delay_import_directory_table_entry);
}
void DelayLoadContents::create(Defined *h) {
helper = h;
std::vector<std::vector<DefinedImportData *>> v = binImports(imports);
// Create .didat contents for each DLL.
for (std::vector<DefinedImportData *> &syms : v) {
// Create the delay import table header.
dllNames.push_back(make<StringChunk>(syms[0]->getDLLName()));
auto *dir = make<DelayDirectoryChunk>(dllNames.back());
size_t base = addresses.size();
Chunk *tm = newTailMergeChunk(dir);
for (DefinedImportData *s : syms) {
Chunk *t = newThunkChunk(s, tm);
auto *a = make<DelayAddressChunk>(t);
addresses.push_back(a);
thunks.push_back(t);
StringRef extName = s->getExternalName();
if (extName.empty()) {
names.push_back(make<OrdinalOnlyChunk>(s->getOrdinal()));
} else {
auto *c = make<HintNameChunk>(extName, 0);
names.push_back(make<LookupChunk>(c));
hintNames.push_back(c);
}
}
thunks.push_back(tm);
// Terminate with null values.
addresses.push_back(make<NullChunk>(8));
names.push_back(make<NullChunk>(8));
for (int i = 0, e = syms.size(); i < e; ++i)
syms[i]->setLocation(addresses[base + i]);
auto *mh = make<NullChunk>(8);
mh->setAlignment(8);
moduleHandles.push_back(mh);
// Fill the delay import table header fields.
dir->moduleHandle = mh;
dir->addressTab = addresses[base];
dir->nameTab = names[base];
dirs.push_back(dir);
}
// Add null terminator.
dirs.push_back(make<NullChunk>(sizeof(delay_import_directory_table_entry)));
}
Chunk *DelayLoadContents::newTailMergeChunk(Chunk *dir) {
switch (config->machine) {
case AMD64:
return make<TailMergeChunkX64>(dir, helper);
case I386:
return make<TailMergeChunkX86>(dir, helper);
case ARMNT:
return make<TailMergeChunkARM>(dir, helper);
case ARM64:
return make<TailMergeChunkARM64>(dir, helper);
default:
llvm_unreachable("unsupported machine type");
}
}
Chunk *DelayLoadContents::newThunkChunk(DefinedImportData *s,
Chunk *tailMerge) {
switch (config->machine) {
case AMD64:
return make<ThunkChunkX64>(s, tailMerge);
case I386:
return make<ThunkChunkX86>(s, tailMerge);
case ARMNT:
return make<ThunkChunkARM>(s, tailMerge);
case ARM64:
return make<ThunkChunkARM64>(s, tailMerge);
default:
llvm_unreachable("unsupported machine type");
}
}
EdataContents::EdataContents() {
uint16_t maxOrdinal = 0;
for (Export &e : config->exports)
maxOrdinal = std::max(maxOrdinal, e.ordinal);
auto *dllName = make<StringChunk>(sys::path::filename(config->outputFile));
auto *addressTab = make<AddressTableChunk>(maxOrdinal);
std::vector<Chunk *> names;
for (Export &e : config->exports)
if (!e.noname)
names.push_back(make<StringChunk>(e.exportName));
std::vector<Chunk *> forwards;
for (Export &e : config->exports) {
if (e.forwardTo.empty())
continue;
e.forwardChunk = make<StringChunk>(e.forwardTo);
forwards.push_back(e.forwardChunk);
}
auto *nameTab = make<NamePointersChunk>(names);
auto *ordinalTab = make<ExportOrdinalChunk>(names.size());
auto *dir = make<ExportDirectoryChunk>(maxOrdinal, names.size(), dllName,
addressTab, nameTab, ordinalTab);
chunks.push_back(dir);
chunks.push_back(dllName);
chunks.push_back(addressTab);
chunks.push_back(nameTab);
chunks.push_back(ordinalTab);
chunks.insert(chunks.end(), names.begin(), names.end());
chunks.insert(chunks.end(), forwards.begin(), forwards.end());
}
} // namespace coff
} // namespace lld

82
deps/lld/COFF/DLL.h vendored
View File

@@ -1,82 +0,0 @@
//===- DLL.h ----------------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLD_COFF_DLL_H
#define LLD_COFF_DLL_H
#include "Chunks.h"
#include "Symbols.h"
namespace lld {
namespace coff {
// Windows-specific.
// IdataContents creates all chunks for the DLL import table.
// You are supposed to call add() to add symbols and then
// call create() to populate the chunk vectors.
class IdataContents {
public:
void add(DefinedImportData *sym) { imports.push_back(sym); }
bool empty() { return imports.empty(); }
void create();
std::vector<DefinedImportData *> imports;
std::vector<Chunk *> dirs;
std::vector<Chunk *> lookups;
std::vector<Chunk *> addresses;
std::vector<Chunk *> hints;
std::vector<Chunk *> dllNames;
};
// Windows-specific.
// DelayLoadContents creates all chunks for the delay-load DLL import table.
class DelayLoadContents {
public:
void add(DefinedImportData *sym) { imports.push_back(sym); }
bool empty() { return imports.empty(); }
void create(Defined *helper);
std::vector<Chunk *> getChunks();
std::vector<Chunk *> getDataChunks();
ArrayRef<Chunk *> getCodeChunks() { return thunks; }
uint64_t getDirRVA() { return dirs[0]->getRVA(); }
uint64_t getDirSize();
private:
Chunk *newThunkChunk(DefinedImportData *s, Chunk *tailMerge);
Chunk *newTailMergeChunk(Chunk *dir);
Defined *helper;
std::vector<DefinedImportData *> imports;
std::vector<Chunk *> dirs;
std::vector<Chunk *> moduleHandles;
std::vector<Chunk *> addresses;
std::vector<Chunk *> names;
std::vector<Chunk *> hintNames;
std::vector<Chunk *> thunks;
std::vector<Chunk *> dllNames;
};
// Windows-specific.
// EdataContents creates all chunks for the DLL export table.
class EdataContents {
public:
EdataContents();
std::vector<Chunk *> chunks;
uint64_t getRVA() { return chunks[0]->getRVA(); }
uint64_t getSize() {
return chunks.back()->getRVA() + chunks.back()->getSize() - getRVA();
}
};
} // namespace coff
} // namespace lld
#endif

View File

@@ -1,268 +0,0 @@
//===- DebugTypes.cpp -----------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "DebugTypes.h"
#include "Driver.h"
#include "InputFiles.h"
#include "lld/Common/ErrorHandler.h"
#include "llvm/DebugInfo/CodeView/TypeRecord.h"
#include "llvm/DebugInfo/PDB/GenericError.h"
#include "llvm/DebugInfo/PDB/Native/InfoStream.h"
#include "llvm/DebugInfo/PDB/Native/NativeSession.h"
#include "llvm/DebugInfo/PDB/Native/PDBFile.h"
#include "llvm/Support/Path.h"
using namespace lld;
using namespace lld::coff;
using namespace llvm;
using namespace llvm::codeview;
namespace {
// The TypeServerSource class represents a PDB type server, a file referenced by
// OBJ files compiled with MSVC /Zi. A single PDB can be shared by several OBJ
// files, therefore there must be only once instance per OBJ lot. The file path
// is discovered from the dependent OBJ's debug type stream. The
// TypeServerSource object is then queued and loaded by the COFF Driver. The
// debug type stream for such PDB files will be merged first in the final PDB,
// before any dependent OBJ.
class TypeServerSource : public TpiSource {
public:
explicit TypeServerSource(MemoryBufferRef m, llvm::pdb::NativeSession *s)
: TpiSource(PDB, nullptr), session(s), mb(m) {}
// Queue a PDB type server for loading in the COFF Driver
static void enqueue(const ObjFile *dependentFile,
const TypeServer2Record &ts);
// Create an instance
static Expected<TypeServerSource *> getInstance(MemoryBufferRef m);
// Fetch the PDB instance loaded for a corresponding dependent OBJ.
static Expected<TypeServerSource *>
findFromFile(const ObjFile *dependentFile);
static std::map<std::string, std::pair<std::string, TypeServerSource *>>
instances;
// The interface to the PDB (if it was opened successfully)
std::unique_ptr<llvm::pdb::NativeSession> session;
private:
MemoryBufferRef mb;
};
// This class represents the debug type stream of an OBJ file that depends on a
// PDB type server (see TypeServerSource).
class UseTypeServerSource : public TpiSource {
public:
UseTypeServerSource(const ObjFile *f, const TypeServer2Record *ts)
: TpiSource(UsingPDB, f), typeServerDependency(*ts) {}
// Information about the PDB type server dependency, that needs to be loaded
// in before merging this OBJ.
TypeServer2Record typeServerDependency;
};
// This class represents the debug type stream of a Microsoft precompiled
// headers OBJ (PCH OBJ). This OBJ kind needs to be merged first in the output
// PDB, before any other OBJs that depend on this. Note that only MSVC generate
// such files, clang does not.
class PrecompSource : public TpiSource {
public:
PrecompSource(const ObjFile *f) : TpiSource(PCH, f) {}
};
// This class represents the debug type stream of an OBJ file that depends on a
// Microsoft precompiled headers OBJ (see PrecompSource).
class UsePrecompSource : public TpiSource {
public:
UsePrecompSource(const ObjFile *f, const PrecompRecord *precomp)
: TpiSource(UsingPCH, f), precompDependency(*precomp) {}
// Information about the Precomp OBJ dependency, that needs to be loaded in
// before merging this OBJ.
PrecompRecord precompDependency;
};
} // namespace
static std::vector<std::unique_ptr<TpiSource>> GC;
TpiSource::TpiSource(TpiKind k, const ObjFile *f) : kind(k), file(f) {
GC.push_back(std::unique_ptr<TpiSource>(this));
}
TpiSource *lld::coff::makeTpiSource(const ObjFile *f) {
return new TpiSource(TpiSource::Regular, f);
}
TpiSource *lld::coff::makeUseTypeServerSource(const ObjFile *f,
const TypeServer2Record *ts) {
TypeServerSource::enqueue(f, *ts);
return new UseTypeServerSource(f, ts);
}
TpiSource *lld::coff::makePrecompSource(const ObjFile *f) {
return new PrecompSource(f);
}
TpiSource *lld::coff::makeUsePrecompSource(const ObjFile *f,
const PrecompRecord *precomp) {
return new UsePrecompSource(f, precomp);
}
namespace lld {
namespace coff {
template <>
const PrecompRecord &retrieveDependencyInfo(const TpiSource *source) {
assert(source->kind == TpiSource::UsingPCH);
return ((const UsePrecompSource *)source)->precompDependency;
}
template <>
const TypeServer2Record &retrieveDependencyInfo(const TpiSource *source) {
assert(source->kind == TpiSource::UsingPDB);
return ((const UseTypeServerSource *)source)->typeServerDependency;
}
} // namespace coff
} // namespace lld
std::map<std::string, std::pair<std::string, TypeServerSource *>>
TypeServerSource::instances;
// Make a PDB path assuming the PDB is in the same folder as the OBJ
static std::string getPdbBaseName(const ObjFile *file, StringRef tSPath) {
StringRef localPath =
!file->parentName.empty() ? file->parentName : file->getName();
SmallString<128> path = sys::path::parent_path(localPath);
// Currently, type server PDBs are only created by MSVC cl, which only runs
// on Windows, so we can assume type server paths are Windows style.
sys::path::append(path, sys::path::filename(tSPath, sys::path::Style::windows));
return path.str();
}
// The casing of the PDB path stamped in the OBJ can differ from the actual path
// on disk. With this, we ensure to always use lowercase as a key for the
// PDBInputFile::Instances map, at least on Windows.
static std::string normalizePdbPath(StringRef path) {
#if defined(_WIN32)
return path.lower();
#else // LINUX
return path;
#endif
}
// If existing, return the actual PDB path on disk.
static Optional<std::string> findPdbPath(StringRef pdbPath,
const ObjFile *dependentFile) {
// Ensure the file exists before anything else. In some cases, if the path
// points to a removable device, Driver::enqueuePath() would fail with an
// error (EAGAIN, "resource unavailable try again") which we want to skip
// silently.
if (llvm::sys::fs::exists(pdbPath))
return normalizePdbPath(pdbPath);
std::string ret = getPdbBaseName(dependentFile, pdbPath);
if (llvm::sys::fs::exists(ret))
return normalizePdbPath(ret);
return None;
}
// Fetch the PDB instance that was already loaded by the COFF Driver.
Expected<TypeServerSource *>
TypeServerSource::findFromFile(const ObjFile *dependentFile) {
const TypeServer2Record &ts =
retrieveDependencyInfo<TypeServer2Record>(dependentFile->debugTypesObj);
Optional<std::string> p = findPdbPath(ts.Name, dependentFile);
if (!p)
return createFileError(ts.Name, errorCodeToError(std::error_code(
ENOENT, std::generic_category())));
auto it = TypeServerSource::instances.find(*p);
// The PDB file exists on disk, at this point we expect it to have been
// inserted in the map by TypeServerSource::loadPDB()
assert(it != TypeServerSource::instances.end());
std::pair<std::string, TypeServerSource *> &pdb = it->second;
if (!pdb.second)
return createFileError(
*p, createStringError(inconvertibleErrorCode(), pdb.first.c_str()));
pdb::PDBFile &pdbFile = (pdb.second)->session->getPDBFile();
pdb::InfoStream &info = cantFail(pdbFile.getPDBInfoStream());
// Just because a file with a matching name was found doesn't mean it can be
// used. The GUID must match between the PDB header and the OBJ
// TypeServer2 record. The 'Age' is used by MSVC incremental compilation.
if (info.getGuid() != ts.getGuid())
return createFileError(
ts.Name,
make_error<pdb::PDBError>(pdb::pdb_error_code::signature_out_of_date));
return pdb.second;
}
// FIXME: Temporary interface until PDBLinker::maybeMergeTypeServerPDB() is
// moved here.
Expected<llvm::pdb::NativeSession *>
lld::coff::findTypeServerSource(const ObjFile *f) {
Expected<TypeServerSource *> ts = TypeServerSource::findFromFile(f);
if (!ts)
return ts.takeError();
return ts.get()->session.get();
}
// Queue a PDB type server for loading in the COFF Driver
void TypeServerSource::enqueue(const ObjFile *dependentFile,
const TypeServer2Record &ts) {
// Start by finding where the PDB is located (either the record path or next
// to the OBJ file)
Optional<std::string> p = findPdbPath(ts.Name, dependentFile);
if (!p)
return;
auto it = TypeServerSource::instances.emplace(
*p, std::pair<std::string, TypeServerSource *>{});
if (!it.second)
return; // another OBJ already scheduled this PDB for load
driver->enqueuePath(*p, false);
}
// Create an instance of TypeServerSource or an error string if the PDB couldn't
// be loaded. The error message will be displayed later, when the referring OBJ
// will be merged in. NOTE - a PDB load failure is not a link error: some
// debug info will simply be missing from the final PDB - that is the default
// accepted behavior.
void lld::coff::loadTypeServerSource(llvm::MemoryBufferRef m) {
std::string path = normalizePdbPath(m.getBufferIdentifier());
Expected<TypeServerSource *> ts = TypeServerSource::getInstance(m);
if (!ts)
TypeServerSource::instances[path] = {toString(ts.takeError()), nullptr};
else
TypeServerSource::instances[path] = {{}, *ts};
}
Expected<TypeServerSource *> TypeServerSource::getInstance(MemoryBufferRef m) {
std::unique_ptr<llvm::pdb::IPDBSession> iSession;
Error err = pdb::NativeSession::createFromPdb(
MemoryBuffer::getMemBuffer(m, false), iSession);
if (err)
return std::move(err);
std::unique_ptr<llvm::pdb::NativeSession> session(
static_cast<pdb::NativeSession *>(iSession.release()));
pdb::PDBFile &pdbFile = session->getPDBFile();
Expected<pdb::InfoStream &> info = pdbFile.getPDBInfoStream();
// All PDB Files should have an Info stream.
if (!info)
return info.takeError();
return new TypeServerSource(m, session.release());
}

View File

@@ -1,60 +0,0 @@
//===- DebugTypes.h ---------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLD_COFF_DEBUGTYPES_H
#define LLD_COFF_DEBUGTYPES_H
#include "llvm/Support/Error.h"
#include "llvm/Support/MemoryBuffer.h"
namespace llvm {
namespace codeview {
class PrecompRecord;
class TypeServer2Record;
} // namespace codeview
namespace pdb {
class NativeSession;
}
} // namespace llvm
namespace lld {
namespace coff {
class ObjFile;
class TpiSource {
public:
enum TpiKind { Regular, PCH, UsingPCH, PDB, UsingPDB };
TpiSource(TpiKind k, const ObjFile *f);
virtual ~TpiSource() {}
const TpiKind kind;
const ObjFile *file;
};
TpiSource *makeTpiSource(const ObjFile *f);
TpiSource *makeUseTypeServerSource(const ObjFile *f,
const llvm::codeview::TypeServer2Record *ts);
TpiSource *makePrecompSource(const ObjFile *f);
TpiSource *makeUsePrecompSource(const ObjFile *f,
const llvm::codeview::PrecompRecord *precomp);
void loadTypeServerSource(llvm::MemoryBufferRef m);
// Temporary interface to get the dependency
template <typename T> const T &retrieveDependencyInfo(const TpiSource *source);
// Temporary interface until we move PDBLinker::maybeMergeTypeServerPDB here
llvm::Expected<llvm::pdb::NativeSession *>
findTypeServerSource(const ObjFile *f);
} // namespace coff
} // namespace lld
#endif

1917
deps/lld/COFF/Driver.cpp vendored

File diff suppressed because it is too large Load Diff

202
deps/lld/COFF/Driver.h vendored
View File

@@ -1,202 +0,0 @@
//===- Driver.h -------------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLD_COFF_DRIVER_H
#define LLD_COFF_DRIVER_H
#include "Config.h"
#include "SymbolTable.h"
#include "lld/Common/LLVM.h"
#include "lld/Common/Reproduce.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Object/Archive.h"
#include "llvm/Object/COFF.h"
#include "llvm/Option/Arg.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/TarWriter.h"
#include <memory>
#include <set>
#include <vector>
namespace lld {
namespace coff {
class LinkerDriver;
extern LinkerDriver *driver;
using llvm::COFF::MachineTypes;
using llvm::COFF::WindowsSubsystem;
using llvm::Optional;
class COFFOptTable : public llvm::opt::OptTable {
public:
COFFOptTable();
};
class ArgParser {
public:
// Concatenate LINK environment variable and given arguments and parse them.
llvm::opt::InputArgList parseLINK(std::vector<const char *> args);
// Tokenizes a given string and then parses as command line options.
llvm::opt::InputArgList parse(StringRef s) { return parse(tokenize(s)); }
// Tokenizes a given string and then parses as command line options in
// .drectve section. /EXPORT options are returned in second element
// to be processed in fastpath.
std::pair<llvm::opt::InputArgList, std::vector<StringRef>>
parseDirectives(StringRef s);
private:
// Parses command line options.
llvm::opt::InputArgList parse(llvm::ArrayRef<const char *> args);
std::vector<const char *> tokenize(StringRef s);
COFFOptTable table;
};
class LinkerDriver {
public:
void link(llvm::ArrayRef<const char *> args);
// Used by the resolver to parse .drectve section contents.
void parseDirectives(InputFile *file);
// Used by ArchiveFile to enqueue members.
void enqueueArchiveMember(const Archive::Child &c, const Archive::Symbol &sym,
StringRef parentName);
MemoryBufferRef takeBuffer(std::unique_ptr<MemoryBuffer> mb);
void enqueuePath(StringRef path, bool wholeArchive);
private:
std::unique_ptr<llvm::TarWriter> tar; // for /linkrepro
// Opens a file. Path has to be resolved already.
MemoryBufferRef openFile(StringRef path);
// Searches a file from search paths.
Optional<StringRef> findFile(StringRef filename);
Optional<StringRef> findLib(StringRef filename);
StringRef doFindFile(StringRef filename);
StringRef doFindLib(StringRef filename);
StringRef doFindLibMinGW(StringRef filename);
// Parses LIB environment which contains a list of search paths.
void addLibSearchPaths();
// Library search path. The first element is always "" (current directory).
std::vector<StringRef> searchPaths;
void maybeExportMinGWSymbols(const llvm::opt::InputArgList &args);
// We don't want to add the same file more than once.
// Files are uniquified by their filesystem and file number.
std::set<llvm::sys::fs::UniqueID> visitedFiles;
std::set<std::string> visitedLibs;
Symbol *addUndefined(StringRef sym);
StringRef mangleMaybe(Symbol *s);
// Windows specific -- "main" is not the only main function in Windows.
// You can choose one from these four -- {w,}{WinMain,main}.
// There are four different entry point functions for them,
// {w,}{WinMain,main}CRTStartup, respectively. The linker needs to
// choose the right one depending on which "main" function is defined.
// This function looks up the symbol table and resolve corresponding
// entry point name.
StringRef findDefaultEntry();
WindowsSubsystem inferSubsystem();
void addBuffer(std::unique_ptr<MemoryBuffer> mb, bool wholeArchive);
void addArchiveBuffer(MemoryBufferRef mbref, StringRef symName,
StringRef parentName, uint64_t offsetInArchive);
void enqueueTask(std::function<void()> task);
bool run();
std::list<std::function<void()>> taskQueue;
std::vector<StringRef> filePaths;
std::vector<MemoryBufferRef> resources;
llvm::StringSet<> directivesExports;
};
// Functions below this line are defined in DriverUtils.cpp.
void printHelp(const char *argv0);
// Parses a string in the form of "<integer>[,<integer>]".
void parseNumbers(StringRef arg, uint64_t *addr, uint64_t *size = nullptr);
void parseGuard(StringRef arg);
// Parses a string in the form of "<integer>[.<integer>]".
// Minor's default value is 0.
void parseVersion(StringRef arg, uint32_t *major, uint32_t *minor);
// Parses a string in the form of "<subsystem>[,<integer>[.<integer>]]".
void parseSubsystem(StringRef arg, WindowsSubsystem *sys, uint32_t *major,
uint32_t *minor);
void parseAlternateName(StringRef);
void parseMerge(StringRef);
void parseSection(StringRef);
void parseAligncomm(StringRef);
// Parses a string in the form of "[:<integer>]"
void parseFunctionPadMin(llvm::opt::Arg *a, llvm::COFF::MachineTypes machine);
// Parses a string in the form of "EMBED[,=<integer>]|NO".
void parseManifest(StringRef arg);
// Parses a string in the form of "level=<string>|uiAccess=<string>"
void parseManifestUAC(StringRef arg);
// Parses a string in the form of "cd|net[,(cd|net)]*"
void parseSwaprun(StringRef arg);
// Create a resource file containing a manifest XML.
std::unique_ptr<MemoryBuffer> createManifestRes();
void createSideBySideManifest();
// Used for dllexported symbols.
Export parseExport(StringRef arg);
void fixupExports();
void assignExportOrdinals();
// Parses a string in the form of "key=value" and check
// if value matches previous values for the key.
// This feature used in the directive section to reject
// incompatible objects.
void checkFailIfMismatch(StringRef arg, InputFile *source);
// Convert Windows resource files (.res files) to a .obj file.
MemoryBufferRef convertResToCOFF(ArrayRef<MemoryBufferRef> mbs);
void runMSVCLinker(std::string rsp, ArrayRef<StringRef> objects);
// Create enum with OPT_xxx values for each option in Options.td
enum {
OPT_INVALID = 0,
#define OPTION(_1, _2, ID, _4, _5, _6, _7, _8, _9, _10, _11, _12) OPT_##ID,
#include "Options.inc"
#undef OPTION
};
} // namespace coff
} // namespace lld
#endif

View File

@@ -1,897 +0,0 @@
//===- DriverUtils.cpp ----------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file contains utility functions for the driver. Because there
// are so many small functions, we created this separate file to make
// Driver.cpp less cluttered.
//
//===----------------------------------------------------------------------===//
#include "Config.h"
#include "Driver.h"
#include "Symbols.h"
#include "lld/Common/ErrorHandler.h"
#include "lld/Common/Memory.h"
#include "llvm/ADT/Optional.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/BinaryFormat/COFF.h"
#include "llvm/Object/COFF.h"
#include "llvm/Object/WindowsResource.h"
#include "llvm/Option/Arg.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Option/Option.h"
#include "llvm/Support/CommandLine.h"
#include "llvm/Support/FileUtilities.h"
#include "llvm/Support/MathExtras.h"
#include "llvm/Support/Process.h"
#include "llvm/Support/Program.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/WindowsManifest/WindowsManifestMerger.h"
#include <memory>
using namespace llvm::COFF;
using namespace llvm;
using llvm::sys::Process;
namespace lld {
namespace coff {
namespace {
const uint16_t SUBLANG_ENGLISH_US = 0x0409;
const uint16_t RT_MANIFEST = 24;
class Executor {
public:
explicit Executor(StringRef s) : prog(saver.save(s)) {}
void add(StringRef s) { args.push_back(saver.save(s)); }
void add(std::string &s) { args.push_back(saver.save(s)); }
void add(Twine s) { args.push_back(saver.save(s)); }
void add(const char *s) { args.push_back(saver.save(s)); }
void run() {
ErrorOr<std::string> exeOrErr = sys::findProgramByName(prog);
if (auto ec = exeOrErr.getError())
fatal("unable to find " + prog + " in PATH: " + ec.message());
StringRef exe = saver.save(*exeOrErr);
args.insert(args.begin(), exe);
if (sys::ExecuteAndWait(args[0], args) != 0)
fatal("ExecuteAndWait failed: " +
llvm::join(args.begin(), args.end(), " "));
}
private:
StringRef prog;
std::vector<StringRef> args;
};
} // anonymous namespace
// Parses a string in the form of "<integer>[,<integer>]".
void parseNumbers(StringRef arg, uint64_t *addr, uint64_t *size) {
StringRef s1, s2;
std::tie(s1, s2) = arg.split(',');
if (s1.getAsInteger(0, *addr))
fatal("invalid number: " + s1);
if (size && !s2.empty() && s2.getAsInteger(0, *size))
fatal("invalid number: " + s2);
}
// Parses a string in the form of "<integer>[.<integer>]".
// If second number is not present, Minor is set to 0.
void parseVersion(StringRef arg, uint32_t *major, uint32_t *minor) {
StringRef s1, s2;
std::tie(s1, s2) = arg.split('.');
if (s1.getAsInteger(0, *major))
fatal("invalid number: " + s1);
*minor = 0;
if (!s2.empty() && s2.getAsInteger(0, *minor))
fatal("invalid number: " + s2);
}
void parseGuard(StringRef fullArg) {
SmallVector<StringRef, 1> splitArgs;
fullArg.split(splitArgs, ",");
for (StringRef arg : splitArgs) {
if (arg.equals_lower("no"))
config->guardCF = GuardCFLevel::Off;
else if (arg.equals_lower("nolongjmp"))
config->guardCF = GuardCFLevel::NoLongJmp;
else if (arg.equals_lower("cf") || arg.equals_lower("longjmp"))
config->guardCF = GuardCFLevel::Full;
else
fatal("invalid argument to /guard: " + arg);
}
}
// Parses a string in the form of "<subsystem>[,<integer>[.<integer>]]".
void parseSubsystem(StringRef arg, WindowsSubsystem *sys, uint32_t *major,
uint32_t *minor) {
StringRef sysStr, ver;
std::tie(sysStr, ver) = arg.split(',');
std::string sysStrLower = sysStr.lower();
*sys = StringSwitch<WindowsSubsystem>(sysStrLower)
.Case("boot_application", IMAGE_SUBSYSTEM_WINDOWS_BOOT_APPLICATION)
.Case("console", IMAGE_SUBSYSTEM_WINDOWS_CUI)
.Case("default", IMAGE_SUBSYSTEM_UNKNOWN)
.Case("efi_application", IMAGE_SUBSYSTEM_EFI_APPLICATION)
.Case("efi_boot_service_driver", IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER)
.Case("efi_rom", IMAGE_SUBSYSTEM_EFI_ROM)
.Case("efi_runtime_driver", IMAGE_SUBSYSTEM_EFI_RUNTIME_DRIVER)
.Case("native", IMAGE_SUBSYSTEM_NATIVE)
.Case("posix", IMAGE_SUBSYSTEM_POSIX_CUI)
.Case("windows", IMAGE_SUBSYSTEM_WINDOWS_GUI)
.Default(IMAGE_SUBSYSTEM_UNKNOWN);
if (*sys == IMAGE_SUBSYSTEM_UNKNOWN && sysStrLower != "default")
fatal("unknown subsystem: " + sysStr);
if (!ver.empty())
parseVersion(ver, major, minor);
}
// Parse a string of the form of "<from>=<to>".
// Results are directly written to Config.
void parseAlternateName(StringRef s) {
StringRef from, to;
std::tie(from, to) = s.split('=');
if (from.empty() || to.empty())
fatal("/alternatename: invalid argument: " + s);
auto it = config->alternateNames.find(from);
if (it != config->alternateNames.end() && it->second != to)
fatal("/alternatename: conflicts: " + s);
config->alternateNames.insert(it, std::make_pair(from, to));
}
// Parse a string of the form of "<from>=<to>".
// Results are directly written to Config.
void parseMerge(StringRef s) {
StringRef from, to;
std::tie(from, to) = s.split('=');
if (from.empty() || to.empty())
fatal("/merge: invalid argument: " + s);
if (from == ".rsrc" || to == ".rsrc")
fatal("/merge: cannot merge '.rsrc' with any section");
if (from == ".reloc" || to == ".reloc")
fatal("/merge: cannot merge '.reloc' with any section");
auto pair = config->merge.insert(std::make_pair(from, to));
bool inserted = pair.second;
if (!inserted) {
StringRef existing = pair.first->second;
if (existing != to)
warn(s + ": already merged into " + existing);
}
}
static uint32_t parseSectionAttributes(StringRef s) {
uint32_t ret = 0;
for (char c : s.lower()) {
switch (c) {
case 'd':
ret |= IMAGE_SCN_MEM_DISCARDABLE;
break;
case 'e':
ret |= IMAGE_SCN_MEM_EXECUTE;
break;
case 'k':
ret |= IMAGE_SCN_MEM_NOT_CACHED;
break;
case 'p':
ret |= IMAGE_SCN_MEM_NOT_PAGED;
break;
case 'r':
ret |= IMAGE_SCN_MEM_READ;
break;
case 's':
ret |= IMAGE_SCN_MEM_SHARED;
break;
case 'w':
ret |= IMAGE_SCN_MEM_WRITE;
break;
default:
fatal("/section: invalid argument: " + s);
}
}
return ret;
}
// Parses /section option argument.
void parseSection(StringRef s) {
StringRef name, attrs;
std::tie(name, attrs) = s.split(',');
if (name.empty() || attrs.empty())
fatal("/section: invalid argument: " + s);
config->section[name] = parseSectionAttributes(attrs);
}
// Parses /aligncomm option argument.
void parseAligncomm(StringRef s) {
StringRef name, align;
std::tie(name, align) = s.split(',');
if (name.empty() || align.empty()) {
error("/aligncomm: invalid argument: " + s);
return;
}
int v;
if (align.getAsInteger(0, v)) {
error("/aligncomm: invalid argument: " + s);
return;
}
config->alignComm[name] = std::max(config->alignComm[name], 1 << v);
}
// Parses /functionpadmin option argument.
void parseFunctionPadMin(llvm::opt::Arg *a, llvm::COFF::MachineTypes machine) {
StringRef arg = a->getNumValues() ? a->getValue() : "";
if (!arg.empty()) {
// Optional padding in bytes is given.
if (arg.getAsInteger(0, config->functionPadMin))
error("/functionpadmin: invalid argument: " + arg);
return;
}
// No optional argument given.
// Set default padding based on machine, similar to link.exe.
// There is no default padding for ARM platforms.
if (machine == I386) {
config->functionPadMin = 5;
} else if (machine == AMD64) {
config->functionPadMin = 6;
} else {
error("/functionpadmin: invalid argument for this machine: " + arg);
}
}
// Parses a string in the form of "EMBED[,=<integer>]|NO".
// Results are directly written to Config.
void parseManifest(StringRef arg) {
if (arg.equals_lower("no")) {
config->manifest = Configuration::No;
return;
}
if (!arg.startswith_lower("embed"))
fatal("invalid option " + arg);
config->manifest = Configuration::Embed;
arg = arg.substr(strlen("embed"));
if (arg.empty())
return;
if (!arg.startswith_lower(",id="))
fatal("invalid option " + arg);
arg = arg.substr(strlen(",id="));
if (arg.getAsInteger(0, config->manifestID))
fatal("invalid option " + arg);
}
// Parses a string in the form of "level=<string>|uiAccess=<string>|NO".
// Results are directly written to Config.
void parseManifestUAC(StringRef arg) {
if (arg.equals_lower("no")) {
config->manifestUAC = false;
return;
}
for (;;) {
arg = arg.ltrim();
if (arg.empty())
return;
if (arg.startswith_lower("level=")) {
arg = arg.substr(strlen("level="));
std::tie(config->manifestLevel, arg) = arg.split(" ");
continue;
}
if (arg.startswith_lower("uiaccess=")) {
arg = arg.substr(strlen("uiaccess="));
std::tie(config->manifestUIAccess, arg) = arg.split(" ");
continue;
}
fatal("invalid option " + arg);
}
}
// Parses a string in the form of "cd|net[,(cd|net)]*"
// Results are directly written to Config.
void parseSwaprun(StringRef arg) {
do {
StringRef swaprun, newArg;
std::tie(swaprun, newArg) = arg.split(',');
if (swaprun.equals_lower("cd"))
config->swaprunCD = true;
else if (swaprun.equals_lower("net"))
config->swaprunNet = true;
else if (swaprun.empty())
error("/swaprun: missing argument");
else
error("/swaprun: invalid argument: " + swaprun);
// To catch trailing commas, e.g. `/spawrun:cd,`
if (newArg.empty() && arg.endswith(","))
error("/swaprun: missing argument");
arg = newArg;
} while (!arg.empty());
}
// An RAII temporary file class that automatically removes a temporary file.
namespace {
class TemporaryFile {
public:
TemporaryFile(StringRef prefix, StringRef extn, StringRef contents = "") {
SmallString<128> s;
if (auto ec = sys::fs::createTemporaryFile("lld-" + prefix, extn, s))
fatal("cannot create a temporary file: " + ec.message());
path = s.str();
if (!contents.empty()) {
std::error_code ec;
raw_fd_ostream os(path, ec, sys::fs::F_None);
if (ec)
fatal("failed to open " + path + ": " + ec.message());
os << contents;
}
}
TemporaryFile(TemporaryFile &&obj) {
std::swap(path, obj.path);
}
~TemporaryFile() {
if (path.empty())
return;
if (sys::fs::remove(path))
fatal("failed to remove " + path);
}
// Returns a memory buffer of this temporary file.
// Note that this function does not leave the file open,
// so it is safe to remove the file immediately after this function
// is called (you cannot remove an opened file on Windows.)
std::unique_ptr<MemoryBuffer> getMemoryBuffer() {
// IsVolatile=true forces MemoryBuffer to not use mmap().
return CHECK(MemoryBuffer::getFile(path, /*FileSize=*/-1,
/*RequiresNullTerminator=*/false,
/*IsVolatile=*/true),
"could not open " + path);
}
std::string path;
};
}
static std::string createDefaultXml() {
std::string ret;
raw_string_ostream os(ret);
// Emit the XML. Note that we do *not* verify that the XML attributes are
// syntactically correct. This is intentional for link.exe compatibility.
os << "<?xml version=\"1.0\" standalone=\"yes\"?>\n"
<< "<assembly xmlns=\"urn:schemas-microsoft-com:asm.v1\"\n"
<< " manifestVersion=\"1.0\">\n";
if (config->manifestUAC) {
os << " <trustInfo>\n"
<< " <security>\n"
<< " <requestedPrivileges>\n"
<< " <requestedExecutionLevel level=" << config->manifestLevel
<< " uiAccess=" << config->manifestUIAccess << "/>\n"
<< " </requestedPrivileges>\n"
<< " </security>\n"
<< " </trustInfo>\n";
}
if (!config->manifestDependency.empty()) {
os << " <dependency>\n"
<< " <dependentAssembly>\n"
<< " <assemblyIdentity " << config->manifestDependency << " />\n"
<< " </dependentAssembly>\n"
<< " </dependency>\n";
}
os << "</assembly>\n";
return os.str();
}
static std::string createManifestXmlWithInternalMt(StringRef defaultXml) {
std::unique_ptr<MemoryBuffer> defaultXmlCopy =
MemoryBuffer::getMemBufferCopy(defaultXml);
windows_manifest::WindowsManifestMerger merger;
if (auto e = merger.merge(*defaultXmlCopy.get()))
fatal("internal manifest tool failed on default xml: " +
toString(std::move(e)));
for (StringRef filename : config->manifestInput) {
std::unique_ptr<MemoryBuffer> manifest =
check(MemoryBuffer::getFile(filename));
if (auto e = merger.merge(*manifest.get()))
fatal("internal manifest tool failed on file " + filename + ": " +
toString(std::move(e)));
}
return merger.getMergedManifest().get()->getBuffer();
}
static std::string createManifestXmlWithExternalMt(StringRef defaultXml) {
// Create the default manifest file as a temporary file.
TemporaryFile Default("defaultxml", "manifest");
std::error_code ec;
raw_fd_ostream os(Default.path, ec, sys::fs::F_Text);
if (ec)
fatal("failed to open " + Default.path + ": " + ec.message());
os << defaultXml;
os.close();
// Merge user-supplied manifests if they are given. Since libxml2 is not
// enabled, we must shell out to Microsoft's mt.exe tool.
TemporaryFile user("user", "manifest");
Executor e("mt.exe");
e.add("/manifest");
e.add(Default.path);
for (StringRef filename : config->manifestInput) {
e.add("/manifest");
e.add(filename);
}
e.add("/nologo");
e.add("/out:" + StringRef(user.path));
e.run();
return CHECK(MemoryBuffer::getFile(user.path), "could not open " + user.path)
.get()
->getBuffer();
}
static std::string createManifestXml() {
std::string defaultXml = createDefaultXml();
if (config->manifestInput.empty())
return defaultXml;
if (windows_manifest::isAvailable())
return createManifestXmlWithInternalMt(defaultXml);
return createManifestXmlWithExternalMt(defaultXml);
}
static std::unique_ptr<WritableMemoryBuffer>
createMemoryBufferForManifestRes(size_t manifestSize) {
size_t resSize = alignTo(
object::WIN_RES_MAGIC_SIZE + object::WIN_RES_NULL_ENTRY_SIZE +
sizeof(object::WinResHeaderPrefix) + sizeof(object::WinResIDs) +
sizeof(object::WinResHeaderSuffix) + manifestSize,
object::WIN_RES_DATA_ALIGNMENT);
return WritableMemoryBuffer::getNewMemBuffer(resSize, config->outputFile +
".manifest.res");
}
static void writeResFileHeader(char *&buf) {
memcpy(buf, COFF::WinResMagic, sizeof(COFF::WinResMagic));
buf += sizeof(COFF::WinResMagic);
memset(buf, 0, object::WIN_RES_NULL_ENTRY_SIZE);
buf += object::WIN_RES_NULL_ENTRY_SIZE;
}
static void writeResEntryHeader(char *&buf, size_t manifestSize) {
// Write the prefix.
auto *prefix = reinterpret_cast<object::WinResHeaderPrefix *>(buf);
prefix->DataSize = manifestSize;
prefix->HeaderSize = sizeof(object::WinResHeaderPrefix) +
sizeof(object::WinResIDs) +
sizeof(object::WinResHeaderSuffix);
buf += sizeof(object::WinResHeaderPrefix);
// Write the Type/Name IDs.
auto *iDs = reinterpret_cast<object::WinResIDs *>(buf);
iDs->setType(RT_MANIFEST);
iDs->setName(config->manifestID);
buf += sizeof(object::WinResIDs);
// Write the suffix.
auto *suffix = reinterpret_cast<object::WinResHeaderSuffix *>(buf);
suffix->DataVersion = 0;
suffix->MemoryFlags = object::WIN_RES_PURE_MOVEABLE;
suffix->Language = SUBLANG_ENGLISH_US;
suffix->Version = 0;
suffix->Characteristics = 0;
buf += sizeof(object::WinResHeaderSuffix);
}
// Create a resource file containing a manifest XML.
std::unique_ptr<MemoryBuffer> createManifestRes() {
std::string manifest = createManifestXml();
std::unique_ptr<WritableMemoryBuffer> res =
createMemoryBufferForManifestRes(manifest.size());
char *buf = res->getBufferStart();
writeResFileHeader(buf);
writeResEntryHeader(buf, manifest.size());
// Copy the manifest data into the .res file.
std::copy(manifest.begin(), manifest.end(), buf);
return std::move(res);
}
void createSideBySideManifest() {
std::string path = config->manifestFile;
if (path == "")
path = config->outputFile + ".manifest";
std::error_code ec;
raw_fd_ostream out(path, ec, sys::fs::F_Text);
if (ec)
fatal("failed to create manifest: " + ec.message());
out << createManifestXml();
}
// Parse a string in the form of
// "<name>[=<internalname>][,@ordinal[,NONAME]][,DATA][,PRIVATE]"
// or "<name>=<dllname>.<name>".
// Used for parsing /export arguments.
Export parseExport(StringRef arg) {
Export e;
StringRef rest;
std::tie(e.name, rest) = arg.split(",");
if (e.name.empty())
goto err;
if (e.name.contains('=')) {
StringRef x, y;
std::tie(x, y) = e.name.split("=");
// If "<name>=<dllname>.<name>".
if (y.contains(".")) {
e.name = x;
e.forwardTo = y;
return e;
}
e.extName = x;
e.name = y;
if (e.name.empty())
goto err;
}
// If "<name>=<internalname>[,@ordinal[,NONAME]][,DATA][,PRIVATE]"
while (!rest.empty()) {
StringRef tok;
std::tie(tok, rest) = rest.split(",");
if (tok.equals_lower("noname")) {
if (e.ordinal == 0)
goto err;
e.noname = true;
continue;
}
if (tok.equals_lower("data")) {
e.data = true;
continue;
}
if (tok.equals_lower("constant")) {
e.constant = true;
continue;
}
if (tok.equals_lower("private")) {
e.isPrivate = true;
continue;
}
if (tok.startswith("@")) {
int32_t ord;
if (tok.substr(1).getAsInteger(0, ord))
goto err;
if (ord <= 0 || 65535 < ord)
goto err;
e.ordinal = ord;
continue;
}
goto err;
}
return e;
err:
fatal("invalid /export: " + arg);
}
static StringRef undecorate(StringRef sym) {
if (config->machine != I386)
return sym;
// In MSVC mode, a fully decorated stdcall function is exported
// as-is with the leading underscore (with type IMPORT_NAME).
// In MinGW mode, a decorated stdcall function gets the underscore
// removed, just like normal cdecl functions.
if (sym.startswith("_") && sym.contains('@') && !config->mingw)
return sym;
return sym.startswith("_") ? sym.substr(1) : sym;
}
// Convert stdcall/fastcall style symbols into unsuffixed symbols,
// with or without a leading underscore. (MinGW specific.)
static StringRef killAt(StringRef sym, bool prefix) {
if (sym.empty())
return sym;
// Strip any trailing stdcall suffix
sym = sym.substr(0, sym.find('@', 1));
if (!sym.startswith("@")) {
if (prefix && !sym.startswith("_"))
return saver.save("_" + sym);
return sym;
}
// For fastcall, remove the leading @ and replace it with an
// underscore, if prefixes are used.
sym = sym.substr(1);
if (prefix)
sym = saver.save("_" + sym);
return sym;
}
// Performs error checking on all /export arguments.
// It also sets ordinals.
void fixupExports() {
// Symbol ordinals must be unique.
std::set<uint16_t> ords;
for (Export &e : config->exports) {
if (e.ordinal == 0)
continue;
if (!ords.insert(e.ordinal).second)
fatal("duplicate export ordinal: " + e.name);
}
for (Export &e : config->exports) {
if (!e.forwardTo.empty()) {
e.exportName = undecorate(e.name);
} else {
e.exportName = undecorate(e.extName.empty() ? e.name : e.extName);
}
}
if (config->killAt && config->machine == I386) {
for (Export &e : config->exports) {
e.name = killAt(e.name, true);
e.exportName = killAt(e.exportName, false);
e.extName = killAt(e.extName, true);
e.symbolName = killAt(e.symbolName, true);
}
}
// Uniquefy by name.
DenseMap<StringRef, Export *> map(config->exports.size());
std::vector<Export> v;
for (Export &e : config->exports) {
auto pair = map.insert(std::make_pair(e.exportName, &e));
bool inserted = pair.second;
if (inserted) {
v.push_back(e);
continue;
}
Export *existing = pair.first->second;
if (e == *existing || e.name != existing->name)
continue;
warn("duplicate /export option: " + e.name);
}
config->exports = std::move(v);
// Sort by name.
std::sort(config->exports.begin(), config->exports.end(),
[](const Export &a, const Export &b) {
return a.exportName < b.exportName;
});
}
void assignExportOrdinals() {
// Assign unique ordinals if default (= 0).
uint16_t max = 0;
for (Export &e : config->exports)
max = std::max(max, e.ordinal);
for (Export &e : config->exports)
if (e.ordinal == 0)
e.ordinal = ++max;
}
// Parses a string in the form of "key=value" and check
// if value matches previous values for the same key.
void checkFailIfMismatch(StringRef arg, InputFile *source) {
StringRef k, v;
std::tie(k, v) = arg.split('=');
if (k.empty() || v.empty())
fatal("/failifmismatch: invalid argument: " + arg);
std::pair<StringRef, InputFile *> existing = config->mustMatch[k];
if (!existing.first.empty() && v != existing.first) {
std::string sourceStr = source ? toString(source) : "cmd-line";
std::string existingStr =
existing.second ? toString(existing.second) : "cmd-line";
fatal("/failifmismatch: mismatch detected for '" + k + "':\n>>> " +
existingStr + " has value " + existing.first + "\n>>> " + sourceStr +
" has value " + v);
}
config->mustMatch[k] = {v, source};
}
// Convert Windows resource files (.res files) to a .obj file.
// Does what cvtres.exe does, but in-process and cross-platform.
MemoryBufferRef convertResToCOFF(ArrayRef<MemoryBufferRef> mbs) {
object::WindowsResourceParser parser;
for (MemoryBufferRef mb : mbs) {
std::unique_ptr<object::Binary> bin = check(object::createBinary(mb));
object::WindowsResource *rf = dyn_cast<object::WindowsResource>(bin.get());
if (!rf)
fatal("cannot compile non-resource file as resource");
std::vector<std::string> duplicates;
if (auto ec = parser.parse(rf, duplicates))
fatal(toString(std::move(ec)));
for (const auto &dupeDiag : duplicates)
if (config->forceMultipleRes)
warn(dupeDiag);
else
error(dupeDiag);
}
Expected<std::unique_ptr<MemoryBuffer>> e =
llvm::object::writeWindowsResourceCOFF(config->machine, parser,
config->timestamp);
if (!e)
fatal("failed to write .res to COFF: " + toString(e.takeError()));
MemoryBufferRef mbref = **e;
make<std::unique_ptr<MemoryBuffer>>(std::move(*e)); // take ownership
return mbref;
}
// Create OptTable
// Create prefix string literals used in Options.td
#define PREFIX(NAME, VALUE) const char *const NAME[] = VALUE;
#include "Options.inc"
#undef PREFIX
// Create table mapping all options defined in Options.td
static const llvm::opt::OptTable::Info infoTable[] = {
#define OPTION(X1, X2, ID, KIND, GROUP, ALIAS, X7, X8, X9, X10, X11, X12) \
{X1, X2, X10, X11, OPT_##ID, llvm::opt::Option::KIND##Class, \
X9, X8, OPT_##GROUP, OPT_##ALIAS, X7, X12},
#include "Options.inc"
#undef OPTION
};
COFFOptTable::COFFOptTable() : OptTable(infoTable, true) {}
// Set color diagnostics according to --color-diagnostics={auto,always,never}
// or --no-color-diagnostics flags.
static void handleColorDiagnostics(opt::InputArgList &args) {
auto *arg = args.getLastArg(OPT_color_diagnostics, OPT_color_diagnostics_eq,
OPT_no_color_diagnostics);
if (!arg)
return;
if (arg->getOption().getID() == OPT_color_diagnostics) {
errorHandler().colorDiagnostics = true;
} else if (arg->getOption().getID() == OPT_no_color_diagnostics) {
errorHandler().colorDiagnostics = false;
} else {
StringRef s = arg->getValue();
if (s == "always")
errorHandler().colorDiagnostics = true;
else if (s == "never")
errorHandler().colorDiagnostics = false;
else if (s != "auto")
error("unknown option: --color-diagnostics=" + s);
}
}
static cl::TokenizerCallback getQuotingStyle(opt::InputArgList &args) {
if (auto *arg = args.getLastArg(OPT_rsp_quoting)) {
StringRef s = arg->getValue();
if (s != "windows" && s != "posix")
error("invalid response file quoting: " + s);
if (s == "windows")
return cl::TokenizeWindowsCommandLine;
return cl::TokenizeGNUCommandLine;
}
// The COFF linker always defaults to Windows quoting.
return cl::TokenizeWindowsCommandLine;
}
// Parses a given list of options.
opt::InputArgList ArgParser::parse(ArrayRef<const char *> argv) {
// Make InputArgList from string vectors.
unsigned missingIndex;
unsigned missingCount;
// We need to get the quoting style for response files before parsing all
// options so we parse here before and ignore all the options but
// --rsp-quoting.
opt::InputArgList args = table.ParseArgs(argv, missingIndex, missingCount);
// Expand response files (arguments in the form of @<filename>)
// and then parse the argument again.
SmallVector<const char *, 256> expandedArgv(argv.data(),
argv.data() + argv.size());
cl::ExpandResponseFiles(saver, getQuotingStyle(args), expandedArgv);
args = table.ParseArgs(makeArrayRef(expandedArgv).drop_front(), missingIndex,
missingCount);
// Print the real command line if response files are expanded.
if (args.hasArg(OPT_verbose) && argv.size() != expandedArgv.size()) {
std::string msg = "Command line:";
for (const char *s : expandedArgv)
msg += " " + std::string(s);
message(msg);
}
// Save the command line after response file expansion so we can write it to
// the PDB if necessary.
config->argv = {expandedArgv.begin(), expandedArgv.end()};
// Handle /WX early since it converts missing argument warnings to errors.
errorHandler().fatalWarnings = args.hasFlag(OPT_WX, OPT_WX_no, false);
if (missingCount)
fatal(Twine(args.getArgString(missingIndex)) + ": missing argument");
handleColorDiagnostics(args);
for (auto *arg : args.filtered(OPT_UNKNOWN)) {
std::string nearest;
if (table.findNearest(arg->getAsString(args), nearest) > 1)
warn("ignoring unknown argument '" + arg->getAsString(args) + "'");
else
warn("ignoring unknown argument '" + arg->getAsString(args) +
"', did you mean '" + nearest + "'");
}
if (args.hasArg(OPT_lib))
warn("ignoring /lib since it's not the first argument");
return args;
}
// Tokenizes and parses a given string as command line in .drective section.
// /EXPORT options are processed in fastpath.
std::pair<opt::InputArgList, std::vector<StringRef>>
ArgParser::parseDirectives(StringRef s) {
std::vector<StringRef> exports;
SmallVector<const char *, 16> rest;
for (StringRef tok : tokenize(s)) {
if (tok.startswith_lower("/export:") || tok.startswith_lower("-export:"))
exports.push_back(tok.substr(strlen("/export:")));
else
rest.push_back(tok.data());
}
// Make InputArgList from unparsed string vectors.
unsigned missingIndex;
unsigned missingCount;
opt::InputArgList args = table.ParseArgs(rest, missingIndex, missingCount);
if (missingCount)
fatal(Twine(args.getArgString(missingIndex)) + ": missing argument");
for (auto *arg : args.filtered(OPT_UNKNOWN))
warn("ignoring unknown argument: " + arg->getAsString(args));
return {std::move(args), std::move(exports)};
}
// link.exe has an interesting feature. If LINK or _LINK_ environment
// variables exist, their contents are handled as command line strings.
// So you can pass extra arguments using them.
opt::InputArgList ArgParser::parseLINK(std::vector<const char *> argv) {
// Concatenate LINK env and command line arguments, and then parse them.
if (Optional<std::string> s = Process::GetEnv("LINK")) {
std::vector<const char *> v = tokenize(*s);
argv.insert(std::next(argv.begin()), v.begin(), v.end());
}
if (Optional<std::string> s = Process::GetEnv("_LINK_")) {
std::vector<const char *> v = tokenize(*s);
argv.insert(std::next(argv.begin()), v.begin(), v.end());
}
return parse(argv);
}
std::vector<const char *> ArgParser::tokenize(StringRef s) {
SmallVector<const char *, 16> tokens;
cl::TokenizeWindowsCommandLine(s, saver, tokens);
return std::vector<const char *>(tokens.begin(), tokens.end());
}
void printHelp(const char *argv0) {
COFFOptTable().PrintHelp(outs(),
(std::string(argv0) + " [options] file...").c_str(),
"LLVM Linker", false);
}
} // namespace coff
} // namespace lld

317
deps/lld/COFF/ICF.cpp vendored
View File

@@ -1,317 +0,0 @@
//===- ICF.cpp ------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// ICF is short for Identical Code Folding. That is a size optimization to
// identify and merge two or more read-only sections (typically functions)
// that happened to have the same contents. It usually reduces output size
// by a few percent.
//
// On Windows, ICF is enabled by default.
//
// See ELF/ICF.cpp for the details about the algortihm.
//
//===----------------------------------------------------------------------===//
#include "ICF.h"
#include "Chunks.h"
#include "Symbols.h"
#include "lld/Common/ErrorHandler.h"
#include "lld/Common/Threads.h"
#include "lld/Common/Timer.h"
#include "llvm/ADT/Hashing.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Parallel.h"
#include "llvm/Support/raw_ostream.h"
#include "llvm/Support/xxhash.h"
#include <algorithm>
#include <atomic>
#include <vector>
using namespace llvm;
namespace lld {
namespace coff {
static Timer icfTimer("ICF", Timer::root());
class ICF {
public:
void run(ArrayRef<Chunk *> v);
private:
void segregate(size_t begin, size_t end, bool constant);
bool assocEquals(const SectionChunk *a, const SectionChunk *b);
bool equalsConstant(const SectionChunk *a, const SectionChunk *b);
bool equalsVariable(const SectionChunk *a, const SectionChunk *b);
bool isEligible(SectionChunk *c);
size_t findBoundary(size_t begin, size_t end);
void forEachClassRange(size_t begin, size_t end,
std::function<void(size_t, size_t)> fn);
void forEachClass(std::function<void(size_t, size_t)> fn);
std::vector<SectionChunk *> chunks;
int cnt = 0;
std::atomic<bool> repeat = {false};
};
// Returns true if section S is subject of ICF.
//
// Microsoft's documentation
// (https://msdn.microsoft.com/en-us/library/bxwfs976.aspx; visited April
// 2017) says that /opt:icf folds both functions and read-only data.
// Despite that, the MSVC linker folds only functions. We found
// a few instances of programs that are not safe for data merging.
// Therefore, we merge only functions just like the MSVC tool. However, we also
// merge read-only sections in a couple of cases where the address of the
// section is insignificant to the user program and the behaviour matches that
// of the Visual C++ linker.
bool ICF::isEligible(SectionChunk *c) {
// Non-comdat chunks, dead chunks, and writable chunks are not elegible.
bool writable = c->getOutputCharacteristics() & llvm::COFF::IMAGE_SCN_MEM_WRITE;
if (!c->isCOMDAT() || !c->live || writable)
return false;
// Code sections are eligible.
if (c->getOutputCharacteristics() & llvm::COFF::IMAGE_SCN_MEM_EXECUTE)
return true;
// .pdata and .xdata unwind info sections are eligible.
StringRef outSecName = c->getSectionName().split('$').first;
if (outSecName == ".pdata" || outSecName == ".xdata")
return true;
// So are vtables.
if (c->sym && c->sym->getName().startswith("??_7"))
return true;
// Anything else not in an address-significance table is eligible.
return !c->keepUnique;
}
// Split an equivalence class into smaller classes.
void ICF::segregate(size_t begin, size_t end, bool constant) {
while (begin < end) {
// Divide [Begin, End) into two. Let Mid be the start index of the
// second group.
auto bound = std::stable_partition(
chunks.begin() + begin + 1, chunks.begin() + end, [&](SectionChunk *s) {
if (constant)
return equalsConstant(chunks[begin], s);
return equalsVariable(chunks[begin], s);
});
size_t mid = bound - chunks.begin();
// Split [Begin, End) into [Begin, Mid) and [Mid, End). We use Mid as an
// equivalence class ID because every group ends with a unique index.
for (size_t i = begin; i < mid; ++i)
chunks[i]->eqClass[(cnt + 1) % 2] = mid;
// If we created a group, we need to iterate the main loop again.
if (mid != end)
repeat = true;
begin = mid;
}
}
// Returns true if two sections' associative children are equal.
bool ICF::assocEquals(const SectionChunk *a, const SectionChunk *b) {
auto childClasses = [&](const SectionChunk *sc) {
std::vector<uint32_t> classes;
for (const SectionChunk &c : sc->children())
if (!c.getSectionName().startswith(".debug") &&
c.getSectionName() != ".gfids$y" && c.getSectionName() != ".gljmp$y")
classes.push_back(c.eqClass[cnt % 2]);
return classes;
};
return childClasses(a) == childClasses(b);
}
// Compare "non-moving" part of two sections, namely everything
// except relocation targets.
bool ICF::equalsConstant(const SectionChunk *a, const SectionChunk *b) {
if (a->relocsSize != b->relocsSize)
return false;
// Compare relocations.
auto eq = [&](const coff_relocation &r1, const coff_relocation &r2) {
if (r1.Type != r2.Type ||
r1.VirtualAddress != r2.VirtualAddress) {
return false;
}
Symbol *b1 = a->file->getSymbol(r1.SymbolTableIndex);
Symbol *b2 = b->file->getSymbol(r2.SymbolTableIndex);
if (b1 == b2)
return true;
if (auto *d1 = dyn_cast<DefinedRegular>(b1))
if (auto *d2 = dyn_cast<DefinedRegular>(b2))
return d1->getValue() == d2->getValue() &&
d1->getChunk()->eqClass[cnt % 2] == d2->getChunk()->eqClass[cnt % 2];
return false;
};
if (!std::equal(a->getRelocs().begin(), a->getRelocs().end(),
b->getRelocs().begin(), eq))
return false;
// Compare section attributes and contents.
return a->getOutputCharacteristics() == b->getOutputCharacteristics() &&
a->getSectionName() == b->getSectionName() &&
a->header->SizeOfRawData == b->header->SizeOfRawData &&
a->checksum == b->checksum && a->getContents() == b->getContents() &&
assocEquals(a, b);
}
// Compare "moving" part of two sections, namely relocation targets.
bool ICF::equalsVariable(const SectionChunk *a, const SectionChunk *b) {
// Compare relocations.
auto eq = [&](const coff_relocation &r1, const coff_relocation &r2) {
Symbol *b1 = a->file->getSymbol(r1.SymbolTableIndex);
Symbol *b2 = b->file->getSymbol(r2.SymbolTableIndex);
if (b1 == b2)
return true;
if (auto *d1 = dyn_cast<DefinedRegular>(b1))
if (auto *d2 = dyn_cast<DefinedRegular>(b2))
return d1->getChunk()->eqClass[cnt % 2] == d2->getChunk()->eqClass[cnt % 2];
return false;
};
return std::equal(a->getRelocs().begin(), a->getRelocs().end(),
b->getRelocs().begin(), eq) &&
assocEquals(a, b);
}
// Find the first Chunk after Begin that has a different class from Begin.
size_t ICF::findBoundary(size_t begin, size_t end) {
for (size_t i = begin + 1; i < end; ++i)
if (chunks[begin]->eqClass[cnt % 2] != chunks[i]->eqClass[cnt % 2])
return i;
return end;
}
void ICF::forEachClassRange(size_t begin, size_t end,
std::function<void(size_t, size_t)> fn) {
while (begin < end) {
size_t mid = findBoundary(begin, end);
fn(begin, mid);
begin = mid;
}
}
// Call Fn on each class group.
void ICF::forEachClass(std::function<void(size_t, size_t)> fn) {
// If the number of sections are too small to use threading,
// call Fn sequentially.
if (chunks.size() < 1024) {
forEachClassRange(0, chunks.size(), fn);
++cnt;
return;
}
// Shard into non-overlapping intervals, and call Fn in parallel.
// The sharding must be completed before any calls to Fn are made
// so that Fn can modify the Chunks in its shard without causing data
// races.
const size_t numShards = 256;
size_t step = chunks.size() / numShards;
size_t boundaries[numShards + 1];
boundaries[0] = 0;
boundaries[numShards] = chunks.size();
parallelForEachN(1, numShards, [&](size_t i) {
boundaries[i] = findBoundary((i - 1) * step, chunks.size());
});
parallelForEachN(1, numShards + 1, [&](size_t i) {
if (boundaries[i - 1] < boundaries[i]) {
forEachClassRange(boundaries[i - 1], boundaries[i], fn);
}
});
++cnt;
}
// Merge identical COMDAT sections.
// Two sections are considered the same if their section headers,
// contents and relocations are all the same.
void ICF::run(ArrayRef<Chunk *> vec) {
ScopedTimer t(icfTimer);
// Collect only mergeable sections and group by hash value.
uint32_t nextId = 1;
for (Chunk *c : vec) {
if (auto *sc = dyn_cast<SectionChunk>(c)) {
if (isEligible(sc))
chunks.push_back(sc);
else
sc->eqClass[0] = nextId++;
}
}
// Make sure that ICF doesn't merge sections that are being handled by string
// tail merging.
for (MergeChunk *mc : MergeChunk::instances)
if (mc)
for (SectionChunk *sc : mc->sections)
sc->eqClass[0] = nextId++;
// Initially, we use hash values to partition sections.
parallelForEach(chunks, [&](SectionChunk *sc) {
sc->eqClass[0] = xxHash64(sc->getContents());
});
// Combine the hashes of the sections referenced by each section into its
// hash.
for (unsigned cnt = 0; cnt != 2; ++cnt) {
parallelForEach(chunks, [&](SectionChunk *sc) {
uint32_t hash = sc->eqClass[cnt % 2];
for (Symbol *b : sc->symbols())
if (auto *sym = dyn_cast_or_null<DefinedRegular>(b))
hash += sym->getChunk()->eqClass[cnt % 2];
// Set MSB to 1 to avoid collisions with non-hash classs.
sc->eqClass[(cnt + 1) % 2] = hash | (1U << 31);
});
}
// From now on, sections in Chunks are ordered so that sections in
// the same group are consecutive in the vector.
llvm::stable_sort(chunks, [](const SectionChunk *a, const SectionChunk *b) {
return a->eqClass[0] < b->eqClass[0];
});
// Compare static contents and assign unique IDs for each static content.
forEachClass([&](size_t begin, size_t end) { segregate(begin, end, true); });
// Split groups by comparing relocations until convergence is obtained.
do {
repeat = false;
forEachClass(
[&](size_t begin, size_t end) { segregate(begin, end, false); });
} while (repeat);
log("ICF needed " + Twine(cnt) + " iterations");
// Merge sections in the same classs.
forEachClass([&](size_t begin, size_t end) {
if (end - begin == 1)
return;
log("Selected " + chunks[begin]->getDebugName());
for (size_t i = begin + 1; i < end; ++i) {
log(" Removed " + chunks[i]->getDebugName());
chunks[begin]->replace(chunks[i]);
}
});
}
// Entry point to ICF.
void doICF(ArrayRef<Chunk *> chunks) { ICF().run(chunks); }
} // namespace coff
} // namespace lld

25
deps/lld/COFF/ICF.h vendored
View File

@@ -1,25 +0,0 @@
//===- ICF.h --------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLD_COFF_ICF_H
#define LLD_COFF_ICF_H
#include "lld/Common/LLVM.h"
#include "llvm/ADT/ArrayRef.h"
namespace lld {
namespace coff {
class Chunk;
void doICF(ArrayRef<Chunk *> chunks);
} // namespace coff
} // namespace lld
#endif

View File

@@ -1,881 +0,0 @@
//===- InputFiles.cpp -----------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "InputFiles.h"
#include "Chunks.h"
#include "Config.h"
#include "DebugTypes.h"
#include "Driver.h"
#include "SymbolTable.h"
#include "Symbols.h"
#include "lld/Common/ErrorHandler.h"
#include "lld/Common/Memory.h"
#include "llvm-c/lto.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/Triple.h"
#include "llvm/ADT/Twine.h"
#include "llvm/BinaryFormat/COFF.h"
#include "llvm/DebugInfo/CodeView/DebugSubsectionRecord.h"
#include "llvm/DebugInfo/CodeView/SymbolDeserializer.h"
#include "llvm/DebugInfo/CodeView/SymbolRecord.h"
#include "llvm/DebugInfo/CodeView/TypeDeserializer.h"
#include "llvm/Object/Binary.h"
#include "llvm/Object/COFF.h"
#include "llvm/Support/Casting.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/ErrorOr.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
#include "llvm/Target/TargetOptions.h"
#include <cstring>
#include <system_error>
#include <utility>
using namespace llvm;
using namespace llvm::COFF;
using namespace llvm::codeview;
using namespace llvm::object;
using namespace llvm::support::endian;
using llvm::Triple;
using llvm::support::ulittle32_t;
namespace lld {
namespace coff {
std::vector<ObjFile *> ObjFile::instances;
std::vector<ImportFile *> ImportFile::instances;
std::vector<BitcodeFile *> BitcodeFile::instances;
/// Checks that Source is compatible with being a weak alias to Target.
/// If Source is Undefined and has no weak alias set, makes it a weak
/// alias to Target.
static void checkAndSetWeakAlias(SymbolTable *symtab, InputFile *f,
Symbol *source, Symbol *target) {
if (auto *u = dyn_cast<Undefined>(source)) {
if (u->weakAlias && u->weakAlias != target) {
// Weak aliases as produced by GCC are named in the form
// .weak.<weaksymbol>.<othersymbol>, where <othersymbol> is the name
// of another symbol emitted near the weak symbol.
// Just use the definition from the first object file that defined
// this weak symbol.
if (config->mingw)
return;
symtab->reportDuplicate(source, f);
}
u->weakAlias = target;
}
}
ArchiveFile::ArchiveFile(MemoryBufferRef m) : InputFile(ArchiveKind, m) {}
void ArchiveFile::parse() {
// Parse a MemoryBufferRef as an archive file.
file = CHECK(Archive::create(mb), this);
// Read the symbol table to construct Lazy objects.
for (const Archive::Symbol &sym : file->symbols())
symtab->addLazy(this, sym);
}
// Returns a buffer pointing to a member file containing a given symbol.
void ArchiveFile::addMember(const Archive::Symbol &sym) {
const Archive::Child &c =
CHECK(sym.getMember(),
"could not get the member for symbol " + toCOFFString(sym));
// Return an empty buffer if we have already returned the same buffer.
if (!seen.insert(c.getChildOffset()).second)
return;
driver->enqueueArchiveMember(c, sym, getName());
}
std::vector<MemoryBufferRef> getArchiveMembers(Archive *file) {
std::vector<MemoryBufferRef> v;
Error err = Error::success();
for (const ErrorOr<Archive::Child> &cOrErr : file->children(err)) {
Archive::Child c =
CHECK(cOrErr,
file->getFileName() + ": could not get the child of the archive");
MemoryBufferRef mbref =
CHECK(c.getMemoryBufferRef(),
file->getFileName() +
": could not get the buffer for a child of the archive");
v.push_back(mbref);
}
if (err)
fatal(file->getFileName() +
": Archive::children failed: " + toString(std::move(err)));
return v;
}
void ObjFile::parse() {
// Parse a memory buffer as a COFF file.
std::unique_ptr<Binary> bin = CHECK(createBinary(mb), this);
if (auto *obj = dyn_cast<COFFObjectFile>(bin.get())) {
bin.release();
coffObj.reset(obj);
} else {
fatal(toString(this) + " is not a COFF file");
}
// Read section and symbol tables.
initializeChunks();
initializeSymbols();
initializeFlags();
initializeDependencies();
}
const coff_section* ObjFile::getSection(uint32_t i) {
const coff_section *sec;
if (auto ec = coffObj->getSection(i, sec))
fatal("getSection failed: #" + Twine(i) + ": " + ec.message());
return sec;
}
// We set SectionChunk pointers in the SparseChunks vector to this value
// temporarily to mark comdat sections as having an unknown resolution. As we
// walk the object file's symbol table, once we visit either a leader symbol or
// an associative section definition together with the parent comdat's leader,
// we set the pointer to either nullptr (to mark the section as discarded) or a
// valid SectionChunk for that section.
static SectionChunk *const pendingComdat = reinterpret_cast<SectionChunk *>(1);
void ObjFile::initializeChunks() {
uint32_t numSections = coffObj->getNumberOfSections();
chunks.reserve(numSections);
sparseChunks.resize(numSections + 1);
for (uint32_t i = 1; i < numSections + 1; ++i) {
const coff_section *sec = getSection(i);
if (sec->Characteristics & IMAGE_SCN_LNK_COMDAT)
sparseChunks[i] = pendingComdat;
else
sparseChunks[i] = readSection(i, nullptr, "");
}
}
SectionChunk *ObjFile::readSection(uint32_t sectionNumber,
const coff_aux_section_definition *def,
StringRef leaderName) {
const coff_section *sec = getSection(sectionNumber);
StringRef name;
if (Expected<StringRef> e = coffObj->getSectionName(sec))
name = *e;
else
fatal("getSectionName failed: #" + Twine(sectionNumber) + ": " +
toString(e.takeError()));
if (name == ".drectve") {
ArrayRef<uint8_t> data;
cantFail(coffObj->getSectionContents(sec, data));
directives = StringRef((const char *)data.data(), data.size());
return nullptr;
}
if (name == ".llvm_addrsig") {
addrsigSec = sec;
return nullptr;
}
// Object files may have DWARF debug info or MS CodeView debug info
// (or both).
//
// DWARF sections don't need any special handling from the perspective
// of the linker; they are just a data section containing relocations.
// We can just link them to complete debug info.
//
// CodeView needs linker support. We need to interpret debug info,
// and then write it to a separate .pdb file.
// Ignore DWARF debug info unless /debug is given.
if (!config->debug && name.startswith(".debug_"))
return nullptr;
if (sec->Characteristics & llvm::COFF::IMAGE_SCN_LNK_REMOVE)
return nullptr;
auto *c = make<SectionChunk>(this, sec);
if (def)
c->checksum = def->CheckSum;
// link.exe uses the presence of .rsrc$01 for LNK4078, so match that.
if (name == ".rsrc$01")
isResourceObjFile = true;
// CodeView sections are stored to a different vector because they are not
// linked in the regular manner.
if (c->isCodeView())
debugChunks.push_back(c);
else if (name == ".gfids$y")
guardFidChunks.push_back(c);
else if (name == ".gljmp$y")
guardLJmpChunks.push_back(c);
else if (name == ".sxdata")
sXDataChunks.push_back(c);
else if (config->tailMerge && sec->NumberOfRelocations == 0 &&
name == ".rdata" && leaderName.startswith("??_C@"))
// COFF sections that look like string literal sections (i.e. no
// relocations, in .rdata, leader symbol name matches the MSVC name mangling
// for string literals) are subject to string tail merging.
MergeChunk::addSection(c);
else
chunks.push_back(c);
return c;
}
void ObjFile::readAssociativeDefinition(
COFFSymbolRef sym, const coff_aux_section_definition *def) {
readAssociativeDefinition(sym, def, def->getNumber(sym.isBigObj()));
}
void ObjFile::readAssociativeDefinition(COFFSymbolRef sym,
const coff_aux_section_definition *def,
uint32_t parentIndex) {
SectionChunk *parent = sparseChunks[parentIndex];
int32_t sectionNumber = sym.getSectionNumber();
auto diag = [&]() {
StringRef name, parentName;
coffObj->getSymbolName(sym, name);
const coff_section *parentSec = getSection(parentIndex);
if (Expected<StringRef> e = coffObj->getSectionName(parentSec))
parentName = *e;
error(toString(this) + ": associative comdat " + name + " (sec " +
Twine(sectionNumber) + ") has invalid reference to section " +
parentName + " (sec " + Twine(parentIndex) + ")");
};
if (parent == pendingComdat) {
// This can happen if an associative comdat refers to another associative
// comdat that appears after it (invalid per COFF spec) or to a section
// without any symbols.
diag();
return;
}
// Check whether the parent is prevailing. If it is, so are we, and we read
// the section; otherwise mark it as discarded.
if (parent) {
SectionChunk *c = readSection(sectionNumber, def, "");
sparseChunks[sectionNumber] = c;
if (c) {
c->selection = IMAGE_COMDAT_SELECT_ASSOCIATIVE;
parent->addAssociative(c);
}
} else {
sparseChunks[sectionNumber] = nullptr;
}
}
void ObjFile::recordPrevailingSymbolForMingw(
COFFSymbolRef sym, DenseMap<StringRef, uint32_t> &prevailingSectionMap) {
// For comdat symbols in executable sections, where this is the copy
// of the section chunk we actually include instead of discarding it,
// add the symbol to a map to allow using it for implicitly
// associating .[px]data$<func> sections to it.
int32_t sectionNumber = sym.getSectionNumber();
SectionChunk *sc = sparseChunks[sectionNumber];
if (sc && sc->getOutputCharacteristics() & IMAGE_SCN_MEM_EXECUTE) {
StringRef name;
coffObj->getSymbolName(sym, name);
if (getMachineType() == I386)
name.consume_front("_");
prevailingSectionMap[name] = sectionNumber;
}
}
void ObjFile::maybeAssociateSEHForMingw(
COFFSymbolRef sym, const coff_aux_section_definition *def,
const DenseMap<StringRef, uint32_t> &prevailingSectionMap) {
StringRef name;
coffObj->getSymbolName(sym, name);
if (name.consume_front(".pdata$") || name.consume_front(".xdata$") ||
name.consume_front(".eh_frame$")) {
// For MinGW, treat .[px]data$<func> and .eh_frame$<func> as implicitly
// associative to the symbol <func>.
auto parentSym = prevailingSectionMap.find(name);
if (parentSym != prevailingSectionMap.end())
readAssociativeDefinition(sym, def, parentSym->second);
}
}
Symbol *ObjFile::createRegular(COFFSymbolRef sym) {
SectionChunk *sc = sparseChunks[sym.getSectionNumber()];
if (sym.isExternal()) {
StringRef name;
coffObj->getSymbolName(sym, name);
if (sc)
return symtab->addRegular(this, name, sym.getGeneric(), sc);
// For MinGW symbols named .weak.* that point to a discarded section,
// don't create an Undefined symbol. If nothing ever refers to the symbol,
// everything should be fine. If something actually refers to the symbol
// (e.g. the undefined weak alias), linking will fail due to undefined
// references at the end.
if (config->mingw && name.startswith(".weak."))
return nullptr;
return symtab->addUndefined(name, this, false);
}
if (sc)
return make<DefinedRegular>(this, /*Name*/ "", /*IsCOMDAT*/ false,
/*IsExternal*/ false, sym.getGeneric(), sc);
return nullptr;
}
void ObjFile::initializeSymbols() {
uint32_t numSymbols = coffObj->getNumberOfSymbols();
symbols.resize(numSymbols);
SmallVector<std::pair<Symbol *, uint32_t>, 8> weakAliases;
std::vector<uint32_t> pendingIndexes;
pendingIndexes.reserve(numSymbols);
DenseMap<StringRef, uint32_t> prevailingSectionMap;
std::vector<const coff_aux_section_definition *> comdatDefs(
coffObj->getNumberOfSections() + 1);
for (uint32_t i = 0; i < numSymbols; ++i) {
COFFSymbolRef coffSym = check(coffObj->getSymbol(i));
bool prevailingComdat;
if (coffSym.isUndefined()) {
symbols[i] = createUndefined(coffSym);
} else if (coffSym.isWeakExternal()) {
symbols[i] = createUndefined(coffSym);
uint32_t tagIndex = coffSym.getAux<coff_aux_weak_external>()->TagIndex;
weakAliases.emplace_back(symbols[i], tagIndex);
} else if (Optional<Symbol *> optSym =
createDefined(coffSym, comdatDefs, prevailingComdat)) {
symbols[i] = *optSym;
if (config->mingw && prevailingComdat)
recordPrevailingSymbolForMingw(coffSym, prevailingSectionMap);
} else {
// createDefined() returns None if a symbol belongs to a section that
// was pending at the point when the symbol was read. This can happen in
// two cases:
// 1) section definition symbol for a comdat leader;
// 2) symbol belongs to a comdat section associated with another section.
// In both of these cases, we can expect the section to be resolved by
// the time we finish visiting the remaining symbols in the symbol
// table. So we postpone the handling of this symbol until that time.
pendingIndexes.push_back(i);
}
i += coffSym.getNumberOfAuxSymbols();
}
for (uint32_t i : pendingIndexes) {
COFFSymbolRef sym = check(coffObj->getSymbol(i));
if (const coff_aux_section_definition *def = sym.getSectionDefinition()) {
if (def->Selection == IMAGE_COMDAT_SELECT_ASSOCIATIVE)
readAssociativeDefinition(sym, def);
else if (config->mingw)
maybeAssociateSEHForMingw(sym, def, prevailingSectionMap);
}
if (sparseChunks[sym.getSectionNumber()] == pendingComdat) {
StringRef name;
coffObj->getSymbolName(sym, name);
log("comdat section " + name +
" without leader and unassociated, discarding");
continue;
}
symbols[i] = createRegular(sym);
}
for (auto &kv : weakAliases) {
Symbol *sym = kv.first;
uint32_t idx = kv.second;
checkAndSetWeakAlias(symtab, this, sym, symbols[idx]);
}
}
Symbol *ObjFile::createUndefined(COFFSymbolRef sym) {
StringRef name;
coffObj->getSymbolName(sym, name);
return symtab->addUndefined(name, this, sym.isWeakExternal());
}
void ObjFile::handleComdatSelection(COFFSymbolRef sym, COMDATType &selection,
bool &prevailing, DefinedRegular *leader) {
if (prevailing)
return;
// There's already an existing comdat for this symbol: `Leader`.
// Use the comdats's selection field to determine if the new
// symbol in `Sym` should be discarded, produce a duplicate symbol
// error, etc.
SectionChunk *leaderChunk = nullptr;
COMDATType leaderSelection = IMAGE_COMDAT_SELECT_ANY;
if (leader->data) {
leaderChunk = leader->getChunk();
leaderSelection = leaderChunk->selection;
} else {
// FIXME: comdats from LTO files don't know their selection; treat them
// as "any".
selection = leaderSelection;
}
if ((selection == IMAGE_COMDAT_SELECT_ANY &&
leaderSelection == IMAGE_COMDAT_SELECT_LARGEST) ||
(selection == IMAGE_COMDAT_SELECT_LARGEST &&
leaderSelection == IMAGE_COMDAT_SELECT_ANY)) {
// cl.exe picks "any" for vftables when building with /GR- and
// "largest" when building with /GR. To be able to link object files
// compiled with each flag, "any" and "largest" are merged as "largest".
leaderSelection = selection = IMAGE_COMDAT_SELECT_LARGEST;
}
// Other than that, comdat selections must match. This is a bit more
// strict than link.exe which allows merging "any" and "largest" if "any"
// is the first symbol the linker sees, and it allows merging "largest"
// with everything (!) if "largest" is the first symbol the linker sees.
// Making this symmetric independent of which selection is seen first
// seems better though.
// (This behavior matches ModuleLinker::getComdatResult().)
if (selection != leaderSelection) {
log(("conflicting comdat type for " + toString(*leader) + ": " +
Twine((int)leaderSelection) + " in " + toString(leader->getFile()) +
" and " + Twine((int)selection) + " in " + toString(this))
.str());
symtab->reportDuplicate(leader, this);
return;
}
switch (selection) {
case IMAGE_COMDAT_SELECT_NODUPLICATES:
symtab->reportDuplicate(leader, this);
break;
case IMAGE_COMDAT_SELECT_ANY:
// Nothing to do.
break;
case IMAGE_COMDAT_SELECT_SAME_SIZE:
if (leaderChunk->getSize() != getSection(sym)->SizeOfRawData)
symtab->reportDuplicate(leader, this);
break;
case IMAGE_COMDAT_SELECT_EXACT_MATCH: {
SectionChunk newChunk(this, getSection(sym));
// link.exe only compares section contents here and doesn't complain
// if the two comdat sections have e.g. different alignment.
// Match that.
if (leaderChunk->getContents() != newChunk.getContents())
symtab->reportDuplicate(leader, this);
break;
}
case IMAGE_COMDAT_SELECT_ASSOCIATIVE:
// createDefined() is never called for IMAGE_COMDAT_SELECT_ASSOCIATIVE.
// (This means lld-link doesn't produce duplicate symbol errors for
// associative comdats while link.exe does, but associate comdats
// are never extern in practice.)
llvm_unreachable("createDefined not called for associative comdats");
case IMAGE_COMDAT_SELECT_LARGEST:
if (leaderChunk->getSize() < getSection(sym)->SizeOfRawData) {
// Replace the existing comdat symbol with the new one.
StringRef name;
coffObj->getSymbolName(sym, name);
// FIXME: This is incorrect: With /opt:noref, the previous sections
// make it into the final executable as well. Correct handling would
// be to undo reading of the whole old section that's being replaced,
// or doing one pass that determines what the final largest comdat
// is for all IMAGE_COMDAT_SELECT_LARGEST comdats and then reading
// only the largest one.
replaceSymbol<DefinedRegular>(leader, this, name, /*IsCOMDAT*/ true,
/*IsExternal*/ true, sym.getGeneric(),
nullptr);
prevailing = true;
}
break;
case IMAGE_COMDAT_SELECT_NEWEST:
llvm_unreachable("should have been rejected earlier");
}
}
Optional<Symbol *> ObjFile::createDefined(
COFFSymbolRef sym,
std::vector<const coff_aux_section_definition *> &comdatDefs,
bool &prevailing) {
prevailing = false;
auto getName = [&]() {
StringRef s;
coffObj->getSymbolName(sym, s);
return s;
};
if (sym.isCommon()) {
auto *c = make<CommonChunk>(sym);
chunks.push_back(c);
return symtab->addCommon(this, getName(), sym.getValue(), sym.getGeneric(),
c);
}
if (sym.isAbsolute()) {
StringRef name = getName();
// Skip special symbols.
if (name == "@comp.id")
return nullptr;
if (name == "@feat.00") {
feat00Flags = sym.getValue();
return nullptr;
}
if (sym.isExternal())
return symtab->addAbsolute(name, sym);
return make<DefinedAbsolute>(name, sym);
}
int32_t sectionNumber = sym.getSectionNumber();
if (sectionNumber == llvm::COFF::IMAGE_SYM_DEBUG)
return nullptr;
if (llvm::COFF::isReservedSectionNumber(sectionNumber))
fatal(toString(this) + ": " + getName() +
" should not refer to special section " + Twine(sectionNumber));
if ((uint32_t)sectionNumber >= sparseChunks.size())
fatal(toString(this) + ": " + getName() +
" should not refer to non-existent section " + Twine(sectionNumber));
// Comdat handling.
// A comdat symbol consists of two symbol table entries.
// The first symbol entry has the name of the section (e.g. .text), fixed
// values for the other fields, and one auxilliary record.
// The second symbol entry has the name of the comdat symbol, called the
// "comdat leader".
// When this function is called for the first symbol entry of a comdat,
// it sets comdatDefs and returns None, and when it's called for the second
// symbol entry it reads comdatDefs and then sets it back to nullptr.
// Handle comdat leader.
if (const coff_aux_section_definition *def = comdatDefs[sectionNumber]) {
comdatDefs[sectionNumber] = nullptr;
DefinedRegular *leader;
if (sym.isExternal()) {
std::tie(leader, prevailing) =
symtab->addComdat(this, getName(), sym.getGeneric());
} else {
leader = make<DefinedRegular>(this, /*Name*/ "", /*IsCOMDAT*/ false,
/*IsExternal*/ false, sym.getGeneric());
prevailing = true;
}
if (def->Selection < (int)IMAGE_COMDAT_SELECT_NODUPLICATES ||
// Intentionally ends at IMAGE_COMDAT_SELECT_LARGEST: link.exe
// doesn't understand IMAGE_COMDAT_SELECT_NEWEST either.
def->Selection > (int)IMAGE_COMDAT_SELECT_LARGEST) {
fatal("unknown comdat type " + std::to_string((int)def->Selection) +
" for " + getName() + " in " + toString(this));
}
COMDATType selection = (COMDATType)def->Selection;
if (leader->isCOMDAT)
handleComdatSelection(sym, selection, prevailing, leader);
if (prevailing) {
SectionChunk *c = readSection(sectionNumber, def, getName());
sparseChunks[sectionNumber] = c;
c->sym = cast<DefinedRegular>(leader);
c->selection = selection;
cast<DefinedRegular>(leader)->data = &c->repl;
} else {
sparseChunks[sectionNumber] = nullptr;
}
return leader;
}
// Prepare to handle the comdat leader symbol by setting the section's
// ComdatDefs pointer if we encounter a non-associative comdat.
if (sparseChunks[sectionNumber] == pendingComdat) {
if (const coff_aux_section_definition *def = sym.getSectionDefinition()) {
if (def->Selection != IMAGE_COMDAT_SELECT_ASSOCIATIVE)
comdatDefs[sectionNumber] = def;
}
return None;
}
return createRegular(sym);
}
MachineTypes ObjFile::getMachineType() {
if (coffObj)
return static_cast<MachineTypes>(coffObj->getMachine());
return IMAGE_FILE_MACHINE_UNKNOWN;
}
ArrayRef<uint8_t> ObjFile::getDebugSection(StringRef secName) {
if (SectionChunk *sec = SectionChunk::findByName(debugChunks, secName))
return sec->consumeDebugMagic();
return {};
}
// OBJ files systematically store critical informations in a .debug$S stream,
// even if the TU was compiled with no debug info. At least two records are
// always there. S_OBJNAME stores a 32-bit signature, which is loaded into the
// PCHSignature member. S_COMPILE3 stores compile-time cmd-line flags. This is
// currently used to initialize the hotPatchable member.
void ObjFile::initializeFlags() {
ArrayRef<uint8_t> data = getDebugSection(".debug$S");
if (data.empty())
return;
DebugSubsectionArray subsections;
BinaryStreamReader reader(data, support::little);
ExitOnError exitOnErr;
exitOnErr(reader.readArray(subsections, data.size()));
for (const DebugSubsectionRecord &ss : subsections) {
if (ss.kind() != DebugSubsectionKind::Symbols)
continue;
unsigned offset = 0;
// Only parse the first two records. We are only looking for S_OBJNAME
// and S_COMPILE3, and they usually appear at the beginning of the
// stream.
for (unsigned i = 0; i < 2; ++i) {
Expected<CVSymbol> sym = readSymbolFromStream(ss.getRecordData(), offset);
if (!sym) {
consumeError(sym.takeError());
return;
}
if (sym->kind() == SymbolKind::S_COMPILE3) {
auto cs =
cantFail(SymbolDeserializer::deserializeAs<Compile3Sym>(sym.get()));
hotPatchable =
(cs.Flags & CompileSym3Flags::HotPatch) != CompileSym3Flags::None;
}
if (sym->kind() == SymbolKind::S_OBJNAME) {
auto objName = cantFail(SymbolDeserializer::deserializeAs<ObjNameSym>(
sym.get()));
pchSignature = objName.Signature;
}
offset += sym->length();
}
}
}
// Depending on the compilation flags, OBJs can refer to external files,
// necessary to merge this OBJ into the final PDB. We currently support two
// types of external files: Precomp/PCH OBJs, when compiling with /Yc and /Yu.
// And PDB type servers, when compiling with /Zi. This function extracts these
// dependencies and makes them available as a TpiSource interface (see
// DebugTypes.h). Both cases only happen with cl.exe: clang-cl produces regular
// output even with /Yc and /Yu and with /Zi.
void ObjFile::initializeDependencies() {
if (!config->debug)
return;
bool isPCH = false;
ArrayRef<uint8_t> data = getDebugSection(".debug$P");
if (!data.empty())
isPCH = true;
else
data = getDebugSection(".debug$T");
if (data.empty())
return;
CVTypeArray types;
BinaryStreamReader reader(data, support::little);
cantFail(reader.readArray(types, reader.getLength()));
CVTypeArray::Iterator firstType = types.begin();
if (firstType == types.end())
return;
debugTypes.emplace(types);
if (isPCH) {
debugTypesObj = makePrecompSource(this);
return;
}
if (firstType->kind() == LF_TYPESERVER2) {
TypeServer2Record ts = cantFail(
TypeDeserializer::deserializeAs<TypeServer2Record>(firstType->data()));
debugTypesObj = makeUseTypeServerSource(this, &ts);
return;
}
if (firstType->kind() == LF_PRECOMP) {
PrecompRecord precomp = cantFail(
TypeDeserializer::deserializeAs<PrecompRecord>(firstType->data()));
debugTypesObj = makeUsePrecompSource(this, &precomp);
return;
}
debugTypesObj = makeTpiSource(this);
}
StringRef ltrim1(StringRef s, const char *chars) {
if (!s.empty() && strchr(chars, s[0]))
return s.substr(1);
return s;
}
void ImportFile::parse() {
const char *buf = mb.getBufferStart();
const auto *hdr = reinterpret_cast<const coff_import_header *>(buf);
// Check if the total size is valid.
if (mb.getBufferSize() != sizeof(*hdr) + hdr->SizeOfData)
fatal("broken import library");
// Read names and create an __imp_ symbol.
StringRef name = saver.save(StringRef(buf + sizeof(*hdr)));
StringRef impName = saver.save("__imp_" + name);
const char *nameStart = buf + sizeof(coff_import_header) + name.size() + 1;
dllName = StringRef(nameStart);
StringRef extName;
switch (hdr->getNameType()) {
case IMPORT_ORDINAL:
extName = "";
break;
case IMPORT_NAME:
extName = name;
break;
case IMPORT_NAME_NOPREFIX:
extName = ltrim1(name, "?@_");
break;
case IMPORT_NAME_UNDECORATE:
extName = ltrim1(name, "?@_");
extName = extName.substr(0, extName.find('@'));
break;
}
this->hdr = hdr;
externalName = extName;
impSym = symtab->addImportData(impName, this);
// If this was a duplicate, we logged an error but may continue;
// in this case, impSym is nullptr.
if (!impSym)
return;
if (hdr->getType() == llvm::COFF::IMPORT_CONST)
static_cast<void>(symtab->addImportData(name, this));
// If type is function, we need to create a thunk which jump to an
// address pointed by the __imp_ symbol. (This allows you to call
// DLL functions just like regular non-DLL functions.)
if (hdr->getType() == llvm::COFF::IMPORT_CODE)
thunkSym = symtab->addImportThunk(
name, cast_or_null<DefinedImportData>(impSym), hdr->Machine);
}
BitcodeFile::BitcodeFile(MemoryBufferRef mb, StringRef archiveName,
uint64_t offsetInArchive)
: InputFile(BitcodeKind, mb) {
std::string path = mb.getBufferIdentifier().str();
if (config->thinLTOIndexOnly)
path = replaceThinLTOSuffix(mb.getBufferIdentifier());
// ThinLTO assumes that all MemoryBufferRefs given to it have a unique
// name. If two archives define two members with the same name, this
// causes a collision which result in only one of the objects being taken
// into consideration at LTO time (which very likely causes undefined
// symbols later in the link stage). So we append file offset to make
// filename unique.
MemoryBufferRef mbref(
mb.getBuffer(),
saver.save(archiveName + path +
(archiveName.empty() ? "" : utostr(offsetInArchive))));
obj = check(lto::InputFile::create(mbref));
}
void BitcodeFile::parse() {
std::vector<std::pair<Symbol *, bool>> comdat(obj->getComdatTable().size());
for (size_t i = 0; i != obj->getComdatTable().size(); ++i)
// FIXME: lto::InputFile doesn't keep enough data to do correct comdat
// selection handling.
comdat[i] = symtab->addComdat(this, saver.save(obj->getComdatTable()[i]));
for (const lto::InputFile::Symbol &objSym : obj->symbols()) {
StringRef symName = saver.save(objSym.getName());
int comdatIndex = objSym.getComdatIndex();
Symbol *sym;
if (objSym.isUndefined()) {
sym = symtab->addUndefined(symName, this, false);
} else if (objSym.isCommon()) {
sym = symtab->addCommon(this, symName, objSym.getCommonSize());
} else if (objSym.isWeak() && objSym.isIndirect()) {
// Weak external.
sym = symtab->addUndefined(symName, this, true);
std::string fallback = objSym.getCOFFWeakExternalFallback();
Symbol *alias = symtab->addUndefined(saver.save(fallback));
checkAndSetWeakAlias(symtab, this, sym, alias);
} else if (comdatIndex != -1) {
if (symName == obj->getComdatTable()[comdatIndex])
sym = comdat[comdatIndex].first;
else if (comdat[comdatIndex].second)
sym = symtab->addRegular(this, symName);
else
sym = symtab->addUndefined(symName, this, false);
} else {
sym = symtab->addRegular(this, symName);
}
symbols.push_back(sym);
if (objSym.isUsed())
config->gcroot.push_back(sym);
}
directives = obj->getCOFFLinkerOpts();
}
MachineTypes BitcodeFile::getMachineType() {
switch (Triple(obj->getTargetTriple()).getArch()) {
case Triple::x86_64:
return AMD64;
case Triple::x86:
return I386;
case Triple::arm:
return ARMNT;
case Triple::aarch64:
return ARM64;
default:
return IMAGE_FILE_MACHINE_UNKNOWN;
}
}
std::string replaceThinLTOSuffix(StringRef path) {
StringRef suffix = config->thinLTOObjectSuffixReplace.first;
StringRef repl = config->thinLTOObjectSuffixReplace.second;
if (path.consume_back(suffix))
return (path + repl).str();
return path;
}
} // namespace coff
} // namespace lld
// Returns the last element of a path, which is supposed to be a filename.
static StringRef getBasename(StringRef path) {
return sys::path::filename(path, sys::path::Style::windows);
}
// Returns a string in the format of "foo.obj" or "foo.obj(bar.lib)".
std::string lld::toString(const coff::InputFile *file) {
if (!file)
return "<internal>";
if (file->parentName.empty() || file->kind() == coff::InputFile::ImportKind)
return file->getName();
return (getBasename(file->parentName) + "(" + getBasename(file->getName()) +
")")
.str();
}

View File

@@ -1,321 +0,0 @@
//===- InputFiles.h ---------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLD_COFF_INPUT_FILES_H
#define LLD_COFF_INPUT_FILES_H
#include "Config.h"
#include "lld/Common/LLVM.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/DebugInfo/CodeView/TypeRecord.h"
#include "llvm/LTO/LTO.h"
#include "llvm/Object/Archive.h"
#include "llvm/Object/COFF.h"
#include "llvm/Support/StringSaver.h"
#include <memory>
#include <set>
#include <vector>
namespace llvm {
namespace pdb {
class DbiModuleDescriptorBuilder;
}
}
namespace lld {
namespace coff {
std::vector<MemoryBufferRef> getArchiveMembers(llvm::object::Archive *file);
using llvm::COFF::IMAGE_FILE_MACHINE_UNKNOWN;
using llvm::COFF::MachineTypes;
using llvm::object::Archive;
using llvm::object::COFFObjectFile;
using llvm::object::COFFSymbolRef;
using llvm::object::coff_import_header;
using llvm::object::coff_section;
class Chunk;
class Defined;
class DefinedImportData;
class DefinedImportThunk;
class DefinedRegular;
class Lazy;
class SectionChunk;
class Symbol;
class Undefined;
class TpiSource;
// The root class of input files.
class InputFile {
public:
enum Kind { ArchiveKind, ObjectKind, ImportKind, BitcodeKind };
Kind kind() const { return fileKind; }
virtual ~InputFile() {}
// Returns the filename.
StringRef getName() const { return mb.getBufferIdentifier(); }
// Reads a file (the constructor doesn't do that).
virtual void parse() = 0;
// Returns the CPU type this file was compiled to.
virtual MachineTypes getMachineType() { return IMAGE_FILE_MACHINE_UNKNOWN; }
MemoryBufferRef mb;
// An archive file name if this file is created from an archive.
StringRef parentName;
// Returns .drectve section contents if exist.
StringRef getDirectives() { return directives; }
protected:
InputFile(Kind k, MemoryBufferRef m) : mb(m), fileKind(k) {}
StringRef directives;
private:
const Kind fileKind;
};
// .lib or .a file.
class ArchiveFile : public InputFile {
public:
explicit ArchiveFile(MemoryBufferRef m);
static bool classof(const InputFile *f) { return f->kind() == ArchiveKind; }
void parse() override;
// Enqueues an archive member load for the given symbol. If we've already
// enqueued a load for the same archive member, this function does nothing,
// which ensures that we don't load the same member more than once.
void addMember(const Archive::Symbol &sym);
private:
std::unique_ptr<Archive> file;
llvm::DenseSet<uint64_t> seen;
};
// .obj or .o file. This may be a member of an archive file.
class ObjFile : public InputFile {
public:
explicit ObjFile(MemoryBufferRef m) : InputFile(ObjectKind, m) {}
static bool classof(const InputFile *f) { return f->kind() == ObjectKind; }
void parse() override;
MachineTypes getMachineType() override;
ArrayRef<Chunk *> getChunks() { return chunks; }
ArrayRef<SectionChunk *> getDebugChunks() { return debugChunks; }
ArrayRef<SectionChunk *> getSXDataChunks() { return sXDataChunks; }
ArrayRef<SectionChunk *> getGuardFidChunks() { return guardFidChunks; }
ArrayRef<SectionChunk *> getGuardLJmpChunks() { return guardLJmpChunks; }
ArrayRef<Symbol *> getSymbols() { return symbols; }
ArrayRef<uint8_t> getDebugSection(StringRef secName);
// Returns a Symbol object for the symbolIndex'th symbol in the
// underlying object file.
Symbol *getSymbol(uint32_t symbolIndex) {
return symbols[symbolIndex];
}
// Returns the underlying COFF file.
COFFObjectFile *getCOFFObj() { return coffObj.get(); }
// Add a symbol for a range extension thunk. Return the new symbol table
// index. This index can be used to modify a relocation.
uint32_t addRangeThunkSymbol(Symbol *thunk) {
symbols.push_back(thunk);
return symbols.size() - 1;
}
static std::vector<ObjFile *> instances;
// Flags in the absolute @feat.00 symbol if it is present. These usually
// indicate if an object was compiled with certain security features enabled
// like stack guard, safeseh, /guard:cf, or other things.
uint32_t feat00Flags = 0;
// True if this object file is compatible with SEH. COFF-specific and
// x86-only. COFF spec 5.10.1. The .sxdata section.
bool hasSafeSEH() { return feat00Flags & 0x1; }
// True if this file was compiled with /guard:cf.
bool hasGuardCF() { return feat00Flags & 0x800; }
// Pointer to the PDB module descriptor builder. Various debug info records
// will reference object files by "module index", which is here. Things like
// source files and section contributions are also recorded here. Will be null
// if we are not producing a PDB.
llvm::pdb::DbiModuleDescriptorBuilder *moduleDBI = nullptr;
const coff_section *addrsigSec = nullptr;
// When using Microsoft precompiled headers, this is the PCH's key.
// The same key is used by both the precompiled object, and objects using the
// precompiled object. Any difference indicates out-of-date objects.
llvm::Optional<uint32_t> pchSignature;
// Whether this is an object file created from .res files.
bool isResourceObjFile = false;
// Whether this file was compiled with /hotpatch.
bool hotPatchable = false;
// Whether the object was already merged into the final PDB.
bool mergedIntoPDB = false;
// If the OBJ has a .debug$T stream, this tells how it will be handled.
TpiSource *debugTypesObj = nullptr;
// The .debug$T stream if there's one.
llvm::Optional<llvm::codeview::CVTypeArray> debugTypes;
private:
const coff_section* getSection(uint32_t i);
const coff_section *getSection(COFFSymbolRef sym) {
return getSection(sym.getSectionNumber());
}
void initializeChunks();
void initializeSymbols();
void initializeFlags();
void initializeDependencies();
SectionChunk *
readSection(uint32_t sectionNumber,
const llvm::object::coff_aux_section_definition *def,
StringRef leaderName);
void readAssociativeDefinition(
COFFSymbolRef coffSym,
const llvm::object::coff_aux_section_definition *def);
void readAssociativeDefinition(
COFFSymbolRef coffSym,
const llvm::object::coff_aux_section_definition *def,
uint32_t parentSection);
void recordPrevailingSymbolForMingw(
COFFSymbolRef coffSym,
llvm::DenseMap<StringRef, uint32_t> &prevailingSectionMap);
void maybeAssociateSEHForMingw(
COFFSymbolRef sym, const llvm::object::coff_aux_section_definition *def,
const llvm::DenseMap<StringRef, uint32_t> &prevailingSectionMap);
// Given a new symbol Sym with comdat selection Selection, if the new
// symbol is not (yet) Prevailing and the existing comdat leader set to
// Leader, emits a diagnostic if the new symbol and its selection doesn't
// match the existing symbol and its selection. If either old or new
// symbol have selection IMAGE_COMDAT_SELECT_LARGEST, Sym might replace
// the existing leader. In that case, Prevailing is set to true.
void handleComdatSelection(COFFSymbolRef sym,
llvm::COFF::COMDATType &selection,
bool &prevailing, DefinedRegular *leader);
llvm::Optional<Symbol *>
createDefined(COFFSymbolRef sym,
std::vector<const llvm::object::coff_aux_section_definition *>
&comdatDefs,
bool &prevailingComdat);
Symbol *createRegular(COFFSymbolRef sym);
Symbol *createUndefined(COFFSymbolRef sym);
std::unique_ptr<COFFObjectFile> coffObj;
// List of all chunks defined by this file. This includes both section
// chunks and non-section chunks for common symbols.
std::vector<Chunk *> chunks;
// CodeView debug info sections.
std::vector<SectionChunk *> debugChunks;
// Chunks containing symbol table indices of exception handlers. Only used for
// 32-bit x86.
std::vector<SectionChunk *> sXDataChunks;
// Chunks containing symbol table indices of address taken symbols and longjmp
// targets. These are not linked into the final binary when /guard:cf is set.
std::vector<SectionChunk *> guardFidChunks;
std::vector<SectionChunk *> guardLJmpChunks;
// This vector contains the same chunks as Chunks, but they are
// indexed such that you can get a SectionChunk by section index.
// Nonexistent section indices are filled with null pointers.
// (Because section number is 1-based, the first slot is always a
// null pointer.)
std::vector<SectionChunk *> sparseChunks;
// This vector contains a list of all symbols defined or referenced by this
// file. They are indexed such that you can get a Symbol by symbol
// index. Nonexistent indices (which are occupied by auxiliary
// symbols in the real symbol table) are filled with null pointers.
std::vector<Symbol *> symbols;
};
// This type represents import library members that contain DLL names
// and symbols exported from the DLLs. See Microsoft PE/COFF spec. 7
// for details about the format.
class ImportFile : public InputFile {
public:
explicit ImportFile(MemoryBufferRef m) : InputFile(ImportKind, m) {}
static bool classof(const InputFile *f) { return f->kind() == ImportKind; }
static std::vector<ImportFile *> instances;
Symbol *impSym = nullptr;
Symbol *thunkSym = nullptr;
std::string dllName;
private:
void parse() override;
public:
StringRef externalName;
const coff_import_header *hdr;
Chunk *location = nullptr;
// We want to eliminate dllimported symbols if no one actually refers them.
// These "Live" bits are used to keep track of which import library members
// are actually in use.
//
// If the Live bit is turned off by MarkLive, Writer will ignore dllimported
// symbols provided by this import library member. We also track whether the
// imported symbol is used separately from whether the thunk is used in order
// to avoid creating unnecessary thunks.
bool live = !config->doGC;
bool thunkLive = !config->doGC;
};
// Used for LTO.
class BitcodeFile : public InputFile {
public:
BitcodeFile(MemoryBufferRef mb, StringRef archiveName,
uint64_t offsetInArchive);
static bool classof(const InputFile *f) { return f->kind() == BitcodeKind; }
ArrayRef<Symbol *> getSymbols() { return symbols; }
MachineTypes getMachineType() override;
static std::vector<BitcodeFile *> instances;
std::unique_ptr<llvm::lto::InputFile> obj;
private:
void parse() override;
std::vector<Symbol *> symbols;
};
std::string replaceThinLTOSuffix(StringRef path);
} // namespace coff
std::string toString(const coff::InputFile *file);
} // namespace lld
#endif

206
deps/lld/COFF/LTO.cpp vendored
View File

@@ -1,206 +0,0 @@
//===- LTO.cpp ------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "LTO.h"
#include "Config.h"
#include "InputFiles.h"
#include "Symbols.h"
#include "lld/Common/Args.h"
#include "lld/Common/ErrorHandler.h"
#include "lld/Common/Strings.h"
#include "lld/Common/TargetOptionsCommandFlags.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/ADT/Twine.h"
#include "llvm/Bitcode/BitcodeWriter.h"
#include "llvm/IR/DiagnosticPrinter.h"
#include "llvm/LTO/Caching.h"
#include "llvm/LTO/Config.h"
#include "llvm/LTO/LTO.h"
#include "llvm/Object/SymbolicFile.h"
#include "llvm/Support/CodeGen.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/MemoryBuffer.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
#include <cstddef>
#include <memory>
#include <string>
#include <system_error>
#include <vector>
using namespace llvm;
using namespace llvm::object;
using namespace lld;
using namespace lld::coff;
// Creates an empty file to and returns a raw_fd_ostream to write to it.
static std::unique_ptr<raw_fd_ostream> openFile(StringRef file) {
std::error_code ec;
auto ret =
llvm::make_unique<raw_fd_ostream>(file, ec, sys::fs::OpenFlags::F_None);
if (ec) {
error("cannot open " + file + ": " + ec.message());
return nullptr;
}
return ret;
}
static std::string getThinLTOOutputFile(StringRef path) {
return lto::getThinLTOOutputFile(path,
config->thinLTOPrefixReplace.first,
config->thinLTOPrefixReplace.second);
}
static lto::Config createConfig() {
lto::Config c;
c.Options = initTargetOptionsFromCodeGenFlags();
// Always emit a section per function/datum with LTO. LLVM LTO should get most
// of the benefit of linker GC, but there are still opportunities for ICF.
c.Options.FunctionSections = true;
c.Options.DataSections = true;
// Use static reloc model on 32-bit x86 because it usually results in more
// compact code, and because there are also known code generation bugs when
// using the PIC model (see PR34306).
if (config->machine == COFF::IMAGE_FILE_MACHINE_I386)
c.RelocModel = Reloc::Static;
else
c.RelocModel = Reloc::PIC_;
c.DisableVerify = true;
c.DiagHandler = diagnosticHandler;
c.OptLevel = config->ltoo;
c.CPU = getCPUStr();
c.MAttrs = getMAttrs();
c.CGOptLevel = args::getCGOptLevel(config->ltoo);
if (config->saveTemps)
checkError(c.addSaveTemps(std::string(config->outputFile) + ".",
/*UseInputModulePath*/ true));
return c;
}
BitcodeCompiler::BitcodeCompiler() {
// Initialize indexFile.
if (!config->thinLTOIndexOnlyArg.empty())
indexFile = openFile(config->thinLTOIndexOnlyArg);
// Initialize ltoObj.
lto::ThinBackend backend;
if (config->thinLTOIndexOnly) {
auto OnIndexWrite = [&](StringRef S) { thinIndices.erase(S); };
backend = lto::createWriteIndexesThinBackend(
config->thinLTOPrefixReplace.first, config->thinLTOPrefixReplace.second,
config->thinLTOEmitImportsFiles, indexFile.get(), OnIndexWrite);
} else if (config->thinLTOJobs != 0) {
backend = lto::createInProcessThinBackend(config->thinLTOJobs);
}
ltoObj = llvm::make_unique<lto::LTO>(createConfig(), backend,
config->ltoPartitions);
}
BitcodeCompiler::~BitcodeCompiler() = default;
static void undefine(Symbol *s) { replaceSymbol<Undefined>(s, s->getName()); }
void BitcodeCompiler::add(BitcodeFile &f) {
lto::InputFile &obj = *f.obj;
unsigned symNum = 0;
std::vector<Symbol *> symBodies = f.getSymbols();
std::vector<lto::SymbolResolution> resols(symBodies.size());
if (config->thinLTOIndexOnly)
thinIndices.insert(obj.getName());
// Provide a resolution to the LTO API for each symbol.
for (const lto::InputFile::Symbol &objSym : obj.symbols()) {
Symbol *sym = symBodies[symNum];
lto::SymbolResolution &r = resols[symNum];
++symNum;
// Ideally we shouldn't check for SF_Undefined but currently IRObjectFile
// reports two symbols for module ASM defined. Without this check, lld
// flags an undefined in IR with a definition in ASM as prevailing.
// Once IRObjectFile is fixed to report only one symbol this hack can
// be removed.
r.Prevailing = !objSym.isUndefined() && sym->getFile() == &f;
r.VisibleToRegularObj = sym->isUsedInRegularObj;
if (r.Prevailing)
undefine(sym);
}
checkError(ltoObj->add(std::move(f.obj), resols));
}
// Merge all the bitcode files we have seen, codegen the result
// and return the resulting objects.
std::vector<StringRef> BitcodeCompiler::compile() {
unsigned maxTasks = ltoObj->getMaxTasks();
buf.resize(maxTasks);
files.resize(maxTasks);
// The /lldltocache option specifies the path to a directory in which to cache
// native object files for ThinLTO incremental builds. If a path was
// specified, configure LTO to use it as the cache directory.
lto::NativeObjectCache cache;
if (!config->ltoCache.empty())
cache = check(lto::localCache(
config->ltoCache, [&](size_t task, std::unique_ptr<MemoryBuffer> mb) {
files[task] = std::move(mb);
}));
checkError(ltoObj->run(
[&](size_t task) {
return llvm::make_unique<lto::NativeObjectStream>(
llvm::make_unique<raw_svector_ostream>(buf[task]));
},
cache));
// Emit empty index files for non-indexed files
for (StringRef s : thinIndices) {
std::string path = getThinLTOOutputFile(s);
openFile(path + ".thinlto.bc");
if (config->thinLTOEmitImportsFiles)
openFile(path + ".imports");
}
// ThinLTO with index only option is required to generate only the index
// files. After that, we exit from linker and ThinLTO backend runs in a
// distributed environment.
if (config->thinLTOIndexOnly) {
if (indexFile)
indexFile->close();
return {};
}
if (!config->ltoCache.empty())
pruneCache(config->ltoCache, config->ltoCachePolicy);
std::vector<StringRef> ret;
for (unsigned i = 0; i != maxTasks; ++i) {
if (buf[i].empty())
continue;
if (config->saveTemps) {
if (i == 0)
saveBuffer(buf[i], config->outputFile + ".lto.obj");
else
saveBuffer(buf[i], config->outputFile + Twine(i) + ".lto.obj");
}
ret.emplace_back(buf[i].data(), buf[i].size());
}
for (std::unique_ptr<MemoryBuffer> &file : files)
if (file)
ret.push_back(file->getBuffer());
return ret;
}

60
deps/lld/COFF/LTO.h vendored
View File

@@ -1,60 +0,0 @@
//===- LTO.h ----------------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file provides a way to combine bitcode files into one COFF
// file by compiling them using LLVM.
//
// If LTO is in use, your input files are not in regular COFF files
// but instead LLVM bitcode files. In that case, the linker has to
// convert bitcode files into the native format so that we can create
// a COFF file that contains native code. This file provides that
// functionality.
//
//===----------------------------------------------------------------------===//
#ifndef LLD_COFF_LTO_H
#define LLD_COFF_LTO_H
#include "lld/Common/LLVM.h"
#include "llvm/ADT/DenseSet.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Support/raw_ostream.h"
#include <memory>
#include <vector>
namespace llvm {
namespace lto {
class LTO;
}
}
namespace lld {
namespace coff {
class BitcodeFile;
class InputFile;
class BitcodeCompiler {
public:
BitcodeCompiler();
~BitcodeCompiler();
void add(BitcodeFile &f);
std::vector<StringRef> compile();
private:
std::unique_ptr<llvm::lto::LTO> ltoObj;
std::vector<SmallString<0>> buf;
std::vector<std::unique_ptr<MemoryBuffer>> files;
std::unique_ptr<llvm::raw_fd_ostream> indexFile;
llvm::DenseSet<StringRef> thinIndices;
};
}
}
#endif

View File

@@ -1,124 +0,0 @@
//===- MapFile.cpp --------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file implements the /lldmap option. It shows lists in order and
// hierarchically the output sections, input sections, input files and
// symbol:
//
// Address Size Align Out File Symbol
// 00201000 00000015 4 .text
// 00201000 0000000e 4 test.o:(.text)
// 0020100e 00000000 0 local
// 00201005 00000000 0 f(int)
//
//===----------------------------------------------------------------------===//
#include "MapFile.h"
#include "SymbolTable.h"
#include "Symbols.h"
#include "Writer.h"
#include "lld/Common/ErrorHandler.h"
#include "lld/Common/Threads.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
using namespace llvm::object;
using namespace lld;
using namespace lld::coff;
using SymbolMapTy =
DenseMap<const SectionChunk *, SmallVector<DefinedRegular *, 4>>;
static const std::string indent8 = " "; // 8 spaces
static const std::string indent16 = " "; // 16 spaces
// Print out the first three columns of a line.
static void writeHeader(raw_ostream &os, uint64_t addr, uint64_t size,
uint64_t align) {
os << format("%08llx %08llx %5lld ", addr, size, align);
}
// Returns a list of all symbols that we want to print out.
static std::vector<DefinedRegular *> getSymbols() {
std::vector<DefinedRegular *> v;
for (ObjFile *file : ObjFile::instances)
for (Symbol *b : file->getSymbols())
if (auto *sym = dyn_cast_or_null<DefinedRegular>(b))
if (sym && !sym->getCOFFSymbol().isSectionDefinition())
v.push_back(sym);
return v;
}
// Returns a map from sections to their symbols.
static SymbolMapTy getSectionSyms(ArrayRef<DefinedRegular *> syms) {
SymbolMapTy ret;
for (DefinedRegular *s : syms)
ret[s->getChunk()].push_back(s);
// Sort symbols by address.
for (auto &it : ret) {
SmallVectorImpl<DefinedRegular *> &v = it.second;
std::sort(v.begin(), v.end(), [](DefinedRegular *a, DefinedRegular *b) {
return a->getRVA() < b->getRVA();
});
}
return ret;
}
// Construct a map from symbols to their stringified representations.
static DenseMap<DefinedRegular *, std::string>
getSymbolStrings(ArrayRef<DefinedRegular *> syms) {
std::vector<std::string> str(syms.size());
parallelForEachN((size_t)0, syms.size(), [&](size_t i) {
raw_string_ostream os(str[i]);
writeHeader(os, syms[i]->getRVA(), 0, 0);
os << indent16 << toString(*syms[i]);
});
DenseMap<DefinedRegular *, std::string> ret;
for (size_t i = 0, e = syms.size(); i < e; ++i)
ret[syms[i]] = std::move(str[i]);
return ret;
}
void coff::writeMapFile(ArrayRef<OutputSection *> outputSections) {
if (config->mapFile.empty())
return;
std::error_code ec;
raw_fd_ostream os(config->mapFile, ec, sys::fs::F_None);
if (ec)
fatal("cannot open " + config->mapFile + ": " + ec.message());
// Collect symbol info that we want to print out.
std::vector<DefinedRegular *> syms = getSymbols();
SymbolMapTy sectionSyms = getSectionSyms(syms);
DenseMap<DefinedRegular *, std::string> symStr = getSymbolStrings(syms);
// Print out the header line.
os << "Address Size Align Out In Symbol\n";
// Print out file contents.
for (OutputSection *sec : outputSections) {
writeHeader(os, sec->getRVA(), sec->getVirtualSize(), /*align=*/pageSize);
os << sec->name << '\n';
for (Chunk *c : sec->chunks) {
auto *sc = dyn_cast<SectionChunk>(c);
if (!sc)
continue;
writeHeader(os, sc->getRVA(), sc->getSize(), sc->getAlignment());
os << indent8 << sc->file->getName() << ":(" << sc->getSectionName()
<< ")\n";
for (DefinedRegular *sym : sectionSyms[sc])
os << symStr[sym] << '\n';
}
}
}

View File

@@ -1,21 +0,0 @@
//===- MapFile.h ------------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLD_COFF_MAPFILE_H
#define LLD_COFF_MAPFILE_H
#include "llvm/ADT/ArrayRef.h"
namespace lld {
namespace coff {
class OutputSection;
void writeMapFile(llvm::ArrayRef<OutputSection *> outputSections);
}
}
#endif

View File

@@ -1,73 +0,0 @@
//===- MarkLive.cpp -------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "Chunks.h"
#include "Symbols.h"
#include "lld/Common/Timer.h"
#include "llvm/ADT/STLExtras.h"
#include <vector>
namespace lld {
namespace coff {
static Timer gctimer("GC", Timer::root());
// Set live bit on for each reachable chunk. Unmarked (unreachable)
// COMDAT chunks will be ignored by Writer, so they will be excluded
// from the final output.
void markLive(ArrayRef<Chunk *> chunks) {
ScopedTimer t(gctimer);
// We build up a worklist of sections which have been marked as live. We only
// push into the worklist when we discover an unmarked section, and we mark
// as we push, so sections never appear twice in the list.
SmallVector<SectionChunk *, 256> worklist;
// COMDAT section chunks are dead by default. Add non-COMDAT chunks.
for (Chunk *c : chunks)
if (auto *sc = dyn_cast<SectionChunk>(c))
if (sc->live)
worklist.push_back(sc);
auto enqueue = [&](SectionChunk *c) {
if (c->live)
return;
c->live = true;
worklist.push_back(c);
};
auto addSym = [&](Symbol *b) {
if (auto *sym = dyn_cast<DefinedRegular>(b))
enqueue(sym->getChunk());
else if (auto *sym = dyn_cast<DefinedImportData>(b))
sym->file->live = true;
else if (auto *sym = dyn_cast<DefinedImportThunk>(b))
sym->wrappedSym->file->live = sym->wrappedSym->file->thunkLive = true;
};
// Add GC root chunks.
for (Symbol *b : config->gcroot)
addSym(b);
while (!worklist.empty()) {
SectionChunk *sc = worklist.pop_back_val();
assert(sc->live && "We mark as live when pushing onto the worklist!");
// Mark all symbols listed in the relocation table for this section.
for (Symbol *b : sc->symbols())
if (b)
addSym(b);
// Mark associative sections if any.
for (SectionChunk &c : sc->children())
enqueue(&c);
}
}
}
}

View File

@@ -1,25 +0,0 @@
//===- MarkLive.h -----------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLD_COFF_MARKLIVE_H
#define LLD_COFF_MARKLIVE_H
#include "lld/Common/LLVM.h"
#include "llvm/ADT/ArrayRef.h"
namespace lld {
namespace coff {
class Chunk;
void markLive(ArrayRef<Chunk *> chunks);
} // namespace coff
} // namespace lld
#endif // LLD_COFF_MARKLIVE_H

View File

@@ -1,166 +0,0 @@
//===- MinGW.cpp ----------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "MinGW.h"
#include "SymbolTable.h"
#include "lld/Common/ErrorHandler.h"
#include "llvm/Object/COFF.h"
#include "llvm/Support/Path.h"
#include "llvm/Support/raw_ostream.h"
using namespace lld;
using namespace lld::coff;
using namespace llvm;
using namespace llvm::COFF;
AutoExporter::AutoExporter() {
excludeLibs = {
"libgcc",
"libgcc_s",
"libstdc++",
"libmingw32",
"libmingwex",
"libg2c",
"libsupc++",
"libobjc",
"libgcj",
"libclang_rt.builtins",
"libclang_rt.builtins-aarch64",
"libclang_rt.builtins-arm",
"libclang_rt.builtins-i386",
"libclang_rt.builtins-x86_64",
"libc++",
"libc++abi",
"libunwind",
"libmsvcrt",
"libucrtbase",
};
excludeObjects = {
"crt0.o", "crt1.o", "crt1u.o", "crt2.o", "crt2u.o", "dllcrt1.o",
"dllcrt2.o", "gcrt0.o", "gcrt1.o", "gcrt2.o", "crtbegin.o", "crtend.o",
};
excludeSymbolPrefixes = {
// Import symbols
"__imp_",
"__IMPORT_DESCRIPTOR_",
// Extra import symbols from GNU import libraries
"__nm_",
// C++ symbols
"__rtti_",
"__builtin_",
// Artifical symbols such as .refptr
".",
};
excludeSymbolSuffixes = {
"_iname",
"_NULL_THUNK_DATA",
};
if (config->machine == I386) {
excludeSymbols = {
"__NULL_IMPORT_DESCRIPTOR",
"__pei386_runtime_relocator",
"_do_pseudo_reloc",
"_impure_ptr",
"__impure_ptr",
"__fmode",
"_environ",
"___dso_handle",
// These are the MinGW names that differ from the standard
// ones (lacking an extra underscore).
"_DllMain@12",
"_DllEntryPoint@12",
"_DllMainCRTStartup@12",
};
excludeSymbolPrefixes.insert("__head_");
} else {
excludeSymbols = {
"__NULL_IMPORT_DESCRIPTOR",
"_pei386_runtime_relocator",
"do_pseudo_reloc",
"impure_ptr",
"_impure_ptr",
"_fmode",
"environ",
"__dso_handle",
// These are the MinGW names that differ from the standard
// ones (lacking an extra underscore).
"DllMain",
"DllEntryPoint",
"DllMainCRTStartup",
};
excludeSymbolPrefixes.insert("_head_");
}
}
void AutoExporter::addWholeArchive(StringRef path) {
StringRef libName = sys::path::filename(path);
// Drop the file extension, to match the processing below.
libName = libName.substr(0, libName.rfind('.'));
excludeLibs.erase(libName);
}
bool AutoExporter::shouldExport(Defined *sym) const {
if (!sym || !sym->isLive() || !sym->getChunk())
return false;
// Only allow the symbol kinds that make sense to export; in particular,
// disallow import symbols.
if (!isa<DefinedRegular>(sym) && !isa<DefinedCommon>(sym))
return false;
if (excludeSymbols.count(sym->getName()))
return false;
for (StringRef prefix : excludeSymbolPrefixes.keys())
if (sym->getName().startswith(prefix))
return false;
for (StringRef suffix : excludeSymbolSuffixes.keys())
if (sym->getName().endswith(suffix))
return false;
// If a corresponding __imp_ symbol exists and is defined, don't export it.
if (symtab->find(("__imp_" + sym->getName()).str()))
return false;
// Check that file is non-null before dereferencing it, symbols not
// originating in regular object files probably shouldn't be exported.
if (!sym->getFile())
return false;
StringRef libName = sys::path::filename(sym->getFile()->parentName);
// Drop the file extension.
libName = libName.substr(0, libName.rfind('.'));
if (!libName.empty())
return !excludeLibs.count(libName);
StringRef fileName = sys::path::filename(sym->getFile()->getName());
return !excludeObjects.count(fileName);
}
void coff::writeDefFile(StringRef name) {
std::error_code ec;
raw_fd_ostream os(name, ec, sys::fs::F_None);
if (ec)
fatal("cannot open " + name + ": " + ec.message());
os << "EXPORTS\n";
for (Export &e : config->exports) {
os << " " << e.exportName << " "
<< "@" << e.ordinal;
if (auto *def = dyn_cast_or_null<Defined>(e.sym)) {
if (def && def->getChunk() &&
!(def->getChunk()->getOutputCharacteristics() & IMAGE_SCN_MEM_EXECUTE))
os << " DATA";
}
os << "\n";
}
}

41
deps/lld/COFF/MinGW.h vendored
View File

@@ -1,41 +0,0 @@
//===- MinGW.h --------------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLD_COFF_MINGW_H
#define LLD_COFF_MINGW_H
#include "Config.h"
#include "Symbols.h"
#include "lld/Common/LLVM.h"
namespace lld {
namespace coff {
// Logic for deciding what symbols to export, when exporting all
// symbols for MinGW.
class AutoExporter {
public:
AutoExporter();
void addWholeArchive(StringRef path);
llvm::StringSet<> excludeSymbols;
llvm::StringSet<> excludeSymbolPrefixes;
llvm::StringSet<> excludeSymbolSuffixes;
llvm::StringSet<> excludeLibs;
llvm::StringSet<> excludeObjects;
bool shouldExport(Defined *sym) const;
};
void writeDefFile(StringRef name);
} // namespace coff
} // namespace lld
#endif

View File

@@ -1,225 +0,0 @@
include "llvm/Option/OptParser.td"
// link.exe accepts options starting with either a dash or a slash.
// Flag that takes no arguments.
class F<string name> : Flag<["/", "-", "/?", "-?"], name>;
// Flag that takes one argument after ":".
class P<string name, string help> :
Joined<["/", "-", "/?", "-?"], name#":">, HelpText<help>;
// Boolean flag which can be suffixed by ":no". Using it unsuffixed turns the
// flag on and using it suffixed by ":no" turns it off.
multiclass B<string name, string help_on, string help_off> {
def "" : F<name>, HelpText<help_on>;
def _no : F<name#":no">, HelpText<help_off>;
}
def align : P<"align", "Section alignment">;
def aligncomm : P<"aligncomm", "Set common symbol alignment">;
def alternatename : P<"alternatename", "Define weak alias">;
def base : P<"base", "Base address of the program">;
def color_diagnostics: Flag<["--"], "color-diagnostics">,
HelpText<"Use colors in diagnostics">;
def color_diagnostics_eq: Joined<["--"], "color-diagnostics=">,
HelpText<"Use colors in diagnostics; one of 'always', 'never', 'auto'">;
def defaultlib : P<"defaultlib", "Add the library to the list of input files">;
def delayload : P<"delayload", "Delay loaded DLL name">;
def entry : P<"entry", "Name of entry point symbol">;
def errorlimit : P<"errorlimit",
"Maximum number of errors to emit before stopping (0 = no limit)">;
def export : P<"export", "Export a function">;
// No help text because /failifmismatch is not intended to be used by the user.
def failifmismatch : P<"failifmismatch", "">;
def filealign : P<"filealign", "Section alignment in the output file">;
def functionpadmin : F<"functionpadmin">;
def functionpadmin_opt : P<"functionpadmin", "Prepares an image for hotpatching">;
def guard : P<"guard", "Control flow guard">;
def heap : P<"heap", "Size of the heap">;
def ignore : P<"ignore", "Specify warning codes to ignore">;
def implib : P<"implib", "Import library name">;
def lib : F<"lib">,
HelpText<"Act like lib.exe; must be first argument if present">;
def libpath : P<"libpath", "Additional library search path">;
def linkrepro : P<"linkrepro", "Dump linker invocation and input files for debugging">;
def lldltocache : P<"lldltocache", "Path to ThinLTO cached object file directory">;
def lldltocachepolicy : P<"lldltocachepolicy", "Pruning policy for the ThinLTO cache">;
def lldsavetemps : F<"lldsavetemps">,
HelpText<"Save temporary files instead of deleting them">;
def machine : P<"machine", "Specify target platform">;
def merge : P<"merge", "Combine sections">;
def mllvm : P<"mllvm", "Options to pass to LLVM">;
def nodefaultlib : P<"nodefaultlib", "Remove a default library">;
def opt : P<"opt", "Control optimizations">;
def order : P<"order", "Put functions in order">;
def out : P<"out", "Path to file to write output">;
def natvis : P<"natvis", "Path to natvis file to embed in the PDB">;
def no_color_diagnostics: F<"no-color-diagnostics">,
HelpText<"Do not use colors in diagnostics">;
def pdb : P<"pdb", "PDB file path">;
def pdbaltpath : P<"pdbaltpath", "PDB file path to embed in the image">;
def section : P<"section", "Specify section attributes">;
def stack : P<"stack", "Size of the stack">;
def stub : P<"stub", "Specify DOS stub file">;
def subsystem : P<"subsystem", "Specify subsystem">;
def timestamp : P<"timestamp", "Specify the PE header timestamp">;
def version : P<"version", "Specify a version number in the PE header">;
def wholearchive_file : P<"wholearchive", "Include all object files from this archive">;
def disallowlib : Joined<["/", "-", "/?", "-?"], "disallowlib:">,
Alias<nodefaultlib>;
def manifest : F<"manifest">, HelpText<"Create .manifest file">;
def manifest_colon : P<
"manifest",
"NO disables manifest output; EMBED[,ID=#] embeds manifest as resource in the image">;
def manifestuac : P<"manifestuac", "User access control">;
def manifestfile : P<"manifestfile", "Manifest output path, with /manifest">;
def manifestdependency : P<
"manifestdependency",
"Attributes for <dependency> element in manifest file; implies /manifest">;
def manifestinput : P<
"manifestinput",
"Additional manifest inputs; only valid with /manifest:embed">;
// We cannot use multiclass P because class name "incl" is different
// from its command line option name. We do this because "include" is
// a reserved keyword in tablegen.
def incl : Joined<["/", "-", "/?", "-?"], "include:">,
HelpText<"Force symbol to be added to symbol table as undefined one">;
// "def" is also a keyword.
def deffile : Joined<["/", "-", "/?", "-?"], "def:">,
HelpText<"Use module-definition file">;
def debug : F<"debug">, HelpText<"Embed a symbol table in the image">;
def debug_opt : P<"debug", "Embed a symbol table in the image with option">;
def debugtype : P<"debugtype", "Debug Info Options">;
def dll : F<"dll">, HelpText<"Create a DLL">;
def driver : P<"driver", "Generate a Windows NT Kernel Mode Driver">;
def nodefaultlib_all : F<"nodefaultlib">,
HelpText<"Remove all default libraries">;
def noentry : F<"noentry">,
HelpText<"Don't add reference to DllMainCRTStartup; only valid with /dll">;
def profile : F<"profile">;
def repro : F<"Brepro">,
HelpText<"Use a hash of the executable as the PE header timestamp">;
def swaprun : P<"swaprun",
"Comma-separated list of 'cd' or 'net'">;
def swaprun_cd : F<"swaprun:cd">, Alias<swaprun>, AliasArgs<["cd"]>,
HelpText<"Make loader run output binary from swap instead of from CD">;
def swaprun_net : F<"swaprun:net">, Alias<swaprun>, AliasArgs<["net"]>,
HelpText<"Make loader run output binary from swap instead of from network">;
def verbose : F<"verbose">;
def wholearchive_flag : F<"wholearchive">;
def force : F<"force">,
HelpText<"Allow undefined and multiply defined symbols when creating executables">;
def force_unresolved : F<"force:unresolved">,
HelpText<"Allow undefined symbols when creating executables">;
def force_multiple : F<"force:multiple">,
HelpText<"Allow multiply defined symbols when creating executables">;
def force_multipleres : F<"force:multipleres">,
HelpText<"Allow multiply defined resources when creating executables">;
defm WX : B<"WX", "Treat warnings as errors", "Don't treat warnings as errors">;
defm allowbind : B<"allowbind", "Enable DLL binding (default)",
"Disable DLL binding">;
defm allowisolation : B<"allowisolation", "Enable DLL isolation (default)",
"Disable DLL isolation">;
defm appcontainer : B<"appcontainer",
"Image can only be run in an app container",
"Image can run outside an app container (default)">;
defm dynamicbase : B<"dynamicbase", "Enable ASLR (default unless /fixed)",
"Disable ASLR (default when /fixed)">;
defm fixed : B<"fixed", "Disable base relocations",
"Enable base relocations (default)">;
defm highentropyva : B<"highentropyva",
"Enable 64-bit ASLR (default on 64-bit)",
"Disable 64-bit ASLR">;
defm incremental : B<"incremental",
"Keep original import library if contents are unchanged",
"Overwrite import library even if contents are unchanged">;
defm integritycheck : B<"integritycheck",
"Set FORCE_INTEGRITY bit in PE header",
"No effect (default)">;
defm largeaddressaware : B<"largeaddressaware",
"Enable large addresses (default on 64-bit)",
"Disable large addresses (default on 32-bit)">;
defm nxcompat : B<"nxcompat", "Enable data execution prevention (default)",
"Disable data execution provention">;
defm safeseh : B<"safeseh",
"Produce an image with Safe Exception Handler (only for x86)",
"Don't produce an image with Safe Exception Handler">;
defm tsaware : B<"tsaware",
"Create Terminal Server aware executable (default)",
"Create non-Terminal Server aware executable">;
def help : F<"help">;
// /?? and -?? must be before /? and -? to not confuse lib/Options.
def help_q : Flag<["/??", "-??", "/?", "-?"], "">, Alias<help>;
// LLD extensions
def exclude_all_symbols : F<"exclude-all-symbols">;
def export_all_symbols : F<"export-all-symbols">;
defm demangle : B<"demangle",
"Demangle symbols in output (default)",
"Do not demangle symbols in output">;
def include_optional : Joined<["/", "-", "/?", "-?"], "includeoptional:">,
HelpText<"Add symbol as undefined, but allow it to remain undefined">;
def kill_at : F<"kill-at">;
def lldmingw : F<"lldmingw">;
def output_def : Joined<["/", "-", "/?", "-?"], "output-def:">;
def pdb_source_path : P<"pdbsourcepath",
"Base path used to make relative source file path absolute in PDB">;
def rsp_quoting : Joined<["--"], "rsp-quoting=">,
HelpText<"Quoting style for response files, 'windows' (default) or 'posix'">;
def thinlto_emit_imports_files :
F<"thinlto-emit-imports-files">,
HelpText<"Emit .imports files with -thinlto-index-only">;
def thinlto_index_only :
F<"thinlto-index-only">,
HelpText<"Instead of linking, emit ThinLTO index files">;
def thinlto_index_only_arg : P<
"thinlto-index-only",
"-thinlto-index-only and also write native module names to file">;
def thinlto_object_suffix_replace : P<
"thinlto-object-suffix-replace",
"'old;new' replace old suffix with new suffix in ThinLTO index">;
def thinlto_prefix_replace: P<
"thinlto-prefix-replace",
"'old;new' replace old prefix with new prefix in ThinLTO outputs">;
def dash_dash_version : Flag<["--"], "version">,
HelpText<"Print version information">;
defm threads: B<"threads",
"Run the linker multi-threaded (default)",
"Do not run the linker multi-threaded">;
// Flags for debugging
def lldmap : F<"lldmap">;
def lldmap_file : Joined<["/", "-", "/?", "-?"], "lldmap:">;
def show_timing : F<"time">;
def summary : F<"summary">;
//==============================================================================
// The flags below do nothing. They are defined only for link.exe compatibility.
//==============================================================================
class QF<string name> : Joined<["/", "-", "/?", "-?"], name#":">;
def ignoreidl : F<"ignoreidl">;
def nologo : F<"nologo">;
def throwingnew : F<"throwingnew">;
def editandcontinue : F<"editandcontinue">;
def fastfail : F<"fastfail">;
def delay : QF<"delay">;
def errorreport : QF<"errorreport">;
def idlout : QF<"idlout">;
def maxilksize : QF<"maxilksize">;
def tlbid : QF<"tlbid">;
def tlbout : QF<"tlbout">;
def verbose_all : QF<"verbose">;
def guardsym : QF<"guardsym">;

1836
deps/lld/COFF/PDB.cpp vendored

File diff suppressed because it is too large Load Diff

37
deps/lld/COFF/PDB.h vendored
View File

@@ -1,37 +0,0 @@
//===- PDB.h ----------------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLD_COFF_PDB_H
#define LLD_COFF_PDB_H
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/StringRef.h"
namespace llvm {
namespace codeview {
union DebugInfo;
}
}
namespace lld {
namespace coff {
class OutputSection;
class SectionChunk;
class SymbolTable;
void createPDB(SymbolTable *symtab,
llvm::ArrayRef<OutputSection *> outputSections,
llvm::ArrayRef<uint8_t> sectionTable,
llvm::codeview::DebugInfo *buildId);
std::pair<llvm::StringRef, uint32_t> getFileLine(const SectionChunk *c,
uint32_t addr);
}
}
#endif

View File

@@ -1 +0,0 @@
See docs/NewLLD.rst

View File

@@ -1,615 +0,0 @@
//===- SymbolTable.cpp ----------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "SymbolTable.h"
#include "Config.h"
#include "Driver.h"
#include "LTO.h"
#include "PDB.h"
#include "Symbols.h"
#include "lld/Common/ErrorHandler.h"
#include "lld/Common/Memory.h"
#include "lld/Common/Timer.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/Object/WindowsMachineFlag.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
#include <utility>
using namespace llvm;
namespace lld {
namespace coff {
static Timer ltoTimer("LTO", Timer::root());
SymbolTable *symtab;
void SymbolTable::addFile(InputFile *file) {
log("Reading " + toString(file));
file->parse();
MachineTypes mt = file->getMachineType();
if (config->machine == IMAGE_FILE_MACHINE_UNKNOWN) {
config->machine = mt;
} else if (mt != IMAGE_FILE_MACHINE_UNKNOWN && config->machine != mt) {
error(toString(file) + ": machine type " + machineToStr(mt) +
" conflicts with " + machineToStr(config->machine));
return;
}
if (auto *f = dyn_cast<ObjFile>(file)) {
ObjFile::instances.push_back(f);
} else if (auto *f = dyn_cast<BitcodeFile>(file)) {
BitcodeFile::instances.push_back(f);
} else if (auto *f = dyn_cast<ImportFile>(file)) {
ImportFile::instances.push_back(f);
}
driver->parseDirectives(file);
}
static void errorOrWarn(const Twine &s) {
if (config->forceUnresolved)
warn(s);
else
error(s);
}
// Returns the symbol in SC whose value is <= Addr that is closest to Addr.
// This is generally the global variable or function whose definition contains
// Addr.
static Symbol *getSymbol(SectionChunk *sc, uint32_t addr) {
DefinedRegular *candidate = nullptr;
for (Symbol *s : sc->file->getSymbols()) {
auto *d = dyn_cast_or_null<DefinedRegular>(s);
if (!d || !d->data || d->getChunk() != sc || d->getValue() > addr ||
(candidate && d->getValue() < candidate->getValue()))
continue;
candidate = d;
}
return candidate;
}
// Given a file and the index of a symbol in that file, returns a description
// of all references to that symbol from that file. If no debug information is
// available, returns just the name of the file, else one string per actual
// reference as described in the debug info.
std::vector<std::string> getSymbolLocations(ObjFile *file, uint32_t symIndex) {
struct Location {
Symbol *sym;
std::pair<StringRef, uint32_t> fileLine;
};
std::vector<Location> locations;
for (Chunk *c : file->getChunks()) {
auto *sc = dyn_cast<SectionChunk>(c);
if (!sc)
continue;
for (const coff_relocation &r : sc->getRelocs()) {
if (r.SymbolTableIndex != symIndex)
continue;
std::pair<StringRef, uint32_t> fileLine =
getFileLine(sc, r.VirtualAddress);
Symbol *sym = getSymbol(sc, r.VirtualAddress);
if (!fileLine.first.empty() || sym)
locations.push_back({sym, fileLine});
}
}
if (locations.empty())
return std::vector<std::string>({"\n>>> referenced by " + toString(file)});
std::vector<std::string> symbolLocations(locations.size());
size_t i = 0;
for (Location loc : locations) {
llvm::raw_string_ostream os(symbolLocations[i++]);
os << "\n>>> referenced by ";
if (!loc.fileLine.first.empty())
os << loc.fileLine.first << ":" << loc.fileLine.second
<< "\n>>> ";
os << toString(file);
if (loc.sym)
os << ":(" << toString(*loc.sym) << ')';
}
return symbolLocations;
}
// For an undefined symbol, stores all files referencing it and the index of
// the undefined symbol in each file.
struct UndefinedDiag {
Symbol *sym;
struct File {
ObjFile *oFile;
uint64_t symIndex;
};
std::vector<File> files;
};
static void reportUndefinedSymbol(const UndefinedDiag &undefDiag) {
std::string out;
llvm::raw_string_ostream os(out);
os << "undefined symbol: " << toString(*undefDiag.sym);
const size_t maxUndefReferences = 10;
size_t i = 0, numRefs = 0;
for (const UndefinedDiag::File &ref : undefDiag.files) {
std::vector<std::string> symbolLocations =
getSymbolLocations(ref.oFile, ref.symIndex);
numRefs += symbolLocations.size();
for (const std::string &s : symbolLocations) {
if (i >= maxUndefReferences)
break;
os << s;
i++;
}
}
if (i < numRefs)
os << "\n>>> referenced " << numRefs - i << " more times";
errorOrWarn(os.str());
}
void SymbolTable::loadMinGWAutomaticImports() {
for (auto &i : symMap) {
Symbol *sym = i.second;
auto *undef = dyn_cast<Undefined>(sym);
if (!undef)
continue;
if (!sym->isUsedInRegularObj)
continue;
StringRef name = undef->getName();
if (name.startswith("__imp_"))
continue;
// If we have an undefined symbol, but we have a Lazy representing a
// symbol we could load from file, make sure to load that.
Lazy *l = dyn_cast_or_null<Lazy>(find(("__imp_" + name).str()));
if (!l || l->pendingArchiveLoad)
continue;
log("Loading lazy " + l->getName() + " from " + l->file->getName() +
" for automatic import");
l->pendingArchiveLoad = true;
l->file->addMember(l->sym);
}
}
bool SymbolTable::handleMinGWAutomaticImport(Symbol *sym, StringRef name) {
if (name.startswith("__imp_"))
return false;
Defined *imp = dyn_cast_or_null<Defined>(find(("__imp_" + name).str()));
if (!imp)
return false;
// Replace the reference directly to a variable with a reference
// to the import address table instead. This obviously isn't right,
// but we mark the symbol as isRuntimePseudoReloc, and a later pass
// will add runtime pseudo relocations for every relocation against
// this Symbol. The runtime pseudo relocation framework expects the
// reference itself to point at the IAT entry.
size_t impSize = 0;
if (isa<DefinedImportData>(imp)) {
log("Automatically importing " + name + " from " +
cast<DefinedImportData>(imp)->getDLLName());
impSize = sizeof(DefinedImportData);
} else if (isa<DefinedRegular>(imp)) {
log("Automatically importing " + name + " from " +
toString(cast<DefinedRegular>(imp)->file));
impSize = sizeof(DefinedRegular);
} else {
warn("unable to automatically import " + name + " from " + imp->getName() +
" from " + toString(cast<DefinedRegular>(imp)->file) +
"; unexpected symbol type");
return false;
}
sym->replaceKeepingName(imp, impSize);
sym->isRuntimePseudoReloc = true;
// There may exist symbols named .refptr.<name> which only consist
// of a single pointer to <name>. If it turns out <name> is
// automatically imported, we don't need to keep the .refptr.<name>
// pointer at all, but redirect all accesses to it to the IAT entry
// for __imp_<name> instead, and drop the whole .refptr.<name> chunk.
DefinedRegular *refptr =
dyn_cast_or_null<DefinedRegular>(find((".refptr." + name).str()));
if (refptr && refptr->getChunk()->getSize() == config->wordsize) {
SectionChunk *sc = dyn_cast_or_null<SectionChunk>(refptr->getChunk());
if (sc && sc->getRelocs().size() == 1 && *sc->symbols().begin() == sym) {
log("Replacing .refptr." + name + " with " + imp->getName());
refptr->getChunk()->live = false;
refptr->replaceKeepingName(imp, impSize);
}
}
return true;
}
void SymbolTable::reportRemainingUndefines() {
SmallPtrSet<Symbol *, 8> undefs;
DenseMap<Symbol *, Symbol *> localImports;
for (auto &i : symMap) {
Symbol *sym = i.second;
auto *undef = dyn_cast<Undefined>(sym);
if (!undef)
continue;
if (!sym->isUsedInRegularObj)
continue;
StringRef name = undef->getName();
// A weak alias may have been resolved, so check for that.
if (Defined *d = undef->getWeakAlias()) {
// We want to replace Sym with D. However, we can't just blindly
// copy sizeof(SymbolUnion) bytes from D to Sym because D may be an
// internal symbol, and internal symbols are stored as "unparented"
// Symbols. For that reason we need to check which type of symbol we
// are dealing with and copy the correct number of bytes.
if (isa<DefinedRegular>(d))
memcpy(sym, d, sizeof(DefinedRegular));
else if (isa<DefinedAbsolute>(d))
memcpy(sym, d, sizeof(DefinedAbsolute));
else
memcpy(sym, d, sizeof(SymbolUnion));
continue;
}
// If we can resolve a symbol by removing __imp_ prefix, do that.
// This odd rule is for compatibility with MSVC linker.
if (name.startswith("__imp_")) {
Symbol *imp = find(name.substr(strlen("__imp_")));
if (imp && isa<Defined>(imp)) {
auto *d = cast<Defined>(imp);
replaceSymbol<DefinedLocalImport>(sym, name, d);
localImportChunks.push_back(cast<DefinedLocalImport>(sym)->getChunk());
localImports[sym] = d;
continue;
}
}
// We don't want to report missing Microsoft precompiled headers symbols.
// A proper message will be emitted instead in PDBLinker::aquirePrecompObj
if (name.contains("_PchSym_"))
continue;
if (config->mingw && handleMinGWAutomaticImport(sym, name))
continue;
// Remaining undefined symbols are not fatal if /force is specified.
// They are replaced with dummy defined symbols.
if (config->forceUnresolved)
replaceSymbol<DefinedAbsolute>(sym, name, 0);
undefs.insert(sym);
}
if (undefs.empty() && localImports.empty())
return;
for (Symbol *b : config->gcroot) {
if (undefs.count(b))
errorOrWarn("<root>: undefined symbol: " + toString(*b));
if (config->warnLocallyDefinedImported)
if (Symbol *imp = localImports.lookup(b))
warn("<root>: locally defined symbol imported: " + toString(*imp) +
" (defined in " + toString(imp->getFile()) + ") [LNK4217]");
}
std::vector<UndefinedDiag> undefDiags;
DenseMap<Symbol *, int> firstDiag;
for (ObjFile *file : ObjFile::instances) {
size_t symIndex = (size_t)-1;
for (Symbol *sym : file->getSymbols()) {
++symIndex;
if (!sym)
continue;
if (undefs.count(sym)) {
auto it = firstDiag.find(sym);
if (it == firstDiag.end()) {
firstDiag[sym] = undefDiags.size();
undefDiags.push_back({sym, {{file, symIndex}}});
} else {
undefDiags[it->second].files.push_back({file, symIndex});
}
}
if (config->warnLocallyDefinedImported)
if (Symbol *imp = localImports.lookup(sym))
warn(toString(file) +
": locally defined symbol imported: " + toString(*imp) +
" (defined in " + toString(imp->getFile()) + ") [LNK4217]");
}
}
for (const UndefinedDiag& undefDiag : undefDiags)
reportUndefinedSymbol(undefDiag);
}
std::pair<Symbol *, bool> SymbolTable::insert(StringRef name) {
bool inserted = false;
Symbol *&sym = symMap[CachedHashStringRef(name)];
if (!sym) {
sym = reinterpret_cast<Symbol *>(make<SymbolUnion>());
sym->isUsedInRegularObj = false;
sym->pendingArchiveLoad = false;
inserted = true;
}
return {sym, inserted};
}
std::pair<Symbol *, bool> SymbolTable::insert(StringRef name, InputFile *file) {
std::pair<Symbol *, bool> result = insert(name);
if (!file || !isa<BitcodeFile>(file))
result.first->isUsedInRegularObj = true;
return result;
}
Symbol *SymbolTable::addUndefined(StringRef name, InputFile *f,
bool isWeakAlias) {
Symbol *s;
bool wasInserted;
std::tie(s, wasInserted) = insert(name, f);
if (wasInserted || (isa<Lazy>(s) && isWeakAlias)) {
replaceSymbol<Undefined>(s, name);
return s;
}
if (auto *l = dyn_cast<Lazy>(s)) {
if (!s->pendingArchiveLoad) {
s->pendingArchiveLoad = true;
l->file->addMember(l->sym);
}
}
return s;
}
void SymbolTable::addLazy(ArchiveFile *f, const Archive::Symbol &sym) {
StringRef name = sym.getName();
Symbol *s;
bool wasInserted;
std::tie(s, wasInserted) = insert(name);
if (wasInserted) {
replaceSymbol<Lazy>(s, f, sym);
return;
}
auto *u = dyn_cast<Undefined>(s);
if (!u || u->weakAlias || s->pendingArchiveLoad)
return;
s->pendingArchiveLoad = true;
f->addMember(sym);
}
void SymbolTable::reportDuplicate(Symbol *existing, InputFile *newFile) {
std::string msg = "duplicate symbol: " + toString(*existing) + " in " +
toString(existing->getFile()) + " and in " +
toString(newFile);
if (config->forceMultiple)
warn(msg);
else
error(msg);
}
Symbol *SymbolTable::addAbsolute(StringRef n, COFFSymbolRef sym) {
Symbol *s;
bool wasInserted;
std::tie(s, wasInserted) = insert(n, nullptr);
s->isUsedInRegularObj = true;
if (wasInserted || isa<Undefined>(s) || isa<Lazy>(s))
replaceSymbol<DefinedAbsolute>(s, n, sym);
else if (!isa<DefinedCOFF>(s))
reportDuplicate(s, nullptr);
return s;
}
Symbol *SymbolTable::addAbsolute(StringRef n, uint64_t va) {
Symbol *s;
bool wasInserted;
std::tie(s, wasInserted) = insert(n, nullptr);
s->isUsedInRegularObj = true;
if (wasInserted || isa<Undefined>(s) || isa<Lazy>(s))
replaceSymbol<DefinedAbsolute>(s, n, va);
else if (!isa<DefinedCOFF>(s))
reportDuplicate(s, nullptr);
return s;
}
Symbol *SymbolTable::addSynthetic(StringRef n, Chunk *c) {
Symbol *s;
bool wasInserted;
std::tie(s, wasInserted) = insert(n, nullptr);
s->isUsedInRegularObj = true;
if (wasInserted || isa<Undefined>(s) || isa<Lazy>(s))
replaceSymbol<DefinedSynthetic>(s, n, c);
else if (!isa<DefinedCOFF>(s))
reportDuplicate(s, nullptr);
return s;
}
Symbol *SymbolTable::addRegular(InputFile *f, StringRef n,
const coff_symbol_generic *sym,
SectionChunk *c) {
Symbol *s;
bool wasInserted;
std::tie(s, wasInserted) = insert(n, f);
if (wasInserted || !isa<DefinedRegular>(s))
replaceSymbol<DefinedRegular>(s, f, n, /*IsCOMDAT*/ false,
/*IsExternal*/ true, sym, c);
else
reportDuplicate(s, f);
return s;
}
std::pair<DefinedRegular *, bool>
SymbolTable::addComdat(InputFile *f, StringRef n,
const coff_symbol_generic *sym) {
Symbol *s;
bool wasInserted;
std::tie(s, wasInserted) = insert(n, f);
if (wasInserted || !isa<DefinedRegular>(s)) {
replaceSymbol<DefinedRegular>(s, f, n, /*IsCOMDAT*/ true,
/*IsExternal*/ true, sym, nullptr);
return {cast<DefinedRegular>(s), true};
}
auto *existingSymbol = cast<DefinedRegular>(s);
if (!existingSymbol->isCOMDAT)
reportDuplicate(s, f);
return {existingSymbol, false};
}
Symbol *SymbolTable::addCommon(InputFile *f, StringRef n, uint64_t size,
const coff_symbol_generic *sym, CommonChunk *c) {
Symbol *s;
bool wasInserted;
std::tie(s, wasInserted) = insert(n, f);
if (wasInserted || !isa<DefinedCOFF>(s))
replaceSymbol<DefinedCommon>(s, f, n, size, sym, c);
else if (auto *dc = dyn_cast<DefinedCommon>(s))
if (size > dc->getSize())
replaceSymbol<DefinedCommon>(s, f, n, size, sym, c);
return s;
}
Symbol *SymbolTable::addImportData(StringRef n, ImportFile *f) {
Symbol *s;
bool wasInserted;
std::tie(s, wasInserted) = insert(n, nullptr);
s->isUsedInRegularObj = true;
if (wasInserted || isa<Undefined>(s) || isa<Lazy>(s)) {
replaceSymbol<DefinedImportData>(s, n, f);
return s;
}
reportDuplicate(s, f);
return nullptr;
}
Symbol *SymbolTable::addImportThunk(StringRef name, DefinedImportData *id,
uint16_t machine) {
Symbol *s;
bool wasInserted;
std::tie(s, wasInserted) = insert(name, nullptr);
s->isUsedInRegularObj = true;
if (wasInserted || isa<Undefined>(s) || isa<Lazy>(s)) {
replaceSymbol<DefinedImportThunk>(s, name, id, machine);
return s;
}
reportDuplicate(s, id->file);
return nullptr;
}
void SymbolTable::addLibcall(StringRef name) {
Symbol *sym = findUnderscore(name);
if (!sym)
return;
if (Lazy *l = dyn_cast<Lazy>(sym)) {
MemoryBufferRef mb = l->getMemberBuffer();
if (identify_magic(mb.getBuffer()) == llvm::file_magic::bitcode)
addUndefined(sym->getName());
}
}
std::vector<Chunk *> SymbolTable::getChunks() {
std::vector<Chunk *> res;
for (ObjFile *file : ObjFile::instances) {
ArrayRef<Chunk *> v = file->getChunks();
res.insert(res.end(), v.begin(), v.end());
}
return res;
}
Symbol *SymbolTable::find(StringRef name) {
return symMap.lookup(CachedHashStringRef(name));
}
Symbol *SymbolTable::findUnderscore(StringRef name) {
if (config->machine == I386)
return find(("_" + name).str());
return find(name);
}
// Return all symbols that start with Prefix, possibly ignoring the first
// character of Prefix or the first character symbol.
std::vector<Symbol *> SymbolTable::getSymsWithPrefix(StringRef prefix) {
std::vector<Symbol *> syms;
for (auto pair : symMap) {
StringRef name = pair.first.val();
if (name.startswith(prefix) || name.startswith(prefix.drop_front()) ||
name.drop_front().startswith(prefix) ||
name.drop_front().startswith(prefix.drop_front())) {
syms.push_back(pair.second);
}
}
return syms;
}
Symbol *SymbolTable::findMangle(StringRef name) {
if (Symbol *sym = find(name))
if (!isa<Undefined>(sym))
return sym;
// Efficient fuzzy string lookup is impossible with a hash table, so iterate
// the symbol table once and collect all possibly matching symbols into this
// vector. Then compare each possibly matching symbol with each possible
// mangling.
std::vector<Symbol *> syms = getSymsWithPrefix(name);
auto findByPrefix = [&syms](const Twine &t) -> Symbol * {
std::string prefix = t.str();
for (auto *s : syms)
if (s->getName().startswith(prefix))
return s;
return nullptr;
};
// For non-x86, just look for C++ functions.
if (config->machine != I386)
return findByPrefix("?" + name + "@@Y");
if (!name.startswith("_"))
return nullptr;
// Search for x86 stdcall function.
if (Symbol *s = findByPrefix(name + "@"))
return s;
// Search for x86 fastcall function.
if (Symbol *s = findByPrefix("@" + name.substr(1) + "@"))
return s;
// Search for x86 vectorcall function.
if (Symbol *s = findByPrefix(name.substr(1) + "@@"))
return s;
// Search for x86 C++ non-member function.
return findByPrefix("?" + name.substr(1) + "@@Y");
}
Symbol *SymbolTable::addUndefined(StringRef name) {
return addUndefined(name, nullptr, false);
}
std::vector<StringRef> SymbolTable::compileBitcodeFiles() {
lto.reset(new BitcodeCompiler);
for (BitcodeFile *f : BitcodeFile::instances)
lto->add(*f);
return lto->compile();
}
void SymbolTable::addCombinedLTOObjects() {
if (BitcodeFile::instances.empty())
return;
ScopedTimer t(ltoTimer);
for (StringRef object : compileBitcodeFiles()) {
auto *obj = make<ObjFile>(MemoryBufferRef(object, "lto.tmp"));
obj->parse();
ObjFile::instances.push_back(obj);
}
}
} // namespace coff
} // namespace lld

View File

@@ -1,132 +0,0 @@
//===- SymbolTable.h --------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLD_COFF_SYMBOL_TABLE_H
#define LLD_COFF_SYMBOL_TABLE_H
#include "InputFiles.h"
#include "LTO.h"
#include "llvm/ADT/CachedHashString.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/DenseMapInfo.h"
#include "llvm/Support/raw_ostream.h"
namespace llvm {
struct LTOCodeGenerator;
}
namespace lld {
namespace coff {
class Chunk;
class CommonChunk;
class Defined;
class DefinedAbsolute;
class DefinedRegular;
class DefinedRelative;
class Lazy;
class SectionChunk;
class Symbol;
// SymbolTable is a bucket of all known symbols, including defined,
// undefined, or lazy symbols (the last one is symbols in archive
// files whose archive members are not yet loaded).
//
// We put all symbols of all files to a SymbolTable, and the
// SymbolTable selects the "best" symbols if there are name
// conflicts. For example, obviously, a defined symbol is better than
// an undefined symbol. Or, if there's a conflict between a lazy and a
// undefined, it'll read an archive member to read a real definition
// to replace the lazy symbol. The logic is implemented in the
// add*() functions, which are called by input files as they are parsed.
// There is one add* function per symbol type.
class SymbolTable {
public:
void addFile(InputFile *file);
// Try to resolve any undefined symbols and update the symbol table
// accordingly, then print an error message for any remaining undefined
// symbols.
void reportRemainingUndefines();
void loadMinGWAutomaticImports();
bool handleMinGWAutomaticImport(Symbol *sym, StringRef name);
// Returns a list of chunks of selected symbols.
std::vector<Chunk *> getChunks();
// Returns a symbol for a given name. Returns a nullptr if not found.
Symbol *find(StringRef name);
Symbol *findUnderscore(StringRef name);
// Occasionally we have to resolve an undefined symbol to its
// mangled symbol. This function tries to find a mangled name
// for U from the symbol table, and if found, set the symbol as
// a weak alias for U.
Symbol *findMangle(StringRef name);
// Build a set of COFF objects representing the combined contents of
// BitcodeFiles and add them to the symbol table. Called after all files are
// added and before the writer writes results to a file.
void addCombinedLTOObjects();
std::vector<StringRef> compileBitcodeFiles();
// Creates an Undefined symbol for a given name.
Symbol *addUndefined(StringRef name);
Symbol *addSynthetic(StringRef n, Chunk *c);
Symbol *addAbsolute(StringRef n, uint64_t va);
Symbol *addUndefined(StringRef name, InputFile *f, bool isWeakAlias);
void addLazy(ArchiveFile *f, const Archive::Symbol &sym);
Symbol *addAbsolute(StringRef n, COFFSymbolRef s);
Symbol *addRegular(InputFile *f, StringRef n,
const llvm::object::coff_symbol_generic *s = nullptr,
SectionChunk *c = nullptr);
std::pair<DefinedRegular *, bool>
addComdat(InputFile *f, StringRef n,
const llvm::object::coff_symbol_generic *s = nullptr);
Symbol *addCommon(InputFile *f, StringRef n, uint64_t size,
const llvm::object::coff_symbol_generic *s = nullptr,
CommonChunk *c = nullptr);
Symbol *addImportData(StringRef n, ImportFile *f);
Symbol *addImportThunk(StringRef name, DefinedImportData *s,
uint16_t machine);
void addLibcall(StringRef name);
void reportDuplicate(Symbol *existing, InputFile *newFile);
// A list of chunks which to be added to .rdata.
std::vector<Chunk *> localImportChunks;
// Iterates symbols in non-determinstic hash table order.
template <typename T> void forEachSymbol(T callback) {
for (auto &pair : symMap)
callback(pair.second);
}
private:
/// Inserts symbol if not already present.
std::pair<Symbol *, bool> insert(StringRef name);
/// Same as insert(Name), but also sets isUsedInRegularObj.
std::pair<Symbol *, bool> insert(StringRef name, InputFile *f);
std::vector<Symbol *> getSymsWithPrefix(StringRef prefix);
llvm::DenseMap<llvm::CachedHashStringRef, Symbol *> symMap;
std::unique_ptr<BitcodeCompiler> lto;
};
extern SymbolTable *symtab;
std::vector<std::string> getSymbolLocations(ObjFile *file, uint32_t symIndex);
} // namespace coff
} // namespace lld
#endif

View File

@@ -1,131 +0,0 @@
//===- Symbols.cpp --------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "Symbols.h"
#include "InputFiles.h"
#include "lld/Common/ErrorHandler.h"
#include "lld/Common/Memory.h"
#include "lld/Common/Strings.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/raw_ostream.h"
using namespace llvm;
using namespace llvm::object;
using namespace lld::coff;
namespace lld {
static_assert(sizeof(SymbolUnion) <= 48,
"symbols should be optimized for memory usage");
// Returns a symbol name for an error message.
static std::string demangle(StringRef symName) {
if (config->demangle)
if (Optional<std::string> s = demangleMSVC(symName))
return *s;
return symName;
}
std::string toString(coff::Symbol &b) { return demangle(b.getName()); }
std::string toCOFFString(const Archive::Symbol &b) {
return demangle(b.getName());
}
namespace coff {
StringRef Symbol::getName() {
// COFF symbol names are read lazily for a performance reason.
// Non-external symbol names are never used by the linker except for logging
// or debugging. Their internal references are resolved not by name but by
// symbol index. And because they are not external, no one can refer them by
// name. Object files contain lots of non-external symbols, and creating
// StringRefs for them (which involves lots of strlen() on the string table)
// is a waste of time.
if (nameData == nullptr) {
auto *d = cast<DefinedCOFF>(this);
StringRef nameStr;
cast<ObjFile>(d->file)->getCOFFObj()->getSymbolName(d->sym, nameStr);
nameData = nameStr.data();
nameSize = nameStr.size();
assert(nameSize == nameStr.size() && "name length truncated");
}
return StringRef(nameData, nameSize);
}
InputFile *Symbol::getFile() {
if (auto *sym = dyn_cast<DefinedCOFF>(this))
return sym->file;
if (auto *sym = dyn_cast<Lazy>(this))
return sym->file;
return nullptr;
}
bool Symbol::isLive() const {
if (auto *r = dyn_cast<DefinedRegular>(this))
return r->getChunk()->live;
if (auto *imp = dyn_cast<DefinedImportData>(this))
return imp->file->live;
if (auto *imp = dyn_cast<DefinedImportThunk>(this))
return imp->wrappedSym->file->thunkLive;
// Assume any other kind of symbol is live.
return true;
}
// MinGW specific.
void Symbol::replaceKeepingName(Symbol *other, size_t size) {
StringRef origName = getName();
memcpy(this, other, size);
nameData = origName.data();
nameSize = origName.size();
}
COFFSymbolRef DefinedCOFF::getCOFFSymbol() {
size_t symSize = cast<ObjFile>(file)->getCOFFObj()->getSymbolTableEntrySize();
if (symSize == sizeof(coff_symbol16))
return COFFSymbolRef(reinterpret_cast<const coff_symbol16 *>(sym));
assert(symSize == sizeof(coff_symbol32));
return COFFSymbolRef(reinterpret_cast<const coff_symbol32 *>(sym));
}
uint16_t DefinedAbsolute::numOutputSections;
static Chunk *makeImportThunk(DefinedImportData *s, uint16_t machine) {
if (machine == AMD64)
return make<ImportThunkChunkX64>(s);
if (machine == I386)
return make<ImportThunkChunkX86>(s);
if (machine == ARM64)
return make<ImportThunkChunkARM64>(s);
assert(machine == ARMNT);
return make<ImportThunkChunkARM>(s);
}
DefinedImportThunk::DefinedImportThunk(StringRef name, DefinedImportData *s,
uint16_t machine)
: Defined(DefinedImportThunkKind, name), wrappedSym(s),
data(makeImportThunk(s, machine)) {}
Defined *Undefined::getWeakAlias() {
// A weak alias may be a weak alias to another symbol, so check recursively.
for (Symbol *a = weakAlias; a; a = cast<Undefined>(a)->weakAlias)
if (auto *d = dyn_cast<Defined>(a))
return d;
return nullptr;
}
MemoryBufferRef Lazy::getMemberBuffer() {
Archive::Child c =
CHECK(sym.getMember(),
"could not get the member for symbol " + toCOFFString(sym));
return CHECK(c.getMemoryBufferRef(),
"could not get the buffer for the member defining symbol " +
toCOFFString(sym));
}
} // namespace coff
} // namespace lld

View File

@@ -1,444 +0,0 @@
//===- Symbols.h ------------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLD_COFF_SYMBOLS_H
#define LLD_COFF_SYMBOLS_H
#include "Chunks.h"
#include "Config.h"
#include "lld/Common/LLVM.h"
#include "lld/Common/Memory.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/Object/Archive.h"
#include "llvm/Object/COFF.h"
#include <atomic>
#include <memory>
#include <vector>
namespace lld {
std::string toString(coff::Symbol &b);
// There are two different ways to convert an Archive::Symbol to a string:
// One for Microsoft name mangling and one for Itanium name mangling.
// Call the functions toCOFFString and toELFString, not just toString.
std::string toCOFFString(const coff::Archive::Symbol &b);
namespace coff {
using llvm::object::Archive;
using llvm::object::COFFSymbolRef;
using llvm::object::coff_import_header;
using llvm::object::coff_symbol_generic;
class ArchiveFile;
class InputFile;
class ObjFile;
class SymbolTable;
// The base class for real symbol classes.
class Symbol {
public:
enum Kind {
// The order of these is significant. We start with the regular defined
// symbols as those are the most prevalent and the zero tag is the cheapest
// to set. Among the defined kinds, the lower the kind is preferred over
// the higher kind when testing whether one symbol should take precedence
// over another.
DefinedRegularKind = 0,
DefinedCommonKind,
DefinedLocalImportKind,
DefinedImportThunkKind,
DefinedImportDataKind,
DefinedAbsoluteKind,
DefinedSyntheticKind,
UndefinedKind,
LazyKind,
LastDefinedCOFFKind = DefinedCommonKind,
LastDefinedKind = DefinedSyntheticKind,
};
Kind kind() const { return static_cast<Kind>(symbolKind); }
// Returns the symbol name.
StringRef getName();
void replaceKeepingName(Symbol *other, size_t size);
// Returns the file from which this symbol was created.
InputFile *getFile();
// Indicates that this symbol will be included in the final image. Only valid
// after calling markLive.
bool isLive() const;
protected:
friend SymbolTable;
explicit Symbol(Kind k, StringRef n = "")
: symbolKind(k), isExternal(true), isCOMDAT(false),
writtenToSymtab(false), pendingArchiveLoad(false), isGCRoot(false),
isRuntimePseudoReloc(false), nameSize(n.size()),
nameData(n.empty() ? nullptr : n.data()) {}
const unsigned symbolKind : 8;
unsigned isExternal : 1;
public:
// This bit is used by the \c DefinedRegular subclass.
unsigned isCOMDAT : 1;
// This bit is used by Writer::createSymbolAndStringTable() to prevent
// symbols from being written to the symbol table more than once.
unsigned writtenToSymtab : 1;
// True if this symbol was referenced by a regular (non-bitcode) object.
unsigned isUsedInRegularObj : 1;
// True if we've seen both a lazy and an undefined symbol with this symbol
// name, which means that we have enqueued an archive member load and should
// not load any more archive members to resolve the same symbol.
unsigned pendingArchiveLoad : 1;
/// True if we've already added this symbol to the list of GC roots.
unsigned isGCRoot : 1;
unsigned isRuntimePseudoReloc : 1;
protected:
// Symbol name length. Assume symbol lengths fit in a 32-bit integer.
uint32_t nameSize;
const char *nameData;
};
// The base class for any defined symbols, including absolute symbols,
// etc.
class Defined : public Symbol {
public:
Defined(Kind k, StringRef n) : Symbol(k, n) {}
static bool classof(const Symbol *s) { return s->kind() <= LastDefinedKind; }
// Returns the RVA (relative virtual address) of this symbol. The
// writer sets and uses RVAs.
uint64_t getRVA();
// Returns the chunk containing this symbol. Absolute symbols and __ImageBase
// do not have chunks, so this may return null.
Chunk *getChunk();
};
// Symbols defined via a COFF object file or bitcode file. For COFF files, this
// stores a coff_symbol_generic*, and names of internal symbols are lazily
// loaded through that. For bitcode files, Sym is nullptr and the name is stored
// as a decomposed StringRef.
class DefinedCOFF : public Defined {
friend Symbol;
public:
DefinedCOFF(Kind k, InputFile *f, StringRef n, const coff_symbol_generic *s)
: Defined(k, n), file(f), sym(s) {}
static bool classof(const Symbol *s) {
return s->kind() <= LastDefinedCOFFKind;
}
InputFile *getFile() { return file; }
COFFSymbolRef getCOFFSymbol();
InputFile *file;
protected:
const coff_symbol_generic *sym;
};
// Regular defined symbols read from object file symbol tables.
class DefinedRegular : public DefinedCOFF {
public:
DefinedRegular(InputFile *f, StringRef n, bool isCOMDAT,
bool isExternal = false,
const coff_symbol_generic *s = nullptr,
SectionChunk *c = nullptr)
: DefinedCOFF(DefinedRegularKind, f, n, s), data(c ? &c->repl : nullptr) {
this->isExternal = isExternal;
this->isCOMDAT = isCOMDAT;
}
static bool classof(const Symbol *s) {
return s->kind() == DefinedRegularKind;
}
uint64_t getRVA() const { return (*data)->getRVA() + sym->Value; }
SectionChunk *getChunk() const { return *data; }
uint32_t getValue() const { return sym->Value; }
SectionChunk **data;
};
class DefinedCommon : public DefinedCOFF {
public:
DefinedCommon(InputFile *f, StringRef n, uint64_t size,
const coff_symbol_generic *s = nullptr,
CommonChunk *c = nullptr)
: DefinedCOFF(DefinedCommonKind, f, n, s), data(c), size(size) {
this->isExternal = true;
}
static bool classof(const Symbol *s) {
return s->kind() == DefinedCommonKind;
}
uint64_t getRVA() { return data->getRVA(); }
CommonChunk *getChunk() { return data; }
private:
friend SymbolTable;
uint64_t getSize() const { return size; }
CommonChunk *data;
uint64_t size;
};
// Absolute symbols.
class DefinedAbsolute : public Defined {
public:
DefinedAbsolute(StringRef n, COFFSymbolRef s)
: Defined(DefinedAbsoluteKind, n), va(s.getValue()) {
isExternal = s.isExternal();
}
DefinedAbsolute(StringRef n, uint64_t v)
: Defined(DefinedAbsoluteKind, n), va(v) {}
static bool classof(const Symbol *s) {
return s->kind() == DefinedAbsoluteKind;
}
uint64_t getRVA() { return va - config->imageBase; }
void setVA(uint64_t v) { va = v; }
// Section index relocations against absolute symbols resolve to
// this 16 bit number, and it is the largest valid section index
// plus one. This variable keeps it.
static uint16_t numOutputSections;
private:
uint64_t va;
};
// This symbol is used for linker-synthesized symbols like __ImageBase and
// __safe_se_handler_table.
class DefinedSynthetic : public Defined {
public:
explicit DefinedSynthetic(StringRef name, Chunk *c)
: Defined(DefinedSyntheticKind, name), c(c) {}
static bool classof(const Symbol *s) {
return s->kind() == DefinedSyntheticKind;
}
// A null chunk indicates that this is __ImageBase. Otherwise, this is some
// other synthesized chunk, like SEHTableChunk.
uint32_t getRVA() { return c ? c->getRVA() : 0; }
Chunk *getChunk() { return c; }
private:
Chunk *c;
};
// This class represents a symbol defined in an archive file. It is
// created from an archive file header, and it knows how to load an
// object file from an archive to replace itself with a defined
// symbol. If the resolver finds both Undefined and Lazy for
// the same name, it will ask the Lazy to load a file.
class Lazy : public Symbol {
public:
Lazy(ArchiveFile *f, const Archive::Symbol s)
: Symbol(LazyKind, s.getName()), file(f), sym(s) {}
static bool classof(const Symbol *s) { return s->kind() == LazyKind; }
MemoryBufferRef getMemberBuffer();
ArchiveFile *file;
private:
friend SymbolTable;
private:
const Archive::Symbol sym;
};
// Undefined symbols.
class Undefined : public Symbol {
public:
explicit Undefined(StringRef n) : Symbol(UndefinedKind, n) {}
static bool classof(const Symbol *s) { return s->kind() == UndefinedKind; }
// An undefined symbol can have a fallback symbol which gives an
// undefined symbol a second chance if it would remain undefined.
// If it remains undefined, it'll be replaced with whatever the
// Alias pointer points to.
Symbol *weakAlias = nullptr;
// If this symbol is external weak, try to resolve it to a defined
// symbol by searching the chain of fallback symbols. Returns the symbol if
// successful, otherwise returns null.
Defined *getWeakAlias();
};
// Windows-specific classes.
// This class represents a symbol imported from a DLL. This has two
// names for internal use and external use. The former is used for
// name resolution, and the latter is used for the import descriptor
// table in an output. The former has "__imp_" prefix.
class DefinedImportData : public Defined {
public:
DefinedImportData(StringRef n, ImportFile *f)
: Defined(DefinedImportDataKind, n), file(f) {
}
static bool classof(const Symbol *s) {
return s->kind() == DefinedImportDataKind;
}
uint64_t getRVA() { return file->location->getRVA(); }
Chunk *getChunk() { return file->location; }
void setLocation(Chunk *addressTable) { file->location = addressTable; }
StringRef getDLLName() { return file->dllName; }
StringRef getExternalName() { return file->externalName; }
uint16_t getOrdinal() { return file->hdr->OrdinalHint; }
ImportFile *file;
};
// This class represents a symbol for a jump table entry which jumps
// to a function in a DLL. Linker are supposed to create such symbols
// without "__imp_" prefix for all function symbols exported from
// DLLs, so that you can call DLL functions as regular functions with
// a regular name. A function pointer is given as a DefinedImportData.
class DefinedImportThunk : public Defined {
public:
DefinedImportThunk(StringRef name, DefinedImportData *s, uint16_t machine);
static bool classof(const Symbol *s) {
return s->kind() == DefinedImportThunkKind;
}
uint64_t getRVA() { return data->getRVA(); }
Chunk *getChunk() { return data; }
DefinedImportData *wrappedSym;
private:
Chunk *data;
};
// If you have a symbol "foo" in your object file, a symbol name
// "__imp_foo" becomes automatically available as a pointer to "foo".
// This class is for such automatically-created symbols.
// Yes, this is an odd feature. We didn't intend to implement that.
// This is here just for compatibility with MSVC.
class DefinedLocalImport : public Defined {
public:
DefinedLocalImport(StringRef n, Defined *s)
: Defined(DefinedLocalImportKind, n), data(make<LocalImportChunk>(s)) {}
static bool classof(const Symbol *s) {
return s->kind() == DefinedLocalImportKind;
}
uint64_t getRVA() { return data->getRVA(); }
Chunk *getChunk() { return data; }
private:
LocalImportChunk *data;
};
inline uint64_t Defined::getRVA() {
switch (kind()) {
case DefinedAbsoluteKind:
return cast<DefinedAbsolute>(this)->getRVA();
case DefinedSyntheticKind:
return cast<DefinedSynthetic>(this)->getRVA();
case DefinedImportDataKind:
return cast<DefinedImportData>(this)->getRVA();
case DefinedImportThunkKind:
return cast<DefinedImportThunk>(this)->getRVA();
case DefinedLocalImportKind:
return cast<DefinedLocalImport>(this)->getRVA();
case DefinedCommonKind:
return cast<DefinedCommon>(this)->getRVA();
case DefinedRegularKind:
return cast<DefinedRegular>(this)->getRVA();
case LazyKind:
case UndefinedKind:
llvm_unreachable("Cannot get the address for an undefined symbol.");
}
llvm_unreachable("unknown symbol kind");
}
inline Chunk *Defined::getChunk() {
switch (kind()) {
case DefinedRegularKind:
return cast<DefinedRegular>(this)->getChunk();
case DefinedAbsoluteKind:
return nullptr;
case DefinedSyntheticKind:
return cast<DefinedSynthetic>(this)->getChunk();
case DefinedImportDataKind:
return cast<DefinedImportData>(this)->getChunk();
case DefinedImportThunkKind:
return cast<DefinedImportThunk>(this)->getChunk();
case DefinedLocalImportKind:
return cast<DefinedLocalImport>(this)->getChunk();
case DefinedCommonKind:
return cast<DefinedCommon>(this)->getChunk();
case LazyKind:
case UndefinedKind:
llvm_unreachable("Cannot get the chunk of an undefined symbol.");
}
llvm_unreachable("unknown symbol kind");
}
// A buffer class that is large enough to hold any Symbol-derived
// object. We allocate memory using this class and instantiate a symbol
// using the placement new.
union SymbolUnion {
alignas(DefinedRegular) char a[sizeof(DefinedRegular)];
alignas(DefinedCommon) char b[sizeof(DefinedCommon)];
alignas(DefinedAbsolute) char c[sizeof(DefinedAbsolute)];
alignas(DefinedSynthetic) char d[sizeof(DefinedSynthetic)];
alignas(Lazy) char e[sizeof(Lazy)];
alignas(Undefined) char f[sizeof(Undefined)];
alignas(DefinedImportData) char g[sizeof(DefinedImportData)];
alignas(DefinedImportThunk) char h[sizeof(DefinedImportThunk)];
alignas(DefinedLocalImport) char i[sizeof(DefinedLocalImport)];
};
template <typename T, typename... ArgT>
void replaceSymbol(Symbol *s, ArgT &&... arg) {
static_assert(std::is_trivially_destructible<T>(),
"Symbol types must be trivially destructible");
static_assert(sizeof(T) <= sizeof(SymbolUnion), "Symbol too small");
static_assert(alignof(T) <= alignof(SymbolUnion),
"SymbolUnion not aligned enough");
assert(static_cast<Symbol *>(static_cast<T *>(nullptr)) == nullptr &&
"Not a Symbol");
new (s) T(std::forward<ArgT>(arg)...);
}
} // namespace coff
} // namespace lld
#endif

View File

@@ -1,65 +0,0 @@
//===- TypeMerger.h ---------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLD_COFF_TYPEMERGER_H
#define LLD_COFF_TYPEMERGER_H
#include "Config.h"
#include "llvm/DebugInfo/CodeView/GlobalTypeTableBuilder.h"
#include "llvm/DebugInfo/CodeView/MergingTypeTableBuilder.h"
#include "llvm/Support/Allocator.h"
namespace lld {
namespace coff {
class TypeMerger {
public:
TypeMerger(llvm::BumpPtrAllocator &alloc)
: typeTable(alloc), iDTable(alloc), globalTypeTable(alloc),
globalIDTable(alloc) {}
/// Get the type table or the global type table if /DEBUG:GHASH is enabled.
inline llvm::codeview::TypeCollection &getTypeTable() {
if (config->debugGHashes)
return globalTypeTable;
return typeTable;
}
/// Get the ID table or the global ID table if /DEBUG:GHASH is enabled.
inline llvm::codeview::TypeCollection &getIDTable() {
if (config->debugGHashes)
return globalIDTable;
return iDTable;
}
/// Type records that will go into the PDB TPI stream.
llvm::codeview::MergingTypeTableBuilder typeTable;
/// Item records that will go into the PDB IPI stream.
llvm::codeview::MergingTypeTableBuilder iDTable;
/// Type records that will go into the PDB TPI stream (for /DEBUG:GHASH)
llvm::codeview::GlobalTypeTableBuilder globalTypeTable;
/// Item records that will go into the PDB IPI stream (for /DEBUG:GHASH)
llvm::codeview::GlobalTypeTableBuilder globalIDTable;
};
/// Map from type index and item index in a type server PDB to the
/// corresponding index in the destination PDB.
struct CVIndexMap {
llvm::SmallVector<llvm::codeview::TypeIndex, 0> tpiMap;
llvm::SmallVector<llvm::codeview::TypeIndex, 0> ipiMap;
bool isTypeServerMap = false;
bool isPrecompiledTypeMap = false;
};
} // namespace coff
} // namespace lld
#endif

1932
deps/lld/COFF/Writer.cpp vendored

File diff suppressed because it is too large Load Diff

View File

@@ -1,85 +0,0 @@
//===- Writer.h -------------------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLD_COFF_WRITER_H
#define LLD_COFF_WRITER_H
#include "Chunks.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Object/COFF.h"
#include <chrono>
#include <cstdint>
#include <vector>
namespace lld {
namespace coff {
static const int pageSize = 4096;
void writeResult();
class PartialSection {
public:
PartialSection(StringRef n, uint32_t chars)
: name(n), characteristics(chars) {}
StringRef name;
unsigned characteristics;
std::vector<Chunk *> chunks;
};
// OutputSection represents a section in an output file. It's a
// container of chunks. OutputSection and Chunk are 1:N relationship.
// Chunks cannot belong to more than one OutputSections. The writer
// creates multiple OutputSections and assign them unique,
// non-overlapping file offsets and RVAs.
class OutputSection {
public:
OutputSection(llvm::StringRef n, uint32_t chars) : name(n) {
header.Characteristics = chars;
}
void addChunk(Chunk *c);
void insertChunkAtStart(Chunk *c);
void merge(OutputSection *other);
void setPermissions(uint32_t c);
uint64_t getRVA() { return header.VirtualAddress; }
uint64_t getFileOff() { return header.PointerToRawData; }
void writeHeaderTo(uint8_t *buf);
void addContributingPartialSection(PartialSection *sec);
// Returns the size of this section in an executable memory image.
// This may be smaller than the raw size (the raw size is multiple
// of disk sector size, so there may be padding at end), or may be
// larger (if that's the case, the loader reserves spaces after end
// of raw data).
uint64_t getVirtualSize() { return header.VirtualSize; }
// Returns the size of the section in the output file.
uint64_t getRawSize() { return header.SizeOfRawData; }
// Set offset into the string table storing this section name.
// Used only when the name is longer than 8 bytes.
void setStringTableOff(uint32_t v) { stringTableOff = v; }
// N.B. The section index is one based.
uint32_t sectionIndex = 0;
llvm::StringRef name;
llvm::object::coff_section header = {};
std::vector<Chunk *> chunks;
std::vector<Chunk *> origChunks;
std::vector<PartialSection *> contribSections;
private:
uint32_t stringTableOff = 0;
};
} // namespace coff
} // namespace lld
#endif

View File

@@ -1,82 +0,0 @@
//===- Args.cpp -----------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "lld/Common/Args.h"
#include "lld/Common/ErrorHandler.h"
#include "llvm/ADT/SmallVector.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringRef.h"
#include "llvm/Option/ArgList.h"
#include "llvm/Support/Path.h"
using namespace llvm;
using namespace lld;
// TODO(sbc): Remove this once CGOptLevel can be set completely based on bitcode
// function metadata.
CodeGenOpt::Level lld::args::getCGOptLevel(int optLevelLTO) {
if (optLevelLTO == 3)
return CodeGenOpt::Aggressive;
assert(optLevelLTO < 3);
return CodeGenOpt::Default;
}
int64_t lld::args::getInteger(opt::InputArgList &args, unsigned key,
int64_t Default) {
auto *a = args.getLastArg(key);
if (!a)
return Default;
int64_t v;
if (to_integer(a->getValue(), v, 10))
return v;
StringRef spelling = args.getArgString(a->getIndex());
error(spelling + ": number expected, but got '" + a->getValue() + "'");
return 0;
}
std::vector<StringRef> lld::args::getStrings(opt::InputArgList &args, int id) {
std::vector<StringRef> v;
for (auto *arg : args.filtered(id))
v.push_back(arg->getValue());
return v;
}
uint64_t lld::args::getZOptionValue(opt::InputArgList &args, int id,
StringRef key, uint64_t Default) {
for (auto *arg : args.filtered_reverse(id)) {
std::pair<StringRef, StringRef> kv = StringRef(arg->getValue()).split('=');
if (kv.first == key) {
uint64_t result = Default;
if (!to_integer(kv.second, result))
error("invalid " + key + ": " + kv.second);
return result;
}
}
return Default;
}
std::vector<StringRef> lld::args::getLines(MemoryBufferRef mb) {
SmallVector<StringRef, 0> arr;
mb.getBuffer().split(arr, '\n');
std::vector<StringRef> ret;
for (StringRef s : arr) {
s = s.trim();
if (!s.empty() && s[0] != '#')
ret.push_back(s);
}
return ret;
}
StringRef lld::args::getFilenameWithoutExe(StringRef path) {
if (path.endswith_lower(".exe"))
return sys::path::stem(path);
return sys::path::filename(path);
}

View File

@@ -1,60 +0,0 @@
if(NOT LLD_BUILT_STANDALONE)
set(tablegen_deps intrinsics_gen)
endif()
find_first_existing_vc_file("${LLVM_MAIN_SRC_DIR}" llvm_vc)
find_first_existing_vc_file("${LLD_SOURCE_DIR}" lld_vc)
set(version_inc "${CMAKE_CURRENT_BINARY_DIR}/VCSVersion.inc")
set(generate_vcs_version_script "${LLVM_CMAKE_PATH}/GenerateVersionFromVCS.cmake")
if(lld_vc)
set(lld_source_dir ${LLD_SOURCE_DIR})
endif()
add_custom_command(OUTPUT "${version_inc}"
DEPENDS "${lld_vc}" "${generate_vcs_version_script}"
COMMAND ${CMAKE_COMMAND} "-DNAMES=LLD"
"-DLLD_SOURCE_DIR=${LLD_SOURCE_DIR}"
"-DHEADER_FILE=${version_inc}"
-P "${generate_vcs_version_script}")
# Mark the generated header as being generated.
set_source_files_properties("${version_inc}"
PROPERTIES GENERATED TRUE
HEADER_FILE_ONLY TRUE)
set_property(SOURCE Version.cpp APPEND PROPERTY
COMPILE_DEFINITIONS "HAVE_VCS_VERSION_INC")
add_lld_library(lldCommon
Args.cpp
ErrorHandler.cpp
Filesystem.cpp
Memory.cpp
Reproduce.cpp
Strings.cpp
TargetOptionsCommandFlags.cpp
Threads.cpp
Timer.cpp
VCSVersion.inc
Version.cpp
ADDITIONAL_HEADER_DIRS
${LLD_INCLUDE_DIR}/lld/Common
LINK_COMPONENTS
Codegen
Core
Demangle
MC
Option
Support
Target
LINK_LIBS
${LLVM_PTHREAD_LIB}
DEPENDS
${tablegen_deps}
)

View File

@@ -1,178 +0,0 @@
//===- ErrorHandler.cpp ---------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "lld/Common/ErrorHandler.h"
#include "lld/Common/Threads.h"
#include "llvm/ADT/Twine.h"
#include "llvm/IR/DiagnosticInfo.h"
#include "llvm/IR/DiagnosticPrinter.h"
#include "llvm/Support/ManagedStatic.h"
#include "llvm/Support/raw_ostream.h"
#include <mutex>
#include <regex>
#if !defined(_MSC_VER) && !defined(__MINGW32__)
#include <unistd.h>
#endif
using namespace llvm;
using namespace lld;
// The functions defined in this file can be called from multiple threads,
// but outs() or errs() are not thread-safe. We protect them using a mutex.
static std::mutex mu;
// Prints "\n" or does nothing, depending on Msg contents of
// the previous call of this function.
static void newline(raw_ostream *errorOS, const Twine &msg) {
// True if the previous error message contained "\n".
// We want to separate multi-line error messages with a newline.
static bool flag;
if (flag)
*errorOS << "\n";
flag = StringRef(msg.str()).contains('\n');
}
ErrorHandler &lld::errorHandler() {
static ErrorHandler handler;
return handler;
}
void lld::exitLld(int val) {
// Delete any temporary file, while keeping the memory mapping open.
if (errorHandler().outputBuffer)
errorHandler().outputBuffer->discard();
// Dealloc/destroy ManagedStatic variables before calling
// _exit(). In a non-LTO build, this is a nop. In an LTO
// build allows us to get the output of -time-passes.
llvm_shutdown();
outs().flush();
errs().flush();
_exit(val);
}
void lld::diagnosticHandler(const DiagnosticInfo &di) {
SmallString<128> s;
raw_svector_ostream os(s);
DiagnosticPrinterRawOStream dp(os);
di.print(dp);
switch (di.getSeverity()) {
case DS_Error:
error(s);
break;
case DS_Warning:
warn(s);
break;
case DS_Remark:
case DS_Note:
message(s);
break;
}
}
void lld::checkError(Error e) {
handleAllErrors(std::move(e),
[&](ErrorInfoBase &eib) { error(eib.message()); });
}
static std::string getLocation(std::string msg, std::string defaultMsg) {
static std::vector<std::regex> Regexes{
std::regex(R"(^undefined symbol:.*\n>>> referenced by (\S+):(\d+)\n.*)"),
std::regex(R"(^undefined symbol:.*\n>>> referenced by (.*):)"),
std::regex(
R"(^duplicate symbol: .*\n>>> defined in (\S+)\n>>> defined in.*)"),
std::regex(
R"(^duplicate symbol: .*\n>>> defined at (\S+):(\d+).*)"),
std::regex(
R"(.*\n>>> defined in .*\n>>> referenced by (\S+):(\d+))"),
std::regex(
R"(^undefined (internal|hidden|protected) symbol: .*\n>>> referenced by (\S+):(\d+)\n.*)"),
std::regex(R"((\S+):(\d+): unclosed quote)"),
};
std::smatch Match;
for (std::regex &Re : Regexes) {
if (std::regex_search(msg, Match, Re)) {
return Match.size() > 2 ? Match.str(1) + "(" + Match.str(2) + ")"
: Match.str(1);
}
}
return defaultMsg;
}
void ErrorHandler::printHeader(StringRef s, raw_ostream::Colors c,
const Twine &msg) {
if (vsDiagnostics) {
// A Visual Studio-style error message starts with an error location.
// If a location cannot be extracted then we default to LogName.
*errorOS << getLocation(msg.str(), logName) << ": ";
} else {
*errorOS << logName << ": ";
}
if (colorDiagnostics) {
errorOS->changeColor(c, true);
*errorOS << s;
errorOS->resetColor();
} else {
*errorOS << s;
}
}
void ErrorHandler::log(const Twine &msg) {
if (verbose) {
std::lock_guard<std::mutex> lock(mu);
*errorOS << logName << ": " << msg << "\n";
}
}
void ErrorHandler::message(const Twine &msg) {
std::lock_guard<std::mutex> lock(mu);
outs() << msg << "\n";
outs().flush();
}
void ErrorHandler::warn(const Twine &msg) {
if (fatalWarnings) {
error(msg);
return;
}
std::lock_guard<std::mutex> lock(mu);
newline(errorOS, msg);
printHeader("warning: ", raw_ostream::MAGENTA, msg);
*errorOS << msg << "\n";
}
void ErrorHandler::error(const Twine &msg) {
std::lock_guard<std::mutex> lock(mu);
newline(errorOS, msg);
if (errorLimit == 0 || errorCount < errorLimit) {
printHeader("error: ", raw_ostream::RED, msg);
*errorOS << msg << "\n";
} else if (errorCount == errorLimit) {
printHeader("error: ", raw_ostream::RED, msg);
*errorOS << errorLimitExceededMsg << "\n";
if (exitEarly)
exitLld(1);
}
++errorCount;
}
void ErrorHandler::fatal(const Twine &msg) {
error(msg);
exitLld(1);
}

View File

@@ -1,99 +0,0 @@
//===- Filesystem.cpp -----------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file contains a few utility functions to handle files.
//
//===----------------------------------------------------------------------===//
#include "lld/Common/Filesystem.h"
#include "lld/Common/Threads.h"
#include "llvm/Config/llvm-config.h"
#include "llvm/Support/FileOutputBuffer.h"
#include "llvm/Support/FileSystem.h"
#if LLVM_ON_UNIX
#include <unistd.h>
#endif
#include <thread>
using namespace llvm;
using namespace lld;
// Removes a given file asynchronously. This is a performance hack,
// so remove this when operating systems are improved.
//
// On Linux (and probably on other Unix-like systems), unlink(2) is a
// noticeably slow system call. As of 2016, unlink takes 250
// milliseconds to remove a 1 GB file on ext4 filesystem on my machine.
//
// To create a new result file, we first remove existing file. So, if
// you repeatedly link a 1 GB program in a regular compile-link-debug
// cycle, every cycle wastes 250 milliseconds only to remove a file.
// Since LLD can link a 1 GB binary in about 5 seconds, that waste
// actually counts.
//
// This function spawns a background thread to remove the file.
// The calling thread returns almost immediately.
void lld::unlinkAsync(StringRef path) {
// Removing a file is async on windows.
#if defined(_WIN32)
sys::fs::remove(path);
#else
if (!threadsEnabled || !sys::fs::exists(path) ||
!sys::fs::is_regular_file(path))
return;
// We cannot just remove path from a different thread because we are now going
// to create path as a new file.
// Instead we open the file and unlink it on this thread. The unlink is fast
// since the open fd guarantees that it is not removing the last reference.
int fd;
std::error_code ec = sys::fs::openFileForRead(path, fd);
sys::fs::remove(path);
if (ec)
return;
// close and therefore remove TempPath in background.
std::mutex m;
std::condition_variable cv;
bool started = false;
std::thread([&, fd] {
{
std::lock_guard<std::mutex> l(m);
started = true;
cv.notify_all();
}
::close(fd);
}).detach();
// GLIBC 2.26 and earlier have race condition that crashes an entire process
// if the main thread calls exit(2) while other thread is starting up.
std::unique_lock<std::mutex> l(m);
cv.wait(l, [&] { return started; });
#endif
}
// Simulate file creation to see if Path is writable.
//
// Determining whether a file is writable or not is amazingly hard,
// and after all the only reliable way of doing that is to actually
// create a file. But we don't want to do that in this function
// because LLD shouldn't update any file if it will end in a failure.
// We also don't want to reimplement heuristics to determine if a
// file is writable. So we'll let FileOutputBuffer do the work.
//
// FileOutputBuffer doesn't touch a desitnation file until commit()
// is called. We use that class without calling commit() to predict
// if the given file is writable.
std::error_code lld::tryCreateFile(StringRef path) {
if (path.empty())
return std::error_code();
if (path == "-")
return std::error_code();
return errorToErrorCode(FileOutputBuffer::create(path, 1).takeError());
}

View File

@@ -1,22 +0,0 @@
//===- Memory.cpp ---------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "lld/Common/Memory.h"
using namespace llvm;
using namespace lld;
BumpPtrAllocator lld::bAlloc;
StringSaver lld::saver{bAlloc};
std::vector<SpecificAllocBase *> lld::SpecificAllocBase::instances;
void lld::freeArena() {
for (SpecificAllocBase *alloc : SpecificAllocBase::instances)
alloc->reset();
bAlloc.Reset();
}

View File

@@ -1,61 +0,0 @@
//===- Reproduce.cpp - Utilities for creating reproducers -----------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "lld/Common/Reproduce.h"
#include "llvm/Option/Arg.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FileSystem.h"
#include "llvm/Support/Path.h"
using namespace lld;
using namespace llvm;
using namespace llvm::sys;
// Makes a given pathname an absolute path first, and then remove
// beginning /. For example, "../foo.o" is converted to "home/john/foo.o",
// assuming that the current directory is "/home/john/bar".
// Returned string is a forward slash separated path even on Windows to avoid
// a mess with backslash-as-escape and backslash-as-path-separator.
std::string lld::relativeToRoot(StringRef path) {
SmallString<128> abs = path;
if (fs::make_absolute(abs))
return path;
path::remove_dots(abs, /*remove_dot_dot=*/true);
// This is Windows specific. root_name() returns a drive letter
// (e.g. "c:") or a UNC name (//net). We want to keep it as part
// of the result.
SmallString<128> res;
StringRef root = path::root_name(abs);
if (root.endswith(":"))
res = root.drop_back();
else if (root.startswith("//"))
res = root.substr(2);
path::append(res, path::relative_path(abs));
return path::convert_to_slash(res);
}
// Quote a given string if it contains a space character.
std::string lld::quote(StringRef s) {
if (s.contains(' '))
return ("\"" + s + "\"").str();
return s;
}
// Converts an Arg to a string representation suitable for a response file.
// To show an Arg in a diagnostic, use Arg::getAsString() instead.
std::string lld::toString(const opt::Arg &arg) {
std::string k = arg.getSpelling();
if (arg.getNumValues() == 0)
return k;
std::string v = quote(arg.getValue());
if (arg.getOption().getRenderStyle() == opt::Option::RenderJoinedStyle)
return k + v;
return k + " " + v;
}

View File

@@ -1,103 +0,0 @@
//===- Strings.cpp -------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "lld/Common/Strings.h"
#include "lld/Common/ErrorHandler.h"
#include "lld/Common/LLVM.h"
#include "llvm/Demangle/Demangle.h"
#include "llvm/Support/GlobPattern.h"
#include <algorithm>
#include <mutex>
#include <vector>
using namespace llvm;
using namespace lld;
// Returns the demangled C++ symbol name for Name.
Optional<std::string> lld::demangleItanium(StringRef name) {
// itaniumDemangle can be used to demangle strings other than symbol
// names which do not necessarily start with "_Z". Name can be
// either a C or C++ symbol. Don't call itaniumDemangle if the name
// does not look like a C++ symbol name to avoid getting unexpected
// result for a C symbol that happens to match a mangled type name.
if (!name.startswith("_Z"))
return None;
char *buf = itaniumDemangle(name.str().c_str(), nullptr, nullptr, nullptr);
if (!buf)
return None;
std::string s(buf);
free(buf);
return s;
}
Optional<std::string> lld::demangleMSVC(StringRef name) {
std::string prefix;
if (name.consume_front("__imp_"))
prefix = "__declspec(dllimport) ";
// Demangle only C++ names.
if (!name.startswith("?"))
return None;
char *buf = microsoftDemangle(name.str().c_str(), nullptr, nullptr, nullptr);
if (!buf)
return None;
std::string s(buf);
free(buf);
return prefix + s;
}
StringMatcher::StringMatcher(ArrayRef<StringRef> pat) {
for (StringRef s : pat) {
Expected<GlobPattern> pat = GlobPattern::create(s);
if (!pat)
error(toString(pat.takeError()));
else
patterns.push_back(*pat);
}
}
bool StringMatcher::match(StringRef s) const {
for (const GlobPattern &pat : patterns)
if (pat.match(s))
return true;
return false;
}
// Converts a hex string (e.g. "deadbeef") to a vector.
std::vector<uint8_t> lld::parseHex(StringRef s) {
std::vector<uint8_t> hex;
while (!s.empty()) {
StringRef b = s.substr(0, 2);
s = s.substr(2);
uint8_t h;
if (!to_integer(b, h, 16)) {
error("not a hexadecimal value: " + b);
return {};
}
hex.push_back(h);
}
return hex;
}
// Returns true if S is valid as a C language identifier.
bool lld::isValidCIdentifier(StringRef s) {
return !s.empty() && (isAlpha(s[0]) || s[0] == '_') &&
std::all_of(s.begin() + 1, s.end(),
[](char c) { return c == '_' || isAlnum(c); });
}
// Write the contents of the a buffer to a file
void lld::saveBuffer(StringRef buffer, const Twine &path) {
std::error_code ec;
raw_fd_ostream os(path.str(), ec, sys::fs::OpenFlags::F_None);
if (ec)
error("cannot create " + path + ": " + ec.message());
os << buffer;
}

View File

@@ -1,35 +0,0 @@
//===-- TargetOptionsCommandFlags.cpp ---------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file exists as a place for global variables defined in LLVM's
// CodeGen/CommandFlags.inc. By putting the resulting object file in
// an archive and linking with it, the definitions will automatically be
// included when needed and skipped when already present.
//
//===----------------------------------------------------------------------===//
#include "lld/Common/TargetOptionsCommandFlags.h"
#include "llvm/CodeGen/CommandFlags.inc"
#include "llvm/Target/TargetOptions.h"
// Define an externally visible version of
// initTargetOptionsFromCodeGenFlags, so that its functionality can be
// used without having to include llvm/CodeGen/CommandFlags.inc, which
// would lead to multiple definitions of the command line flags.
llvm::TargetOptions lld::initTargetOptionsFromCodeGenFlags() {
return ::InitTargetOptionsFromCodeGenFlags();
}
llvm::Optional<llvm::CodeModel::Model> lld::getCodeModelFromCMModel() {
return getCodeModel();
}
std::string lld::getCPUStr() { return ::getCPUStr(); }
std::vector<std::string> lld::getMAttrs() { return ::MAttrs; }

View File

@@ -1,11 +0,0 @@
//===- Threads.cpp --------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "lld/Common/Threads.h"
bool lld::threadsEnabled = true;

View File

@@ -1,79 +0,0 @@
//===- Timer.cpp ----------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "lld/Common/Timer.h"
#include "lld/Common/ErrorHandler.h"
#include "llvm/Support/Format.h"
using namespace lld;
using namespace llvm;
ScopedTimer::ScopedTimer(Timer &t) : t(&t) { t.start(); }
void ScopedTimer::stop() {
if (!t)
return;
t->stop();
t = nullptr;
}
ScopedTimer::~ScopedTimer() { stop(); }
Timer::Timer(llvm::StringRef name) : name(name), parent(nullptr) {}
Timer::Timer(llvm::StringRef name, Timer &parent)
: name(name), parent(&parent) {}
void Timer::start() {
if (parent && total.count() == 0)
parent->children.push_back(this);
startTime = std::chrono::high_resolution_clock::now();
}
void Timer::stop() {
total += (std::chrono::high_resolution_clock::now() - startTime);
}
Timer &Timer::root() {
static Timer rootTimer("Total Link Time");
return rootTimer;
}
void Timer::print() {
double totalDuration = static_cast<double>(root().millis());
// We want to print the grand total under all the intermediate phases, so we
// print all children first, then print the total under that.
for (const auto &child : children)
child->print(1, totalDuration);
message(std::string(49, '-'));
root().print(0, root().millis(), false);
}
double Timer::millis() const {
return std::chrono::duration_cast<std::chrono::duration<double, std::milli>>(
total)
.count();
}
void Timer::print(int depth, double totalDuration, bool recurse) const {
double p = 100.0 * millis() / totalDuration;
SmallString<32> str;
llvm::raw_svector_ostream stream(str);
std::string s = std::string(depth * 2, ' ') + name + std::string(":");
stream << format("%-30s%5d ms (%5.1f%%)", s.c_str(), (int)millis(), p);
message(str);
if (recurse) {
for (const auto &child : children)
child->print(depth + 1, totalDuration);
}
}

View File

@@ -1,27 +0,0 @@
//===- lib/Common/Version.cpp - LLD Version Number ---------------*- C++-=====//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
//
// This file defines several version-related utility functions for LLD.
//
//===----------------------------------------------------------------------===//
#include "lld/Common/Version.h"
#ifdef HAVE_VCS_VERSION_INC
#include "VCSVersion.inc"
#endif
// Returns a version string, e.g.:
// lld 9.0.0 (https://github.com/llvm/llvm-project.git 9efdd7ac5e914d3c9fa1ef)
std::string lld::getLLDVersion() {
#if defined(LLD_REPOSITORY) && defined(LLD_REVISION)
return "LLD " LLD_VERSION_STRING " (" LLD_REPOSITORY " " LLD_REVISION ")";
#else
return "LLD " LLD_VERSION_STRING;
#endif
}

View File

@@ -1,651 +0,0 @@
//===- AArch64ErrataFix.cpp -----------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
// This file implements Section Patching for the purpose of working around
// errata in CPUs. The general principle is that an erratum sequence of one or
// more instructions is detected in the instruction stream, one of the
// instructions in the sequence is replaced with a branch to a patch sequence
// of replacement instructions. At the end of the replacement sequence the
// patch branches back to the instruction stream.
// This technique is only suitable for fixing an erratum when:
// - There is a set of necessary conditions required to trigger the erratum that
// can be detected at static link time.
// - There is a set of replacement instructions that can be used to remove at
// least one of the necessary conditions that trigger the erratum.
// - We can overwrite an instruction in the erratum sequence with a branch to
// the replacement sequence.
// - We can place the replacement sequence within range of the branch.
// FIXME:
// - The implementation here only supports one patch, the AArch64 Cortex-53
// errata 843419 that affects r0p0, r0p1, r0p2 and r0p4 versions of the core.
// To keep the initial version simple there is no support for multiple
// architectures or selection of different patches.
//===----------------------------------------------------------------------===//
#include "AArch64ErrataFix.h"
#include "Config.h"
#include "LinkerScript.h"
#include "OutputSections.h"
#include "Relocations.h"
#include "Symbols.h"
#include "SyntheticSections.h"
#include "Target.h"
#include "lld/Common/Memory.h"
#include "lld/Common/Strings.h"
#include "llvm/Support/Endian.h"
#include "llvm/Support/raw_ostream.h"
#include <algorithm>
using namespace llvm;
using namespace llvm::ELF;
using namespace llvm::object;
using namespace llvm::support;
using namespace llvm::support::endian;
using namespace lld;
using namespace lld::elf;
// Helper functions to identify instructions and conditions needed to trigger
// the Cortex-A53-843419 erratum.
// ADRP
// | 1 | immlo (2) | 1 | 0 0 0 0 | immhi (19) | Rd (5) |
static bool isADRP(uint32_t instr) {
return (instr & 0x9f000000) == 0x90000000;
}
// Load and store bit patterns from ARMv8-A ARM ARM.
// Instructions appear in order of appearance starting from table in
// C4.1.3 Loads and Stores.
// All loads and stores have 1 (at bit postion 27), (0 at bit position 25).
// | op0 x op1 (2) | 1 op2 0 op3 (2) | x | op4 (5) | xxxx | op5 (2) | x (10) |
static bool isLoadStoreClass(uint32_t instr) {
return (instr & 0x0a000000) == 0x08000000;
}
// LDN/STN multiple no offset
// | 0 Q 00 | 1100 | 0 L 00 | 0000 | opcode (4) | size (2) | Rn (5) | Rt (5) |
// LDN/STN multiple post-indexed
// | 0 Q 00 | 1100 | 1 L 0 | Rm (5)| opcode (4) | size (2) | Rn (5) | Rt (5) |
// L == 0 for stores.
// Utility routine to decode opcode field of LDN/STN multiple structure
// instructions to find the ST1 instructions.
// opcode == 0010 ST1 4 registers.
// opcode == 0110 ST1 3 registers.
// opcode == 0111 ST1 1 register.
// opcode == 1010 ST1 2 registers.
static bool isST1MultipleOpcode(uint32_t instr) {
return (instr & 0x0000f000) == 0x00002000 ||
(instr & 0x0000f000) == 0x00006000 ||
(instr & 0x0000f000) == 0x00007000 ||
(instr & 0x0000f000) == 0x0000a000;
}
static bool isST1Multiple(uint32_t instr) {
return (instr & 0xbfff0000) == 0x0c000000 && isST1MultipleOpcode(instr);
}
// Writes to Rn (writeback).
static bool isST1MultiplePost(uint32_t instr) {
return (instr & 0xbfe00000) == 0x0c800000 && isST1MultipleOpcode(instr);
}
// LDN/STN single no offset
// | 0 Q 00 | 1101 | 0 L R 0 | 0000 | opc (3) S | size (2) | Rn (5) | Rt (5)|
// LDN/STN single post-indexed
// | 0 Q 00 | 1101 | 1 L R | Rm (5) | opc (3) S | size (2) | Rn (5) | Rt (5)|
// L == 0 for stores
// Utility routine to decode opcode field of LDN/STN single structure
// instructions to find the ST1 instructions.
// R == 0 for ST1 and ST3, R == 1 for ST2 and ST4.
// opcode == 000 ST1 8-bit.
// opcode == 010 ST1 16-bit.
// opcode == 100 ST1 32 or 64-bit (Size determines which).
static bool isST1SingleOpcode(uint32_t instr) {
return (instr & 0x0040e000) == 0x00000000 ||
(instr & 0x0040e000) == 0x00004000 ||
(instr & 0x0040e000) == 0x00008000;
}
static bool isST1Single(uint32_t instr) {
return (instr & 0xbfff0000) == 0x0d000000 && isST1SingleOpcode(instr);
}
// Writes to Rn (writeback).
static bool isST1SinglePost(uint32_t instr) {
return (instr & 0xbfe00000) == 0x0d800000 && isST1SingleOpcode(instr);
}
static bool isST1(uint32_t instr) {
return isST1Multiple(instr) || isST1MultiplePost(instr) ||
isST1Single(instr) || isST1SinglePost(instr);
}
// Load/store exclusive
// | size (2) 00 | 1000 | o2 L o1 | Rs (5) | o0 | Rt2 (5) | Rn (5) | Rt (5) |
// L == 0 for Stores.
static bool isLoadStoreExclusive(uint32_t instr) {
return (instr & 0x3f000000) == 0x08000000;
}
static bool isLoadExclusive(uint32_t instr) {
return (instr & 0x3f400000) == 0x08400000;
}
// Load register literal
// | opc (2) 01 | 1 V 00 | imm19 | Rt (5) |
static bool isLoadLiteral(uint32_t instr) {
return (instr & 0x3b000000) == 0x18000000;
}
// Load/store no-allocate pair
// (offset)
// | opc (2) 10 | 1 V 00 | 0 L | imm7 | Rt2 (5) | Rn (5) | Rt (5) |
// L == 0 for stores.
// Never writes to register
static bool isSTNP(uint32_t instr) {
return (instr & 0x3bc00000) == 0x28000000;
}
// Load/store register pair
// (post-indexed)
// | opc (2) 10 | 1 V 00 | 1 L | imm7 | Rt2 (5) | Rn (5) | Rt (5) |
// L == 0 for stores, V == 0 for Scalar, V == 1 for Simd/FP
// Writes to Rn.
static bool isSTPPost(uint32_t instr) {
return (instr & 0x3bc00000) == 0x28800000;
}
// (offset)
// | opc (2) 10 | 1 V 01 | 0 L | imm7 | Rt2 (5) | Rn (5) | Rt (5) |
static bool isSTPOffset(uint32_t instr) {
return (instr & 0x3bc00000) == 0x29000000;
}
// (pre-index)
// | opc (2) 10 | 1 V 01 | 1 L | imm7 | Rt2 (5) | Rn (5) | Rt (5) |
// Writes to Rn.
static bool isSTPPre(uint32_t instr) {
return (instr & 0x3bc00000) == 0x29800000;
}
static bool isSTP(uint32_t instr) {
return isSTPPost(instr) || isSTPOffset(instr) || isSTPPre(instr);
}
// Load/store register (unscaled immediate)
// | size (2) 11 | 1 V 00 | opc (2) 0 | imm9 | 00 | Rn (5) | Rt (5) |
// V == 0 for Scalar, V == 1 for Simd/FP.
static bool isLoadStoreUnscaled(uint32_t instr) {
return (instr & 0x3b000c00) == 0x38000000;
}
// Load/store register (immediate post-indexed)
// | size (2) 11 | 1 V 00 | opc (2) 0 | imm9 | 01 | Rn (5) | Rt (5) |
static bool isLoadStoreImmediatePost(uint32_t instr) {
return (instr & 0x3b200c00) == 0x38000400;
}
// Load/store register (unprivileged)
// | size (2) 11 | 1 V 00 | opc (2) 0 | imm9 | 10 | Rn (5) | Rt (5) |
static bool isLoadStoreUnpriv(uint32_t instr) {
return (instr & 0x3b200c00) == 0x38000800;
}
// Load/store register (immediate pre-indexed)
// | size (2) 11 | 1 V 00 | opc (2) 0 | imm9 | 11 | Rn (5) | Rt (5) |
static bool isLoadStoreImmediatePre(uint32_t instr) {
return (instr & 0x3b200c00) == 0x38000c00;
}
// Load/store register (register offset)
// | size (2) 11 | 1 V 00 | opc (2) 1 | Rm (5) | option (3) S | 10 | Rn | Rt |
static bool isLoadStoreRegisterOff(uint32_t instr) {
return (instr & 0x3b200c00) == 0x38200800;
}
// Load/store register (unsigned immediate)
// | size (2) 11 | 1 V 01 | opc (2) | imm12 | Rn (5) | Rt (5) |
static bool isLoadStoreRegisterUnsigned(uint32_t instr) {
return (instr & 0x3b000000) == 0x39000000;
}
// Rt is always in bit position 0 - 4.
static uint32_t getRt(uint32_t instr) { return (instr & 0x1f); }
// Rn is always in bit position 5 - 9.
static uint32_t getRn(uint32_t instr) { return (instr >> 5) & 0x1f; }
// C4.1.2 Branches, Exception Generating and System instructions
// | op0 (3) 1 | 01 op1 (4) | x (22) |
// op0 == 010 101 op1 == 0xxx Conditional Branch.
// op0 == 110 101 op1 == 1xxx Unconditional Branch Register.
// op0 == x00 101 op1 == xxxx Unconditional Branch immediate.
// op0 == x01 101 op1 == 0xxx Compare and branch immediate.
// op0 == x01 101 op1 == 1xxx Test and branch immediate.
static bool isBranch(uint32_t instr) {
return ((instr & 0xfe000000) == 0xd6000000) || // Cond branch.
((instr & 0xfe000000) == 0x54000000) || // Uncond branch reg.
((instr & 0x7c000000) == 0x14000000) || // Uncond branch imm.
((instr & 0x7c000000) == 0x34000000); // Compare and test branch.
}
static bool isV8SingleRegisterNonStructureLoadStore(uint32_t instr) {
return isLoadStoreUnscaled(instr) || isLoadStoreImmediatePost(instr) ||
isLoadStoreUnpriv(instr) || isLoadStoreImmediatePre(instr) ||
isLoadStoreRegisterOff(instr) || isLoadStoreRegisterUnsigned(instr);
}
// Note that this function refers to v8.0 only and does not include the
// additional load and store instructions added for in later revisions of
// the architecture such as the Atomic memory operations introduced
// in v8.1.
static bool isV8NonStructureLoad(uint32_t instr) {
if (isLoadExclusive(instr))
return true;
if (isLoadLiteral(instr))
return true;
else if (isV8SingleRegisterNonStructureLoadStore(instr)) {
// For Load and Store single register, Loads are derived from a
// combination of the Size, V and Opc fields.
uint32_t size = (instr >> 30) & 0xff;
uint32_t v = (instr >> 26) & 0x1;
uint32_t opc = (instr >> 22) & 0x3;
// For the load and store instructions that we are decoding.
// Opc == 0 are all stores.
// Opc == 1 with a couple of exceptions are loads. The exceptions are:
// Size == 00 (0), V == 1, Opc == 10 (2) which is a store and
// Size == 11 (3), V == 0, Opc == 10 (2) which is a prefetch.
return opc != 0 && !(size == 0 && v == 1 && opc == 2) &&
!(size == 3 && v == 0 && opc == 2);
}
return false;
}
// The following decode instructions are only complete up to the instructions
// needed for errata 843419.
// Instruction with writeback updates the index register after the load/store.
static bool hasWriteback(uint32_t instr) {
return isLoadStoreImmediatePre(instr) || isLoadStoreImmediatePost(instr) ||
isSTPPre(instr) || isSTPPost(instr) || isST1SinglePost(instr) ||
isST1MultiplePost(instr);
}
// For the load and store class of instructions, a load can write to the
// destination register, a load and a store can write to the base register when
// the instruction has writeback.
static bool doesLoadStoreWriteToReg(uint32_t instr, uint32_t reg) {
return (isV8NonStructureLoad(instr) && getRt(instr) == reg) ||
(hasWriteback(instr) && getRn(instr) == reg);
}
// Scanner for Cortex-A53 errata 843419
// Full details are available in the Cortex A53 MPCore revision 0 Software
// Developers Errata Notice (ARM-EPM-048406).
//
// The instruction sequence that triggers the erratum is common in compiled
// AArch64 code, however it is sensitive to the offset of the sequence within
// a 4k page. This means that by scanning and fixing the patch after we have
// assigned addresses we only need to disassemble and fix instances of the
// sequence in the range of affected offsets.
//
// In summary the erratum conditions are a series of 4 instructions:
// 1.) An ADRP instruction that writes to register Rn with low 12 bits of
// address of instruction either 0xff8 or 0xffc.
// 2.) A load or store instruction that can be:
// - A single register load or store, of either integer or vector registers.
// - An STP or STNP, of either integer or vector registers.
// - An Advanced SIMD ST1 store instruction.
// - Must not write to Rn, but may optionally read from it.
// 3.) An optional instruction that is not a branch and does not write to Rn.
// 4.) A load or store from the Load/store register (unsigned immediate) class
// that uses Rn as the base address register.
//
// Note that we do not attempt to scan for Sequence 2 as described in the
// Software Developers Errata Notice as this has been assessed to be extremely
// unlikely to occur in compiled code. This matches gold and ld.bfd behavior.
// Return true if the Instruction sequence Adrp, Instr2, and Instr4 match
// the erratum sequence. The Adrp, Instr2 and Instr4 correspond to 1.), 2.),
// and 4.) in the Scanner for Cortex-A53 errata comment above.
static bool is843419ErratumSequence(uint32_t instr1, uint32_t instr2,
uint32_t instr4) {
if (!isADRP(instr1))
return false;
uint32_t rn = getRt(instr1);
return isLoadStoreClass(instr2) &&
(isLoadStoreExclusive(instr2) || isLoadLiteral(instr2) ||
isV8SingleRegisterNonStructureLoadStore(instr2) || isSTP(instr2) ||
isSTNP(instr2) || isST1(instr2)) &&
!doesLoadStoreWriteToReg(instr2, rn) &&
isLoadStoreRegisterUnsigned(instr4) && getRn(instr4) == rn;
}
// Scan the instruction sequence starting at Offset Off from the base of
// InputSection IS. We update Off in this function rather than in the caller as
// we can skip ahead much further into the section when we know how many
// instructions we've scanned.
// Return the offset of the load or store instruction in IS that we want to
// patch or 0 if no patch required.
static uint64_t scanCortexA53Errata843419(InputSection *isec, uint64_t &off,
uint64_t limit) {
uint64_t isecAddr = isec->getVA(0);
// Advance Off so that (ISAddr + Off) modulo 0x1000 is at least 0xff8.
uint64_t initialPageOff = (isecAddr + off) & 0xfff;
if (initialPageOff < 0xff8)
off += 0xff8 - initialPageOff;
bool optionalAllowed = limit - off > 12;
if (off >= limit || limit - off < 12) {
// Need at least 3 4-byte sized instructions to trigger erratum.
off = limit;
return 0;
}
uint64_t patchOff = 0;
const uint8_t *buf = isec->data().begin();
const ulittle32_t *instBuf = reinterpret_cast<const ulittle32_t *>(buf + off);
uint32_t instr1 = *instBuf++;
uint32_t instr2 = *instBuf++;
uint32_t instr3 = *instBuf++;
if (is843419ErratumSequence(instr1, instr2, instr3)) {
patchOff = off + 8;
} else if (optionalAllowed && !isBranch(instr3)) {
uint32_t instr4 = *instBuf++;
if (is843419ErratumSequence(instr1, instr2, instr4))
patchOff = off + 12;
}
if (((isecAddr + off) & 0xfff) == 0xff8)
off += 4;
else
off += 0xffc;
return patchOff;
}
class lld::elf::Patch843419Section : public SyntheticSection {
public:
Patch843419Section(InputSection *p, uint64_t off);
void writeTo(uint8_t *buf) override;
size_t getSize() const override { return 8; }
uint64_t getLDSTAddr() const;
// The Section we are patching.
const InputSection *patchee;
// The offset of the instruction in the Patchee section we are patching.
uint64_t patcheeOffset;
// A label for the start of the Patch that we can use as a relocation target.
Symbol *patchSym;
};
lld::elf::Patch843419Section::Patch843419Section(InputSection *p, uint64_t off)
: SyntheticSection(SHF_ALLOC | SHF_EXECINSTR, SHT_PROGBITS, 4,
".text.patch"),
patchee(p), patcheeOffset(off) {
this->parent = p->getParent();
patchSym = addSyntheticLocal(
saver.save("__CortexA53843419_" + utohexstr(getLDSTAddr())), STT_FUNC, 0,
getSize(), *this);
addSyntheticLocal(saver.save("$x"), STT_NOTYPE, 0, 0, *this);
}
uint64_t lld::elf::Patch843419Section::getLDSTAddr() const {
return patchee->getVA(patcheeOffset);
}
void lld::elf::Patch843419Section::writeTo(uint8_t *buf) {
// Copy the instruction that we will be replacing with a branch in the
// Patchee Section.
write32le(buf, read32le(patchee->data().begin() + patcheeOffset));
// Apply any relocation transferred from the original PatcheeSection.
// For a SyntheticSection Buf already has outSecOff added, but relocateAlloc
// also adds outSecOff so we need to subtract to avoid double counting.
this->relocateAlloc(buf - outSecOff, buf - outSecOff + getSize());
// Return address is the next instruction after the one we have just copied.
uint64_t s = getLDSTAddr() + 4;
uint64_t p = patchSym->getVA() + 4;
target->relocateOne(buf + 4, R_AARCH64_JUMP26, s - p);
}
void AArch64Err843419Patcher::init() {
// The AArch64 ABI permits data in executable sections. We must avoid scanning
// this data as if it were instructions to avoid false matches. We use the
// mapping symbols in the InputObjects to identify this data, caching the
// results in sectionMap so we don't have to recalculate it each pass.
// The ABI Section 4.5.4 Mapping symbols; defines local symbols that describe
// half open intervals [Symbol Value, Next Symbol Value) of code and data
// within sections. If there is no next symbol then the half open interval is
// [Symbol Value, End of section). The type, code or data, is determined by
// the mapping symbol name, $x for code, $d for data.
auto isCodeMapSymbol = [](const Symbol *b) {
return b->getName() == "$x" || b->getName().startswith("$x.");
};
auto isDataMapSymbol = [](const Symbol *b) {
return b->getName() == "$d" || b->getName().startswith("$d.");
};
// Collect mapping symbols for every executable InputSection.
for (InputFile *file : objectFiles) {
auto *f = cast<ObjFile<ELF64LE>>(file);
for (Symbol *b : f->getLocalSymbols()) {
auto *def = dyn_cast<Defined>(b);
if (!def)
continue;
if (!isCodeMapSymbol(def) && !isDataMapSymbol(def))
continue;
if (auto *sec = dyn_cast_or_null<InputSection>(def->section))
if (sec->flags & SHF_EXECINSTR)
sectionMap[sec].push_back(def);
}
}
// For each InputSection make sure the mapping symbols are in sorted in
// ascending order and free from consecutive runs of mapping symbols with
// the same type. For example we must remove the redundant $d.1 from $x.0
// $d.0 $d.1 $x.1.
for (auto &kv : sectionMap) {
std::vector<const Defined *> &mapSyms = kv.second;
if (mapSyms.size() <= 1)
continue;
llvm::stable_sort(mapSyms, [](const Defined *a, const Defined *b) {
return a->value < b->value;
});
mapSyms.erase(
std::unique(mapSyms.begin(), mapSyms.end(),
[=](const Defined *a, const Defined *b) {
return (isCodeMapSymbol(a) && isCodeMapSymbol(b)) ||
(isDataMapSymbol(a) && isDataMapSymbol(b));
}),
mapSyms.end());
}
initialized = true;
}
// Insert the PatchSections we have created back into the
// InputSectionDescription. As inserting patches alters the addresses of
// InputSections that follow them, we try and place the patches after all the
// executable sections, although we may need to insert them earlier if the
// InputSectionDescription is larger than the maximum branch range.
void AArch64Err843419Patcher::insertPatches(
InputSectionDescription &isd, std::vector<Patch843419Section *> &patches) {
uint64_t isecLimit;
uint64_t prevIsecLimit = isd.sections.front()->outSecOff;
uint64_t patchUpperBound = prevIsecLimit + target->getThunkSectionSpacing();
uint64_t outSecAddr = isd.sections.front()->getParent()->addr;
// Set the outSecOff of patches to the place where we want to insert them.
// We use a similar strategy to Thunk placement. Place patches roughly
// every multiple of maximum branch range.
auto patchIt = patches.begin();
auto patchEnd = patches.end();
for (const InputSection *isec : isd.sections) {
isecLimit = isec->outSecOff + isec->getSize();
if (isecLimit > patchUpperBound) {
while (patchIt != patchEnd) {
if ((*patchIt)->getLDSTAddr() - outSecAddr >= prevIsecLimit)
break;
(*patchIt)->outSecOff = prevIsecLimit;
++patchIt;
}
patchUpperBound = prevIsecLimit + target->getThunkSectionSpacing();
}
prevIsecLimit = isecLimit;
}
for (; patchIt != patchEnd; ++patchIt) {
(*patchIt)->outSecOff = isecLimit;
}
// merge all patch sections. We use the outSecOff assigned above to
// determine the insertion point. This is ok as we only merge into an
// InputSectionDescription once per pass, and at the end of the pass
// assignAddresses() will recalculate all the outSecOff values.
std::vector<InputSection *> tmp;
tmp.reserve(isd.sections.size() + patches.size());
auto mergeCmp = [](const InputSection *a, const InputSection *b) {
if (a->outSecOff < b->outSecOff)
return true;
if (a->outSecOff == b->outSecOff && isa<Patch843419Section>(a) &&
!isa<Patch843419Section>(b))
return true;
return false;
};
std::merge(isd.sections.begin(), isd.sections.end(), patches.begin(),
patches.end(), std::back_inserter(tmp), mergeCmp);
isd.sections = std::move(tmp);
}
// Given an erratum sequence that starts at address adrpAddr, with an
// instruction that we need to patch at patcheeOffset from the start of
// InputSection IS, create a Patch843419 Section and add it to the
// Patches that we need to insert.
static void implementPatch(uint64_t adrpAddr, uint64_t patcheeOffset,
InputSection *isec,
std::vector<Patch843419Section *> &patches) {
// There may be a relocation at the same offset that we are patching. There
// are four cases that we need to consider.
// Case 1: R_AARCH64_JUMP26 branch relocation. We have already patched this
// instance of the erratum on a previous patch and altered the relocation. We
// have nothing more to do.
// Case 2: A TLS Relaxation R_RELAX_TLS_IE_TO_LE. In this case the ADRP that
// we read will be transformed into a MOVZ later so we actually don't match
// the sequence and have nothing more to do.
// Case 3: A load/store register (unsigned immediate) class relocation. There
// are two of these R_AARCH_LD64_ABS_LO12_NC and R_AARCH_LD64_GOT_LO12_NC and
// they are both absolute. We need to add the same relocation to the patch,
// and replace the relocation with a R_AARCH_JUMP26 branch relocation.
// Case 4: No relocation. We must create a new R_AARCH64_JUMP26 branch
// relocation at the offset.
auto relIt = llvm::find_if(isec->relocations, [=](const Relocation &r) {
return r.offset == patcheeOffset;
});
if (relIt != isec->relocations.end() &&
(relIt->type == R_AARCH64_JUMP26 || relIt->expr == R_RELAX_TLS_IE_TO_LE))
return;
log("detected cortex-a53-843419 erratum sequence starting at " +
utohexstr(adrpAddr) + " in unpatched output.");
auto *ps = make<Patch843419Section>(isec, patcheeOffset);
patches.push_back(ps);
auto makeRelToPatch = [](uint64_t offset, Symbol *patchSym) {
return Relocation{R_PC, R_AARCH64_JUMP26, offset, 0, patchSym};
};
if (relIt != isec->relocations.end()) {
ps->relocations.push_back(
{relIt->expr, relIt->type, 0, relIt->addend, relIt->sym});
*relIt = makeRelToPatch(patcheeOffset, ps->patchSym);
} else
isec->relocations.push_back(makeRelToPatch(patcheeOffset, ps->patchSym));
}
// Scan all the instructions in InputSectionDescription, for each instance of
// the erratum sequence create a Patch843419Section. We return the list of
// Patch843419Sections that need to be applied to ISD.
std::vector<Patch843419Section *>
AArch64Err843419Patcher::patchInputSectionDescription(
InputSectionDescription &isd) {
std::vector<Patch843419Section *> patches;
for (InputSection *isec : isd.sections) {
// LLD doesn't use the erratum sequence in SyntheticSections.
if (isa<SyntheticSection>(isec))
continue;
// Use sectionMap to make sure we only scan code and not inline data.
// We have already sorted MapSyms in ascending order and removed consecutive
// mapping symbols of the same type. Our range of executable instructions to
// scan is therefore [codeSym->value, dataSym->value) or [codeSym->value,
// section size).
std::vector<const Defined *> &mapSyms = sectionMap[isec];
auto codeSym = llvm::find_if(mapSyms, [&](const Defined *ms) {
return ms->getName().startswith("$x");
});
while (codeSym != mapSyms.end()) {
auto dataSym = std::next(codeSym);
uint64_t off = (*codeSym)->value;
uint64_t limit =
(dataSym == mapSyms.end()) ? isec->data().size() : (*dataSym)->value;
while (off < limit) {
uint64_t startAddr = isec->getVA(off);
if (uint64_t patcheeOffset = scanCortexA53Errata843419(isec, off, limit))
implementPatch(startAddr, patcheeOffset, isec, patches);
}
if (dataSym == mapSyms.end())
break;
codeSym = std::next(dataSym);
}
}
return patches;
}
// For each InputSectionDescription make one pass over the executable sections
// looking for the erratum sequence; creating a synthetic Patch843419Section
// for each instance found. We insert these synthetic patch sections after the
// executable code in each InputSectionDescription.
//
// PreConditions:
// The Output and Input Sections have had their final addresses assigned.
//
// PostConditions:
// Returns true if at least one patch was added. The addresses of the
// Ouptut and Input Sections may have been changed.
// Returns false if no patches were required and no changes were made.
bool AArch64Err843419Patcher::createFixes() {
if (initialized == false)
init();
bool addressesChanged = false;
for (OutputSection *os : outputSections) {
if (!(os->flags & SHF_ALLOC) || !(os->flags & SHF_EXECINSTR))
continue;
for (BaseCommand *bc : os->sectionCommands)
if (auto *isd = dyn_cast<InputSectionDescription>(bc)) {
std::vector<Patch843419Section *> patches =
patchInputSectionDescription(*isd);
if (!patches.empty()) {
insertPatches(*isd, patches);
addressesChanged = true;
}
}
}
return addressesChanged;
}

View File

@@ -1,50 +0,0 @@
//===- AArch64ErrataFix.h ---------------------------------------*- C++ -*-===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#ifndef LLD_ELF_AARCH64ERRATAFIX_H
#define LLD_ELF_AARCH64ERRATAFIX_H
#include "lld/Common/LLVM.h"
#include <map>
#include <vector>
namespace lld {
namespace elf {
class Defined;
class InputSection;
struct InputSectionDescription;
class OutputSection;
class Patch843419Section;
class AArch64Err843419Patcher {
public:
// return true if Patches have been added to the OutputSections.
bool createFixes();
private:
std::vector<Patch843419Section *>
patchInputSectionDescription(InputSectionDescription &isd);
void insertPatches(InputSectionDescription &isd,
std::vector<Patch843419Section *> &patches);
void init();
// A cache of the mapping symbols defined by the InputSection sorted in order
// of ascending value with redundant symbols removed. These describe
// the ranges of code and data in an executable InputSection.
std::map<InputSection *, std::vector<const Defined *>> sectionMap;
bool initialized = false;
};
} // namespace elf
} // namespace lld
#endif

View File

@@ -1,590 +0,0 @@
//===- AArch64.cpp --------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "Symbols.h"
#include "SyntheticSections.h"
#include "Target.h"
#include "Thunks.h"
#include "lld/Common/ErrorHandler.h"
#include "llvm/Object/ELF.h"
#include "llvm/Support/Endian.h"
using namespace llvm;
using namespace llvm::support::endian;
using namespace llvm::ELF;
using namespace lld;
using namespace lld::elf;
// Page(Expr) is the page address of the expression Expr, defined
// as (Expr & ~0xFFF). (This applies even if the machine page size
// supported by the platform has a different value.)
uint64_t elf::getAArch64Page(uint64_t expr) {
return expr & ~static_cast<uint64_t>(0xFFF);
}
namespace {
class AArch64 : public TargetInfo {
public:
AArch64();
RelExpr getRelExpr(RelType type, const Symbol &s,
const uint8_t *loc) const override;
RelType getDynRel(RelType type) const override;
void writeGotPlt(uint8_t *buf, const Symbol &s) const override;
void writePltHeader(uint8_t *buf) const override;
void writePlt(uint8_t *buf, uint64_t gotPltEntryAddr, uint64_t pltEntryAddr,
int32_t index, unsigned relOff) const override;
bool needsThunk(RelExpr expr, RelType type, const InputFile *file,
uint64_t branchAddr, const Symbol &s) const override;
uint32_t getThunkSectionSpacing() const override;
bool inBranchRange(RelType type, uint64_t src, uint64_t dst) const override;
bool usesOnlyLowPageBits(RelType type) const override;
void relocateOne(uint8_t *loc, RelType type, uint64_t val) const override;
RelExpr adjustRelaxExpr(RelType type, const uint8_t *data,
RelExpr expr) const override;
void relaxTlsGdToLe(uint8_t *loc, RelType type, uint64_t val) const override;
void relaxTlsGdToIe(uint8_t *loc, RelType type, uint64_t val) const override;
void relaxTlsIeToLe(uint8_t *loc, RelType type, uint64_t val) const override;
};
} // namespace
AArch64::AArch64() {
copyRel = R_AARCH64_COPY;
relativeRel = R_AARCH64_RELATIVE;
iRelativeRel = R_AARCH64_IRELATIVE;
gotRel = R_AARCH64_GLOB_DAT;
noneRel = R_AARCH64_NONE;
pltRel = R_AARCH64_JUMP_SLOT;
symbolicRel = R_AARCH64_ABS64;
tlsDescRel = R_AARCH64_TLSDESC;
tlsGotRel = R_AARCH64_TLS_TPREL64;
pltEntrySize = 16;
pltHeaderSize = 32;
defaultMaxPageSize = 65536;
// Align to the 2 MiB page size (known as a superpage or huge page).
// FreeBSD automatically promotes 2 MiB-aligned allocations.
defaultImageBase = 0x200000;
needsThunks = true;
}
RelExpr AArch64::getRelExpr(RelType type, const Symbol &s,
const uint8_t *loc) const {
switch (type) {
case R_AARCH64_TLSDESC_ADR_PAGE21:
return R_AARCH64_TLSDESC_PAGE;
case R_AARCH64_TLSDESC_LD64_LO12:
case R_AARCH64_TLSDESC_ADD_LO12:
return R_TLSDESC;
case R_AARCH64_TLSDESC_CALL:
return R_TLSDESC_CALL;
case R_AARCH64_TLSLE_ADD_TPREL_HI12:
case R_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
case R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC:
case R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC:
case R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC:
case R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC:
case R_AARCH64_TLSLE_LDST128_TPREL_LO12_NC:
return R_TLS;
case R_AARCH64_CALL26:
case R_AARCH64_CONDBR19:
case R_AARCH64_JUMP26:
case R_AARCH64_TSTBR14:
return R_PLT_PC;
case R_AARCH64_PREL16:
case R_AARCH64_PREL32:
case R_AARCH64_PREL64:
case R_AARCH64_ADR_PREL_LO21:
case R_AARCH64_LD_PREL_LO19:
return R_PC;
case R_AARCH64_ADR_PREL_PG_HI21:
case R_AARCH64_ADR_PREL_PG_HI21_NC:
return R_AARCH64_PAGE_PC;
case R_AARCH64_LD64_GOT_LO12_NC:
case R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
return R_GOT;
case R_AARCH64_ADR_GOT_PAGE:
case R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
return R_AARCH64_GOT_PAGE_PC;
case R_AARCH64_NONE:
return R_NONE;
default:
return R_ABS;
}
}
RelExpr AArch64::adjustRelaxExpr(RelType type, const uint8_t *data,
RelExpr expr) const {
if (expr == R_RELAX_TLS_GD_TO_IE) {
if (type == R_AARCH64_TLSDESC_ADR_PAGE21)
return R_AARCH64_RELAX_TLS_GD_TO_IE_PAGE_PC;
return R_RELAX_TLS_GD_TO_IE_ABS;
}
return expr;
}
bool AArch64::usesOnlyLowPageBits(RelType type) const {
switch (type) {
default:
return false;
case R_AARCH64_ADD_ABS_LO12_NC:
case R_AARCH64_LD64_GOT_LO12_NC:
case R_AARCH64_LDST128_ABS_LO12_NC:
case R_AARCH64_LDST16_ABS_LO12_NC:
case R_AARCH64_LDST32_ABS_LO12_NC:
case R_AARCH64_LDST64_ABS_LO12_NC:
case R_AARCH64_LDST8_ABS_LO12_NC:
case R_AARCH64_TLSDESC_ADD_LO12:
case R_AARCH64_TLSDESC_LD64_LO12:
case R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
return true;
}
}
RelType AArch64::getDynRel(RelType type) const {
if (type == R_AARCH64_ABS64)
return type;
return R_AARCH64_NONE;
}
void AArch64::writeGotPlt(uint8_t *buf, const Symbol &) const {
write64le(buf, in.plt->getVA());
}
void AArch64::writePltHeader(uint8_t *buf) const {
const uint8_t pltData[] = {
0xf0, 0x7b, 0xbf, 0xa9, // stp x16, x30, [sp,#-16]!
0x10, 0x00, 0x00, 0x90, // adrp x16, Page(&(.plt.got[2]))
0x11, 0x02, 0x40, 0xf9, // ldr x17, [x16, Offset(&(.plt.got[2]))]
0x10, 0x02, 0x00, 0x91, // add x16, x16, Offset(&(.plt.got[2]))
0x20, 0x02, 0x1f, 0xd6, // br x17
0x1f, 0x20, 0x03, 0xd5, // nop
0x1f, 0x20, 0x03, 0xd5, // nop
0x1f, 0x20, 0x03, 0xd5 // nop
};
memcpy(buf, pltData, sizeof(pltData));
uint64_t got = in.gotPlt->getVA();
uint64_t plt = in.plt->getVA();
relocateOne(buf + 4, R_AARCH64_ADR_PREL_PG_HI21,
getAArch64Page(got + 16) - getAArch64Page(plt + 4));
relocateOne(buf + 8, R_AARCH64_LDST64_ABS_LO12_NC, got + 16);
relocateOne(buf + 12, R_AARCH64_ADD_ABS_LO12_NC, got + 16);
}
void AArch64::writePlt(uint8_t *buf, uint64_t gotPltEntryAddr,
uint64_t pltEntryAddr, int32_t index,
unsigned relOff) const {
const uint8_t inst[] = {
0x10, 0x00, 0x00, 0x90, // adrp x16, Page(&(.plt.got[n]))
0x11, 0x02, 0x40, 0xf9, // ldr x17, [x16, Offset(&(.plt.got[n]))]
0x10, 0x02, 0x00, 0x91, // add x16, x16, Offset(&(.plt.got[n]))
0x20, 0x02, 0x1f, 0xd6 // br x17
};
memcpy(buf, inst, sizeof(inst));
relocateOne(buf, R_AARCH64_ADR_PREL_PG_HI21,
getAArch64Page(gotPltEntryAddr) - getAArch64Page(pltEntryAddr));
relocateOne(buf + 4, R_AARCH64_LDST64_ABS_LO12_NC, gotPltEntryAddr);
relocateOne(buf + 8, R_AARCH64_ADD_ABS_LO12_NC, gotPltEntryAddr);
}
bool AArch64::needsThunk(RelExpr expr, RelType type, const InputFile *file,
uint64_t branchAddr, const Symbol &s) const {
// ELF for the ARM 64-bit architecture, section Call and Jump relocations
// only permits range extension thunks for R_AARCH64_CALL26 and
// R_AARCH64_JUMP26 relocation types.
if (type != R_AARCH64_CALL26 && type != R_AARCH64_JUMP26)
return false;
uint64_t dst = (expr == R_PLT_PC) ? s.getPltVA() : s.getVA();
return !inBranchRange(type, branchAddr, dst);
}
uint32_t AArch64::getThunkSectionSpacing() const {
// See comment in Arch/ARM.cpp for a more detailed explanation of
// getThunkSectionSpacing(). For AArch64 the only branches we are permitted to
// Thunk have a range of +/- 128 MiB
return (128 * 1024 * 1024) - 0x30000;
}
bool AArch64::inBranchRange(RelType type, uint64_t src, uint64_t dst) const {
if (type != R_AARCH64_CALL26 && type != R_AARCH64_JUMP26)
return true;
// The AArch64 call and unconditional branch instructions have a range of
// +/- 128 MiB.
uint64_t range = 128 * 1024 * 1024;
if (dst > src) {
// Immediate of branch is signed.
range -= 4;
return dst - src <= range;
}
return src - dst <= range;
}
static void write32AArch64Addr(uint8_t *l, uint64_t imm) {
uint32_t immLo = (imm & 0x3) << 29;
uint32_t immHi = (imm & 0x1FFFFC) << 3;
uint64_t mask = (0x3 << 29) | (0x1FFFFC << 3);
write32le(l, (read32le(l) & ~mask) | immLo | immHi);
}
// Return the bits [Start, End] from Val shifted Start bits.
// For instance, getBits(0xF0, 4, 8) returns 0xF.
static uint64_t getBits(uint64_t val, int start, int end) {
uint64_t mask = ((uint64_t)1 << (end + 1 - start)) - 1;
return (val >> start) & mask;
}
static void or32le(uint8_t *p, int32_t v) { write32le(p, read32le(p) | v); }
// Update the immediate field in a AARCH64 ldr, str, and add instruction.
static void or32AArch64Imm(uint8_t *l, uint64_t imm) {
or32le(l, (imm & 0xFFF) << 10);
}
void AArch64::relocateOne(uint8_t *loc, RelType type, uint64_t val) const {
switch (type) {
case R_AARCH64_ABS16:
case R_AARCH64_PREL16:
checkIntUInt(loc, val, 16, type);
write16le(loc, val);
break;
case R_AARCH64_ABS32:
case R_AARCH64_PREL32:
checkIntUInt(loc, val, 32, type);
write32le(loc, val);
break;
case R_AARCH64_ABS64:
case R_AARCH64_PREL64:
write64le(loc, val);
break;
case R_AARCH64_ADD_ABS_LO12_NC:
or32AArch64Imm(loc, val);
break;
case R_AARCH64_ADR_GOT_PAGE:
case R_AARCH64_ADR_PREL_PG_HI21:
case R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21:
case R_AARCH64_TLSDESC_ADR_PAGE21:
checkInt(loc, val, 33, type);
LLVM_FALLTHROUGH;
case R_AARCH64_ADR_PREL_PG_HI21_NC:
write32AArch64Addr(loc, val >> 12);
break;
case R_AARCH64_ADR_PREL_LO21:
checkInt(loc, val, 21, type);
write32AArch64Addr(loc, val);
break;
case R_AARCH64_JUMP26:
// Normally we would just write the bits of the immediate field, however
// when patching instructions for the cpu errata fix -fix-cortex-a53-843419
// we want to replace a non-branch instruction with a branch immediate
// instruction. By writing all the bits of the instruction including the
// opcode and the immediate (0 001 | 01 imm26) we can do this
// transformation by placing a R_AARCH64_JUMP26 relocation at the offset of
// the instruction we want to patch.
write32le(loc, 0x14000000);
LLVM_FALLTHROUGH;
case R_AARCH64_CALL26:
checkInt(loc, val, 28, type);
or32le(loc, (val & 0x0FFFFFFC) >> 2);
break;
case R_AARCH64_CONDBR19:
case R_AARCH64_LD_PREL_LO19:
checkAlignment(loc, val, 4, type);
checkInt(loc, val, 21, type);
or32le(loc, (val & 0x1FFFFC) << 3);
break;
case R_AARCH64_LDST8_ABS_LO12_NC:
case R_AARCH64_TLSLE_LDST8_TPREL_LO12_NC:
or32AArch64Imm(loc, getBits(val, 0, 11));
break;
case R_AARCH64_LDST16_ABS_LO12_NC:
case R_AARCH64_TLSLE_LDST16_TPREL_LO12_NC:
checkAlignment(loc, val, 2, type);
or32AArch64Imm(loc, getBits(val, 1, 11));
break;
case R_AARCH64_LDST32_ABS_LO12_NC:
case R_AARCH64_TLSLE_LDST32_TPREL_LO12_NC:
checkAlignment(loc, val, 4, type);
or32AArch64Imm(loc, getBits(val, 2, 11));
break;
case R_AARCH64_LDST64_ABS_LO12_NC:
case R_AARCH64_LD64_GOT_LO12_NC:
case R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC:
case R_AARCH64_TLSLE_LDST64_TPREL_LO12_NC:
case R_AARCH64_TLSDESC_LD64_LO12:
checkAlignment(loc, val, 8, type);
or32AArch64Imm(loc, getBits(val, 3, 11));
break;
case R_AARCH64_LDST128_ABS_LO12_NC:
case R_AARCH64_TLSLE_LDST128_TPREL_LO12_NC:
checkAlignment(loc, val, 16, type);
or32AArch64Imm(loc, getBits(val, 4, 11));
break;
case R_AARCH64_MOVW_UABS_G0_NC:
or32le(loc, (val & 0xFFFF) << 5);
break;
case R_AARCH64_MOVW_UABS_G1_NC:
or32le(loc, (val & 0xFFFF0000) >> 11);
break;
case R_AARCH64_MOVW_UABS_G2_NC:
or32le(loc, (val & 0xFFFF00000000) >> 27);
break;
case R_AARCH64_MOVW_UABS_G3:
or32le(loc, (val & 0xFFFF000000000000) >> 43);
break;
case R_AARCH64_TSTBR14:
checkInt(loc, val, 16, type);
or32le(loc, (val & 0xFFFC) << 3);
break;
case R_AARCH64_TLSLE_ADD_TPREL_HI12:
checkUInt(loc, val, 24, type);
or32AArch64Imm(loc, val >> 12);
break;
case R_AARCH64_TLSLE_ADD_TPREL_LO12_NC:
case R_AARCH64_TLSDESC_ADD_LO12:
or32AArch64Imm(loc, val);
break;
default:
error(getErrorLocation(loc) + "unrecognized relocation " + toString(type));
}
}
void AArch64::relaxTlsGdToLe(uint8_t *loc, RelType type, uint64_t val) const {
// TLSDESC Global-Dynamic relocation are in the form:
// adrp x0, :tlsdesc:v [R_AARCH64_TLSDESC_ADR_PAGE21]
// ldr x1, [x0, #:tlsdesc_lo12:v [R_AARCH64_TLSDESC_LD64_LO12]
// add x0, x0, :tlsdesc_los:v [R_AARCH64_TLSDESC_ADD_LO12]
// .tlsdesccall [R_AARCH64_TLSDESC_CALL]
// blr x1
// And it can optimized to:
// movz x0, #0x0, lsl #16
// movk x0, #0x10
// nop
// nop
checkUInt(loc, val, 32, type);
switch (type) {
case R_AARCH64_TLSDESC_ADD_LO12:
case R_AARCH64_TLSDESC_CALL:
write32le(loc, 0xd503201f); // nop
return;
case R_AARCH64_TLSDESC_ADR_PAGE21:
write32le(loc, 0xd2a00000 | (((val >> 16) & 0xffff) << 5)); // movz
return;
case R_AARCH64_TLSDESC_LD64_LO12:
write32le(loc, 0xf2800000 | ((val & 0xffff) << 5)); // movk
return;
default:
llvm_unreachable("unsupported relocation for TLS GD to LE relaxation");
}
}
void AArch64::relaxTlsGdToIe(uint8_t *loc, RelType type, uint64_t val) const {
// TLSDESC Global-Dynamic relocation are in the form:
// adrp x0, :tlsdesc:v [R_AARCH64_TLSDESC_ADR_PAGE21]
// ldr x1, [x0, #:tlsdesc_lo12:v [R_AARCH64_TLSDESC_LD64_LO12]
// add x0, x0, :tlsdesc_los:v [R_AARCH64_TLSDESC_ADD_LO12]
// .tlsdesccall [R_AARCH64_TLSDESC_CALL]
// blr x1
// And it can optimized to:
// adrp x0, :gottprel:v
// ldr x0, [x0, :gottprel_lo12:v]
// nop
// nop
switch (type) {
case R_AARCH64_TLSDESC_ADD_LO12:
case R_AARCH64_TLSDESC_CALL:
write32le(loc, 0xd503201f); // nop
break;
case R_AARCH64_TLSDESC_ADR_PAGE21:
write32le(loc, 0x90000000); // adrp
relocateOne(loc, R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21, val);
break;
case R_AARCH64_TLSDESC_LD64_LO12:
write32le(loc, 0xf9400000); // ldr
relocateOne(loc, R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC, val);
break;
default:
llvm_unreachable("unsupported relocation for TLS GD to LE relaxation");
}
}
void AArch64::relaxTlsIeToLe(uint8_t *loc, RelType type, uint64_t val) const {
checkUInt(loc, val, 32, type);
if (type == R_AARCH64_TLSIE_ADR_GOTTPREL_PAGE21) {
// Generate MOVZ.
uint32_t regNo = read32le(loc) & 0x1f;
write32le(loc, (0xd2a00000 | regNo) | (((val >> 16) & 0xffff) << 5));
return;
}
if (type == R_AARCH64_TLSIE_LD64_GOTTPREL_LO12_NC) {
// Generate MOVK.
uint32_t regNo = read32le(loc) & 0x1f;
write32le(loc, (0xf2800000 | regNo) | ((val & 0xffff) << 5));
return;
}
llvm_unreachable("invalid relocation for TLS IE to LE relaxation");
}
// AArch64 may use security features in variant PLT sequences. These are:
// Pointer Authentication (PAC), introduced in armv8.3-a and Branch Target
// Indicator (BTI) introduced in armv8.5-a. The additional instructions used
// in the variant Plt sequences are encoded in the Hint space so they can be
// deployed on older architectures, which treat the instructions as a nop.
// PAC and BTI can be combined leading to the following combinations:
// writePltHeader
// writePltHeaderBti (no PAC Header needed)
// writePlt
// writePltBti (BTI only)
// writePltPac (PAC only)
// writePltBtiPac (BTI and PAC)
//
// When PAC is enabled the dynamic loader encrypts the address that it places
// in the .got.plt using the pacia1716 instruction which encrypts the value in
// x17 using the modifier in x16. The static linker places autia1716 before the
// indirect branch to x17 to authenticate the address in x17 with the modifier
// in x16. This makes it more difficult for an attacker to modify the value in
// the .got.plt.
//
// When BTI is enabled all indirect branches must land on a bti instruction.
// The static linker must place a bti instruction at the start of any PLT entry
// that may be the target of an indirect branch. As the PLT entries call the
// lazy resolver indirectly this must have a bti instruction at start. In
// general a bti instruction is not needed for a PLT entry as indirect calls
// are resolved to the function address and not the PLT entry for the function.
// There are a small number of cases where the PLT address can escape, such as
// taking the address of a function or ifunc via a non got-generating
// relocation, and a shared library refers to that symbol.
//
// We use the bti c variant of the instruction which permits indirect branches
// (br) via x16/x17 and indirect function calls (blr) via any register. The ABI
// guarantees that all indirect branches from code requiring BTI protection
// will go via x16/x17
namespace {
class AArch64BtiPac final : public AArch64 {
public:
AArch64BtiPac();
void writePltHeader(uint8_t *buf) const override;
void writePlt(uint8_t *buf, uint64_t gotPltEntryAddr, uint64_t pltEntryAddr,
int32_t index, unsigned relOff) const override;
private:
bool btiHeader; // bti instruction needed in PLT Header
bool btiEntry; // bti instruction needed in PLT Entry
bool pacEntry; // autia1716 instruction needed in PLT Entry
};
} // namespace
AArch64BtiPac::AArch64BtiPac() {
btiHeader = (config->andFeatures & GNU_PROPERTY_AARCH64_FEATURE_1_BTI);
// A BTI (Branch Target Indicator) Plt Entry is only required if the
// address of the PLT entry can be taken by the program, which permits an
// indirect jump to the PLT entry. This can happen when the address
// of the PLT entry for a function is canonicalised due to the address of
// the function in an executable being taken by a shared library.
// FIXME: There is a potential optimization to omit the BTI if we detect
// that the address of the PLT entry isn't taken.
btiEntry = btiHeader && !config->shared;
pacEntry = (config->andFeatures & GNU_PROPERTY_AARCH64_FEATURE_1_PAC);
if (btiEntry || pacEntry)
pltEntrySize = 24;
}
void AArch64BtiPac::writePltHeader(uint8_t *buf) const {
const uint8_t btiData[] = { 0x5f, 0x24, 0x03, 0xd5 }; // bti c
const uint8_t pltData[] = {
0xf0, 0x7b, 0xbf, 0xa9, // stp x16, x30, [sp,#-16]!
0x10, 0x00, 0x00, 0x90, // adrp x16, Page(&(.plt.got[2]))
0x11, 0x02, 0x40, 0xf9, // ldr x17, [x16, Offset(&(.plt.got[2]))]
0x10, 0x02, 0x00, 0x91, // add x16, x16, Offset(&(.plt.got[2]))
0x20, 0x02, 0x1f, 0xd6, // br x17
0x1f, 0x20, 0x03, 0xd5, // nop
0x1f, 0x20, 0x03, 0xd5 // nop
};
const uint8_t nopData[] = { 0x1f, 0x20, 0x03, 0xd5 }; // nop
uint64_t got = in.gotPlt->getVA();
uint64_t plt = in.plt->getVA();
if (btiHeader) {
// PltHeader is called indirectly by plt[N]. Prefix pltData with a BTI C
// instruction.
memcpy(buf, btiData, sizeof(btiData));
buf += sizeof(btiData);
plt += sizeof(btiData);
}
memcpy(buf, pltData, sizeof(pltData));
relocateOne(buf + 4, R_AARCH64_ADR_PREL_PG_HI21,
getAArch64Page(got + 16) - getAArch64Page(plt + 8));
relocateOne(buf + 8, R_AARCH64_LDST64_ABS_LO12_NC, got + 16);
relocateOne(buf + 12, R_AARCH64_ADD_ABS_LO12_NC, got + 16);
if (!btiHeader)
// We didn't add the BTI c instruction so round out size with NOP.
memcpy(buf + sizeof(pltData), nopData, sizeof(nopData));
}
void AArch64BtiPac::writePlt(uint8_t *buf, uint64_t gotPltEntryAddr,
uint64_t pltEntryAddr, int32_t index,
unsigned relOff) const {
// The PLT entry is of the form:
// [btiData] addrInst (pacBr | stdBr) [nopData]
const uint8_t btiData[] = { 0x5f, 0x24, 0x03, 0xd5 }; // bti c
const uint8_t addrInst[] = {
0x10, 0x00, 0x00, 0x90, // adrp x16, Page(&(.plt.got[n]))
0x11, 0x02, 0x40, 0xf9, // ldr x17, [x16, Offset(&(.plt.got[n]))]
0x10, 0x02, 0x00, 0x91 // add x16, x16, Offset(&(.plt.got[n]))
};
const uint8_t pacBr[] = {
0x9f, 0x21, 0x03, 0xd5, // autia1716
0x20, 0x02, 0x1f, 0xd6 // br x17
};
const uint8_t stdBr[] = {
0x20, 0x02, 0x1f, 0xd6, // br x17
0x1f, 0x20, 0x03, 0xd5 // nop
};
const uint8_t nopData[] = { 0x1f, 0x20, 0x03, 0xd5 }; // nop
if (btiEntry) {
memcpy(buf, btiData, sizeof(btiData));
buf += sizeof(btiData);
pltEntryAddr += sizeof(btiData);
}
memcpy(buf, addrInst, sizeof(addrInst));
relocateOne(buf, R_AARCH64_ADR_PREL_PG_HI21,
getAArch64Page(gotPltEntryAddr) -
getAArch64Page(pltEntryAddr));
relocateOne(buf + 4, R_AARCH64_LDST64_ABS_LO12_NC, gotPltEntryAddr);
relocateOne(buf + 8, R_AARCH64_ADD_ABS_LO12_NC, gotPltEntryAddr);
if (pacEntry)
memcpy(buf + sizeof(addrInst), pacBr, sizeof(pacBr));
else
memcpy(buf + sizeof(addrInst), stdBr, sizeof(stdBr));
if (!btiEntry)
// We didn't add the BTI c instruction so round out size with NOP.
memcpy(buf + sizeof(addrInst) + sizeof(stdBr), nopData, sizeof(nopData));
}
static TargetInfo *getTargetInfo() {
if (config->andFeatures & (GNU_PROPERTY_AARCH64_FEATURE_1_BTI |
GNU_PROPERTY_AARCH64_FEATURE_1_PAC)) {
static AArch64BtiPac t;
return &t;
}
static AArch64 t;
return &t;
}
TargetInfo *elf::getAArch64TargetInfo() { return getTargetInfo(); }

View File

@@ -1,113 +0,0 @@
//===- AMDGPU.cpp ---------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "InputFiles.h"
#include "Symbols.h"
#include "Target.h"
#include "lld/Common/ErrorHandler.h"
#include "llvm/Object/ELF.h"
#include "llvm/Support/Endian.h"
using namespace llvm;
using namespace llvm::object;
using namespace llvm::support::endian;
using namespace llvm::ELF;
using namespace lld;
using namespace lld::elf;
namespace {
class AMDGPU final : public TargetInfo {
public:
AMDGPU();
uint32_t calcEFlags() const override;
void relocateOne(uint8_t *loc, RelType type, uint64_t val) const override;
RelExpr getRelExpr(RelType type, const Symbol &s,
const uint8_t *loc) const override;
RelType getDynRel(RelType type) const override;
};
} // namespace
AMDGPU::AMDGPU() {
relativeRel = R_AMDGPU_RELATIVE64;
gotRel = R_AMDGPU_ABS64;
noneRel = R_AMDGPU_NONE;
symbolicRel = R_AMDGPU_ABS64;
}
static uint32_t getEFlags(InputFile *file) {
return cast<ObjFile<ELF64LE>>(file)->getObj().getHeader()->e_flags;
}
uint32_t AMDGPU::calcEFlags() const {
assert(!objectFiles.empty());
uint32_t ret = getEFlags(objectFiles[0]);
// Verify that all input files have the same e_flags.
for (InputFile *f : makeArrayRef(objectFiles).slice(1)) {
if (ret == getEFlags(f))
continue;
error("incompatible e_flags: " + toString(f));
return 0;
}
return ret;
}
void AMDGPU::relocateOne(uint8_t *loc, RelType type, uint64_t val) const {
switch (type) {
case R_AMDGPU_ABS32:
case R_AMDGPU_GOTPCREL:
case R_AMDGPU_GOTPCREL32_LO:
case R_AMDGPU_REL32:
case R_AMDGPU_REL32_LO:
write32le(loc, val);
break;
case R_AMDGPU_ABS64:
case R_AMDGPU_REL64:
write64le(loc, val);
break;
case R_AMDGPU_GOTPCREL32_HI:
case R_AMDGPU_REL32_HI:
write32le(loc, val >> 32);
break;
default:
llvm_unreachable("unknown relocation");
}
}
RelExpr AMDGPU::getRelExpr(RelType type, const Symbol &s,
const uint8_t *loc) const {
switch (type) {
case R_AMDGPU_ABS32:
case R_AMDGPU_ABS64:
return R_ABS;
case R_AMDGPU_REL32:
case R_AMDGPU_REL32_LO:
case R_AMDGPU_REL32_HI:
case R_AMDGPU_REL64:
return R_PC;
case R_AMDGPU_GOTPCREL:
case R_AMDGPU_GOTPCREL32_LO:
case R_AMDGPU_GOTPCREL32_HI:
return R_GOT_PC;
default:
error(getErrorLocation(loc) + "unknown relocation (" + Twine(type) +
") against symbol " + toString(s));
return R_NONE;
}
}
RelType AMDGPU::getDynRel(RelType type) const {
if (type == R_AMDGPU_ABS64)
return type;
return R_AMDGPU_NONE;
}
TargetInfo *elf::getAMDGPUTargetInfo() {
static AMDGPU target;
return &target;
}

Some files were not shown because too many files have changed in this diff Show More