Commit Graph

18846 Commits

Author SHA1 Message Date
Jonathan Marler
ca98625789
std.os.execvpe: fix buffer overflow
The NameTooLong check isn't taking the sentinel 0 into account which
would result in a buffer overflow on the stack.
2022-06-21 11:21:45 +02:00
Jakub Konka
74ed7c1f09
Merge pull request #11875 from motiejus/pagezero-size
[MachO] add -pagezero_size
2022-06-20 17:51:20 +02:00
Jakub Konka
8752db3285 macho: -pagezero_size is always in hex
This matches the behavior of other linkers out there including
`ld64` and `lld`.
2022-06-20 14:26:59 +02:00
Jakub Konka
753e2b8639 macho: verbose print pagezero size if specified 2022-06-20 13:52:39 +02:00
Jakub Konka
ea9b7a0626 macho: round down pagezero size to page size
If page aligned requested pagezero size is 0, skip generating
__PAGEZERO segment.

Add misc improvements to the pipeline, and correctly transfer the
requested __PAGEZERO size to the linker.
2022-06-20 13:39:33 +02:00
Motiejus Jakštys
98138ba78c [MachO] add -pagezero_size
Pass `-pagezero_size` to the MachO linker. This is the final
"unsupported linker arg" that I could chase that CGo uses. After this
and #11874 we may be able to fail on an "unsupported linker arg" instead
of emiting a warning.

Test case:

    zig=/code/zig/build/zig
    CGO_ENABLED=1 GOOS=darwin GOARCH=amd64 CC="$zig cc -target x86_64-macos" CXX="$zig c++ -target x86_64-macos" go build -a -ldflags "-s -w" cgo.go

I compiled a trivial CGo program and executed it on an amd64 Darwin
host.

To be honest, I am not entirely sure what this is doing. This feels
right after reading what this argument does in LLVM sources, but I am by
no means qualified to make MachO pull requests. Will take feedback.
2022-06-20 13:39:33 +02:00
Jakub Konka
a97a39bea6
Merge pull request #11893 from Luukdegram/wasm-sat
stage2: wasm - saturating arithmetic
2022-06-20 08:48:46 +02:00
Jakub Konka
74442f3503
Merge pull request #11847 from ziglang/better-libcompiler_rt 2022-06-20 00:26:39 +02:00
Jakub Konka
1d4dbf8d3c macos: run test-cases single threaded in the CI 2022-06-19 21:08:53 +02:00
Luuk de Gram
4957c7cbbd
wasm: enable passing behavior tests
This also splits the test cases for addition and subtraction as the wasm
backend does not yet provide support for 128bit saturating arithmetic.
2022-06-19 17:27:56 +02:00
Luuk de Gram
a50147bfff
wasm: fixes for signed saturation 2022-06-19 17:26:44 +02:00
Luuk de Gram
05600a6d84
wasm: saturating shift-left for signed integers 2022-06-19 15:50:03 +02:00
Jakub Konka
b4f2c0dcb9 compiler-rt: fix logic for choosing __gnu_{f2h,h2f}_ieee
Similar to wasm32-wasi-musl, Apple targets also want standard
symbol names.
2022-06-19 15:12:08 +02:00
Luuk de Gram
53831442ef
wasm: saturating shift-left for unsigned integers 2022-06-19 14:30:17 +02:00
Luuk de Gram
ce5d934f5f
wasm: saturating add and sub for signed integers 2022-06-19 14:30:17 +02:00
Luuk de Gram
fcd4280a8c
wasm: implement saturating add, sub for unsigned
Implements +| and -| for unsigned integers <= 64 bits.
2022-06-19 14:30:13 +02:00
Jakub Konka
091238254e macho: return from flushModule if building object for static lib 2022-06-18 22:55:55 +02:00
Andrew Kelley
30ef033693 compiler-rt: fix logic for choosing __gnu_{f2h,h2f}_ieee
wasm32-wasi-musl wants the standard symbol names however Linux requires
the `__gnu_*` flavors. I did not find any authoritative source on what
decides which symbol flavors to use. If we run into more trouble in the
future we can go back to having both.
2022-06-17 20:25:17 -07:00
Andrew Kelley
e4092d4442 stage2: rip out multi-compilation-unit compiler-rt
After doing performance testing, it seems that multi-compilation-unit
compiler-rt did not bring the performance improvements that we expected
it to. The idea is that it makes linking faster, however, it incurred a
cost in the frontend that was not offset by any gains in linking.

Furthermore, the single-object compiler-rt (with -ffunction-sections and
--gc-sections) ends up being fewer bytes on disk and so it's actually
the same or faster linking speed than the multi-compilation-unit
version.

So we are planning to keep using single-compilation-unit compiler-rt for
the foreseeable future, but may experiment with this again in the
future, in which case this commit can be reverted.
2022-06-17 18:34:11 -07:00
Andrew Kelley
2064d86298 update CMakeLists.txt source files 2022-06-17 18:24:57 -07:00
Andrew Kelley
ebab5288c3 compiler-rt: fix aeabi logic
Before, compiler-rt would have the wrong symbols for ARM targets.
2022-06-17 18:22:35 -07:00
Andrew Kelley
0556a2ba53 compiler-rt: finish cleanups
Finishes cleanups that I started in other commits in this branch.

 * Use common.linkage for all exports instead of redoing the logic in
   each file.
 * Remove pointless `@setRuntimeSafety` calls.
 * Avoid redundantly exporting multiple versions of functions. For
   example, if PPC wants `ceilf128` then don't also export `ceilq`;
   similarly if ARM wants `__aeabi_ddiv` then don't also export
   `__divdf3`.
 * Use `inline` for helper functions instead of making inline calls at
   callsites.
2022-06-17 18:10:00 -07:00
Andrew Kelley
3efc229bbf compiler-rt: musl ABI also needs __gnu_f2h_ieee etc 2022-06-17 16:42:50 -07:00
Andrew Kelley
bcf3a7d600 compiler-rt: gedf2 and gesf2 2022-06-17 16:40:25 -07:00
Andrew Kelley
e798a3a779 compiler-rt: disable separate compilation units 2022-06-17 16:38:59 -07:00
Andrew Kelley
5cd548e530 Compilation: multi-thread compiler-rt
compiler_rt_lib and compiler_rt_obj are extracted from the generic
JobQueue into simple boolean flags, and then handled explicitly inside
performAllTheWork().

Introduced generic handling of allocation failure and made
setMiscFailure not return a possible error.

Building the compiler-rt static library now takes advantage of
Compilation's ThreadPool. This introduced a problem, however, because
now each of the object files of compiler-rt all perform AstGen for the
full standard library and compiler-rt files. Even though all of them end
up being cache hits except for the first ones, this is wasteful - O(N*M)
where N is number of compilation units inside compiler-rt and M is the
number of .zig files in the standard library and compiler-rt combined.

More importantly, however, it causes a deadlock, because each thread
interacts with a file system lock for doing AstGen on files, and threads
end up waiting for each other. This will need to be handled with a
process-level file caching system, or some other creative solution.
2022-06-17 16:38:59 -07:00
Andrew Kelley
b4f3e69342 update CMakeLists.txt source file list 2022-06-17 16:38:59 -07:00
Andrew Kelley
fcebdbe25d compiler-rt: no more -ffunction-sections 2022-06-17 16:38:59 -07:00
Andrew Kelley
bbc6103398 compiler-rt: fix tests 2022-06-17 16:38:59 -07:00
Andrew Kelley
453243d9e0 compiler-rt: correct the list of builtins to build 2022-06-17 16:38:59 -07:00
Andrew Kelley
4200f89d94 compiler-rt: sort source files 2022-06-17 16:38:59 -07:00
Andrew Kelley
a8a7f15106 compiler-rt: use callconv(.AAPCS) on all __aeabi_ functions 2022-06-17 16:38:59 -07:00
Andrew Kelley
25671f5a97 compiler-rt: move SPARC functions into appropriate compilation units 2022-06-17 16:38:59 -07:00
Andrew Kelley
c99c085d70 compiler-rt: break up functions even more
The purpose of this branch is to switch to using an object file for each
independent function, in order to make linking simpler - instead of
relying on `-ffunction-sections` and `--gc-sections`, which involves the
linker doing the work of linking everything and then undoing work via
garbage collection, this will allow the linker to only include the
compilation units that are depended on in the first place.

This commit makes progress towards that goal.
2022-06-17 16:38:59 -07:00
Jakub Konka
47c834e477 macho: unify flushing object path with other linkers 2022-06-17 16:38:59 -07:00
Jakub Konka
f572e5a0c4 compiler_rt: shuffle order of imports to mark relevant symbols for export 2022-06-17 16:38:59 -07:00
Jakub Konka
57c530155f compiler_rt: correctly export allrem and aullrem for i386-windows-msvc 2022-06-17 16:38:59 -07:00
Jakub Konka
2259d629d3 compiler_rt: use single cache for libcompiler_rt.a static lib 2022-06-17 16:38:59 -07:00
Jakub Konka
80790be309 compiler_rt: compile each unit separately for improved archiving 2022-06-17 16:38:59 -07:00
Andrew Kelley
33cf6ef621
Merge pull request #11881 from Vexu/stage2
Stage2: fixes for bugs found while looking for miscompilations
2022-06-17 19:23:08 -04:00
Veikka Tuominen
28986a0590 stage2: check that struct is a tuple when value tags differ in eql 2022-06-17 21:04:21 +03:00
Veikka Tuominen
a224dfceee std.tz: fix function returning pointer to local variable 2022-06-17 21:04:21 +03:00
Xavier Bouchoux
b66247c97a stage2: coerce tuple to vector 2022-06-17 19:06:17 +03:00
Omar Alhammadi
69e2cac0d3
stage2: comptime @bitCast packed struct bug fix 2022-06-17 19:04:51 +03:00
Veikka Tuominen
b9dcbe6b4c Sema: handle sentinels in tupleToArray 2022-06-17 18:57:02 +03:00
Veikka Tuominen
ffa6f895ff Sema: validateArrayInit detect bitcast before store 2022-06-17 18:57:02 +03:00
Motiejus Jakštys
d506275a06 [elf] understand -no-pie
This passes -Wl,-no-pie linker arg. Golang uses that. From the `ld(1)`
man page:

   Create a position dependent executable.  This is the default.

Not adding to the help text, because this is the default.
2022-06-16 15:27:30 -04:00
Jakub Konka
d3caacfab7
Merge pull request #11864 from jedisct1/wasi-libc-update
Update the WASI libc to 30094b6ed05f19cee102115215863d185f2db4f0
2022-06-15 12:33:17 +02:00
Frank Denis
27610b0a0f
std/crypto: add support for ECDSA signatures (#11855)
ECDSA is the most commonly used signature scheme today, mainly for
historical and conformance reasons. It is a necessary evil for
many standard protocols such as TLS and JWT.

It is tricky to implement securely and has been the root cause of
multiple security disasters, from the Playstation 3 hack to multiple
critical issues in OpenSSL and Java.

This implementation combines lessons learned from the past with
recent recommendations.

In Zig, the NIST curves that ECDSA is almost always instantied with
use formally verified field arithmetic, giving us peace of mind
even on edge cases. And the API rejects neutral elements where it
matters, and unconditionally checks for non-canonical encoding for
scalars and group elements. This automatically eliminates common
vulnerabilities such as https://sk.tl/2LpS695v .

ECDSA's security heavily relies on the security of the random number
generator, which is a concern in some environments.

This implementation mitigates this by computing deterministic
nonces using the conservative scheme from Pornin et al. with the
optional addition of randomness as proposed in Ericsson's
"Deterministic ECDSA and EdDSA Signatures with Additional Randomness"
document. This approach mitigates both the implications of a weak RNG
and the practical implications of fault attacks.

Project Wycheproof is a Google project to test crypto libraries against
known attacks by triggering edge cases. It discovered vulnerabilities
in virtually all major ECDSA implementations.

The entire set of ECDSA-P256-SHA256 test vectors from Project Wycheproof
is included here. Zero defects were found in this implementation.

The public API differs from the Ed25519 one. Instead of raw byte strings
for keys and signatures, we introduce Signature, PublicKey and SecretKey
structures.

The reason is that a raw byte representation would not be optimal.
There are multiple standard representations for keys and signatures,
and decoding/encoding them may not be cheap (field elements have to be
converted from/to the montgomery domain).

So, the intent is to eventually move ed25519 to the same API, which
is not going to introduce any performance regression, but will bring
us a consistent API, that we can also reuse for RSA.
2022-06-15 08:55:39 +02:00
Andrew Kelley
0e9458a3fc test-cases: avoid using realpath since it is not portable
For example FreeBSD does not support this syscall.
2022-06-14 22:15:22 -07:00