140 Commits

Author SHA1 Message Date
Alexandros Naskos
fac9a4e286 Start working on PE/COFF linking. 2020-09-04 05:12:26 +03:00
Sahnvour
575fbd5e35 hash_map: rename to ArrayHashMap and add new HashMap implementation 2020-09-02 00:17:50 +02: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
222e23c678 Linker: make defaults read-only 2020-08-22 12:45:29 -07:00
Noam Preil
8c321f0cf5 SPU-II: Fix linking 2020-08-22 12:45:29 -07: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
Jakub Konka
5fe878cd42
Merge pull request #6085 from kubkon/macho-header
Write out Mach-O header
2020-08-19 07:50:11 +02:00
Isaac Freund
741fb8d306 stage2/link: clarify comments on calling order 2020-08-18 19:47:20 -04: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
Isaac Freund
9f44284ad5
stage2/wasm: add basic test cases 2020-08-18 01:47:03 +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
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
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
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
Andrew Kelley
8d8d568854 stage2: implement zig version 2020-08-15 20:04:08 -04:00
Andrew Kelley
5f7c7191ab stage2: astgen for non-labeled blocks 2020-08-14 11:28:40 -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
heidezomp
16d118a8d9 update std and src-self-hosted for std.log breaking change 2020-08-13 17:14:15 +02:00
Andrew Kelley
eec53d67ab stage2: anyerror -> explicit error set 2020-08-12 21:59:40 -07:00
Noam Preil
5a166cead8 CBE: fix handling of IR dependencies 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
Andrew Kelley
de4f3f11f7 stage2: astgen for while loops
See #6021
2020-08-12 21:13:16 -07: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
fd47839064 stage2: fix crash on empty source file 2020-08-08 18:19:48 -07:00
Andrew Kelley
30bace66d4 refactor now that stage1 supports anon default struct field inits 2020-08-07 22:45:45 -07: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
Noam Preil
a5b76d2474 Stage2: minor File.ELF refactor 2020-08-05 11:25:08 -07: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
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
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
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
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
Andrew Kelley
0962cc5a32 stage2: implement .debug_aranges DWARF 2020-07-31 01:16:34 -07:00
Andrew Kelley
acd0dabab2 stage2: add some tracy calls to link.zig functions 2020-07-30 23:51:14 -07:00