def BuildAndInstall_libgcc_s(): arch = 'arm' project = 'libgcc' tcpath = GetToolchainPath(arch, 'bionic') # Remove temp copy of libgcc.a, it get's installed at the end os.remove(os.path.join(tcpath, 'arm-nacl', 'lib', 'libgcc.a')) # Prep work path workpath = os.path.join(TOOLCHAIN_BUILD_OUT, 'gcc_$GCC_bionic_work') workpath = ReplaceArch(workpath, arch) dstpath = ReplaceArch(os.path.join(workpath, '$NACL-nacl/libgcc'), arch) # Prep install path inspath = os.path.join(TOOLCHAIN_BUILD_OUT, 'gcc_$GCC_bionic_install') inspath = ReplaceArch(inspath, arch) MakeGCCProject(arch, project, dstpath) MakeGCCProject(arch, project, dstpath, ['install']) UpdateFromTo(os.path.join(inspath, 'lib', 'gcc'), os.path.join(tcpath, 'lib', 'gcc'), filters=['*.o']) UpdateFromTo(os.path.join(inspath, 'lib', 'libgcc_s.so.1'), os.path.join(tcpath, 'arm-nacl', 'lib', 'libgcc_s.so.1')) UpdateFromTo(os.path.join(inspath, 'lib', 'libgcc_s.so'), os.path.join(tcpath, 'arm-nacl', 'lib', 'libgcc_s.so'))
def ConfigureAndBuild_libstdcpp(): arch = 'arm' project = 'libstdc++' tcpath = GetToolchainPath(arch, 'bionic') # Prep work path workpath = os.path.join(TOOLCHAIN_BUILD_OUT, 'gcc_$GCC_bionic_work') workpath = ReplaceArch(workpath, arch) # Prep install path inspath = os.path.join(TOOLCHAIN_BUILD_OUT, 'gcc_$GCC_bionic_install') inspath = ReplaceArch(inspath, arch) dstpath = ReplaceArch(os.path.join(workpath, '$NACL-nacl/libstdc++-v3'), arch) Mkdir(dstpath) cfg = [ '../../../../src/gcc_libs/libstdc++-v3/configure', '--host=arm-nacl', '--build=i686-linux', '--target=arm-nacl', '--enable-shared', '--with-newlib', '--disable-libstdcxx-pch', '--enable-shared-libgcc', '--with-dwarf3', '--prefix=' + inspath, 'CFLAGS=-I../../../gcc_lib_arm_work' ] ConfigureGCCProject(arch, project, cfg, dstpath, inspath) MakeGCCProject(arch, project, dstpath) MakeGCCProject(arch, project, dstpath, ['install']) UpdateFromTo(os.path.join(inspath, 'lib'), os.path.join(tcpath, 'arm-nacl', 'lib')) UpdateFromTo(os.path.join(inspath, 'include'), os.path.join(tcpath, 'arm-nacl', 'include'))
def ConfigureAndBuildArmCXX(config=False): arch = 'arm' project = 'libstdc++' tcpath = os.path.join(TOOLCHAIN, 'linux_$ARCH_bionic') tcpath = ReplaceArch(tcpath, arch) # Prep work path workpath = os.path.join(TOOLCHAIN_BUILD_OUT, 'cxx_$GCC_bionic_work') workpath = ReplaceArch(workpath, arch) Mkdir(workpath) Symlink('../gcc_libs_arm_work/gcc', os.path.join(workpath, 'gcc')) # Prep install path inspath = os.path.join(TOOLCHAIN_BUILD_OUT, 'cxx_$GCC_bionic_install') inspath = ReplaceArch(inspath, arch) dstpath = ReplaceArch(os.path.join(workpath, '$NACL-nacl/libstdc++-v3'), arch) Mkdir(dstpath) cfg = [ '../../../../src/gcc_libs/libstdc++-v3/configure', '--host=arm-nacl', '--build=i686-linux', '--target=arm-nacl', '--enable-shared', '--with-newlib', '--disable-libstdcxx-pch', '--enable-shared-libgcc', '--with-dwarf3', '--prefix=' + inspath, 'CFLAGS=-I../../../gcc_lib_arm_work' ] ConfigureAndInstallForGCC(arch, project, cfg, dstpath, inspath) UpdateFromTo(os.path.join(inspath, 'lib'), os.path.join(tcpath, 'arm-nacl', 'lib')) UpdateFromTo(os.path.join(inspath, 'include'), os.path.join(tcpath, 'arm-nacl', 'include'))
def ConfigureAndBuild_libgcc(config=False): arch = 'arm' project = 'libgcc' tcpath = GetToolchainPath(arch, 'bionic') # Prep work path workpath = os.path.join(TOOLCHAIN_BUILD_OUT, 'gcc_$GCC_bionic_work') workpath = ReplaceArch(workpath, arch) Mkdir(workpath) Symlink('../gcc_libs_arm_work/gcc', os.path.join(workpath, 'gcc')) # Prep install path inspath = os.path.join(TOOLCHAIN_BUILD_OUT, 'gcc_$GCC_bionic_install') inspath = ReplaceArch(inspath, arch) dstpath = ReplaceArch(os.path.join(workpath, '$NACL-nacl/libgcc'), arch) cfg = [ '../../../../src/gcc_libs/libgcc/configure', '--host=arm-nacl', '--build=i686-linux', '--target=arm-nacl', '--enable-shared', '--enable-shared-libgcc', '--with-dwarf3', '--with-newlib', '--prefix=' + inspath, 'CFLAGS=-I../../../gcc_lib_arm_work' ] ConfigureGCCProject(arch, project, cfg, dstpath, inspath) MakeGCCProject(arch, project, dstpath, ['libgcc.a']) # Copy temp version of libgcc.a for linking libc.so UpdateFromTo(os.path.join(dstpath, 'libgcc.a'), os.path.join(tcpath, 'arm-nacl', 'lib', 'libgcc.a'))
def UpdateNaClHeaders(out_path, libc, arch): modified = False for src, dst in NACL_HEADER_MAP[libc]: src_path = os.path.join(NACL_DIR, src) dst_path = os.path.join(out_path, arch + '-nacl', 'include', dst) modifed = modified or UpdateFromTo(src_path, dst_path) return modified
def ConfigureAndBuild(arch, project, workpath, inspath, tcpath=None): # Create project for CRTx and LIBC files print 'Configure %s for %s.\n' % (project, arch) srcpath = os.path.join(TOOLCHAIN_BUILD_SRC, project) dstpath = ReplaceArch(os.path.join(workpath, '$NACL-nacl', project), arch) libpath = ReplaceArch(os.path.join(inspath, '$NACL-nacl', 'lib'), arch) CreateProject(arch, srcpath, dstpath, libpath) print 'Building %s for %s at %s.' % (project, arch, dstpath) if process.Run(['make', '-j12', 'V=1'], cwd=dstpath, outfile=sys.stdout): raise RuntimeError('Failed to build %s for %s.\n' % (project, arch)) if tcpath: UpdateFromTo(inspath, tcpath) print 'Done with %s for %s.\n' % (project, arch)
def CompileCrt(out_path, libc, sub_arches): modified = False for sub_arch in sub_arches: cc = os.path.join(out_path, 'bin', sub_arch + '-nacl-gcc') for src, dst in NACL_CRT_MAP[sub_arch]: src_path = os.path.join(NACL_DIR, src) dst_path = os.path.join(out_path, dst) if not NeedsUpdate(src_path, dst_path): continue if src.endswith('.x'): UpdateFromTo(src_path, dst_path) else: args = [cc, '-c', src_path, '-o', dst_path] subprocess.call(args) modified = True return modified
def CreateBasicToolchain(): # Create a toolchain directory containing only the toolchain binaries and # basic files line nacl_arm_macros.s. arch = 'arm' UpdateFromTo( GetToolchainPath(arch, 'newlib'), GetToolchainPath(arch, 'bionic'), filters=['*arm-nacl/include*', '*arm-nacl/lib*', '*.a', '*.o']) UpdateFromTo(GetToolchainPath(arch, 'newlib'), GetToolchainPath(arch, 'bionic'), paterns=['*.s']) # Static build uses: # crt1.o crti.o 4.8.2/crtbeginT.o ... 4.8.2/crtend.o crtn.o # -shared build uses: # crti.o 4.8.2/crtbeginS.o ... 4.8.2/crtendS.o crtn.o crtn.o # However we only provide a crtbegin(S) and crtend(S) EMPTY = """/* * This is a dummy linker script. * libnacl.a, libcrt_common.a, crt0.o crt1.o crti.o and crtn.o are all * empty. Instead all the work is done by crtbegin(S).o and crtend(S).o and * the bionic libc. These are provided for compatability with the newlib * toolchain binaries. */""" EMPTY_FILES = [ 'crt0.o', 'crt1.o', 'crti.o', 'crtn.o', 'libnacl.a', 'libcrt_common.a', 'libpthread.a' ] # Bionic uses the following include paths BIONIC_PAIRS = [ ('bionic/libc/arch-nacl/syscalls/irt_poll.h', '$NACL-nacl/include/irt_poll.h'), ('bionic/libc/arch-nacl/syscalls/irt_socket.h', '$NACL-nacl/include/irt_socket.h'), ('bionic/libc/include', '$NACL-nacl/include'), ('bionic/libc/arch-nacl/syscalls/nacl_stat.h', '$NACL-nacl/include/nacl_stat.h'), ('bionic/libc/arch-$ARCH/include/machine', '$NACL-nacl/include/machine'), ('bionic/libc/kernel/common', '$NACL-nacl/include'), ('bionic/libc/kernel/arch-$ARCH/asm', '$NACL-nacl/include/asm'), ('bionic/libm/include', '$NACL-nacl/include'), ('bionic/libm/$CPU', '$NACL-nacl/include'), ('bionic/safe-iop/include', '$NACL-nacl/include'), ('bionic/libstdc++/nacl', '$NACL-nacl/include/c++/4.8.2/$NACL-nacl'), ('bionic/nacl/$ARCH', '.'), ] for arch in ARCHES: for name in ['irt.h', 'irt_dev.h']: src = os.path.join(NATIVE_CLIENT, 'src', 'untrusted', 'irt', name) dst = GetToolchainPath(arch, 'bionic', '$NACL-nacl', 'include', name) MungeIRT(src, ReplaceArch(dst, arch)) inspath = GetToolchainPath(arch, 'bionic') inspath = ReplaceArch(inspath, arch) # Create empty objects and libraries libpath = ReplaceArch(os.path.join(inspath, '$NACL-nacl', 'lib'), arch) for name in EMPTY_FILES: UpdateText(os.path.join(libpath, name), EMPTY) # Copy BIONIC files to toolchain for src, dst in BIONIC_PAIRS: srcpath = ReplaceArch(os.path.join(TOOLCHAIN_BUILD_SRC, src), arch) dstpath = ReplaceArch(os.path.join(inspath, dst), arch) UpdateFromTo(srcpath, dstpath) # Build specs file gcc = ReplaceArch(os.path.join(inspath, 'bin', '$NACL-nacl-gcc'), arch) lib = ReplaceArch(os.path.join(inspath, 'lib/gcc/$NACL-nacl/$VER'), arch) specs = os.path.join(lib, 'specs') with open(specs, 'w') as specfile: process.Run([gcc, '-dumpspecs'], cwd=None, shell=False, outfile=specfile, verbose=False) text = open(specs, 'r').read() # Replace items in the spec file text = ReplaceText(text, [{ '-lgcc': '-lgcc --as-needed %{!static: -lgcc_s} --no-as-needed %{!shared: -lgcc_eh}', '--hash-style=gnu': '--hash-style=sysv', }]) open(specs, 'w').write(text)
def CreateBasicToolchain(): # Create a toolchain directory containing only the toolchain binaries and # basic files line nacl_arm_macros.s. UpdateFromTo( ARM_NEWLIB, ARM_BIONIC, filters=['*arm-nacl/include*', '*arm-nacl/lib*', '*.a', '*.o']) UpdateFromTo(ARM_NEWLIB, ARM_BIONIC, paterns=['*.s']) UpdateFromTo(X86_NEWLIB, X86_BIONIC, filters=['*x86_64-nacl/include*', '*x86_64-nacl/lib*', '*.o']) UpdateFromTo(X86_NEWLIB, X86_BIONIC, paterns=['*.s']) # Static build uses: # crt1.o crti.o 4.8.2/crtbeginT.o ... 4.8.2/crtend.o crtn.o # -shared build uses: # crti.o 4.8.2/crtbeginS.o ... 4.8.2/crtendS.o crtn.o crtn.o # However we only provide a crtbegin(S) and crtend(S) EMPTY = """/* * This is a dummy linker script. * libnacl.a, libcrt_common.a, crt0.o crt1.o crti.o and crtn.o are all * empty. Instead all the work is done by crtbegin(S).o and crtend(S).o and * the bionic libc. These are provided for compatability with the newlib * toolchain binaries. */""" EMPTY_FILES = [ 'crt0.o', 'crt1.o', 'crti.o', 'crtn.o', 'libnacl.a', 'libcrt_common.a', 'libpthread.a' ] # Bionic uses the following include paths BIONIC_PAIRS = [ ('bionic/libc/include', '$NACL-nacl/include'), ('bionic/libc/arch-nacl/syscalls/irt.h', '$NACL-nacl/include/irt.h'), ('bionic/libc/arch-nacl/syscalls/irt_syscalls.h', '$NACL-nacl/include/irt_syscalls.h'), ('bionic/libc/arch-nacl/syscalls/nacl_stat.h', '$NACL-nacl/include/nacl_stat.h'), ('../../src/untrusted/irt/irt_dev.h', '$NACL-nacl/include/irt_dev.h'), ('bionic/libc/arch-$ARCH/include/machine', '$NACL-nacl/include/machine'), ('bionic/libc/kernel/common', '$NACL-nacl/include'), ('bionic/libc/kernel/arch-$ARCH/asm', '$NACL-nacl/include/asm'), ('bionic/libm/include', '$NACL-nacl/include'), ('bionic/libm/$CPU', '$NACL-nacl/include'), ('bionic/safe-iop/include', '$NACL-nacl/include'), ('bionic/libstdc++/nacl', '$NACL-nacl/include/c++/4.8.2/$NACL-nacl'), ('bionic/nacl/$ARCH', '.'), ] for arch in ARCHES: inspath = os.path.join(TOOLCHAIN, 'linux_$ARCH_bionic') inspath = ReplaceArch(inspath, arch) # Create empty objects and libraries libpath = ReplaceArch(os.path.join(inspath, '$NACL-nacl', 'lib'), arch) for name in EMPTY_FILES: UpdateText(os.path.join(libpath, name), EMPTY) # Copy BIONIC files to toolchain for src, dst in BIONIC_PAIRS: srcpath = ReplaceArch(os.path.join(TOOLCHAIN_BUILD_SRC, src), arch) dstpath = ReplaceArch(os.path.join(inspath, dst), arch) UpdateFromTo(srcpath, dstpath) workpath = os.path.join(TOOLCHAIN_BUILD_OUT, 'bionic_$ARCH_work') workpath = ReplaceArch(workpath, arch) ConfigureAndBuild(arch, 'bionic/libc', workpath, inspath) ConfigureAndBuild(arch, 'bionic/libm', workpath, inspath) # ConfigureAndBuild(arch, 'bionic/linker', workpath, inspath) # Build specs file gcc = ReplaceArch(os.path.join(inspath, 'bin', '$NACL-nacl-gcc'), arch) lib = ReplaceArch(os.path.join(inspath, 'lib/gcc/$NACL-nacl/$VER'), arch) specs = os.path.join(lib, 'specs') with open(specs, 'w') as specfile: process.Run([gcc, '-dumpspecs'], cwd=None, shell=False, outfile=specfile, verbose=False) text = open(specs, 'r').read() text = ReplaceText(text, [{'-lgcc': '-lgcc %{!shared: -lgcc_eh}'}]) open(specs, 'w').write(text)