Skip to content

Commit

Permalink
Add Support for LLVM 11. Fixes rust-lang#217
Browse files Browse the repository at this point in the history
Added support for an llvm 11 feature
Fixed the Debug builder API to support the new arguments
  • Loading branch information
ghaith authored and TheDan64 committed Jan 10, 2021
1 parent 3eab4db commit 9414870
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 5 deletions.
3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ llvm7-0 = ["llvm-sys-70"]
llvm8-0 = ["llvm-sys-80"]
llvm9-0 = ["llvm-sys-90"]
llvm10-0 = ["llvm-sys-100"]
llvm11-0 = ["llvm-sys-110"]
# Don't link aganist LLVM libraries. This is useful if another dependency is
# installing LLVM. See llvm-sys for more details. We can't enable a single
# `no-llvm-linking` feature across the board of llvm versions, as it'll cause
Expand All @@ -41,6 +42,7 @@ llvm7-0-no-llvm-linking = ["llvm7-0", "llvm-sys-70/no-llvm-linking"]
llvm8-0-no-llvm-linking = ["llvm8-0", "llvm-sys-80/no-llvm-linking"]
llvm9-0-no-llvm-linking = ["llvm9-0", "llvm-sys-90/no-llvm-linking"]
llvm10-0-no-llvm-linking = ["llvm10-0", "llvm-sys-100/no-llvm-linking"]
llvm11-0-no-llvm-linking = ["llvm11-0", "llvm-sys-110/no-llvm-linking"]
# Don't force linking to libffi on non-windows platforms. Without this feature
# inkwell always links to libffi on non-windows platforms.
no-libffi-linking = []
Expand Down Expand Up @@ -96,6 +98,7 @@ llvm-sys-70 = { package = "llvm-sys", version = "70.4", optional = true }
llvm-sys-80 = { package = "llvm-sys", version = "80.3", optional = true }
llvm-sys-90 = { package = "llvm-sys", version = "90.2", optional = true }
llvm-sys-100 = { package = "llvm-sys", version = "100.2", optional = true }
llvm-sys-110 = { package = "llvm-sys", version = "110.0", optional = true }
once_cell = "1.4.1"
parking_lot = "0.11"
regex = "1"
Expand Down
4 changes: 2 additions & 2 deletions internal_macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ use syn::spanned::Spanned;
use syn::{Token, LitFloat, Ident, Item, Field, Variant, Attribute};

// This array should match the LLVM features in the top level Cargo manifest
const FEATURE_VERSIONS: [&str; 11] =
["llvm3-6", "llvm3-7", "llvm3-8", "llvm3-9", "llvm4-0", "llvm5-0", "llvm6-0", "llvm7-0", "llvm8-0", "llvm9-0", "llvm10-0"];
const FEATURE_VERSIONS: [&str; 12] =
["llvm3-6", "llvm3-7", "llvm3-8", "llvm3-9", "llvm4-0", "llvm5-0", "llvm6-0", "llvm7-0", "llvm8-0", "llvm9-0", "llvm10-0", "llvm11-0"];

/// Gets the index of the feature version that represents `latest`
fn get_latest_feature_index(features: &[&str]) -> usize {
Expand Down
119 changes: 119 additions & 0 deletions src/debug_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ pub trait AsDIScope<'ctx> {
}

impl<'ctx> DebugInfoBuilder<'ctx> {
#[llvm_versions(3.6..=10.0)]
pub(crate) fn new(
module: &Module,
allow_unresolved: bool,
Expand Down Expand Up @@ -210,6 +211,59 @@ impl<'ctx> DebugInfoBuilder<'ctx> {
(builder, cu)
}

#[llvm_versions(11.0)]
pub(crate) fn new(
module: &Module,
allow_unresolved: bool,
language: DWARFSourceLanguage,
filename: &str,
directory: &str,
producer: &str,
is_optimized: bool,
flags: &str,
runtime_ver: libc::c_uint,
split_name: &str,
kind: DWARFEmissionKind,
dwo_id: libc::c_uint,
split_debug_inlining: bool,
debug_info_for_profiling: bool,
sysroot: &str,
sdk: &str,
) -> (Self, DICompileUnit<'ctx>) {
let builder = unsafe {
if allow_unresolved {
LLVMCreateDIBuilder(module.module.get())
} else {
LLVMCreateDIBuilderDisallowUnresolved(module.module.get())
}
};

let builder = DebugInfoBuilder {
builder,
_marker: PhantomData,
};

let file = builder.create_file(filename, directory);

let cu = builder.create_compile_unit(
language,
file,
producer,
is_optimized,
flags,
runtime_ver,
split_name,
kind,
dwo_id,
split_debug_inlining,
debug_info_for_profiling,
sysroot,
sdk
);

(builder, cu)
}

/// A DICompileUnit provides an anchor for all debugging information generated during this instance of compilation.
///
/// * `language` - Source programming language
Expand All @@ -223,6 +277,7 @@ impl<'ctx> DebugInfoBuilder<'ctx> {
/// * `dwo_id` - The DWOId if this is a split skeleton compile unit.
/// * `split_debug_inlining` - Whether to emit inline debug info.
/// * `debug_info_for_profiling` - Whether to emit extra debug info for profile collection.
#[llvm_versions(3.6..=10.0)]
fn create_compile_unit(
&self,
language: DWARFSourceLanguage,
Expand Down Expand Up @@ -264,6 +319,70 @@ impl<'ctx> DebugInfoBuilder<'ctx> {
}
}

/// A DICompileUnit provides an anchor for all debugging information generated during this instance of compilation.
///
/// * `language` - Source programming language
/// * `file` - File info
/// * `producer` - Identify the producer of debugging information and code. Usually this is a compiler version string.
/// * `is_optimized` - A boolean flag which indicates whether optimization is enabled or not.
/// * `flags` - This string lists command line options. This string is directly embedded in debug info output which may be used by a tool analyzing generated debugging information.
/// * `runtime_ver` - This indicates runtime version for languages like Objective-C.
/// * `split_name` - The name of the file that we'll split debug info out into.
/// * `kind` - The kind of debug information to generate.
/// * `dwo_id` - The DWOId if this is a split skeleton compile unit.
/// * `split_debug_inlining` - Whether to emit inline debug info.
/// * `debug_info_for_profiling` - Whether to emit extra debug info for profile collection.
/// * `sysroot` The clang system root (value of -isysroot).
/// * `sdk` The SDK name. On Darwin, this is the last component of the sysroot.
#[llvm_versions(11.0)]
fn create_compile_unit(
&self,
language: DWARFSourceLanguage,
file: DIFile<'ctx>,
producer: &str,
is_optimized: bool,
flags: &str,
runtime_ver: libc::c_uint,
split_name: &str,
kind: DWARFEmissionKind,
dwo_id: libc::c_uint,
split_debug_inlining: bool,
debug_info_for_profiling: bool,
sysroot: &str,
sdk: &str,
) -> DICompileUnit<'ctx> {

let metadata_ref = unsafe {
LLVMDIBuilderCreateCompileUnit(
self.builder,
language.into(),
file.metadata_ref,
producer.as_ptr() as _,
producer.len(),
is_optimized as _,
flags.as_ptr() as _,
flags.len(),
runtime_ver,
split_name.as_ptr() as _,
split_name.len(),
kind.into(),
dwo_id,
split_debug_inlining as _,
debug_info_for_profiling as _,
sysroot.as_ptr() as _,
sysroot.len(),
sdk.as_ptr() as _,
sdk.len(),
)
};

DICompileUnit {
file,
metadata_ref,
_marker: PhantomData,
}
}

/// A DIFunction provides an anchor for all debugging information generated for the specified subprogram.
///
/// * `scope` - Function scope.
Expand Down
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ extern crate llvm_sys_80 as llvm_sys;
extern crate llvm_sys_90 as llvm_sys;
#[cfg(feature="llvm10-0")]
extern crate llvm_sys_100 as llvm_sys;
#[cfg(feature="llvm11-0")]
extern crate llvm_sys_110 as llvm_sys;

use llvm_sys::{LLVMIntPredicate, LLVMRealPredicate, LLVMVisibility, LLVMThreadLocalMode, LLVMDLLStorageClass, LLVMAtomicOrdering, LLVMAtomicRMWBinOp};

Expand Down Expand Up @@ -100,7 +102,7 @@ macro_rules! assert_unique_used_features {
}
}

assert_unique_used_features!{"llvm3-6", "llvm3-7", "llvm3-8", "llvm3-9", "llvm4-0", "llvm5-0", "llvm6-0", "llvm7-0", "llvm8-0", "llvm9-0", "llvm10-0"}
assert_unique_used_features!{"llvm3-6", "llvm3-7", "llvm3-8", "llvm3-9", "llvm4-0", "llvm5-0", "llvm6-0", "llvm7-0", "llvm8-0", "llvm9-0", "llvm10-0", "llvm11-0"}

/// Defines the address space in which a global will be inserted.
///
Expand Down
28 changes: 27 additions & 1 deletion src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1354,7 +1354,7 @@ impl<'ctx> Module<'ctx> {
}

/// Creates a `DebugInfoBuilder` for this `Module`.
#[llvm_versions(7.0..=latest)]
#[llvm_versions(7.0..=10.0)]
pub fn create_debug_info_builder(&self,
allow_unresolved: bool,
language: DWARFSourceLanguage,
Expand All @@ -1374,6 +1374,32 @@ impl<'ctx> Module<'ctx> {
language, filename, directory, producer, is_optimized, flags, runtime_ver, split_name, kind, dwo_id, split_debug_inlining, debug_info_for_profiling
)
}

/// Creates a `DebugInfoBuilder` for this `Module`.
#[llvm_versions(11.0)]
pub fn create_debug_info_builder(&self,
allow_unresolved: bool,
language: DWARFSourceLanguage,
filename: &str,
directory: &str,
producer: &str,
is_optimized: bool,
flags: &str,
runtime_ver: libc::c_uint,
split_name: &str,
kind: DWARFEmissionKind,
dwo_id: libc::c_uint,
split_debug_inlining: bool,
debug_info_for_profiling: bool,
sysroot: &str,
sdk: &str,
) -> (DebugInfoBuilder<'ctx>, DICompileUnit<'ctx>) {
DebugInfoBuilder::new(self, allow_unresolved,
language, filename, directory, producer, is_optimized, flags,
runtime_ver, split_name, kind, dwo_id, split_debug_inlining,
debug_info_for_profiling, sysroot, sdk
)
}
}

impl Clone for Module<'_> {
Expand Down
8 changes: 8 additions & 0 deletions src/types/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,17 @@ impl<'ctx> AnyTypeEnum<'ctx> {
LLVMTypeKind::LLVMX86_FP80TypeKind |
LLVMTypeKind::LLVMFP128TypeKind |
LLVMTypeKind::LLVMPPC_FP128TypeKind => AnyTypeEnum::FloatType(FloatType::new(type_)),
#[cfg(feature = "llvm11-0")]
LLVMTypeKind::LLVMBFloatTypeKind => AnyTypeEnum::FloatType(FloatType::new(type_)),
LLVMTypeKind::LLVMLabelTypeKind => panic!("FIXME: Unsupported type: Label"),
LLVMTypeKind::LLVMIntegerTypeKind => AnyTypeEnum::IntType(IntType::new(type_)),
LLVMTypeKind::LLVMFunctionTypeKind => AnyTypeEnum::FunctionType(FunctionType::new(type_)),
LLVMTypeKind::LLVMStructTypeKind => AnyTypeEnum::StructType(StructType::new(type_)),
LLVMTypeKind::LLVMArrayTypeKind => AnyTypeEnum::ArrayType(ArrayType::new(type_)),
LLVMTypeKind::LLVMPointerTypeKind => AnyTypeEnum::PointerType(PointerType::new(type_)),
LLVMTypeKind::LLVMVectorTypeKind => AnyTypeEnum::VectorType(VectorType::new(type_)),
#[cfg(feature = "llvm11-0")]
LLVMTypeKind::LLVMScalableVectorTypeKind => AnyTypeEnum::VectorType(VectorType::new(type_)),
LLVMTypeKind::LLVMMetadataTypeKind => panic!("FIXME: Unsupported type: Metadata"),
LLVMTypeKind::LLVMX86_MMXTypeKind => panic!("FIXME: Unsupported type: MMX"),
#[cfg(not(any(feature = "llvm3-6", feature = "llvm3-7")))]
Expand Down Expand Up @@ -277,11 +281,15 @@ impl<'ctx> BasicTypeEnum<'ctx> {
LLVMTypeKind::LLVMX86_FP80TypeKind |
LLVMTypeKind::LLVMFP128TypeKind |
LLVMTypeKind::LLVMPPC_FP128TypeKind => BasicTypeEnum::FloatType(FloatType::new(type_)),
#[cfg(feature= "llvm11-0")]
LLVMTypeKind::LLVMBFloatTypeKind => BasicTypeEnum::FloatType(FloatType::new(type_)),
LLVMTypeKind::LLVMIntegerTypeKind => BasicTypeEnum::IntType(IntType::new(type_)),
LLVMTypeKind::LLVMStructTypeKind => BasicTypeEnum::StructType(StructType::new(type_)),
LLVMTypeKind::LLVMPointerTypeKind => BasicTypeEnum::PointerType(PointerType::new(type_)),
LLVMTypeKind::LLVMArrayTypeKind => BasicTypeEnum::ArrayType(ArrayType::new(type_)),
LLVMTypeKind::LLVMVectorTypeKind => BasicTypeEnum::VectorType(VectorType::new(type_)),
#[cfg(feature= "llvm11-0")]
LLVMTypeKind::LLVMScalableVectorTypeKind => BasicTypeEnum::VectorType(VectorType::new(type_)),
LLVMTypeKind::LLVMMetadataTypeKind => unreachable!("Unsupported basic type: Metadata"),
LLVMTypeKind::LLVMX86_MMXTypeKind => unreachable!("Unsupported basic type: MMX"),
LLVMTypeKind::LLVMLabelTypeKind => unreachable!("Unsupported basic type: Label"),
Expand Down
2 changes: 1 addition & 1 deletion src/values/metadata_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ pub const FIRST_CUSTOM_METADATA_KIND_ID: u32 = 25;
pub const FIRST_CUSTOM_METADATA_KIND_ID: u32 = 26;
#[cfg(feature = "llvm9-0")]
pub const FIRST_CUSTOM_METADATA_KIND_ID: u32 = 28;
#[cfg(feature = "llvm10-0")]
#[cfg(any(feature = "llvm10-0", feature = "llvm11-0"))]
pub const FIRST_CUSTOM_METADATA_KIND_ID: u32 = 30;

#[derive(PartialEq, Eq, Clone, Copy, Hash)]
Expand Down
24 changes: 24 additions & 0 deletions tests/all/test_debug_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ fn test_smoke() {
0,
false,
false,
#[cfg(feature = "llvm11-0")]
"",
#[cfg(feature = "llvm11-0")]
"",
);

let ditype = dibuilder
Expand Down Expand Up @@ -106,6 +110,10 @@ fn test_struct_with_placeholders() {
0,
false,
false,
#[cfg(feature = "llvm11-0")]
"",
#[cfg(feature = "llvm11-0")]
"",
);

// Some byte aligned integer types.
Expand Down Expand Up @@ -219,6 +227,10 @@ fn test_no_explicit_finalize() {
0,
false,
false,
#[cfg(feature = "llvm11-0")]
"",
#[cfg(feature = "llvm11-0")]
"",
);

drop(dibuilder);
Expand Down Expand Up @@ -246,6 +258,10 @@ fn test_replacing_placeholder_with_placeholder() {
0,
false,
false,
#[cfg(feature = "llvm11-0")]
"",
#[cfg(feature = "llvm11-0")]
"",
);

let i32ty = dibuilder
Expand Down Expand Up @@ -289,6 +305,10 @@ fn test_anonymous_basic_type() {
0,
false,
false,
#[cfg(feature = "llvm11-0")]
"",
#[cfg(feature = "llvm11-0")]
"",
);

assert_eq!(
Expand Down Expand Up @@ -323,6 +343,10 @@ fn test_global_expressions() {
0,
false,
false,
#[cfg(feature = "llvm11-0")]
"",
#[cfg(feature = "llvm11-0")]
"",
);

let di_type = dibuilder.create_basic_type("type_name", 0_u64, 0x00, DIFlags::ZERO);
Expand Down

0 comments on commit 9414870

Please sign in to comment.