Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node-v5.0.0-rc.1 can't work on Android L due to error: only position independent executables (PIE) are supported #3581

Closed
kikijhu opened this issue Oct 29, 2015 · 14 comments
Labels
arm Issues and PRs related to the ARM platform. build Issues and PRs related to build files or the CI.

Comments

@kikijhu
Copy link

kikijhu commented Oct 29, 2015

issue description

I downloaded the latest node-v5.0.0-rc.1 and make it with Android NDK r10e, but it can’t work on Android L.

compile environment

  • ubuntu 14.04
  • python 2.7.6
  • gcc 4.8.4

error log

C:\Users\Kiki>adb shell
# node -v
error: only position independent executables (PIE) are supported.

solution

I searched on Google for solution, found it, to add two flags in Android.mk.

LOCAL_CFLAGS += -fPIE -pie  
LOCAL_LDFLAGS += -fPIE -pie

But it seems node-v5.0.0-rc.1 just uses NDK toolchain, not use NDK to compile a executable file.
So how to add these two flags to node-v5.0.0-rc.1?

@mscdex
Copy link
Contributor

mscdex commented Oct 29, 2015

Can't you just set the standard CFLAGS and LDFLAGS environment variables before compiling?

@mscdex mscdex added build Issues and PRs related to build files or the CI. arm Issues and PRs related to the ARM platform. labels Oct 29, 2015
@kikijhu
Copy link
Author

kikijhu commented Oct 29, 2015

I see flag settings in these file, and it seemed node-v5.0.0-rc.1 already considered PIE, but what's the problem to the end?

node/deps/uv/common.gypi

 'conditions': [
          ['OS == "android"', {
            'cflags': [ '-fPIE' ],
            'ldflags': [ '-fPIE', '-pie' ]
          }]
        ]

deps/v8/build/standalone.gypi

  ['(target_arch=="arm" or target_arch=="arm64" or target_arch=="x64" or target_arch=="ia32") and component!="shared_library"', {
                'cflags': [
                  '-fPIE',
                ],
                'ldflags': [
                  '-pie',
                ],
              }],

@Fishrock123
Copy link
Member

cc @evanlucas and @Gioyik maybe?

@kikijhu
Copy link
Author

kikijhu commented Nov 9, 2015

I've fixed this issue by modified <node-v5.0.0-rc.1>\common.gypi.

I added -fPIE for cflags and -pie for ldflags on Android.

'target_defaults': {
    'default_configuration': 'Release',
    'configurations': {
      'Debug': {
        'variables': {
          'v8_enable_handle_zapping': 1,
        },
        'defines': [ 'DEBUG', '_DEBUG' ],
        'cflags': [ '-g', '-O0' ],
        'conditions': [
          ['target_arch=="x64"', {
            'msvs_configuration_platform': 'x64',
          }],
          ['OS=="aix"', {
            'cflags': [ '-gxcoff' ],
            'ldflags': [ '-Wl,-bbigtoc' ],
          }],
          ['OS == "android"', {
            'cflags': [ '-fPIE' ],
            'ldflags': [ '-fPIE', '-pie' ]
          }]
        ],
        'msvs_settings': {
          'VCCLCompilerTool': {
            'RuntimeLibrary': 1, # static debug
            'Optimization': 0, # /Od, no optimization
            'MinimalRebuild': 'false',
            'OmitFramePointers': 'false',
            'BasicRuntimeChecks': 3, # /RTC1
          },
          'VCLinkerTool': {
            'LinkIncremental': 2, # enable incremental linking
          },
        },
        'xcode_settings': {
          'GCC_OPTIMIZATION_LEVEL': '0', # stop gyp from defaulting to -Os
        },
      },
      'Release': {
        'variables': {
          'v8_enable_handle_zapping': 0,
        },
        'cflags': [ '-O3', '-ffunction-sections', '-fdata-sections' ],
        'conditions': [
          ['target_arch=="x64"', {
            'msvs_configuration_platform': 'x64',
          }],
          ['OS=="solaris"', {
            `# pull in V8's postmortem metadata`
            'ldflags': [ '-Wl,-z,allextract' ]
          }],
          ['OS!="mac" and OS!="win"', {
            'cflags': [ '-fno-omit-frame-pointer' ],
          }],
          ['OS == "android"', {
            'cflags': [ '-fPIE' ],
            'ldflags': [ '-fPIE', '-pie' ]
          }]
        ],

@bnoordhuis
Copy link
Member

A pull request that updates common.gypi would be fine IMO. Please see CONTRIBUTING.md for details.

@IvanGaravito
Copy link

Hey @kikijhu , I had the same problem with node v4.2.4, and it worked adding PIE flags as you said. Thanks!

@kikijhu
Copy link
Author

kikijhu commented Jan 14, 2016

@IvanGaravito Glad to help you : )

@kikijhu
Copy link
Author

kikijhu commented Jan 18, 2016

I modified the solution.

I add a flag cflag-pie in ./android-configure
If you want to compile the code with -fPIE, just set it as true, otherwise just set it as false.

./configure \
    --dest-cpu=arm \
    --dest-os=android \
    --cflag-pie=true

Modify ./configure

def configure_node(o):
  if options.dest_os == 'android':
    o['variables']['OS'] = 'android'
  o['variables']['cflag_pie'] = options.cflag_pie

parser.add_option('--cflag-pie',
action='store_true',
dest='cflag_pie',
help='add cflags -fPIE')

Modify ./common.gypi

'target_defaults': {
    'default_configuration': 'Release',
    'configurations': {
      'Debug': {
        'variables': {
          'v8_enable_handle_zapping': 1,
        },
        ...
          ['cflag_pie == "true"', {
            'cflags': [ '-fPIE' ],
            'ldflags': [ '-fPIE', '-pie' ]
          }]
        ],...
      },
      'Release': {
        'variables': {
          'v8_enable_handle_zapping': 0,
        },
        'cflags': [ '-O3', '-ffunction-sections', '-fdata-sections' ],
        ...
          ['cflag_pie == "true"', {
            'cflags': [ '-fPIE' ],
            'ldflags': [ '-fPIE', '-pie' ]
          }]
        ],

./config.gypi will contains the flag

# Do not edit. Generated by the configure script.
{ 'target_defaults': { 'cflags': [],
                       'default_configuration': 'Release',
                       'defines': [],
                       'include_dirs': [],
                       'libraries': []},
  'variables': { 'OS': 'android',
                 'arm_float_abi': 'default',
                 'arm_fpu': 'vfpv3',
                 'arm_thumb': 0,
                 'arm_version': '7',
                 'asan': 0,
                 'cflag_pie': 'true',
                 'gas_version': '2.24',
                 'host_arch': 'x64',
                 'icu_small': 'false',
                 'node_byteorder': 'little',
                 'node_enable_v8_vtunejit': 'false',
                 'node_install_npm': 'true',
                 'node_prefix': '/usr/local',
                 'node_release_urlbase': '',
                 'node_shared_http_parser': 'false',
                 'node_shared_libuv': 'false',
                 'node_shared_openssl': 'false',
                 'node_shared_zlib': 'false',
                 'node_tag': '',
                 'node_use_dtrace': 'false',
                 'node_use_etw': 'false',
                 'node_use_lttng': 'false',
                 'node_use_openssl': 'true',
                 'node_use_perfctr': 'false',
                 'openssl_fips': '',
                 'openssl_no_asm': 0,
                 'python': '/home/kiki/node.js/node-v5.4.1/android-toolchain/bin/python',
                 'target_arch': 'arm',
                 'v8_enable_gdbjit': 0,
                 'v8_enable_i18n_support': 0,
                 'v8_no_strict_aliasing': 1,
                 'v8_optimized_debug': 0,
                 'v8_random_seed': 0,
                 'v8_use_snapshot': 'true',
                 'want_separate_host_toolset': 1}}

@Fishrock123
Copy link
Member

@kikijhu Mind making a Pull Request for this? :D

@kikijhu
Copy link
Author

kikijhu commented Jan 19, 2016

@bnoordhuis @Fishrock123 I'm behind the firewall in company, so can't pull code from github . Worse still, I can't even access github at home due to the firewall of China >_<.
I will be glad if someone contribute these changes to developer branch.

@bnoordhuis
Copy link
Member

Is there an Android developer who wants to take this on? @kikijhu's changes look useful but no one on the core team develops on or for Android, as far as I'm aware.

@bsegault
Copy link

@bnoordhuis @kikijhu I was looking just for your answer. Works fine for me with node v4.4.0. Will test on node 5 & do a pull request as soon as possible. Thanks a lot =D

@rvagg
Copy link
Member

rvagg commented Mar 22, 2016

I'm seeking some feedback about how Node.js is used on Android if anyone watching this thread would like to tell us about it: nodejs/build#359

@bnoordhuis
Copy link
Member

Closing, we're building with -fPIE -fpie as of commit 271201f.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
arm Issues and PRs related to the ARM platform. build Issues and PRs related to build files or the CI.
Projects
None yet
Development

No branches or pull requests

7 participants