mirror of
https://github.com/QuasarApp/ELFIO.git
synced 2025-05-13 19:39:35 +00:00
arrange_local_symbols() added
ELF standard requires that all STB_LOCAL symbols will go prior others and sh_info entry will contain the number of the local symbols
This commit is contained in:
parent
d2c3fb6a14
commit
8e0b5754e4
1
.gitignore
vendored
1
.gitignore
vendored
@ -44,6 +44,7 @@ tests/elf_examples/write_exe_i386_32_section_added
|
|||||||
tests/elf_examples/ppc-32bit-testcopy*.elf
|
tests/elf_examples/ppc-32bit-testcopy*.elf
|
||||||
tests/elf_examples/null_section_inside_segment*
|
tests/elf_examples/null_section_inside_segment*
|
||||||
tests/elf_examples/segment_containing_no_section*
|
tests/elf_examples/segment_containing_no_section*
|
||||||
|
tests/elf_examples/test_symbols_order.elf
|
||||||
examples/writer/hello_x86_64
|
examples/writer/hello_x86_64
|
||||||
examples/write_obj/hello
|
examples/write_obj/hello
|
||||||
|
|
||||||
|
9
.vscode/launch.json
vendored
9
.vscode/launch.json
vendored
@ -8,10 +8,13 @@
|
|||||||
"name": "Run ELFIO Tests",
|
"name": "Run ELFIO Tests",
|
||||||
"type": "cppdbg",
|
"type": "cppdbg",
|
||||||
"request": "launch",
|
"request": "launch",
|
||||||
"program": "${workspaceFolder}/ELFIOTest/ELFIOTest",
|
"program": "${workspaceFolder}/tests/ELFIOTest",
|
||||||
"args": [],
|
"args": [
|
||||||
|
"-r",
|
||||||
|
"short"
|
||||||
|
],
|
||||||
"stopAtEntry": false,
|
"stopAtEntry": false,
|
||||||
"cwd": "${workspaceFolder}/ELFIOTest",
|
"cwd": "${workspaceFolder}/tests",
|
||||||
"environment": [],
|
"environment": [],
|
||||||
"externalConsole": false,
|
"externalConsole": false,
|
||||||
"MIMode": "gdb",
|
"MIMode": "gdb",
|
||||||
|
9
.vscode/tasks.json
vendored
9
.vscode/tasks.json
vendored
@ -9,12 +9,15 @@
|
|||||||
"CXXFLAGS='-g -O0'"
|
"CXXFLAGS='-g -O0'"
|
||||||
],
|
],
|
||||||
"options": {
|
"options": {
|
||||||
"cwd": "${workspaceRoot}/ELFIOTest",
|
"cwd": "${workspaceRoot}/tests"
|
||||||
},
|
},
|
||||||
"group": {
|
"group": {
|
||||||
"kind": "build",
|
"kind": "build",
|
||||||
"isDefault": true
|
"isDefault": true
|
||||||
}
|
},
|
||||||
|
"problemMatcher": [
|
||||||
|
"$gcc"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"type": "shell",
|
"type": "shell",
|
||||||
@ -25,7 +28,7 @@
|
|||||||
"CXXFLAGS='-g -O0'"
|
"CXXFLAGS='-g -O0'"
|
||||||
],
|
],
|
||||||
"options": {
|
"options": {
|
||||||
"cwd": "${workspaceRoot}",
|
"cwd": "${workspaceRoot}"
|
||||||
},
|
},
|
||||||
"group": {
|
"group": {
|
||||||
"kind": "build",
|
"kind": "build",
|
||||||
|
@ -215,7 +215,23 @@ class symbol_section_accessor_template
|
|||||||
}
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
private:
|
Elf_Xword
|
||||||
|
arrange_local_symbols()
|
||||||
|
{
|
||||||
|
int nRet = 0;
|
||||||
|
|
||||||
|
if (elf_file.get_class() == ELFCLASS32) {
|
||||||
|
nRet = generic_arrange_local_symbols<Elf32_Sym>();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
nRet = generic_arrange_local_symbols<Elf64_Sym>();
|
||||||
|
}
|
||||||
|
|
||||||
|
return nRet;
|
||||||
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
private :
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
void
|
void
|
||||||
find_hash_section()
|
find_hash_section()
|
||||||
@ -345,6 +361,61 @@ class symbol_section_accessor_template
|
|||||||
return nRet;
|
return nRet;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
template <class T>
|
||||||
|
Elf_Xword
|
||||||
|
generic_arrange_local_symbols()
|
||||||
|
{
|
||||||
|
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 current = 0;
|
||||||
|
Elf_Xword count = get_symbols_num();
|
||||||
|
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
T *p1 = nullptr;
|
||||||
|
T *p2 = nullptr;
|
||||||
|
|
||||||
|
while (first_not_local < count)
|
||||||
|
{
|
||||||
|
p1 = const_cast<T *>(generic_get_symbol_ptr<T>(first_not_local));
|
||||||
|
if (ELF_ST_BIND(convertor(p1->st_info)) != STB_LOCAL)
|
||||||
|
break;
|
||||||
|
++first_not_local;
|
||||||
|
}
|
||||||
|
|
||||||
|
current = first_not_local + 1;
|
||||||
|
while (current < count)
|
||||||
|
{
|
||||||
|
p2 = const_cast<T *>(generic_get_symbol_ptr<T>(current));
|
||||||
|
if (ELF_ST_BIND(convertor(p2->st_info)) == STB_LOCAL)
|
||||||
|
break;
|
||||||
|
++current;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (first_not_local < count && current < count)
|
||||||
|
{
|
||||||
|
// Swap the symbols
|
||||||
|
T tmp;
|
||||||
|
memcpy(&tmp, p1, size);
|
||||||
|
memcpy(p1, p2, size);
|
||||||
|
memcpy(p2, &tmp, size);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Update 'info' field of the section
|
||||||
|
symbol_section->set_info(first_not_local);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Elf_Word nRet = symbol_section->get_size() / sizeof(entry) - 1;
|
||||||
|
|
||||||
|
return first_not_local;
|
||||||
|
}
|
||||||
|
|
||||||
//------------------------------------------------------------------------------
|
//------------------------------------------------------------------------------
|
||||||
private:
|
private:
|
||||||
const elfio& elf_file;
|
const elfio& elf_file;
|
||||||
|
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user