mirror of
https://github.com/ptitSeb/box64.git
synced 2025-05-08 07:59:18 +08:00
Added support for R_X86_64_IRELATIVE reloc, along with a test for it (for #303)
This commit is contained in:
parent
48b881f491
commit
672a41a79c
@ -736,7 +736,12 @@ add_test(backtrace ${CMAKE_COMMAND} -D TEST_PROGRAM=${CMAKE_BINARY_DIR}/${BOX64}
|
||||
-D TEST_REFERENCE=${CMAKE_SOURCE_DIR}/tests/ref19.txt
|
||||
-P ${CMAKE_SOURCE_DIR}/runTest.cmake )
|
||||
|
||||
file(GLOB extension_tests "${CMAKE_SOURCE_DIR}/tests/extensions/*.c")
|
||||
add_test(irelative_reloc ${CMAKE_COMMAND} -D TEST_PROGRAM=${CMAKE_BINARY_DIR}/${BOX64}
|
||||
-D TEST_ARGS=${CMAKE_SOURCE_DIR}/tests/test20 -D TEST_OUTPUT=tmpfile20.txt
|
||||
-D TEST_REFERENCE=${CMAKE_SOURCE_DIR}/tests/ref20.txt
|
||||
-P ${CMAKE_SOURCE_DIR}/runTest.cmake )
|
||||
|
||||
file(GLOB extension_tests "${CMAKE_SOURCE_DIR}/tests/extensions/*.c")
|
||||
foreach(file ${extension_tests})
|
||||
get_filename_component(testname "${file}" NAME_WE)
|
||||
add_test(NAME "${testname}" COMMAND ${CMAKE_COMMAND} -D TEST_PROGRAM=${CMAKE_BINARY_DIR}/${BOX64}
|
||||
|
@ -620,6 +620,14 @@ int RelocateElfRELA(lib_t *maplib, lib_t *local_maplib, int bindnow, elfheader_t
|
||||
printf_dump(LOG_NEVER, "Apply %s R_X86_64_RELATIVE @%p (%p -> %p)\n", (bind==STB_LOCAL)?"Local":"Global", p, *(void**)p, (void*)(head->delta+ rela[i].r_addend));
|
||||
*p = head->delta+ rela[i].r_addend;
|
||||
break;
|
||||
case R_X86_64_IRELATIVE:
|
||||
{
|
||||
x64emu_t* emu = thread_get_emu();
|
||||
EmuCall(emu, head->delta+rela[i].r_addend);
|
||||
printf_dump(LOG_NEVER, "Apply %s R_X86_64_IRELATIVE @%p (%p -> %p()=%p)\n", (bind==STB_LOCAL)?"Local":"Global", p, *(void**)p, (void*)(head->delta+ rela[i].r_addend), (void*)(R_RAX));
|
||||
*p = R_RAX;
|
||||
}
|
||||
break;
|
||||
case R_X86_64_COPY:
|
||||
globoffs = offs;
|
||||
globend = end;
|
||||
|
2
tests/ref20.txt
Normal file
2
tests/ref20.txt
Normal file
@ -0,0 +1,2 @@
|
||||
|
||||
Called function number 2
|
BIN
tests/test20
Executable file
BIN
tests/test20
Executable file
Binary file not shown.
21
tests/test20.c
Normal file
21
tests/test20.c
Normal file
@ -0,0 +1,21 @@
|
||||
#include <stdio.h>
|
||||
int myfunc1() { return 1; }
|
||||
int myfunc2() { return 2; }
|
||||
|
||||
// Prototype for the common entry point
|
||||
/*extern "C" */int myfunc();
|
||||
__asm__ (".type myfunc, @gnu_indirect_function");
|
||||
// Make the dispatcher function. This returns a pointer to the desired function version
|
||||
typeof(myfunc) * myfunc_dispatch (void) __asm__ ("myfunc");
|
||||
typeof(myfunc) * myfunc_dispatch (void) {
|
||||
if (0)
|
||||
return &myfunc1;
|
||||
else
|
||||
return &myfunc2;
|
||||
}
|
||||
|
||||
int main() {
|
||||
printf("\nCalled function number %i\n", myfunc());
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user