Skip to content

Commit 29dc083

Browse files
committed
llvm: dwo only emitted when object code emitted
`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>
1 parent 9bcc083 commit 29dc083

File tree

3 files changed

+68
-5
lines changed

3 files changed

+68
-5
lines changed

compiler/rustc_codegen_llvm/src/back/write.rs

+13-3
Original file line numberDiff line numberDiff line change
@@ -765,11 +765,21 @@ pub(crate) unsafe fn codegen(
765765
drop(handlers);
766766
}
767767

768+
// `.dwo` files are only emitted if:
769+
//
770+
// - Object files are being emitted (i.e. bitcode only or metadata only compilations will not
771+
// produce dwarf objects, even if otherwise enabled)
772+
// - Target supports Split DWARF
773+
// - Split debuginfo is enabled
774+
// - Split DWARF kind is `split` (i.e. debuginfo is split into `.dwo` files, not different
775+
// sections in the `.o` files).
776+
let dwarf_object_emitted = matches!(config.emit_obj, EmitObj::ObjectCode(_))
777+
&& cgcx.target_can_use_split_dwarf
778+
&& cgcx.split_debuginfo != SplitDebuginfo::Off
779+
&& cgcx.split_dwarf_kind == SplitDwarfKind::Split;
768780
Ok(module.into_compiled_module(
769781
config.emit_obj != EmitObj::None,
770-
cgcx.target_can_use_split_dwarf
771-
&& cgcx.split_debuginfo != SplitDebuginfo::Off
772-
&& cgcx.split_dwarf_kind == SplitDwarfKind::Split,
782+
dwarf_object_emitted,
773783
config.emit_bc,
774784
&cgcx.output_filenames,
775785
))

src/test/run-make-fulldeps/split-debuginfo/Makefile

+54-2
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ off:
5353
[ ! -f $(TMPDIR)/*.dwp ]
5454
[ ! -f $(TMPDIR)/*.dwo ]
5555

56-
packed: packed-split packed-single packed-remapped packed-crosscrate
56+
packed: packed-split packed-single packed-lto packed-remapped packed-crosscrate
5757

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

80+
packed-lto: packed-lto-split packed-lto-single
81+
82+
# - rmeta file added to rlib, no object files are generated and thus no debuginfo is generated
83+
# - `.o` never created
84+
# - `.dwo` never created
85+
# - `.dwp` never created
86+
packed-lto-split:
87+
$(RUSTC) baz.rs -g $(UNSTABLEOPTS) -Csplit-debuginfo=packed -Zsplit-dwarf-kind=split \
88+
--crate-type=rlib -Clinker-plugin-lto
89+
ls $(TMPDIR)/*.o && exit 1 || exit 0
90+
ls $(TMPDIR)/*.dwo && exit 1 || exit 0
91+
ls $(TMPDIR)/*.dwp && exit 1 || exit 0
92+
rm $(TMPDIR)/libbaz.rlib
93+
94+
# - rmeta file added to rlib, no object files are generated and thus no debuginfo is generated
95+
# - `.o` never created
96+
# - `.dwo` never created
97+
# - `.dwp` never created
98+
packed-lto-single:
99+
$(RUSTC) baz.rs -g $(UNSTABLEOPTS) -Csplit-debuginfo=packed -Zsplit-dwarf-kind=single \
100+
--crate-type=rlib -Clinker-plugin-lto
101+
ls $(TMPDIR)/*.o && exit 1 || exit 0
102+
ls $(TMPDIR)/*.dwo && exit 1 || exit 0
103+
ls $(TMPDIR)/*.dwp && exit 1 || exit 0
104+
rm $(TMPDIR)/libbaz.rlib
105+
80106
packed-remapped: packed-remapped-split packed-remapped-single
81107

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

156-
unpacked: unpacked-split unpacked-single unpacked-remapped unpacked-crosscrate
182+
unpacked: unpacked-split unpacked-single unpacked-lto unpacked-remapped unpacked-crosscrate
157183

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

206+
unpacked-lto: packed-lto-split packed-lto-single
207+
208+
# - rmeta file added to rlib, no object files are generated and thus no debuginfo is generated
209+
# - `.o` never created
210+
# - `.dwo` never created
211+
# - `.dwp` never created
212+
unpacked-lto-split:
213+
$(RUSTC) baz.rs -g $(UNSTABLEOPTS) -Csplit-debuginfo=unpacked -Zsplit-dwarf-kind=split \
214+
--crate-type=rlib -Clinker-plugin-lto
215+
ls $(TMPDIR)/*.o && exit 1 || exit 0
216+
ls $(TMPDIR)/*.dwo && exit 1 || exit 0
217+
ls $(TMPDIR)/*.dwp && exit 1 || exit 0
218+
rm $(TMPDIR)/libbaz.rlib
219+
220+
# - rmeta file added to rlib, no object files are generated and thus no debuginfo is generated
221+
# - `.o` never created
222+
# - `.dwo` never created
223+
# - `.dwp` never created
224+
unpacked-lto-single:
225+
$(RUSTC) baz.rs -g $(UNSTABLEOPTS) -Csplit-debuginfo=unpacked -Zsplit-dwarf-kind=single \
226+
--crate-type=rlib -Clinker-plugin-lto
227+
ls $(TMPDIR)/*.o && exit 1 || exit 0
228+
ls $(TMPDIR)/*.dwo && exit 1 || exit 0
229+
ls $(TMPDIR)/*.dwp && exit 1 || exit 0
230+
rm $(TMPDIR)/libbaz.rlib
231+
180232
unpacked-remapped: unpacked-remapped-split unpacked-remapped-single
181233

182234
# - Debuginfo in `.dwo` files
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
// empty

0 commit comments

Comments
 (0)