On 20/10/12 03:15, Michael Spencer wrote:> On Fri, Oct 19, 2012 at 2:55 AM, r4start <r4start at gmail.com>
wrote:
>> Hi all.
>>
>> While compiling next code
>> @A = weak unnamed_addr constant { i32, i32, i32 } { i32 0, i32 0, i32 0
},
>> section ".data"
>> was discovered that llc ignores weak linkage if we emit it in COFF
object.
>> Attached patch solves this problem, please review.
>>
>> I found some similar tests in test/Objects/Inputs. Should I do
something
>> like trivial.ll checking or there is a better way
>> to check patch behaviour?
>>
>> - Dmitry Sokolov.
>>
>> _______________________________________________
>> LLVM Developers mailing list
>> LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu
>> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
>>
> test/Object is not the right place for the test. It should probably go
> in test/MC/COFF as a .ll file, although technically it's codegen...
>
> Also, I'm pretty sure this is wrong for MinGW. What do msvc and
> mingw-gcc produce for c code that generates this?
>
> - Michael Spencer
For this c code(see attachments) cl, mingw and clang produce different
coff's(was used dumpbin with option /ALL):
1) Cl generate separate COMDAT section with linkage selection "pick
any"
2) Mingw place this value to regular section and place special auxilary
record to symbol table
3) Clang without patch just ignore weakness of this value and place it
to regular section.
But for weak values without explicit section specification it use
cl-like way. i.e. generate
separate COMDAT section with a little difference in naming (unique
suffix after $)
4) With this patch clang will generate correct COMDAT section for values
with explicit section specification.
The problem is in backend. When we have explicit section specification
linkage type is ignored.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 1.c
Type: text/x-csrc
Size: 175 bytes
Desc: not available
URL:
<http://lists.llvm.org/pipermail/llvm-dev/attachments/20121022/4d7be13c/attachment.c>
-------------- next part --------------
Microsoft (R) COFF/PE Dumper Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file 1.obj
File Type: COFF OBJECT
FILE HEADER VALUES
14C machine (x86)
3 number of sections
50853E78 time date stamp Mon Oct 22 16:39:20 2012
123 file pointer to symbol table
9 number of symbols
0 size of optional header
0 characteristics
SECTION HEADER #1
.drectve name
0 physical address
0 virtual address
2F size of raw data
8C file pointer to raw data (0000008C to 000000BA)
0 file pointer to relocation table
0 file pointer to line numbers
0 number of relocations
0 number of line numbers
100A00 flags
Info
Remove
1 byte align
RAW DATA #1
00000000: 20 20 20 2F 44 45 46 41 55 4C 54 4C 49 42 3A 22
/DEFAULTLIB:"
00000010: 4C 49 42 43 4D 54 22 20 2F 44 45 46 41 55 4C 54 LIBCMT"
/DEFAULT
00000020: 4C 49 42 3A 22 4F 4C 44 4E 41 4D 45 53 22 20
LIB:"OLDNAMES"
Linker Directives
-----------------
/DEFAULTLIB:"LIBCMT"
/DEFAULTLIB:"OLDNAMES"
SECTION HEADER #2
.debug$S name
0 physical address
0 virtual address
64 size of raw data
BB file pointer to raw data (000000BB to 0000011E)
0 file pointer to relocation table
0 file pointer to line numbers
0 number of relocations
0 number of line numbers
42100040 flags
Initialized Data
Discardable
1 byte align
Read Only
RAW DATA #2
00000000: 04 00 00 00 F1 00 00 00 58 00 00 00 1A 00 01 11 ....n...X.......
00000010: 00 00 00 00 43 3A 5C 4D 69 6E 47 57 5C 77 6F 72 ....C:\MinGW\wor
00000020: 6B 5C 31 2E 6F 62 6A 00 3A 00 3C 11 00 22 00 00
k\1.obj.:.<.."..
00000030: 07 00 10 00 00 00 1B 9D 01 00 10 00 00 00 1B 9D ................
00000040: 01 00 4D 69 63 72 6F 73 6F 66 74 20 28 52 29 20 ..Microsoft (R)
00000050: 4F 70 74 69 6D 69 7A 69 6E 67 20 43 6F 6D 70 69 Optimizing Compi
00000060: 6C 65 72 00 ler.
SECTION HEADER #3
.xdata name
0 physical address
0 virtual address
4 size of raw data
11F file pointer to raw data (0000011F to 00000122)
0 file pointer to relocation table
0 file pointer to line numbers
0 number of relocations
0 number of line numbers
C0301040 flags
Initialized Data
COMDAT; sym= _aaa
4 byte align
Read Write
RAW DATA #3
00000000: F3 E0 01 00 oa..
COFF SYMBOL TABLE
000 00AA9D1B ABS notype Static | @comp.id
001 00000001 ABS notype Static | @feat.00
002 00000000 SECT1 notype Static | .drectve
Section length 2F, #relocs 0, #linenums 0, checksum 0
004 00000000 SECT2 notype Static | .debug$S
Section length 64, #relocs 0, #linenums 0, checksum 0
006 00000000 SECT3 notype Static | .xdata
Section length 4, #relocs 0, #linenums 0, checksum 242A58A8,
selection 2 (pick any)
008 00000000 SECT3 notype External | _aaa
String Table Size = 0x0 bytes
Summary
64 .debug$S
2F .drectve
4 .xdata
-------------- next part --------------
Microsoft (R) COFF/PE Dumper Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file d:\Work\analysis\llvm_exec\1.o
File Type: COFF OBJECT
FILE HEADER VALUES
14C machine (x86)
1 number of sections
50851C8B time date stamp Mon Oct 22 14:14:35 2012
40 file pointer to symbol table
3 number of symbols
0 size of optional header
0 characteristics
SECTION HEADER #1
.xdata name
0 physical address
0 virtual address
4 size of raw data
3C file pointer to raw data (0000003C to 0000003F)
0 file pointer to relocation table
0 file pointer to line numbers
0 number of relocations
0 number of line numbers
C0300040 flags
Initialized Data
4 byte align
Read Write
RAW DATA #1
00000000: F3 E0 01 00 oa..
COFF SYMBOL TABLE
000 00000000 SECT1 notype Static | .xdata
Section length 4, #relocs 0, #linenums 0, checksum 0
002 00000000 SECT1 notype External | _aaa
String Table Size = 0x0 bytes
Summary
4 .xdata
-------------- next part --------------
Microsoft (R) COFF/PE Dumper Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file d:\Work\analysis\llvm_exec\1.o
File Type: COFF OBJECT
FILE HEADER VALUES
14C machine (x86)
1 number of sections
50853FEC time date stamp Mon Oct 22 16:45:32 2012
40 file pointer to symbol table
3 number of symbols
0 size of optional header
0 characteristics
SECTION HEADER #1
/4 name (.xdata$aaa)
0 physical address
0 virtual address
4 size of raw data
3C file pointer to raw data (0000003C to 0000003F)
0 file pointer to relocation table
0 file pointer to line numbers
0 number of relocations
0 number of line numbers
C0301040 flags
Initialized Data
COMDAT; sym= _aaa
4 byte align
Read Write
RAW DATA #1
00000000: F3 E0 01 00 oa..
COFF SYMBOL TABLE
000 00000000 SECT1 notype Static | .xdata$aaa
Section length 4, #relocs 0, #linenums 0, checksum 0,
selection 2 (pick any)
002 00000000 SECT1 notype External | _aaa
String Table Size = 0xF bytes
Summary
4 .xdata$aaa
-------------- next part --------------
Microsoft (R) COFF/PE Dumper Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.
Dump of file 1.o
File Type: COFF OBJECT
FILE HEADER VALUES
14C machine (x86)
4 number of sections
0 time date stamp Thu Jan 01 04:00:00 1970
B8 file pointer to symbol table
D number of symbols
0 size of optional header
105 characteristics
Relocations stripped
Line numbers stripped
32 bit word machine
SECTION HEADER #1
.text name
0 physical address
0 virtual address
0 size of raw data
0 file pointer to raw data
0 file pointer to relocation table
0 file pointer to line numbers
0 number of relocations
0 number of line numbers
60300020 flags
Code
4 byte align
Execute Read
SECTION HEADER #2
.data name
0 physical address
0 virtual address
0 size of raw data
0 file pointer to raw data
0 file pointer to relocation table
0 file pointer to line numbers
0 number of relocations
0 number of line numbers
C0300040 flags
Initialized Data
4 byte align
Read Write
SECTION HEADER #3
.bss name
0 physical address
0 virtual address
0 size of raw data
0 file pointer to raw data
0 file pointer to relocation table
0 file pointer to line numbers
0 number of relocations
0 number of line numbers
C0300080 flags
Uninitialized Data
4 byte align
Read Write
SECTION HEADER #4
.xdata name
0 physical address
0 virtual address
4 size of raw data
B4 file pointer to raw data (000000B4 to 000000B7)
0 file pointer to relocation table
0 file pointer to line numbers
0 number of relocations
0 number of line numbers
40300040 flags
Initialized Data
4 byte align
Read Only
RAW DATA #4
00000000: F3 E0 01 00 oa..
COFF SYMBOL TABLE
000 00000000 DEBUG notype Filename | .file
1.c
002 00000000 SECT1 notype Static | .text
Section length 0, #relocs 0, #linenums 0, checksum 0
004 00000000 SECT2 notype Static | .data
Section length 0, #relocs 0, #linenums 0, checksum 0
006 00000000 SECT3 notype Static | .bss
Section length 0, #relocs 0, #linenums 0, checksum 0
008 00000000 SECT4 notype Static | .xdata
Section length 4, #relocs 0, #linenums 0, checksum 0
00A 00000000 SECT4 notype External | .weak._aaa.
00B 00000000 UNDEF notype WeakExternal | _aaa
Default index A No library search
String Table Size = 0x10 bytes
Summary
0 .bss
0 .data
0 .text
4 .xdata