Chromium Code Reviews| Index: tools/relocation_packer/src/elf_traits.h |
| diff --git a/tools/relocation_packer/src/elf_traits.h b/tools/relocation_packer/src/elf_traits.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..71a7a0dab720273ea6dbb25ba3f76eac60491ddd |
| --- /dev/null |
| +++ b/tools/relocation_packer/src/elf_traits.h |
| @@ -0,0 +1,102 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +// Target-specific ELF type traits. |
| + |
| +#ifndef TOOLS_RELOCATION_PACKER_SRC_ELF_TRAITS_H_ |
| +#define TOOLS_RELOCATION_PACKER_SRC_ELF_TRAITS_H_ |
| + |
| +#include "elf.h" |
| +#include "libelf.h" |
| + |
| +// The TARGET_ macro controls which Elf types we expect and handle. |
| +// Either TARGET_ARM or TARGET_AARCH must be defined, but not both. |
|
rmcilroy
2014/07/18 14:05:17
TARGET_AARCH64
simonb (inactive)
2014/07/21 12:15:49
Done. Switched to TARGET_ARM and TARGET_ARM64 for
|
| + |
| +#if !defined(TARGET_ARM) && !defined(TARGET_AARCH64) |
| +#error "Unsupported target, define one of TARGET_ARM or TARGET_AARCH64" |
| +#elif defined(TARGET_ARM) && defined(TARGET_AARCH64) |
| +#error "Define one of TARGET_ARM or TARGET_AARCH64, but not both" |
| +#endif |
| + |
| +// ELF is a traits structure used to provide convenient aliases for |
| +// 32/64 bit Elf types and functions, depending on the target specified. |
| + |
| +#if defined(TARGET_ARM) |
| +struct ELF { |
| + typedef Elf32_Addr Addr; |
| + typedef Elf32_Dyn Dyn; |
| + typedef Elf32_Ehdr Ehdr; |
| + typedef Elf32_Off Off; |
| + typedef Elf32_Phdr Phdr; |
| + typedef Elf32_Rel Rel; |
| + typedef Elf32_Shdr Shdr; |
| + typedef Elf32_Sword Sword; |
| + typedef Elf32_Sxword Sxword; |
| + typedef Elf32_Sym Sym; |
| + typedef Elf32_Word Word; |
| + typedef Elf32_Xword Xword; |
| + |
| + static inline Ehdr* getehdr(Elf* elf) { return elf32_getehdr(elf); } |
| + static inline Phdr* getphdr(Elf* elf) { return elf32_getphdr(elf); } |
| + static inline Shdr* getshdr(Elf_Scn* scn) { return elf32_getshdr(scn); } |
| + |
| + enum { kMachine = EM_ARM }; |
| + enum { kFileClass = ELFCLASS32 }; |
| + enum { kArmRelativeRelocationCode = R_ARM_RELATIVE }; |
| + enum { kArmNoRelocationCode = R_ARM_NONE }; |
|
rmcilroy
2014/07/18 14:05:17
Remove "Arm" from both of these variable names, ju
simonb (inactive)
2014/07/21 12:15:49
Done.
|
| + |
| + static inline const char* Machine() { return "ARM"; } |
| + |
| +#define ELF_R_SYM(val) ELF32_R_SYM(val) |
| +#define ELF_R_TYPE(val) ELF32_R_TYPE(val) |
| +#define ELF_R_INFO(sym, type) ELF32_R_INFO(sym, type) |
| +#define ELF_ST_TYPE(val) ELF32_ST_TYPE(val) |
| +}; |
| +#endif // TARGET_ARM |
|
rmcilroy
2014/07/18 14:05:17
#elif defined(TARGET_AARCH64)
simonb (inactive)
2014/07/21 12:15:49
Done.
|
| + |
| +#if defined(TARGET_AARCH64) |
| +struct ELF { |
| + typedef Elf64_Addr Addr; |
| + typedef Elf64_Dyn Dyn; |
| + typedef Elf64_Ehdr Ehdr; |
| + typedef Elf64_Off Off; |
| + typedef Elf64_Phdr Phdr; |
| + typedef Elf64_Rel Rel; |
| + typedef Elf64_Shdr Shdr; |
| + typedef Elf64_Sword Sword; |
| + typedef Elf64_Sxword Sxword; |
| + typedef Elf64_Sym Sym; |
| + typedef Elf64_Word Word; |
| + typedef Elf64_Xword Xword; |
| + |
| + static inline Ehdr* getehdr(Elf* elf) { return elf64_getehdr(elf); } |
| + static inline Phdr* getphdr(Elf* elf) { return elf64_getphdr(elf); } |
| + static inline Shdr* getshdr(Elf_Scn* scn) { return elf64_getshdr(scn); } |
| + |
| +// TODO(simonb): Eliminate these once AARCH64 appears reliably in elf.h. |
| +#ifndef EM_AARCH64 |
| +#define EM_AARCH64 183 |
| +#endif |
| +#ifndef R_AARCH64_RELATIVE |
| +#define R_AARCH64_RELATIVE 1027 |
| +#endif |
| +#ifndef R_AARCH64_NONE |
| +#define R_AARCH64_NONE 0 |
| +#endif |
| + |
| + enum { kMachine = EM_AARCH64 }; |
| + enum { kFileClass = ELFCLASS64 }; |
| + enum { kArmRelativeRelocationCode = R_AARCH64_RELATIVE }; |
| + enum { kArmNoRelocationCode = R_AARCH64_NONE }; |
| + |
| + static inline const char* Machine() { return "AARCH64"; } |
| + |
| +#define ELF_R_SYM(val) ELF64_R_SYM(val) |
| +#define ELF_R_TYPE(val) ELF64_R_TYPE(val) |
| +#define ELF_R_INFO(sym, type) ELF64_R_INFO(sym, type) |
| +#define ELF_ST_TYPE(val) ELF64_ST_TYPE(val) |
| +}; |
| +#endif // TARGET_AARCH64 |
| + |
| +#endif // TOOLS_RELOCATION_PACKER_SRC_ELF_TRAITS_H_ |