Skip to content
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
4 changes: 2 additions & 2 deletions compiler/rustc_codegen_llvm/src/back/owned_target_machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl OwnedTargetMachine {
use_init_array: bool,
split_dwarf_file: &CStr,
output_obj_file: &CStr,
debug_info_compression: &CStr,
debug_info_compression: llvm::CompressionKind,
use_emulated_tls: bool,
use_wasm_eh: bool,
) -> Result<Self, LlvmError<'static>> {
Expand All @@ -62,7 +62,7 @@ impl OwnedTargetMachine {
use_init_array,
split_dwarf_file.as_ptr(),
output_obj_file.as_ptr(),
debug_info_compression.as_ptr(),
debug_info_compression,
use_emulated_tls,
use_wasm_eh,
)
Expand Down
25 changes: 13 additions & 12 deletions compiler/rustc_codegen_llvm/src/back/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ use std::sync::Arc;
use std::{fs, slice, str};

use libc::{c_char, c_int, c_void, size_t};
use llvm::{
LLVMRustLLVMHasZlibCompressionForDebugSymbols, LLVMRustLLVMHasZstdCompressionForDebugSymbols,
};
use rustc_codegen_ssa::back::link::ensure_removed;
use rustc_codegen_ssa::back::versioned_llvm_target;
use rustc_codegen_ssa::back::write::{
Expand Down Expand Up @@ -252,21 +249,25 @@ pub(crate) fn target_machine_factory(

let use_emulated_tls = matches!(sess.tls_model(), TlsModel::Emulated);

let debuginfo_compression = sess.opts.debuginfo_compression.to_string();
match sess.opts.debuginfo_compression {
rustc_session::config::DebugInfoCompression::Zlib => {
if !unsafe { LLVMRustLLVMHasZlibCompressionForDebugSymbols() } {
let debuginfo_compression = match sess.opts.debuginfo_compression {
config::DebugInfoCompression::None => llvm::CompressionKind::None,
config::DebugInfoCompression::Zlib => {
if llvm::LLVMRustLLVMHasZlibCompression() {
llvm::CompressionKind::Zlib
} else {
sess.dcx().emit_warn(UnknownCompression { algorithm: "zlib" });
llvm::CompressionKind::None
}
}
rustc_session::config::DebugInfoCompression::Zstd => {
if !unsafe { LLVMRustLLVMHasZstdCompressionForDebugSymbols() } {
config::DebugInfoCompression::Zstd => {
if llvm::LLVMRustLLVMHasZstdCompression() {
llvm::CompressionKind::Zstd
} else {
sess.dcx().emit_warn(UnknownCompression { algorithm: "zstd" });
llvm::CompressionKind::None
}
}
rustc_session::config::DebugInfoCompression::None => {}
};
let debuginfo_compression = SmallCStr::new(&debuginfo_compression);

let file_name_display_preference =
sess.filename_display_preference(RemapPathScopeComponents::DEBUGINFO);
Expand Down Expand Up @@ -310,7 +311,7 @@ pub(crate) fn target_machine_factory(
use_init_array,
&split_dwarf_file,
&output_obj_file,
&debuginfo_compression,
debuginfo_compression,
use_emulated_tls,
use_wasm_eh,
)
Expand Down
16 changes: 12 additions & 4 deletions compiler/rustc_codegen_llvm/src/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,15 @@ pub(crate) enum Opcode {
CatchSwitch = 65,
}

/// Must match the layout of `LLVMRustCompressionKind`.
#[derive(Copy, Clone)]
#[repr(C)]
pub(crate) enum CompressionKind {
None = 0,
Zlib = 1,
Zstd = 2,
}

unsafe extern "C" {
type Opaque;
}
Expand Down Expand Up @@ -2328,7 +2337,7 @@ unsafe extern "C" {
UseInitArray: bool,
SplitDwarfFile: *const c_char,
OutputObjFile: *const c_char,
DebugInfoCompression: *const c_char,
DebugInfoCompression: CompressionKind,
UseEmulatedTls: bool,
UseWasmEH: bool,
) -> *mut TargetMachine;
Expand Down Expand Up @@ -2516,9 +2525,8 @@ unsafe extern "C" {

pub(crate) fn LLVMRustGetElementTypeArgIndex(CallSite: &Value) -> i32;

pub(crate) fn LLVMRustLLVMHasZlibCompressionForDebugSymbols() -> bool;

pub(crate) fn LLVMRustLLVMHasZstdCompressionForDebugSymbols() -> bool;
pub(crate) safe fn LLVMRustLLVMHasZlibCompression() -> bool;
pub(crate) safe fn LLVMRustLLVMHasZstdCompression() -> bool;

pub(crate) fn LLVMRustGetSymbols(
buf_ptr: *const u8,
Expand Down
42 changes: 31 additions & 11 deletions compiler/rustc_llvm/llvm-wrapper/PassWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,31 @@ static FloatABI::ABIType fromRust(LLVMRustFloatABI RustFloatAbi) {
report_fatal_error("Bad FloatABI.");
}

// Must match the layout of `rustc_codegen_llvm::llvm::ffi::CompressionKind`.
enum class LLVMRustCompressionKind {
None = 0,
Zlib = 1,
Zstd = 2,
};

static llvm::DebugCompressionType fromRust(LLVMRustCompressionKind Kind) {
switch (Kind) {
case LLVMRustCompressionKind::None:
return llvm::DebugCompressionType::None;
case LLVMRustCompressionKind::Zlib:
if (!llvm::compression::zlib::isAvailable()) {
report_fatal_error("LLVMRustCompressionKind::Zlib not available");
}
return llvm::DebugCompressionType::Zlib;
case LLVMRustCompressionKind::Zstd:
if (!llvm::compression::zstd::isAvailable()) {
report_fatal_error("LLVMRustCompressionKind::Zstd not available");
}
return llvm::DebugCompressionType::Zstd;
}
report_fatal_error("bad LLVMRustCompressionKind");
}

extern "C" void LLVMRustPrintTargetCPUs(LLVMTargetMachineRef TM,
RustStringRef OutStr) {
ArrayRef<SubtargetSubTypeKV> CPUTable =
Expand Down Expand Up @@ -271,7 +296,8 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
bool TrapUnreachable, bool Singlethread, bool VerboseAsm,
bool EmitStackSizeSection, bool RelaxELFRelocations, bool UseInitArray,
const char *SplitDwarfFile, const char *OutputObjFile,
const char *DebugInfoCompression, bool UseEmulatedTls, bool UseWasmEH) {
LLVMRustCompressionKind DebugInfoCompression, bool UseEmulatedTls,
bool UseWasmEH) {

auto OptLevel = fromRust(RustOptLevel);
auto RM = fromRust(RustReloc);
Expand Down Expand Up @@ -307,16 +333,10 @@ extern "C" LLVMTargetMachineRef LLVMRustCreateTargetMachine(
if (OutputObjFile) {
Options.ObjectFilenameForDebug = OutputObjFile;
}
if (!strcmp("zlib", DebugInfoCompression) &&
llvm::compression::zlib::isAvailable()) {
Options.MCOptions.CompressDebugSections = DebugCompressionType::Zlib;
} else if (!strcmp("zstd", DebugInfoCompression) &&
llvm::compression::zstd::isAvailable()) {
Options.MCOptions.CompressDebugSections = DebugCompressionType::Zstd;
} else if (!strcmp("none", DebugInfoCompression)) {
Options.MCOptions.CompressDebugSections = DebugCompressionType::None;
}

// To avoid fatal errors, make sure the Rust-side code only passes a
// compression kind that is known to be supported by this build of LLVM, via
// `LLVMRustLLVMHasZlibCompression` and `LLVMRustLLVMHasZstdCompression`.
Options.MCOptions.CompressDebugSections = fromRust(DebugInfoCompression);
Options.MCOptions.X86RelaxRelocations = RelaxELFRelocations;
Options.UseInitArray = UseInitArray;
Options.EmulatedTLS = UseEmulatedTls;
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_llvm/llvm-wrapper/RustWrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1640,11 +1640,11 @@ extern "C" bool LLVMRustIsNonGVFunctionPointerTy(LLVMValueRef V) {
return false;
}

extern "C" bool LLVMRustLLVMHasZlibCompressionForDebugSymbols() {
extern "C" bool LLVMRustLLVMHasZlibCompression() {
return llvm::compression::zlib::isAvailable();
}

extern "C" bool LLVMRustLLVMHasZstdCompressionForDebugSymbols() {
extern "C" bool LLVMRustLLVMHasZstdCompression() {
return llvm::compression::zstd::isAvailable();
}

Expand Down
11 changes: 0 additions & 11 deletions compiler/rustc_session/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -583,17 +583,6 @@ pub enum DebugInfoCompression {
Zstd,
}

impl ToString for DebugInfoCompression {
fn to_string(&self) -> String {
match self {
DebugInfoCompression::None => "none",
DebugInfoCompression::Zlib => "zlib",
DebugInfoCompression::Zstd => "zstd",
}
.to_owned()
}
}

#[derive(Clone, Copy, Debug, PartialEq, Hash)]
pub enum MirStripDebugInfo {
None,
Expand Down
Loading