Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
cf2d0ce
diagnostics: suggest changing `s@self::{macro}@::macro` for exported
notriddle Nov 13, 2022
98091c0
diagnostics: add `};` only if `{` was added too
notriddle Nov 13, 2022
dbc0ed2
Unify stable and unstable sort implementations in same core module
Voultapher Nov 20, 2022
1ec59cd
Remove debug unused
Voultapher Nov 21, 2022
4b5844f
Document all unsafe blocks
Voultapher Nov 21, 2022
04af19f
diagnostics: use `module_path` to check crate import instead of strings
notriddle Dec 6, 2022
f2070c3
diagnostics: remvoe unnecessary use of `source_map.start_point`
notriddle Dec 6, 2022
280f69d
Fix IndexVec::drain_enumerated
compiler-errors Jan 19, 2023
c9c8e29
HACK: self ty ambiguity hack
compiler-errors Jan 19, 2023
ac4956b
Support `.comment` section like GCC/Clang (`!llvm.ident`)
ojeda May 28, 2022
aee75f2
Assert goal is fully normalized during assemble
compiler-errors Jan 19, 2023
f53f5b4
swap Ambiguity and Unimplemented in new trait engine
compiler-errors Jan 19, 2023
69890b2
trait solver: PointerSized
compiler-errors Jan 18, 2023
ed6aebb
trait solver: Implement Fn traits and tuple trait
compiler-errors Jan 19, 2023
05889fc
rustdoc: remove redundant CSS selector `.sidebar .current`
notriddle Jan 19, 2023
734f375
Change `bindings_with_variant_name` to deny-by-default
timrobertsdev Nov 8, 2022
1cbce72
Add `compile_fail` to doctest for `bindings_with_variant_name`
timrobertsdev Nov 8, 2022
1adb4d6
Fix typo in opaque_types.rs
eltociear Jan 20, 2023
a641b92
remove leading comma when there are no args in check macro expansion
DebugSteven Jan 19, 2023
c3e30f1
Rollup merge of #97550 - ojeda:comment-section, r=bjorn3
compiler-errors Jan 20, 2023
bb5f43e
Rollup merge of #104154 - timrobertsdev:deny-by-default-bindings_with…
compiler-errors Jan 20, 2023
993932b
Rollup merge of #104347 - notriddle:notriddle/import-macro-from-self-…
compiler-errors Jan 20, 2023
4b7bec8
Rollup merge of #104672 - Voultapher:unify-sort-modules, r=thomcc
compiler-errors Jan 20, 2023
8a66e39
Rollup merge of #107061 - compiler-errors:new-solver-new-candidates-3…
compiler-errors Jan 20, 2023
7c5f572
Rollup merge of #107095 - notriddle:notriddle/sidebar-current, r=Guil…
compiler-errors Jan 20, 2023
644e0cc
Rollup merge of #107112 - eltociear:patch-19, r=albertlarsan68
compiler-errors Jan 20, 2023
222510e
Rollup merge of #107124 - DebugSteven:check-macro-expansion, r=albert…
compiler-errors Jan 20, 2023
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
Support .comment section like GCC/Clang (!llvm.ident)
Both GCC and Clang write by default a `.comment` section with compiler
information:

```txt
$ gcc -c -xc /dev/null && readelf -p '.comment' null.o

String dump of section '.comment':
  [     1]  GCC: (GNU) 11.2.0

$ clang -c -xc /dev/null && readelf -p '.comment' null.o

String dump of section '.comment':
  [     1]  clang version 14.0.1 (https://github.com/llvm/llvm-project.git c62053979489ccb002efe411c3af059addcb5d7d)
```

They also implement the `-Qn` flag to avoid doing so:

```txt
$ gcc -Qn -c -xc /dev/null && readelf -p '.comment' null.o
readelf: Warning: Section '.comment' was not dumped because it does not exist!

$ clang -Qn -c -xc /dev/null && readelf -p '.comment' null.o
readelf: Warning: Section '.comment' was not dumped because it does not exist!
```

So far, `rustc` only does it for WebAssembly targets and only
when debug info is enabled:

```txt
$ echo 'fn main(){}' | rustc --target=wasm32-unknown-unknown --emit=llvm-ir -Cdebuginfo=2 - && grep llvm.ident rust_out.ll
!llvm.ident = !{!27}
```

In the RFC part of this PR it was decided to always add
the information, which gets us closer to other popular compilers.
An opt-out flag like GCC and Clang may be added later on if deemed
necessary.

Implementation-wise, this covers both `ModuleLlvm::new()` and
`ModuleLlvm::new_metadata()` cases by moving the addition to
`context::create_module` and adds a few test cases.

ThinLTO also sees the `llvm.ident` named metadata duplicated (in
temporary outputs), so this deduplicates it like it is done for
`wasm.custom_sections`. The tests also check this duplication does
not take place.

Signed-off-by: Miguel Ojeda <ojeda@kernel.org>
  • Loading branch information
ojeda committed Jan 19, 2023
commit ac4956b9c09932f48700686822023646ad8a5ba2
18 changes: 18 additions & 0 deletions compiler/rustc_codegen_llvm/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use rustc_target::abi::{
use rustc_target::spec::{HasTargetSpec, RelocModel, Target, TlsModel};
use smallvec::SmallVec;

use libc::c_uint;
use std::cell::{Cell, RefCell};
use std::ffi::CStr;
use std::str;
Expand Down Expand Up @@ -347,6 +348,23 @@ pub unsafe fn create_module<'ll>(
);
}

// Insert `llvm.ident` metadata.
//
// On the wasm targets it will get hooked up to the "producer" sections
// `processed-by` information.
let rustc_producer =
format!("rustc version {}", option_env!("CFG_VERSION").expect("CFG_VERSION"));
let name_metadata = llvm::LLVMMDStringInContext(
llcx,
rustc_producer.as_ptr().cast(),
rustc_producer.as_bytes().len() as c_uint,
);
llvm::LLVMAddNamedMetadataOperand(
llmod,
cstr!("llvm.ident").as_ptr(),
llvm::LLVMMDNodeInContext(llcx, &name_metadata, 1),
);

llmod
}

Expand Down
15 changes: 0 additions & 15 deletions compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -907,21 +907,6 @@ pub fn build_compile_unit_di_node<'ll, 'tcx>(
);
}

// Insert `llvm.ident` metadata on the wasm targets since that will
// get hooked up to the "producer" sections `processed-by` information.
if tcx.sess.target.is_like_wasm {
let name_metadata = llvm::LLVMMDStringInContext(
debug_context.llcontext,
rustc_producer.as_ptr().cast(),
rustc_producer.as_bytes().len() as c_uint,
);
llvm::LLVMAddNamedMetadataOperand(
debug_context.llmod,
cstr!("llvm.ident").as_ptr(),
llvm::LLVMMDNodeInContext(debug_context.llcontext, &name_metadata, 1),
);
}

return unit_metadata;
};

Expand Down
5 changes: 5 additions & 0 deletions compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1360,6 +1360,11 @@ LLVMRustPrepareThinLTOImport(const LLVMRustThinLTOData *Data, LLVMModuleRef M,
if (WasmCustomSections)
WasmCustomSections->eraseFromParent();

// `llvm.ident` named metadata also gets duplicated.
auto *llvmIdent = (*MOrErr)->getNamedMetadata("llvm.ident");
if (llvmIdent)
llvmIdent->eraseFromParent();

return MOrErr;
};
bool ClearDSOLocal = clearDSOLocalOnDeclarations(Mod, Target);
Expand Down
15 changes: 15 additions & 0 deletions tests/codegen/llvm-ident.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// Verifies that the `!llvm.ident` named metadata is emitted.
//
// revisions: NONE OPT DEBUG
//
// [OPT] compile-flags: -Copt-level=2
// [DEBUG] compile-flags: -Cdebuginfo=2

// The named metadata should contain a single metadata node (see
// `LLVMRustPrepareThinLTOImport` for details).
// CHECK: !llvm.ident = !{![[ID:[0-9]+]]}

// In addition, check that the metadata node has the expected content.
// CHECK: ![[ID]] = !{!"rustc version 1.{{.*}}"}

fn main() {}
15 changes: 15 additions & 0 deletions tests/run-make/comment-section/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
include ../../run-make-fulldeps/tools.mk

# only-linux

all:
echo 'fn main(){}' | $(RUSTC) - --emit=link,obj -Csave-temps

# Check linked output has a `.comment` section with the expected content.
readelf -p '.comment' $(TMPDIR)/rust_out | $(CGREP) -F 'rustc version 1.'

# Check all object files (including temporary outputs) have a `.comment`
# section with the expected content.
set -e; for f in $(TMPDIR)/*.o; do \
readelf -p '.comment' $$f | $(CGREP) -F 'rustc version 1.'; \
done
19 changes: 19 additions & 0 deletions tests/run-make/llvm-ident/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
include ../../run-make-fulldeps/tools.mk

# only-linux

all:
# `-Ccodegen-units=16 -Copt-level=2` is used here to trigger thin LTO
# across codegen units to test deduplication of the named metadata
# (see `LLVMRustPrepareThinLTOImport` for details).
echo 'fn main(){}' | $(RUSTC) - --emit=link,obj -Csave-temps -Ccodegen-units=16 -Copt-level=2

# `llvm-dis` is used here since `--emit=llvm-ir` does not emit LLVM IR
# for temporary outputs.
"$(LLVM_BIN_DIR)"/llvm-dis $(TMPDIR)/*.bc

# Check LLVM IR files (including temporary outputs) have `!llvm.ident`
# named metadata, reusing the related codegen test.
set -e; for f in $(TMPDIR)/*.ll; do \
$(LLVM_FILECHECK) --input-file $$f ../../codegen/llvm-ident.rs; \
done