diff --git a/.vscode/launch.json b/.vscode/launch.json index 48355c0..43cb6b3 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -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" }, { diff --git a/elfio/elfio_symbols.hpp b/elfio/elfio_symbols.hpp index 7a1654c..f84e7c5 100644 --- a/elfio/elfio_symbols.hpp +++ b/elfio/elfio_symbols.hpp @@ -120,10 +120,9 @@ template 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 ) { - ret = true; - } + section_index, other ) && + ( symbol_name == name ) ) { + ret = true; } } } @@ -346,7 +345,7 @@ template 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 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 symbol_section_accessor_template if ( symbol_section->get_entry_size() < sizeof( T ) ) { return nullptr; } - const T* pSym = reinterpret_cast( + const auto* pSym = reinterpret_cast( symbol_section->get_data() + index * symbol_section->get_entry_size() ); @@ -443,7 +443,7 @@ template class symbol_section_accessor_template if ( nullptr != symbol_section->get_data() && index < get_symbols_num() ) { - const T* pSym = reinterpret_cast( + const auto* pSym = reinterpret_cast( symbol_section->get_data() + index * symbol_section->get_entry_size() ); diff --git a/tests/ELFIOTest1.cpp b/tests/ELFIOTest1.cpp index 169a440..b24a5f4 100644 --- a/tests/ELFIOTest1.cpp +++ b/tests/ELFIOTest1.cpp @@ -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() );