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

Side by Side Diff: pydir/szbuild.py

Issue 944333002: Subzero: Update tests and build scripts for sandboxing. (Closed) Base URL: https://chromium.googlesource.com/native_client/pnacl-subzero.git@master
Patch Set: More code review changes Created 5 years, 10 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
« no previous file with comments | « pydir/crosstest.py ('k') | pydir/szbuild_spec2k.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python2 1 #!/usr/bin/env python2
2 2
3 import argparse 3 import argparse
4 import os 4 import os
5 import pipes 5 import pipes
6 import re 6 import re
7 import sys 7 import sys
8 8
9 from utils import shellcmd 9 from utils import shellcmd
10 from utils import FindBaseNaCl 10 from utils import FindBaseNaCl
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
76 action='store', 76 action='store',
77 help='Output executable. Default %(default)s.') 77 help='Output executable. Default %(default)s.')
78 argparser.add_argument('-O', default='2', dest='optlevel', 78 argparser.add_argument('-O', default='2', dest='optlevel',
79 choices=['m1', '-1', '0', '1', '2'], 79 choices=['m1', '-1', '0', '1', '2'],
80 help='Optimization level ' + 80 help='Optimization level ' +
81 '(m1 and -1 are equivalent).' + 81 '(m1 and -1 are equivalent).' +
82 ' Default %(default)s.') 82 ' Default %(default)s.')
83 argparser.add_argument('--filetype', default='iasm', dest='filetype', 83 argparser.add_argument('--filetype', default='iasm', dest='filetype',
84 choices=['obj', 'asm', 'iasm'], 84 choices=['obj', 'asm', 'iasm'],
85 help='Output file type. Default %(default)s.') 85 help='Output file type. Default %(default)s.')
86 argparser.add_argument('--sandbox', dest='sandbox', action='store_true',
87 help='Enabled sandboxing in the translator')
86 argparser.add_argument('--verbose', '-v', dest='verbose', 88 argparser.add_argument('--verbose', '-v', dest='verbose',
87 action='store_true', 89 action='store_true',
88 help='Display some extra debugging output') 90 help='Display some extra debugging output')
89 argparser.add_argument('--sz', dest='sz_args', action='append', default=[], 91 argparser.add_argument('--sz', dest='sz_args', action='append', default=[],
90 help='Extra arguments for Subzero') 92 help='Extra arguments for Subzero')
91 argparser.add_argument('--llc', dest='llc_args', action='append', 93 argparser.add_argument('--llc', dest='llc_args', action='append',
92 default=[], help='Extra arguments for llc') 94 default=[], help='Extra arguments for llc')
93 95
94 def main(): 96 def main():
95 """Create a hybrid translation from Subzero and llc. 97 """Create a hybrid translation from Subzero and llc.
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 145
144 def ProcessPexe(args, pexe, exe): 146 def ProcessPexe(args, pexe, exe):
145 [pexe_base, ext] = os.path.splitext(pexe) 147 [pexe_base, ext] = os.path.splitext(pexe)
146 if ext != '.pexe': 148 if ext != '.pexe':
147 pexe_base = pexe 149 pexe_base = pexe
148 pexe_base_unescaped = pexe_base 150 pexe_base_unescaped = pexe_base
149 pexe_base = pipes.quote(pexe_base) 151 pexe_base = pipes.quote(pexe_base)
150 pexe = pipes.quote(pexe) 152 pexe = pipes.quote(pexe)
151 153
152 nacl_root = FindBaseNaCl() 154 nacl_root = FindBaseNaCl()
155 path_addition = (
156 '{root}/toolchain/linux_x86/pnacl_newlib/bin'
157 ).format(root=nacl_root)
153 os.environ['PATH'] = ( 158 os.environ['PATH'] = (
154 '{root}/toolchain/linux_x86/pnacl_newlib/bin{sep}' + 159 '{dir}{sep}{path}'
155 '{path}' 160 ).format(dir=path_addition, sep=os.pathsep, path=os.environ['PATH'])
156 ).format(root=nacl_root, sep=os.pathsep, path=os.environ['PATH'])
157 obj_llc = pexe_base + '.llc.o' 161 obj_llc = pexe_base + '.llc.o'
158 obj_sz = pexe_base + '.sz.o' 162 obj_sz = pexe_base + '.sz.o'
159 asm_sz = pexe_base + '.sz.s' 163 asm_sz = pexe_base + '.sz.s'
160 obj_llc_weak = pexe_base + '.weak.llc.o' 164 obj_llc_weak = pexe_base + '.weak.llc.o'
161 obj_sz_weak = pexe_base + '.weak.sz.o' 165 obj_sz_weak = pexe_base + '.weak.sz.o'
162 obj_partial = obj_sz # overridden for hybrid mode 166 obj_partial = obj_sz # overridden for hybrid mode
163 sym_llc = pexe_base + '.sym.llc.txt' 167 sym_llc = pexe_base + '.sym.llc.txt'
164 sym_sz = pexe_base + '.sym.sz.txt' 168 sym_sz = pexe_base + '.sym.sz.txt'
165 sym_sz_unescaped = pexe_base_unescaped + '.sym.sz.txt' 169 sym_sz_unescaped = pexe_base_unescaped + '.sym.sz.txt'
166 whitelist_sz = pexe_base + '.wl.sz.txt' 170 whitelist_sz = pexe_base + '.wl.sz.txt'
167 whitelist_sz_unescaped = pexe_base_unescaped + '.wl.sz.txt' 171 whitelist_sz_unescaped = pexe_base_unescaped + '.wl.sz.txt'
168 llvm2ice = ( 172 llvm2ice = (
169 '{root}/toolchain_build/src/subzero/llvm2ice' 173 '{root}/toolchain_build/src/subzero/llvm2ice'
170 ).format(root=nacl_root) 174 ).format(root=nacl_root)
171 llcbin = ( 175 llcbin = 'llc'
172 '{root}/toolchain/linux_x86/pnacl_newlib/bin/llc' 176 gold = 'le32-nacl-ld.gold'
173 ).format(root=nacl_root)
174 opt_level = args.optlevel 177 opt_level = args.optlevel
175 opt_level_map = { 'm1':'0', '-1':'0', '0':'0', '1':'1', '2':'2' } 178 opt_level_map = { 'm1':'0', '-1':'0', '0':'0', '1':'1', '2':'2' }
176 hybrid = args.include or args.exclude 179 hybrid = args.include or args.exclude
177 180
178 if hybrid and (args.force or 181 if hybrid and (args.force or
179 NewerThanOrNotThere(pexe, obj_llc) or 182 NewerThanOrNotThere(pexe, obj_llc) or
180 NewerThanOrNotThere(llcbin, obj_llc)): 183 NewerThanOrNotThere(llcbin, obj_llc)):
181 # Only run pnacl-translate in hybrid mode. 184 # Only run pnacl-translate in hybrid mode.
182 shellcmd(['pnacl-translate', 185 shellcmd(['pnacl-translate',
186 '-split-module=1',
183 '-ffunction-sections', 187 '-ffunction-sections',
184 '-fdata-sections', 188 '-fdata-sections',
185 '-c', 189 '-c',
186 '-arch', 'x86-32-linux', 190 '-arch', 'x86-32' if args.sandbox else 'x86-32-linux',
187 '-O' + opt_level_map[opt_level], 191 '-O' + opt_level_map[opt_level],
188 '--pnacl-driver-append-LLC_FLAGS_EXTRA=-externalize', 192 '--pnacl-driver-append-LLC_FLAGS_EXTRA=-externalize',
189 '-o', obj_llc] + 193 '-o', obj_llc] +
194 (['--pnacl-driver-verbose'] if args.verbose else []) +
190 args.llc_args + 195 args.llc_args +
191 [pexe], 196 [pexe],
192 echo=args.verbose) 197 echo=args.verbose)
193 shellcmd(( 198 if not args.sandbox:
194 'objcopy --redefine-sym _start=_user_start {obj}' 199 shellcmd((
195 ).format(obj=obj_llc), echo=args.verbose) 200 'objcopy --redefine-sym _start=_user_start {obj}'
201 ).format(obj=obj_llc), echo=args.verbose)
196 # Generate llc syms file for consistency, even though it's not used. 202 # Generate llc syms file for consistency, even though it's not used.
197 shellcmd(( 203 shellcmd((
198 'nm {obj} | sed -n "s/.* [a-zA-Z] //p" > {sym}' 204 'nm {obj} | sed -n "s/.* [a-zA-Z] //p" > {sym}'
199 ).format(obj=obj_llc, sym=sym_llc), echo=args.verbose) 205 ).format(obj=obj_llc, sym=sym_llc), echo=args.verbose)
200 206
201 if (args.force or 207 if (args.force or
202 NewerThanOrNotThere(pexe, obj_sz) or 208 NewerThanOrNotThere(pexe, obj_sz) or
203 NewerThanOrNotThere(llvm2ice, obj_sz)): 209 NewerThanOrNotThere(llvm2ice, obj_sz)):
204 # Run llvm2ice regardless of hybrid mode. 210 # Run llvm2ice regardless of hybrid mode.
205 shellcmd([llvm2ice, 211 shellcmd([llvm2ice,
206 '-O' + opt_level, 212 '-O' + opt_level,
207 '-bitcode-format=pnacl', 213 '-bitcode-format=pnacl',
208 '-filetype=' + args.filetype, 214 '-filetype=' + args.filetype,
209 '-o', obj_sz if args.filetype == 'obj' else asm_sz] + 215 '-o', obj_sz if args.filetype == 'obj' else asm_sz] +
210 (['-externalize', 216 (['-externalize',
211 '-ffunction-sections', 217 '-ffunction-sections',
212 '-fdata-sections'] if hybrid else []) + 218 '-fdata-sections'] if hybrid else []) +
219 (['-sandbox'] if args.sandbox else []) +
213 args.sz_args + 220 args.sz_args +
214 [pexe], 221 [pexe],
215 echo=args.verbose) 222 echo=args.verbose)
216 if args.filetype != 'obj': 223 if args.filetype != 'obj':
217 shellcmd(( 224 shellcmd((
218 'llvm-mc -arch=x86 -filetype=obj -o {obj} {asm}' 225 'llvm-mc -triple={triple} -filetype=obj -o {obj} {asm}'
219 ).format(asm=asm_sz, obj=obj_sz), echo=args.verbose) 226 ).format(asm=asm_sz, obj=obj_sz,
220 shellcmd(( 227 triple='i686-nacl' if args.sandbox else 'i686'),
221 'objcopy --redefine-sym _start=_user_start {obj}' 228 echo=args.verbose)
222 ).format(obj=obj_sz), echo=args.verbose) 229 if not args.sandbox:
230 shellcmd((
231 'objcopy --redefine-sym _start=_user_start {obj}'
232 ).format(obj=obj_sz), echo=args.verbose)
223 if hybrid: 233 if hybrid:
224 shellcmd(( 234 shellcmd((
225 'nm {obj} | sed -n "s/.* [a-zA-Z] //p" > {sym}' 235 'nm {obj} | sed -n "s/.* [a-zA-Z] //p" > {sym}'
226 ).format(obj=obj_sz, sym=sym_sz), echo=args.verbose) 236 ).format(obj=obj_sz, sym=sym_sz), echo=args.verbose)
227 237
228 if hybrid: 238 if hybrid:
229 with open(sym_sz_unescaped) as f: 239 with open(sym_sz_unescaped) as f:
230 sz_syms = f.read().splitlines() 240 sz_syms = f.read().splitlines()
231 re_include_str = BuildRegex(args.include, sz_syms) 241 re_include_str = BuildRegex(args.include, sz_syms)
232 re_exclude_str = BuildRegex(args.exclude, sz_syms) 242 re_exclude_str = BuildRegex(args.exclude, sz_syms)
(...skipping 26 matching lines...) Expand all
259 ).format(obj=obj_llc, weak=obj_llc_weak), echo=args.verbose) 269 ).format(obj=obj_llc, weak=obj_llc_weak), echo=args.verbose)
260 obj_partial = pexe_base + '.o' 270 obj_partial = pexe_base + '.o'
261 shellcmd(( 271 shellcmd((
262 'ld -r -m elf_i386 -o {partial} {sz} {llc}' 272 'ld -r -m elf_i386 -o {partial} {sz} {llc}'
263 ).format(partial=obj_partial, sz=obj_sz_weak, llc=obj_llc_weak), 273 ).format(partial=obj_partial, sz=obj_sz_weak, llc=obj_llc_weak),
264 echo=args.verbose) 274 echo=args.verbose)
265 shellcmd(( 275 shellcmd((
266 'objcopy -w --localize-symbol="*" {partial}' 276 'objcopy -w --localize-symbol="*" {partial}'
267 ).format(partial=obj_partial), echo=args.verbose) 277 ).format(partial=obj_partial), echo=args.verbose)
268 shellcmd(( 278 shellcmd((
269 'objcopy --globalize-symbol=_user_start {partial}' 279 'objcopy --globalize-symbol={start} {partial}'
270 ).format(partial=obj_partial), echo=args.verbose) 280 ).format(partial=obj_partial,
281 start='_start' if args.sandbox else '_user_start'),
282 echo=args.verbose)
271 283
272 # Run the linker regardless of hybrid mode. 284 # Run the linker regardless of hybrid mode.
273 linker = ( 285 linker = (
274 '{root}/../third_party/llvm-build/Release+Asserts/bin/clang' 286 '{root}/../third_party/llvm-build/Release+Asserts/bin/clang'
275 ).format(root=nacl_root) 287 ).format(root=nacl_root)
276 shellcmd(( 288 if args.sandbox:
277 '{ld} -m32 {partial} -o {exe} -O{opt_level} ' + 289 linklib = ('{root}/toolchain/linux_x86/pnacl_newlib/translator/' +
278 # Keep the rest of this command line (except szrt.c) in sync 290 'x86-32/lib').format(root=nacl_root)
279 # with RunHostLD() in pnacl-translate.py. 291 shellcmd((
280 '{root}/toolchain/linux_x86/pnacl_newlib/translator/x86-32-linux/lib/' + 292 '{gold} -nostdlib --no-fix-cortex-a8 --eh-frame-hdr -z text ' +
281 '{{unsandboxed_irt,irt_random,irt_query_list}}.o ' + 293 '--build-id --entry=__pnacl_start -static ' +
282 '{root}/toolchain_build/src/subzero/runtime/szrt.c ' + 294 '{linklib}/crtbegin.o {partial} ' +
283 '{root}/toolchain_build/src/subzero/runtime/szrt_i686.ll ' + 295 '{root}/toolchain_build/src/subzero/build/runtime/' +
284 '-lpthread -lrt' 296 'szrt_sb_x8632.o ' +
285 ).format(ld=linker, partial=obj_partial, exe=exe, 297 '{linklib}/libpnacl_irt_shim_dummy.a --start-group ' +
286 opt_level=opt_level_map[opt_level], root=nacl_root), 298 '{linklib}/libgcc.a {linklib}/libcrt_platform.a ' +
287 echo=args.verbose) 299 '--end-group {linklib}/crtend.o --undefined=_start ' +
300 '-o {exe}'
301 ).format(gold=gold, linklib=linklib, partial=obj_partial, exe=exe,
302 root=nacl_root),
303 echo=args.verbose)
304 else:
305 shellcmd((
306 '{ld} -m32 {partial} -o {exe} ' +
307 # Keep the rest of this command line (except szrt_native_x8632.o) in
308 # sync with RunHostLD() in pnacl-translate.py.
309 '{root}/toolchain/linux_x86/pnacl_newlib/translator/x86-32-linux/' +
310 'lib/{{unsandboxed_irt,irt_random,irt_query_list}}.o ' +
311 '{root}/toolchain_build/src/subzero/build/runtime/' +
312 'szrt_native_x8632.o -lpthread -lrt'
313 ).format(ld=linker, partial=obj_partial, exe=exe, root=nacl_root),
314 echo=args.verbose)
288 315
289 # Put the extra verbose printing at the end. 316 # Put the extra verbose printing at the end.
290 if args.verbose: 317 if args.verbose:
291 print 'PATH={path}'.format(path=os.environ['PATH']) 318 print 'PATH: {path}'.format(path=path_addition)
292 if hybrid: 319 if hybrid:
293 print 'include={regex}'.format(regex=re_include_str) 320 print 'include={regex}'.format(regex=re_include_str)
294 print 'exclude={regex}'.format(regex=re_exclude_str) 321 print 'exclude={regex}'.format(regex=re_exclude_str)
295 print 'default_match={dm}'.format(dm=default_match) 322 print 'default_match={dm}'.format(dm=default_match)
296 print 'Number of Subzero syms = {num}'.format(num=len(sz_syms)) 323 print 'Number of Subzero syms = {num}'.format(num=len(sz_syms))
297 324
298 if __name__ == '__main__': 325 if __name__ == '__main__':
299 main() 326 main()
OLDNEW
« no previous file with comments | « pydir/crosstest.py ('k') | pydir/szbuild_spec2k.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698