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

LLVM upgrade #34743

Merged
merged 33 commits into from
Aug 1, 2016
Merged

LLVM upgrade #34743

merged 33 commits into from
Aug 1, 2016

Conversation

badboy
Copy link
Member

@badboy badboy commented Jul 9, 2016

As discussed in https://internals.rust-lang.org/t/need-help-with-emscripten-port/3154/46 I'm trying to update the used LLVM checkout in Rust.

I basically took @shepmaster's code and applied it on top (though I did the commits manually, the original commits have better descriptions.

With these changes I was able to build rustc. make check throws one last error on run-pass/issue-28950.rs. Output: https://gist.github.com/badboy/bcdd3bbde260860b6159aa49070a9052

I took the metadata changes as is and they seem to work, though it now uses the module in another step. I'm not sure if this is the best and correct way.

Things to do:

  • Make run-pass/issue-28950.rs pass unrelated
  • Find out how the PositionIndependentExecutable setting is now used
  • Is the llvm::legacy still the right way to do these things?

cc @brson @alexcrichton

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @pnkfelix (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@badboy
Copy link
Member Author

badboy commented Jul 9, 2016

Ah, forgot to mention that I am using a LLVM checkout of http://llvm.org/git/llvm.git

@@ -267,7 +267,7 @@ LLVMRustAddLibraryInfo(LLVMPassManagerRef PMB,
// similar code in clang's BackendUtil.cpp file.
extern "C" void
LLVMRustRunFunctionPassManager(LLVMPassManagerRef PM, LLVMModuleRef M) {
FunctionPassManager *P = unwrap<FunctionPassManager>(PM);
llvm::legacy::FunctionPassManager *P = unwrap<llvm::legacy::FunctionPassManager>(PM);
Copy link
Member

Choose a reason for hiding this comment

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

llvm::legacy::FunctionPassManager

Tangential comment to this pull request: Does anyone know what this got replaced with since it's presumably legacy now?

Copy link
Contributor

Choose a reason for hiding this comment

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

LLVM pass manager infrastructure is currently getting rewritten to be more flexible. See https://github.com/llvm-mirror/llvm/blob/d1aa4ea020d932ffc6a3c3e4d1bbab659391c725/tools/opt/NewPMDriver.cpp#L50 for a usage example for the new API. That said, the rewrite isn't complete yet.

Copy link
Member

Choose a reason for hiding this comment

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

Looks like clang is also still using this, so we probably don't need to update just yet until they do at least.

@@ -188,7 +188,7 @@ LLVMRustCreateTargetMachine(const char *triple,
}

TargetOptions Options;
Options.PositionIndependentExecutable = PositionIndependentExecutable;
//Options.PositionIndependentExecutable = PositionIndependentExecutable;
Copy link
Member

Choose a reason for hiding this comment

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

I'm pretty sure this is a hack that only makes sense in my fork (there's no PIE for microcontrollers :-)).

Even if we wanted to remove this (doubtful), it should be removed and not commented-out. I believe that LLVM applies this flag at a more granular level now, so looking downward for another flag to apply it to seems reasonable.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, this is one of the things mentioned above. I left it in, so I remember to fix that.

Copy link
Member

Choose a reason for hiding this comment

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

This was deleted here which appears to be replaced by this which is a new setPIELevel function on the LLVM module itself.

The LLVM module isn't available at this time so we'll just have to arrange for it to be set later. Perhaps something like this though:

  • Leave this block, but gated by #if LLVM_VERSION_MINOR <= 8 for compatibility with older versions.
  • Add LLVMRustSetModulePIELevel as a function which is a noop on pre-LLVM-3.9 and afterwards calls the setPIELevel function on the LLVM module.

Copy link
Member Author

Choose a reason for hiding this comment

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

Did you mean we have a LLVMRustSetModulePIELevel with the #ifdef for calling the setPIELevel method?
If so, at what point do we call it?

Copy link
Member

Choose a reason for hiding this comment

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

If so, at what point do we call it?

I'd believe you want to call it every time an LLVM module is created.

@shepmaster
Copy link
Member

I'm no core contributor, but I don't see the value in commit X introducing less-than-great variable names and then commit X+1 improving them. I'd just squash those two together.

@badboy
Copy link
Member Author

badboy commented Jul 9, 2016

@shepmaster yes, I should have squashed them beforehand. I can still do this.

let work_dir = &cx.sess().working_dir;
let compile_unit_name = match cx.sess().local_crate_source_file {
None => fallback_path(cx),
pub fn compile_unit_metadata(scc: &::context::SharedCrateContext, debug_context: &CrateDebugContext, sess: &::session::Session) -> DIDescriptor {
Copy link
Member

Choose a reason for hiding this comment

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

Right now our line limit is 100 characters so I think this will trigger make tidy, could you also add imports instead of using absolute paths here?

@alexcrichton
Copy link
Member

A failure on issue-28950 looks like it may be specific to your system or something like that, I doubt that the LLVM changes would cause it to fail. Are you sure that it succeeds before this PR on your local computer?

@badboy
Copy link
Member Author

badboy commented Jul 10, 2016

@alexcrichton Indeed, with a fresh checkout of rust-lang/rust I see the same error on issue-28950

@alexbool
Copy link
Contributor

This is supposed to fix #34119 ?

@badboy
Copy link
Member Author

badboy commented Jul 11, 2016

@alexbool If it is fixed by something in LLVM upstream, then yes

@brson
Copy link
Contributor

brson commented Jul 11, 2016

cc @kripken Here's Rust's LLVM upgrade.

@kripken
Copy link

kripken commented Jul 11, 2016

@brson: cool, emscripten's merges of that same LLVM commit are in https://github.com/kripken/emscripten-fastcomp/tree/next-merge and https://github.com/kripken/emscripten-fastcomp-clang/tree/next-merge .

The tracking issue is emscripten-core/emscripten#4430. Looks like only some SIMD issues block it, which probably wouldn't be a problem for rust, so it could be usable for testing already.

@shepmaster
Copy link
Member

I'd strongly encourage having links to the original LLVM issues / commits that are forcing these changes. These links should be in the commit message that modifies the relevant aspect of the code. That should make it much easier for people in the future to track down the why.

@shepmaster
Copy link
Member

That should make it much easier for people in the future to track down the why.

I say this having been one of those people to track down such information in the past.

@alexcrichton
Copy link
Member

@shepmaster to clarify, you mean the changes to LLVM bindings and why they're changing? (e.g. this)

@shepmaster
Copy link
Member

you mean the changes to LLVM bindings and why they're changing

Yeah; sorry to be unclear. Having the commit message be something like

[LLVM 3.9] Configure PIE at the module level instead of compilation unit level

This was deleted here[linky] which appears to be replaced by this[linky] which is a new setPIELevel function on the LLVM module itself.

would make that commit 💯 in my book. Otherwise the commit is like "moving some functions around!"

Again, I stress that I hold no power to enforce these suggestions; I just would have found commits like this to be useful when I was digging into the existing code to make these kind of changes. 🌴

@alexcrichton
Copy link
Member

Sounds like a good plan to me!

@badboy
Copy link
Member Author

badboy commented Jul 12, 2016

I will rebase the commits and change accordingly (force-push incoming!)

@shepmaster Thanks for mentioning this, it's indeed a good idea, especially in the long run

@solson
Copy link
Member

solson commented Jul 13, 2016

@alexcrichton @eddyb Can this PR also be placed under the "Launch MIR into Orbit" milestone, since it's blocking #34119?

@alexcrichton alexcrichton added this to the Launch MIR into Orbit milestone Jul 13, 2016
@alexcrichton
Copy link
Member

@solson sure!

@badboy
Copy link
Member Author

badboy commented Jul 14, 2016

I just force-pushed with the new commits

  • Reorganized all commits into logical blocks, including proper descriptions and links
  • I had to upgrade compiler-rt as well to get it to compile, this is not yet reflected here
  • I had to re-enable the std::thread thing in LLVM to get it to compile at least once. We probably need to find a proper workaround first.
  • When choosing anything other than Default in ffc5a8608f1418f6a52f754232ba5edb90427370 I get the following error on compile:
error: linking with `cc` failed: exit code: 1
note: "cc" "-Wl,--as-needed" "-Wl,-z,noexecstack" "-m64" "-L" "/home/jer/src/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib" "/home/jer/src/rust/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/debug/deps/std-b8d6c224bdd7e5ff.0.o" "/home/jer/src/rust/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/debug/deps/std-b8d6c224bdd7e5ff.1.o" "/home/jer/src/rust/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/debug/deps/std-b8d6c224bdd7e5ff.2.o" "/home/jer/src/rust/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/debug/deps/std-b8d6c224bdd7e5ff.3.o" "-o" "/home/jer/src/rust/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/debug/deps/libstd-b8d6c224bdd7e5ff.so" "/home/jer/src/rust/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/debug/deps/std-b8d6c224bdd7e5ff.metadata.o" "-nodefaultlibs" "-L" "/home/jer/src/rust/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/debug/deps" "-L" "/home/jer/src/rust/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/debug/deps" "-L" "/home/jer/src/rust/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/debug/build/std-26167b16044fc6c3/out/.libs" "-L" "/home/jer/src/rust/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/debug/build/alloc_jemalloc-0986af1f8480d6ae/out/lib" "-L" "/home/jer/src/rust/build/x86_64-unknown-linux-gnu/stage1/lib/rustlib/x86_64-unknown-linux-gnu/lib" "-Wl,-Bstatic" "-Wl,--whole-archive" "-l" "backtrace" "-Wl,--no-whole-archive" "-Wl,-Bdynamic" "-l" "dl" "-l" "rt" "-l" "pthread" "-Wl,--whole-archive" "/tmp/rustc.FqfLoqjnVH7z/libcollections-af9a9d510058b25a.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.FqfLoqjnVH7z/libpanic_unwind-17c382f05cff5951.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.FqfLoqjnVH7z/liballoc-3e8adf33e113f98f.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.FqfLoqjnVH7z/liballoc_jemalloc-565df9f061d73123.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.FqfLoqjnVH7z/librustc_unicode-f4dd78d2f1b9c500.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.FqfLoqjnVH7z/libunwind-f70560ece060458e.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.FqfLoqjnVH7z/liblibc-b8c0e2a7b980b655.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.FqfLoqjnVH7z/librand-f0667cf9d06dbb0e.rlib" "-Wl,--no-whole-archive" "-Wl,--whole-archive" "/tmp/rustc.FqfLoqjnVH7z/libcore-d7d9994298ae504c.rlib" "-Wl,--no-whole-archive" "-l" "pthread" "-l" "gcc_s" "-l" "c" "-l" "m" "-l" "rt" "-l" "util" "-shared" "-Wl,-rpath,$ORIGIN/../lib" "-l" "compiler-rt"
note: /usr/bin/ld: /home/jer/src/rust/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/debug/deps/std-b8d6c224bdd7e5ff.0.o: relocation R_X86_64_TPOFF32 against `_ZN3std11collections4hash3map11RandomState3new4KEYS7__getit5__KEY17hc8a582c36b9a9c3eE' can not be used when making a shared object; recompile with -fPIC
/home/jer/src/rust/build/x86_64-unknown-linux-gnu/stage1-std/x86_64-unknown-linux-gnu/debug/deps/std-b8d6c224bdd7e5ff.0.o: error adding symbols: Bad value
collect2: error: ld returned 1 exit status

error: aborting due to previous error
error: Could not compile `std`.

It seems something is not compiled correctly with -fPIC, but I'm not sure what to do here.

@eddyb
Copy link
Member

eddyb commented Jul 31, 2016

@tmiasko That's interesting. Do you have a backtrace? We couldn't get anything, reproduction seemed to need the concurrent builds, or a specific builder, to trigger.

@alexcrichton
Copy link
Member

@tmiasko did some digging and discovered that https://reviews.llvm.org/D22858 may be relevant (stack trace gathered). I've updated our LLVM submodule with this commit (rebased on the llvm/release_39 branch) and now it's rust-lang/llvm@d1cc489. @badboy wanna try updating to that and give it a go? Builds in dev are running, but we can do in parallel hopefully :)

@tmiasko did some digging and discovered that
https://reviews.llvm.org/D22858 may be relevant.
@badboy
Copy link
Member Author

badboy commented Aug 1, 2016

Done! Upgraded to d1cc489

@eddyb
Copy link
Member

eddyb commented Aug 1, 2016

@bors r+

@bors
Copy link
Contributor

bors commented Aug 1, 2016

📌 Commit 5d1d247 has been approved by eddyb

@bors
Copy link
Contributor

bors commented Aug 1, 2016

⌛ Testing commit 5d1d247 with merge 2c1612c...

bors added a commit that referenced this pull request Aug 1, 2016
LLVM upgrade

As discussed in https://internals.rust-lang.org/t/need-help-with-emscripten-port/3154/46 I'm trying to update the used LLVM checkout in Rust.

I basically took @shepmaster's code and applied it on top (though I did the commits manually, the [original commits have better descriptions](master...avr-rust:avr-support).

With these changes I was able to build rustc. `make check` throws one last error on `run-pass/issue-28950.rs`. Output: https://gist.github.com/badboy/bcdd3bbde260860b6159aa49070a9052

I took the metadata changes as is and they seem to work, though it now uses the module in another step. I'm not sure if this is the best and correct way.

Things to do:

* [x] ~~Make `run-pass/issue-28950.rs` pass~~ unrelated
* [x] Find out how the `PositionIndependentExecutable` setting is now used
* [x] Is the `llvm::legacy` still the right way to do these things?

cc @brson @alexcrichton
@badboy
Copy link
Member Author

badboy commented Aug 1, 2016

Wuhu! 🎉

@eminence
Copy link
Contributor

eminence commented Aug 1, 2016

Outstanding work everyone!

@michaelwoerister
Copy link
Member

Epic! :)

@shepmaster
Copy link
Member

Hurrah! Now it's time to rebase the AVR and Emscripten forks and really give it a workout ;-)

@badboy
Copy link
Member Author

badboy commented Aug 1, 2016

@shepmaster: That's the next step and I'll try to work on it this week

@bstrie
Copy link
Contributor

bstrie commented Aug 1, 2016

Heroes, every one of you! On with MIR!

@whitequark
Copy link
Member

Looks like this missed the LLVM version check in configure, not sure why it didn't break bots:

--- .../rust/configure  Sat Aug 13 01:03:47 2016
+++ .../rust/configure  Sat Aug 13 01:03:50 2016
@@ -1013,7 +1013,7 @@
     LLVM_VERSION=$($LLVM_CONFIG --version)

     case $LLVM_VERSION in
-        (3.[7-8]*)
+        (3.[7-9]*)
             msg "found ok version of LLVM: $LLVM_VERSION"
             ;;
         (*)

@shepmaster
Copy link
Member

I have a PR out for that - #35594. No idea about the bots.

spladug added a commit to spladug/rust that referenced this pull request Aug 17, 2016
The minimum got bumped in the LLVM upgrade of rust-lang#34743.
eddyb added a commit to eddyb/rust that referenced this pull request Aug 18, 2016
…omatsakis

Update minimum CMake version in README

The minimum got bumped in the LLVM upgrade of rust-lang#34743.
pmatos pushed a commit to LinkiTools/rust that referenced this pull request Sep 27, 2016
Soon the LLVM upgrade (rust-lang#34743) will require an updated CMake installation, and
the easiest way to do this was to upgrade the Ubuntu version of the bots to
16.04. This in turn brings in a new MIPS compiler on the linux-cross builder,
which is now from the "official" ubuntu repositories. Unfortunately these
new compilers don't support compiling with the `-msoft-float` flag like we're
currently passing, causing compiles to fail.

This commit removes these flags as it's not clear *why* they're being passed, as
the mipsel targets also don't have it. At least if it's not supported by a
debian default compiler, perhaps it's not too relevant to support?
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.

None yet