aboutsummaryrefslogtreecommitdiff
path: root/src/link/Plan9.zig
AgeCommit message (Collapse)Author
2022-11-04all: rename i386 to x86Ali Chraghi
2022-10-29Merge pull request #13082 from g-w1/unnamed-decls-and-relocs-p9Andrew Kelley
Plan9: Fix The Backend
2022-10-24link: add an explicit error set for flush() and flushModule()Andrew Kelley
This makes it easier to understand how control flow should happen in various cases; already just by doing this it is revealed that UndefinedSymbol and UndefinedSymbolReference should be merged, and that MissingMainEntrypoint should be removed in favor of the ErrorFlags mechanism thath we already have for missing the main entrypoint. The main motivation for this change, however, is preventing a compile error when there is conditional compilation inside linker implementations, causing the flush() error set to depend on compilation options. With this change, the error set is fixed, and, notably, the `-Donly-c` flag no longer has compilation errors due to this error set.
2022-10-24additional fixes for Plan9Jacob G-W
with this, the tests should pass
2022-10-24Add relocations to the plan9 backendJacob G-W
2022-10-24Plan9: deal with unnamed declsJacob G-W
Hello World works again!
2022-09-13stage2: remove pointless discards from source codeAndrew Kelley
Good riddance!
2022-08-18std.Target gains ObjectFormat fieldAndrew Kelley
2022-04-20stage2: use indexes for Decl objectsAndrew Kelley
Rather than allocating Decl objects with an Allocator, we instead allocate them with a SegmentedList. This provides four advantages: * Stable memory so that one thread can access a Decl object while another thread allocates additional Decl objects from this list. * It allows us to use u32 indexes to reference Decl objects rather than pointers, saving memory in Type, Value, and dependency sets. * Using integers to reference Decl objects rather than pointers makes serialization trivial. * It provides a unique integer to be used for anonymous symbol names, avoiding multi-threaded contention on an atomic counter.
2022-04-17stage2: expose progress bar API to linker backendsAndrew Kelley
This gives us insight as to what is happening when we are waiting for things such as LLVM emit object and LLD linking.
2022-04-14stage2: progress towards stage3Andrew Kelley
* The `@bitCast` workaround is removed in favor of `@ptrCast` properly doing element casting for slice element types. This required an enhancement both to stage1 and stage2. * stage1 incorrectly accepts `.{}` instead of `{}`. stage2 code that abused this is fixed. * Make some parameters comptime to support functions in switch expressions (as opposed to making them function pointers). * Avoid relying on local temporaries being mutable. * Workarounds for when stage1 and stage2 disagree on function pointer types. * Workaround recursive formatting bug with a `@panic("TODO")`. * Remove unreachable `else` prongs for some inferred error sets. All in effort towards #89.
2022-03-01codegen: lower field_ptr to memory across linking backendsJakub Konka
This requires generating an addend for the target relocation as the field pointer might point at a field inner to the container.
2022-02-16link: avoid double close on openPath errorAndrew Kelley
2022-02-11macho: correctly lower slices incl reloc and rebase trackingJakub Konka
Match changes required to `Elf` linker, which enable lowering of const slices on `MachO` targets. Expand `Mir` instructions requiring the knowledge of the containing atom - pass the symbol index into the linker's table from codegen via mir to emitter, to then utilise it in the linker.
2022-02-11elf: store pointer relocations indexed by containing atomJakub Konka
In `getDeclVAddr`, it may happen that the target `Decl` has not been allocated space in virtual memory. In this case, we store a relocation in the linker-global table which we will iterate over when flushing the module, and fill in any missing address in the final binary. Note that for optimisation, if the address was resolved at the time of a call to `getDeclVAddr`, we skip relocating this atom. This commit also adds the glue code for lowering const slices in the ARM backend.
2022-02-07stage2: lower unnamed constants in Elf and MachOJakub Konka
* link: add a virtual function `lowerUnnamedConsts`, similar to `updateFunc` or `updateDecl` which needs to be implemented by the linker backend in order to be used with the `CodeGen` code * elf: implement `lowerUnnamedConsts` specialization where we lower unnamed constants to `.rodata` section. We keep track of the atoms encompassing the lowered unnamed consts in a global table indexed by parent `Decl`. When the `Decl` is updated or destroyed, we clear the unnamed consts referenced within the `Decl`. * macho: implement `lowerUnnamedConsts` specialization where we lower unnamed constants to `__TEXT,__const` section. We keep track of the atoms encompassing the lowered unnamed consts in a global table indexed by parent `Decl`. When the `Decl` is updated or destroyed, we clear the unnamed consts referenced within the `Decl`. * x64: change `MCValue.linker_sym_index` into two `MCValue`s: `.got_load` and `.direct_load`. The former signifies to the emitter that it should emit a GOT load relocation, while the latter that it should emit a direct load (`SIGNED`) relocation. * x64: lower `struct` instantiations
2022-01-06Plan9: fix amount to say included line count isJacob G-W
Not sure why this was working before...
2022-01-06Plan9: implement getDeclVAddrJacob G-W
2022-01-06plan9: fix .z symbol in debuginfoJacob G-W
This allows the `acid` debugger on plan9 to be used to debug a zig source file without patching `acid`! The patch adds a second `z` symbol. This z symbol has a value of 0, which means that it pops the history stack. We put a very large number for the value of the second symbol because it has to be at least as large as the linecount of the file. The debuginfo format is meant to be used with c files, where the stack would look something like this: ``` -> Line: 0x1 (1) Name: 0x1/0x2/0x3/0xe/0x13/0x1b (/sys/src/libc/port/malloc.c) -> Line: 0x2 (2) Name: 0x1/0x6/0x7/0x8 (/amd64/include/u.h) -> Line: 0x4f (79) Name: () -> Line: 0x50 (80) Name: 0x1/0x2/0x7/0x9 (/sys/include/libc.h) -> Line: 0x358 (856) Name: () -> Line: 0x359 (857) Name: 0x1/0x2/0x7/0x1c (/sys/include/pool.h) -> Line: 0x392 (914) Name: () -> Line: 0x393 (915) Name: 0x1/0x2/0x7/0x1d (/sys/include/tos.h) -> Line: 0x3ab (939) Name: () -> Line: 0x4eb (1259) Name: () ``` however in zig, we do not use includes and .h files, so we only need the first and last items in the stack: the source file that the symbols belong to, and the pop symbol with a null name and a value of the total linecount of the preprocessed source. Since there is no preprocessing in zig, we just make the linecount very large. There do not appear to be any downsides to this approach. If this causes a bug in the future, a simple fix would be to make the pop symbol just have the value of how many newlines are in the source file.
2021-12-18plan9 linker: fix off by 1 errorJacob G-W
2021-11-30allocgate: renamed getAllocator function to allocatorLee Cannon
2021-11-30allocgate: stage 1 and 2 buildingLee Cannon
2021-11-30allocgate: std Allocator interface refactorLee Cannon
2021-11-30std lib API deprecations for the upcoming 0.9.0 releaseAndrew Kelley
See #3811
2021-11-21stage2: fix the build for 32-bit architecturesAndrew Kelley
* Introduce a mechanism into Sema for emitting a compile error when an integer is too big and we need it to fit into a usize. * Add `@intCast` where necessary * link/MachO: fix an unnecessary allocation when all that was happening was appending zeroes to an ArrayList. * Add `error.Overflow` as a possible error to some codepaths, allowing usage of `math.intCast`. closes #9710
2021-10-02Delete Module.Scope, move Block into SemaMartin Wickham
2021-10-02Remove my dumb "namespace decl" hackMartin Wickham
2021-09-20plan9 linker: link lineinfo and filenamesJacob G-W
2021-09-18plan9 linker: get ready to delete allocateDeclIndexesJacob G-W
2021-09-18plan9 linker: add free lists for got_index and sym_indexJacob G-W
This allows the same global offset and symbol table index to be re-used if a decl is freed.
2021-09-18plan9: emit line debug info in codegenJacob G-W
2021-09-14plan9 linker: fix for 32 bitJacob G-W
2021-07-29stage2: garbage collect unused anon declsAndrew Kelley
After this change, the frontend and backend cooperate to keep track of which Decls are actually emitted into the machine code. When any backend sees a `decl_ref` Value, it must mark the corresponding Decl `alive` field to true. This prevents unused comptime data from spilling into the output object files. For example, if you do an `inline for` loop, previously, any intermediate value calculations would have gone into the object file. Now they are garbage collected immediately after the owner Decl has its machine code generated. In the frontend, when it is time to send a Decl to the linker, if it has not been marked "alive" then it is deleted instead. Additional improvements: * Resolve type ABI layouts after successful semantic analysis of a Decl. This is needed so that the backend has access to struct fields. * Sema: fix incorrect logic in resolveMaybeUndefVal. It should return "not comptime known" instead of a compile error for global variables. * `Value.pointerDeref` now returns `null` in the case that the pointer deref cannot happen at compile-time. This is true for global variables, for example. Another example is if a comptime known pointer has a hard coded address value. * Binary arithmetic sets the requireRuntimeBlock source location to the lhs_src or rhs_src as appropriate instead of on the operator node. * Fix LLVM codegen for slice_elem_val which had the wrong logic for when the operand was not a pointer. As noted in the comment in the implementation of deleteUnusedDecl, a future improvement will be to rework the frontend/linker interface to remove the frontend's responsibility of calling allocateDeclIndexes. I discovered some issues with the plan9 linker backend that are related to this, and worked around them for now.
2021-07-20plan9 linker: fix after testingJacob G-W
* exports get rendered properly in symbol table * global offset table is at the start of data section instead of after symtab * various null use fixes
2021-07-20plan9 linker: make more incrementalJacob G-W
The incrementalness is now roughly the same as the c backend rather than the spirv backend before.
2021-07-20stage2: Air and Liveness are passed ephemerallyAndrew Kelley
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-11stage2 plan9: add aarch64 supportJacob G-W
2021-07-08plan9 cleanupsAndrew Kelley
* rename files to adhere to conventions * remove unnecessary function / optionality * fix merge conflict * better panic message * remove unnecessary TODO comment * proper namespacing of declarations * clean up documentation comments * no copyright header needed for a brand new zig file that is not copied from anywhere
2021-07-08plan9 linker: remove unused stuffJacob G-W
2021-07-08plan9 linker: remove panics and improve 64 bit supportJacob G-W
Don't @intCast when we do not need to, and change some panics to unreachable when they can never happen.
2021-07-08plan9 linker: use a global offset tableJacob G-W
this simplifies stuff and makes us not have to use relocations
2021-07-08plan9 linker: correct runtime vs file offset converting codeJacob G-W
2021-07-08plan9 linker: produce an object file that can actually work!!!Jacob G-W
2021-07-08plan9 linker: do relocationsJacob G-W
2021-07-08plan9 linker: write symbol tableJacob G-W
Also switch to iovecs because gotta go fast.
2021-07-08plan9 linker: make runnable binariesJacob G-W
We can now run binaries! (they segfault, but still run!)
2021-07-08initial plan9 boilerplatejacob gw
The code now compiles and fails with Plan9ObjectFormatUnimplemented