Commit 16510cd5 authored by simonb@chromium.org's avatar simonb@chromium.org

crazy_linker: Add support for x86_64.

Add EM_X86_64 and support for x86_64 relocations.

BUG=369133

Review URL: https://codereview.chromium.org/346583004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287591 0039d316-1c4b-4281-b951-d872f2087c98
parent 0f12403a
...@@ -33,3 +33,5 @@ Local Modifications: ...@@ -33,3 +33,5 @@ Local Modifications:
- Fix for crbug/394306 (Chrome crashes during startup ... on Arm64 AAW15) - Fix for crbug/394306 (Chrome crashes during startup ... on Arm64 AAW15)
- Move packed relocation dynamic tags from DT_LOPROC range to DT_LOOS range. - Move packed relocation dynamic tags from DT_LOPROC range to DT_LOOS range.
- Add support for x86_64.
...@@ -66,6 +66,17 @@ ...@@ -66,6 +66,17 @@
#endif // __i386__ #endif // __i386__
#ifdef __x86_64__
/* x86_64 relocations */
#define R_X86_64_64 1
#define R_X86_64_PC32 2
#define R_X86_64_GLOB_DAT 6
#define R_X86_64_JMP_SLOT 7
#define R_X86_64_RELATIVE 8
#endif // __x86_64__
namespace crazy { namespace crazy {
namespace { namespace {
...@@ -122,6 +133,19 @@ RelocationType GetRelocationType(ELF::Word r_type) { ...@@ -122,6 +133,19 @@ RelocationType GetRelocationType(ELF::Word r_type) {
return RELOCATION_TYPE_PC_RELATIVE; return RELOCATION_TYPE_PC_RELATIVE;
#endif #endif
#ifdef __x86_64__
case R_X86_64_JMP_SLOT:
case R_X86_64_GLOB_DAT:
case R_X86_64_64:
return RELOCATION_TYPE_ABSOLUTE;
case R_X86_64_RELATIVE:
return RELOCATION_TYPE_RELATIVE;
case R_X86_64_PC32:
return RELOCATION_TYPE_PC_RELATIVE;
#endif
#ifdef __mips__ #ifdef __mips__
case R_MIPS_REL32: case R_MIPS_REL32:
return RELOCATION_TYPE_RELATIVE; return RELOCATION_TYPE_RELATIVE;
...@@ -473,6 +497,32 @@ bool ElfRelocations::ApplyRelaReloc(const ELF::Rela* rela, ...@@ -473,6 +497,32 @@ bool ElfRelocations::ApplyRelaReloc(const ELF::Rela* rela,
return false; return false;
#endif // __aarch64__ #endif // __aarch64__
#ifdef __x86_64__
case R_X86_64_JMP_SLOT:
*target = sym_addr + addend;
break;
case R_X86_64_GLOB_DAT:
*target = sym_addr + addend;
break;
case R_X86_64_RELATIVE:
if (rela_symbol) {
*error = "Invalid relative relocation with symbol";
return false;
}
*target = load_bias_ + addend;
break;
case R_X86_64_64:
*target = sym_addr + addend;
break;
case R_X86_64_PC32:
*target = sym_addr + (addend - reloc);
break;
#endif // __x86_64__
default: default:
error->Format("Invalid relocation type (%d)", rela_type); error->Format("Invalid relocation type (%d)", rela_type);
return false; return false;
...@@ -815,6 +865,12 @@ void ElfRelocations::AdjustRelocation(ELF::Word rel_type, ...@@ -815,6 +865,12 @@ void ElfRelocations::AdjustRelocation(ELF::Word rel_type,
break; break;
#endif #endif
#ifdef __x86_64__
case R_X86_64_RELATIVE:
*dst_ptr += map_delta;
break;
#endif
#ifdef __mips__ #ifdef __mips__
case R_MIPS_REL32: case R_MIPS_REL32:
*dst_ptr += map_delta; *dst_ptr += map_delta;
......
...@@ -67,6 +67,8 @@ struct ELF { ...@@ -67,6 +67,8 @@ struct ELF {
#define ELF_MACHINE EM_ARM #define ELF_MACHINE EM_ARM
#elif defined(__i386__) #elif defined(__i386__)
#define ELF_MACHINE EM_386 #define ELF_MACHINE EM_386
#elif defined(__x86_64__)
#define ELF_MACHINE EM_X86_64
#elif defined(__mips__) && !defined(__LP64__) // mips64el defines __mips__ too #elif defined(__mips__) && !defined(__LP64__) // mips64el defines __mips__ too
#define ELF_MACHINE EM_MIPS #define ELF_MACHINE EM_MIPS
#elif defined(__aarch64__) #elif defined(__aarch64__)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment