Skip to content

Commit 1d7543e

Browse files
aykevldeadprogram
authored andcommitted
all: switch to LLVM 16
This commit adds support for LLVM 16 and switches to it by default. That means three LLVM versions are supported at the same time: LLVM 14, 15, and 16. This commit includes work by QuLogic: * Part of this work was based on a PR by QuLogic: #3649 But I also had parts of this already implemented in an old branch I already made for LLVM 16. * QuLogic also provided a CGo fix here, which is also incorporated in this commit: #3869 The difference with the original PR by QuLogic is that this commit is more complete: * It switches to LLVM 16 by default. * It updates some things to also make it work with a self-built LLVM. * It fixes the CGo bug in a slightly different way, and also fixes another one not included in the original PR. * It does not keep compiler tests passing on older LLVM versions. I have found this to be quite burdensome and therefore don't generally do this - the smoke tests should hopefully catch most regressions.
1 parent ff32fbb commit 1d7543e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+233
-164
lines changed

.circleci/config.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ commands:
1010
steps:
1111
- restore_cache:
1212
keys:
13-
- llvm-source-14-v3
13+
- llvm-source-16-v3
1414
- run:
1515
name: "Fetch LLVM source"
1616
command: make llvm-source
1717
- save_cache:
18-
key: llvm-source-14-v3
18+
key: llvm-source-16-v3
1919
paths:
2020
- llvm-project/clang/lib/Headers
2121
- llvm-project/clang/include

.github/workflows/build-macos.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
uses: actions/cache/restore@v3
3434
id: cache-llvm-source
3535
with:
36-
key: llvm-source-15-macos-v3
36+
key: llvm-source-16-macos-v1
3737
path: |
3838
llvm-project/clang/lib/Headers
3939
llvm-project/clang/include
@@ -58,7 +58,7 @@ jobs:
5858
uses: actions/cache/restore@v3
5959
id: cache-llvm-build
6060
with:
61-
key: llvm-build-15-macos-v4
61+
key: llvm-build-16-macos-v1
6262
path: llvm-build
6363
- name: Build LLVM
6464
if: steps.cache-llvm-build.outputs.cache-hit != 'true'
@@ -120,7 +120,7 @@ jobs:
120120
- name: Install LLVM
121121
shell: bash
122122
run: |
123-
HOMEBREW_NO_AUTO_UPDATE=1 brew install llvm@15
123+
HOMEBREW_NO_AUTO_UPDATE=1 brew install llvm@16
124124
- name: Checkout
125125
uses: actions/checkout@v3
126126
- name: Install Go

.github/workflows/docker.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
push: true
5454
tags: ${{ steps.meta.outputs.tags }}
5555
labels: ${{ steps.meta.outputs.labels }}
56-
build-contexts: tinygo-llvm-build=docker-image://tinygo/llvm-15
56+
build-contexts: tinygo-llvm-build=docker-image://tinygo/llvm-16
5757
cache-from: type=gha
5858
cache-to: type=gha,mode=max
5959
- name: Trigger Drivers repo build on Github Actions

.github/workflows/linux.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ jobs:
4343
uses: actions/cache/restore@v3
4444
id: cache-llvm-source
4545
with:
46-
key: llvm-source-15-linux-alpine-v3
46+
key: llvm-source-16-linux-alpine-v1
4747
path: |
4848
llvm-project/clang/lib/Headers
4949
llvm-project/clang/include
@@ -68,7 +68,7 @@ jobs:
6868
uses: actions/cache/restore@v3
6969
id: cache-llvm-build
7070
with:
71-
key: llvm-build-15-linux-alpine-v4
71+
key: llvm-build-16-linux-alpine-v1
7272
path: llvm-build
7373
- name: Build LLVM
7474
if: steps.cache-llvm-build.outputs.cache-hit != 'true'
@@ -194,7 +194,7 @@ jobs:
194194
uses: actions/cache/restore@v3
195195
id: cache-llvm-source
196196
with:
197-
key: llvm-source-15-linux-asserts-v3
197+
key: llvm-source-16-linux-asserts-v1
198198
path: |
199199
llvm-project/clang/lib/Headers
200200
llvm-project/clang/include
@@ -219,7 +219,7 @@ jobs:
219219
uses: actions/cache/restore@v3
220220
id: cache-llvm-build
221221
with:
222-
key: llvm-build-15-linux-asserts-v4
222+
key: llvm-build-16-linux-asserts-v1
223223
path: llvm-build
224224
- name: Build LLVM
225225
if: steps.cache-llvm-build.outputs.cache-hit != 'true'
@@ -297,7 +297,7 @@ jobs:
297297
uses: actions/cache/restore@v3
298298
id: cache-llvm-source
299299
with:
300-
key: llvm-source-15-linux-v3
300+
key: llvm-source-16-linux-v1
301301
path: |
302302
llvm-project/clang/lib/Headers
303303
llvm-project/clang/include
@@ -322,7 +322,7 @@ jobs:
322322
uses: actions/cache/restore@v3
323323
id: cache-llvm-build
324324
with:
325-
key: llvm-build-15-linux-arm-v4
325+
key: llvm-build-16-linux-arm-v1
326326
path: llvm-build
327327
- name: Build LLVM
328328
if: steps.cache-llvm-build.outputs.cache-hit != 'true'
@@ -414,7 +414,7 @@ jobs:
414414
uses: actions/cache/restore@v3
415415
id: cache-llvm-source
416416
with:
417-
key: llvm-source-15-linux-v3
417+
key: llvm-source-16-linux-v1
418418
path: |
419419
llvm-project/clang/lib/Headers
420420
llvm-project/clang/include
@@ -439,7 +439,7 @@ jobs:
439439
uses: actions/cache/restore@v3
440440
id: cache-llvm-build
441441
with:
442-
key: llvm-build-15-linux-arm64-v4
442+
key: llvm-build-16-linux-arm64-v1
443443
path: llvm-build
444444
- name: Build LLVM
445445
if: steps.cache-llvm-build.outputs.cache-hit != 'true'

.github/workflows/llvm.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ jobs:
3535
uses: docker/metadata-action@v4
3636
with:
3737
images: |
38-
tinygo/llvm-15
39-
ghcr.io/${{ github.repository_owner }}/llvm-15
38+
tinygo/llvm-16
39+
ghcr.io/${{ github.repository_owner }}/llvm-16
4040
tags: |
4141
type=sha,format=long
4242
type=raw,value=latest

.github/workflows/sizediff.yml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ jobs:
2424
submodules: true
2525
- name: Install apt dependencies
2626
run: |
27-
echo 'deb https://apt.llvm.org/jammy/ llvm-toolchain-jammy-15 main' | sudo tee /etc/apt/sources.list.d/llvm.list
27+
echo 'deb https://apt.llvm.org/jammy/ llvm-toolchain-jammy-16 main' | sudo tee /etc/apt/sources.list.d/llvm.list
2828
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
2929
sudo apt-get update
3030
sudo apt-get install --no-install-recommends -y \
31-
llvm-15-dev \
32-
clang-15 \
33-
libclang-15-dev \
34-
lld-15
31+
llvm-16-dev \
32+
clang-16 \
33+
libclang-16-dev \
34+
lld-16
3535
- name: Restore LLVM source cache
3636
uses: actions/cache@v3
3737
id: cache-llvm-source
3838
with:
39-
key: llvm-source-15-sizediff-v1
39+
key: llvm-source-16-sizediff-v1
4040
path: |
4141
llvm-project/compiler-rt
4242
- name: Download LLVM source

.github/workflows/windows.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
uses: actions/cache/restore@v3
4242
id: cache-llvm-source
4343
with:
44-
key: llvm-source-15-windows-v4
44+
key: llvm-source-16-windows-v1
4545
path: |
4646
llvm-project/clang/lib/Headers
4747
llvm-project/clang/include
@@ -66,7 +66,7 @@ jobs:
6666
uses: actions/cache/restore@v3
6767
id: cache-llvm-build
6868
with:
69-
key: llvm-build-15-windows-v6
69+
key: llvm-build-16-windows-v1
7070
path: llvm-build
7171
- name: Build LLVM
7272
if: steps.cache-llvm-build.outputs.cache-hit != 'true'

Makefile

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ LLD_SRC ?= $(LLVM_PROJECTDIR)/lld
1010

1111
# Try to autodetect LLVM build tools.
1212
# Versions are listed here in descending priority order.
13-
LLVM_VERSIONS = 15 14 13 12 11
13+
LLVM_VERSIONS = 16 15 14 13 12 11
1414
errifempty = $(if $(1),$(1),$(error $(2)))
1515
detect = $(shell which $(call errifempty,$(firstword $(foreach p,$(2),$(shell command -v $(p) 2> /dev/null && echo $(p)))),failed to locate $(1) at any of: $(2)))
1616
toolSearchPathsVersion = $(1)-$(2)
@@ -113,7 +113,7 @@ endif
113113

114114
.PHONY: all tinygo test $(LLVM_BUILDDIR) llvm-source clean fmt gen-device gen-device-nrf gen-device-nxp gen-device-avr gen-device-rp
115115

116-
LLVM_COMPONENTS = all-targets analysis asmparser asmprinter bitreader bitwriter codegen core coroutines coverage debuginfodwarf debuginfopdb executionengine frontendopenmp instrumentation interpreter ipo irreader libdriver linker lto mc mcjit objcarcopts option profiledata scalaropts support target windowsdriver windowsmanifest
116+
LLVM_COMPONENTS = all-targets analysis asmparser asmprinter bitreader bitwriter codegen core coroutines coverage debuginfodwarf debuginfopdb executionengine frontendhlsl frontendopenmp instrumentation interpreter ipo irreader libdriver linker lto mc mcjit objcarcopts option profiledata scalaropts support target windowsdriver windowsmanifest
117117

118118
ifeq ($(OS),Windows_NT)
119119
EXE = .exe
@@ -154,7 +154,7 @@ LLD_LIB_NAMES = lldCOFF lldCommon lldELF lldMachO lldMinGW lldWasm
154154
LLD_LIBS = $(START_GROUP) $(addprefix -l,$(LLD_LIB_NAMES)) $(END_GROUP)
155155

156156
# Other libraries that are needed to link TinyGo.
157-
EXTRA_LIB_NAMES = LLVMInterpreter LLVMMCA LLVMX86TargetMCA
157+
EXTRA_LIB_NAMES = LLVMInterpreter LLVMMCA LLVMRISCVTargetMCA LLVMX86TargetMCA
158158

159159
# All libraries to be built and linked with the tinygo binary (lib/lib*.a).
160160
LIB_NAMES = clang $(CLANG_LIB_NAMES) $(LLD_LIB_NAMES) $(EXTRA_LIB_NAMES)
@@ -170,7 +170,7 @@ NINJA_BUILD_TARGETS = clang llvm-config llvm-ar llvm-nm $(addprefix lib/lib,$(ad
170170
# For static linking.
171171
ifneq ("$(wildcard $(LLVM_BUILDDIR)/bin/llvm-config*)","")
172172
CGO_CPPFLAGS+=$(shell $(LLVM_CONFIG_PREFIX) $(LLVM_BUILDDIR)/bin/llvm-config --cppflags) -I$(abspath $(LLVM_BUILDDIR))/tools/clang/include -I$(abspath $(CLANG_SRC))/include -I$(abspath $(LLD_SRC))/include
173-
CGO_CXXFLAGS=-std=c++14
173+
CGO_CXXFLAGS=-std=c++17
174174
CGO_LDFLAGS+=-L$(abspath $(LLVM_BUILDDIR)/lib) -lclang $(CLANG_LIBS) $(LLD_LIBS) $(shell $(LLVM_CONFIG_PREFIX) $(LLVM_BUILDDIR)/bin/llvm-config --ldflags --libs --system-libs $(LLVM_COMPONENTS)) -lstdc++ $(CGO_LDFLAGS_EXTRA)
175175
endif
176176

@@ -238,7 +238,7 @@ gen-device-renesas: build/gen-device-svd
238238

239239
# Get LLVM sources.
240240
$(LLVM_PROJECTDIR)/llvm:
241-
git clone -b xtensa_release_15.x --depth=1 https://github.com/espressif/llvm-project $(LLVM_PROJECTDIR)
241+
git clone -b xtensa_release_16.x --depth=1 https://github.com/espressif/llvm-project $(LLVM_PROJECTDIR)
242242
llvm-source: $(LLVM_PROJECTDIR)/llvm
243243

244244
# Configure LLVM.

builder/cc1as.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#include "llvm/Support/Timer.h"
5757
#include "llvm/Support/raw_ostream.h"
5858
#include <memory>
59+
#include <optional>
5960
#include <system_error>
6061
using namespace clang;
6162
using namespace clang::driver;
@@ -103,6 +104,14 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
103104
Opts.Triple = llvm::Triple::normalize(Args.getLastArgValue(OPT_triple));
104105
if (Arg *A = Args.getLastArg(options::OPT_darwin_target_variant_triple))
105106
Opts.DarwinTargetVariantTriple = llvm::Triple(A->getValue());
107+
if (Arg *A = Args.getLastArg(OPT_darwin_target_variant_sdk_version_EQ)) {
108+
VersionTuple Version;
109+
if (Version.tryParse(A->getValue()))
110+
Diags.Report(diag::err_drv_invalid_value)
111+
<< A->getAsString(Args) << A->getValue();
112+
else
113+
Opts.DarwinTargetVariantSDKVersion = Version;
114+
}
106115

107116
Opts.CPU = std::string(Args.getLastArgValue(OPT_target_cpu));
108117
Opts.Features = Args.getAllArgValues(OPT_target_feature);
@@ -122,11 +131,12 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
122131
Opts.CompressDebugSections =
123132
llvm::StringSwitch<llvm::DebugCompressionType>(A->getValue())
124133
.Case("none", llvm::DebugCompressionType::None)
125-
.Case("zlib", llvm::DebugCompressionType::Z)
134+
.Case("zlib", llvm::DebugCompressionType::Zlib)
135+
.Case("zstd", llvm::DebugCompressionType::Zstd)
126136
.Default(llvm::DebugCompressionType::None);
127137
}
128138

129-
Opts.RelaxELFRelocations = Args.hasArg(OPT_mrelax_relocations);
139+
Opts.RelaxELFRelocations = !Args.hasArg(OPT_mrelax_relocations_no);
130140
if (auto *DwarfFormatArg = Args.getLastArg(OPT_gdwarf64, OPT_gdwarf32))
131141
Opts.Dwarf64 = DwarfFormatArg->getOption().matches(OPT_gdwarf64);
132142
Opts.DwarfVersion = getLastArgIntValue(Args, OPT_dwarf_version_EQ, 2, Diags);
@@ -189,6 +199,7 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
189199
Opts.NoExecStack = Args.hasArg(OPT_mno_exec_stack);
190200
Opts.FatalWarnings = Args.hasArg(OPT_massembler_fatal_warnings);
191201
Opts.NoWarn = Args.hasArg(OPT_massembler_no_warn);
202+
Opts.NoTypeCheck = Args.hasArg(OPT_mno_type_check);
192203
Opts.RelocationModel =
193204
std::string(Args.getLastArgValue(OPT_mrelocation_model, "pic"));
194205
Opts.TargetABI = std::string(Args.getLastArgValue(OPT_target_abi));
@@ -214,6 +225,8 @@ bool AssemblerInvocation::CreateFromArgs(AssemblerInvocation &Opts,
214225
.Case("default", EmitDwarfUnwindType::Default);
215226
}
216227

228+
Opts.AsSecureLogFile = Args.getLastArgValue(OPT_as_secure_log_file);
229+
217230
return Success;
218231
}
219232

@@ -265,6 +278,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
265278

266279
MCTargetOptions MCOptions;
267280
MCOptions.EmitDwarfUnwind = Opts.EmitDwarfUnwind;
281+
MCOptions.AsSecureLogFile = Opts.AsSecureLogFile;
268282

269283
std::unique_ptr<MCAsmInfo> MAI(
270284
TheTarget->createMCAsmInfo(*MRI, Opts.Triple, MCOptions));
@@ -314,6 +328,8 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
314328
TheTarget->createMCObjectFileInfo(Ctx, PIC));
315329
if (Opts.DarwinTargetVariantTriple)
316330
MOFI->setDarwinTargetVariantTriple(*Opts.DarwinTargetVariantTriple);
331+
if (!Opts.DarwinTargetVariantSDKVersion.empty())
332+
MOFI->setDarwinTargetVariantSDKVersion(Opts.DarwinTargetVariantSDKVersion);
317333
Ctx.setObjectFileInfo(MOFI.get());
318334

319335
if (Opts.SaveTemporaryLabels)
@@ -353,6 +369,7 @@ static bool ExecuteAssemblerImpl(AssemblerInvocation &Opts,
353369

354370
MCOptions.MCNoWarn = Opts.NoWarn;
355371
MCOptions.MCFatalWarnings = Opts.FatalWarnings;
372+
MCOptions.MCNoTypeCheck = Opts.NoTypeCheck;
356373
MCOptions.ABIName = Opts.TargetABI;
357374

358375
// FIXME: There is a bit of code duplication with addPassesToEmitFile.

builder/cc1as.h

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ struct AssemblerInvocation {
8282
unsigned NoExecStack : 1;
8383
unsigned FatalWarnings : 1;
8484
unsigned NoWarn : 1;
85+
unsigned NoTypeCheck : 1;
8586
unsigned IncrementalLinkerCompatible : 1;
8687
unsigned EmbedBitcode : 1;
8788

@@ -97,7 +98,14 @@ struct AssemblerInvocation {
9798

9899
/// Darwin target variant triple, the variant of the deployment target
99100
/// for which the code is being compiled.
100-
llvm::Optional<llvm::Triple> DarwinTargetVariantTriple;
101+
std::optional<llvm::Triple> DarwinTargetVariantTriple;
102+
103+
/// The version of the darwin target variant SDK which was used during the
104+
/// compilation
105+
llvm::VersionTuple DarwinTargetVariantSDKVersion;
106+
107+
/// The name of a file to use with \c .secure_log_unique directives.
108+
std::string AsSecureLogFile;
101109
/// @}
102110

103111
public:
@@ -114,6 +122,7 @@ struct AssemblerInvocation {
114122
NoExecStack = 0;
115123
FatalWarnings = 0;
116124
NoWarn = 0;
125+
NoTypeCheck = 0;
117126
IncrementalLinkerCompatible = 0;
118127
Dwarf64 = 0;
119128
DwarfVersion = 0;

0 commit comments

Comments
 (0)