| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| //===- X86_32RelocationFunctions.h---------------------------------------===// | ||
| // Part of the eld Project, under the BSD License | ||
| // See https://github.com/qualcomm/eld/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
| //===----------------------------------------------------------------------===// | ||
| #ifndef ELD_TARGET_X86_32_RELOCATION_FUNCTIONS_H | ||
| #define ELD_TARGET_X86_32_RELOCATION_FUNCTIONS_H | ||
|
|
||
| #include "X86_32Relocator.h" | ||
|
|
||
| namespace eld { | ||
| namespace x86_32 { | ||
|
|
||
| using RelocationHandler = Relocator::Result (*)(Relocation &pReloc, | ||
| X86_32Relocator &pParent); | ||
|
|
||
| // R_386_NONE. | ||
| Relocator::Result none(Relocation &pReloc, X86_32Relocator &pParent); | ||
| // R_386_8, R_386_16, and R_386_32: S + A. | ||
| Relocator::Result relocAbs(Relocation &pReloc, X86_32Relocator &pParent); | ||
| // Any relocation not implemented by the current i386 backend. | ||
| Relocator::Result unsupported(Relocation &pReloc, X86_32Relocator &pParent); | ||
|
|
||
| } // namespace x86_32 | ||
| } // namespace eld | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,59 @@ | ||
| //===- X86_32RelocationInfo.h--------------------------------------------===// | ||
| // Part of the eld Project, under the BSD License | ||
| // See https://github.com/qualcomm/eld/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
| //===----------------------------------------------------------------------===// | ||
| // Basic ELD policy types for i386 ELF32 relocations. | ||
| // | ||
| // The descriptor table is defined in X86_32RelocationTable.h and is indexed by | ||
| // the ELF relocation number. | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef ELD_TARGET_X86_32_RELOCATION_INFO_H | ||
| #define ELD_TARGET_X86_32_RELOCATION_INFO_H | ||
|
|
||
| #include <cstdint> | ||
|
|
||
| namespace eld { | ||
| namespace x86_32 { | ||
|
|
||
| // The width, in bits, of the field an i386 relocation writes into. | ||
| enum class EncodingWidth : uint8_t { None, Bits8, Bits16, Bits32 }; | ||
|
|
||
| // No range check is required for a full-width field. Narrow fields accept | ||
| // values representable as either signed or unsigned. | ||
| enum class RangeCheck { None, SignedOrUnsigned }; | ||
|
|
||
| // Keep the table size tied to LLVM's canonical relocation list. The array may | ||
| // contain holes because ELF relocation values are not required to be dense. | ||
| inline constexpr uint32_t getRelocationTableSize() { | ||
| uint32_t Max = 0; | ||
| #define ELF_RELOC(RelocName, Value) \ | ||
| if (Value > Max) \ | ||
| Max = Value; | ||
| #include "llvm/BinaryFormat/ELFRelocs/i386.def" | ||
| #undef ELF_RELOC | ||
| return Max + 1; | ||
| } | ||
|
|
||
| inline constexpr uint32_t RelocationTableSize = getRelocationTableSize(); | ||
|
|
||
| // Number of bits in the field an i386 relocation writes. | ||
| inline constexpr unsigned getFieldBits(EncodingWidth Width) { | ||
| switch (Width) { | ||
| case EncodingWidth::Bits8: | ||
| return 8; | ||
| case EncodingWidth::Bits16: | ||
| return 16; | ||
| case EncodingWidth::Bits32: | ||
| return 32; | ||
| case EncodingWidth::None: | ||
| return 0; | ||
| } | ||
| return 0; | ||
| } | ||
|
|
||
| } // namespace x86_32 | ||
| } // namespace eld | ||
|
|
||
| #endif |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| //===- X86_32RelocationTable.h--------------------------------------------===// | ||
| // Part of the eld Project, under the BSD License | ||
| // See https://github.com/qualcomm/eld/LICENSE.txt for license information. | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
| //===----------------------------------------------------------------------===// | ||
| // The i386 relocation descriptor table. | ||
| //===----------------------------------------------------------------------===// | ||
|
|
||
| #ifndef ELD_TARGET_X86_32_RELOCATION_TABLE_H | ||
| #define ELD_TARGET_X86_32_RELOCATION_TABLE_H | ||
|
|
||
| #include "X86_32RelocationFunctions.h" | ||
| #include "X86_32RelocationInfo.h" | ||
| #include "llvm/BinaryFormat/ELF.h" | ||
|
|
||
| #include <array> | ||
|
|
||
| namespace eld { | ||
| namespace x86_32 { | ||
|
|
||
| struct RelocationDescriptor { | ||
| const char *Name = nullptr; | ||
| EncodingWidth Width = EncodingWidth::None; | ||
| RangeCheck Range = RangeCheck::None; | ||
| RelocationHandler Handler = &unsupported; | ||
| }; | ||
|
|
||
| // This list contains ELD-specific behavior. Relocation names and numeric | ||
| // values come from LLVM's i386.def and are populated separately below. | ||
| // clang-format off | ||
| #define X86_32_RELOC_OVERRIDES(Add) \ | ||
| Add(llvm::ELF::R_386_NONE, none, EncodingWidth::None, RangeCheck::None) \ | ||
| Add(llvm::ELF::R_386_32, relocAbs, EncodingWidth::Bits32, RangeCheck::None) \ | ||
| Add(llvm::ELF::R_386_16, relocAbs, EncodingWidth::Bits16, \ | ||
| RangeCheck::SignedOrUnsigned) \ | ||
| Add(llvm::ELF::R_386_8, relocAbs, EncodingWidth::Bits8, \ | ||
| RangeCheck::SignedOrUnsigned) | ||
| // clang-format on | ||
|
|
||
| inline constexpr std::array<RelocationDescriptor, RelocationTableSize> | ||
| createRelocationDescriptors() { | ||
| std::array<RelocationDescriptor, RelocationTableSize> Entries{}; | ||
|
|
||
| // LLVM's i386.def is the source of truth for public relocation names and | ||
| // values. Entries not present in that definition remain unnamed and | ||
| // unsupported. | ||
| #define ELF_RELOC(RelocName, Value) Entries[Value].Name = #RelocName; | ||
| #include "llvm/BinaryFormat/ELFRelocs/i386.def" | ||
| #undef ELF_RELOC | ||
|
|
||
| // Add the ELD handler and encoding policy for each supported relocation. | ||
| #define ADD_X86_32_RELOC_OVERRIDE(Type, Function, FieldWidth, RangePolicy) \ | ||
| Entries[Type].Handler = &Function; \ | ||
| Entries[Type].Width = FieldWidth; \ | ||
| Entries[Type].Range = RangePolicy; | ||
| X86_32_RELOC_OVERRIDES(ADD_X86_32_RELOC_OVERRIDE) | ||
| #undef ADD_X86_32_RELOC_OVERRIDE | ||
|
|
||
| return Entries; | ||
| } | ||
|
|
||
| inline constexpr std::array<RelocationDescriptor, RelocationTableSize> Relocs = | ||
| createRelocationDescriptors(); | ||
|
|
||
| #undef X86_32_RELOC_OVERRIDES | ||
|
|
||
| } // namespace x86_32 | ||
| } // namespace eld | ||
|
|
||
| #endif | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| #---AbsoluteRelocation.test------------ i386 ELF32 relocations -------------# | ||
| #BEGIN_COMMENT | ||
| # Verify normal i386 absolute relocations use the addend stored in the target | ||
| # field and write the expected 8-, 16-, and 32-bit values. | ||
| #END_COMMENT | ||
| #START_TEST | ||
| RUN: %clang -c %p/Inputs/absolute.s -o %t.absolute.o | ||
| RUN: %link %linkopts -m elf_i386 -T %p/Inputs/absolute.t %t.absolute.o -o %t.absolute.out | ||
| RUN: %readelf -x .text %t.absolute.out | %filecheck %s --check-prefix=BYTES | ||
| RUN: %readelf -r %t.absolute.out | %filecheck %s --check-prefix=RELOCS | ||
|
|
||
| # target is at address 8. The in-place addends are 1, 2, and 3. | ||
| BYTES: Hex dump of section '.text': | ||
| BYTES-NEXT: 0x00000000 090a000b 0000005a 00 | ||
|
|
||
| RELOCS: R_386_8 | ||
| RELOCS-NEXT: R_386_16 | ||
| RELOCS-NEXT: R_386_32 | ||
| RELOCS-NEXT: R_386_NONE | ||
| #END_TEST |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| .section .text,"ax",@progbits | ||
| .globl _start | ||
| .type _start,@function | ||
| _start: | ||
| .byte 0x01 | ||
| .value 0x0002 | ||
| .long 0x00000003 | ||
| .byte 0x5a | ||
| .reloc 0, R_386_8, target | ||
| .reloc 1, R_386_16, target | ||
| .reloc 3, R_386_32, target | ||
| .reloc 7, R_386_NONE, target | ||
| target: | ||
| .byte 0 | ||
| .size _start, .-_start |
| Back | FazBrowse Home | New Git URL |
Uh oh!
There was an error while loading. Please reload this page.