Skip to content

Commit

Permalink
Merge .xdata into .rdata by default
Browse files Browse the repository at this point in the history
Summary: MSVC does this. The user can override it with their own /merge: flag.

Reviewers: ruiu, pcc

Subscribers: llvm-commits

Differential Revision: https://reviews.llvm.org/D40197

llvm-svn: 318699
  • Loading branch information
rnk committed Nov 20, 2017
1 parent 523edb0 commit 95cc796
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 26 deletions.
4 changes: 4 additions & 0 deletions lld/COFF/Driver.cpp
Expand Up @@ -966,6 +966,10 @@ void LinkerDriver::link(ArrayRef<const char *> ArgsArr) {
for (auto *Arg : Args.filtered(OPT_merge))
parseMerge(Arg->getValue());

// Add default section merging rules after user rules. User rules take
// precedence, but we will emit a warning if there is a conflict.
parseMerge(".xdata=.rdata");

// Handle /section
for (auto *Arg : Args.filtered(OPT_section))
parseSection(Arg->getValue());
Expand Down
20 changes: 15 additions & 5 deletions lld/test/COFF/icf-xdata.s
@@ -1,13 +1,23 @@
# RUN: llvm-mc %s -triple x86_64-windows-msvc -filetype=obj -o %t.obj
# RUN: lld-link %t.obj -dll -noentry -out:%t.dll -merge:.xdata=.xdata 2>&1 \
# RUN: | FileCheck %s --check-prefix=WARN
# RUN: llvm-readobj -sections %t.dll | FileCheck %s --check-prefix=XDATA
# RUN: lld-link %t.obj -dll -noentry -out:%t.dll
# RUN: llvm-readobj -sections %t.dll | FileCheck %s
# RUN: llvm-readobj -sections %t.dll | FileCheck %s --check-prefix=RDATA

# There shouldn't be much xdata, because all three .pdata entries (12 bytes
# each) should use the same .xdata unwind info.
# CHECK: Name: .pdata
# CHECK-NEXT: VirtualSize: 0x24
# CHECK: Name: .xdata
# CHECK-NEXT: VirtualSize: 0x8
# XDATA: Name: .pdata
# XDATA-NEXT: VirtualSize: 0x24
# XDATA: Name: .xdata
# XDATA-NEXT: VirtualSize: 0x8
#
# WARN: warning: .xdata=.rdata: already merged into .xdata
#
# RDATA: Name: .pdata
# RDATA-NEXT: VirtualSize: 0x24
# RDATA: Name: .rdata
# RDATA-NEXT: VirtualSize: 0x8

.text
callee:
Expand Down
32 changes: 11 additions & 21 deletions lld/test/COFF/pdb.test
Expand Up @@ -201,7 +201,7 @@ RAW-NEXT: .pdata name
RAW-NEXT: virtual size
RAW-NEXT: 1000 virtual address
RAW-NEXT: 200 size of raw data
RAW-NEXT: 400 file pointer to raw data
RAW-NEXT: 200 file pointer to raw data
RAW-NEXT: 0 file pointer to relocation table
RAW-NEXT: 0 file pointer to line numbers
RAW-NEXT: 0 number of relocations
Expand All @@ -214,7 +214,7 @@ RAW-NEXT: .text name
RAW-NEXT: virtual size
RAW-NEXT: 2000 virtual address
RAW-NEXT: 200 size of raw data
RAW-NEXT: 600 file pointer to raw data
RAW-NEXT: 400 file pointer to raw data
RAW-NEXT: 0 file pointer to relocation table
RAW-NEXT: 0 file pointer to line numbers
RAW-NEXT: 0 number of relocations
Expand All @@ -224,31 +224,19 @@ RAW-NEXT: IMAGE_SCN_CNT_CODE
RAW-NEXT: IMAGE_SCN_MEM_EXECUTE
RAW-NEXT: IMAGE_SCN_MEM_READ
RAW: SECTION HEADER #3
RAW-NEXT: .xdata name
RAW-NEXT: virtual size
RAW-NEXT: 3000 virtual address
RAW-NEXT: 200 size of raw data
RAW-NEXT: 800 file pointer to raw data
RAW-NEXT: 0 file pointer to relocation table
RAW-NEXT: 0 file pointer to line numbers
RAW-NEXT: 0 number of relocations
RAW-NEXT: 0 number of line numbers
RAW-NEXT: 40000040 flags
RAW-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA
RAW-NEXT: IMAGE_SCN_MEM_READ
RAW: SECTION HEADER #4
RAW-NEXT: .rdata name
RAW-NEXT: virtual size
RAW-NEXT: 4000 virtual address
RAW-NEXT: 3000 virtual address
RAW-NEXT: 200 size of raw data
RAW-NEXT: A00 file pointer to raw data
RAW-NEXT: 600 file pointer to raw data
RAW-NEXT: 0 file pointer to relocation table
RAW-NEXT: 0 file pointer to line numbers
RAW-NEXT: 0 number of relocations
RAW-NEXT: 0 number of line numbers
RAW-NEXT: 40000040 flags
RAW-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA
RAW-NEXT: IMAGE_SCN_MEM_READ
RAW-NOT: SECTION HEADER
RAW: Original Section Headers
RAW-NEXT: ============================================================
RAW-NEXT: PDB does not contain the requested image section header type
Expand All @@ -262,8 +250,13 @@ RAW-NEXT: IMAGE_SCN_MEM_READ
RAW-NEXT: SC[.text] | mod = 1, 0002:0016, size = 6, data crc = 2139436471, reloc crc = 0
RAW-NEXT: IMAGE_SCN_CNT_CODE | IMAGE_SCN_ALIGN_16BYTES | IMAGE_SCN_MEM_EXECUTE |
RAW-NEXT: IMAGE_SCN_MEM_READ
RAW-NEXT: SC[.xdata] | mod = 0, 0003:0000, size = 8, data crc = 264583633, reloc crc = 0
RAW-NEXT: SC[???] | mod = 0, 0003:0000, size = 8, data crc = 264583633, reloc crc = 0
RAW-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_ALIGN_4BYTES | IMAGE_SCN_MEM_READ
RAW-NEXT: SC[???] | mod = 2, 0003:0008, size = 28, data crc = 0, reloc crc = 0
RAW-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ
RAW-NEXT: SC[???] | mod = 2, 0003:0036, size = 94, data crc = 0, reloc crc = 0
RAW-NEXT: IMAGE_SCN_CNT_INITIALIZED_DATA | IMAGE_SCN_MEM_READ
RAW-NOT: SC[
RAW: Section Map
RAW-NEXT: ============================================================
RAW-NEXT: Section 0000 | ovl = 0, group = 0, frame = 1, name = 65535
Expand All @@ -277,7 +270,4 @@ RAW-NEXT: class = 65535, offset = 0, size =
RAW-NEXT: flags = read | 32 bit addr | selector
RAW-NEXT: Section 0003 | ovl = 0, group = 0, frame = 4, name = 65535
RAW-NEXT: class = 65535, offset = 0, size =
RAW-NEXT: flags = read | 32 bit addr | selector
RAW-NEXT: Section 0004 | ovl = 0, group = 0, frame = 5, name = 65535
RAW-NEXT: class = 65535, offset = 0, size =
RAW-NEXT: flags = 32 bit addr | absolute addr

0 comments on commit 95cc796

Please sign in to comment.