|
| 1 | +From 4b10a30d6d02675892fd0220fa1d722d9f342359 Mon Sep 17 00:00:00 2001 |
| 2 | +From: WANG Xuerui <git@xen0n.name> |
| 3 | +Date: Sat, 19 Oct 2024 22:11:52 +0800 |
| 4 | +Subject: [PATCH 01/12] LoongArch: Default to a maximum page size of 64KiB |
| 5 | + |
| 6 | +As per the spec (Section 7.5.10, LoongArch Reference Manual Vol. 1), |
| 7 | +LoongArch machines are not limited in page size choices, and currently |
| 8 | +page sizes of 4KiB, 16KiB and 64KiB are supported by mainline Linux. |
| 9 | +While 16KiB is the most common, the current BFD code says it is the |
| 10 | +maximum; this is not correct, and as an effect, almost all existing |
| 11 | +binaries are incompatible with a 64KiB kernel because the sections are |
| 12 | +not sufficiently aligned, while being totally fine otherwise. |
| 13 | +This is needlessly complicating integration testing [1]. |
| 14 | + |
| 15 | +This patch fixes the inconsistency, and also brings BFD behavior in line |
| 16 | +with that of LLD [2]. |
| 17 | + |
| 18 | +[1] https://github.com/loongson-community/discussions/issues/47 |
| 19 | +[2] https://github.com/llvm/llvm-project/blob/llvmorg-19.1.0/lld/ELF/Arch/LoongArch.cpp#L174-L183 |
| 20 | + |
| 21 | +bfd/ |
| 22 | + * elfnn-loongarch.c (ELF_MAXPAGESIZE): Bump to 64KiB. |
| 23 | + (ELF_MINPAGESIZE): Define as 4KiB. |
| 24 | + (ELF_COMMONPAGESIZE): Define as 16KiB. |
| 25 | + |
| 26 | +ld/ |
| 27 | + * testsuite/ld-loongarch-elf/64_pcrel.d: Update assertions after |
| 28 | + changing the target max page size to 64KiB. |
| 29 | + * testsuite/ld-loongarch-elf/data-got.d: Likewise. |
| 30 | + * testsuite/ld-loongarch-elf/desc-relex.d: Likewise. |
| 31 | + * testsuite/ld-loongarch-elf/relax-align-ignore-start.d: Likewise. |
| 32 | + * testsuite/ld-loongarch-elf/tlsdesc_abs.d: Make the fuzzy match work |
| 33 | + as intended by not checking exact instruction words. |
| 34 | + * testsuite/ld-loongarch-elf/tlsdesc_extreme.d: Likewise. |
| 35 | + |
| 36 | +Signed-off-by: WANG Xuerui <git@xen0n.name> |
| 37 | +--- |
| 38 | + bfd/elfnn-loongarch.c | 4 +++- |
| 39 | + ld/testsuite/ld-loongarch-elf/64_pcrel.d | 2 +- |
| 40 | + ld/testsuite/ld-loongarch-elf/data-got.d | 2 +- |
| 41 | + ld/testsuite/ld-loongarch-elf/desc-relax.d | 2 +- |
| 42 | + .../ld-loongarch-elf/relax-align-ignore-start.d | 2 +- |
| 43 | + ld/testsuite/ld-loongarch-elf/tlsdesc_abs.d | 12 ++++++------ |
| 44 | + ld/testsuite/ld-loongarch-elf/tlsdesc_extreme.d | 8 ++++---- |
| 45 | + 7 files changed, 17 insertions(+), 15 deletions(-) |
| 46 | + |
| 47 | +diff --git a/bfd/elfnn-loongarch.c b/bfd/elfnn-loongarch.c |
| 48 | +index 13216ef9..8dfb5ea1 100644 |
| 49 | +--- a/bfd/elfnn-loongarch.c |
| 50 | ++++ b/bfd/elfnn-loongarch.c |
| 51 | +@@ -6171,7 +6171,9 @@ elf_loongarch64_hash_symbol (struct elf_link_hash_entry *h) |
| 52 | + #define ELF_ARCH bfd_arch_loongarch |
| 53 | + #define ELF_TARGET_ID LARCH_ELF_DATA |
| 54 | + #define ELF_MACHINE_CODE EM_LOONGARCH |
| 55 | +-#define ELF_MAXPAGESIZE 0x4000 |
| 56 | ++#define ELF_MINPAGESIZE 0x1000 |
| 57 | ++#define ELF_MAXPAGESIZE 0x10000 |
| 58 | ++#define ELF_COMMONPAGESIZE 0x4000 |
| 59 | + #define bfd_elfNN_bfd_reloc_type_lookup loongarch_reloc_type_lookup |
| 60 | + #define bfd_elfNN_bfd_link_hash_table_create \ |
| 61 | + loongarch_elf_link_hash_table_create |
| 62 | +diff --git a/ld/testsuite/ld-loongarch-elf/64_pcrel.d b/ld/testsuite/ld-loongarch-elf/64_pcrel.d |
| 63 | +index 2ea063b7..1f4664ea 100644 |
| 64 | +--- a/ld/testsuite/ld-loongarch-elf/64_pcrel.d |
| 65 | ++++ b/ld/testsuite/ld-loongarch-elf/64_pcrel.d |
| 66 | +@@ -1,4 +1,4 @@ |
| 67 | + #... |
| 68 | +-.*0xffffbffc.* |
| 69 | ++.*0xfffefffc.* |
| 70 | + .*0xffffffff.* |
| 71 | + #pass |
| 72 | +diff --git a/ld/testsuite/ld-loongarch-elf/data-got.d b/ld/testsuite/ld-loongarch-elf/data-got.d |
| 73 | +index a754478a..4a26c72d 100644 |
| 74 | +--- a/ld/testsuite/ld-loongarch-elf/data-got.d |
| 75 | ++++ b/ld/testsuite/ld-loongarch-elf/data-got.d |
| 76 | +@@ -8,7 +8,7 @@ |
| 77 | + #skip: loongarch32-*-* |
| 78 | + |
| 79 | + #... |
| 80 | +- GNU_RELRO 0x003c10 0x0000000000007c10 0x0000000000007c10 0x0003f0 0x0003f0 R 0x1 |
| 81 | ++ GNU_RELRO 0x00fc10 0x000000000001fc10 0x000000000001fc10 0x0003f0 0x0003f0 R 0x1 |
| 82 | + #... |
| 83 | + 01 .dynamic .got .got.plt .data |
| 84 | + #... |
| 85 | +diff --git a/ld/testsuite/ld-loongarch-elf/desc-relax.d b/ld/testsuite/ld-loongarch-elf/desc-relax.d |
| 86 | +index c885953c..48f2d1e3 100644 |
| 87 | +--- a/ld/testsuite/ld-loongarch-elf/desc-relax.d |
| 88 | ++++ b/ld/testsuite/ld-loongarch-elf/desc-relax.d |
| 89 | +@@ -9,7 +9,7 @@ |
| 90 | + Disassembly of section .text: |
| 91 | + |
| 92 | + 0+188 <.*>: |
| 93 | +- 188: 18020844 pcaddi \$a0, 4162 |
| 94 | ++ 188: 18080844 pcaddi \$a0, 16450 |
| 95 | + 18c: 28c00081 ld.d \$ra, \$a0, 0 |
| 96 | + 190: 4c000021 jirl \$ra, \$ra, 0 |
| 97 | + 194: 0010888c add.d \$t0, \$a0, \$tp |
| 98 | +diff --git a/ld/testsuite/ld-loongarch-elf/relax-align-ignore-start.d b/ld/testsuite/ld-loongarch-elf/relax-align-ignore-start.d |
| 99 | +index 939cf427..70763ff0 100644 |
| 100 | +--- a/ld/testsuite/ld-loongarch-elf/relax-align-ignore-start.d |
| 101 | ++++ b/ld/testsuite/ld-loongarch-elf/relax-align-ignore-start.d |
| 102 | +@@ -12,5 +12,5 @@ Disassembly of section bbb: |
| 103 | + 0000000120000080 <bbb>: |
| 104 | + [ ]+120000080:[ ]+4c000020[ ]+ret |
| 105 | + Disassembly of section ccc: |
| 106 | +-0000000120000090 <__bss_start-0x4004>: |
| 107 | ++0000000120000090 <__bss_start-0x10004>: |
| 108 | + [ ]+120000090:[ ]+4c000020[ ]+ret |
| 109 | +diff --git a/ld/testsuite/ld-loongarch-elf/tlsdesc_abs.d b/ld/testsuite/ld-loongarch-elf/tlsdesc_abs.d |
| 110 | +index 62f5a2a0..7e23454b 100644 |
| 111 | +--- a/ld/testsuite/ld-loongarch-elf/tlsdesc_abs.d |
| 112 | ++++ b/ld/testsuite/ld-loongarch-elf/tlsdesc_abs.d |
| 113 | +@@ -9,15 +9,15 @@ |
| 114 | + Disassembly of section .text: |
| 115 | + |
| 116 | + 0+120000100 <.*>: |
| 117 | +- 120000100: 14400084 lu12i.w \$a0, .* |
| 118 | +- 120000104: 03850084 ori \$a0, \$a0, .* |
| 119 | +- 120000108: 16000024 lu32i.d \$a0, .* |
| 120 | ++ 120000100: ........ lu12i.w \$a0, .* |
| 121 | ++ 120000104: ........ ori \$a0, \$a0, .* |
| 122 | ++ 120000108: ........ lu32i.d \$a0, .* |
| 123 | + 12000010c: 03000084 lu52i.d \$a0, \$a0, 0 |
| 124 | + 120000110: 28c00081 ld.d \$ra, \$a0, 0 |
| 125 | + 120000114: 4c000021 jirl \$ra, \$ra, 0 |
| 126 | +- 120000118: 14400084 lu12i.w \$a0, .* |
| 127 | +- 12000011c: 03850084 ori \$a0, \$a0, .* |
| 128 | +- 120000120: 16000024 lu32i.d \$a0, .* |
| 129 | ++ 120000118: ........ lu12i.w \$a0, .* |
| 130 | ++ 12000011c: ........ ori \$a0, \$a0, .* |
| 131 | ++ 120000120: ........ lu32i.d \$a0, .* |
| 132 | + 120000124: 03000084 lu52i.d \$a0, \$a0, 0 |
| 133 | + 120000128: 28c00081 ld.d \$ra, \$a0, 0 |
| 134 | + 12000012c: 4c000021 jirl \$ra, \$ra, 0 |
| 135 | +diff --git a/ld/testsuite/ld-loongarch-elf/tlsdesc_extreme.d b/ld/testsuite/ld-loongarch-elf/tlsdesc_extreme.d |
| 136 | +index 55179997..fbc1d945 100644 |
| 137 | +--- a/ld/testsuite/ld-loongarch-elf/tlsdesc_extreme.d |
| 138 | ++++ b/ld/testsuite/ld-loongarch-elf/tlsdesc_extreme.d |
| 139 | +@@ -9,15 +9,15 @@ |
| 140 | + Disassembly of section .text: |
| 141 | + |
| 142 | + 0+120000100 <.*>: |
| 143 | +- 120000100: 1a000084 pcalau12i \$a0, .* |
| 144 | +- 120000104: 02c52001 li.d \$ra, .* |
| 145 | ++ 120000100: ........ pcalau12i \$a0, .* |
| 146 | ++ 120000104: ........ li.d \$ra, .* |
| 147 | + 120000108: 16000001 lu32i.d \$ra, 0 |
| 148 | + 12000010c: 03000021 lu52i.d \$ra, \$ra, 0 |
| 149 | + 120000110: 00108484 add.d \$a0, \$a0, \$ra |
| 150 | + 120000114: 28c00081 ld.d \$ra, \$a0, 0 |
| 151 | + 120000118: 4c000021 jirl \$ra, \$ra, 0 |
| 152 | +- 12000011c: 1a000084 pcalau12i \$a0, .* |
| 153 | +- 120000120: 02c5200d li.d \$t1, .* |
| 154 | ++ 12000011c: ........ pcalau12i \$a0, .* |
| 155 | ++ 120000120: ........ li.d \$t1, .* |
| 156 | + 120000124: 1600000d lu32i.d \$t1, 0 |
| 157 | + 120000128: 030001ad lu52i.d \$t1, \$t1, 0 |
| 158 | + 12000012c: 0010b484 add.d \$a0, \$a0, \$t1 |
| 159 | +-- |
| 160 | +2.47.3 |
| 161 | + |
0 commit comments