aboutsummaryrefslogtreecommitdiff
path: root/src-self-hosted/link.zig
AgeCommit message (Collapse)Author
2020-05-27self-hosted: introduce a virtual address allocation schemeAndrew Kelley
The binary file abstraction changed its struct named "Decl" to "TextBlock" and it now represents an allocated slice of memory in the .text section. It has two new fields: prev and next, making it a linked list node. This allows a TextBlock to find its neighbors. The ElfFile struct now has free_list and last_text_block fields. Doc comments for free_list are reproduced here: A list of text blocks that have surplus capacity. This list can have false positives, as functions grow and shrink over time, only sometimes being added or removed from the freelist. A text block has surplus capacity when its overcapacity value is greater than minimum_text_block_size * alloc_num / alloc_den. That is, when it has so much extra capacity, that we could fit a small new symbol in it, itself with ideal_capacity or more. Ideal capacity is defined by size * alloc_num / alloc_den. Overcapacity is measured by actual_capacity - ideal_capacity. Note that overcapacity can be negative. A simple way to have negative overcapacity is to allocate a fresh text block, which will have ideal capacity, and then grow it by 1 byte. It will then have -1 overcapacity. The last_text_block keeps track of the end of the .text section. Allocation, freeing, and resizing decls are all now more sophisticated, and participate in the virtual address allocation scheme. There is no longer the possibility for virtual address collisions.
2020-05-19stage2: function calls using the global offset tableAndrew Kelley
so far they don't support parameters or return values
2020-05-19stage2: set up a trampoline table for functionsAndrew Kelley
However there does not appear to be an x86 encoding for calling an immediate address. So there's no point of setting this up. We should just emit an indirect call to the got addr.
2020-05-16self hosted repl: close executables between updatesAndrew Kelley
This allows the executable to be executed
2020-05-15move Module to its own fileAndrew Kelley
2020-05-15fix the global offset table code and updating decl exportsAndrew Kelley
2020-05-14fix codegen of sentinel-terminated arrays and .got alignmentAndrew Kelley
we now have an exit(0) program working
2020-05-14self-hosted: fix codegen and resolve some analysis bugsAndrew Kelley
2020-05-13self-hosted: fix the rest of the compile errorsAndrew Kelley
2020-05-13self-hosted: fix compile errors, except for codegen.zigAndrew Kelley
2020-05-12self-hosted: link: global offset table support for declsAndrew Kelley
2020-05-12self-hosted: rework the memory layout of ir.Module and related typesAndrew Kelley
* add TypedValue.Managed which represents a Type, a Value, and some kind of memory management strategy. * introduce an analysis queue * flesh out how incremental compilation works with respect to exports * ir.text.Module is only capable of one error message during parsing * link.zig no longer has a decl table map and instead has structs that exist directly on ir.Module.Decl and ir.Module.Export * implement primitive .text block allocation * implement linker code for updating Decls and Exports * implement null Type Some supporting std lib changes: * add std.ArrayList.appendSliceAssumeCapacity * add std.fs.File.copyRange and copyRangeAll * fix std.HashMap having modification safety on in ReleaseSmall builds * add std.HashMap.putAssumeCapacityNoClobber
2020-05-10rework self-hosted compiler for incremental buildsAndrew Kelley
* introduce std.ArrayListUnmanaged for when you have the allocator stored elsewhere * move std.heap.ArenaAllocator implementation to its own file. extract the main state into std.heap.ArenaAllocator.State, which can be stored as an alternative to storing the entire ArenaAllocator, saving 24 bytes per ArenaAllocator on 64 bit targets. * std.LinkedList.Node pointer field now defaults to being null initialized. * Rework self-hosted compiler Package API * Delete almost all the bitrotted self-hosted compiler code. The only bit rotted code left is in main.zig and compilation.zig * Add call instruction to ZIR * self-hosted compiler ir API and link API are reworked to support a long-running compiler that incrementally updates declarations * Introduce the concept of scopes to ZIR semantic analysis * ZIR text format supports referencing named decls that are declared later in the file * Figure out how memory management works for the long-running compiler and incremental compilation. The main roots are top level declarations. There is a table of decls. The key is a cryptographic hash of the fully qualified decl name. Each decl has an arena allocator where all of the memory related to that decl is stored. Each code block has its own arena allocator for the lifetime of the block. Values that want to survive when going out of scope in a block must get copied into the outer block. Finally, values must get copied into the Decl arena to be long-lived. * Delete the unused MemoryCell struct. Instead, comptime pointers are based on references to Decl structs. * Figure out how caching works. Each Decl will store a set of other Decls which must be recompiled when it changes. This branch is still work-in-progress; this commit breaks the build.
2020-05-01zir: add breakpoint() instruction and object file abilityAndrew Kelley
2020-05-01link: introduce the concept of output mode and link modeAndrew Kelley
2020-05-01link: recognize that Windows does not have POSIX fs modesAndrew Kelley
2020-04-24link: change default executable mode to 0o777Andrew Kelley
Jonathan S writes: On common systems with a 022 umask, this will still result in a file created with 755 permissions, but it works appropriately if the system is configured more leniently. (As another data point, C's fopen seems to open files with the 666 mode.)
2020-04-24bug fixes to make it workAndrew Kelley
2020-04-23codegen: write the updated code size to PT_LOAD section headerAndrew Kelley
2020-04-23basics of writing ELF and machine code generationAndrew Kelley
2020-04-22zir-to-elf skeletonAndrew Kelley
2020-04-01(breaking) std.Buffer => std.ArrayListSentineled(u8, 0)Andrew Kelley
This new name (and the fact that it is a function returning a type) will make it more clear which use cases are better suited for ArrayList and which are better suited for ArrayListSentineled. Also for consistency with ArrayList, * `append` => `appendSlice` * `appendByte` => `append` Thanks daurnimator for pointing out the confusion of std.Buffer.
2020-03-30std lib API deprecations for the upcoming 0.6.0 releaseAndrew Kelley
See #3811
2020-03-17clean up some self-hosted bitrot + don't assume libstdc++Andrew Kelley
closes #4682 The self-hosted compiler is still bit rotted and still not compiling successfully yet. I have a more serious rework of the code in a different branch.
2020-02-28introduce operating system version ranges as part of the targetAndrew Kelley
* 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-03Add InstallRawStep to Zig build system that does a similar job to ↵Michaël Larouche
llvm-objcopy. To use it, do 'exe.installRaw("kernel.bin");' where exe is a LibExeObjStep Part of #2826
2020-02-01Run `zig fmt`LemonBoy
2020-01-07add --eh-frame-hdr conditionallyDavid Cao
2020-01-07add --eh-frame-hdr arg for linkingDavid Cao
2019-12-29fix stage2 buildVexu
2019-12-11self-hosted: manually parse argsAndrew Kelley
2019-12-08update self-hosted compiler to new format APIAndrew Kelley
2019-12-02remove upstream support for Zen hobby OSAndrew Kelley
The new plan to support hobby operating systems is #3784. And what kind of name is "Zen" anyway? There's already a [Zen programming language](http://zenlang.sourceforge.net/) and that's just confusing.
2019-12-01fixes for self-hosted compilerAndrew Kelley
2019-11-26add workaround for #3190Vexu
2019-11-26solve recursion in self hostedVexu
2019-11-26fixes and cleanup in self hostedVexu
2019-11-24Merge remote-tracking branch 'origin/master' into null-terminated-pointersAndrew Kelley
2019-11-23self hosted compiler: small miscellaneous fixesVexu
2019-11-21string literals are now null terminatedAndrew Kelley
this also deletes C string literals from the language, and then makes the std lib changes and compiler changes necessary to get the behavior tests and std lib tests passing again.
2019-11-08self hosted compiler: various small fixesVexu
2019-11-07self hosted compiler: move functions to util.zigto avoid defining llvm ↵Vexu
instricts.
2019-11-07self hosted compiler: use enum literalsVexu
2019-11-07self hosted compiler: unify Target and std.TargetVexu
2019-11-07self hosted compiler: remove await async patternVexu
2019-08-13avoid the word "coroutine", they're "async functions"Andrew Kelley
2019-06-09different array literal syntax when inferring the sizeAndrew Kelley
old syntax: []i32{1, 2, 3} new syntax: [_]i32{1, 2, 3} closes #1797
2019-06-07update the default macos version min to 10.14Andrew Kelley
2019-05-26clean up references to osAndrew Kelley
2019-02-26breaking changes to the way targets work in zigAndrew Kelley
* CLI: `-target [name]` instead of `--target-*` args. This matches clang's API. * `builtin.Environ` renamed to `builtin.Abi` - likewise `builtin.environ` renamed to `builtin.abi` * stop hiding the concept of sub-arch. closes #1526 * `zig targets` only shows available targets. closes #438 * include all targets in readme, even those that don't print with `zig targets` but note they are Tier 4 * refactor target.cpp and make the naming conventions more consistent * introduce the concept of a "default C ABI" for a given OS/Arch combo. As a rule of thumb, if the system compiler is clang or gcc then the default C ABI is the gnu ABI.