Skip to content

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

Description

@kikijhu

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?

Activity

  1. mscdex commented on Oct 29, 2015

    @mscdex
    Contributor

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

  2. added
    buildIssues and PRs related to Node.js builds or CI infrastructure.
    armIssues and PRs related to the ARM architecture.
    on Oct 29, 2015
  3. kikijhu commented on Oct 29, 2015

    @kikijhu
    Author

    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',
                    ],
                  }],
  4. Fishrock123 commented on Nov 2, 2015

    @Fishrock123
    Contributor

    cc @evanlucas and @Gioyik maybe?

  5. kikijhu commented on Nov 9, 2015

    @kikijhu
    Author

    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' ]
              }]
            ],
  6. bnoordhuis commented on Nov 9, 2015

    @bnoordhuis
    Member

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

  7. IvanGaravito commented on Dec 31, 2015

    @IvanGaravito

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

  8. kikijhu commented on Jan 14, 2016

    @kikijhu
    Author

    @IvanGaravito Glad to help you : )

  9. kikijhu commented on Jan 18, 2016

    @kikijhu
    Author

    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}}
    
  10. Fishrock123 commented on Jan 18, 2016

    @Fishrock123
    Contributor

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

  11. kikijhu commented on Jan 19, 2016

    @kikijhu
    Author

    @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.

  12. bnoordhuis commented on Feb 12, 2016

    @bnoordhuis
    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.

  13. bsegault commented on Mar 17, 2016

    @bsegault

    @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

  14. rvagg commented on Mar 22, 2016

    @rvagg
    Member

    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

  15. bnoordhuis commented on May 2, 2016

    @bnoordhuis
    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    armIssues and PRs related to the ARM architecture.buildIssues and PRs related to Node.js builds or CI infrastructure.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions