Skip to content

Make LLVM emit assembly comments with -Z asm-comments #53290

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

Merged
merged 1 commit into from
Aug 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 3 additions & 0 deletions src/librustc_codegen_llvm/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,8 @@ pub fn target_machine_factory(sess: &Session, find_features: bool)
let is_pie_binary = !find_features && is_pie_binary(sess);
let trap_unreachable = sess.target.target.options.trap_unreachable;

let asm_comments = sess.asm_comments();

Arc::new(move || {
let tm = unsafe {
llvm::LLVMRustCreateTargetMachine(
Expand All @@ -195,6 +197,7 @@ pub fn target_machine_factory(sess: &Session, find_features: bool)
fdata_sections,
trap_unreachable,
singlethread,
asm_comments,
)
};

Expand Down
3 changes: 2 additions & 1 deletion src/librustc_codegen_llvm/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1455,7 +1455,8 @@ extern "C" {
FunctionSections: bool,
DataSections: bool,
TrapUnreachable: bool,
Singlethread: bool)
Singlethread: bool,
AsmComments: bool)
-> Option<&'static mut TargetMachine>;
pub fn LLVMRustDisposeTargetMachine(T: &'static mut TargetMachine);
pub fn LLVMRustAddAnalysisPasses(T: &'a TargetMachine, PM: &PassManager<'a>, M: &'a Module);
Expand Down
5 changes: 4 additions & 1 deletion src/rustllvm/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,8 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
bool PositionIndependentExecutable, bool FunctionSections,
bool DataSections,
bool TrapUnreachable,
bool Singlethread) {
bool Singlethread,
bool AsmComments) {

auto OptLevel = fromRust(RustOptLevel);
auto RM = fromRust(RustReloc);
Expand All @@ -393,6 +394,8 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
}
Options.DataSections = DataSections;
Options.FunctionSections = FunctionSections;
Options.MCOptions.AsmVerbose = AsmComments;
Options.MCOptions.PreserveAsmComments = AsmComments;

if (TrapUnreachable) {
// Tell LLVM to codegen `unreachable` into an explicit trap instruction.
Expand Down