OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 |
| 3 # Copyright (c) 2012 Google Inc. All rights reserved. |
| 4 # Use of this source code is governed by a BSD-style license that can be |
| 5 # found in the LICENSE file. |
| 6 |
| 7 """ |
| 8 Make sure additional options are handled. |
| 9 """ |
| 10 |
| 11 import TestGyp |
| 12 |
| 13 import os |
| 14 import subprocess |
| 15 import sys |
| 16 |
| 17 # Find /third_party/pefile based on current directory and script path. |
| 18 sys.path.append(os.path.join( |
| 19 os.path.dirname(__file__), '..', '..', '..', '..', 'third_party', 'pefile')) |
| 20 sys.path.append(os.path.join( |
| 21 os.path.dirname(__file__), '..', '..', '..', '..', '..', |
| 22 'third_party', 'pefile')) |
| 23 import pefile |
| 24 |
| 25 |
| 26 if sys.platform == 'win32': |
| 27 test = TestGyp.TestGyp(formats=['ninja', 'msvs']) |
| 28 |
| 29 CHDIR = 'linker_flags' |
| 30 test.run_gyp('additional-options.gyp', chdir=CHDIR) |
| 31 test.build('additional-options.gyp', test.ALL, chdir=CHDIR) |
| 32 |
| 33 # Confirm /safeseh made it to the final binary |
| 34 exe_path = test.built_file_path('test_additional_few.exe', chdir=CHDIR) |
| 35 pe = pefile.PE(exe_path, fast_load=True) |
| 36 pe.parse_data_directories(directories=[ |
| 37 pefile.DIRECTORY_ENTRY['IMAGE_DIRECTORY_ENTRY_LOAD_CONFIG']]) |
| 38 NO_SEH_FLAG = 0x0400 |
| 39 MACHINE_TYPE_AMD64 = 0x8664 |
| 40 if (pe.OPTIONAL_HEADER.DllCharacteristics & NO_SEH_FLAG or |
| 41 (hasattr(pe, "DIRECTORY_ENTRY_LOAD_CONFIG") and |
| 42 pe.DIRECTORY_ENTRY_LOAD_CONFIG.struct.SEHandlerCount > 0 and |
| 43 pe.DIRECTORY_ENTRY_LOAD_CONFIG.struct.SEHandlerTable != 0) or |
| 44 pe.FILE_HEADER.Machine == MACHINE_TYPE_AMD64): |
| 45 pass |
| 46 else: |
| 47 print 'No /SAFESEH flag on %s.' % exe_path |
| 48 test.fail_test() |
| 49 |
| 50 |
| 51 if test.format == 'ninja': |
| 52 ninja_file = test.built_file_path('obj/test_additional_none.ninja', |
| 53 chdir=CHDIR) |
| 54 # Just generates OK |
| 55 |
| 56 ninja_file = test.built_file_path('obj/test_additional_few.ninja', |
| 57 chdir=CHDIR) |
| 58 test.must_contain(ninja_file, '/safeseh') |
| 59 test.must_contain(ninja_file, '/ignore:4199') |
| 60 |
| 61 test.pass_test() |
OLD | NEW |