15212 Commits

Author SHA1 Message Date
Andrew Kelley
0f38f68696 stage2: Air and Liveness are passed ephemerally
to the link infrastructure, instead of being stored with Module.Fn. This
moves towards a strategy to make more efficient use of memory by not
storing Air or Liveness data in the Fn struct, but computing it on
demand, immediately sending it to the backend, and then immediately
freeing it.

Backends which want to defer codegen until flush() such as SPIR-V
must move the Air/Liveness data upon `updateFunc` being called and keep
track of that data in the backend implementation itself.
2021-07-20 12:19:16 -07:00
Andrew Kelley
0ffc6b5cc3 cmake: fix Liveness.zig file path 2021-07-20 12:19:16 -07:00
Andrew Kelley
913393fd3b stage2: first pass over Module.zig for AIR memory layout 2021-07-20 12:19:16 -07:00
Andrew Kelley
ee6432537e stage2: first pass over codegen.zig for AIR memory layout 2021-07-20 12:19:16 -07:00
Andrew Kelley
ef7080aed1 stage2: update Liveness, SPIR-V for new AIR memory layout
also do the inline assembly instruction
2021-07-20 12:19:16 -07:00
Andrew Kelley
9918a5fbe3 AstGen: remove unneeded field ref_start_index
Previously, this field was used because the Zir.Inst.Ref encoding
supported the concept of references to function parameters. However now
thanks to whole-file-astgen, the implementations of indexToRef and
refToIndex are trivial addition/subtraction of a comptime const integer.
2021-07-20 12:19:14 -07:00
Andrew Kelley
3c3abaf390 stage2: update liveness analysis to new AIR memory layout
It's pretty compact, with each AIR instruction only taking up 4 bits,
plus a sparse table for special instructions such as conditional branch,
switch branch, and function calls with more than 2 arguments.
2021-07-20 12:18:14 -07:00
Andrew Kelley
5d6f7b44c1 stage2: rework AIR memory layout
This commit changes the AIR file and the documentation of the memory
layout. The actual work of modifying the surrounding code (in Sema and
codegen) is not yet done.
2021-07-20 12:18:14 -07:00
Jakub Konka
a442b165f1 macho: add stub relocs when adding extern fn
in self-hosted.
2021-07-20 20:33:07 +02:00
charlieman
bfe2005167
std: remove dead code in std.os.read 2021-07-20 10:22:06 +02:00
Jakub Konka
1843ecf51b macho: add export to the symbol resolver
in updateDeclExports so that we can track globals for symbol
resolution like in the traditional linker.
2021-07-20 10:07:46 +02:00
Loris Cro
e807020679 Fixed wrong "unable to load" error for non-existing import files
- Changed ZIR encoding of `import` metadata from having instruction
  indexes to storing token indexes.
2021-07-19 23:23:42 -04:00
Isaac Freund
00e944f718 langref: remove incorrect statement on c_void
c_void is *not* simply `const c_void = opaque{};`. It has unique
semantics as any pointer type may coerce to `*c_void` which is not true
for an arbitrary `*opaque{}`.
2021-07-19 20:03:26 -04:00
Evan Haas
3e67ef5c9f translate-c: Handle underscore when used as an identifier
Use `@` syntax to escape `_` when used as an identifier.

Remove the stage1 astgen prohibition against assigning from `_`

Note: there a few stage1 bugs preventing `_` from being used as an identifier
for a local variable or function parameter; these will be fixed by stage2.
They are unlikely to arise in real C code since identifiers starting with
underscore are reserved for the implementation.
2021-07-19 12:56:23 +03:00
Tizoner
c905056562 fix style warning in json.zig 2021-07-19 12:55:05 +03:00
Adam C
95e5fac412
FIX typo in doc comment for std.math.hypot (#9413) 2021-07-18 23:53:06 +02:00
Jakub Konka
4bc72c48b7 macho: temporarily dupe a few linkedit fns so that traditional linker works 2021-07-18 18:36:48 +02:00
Jakub Konka
f6d13e9d6f zld: move contents of Zld into MachO module 2021-07-18 17:48:00 +02:00
Jakub Konka
e0b53ad3c9 macho: clean up imports 2021-07-18 15:39:01 +02:00
Jakub Konka
2828cd2983 zld: migrate symbol mgmt to incremental backend 2021-07-18 15:05:52 +02:00
Jakub Konka
5aa9c0b4ab zld: allocate empty TextBlock for synthetic ___dso_handle 2021-07-17 23:50:45 +02:00
Jakub Konka
a095263462 zld: more fixes todo with symbol resolution
namely, fixes proper symbol reolution when scanning and including
objects from static archives, and properly discard any null symbols
when a tentative definition was substituted by a defined, global symbol.
2021-07-17 23:21:04 +02:00
Jakub Konka
d8c4838c7d zld: fix incorrect global symbol collision check 2021-07-17 18:43:28 +02:00
Jakub Konka
9f20a51555 zld: demote logging back to debug from warn 2021-07-17 18:33:47 +02:00
Jakub Konka
fccac48a55 zld: fix committing stub info into final binary 2021-07-17 18:19:32 +02:00
Jakub Konka
97914d93a9 zld: fixup flush function 2021-07-17 17:30:16 +02:00
Jakub Konka
d81783375c zld: allocate TextBlocks and symbols 2021-07-17 15:13:16 +02:00
Jakub Konka
71384a383e zld: correctly set n_sect for sections as symbols 2021-07-17 11:29:40 +02:00
Jakub Konka
db8020ac0d zld: adjust resolving relocs logic to the new approach 2021-07-17 11:01:10 +02:00
Jay Petacat
9979741bff stage1: Fix OsOther by adding missing OsPlan9 2021-07-16 19:35:25 -04:00
Jakub Konka
407745a5e9 zld: simplify and move Relocations into TextBlock
It makes sense to have them as a dependent type since they only ever
deal with TextBlocks. Simplify Relocations to rely on symbol indices
and symbol resolver rather than pointers.
2021-07-17 01:03:40 +02:00
Jakub Konka
54a403d4ff zld: replace parsed reloc with a simple wrapper around macho.relocation_info 2021-07-16 17:18:53 +02:00
Jakub Konka
5a2bea2931 zld: draft symbol resolver on macho.nlist_64 only 2021-07-16 13:02:02 +02:00
Daniele Cocca
8cde0c91c6 Fix "unused local constant" error
Amends b009aca38a861f74fd5378db19c65db286ad397e.
The PR predated the introduction of unused variable/constant checks,
thus the build checks weren't reporting this failure until later when
merged into master.
2021-07-15 20:56:24 -04:00
Daniele Cocca
b009aca38a src: return a null-terminated slice 2021-07-15 15:12:44 -04:00
Jonathan Marler
08e5daa7d5 Add std.unicode.fmtUtf16le 2021-07-15 20:37:16 +03:00
Jakub Konka
f519e781c6 zld: move TextBlock into standalone file
which should make managing the logic of parsing and resolving relocs
that much simpler to parse.
2021-07-15 18:49:48 +02:00
Jakub Konka
c47ce31071 zld: thin out Relocation by not storing *TextBlock
this way we shave off 8 bytes per Relocation structure, and instead
we can pass the *TextBlock as args to resolve function.
2021-07-15 18:49:47 +02:00
Jakub Konka
f8678c48ff zld: reuse string table for symbol names
rather than manage allocs separately per symbol.
2021-07-15 18:49:47 +02:00
Jakub Konka
ec874a9b2b zld: move tracking binding for proxies into TextBlock
which is the source of binding rather than its target. That is,
we now track by source.
2021-07-15 18:49:47 +02:00
Jakub Konka
0135b46659 zld: remove StringTable abstraction 2021-07-15 18:49:47 +02:00
Jakub Konka
f87424ab63 zld: invoke traditional linker if has LLVM as a temp measure 2021-07-15 18:49:47 +02:00
Jakub Konka
9ca69c51e7 zld: error out if LTO is requested targeting Darwin 2021-07-15 18:49:47 +02:00
Jakub Konka
e3575cdad4 zld: decommision use_lld for MachO
Invoke `linkAsArchive` directly in MachO backend when LLVM is available
and we are asked to create a static lib.
2021-07-15 18:49:47 +02:00
Jakub Konka
398672eb30 zld: add temp basic handling of debugging stabs 2021-07-15 18:49:47 +02:00
Jakub Konka
e17f12dd64 zld: fix incorrectly worked out section size
Also, add a solution to a degenerate case where on x86_64 a relocation
refers to a cell in a section via section start address even though
a symbol exists. In such case, make the section spawned symbol an alias
of the actual symbol.
2021-07-15 18:49:47 +02:00
Jakub Konka
de30a704b1 zld: map [section addr, first symbol) to a tracked TextBlock
which applies exclusively to x86_64-macos.
2021-07-15 18:49:47 +02:00
Jakub Konka
da07251000 zld: make addend i64 in Signed reloc 2021-07-15 18:49:47 +02:00
Jakub Konka
496903c6a8 zld: add DICE support mainly for x86_64-macos 2021-07-15 18:49:47 +02:00
Jakub Konka
e3fe9a9df5 zld: fix parsing and resolving Signed relocs
on x86_64-macos since this an x86_64 only relocation type.
2021-07-15 18:49:47 +02:00