diff options
author | Moritz Angermann <moritz.angermann@gmail.com> | 2019-05-16 13:35:31 +0800 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2019-07-02 16:18:05 -0400 |
commit | 826939387be69b100461dd553937dfea729b15ef (patch) | |
tree | 1545082f520c59e5c362b62aa2f0b0ea294d87a3 /rts/linker/Elf.c | |
parent | bd660edeb783a74e5ca3f1f82713b2aeedae19dc (diff) | |
download | haskell-826939387be69b100461dd553937dfea729b15ef.tar.gz |
Add _GLOBAL_OFFSET_TABLE_ support
This adds lookup logic for _GLOBAL_OFFSET_TABLE_ as well as
relocation logic for R_ARM_BASE_PREL and R_ARM_GOT_BREL which
the gnu toolchain (gas, gcc, ...) prefers to produce. Apparently
recent llvm toolchains will produce those as well.
Diffstat (limited to 'rts/linker/Elf.c')
-rw-r--r-- | rts/linker/Elf.c | 33 |
1 files changed, 31 insertions, 2 deletions
diff --git a/rts/linker/Elf.c b/rts/linker/Elf.c index 4378032c3e..7e5386e178 100644 --- a/rts/linker/Elf.c +++ b/rts/linker/Elf.c @@ -1019,6 +1019,19 @@ do_Elf_Rel_relocations ( ObjectCode* oc, char* ehdrC, return 1; } + /* The following nomenclature is used for the operation: + * - S -- (when used on its own) is the address of the symbol. + * - A -- is the addend for the relocation. + * - P -- is the address of the place being relocated (derived from r_offset). + * - Pa - is the adjusted address of the place being relocated, defined as (P & 0xFFFFFFFC). + * - T -- is 1 if the target symbol S has type STT_FUNC and the symbol addresses a Thumb instruction; it is 0 otherwise. + * - B(S) is the addressing origin of the output segment defining the symbol S. The origin is not required to be the + * base address of the segment. This value must always be word-aligned. + * - GOT_ORG is the addressing origin of the Global Offset Table (the indirection table for imported data addresses). + * This value must always be word-aligned. See ยง4.6.1.8, Proxy generating relocations. + * - GOT(S) is the address of the GOT entry for the symbol S. + */ + for (j = 0; j < nent; j++) { Elf_Addr offset = rtab[j].r_offset; Elf_Addr info = rtab[j].r_info; @@ -1113,19 +1126,35 @@ do_Elf_Rel_relocations ( ObjectCode* oc, char* ehdrC, # endif # ifdef arm_HOST_ARCH - case COMPAT_R_ARM_ABS32: + case COMPAT_R_ARM_ABS32: /* (S + A) | T */ // Specified by Linux ARM ABI to be equivalent to ABS32 case COMPAT_R_ARM_TARGET1: *(Elf32_Word *)P += S; *(Elf32_Word *)P |= T; break; - case COMPAT_R_ARM_REL32: + case COMPAT_R_ARM_REL32: /* ((S + A) | T) โ P */ *(Elf32_Word *)P += S; *(Elf32_Word *)P |= T; *(Elf32_Word *)P -= P; break; + case COMPAT_R_ARM_BASE_PREL: /* B(S) + A โ P */ + { + int32_t A = *pP; + // bfd used to encode sb (B(S)) as 0. + *(uint32_t *)P += 0 + A - P; + break; + } + + case COMPAT_R_ARM_GOT_BREL: /* GOT(S) + A โ GOT_ORG */ + { + int32_t A = *pP; + void* GOT_S = symbol->got_addr; + *(uint32_t *)P = (uint32_t) GOT_S + A - (uint32_t) oc->info->got_start; + break; + } + case COMPAT_R_ARM_CALL: case COMPAT_R_ARM_JUMP24: { |