Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rollup of 11 pull requests #129391

Closed
wants to merge 30 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
07481b9
use old ctx if has same expand environment during decode span
bvanjoi Jul 4, 2024
0b87af9
Add `-Z embed-source=yes` to embed source code in DWARF debug info
Mrmaxmeier Apr 27, 2024
608901b
Add run-make test for -Zembed-source=yes
Mrmaxmeier Jul 16, 2024
e518451
Enable `f16` on x86 and x86-64
tgross35 Jul 29, 2024
0a5d5ff
Change `f16` doctests in core to run on x86-64
tgross35 Jul 29, 2024
8a61674
WASI fixing unsafe_op_in_unsafe_fn for std::{os, sys}
g0djan Aug 5, 2024
6899f5a
-Zembed-source: Don't try to warn about incompatible codegen backends
Mrmaxmeier Aug 6, 2024
10ef666
Add more test cases for untranslatable_diagnostic lint
GrigorenkoPV Aug 10, 2024
3cc2a6f
`untranslatable_diagnostic` lint: point at the untranslated thing
GrigorenkoPV Aug 10, 2024
e94a4ee
Refactor: `diagnostic_outside_of_impl`, `untranslatable_diagnostic`
GrigorenkoPV Aug 10, 2024
76fbf0a
Test wholearchive on rust staticlib
ChrisDenton Aug 18, 2024
9d7574f
rustdoc: animate the `:target` highlight
notriddle Aug 19, 2024
40af214
Make import libraries compatible with wholearchive
ChrisDenton Aug 19, 2024
c836739
Change `assert_unsafe_precondition` docs to refer to `check_language_ub`
ChaiTRex Aug 21, 2024
81c00dd
Add `const_cell_into_inner` to `OnceCell`
tgross35 Aug 21, 2024
7232a07
Explain the `run-make/debugger-visualizer-dep-info` Python script
Zalathar Aug 22, 2024
5fc562c
Rename `foo.py` to `my_gdb_script.py`
Zalathar Aug 22, 2024
34cdfc9
Advise against removing `run-make/libtest-junit/validate_junit.py`
Zalathar Aug 22, 2024
ca7c55f
Do not rely on names to find lifetimes.
cjgillot Aug 22, 2024
0dbfe1b
Rollup merge of #126985 - Mrmaxmeier:dwarf-embed-source, r=davidtwco
jieyouxu Aug 22, 2024
35d6344
Rollup merge of #127279 - bvanjoi:fix-112680, r=petrochenkov
jieyouxu Aug 22, 2024
c7afff3
Rollup merge of #128349 - tgross35:x86-f16, r=Noratrieb
jieyouxu Aug 22, 2024
765a045
Rollup merge of #128432 - g0djan:godjan/wasi_prohibit_implicit_unsafe…
jieyouxu Aug 22, 2024
126a5c2
Rollup merge of #128941 - GrigorenkoPV:internal-diagnostic-lints, r=d…
jieyouxu Aug 22, 2024
f24be46
Rollup merge of #129257 - ChrisDenton:rename-null-descriptor, r=jieyouxu
jieyouxu Aug 22, 2024
ccdaea7
Rollup merge of #129284 - notriddle:notriddle/animate-target=light, r…
jieyouxu Aug 22, 2024
738014a
Rollup merge of #129376 - ChaiTRex:assert_unsafe_precondition_check_l…
jieyouxu Aug 22, 2024
18d4e5b
Rollup merge of #129382 - tgross35:once-cell-const-into-inner, r=Nora…
jieyouxu Aug 22, 2024
a75f9b9
Rollup merge of #129387 - Zalathar:python-apologia, r=jieyouxu
jieyouxu Aug 22, 2024
24e7d69
Rollup merge of #129388 - cjgillot:region-def-id, r=compiler-errors
jieyouxu Aug 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add -Z embed-source=yes to embed source code in DWARF debug info
  • Loading branch information
Mrmaxmeier committed Jul 29, 2024
commit 0b87af9d4f7c6faa9e89496609f016dc3e3977e1
9 changes: 9 additions & 0 deletions compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,9 @@ pub fn file_metadata<'ll>(cx: &CodegenCx<'ll, '_>, source_file: &SourceFile) ->
};
let hash_value = hex_encode(source_file.src_hash.hash_bytes());

let source =
cx.sess().opts.unstable_opts.embed_source.then_some(()).and(source_file.src.as_ref());

unsafe {
llvm::LLVMRustDIBuilderCreateFile(
DIB(cx),
Expand All @@ -639,6 +642,8 @@ pub fn file_metadata<'ll>(cx: &CodegenCx<'ll, '_>, source_file: &SourceFile) ->
hash_kind,
hash_value.as_ptr().cast(),
hash_value.len(),
source.map_or(ptr::null(), |x| x.as_ptr().cast()),
source.map_or(0, |x| x.len()),
)
}
}
Expand All @@ -659,6 +664,8 @@ pub fn unknown_file_metadata<'ll>(cx: &CodegenCx<'ll, '_>) -> &'ll DIFile {
llvm::ChecksumKind::None,
hash_value.as_ptr().cast(),
hash_value.len(),
ptr::null(),
0,
)
})
}
Expand Down Expand Up @@ -943,6 +950,8 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
llvm::ChecksumKind::None,
ptr::null(),
0,
ptr::null(),
0,
);

let unit_metadata = llvm::LLVMRustDIBuilderCreateCompileUnit(
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1853,6 +1853,8 @@ extern "C" {
CSKind: ChecksumKind,
Checksum: *const c_char,
ChecksumLen: size_t,
Source: *const c_char,
SourceLen: size_t,
) -> &'a DIFile;

pub fn LLVMRustDIBuilderCreateSubroutineType<'a>(
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_interface/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -773,6 +773,7 @@ fn test_unstable_options_tracking_hash() {
tracked!(direct_access_external_data, Some(true));
tracked!(dual_proc_macros, true);
tracked!(dwarf_version, Some(5));
tracked!(embed_source, true);
tracked!(emit_thin_lto, false);
tracked!(export_executable_symbols, true);
tracked!(fewer_names, Some(true));
Expand Down
9 changes: 7 additions & 2 deletions compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -901,14 +901,19 @@ extern "C" LLVMMetadataRef
LLVMRustDIBuilderCreateFile(LLVMRustDIBuilderRef Builder, const char *Filename,
size_t FilenameLen, const char *Directory,
size_t DirectoryLen, LLVMRustChecksumKind CSKind,
const char *Checksum, size_t ChecksumLen) {
const char *Checksum, size_t ChecksumLen,
const char *Source, size_t SourceLen) {

std::optional<DIFile::ChecksumKind> llvmCSKind = fromRust(CSKind);
std::optional<DIFile::ChecksumInfo<StringRef>> CSInfo{};
if (llvmCSKind)
CSInfo.emplace(*llvmCSKind, StringRef{Checksum, ChecksumLen});
std::optional<StringRef> oSource{};
if (Source)
oSource = StringRef(Source, SourceLen);
return wrap(Builder->createFile(StringRef(Filename, FilenameLen),
StringRef(Directory, DirectoryLen), CSInfo));
StringRef(Directory, DirectoryLen), CSInfo,
oSource));
}

extern "C" LLVMMetadataRef
Expand Down
6 changes: 6 additions & 0 deletions compiler/rustc_session/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@ session_crate_name_empty = crate name must not be empty

session_crate_name_invalid = crate names cannot start with a `-`, but `{$s}` has a leading hyphen

session_embed_source_insufficient_dwarf_version = `-Zembed-source=y` requires at least `-Z dwarf-version=5` but DWARF version is {$dwarf_version}

session_embed_source_requires_debug_info = `-Zembed-source=y` requires debug information to be enabled

session_embed_source_requires_llvm_backend = `-Zembed-source=y` is only supported on the LLVM codegen backend

session_expr_parentheses_needed = parentheses are required to parse this as an expression

session_failed_to_create_profiler = failed to create profiler: {$err}
Expand Down
14 changes: 14 additions & 0 deletions compiler/rustc_session/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,20 @@ pub(crate) struct UnsupportedDwarfVersion {
pub(crate) dwarf_version: u32,
}

#[derive(Diagnostic)]
#[diag(session_embed_source_insufficient_dwarf_version)]
pub(crate) struct EmbedSourceInsufficientDwarfVersion {
pub(crate) dwarf_version: u32,
}

#[derive(Diagnostic)]
#[diag(session_embed_source_requires_debug_info)]
pub(crate) struct EmbedSourceRequiresDebugInfo;

#[derive(Diagnostic)]
#[diag(session_embed_source_requires_llvm_backend)]
pub(crate) struct EmbedSourceRequiresLLVMBackend;

#[derive(Diagnostic)]
#[diag(session_target_stack_protector_not_supported)]
pub(crate) struct StackProtectorNotSupportedForTarget<'a> {
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_session/src/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1708,6 +1708,8 @@ options! {
them only if an error has not been emitted"),
ehcont_guard: bool = (false, parse_bool, [TRACKED],
"generate Windows EHCont Guard tables"),
embed_source: bool = (false, parse_bool, [TRACKED],
"embed source text in DWARF debug sections (default: no)"),
emit_stack_sizes: bool = (false, parse_bool, [UNTRACKED],
"emit a section containing stack size metadata (default: no)"),
emit_thin_lto: bool = (true, parse_bool, [TRACKED],
Expand Down
25 changes: 23 additions & 2 deletions compiler/rustc_session/src/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ use rustc_target::spec::{
use crate::code_stats::CodeStats;
pub use crate::code_stats::{DataTypeKind, FieldInfo, FieldKind, SizeKind, VariantInfo};
use crate::config::{
self, CoverageLevel, CrateType, ErrorOutputType, FunctionReturn, Input, InstrumentCoverage,
OptLevel, OutFileName, OutputType, RemapPathScopeComponents, SwitchWithOptPath,
self, CoverageLevel, CrateType, DebugInfo, ErrorOutputType, FunctionReturn, Input,
InstrumentCoverage, OptLevel, OutFileName, OutputType, RemapPathScopeComponents,
SwitchWithOptPath,
};
use crate::parse::{add_feature_diagnostics, ParseSess};
use crate::search_paths::{PathKind, SearchPath};
Expand Down Expand Up @@ -1300,6 +1301,26 @@ fn validate_commandline_args_with_session_available(sess: &Session) {
.emit_err(errors::SplitDebugInfoUnstablePlatform { debuginfo: sess.split_debuginfo() });
}

if sess.opts.unstable_opts.embed_source {
let dwarf_version =
sess.opts.unstable_opts.dwarf_version.unwrap_or(sess.target.default_dwarf_version);

let uses_llvm_backend =
matches!(sess.opts.unstable_opts.codegen_backend.as_deref(), None | Some("llvm"));

if dwarf_version < 5 {
sess.dcx().emit_warn(errors::EmbedSourceInsufficientDwarfVersion { dwarf_version });
}

if sess.opts.debuginfo == DebugInfo::None {
sess.dcx().emit_warn(errors::EmbedSourceRequiresDebugInfo);
}

if !uses_llvm_backend {
sess.dcx().emit_warn(errors::EmbedSourceRequiresLLVMBackend);
}
}

if sess.opts.unstable_opts.instrument_xray.is_some() && !sess.target.options.supports_xray {
sess.dcx().emit_err(errors::InstrumentationNotSupported { us: "XRay".to_string() });
}
Expand Down
12 changes: 12 additions & 0 deletions src/doc/unstable-book/src/compiler-flags/embed-source.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# `embed-source`

This flag controls whether the compiler embeds the program source code text into
the object debug information section. It takes one of the following values:

* `y`, `yes`, `on` or `true`: put source code in debug info.
* `n`, `no`, `off`, `false` or no value: omit source code from debug info (the default).

This flag is ignored in configurations that don't emit DWARF debug information
and is ignored on non-LLVM backends. `-Z embed-source` requires DWARFv5. Use
`-Z dwarf-version=5` to control the compiler's DWARF target version and `-g` to
enable debug info generation.