aboutsummaryrefslogtreecommitdiff
path: root/src-self-hosted/link.zig
AgeCommit message (Collapse)Author
2020-09-21rename src-self-hosted/ to src/Andrew Kelley
2020-09-21stage2: building compiler_rt and libc static archive with stage1Andrew Kelley
* add CLI support for verbose debugging options * implement building compiler_rt and libc static archive using stage1 C++ backend * add function_sections and link_libcpp to root cache hash. * cleanups to use the new Directory.join method. * Package supports being initialized directly and cleaned up create() method. * fix classifyFileExt incorrectly saying .zir is .zig. Thanks @Rocknest! * unify updateSubCompilation implementations
2020-09-18stage2 now supports using stage1 as a backend for compiling zig codeAndrew Kelley
* move stage2.cpp code into zig0.cpp for simplicity * add -ftime-report and some more CLI options to stage2 * stage2 compites the llvm cpu features string * classifyFileExt understands more file extensions * correction to generateBuiltinZigSource using the wrong allocator (thanks dbandstra!) * stage2 is now able to build hello.zig into hello.o using stage1 as a library however it fails linking due to missing compiler-rt * remove dead code * simplify zig0 builtin.zig source * fix not resolving builtin.zig source path causing duplicate imports * fix stage1.h not being valid C code * fix stage2.h not being valid C code
2020-09-17stage2: implement --show-builtinAndrew Kelley
This takes the place of `zig builtin`. This is an improvement over the command because now the generated source will correctly show LinkMode and OutputMode, whereas before it was always stuck as Static and Obj, respectively.
2020-09-17delete all stage1 c++ code not directly related to compiling stage2Andrew Kelley
Deleted 16,000+ lines of c++ code, including: * an implementation of blake hashing * the cache hash system * compiler.cpp * all the linking code, and everything having to do with building glibc, musl, and mingw-w64 * much of the stage1 compiler internals got slimmed down since it now assumes it is always outputting an object file. More stuff: * stage1 is now built with a different strategy: we have a tiny zig0.cpp which is a slimmed down version of what stage1 main.cpp used to be. Its only purpose is to build stage2 zig code into an object file, which is then linked by the host build system (cmake) into stage1. zig0.cpp uses the same C API that stage2 now has access to, so that stage2 zig code can call into stage1 c++ code. - stage1.h is - stage2.h is - stage1.zig is the main entry point for the Zig/C++ hybrid compiler. It has the functions exported from Zig, called in C++, and bindings for the functions exported from C++, called from Zig. * removed the memory profiling instrumentation from stage1. Abandon ship! * Re-added the sections to the README about how to build stage2 and stage3. * stage2 now knows as a comptime boolean whether it is being compiled as part of stage1 or as stage2. - TODO use this flag to call into stage1 for compiling zig code. * introduce -fdll-export-fns and -fno-dll-export-fns and clarify its relationship to link_mode (static/dynamic) * implement depending on LLVM to detect native target cpu features when LLVM extensions are enabled and zig lacks CPU feature detection for that target architecture. * C importing is broken, will need some stage2 support to function again.
2020-09-14stage2: support for machine code model CLIAndrew Kelley
2020-09-14stage2: implement writing archive filesAndrew Kelley
2020-09-14move std.cache_hash from std to stage2Andrew Kelley
The API is pretty specific to the implementationt details of the self-hosted compiler. I don't want to have to independently support and maintain this as part of the standard library, and be obligated to not make breaking changes to it with changes to the implementation of stage2.
2020-09-14fix stage1 regressions in this branchAndrew Kelley
also prepare for supporting linking into archives
2020-09-13stage2: CRT files retain locks on the build artifactsAndrew Kelley
2020-09-13stage2: don't create empty object files when no zig sourceAndrew Kelley
2020-09-13stage2: rename ZigModule to ModuleAndrew Kelley
2020-09-13stage2: rename Module to CompilationAndrew Kelley
2020-09-13stage2: caching system integration & Module/Compilation splittingAndrew Kelley
* update to the new cache hash API * std.Target defaultVersionRange moves to std.Target.Os.Tag * std.Target.Os gains getVersionRange which returns a tagged union * start the process of splitting Module into Compilation and "zig module". - The parts of Module having to do with only compiling zig code are extracted into ZigModule.zig. - Next step is to rename Module to Compilation. - After that rename ZigModule back to Module. * implement proper cache hash usage when compiling C objects, and properly manage the file lock of the build artifacts. * make versions optional to match recent changes to master branch. * proper cache hash integration for compiling zig code * proper cache hash integration for linking even when not compiling zig code. * ELF LLD linking integrates with the caching system. A comment from the source code: Here we want to determine whether we can save time by not invoking LLD when the output is unchanged. None of the linker options or the object files that are being linked are in the hash that namespaces the directory we are outputting to. Therefore, we must hash those now, and the resulting digest will form the "id" of the linking job we are about to perform. After a successful link, we store the id in the metadata of a symlink named "id.txt" in the artifact directory. So, now, we check if this symlink exists, and if it matches our digest. If so, we can skip linking. Otherwise, we proceed with invoking LLD. * implement disable_c_depfile option * add tracy to a few more functions
2020-09-12stage2: linking with LLD and building glibc static CRT filesAndrew Kelley
* implement --debug-cc and --debug-link * implement C source files having extra flags - TODO a way to pass them on the CLI * introduce the Directory abstraction which contains both an open file descriptor and a file path name. The former is preferred but the latter is needed when communicating paths over a command line (e.g. to Clang or LLD). * use the cache hash to choose an artifact directory - TODO: use separate cache hash instances for the zig module and each C object * Module: introduce the crt_files table for keeping track of built libc artifacts for linking. * Add the ability to build 4/6 of the glibc static CRT lib files. * The zig-cache directory is now passed as a parameter to Module. * Implement the CLI logic of -femit-bin and -femit-h - TODO: respect -fno-emit-bin - TODO: the emit .h feature * Add the -fvalgrind, -fstack-check, and --single-threaded CLI options. * Implement the logic for auto detecting whether to enable PIC, sanitize-C, stack-check, valgrind, and single-threaded. * Properly add PIC args (or not) to clang argv. * Implement renaming clang-compiled object files into their proper place within the cache artifact directory. - TODO: std lib needs a proper higher level abstraction for std.os.renameat. * Package is cleaned up to use the "Unmanaged" StringHashMap and use the new Directory abstraction. * Clean up zig lib directory detection to make proper use of directory handles. * Linker code invokes LLD. - TODO properly deal with the stdout and stderr that we get from it and expose diagnostics from the Module API that match the expected error message format. * Delete the bitrotted LLVM C ABI bindings. We'll resurrect just the functions we need as we introduce dependencies on them. So far it only has ZigLLDLink in it. * Remove dead timer code. * `zig env` now prints the path to the zig executable as well.
2020-09-09stage2: progress towards LLD linkingAndrew Kelley
* add `zig libc` command * add `--libc` CLI and integrate it with Module and linker code * implement libc detection and paths resolution * port LLD ELF linker line construction to stage2 * integrate dynamic linker option into Module and linker code * implement default link_mode detection and error handling if user requests static when it cannot be fulfilled * integrate more linker options * implement detection of .so.X.Y.Z file extension as a shared object file. nice try, you can't fool me. * correct usage text for -dynamic and -static
2020-09-09stage2 linker code supports opening an intermediate object fileAndrew Kelley
For when linking with LLD, we always create an object rather than going straight to the executable. Next step is putting this object on the LLD linker line.
2020-09-09stage2: compiling C objects with clangAndrew Kelley
* add target_util.zig which has ported code from src/target.cpp * Module gains an arena that owns memory used during initialization that has the same lifetime as the Module. Useful for constructing file paths and lists of strings that have mixed lifetimes. - The Module memory itself is allocated in this arena. init/deinit are modified to be create/destroy. - root_name moves to the arena and no longer needs manual free * implement the ability to invoke `zig clang` as a subprocess - there are lots of TODOs that should be solved before merging * Module now requires a Random object and zig_lib_dir * Module now requires a path to its own executable or any zig executable that can do `zig clang`. * Wire up more CLI options. * Module creates "zig-cache" directory and "tmp" and "o" subdirectories ("h" is created by the cache_hash) * stubbed out some of the things linker code needs to do with TODO prints * delete dead code for computing compiler id. the previous commit eliminated the need for it. * add `zig translate-c` CLI option but it's not fully hooked up yet. It should be possible for this to be fully wired up before merging this branch. * `zig targets` now uses canonical data for available_libcs
2020-09-09stage2: more progress moving `zig cc` to stage2Andrew Kelley
* std.cache_hash exposes Hasher type * std.cache_hash makes hasher_init a global const * std.cache_hash supports cloning so that clones can share the same open manifest dir handle as well as fork from shared hasher state * start to populate the cache_hash for stage2 builds * remove a footgun from std.cache_hash add function * get rid of std.Target.ObjectFormat.unknown * rework stage2 logic for resolving output artifact names by adding object_format as an optional parameter to std.zig.binNameAlloc * support -Denable-llvm in stage2 tests * Module supports the use case when there are no .zig files * introduce c_object_table and failed_c_objects to Module * propagate many new kinds of data from CLI into Module and into linker.Options * introduce -fLLVM, -fLLD, -fClang and their -fno- counterparts. closes #6251. - add logic for choosing when to use LLD or zig's self-hosted linker * stub code for implementing invoking Clang to build C objects * add -femit-h, -femit-h=foo, and -fno-emit-h CLI options
2020-09-04Added .pe ObjectFormatAlexandros Naskos
MachO linker no longer collects unused dwarf debug information
2020-09-04Completed basic PE linker for stage2Alexandros Naskos
Added std.coff.MachineType Added image characteristic and section flag valued to std.coff Added std.Target.Cpu.Arch.toCoffMachine Fixed stage2 --watch flag on windows
2020-09-04Start working on PE/COFF linking.Alexandros Naskos
2020-09-02hash_map: rename to ArrayHashMap and add new HashMap implementationSahnvour
2020-08-22stage2: clean up SPU Mk II codeAndrew Kelley
* 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-22Linker: make defaults read-onlyNoam Preil
2020-08-22SPU-II: Fix linkingNoam Preil
2020-08-21stage2: decouple codegen.zig from ELFAndrew Kelley
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-19Merge pull request #6085 from kubkon/macho-headerJakub Konka
Write out Mach-O header
2020-08-18stage2/link: clarify comments on calling orderIsaac Freund
2020-08-18Write out Mach-O headerJakub Konka
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-18stage2/wasm: add basic test casesIsaac Freund
2020-08-18stage2/wasm: write exports on flush, cleanupIsaac Freund
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-18stage2/wasm: implement basic container generationIsaac Freund
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-17Merge pull request #6046 from heidezomp/std-log-scoped-part2Andrew Kelley
std.log: (breaking) remove scope parameter from logging functions
2020-08-17Move Mach-O to link/MachO.zig submoduleJakub Konka
Remove `ptrWidth` since as of Catalina, all apps are 64bits only. Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-08-17Add skeleton for MachO support in stage2Jakub Konka
This commit adds an empty skeleton for MachO format support in stage2.
2020-08-15stage2: implement zig versionAndrew Kelley
2020-08-14stage2: astgen for non-labeled blocksAndrew Kelley
2020-08-13stage2: implement while loops (bool condition)Andrew Kelley
* 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-13update std and src-self-hosted for std.log breaking changeheidezomp
2020-08-12stage2: anyerror -> explicit error setAndrew Kelley
2020-08-12CBE: fix handling of IR dependenciesNoam Preil
2020-08-12CBE: Use zig_noreturn instead of noreturn to avoid namespace conflictNoam Preil
2020-08-12stage2: astgen for while loopsAndrew Kelley
See #6021
2020-08-11stage2: basic support for parameters .debug_infoAndrew Kelley
see #6014
2020-08-11stage2: emit DW_TAG_subprogram for function DeclsAndrew Kelley
these have the virtual address range, return type, and name.
2020-08-11stage2: set up per-Decl .debug_infoAndrew Kelley
2020-08-08stage2: fix crash on empty source fileAndrew Kelley
2020-08-07refactor now that stage1 supports anon default struct field initsAndrew Kelley
2020-08-07stage2: make link data in Decl into unionsIsaac Freund
This will allow for implementation of non-Elf backends without wasting memory.