30 Commits

Author SHA1 Message Date
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
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
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
Noam Preil
803a1025bb Targets: add SPU Mark II architecture 2020-08-22 12:45:29 -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
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
Jay Petacat
cf15b4c269 elf: Iterate over headers w/o need for allocator 2020-08-01 16:01:48 +00: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
Vexu
e85fe13e44
run zig fmt on std lib and self hosted 2020-07-11 20:41:19 +03:00
luna
e2cfc65909
Merge branch 'master' into ebadf-error 2020-07-02 00:49:56 -03: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
b96882c57a Fix compilation errors 2020-06-29 18:09:22 +02:00
Luna
f47c6d3c6b std.os: make EBADF return error for read and write 2020-06-28 18:40:43 -03:00
Jonathan Marler
a282ac7a91 Support Reader for InStream 2020-06-09 13:36:17 -04:00
Vexu
0e30edd8d0
std: handle ConnectionTimedOut in switch
regression from #5266
closes #5270
2020-05-06 12:52:26 +03:00
Andrew Kelley
3657a54618
fix regressions in elf parsing code 2020-03-11 17:34:12 -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
ed13cffca4
rework some old ELF parsing code and start to fix emitRaw 2020-03-10 22:01:58 -04: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
xackus
00be934569 short std.builtin enum literals in std lib 2020-03-01 13:57:41 -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
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
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
LemonBoy
333eec557f Initial support for static PIE executables 2019-12-21 17:34:05 +01: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
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
Andrew Kelley
e0db54e89d
update the codebase to use @as 2019-11-08 15:57:24 -05:00
LemonBoy
ba711f1115 Add ELF architecture constant for RISC-V 2019-10-13 12:12:33 +02:00
Andrew Kelley
ed36dbbd9c
mv std/ lib/
that's all this commit does. further commits will fix cli flags and
such.

see #2221
2019-09-25 23:35:41 -04:00