From 591b2536d8d5cd8dbb2c2507e6225e990b500681 Mon Sep 17 00:00:00 2001 From: Philip Craig Date: Wed, 18 Oct 2023 16:18:05 +1000 Subject: [PATCH] macho: relocations --- macho/reloc-aarch64.o | Bin 0 -> 712 bytes macho/reloc-aarch64.s | 35 ++++++++++++++++++++++++++++++++++ macho/reloc-arm.o | Bin 0 -> 620 bytes macho/reloc-arm.s | 43 ++++++++++++++++++++++++++++++++++++++++++ macho/reloc-i386.o | Bin 0 -> 512 bytes macho/reloc-i386.s | 27 ++++++++++++++++++++++++++ macho/reloc-x86_64.o | Bin 0 -> 648 bytes macho/reloc-x86_64.s | 34 +++++++++++++++++++++++++++++++++ macho/reloc.sh | 5 +++++ 9 files changed, 144 insertions(+) create mode 100644 macho/reloc-aarch64.o create mode 100644 macho/reloc-aarch64.s create mode 100644 macho/reloc-arm.o create mode 100644 macho/reloc-arm.s create mode 100644 macho/reloc-i386.o create mode 100644 macho/reloc-i386.s create mode 100644 macho/reloc-x86_64.o create mode 100644 macho/reloc-x86_64.s create mode 100755 macho/reloc.sh diff --git a/macho/reloc-aarch64.o b/macho/reloc-aarch64.o new file mode 100644 index 0000000000000000000000000000000000000000..f4acf1f3838b22dad7b5d709da30647c3fea419a GIT binary patch literal 712 zcmX^A>+L@t1_nk31_;5-z`zgy;wgYc7#JiO7#Lnam{>^%p9mU7-m4-r@#bp7eXb31#+hZ0|P?@69WS)0|UbfCI$wOUT#o$K$I|m!Ulvv zTo4V?17eeir!X)ufbawc28W#t3=CLl5vZZ)G)VZ#|NsA07#KkAnFDeoGXq1f41}Kp z@&hviLo7(22m`|s5Y5cM;3L4mzyRWdXl4cmTONpd9}Wm@%L0`L(aa1Cx*&T%G}PQ$ zs5x~Y{VWU&G9a3nfq@64pM`-z4n#9EFz`Y3@d+|8Fz`Xc93%!x3w%rr46t|sNg?ya oq3I8#7KA}@4pIYRgE1t&b4qdx3>o6n4H-Zz1BUo?1F$Ru03LZS(EtDd literal 0 HcmV?d00001 diff --git a/macho/reloc-aarch64.s b/macho/reloc-aarch64.s new file mode 100644 index 0000000..9852a1c --- /dev/null +++ b/macho/reloc-aarch64.s @@ -0,0 +1,35 @@ + .subsections_via_symbols + .text + // ARM64_RELOC_BRANCH26 + bl _g0 + // ARM64_RELOC_ADDEND, ARM64_RELOC_BRANCH26 + bl _g0 + 20 + // ARM64_RELOC_PAGE21 + adrp x0, _g0@PAGE + // ARM64_RELOC_PAGEOFF12 + ldr w0, [x0, _g0@PAGEOFF] + // ARM64_RELOC_ADDEND, ARM64_RELOC_PAGE21 + adrp x0, _g0@PAGE + 20 + // ARM64_RELOC_ADDEND, ARM64_RELOC_PAGEOFF12 + ldr w0, [x0, _g0@PAGEOFF + 20] + // ARM64_RELOC_GOT_LOAD_PAGE21 + adrp x0, _g0@GOTPAGE + // ARM64_RELOC_GOT_LOAD_PAGEOFF12 + ldr w0, [x0, _g0@GOTPAGEOFF] + // ARM64_RELOC_TLVP_LOAD_PAGE21 + adrp x0, _g0@TLVPPAGE + // ARM64_RELOC_TLVP_LOAD_PAGEOFF12 + ldr w0, [x0, _g0@TLVPPAGEOFF] + + .data +_data: + // ARM64_RELOC_UNSIGNED + .quad _g0 + 20 + // ARM64_RELOC_SUBTRACTOR, ARM64_RELOC_UNSIGNED, length=3 + .quad _g0 - _g1 + 20 + // ARM64_RELOC_SUBTRACTOR, ARM64_RELOC_UNSIGNED, length=2 + .long _g0 - _g1 + 20 + // ARM64_RELOC_POINTER_TO_GOT, pcrel=0, length=3 + .quad _g0@GOT + // ARM64_RELOC_POINTER_TO_GOT, pcrel=1, length=2 + .long _g0@GOT - . diff --git a/macho/reloc-arm.o b/macho/reloc-arm.o new file mode 100644 index 0000000000000000000000000000000000000000..cdd7af4438857a9f49b0d5801ab11e8c5a837e2d GIT binary patch literal 620 zcmX^2>+L@t1_lOB1_lO31_lOZ1_lNV5JLgNKfr(;*f20KxG*v>fM|9G1_lsjf+~%V zFG;N^fpQoa7~ckQ@wy%$5N8hlzoKg@J(~f{B3vq=%bbBLhP!h|SEvkShRD*9GGL z|NmbI6o{E?0vrqsPeF1Ze={*K#Dc_`85m*(7#J3T#2FYE7J|fh(D)n-3=2T= zAbpIGU<0KI9#Hz=g9Z+W0BbE4=|&9k>4psP=>{M% E0E@9gsQ>@~ literal 0 HcmV?d00001 diff --git a/macho/reloc-arm.s b/macho/reloc-arm.s new file mode 100644 index 0000000..5f1ccca --- /dev/null +++ b/macho/reloc-arm.s @@ -0,0 +1,43 @@ + .subsections_via_symbols + .text + .arm +_g1: + // ARM_RELOC_BR24, extern=1 + bl _g0 + 20 + // ARM_RELOC_BR24, extern=0 + bl _g2 + // ARM_RELOC_BR24, scattered + bl _g2 + 20 + // ARM_RELOC_HALF, length=0 + movw r0, :lower16:(_g0 + 20) + // ARM_RELOC_HALF, length=1 + movt r0, :upper16:(_g0 + 20) + + .p2align 2 + .globl _g2 + .thumb +_g2: +_g3: + // ARM_THUMB_RELOC_BR22, extern=1 + bl _g0 + 20 + // ARM_THUMB_RELOC_BR22, extern=0 + bl _g2 + // ARM_THUMB_RELOC_BR22, scattered + bl _g2 + 20 + // ARM_RELOC_HALF, length=2 + movw r0, :lower16:(_g0 + 20) + // ARM_RELOC_HALF, length=3 + movt r0, :upper16:(_g0 + 20) + + .data + // ARM_RELOC_VANILLA, extern=1 + .long _g0 + 20 + // ARM_RELOC_VANILLA, extern=0 + .long _g2 + // ARM_RELOC_VANILLA, scattered + .long _g2 + 20 + // ARM_RELOC_SECTDIFF, ARM_RELOC_PAIR + .long _g2 - _g1 + 20 + // ARM_RELOC_SECTDIFF, ARM_RELOC_PAIR + // TODO: should be ARM_RELOC_LOCAL_SECTDIFF, ARM_RELOC_PAIR? + .long _g3 - _g1 + 20 diff --git a/macho/reloc-i386.o b/macho/reloc-i386.o new file mode 100644 index 0000000000000000000000000000000000000000..67b2e2c29356db62c02cfc6ee2988971db754866 GIT binary patch literal 512 zcmX^2>+L^w1_lOZ1_lO3D6IivC_wlJ7_b9X1_lNfMg|5D4bl(7Oi-oq@g=DhB~T6n z14Dd#h-*X$f)8Q|LiL06Mo#ly+Kz`zGG1R8fBHb@;S0|Ns;BLf47%?p(S YnadELZp;v$Zp09uZpaXyZU7Pk0PndVZU6uP literal 0 HcmV?d00001 diff --git a/macho/reloc-i386.s b/macho/reloc-i386.s new file mode 100644 index 0000000..dac35f2 --- /dev/null +++ b/macho/reloc-i386.s @@ -0,0 +1,27 @@ + .subsections_via_symbols + .text +_g1: + // GENERIC_RELOC_VANILLA, pcrel=1, extern=1 + call _g0 + 20 + // GENERIC_RELOC_VANILLA, pcrel=1, extern=0 + call _g2 + // GENERIC_RELOC_VANILLA, pcrel=1, scattered + call _g2 + 20 + + .p2align 2 + .globl _g2 +_g2: +_g3: + ret + + .data + // GENERIC_RELOC_VANILLA, pcrel=0, extern=1 + .long _g0 + 20 + // GENERIC_RELOC_VANILLA, pcrel=0, extern=0 + .long _g2 + // GENERIC_RELOC_VANILLA, pcrel=0, scattered + .long _g2 + 20 + // GENERIC_RELOC_SECTDIFF, GENERIC_RELOC_PAIR + .long _g2 - _g1 + 20 + // GENERIC_RELOC_LOCAL_SECTDIFF, GENERIC_RELOC_PAIR + .long _g3 - _g1 + 20 diff --git a/macho/reloc-x86_64.o b/macho/reloc-x86_64.o new file mode 100644 index 0000000000000000000000000000000000000000..7f7e750097c4644ad52a6021dabdb7d27b06d207 GIT binary patch literal 648 zcmX^A>+L^w1_nlE1_lO31_lNY9ROl5K!79z1H%gl6Dyew6)k}3f$`ZH7#Kj92`V2S zUy@o;0_89;FvQ1)xJHB^_%K#5lmRpE0V4wgH%N?yp#em}aD049Vo4&52QtsaF~kwU zhnXV*6*>%cp9K>G0}E6PnF6^Jq&9+yfdRy>U}9hpV1U>i096PQ2VoEwMuXU-;1?nc z3=G|@Ao3XN|NsC03#A=r{rCU>e-okOtbhLh|6dViB6N&Zoq>S?BqPVbzyOi~sRzk; zbhCnN`)>*&p&XDLh?@=~7#J8}d@$D^Oft;%fY8295Zcz90qoCKeF$9&vXF^^AypP4 z-zy5CYk47bE+{S;7#L(h!N|zKpbH8cMh1pB5Y52Az{deGhYg~ffe++NK9FLl0Eh|V UgT%o?@##hk@#%(OHUk3#09j);sQ>@~ literal 0 HcmV?d00001 diff --git a/macho/reloc-x86_64.s b/macho/reloc-x86_64.s new file mode 100644 index 0000000..3e22303 --- /dev/null +++ b/macho/reloc-x86_64.s @@ -0,0 +1,34 @@ + .text +_g1: + // X86_64_RELOC_BRANCH + call _g2 + 20 +_g2: + // X86_64_RELOC_SIGNED + movl _g1 + 20(%rip), %eax + // X86_64_RELOC_SIGNED_1, extern=1 + movb $0x12, _g1(%rip) + // X86_64_RELOC_SIGNED_2, extern=1 + movw $0x1234, _g1(%rip) + // X86_64_RELOC_SIGNED_4, extern=1 + movl $0x12345678, _g1(%rip) + // X86_64_RELOC_SIGNED_1, extern=0 + movb $0x12, L1(%rip) + // X86_64_RELOC_SIGNED_2, extern=0 + movw $0x1234, L1(%rip) + // X86_64_RELOC_SIGNED_4, extern=0 + movl $0x12345678, L1(%rip) + // X86_64_RELOC_GOT_LOAD + movq _g1@GOTPCREL(%rip), %rax + // X86_64_RELOC_GOT + pushq _g1@GOTPCREL(%rip) + // X86_64_RELOC_TLV + movq _g1@TLVP(%rip), %rax + + .data +L1: + // X86_64_RELOC_UNSIGNED, extern=1 + .quad _g1 + 20 + // X86_64_RELOC_UNSIGNED, extern=0 + .quad L1 + 20 + // X86_64_RELOC_UNSIGNED, X86_64_RELOC_SUBTRACTOR + .quad _g1 - _g2 + 20 diff --git a/macho/reloc.sh b/macho/reloc.sh new file mode 100755 index 0000000..eb19385 --- /dev/null +++ b/macho/reloc.sh @@ -0,0 +1,5 @@ +#!/bin/sh +llvm-mc-16 -n -triple i386-apple-darwin reloc-i386.s -filetype=obj -o reloc-i386.o +llvm-mc-16 -n -triple x86_64-apple-darwin reloc-x86_64.s -filetype=obj -o reloc-x86_64.o +llvm-mc-16 -n -triple thumbv7-apple-darwin reloc-arm.s -filetype=obj -o reloc-arm.o +llvm-mc-16 -n -triple arm64-apple-darwin reloc-aarch64.s -filetype=obj -o reloc-aarch64.o