Add test that verifies that get_symbols_num() returns increased value after add_symbol()

This commit is contained in:
Serge Lamikhov-Center 2024-06-13 16:22:12 +03:00 committed by Serge Lamikhov-Center
parent 92b9b67df6
commit a872f7cdde
3 changed files with 18 additions and 10 deletions

4
.vscode/launch.json vendored
View File

@ -10,7 +10,7 @@
"request": "launch",
"program": "${workspaceFolder}/build/tests/ELFIOTest",
"args": [
"--gtest_filter=ELFIOTest.load32",
//"--gtest_filter=ELFIOTest.load32",
],
"stopAtEntry": false,
"cwd": "${workspaceFolder}/build/tests",
@ -24,7 +24,7 @@
"ignoreFailures": true
}
],
"preLaunchTask": "ELFIO Test build",
//"preLaunchTask": "ELFIO Test build",
"miDebuggerPath": "/usr/bin/gdb"
},
{

View File

@ -120,13 +120,12 @@ template <class S> class symbol_section_accessor_template
for ( Elf_Xword i = 0; !ret && i < get_symbols_num(); i++ ) {
std::string symbol_name;
if ( get_symbol( i, symbol_name, value, size, bind, type,
section_index, other ) ) {
if ( symbol_name == name ) {
section_index, other ) &&
( symbol_name == name ) ) {
ret = true;
}
}
}
}
return ret;
}
@ -346,7 +345,7 @@ template <class S> class symbol_section_accessor_template
bloom_size = convertor( bloom_size );
bloom_shift = convertor( bloom_shift );
T* bloom_filter =
auto* bloom_filter =
(T*)( hash_section->get_data() + 4 * sizeof( uint32_t ) );
uint32_t hash = elf_gnu_hash( (const unsigned char*)name.c_str() );
@ -377,13 +376,14 @@ template <class S> class symbol_section_accessor_template
if ( ( chain_hash >> 1 ) == ( hash >> 1 ) &&
get_symbol( chain_index + symoffset, symname, value, size,
bind, type, section_index, other ) &&
name == symname ) {
( name == symname ) ) {
ret = true;
break;
}
if ( chain_hash & 1 )
break;
chain_hash = convertor( chains[++chain_index] );
}
}
@ -398,7 +398,7 @@ template <class S> class symbol_section_accessor_template
if ( symbol_section->get_entry_size() < sizeof( T ) ) {
return nullptr;
}
const T* pSym = reinterpret_cast<const T*>(
const auto* pSym = reinterpret_cast<const T*>(
symbol_section->get_data() +
index * symbol_section->get_entry_size() );
@ -443,7 +443,7 @@ template <class S> class symbol_section_accessor_template
if ( nullptr != symbol_section->get_data() &&
index < get_symbols_num() ) {
const T* pSym = reinterpret_cast<const T*>(
const auto* pSym = reinterpret_cast<const T*>(
symbol_section->get_data() +
index * symbol_section->get_entry_size() );

View File

@ -636,6 +636,8 @@ TEST( ELFIOTest, rearrange_local_symbols )
sym_sec->set_entry_size( writer.get_default_entry_size( SHT_SYMTAB ) );
symbol_section_accessor symbols( writer, sym_sec );
auto sym_num = symbols.get_symbols_num();
name = "Str1";
bind = STB_GLOBAL;
value = 1;
@ -677,6 +679,8 @@ TEST( ELFIOTest, rearrange_local_symbols )
symbols.add_symbol( str_writer, name.c_str(), value, size, bind, type,
other, section_index );
ASSERT_EQ( symbols.get_symbols_num(), sym_num + 9);
symbols.arrange_local_symbols( [&]( Elf_Xword first, Elf_Xword ) -> void {
static int counter = 0;
EXPECT_EQ( first, ++counter );
@ -788,12 +792,16 @@ TEST( ELFIOTest, rearrange_local_symbols_with_reallocation )
value = 7;
Elf_Word sym7 = symbols.add_symbol( str_writer, name.c_str(), value, size,
bind, type, other, section_index );
auto sym_num = symbols.get_symbols_num();
name = "Str8";
bind = STB_WEAK;
value = 8;
Elf_Word sym8 = symbols.add_symbol( str_writer, name.c_str(), value, size,
bind, type, other, section_index );
ASSERT_EQ( ( symbols.get_symbols_num() ), ( sym_num + 1 ) );
section* rel_sec = writer.sections.add( ".rel.text" );
rel_sec->set_type( SHT_REL );
rel_sec->set_info( text_sec->get_index() );