Commit 2e7efaf1 authored by mcgrathr@chromium.org's avatar mcgrathr@chromium.org

Use nacl_helper_bootstrap from native_client repository

These sources have been moved over to the native_client repository.
Remove them from chromium/src altogether and just make the gyp files
refer to the native_client stuff.

BUG= none
TEST= linux still builds

R=sehr@google.com,noelallen@chromium.org

Review URL: http://codereview.chromium.org/8799016

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@113074 0039d316-1c4b-4281-b951-d872f2087c98
parent 00d41a8f
......@@ -33,6 +33,7 @@ vars = {
"libjingle_revision": "95",
"libphonenumber_revision": "407",
"libvpx_revision": "109236",
"lss_revision": "9",
"ffmpeg_revision": "112050",
"sfntly_revision": "111",
"skia_revision": "2785",
......@@ -402,7 +403,8 @@ deps_os = {
"/trunk/deps/third_party/swig/linux@" + Var("swig_revision"),
"src/third_party/lss":
(Var("googlecode_url") % "linux-syscall-support") + "/trunk/lss@8",
((Var("googlecode_url") % "linux-syscall-support") + "/trunk/lss@" +
Var("lss_revision")),
"src/third_party/openssl":
"/trunk/deps/third_party/openssl@105093",
......
......@@ -418,7 +418,7 @@
# For now, do not build nacl_helper when disable_nacl=1
['disable_nacl!=1', {
'dependencies': [
'nacl_helper_bootstrap',
'../native_client/src/trusted/service_runtime/linux/nacl_bootstrap.gyp:nacl_helper_bootstrap',
'nacl_helper',
],
}],
......
......@@ -187,166 +187,6 @@
'ldflags': ['-pie'],
},
},
{
'target_name': 'nacl_helper_bootstrap_munge_phdr',
'type': 'executable',
'toolsets': ['host'],
'sources': [
'nacl/nacl_helper_bootstrap_munge_phdr.c',
],
'libraries': [
'-lelf',
],
# This is an ugly kludge because gyp doesn't actually treat
# host_arch=x64 target_arch=ia32 as proper cross compilation.
# It still wants to compile the "host" program with -m32 et
# al. Though a program built that way can indeed run on the
# x86-64 host, we cannot reliably build this program on such a
# host because Ubuntu does not provide the full suite of
# x86-32 libraries in packages that can be installed on an
# x86-64 host; in particular, libelf is missing. So here we
# use the hack of eliding all the -m* flags from the
# compilation lines, getting the command close to what they
# would be if gyp were to really build properly for the host.
# TODO(bradnelson): Clean up with proper cross support.
'conditions': [
['host_arch=="x64"', {
'cflags/': [['exclude', '-m.*']],
'ldflags/': [['exclude', '-m.*']],
}],
],
},
{
'target_name': 'nacl_helper_bootstrap_lib',
'type': 'static_library',
'product_dir': '<(SHARED_INTERMEDIATE_DIR)/chrome',
'hard_depencency': 1,
'include_dirs': [
'..',
],
'sources': [
'nacl/nacl_helper_bootstrap_linux.c',
],
'cflags': [
# The tiny standalone bootstrap program is incompatible with
# -fstack-protector, which might be on by default. That switch
# requires using the standard libc startup code, which we do not.
'-fno-stack-protector',
# We don't want to compile it PIC (or its cousin PIE), because
# it goes at an absolute address anyway, and because any kind
# of PIC complicates life for the x86-32 assembly code. We
# append -fno-* flags here instead of using a 'cflags!' stanza
# to remove -f* flags, just in case some system's compiler
# defaults to using PIC for everything.
'-fno-pic', '-fno-PIC',
'-fno-pie', '-fno-PIE',
],
'cflags!': [
# TODO(glider): -fasan is deprecated.
'-fasan',
'-faddress-sanitizer',
'-w',
],
'conditions': [
['clang==1', {
'cflags': [
# Prevent llvm-opt from replacing my_bzero with a call
# to memset
'-ffreestanding',
# But make its <limits.h> still work!
'-U__STDC_HOSTED__', '-D__STDC_HOSTED__=1',
],
}],
],
},
{
'target_name': 'nacl_helper_bootstrap_raw',
'type': 'none',
'dependencies': [
'nacl_helper_bootstrap_lib',
],
'actions': [
{
'action_name': 'link_with_ld_bfd',
'variables': {
'bootstrap_lib': '<(SHARED_INTERMEDIATE_DIR)/chrome/<(STATIC_LIB_PREFIX)nacl_helper_bootstrap_lib<(STATIC_LIB_SUFFIX)',
'linker_script': 'nacl/nacl_helper_bootstrap_linux.x',
},
'inputs': [
'<(linker_script)',
'<(bootstrap_lib)',
'../tools/ld_bfd/ld',
],
'outputs': [
'<(PRODUCT_DIR)/nacl_helper_bootstrap_raw',
],
'message': 'Linking nacl_helper_bootstrap_raw',
'conditions': [
['target_arch=="x64"', {
'variables': {
'linker_emulation': 'elf_x86_64',
'bootstrap_extra_lib': '',
}
}],
['target_arch=="ia32"', {
'variables': {
'linker_emulation': 'elf_i386',
'bootstrap_extra_lib': '',
}
}],
['target_arch=="arm"', {
'variables': {
'linker_emulation': 'armelf_linux_eabi',
# ARM requires linking against libc due to ABI
# dependencies on memset.
'bootstrap_extra_lib' : "${SYSROOT}/usr/lib/libc.a",
}
}],
],
'action': ['../tools/ld_bfd/ld',
'-m', '<(linker_emulation)',
'--build-id',
# This program is (almost) entirely
# standalone. It has its own startup code, so
# no crt1.o for it. It is statically linked,
# and on x86 it does not use libc at all.
# However, on ARM it needs a few (safe) things
# from libc.
'-static',
# Link with custom linker script for special
# layout. The script uses the symbol RESERVE_TOP.
'<@(nacl_reserve_top)',
'--script=<(linker_script)',
'-o', '<@(_outputs)',
# On x86-64, the default page size with some
# linkers is 2M rather than the real Linux page
# size of 4K. A larger page size is incompatible
# with our custom linker script's special layout.
'-z', 'max-page-size=0x1000',
'--whole-archive', '<(bootstrap_lib)',
'--no-whole-archive',
'<@(bootstrap_extra_lib)',
],
}
],
},
{
'target_name': 'nacl_helper_bootstrap',
'dependencies': [
'nacl_helper_bootstrap_raw',
'nacl_helper_bootstrap_munge_phdr#host',
],
'type': 'none',
'actions': [{
'action_name': 'munge_phdr',
'inputs': ['nacl/nacl_helper_bootstrap_munge_phdr.py',
'<(PRODUCT_DIR)/nacl_helper_bootstrap_munge_phdr',
'<(PRODUCT_DIR)/nacl_helper_bootstrap_raw'],
'outputs': ['<(PRODUCT_DIR)/nacl_helper_bootstrap'],
'message': 'Munging ELF program header',
'action': ['python', '<@(_inputs)', '<@(_outputs)']
}],
},
],
}],
],
......
This diff is collapsed.
/* Copyright (c) 2011 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
* This is a custom linker script used to build nacl_helper_bootstrap.
* It has a very special layout. This script will only work with input
* that is kept extremely minimal. If there are unexpected input sections
* not named here, the result will not be correct.
*
* We need to use a standalone loader program rather than just using a
* dynamically-linked program here because its entire address space will be
* taken over for the NaCl untrusted address space. A normal program would
* cause dynamic linker data structures to point to its .dynamic section,
* which is no longer available after startup.
*
* We need this special layout (and the nacl_helper_bootstrap_munge_phdr
* step) because simply having bss space large enough to reserve the
* address space would cause the kernel loader to think we're using that
* much anonymous memory and refuse to execute the program on a machine
* with not much memory available.
*/
/*
* Set the entry point to the symbol called _start, which we define in assembly.
*/
ENTRY(_start)
/*
* This is the address where the program text starts.
* We set this as low as we think we can get away with.
* The common settings for sysctl vm.mmap_min_addr range from 4k to 64k.
*/
TEXT_START = 0x10000;
/*
* The symbol RESERVE_TOP is the top of the range we are trying to reserve.
* This is set via --defsym on the linker command line, because the correct
* value differs for each machine. It's not defined at all if we do not
* actually need any space reserved for this configuration.
*/
/*
* We specify the program headers we want explicitly, to get the layout
* exactly right and to give the "reserve" segment p_flags of zero, so
* that it gets mapped as PROT_NONE.
*/
PHDRS {
text PT_LOAD FILEHDR PHDRS;
data PT_LOAD;
reserve PT_LOAD FLAGS(0);
r_debug PT_LOAD;
note PT_NOTE;
stack PT_GNU_STACK FLAGS(6); /* RW, no E */
}
/*
* Now we lay out the sections across those segments.
*/
SECTIONS {
. = TEXT_START + SIZEOF_HEADERS;
/*
* The build ID note usually comes first.
* It's both part of the text PT_LOAD segment (like other rodata) and
* it's what the PT_NOTE header points to.
*/
.note.gnu.build-id : {
*(.note.gnu.build-id)
} :text :note
/*
* Here is the program itself.
*/
.text : {
*(.text*)
} :text
.rodata : {
*(.rodata*)
*(.eh_frame*)
}
etext = .;
/*
* Adjust the address for the data segment. We want to adjust up to
* the same address within the page on the next page up.
*/
. = (ALIGN(CONSTANT(MAXPAGESIZE)) -
((CONSTANT(MAXPAGESIZE) - .) & (CONSTANT(MAXPAGESIZE) - 1)));
. = DATA_SEGMENT_ALIGN(CONSTANT(MAXPAGESIZE), CONSTANT(COMMONPAGESIZE));
.data : {
*(.data*)
} :data
.bss : {
*(.bss*)
}
/*
* Now we move up to the next p_align increment, and place the dummy
* segment there. The linker emits this segment with the p_vaddr and
* p_memsz we want, which reserves the address space. But the linker
* gives it a p_filesz of zero. We have to edit the phdr after link
* time to give it a p_filesz matching its p_memsz. That way, the
* kernel doesn't think we are preallocating a huge amount of memory.
* It just maps it from the file, i.e. way off the end of the file,
* which is perfect for reserving the address space.
*/
. = ALIGN(CONSTANT(COMMONPAGESIZE));
RESERVE_START = .;
.reserve : {
. += DEFINED(RESERVE_TOP) ? (RESERVE_TOP - RESERVE_START) : 0;
} :reserve
/*
* This must be placed above the reserved address space, so it won't
* be clobbered by NaCl. We want this to be visible at its fixed address
* in the memory image so the debugger can make sense of things.
*/
.r_debug : {
*(.r_debug)
} :r_debug
/*
* These are empty input sections the linker generates.
* If we don't discard them, they pollute the flags in the output segment.
*/
/DISCARD/ : {
*(.iplt)
*(.rel*)
*(.igot.plt)
}
}
/* Copyright (c) 2011 The Chromium Authors. All rights reserved.
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
* This is a trivial program to edit an ELF file in place, making
* one crucial modification to a program header. It's invoked:
* bootstrap_phdr_hacker FILENAME SEGMENT_NUMBER
* where SEGMENT_NUMBER is the zero-origin index of the program header
* we'll touch. This is a PT_LOAD with p_filesz of zero. We change its
* p_filesz to match its p_memsz value.
*/
#include <errno.h>
#include <error.h>
#include <fcntl.h>
#include <gelf.h>
#include <libelf.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char **argv) {
if (argc != 3)
error(1, 0, "Usage: %s FILENAME SEGMENT_NUMBER", argv[0]);
const char *const file = argv[1];
const int segment = atoi(argv[2]);
int fd = open(file, O_RDWR);
if (fd < 0)
error(2, errno, "Cannot open %s for read/write", file);
if (elf_version(EV_CURRENT) == EV_NONE)
error(2, 0, "elf_version: %s", elf_errmsg(-1));
Elf *elf = elf_begin(fd, ELF_C_RDWR, NULL);
if (elf == NULL)
error(2, 0, "elf_begin: %s", elf_errmsg(-1));
if (elf_flagelf(elf, ELF_C_SET, ELF_F_LAYOUT) == 0)
error(2, 0, "elf_flagelf: %s", elf_errmsg(-1));
GElf_Phdr phdr;
GElf_Phdr *ph = gelf_getphdr(elf, segment, &phdr);
if (ph == NULL)
error(2, 0, "gelf_getphdr: %s", elf_errmsg(-1));
if (ph->p_type != PT_LOAD)
error(3, 0, "Program header %d is %u, not PT_LOAD",
segment, (unsigned int) ph->p_type);
if (ph->p_filesz != 0)
error(3, 0, "Program header %d has nonzero p_filesz", segment);
ph->p_filesz = ph->p_memsz;
if (gelf_update_phdr(elf, segment, ph) == 0)
error(2, 0, "gelf_update_phdr: %s", elf_errmsg(-1));
if (elf_flagphdr(elf, ELF_C_SET, ELF_F_DIRTY) == 0)
error(2, 0, "elf_flagphdr: %s", elf_errmsg(-1));
if (elf_update(elf, ELF_C_WRITE) < 0)
error(2, 0, "elf_update: %s", elf_errmsg(-1));
close(fd);
return 0;
}
#!/usr/bin/env python
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""This takes three command-line arguments:
MUNGE-PHDR-PROGRAM file name of program built from
nacl_helper_bootstrap_munge_phdr.c
INFILE raw linked ELF file name
OUTFILE output file name
We just run the MUNGE-PHDR-PROGRAM on a copy of INFILE.
That modifies the file in place. Then we move it to OUTFILE.
We only have this wrapper script because nacl_helper_bootstrap_munge_phdr.c
wants to modify a file in place (and it would be a much longer and more
fragile program if it created a fresh ELF output file instead).
"""
import shutil
import subprocess
import sys
def Main(argv):
if len(argv) != 4:
print 'Usage: %s MUNGE-PHDR-PROGRAM INFILE OUTFILE' % argv[0]
return 1
[prog, munger, infile, outfile] = argv
tmpfile = outfile + '.tmp'
shutil.copy(infile, tmpfile)
segment_num = '2'
subprocess.check_call([munger, tmpfile, segment_num])
shutil.move(tmpfile, outfile)
return 0
if __name__ == '__main__':
sys.exit(Main(sys.argv))
#!/usr/bin/python
# Copyright (c) 2011 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
"""Wrapper for invoking the BFD loader
A simple script to invoke the bfd loader instead of gold.
This script is in a filename "ld" so it can be invoked from gcc
via the -B flag.
"""
# TODO(bradchen): Delete this script when Gold supports linker scripts properly.
import os
import subprocess
import sys
def PathTo(fname):
if fname[0] == os.pathsep:
return fname
for p in os.environ["PATH"].split(os.pathsep):
fpath = os.path.join(p, fname)
if os.path.exists(fpath):
return fpath
return fname
def FindLDBFD():
cxx = os.getenv("CXX")
if not cxx:
cxx = "g++"
popen = subprocess.Popen(cxx + " -print-prog-name=ld",
shell=True,
stdout=subprocess.PIPE,
stdin=subprocess.PIPE)
(ld, error) = popen.communicate()
if popen.wait() != 0:
print "Could not find ld:" + error
return "ld"
ld = ld.strip()
ld_bfd = PathTo(ld + ".bfd")
if os.access(ld_bfd, os.X_OK):
return ld_bfd
return ld
def main():
args = [FindLDBFD()] + sys.argv[1:]
print("tools/ld_bfd/ld: exec " + ' '.join(args))
sys.exit(subprocess.call(args))
if __name__ == "__main__":
main()
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