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

Add debug assertions to write_bytes and copy* #58783

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Handle null from LLVMRustGetSectionName
  • Loading branch information
nitnelave committed Apr 27, 2019
commit 8590190e3fdab1a7833e2a59b7e1b70ab29fd1f6
1 change: 0 additions & 1 deletion src/libcore/intrinsics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1334,7 +1334,6 @@ pub(crate) fn is_aligned_and_not_null<T>(ptr: *const T) -> bool {
/// Checks whether the regions of memory starting at `src` and `dst` of size
/// `count * size_of::<T>()` overlap.
fn overlaps<T>(src: *const T, dst: *const T, count: usize) -> bool {
use crate::cmp::Ordering;
let src_usize = src as usize;
let dst_usize = dst as usize;
let size = mem::size_of::<T>().checked_mul(count).unwrap();
Expand Down
4 changes: 3 additions & 1 deletion src/librustc_codegen_llvm/llvm/ffi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1706,7 +1706,9 @@ extern "C" {
pub fn LLVMRustArchiveIteratorFree(AIR: &'a mut ArchiveIterator<'a>);
pub fn LLVMRustDestroyArchive(AR: &'static mut Archive);

pub fn LLVMRustGetSectionName(SI: &SectionIterator<'_>, data: &mut *const c_char) -> size_t;
#[allow(improper_ctypes)]
pub fn LLVMRustGetSectionName(SI: &SectionIterator<'_>,
data: &mut Option<std::ptr::NonNull<c_char>>) -> size_t;

#[allow(improper_ctypes)]
pub fn LLVMRustWriteTwineToString(T: &Twine, s: &RustString);
Expand Down
11 changes: 7 additions & 4 deletions src/librustc_codegen_llvm/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ use rustc_data_structures::owning_ref::OwningRef;
use rustc_codegen_ssa::METADATA_FILENAME;

use std::path::Path;
use std::ptr;
use std::slice;
use rustc_fs_util::path_to_c_string;

Expand Down Expand Up @@ -67,10 +66,14 @@ fn search_meta_section<'a>(of: &'a ObjectFile,
unsafe {
let si = mk_section_iter(of.llof);
while llvm::LLVMIsSectionIteratorAtEnd(of.llof, si.llsi) == False {
let mut name_buf = ptr::null();
let mut name_buf = None;
let name_len = llvm::LLVMRustGetSectionName(si.llsi, &mut name_buf);
let name = slice::from_raw_parts(name_buf as *const u8, name_len as usize).to_vec();
let name = String::from_utf8(name).unwrap();
let name = name_buf.map_or(
"".to_string(),
|buf| String::from_utf8(
slice::from_raw_parts(buf.as_ptr() as *const u8,
name_len as usize)
.to_vec()).unwrap());
debug!("get_metadata_section: name {}", name);
if read_metadata_section_name(target) == name {
let cbuf = llvm::LLVMGetSectionContents(si.llsi);
Expand Down