Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(205)

Side by Side Diff: build/toolchain/gcc_solink_wrapper.py

Issue 2175413004: Enable whitelist generation for all builds. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed agrieve's comments and removed stderr filtering. Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2015 The Chromium Authors. All rights reserved. 2 # Copyright 2015 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Runs 'ld -shared' and generates a .TOC file that's untouched when unchanged. 6 """Runs 'ld -shared' and generates a .TOC file that's untouched when unchanged.
7 7
8 This script exists to avoid using complex shell commands in 8 This script exists to avoid using complex shell commands in
9 gcc_toolchain.gni's tool("solink"), in case the host running the compiler 9 gcc_toolchain.gni's tool("solink"), in case the host running the compiler
10 does not have a POSIX-like shell (e.g. Windows). 10 does not have a POSIX-like shell (e.g. Windows).
11 """ 11 """
12 12
13 import argparse 13 import argparse
14 import os 14 import os
15 import re
16 import subprocess 15 import subprocess
17 import sys 16 import sys
18 17
19 18 import wrapper_utils
20 # When running on a Windows host and using a toolchain whose tools are
21 # actually wrapper scripts (i.e. .bat files on Windows) rather than binary
22 # executables, the "command" to run has to be prefixed with this magic.
23 # The GN toolchain definitions take care of that for when GN/Ninja is
24 # running the tool directly. When that command is passed in to this
25 # script, it appears as a unitary string but needs to be split up so that
26 # just 'cmd' is the actual command given to Python's subprocess module.
27 BAT_PREFIX = 'cmd /c call '
28
29 def CommandToRun(command):
30 if command[0].startswith(BAT_PREFIX):
31 command = command[0].split(None, 3) + command[1:]
32 return command
33 19
34 20
35 def CollectSONAME(args): 21 def CollectSONAME(args):
36 """Replaces: readelf -d $sofile | grep SONAME""" 22 """Replaces: readelf -d $sofile | grep SONAME"""
37 toc = '' 23 toc = ''
38 readelf = subprocess.Popen(CommandToRun([args.readelf, '-d', args.sofile]), 24 readelf = subprocess.Popen(wrapper_utils.CommandToRun(
39 stdout=subprocess.PIPE, bufsize=-1) 25 [args.readelf, '-d', args.sofile]), stdout=subprocess.PIPE, bufsize=-1)
40 for line in readelf.stdout: 26 for line in readelf.stdout:
41 if 'SONAME' in line: 27 if 'SONAME' in line:
42 toc += line 28 toc += line
43 return readelf.wait(), toc 29 return readelf.wait(), toc
44 30
45 31
46 def CollectDynSym(args): 32 def CollectDynSym(args):
47 """Replaces: nm --format=posix -g -D $sofile | cut -f1-2 -d' '""" 33 """Replaces: nm --format=posix -g -D $sofile | cut -f1-2 -d' '"""
48 toc = '' 34 toc = ''
49 nm = subprocess.Popen(CommandToRun([ 35 nm = subprocess.Popen(wrapper_utils.CommandToRun([
50 args.nm, '--format=posix', '-g', '-D', args.sofile]), 36 args.nm, '--format=posix', '-g', '-D', args.sofile]),
51 stdout=subprocess.PIPE, bufsize=-1) 37 stdout=subprocess.PIPE, bufsize=-1)
52 for line in nm.stdout: 38 for line in nm.stdout:
53 toc += ' '.join(line.split(' ', 2)[:2]) + '\n' 39 toc += ' '.join(line.split(' ', 2)[:2]) + '\n'
54 return nm.wait(), toc 40 return nm.wait(), toc
55 41
56 42
57 def CollectTOC(args): 43 def CollectTOC(args):
58 result, toc = CollectSONAME(args) 44 result, toc = CollectSONAME(args)
59 if result == 0: 45 if result == 0:
(...skipping 29 matching lines...) Expand all
89 help='Shared object file produced by linking command', 75 help='Shared object file produced by linking command',
90 metavar='FILE') 76 metavar='FILE')
91 parser.add_argument('--tocfile', 77 parser.add_argument('--tocfile',
92 required=True, 78 required=True,
93 help='Output table-of-contents file', 79 help='Output table-of-contents file',
94 metavar='FILE') 80 metavar='FILE')
95 parser.add_argument('--output', 81 parser.add_argument('--output',
96 required=True, 82 required=True,
97 help='Final output shared object file', 83 help='Final output shared object file',
98 metavar='FILE') 84 metavar='FILE')
85 parser.add_argument('--resource-whitelist',
86 help='Merge all resource whitelists into a single file.',
87 metavar='PATH')
99 parser.add_argument('command', nargs='+', 88 parser.add_argument('command', nargs='+',
100 help='Linking command') 89 help='Linking command')
101 args = parser.parse_args() 90 args = parser.parse_args()
102 91
92 if args.resource_whitelist:
93 whitelist_candidates = wrapper_utils.ResolveRspLinks(args.command)
94 wrapper_utils.CombineResourceWhitelists(
95 whitelist_candidates, args.resource_whitelist)
96
103 # First, run the actual link. 97 # First, run the actual link.
104 result = subprocess.call(CommandToRun(args.command)) 98 result = subprocess.call(wrapper_utils.CommandToRun(args.command))
105 if result != 0: 99 if result != 0:
106 return result 100 return result
107 101
108 # Next, generate the contents of the TOC file. 102 # Next, generate the contents of the TOC file.
109 result, toc = CollectTOC(args) 103 result, toc = CollectTOC(args)
110 if result != 0: 104 if result != 0:
111 return result 105 return result
112 106
113 # If there is an existing TOC file with identical contents, leave it alone. 107 # If there is an existing TOC file with identical contents, leave it alone.
114 # Otherwise, write out the TOC file. 108 # Otherwise, write out the TOC file.
115 UpdateTOC(args.tocfile, toc) 109 UpdateTOC(args.tocfile, toc)
116 110
117 # Finally, strip the linked shared object file (if desired). 111 # Finally, strip the linked shared object file (if desired).
118 if args.strip: 112 if args.strip:
119 result = subprocess.call(CommandToRun([args.strip, '--strip-unneeded', 113 result = subprocess.call(wrapper_utils.CommandToRun(
120 '-o', args.output, args.sofile])) 114 [args.strip, '--strip-unneeded', '-o', args.output, args.sofile]))
121 115
122 return result 116 return result
123 117
124 118
125 if __name__ == "__main__": 119 if __name__ == "__main__":
126 sys.exit(main()) 120 sys.exit(main())
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698