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

Fix: module compilation within termux-app on android #1340

Merged
merged 1 commit into from Oct 20, 2018

Conversation

@arrkiin
Copy link
Contributor

commented Nov 16, 2017

Description of change

To solve the problem of linking a compiled module against a preinstalled library of termux-app on android I added a special condition branch to add the required -fPIC flag for the c and c++ compiler. After that everything compiled, linked and works as expected.

addon.gypi Outdated
[ 'OS == "android"', {
'cflags': [ '-fPIC' ],
'cflags_cc': ['-fPIC' ],
}],

This comment has been minimized.

Copy link
@bnoordhuis

bnoordhuis Nov 16, 2017

Member

You can fold this into the previous condition: OS in "android freebsd ...". You don't need to add it to cflags_cc because cflags is for both C and C++ code.

This comment has been minimized.

Copy link
@arrkiin

arrkiin Nov 16, 2017

Author Contributor

@bnoordhuis thanks for your comment. Your proposal was my first attemp to fix it, but it didn't. To verify if I didn't make any mistake I just did some testing:

  • with 'cflags_cc': ['-fPIC' ] it compiles
  • without 'cflags_cc': ['-fPIC' ] it does not

I think I have to compare the verbose outputs in more detail to figure out what happens. Any ideas?

This comment has been minimized.

Copy link
@bnoordhuis

bnoordhuis Nov 16, 2017

Member

env V=1 node-gyp rebuild turns on verbose compilation mode (i.e., prints the compile commands.)

This comment has been minimized.

Copy link
@arrkiin

arrkiin Nov 17, 2017

Author Contributor

This is the compiler command for the variant without ccflags_cc. It seems that the -fPIE after the first -fPIC creates and unlinkable shared library on android.
... -fPIC -Wall -Wextra -Wno-unused-parameter -O3 -fno-omit-frame-pointer -fPIE -fno-rtti ...

With ccflags_cc the command is build like that. It seems, that the later -fPIC overrides the preceding -fPIE so that it produces the right shared library.
... -fPIC -Wall -Wextra -Wno-unused-parameter -O3 -fno-omit-frame-pointer -fPIE -fPIC -fno-rtti ...

With this result I would rather try to remove the -fPIE while compiling shared libraries on android. I added an additional entry in target_condition for removing -fPIE like shown below. That did the trick and produces the following compiler command.
... -fPIC -Wall -Wextra -Wno-unused-parameter -O3 -fno-omit-frame-pointer -fno-rtti ...

Excerpt of my local addon.gypi:

'target_conditions': [
...
      ['library=="shared_library"', {
        'conditions': [
          [ 'OS=="android"', {
            'cflags!': [ '-fPIE' ],
          }]
        ]
      }],
...
]

@bnoordhuis, what is your comment on this?

This comment has been minimized.

Copy link
@bnoordhuis

bnoordhuis Nov 17, 2017

Member

Ah, you're probably getting hit by #1118 - that -fPIE flag is not set by node-gyp, it's inherited from node's common.gypi.

The right thing to do until #1118 is resolved is probably to suppress the flag in node-gyp's addon.gypi.

It must have been broken for quite a while because that flag was added 20 months ago in nodejs/node#5544.

addon.gypi Outdated
@@ -52,6 +52,14 @@
'standalone_static_library': '<(standalone_static_library)'
}],

['library=="shared_library"', {

This comment has been minimized.

Copy link
@bnoordhuis

bnoordhuis Nov 17, 2017

Member

I think you want to unset -fPIE unconditionally, otherwise it's still going to be problematic with add-ons that also build static libraries.

This comment has been minimized.

Copy link
@arrkiin

arrkiin Nov 17, 2017

Author Contributor

Ok. So we only want to remove the flag if we don't want to compile an executable. Am I right?

@bnoordhuis

This comment has been minimized.

Copy link
Member

commented Nov 18, 2017

LGTM, thanks. CI: https://ci.nodejs.org/job/nodegyp-test-pull-request/42/

You don't even need to special-case on OS=="android" when removing -fPIE but this is good enough.

@arrkiin

This comment has been minimized.

Copy link
Contributor Author

commented Nov 20, 2017

@bnoordhuis, when can I expect it to be merged and published?

@bnoordhuis

This comment has been minimized.

Copy link
Member

commented Nov 21, 2017

We don't release that often and it also takes a while for new versions of node-gyp make it into npm and node.

I can merge it but can you squash your commits and write up a nice commit log? If you want to show up under your real name instead of arrkiin, please do git commit --amend --author="...". Cheers.

@pietvanzoen

This comment has been minimized.

Copy link

commented Apr 13, 2018

Hey folks. Would love to see this merged. Running into this issue currently. :)

@arrkiin arrkiin force-pushed the arrkiin:termux_on_android branch from 8d3e678 to 70030a4 May 22, 2018
@arrkiin arrkiin force-pushed the arrkiin:termux_on_android branch from 70030a4 to 9d2ab22 May 22, 2018
@arrkiin

This comment has been minimized.

Copy link
Contributor Author

commented May 22, 2018

Hey @bnoordhuis, sorry for the long delay. After your message I asked myself how to proceed and forgot to continue. In the meantime I used my own fork to do the experiments under termux. Until now I didn't see any problems. Today I just found some time to squash the commits and add my forename.

@maclover7

This comment has been minimized.

@johnnyvf24

This comment has been minimized.

Copy link

commented Aug 14, 2018

Hey folks. Would love to see this merged. Running into this issue currently. :)

I can second that.

@refack
refack approved these changes Oct 20, 2018
@refack

This comment has been minimized.

@refack refack self-assigned this Oct 20, 2018
@refack refack merged commit e2401e1 into nodejs:master Oct 20, 2018
rvagg added a commit that referenced this pull request Apr 24, 2019
PR-URL: #1340
Reviewed-By: Refael Ackermann <refack@gmail.com>
@rvagg rvagg referenced this pull request Apr 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.