Skip to content

Conversation

kateinoigakukun
Copy link
Member

@kateinoigakukun kateinoigakukun commented Sep 15, 2025

WebAssembly does not have a reserved address space by default, so we need to explicitly reserve low addresses for extra inhabitants for enum types with pointer payloads. #39300 added --global-base to reserve low data addresses, but we also need to reserve low function addresses with --table-base for function pointers because WebAssembly uses a separate address space for function pointers.

Corresponding new-driver PR: swiftlang/swift-driver#1987

Minimum problematic code
# Expected
step 1
step 2
END OF ENTRY
Context deinit
# Actual
step 1
Context deinit
step 2
END OF ENTRY
@inline(never)
func blackhole<T>(_ value: T) {}

final class Context {
    func doSomething() {
    }
    deinit {
        print("Context deinit")
    }
}

final class _GenericStorage<Value> {
    let value: Value?

    init(value: Value) {
        self.value = value
    }

    func unwrapAndCopy() {
        if let value = value {
            blackhole(value)
        }
    }
}

func main() {
    let childNode = _GenericStorage(
        value: Context().doSomething,
    )
    print("step 1")
    childNode.unwrapAndCopy()
    print("step 2")
    childNode.unwrapAndCopy()
    print("END OF ENTRY")
}

main()

…resses

WebAssembly does not have a reserved address space by default, so we
need to explicitly reserve low addresses for extra inhabitants for
enum types with pointer payloads. swiftlang#39300
added `--global-base` to reserve low data addresses, but we also need
to reserve low function addresses with `--table-base` for function
pointers because WebAssembly uses a separate address space for function
pointers.
@kateinoigakukun kateinoigakukun requested review from a team and artemcm as code owners September 15, 2025 06:34
@kateinoigakukun
Copy link
Member Author

@swift-ci smoke test

@MaxDesiatov
Copy link
Contributor

@swift-ci smoke test macos

@MaxDesiatov MaxDesiatov added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. legacy driver Area → compiler: the integrated C++ legacy driver. Succeeded by the swift-driver project WebAssembly Platform: WebAssembly labels Sep 15, 2025
@MaxDesiatov
Copy link
Contributor

@swift-ci smoke test

@kateinoigakukun kateinoigakukun merged commit 2b6ea81 into swiftlang:main Sep 15, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. legacy driver Area → compiler: the integrated C++ legacy driver. Succeeded by the swift-driver project memory corruption WebAssembly Platform: WebAssembly

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants