diff --git a/ELFIOTest/ELFIOTest1.cpp b/ELFIOTest/ELFIOTest1.cpp index 46669f403a42b24f87ad1d2ac59dfc4d67cded67..efb49e0c2506abcea39ab23d78443ec089ddf686 100644 --- a/ELFIOTest/ELFIOTest1.cpp +++ b/ELFIOTest/ELFIOTest1.cpp @@ -436,3 +436,50 @@ BOOST_AUTO_TEST_CASE( elf_exe_loadsave_ppc32big3 ) checkExeAreEqual( in, out, SEG_ALIGN ); } +//////////////////////////////////////////////////////////////////////////////// +BOOST_AUTO_TEST_CASE( get_symbol_32 ) +{ + elfio elf; + std::string name; + ELFIO::Elf_Xword size; + unsigned char bind; + unsigned char type; + ELFIO::Elf_Half section_index; + unsigned char other; + std::string in = "../elf_examples/hello_32"; + + BOOST_REQUIRE_EQUAL( elf.load(in), true ); + section* psymsec = elf.sections[ ".symtab" ]; + const symbol_section_accessor symbols( elf, psymsec ); + + BOOST_CHECK_EQUAL( true, + symbols.get_symbol( 0x08048478, name, size, bind, + type, section_index, other) ); + BOOST_CHECK_EQUAL( "_IO_stdin_used", name ); + BOOST_CHECK_EQUAL( 14, section_index ); + BOOST_CHECK_EQUAL( 4, size ); +} + +//////////////////////////////////////////////////////////////////////////////// +BOOST_AUTO_TEST_CASE( get_symbol_64 ) +{ + elfio elf; + std::string name; + ELFIO::Elf_Xword size; + unsigned char bind; + unsigned char type; + ELFIO::Elf_Half section_index; + unsigned char other; + std::string in = "../elf_examples/hello_64"; + + BOOST_REQUIRE_EQUAL( elf.load(in), true ); + section* psymsec = elf.sections[ ".symtab" ]; + const symbol_section_accessor symbols( elf, psymsec ); + + BOOST_CHECK_EQUAL( true, + symbols.get_symbol(0x00400498, name, size, bind, + type, section_index, other) ); + BOOST_CHECK_EQUAL( "main", name ); + BOOST_CHECK_EQUAL( 12, section_index ); + BOOST_CHECK_EQUAL( 21, size ); +} diff --git a/elfio/elfio.hpp b/elfio/elfio.hpp index b8c9150e572b378f31e8f3a8c98377ea46e12fcf..0ab85523dc93efacb50a787910a6f456e4e43705 100644 --- a/elfio/elfio.hpp +++ b/elfio/elfio.hpp @@ -39,7 +39,6 @@ THE SOFTWARE. #include <deque> #include <iterator> #include <typeinfo> -#include <cassert> #include <elfio/elf_types.hpp> #include <elfio/elfio_utils.hpp> diff --git a/elfio/elfio_symbols.hpp b/elfio/elfio_symbols.hpp index 7d86d2ecc2c59f9ee6bc9b04d1f74be2dec94bbd..3a0689ac48aaf62de0325b9450d9ab976f6d9948 100644 --- a/elfio/elfio_symbols.hpp +++ b/elfio/elfio_symbols.hpp @@ -92,9 +92,8 @@ class symbol_section_accessor_template Elf_Word nchain = *(const Elf_Word*)( hash_section->get_data() + sizeof( Elf_Word ) ); Elf_Word val = elf_hash( (const unsigned char*)name.c_str() ); - - Elf_Word y = *(const Elf_Word*)( hash_section->get_data() + - ( 2 + val % nbucket ) * sizeof( Elf_Word ) ); + Elf_Word y = *(const Elf_Word*)( hash_section->get_data() + + ( 2 + val % nbucket ) * sizeof( Elf_Word ) ); std::string str; get_symbol( y, str, value, size, bind, type, section_index, other ); while ( str != name && STN_UNDEF != y && y < nchain ) { @@ -125,9 +124,9 @@ class symbol_section_accessor_template const endianess_convertor& convertor = elf_file.get_convertor(); section* string_section = elf_file.sections[get_string_table_index()]; - Elf_Xword idx = 0; - bool match = false; - Elf64_Addr v = 0; + Elf_Xword idx = 0; + bool match = false; + Elf64_Addr v = 0; if ( elf_file.get_class() == ELFCLASS32 ) { match = generic_search_symbols<Elf32_Sym>([&convertor, &value](const Elf32_Sym* sym) { @@ -139,11 +138,8 @@ class symbol_section_accessor_template }, idx); } - if (match) { - bool found = get_symbol( idx, name, v, size, bind, type, section_index, other ); - assert(found); - assert(v == value); - return true; + if ( match ) { + return get_symbol( idx, name, v, size, bind, type, section_index, other ); } return false;