Commit 050deaa6 by Jan Voung

Build ARM SZ runtime files. Use le32-nacl-objcopy in various places.

Use PNaCl built binutils, which is known to support ARM and MIPS. Otherwise the system-provided binutils may or may not have that support (mine did not and perhaps expected a prefix like arm-xxx-objcopy for the version that did support arm). Split off from CL to run crosstests for ARM under qemu. BUG= https://code.google.com/p/nativeclient/issues/detail?id=4076 R=jpp@chromium.org, stichnot@chromium.org Review URL: https://codereview.chromium.org/1185703006.
parent 0933c0cf
......@@ -278,7 +278,8 @@ $(OBJDIR)/unittest: $(OBJDIR)
@mkdir -p $@
RT_SRC := runtime/szrt.c runtime/szrt_ll.ll runtime/szrt_profiler.c
RT_OBJ := build/runtime/szrt_native_x8632.o build/runtime/szrt_sb_x8632.o
RT_OBJ := build/runtime/szrt_native_x8632.o build/runtime/szrt_sb_x8632.o \
build/runtime/szrt_native_arm32.o build/runtime/szrt_sb_arm32.o
runtime: $(RT_OBJ)
......
#!/usr/bin/env python2
import argparse
from collections import namedtuple
import os
import shutil
import tempfile
......@@ -22,7 +23,7 @@ def Translate(ll_files, extra_args, obj, verbose):
'-bitcode-format=llvm',
'-o', obj
] + extra_args, echo=verbose)
shellcmd(['objcopy',
shellcmd(['le32-nacl-objcopy',
'--strip-symbol=nacl_tp_tdb_offset',
'--strip-symbol=nacl_tp_tls_offset',
obj
......@@ -30,11 +31,53 @@ def Translate(ll_files, extra_args, obj, verbose):
def PartialLink(obj_files, extra_args, lib, verbose):
"""Partially links a set of obj files into a final obj library."""
shellcmd(['ld',
shellcmd(['le32-nacl-ld',
'-o', lib,
'-r',
] + extra_args + obj_files, echo=verbose)
TargetInfo = namedtuple('TargetInfo',
['target', 'triple', 'llc_flags', 'ld_emu'])
def MakeRuntimesForTarget(target_info, ll_files,
srcdir, tempdir, rtdir, verbose):
def TmpFile(template):
return template.format(dir=tempdir, target=target_info.target)
def OutFile(template):
return template.format(rtdir=rtdir, target=target_info.target)
# Translate tempdir/szrt.ll and tempdir/szrt_ll.ll to
# szrt_native_{target}.tmp.o.
Translate(ll_files,
['-mtriple=' + target_info.triple] + target_info.llc_flags,
TmpFile('{dir}/szrt_native_{target}.tmp.o'),
verbose)
# Compile srcdir/szrt_profiler.c to tempdir/szrt_profiler_native_{target}.o
shellcmd(['clang',
'-O2',
'-target=' + target_info.triple,
'-c',
'{srcdir}/szrt_profiler.c'.format(srcdir=srcdir),
'-o', TmpFile('{dir}/szrt_profiler_native_{target}.o')
], echo=verbose)
# Writing full szrt_native_{target}.o.
PartialLink([TmpFile('{dir}/szrt_native_{target}.tmp.o'),
TmpFile('{dir}/szrt_profiler_native_{target}.o')],
['-m {ld_emu}'.format(ld_emu=target_info.ld_emu)],
OutFile('{rtdir}/szrt_native_{target}.o'),
verbose)
# Translate tempdir/szrt.ll and tempdir/szrt_ll.ll to szrt_sb_{target}.o
# The sandboxed library does not get the profiler helper function as the
# binaries are linked with -nostdlib.
Translate(ll_files,
['-mtriple=' + target_info.triple.replace('linux', 'nacl')] +
target_info.llc_flags,
OutFile('{rtdir}/szrt_sb_{target}.o'),
verbose)
def main():
"""Build the Subzero runtime support library for all architectures.
"""
......@@ -80,33 +123,21 @@ def main():
ll_files = ['{dir}/szrt.ll'.format(dir=tempdir),
'{srcdir}/szrt_ll.ll'.format(srcdir=srcdir)]
# Translate tempdir/szrt.ll and tempdir/szrt_ll.ll to
# szrt_native_x8632.tmp.o.
Translate(ll_files,
['-mtriple=i686', '-mcpu=pentium4m'],
'{dir}/szrt_native_x8632.tmp.o'.format(dir=tempdir),
args.verbose)
# Compile srcdir/szrt_profiler.c to tempdir/szrt_profiler_native_i686.o
shellcmd(['clang',
'-O2',
'-target=i686',
'-c',
'{srcdir}/szrt_profiler.c'.format(srcdir=srcdir),
'-o', '{dir}/szrt_profiler_native_x8632.o'.format(dir=tempdir)
], echo=args.verbose)
# Writing full szrt_native_i686.o.
PartialLink(['{dir}/szrt_native_x8632.tmp.o'.format(dir=tempdir),
'{dir}/szrt_profiler_native_x8632.o'.format(dir=tempdir)
], ['-m elf_i386'],
'{rtdir}/szrt_native_x8632.o'.format(rtdir=rtdir), args.verbose)
x8632_target = TargetInfo(target='x8632',
triple='i686-none-linux',
llc_flags=['-mcpu=pentium4m'],
ld_emu='elf_i386_nacl')
MakeRuntimesForTarget(x8632_target, ll_files,
srcdir, tempdir, rtdir, args.verbose)
arm32_target = TargetInfo(target='arm32',
triple='armv7a-none-linux-gnueabihf',
llc_flags=['-mcpu=cortex-a9',
'-float-abi=hard',
'-mattr=+neon'],
ld_emu='armelf_nacl')
MakeRuntimesForTarget(arm32_target, ll_files,
srcdir, tempdir, rtdir, args.verbose)
# Translate tempdir/szrt.ll and tempdir/szrt_ll.ll to szrt_sb_x8632.o
# The sandboxed library does not get the profiler helper function as the
# binaries are linked with -nostdlib.
Translate(ll_files,
['-mtriple=i686-nacl', '-mcpu=pentium4m'],
'{rtdir}/szrt_sb_x8632.o'.format(rtdir=rtdir),
args.verbose)
finally:
try:
shutil.rmtree(tempdir)
......
......@@ -131,7 +131,8 @@ def main():
# currently the only situation where multiple translated files are
# linked into the executable, but when PNaCl supports shared nexe
# libraries, this would need to change.
shellcmd(['objcopy', '--weaken-symbol=__Sz_block_profile_info', obj_sz])
shellcmd(['{bin}/le32-nacl-objcopy'.format(bin=bindir),
'--weaken-symbol=__Sz_block_profile_info', obj_sz])
objs.append(obj_sz)
if args.crosstest_bitcode:
shellcmd(['{bin}/pnacl-llc'.format(bin=bindir),
......
......@@ -177,6 +177,7 @@ def ProcessPexe(args, pexe, exe):
).format(root=nacl_root)
llcbin = '{base}/pnacl-llc'.format(base=path_addition)
gold = 'le32-nacl-ld.gold'
objcopy = 'le32-nacl-objcopy'
opt_level = args.optlevel
opt_level_map = { 'm1':'0', '-1':'0', '0':'0', '1':'1', '2':'2' }
hybrid = args.include or args.exclude
......@@ -200,8 +201,8 @@ def ProcessPexe(args, pexe, exe):
echo=args.verbose)
if not args.sandbox:
shellcmd((
'objcopy --redefine-sym _start=_user_start {obj}'
).format(obj=obj_llc), echo=args.verbose)
'{objcopy} --redefine-sym _start=_user_start {obj}'
).format(objcopy=objcopy, obj=obj_llc), echo=args.verbose)
# Generate llc syms file for consistency, even though it's not used.
shellcmd((
'nm {obj} | sed -n "s/.* [a-zA-Z] //p" > {sym}'
......@@ -233,8 +234,8 @@ def ProcessPexe(args, pexe, exe):
echo=args.verbose)
if not args.sandbox:
shellcmd((
'objcopy --redefine-sym _start=_user_start {obj}'
).format(obj=obj_sz), echo=args.verbose)
'{objcopy} --redefine-sym _start=_user_start {obj}'
).format(objcopy=objcopy, obj=obj_sz), echo=args.verbose)
if hybrid:
shellcmd((
'nm {obj} | sed -n "s/.* [a-zA-Z] //p" > {sym}'
......@@ -259,30 +260,34 @@ def ProcessPexe(args, pexe, exe):
f.write(sym + '\n')
whitelist_has_items = True
shellcmd((
'objcopy --weaken {obj} {weak}'
).format(obj=obj_sz, weak=obj_sz_weak), echo=args.verbose)
'{objcopy} --weaken {obj} {weak}'
).format(objcopy=objcopy, obj=obj_sz, weak=obj_sz_weak),
echo=args.verbose)
if whitelist_has_items:
# objcopy returns an error if the --weaken-symbols file is empty.
shellcmd((
'objcopy --weaken-symbols={whitelist} {obj} {weak}'
).format(whitelist=whitelist_sz, obj=obj_llc,
'{objcopy} --weaken-symbols={whitelist} {obj} {weak}'
).format(objcopy=objcopy,
whitelist=whitelist_sz, obj=obj_llc,
weak=obj_llc_weak),
echo=args.verbose)
else:
shellcmd((
'objcopy {obj} {weak}'
).format(obj=obj_llc, weak=obj_llc_weak), echo=args.verbose)
'{objcopy} {obj} {weak}'
).format(objcopy=objcopy, obj=obj_llc, weak=obj_llc_weak),
echo=args.verbose)
obj_partial = pexe_base + '.o'
shellcmd((
'ld -r -m elf_i386 -o {partial} {sz} {llc}'
).format(partial=obj_partial, sz=obj_sz_weak, llc=obj_llc_weak),
echo=args.verbose)
shellcmd((
'objcopy -w --localize-symbol="*" {partial}'
).format(partial=obj_partial), echo=args.verbose)
'{objcopy} -w --localize-symbol="*" {partial}'
).format(objcopy=objcopy, partial=obj_partial),
echo=args.verbose)
shellcmd((
'objcopy --globalize-symbol={start} {partial}'
).format(partial=obj_partial,
'{objcopy} --globalize-symbol={start} {partial}'
).format(objcopy=objcopy, partial=obj_partial,
start='_start' if args.sandbox else '_user_start'),
echo=args.verbose)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment