-
Notifications
You must be signed in to change notification settings - Fork 11.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[lld][WebAssembly] Do not merge comdat data segments
When running in relocatable mode any input data segments that are part of a comdat group should not be merged with other segments of the same name. This is because the final linker needs to keep the separate so they can be included/excluded individually. Often this is not a problem since normally only one section with a given name `foo` ends up in the output object file. However, the problem occurs when one input contains `foo` which part of a comdat and another object contains a local symbol `foo` we were attempting to merge them. This behaviour matches (I believe) that of the ELF linker. See `LinkerScript.cpp:addInputSec`. Fixes: emscripten-core/emscripten#9726 Differential Revision: https://reviews.llvm.org/D101703
- Loading branch information
Showing
4 changed files
with
80 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.globl foo | ||
.section .data.foo,"G",@,foo,comdat | ||
foo: | ||
.int32 42 | ||
.int32 43 | ||
.size foo, 8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
# RUN: llvm-mc -triple=wasm32 -filetype=obj %p/Inputs/comdat-data.s -o %t1.o | ||
# RUN: llvm-mc -triple=wasm32 -filetype=obj %s -o %t.o | ||
# RUN: wasm-ld --relocatable -o %t.wasm %t.o %t1.o | ||
# RUN: obj2yaml %t.wasm | FileCheck %s | ||
|
||
|
||
.globl _start | ||
.type _start,@function | ||
_start: | ||
.functype _start () -> () | ||
i32.load foo | ||
end_function | ||
|
||
|
||
.section .data.foo,"",@ | ||
foo: | ||
.int32 42 | ||
.size foo, 4 | ||
|
||
# Verify that .data.foo in this file is not merged with comdat .data.foo | ||
# section in Inputs/comdat-data.s. | ||
|
||
# CHECK: - Type: DATA | ||
# CHECK-NEXT: Segments: | ||
# CHECK-NEXT: - SectionOffset: 6 | ||
# CHECK-NEXT: InitFlags: 0 | ||
# CHECK-NEXT: Offset: | ||
# CHECK-NEXT: Opcode: I32_CONST | ||
# CHECK-NEXT: Value: 0 | ||
# CHECK-NEXT: Content: 2A000000 | ||
# CHECK-NEXT: - SectionOffset: 15 | ||
# CHECK-NEXT: InitFlags: 0 | ||
# CHECK-NEXT: Offset: | ||
# CHECK-NEXT: Opcode: I32_CONST | ||
# CHECK-NEXT: Value: 4 | ||
# CHECK-NEXT: Content: 2A0000002B000000 | ||
|
||
# CHECK: SegmentInfo: | ||
# CHECK-NEXT: - Index: 0 | ||
# CHECK-NEXT: Name: .data.foo | ||
# CHECK-NEXT: Alignment: 0 | ||
# CHECK-NEXT: Flags: [ ] | ||
# CHECK-NEXT: - Index: 1 | ||
# CHECK-NEXT: Name: .data.foo | ||
# CHECK-NEXT: Alignment: 0 | ||
# CHECK-NEXT: Flags: [ ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters