aboutsummaryrefslogtreecommitdiffhomepage
path: root/compileopts/target.go
AgeCommit message (Collapse)Author
2021-11-30all: add LLVM 12 supportAyke van Laethem
Originally based on a PR by @QuLogic, but extended a lot to get all tests to pass.
2021-11-20targets: change LLVM features to match vanilla ClangAyke van Laethem
I mistakenly believed the difference was in LLVM version 11.0.0 vs LLVM 11.1.0. However, the difference is in whether we use the Debian version of Clang. The Debian version has had lots of patches. I'm not sure which is to blame, but it could be this one: https://salsa.debian.org/pkg-llvm-team/llvm-toolchain/-/blob/snapshot/debian/patches/clang-arm-default-vfp3-on-armv7a.patch
2021-11-16all: add support for windows/amd64Ayke van Laethem
This uses Mingw-w64, which seems to be the de facto standard for porting Unixy programs to Windows.
2021-11-15all: add support for GOARMAyke van Laethem
This environment variable can be set to 5, 6, or 7 and controls which ARM version (ARMv5, ARMv6, ARMv7) is used when compiling for GOARCH=arm. I have picked the default value ARMv6, which I believe is supported on most common single board computers including all Raspberry Pis. The difference in code size is pretty big. We could even go further and support ARMv4 if anybody is interested. It should be pretty simple to add this if needed.
2021-11-14internal/task: use asyncify on webassemblyNia Waldvogel
This change implements a new "scheduler" for WebAssembly using binaryen's asyncify transform. This is more reliable than the current "coroutines" transform, and works with non-Go code in the call stack. runtime (js/wasm): handle scheduler nesting If WASM calls into JS which calls back into WASM, it is possible for the scheduler to nest. The event from the callback must be handled immediately, so the task cannot simply be deferred to the outer scheduler. This creates a minimal scheduler loop which is used to handle such nesting.
2021-11-07all: add target-features string to all targetsAyke van Laethem
This makes sure that the LLVM target features match the one generated by Clang: - This fixes a bug introduced when setting the target CPU for all targets: Cortex-M4 would now start using floating point operations while they were disabled in C. - This will make it possible in the future to inline C functions in Go and vice versa. This will need some more work though. There is a code size impact. Cortex-M4 targets are increased slightly in binary size while Cortex-M0 targets tend to be reduced a little bit. Other than that, there is little impact.
2021-11-07compileopts: fix reversed append in the target fileAyke van Laethem
With this fix, `cflags` in the target JSON files is correctly ordered. Previously, the cflags of a parent JSON file would come after the ones in the child JSON file, which makes it hard to override properties in the child JSON file. Specifically, this fixes the case where targets/riscv32.json sets `-march=rv32imac` and targets/esp32c3.json wants to override this using `-march=rv32imc` but can't do this because its `-march` comes before the riscv32.json one.
2021-11-05targets: match LLVM triple to the one Clang usesAyke van Laethem
The target triples have to match mostly to be able to link LLVM modules. Linking LLVM modules is already possible (the triples already match), but testing becomes much easier when they match exactly. For macOS, I picked "macosx10.12.0". That's an old and unsupported version, but I had to pick _something_. Clang by default uses "macos10.4.0", which is much older.
2021-11-04builder: build static binaries using musl on LinuxAyke van Laethem
This commit adds support for musl-libc and uses it by default on Linux. The main benefit of it is that binaries are always statically linked instead of depending on the host libc, even when using CGo. Advantages: - The resulting binaries are always statically linked. - No need for any tools on the host OS, like a compiler, linker, or libc in a release build of TinyGo. - This also simplifies cross compilation as no cross compiler is needed (it's all built into the TinyGo release build). Disadvantages: - Binary size increases by 5-6 kilobytes if -no-debug is used. Binary size increases by a much larger margin when debugging symbols are included (the default behavior) because musl is built with debugging symbols enabled. - Musl does things a bit differently than glibc, and some CGo code might rely on the glibc behavior. - The first build takes a bit longer because musl needs to be built. As an additional bonus, time is now obtained from the system in a way that fixes the Y2038 problem because musl has been a bit more agressive in switching to 64-bit time_t.
2021-11-03targets: add CPU property everywhereAyke van Laethem
This is for consistency with Clang, which always adds a CPU flag even if it's not specified in CFLAGS. This commit also adds some tests to make sure the Clang target-cpu matches the CPU property in the JSON files. This does have an effect on the generated binaries. The effect is very small though: on average just 0.2% increase in binary size, apparently because Cortex-M3 and Cortex-M4 are compiled a bit differently. However, when rebased on top of https://github.com/tinygo-org/tinygo/pull/2218 (minsize), the difference drops to -0.1% (a slight decrease on average).
2021-10-04main: remove -target flag for LLVM targetsAyke van Laethem
It is better to use environment variables (GOOS and GOARCH) for consistency instead of providing two slightly incompatible ways. This -target flag should only be used to specify a .json file (either directly or in the TinyGo targets directory). Previously it was possible to specify the LLVM target as well but that was never really fully supported. So: - To specify a different OS/arch like you would in regular Go, use GOOS and GOARCH. - To specify a microcontroller chip or board, use the -target flag. Also remove the old `os.Setenv` which might have had a purpose long ago but doesn't have a purpose now.
2021-10-04main: test other architectures by specifying a different GOARCHAyke van Laethem
... instead of setting a special -target= value. This is more robust and makes sure that the test actually tests different arcitectures as they would be compiled by TinyGo. As an example, the bug of the bugfix in the previous commit ("arm: use armv7 instead of thumbv7") would have been caught if this change was applied earlier. I've decided to put GOOS/GOARCH in compileopts.Options, as it makes sense to me to treat them the same way as command line parameters.
2021-10-04arm: use armv7 instead of thumbv7Ayke van Laethem
At the moment, thumbv7 is crashing. I'm not exactly sure why, but it appears that there is an unknown instruction in __aeabi_uldivmod (probably from libgcc). I've fixed this by switching to armv7, which is also somewhat modern. Maybe we can switch back to Thumb2 (aka thumbv7) once we start using musl and compiler-rt. In the meantime, this does fix a miscompilation (illegal instruction).
2021-09-28build: normalize target triples to match ClangAyke van Laethem
This commit changes a target triple like "armv6m-none-eabi" to "armv6m-unknown-unknow-eabi". The reason is that while the former is correctly parsed in Clang (due to normalization), it wasn't parsed correctly in LLVM meaning that the environment wasn't set to EABI. This change normalizes all target triples and uses the EABI environment (-eabi in the triple) for Cortex-M targets. This change also drops the `--target=` flag in the target JSON files, the flag is now added implicitly in `(*compileopts.Config).CFlags()`. This removes some duplication in target JSON files. Unfortunately, this change also increases code size for Cortex-M targets. It looks like LLVM now emits calls like __aeabi_memmove instead of memmove, which pull in slightly more code (they basically just call the regular C functions) and the calls themself don't seem to be as efficient as they could be. Perhaps this is a LLVM bug that will be fixed in the future, as this is a very common occurrence.
2021-09-15arm: switch to Thumb instruction set on ARMAyke van Laethem
This reduces binary size substantially, for two reasons: - It switches to a much more architecture ARMv4 vs ARMv7. - It switches to Thumb2, which is a lot denser than regular ARM. Practically all modern and not-so-modern ARM chips support Thumb2, so this seems like a safe change to me. The size in numbers: - Code size for testdata/stdlib.go is reduced by about 35%. - Binary size for testdata/stdlib.go (when compiling with -no-debug to strip debug information) is reduced by about 16%.
2021-08-10386: bump minimum requirement to the Pentium 4Ayke van Laethem
Previously we used the i386 target, probably with all optional features disabled. However, the Pentium 4 has been released a _long_ time ago and it seems reasonable to me to take that as a minimum requirement. Upstream Go now also seems to move in this direction: https://github.com/golang/go/issues/40255 The main motivation for this is that there were floating point issues when running the tests for the math package: GOARCH=386 tinygo test math I haven't investigated what's the issue, but I strongly suspect it's caused by the weird x87 80-bit floating point format. This could perhaps be fixed in a different way (by setting the FPU precision to 64 bits) but I figured that just setting the minimum requirement to the Pentium 4 would probably be fine. If needed, we can respect the GO386 environment variable to support these very old CPUs. To support this newer CPU, I had to make sure that the stack is aligned to 16 bytes everywhere. This was not yet always the case.
2021-06-25all: add a flag to the command line to select the serial implementationAyke van Laethem
This can be very useful for some purposes: * It makes it possible to disable the UART in cases where it is not needed or needs to be disabled to conserve power. * It makes it possible to disable the serial output to reduce code size, which may be important for some chips. Sometimes, a few kB can be saved this way. * It makes it possible to override the default, for example you might want to use an actual UART to debug the USB-CDC implementation. It also lowers the dependency on having machine.Serial defined, which is often not defined when targeting a chip. Eventually, we might want to make it possible to write `-target=nrf52` or `-target=atmega328p` for example to target the chip itself with no board specific assumptions. The defaults don't change. I checked this by running `make smoketest` before and after and comparing the results.
2021-06-19main: detect specific serial port IDs based on USB vid/pidAyke van Laethem
This makes it possible to flash a board even when there are multiple different kinds of boards attached, e.g. an Arduino Uno and a Circuit Playground Express. You can find the VID/PID pair in several ways: 1. By running `lsusb` before and after attaching the board and looking at the new USB device. 2. By grepping for `usb_PID` and `usb_VID` in the TinyGo source code. 3. By checking the Arduino IDE boards.txt from the vendor. Note that one board may have multiple VID/PID pairs: * The bootloader and main program may have a different PID, so far I've seen that the main program generally has the bootloader PID with 0x8000 added. * The software running on the board may have an erroneous PID, for example from a different board. I've seen this happen a few times. * A single board may have had some revisions which changed the PID. This is particularly true for the Arduino Uno. As a fallback, if the given VID/PID pair isn't found, the whole set of serial ports will be used. There are many boards which I haven't included yet simply because I couldn't test them.
2021-06-17rp2040: patch elf to checksum 2nd stage bootKenneth Bell
2021-05-09runtime: use the tasks scheduler instead of coroutinesAyke van Laethem
This results in smaller and likely more efficient code. It does require some architecture specific code for each architecture, but I've kept the amount of code as small as possible.
2021-05-02ci: bump Xcode version to use macOS 10.14Ayke van Laethem
The CircleCI macOS builds are failing, probably due to the old macOS version that's used. This version (10.13 High Sierra) isn't supported anymore on Homebrew so it seems best to me to simply bump the version. I picked Xcode 11.1.0 because 10.3.0 is somehow triggering an error while trying to install QEMU (the Python install fails). Because of this newer Xcode version, I had to add an extra flag (-isysroot) to the default command line for MacOS. The reason is that this newer Xcode version no longer stores header files in /usr/local, an SDK must be specified manually. With this change, the default SDK is used.
2021-04-19builder: hard code Clang compilerAyke van Laethem
At the moment, all targets use the Clang compiler to compile C and assembly files. There is no good reason to make this configurable anymore and in fact it will make future changes more complicated (and thus more likely to have bugs). Therefore, I've removed support for setting the compiler. Note that the same is not true for the linker. While it makes sense to standardize on the Clang compiler (because if Clang doesn't support a target, TinyGo is unlikely to support it either), linkers will remain configurable for the foreseeable future. One example is Xtensa, which is supported by the Xtensa LLVM fork but doesn't have support in ld.lld yet. I've also fixed a bug in compileAndCacheCFile: it wasn't using the right CFlags for caching purposes. This could lead to using stale caches. This commit fixes that too.
2021-03-29throw an error on windows builds with no target specifiedTobias Theel
2021-03-29gdb: enable to specify multiple candidates for gdbsago35
2020-12-30Add support for additional openocd commands (#1492)Jacques Supcik
main: add ability to define specific OpenOCD commands to be executed for a target.
2020-10-03add wasm-abi field in TargetSpec && set generic for WASI by default (#1421)Takeshi Yoneda
Signed-off-by: mathetake <[email protected]>
2020-10-02gc: use raw stack access whenever possibleAyke van Laethem
The only architecture that actually needs special support for scanning the stack is WebAssembly. All others allow raw access to the stack with a small bit of assembly. Therefore, don't manually keep track of all these objects on the stack manually and instead just use conservative stack scanning. This results in a massive code size decrease in the affected targets (only tested linux/amd64 for code size) - sometimes around 33%. It also allows for future improvements such as using proper stackful goroutines.
2020-10-02main: add support for debugging qemu-user targetsAyke van Laethem
This commit allows debugging like the following: GOARCH=arm tinygo gdb ./testdata/alias.go This can be very useful to debug issues on a different instruction set architecture but still on a host system. I tested the following 7 configurations to make sure it works and I didn't break anything: GOOS=amd64 GOOS=386 GOOS=arm GOOS=arm64 tinygo gdb -target=hifive1-qemu tinygo gdb -target=cortex-m-qemu tinygo gdb -target=microbit
2020-10-02main: improve support for x86-32 and add testsAyke van Laethem
To avoid breaking this, make sure we actually test x86-32 (aka i386 aka GOARCH=386) support in CI. Also remove the now-unnecessary binutils-arm-none-eabi package to speed up CI a bit.
2020-09-20compileopts: simplify copyProperties using reflectionJacques Supcik
2020-08-31compileopts: add support for custom binary formatsAyke van Laethem
Some chips (like the ESP family) have a particular image format that is more complex than simply dumping everything in a raw image.
2020-08-27arm: automatically determine stack sizesAyke van Laethem
This is a big change that will determine the stack size for many goroutines automatically. Functions that aren't recursive and don't call function pointers can in many cases have an automatically determined worst case stack size. This is useful, as the stack size is usually much lower than the previous hardcoded default of 1024 bytes: somewhere around 200-500 bytes is common. A side effect of this change is that the default stack sizes (including the stack size for other architectures such as AVR) can now be changed in the config JSON file, making it tunable per application.
2020-07-31nintendoswitch: Add experimental Nintendo Switch support without CRTLucas Teske
Bare minimal nintendo switch support using LLD
2020-07-08Changes according to @aykevl's feedbackYannis Huber
2020-07-08Add llvm code model option in target definitionYannis Huber
2020-06-08compiler: add support for custom code modelYannis Huber
2020-03-22all: include picolibc for bare metal targetsAyke van Laethem
This is necessary for better CGo support on bare metal. Existing libraries expect to be able to include parts of libc and expect to be able to link to those symbols. Because with this all targets have a working libc, it is now possible to add tests to check that a libc in fact works basically. Not all parts of picolibc are included, such as the math or stdio parts. These should be added later, when needed. This commit also avoids the need for the custom memcpy/memset/memcmp symbols that are sometimes emitted by LLVM. The C library will take care of that.
2020-01-20compileopts: fix CGo when cross compilingAyke van Laethem
Use the cross compiling toolchains for compiling/linking. This fixes CGo support, and therefore allows CGo to be used when cross compiling to Linux on a different architecture. This commit also removes some redundant testing code.
2020-01-12compiler: add support for debugging through JLinkGDBServerAyke van Laethem
Some J-Link targets aren't supported in OpenOCD (or would need some special configuration), so also give the option to use JLinkGDBServer instead.
2020-01-06targets: add target circuitplay-bluefruitMichael Matloob
Add a target for the Adafruit Circuit Playground Bluefruit, which is based on the nRF52840. Adds the necessary code for the machine package and the json and linker script files in the targets directory. The machine package code is based on board_circuitplay_express.go, with modifications made by consulting the wiring diagram on the adafruit website here: https://learn.adafruit.com/adafruit-circuit-playground-bluefruit/downloads Also adds support to the uf2 conversion packacge to set the familyID field. The Circuit Playground Bluefruit firmware rejects uf2 files without the family id set to 0xADA52840 (and without the flag specifying that the family id is present).
2019-11-12main: add -programmer flagAyke van Laethem
This flag is overloaded. It can be used in two ways: * Choosing the flash method to use (openocd, msd, command). * Choosing the OpenOCD programmer name. For example, you can use one of these to use OpenOCD instead of the mass-storage device programmer: tinygo flash -target=microbit -programmer=openocd tinygo flash -target=microbit -programmer=cmsis-dap
2019-11-04compileopts: add linkerscript keyAyke van Laethem
Setting the linker script as one property (instead of as part of the generic ldflags property) allows it to be overriden. This is important for the SoftDevice on Nordic chips, because the SoftDevice takes up a fixed part of the flash/RAM and the application must be flashed at a different position. With this linkerscript option, it is possible to create (for example) a pca10040-s132v6 that overrides the default linker script.
2019-11-04main: move target specification into a separate packageAyke van Laethem