Skip to content

Commit 3e4a2fa

Browse files
author
Serge Lamikhov-Center
committed
Add tests for the new flavor of get_symbol()
1 parent 1a5ac38 commit 3e4a2fa

File tree

3 files changed

+54
-12
lines changed

3 files changed

+54
-12
lines changed

ELFIOTest/ELFIOTest1.cpp

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,3 +436,50 @@ BOOST_AUTO_TEST_CASE( elf_exe_loadsave_ppc32big3 )
436436
checkExeAreEqual( in, out, SEG_ALIGN );
437437
}
438438

439+
////////////////////////////////////////////////////////////////////////////////
440+
BOOST_AUTO_TEST_CASE( get_symbol_32 )
441+
{
442+
elfio elf;
443+
std::string name;
444+
ELFIO::Elf_Xword size;
445+
unsigned char bind;
446+
unsigned char type;
447+
ELFIO::Elf_Half section_index;
448+
unsigned char other;
449+
std::string in = "../elf_examples/hello_32";
450+
451+
BOOST_REQUIRE_EQUAL( elf.load(in), true );
452+
section* psymsec = elf.sections[ ".symtab" ];
453+
const symbol_section_accessor symbols( elf, psymsec );
454+
455+
BOOST_CHECK_EQUAL( true,
456+
symbols.get_symbol( 0x08048478, name, size, bind,
457+
type, section_index, other) );
458+
BOOST_CHECK_EQUAL( "_IO_stdin_used", name );
459+
BOOST_CHECK_EQUAL( 14, section_index );
460+
BOOST_CHECK_EQUAL( 4, size );
461+
}
462+
463+
////////////////////////////////////////////////////////////////////////////////
464+
BOOST_AUTO_TEST_CASE( get_symbol_64 )
465+
{
466+
elfio elf;
467+
std::string name;
468+
ELFIO::Elf_Xword size;
469+
unsigned char bind;
470+
unsigned char type;
471+
ELFIO::Elf_Half section_index;
472+
unsigned char other;
473+
std::string in = "../elf_examples/hello_64";
474+
475+
BOOST_REQUIRE_EQUAL( elf.load(in), true );
476+
section* psymsec = elf.sections[ ".symtab" ];
477+
const symbol_section_accessor symbols( elf, psymsec );
478+
479+
BOOST_CHECK_EQUAL( true,
480+
symbols.get_symbol(0x00400498, name, size, bind,
481+
type, section_index, other) );
482+
BOOST_CHECK_EQUAL( "main", name );
483+
BOOST_CHECK_EQUAL( 12, section_index );
484+
BOOST_CHECK_EQUAL( 21, size );
485+
}

elfio/elfio.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ THE SOFTWARE.
3939
#include <deque>
4040
#include <iterator>
4141
#include <typeinfo>
42-
#include <cassert>
4342

4443
#include <elfio/elf_types.hpp>
4544
#include <elfio/elfio_utils.hpp>

elfio/elfio_symbols.hpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,8 @@ class symbol_section_accessor_template
9292
Elf_Word nchain = *(const Elf_Word*)( hash_section->get_data() +
9393
sizeof( Elf_Word ) );
9494
Elf_Word val = elf_hash( (const unsigned char*)name.c_str() );
95-
96-
Elf_Word y = *(const Elf_Word*)( hash_section->get_data() +
97-
( 2 + val % nbucket ) * sizeof( Elf_Word ) );
95+
Elf_Word y = *(const Elf_Word*)( hash_section->get_data() +
96+
( 2 + val % nbucket ) * sizeof( Elf_Word ) );
9897
std::string str;
9998
get_symbol( y, str, value, size, bind, type, section_index, other );
10099
while ( str != name && STN_UNDEF != y && y < nchain ) {
@@ -125,9 +124,9 @@ class symbol_section_accessor_template
125124
const endianess_convertor& convertor = elf_file.get_convertor();
126125
section* string_section = elf_file.sections[get_string_table_index()];
127126

128-
Elf_Xword idx = 0;
129-
bool match = false;
130-
Elf64_Addr v = 0;
127+
Elf_Xword idx = 0;
128+
bool match = false;
129+
Elf64_Addr v = 0;
131130

132131
if ( elf_file.get_class() == ELFCLASS32 ) {
133132
match = generic_search_symbols<Elf32_Sym>([&convertor, &value](const Elf32_Sym* sym) {
@@ -139,11 +138,8 @@ class symbol_section_accessor_template
139138
}, idx);
140139
}
141140

142-
if (match) {
143-
bool found = get_symbol( idx, name, v, size, bind, type, section_index, other );
144-
assert(found);
145-
assert(v == value);
146-
return true;
141+
if ( match ) {
142+
return get_symbol( idx, name, v, size, bind, type, section_index, other );
147143
}
148144

149145
return false;

0 commit comments

Comments
 (0)