
Fixes #85578, a use-after-free caused by some `MCSymbolWasm` data being freed too early. Previously, `WebAssemblyAsmParser` owned the data that is moved to `MCContext` by this PR, which caused problems when handling module ASM, because the ASM parser was destroyed after parsing the module ASM, but the symbols persisted. The added test passes locally with an LLVM build with AddressSanitizer enabled. Implementation notes: * I've called the added method <code>allocate<b><i>Generic</i></b>String</code> and added the second paragraph of its documentation to maybe guide people a bit on when to use this method (based on my (limited) understanding of the `MCContext` class). We could also just call it `allocateString` and remove that second paragraph. * The added `createWasmSignature` method does not support taking the return and parameter types as arguments: Specifying them afterwards is barely any longer and prevents them from being accidentally specified in the wrong order. * This removes a _"TODO: Do the uniquing of Signatures here instead of ObjectFileWriter?"_ since the field it's attached to is also removed. Let me know if you think that TODO should be preserved somewhere.
26 lines
878 B
LLVM
26 lines
878 B
LLVM
; Ensure that symbols from module ASM are properly exported.
|
|
;
|
|
; Regression test for https://github.com/llvm/llvm-project/issues/85578.
|
|
|
|
; RUN: llc -mtriple=wasm32-unknown-unknown -filetype=obj %s -o - | obj2yaml | FileCheck %s
|
|
|
|
module asm "test_func:"
|
|
module asm " .globl test_func"
|
|
module asm " .functype test_func (i32) -> (i32)"
|
|
module asm " .export_name test_func, test_export"
|
|
module asm " end_function"
|
|
|
|
; CHECK: - Type: TYPE
|
|
; CHECK-NEXT: Signatures:
|
|
; CHECK-NEXT: - Index: 0
|
|
; CHECK-NEXT: ParamTypes:
|
|
; CHECK-NEXT: - I32
|
|
; CHECK-NEXT: ReturnTypes:
|
|
; CHECK-NEXT: - I32
|
|
|
|
; CHECK: - Type: EXPORT
|
|
; CHECK-NEXT: Exports:
|
|
; CHECK-NEXT: - Name: test_export
|
|
; CHECK-NEXT: Kind: FUNCTION
|
|
; CHECK-NEXT: Index: 0
|