Skip to content

Commit

Permalink
Use the pnacl-clang toolchain for (P)NaCL builds
Browse files Browse the repository at this point in the history
Patch from JF Bastien <jfb@google.com>.

R=bmeurer@chromium.org

Review URL: https://codereview.chromium.org/631703002

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24402 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
  • Loading branch information
svenpanne@chromium.org committed Oct 6, 2014
1 parent d468f6f commit 0dda232
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 44 deletions.
39 changes: 16 additions & 23 deletions Makefile.nacl
Original file line number Diff line number Diff line change
Expand Up @@ -36,41 +36,29 @@ NACL_BUILDS = $(foreach mode,$(MODES), \
$(addsuffix .$(mode),$(NACL_ARCHES)))

HOST_OS = $(shell uname -s | sed -e 's/Linux/linux/;s/Darwin/mac/')
ifeq ($(HOST_OS), linux)
TOOLCHAIN_DIR = linux_x86_glibc
else
ifeq ($(HOST_OS), mac)
TOOLCHAIN_DIR = mac_x86_glibc
else
$(error Host platform "${HOST_OS}" is not supported)
endif
endif

TOOLCHAIN_PATH = $(realpath ${NACL_SDK_ROOT}/toolchain)
NACL_TOOLCHAIN ?= ${TOOLCHAIN_PATH}/${TOOLCHAIN_DIR}
NACL_TOOLCHAIN ?= ${TOOLCHAIN_PATH}/linux_pnacl

ifeq ($(wildcard $(NACL_TOOLCHAIN)),)
$(error Cannot find Native Client toolchain in "${NACL_TOOLCHAIN}")
endif

ifeq ($(ARCH), nacl_ia32)
GYPENV = nacl_target_arch=nacl_ia32 v8_target_arch=arm v8_host_arch=ia32
TOOLCHAIN_ARCH = x86-4.4
NACL_CC = "$(NACL_TOOLCHAIN)/bin/i686-nacl-gcc"
NACL_CXX = "$(NACL_TOOLCHAIN)/bin/i686-nacl-g++"
NACL_LINK = "$(NACL_TOOLCHAIN)/bin/i686-nacl-g++"
NACL_CC = "$(NACL_TOOLCHAIN)/bin/pnacl-clang"
NACL_CXX = "$(NACL_TOOLCHAIN)/bin/pnacl-clang++"
NACL_LINK = "$(NACL_TOOLCHAIN)/bin/pnacl-clang++ --pnacl-allow-native -arch x86-32"
else
ifeq ($(ARCH), nacl_x64)
GYPENV = nacl_target_arch=nacl_x64 v8_target_arch=arm v8_host_arch=ia32
TOOLCHAIN_ARCH = x86-4.4
NACL_CC = "$(NACL_TOOLCHAIN)/bin/x86_64-nacl-gcc"
NACL_CXX = "$(NACL_TOOLCHAIN)/bin/x86_64-nacl-g++"
NACL_LINK = "$(NACL_TOOLCHAIN)/bin/x86_64-nacl-g++"
NACL_CC = "$(NACL_TOOLCHAIN)/bin/pnacl-clang"
NACL_CXX = "$(NACL_TOOLCHAIN)/bin/pnacl-clang++"
NACL_LINK = "$(NACL_TOOLCHAIN)/bin/pnacl-clang++ --pnacl-allow-native -arch x86-64"
else
$(error Target architecture "${ARCH}" is not supported)
endif
endif

ifeq ($(wildcard $(NACL_TOOLCHAIN)),)
$(error Cannot find Native Client toolchain in "${NACL_TOOLCHAIN}")
endif

# For mksnapshot host generation.
GYPENV += host_os=${HOST_OS}

Expand All @@ -85,7 +73,11 @@ NACL_MAKEFILES = $(addprefix $(OUTDIR)/Makefile.,$(NACL_BUILDS))
# For some reason the $$(basename $$@) expansion didn't work here...
$(NACL_BUILDS): $(NACL_MAKEFILES)
@$(MAKE) -C "$(OUTDIR)" -f Makefile.$@ \
CC=${NACL_CC} \
CXX=${NACL_CXX} \
AR="$(NACL_TOOLCHAIN)/bin/pnacl-ar" \
RANLIB="$(NACL_TOOLCHAIN)/bin/pnacl-ranlib" \
LD="$(NACL_TOOLCHAIN)/bin/pnacl-ld" \
LINK=${NACL_LINK} \
BUILDTYPE=$(shell echo $(subst .,,$(suffix $@)) | \
python -c "print raw_input().capitalize()") \
Expand All @@ -97,6 +89,7 @@ $(NACL_MAKEFILES):
GYP_DEFINES="${GYPENV}" \
CC=${NACL_CC} \
CXX=${NACL_CXX} \
LINK=${NACL_LINK} \
PYTHONPATH="$(shell pwd)/tools/generate_shim_headers:$(shell pwd)/build:$(PYTHONPATH)" \
build/gyp/gyp --generator-output="${OUTDIR}" build/all.gyp \
-Ibuild/standalone.gypi --depth=. \
Expand Down
10 changes: 7 additions & 3 deletions src/base/atomicops.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,17 @@ namespace base {

typedef char Atomic8;
typedef int32_t Atomic32;
#ifdef V8_HOST_ARCH_64_BIT
#if defined(__native_client__)
typedef int64_t Atomic64;
#elif defined(V8_HOST_ARCH_64_BIT)
// We need to be able to go between Atomic64 and AtomicWord implicitly. This
// means Atomic64 and AtomicWord should be the same type on 64-bit.
#if defined(__ILP32__)
typedef int64_t Atomic64;
#else
typedef intptr_t Atomic64;
#endif
#endif
#endif // defined(V8_HOST_ARCH_64_BIT)
#endif // defined(__native_client__)

// Use AtomicWord for a machine-sized pointer. It will use the Atomic32 or
// Atomic64 routines below, depending on your architecture.
Expand Down Expand Up @@ -140,6 +142,8 @@ Atomic64 Release_Load(volatile const Atomic64* ptr);
#include "src/base/atomicops_internals_x86_msvc.h"
#elif defined(__APPLE__)
#include "src/base/atomicops_internals_mac.h"
#elif defined(__native_client__)
#include "src/base/atomicops_internals_portable.h"
#elif defined(__GNUC__) && V8_HOST_ARCH_ARM64
#include "src/base/atomicops_internals_arm64_gcc.h"
#elif defined(__GNUC__) && V8_HOST_ARCH_ARM
Expand Down
4 changes: 4 additions & 0 deletions src/base/build_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@
#define V8_HOST_ARCH_64_BIT 1
#endif
#endif // __native_client__
#elif defined(__pnacl__)
// PNaCl is also ILP-32.
#define V8_HOST_ARCH_IA32 1
#define V8_HOST_ARCH_32_BIT 1
#elif defined(_M_IX86) || defined(__i386__)
#define V8_HOST_ARCH_IA32 1
#define V8_HOST_ARCH_32_BIT 1
Expand Down
10 changes: 8 additions & 2 deletions src/base/cpu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@
namespace v8 {
namespace base {

#if V8_HOST_ARCH_IA32 || V8_HOST_ARCH_X64
#if defined(__pnacl__)
// Portable host shouldn't do feature detection.
#elif V8_HOST_ARCH_IA32 || V8_HOST_ARCH_X64

// Define __cpuid() for non-MSVC libraries.
#if !V8_LIBC_MSVCRT
Expand Down Expand Up @@ -290,7 +292,11 @@ CPU::CPU() : stepping_(0),
has_vfp3_d32_(false),
is_fp64_mode_(false) {
memcpy(vendor_, "Unknown", 8);
#if V8_HOST_ARCH_IA32 || V8_HOST_ARCH_X64
#if defined(__pnacl__)
// Portable host shouldn't do feature detection.
// TODO(jfb): Remove the hardcoded ARM simulator flags in the build, and
// hardcode them here instead.
#elif V8_HOST_ARCH_IA32 || V8_HOST_ARCH_X64
int cpu_info[4];

// __cpuid with an InfoType argument of 0 returns the number of
Expand Down
18 changes: 13 additions & 5 deletions tools/gyp/v8.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -1249,11 +1249,19 @@
'toolsets': ['target'],
}],
['OS=="linux"', {
'link_settings': {
'libraries': [
'-lrt'
]
},
'conditions': [
['nacl_target_arch=="none"', {
'link_settings': {
'libraries': [
'-lrt'
],
},
}, {
'defines': [
'V8_LIBRT_NOT_AVAILABLE=1',
],
}],
],
'sources': [
'../../src/base/platform/platform-linux.cc',
'../../src/base/platform/platform-posix.cc'
Expand Down
18 changes: 7 additions & 11 deletions tools/nacl-run.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

import os
from os.path import join, dirname, abspath
import re
import subprocess
import sys
import tempfile
Expand Down Expand Up @@ -82,7 +83,7 @@ def GetNaClArchFromNexe(nexe):
try:
p = subprocess.Popen(['file', nexe], stdout=subprocess.PIPE)
out, err = p.communicate()
lines = out.split('\n')
lines = [re.sub("\s+", " " , line) for line in out.split('\n')]
if lines[0].find(": ELF 32-bit LSB executable, Intel 80386") > 0:
return "x86_32"
if lines[0].find(": ELF 64-bit LSB executable, x86-64") > 0:
Expand Down Expand Up @@ -116,17 +117,13 @@ def GetNaClResources(nexe):
print("NaCl V8 ARM support is not ready yet.")
sys.exit(1)
else:
print("Invalid nexe %s" % nexe)
print("Invalid nexe %s with NaCl arch %s" % (nexe, nacl_arch))
sys.exit(1)

nacl_sel_ldr = os.path.join(nacl_sdk_dir, "tools", sel_ldr)
nacl_irt = os.path.join(nacl_sdk_dir, "tools", irt)
nacl_ld_so = os.path.join(nacl_sdk_dir, "toolchain", toolchain,
"x86_64-nacl", libdir, "runnable-ld.so")
nacl_lib_path = os.path.join(nacl_sdk_dir, "toolchain", toolchain,
"x86_64-nacl", libdir)

return (nacl_sdk_dir, nacl_sel_ldr, nacl_irt, nacl_ld_so, nacl_lib_path)
return (nacl_sdk_dir, nacl_sel_ldr, nacl_irt)

def Main():
if (len(sys.argv) == 1):
Expand All @@ -135,15 +132,14 @@ def Main():

args = [Escape(arg) for arg in sys.argv[1:]]

(nacl_sdk_dir, nacl_sel_ldr, nacl_irt, nacl_ld_so,
nacl_lib_path) = GetNaClResources(sys.argv[1])
(nacl_sdk_dir, nacl_sel_ldr, nacl_irt) = GetNaClResources(sys.argv[1])

# sel_ldr Options:
# -c -c: disable validation (for performance)
# -a: allow file access
# -B <irt>: load the IRT
command = ' '.join([nacl_sel_ldr, '-c', '-c', '-a', '-B', nacl_irt, '--',
nacl_ld_so, '--library-path', nacl_lib_path] + args)
command = ' '.join([nacl_sel_ldr, '-c', '-c', '-a', '-B', nacl_irt, '--'] +
args)
error_code = Execute(command)
return error_code

Expand Down

0 comments on commit 0dda232

Please sign in to comment.