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

[WIP] Attempt to fix #2497 #2503

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Hardcode84
Copy link
Contributor

I have no idea how OSX infrastructure works, just some copypaste and stackowerflow-driven development.

Also, if we have both dynamic compilation and asan enabled, duplicating entries will be added to -rpath, is this ok?

@@ -343,6 +343,14 @@ void ArgsBuilder::build(llvm::StringRef outputPath,
if (opts::enableDynamicCompile) {
args.push_back("-lldc-jit-rt");
args.push_back("-lldc-jit");
if (global.params.targetTriple->isOSDarwin()) {
Copy link
Member

Choose a reason for hiding this comment

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

make this a little more descriptive, with a bool linkShared or something. Is Darwin the only place where shared JIT RT can be used?

Copy link
Member

Choose a reason for hiding this comment

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

(also it's nicer to put all linker flags related to enableDynamicCompile in a separate function, like addASanLinkFlags)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is Darwin the only place where shared JIT RT can be used?

rpath works differently on OSX and on linux and @executable_path is only supported on OSX.


std::string jitLib = exe_path::prependLibDir("libldc_jit.dylib");
args.push_back("-rpath");
args.push_back(llvm::sys::path::parent_path(jitLib));
Copy link
Member

Choose a reason for hiding this comment

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

why not use exe_path::getLibDir ?

@JohanEngelen
Copy link
Member

duplicating entries will be added to -rpath, is this ok?

For now, I think it's OK. I tested it and it doesn't give problems on my machine (OSX 10.13.2).
There is this: STEllAR-GROUP/hpx#1299 and openmm/openmm#295 .

@Hardcode84
Copy link
Contributor Author

Updated:

  • Moved to separate function
  • Added helper to avoid duplicating flags

@@ -70,6 +74,10 @@ class ArgsBuilder {
virtual void addLdFlag(const llvm::Twine &flag1, const llvm::Twine &flag2) {
args.push_back(("-Wl," + flag1 + "," + flag2).str());
}

void addUniqueArgs(const std::vector<std::string>& arg);
Copy link
Member

Choose a reason for hiding this comment

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

nit: clang-format for the position of the &

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

@@ -495,6 +514,14 @@ void ArgsBuilder::addTargetFlags() {
appendTargetArgsForGcc(args);
}

void ArgsBuilder::addUniqueArgs(const std::vector<std::string> &arg) {
assert(!arg.empty());
if (uniqueArgs.end() == uniqueArgs.find(arg)) {
Copy link
Member

Choose a reason for hiding this comment

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

nit: again the inverted comparison order ;-)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed


void addUniqueArgs(const std::vector<std::string>& arg);

std::set<std::vector<std::string>> uniqueArgs;
Copy link
Member

Choose a reason for hiding this comment

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

uniqueArgs are not read anywhere yet?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It used in addUniqueArgs. If arg isn't in uniqueArgs we add them to args and to uniqueArgs

Copy link
Member

Choose a reason for hiding this comment

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

Ah, indeed. I missed that it adds the args to both args and uniqueArgs.

@Hardcode84
Copy link
Contributor Author

Updated

@JohanEngelen
Copy link
Member

is this still work-in-progress? LGTM.
@ThomasMader can you verify that this fixes #2497 ?

@ThomasMader
Copy link
Contributor

Unfortunately it's not fixing it. "codegen/attr_assumeused.d" additionally fails now but that might be another problem with the base branch.
Rebasing the branch on top of 1.7.0 release tag should prevent such problems.

771: FAIL: LDC :: codegen/attr_assumeused.d (29 of 193) 771: ******************** TEST 'LDC :: codegen/attr_assumeused.d' FAILED ******************** 771: Script: 771: -- 771: /tmp/nix-build-ldcBuild-1.7.0.drv-3/ldc-v1.7.0-src/build/bin/ldc2 -c -output-ll -of=/private/tmp/nix-build-ldcBuild-1.7.0.drv-3/ldc-v1.7.0-src/build/tests/codegen/Output/attr_assumeused.d.tmp.ll /private/tmp/nix-build-ldcBuild-1.7.0.drv-3/ldc-v1.7.0-src/tests/codegen/attr_assumeused.d && FileCheck /private/tmp/nix-build-ldcBuild-1.7.0.drv-3/ldc-v1.7.0-src/tests/codegen/attr_assumeused.d < /private/tmp/nix-build-ldcBuild-1.7.0.drv-3/ldc-v1.7.0-src/build/tests/codegen/Output/attr_assumeused.d.tmp.ll 771: -- 771: Exit Code: 1 771: 771: Command Output (stdout): 771: -- 771: $ "/tmp/nix-build-ldcBuild-1.7.0.drv-3/ldc-v1.7.0-src/build/bin/ldc2" "-c" "-output-ll" "-of=/private/tmp/nix-build-ldcBuild-1.7.0.drv-3/ldc-v1.7.0-src/build/tests/codegen/Output/attr_assumeused.d.tmp.ll" "/private/tmp/nix-build-ldcBuild-1.7.0.drv-3/ldc-v1.7.0-src/tests/codegen/attr_assumeused.d" 771: # command stderr: 771: /private/tmp/nix-build-ldcBuild-1.7.0.drv-3/ldc-v1.7.0-src/tests/codegen/attr_assumeused.d(11): Error: undefined identifier assumeUsedin moduleldc.attributes771: /private/tmp/nix-build-ldcBuild-1.7.0.drv-3/ldc-v1.7.0-src/tests/codegen/attr_assumeused.d(15): Error: undefined identifierassumeUsedin moduleldc.attributes 771: 771: error: command failed with exit status: 1 771: 771: -- 771: 771: ********************

771: Failing Tests (16):
771:     LDC :: codegen/attr_assumeused.d
771:     LDC :: dynamiccompile/array.d
771:     LDC :: dynamiccompile/calls.d
771:     LDC :: dynamiccompile/classes.d
771:     LDC :: dynamiccompile/dump_handler.d
771:     LDC :: dynamiccompile/empty_jit_modules.d
771:     LDC :: dynamiccompile/globals.d
771:     LDC :: dynamiccompile/globals_types.d
771:     LDC :: dynamiccompile/lambdas.d
771:     LDC :: dynamiccompile/params_ctors.d
771:     LDC :: dynamiccompile/recursive_call.d
771:     LDC :: dynamiccompile/simple.d
771:     LDC :: dynamiccompile/struct_init.d
771:     LDC :: dynamiccompile/thread_local.d
771:     LDC :: dynamiccompile/throw.d
771:     LDC :: dynamiccompile/tls_workaround_opt.d

771: FAIL: LDC :: dynamiccompile/tls_workaround_opt.d (160 of 193) 771: ******************** TEST 'LDC :: dynamiccompile/tls_workaround_opt.d' FAILED ******************** 771: Script: 771: -- 771: /tmp/nix-build-ldcBuild-1.7.0.drv-3/ldc-v1.7.0-src/build/bin/ldc2 -enable-dynamic-compile -dynamic-compile-tls-workaround=0 -run /private/tmp/nix-build-ldcBuild-1.7.0.drv-3/ldc-v1.7.0-src/tests/dynamiccompile/tls_workaround_opt.d 771: /tmp/nix-build-ldcBuild-1.7.0.drv-3/ldc-v1.7.0-src/build/bin/ldc2 -enable-dynamic-compile -dynamic-compile-tls-workaround=1 -run /private/tmp/nix-build-ldcBuild-1.7.0.drv-3/ldc-v1.7.0-src/tests/dynamiccompile/tls_workaround_opt.d 771: -- 771: Exit Code: 2 771: 771: Command Output (stdout): 771: -- 771: $ "/tmp/nix-build-ldcBuild-1.7.0.drv-3/ldc-v1.7.0-src/build/bin/ldc2" "-enable-dynamic-compile" "-dynamic-compile-tls-workaround=0" "-run" "/private/tmp/nix-build-ldcBuild-1.7.0.drv-3/ldc-v1.7.0-src/tests/dynamiccompile/tls_workaround_opt.d" 771: # command stderr: 771: dyld: Library not loaded: libldc-jit.77.dylib 771: Referenced from: /private/tmp/nix-build-ldcBuild-1.7.0.drv-3/lit_tmp_Y5IInt/tls_workaround_opt-9829df1-e7c05f 771: Reason: image not found 771: Error: /private/tmp/nix-build-ldcBuild-1.7.0.drv-3/lit_tmp_Y5IInt/tls_workaround_opt-9829df1-e7c05f failed with status: -2 771: Error: message: Abort trap: 6 771: Error: program received signal 2 (Interrupt: 2) 771: 771: error: command failed with exit status: 2 771: 771: -- 771: 771: ********************

@Hardcode84
Copy link
Contributor Author

@ThomasMader can you, please, add instructions how to reproduce Nix setup and how to test specific branch.

@ThomasMader
Copy link
Contributor

On a Mac you should be able to reproduce.

  • You need to checkout https://github.com/ThomasMader/nixpkgs/tree/dynamiccompile
  • Install nix on the machine with: curl https://nixos.org/nix/install | sh
  • cd into the repository and run: nix-build -K -A ldc
    This will need some time because it needs to build the bootstrap compiler too because this changed package is not in the official binary caches.
    It should fail as I reported. The -K option leaves the build directory and you will see the path to it somewhere at the end of the output when failing. It's a directory in /private/tmp
    If you want to run just the specific lit tests from there you need to use: nix-shell -A ldc
    For this to work you need to be in the repository directory too. This should get you into an environment/shell equal to the build. In there you can switch to the temp build dir and just rerun the lit tests or whatever.
    It might be possible that you get permission problems on the rerun. In this case you need to move the temp build dir somewhere else.

Hope this helps.
I can also offer you to try to fix it for myself but as it is now, I don't have a clue what's going on with this dynamiccompile stuff at all.
You will need to brief me.

The changes you made are mainly in linker-gcc.cpp as far as I remember. Because of the file name I guess it has something to do with gcc. Maybe that is the problem? In the package description for ldc in Nix there is no dependency to gcc at all. It's just clang with llvm.

You can see all dependencies on top of the package description file which can be found in the repository at: pkgs/development/compilers/ldc/default.nix

@JohanEngelen
Copy link
Member

fyi, linker-gcc.cpp handles all non-windows linking. On macOS, we use the gcc driver for linking (it's just a front for clang).

@ThomasMader
Copy link
Contributor

You need to checkout https://github.com/ThomasMader/nixpkgs/tree/dynamiccompile

@Hardcode84 Just realized that I forgot to push the change to use your ldc branch in the package description.
Now it should be fine.

@kinke
Copy link
Member

kinke commented Apr 22, 2018

Update: current master already makes sure the install_name of shared lib ldc-jit contains @rpath. It also sets the default rpath when linking with -enable-dynamic-compile. It doesn't set an additional @executable_path rpath as this PR though - I think that should be left to the user, as it depends on how he/she is going to deploy the software (e.g., may use @executable_path/../lib or whatever).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants