aboutsummaryrefslogtreecommitdiff
path: root/src/target.zig
AgeCommit message (Collapse)Author
2022-08-30avoid exposing supportsTailCall in the standard libraryAndrew Kelley
This is problematic because in practice it depends on whether the compiler backend supports it too, as evidenced by the TODO comment about LLVM not supporting some architectures that in fact do support tail calls. Instead this logic is organized strategically in src/target.zig, part of the internal compiler source code, and the behavior tests in question duplicate some logic for deciding whether to proceed with the test. The proper place to expose this flag is in `@import("builtin")` - the generated source file - so that third party compilers can advertise whether they support tail calls.
2022-08-19stage2: disable stack-protector on wasm, matching stage1Andrew Kelley
The CI gave me: unknown import: `env::__stack_chk_fail` has not been defined
2022-08-19stage2: implement stack protectorsAndrew Kelley
This is one of the final remaining TODOs for the LLVM backend.
2022-07-21Sema: improve compile error for bad function alignmentAndrew Kelley
* Integrate more declaratively with src/target.zig * Only trigger the check when a function body is found, do not trigger for function types.
2022-06-30stage2: object format affects whether LLVM can be usedAndrew Kelley
2022-06-27LLVM: fix invalid IR on `@returnAddress` of wasm/bpfAndrew Kelley
see #11946
2022-05-22Set macOS/iPhoneOS/tvOS/watchOS ABI to none (unspecified) by defaultJakub Konka
Prior to this change we would assume the ABI for Apple targets to be GNU which could result in subtle errors in LLVM emitting calls to non-existent system libc provided functions such as `_sincosf` which is a GNU extension and as such is not provided by macOS for example. This would result in linker errors where the linker would not be able to find the said symbol in `libSystem.tbd`. With this change, we now correctly identify macOS (and other Apple platforms) as having ABI `unknown` which translates to unspecified in LLVM under-the-hood: ``` // main.ll target triple = "aarch64-unknown-macos-unknown" ``` Note however that we never suffix the target OS with target version such as `macos11` or `macos12` which means we fail to instruct LLVM of potential optimisations provided by the OS such as the availability of function `___sincosf_stret`. I suggest we investigate that in a follow-up commit.
2022-05-13target: Rename sparcv9 -> sparc64Koakuma
Rename all references of sparcv9 to sparc64, to make Zig align more with other projects. Also, added new function to convert glibc arch name to Zig arch name, since it refers to the architecture as sparcv9. This is based on the suggestion by @kubkon in PR 11847. (https://github.com/ziglang/zig/pull/11487#pullrequestreview-963761757)
2022-05-04stage2: change x86_64 max int alignment from 8 to 16Andrew Kelley
For x86_64, LLVMABIAlignmentOfType(i128) reports 8. However I think 16 is a better number for two reasons: 1. Better machine code when loading into SIMD register. 2. The C ABI wants 16 for extern structs.
2022-05-04stage2: improve semantics of atomic operationsAndrew Kelley
ZIR instructions updated: atomic_load, atomic_rmw, atomic_store, cmpxchg These no longer construct a pointer type as the result location. This solves a TODO that was preventing the pointer from possibly being volatile, as well as properly handling allowzero and addrspace. It also allows the pointer to be over-aligned, which may be needed depending on the target. As a consequence, the element type needs to be communicated in the ZIR. This is done by strategically making one of the operands be ResultLoc.ty instead of ResultLoc.coerced_ty if possible, or otherwise explicitly adding elem_type into the ZIR encoding, such as in the case of atomic_load. The pointer type of atomic operations is now checked in Sema by coercing it to an expected pointer type, that maybe over-aligned according to target requirements. Together with the previous commit, Zig now has smaller alignment for large integers, depending on the target, and yet still has type safety for atomic operations that specially require higher alignment.
2022-04-18wasm: Add support for debug infoLuuk de Gram
This implements basic DWARF output when building for the wasm target. Stacktraces, however, are currently not supported.
2022-04-14stage2: Add SPARC function alignmentKoakuma
This is based on @kubkon's suggestion.
2022-03-17stage2: default to LLVM backendAndrew Kelley
on targets for which self-hosted backends are not up to par. See #89
2022-02-23stage2: make -lgcc_s additionally link libunwindAndrew Kelley
Previously, Zig ignored -lgcc_s with a warning that this dependency is redundant because it is satisfied by compiler-rt. However, sfackler pointed out that it also provides exception handling functions. So if Zig sees -lgcc_s on the linker line, it needs to fulfill this dependency with libunwind. I also made link_libc inferred to be on if libunwind is linked since libunwind depends on libc.
2022-02-09CLI: ignore -lgcc_s when it is redundant with compiler-rtAndrew Kelley
For some projects, they can't help themselves, -lgcc_s ends up on the compiler command line even though it does not belong there. In Zig we know what -lgcc_s does. It's an alternative to compiler-rt. With this commit we emit a warning telling that it is unnecessary to put such thing on the command line, and happily ignore it, since we will fulfill the dependency with compiler-rt.
2022-01-26fix aarch64 include pathMotiejus Jakštys
2022-01-24stage2: type system treats fn ptr and body separatelyAndrew Kelley
This commit updates stage2 to enforce the property that the syntax `fn()void` is a function *body* not a *pointer*. To get a pointer, the syntax `*const fn()void` is required. ZIR puts function alignment into the func instruction rather than the decl because this way it makes it into function types. LLVM backend respects function alignments. Struct and Union have methods `fieldSrcLoc` to help look up source locations of their fields. These trigger full loading, tokenization, and parsing of source files, so should only be called once it is confirmed that an error message needs to be printed. There are some nice new error hints for explaining why a type is required to be comptime, particularly for structs that contain function body types. `Type.requiresComptime` is now moved into Sema because it can fail and might need to trigger field type resolution. Comptime pointer loading takes into account types that do not have a well-defined memory layout and does not try to compute a byte offset for them. `fn()void` syntax no longer secretly makes a pointer. You get a function body type, which requires comptime. However a pointer to a function body can be runtime known (obviously). Compile errors that report "expected pointer, found ..." are factored out into convenience functions `checkPtrOperand` and `checkPtrType` and have a note about function pointers. Implemented `Value.hash` for functions, enum literals, and undefined values. stage1 is not updated to this (yet?), so some workarounds and disabled tests are needed to keep everything working. Should we update stage1 to these new type semantics? Yes probably because I don't want to add too much conditional compilation logic in the std lib for the different backends.
2021-12-16glibc: fix inconsistency of powerpc ABI mappingAndrew Kelley
See the commit message of 5b6d26e97bb97d79782f3c77b02a997e361a1497 for an explanation. This is the same thing but for powerpc instead of mips.
2021-12-15glibc: fix inconsistency of mips ABI mappingAndrew Kelley
Before this commit, glibc headers did the following mapping: * (zig) mipsel-linux-gnu => (glibc) mipsel-linux-gnu * (zig) mipsel-linux-gnu-soft => (glibc) (none) * (zig) mips-linux-gnu => (glibc) mips-linux-gnu * (zig) mips-linux-gnu-soft => (glibc) (none) While the glibc ABI stubs used the (zig) gnueabi and gnueabihf ABIs, and the stage2 available_libcs array listed: * (zig) mipsel-linux-gnu * (zig) mips-linux-gnu The problem is the mismatch between the ABI component of the headers and the stubs. This commit makes the following clarifications: * (zig) mips-linux-gnueabi means soft-float * (zig) mipsel-linux-gnueabi means soft-float * (zig) mips-linux-gnueabihf means hard-float * (zig) mipsel-linux-gnueabihf means hard-float Consequently, the glibc headers now do this mapping: * (zig) mips-linux-gnueabihf => (glibc) mips-linux-gnu * (zig) mipsel-linux-gnueabihf => (glibc) mipsel-linux-gnu * (zig) mips-linux-gnueabi => (glibc) mips-linux-gnu-soft * (zig) mipsel-linux-gnueabi => (glibc) mipsel-linux-gnu-soft The glibc ABI stubs are unchanged, and the stage2 available_libcs array's 2 entries are modified and it gains 2 more: * (zig) mipsel-linux-gnueabi * (zig) mipsel-linux-gnueabihf * (zig) mips-linux-gnueabi * (zig) mips-linux-gnueabihf Now everything is consistent. Zig no longer recognizes a `mips-linux-gnu` triple; one must use `mips-linux-gnueabi` (soft float) or `mips-linux-gnueabihf` (hard float).
2021-12-03stage2: use Target.Abi instead of introducing Target.TargetAbiAndrew Kelley
This branch introduced std.Target.TargetAbi when we already had std.Target.Abi which was, unsurprisingly, already suited for this task. Also pull out the -mabi= cc flag addition to the common area instead of duplicating it for assembly and c files.
2021-11-29update libc linux headers to v5.16-rc3Andrew Kelley
* Add missing Linux headers. Closes #9837 * Update existing headers to latest Linux. * Consolidate headers that are the same for multiple Zig target CPU architectures. For example, Linux has only an x86 directory for both x86_64 and x86 CPU architectures. Now Zig only ships an x86 directory for Linux headers, and will emit the proper corresponding -isystem flags. * tools/update-linux-headers.zig is now available for upgrading to newer Linux headers, and the update process is now documented on the wiki.
2021-11-25infer and match macos sdk version for libc headersJakub Konka
2021-09-30Merge remote-tracking branch 'origin/master' into llvm13Andrew Kelley
2021-09-24Initial bringup of the Solaris/Illumos portStephen Gregoratto
2021-09-20Address Spaces: Yeet address space on function prototypesRobin Voetter
This is a property which solely belongs to pointers to functions, not to the functions themselves. This cannot be properly represented by stage 2 at the moment, as type with zigTypeTag() == .Fn is overloaded for for function pointers and function prototypes.
2021-09-15Merge remote-tracking branch 'origin/master' into llvm13Andrew Kelley
Conflicts: * cmake/Findclang.cmake * cmake/Findlld.cmake * cmake/Findllvm.cmake In master branch, more search paths were added to these files with "12" in the path. In this commit I updated them to "13". * src/stage1/codegen.cpp * src/zig_llvm.cpp * src/zig_llvm.h In master branch, ZigLLVMBuildCmpXchg is improved to add `is_single_threaded`. However, the LLVM 13 C API has this already, and in the llvm13 branch, ZigLLVMBuildCmpXchg is deleted in favor of the C API. In this commit I updated stage2 to use the LLVM 13 C API rather than depending on an improved ZigLLVMBuildCmpXchg. Additionally, src/target.zig largestAtomicBits needed to be updated to include the new m68k ISA.
2021-09-14stage2: implement cmpxchg and improve comptime evalAndrew Kelley
* Implement Sema for `@cmpxchgWeak` and `@cmpxchgStrong`. Both runtime and comptime codepaths are implement. * Implement Codegen for LLVM backend and C backend. * Add LazySrcLoc.node_offset_builtin_call_argX 3...5 * Sema: rework comptime control flow. - `error.ComptimeReturn` is used to signal that a comptime function call has returned a result (stored in the Inlining struct). `analyzeCall` notices this and handles the result. - The ZIR instructions `break_inline`, `block_inline`, `condbr_inline` are now redundant and can be deleted. `break`, `block`, and `condbr` function equivalently inside a comptime scope. - The ZIR instructions `loop` and `repeat` also are modified to directly perform comptime control flow inside a comptime scope, skipping an unnecessary mechanism for analysis of runtime code. This makes Zig perform closer to an interpreter when evaluating comptime code. * Sema: zirRetErrValue looks at Sema.ret_fn_ty rather than sema.func for adding to the inferred error set. This fixes a bug for inlined/comptime function calls. * Implement ZIR printing for cmpxchg. * stage1: make cmpxchg respect --single-threaded - Our LLVM C++ API wrapper failed to expose this boolean flag before. * Fix AIR printing for struct fields showing incorrect liveness data.
2021-08-28Merge remote-tracking branch 'origin/master' into llvm13Andrew Kelley
Conflicts: lib/libcxx/include/__config d57c0cc3bfeff9af297279759ec2b631e6d95140 added support for DragonFlyBSD to libc++ by updating some ifdefs. This needed to be synced with llvm13.
2021-08-23Don't define valgrind_support on macOS (#9612)Frank Denis
Unfortunately, Valgrind for macOS has been broken for years, and the Homebrew formula is only for Linux.
2021-08-16update src/ to LLVM 13 rc1 APIAndrew Kelley
2021-07-08initial plan9 boilerplatejacob gw
The code now compiles and fails with Plan9ObjectFormatUnimplemented
2021-07-02avoid calling into stage1 backend when AstGen failsAndrew Kelley
The motivation for this commit is that there exists source files which produce ast-check errors, but crash stage1 or otherwise trigger stage1 bugs. Previously to this commit, Zig would run AstGen, collect the compile errors, run stage1, report stage1 compile errors and exit if any, and then report AstGen compile errors. The main change in this commit is to report AstGen errors prior to invoking stage1, and in fact if any AstGen errors occur, do not invoke stage1 at all. This caused most of the compile error tests to fail due to things such as unused local variables and mismatched stage1/stage2 error messages. It was taking a long time to update the test cases one-by-one, so I took this opportunity to unify the stage1 and stage2 testing harness, specifically with regards to compile errors. In this way we can start keeping track of which tests pass for 1, 2, or both. `zig build test-compile-errors` no longer works; it is now integrated into `zig build test-stage2`. This is one step closer to executing compile error tests in parallel; in fact the ThreadPool object is already in scope. There are some cases where the stage1 compile errors were actually better; those are left failing in this commit, to be addressed in a follow-up commit. Other changes in this commit: * build.zig: improve support for -Dstage1 used with the test step. * AstGen: minor cosmetic changes to error messages. * stage2: add -fstage1 and -fno-stage1 flags. This now allows one to download a binary of the zig compiler and use the llvm backend of self-hosted. This was also needed for hooking up the test harness. However, I realized that stage1 calls exit() and also has memory leaks, so had to complicate the test harness by not using this flag after all and instead invoking as a child process. - These CLI flags will disappear once we start shipping the self-hosted compiler as the main compiler. Until then, they can be used to try out the work-in-progress stage2. * stage2: select the LLVM backend by default for release modes, as long as the target architecture is supported by LLVM. * test harness: support setting the optimize mode
2021-06-11better awareness of unwind tablesAndrew Kelley
* stage1 backend allows configuring the uwtables function attr via a flag rather than its own logic. * stage2 defaults to enabling uwtable attr when linking libunwind, or always on windows * stage2 makes link_eh_frame_hdr true automatically if uwtable attr is set to be on for zig functions * CLI: add -funwind-tables and -fno-unwind-tables to allow the user to override the defaults. * hook it up to `zig cc` closes #9046
2021-05-24haiku case for libc link flagsAl Hoang
2021-05-23stage2: introduce clangAssemblerSupportsMcpuArgAndrew Kelley
Clang has a completely inconsistent CLI for its integrated assembler for each target architecture. For x86_64, for example, it does not accept an -mcpu parameter, and emits "warning: unused parameter". However, for ARM, -mcpu is needed in order to properly lower assembly to machine code instructions (see new standalone test case provided thanks to @g-w1). This is a compromise between b8f85a805bf61ae11d6ee2bd6d8356fbc98ee3ba and afb9f695b1bdbf81185e7d55d5783bcbab880989.
2021-05-23overhaul elf csu (c-runtime startup) logicMichael Dusan
- more support for linux, android, freebsd, netbsd, openbsd, dragonfly - centralize musl utils; musl logic is no longer intertwined with csu - fix musl compilation to build crti/crtn for full archs list - fix openbsd to support `zig build-lib -dynamic` - initial dragonfly linking success (with a warning) ancillary: - fix emutls (openbsd) tests to use `try`
2021-05-22stage2: only pass -lm -lc -ldl for android libcIsaac Freund
The other libc components are not available on android.
2021-05-20wasm: link dynamically by default when targeting wasmJakub Konka
This matches the behaviour of other languages and leaves us the ability to create actual static Wasm archives with ``` zig build-lib -static some.zig ``` which can then be combined with other Wasm object files and linked into either a Wasm lib or executable using `wasm-ld`. Update langref to reflect the fact we now ship WASI libc.
2021-05-20wasi,cc: fix naming and add stubs for buildingJakub Konka
Rename include dir to match the convention: from `wasm32-wasi` to `wasm-wasi-musl` Add building stubs which will be used to build and cache WASI libc sysroot.
2021-05-14stage2: clarify logic of passing `-integrated-as` to clangAndrew Kelley
make it clear that the logic is only there to lower the amount of noise on the clang command line.
2021-05-13stage2: fix build on OpenBSD/NetBSDIsaac Freund
Apparently these systems do not provide libdl or librt.
2021-05-11stage2: Allow building musl/glibc in thumb modeLemonBoy
2021-04-04glibc: add support for csky architectureAndrew Kelley
2021-02-27std.Target.Abi: add gnuilp32Michael Dusan
2021-02-27std.Target: add powerpcleAndrew Kelley
2021-02-25Merge remote-tracking branch 'origin/master' into llvm12Andrew Kelley
Conflicts: * src/clang.zig * src/llvm.zig - this file got moved to src/llvm/bindings.zig in master branch so I had to put the new LLVM arch/os enum tags into it. * lib/std/target.zig, src/stage1/target.cpp - haiku had an inconsistency with its default target ABI, gnu vs eabi. In this commit we make it gnu in both places to match the latest changes by @hoanga. * src/translate_c.zig
2021-02-01Merge pull request #7827 from Snektron/spirv-setupAndrew Kelley
Stage 2: SPIR-V setup
2021-01-22stage2: wasm arch does not support -mred-zone flagsAndrew Kelley
2021-01-19SPIR-V: Add glsl450 and vulkan spir-v operating system definitionsRobin Voetter
2021-01-11stage2: cleanups regarding red zone CLI flagsAndrew Kelley
* CLI: change to -mred-zone and -mno-red-zone to match gcc/clang. * build.zig: remove the double negative and make it an optional bool. This follows precedent from other flags, allowing the compiler CLI to be the decider of what is default instead of duplicating the default value into the build system code. * Compilation: make it an optional `want_red_zone` instead of a `no_red_zone` bool. The default is decided by a call to `target_util.hasRedZone`. * When creating a Clang command line, put -mred-zone on the command line if we are forcing it to be enabled. * Update update_clang_options.zig with respect to the recent {s}/{} format changes. * `zig cc` integration with red zone preference.