Skip to content

Commit

Permalink
llvm: dwo only emitted when object code emitted
Browse files Browse the repository at this point in the history
`CompiledModule` should not think a DWARF object was emitted when a
bitcode-only compilation has happened, this can confuse archive file
creation (which expects to create an archive containing non-existent dwo
files).

Signed-off-by: David Wood <david.wood@huawei.com>
  • Loading branch information
davidtwco committed Nov 8, 2022
1 parent 9bcc083 commit 29dc083
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 5 deletions.
16 changes: 13 additions & 3 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -765,11 +765,21 @@ pub(crate) unsafe fn codegen(
drop(handlers);
}

// `.dwo` files are only emitted if:
//
// - Object files are being emitted (i.e. bitcode only or metadata only compilations will not
// produce dwarf objects, even if otherwise enabled)
// - Target supports Split DWARF
// - Split debuginfo is enabled
// - Split DWARF kind is `split` (i.e. debuginfo is split into `.dwo` files, not different
// sections in the `.o` files).
let dwarf_object_emitted = matches!(config.emit_obj, EmitObj::ObjectCode(_))
&& cgcx.target_can_use_split_dwarf
&& cgcx.split_debuginfo != SplitDebuginfo::Off
&& cgcx.split_dwarf_kind == SplitDwarfKind::Split;
Ok(module.into_compiled_module(
config.emit_obj != EmitObj::None,
cgcx.target_can_use_split_dwarf
&& cgcx.split_debuginfo != SplitDebuginfo::Off
&& cgcx.split_dwarf_kind == SplitDwarfKind::Split,
dwarf_object_emitted,
config.emit_bc,
&cgcx.output_filenames,
))
Expand Down
56 changes: 54 additions & 2 deletions src/test/run-make-fulldeps/split-debuginfo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ off:
[ ! -f $(TMPDIR)/*.dwp ]
[ ! -f $(TMPDIR)/*.dwo ]

packed: packed-split packed-single packed-remapped packed-crosscrate
packed: packed-split packed-single packed-lto packed-remapped packed-crosscrate

# - Debuginfo in `.dwo` files
# - `.o` deleted
Expand All @@ -77,6 +77,32 @@ packed-single:
rm $(TMPDIR)/foo.dwp
rm $(TMPDIR)/$(call BIN,foo)

packed-lto: packed-lto-split packed-lto-single

# - rmeta file added to rlib, no object files are generated and thus no debuginfo is generated
# - `.o` never created
# - `.dwo` never created
# - `.dwp` never created
packed-lto-split:
$(RUSTC) baz.rs -g $(UNSTABLEOPTS) -Csplit-debuginfo=packed -Zsplit-dwarf-kind=split \
--crate-type=rlib -Clinker-plugin-lto
ls $(TMPDIR)/*.o && exit 1 || exit 0
ls $(TMPDIR)/*.dwo && exit 1 || exit 0
ls $(TMPDIR)/*.dwp && exit 1 || exit 0
rm $(TMPDIR)/libbaz.rlib

# - rmeta file added to rlib, no object files are generated and thus no debuginfo is generated
# - `.o` never created
# - `.dwo` never created
# - `.dwp` never created
packed-lto-single:
$(RUSTC) baz.rs -g $(UNSTABLEOPTS) -Csplit-debuginfo=packed -Zsplit-dwarf-kind=single \
--crate-type=rlib -Clinker-plugin-lto
ls $(TMPDIR)/*.o && exit 1 || exit 0
ls $(TMPDIR)/*.dwo && exit 1 || exit 0
ls $(TMPDIR)/*.dwp && exit 1 || exit 0
rm $(TMPDIR)/libbaz.rlib

packed-remapped: packed-remapped-split packed-remapped-single

# - Debuginfo in `.dwo` files
Expand Down Expand Up @@ -153,7 +179,7 @@ packed-crosscrate-single:
rm $(TMPDIR)/main.dwp
rm $(TMPDIR)/$(call BIN,main)

unpacked: unpacked-split unpacked-single unpacked-remapped unpacked-crosscrate
unpacked: unpacked-split unpacked-single unpacked-lto unpacked-remapped unpacked-crosscrate

# - Debuginfo in `.dwo` files
# - `.o` deleted
Expand All @@ -177,6 +203,32 @@ unpacked-single:
ls $(TMPDIR)/*.dwp && exit 1 || exit 0
rm $(TMPDIR)/$(call BIN,foo)

unpacked-lto: packed-lto-split packed-lto-single

# - rmeta file added to rlib, no object files are generated and thus no debuginfo is generated
# - `.o` never created
# - `.dwo` never created
# - `.dwp` never created
unpacked-lto-split:
$(RUSTC) baz.rs -g $(UNSTABLEOPTS) -Csplit-debuginfo=unpacked -Zsplit-dwarf-kind=split \
--crate-type=rlib -Clinker-plugin-lto
ls $(TMPDIR)/*.o && exit 1 || exit 0
ls $(TMPDIR)/*.dwo && exit 1 || exit 0
ls $(TMPDIR)/*.dwp && exit 1 || exit 0
rm $(TMPDIR)/libbaz.rlib

# - rmeta file added to rlib, no object files are generated and thus no debuginfo is generated
# - `.o` never created
# - `.dwo` never created
# - `.dwp` never created
unpacked-lto-single:
$(RUSTC) baz.rs -g $(UNSTABLEOPTS) -Csplit-debuginfo=unpacked -Zsplit-dwarf-kind=single \
--crate-type=rlib -Clinker-plugin-lto
ls $(TMPDIR)/*.o && exit 1 || exit 0
ls $(TMPDIR)/*.dwo && exit 1 || exit 0
ls $(TMPDIR)/*.dwp && exit 1 || exit 0
rm $(TMPDIR)/libbaz.rlib

unpacked-remapped: unpacked-remapped-split unpacked-remapped-single

# - Debuginfo in `.dwo` files
Expand Down
1 change: 1 addition & 0 deletions src/test/run-make-fulldeps/split-debuginfo/baz.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// empty

0 comments on commit 29dc083

Please sign in to comment.