mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-11-30 17:21:10 +00:00
[lld][WebAssembly] Always include bss segments when --emit-relocs
is used
If we don't do this then we end up with symbols that refer to non-existent segments. Differential Revision: https://reviews.llvm.org/D158025
This commit is contained in:
parent
aa2c701b5d
commit
cb5bc75680
@ -1,39 +0,0 @@
|
||||
; RUN: llc -filetype=obj %s -o %t.o
|
||||
; RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %p/Inputs/ret32.s -o %t.ret32.o
|
||||
; RUN: wasm-ld --emit-relocs -o %t.wasm %t.o %t.ret32.o
|
||||
; RUN: obj2yaml %t.wasm | FileCheck %s
|
||||
|
||||
target triple = "wasm32-unknown-unknown"
|
||||
|
||||
declare i32 @ret32(float)
|
||||
|
||||
define void @unused_function() {
|
||||
ret void
|
||||
}
|
||||
|
||||
define hidden void @_start() local_unnamed_addr #0 {
|
||||
entry:
|
||||
call i32 @ret32(float 0.0)
|
||||
ret void
|
||||
}
|
||||
|
||||
; CHECK: - Type: CODE
|
||||
; CHECK-NEXT: Relocations:
|
||||
; CHECK-NEXT: - Type: R_WASM_FUNCTION_INDEX_LEB
|
||||
; CHECK-NEXT: Index: 1
|
||||
; CHECK-NEXT: Offset: 0x9
|
||||
|
||||
; CHECK: - Type: CUSTOM
|
||||
; CHECK-NEXT: Name: linking
|
||||
; CHECK-NEXT: Version: 2
|
||||
; CHECK-NEXT: SymbolTable:
|
||||
; CHECK-NEXT: - Index: 0
|
||||
; CHECK-NEXT: Kind: FUNCTION
|
||||
; CHECK-NEXT: Name: _start
|
||||
; CHECK-NEXT: Flags: [ ]
|
||||
; CHECK-NEXT: Function: 0
|
||||
; CHECK-NEXT: - Index: 1
|
||||
; CHECK-NEXT: Kind: FUNCTION
|
||||
; CHECK-NEXT: Name: ret32
|
||||
; CHECK-NEXT: Flags: [ VISIBILITY_HIDDEN ]
|
||||
; CHECK-NEXT: Function: 1
|
56
lld/test/wasm/emit-relocs.s
Normal file
56
lld/test/wasm/emit-relocs.s
Normal file
@ -0,0 +1,56 @@
|
||||
# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %s -o %t.o
|
||||
# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %p/Inputs/ret32.s -o %t.ret32.o
|
||||
# RUN: wasm-ld --emit-relocs -o %t.wasm %t.o %t.ret32.o
|
||||
# RUN: obj2yaml %t.wasm | FileCheck %s
|
||||
|
||||
.functype ret32 (f32) -> (i32)
|
||||
|
||||
unused_function:
|
||||
.functype unused_function () -> ()
|
||||
end_function
|
||||
|
||||
.globl _start
|
||||
_start:
|
||||
.functype _start () -> ()
|
||||
f32.const 0.0
|
||||
call ret32
|
||||
drop
|
||||
i32.const foo
|
||||
drop
|
||||
end_function
|
||||
|
||||
.section .bss.data,"",@
|
||||
.p2align 2
|
||||
foo:
|
||||
.int32 0
|
||||
.size foo, 4
|
||||
|
||||
# CHECK: - Type: CODE
|
||||
# CHECK-NEXT: Relocations:
|
||||
# CHECK-NEXT: - Type: R_WASM_FUNCTION_INDEX_LEB
|
||||
# CHECK-NEXT: Index: 1
|
||||
# CHECK-NEXT: Offset: 0x9
|
||||
|
||||
# CHECK: - Type: DATA
|
||||
# CHECK-NEXT: Segments:
|
||||
# CHECK-NEXT: - SectionOffset: 7
|
||||
# CHECK-NEXT: InitFlags: 0
|
||||
# CHECK-NEXT: Offset:
|
||||
# CHECK-NEXT: Opcode: I32_CONST
|
||||
# CHECK-NEXT: Value: 1024
|
||||
# CHECK-NEXT: Content: '00000000'
|
||||
|
||||
# CHECK: - Type: CUSTOM
|
||||
# CHECK-NEXT: Name: linking
|
||||
# CHECK-NEXT: Version: 2
|
||||
# CHECK-NEXT: SymbolTable:
|
||||
# CHECK-NEXT: - Index: 0
|
||||
# CHECK-NEXT: Kind: FUNCTION
|
||||
# CHECK-NEXT: Name: _start
|
||||
# CHECK-NEXT: Flags: [ ]
|
||||
# CHECK-NEXT: Function: 0
|
||||
# CHECK-NEXT: - Index: 1
|
||||
# CHECK-NEXT: Kind: FUNCTION
|
||||
# CHECK-NEXT: Name: ret32
|
||||
# CHECK-NEXT: Flags: [ VISIBILITY_HIDDEN ]
|
||||
# CHECK-NEXT: Function: 1
|
@ -676,7 +676,10 @@ done:
|
||||
// memory is not being imported then we can assume its zero initialized.
|
||||
// In the case the memory is imported, and we can use the memory.fill
|
||||
// instruction, then we can also avoid including the segments.
|
||||
if (config->memoryImport.has_value() && !allowed.count("bulk-memory"))
|
||||
// Finally, if we are emitting relocations, they may refer to locations within
|
||||
// the bss segments, so these segments need to exist in the binary.
|
||||
if (config->emitRelocs ||
|
||||
(config->memoryImport.has_value() && !allowed.count("bulk-memory")))
|
||||
config->emitBssSegments = true;
|
||||
|
||||
if (allowed.count("extended-const"))
|
||||
|
Loading…
Reference in New Issue
Block a user