mirror of
https://github.com/serge1/ELFIO.git
synced 2025-01-16 04:14:39 +00:00
Add a callback to arrange_local_symbols()
This commit is contained in:
parent
9273958309
commit
5a5ba2dc09
@ -216,15 +216,15 @@ class symbol_section_accessor_template
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
Elf_Xword
|
||||
arrange_local_symbols()
|
||||
arrange_local_symbols(std::function<void(Elf_Xword first, Elf_Xword second)> func = nullptr)
|
||||
{
|
||||
int nRet = 0;
|
||||
|
||||
if (elf_file.get_class() == ELFCLASS32) {
|
||||
nRet = generic_arrange_local_symbols<Elf32_Sym>();
|
||||
nRet = generic_arrange_local_symbols<Elf32_Sym>(func);
|
||||
}
|
||||
else {
|
||||
nRet = generic_arrange_local_symbols<Elf64_Sym>();
|
||||
nRet = generic_arrange_local_symbols<Elf64_Sym>(func);
|
||||
}
|
||||
|
||||
return nRet;
|
||||
@ -364,12 +364,12 @@ class symbol_section_accessor_template
|
||||
//------------------------------------------------------------------------------
|
||||
template <class T>
|
||||
Elf_Xword
|
||||
generic_arrange_local_symbols()
|
||||
generic_arrange_local_symbols(std::function<void (Elf_Xword first, Elf_Xword second)> func)
|
||||
{
|
||||
const endianess_convertor &convertor = elf_file.get_convertor();
|
||||
const Elf_Xword size = symbol_section->get_entry_size();
|
||||
|
||||
Elf_Xword first_not_local = 1; // Skip the first entry
|
||||
Elf_Xword first_not_local = 1; // Skip the first entry. It is always NOTYPE
|
||||
Elf_Xword current = 0;
|
||||
Elf_Xword count = get_symbols_num();
|
||||
|
||||
@ -397,6 +397,9 @@ class symbol_section_accessor_template
|
||||
|
||||
if (first_not_local < count && current < count)
|
||||
{
|
||||
if (func)
|
||||
func(first_not_local, current);
|
||||
|
||||
// Swap the symbols
|
||||
T tmp;
|
||||
memcpy(&tmp, p1, size);
|
||||
|
@ -650,7 +650,23 @@ BOOST_AUTO_TEST_CASE(rearrange_local_symbols)
|
||||
value = 8;
|
||||
symbols.add_symbol(str_writer, name.c_str(), value, size, bind, type, other, section_index);
|
||||
|
||||
symbols.arrange_local_symbols();
|
||||
symbols.arrange_local_symbols([symbols](Elf_Xword first, Elf_Xword second) -> void {
|
||||
static int counter = 0;
|
||||
BOOST_CHECK_EQUAL(first, ++counter);
|
||||
// std::string name = "";
|
||||
// ELFIO::Elf64_Addr value = 0;
|
||||
// ELFIO::Elf_Xword size = 0;
|
||||
// unsigned char bind = STB_LOCAL;
|
||||
// unsigned char type = STT_FUNC;
|
||||
// ELFIO::Elf_Half section_index = 0;
|
||||
// unsigned char other = 0;
|
||||
|
||||
// std::cout << first << " " << second << std::endl;
|
||||
// symbols.get_symbol(first, name, value, size, bind, type, section_index, other);
|
||||
// std::cout << " " << name;
|
||||
// symbols.get_symbol(second, name, value, size, bind, type, section_index, other);
|
||||
// std::cout << " " << name << std::endl;
|
||||
});
|
||||
|
||||
BOOST_REQUIRE_EQUAL(writer.save(file_name), true);
|
||||
|
||||
@ -675,6 +691,7 @@ BOOST_AUTO_TEST_CASE(rearrange_local_symbols)
|
||||
rsymbols.get_symbol(i, name, value, size, bind, type, section_index, other);
|
||||
BOOST_CHECK_EQUAL(bind, (unsigned char)STB_LOCAL);
|
||||
}
|
||||
BOOST_CHECK_EQUAL(name, "Str7");
|
||||
|
||||
// Check that all symbols are not LOCAL after the bound value
|
||||
for (Elf_Word i = bound; i < num; i++)
|
||||
@ -683,4 +700,5 @@ BOOST_AUTO_TEST_CASE(rearrange_local_symbols)
|
||||
|
||||
BOOST_CHECK_NE(bind, (unsigned char)STB_LOCAL);
|
||||
}
|
||||
BOOST_CHECK_EQUAL(name, "Str8");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user