4319 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
Vexu
58502b8bfe translate-c: respect C operator precedence in macros 2020-10-05 22:26:11 -04: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
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
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
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
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
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
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
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 c8b4cc2ff9cf15a42f95b2302e02431a0004f5c8.

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
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 2a3393eff853fe0a1dee766c859a345186e91fa3
2020-10-03 17:16:19 -07:00
LemonBoy
3b40b68210 stage2: Build libunwind for non-msvc Windows targets
Closes #6497
2020-10-03 20:47:06 +02:00
joachimschmidt557
fb58fb2d8d stage2 ARM: add testcases for non-leaf fns, parameters, return values 2020-10-03 12:52:04 +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
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