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

CMake building and Initial REL(A) support #37

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
adding some basic comparison operators
  • Loading branch information
deadly-platypus committed Sep 6, 2019
commit fc4ef378df29fb110f31c110e901d89c886121d6
17 changes: 17 additions & 0 deletions elf/elf++.hh
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ ELFPP_BEGIN_NAMESPACE

elf &operator=(const elf &o) = default;

friend bool operator==(const elf &a, const elf &b);

friend bool operator!=(const elf &a, const elf &b);

bool valid() const {
return !!m;
}
Expand Down Expand Up @@ -123,6 +127,11 @@ ELFPP_BEGIN_NAMESPACE
*/
const section &get_section(unsigned index) const;

/**
* @brief Returns the size in bytes each symbol table entry takes up
* in this ELF file
* @return
*/
size_t get_symtab_entry_size() const;

private:
Expand Down Expand Up @@ -520,6 +529,14 @@ ELFPP_BEGIN_NAMESPACE
* @return
*/
const elf &get_elf() const;

friend bool operator==(const sym &a, const sym &b);

friend bool operator!=(const sym &a, const sym &b);

friend bool operator<(const sym &a, const sym &b);

friend bool operator>(const sym &a, const sym &b);
};

/**
Expand Down
28 changes: 27 additions & 1 deletion elf/elf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,14 @@ ELFPP_BEGIN_NAMESPACE
return sizeof(Sym<Elf64>);
}

bool operator==(const elf &a, const elf &b) {
return a.get_loader() == b.get_loader();
}

bool operator!=(const elf &a, const elf &b) {
return a.get_loader() != b.get_loader();
}

//////////////////////////////////////////////////////////////////
// class segment
//
Expand Down Expand Up @@ -387,6 +395,24 @@ ELFPP_BEGIN_NAMESPACE
return strs.get_elf();
}

bool operator==(const sym &a, const sym &b) {
return (a.get_name() == b.get_name() &&
a.get_data().binding() != stb::local &&
a.get_data().binding() != stb::local
);
}

bool operator!=(const sym &a, const sym &b) {
return !(a == b);
}

bool operator<(const sym &a, const sym &b) {
return (a.get_name() < b.get_name());
}

bool operator>(const sym &a, const sym &b) {
return (a.get_name() > b.get_name());
}

//////////////////////////////////////////////////////////////////
// class rela
Expand Down Expand Up @@ -432,7 +458,7 @@ ELFPP_BEGIN_NAMESPACE
}

sym symtab::get_sym(unsigned idx) const {
size_t entry_size = m->f.get_symtab_entry_size();
size_t entry_size = get_elf().get_symtab_entry_size();

if (m->data + idx * entry_size >= m->end) {
std::stringstream err;
Expand Down