Skip to content

Commit

Permalink
Rollup merge of rust-lang#104105 - davidtwco:split-dwarf-lto, r=micha…
Browse files Browse the repository at this point in the history
…elwoerister

llvm: dwo only emitted when object code emitted

Fixes rust-lang#103932.

`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).

r? `````@michaelwoerister`````
  • Loading branch information
Manishearth authored Nov 12, 2022
2 parents e744685 + 29dc083 commit 422299b
Show file tree
Hide file tree
Showing 3 changed files with 210 additions and 17 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
210 changes: 196 additions & 14 deletions src/test/run-make-fulldeps/split-debuginfo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ include ../tools.mk
all: off packed unpacked

ifeq ($(UNAME),Darwin)
# If disabled, don't run dsymutil
# If disabled, don't run `dsymutil`.
off:
rm -rf $(TMPDIR)/*.dSYM
$(RUSTC) foo.rs -g -C split-debuginfo=off
Expand All @@ -29,98 +29,280 @@ unpacked:
[ ! -d $(TMPDIR)/foo.dSYM ]
else
ifdef IS_WINDOWS
# Windows only supports =packed
# Windows only supports packed debuginfo - nothing to test.
off:
packed:
unpacked:
else
# Some non-Windows, non-Darwin platforms are not stable, and some are.
ifeq ($(UNAME),Linux)
UNSTABLEOPTS :=
else
UNSTABLEOPTS := -Zunstable-options
endif

# - Debuginfo in `.o` files
# - `.o` deleted
# - `.dwo` never created
# - `.dwp` never created
off:
$(RUSTC) foo.rs -g -C $(UNSTABLEOPTS) split-debuginfo=off
[ ! -f $(TMPDIR)/*.dwp ]
[ ! -f $(TMPDIR)/*.dwo ]

$(RUSTC) foo.rs -g
[ ! -f $(TMPDIR)/*.dwp ]
[ ! -f $(TMPDIR)/*.dwo ]

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

# - Debuginfo in `.dwo` files
# - `.o` deleted
# - `.dwo` deleted
# - `.dwp` present
packed-split:
$(RUSTC) foo.rs -g $(UNSTABLEOPTS) -C split-debuginfo=packed -Zsplit-dwarf-kind=split
ls $(TMPDIR)/*.dwp
rm -rf $(TMPDIR)/*.dwp $(TMPDIR)/*.dwo
ls $(TMPDIR)/*.o && exit 1 || exit 0
ls $(TMPDIR)/*.dwo && exit 1 || exit 0
rm $(TMPDIR)/foo.dwp
rm $(TMPDIR)/$(call BIN,foo)

# - Debuginfo in `.o` files
# - `.o` deleted
# - `.dwo` never created
# - `.dwp` present
packed-single:
$(RUSTC) foo.rs -g $(UNSTABLEOPTS) -C split-debuginfo=packed -Zsplit-dwarf-kind=single
ls $(TMPDIR)/*.dwp
ls $(TMPDIR)/*.o && exit 1 || exit 0
ls $(TMPDIR)/*.dwo && exit 1 || exit 0
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
rm -rf $(TMPDIR)/*.dwp
ls $(TMPDIR)/*.dwp && exit 1 || exit 0
rm $(TMPDIR)/libbaz.rlib

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

# - Debuginfo in `.dwo` files
# - `.o` and binary refer to remapped `.dwo` paths which do not exist
# - `.o` deleted
# - `.dwo` deleted
# - `.dwp` present
packed-remapped-split:
$(RUSTC) $(UNSTABLEOPTS) -C split-debuginfo=packed -C debuginfo=2 \
-Z split-dwarf-kind=split --remap-path-prefix $(TMPDIR)=/a foo.rs -g
objdump -Wi $(TMPDIR)/foo | grep DW_AT_GNU_dwo_name | (! grep $(TMPDIR)) || exit 1
ls $(TMPDIR)/*.o && exit 1 || exit 0
ls $(TMPDIR)/*.dwo && exit 1 || exit 0
rm $(TMPDIR)/foo.dwp
rm $(TMPDIR)/$(call BIN,foo)

# - Debuginfo in `.o` files
# - `.o` and binary refer to remapped `.o` paths which do not exist
# - `.o` deleted
# - `.dwo` never created
# - `.dwp` present
packed-remapped-single:
$(RUSTC) $(UNSTABLEOPTS) -C split-debuginfo=packed -C debuginfo=2 \
-Z split-dwarf-kind=single --remap-path-prefix $(TMPDIR)=/a foo.rs -g
objdump -Wi $(TMPDIR)/foo | grep DW_AT_GNU_dwo_name | (! grep $(TMPDIR)) || exit 1
ls $(TMPDIR)/*.o && exit 1 || exit 0
ls $(TMPDIR)/*.dwo && exit 1 || exit 0
rm $(TMPDIR)/foo.dwp
rm $(TMPDIR)/$(call BIN,foo)

packed-crosscrate: packed-crosscrate-split packed-crosscrate-single

# - Debuginfo in `.dwo` files
# - (bar) `.rlib` file created, contains `.dwo`
# - (bar) `.o` deleted
# - (bar) `.dwo` deleted
# - (bar) `.dwp` never created
# - (main) `.o` deleted
# - (main) `.dwo` deleted
# - (main) `.dwp` present
packed-crosscrate-split:
$(RUSTC) --crate-type lib $(UNSTABLEOPTS) -C split-debuginfo=packed \
-Zsplit-dwarf-kind=split -C debuginfo=2 -g bar.rs
ls $(TMPDIR)/*.rlib
ls $(TMPDIR)/*.o && exit 1 || exit 0
ls $(TMPDIR)/*.dwo && exit 1 || exit 0
ls $(TMPDIR)/*.dwp && exit 1 || exit 0
$(RUSTC) --extern bar=$(TMPDIR)/libbar.rlib -Z unstable-options $(UNSTABLEOPTS) \
$(RUSTC) --extern bar=$(TMPDIR)/libbar.rlib $(UNSTABLEOPTS) \
-C split-debuginfo=packed -Zsplit-dwarf-kind=split -C debuginfo=2 -g main.rs
rm $(TMPDIR)/*.dwo
ls $(TMPDIR)/*.o && exit 1 || exit 0
ls $(TMPDIR)/*.dwo && exit 1 || exit 0
rm $(TMPDIR)/main.dwp
rm $(TMPDIR)/$(call BIN,main)

# - Debuginfo in `.o` files
# - (bar) `.rlib` file created, contains `.o`
# - (bar) `.o` deleted
# - (bar) `.dwo` never created
# - (bar) `.dwp` never created
# - (main) `.o` deleted
# - (main) `.dwo` never created
# - (main) `.dwp` present
packed-crosscrate-single:
$(RUSTC) --crate-type lib $(UNSTABLEOPTS) -C split-debuginfo=packed \
-Zsplit-dwarf-kind=single -C debuginfo=2 -g bar.rs
ls $(TMPDIR)/*.rlib
ls $(TMPDIR)/*.o && exit 1 || exit 0
ls $(TMPDIR)/*.dwo && exit 1 || exit 0
ls $(TMPDIR)/*.dwp && exit 1 || exit 0
$(RUSTC) --extern bar=$(TMPDIR)/libbar.rlib -Z unstable-options $(UNSTABLEOPTS) \
$(RUSTC) --extern bar=$(TMPDIR)/libbar.rlib $(UNSTABLEOPTS) \
-C split-debuginfo=packed -Zsplit-dwarf-kind=single -C debuginfo=2 -g main.rs
ls $(TMPDIR)/*.o && exit 1 || exit 0
ls $(TMPDIR)/*.dwo && exit 1 || exit 0
rm $(TMPDIR)/main.dwp
rm $(TMPDIR)/$(call BIN,main)

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

# - Debuginfo in `.dwo` files
# - `.o` deleted
# - `.dwo` present
# - `.dwp` never created
unpacked-split:
$(RUSTC) foo.rs -g $(UNSTABLEOPTS) -C split-debuginfo=unpacked -Zsplit-dwarf-kind=split
ls $(TMPDIR)/*.o && exit 1 || exit 0
rm $(TMPDIR)/*.dwo
ls $(TMPDIR)/*.dwp && exit 1 || exit 0
ls $(TMPDIR)/*.dwo
rm -rf $(TMPDIR)/*.dwp $(TMPDIR)/*.dwo
rm $(TMPDIR)/$(call BIN,foo)

# - Debuginfo in `.o` files
# - `.o` present
# - `.dwo` never created
# - `.dwp` never created
unpacked-single:
$(RUSTC) foo.rs -g $(UNSTABLEOPTS) -C split-debuginfo=unpacked -Zsplit-dwarf-kind=single
ls $(TMPDIR)/*.o
ls $(TMPDIR)/*.dwo && exit 1 || exit 0
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
# - `.o` and binary refer to remapped `.dwo` paths which do not exist
# - `.o` deleted
# - `.dwo` present
# - `.dwp` never created
unpacked-remapped-split:
$(RUSTC) $(UNSTABLEOPTS) -C split-debuginfo=unpacked -C debuginfo=2 \
-Z split-dwarf-kind=split --remap-path-prefix $(TMPDIR)=/a foo.rs -g
objdump -Wi $(TMPDIR)/foo | grep DW_AT_GNU_dwo_name | (! grep $(TMPDIR)) || exit 1
ls $(TMPDIR)/*.o && exit 1 || exit 0
rm $(TMPDIR)/*.dwo
ls $(TMPDIR)/*.dwp && exit 1 || exit 0
rm $(TMPDIR)/$(call BIN,foo)

# - Debuginfo in `.o` files
# - `.o` and binary refer to remapped `.o` paths which do not exist
# - `.o` present
# - `.dwo` never created
# - `.dwp` never created
unpacked-remapped-single:
$(RUSTC) $(UNSTABLEOPTS) -C split-debuginfo=unpacked -C debuginfo=2 \
-Z split-dwarf-kind=single --remap-path-prefix $(TMPDIR)=/a foo.rs -g
objdump -Wi $(TMPDIR)/foo | grep DW_AT_GNU_dwo_name | (! grep $(TMPDIR)) || exit 1
ls $(TMPDIR)/*.o
ls $(TMPDIR)/*.dwo && exit 1 || exit 0
ls $(TMPDIR)/*.dwp && exit 1 || exit 0
rm $(TMPDIR)/$(call BIN,foo)

unpacked-crosscrate: packed-crosscrate-split packed-crosscrate-single

# - Debuginfo in `.dwo` files
# - (bar) `.rlib` file created, contains `.dwo`
# - (bar) `.o` deleted
# - (bar) `.dwo` present
# - (bar) `.dwp` never created
# - (main) `.o` deleted
# - (main) `.dwo` present
# - (main) `.dwp` never created
unpacked-crosscrate-split:
$(RUSTC) --crate-type lib $(UNSTABLEOPTS) -C split-debuginfo=unpacked \
-Zsplit-dwarf-kind=split -C debuginfo=2 -g bar.rs
ls $(TMPDIR)/*.rlib
ls $(TMPDIR)/*.o && exit 1 || exit 0
ls $(TMPDIR)/*.dwo
ls $(TMPDIR)/*.dwp && exit 1 || exit 0
$(RUSTC) --extern bar=$(TMPDIR)/libbar.rlib $(UNSTABLEOPTS) \
-C split-debuginfo=unpacked -Zsplit-dwarf-kind=split -C debuginfo=2 -g main.rs
ls $(TMPDIR)/*.o && exit 1 || exit 0
rm $(TMPDIR)/*.dwo
ls $(TMPDIR)/*.dwp && exit 1 || exit 0
rm $(TMPDIR)/$(call BIN,main)

# - Debuginfo in `.o` files
# - (bar) `.rlib` file created, contains `.o`
# - (bar) `.o` present
# - (bar) `.dwo` never created
# - (bar) `.dwp` never created
# - (main) `.o` present
# - (main) `.dwo` never created
# - (main) `.dwp` never created
unpacked-crosscrate-single:
$(RUSTC) --crate-type lib $(UNSTABLEOPTS) -C split-debuginfo=unpacked \
-Zsplit-dwarf-kind=single -C debuginfo=2 -g bar.rs
ls $(TMPDIR)/*.rlib
ls $(TMPDIR)/*.o
ls $(TMPDIR)/*.dwo && exit 1 || exit 0
ls $(TMPDIR)/*.dwp && exit 1 || exit 0
$(RUSTC) --extern bar=$(TMPDIR)/libbar.rlib $(UNSTABLEOPTS) \
-C split-debuginfo=unpacked -Zsplit-dwarf-kind=single -C debuginfo=2 -g main.rs
ls $(TMPDIR)/*.o
ls $(TMPDIR)/*.dwo && exit 1 || exit 0
ls $(TMPDIR)/*.dwp && exit 1 || exit 0
rm $(TMPDIR)/$(call BIN,main)
endif
endif
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 422299b

Please sign in to comment.