Skip to content
This repository has been archived by the owner on Mar 4, 2021. It is now read-only.

Minor fix to reduce dependencies #19

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
22 changes: 14 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,31 +23,37 @@ bloom = "0.3.2"
fnv = "1.0.5"
indexmap = "1.0.1"
log = "0.4"
env_logger = "0.5.10"
pretty_env_logger = "0.2.3"
clap = "2.28.0"
glob = "0.2.11"
ar = "0.6.0"


## bin dependencies
colored = "1"
tempfile = "3.0.2"
sha2 = "0.7.1"
clap = { version = "2.28.0", optional = true }
colored = { version = "1", optional = true }
tempfile = { version = "3.0.2", optional = true }
sha2 = { version = "0.7.1", optional = true }
env_logger = { version = "0.5.10", optional = true }
pretty_env_logger = { version = "0.2.3", optional = true }
glob = { version = "0.2.11", optional = true }

[features]
build-binary = [ "clap", "colored", "tempfile", "sha2", "env_logger", "pretty_env_logger", "glob" ]

[[bin]]
name="readelf"
path="bin/readelf.rs"
required-features = ["build-binary"]


[[bin]]
name="linktree"
path="bin/linktree.rs"
required-features = ["build-binary"]

[[bin]]
name="ld"
path="bin/ld.rs"
required-features = ["build-binary"]

[[bin]]
name="ldd"
path="bin/ldd.rs"
required-features = ["build-binary"]
2 changes: 1 addition & 1 deletion bin/ld.rs
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ impl Collected {

let sh_index_symtab = self.elf.sections.len();
let first_global_symtab = self.symtab.iter().enumerate()
.find(|&(_,s)|s.bind == types::SymbolBind::GLOBAL).map(|(i,_)|i).unwrap_or(0);;
.find(|&(_,s)|s.bind == types::SymbolBind::GLOBAL).map(|(i,_)|i).unwrap_or(0);
self.elf.sections.push(section::Section::new(b".symtab".to_vec(), types::SectionType::SYMTAB,
types::SectionFlags::empty(),
section::SectionContent::Symbols(self.symtab),
Expand Down
2 changes: 1 addition & 1 deletion bolter/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ fn main() {

//sc_symtab.sort_unstable_by(|a,b| a.bind.cmp(&b.bind));
let first_global_symtab = sc_symtab.iter().enumerate()
.find(|&(_,s)|s.bind == types::SymbolBind::GLOBAL).map(|(i,_)|i).unwrap_or(0);;
.find(|&(_,s)|s.bind == types::SymbolBind::GLOBAL).map(|(i,_)|i).unwrap_or(0);
out_elf.sections.push(Section::new(String::from(".symtab"), types::SectionType::SYMTAB,
types::SectionFlags::empty(),
SectionContent::Symbols(sc_symtab),
Expand Down
2 changes: 1 addition & 1 deletion src/dynamic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl Dynamic {
&self,
mut io: W,
eh: &Header,
) -> Result<(usize), Error>
) -> Result<usize, Error>
where
W: Write,
{
Expand Down
2 changes: 1 addition & 1 deletion src/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -679,7 +679,7 @@ impl Elf {

//TODO this code isnt tested at all
//TODO the warnings need to be emited when calling store_all instead
pub fn remove_section(&mut self, at: usize) -> Result<(Section), Error> {
pub fn remove_section(&mut self, at: usize) -> Result<Section, Error> {
let r = self.sections.remove(at);

for sec in &mut self.sections {
Expand Down
4 changes: 2 additions & 2 deletions src/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub enum State {
hash: String,
name: String,
elf: Elf,
read: RefCell<Box<ReadSeekSend>>,
read: RefCell<Box<dyn ReadSeekSend>>,
bloom: BloomFilter,
symbols: Vec<symbol::Symbol>,
},
Expand Down Expand Up @@ -230,7 +230,7 @@ impl State {
}
}

fn make_object(name: String, io: RefCell<Box<ReadSeekSend>>) -> Result<State, Error> {
fn make_object(name: String, io: RefCell<Box<dyn ReadSeekSend>>) -> Result<State, Error> {

let mut elf = Elf::from_reader(&mut *io.borrow_mut())?;

Expand Down
2 changes: 1 addition & 1 deletion src/relocation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl Relocation {
&self,
mut io: W,
eh: &Header,
) -> Result<(usize), Error>
) -> Result<usize, Error>
where
W: Write,
{
Expand Down
2 changes: 1 addition & 1 deletion src/symbol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ impl Symbol {
&self,
mut io: W,
eh: &Header,
) -> Result<(usize), Error>
) -> Result<usize, Error>
where
W: Write,
{
Expand Down
18 changes: 9 additions & 9 deletions tests/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ fn layout_just_text() {
let phdr_segments :Vec<&segment::SegmentHeader> = elf.segments.iter().filter(|x| x.phtype == types::SegmentType::PHDR).collect();
assert_eq!(phdr_segments.len(), 1,
"expecting exactly one phdr segment");
let phdr = phdr_segments.get(0).unwrap();;
let phdr = phdr_segments.get(0).unwrap();

assert_eq!(phdr.offset, elf.header.phoff,
"phdr.offset must be identical to elf header phoff");
Expand All @@ -155,7 +155,7 @@ fn layout_just_text() {
assert_eq!(load_segments.len(), 1,
"expect exactly one load segment");

let segment = load_segments.get(0).unwrap();;
let segment = load_segments.get(0).unwrap();
assert_eq!(segment.offset,0,
"first load segment must start at zero");
assert_eq!(segment.vaddr, 0,
Expand Down Expand Up @@ -205,7 +205,7 @@ fn layout_just_bss() {
let load_segments :Vec<&segment::SegmentHeader> = elf.segments.iter().filter(|x| x.phtype == types::SegmentType::LOAD).collect();
assert_eq!(load_segments.len(), 1,
"expect xactly one load segment");
let segment = load_segments.get(0).unwrap();;
let segment = load_segments.get(0).unwrap();

assert!(segment.vaddr <= elf.sections[1].header.addr,
"first load segment must start at or before .bss");
Expand Down Expand Up @@ -252,8 +252,8 @@ fn layout_text_and_bss_1() {
let load_segments :Vec<&segment::SegmentHeader> = elf.segments.iter().filter(|x| x.phtype == types::SegmentType::LOAD).collect();
assert_eq!(load_segments.len(), 2,
"expect exactly 2 load segments");
let segment0 = load_segments.get(0).unwrap();;
let segment1 = load_segments.get(1).unwrap();;
let segment0 = load_segments.get(0).unwrap();
let segment1 = load_segments.get(1).unwrap();

assert_eq!(segment0.vaddr,0 ,
"first load segment must start at 0");
Expand Down Expand Up @@ -303,9 +303,9 @@ fn layout_text_and_bss_2() {
let load_segments :Vec<&segment::SegmentHeader> = elf.segments.iter().filter(|x| x.phtype == types::SegmentType::LOAD).collect();
assert_eq!(load_segments.len(), 3,
"expect exactly 3 load segments");
let segment0 = load_segments.get(0).unwrap();;
let segment1 = load_segments.get(1).unwrap();;
let segment2 = load_segments.get(2).unwrap();;
let segment0 = load_segments.get(0).unwrap();
let segment1 = load_segments.get(1).unwrap();
let segment2 = load_segments.get(2).unwrap();

assert_eq!(segment0.vaddr, 0,
"first load segment must start at 0");
Expand Down Expand Up @@ -468,7 +468,7 @@ fn layout_many_bss() {
"expect exactly 5 segments");

let load_segments :Vec<&segment::SegmentHeader> = elf.segments.iter().filter(|x| x.phtype == types::SegmentType::LOAD).collect();
let segment0 = load_segments.get(0).unwrap();;
let segment0 = load_segments.get(0).unwrap();
assert!(!segment0.flags.contains(types::SegmentFlags::WRITABLE),
"first load segment must NOT be writable");
}