diff options
| author | Otavio Salvador <otavio@ossystems.com.br> | 2023-01-09 08:28:43 -0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-01-09 08:28:43 -0300 |
| commit | 10c960f0eaa5fb774a676707c5148e29a6ae09b3 (patch) | |
| tree | 135751a7aa3a8f6d41033519c9800bce66c70c80 /recipes-security/optee-imx/optee-os/0001-core-Define-section-attributes-for-clang.patch | |
| parent | 162bb95bd59ece43d4883551f4a839f59a08db34 (diff) | |
| parent | 39470ba479f5f5a658bec286571b2fba43b0ed04 (diff) | |
| download | meta-freescale-10c960f0eaa5fb774a676707c5148e29a6ae09b3.tar.gz | |
Merge pull request #1373 from YoeDistro/yoe/mut
optee-os: Fix build with clang
Diffstat (limited to 'recipes-security/optee-imx/optee-os/0001-core-Define-section-attributes-for-clang.patch')
| -rw-r--r-- | recipes-security/optee-imx/optee-os/0001-core-Define-section-attributes-for-clang.patch | 230 |
1 files changed, 230 insertions, 0 deletions
diff --git a/recipes-security/optee-imx/optee-os/0001-core-Define-section-attributes-for-clang.patch b/recipes-security/optee-imx/optee-os/0001-core-Define-section-attributes-for-clang.patch new file mode 100644 index 000000000..2abd78a82 --- /dev/null +++ b/recipes-security/optee-imx/optee-os/0001-core-Define-section-attributes-for-clang.patch | |||
| @@ -0,0 +1,230 @@ | |||
| 1 | From f189457b79989543f65b8a4e8729eff2cdf9a758 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Khem Raj <raj.khem@gmail.com> | ||
| 3 | Date: Sat, 13 Aug 2022 19:24:55 -0700 | ||
| 4 | Subject: [PATCH] core: Define section attributes for clang | ||
| 5 | |||
| 6 | Clang's attribute section is not same as gcc, here we need to add flags | ||
| 7 | to sections so they can be eventually collected by linker into final | ||
| 8 | output segments. Only way to do so with clang is to use | ||
| 9 | |||
| 10 | pragma clang section ... | ||
| 11 | |||
| 12 | The behavious is described here [1], this allows us to define names bss | ||
| 13 | sections. This was not an issue until clang-15 where LLD linker starts | ||
| 14 | to detect the section flags before merging them and throws the following | ||
| 15 | errors | ||
| 16 | |||
| 17 | | ld.lld: error: section type mismatch for .nozi.kdata_page | ||
| 18 | | >>> /mnt/b/yoe/master/build/tmp/work/qemuarm64-yoe-linux/optee-os-tadevkit/3.17.0-r0/build/core/arch/arm/kernel/thread.o:(.nozi.kdata_page): SHT_PROGBITS | ||
| 19 | | >>> output section .nozi: SHT_NOBITS | ||
| 20 | | | ||
| 21 | | ld.lld: error: section type mismatch for .nozi.mmu.l2 | ||
| 22 | | >>> /mnt/b/yoe/master/build/tmp/work/qemuarm64-yoe-linux/optee-os-tadevkit/3.17.0-r0/build/core/arch/arm/mm/core_mmu_lpae.o:(.nozi.mmu.l2): SHT_PROGBITS | ||
| 23 | | >>> output section .nozi: SHT_NOBITS | ||
| 24 | |||
| 25 | These sections should be carrying SHT_NOBITS but so far it was not | ||
| 26 | possible to do so, this patch tries to use clangs pragma to get this | ||
| 27 | going and match the functionality with gcc. | ||
| 28 | |||
| 29 | [1] https://intel.github.io/llvm-docs/clang/LanguageExtensions.html#specifying-section-names-for-global-objects-pragma-clang-section | ||
| 30 | |||
| 31 | Upstream-Status: Pending | ||
| 32 | Signed-off-by: Khem Raj <raj.khem@gmail.com> | ||
| 33 | --- | ||
| 34 | core/arch/arm/kernel/thread.c | 19 +++++++++++++++-- | ||
| 35 | core/arch/arm/mm/core_mmu_lpae.c | 35 ++++++++++++++++++++++++++++---- | ||
| 36 | core/arch/arm/mm/pgt_cache.c | 12 ++++++++++- | ||
| 37 | core/kernel/thread.c | 13 +++++++++++- | ||
| 38 | 4 files changed, 71 insertions(+), 8 deletions(-) | ||
| 39 | |||
| 40 | --- a/core/arch/arm/kernel/thread.c | ||
| 41 | +++ b/core/arch/arm/kernel/thread.c | ||
| 42 | @@ -44,16 +44,31 @@ static size_t thread_user_kcode_size __n | ||
| 43 | #if defined(CFG_CORE_UNMAP_CORE_AT_EL0) && \ | ||
| 44 | defined(CFG_CORE_WORKAROUND_SPECTRE_BP_SEC) && defined(ARM64) | ||
| 45 | long thread_user_kdata_sp_offset __nex_bss; | ||
| 46 | +#ifdef __clang__ | ||
| 47 | +#ifndef CFG_VIRTUALIZATION | ||
| 48 | +#pragma clang section bss=".nozi.kdata_page" | ||
| 49 | +#else | ||
| 50 | +#pragma clang section bss=".nex_nozi.kdata_page" | ||
| 51 | +#endif | ||
| 52 | +#endif | ||
| 53 | static uint8_t thread_user_kdata_page[ | ||
| 54 | ROUNDUP(sizeof(struct thread_core_local) * CFG_TEE_CORE_NB_CORE, | ||
| 55 | SMALL_PAGE_SIZE)] | ||
| 56 | __aligned(SMALL_PAGE_SIZE) | ||
| 57 | +#ifndef __clang__ | ||
| 58 | #ifndef CFG_VIRTUALIZATION | ||
| 59 | - __section(".nozi.kdata_page"); | ||
| 60 | + __section(".nozi.kdata_page") | ||
| 61 | #else | ||
| 62 | - __section(".nex_nozi.kdata_page"); | ||
| 63 | + __section(".nex_nozi.kdata_page") | ||
| 64 | #endif | ||
| 65 | #endif | ||
| 66 | + ; | ||
| 67 | +#endif | ||
| 68 | + | ||
| 69 | +/* reset BSS section to default ( .bss ) */ | ||
| 70 | +#ifdef __clang__ | ||
| 71 | +#pragma clang section bss="" | ||
| 72 | +#endif | ||
| 73 | |||
| 74 | #ifdef ARM32 | ||
| 75 | uint32_t __nostackcheck thread_get_exceptions(void) | ||
| 76 | --- a/core/arch/arm/mm/core_mmu_lpae.c | ||
| 77 | +++ b/core/arch/arm/mm/core_mmu_lpae.c | ||
| 78 | @@ -233,19 +233,46 @@ typedef uint16_t l1_idx_t; | ||
| 79 | typedef uint64_t base_xlat_tbls_t[CFG_TEE_CORE_NB_CORE][NUM_BASE_LEVEL_ENTRIES]; | ||
| 80 | typedef uint64_t xlat_tbl_t[XLAT_TABLE_ENTRIES]; | ||
| 81 | |||
| 82 | +#ifdef __clang__ | ||
| 83 | +#pragma clang section bss=".nozi.mmu.base_table" | ||
| 84 | +#endif | ||
| 85 | static base_xlat_tbls_t base_xlation_table[NUM_BASE_TABLES] | ||
| 86 | __aligned(NUM_BASE_LEVEL_ENTRIES * XLAT_ENTRY_SIZE) | ||
| 87 | - __section(".nozi.mmu.base_table"); | ||
| 88 | +#ifndef __clang__ | ||
| 89 | + __section(".nozi.mmu.base_table") | ||
| 90 | +#endif | ||
| 91 | +; | ||
| 92 | +#ifdef __clang__ | ||
| 93 | +#pragma clang section bss="" | ||
| 94 | +#endif | ||
| 95 | |||
| 96 | +#ifdef __clang__ | ||
| 97 | +#pragma clang section bss=".nozi.mmu.l2" | ||
| 98 | +#endif | ||
| 99 | static xlat_tbl_t xlat_tables[MAX_XLAT_TABLES] | ||
| 100 | - __aligned(XLAT_TABLE_SIZE) __section(".nozi.mmu.l2"); | ||
| 101 | + __aligned(XLAT_TABLE_SIZE) | ||
| 102 | +#ifndef __clang__ | ||
| 103 | + __section(".nozi.mmu.l2") | ||
| 104 | +#endif | ||
| 105 | +; | ||
| 106 | +#ifdef __clang__ | ||
| 107 | +#pragma clang section bss="" | ||
| 108 | +#endif | ||
| 109 | |||
| 110 | #define XLAT_TABLES_SIZE (sizeof(xlat_tbl_t) * MAX_XLAT_TABLES) | ||
| 111 | |||
| 112 | +#ifdef __clang__ | ||
| 113 | +#pragma clang section bss=".nozi.mmu.l2" | ||
| 114 | +#endif | ||
| 115 | /* MMU L2 table for TAs, one for each thread */ | ||
| 116 | static xlat_tbl_t xlat_tables_ul1[CFG_NUM_THREADS] | ||
| 117 | - __aligned(XLAT_TABLE_SIZE) __section(".nozi.mmu.l2"); | ||
| 118 | - | ||
| 119 | +#ifndef __clang__ | ||
| 120 | + __aligned(XLAT_TABLE_SIZE) __section(".nozi.mmu.l2") | ||
| 121 | +#endif | ||
| 122 | +; | ||
| 123 | +#ifdef __clang__ | ||
| 124 | +#pragma clang section bss="" | ||
| 125 | +#endif | ||
| 126 | /* | ||
| 127 | * TAs page table entry inside a level 1 page table. | ||
| 128 | * | ||
| 129 | --- a/core/arch/arm/mm/pgt_cache.c | ||
| 130 | +++ b/core/arch/arm/mm/pgt_cache.c | ||
| 131 | @@ -410,8 +410,18 @@ void pgt_init(void) | ||
| 132 | * has a large alignment, while .bss has a small alignment. The current | ||
| 133 | * link script is optimized for small alignment in .bss | ||
| 134 | */ | ||
| 135 | +#ifdef __clang__ | ||
| 136 | +#pragma clang section bss=".nozi.mmu.l2" | ||
| 137 | +#endif | ||
| 138 | static uint8_t pgt_tables[PGT_CACHE_SIZE][PGT_SIZE] | ||
| 139 | - __aligned(PGT_SIZE) __section(".nozi.pgt_cache"); | ||
| 140 | + __aligned(PGT_SIZE) | ||
| 141 | +#ifndef __clang__ | ||
| 142 | + __section(".nozi.pgt_cache") | ||
| 143 | +#endif | ||
| 144 | + ; | ||
| 145 | +#ifdef __clang__ | ||
| 146 | +#pragma clang section bss="" | ||
| 147 | +#endif | ||
| 148 | size_t n; | ||
| 149 | |||
| 150 | for (n = 0; n < ARRAY_SIZE(pgt_tables); n++) { | ||
| 151 | --- a/core/kernel/thread.c | ||
| 152 | +++ b/core/kernel/thread.c | ||
| 153 | @@ -38,13 +38,24 @@ struct thread_core_local thread_core_loc | ||
| 154 | name[stack_num][sizeof(name[stack_num]) / sizeof(uint32_t) - 1] | ||
| 155 | #endif | ||
| 156 | |||
| 157 | +#define DO_PRAGMA(x) _Pragma (#x) | ||
| 158 | + | ||
| 159 | +#ifdef __clang__ | ||
| 160 | +#define DECLARE_STACK(name, num_stacks, stack_size, linkage) \ | ||
| 161 | +DO_PRAGMA (clang section bss=".nozi_stack." #name) \ | ||
| 162 | +linkage uint32_t name[num_stacks] \ | ||
| 163 | + [ROUNDUP(stack_size + STACK_CANARY_SIZE + STACK_CHECK_EXTRA, \ | ||
| 164 | + STACK_ALIGNMENT) / sizeof(uint32_t)] \ | ||
| 165 | + __attribute__((aligned(STACK_ALIGNMENT))); \ | ||
| 166 | +DO_PRAGMA(clang section bss="") | ||
| 167 | +#else | ||
| 168 | #define DECLARE_STACK(name, num_stacks, stack_size, linkage) \ | ||
| 169 | linkage uint32_t name[num_stacks] \ | ||
| 170 | [ROUNDUP(stack_size + STACK_CANARY_SIZE + STACK_CHECK_EXTRA, \ | ||
| 171 | STACK_ALIGNMENT) / sizeof(uint32_t)] \ | ||
| 172 | __attribute__((section(".nozi_stack." # name), \ | ||
| 173 | aligned(STACK_ALIGNMENT))) | ||
| 174 | - | ||
| 175 | +#endif | ||
| 176 | #define GET_STACK(stack) ((vaddr_t)(stack) + STACK_SIZE(stack)) | ||
| 177 | |||
| 178 | DECLARE_STACK(stack_tmp, CFG_TEE_CORE_NB_CORE, STACK_TMP_SIZE, | ||
| 179 | --- a/core/arch/arm/mm/core_mmu_v7.c | ||
| 180 | +++ b/core/arch/arm/mm/core_mmu_v7.c | ||
| 181 | @@ -204,16 +204,46 @@ typedef uint32_t l1_xlat_tbl_t[NUM_L1_EN | ||
| 182 | typedef uint32_t l2_xlat_tbl_t[NUM_L2_ENTRIES]; | ||
| 183 | typedef uint32_t ul1_xlat_tbl_t[NUM_UL1_ENTRIES]; | ||
| 184 | |||
| 185 | +#ifdef __clang__ | ||
| 186 | +#pragma clang section bss=".nozi.mmu.l1" | ||
| 187 | +#endif | ||
| 188 | static l1_xlat_tbl_t main_mmu_l1_ttb | ||
| 189 | - __aligned(L1_ALIGNMENT) __section(".nozi.mmu.l1"); | ||
| 190 | + __aligned(L1_ALIGNMENT) | ||
| 191 | +#ifndef __clang__ | ||
| 192 | + __section(".nozi.mmu.l1") | ||
| 193 | +#endif | ||
| 194 | +; | ||
| 195 | +#ifdef __clang__ | ||
| 196 | +#pragma clang section bss="" | ||
| 197 | +#endif | ||
| 198 | |||
| 199 | /* L2 MMU tables */ | ||
| 200 | +#ifdef __clang__ | ||
| 201 | +#pragma clang section bss=".nozi.mmu.l2" | ||
| 202 | +#endif | ||
| 203 | static l2_xlat_tbl_t main_mmu_l2_ttb[MAX_XLAT_TABLES] | ||
| 204 | - __aligned(L2_ALIGNMENT) __section(".nozi.mmu.l2"); | ||
| 205 | + __aligned(L2_ALIGNMENT) | ||
| 206 | +#ifndef __clang__ | ||
| 207 | + __section(".nozi.mmu.l2") | ||
| 208 | +#endif | ||
| 209 | +; | ||
| 210 | +#ifdef __clang__ | ||
| 211 | +#pragma clang section bss="" | ||
| 212 | +#endif | ||
| 213 | |||
| 214 | /* MMU L1 table for TAs, one for each thread */ | ||
| 215 | +#ifdef __clang__ | ||
| 216 | +#pragma clang section bss=".nozi.mmu.ul1" | ||
| 217 | +#endif | ||
| 218 | static ul1_xlat_tbl_t main_mmu_ul1_ttb[CFG_NUM_THREADS] | ||
| 219 | - __aligned(UL1_ALIGNMENT) __section(".nozi.mmu.ul1"); | ||
| 220 | + __aligned(UL1_ALIGNMENT) | ||
| 221 | +#ifndef __clang__ | ||
| 222 | + __section(".nozi.mmu.ul1") | ||
| 223 | +#endif | ||
| 224 | +; | ||
| 225 | +#ifdef __clang__ | ||
| 226 | +#pragma clang section bss="" | ||
| 227 | +#endif | ||
| 228 | |||
| 229 | struct mmu_partition { | ||
| 230 | l1_xlat_tbl_t *l1_table; | ||
