1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
#!/usr/bin/env python
# Copyright (c) 2013 Google Inc. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""
Make sure the link order of object files is the same between msvs and ninja.
"""
from __future__ import print_function
import TestGyp
import sys
if sys.platform == 'win32':
test = TestGyp.TestGyp(formats=['msvs', 'ninja'])
CHDIR = 'linker-flags'
test.run_gyp('link-ordering.gyp', chdir=CHDIR)
test.build('link-ordering.gyp', test.ALL, chdir=CHDIR)
def GetDisasm(exe):
full_path = test.built_file_path(exe, chdir=CHDIR)
# Get disassembly and drop int3 padding between functions.
return '\n'.join(
x for x in test.run_dumpbin('/disasm', full_path).splitlines()
if 'CC' not in x)
# This is the full dump that we expect. The source files in the .gyp match
# this order which is what determines the ordering in the binary.
expected_disasm_basic = '''
_mainCRTStartup:
00401000: B8 05 00 00 00 mov eax,5
00401005: C3 ret
?z@@YAHXZ:
00401010: B8 03 00 00 00 mov eax,3
00401015: C3 ret
?x@@YAHXZ:
00401020: B8 01 00 00 00 mov eax,1
00401025: C3 ret
?y@@YAHXZ:
00401030: B8 02 00 00 00 mov eax,2
00401035: C3 ret
_main:
00401040: 33 C0 xor eax,eax
00401042: C3 ret
'''
if expected_disasm_basic not in GetDisasm('test_ordering_exe.exe'):
print(GetDisasm('test_ordering_exe.exe'))
test.fail_test()
# Similar to above. The VS generator handles subdirectories differently.
expected_disasm_subdirs = '''
_mainCRTStartup:
00401000: B8 05 00 00 00 mov eax,5
00401005: C3 ret
_main:
00401010: 33 C0 xor eax,eax
00401012: C3 ret
?y@@YAHXZ:
00401020: B8 02 00 00 00 mov eax,2
00401025: C3 ret
?z@@YAHXZ:
00401030: B8 03 00 00 00 mov eax,3
00401035: C3 ret
'''
if expected_disasm_subdirs not in GetDisasm('test_ordering_subdirs.exe'):
print(GetDisasm('test_ordering_subdirs.exe'))
test.fail_test()
# Similar, but with directories mixed into folders (crt and main at the same
# level, but with a subdir in the middle).
expected_disasm_subdirs_mixed = '''
_mainCRTStartup:
00401000: B8 05 00 00 00 mov eax,5
00401005: C3 ret
?x@@YAHXZ:
00401010: B8 01 00 00 00 mov eax,1
00401015: C3 ret
_main:
00401020: 33 C0 xor eax,eax
00401022: C3 ret
?z@@YAHXZ:
00401030: B8 03 00 00 00 mov eax,3
00401035: C3 ret
?y@@YAHXZ:
00401040: B8 02 00 00 00 mov eax,2
00401045: C3 ret
'''
if (expected_disasm_subdirs_mixed not in
GetDisasm('test_ordering_subdirs_mixed.exe')):
print(GetDisasm('test_ordering_subdirs_mixed.exe'))
test.fail_test()
test.pass_test()
|