llvm-capstone/lld/test/COFF/output-chars.test

110 lines
3.4 KiB
Plaintext
Raw Normal View History

COFF: Use (name, output characteristics) as a key when grouping input sections into output sections. This is what link.exe does and lets us avoid needing to worry about merging output characteristics while adding input sections to output sections. With this change we can't process /merge in the same way as before because sections with different output characteristics can still be merged into one another. So this change moves the processing of /merge to just before we assign addresses. In the case where there are multiple output sections with the same name, link.exe only merges the first section with the source name into the first section with the target name, and we do the same. At the same time I also implemented transitive merging (which means that /merge:.c=.b /merge:.b=.a merges both .c and .b into .a). This isn't quite enough though because link.exe has a special case for .CRT in 32-bit mode: it processes sections whose output characteristics are DATA | R | W as though the output characteristics were DATA | R (so that they get merged into things like constructor lists in the expected way). Chromium has a few such sections, and it turns out that those sections were causing the problem that resulted in r318699 (merge .xdata into .rdata) being reverted: because of the previous permission merging semantics, the .CRT sections were causing the entire .rdata section to become writable, which caused the SEH runtime to crash because it apparently requires .xdata to be read-only. This change also implements the same special case. This should unblock being able to merge .xdata into .rdata by default, as well as .bss into .data, both of which will be done in followups. Differential Revision: https://reviews.llvm.org/D45801 llvm-svn: 330479
2018-04-20 21:10:33 +00:00
# RUN: yaml2obj %s > %t.obj
# RUN: lld-link /out:%t.dll /entry:__ImageBase /dll %t.obj
# RUN: llvm-readobj -sections %t.dll | FileCheck %s
# RUN: lld-link /out:%t.dll /entry:__ImageBase /dll %t.obj /section:.foo,rwe
# RUN: llvm-readobj -sections %t.dll | FileCheck --check-prefix=SECTION %s
# RUN: lld-link /out:%t.dll /entry:__ImageBase /dll %t.obj /merge:.foo=.bar
# RUN: llvm-readobj -sections -section-data %t.dll | FileCheck --check-prefix=MERGE %s
# RUN: lld-link /out:%t.dll /entry:__ImageBase /dll %t.obj /merge:.foo=.bar /section:.foo,rwe
# RUN: llvm-readobj -sections %t.dll | FileCheck --check-prefix=MERGE-SECTION %s
# CHECK: Name: .foo
# CHECK: Characteristics [
# CHECK-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA
# CHECK-NEXT: IMAGE_SCN_MEM_READ
# CHECK-NEXT: ]
# CHECK: Name: .foo
# CHECK: Characteristics [
# CHECK-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA
# CHECK-NEXT: IMAGE_SCN_MEM_READ
# CHECK-NEXT: IMAGE_SCN_MEM_WRITE
# CHECK-NEXT: ]
# SECTION: Name: .foo
# SECTION: Characteristics [
# SECTION-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA
COFF: Use (name, output characteristics) as a key when grouping input sections into output sections. This is what link.exe does and lets us avoid needing to worry about merging output characteristics while adding input sections to output sections. With this change we can't process /merge in the same way as before because sections with different output characteristics can still be merged into one another. So this change moves the processing of /merge to just before we assign addresses. In the case where there are multiple output sections with the same name, link.exe only merges the first section with the source name into the first section with the target name, and we do the same. At the same time I also implemented transitive merging (which means that /merge:.c=.b /merge:.b=.a merges both .c and .b into .a). This isn't quite enough though because link.exe has a special case for .CRT in 32-bit mode: it processes sections whose output characteristics are DATA | R | W as though the output characteristics were DATA | R (so that they get merged into things like constructor lists in the expected way). Chromium has a few such sections, and it turns out that those sections were causing the problem that resulted in r318699 (merge .xdata into .rdata) being reverted: because of the previous permission merging semantics, the .CRT sections were causing the entire .rdata section to become writable, which caused the SEH runtime to crash because it apparently requires .xdata to be read-only. This change also implements the same special case. This should unblock being able to merge .xdata into .rdata by default, as well as .bss into .data, both of which will be done in followups. Differential Revision: https://reviews.llvm.org/D45801 llvm-svn: 330479
2018-04-20 21:10:33 +00:00
# SECTION-NEXT: IMAGE_SCN_MEM_EXECUTE
# SECTION-NEXT: IMAGE_SCN_MEM_READ
# SECTION-NEXT: IMAGE_SCN_MEM_WRITE
# SECTION-NEXT: ]
# SECTION: Name: .foo
# SECTION: Characteristics [
# SECTION-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA
COFF: Use (name, output characteristics) as a key when grouping input sections into output sections. This is what link.exe does and lets us avoid needing to worry about merging output characteristics while adding input sections to output sections. With this change we can't process /merge in the same way as before because sections with different output characteristics can still be merged into one another. So this change moves the processing of /merge to just before we assign addresses. In the case where there are multiple output sections with the same name, link.exe only merges the first section with the source name into the first section with the target name, and we do the same. At the same time I also implemented transitive merging (which means that /merge:.c=.b /merge:.b=.a merges both .c and .b into .a). This isn't quite enough though because link.exe has a special case for .CRT in 32-bit mode: it processes sections whose output characteristics are DATA | R | W as though the output characteristics were DATA | R (so that they get merged into things like constructor lists in the expected way). Chromium has a few such sections, and it turns out that those sections were causing the problem that resulted in r318699 (merge .xdata into .rdata) being reverted: because of the previous permission merging semantics, the .CRT sections were causing the entire .rdata section to become writable, which caused the SEH runtime to crash because it apparently requires .xdata to be read-only. This change also implements the same special case. This should unblock being able to merge .xdata into .rdata by default, as well as .bss into .data, both of which will be done in followups. Differential Revision: https://reviews.llvm.org/D45801 llvm-svn: 330479
2018-04-20 21:10:33 +00:00
# SECTION-NEXT: IMAGE_SCN_MEM_EXECUTE
# SECTION-NEXT: IMAGE_SCN_MEM_READ
# SECTION-NEXT: IMAGE_SCN_MEM_WRITE
# SECTION-NEXT: ]
# MERGE: Name: .bar
# MERGE: Characteristics [
# MERGE-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA
# MERGE-NEXT: IMAGE_SCN_MEM_READ
# MERGE-NEXT: ]
# MERGE-NEXT: SectionData (
# MERGE-NEXT: 0000: 0301
# MERGE: Name: .bar
# MERGE: Characteristics [
# MERGE-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA
# MERGE-NEXT: IMAGE_SCN_MEM_READ
# MERGE-NEXT: IMAGE_SCN_MEM_WRITE
# MERGE-NEXT: ]
# MERGE-NEXT: SectionData (
# MERGE-NEXT: 0000: 04
# MERGE: Name: .foo
# MERGE: Characteristics [
# MERGE-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA
# MERGE-NEXT: IMAGE_SCN_MEM_READ
# MERGE-NEXT: IMAGE_SCN_MEM_WRITE
# MERGE-NEXT: ]
# MERGE-NEXT: SectionData (
# MERGE-NEXT: 0000: 02
# MERGE-SECTION: Name: .bar
# MERGE-SECTION: Characteristics [
# MERGE-SECTION-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA
# MERGE-SECTION-NEXT: IMAGE_SCN_MEM_READ
# MERGE-SECTION-NEXT: ]
# MERGE-SECTION: Name: .bar
# MERGE-SECTION: Characteristics [
# MERGE-SECTION-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA
# MERGE-SECTION-NEXT: IMAGE_SCN_MEM_READ
# MERGE-SECTION-NEXT: IMAGE_SCN_MEM_WRITE
# MERGE-SECTION-NEXT: ]
# MERGE-SECTION: Name: .foo
# MERGE-SECTION: Characteristics [
# MERGE-SECTION-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA
COFF: Use (name, output characteristics) as a key when grouping input sections into output sections. This is what link.exe does and lets us avoid needing to worry about merging output characteristics while adding input sections to output sections. With this change we can't process /merge in the same way as before because sections with different output characteristics can still be merged into one another. So this change moves the processing of /merge to just before we assign addresses. In the case where there are multiple output sections with the same name, link.exe only merges the first section with the source name into the first section with the target name, and we do the same. At the same time I also implemented transitive merging (which means that /merge:.c=.b /merge:.b=.a merges both .c and .b into .a). This isn't quite enough though because link.exe has a special case for .CRT in 32-bit mode: it processes sections whose output characteristics are DATA | R | W as though the output characteristics were DATA | R (so that they get merged into things like constructor lists in the expected way). Chromium has a few such sections, and it turns out that those sections were causing the problem that resulted in r318699 (merge .xdata into .rdata) being reverted: because of the previous permission merging semantics, the .CRT sections were causing the entire .rdata section to become writable, which caused the SEH runtime to crash because it apparently requires .xdata to be read-only. This change also implements the same special case. This should unblock being able to merge .xdata into .rdata by default, as well as .bss into .data, both of which will be done in followups. Differential Revision: https://reviews.llvm.org/D45801 llvm-svn: 330479
2018-04-20 21:10:33 +00:00
# MERGE-SECTION-NEXT: IMAGE_SCN_MEM_EXECUTE
# MERGE-SECTION-NEXT: IMAGE_SCN_MEM_READ
# MERGE-SECTION-NEXT: IMAGE_SCN_MEM_WRITE
# MERGE-SECTION-NEXT: ]
--- !COFF
header:
Machine: IMAGE_FILE_MACHINE_AMD64
Characteristics: [ ]
sections:
- Name: .foo
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]
Alignment: 1
SectionData: 01
- Name: .foo
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
Alignment: 1
SectionData: 02
- Name: .bar
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ ]
Alignment: 1
SectionData: 03
- Name: .bar
Characteristics: [ IMAGE_SCN_CNT_INITIALIZED_DATA, IMAGE_SCN_MEM_READ, IMAGE_SCN_MEM_WRITE ]
Alignment: 1
SectionData: 04
symbols:
...