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

test: add lib path env when node_shared=true #18626

Closed

Conversation

yhwang
Copy link
Member

@yhwang yhwang commented Feb 7, 2018

When building the node with --shared option, the major output is the
shared library. However, we still build a node executable which links
to the shared lib. It's for testing purpose. When testing with the
executable, some test cases move/copy the executable, change the relative
path to the shared library and fail. Using lib path env would solve the
issue. However, in macOS, need to modify the dependency in the
executable by using the install_name_tool utility. In AIX, -brtl
linker option rebinds the symbols in the executable and addon modules
could use them.

Refs: #18535

Signed-off-by: Yihong Wang yh.wang@ibm.com

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • commit message follows commit guidelines
Affected core subsystem(s)

test, build

@nodejs-github-bot nodejs-github-bot added the build Issues and PRs related to build files or the CI. label Feb 7, 2018
Makefile Outdated
@@ -239,6 +239,9 @@ v8:
.PHONY: test
# This does not run tests of third-party libraries inside deps.
test: all ## Runs default tests, linters, and builds docs.
ifeq ($(OSTYPE)$(NODE_TARGET_TYPE),darwinshared_library)
$(MAKE) -s change-install-name
endif
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it would be better to make change-install-name a no-op itself, rather than making its usage conditional? The current implementation wouldn’t work on other OSes anyway, right?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's only for macOS. so you mean make it no-op for other platform?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yhwang Yes, exactly that 👍

Makefile Outdated
# to the shared library with abs path.
.PHONY: change-install-name
change-install-name:
install_name_tool -change /usr/local/lib/libnode.$(NODE_MODULE_VERSION).dylib \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is /usr/local/lib hardcoded somewhere else, or should we use the actual prefix here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's a good question. I don't know where it comes from. and that's important for shared lib embedders. If they build the shared lib, they may want to change it. And that's for macOS only.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yhwang I guess it’s coming from $(PREFIX) or ./configure --prefix=…?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see. if that's the case, let me change it to variable. Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@addaleax oops, seems the /usr/local/lib comes from here: https://github.com/nodejs/node/blob/master/tools/gyp/pylib/gyp/xcode_emulation.py#L763
And it doesn't honor PREFIX..... is this a bug?

Copy link
Member Author

@yhwang yhwang Feb 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Linux we use $ORIGIN in rpath when linking. For macOS, we can use @loader_path. Should I add a TODO in the comment and do the change in other PR?
In here, I will leave it to /usr/local/lib for now. is that okay?

[Edit] There is @rpath since macOS 10.5

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@addaleax I updated my change to use @rpath. Then I reverted my change in Makefile. You may take a look.

Makefile Outdated
.PHONY: change-install-name
change-install-name:
install_name_tool -change /usr/local/lib/libnode.$(NODE_MODULE_VERSION).dylib \
$(shell pwd)/out/Release/libnode.$(NODE_MODULE_VERSION).dylib \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Release → BUILDTYPE?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. Let me work on it.

return;
}
process.env.LD_LIBRARY_PATH =
path.join(path.dirname(process.execPath), 'lib.target');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this extend LD_LIBRARY_PATH instead of replace it? (Same for LIBPATH and DYLD_LIBRARY_PATH below).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure. Let me change to extend these variables.

@yhwang yhwang force-pushed the sharedlib-fix-testcase-lib-not-found branch 2 times, most recently from b354c8c to 0295775 Compare February 8, 2018 20:06
@yhwang yhwang force-pushed the sharedlib-fix-testcase-lib-not-found branch 2 times, most recently from 7318472 to eed929e Compare February 8, 2018 21:46
@BridgeAR
Copy link
Member

@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Feb 10, 2018
@yhwang
Copy link
Member Author

yhwang commented Feb 12, 2018

failed on a flaky test case: test_callback_scope/test-resolve-async. It means the CI should be good for this PR.

@@ -802,3 +802,32 @@ exports.hijackStdout = hijackStdWritable.bind(null, 'stdout');
exports.hijackStderr = hijackStdWritable.bind(null, 'stderr');
exports.restoreStdout = restoreWritable.bind(null, 'stdout');
exports.restoreStderr = restoreWritable.bind(null, 'stderr');

// Check if the executable links to the shared lib node or not.
exports.isSharedLibNode = process.config.variables.node_shared === true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is currently not used at all, right? If so, I would rather remove it again.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure!

process.env.PATH =
(process.env.PATH ? process.env.PATH + path.delimiter : '') +
path.dirname(process.execPath);
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is only going to be called rarely, I feel like it would be better to move this to a separate file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to a file which both test-child-process-fork-exec-path and test-module-loading-globalpaths can access? not familiar with the directory structure of the testing suites, any suggestion?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is for example test/common/countdown.js. Similar to that you can just add another file.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@BridgeAR I moved the function to a new file: shared-lib-util.js

When building the node with `--shared` option, the major output is the
shared library. However, we still build a node executable which links
to the shared lib. It's for testing purpose. When testing with the
executable, some test cases move/copy the executable, change the relative
path to the shared library and fail. Using lib path env would solve the
issue. However, in macOS, need to change the install name for the shared
library and use rpath in the executable. In AIX, `-brtl` linker option
rebinds the symbols in the executable and addon modules could use them.

Signed-off-by: Yihong Wang <yh.wang@ibm.com>
@yhwang yhwang force-pushed the sharedlib-fix-testcase-lib-not-found branch from eed929e to b6f1ae3 Compare February 13, 2018 00:32
Copy link
Member

@BridgeAR BridgeAR left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@yhwang
Copy link
Member Author

yhwang commented Feb 13, 2018

May I have another CI to verify this PR again after I refactor the function to a separated js file?

@mhdawson
Copy link
Member

@yhwang
Copy link
Member Author

yhwang commented Feb 15, 2018

Only failed on pi1. However, on those 6 runs on pi1. 2 runs passed! (If I interpret the results correctly.)

@BridgeAR
Copy link
Member

Landed in ec9e792 🎉

BridgeAR pushed a commit to BridgeAR/node that referenced this pull request Feb 16, 2018
When building the node with `--shared` option, the major output is the
shared library. However, we still build a node executable which links
to the shared lib. It's for testing purpose. When testing with the
executable, some test cases move/copy the executable, change the
relative path to the shared library and fail. Using lib path env would
solve the issue. However, in macOS, need to change the install name for
the shared library and use rpath in the executable. In AIX, `-brtl`
linker option rebinds the symbols in the executable and addon modules
could use them.

Signed-off-by: Yihong Wang <yh.wang@ibm.com>

PR-URL: nodejs#18626
Refs: nodejs#18535
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@BridgeAR BridgeAR closed this Feb 16, 2018
@yhwang yhwang deleted the sharedlib-fix-testcase-lib-not-found branch February 16, 2018 17:14
MylesBorins pushed a commit that referenced this pull request Feb 21, 2018
When building the node with `--shared` option, the major output is the
shared library. However, we still build a node executable which links
to the shared lib. It's for testing purpose. When testing with the
executable, some test cases move/copy the executable, change the
relative path to the shared library and fail. Using lib path env would
solve the issue. However, in macOS, need to change the install name for
the shared library and use rpath in the executable. In AIX, `-brtl`
linker option rebinds the symbols in the executable and addon modules
could use them.

Signed-off-by: Yihong Wang <yh.wang@ibm.com>

PR-URL: #18626
Refs: #18535
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@MylesBorins MylesBorins mentioned this pull request Feb 21, 2018
MylesBorins pushed a commit that referenced this pull request Feb 21, 2018
When building the node with `--shared` option, the major output is the
shared library. However, we still build a node executable which links
to the shared lib. It's for testing purpose. When testing with the
executable, some test cases move/copy the executable, change the
relative path to the shared library and fail. Using lib path env would
solve the issue. However, in macOS, need to change the install name for
the shared library and use rpath in the executable. In AIX, `-brtl`
linker option rebinds the symbols in the executable and addon modules
could use them.

Signed-off-by: Yihong Wang <yh.wang@ibm.com>

PR-URL: #18626
Refs: #18535
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
When building the node with `--shared` option, the major output is the
shared library. However, we still build a node executable which links
to the shared lib. It's for testing purpose. When testing with the
executable, some test cases move/copy the executable, change the
relative path to the shared library and fail. Using lib path env would
solve the issue. However, in macOS, need to change the install name for
the shared library and use rpath in the executable. In AIX, `-brtl`
linker option rebinds the symbols in the executable and addon modules
could use them.

Signed-off-by: Yihong Wang <yh.wang@ibm.com>

PR-URL: nodejs#18626
Refs: nodejs#18535
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@MylesBorins
Copy link
Contributor

MylesBorins commented Aug 7, 2018

Should this be backported to v8.x-staging? If yes please follow the guide and raise a backport PR, if not let me know or add the dont-land-on label.

edit: got it to land

MylesBorins pushed a commit that referenced this pull request Aug 7, 2018
When building the node with `--shared` option, the major output is the
shared library. However, we still build a node executable which links
to the shared lib. It's for testing purpose. When testing with the
executable, some test cases move/copy the executable, change the
relative path to the shared library and fail. Using lib path env would
solve the issue. However, in macOS, need to change the install name for
the shared library and use rpath in the executable. In AIX, `-brtl`
linker option rebinds the symbols in the executable and addon modules
could use them.

Signed-off-by: Yihong Wang <yh.wang@ibm.com>

PR-URL: #18626
Refs: #18535
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@yhwang
Copy link
Member Author

yhwang commented Aug 7, 2018

@MylesBorins thanks.

MylesBorins pushed a commit that referenced this pull request Aug 7, 2018
When building the node with `--shared` option, the major output is the
shared library. However, we still build a node executable which links
to the shared lib. It's for testing purpose. When testing with the
executable, some test cases move/copy the executable, change the
relative path to the shared library and fail. Using lib path env would
solve the issue. However, in macOS, need to change the install name for
the shared library and use rpath in the executable. In AIX, `-brtl`
linker option rebinds the symbols in the executable and addon modules
could use them.

Signed-off-by: Yihong Wang <yh.wang@ibm.com>

PR-URL: #18626
Refs: #18535
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
MylesBorins pushed a commit that referenced this pull request Aug 9, 2018
When building the node with `--shared` option, the major output is the
shared library. However, we still build a node executable which links
to the shared lib. It's for testing purpose. When testing with the
executable, some test cases move/copy the executable, change the
relative path to the shared library and fail. Using lib path env would
solve the issue. However, in macOS, need to change the install name for
the shared library and use rpath in the executable. In AIX, `-brtl`
linker option rebinds the symbols in the executable and addon modules
could use them.

Signed-off-by: Yihong Wang <yh.wang@ibm.com>

PR-URL: #18626
Refs: #18535
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@MylesBorins MylesBorins mentioned this pull request Aug 16, 2018
MylesBorins pushed a commit that referenced this pull request Aug 16, 2018
When building the node with `--shared` option, the major output is the
shared library. However, we still build a node executable which links
to the shared lib. It's for testing purpose. When testing with the
executable, some test cases move/copy the executable, change the
relative path to the shared library and fail. Using lib path env would
solve the issue. However, in macOS, need to change the install name for
the shared library and use rpath in the executable. In AIX, `-brtl`
linker option rebinds the symbols in the executable and addon modules
could use them.

Signed-off-by: Yihong Wang <yh.wang@ibm.com>

PR-URL: #18626
Refs: #18535
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. build Issues and PRs related to build files or the CI.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants