
This fixes a bug with string merging with string symbols that contain NULLs, as is the case in the `merge-string.s` test. The bug only showed when we run with `--relocatable` and then try read the resulting object back in. In this case we would end up with string symbols that extend past the end of the segment in which they live. The problem comes from the fact that sections which are flagged as string mergable assume that all strings are NULL terminated. The merging algorithm will drop trailing chars that follow a NULL since they are essentially unreachable. However, the "size" attribute (in the symbol table) of such a truncated symbol is not updated resulting a symbol size that can overlap the end of the segment. I verified that this can happen in ELF too given the right conditions and the its harmless enough. In practice Strings that contain embedded null should not be part of a mergable section. Differential Revision: https://reviews.llvm.org/D102281
102 lines
3.6 KiB
ArmAsm
102 lines
3.6 KiB
ArmAsm
// RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %s -o %t.o
|
|
// RUN: wasm-ld -O1 %t.o -o %t.wasm --no-gc-sections --no-entry
|
|
// RUN: obj2yaml %t.wasm | FileCheck %s --check-prefixes=COMMON,MERGE
|
|
|
|
// Check that the default is the same as -O1 (since we default to -O1)
|
|
// RUN: wasm-ld %t.o -o %t.wasm --no-gc-sections --no-entry
|
|
// RUN: obj2yaml %t.wasm | FileCheck %s --check-prefixes=COMMON,MERGE
|
|
|
|
// Check that -O0 disables merging
|
|
// RUN: wasm-ld -O0 %t.o -o %t2.wasm --no-gc-sections --no-entry
|
|
// RUN: obj2yaml %t2.wasm | FileCheck --check-prefixes=COMMON,NOMERGE %s
|
|
|
|
// Check relocatable
|
|
// RUN: wasm-ld -r %t.o -o %t2.o
|
|
// RUN: obj2yaml %t2.o | FileCheck --check-prefixes=RELOC %s
|
|
|
|
.section .rodata1,"S",@
|
|
.asciz "abc"
|
|
foo:
|
|
.ascii "a"
|
|
.size foo, 1
|
|
bar:
|
|
.asciz "bc"
|
|
.asciz "bc"
|
|
.size bar, 6
|
|
|
|
.section .rodata_relocs,"",@
|
|
negative_addend:
|
|
.int32 foo-10
|
|
.size negative_addend, 4
|
|
|
|
.globl foo
|
|
.globl bar
|
|
.export_name foo, foo
|
|
.export_name bar, bar
|
|
|
|
// COMMON: - Type: GLOBAL
|
|
// COMMON-NEXT: Globals:
|
|
// COMMON-NEXT: - Index: 0
|
|
// COMMON-NEXT: Type: I32
|
|
// COMMON-NEXT: Mutable: true
|
|
// COMMON-NEXT: InitExpr:
|
|
// COMMON-NEXT: Opcode: I32_CONST
|
|
// COMMON-NEXT: Value: 66576
|
|
// COMMON-NEXT: - Index: 1
|
|
// COMMON-NEXT: Type: I32
|
|
// COMMON-NEXT: Mutable: false
|
|
// COMMON-NEXT: InitExpr:
|
|
// COMMON-NEXT: Opcode: I32_CONST
|
|
// MERGE-NEXT: Value: 1024
|
|
// NOMERGE-NEXT: Value: 1028
|
|
// COMMON-NEXT: - Index: 2
|
|
// COMMON-NEXT: Type: I32
|
|
// COMMON-NEXT: Mutable: false
|
|
// COMMON-NEXT: InitExpr:
|
|
// COMMON-NEXT: Opcode: I32_CONST
|
|
// MERGE-NEXT: Value: 1025
|
|
// NOMERGE-NEXT: Value: 1029
|
|
// COMMON-NEXT: - Type: EXPORT
|
|
// COMMON-NEXT: Exports:
|
|
// COMMON-NEXT: - Name: memory
|
|
// COMMON-NEXT: Kind: MEMORY
|
|
// COMMON-NEXT: Index: 0
|
|
// COMMON-NEXT: - Name: foo
|
|
// COMMON-NEXT: Kind: GLOBAL
|
|
// COMMON-NEXT: Index: 1
|
|
// COMMON-NEXT: - Name: bar
|
|
// COMMON-NEXT: Kind: GLOBAL
|
|
// COMMON-NEXT: Index: 2
|
|
|
|
//
|
|
// COMMON: - Type: DATA
|
|
// COMMON-NEXT: Segments:
|
|
// COMMON-NEXT: - SectionOffset: 7
|
|
// COMMON-NEXT: InitFlags: 0
|
|
// COMMON-NEXT: Offset:
|
|
// COMMON-NEXT: Opcode: I32_CONST
|
|
// COMMON-NEXT: Value: 1024
|
|
// MERGE-NEXT: Content: '61626300'
|
|
// NOMERGE-NEXT: Content: '6162630061626300626300'
|
|
|
|
|
|
// RELOC: - Type: DATA
|
|
// RELOC-NEXT: Relocations:
|
|
// RELOC-NEXT: - Type: R_WASM_MEMORY_ADDR_I32
|
|
// RELOC-NEXT: Index: 0
|
|
// RELOC-NEXT: Offset: 0xF
|
|
// RELOC-NEXT: Addend: -10
|
|
// RELOC-NEXT: Segments:
|
|
// RELOC-NEXT: - SectionOffset: 6
|
|
// RELOC-NEXT: InitFlags: 0
|
|
// RELOC-NEXT: Offset:
|
|
// RELOC-NEXT: Opcode: I32_CONST
|
|
// RELOC-NEXT: Value: 0
|
|
// RELOC-NEXT: Content: '61626300'
|
|
// RELOC-NEXT: - SectionOffset: 15
|
|
// RELOC-NEXT: InitFlags: 0
|
|
// RELOC-NEXT: Offset:
|
|
// RELOC-NEXT: Opcode: I32_CONST
|
|
// RELOC-NEXT: Value: 4
|
|
// RELOC-NEXT: Content: F6FFFFFF
|