Skip to content

Commit

Permalink
Allow rustc to automatically link to alloc
Browse files Browse the repository at this point in the history
This hack is necessary for rustc point to the correct version of the
alloc crate when `phdrs` is used in `library/std` during the bootstrap
process.
  • Loading branch information
jacob-hughes committed Jan 25, 2024
1 parent c1fcf63 commit 5d7fb3a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ license = "Apache-2.0 OR MIT"
libc = { version = "0.2.94", default-features = false }
core = { version = "1.0.0", optional = true, package = 'rustc-std-workspace-core' }
compiler_builtins = { version = "0.1.16", optional = true }
alloc = { version = "1.0.0", optional = true, package = "rustc-std-workspace-alloc" }

[features]
default = ["std"]
rustc-dep-of-std = ['core', 'compiler_builtins']
rustc-dep-of-std = ['core', 'compiler_builtins', 'alloc']
std = []
alloc = []
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#![cfg_attr(not(feature = "std"), no_std)]
#![cfg(not(feature = "rustc-dep-of-std"))]
extern crate alloc;

use libc::{c_int, c_void, dl_iterate_phdr, dl_phdr_info};
pub use libc::{
Expand All @@ -12,12 +14,10 @@ use core::{
iter::Iterator,
};

#[cfg(feature = "alloc")]
extern crate alloc;
#[cfg(feature = "alloc")]
#[cfg(not(feature = "std"))]
use alloc::{borrow::ToOwned, ffi::CString, format, string::String, vec::Vec};

#[cfg(not(feature = "alloc"))]
#[cfg(feature = "std")]
use std::ffi::CString;

#[cfg(target_pointer_width = "64")]
Expand Down Expand Up @@ -89,7 +89,7 @@ impl Object {
}

impl Debug for Object {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(
f,
"Object {{ addr: 0x{:x}, name: {:?}, phdrs: {:?}, num_phdrs: {} }}",
Expand Down Expand Up @@ -145,7 +145,7 @@ impl ProgramHeader {
}

impl Debug for ProgramHeader {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let mut to_write = String::from("ProgramHeader(");
let type_ = self.type_();
let type_str = match type_ {
Expand Down

0 comments on commit 5d7fb3a

Please sign in to comment.