Include debuginfo in release builds of LLVM by default

53efcb0
Opened by Ximin Luo at 2023-05-20 22:29:04

This would be useful to help debug things like #42476. At the moment I can only debug it using Debian's rustc as stage0 - its LLVM is built separately and dynamically linked into librustc_llvm, so debugging symbols work there. However with rust's own 1.16 stage0 I get this instead:

(gdb) bt
#0  0x00003fffb5e6180c in (anonymous namespace)::ELFObjectWriter::computeSymbolTable(llvm::MCAssembler&, llvm::MCAsmLayout const&, llvm::DenseMap<llvm::MCSectionELF const*, unsigned int, llvm::DenseMapInfo<llvm::MCSectionELF const*>, llvm::detail::DenseMapPair<llvm::MCSectionELF const*, unsigned int> > const&, llvm::DenseMap<llvm::MCSymbol const*, unsigned int, llvm::DenseMapInfo<llvm::MCSymbol const*>, llvm::detail::DenseMapPair<llvm::MCSymbol const*, unsigned int> > const&, std::map<llvm::MCSectionELF const*, std::pair<unsigned long, unsigned long>, std::less<llvm::MCSectionELF const*>, std::allocator<std::pair<llvm::MCSectionELF const* const, std::pair<unsigned long, unsigned long> > > >&) [clone .constprop.338] ()
   from /home/infinity0/build2/rustc-1.17.0+dfsg2/build/powerpc64le-unknown-linux-gnu/stage0/bin/../lib/../lib/librustc_llvm-1b4bf1d78c7d2bcc.so
[..]

(sid_ppc64el-dchroot)infinity0@plummer:~/rustc-1.17.0+dfsg2$ sha256sum /home/infinity0/build2/rustc-1.17.0+dfsg2/build/powerpc64le-unknown-linux-gnu/stage0/bin/../lib/../lib/librustc_llvm-1b4bf1d78c7d2bcc.so  
d3090a547a2a8189cb116cc726965e4af0695cd4ae48ae41f05224a3d429534b  /home/infinity0/build2/rustc-1.17.0+dfsg2/build/powerpc64le-unknown-linux-gnu/stage0/bin/../lib/../lib/librustc_llvm-1b4bf1d78c7d2bcc.so
^^^^ matches the one from rustc-1.16.0-powerpc64le-unknown-linux-gnu.tar.gz

(sid_ppc64el-dchroot)infinity0@plummer:~/rustc-1.17.0+dfsg2$ objdump --debugging /home/infinity0/build2/rustc-1.17.0+dfsg2/build/powerpc64le-unknown-linux-gnu/stage0/bin/../lib/../lib/librustc_llvm-1b4bf1d78c7d2bcc.so  | wc -l
80819

< eddyb> infinity0: you have to build LLVM in a special way to get DWARF for it < eddyb> and if you don't do it right you can easily run out of memory < eddyb> I'm not even sure we support that mode < eddyb> ah https://github.com/rust-lang/rust/blob/master/src/bootstrap/config.toml.example#L21 < eddyb> see https://github.com/rust-lang/rust/blob/master/src/bootstrap/config.toml.example#L56-L59 < eddyb> might have to be set to 1 /cc @eddyb

I don't think we in Debian are doing anything particularly special, FWIW: https://sources.debian.net/src/llvm-toolchain-3.9/1:3.9.1-9/debian/rules/#L250 (@sylvestre is the maintainer).

  1. I can see Debian turning on debuginfo and using gold to improve link performance.

    I remember something about split debuginfo being very useful in such builds. Maybe that's the case for all distro builds if the distro has separate debuginfo packages?

    Eduard-Mihai Burtescu at 2017-06-07 10:48:01

  2. Yes, Debian does split debuginfo. However we don't usually need buildsystem-level support for that, we just use dh_strip, which wraps around strip(1), after the build (e.g. here). I'm not sure what would be suitable for rust upstream.

    Ximin Luo at 2017-06-07 11:18:44

  3. @infinity0 Ah, there's a LLVM cmake option (or was, maybe it's changed since) to support that as part of the build, which, along with using gold, drastically improved building with debuginfo for me.

    Eduard-Mihai Burtescu at 2017-06-07 11:33:43

  4. https://github.com/rust-lang/rust/issues/67109 looks related.

    jyn at 2023-05-20 22:29:04