1
1
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
3
3
--- a/clang/lib/Driver/ToolChains/WebAssembly.cpp
4
4
+++ b/clang/lib/Driver/ToolChains/WebAssembly.cpp
5
5
@@ -6,6 +6,8 @@
@@ -9,17 +9,17 @@ index bd25fd1a8933..b906bff5d5c7 100644
9
9
+ #include <sstream>
10
10
+
11
11
#include "WebAssembly.h"
12
- #include "CommonArgs.h"
13
12
#include "Gnu.h"
14
- @@ -19,6 +21,7 @@
13
+ #include "clang/Config/config.h"
14
+ @@ -17,6 +19,7 @@
15
15
#include "llvm/Option/ArgList.h"
16
16
#include "llvm/Support/FileSystem.h"
17
17
#include "llvm/Support/Path.h"
18
18
+ #include "llvm/Support/Process.h"
19
19
#include "llvm/Support/VirtualFileSystem.h"
20
20
21
21
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,
23
23
CmdArgs.push_back("-o");
24
24
CmdArgs.push_back(Output.getFilename());
25
25
@@ -44,7 +44,7 @@ index bd25fd1a8933..b906bff5d5c7 100644
44
44
}
45
45
46
46
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,
48
48
ResponseFileSupport::AtFileCurCP(),
49
49
Linker, CmdArgs, Inputs, Output));
50
50
@@ -95,10 +95,10 @@ index bd25fd1a8933..b906bff5d5c7 100644
95
95
}
96
96
97
97
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
99
99
--- a/compiler-rt/cmake/Modules/AddCompilerRT.cmake
100
100
+++ 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)
102
102
target_link_libraries(${libname} PRIVATE ${builtins_${libname}})
103
103
endif()
104
104
if(${type} STREQUAL "SHARED")
@@ -110,10 +110,10 @@ index c3e734f72392..282a321fd70b 100644
110
110
if(WIN32 AND NOT CYGWIN AND NOT MINGW)
111
111
set_target_properties(${libname} PROPERTIES IMPORT_PREFIX "")
112
112
diff --git a/lld/wasm/InputChunks.cpp b/lld/wasm/InputChunks.cpp
113
- index 0e6c4e691be1..bfa438505d98 100644
113
+ index 181221a77b10..c813e62e7b93 100644
114
114
--- a/lld/wasm/InputChunks.cpp
115
115
+++ 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 {
117
117
// Generate code to apply relocations to the data section at runtime.
118
118
// This is only called when generating shared libraries (PIC) where address are
119
119
// not known at static link time.
@@ -127,7 +127,7 @@ index 0e6c4e691be1..bfa438505d98 100644
127
127
unsigned opcode_ptr_const = is64 ? WASM_OPCODE_I64_CONST
128
128
: WASM_OPCODE_I32_CONST;
129
129
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 {
131
131
if (!requiresRuntimeReloc)
132
132
continue;
133
133
@@ -142,7 +142,7 @@ index 0e6c4e691be1..bfa438505d98 100644
142
142
LLVM_DEBUG(dbgs() << "gen reloc: type=" << relocTypeToString(rel.Type)
143
143
<< " addend=" << rel.Addend << " index=" << rel.Index
144
144
<< " 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 {
146
146
writeU8(os, opcode_reloc_store, "I32_STORE");
147
147
writeUleb128(os, 2, "align");
148
148
writeUleb128(os, 0, "offset");
@@ -153,23 +153,23 @@ index 0e6c4e691be1..bfa438505d98 100644
153
153
154
154
// Split WASM_SEG_FLAG_STRINGS section. Such a section is a sequence of
155
155
diff --git a/lld/wasm/InputChunks.h b/lld/wasm/InputChunks.h
156
- index f545449e1246..d231382a5f5e 100644
156
+ index 1fe78d76631f..2c721f5f92e8 100644
157
157
--- a/lld/wasm/InputChunks.h
158
158
+++ b/lld/wasm/InputChunks.h
159
- @@ -78,7 +78,7 @@ public:
160
-
159
+ @@ -79,7 +79,7 @@ public:
161
160
size_t getNumRelocations() const { return relocations.size(); }
161
+ size_t getNumLiveRelocations() const;
162
162
void writeRelocations(llvm::raw_ostream &os) const;
163
163
- bool generateRelocationCode(raw_ostream &os) const;
164
164
+ void generateRelocationCode(std::vector<std::string> &funcs) const;
165
165
166
166
bool isTLS() const { return flags & llvm::wasm::WASM_SEG_FLAG_TLS; }
167
167
bool isRetained() const { return flags & llvm::wasm::WASM_SEG_FLAG_RETAIN; }
168
168
diff --git a/lld/wasm/SyntheticSections.cpp b/lld/wasm/SyntheticSections.cpp
169
- index 0e2aa57e9048..e5df7d8c0be0 100644
169
+ index e1192706ea91..1b97039b1f1f 100644
170
170
--- a/lld/wasm/SyntheticSections.cpp
171
171
+++ b/lld/wasm/SyntheticSections.cpp
172
- @@ -299 ,6 +299 ,8 @@ void FunctionSection::writeBody() {
172
+ @@ -312 ,6 +312 ,8 @@ void FunctionSection::writeBody() {
173
173
void FunctionSection::addFunction(InputFunction *func) {
174
174
if (!func->live)
175
175
return;
@@ -179,10 +179,10 @@ index 0e2aa57e9048..e5df7d8c0be0 100644
179
179
out.importSec->getNumImportedFunctions() + inputFunctions.size();
180
180
inputFunctions.emplace_back(func);
181
181
diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp
182
- index 2bf4b370a7db..19fca2616c7a 100644
182
+ index b704677d36c9..ac9eab2b9dd5 100644
183
183
--- a/lld/wasm/Writer.cpp
184
184
+++ b/lld/wasm/Writer.cpp
185
- @@ -1452 ,20 +1452 ,21 @@ void Writer::createStartFunction() {
185
+ @@ -1455 ,20 +1455 ,21 @@ void Writer::createStartFunction() {
186
186
void Writer::createApplyDataRelocationsFunction() {
187
187
LLVM_DEBUG(dbgs() << "createApplyDataRelocationsFunction\n");
188
188
// First write the body's contents to a string.
@@ -213,7 +213,7 @@ index 2bf4b370a7db..19fca2616c7a 100644
213
213
writeU8(os, WASM_OPCODE_END, "END");
214
214
}
215
215
216
- @@ -1478 ,24 +1479 ,67 @@ void Writer::createApplyDataRelocationsFunction() {
216
+ @@ -1481 ,24 +1482 ,67 @@ void Writer::createApplyDataRelocationsFunction() {
217
217
make<SyntheticFunction>(nullSignature, "__wasm_apply_data_relocs"));
218
218
def->markLive();
219
219
@@ -288,10 +288,10 @@ index 2bf4b370a7db..19fca2616c7a 100644
288
288
289
289
// Similar to createApplyDataRelocationsFunction but generates relocation code
290
290
diff --git a/llvm/cmake/modules/AddLLVM.cmake b/llvm/cmake/modules/AddLLVM.cmake
291
- index d3e9377c8d2f..50a34184919a 100644
291
+ index 83772ed8d2b1..0a7360d9357a 100644
292
292
--- a/llvm/cmake/modules/AddLLVM.cmake
293
293
+++ 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)
295
295
# FIXME: update this when there is better solution.
296
296
set(_install_rpath "${LLVM_LIBRARY_OUTPUT_INTDIR}" "${CMAKE_INSTALL_PREFIX}/lib${LLVM_LIBDIR_SUFFIX}" ${extra_libdir})
297
297
elseif(UNIX)
@@ -301,7 +301,7 @@ index d3e9377c8d2f..50a34184919a 100644
301
301
if(${CMAKE_SYSTEM_NAME} MATCHES "(FreeBSD|DragonFly)")
302
302
set_property(TARGET ${name} APPEND_STRING PROPERTY
303
303
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)
305
305
return()
306
306
endif()
307
307
@@ -320,3 +320,22 @@ index d3e9377c8d2f..50a34184919a 100644
320
320
endif()
321
321
322
322
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