Skip to content

Commit 2b6ea81

Browse files
Merge pull request #84285 from kateinoigakukun/yt/fix-tagged-funcptr
[Legacy Driver][wasm] Pass `--table-base` to reserve low function addresses
2 parents e8a9286 + 5431bb1 commit 2b6ea81

File tree

4 files changed

+55
-5
lines changed

4 files changed

+55
-5
lines changed

lib/Driver/WebAssemblyToolChains.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,12 +188,16 @@ toolchains::WebAssembly::constructInvocation(const DynamicLinkJobAction &job,
188188

189189
// WebAssembly doesn't reserve low addresses But without "extra inhabitants"
190190
// of the pointer representation, runtime performance and memory footprint are
191-
// worse. So assume that compiler driver uses wasm-ld and --global-base=1024
192-
// to reserve low 1KB.
191+
// worse. So assume that compiler driver uses wasm-ld and --global-base=4096
192+
// to reserve low 4KB.
193193
Arguments.push_back("-Xlinker");
194194
Arguments.push_back(context.Args.MakeArgString(
195195
Twine("--global-base=") +
196196
std::to_string(SWIFT_ABI_WASM32_LEAST_VALID_POINTER)));
197+
Arguments.push_back("-Xlinker");
198+
Arguments.push_back(context.Args.MakeArgString(
199+
Twine("--table-base=") +
200+
std::to_string(SWIFT_ABI_WASM32_LEAST_VALID_POINTER)));
197201

198202
// These custom arguments should be right before the object file at the end.
199203
context.Args.AddAllArgs(Arguments, options::OPT_linker_option_Group);

stdlib/public/SwiftShims/swift/shims/System.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,8 @@
220220

221221
// WebAssembly doesn't reserve low addresses. But without "extra inhabitants" of
222222
// the pointer representation, runtime performance and memory footprint are
223-
// worse. So assume that compiler driver uses wasm-ld and --global-base=1024 to
224-
// reserve low 1KB.
223+
// worse. So assume that compiler driver uses wasm-ld and --global-base=4096 to
224+
// reserve low 4KB.
225225
#define SWIFT_ABI_WASM32_LEAST_VALID_POINTER 4096
226226

227227
#endif // SWIFT_STDLIB_SHIMS_ABI_SYSTEM_H

test/Interpreter/enum.swift

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -745,3 +745,45 @@ func reproduction<T: Init>(_ x: Int, _ y: Int, _ t: T) {
745745

746746
// CHECK: there is no byte
747747
reproduction(2, 3, TrailingByte())
748+
749+
do {
750+
// regression test for https://github.com/swiftlang/swift-driver/pull/1987
751+
@inline(never) func blackhole<T>(_ t: T) { }
752+
753+
final class Context {
754+
func doSomething() {}
755+
deinit {
756+
print("Context deinit")
757+
}
758+
}
759+
760+
enum MyOptional<Value> {
761+
case some(Value)
762+
case none
763+
}
764+
765+
final class _GenericStorage<Value> {
766+
let value: MyOptional<Value>
767+
768+
init(value: Value) {
769+
self.value = .some(value)
770+
}
771+
772+
func unwrapAndCopy() {
773+
if case .some(let value) = value {
774+
blackhole(value)
775+
}
776+
}
777+
}
778+
779+
let test = _GenericStorage(
780+
value: Context().doSomething,
781+
)
782+
// CHECK: test.unwrapAndCopy
783+
print("test.unwrapAndCopy")
784+
test.unwrapAndCopy()
785+
// CHECK: test.unwrapAndCopy
786+
print("test.unwrapAndCopy")
787+
test.unwrapAndCopy()
788+
// CHECK: Context deinit
789+
}

utils/swift_build_support/swift_build_support/products/wasmstdlib.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,11 @@ def _build_stdlib(self, host_target, target_triple, llvm_cmake_dir):
191191
# Test configuration
192192
self.cmake_options.define('SWIFT_INCLUDE_TESTS:BOOL', 'TRUE')
193193
self.cmake_options.define('SWIFT_ENABLE_SOURCEKIT_TESTS:BOOL', 'FALSE')
194-
lit_test_paths = ['IRGen', 'stdlib', 'Concurrency/Runtime', 'embedded']
194+
lit_test_paths = [
195+
'IRGen', 'stdlib', 'Concurrency/Runtime', 'embedded',
196+
# TODO(katei): Enable all interpreter tests
197+
'Interpreter/enum.swift',
198+
]
195199
lit_test_paths = [os.path.join(
196200
self.build_dir, 'test-wasi-wasm32', path) for path in lit_test_paths]
197201
self.cmake_options.define('SWIFT_LIT_TEST_PATHS:STRING',

0 commit comments

Comments
 (0)