Commit Graph

2158 Commits (6febe7e977072fea1bf7b6003be2d6c1f3654905)

Author SHA1 Message Date
Maciej Walczak 6febe7e977
copy_file_range linux syscall (#6010) 2020-08-11 15:49:43 -04: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
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 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 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
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 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 c594f8dc26 stage2 tests: support the -Denable-qemu options and friends 2020-08-04 15:32:16 -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 d624bf8059 stage2 .debug_line stepping with gdb is working 2020-08-03 21:01:06 -07:00
Andrew Kelley 659603c621 codegen: emit .debug_line ops for IR instructions 2020-08-02 21:28:06 -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
S0urc3C0de 5ae88e919b Add rdynamic option to build.zig 2020-08-02 17:50:06 +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