Stream: t-compiler/help

Topic: LLVM / rustc symbol names missing


Jake Goulding (Jun 20 2020 at 11:13, on Zulip):

I'm trying to debug an LLVM assertion, but I don't have symbol names. This is my config.toml:

[llvm]
optimize = true
release-debuginfo = true
assertions = true

[rust]
debug = true
incremental = true
Jake Goulding (Jun 20 2020 at 11:13, on Zulip):

I deleted my build directory and rebuilt overnight, so there shouldn't be any strange leftovers

Jake Goulding (Jun 20 2020 at 11:19, on Zulip):

Any other settings I might have missed?

Jake Goulding (Jun 20 2020 at 14:10, on Zulip):

It seems like I have symbols once I look at libstd, but not in librustc_driver — is there special debug flags for that?

Jake Goulding (Jun 20 2020 at 14:13, on Zulip):

I have a build/x86_64-apple-darwin/stage1-rustc/x86_64-apple-darwin/release/deps/librustc_driver-4db96b6858843117.dylib.dSYM which seems like it should be applicable

Jake Goulding (Jun 20 2020 at 14:24, on Zulip):
(lldb) script lldb.target.module['/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage2/bin/rustc'].GetNumCompileUnits()
2

(lldb) script lldb.target.module['/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage2/lib/libstd-4bf044f23608a072.dylib'].GetNumCompileUnits()
351

(lldb) script lldb.target.module['/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage2/lib/librustc_driver-4db96b6858843117.dylib'].GetNumCompileUnits()
0
simulacrum (Jun 20 2020 at 14:38, on Zulip):

Hm, I think this might be fixed on latest beta but we haven't bumped yet..

simulacrum (Jun 20 2020 at 14:39, on Zulip):

https://github.com/rust-lang/cargo/pull/8329

simulacrum (Jun 20 2020 at 14:39, on Zulip):

But that might not be it since this is presumably not an executable

Jake Goulding (Jun 20 2020 at 14:39, on Zulip):

Ok; is there a way I can do the bump locally, test it (and then push the bump?)

simulacrum (Jun 20 2020 at 14:40, on Zulip):

Ah yeah, easiest is probably to rustup update beta and then edit config.toml to point cargo at ~/.rustup/toolchains/beta.../bin/cargo

simulacrum (Jun 20 2020 at 14:40, on Zulip):

(with tilde expanded)

simulacrum (Jun 20 2020 at 14:40, on Zulip):

We have a PR up for the bump to be clear

Jake Goulding (Jun 20 2020 at 14:42, on Zulip):

Worth a shot; I'll report back in 1.5 hours after the rebuild

simulacrum (Jun 20 2020 at 14:42, on Zulip):

But if that doesn't help, and I think it might not, I would try and see if there's dsym files in the build/host/stage2/lib directory - if not, you may be able to copy them in manually from stage2-rustc

simulacrum (Jun 20 2020 at 14:42, on Zulip):

@Jake Goulding you shouldn't need to rebuild llvm

simulacrum (Jun 20 2020 at 14:42, on Zulip):

So x.py clean should delete everything else

Jake Goulding (Jun 20 2020 at 14:43, on Zulip):

copy them in manually from stage2-rustc

Copy them to ... ?

Jake Goulding (Jun 20 2020 at 14:47, on Zulip):
running: "/Users/shep/.rustup/toolchains/beta-x86_64-apple-darwin/bin/cargo" "build" "--target" "x86_64-apple-darwin" "-Zbinary-dep-depinfo" "-j" "12" "--release" "--features" "panic-unwind backtrace compiler-builtins-c" "--manifest-path" "/Users/shep/Projects/rust/src/libtest/Cargo.toml" "--message-format" "json-render-diagnostics"

Should I worry that there's no obvious debug symbol arguments in this execution?

simulacrum (Jun 20 2020 at 15:24, on Zulip):

well cargo itself doesn't really have command line debug flags, so no that should be fine

simulacrum (Jun 20 2020 at 15:24, on Zulip):

(we set an env variable IIRC?)

simulacrum (Jun 20 2020 at 15:25, on Zulip):

I imagine if you're getting std backtraces you can do the same with rustc dsym as std dsym already happened(?)

simulacrum (Jun 20 2020 at 15:25, on Zulip):

I'm not really familiar with the particulars of how dsym/debuginfo on macos works

Jake Goulding (Jun 20 2020 at 15:35, on Zulip):

Using the newer beta doesn't seem to help

Jake Goulding (Jun 20 2020 at 15:36, on Zulip):

What's strange is that LLDB _knows_ there is a debugging file:

[  0] 77A76DF3-8E0F-371C-866F-D263997580C1 0x0000000100000000 /Users/shep/Projects/rust/build/x86_64-apple-darwin/stage1/bin/rustc
      /System/Volumes/Data/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/x86_64-apple-darwin/release/deps/rustc_binary-d9ae79f3133c58cb.dSYM/Contents/Resources/DWARF/rustc_binary-d9ae79f3133c58cb
[  1] E4698FBD-806A-3396-B279-E685BA37430B 0x0000000100004000 /usr/lib/dyld
[  2] 44B06C71-9E27-35C7-8392-93847F85DF07 0x0000000100109000 /Users/shep/Projects/rust/build/x86_64-apple-darwin/stage1/lib/librustc_driver-ac37c53b8f5deab0.dylib
      /System/Volumes/Data/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/x86_64-apple-darwin/release/deps/librustc_driver-ac37c53b8f5deab0.dylib.dSYM/Contents/Resources/DWARF/librustc_driver-ac37c53b8f5deab0.dylib
[  3] F90C4365-BAA1-331B-A7A6-562F049C47E1 0x000000010ee17000 /Users/shep/Projects/rust/build/x86_64-apple-darwin/stage1/lib/libstd-bde4c9f9be2d6057.dylib
      /System/Volumes/Data/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-std/x86_64-apple-darwin/release/deps/libstd-bde4c9f9be2d6057.dylib.dSYM/Contents/Resources/DWARF/libstd-bde4c9f9be2d6057.dylib
Jake Goulding (Jun 20 2020 at 15:37, on Zulip):

And file states

/System/Volumes/Data/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/x86_64-apple-darwin/release/deps/librustc_driver-ac37c53b8f5deab0.dylib.dSYM/Contents/Resources/DWARF/librustc_driver-ac37c53b8f5deab0.dylib: Mach-O 64-bit dSYM companion file x86_64
simulacrum (Jun 20 2020 at 15:45, on Zulip):

hm

simulacrum (Jun 20 2020 at 15:45, on Zulip):

maybe we're not able to find LLVM debuginfo though?

simulacrum (Jun 20 2020 at 15:45, on Zulip):

I have no idea how static linking and debuginfo play together

simulacrum (Jun 20 2020 at 15:45, on Zulip):

(IIRC we are static linking llvm?)

Jake Goulding (Jun 20 2020 at 15:46, on Zulip):

That was my understanding as well (... statically linking LLVM into the dynamic library so we can have multiple LLVM backends concurrently, last I remember)

Jake Goulding (Jun 20 2020 at 15:46, on Zulip):

that was to support "new" LLVM and "old" Emscripten LLVM; so that info is a few years old

Jake Goulding (Jun 20 2020 at 15:47, on Zulip):

But I feel that the problem has to be one step higher, as the Rust code in librustc_driver also doesn't have symbols

Jake Goulding (Jun 20 2020 at 15:48, on Zulip):

e.g.

frame #23: 0x000000010010bdaf librustc_driver-ac37c53b8f5deab0.dylib`rustc_interface::interface::run_compiler_in_existing_thread_pool::hb87d26f888e882b2 + 751
librustc_driver-ac37c53b8f5deab0.dylib`rustc_interface::interface::run_compiler_in_existing_thread_pool::hb87d26f888e882b2:
->  0x10010bdaf <+751>: movl   %eax, %r15d
    0x10010bdb2 <+754>: movq   0x638(%rbx), %rax
    0x10010bdb9 <+761>: testq  %rax, %rax
    0x10010bdbc <+764>: je     0x10010bdd3               ; <+787>
Jake Goulding (Jun 20 2020 at 15:55, on Zulip):
   Compiling rustc_driver v0.0.0 (/Users/shep/Projects/rust/src/librustc_driver)

How can I get that to be a cargo --verbose output instead? Maybe seeing how that crate is compiled would help

Jake Goulding (Jun 20 2020 at 15:58, on Zulip):

And LLVM has some amount of symbols, as running llc inside of lldb shows some source code.

Jake Goulding (Jun 20 2020 at 15:59, on Zulip):

I guess I could also try to create a parallel reproduction — a C library with debug symbols, linked into a Rust dylib, loaded into a Rust program (ugh that sounds like a lot of work)

Jake Goulding (Jun 20 2020 at 16:00, on Zulip):

I'm just a bit surprised that I'm the first to run into this; it's not like macOS is a never-used platform, and I know people use debuggers.

simulacrum (Jun 20 2020 at 16:00, on Zulip):

-vvvv to x.py should work

simulacrum (Jun 20 2020 at 16:01, on Zulip):

there should be no dynamic linking in the llvm / codegen backends these days by default

simulacrum (Jun 20 2020 at 16:01, on Zulip):

(rustc_driver is still a dylib iirc though)

bjorn3 (Jun 20 2020 at 16:07, on Zulip):

Jake Goulding said:

that was to support "new" LLVM and "old" Emscripten LLVM; so that info is a few years old

rustc_codegen_llvm has since been turned into a regular dependency of rustc_driver, so it is no longer possible to have multiple LLVM backends.

simulacrum (Jun 20 2020 at 16:09, on Zulip):

it is, I think, just not easily -- we still have the codegen loading code

bjorn3 (Jun 20 2020 at 16:11, on Zulip):

The codegen loading code doesn't support loading from the sysroot anymore. It only supports absolute paths. And yes it is technically still possible to compile rustc_codegen_llvm separately. You do have to add crate-type = ["dylib"] and extern crate rustc_driver; though.

simulacrum (Jun 20 2020 at 16:12, on Zulip):

oh sure

simulacrum (Jun 20 2020 at 16:12, on Zulip):

but that all seems like "support mostly still there"

Jake Goulding (Jun 20 2020 at 16:22, on Zulip):

Rebuilding with -vvvv; we'll see if anything pops out

Jake Goulding (Jun 20 2020 at 16:24, on Zulip):
rustc command: \
"DYLD_LIBRARY_PATH"="/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0/lib" \
"/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0/bin/rustc" \
"--crate-name" \
"build_script_build" \
"--edition=2018" \
"src/librustc_driver/build.rs" \
"--error-format=json" \
"--json=diagnostic-rendered-ansi" \
"--crate-type" \
"bin" \
"--emit=dep-info,link" \
"-C" \
"opt-level=3" \
"-Cembed-bitcode=no" \
"-C" \
"debuginfo=2" \
"--cfg" \
"feature=\"llvm\"" \
"-C" \
"metadata=f21e2d1fd9668325" \
"-C" \
"extra-filename=-f21e2d1fd9668325" \
"--out-dir" \
"/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/release/build/rustc_driver-f21e2d1fd9668325" \
"-C" \
"incremental=/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/release/incremental" \
"-L" \
"dependency=/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/release/deps" \
"-Zbinary-dep-depinfo"
Jake Goulding (Jun 20 2020 at 16:25, on Zulip):

so the build script has debugging :upside_down:

Jake Goulding (Jun 20 2020 at 17:33, on Zulip):
rustc command: \
"DYLD_LIBRARY_PATH"="/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0/lib" \
"/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0/bin/rustc" \
"--crate-name" "rustc_driver" \
"--edition=2018" \
"src/librustc_driver/lib.rs" \
"--error-format=json" \
"--json=diagnostic-rendered-ansi" \
"--crate-type" "dylib" \
"--emit=dep-info,link" \
"-C" "prefer-dynamic" \
"-C" "opt-level=3" \
"-Cembed-bitcode=no" \
"-C" "debuginfo=2" \
"--cfg" "feature=\"llvm\"" \
"-C" "metadata=ac37c53b8f5deab0" \
"-C" "extra-filename=-ac37c53b8f5deab0" \
"--out-dir" "/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/x86_64-apple-darwin/release/deps" \
"--target" "x86_64-apple-darwin" \
"-C" "incremental=/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/x86_64-apple-darwin/release/incremental" \
"-L" "dependency=/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/x86_64-apple-darwin/release/deps" \
"-L" "dependency=/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/release/deps" \
"--extern" "env_logger=/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/x86_64-apple-darwin/release/deps/libenv_logger-279167b967f1d3a9.rlib" \
"--extern" "lazy_static=/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/x86_64-apple-darwin/release/deps/liblazy_static-73707428c7faebec.rlib" \
"--extern" "libc=/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/x86_64-apple-darwin/release/deps/liblibc-2ddc9b87cd47ca28.rlib" \
"--extern" "log=/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/x86_64-apple-darwin/release/deps/liblog-c9b296a3791658e0.rlib" \
"--extern" "rustc_ast=/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/x86_64-apple-darwin/release/deps/librustc_ast-3a4eed4c61ca1aee.rlib" \
"--extern" "rustc_ast_pretty=/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/x86_64-apple-darwin/release/deps/librustc_ast_pretty-8a5210dab4898efc.rlib" \
"--extern" "rustc_codegen_ssa=/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/x86_64-apple-darwin/release/deps/librustc_codegen_ssa-755bea4b5a82ffe2.rlib" \
"--extern" "rustc_data_structures=/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/x86_64-apple-darwin/release/deps/librustc_data_structures-fefcef1c6b450e7a.rlib" \
"--extern" "rustc_error_codes=/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/x86_64-apple-darwin/release/deps/librustc_error_codes-a6d97085eea602f0.rlib" \
"--extern" "rustc_errors=/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/x86_64-apple-darwin/release/deps/librustc_errors-c64bcc90664ca3de.rlib" \
"--extern" "rustc_feature=/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/x86_64-apple-darwin/release/deps/librustc_feature-30106191771ae53b.rlib" \
"--extern" "rustc_hir=/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/x86_64-apple-darwin/release/deps/librustc_hir-d07084e5ca85481f.rlib" \
"--extern" "rustc_hir_pretty=/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/x86_64-apple-darwin/release/deps/librustc_hir_pretty-1b8165c2917acfaa.rlib" \
"--extern" "rustc_interface=/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/x86_64-apple-darwin/release/deps/librustc_interface-654bb2110d58d634.rlib" \
"--extern" "rustc_lint=/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/x86_64-apple-darwin/release/deps/librustc_lint-a39907fd6d163331.rlib" \
"--extern" "rustc_metadata=/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/x86_64-apple-darwin/release/deps/librustc_metadata-2e15c00629886ae0.rlib" \
"--extern" "rustc_middle=/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/x86_64-apple-darwin/release/deps/librustc_middle-2c2e0c8acf8e51b9.rlib" \
"--extern" "rustc_mir=/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/x86_64-apple-darwin/release/deps/librustc_mir-5c4efa7c7d494816.rlib" \
"--extern" "rustc_parse=/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/x86_64-apple-darwin/release/deps/librustc_parse-54e3fda7a722ed84.rlib" \
"--extern" "rustc_plugin_impl=/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/x86_64-apple-darwin/release/deps/librustc_plugin_impl-041835cd58d884fe.rlib" \
"--extern" "rustc_save_analysis=/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/x86_64-apple-darwin/release/deps/librustc_save_analysis-554311788e63e557.rlib" \
"--extern" "rustc_serialize=/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/x86_64-apple-darwin/release/deps/librustc_serialize-9aa7982af7ecc463.rlib" \
"--extern" "rustc_session=/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/x86_64-apple-darwin/release/deps/librustc_session-570425574f2048ad.rlib" \
"--extern" "rustc_span=/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/x86_64-apple-darwin/release/deps/librustc_span-4c530e026d8b3a4c.rlib" \
"--extern" "rustc_target=/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/x86_64-apple-darwin/release/deps/librustc_target-0454220c81561b05.rlib" \
"--cfg=bootstrap" \
"-Zmacro-backtrace" \
"-Zosx-rpath-install-name" \
"-Clink-args=-Wl,-rpath,@loader_path/../lib" \
"-Wrust_2018_idioms" \
"-Wunused_lifetimes" \
"-Dwarnings" \
"-Zunstable-options" \
"-Wrustc::internal" \
"-Cprefer-dynamic" \
"-Cllvm-args=-import-instr-limit=10" \
"-Zbinary-dep-depinfo" \
"-L" "native=/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/x86_64-apple-darwin/release/build/psm-a38ad44340af03da/out" \
"-L" "native=/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-rustc/x86_64-apple-darwin/release/build/rustc_llvm-fcb13369a7b1386b/out" \
"-L" "native=/Users/shep/Projects/rust/build/x86_64-apple-darwin/llvm/build/lib" \
"--sysroot" "/Users/shep/Projects/rust/build/x86_64-apple-darwin/stage0-sysroot" \
"-C" "debug-assertions=y" \
"-Z" "force-unstable-if-unmarked"
Jake Goulding (Jun 20 2020 at 17:35, on Zulip):

so, debuginfo is 2, which is what I'd expect...

Jake Goulding (Jun 20 2020 at 18:08, on Zulip):

It's also frustrating because libstd is dynamically linked as well

Jake Goulding (Jun 20 2020 at 18:32, on Zulip):

And trying to reproduce doesn't exhibit the same problem. I directly added the dylib project as a dependency and used libloading, but both ways has symbols in the library

nagisa (Jun 21 2020 at 02:46, on Zulip):

readelf of a solib/binary should answer if the debug info does in fact remain in the final outputs.

nagisa (Jun 21 2020 at 02:48, on Zulip):
readelf --debug-dump=info dsoname | grep -A 2 'Compilation Unit @

is something I had in my scrollback.

Last update: Sep 28 2020 at 14:45UTC