Skip to content

Commit 6e429c3

Browse files
committed
Update wasm to llvm 21
1 parent 7f896f5 commit 6e429c3

File tree

4 files changed

+60
-51
lines changed

4 files changed

+60
-51
lines changed

overlays/nix-prefetch-git-minimal.nix

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ final: prev: {
1717
# This can reduce closure size of nix-tools:
1818
# * Eliminates dependency on python3 (70MB)
1919
# * Allows sharing with `fetchgit` as it also uses `gitMinimal` (50MB)
20-
inherit (final.callPackages (final.path + "/pkgs/tools/package-management/nix-prefetch-scripts") {
21-
git = final.gitMinimal;
22-
}) nix-prefetch-git;
20+
inherit (
21+
let f = import (final.path + "/pkgs/tools/package-management/nix-prefetch-scripts");
22+
in
23+
if (builtins.functionArgs f) ? git
24+
then final.callPackages f { git = final.gitMinimal; }
25+
else prev) nix-prefetch-git;
2326

2427
# fetchgit use `buildPackages.gitMinimal` and on nixpkgs 21.11
2528
# and earlier that causes problems when cross compiling.

overlays/patches/wasm/llvm/gnu-install-dirs.patch

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
diff --git a/CMakeLists.txt b/CMakeLists.txt
2-
index c9ff3696e22d..bd96aab5e237 100644
2+
index 73c4fc14f031..42284703a52c 100644
33
--- a/CMakeLists.txt
44
+++ b/CMakeLists.txt
5-
@@ -1133,9 +1133,9 @@ if (NOT TENSORFLOW_AOT_PATH STREQUAL "")
5+
@@ -1153,9 +1153,9 @@ if (NOT TENSORFLOW_AOT_PATH STREQUAL "")
66
add_subdirectory(${TENSORFLOW_AOT_PATH}/xla_aot_runtime_src
77
${CMAKE_ARCHIVE_OUTPUT_DIRECTORY}/tf_runtime)
88
install(TARGETS tf_xla_runtime EXPORT LLVMExports
@@ -15,7 +15,7 @@ index c9ff3696e22d..bd96aab5e237 100644
1515
# Once we add more modules, we should handle this more automatically.
1616
if (DEFINED LLVM_OVERRIDE_MODEL_HEADER_INLINERSIZEMODEL)
1717
diff --git a/cmake/modules/AddLLVM.cmake b/cmake/modules/AddLLVM.cmake
18-
index baf47677b247..81954240a9bf 100644
18+
index 52bf7ca0906a..ba2f4be17f08 100644
1919
--- a/cmake/modules/AddLLVM.cmake
2020
+++ b/cmake/modules/AddLLVM.cmake
2121
@@ -974,8 +974,8 @@ macro(add_llvm_library name)
@@ -29,17 +29,17 @@ index baf47677b247..81954240a9bf 100644
2929
RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}" COMPONENT ${name})
3030

3131
if (NOT LLVM_ENABLE_IDE)
32-
@@ -2240,7 +2240,7 @@ function(llvm_install_library_symlink name dest type)
32+
@@ -2258,7 +2258,7 @@ function(llvm_install_library_symlink name dest type)
3333
set(LLVM_LINK_OR_COPY copy)
3434
endif()
3535

3636
- set(output_dir lib${LLVM_LIBDIR_SUFFIX})
3737
+ set(output_dir ${CMAKE_INSTALL_FULL_LIBDIR}${LLVM_LIBDIR_SUFFIX})
38-
if(WIN32 AND "${type}" STREQUAL "SHARED")
38+
if((WIN32 OR CYGWIN) AND "${type}" STREQUAL "SHARED")
3939
set(output_dir "${CMAKE_INSTALL_BINDIR}")
4040
endif()
41-
@@ -2516,15 +2516,37 @@ function(llvm_setup_rpath name)
42-
41+
@@ -2534,15 +2534,37 @@ function(llvm_setup_rpath name)
42+
4343
if (APPLE)
4444
set(_install_name_dir INSTALL_NAME_DIR "@rpath")
4545
- set(_install_rpath "@loader_path/../lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
@@ -79,19 +79,6 @@ index baf47677b247..81954240a9bf 100644
7979
if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
8080
set_property(TARGET ${name} APPEND_STRING PROPERTY
8181
LINK_FLAGS " -Wl,-z,origin ")
82-
@@ -2539,9 +2561,9 @@ function(llvm_setup_rpath name)
83-
endif()
84-
85-
# Enable BUILD_WITH_INSTALL_RPATH unless CMAKE_BUILD_RPATH is set.
86-
- if("${CMAKE_BUILD_RPATH}" STREQUAL "")
87-
- set_property(TARGET ${name} PROPERTY BUILD_WITH_INSTALL_RPATH ON)
88-
- endif()
89-
+ #if("${CMAKE_BUILD_RPATH}" STREQUAL "")
90-
+ # set_property(TARGET ${name} PROPERTY BUILD_WITH_INSTALL_RPATH ON)
91-
+ #endif()
92-
93-
set_target_properties(${name} PROPERTIES
94-
INSTALL_RPATH "${_install_rpath}"
9582
diff --git a/cmake/modules/AddOCaml.cmake b/cmake/modules/AddOCaml.cmake
9683
index 2d9116b08a52..2dd7cad4ec66 100644
9784
--- a/cmake/modules/AddOCaml.cmake
@@ -122,7 +109,7 @@ index ef4cfa3acdb5..7478e157a7c2 100644
122109
"${LLVM_CONFIG_LIBRARY_DIR}"
123110
# FIXME: Should there be other entries here?
124111
diff --git a/tools/llvm-config/BuildVariables.inc.in b/tools/llvm-config/BuildVariables.inc.in
125-
index 370005cd8d7d..7e790bc52111 100644
112+
index e4e1d449bf4d..3aab6ea7bf8b 100644
126113
--- a/tools/llvm-config/BuildVariables.inc.in
127114
+++ b/tools/llvm-config/BuildVariables.inc.in
128115
@@ -23,6 +23,7 @@
@@ -134,10 +121,10 @@ index 370005cd8d7d..7e790bc52111 100644
134121
#define LLVM_INSTALL_PACKAGE_DIR "@LLVM_INSTALL_PACKAGE_DIR@"
135122
#define LLVM_TARGETS_BUILT "@LLVM_TARGETS_BUILT@"
136123
diff --git a/tools/llvm-config/llvm-config.cpp b/tools/llvm-config/llvm-config.cpp
137-
index d5b76b1bb6c1..1dbdb2a8f10d 100644
124+
index 49df8fdcb7f7..c7cb05b82821 100644
138125
--- a/tools/llvm-config/llvm-config.cpp
139126
+++ b/tools/llvm-config/llvm-config.cpp
140-
@@ -366,7 +366,11 @@ int main(int argc, char **argv) {
127+
@@ -365,7 +365,11 @@ int main(int argc, char **argv) {
141128
sys::fs::make_absolute(ActivePrefix, Path);
142129
ActiveBinDir = std::string(Path);
143130
}

overlays/patches/wasm/llvm/haskell-wasm-llvm-project.patch

Lines changed: 41 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/clang/lib/Driver/ToolChains/WebAssembly.cpp b/clang/lib/Driver/ToolChains/WebAssembly.cpp
2-
index bd25fd1a8933..b906bff5d5c7 100644
2+
index 5054868b5ff4..e4fcd949ff71 100644
33
--- a/clang/lib/Driver/ToolChains/WebAssembly.cpp
44
+++ b/clang/lib/Driver/ToolChains/WebAssembly.cpp
55
@@ -6,6 +6,8 @@
@@ -9,17 +9,17 @@ index bd25fd1a8933..b906bff5d5c7 100644
99
+#include <sstream>
1010
+
1111
#include "WebAssembly.h"
12-
#include "CommonArgs.h"
1312
#include "Gnu.h"
14-
@@ -19,6 +21,7 @@
13+
#include "clang/Config/config.h"
14+
@@ -17,6 +19,7 @@
1515
#include "llvm/Option/ArgList.h"
1616
#include "llvm/Support/FileSystem.h"
1717
#include "llvm/Support/Path.h"
1818
+#include "llvm/Support/Process.h"
1919
#include "llvm/Support/VirtualFileSystem.h"
2020

2121
using namespace clang::driver;
22-
@@ -168,21 +171,12 @@ void wasm::Linker::ConstructJob(Compilation &C, const JobAction &JA,
22+
@@ -179,21 +182,12 @@ void wasm::Linker::ConstructJob(Compilation &C, const JobAction &JA,
2323
CmdArgs.push_back("-o");
2424
CmdArgs.push_back(Output.getFilename());
2525

@@ -44,7 +44,7 @@ index bd25fd1a8933..b906bff5d5c7 100644
4444
}
4545

4646
if (!WasmOptPath.empty()) {
47-
@@ -193,29 +187,27 @@ void wasm::Linker::ConstructJob(Compilation &C, const JobAction &JA,
47+
@@ -204,29 +198,27 @@ void wasm::Linker::ConstructJob(Compilation &C, const JobAction &JA,
4848
ResponseFileSupport::AtFileCurCP(),
4949
Linker, CmdArgs, Inputs, Output));
5050

@@ -95,10 +95,10 @@ index bd25fd1a8933..b906bff5d5c7 100644
9595
}
9696

9797
diff --git a/compiler-rt/cmake/Modules/AddCompilerRT.cmake b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
98-
index c3e734f72392..282a321fd70b 100644
98+
index fb2aee8e42ee..a5de2dca1bc9 100644
9999
--- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake
100100
+++ b/compiler-rt/cmake/Modules/AddCompilerRT.cmake
101-
@@ -382,8 +382,8 @@ function(add_compiler_rt_runtime name type)
101+
@@ -390,8 +390,8 @@ function(add_compiler_rt_runtime name type)
102102
target_link_libraries(${libname} PRIVATE ${builtins_${libname}})
103103
endif()
104104
if(${type} STREQUAL "SHARED")
@@ -110,10 +110,10 @@ index c3e734f72392..282a321fd70b 100644
110110
if(WIN32 AND NOT CYGWIN AND NOT MINGW)
111111
set_target_properties(${libname} PROPERTIES IMPORT_PREFIX "")
112112
diff --git a/lld/wasm/InputChunks.cpp b/lld/wasm/InputChunks.cpp
113-
index 0e6c4e691be1..bfa438505d98 100644
113+
index 181221a77b10..c813e62e7b93 100644
114114
--- a/lld/wasm/InputChunks.cpp
115115
+++ b/lld/wasm/InputChunks.cpp
116-
@@ -361,12 +361,11 @@ uint64_t InputChunk::getVA(uint64_t offset) const {
116+
@@ -409,12 +409,11 @@ uint64_t InputChunk::getVA(uint64_t offset) const {
117117
// Generate code to apply relocations to the data section at runtime.
118118
// This is only called when generating shared libraries (PIC) where address are
119119
// not known at static link time.
@@ -127,7 +127,7 @@ index 0e6c4e691be1..bfa438505d98 100644
127127
unsigned opcode_ptr_const = is64 ? WASM_OPCODE_I64_CONST
128128
: WASM_OPCODE_I32_CONST;
129129
unsigned opcode_ptr_add = is64 ? WASM_OPCODE_I64_ADD
130-
@@ -385,6 +384,14 @@ bool InputChunk::generateRelocationCode(raw_ostream &os) const {
130+
@@ -433,6 +432,14 @@ bool InputChunk::generateRelocationCode(raw_ostream &os) const {
131131
if (!requiresRuntimeReloc)
132132
continue;
133133

@@ -142,7 +142,7 @@ index 0e6c4e691be1..bfa438505d98 100644
142142
LLVM_DEBUG(dbgs() << "gen reloc: type=" << relocTypeToString(rel.Type)
143143
<< " addend=" << rel.Addend << " index=" << rel.Index
144144
<< " output offset=" << offset << "\n");
145-
@@ -439,9 +446,7 @@ bool InputChunk::generateRelocationCode(raw_ostream &os) const {
145+
@@ -487,9 +494,7 @@ bool InputChunk::generateRelocationCode(raw_ostream &os) const {
146146
writeU8(os, opcode_reloc_store, "I32_STORE");
147147
writeUleb128(os, 2, "align");
148148
writeUleb128(os, 0, "offset");
@@ -153,23 +153,23 @@ index 0e6c4e691be1..bfa438505d98 100644
153153

154154
// Split WASM_SEG_FLAG_STRINGS section. Such a section is a sequence of
155155
diff --git a/lld/wasm/InputChunks.h b/lld/wasm/InputChunks.h
156-
index f545449e1246..d231382a5f5e 100644
156+
index 1fe78d76631f..2c721f5f92e8 100644
157157
--- a/lld/wasm/InputChunks.h
158158
+++ b/lld/wasm/InputChunks.h
159-
@@ -78,7 +78,7 @@ public:
160-
159+
@@ -79,7 +79,7 @@ public:
161160
size_t getNumRelocations() const { return relocations.size(); }
161+
size_t getNumLiveRelocations() const;
162162
void writeRelocations(llvm::raw_ostream &os) const;
163163
- bool generateRelocationCode(raw_ostream &os) const;
164164
+ void generateRelocationCode(std::vector<std::string> &funcs) const;
165165

166166
bool isTLS() const { return flags & llvm::wasm::WASM_SEG_FLAG_TLS; }
167167
bool isRetained() const { return flags & llvm::wasm::WASM_SEG_FLAG_RETAIN; }
168168
diff --git a/lld/wasm/SyntheticSections.cpp b/lld/wasm/SyntheticSections.cpp
169-
index 0e2aa57e9048..e5df7d8c0be0 100644
169+
index e1192706ea91..1b97039b1f1f 100644
170170
--- a/lld/wasm/SyntheticSections.cpp
171171
+++ b/lld/wasm/SyntheticSections.cpp
172-
@@ -299,6 +299,8 @@ void FunctionSection::writeBody() {
172+
@@ -312,6 +312,8 @@ void FunctionSection::writeBody() {
173173
void FunctionSection::addFunction(InputFunction *func) {
174174
if (!func->live)
175175
return;
@@ -179,10 +179,10 @@ index 0e2aa57e9048..e5df7d8c0be0 100644
179179
out.importSec->getNumImportedFunctions() + inputFunctions.size();
180180
inputFunctions.emplace_back(func);
181181
diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp
182-
index 2bf4b370a7db..19fca2616c7a 100644
182+
index b704677d36c9..ac9eab2b9dd5 100644
183183
--- a/lld/wasm/Writer.cpp
184184
+++ b/lld/wasm/Writer.cpp
185-
@@ -1452,20 +1452,21 @@ void Writer::createStartFunction() {
185+
@@ -1455,20 +1455,21 @@ void Writer::createStartFunction() {
186186
void Writer::createApplyDataRelocationsFunction() {
187187
LLVM_DEBUG(dbgs() << "createApplyDataRelocationsFunction\n");
188188
// First write the body's contents to a string.
@@ -213,7 +213,7 @@ index 2bf4b370a7db..19fca2616c7a 100644
213213
writeU8(os, WASM_OPCODE_END, "END");
214214
}
215215

216-
@@ -1478,24 +1479,67 @@ void Writer::createApplyDataRelocationsFunction() {
216+
@@ -1481,24 +1482,67 @@ void Writer::createApplyDataRelocationsFunction() {
217217
make<SyntheticFunction>(nullSignature, "__wasm_apply_data_relocs"));
218218
def->markLive();
219219

@@ -288,10 +288,10 @@ index 2bf4b370a7db..19fca2616c7a 100644
288288

289289
// Similar to createApplyDataRelocationsFunction but generates relocation code
290290
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
291-
index d3e9377c8d2f..50a34184919a 100644
291+
index 83772ed8d2b1..0a7360d9357a 100644
292292
--- a/llvm/cmake/modules/AddLLVM.cmake
293293
+++ b/llvm/cmake/modules/AddLLVM.cmake
294-
@@ -2524,8 +2524,7 @@ function(llvm_setup_rpath name)
294+
@@ -2547,8 +2547,7 @@ function(llvm_setup_rpath name)
295295
# FIXME: update this when there is better solution.
296296
set(_install_rpath "${LLVM_LIBRARY_OUTPUT_INTDIR}" "${CMAKE_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
297297
elseif(UNIX)
@@ -301,7 +301,7 @@ index d3e9377c8d2f..50a34184919a 100644
301301
if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
302302
set_property(TARGET ${name} APPEND_STRING PROPERTY
303303
LINK_FLAGS " -Wl,-z,origin ")
304-
@@ -2539,16 +2538,9 @@ function(llvm_setup_rpath name)
304+
@@ -2562,16 +2561,9 @@ function(llvm_setup_rpath name)
305305
return()
306306
endif()
307307

@@ -320,3 +320,22 @@ index d3e9377c8d2f..50a34184919a 100644
320320
endif()
321321

322322
set_target_properties(${name} PROPERTIES
323+
diff --git a/llvm/lib/MC/MCParser/WasmAsmParser.cpp b/llvm/lib/MC/MCParser/WasmAsmParser.cpp
324+
index 1f824b80bcd4..1025d3ee3026 100644
325+
--- a/llvm/lib/MC/MCParser/WasmAsmParser.cpp
326+
+++ b/llvm/lib/MC/MCParser/WasmAsmParser.cpp
327+
@@ -228,7 +228,13 @@ public:
328+
if (WasmSym->isFunction()) {
329+
// Ignore .size directives for function symbols. They get their size
330+
// set automatically based on their content.
331+
- Warning(Loc, ".size directive ignored for function symbols");
332+
+ //
333+
+ // Upstream LLVM treats this as a warning, we turn this into an
334+
+ // error since it almost certainly signals severely malformed
335+
+ // assembly due to miscompilation, and data/function symbol kind
336+
+ // confusion is not always caught at link-time and might
337+
+ // manifest as wasm runtime crashes :/
338+
+ Error(Loc, ".size directive ignored for function symbols");
339+
} else {
340+
getStreamer().emitELFSize(Sym, Expr);
341+
}

overlays/wasm.nix

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
final: prev: prev.lib.optionalAttrs prev.stdenv.targetPlatform.isWasm {
2-
llvmPackages = final.llvmPackages_20.override {
2+
llvmPackages = final.llvmPackages_21.override {
33
patchesFn = p: p // { "llvm/gnu-install-dirs.patch" = [{path = ./patches/wasm;}]; };
44
monorepoSrc =
55
final.stdenv.mkDerivation {
66
pname = "llvm-source";
7-
version = final.llvmPackages_20.llvm.version + "-haskell";
8-
src = final.llvmPackages_20.llvm.monorepoSrc;
7+
version = final.llvmPackages_21.llvm.version + "-haskell";
8+
src = final.llvmPackages_21.llvm.monorepoSrc;
99
patches = ./patches/wasm/llvm/haskell-wasm-llvm-project.patch;
1010
buildPhase = "true";
1111
installPhase = ''

0 commit comments

Comments
 (0)