11diff --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
9797diff --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 "")
112112diff --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
155155diff --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; }
168168diff --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);
181181diff --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
290290diff --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+ }
0 commit comments