forked from flang-compiler/f18-llvm-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WebAssembly][Objcopy] Write output section headers identically to in…
…puts Previously when objcopy generated section headers, it padded the LEB that encodes the section size out to 5 bytes, matching the behavior of clang. This is correct, but results in a binary that differs from the input. This can sometimes have undesirable consequences (e.g. breaking source maps). This change makes the object reader remember the size of the LEB encoding in the section header, so that llvm-objcopy can reproduce it exactly. For sections not read from an object file (e.g. that llvm-objcopy is adding itself), pad to 5 bytes. Reviewed By: jhenderson Differential Revision: https://reviews.llvm.org/D155535
- Loading branch information
Showing
11 changed files
with
178 additions
and
12 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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
## Test that obj2yaml output includes the section header size encoding length | ||
## only when the length isn't padded to 5 bytes. | ||
# RUN: yaml2obj --docnum=1 %s | obj2yaml | FileCheck %s | ||
|
||
--- !WASM | ||
FileHeader: | ||
Version: 0x1 | ||
Sections: | ||
- Type: TYPE | ||
HeaderSecSizeEncodingLen: 3 | ||
Signatures: | ||
- Index: 0 | ||
ParamTypes: | ||
- I32 | ||
- I32 | ||
ReturnTypes: | ||
- I32 | ||
- Type: FUNCTION | ||
HeaderSecSizeEncodingLen: 4 | ||
FunctionTypes: [ 0 ] | ||
- Type: MEMORY | ||
HeaderSecSizeEncodingLen: 1 | ||
Memories: | ||
- Flags: [ HAS_MAX ] | ||
Minimum: 0x100 | ||
Maximum: 0x100 | ||
- Type: EXPORT | ||
HeaderSecSizeEncodingLen: 5 | ||
Exports: | ||
- Name: add | ||
Kind: FUNCTION | ||
Index: 0 | ||
- Type: CODE | ||
HeaderSecSizeEncodingLen: 2 | ||
Functions: | ||
- Index: 0 | ||
Locals: [] | ||
Body: 200020016A0B | ||
... | ||
# CHECK: --- !WASM | ||
# CHECK-NEXT: FileHeader: | ||
# CHECK-NEXT: Version: 0x1 | ||
# CHECK-NEXT: Sections: | ||
# CHECK-NEXT: - Type: TYPE | ||
# CHECK-NEXT: HeaderSecSizeEncodingLen: 3 | ||
# CHECK-NEXT: Signatures: | ||
# CHECK-NEXT: - Index: 0 | ||
# CHECK-NEXT: ParamTypes: | ||
# CHECK-NEXT: - I32 | ||
# CHECK-NEXT: - I32 | ||
# CHECK-NEXT: ReturnTypes: | ||
# CHECK-NEXT: - I32 | ||
# CHECK-NEXT: - Type: FUNCTION | ||
# CHECK-NEXT: HeaderSecSizeEncodingLen: 4 | ||
# CHECK-NEXT: FunctionTypes: [ 0 ] | ||
# CHECK-NEXT: - Type: MEMORY | ||
# CHECK-NEXT: Memories: | ||
# CHECK-NEXT: - Flags: [ HAS_MAX ] | ||
# CHECK-NEXT: Minimum: 0x100 | ||
# CHECK-NEXT: Maximum: 0x100 | ||
# CHECK-NEXT: - Type: EXPORT | ||
# CHECK-NEXT: Exports: | ||
# CHECK-NEXT: - Name: add | ||
# CHECK-NEXT: Kind: FUNCTION | ||
# CHECK-NEXT: Index: 0 | ||
# CHECK-NEXT: - Type: CODE | ||
# CHECK-NEXT: HeaderSecSizeEncodingLen: 2 | ||
# CHECK-NEXT: Functions: | ||
# CHECK-NEXT: - Index: 0 | ||
# CHECK-NEXT: Locals: [] | ||
# CHECK-NEXT: Body: 200020016A0B | ||
|
||
## Test if we correctly error out if the provided section header size is less | ||
## than the size required. | ||
# RUN: not yaml2obj --docnum=2 %s -o /dev/null 2>&1 | FileCheck %s --check-prefix=INVALID | ||
# INVALID: yaml2obj: error: section header length can't be encoded in a LEB of size 0 | ||
|
||
--- !WASM | ||
FileHeader: | ||
Version: 0x1 | ||
Sections: | ||
- Type: TYPE | ||
HeaderSecSizeEncodingLen: 0 | ||
Signatures: | ||
- Index: 0 | ||
ParamTypes: | ||
- I32 | ||
- I32 | ||
ReturnTypes: | ||
- I32 | ||
... |
41 changes: 41 additions & 0 deletions
41
llvm/test/tools/llvm-objcopy/wasm/section-header-size.test
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,41 @@ | ||
## Test that objcopy generates section headers that are identical to those from | ||
## the input binary, including the encoded size of the LEB that represents the | ||
## section size. | ||
|
||
# RUN: yaml2obj %s -o %t.wasm | ||
# RUN: llvm-objcopy %t.wasm %t.wasm.copy | ||
# RUN: diff %t.wasm %t.wasm.copy | ||
|
||
--- !WASM | ||
FileHeader: | ||
Version: 0x1 | ||
Sections: | ||
- Type: TYPE | ||
HeaderSecSizeEncodingLen: 3 | ||
Signatures: | ||
- Index: 0 | ||
ParamTypes: | ||
- I32 | ||
- I32 | ||
ReturnTypes: | ||
- I32 | ||
- Type: FUNCTION | ||
HeaderSecSizeEncodingLen: 4 | ||
FunctionTypes: [ 0 ] | ||
- Type: MEMORY | ||
HeaderSecSizeEncodingLen: 1 | ||
Memories: | ||
- Flags: [ HAS_MAX ] | ||
Minimum: 0x100 | ||
Maximum: 0x100 | ||
- Type: EXPORT | ||
HeaderSecSizeEncodingLen: 5 | ||
Exports: | ||
- Name: add | ||
Kind: FUNCTION | ||
Index: 0 | ||
- Type: CODE | ||
Functions: | ||
- Index: 0 | ||
Locals: [] | ||
Body: 200020016A0B |
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