All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/2] gator-daemon: Define _GNU_SOURCE feature test macro
@ 2022-08-14  2:51 Khem Raj
  2022-08-14  2:51 ` [PATCH 2/2] optee-os: Add section attribute parameters when clang is used Khem Raj
  2022-08-16  2:08 ` [PATCH 1/2] gator-daemon: Define _GNU_SOURCE feature test macro Jon Mason
  0 siblings, 2 replies; 5+ messages in thread
From: Khem Raj @ 2022-08-14  2:51 UTC (permalink / raw)
  To: meta-arm; +Cc: Khem Raj

Needed for getting vasprintf API from libc

Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 .../0001-daemon-mxml-Define-_GNU_SOURCE.patch | 31 +++++++++++++++++++
 .../gator-daemon/gator-daemon_7.7.0.bb        |  1 +
 2 files changed, 32 insertions(+)
 create mode 100644 meta-arm/recipes-devtools/gator-daemon/gator-daemon/0001-daemon-mxml-Define-_GNU_SOURCE.patch

diff --git a/meta-arm/recipes-devtools/gator-daemon/gator-daemon/0001-daemon-mxml-Define-_GNU_SOURCE.patch b/meta-arm/recipes-devtools/gator-daemon/gator-daemon/0001-daemon-mxml-Define-_GNU_SOURCE.patch
new file mode 100644
index 0000000..d246043
--- /dev/null
+++ b/meta-arm/recipes-devtools/gator-daemon/gator-daemon/0001-daemon-mxml-Define-_GNU_SOURCE.patch
@@ -0,0 +1,31 @@
+From 04e2e924c3ab8da41343277746804dbcd7bf520d Mon Sep 17 00:00:00 2001
+From: Khem Raj <raj.khem@gmail.com>
+Date: Sat, 13 Aug 2022 16:49:52 -0700
+Subject: [PATCH] daemon/mxml: Define _GNU_SOURCE
+
+This file uses vasprintf() which is defined only with _GNU_SOURCE
+feature macro is on.
+
+Upstream-Status: Pending
+
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+---
+ daemon/mxml/mxml-string.c | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/daemon/mxml/mxml-string.c b/daemon/mxml/mxml-string.c
+index 678aeb9..c9cd153 100644
+--- a/daemon/mxml/mxml-string.c
++++ b/daemon/mxml/mxml-string.c
+@@ -13,6 +13,8 @@
+  * Include necessary headers...
+  */
+ 
++#define _GNU_SOURCE
++
+ #include "config.h"
+ 
+ 
+-- 
+2.37.2
+
diff --git a/meta-arm/recipes-devtools/gator-daemon/gator-daemon_7.7.0.bb b/meta-arm/recipes-devtools/gator-daemon/gator-daemon_7.7.0.bb
index 492d321..07b8abb 100644
--- a/meta-arm/recipes-devtools/gator-daemon/gator-daemon_7.7.0.bb
+++ b/meta-arm/recipes-devtools/gator-daemon/gator-daemon_7.7.0.bb
@@ -18,6 +18,7 @@ LIC_FILES_CHKSUM = "file://COPYING;md5=b234ee4d69f5fce4486a80fdaf4a4263 \
 SRCREV = "9d8d75fa08352470c51abc23fe3b314879bd8b78"
 SRC_URI = "git://github.com/ARM-software/gator.git;protocol=http;branch=main;protocol=https \
            file://0001-Sources.mk-Remove-xml-PmuXMLParser.h-header-from-GAT.patch;striplevel=2 \
+           file://0001-daemon-mxml-Define-_GNU_SOURCE.patch;striplevel=2 \
           "
 
 S = "${WORKDIR}/git/daemon"
-- 
2.37.2



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] optee-os: Add section attribute parameters when clang is used
  2022-08-14  2:51 [PATCH 1/2] gator-daemon: Define _GNU_SOURCE feature test macro Khem Raj
@ 2022-08-14  2:51 ` Khem Raj
  2022-08-15 18:25   ` Jon Mason
  2022-08-16  2:08 ` [PATCH 1/2] gator-daemon: Define _GNU_SOURCE feature test macro Jon Mason
  1 sibling, 1 reply; 5+ messages in thread
From: Khem Raj @ 2022-08-14  2:51 UTC (permalink / raw)
  To: meta-arm; +Cc: Khem Raj

Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 meta-arm/recipes-security/optee/optee-os.inc  |   1 +
 ...-Define-section-attributes-for-clang.patch | 188 ++++++++++++++++++
 2 files changed, 189 insertions(+)
 create mode 100644 meta-arm/recipes-security/optee/optee-os/0001-core-Define-section-attributes-for-clang.patch

diff --git a/meta-arm/recipes-security/optee/optee-os.inc b/meta-arm/recipes-security/optee/optee-os.inc
index 11193dc..7834aae 100644
--- a/meta-arm/recipes-security/optee/optee-os.inc
+++ b/meta-arm/recipes-security/optee/optee-os.inc
@@ -19,6 +19,7 @@ SRC_URI = "git://github.com/OP-TEE/optee_os.git;branch=master;protocol=https"
 SRC_URI:append = " \
     file://0006-allow-setting-sysroot-for-libgcc-lookup.patch \
     file://0007-allow-setting-sysroot-for-clang.patch \
+    file://0001-core-Define-section-attributes-for-clang.patch \
    "
 
 S = "${WORKDIR}/git"
diff --git a/meta-arm/recipes-security/optee/optee-os/0001-core-Define-section-attributes-for-clang.patch b/meta-arm/recipes-security/optee/optee-os/0001-core-Define-section-attributes-for-clang.patch
new file mode 100644
index 0000000..db88e7f
--- /dev/null
+++ b/meta-arm/recipes-security/optee/optee-os/0001-core-Define-section-attributes-for-clang.patch
@@ -0,0 +1,188 @@
+From f189457b79989543f65b8a4e8729eff2cdf9a758 Mon Sep 17 00:00:00 2001
+From: Khem Raj <raj.khem@gmail.com>
+Date: Sat, 13 Aug 2022 19:24:55 -0700
+Subject: [PATCH] core: Define section attributes for clang
+
+Clang's attribute section is not same as gcc, here we need to add flags
+to sections so they can be eventually collected by linker into final
+output segments. Only way to do so with clang is to use
+
+pragma clang section ...
+
+The behavious is described here [1], this allows us to define names bss
+sections. This was not an issue until clang-15 where LLD linker starts
+to detect the section flags before merging them and throws the following
+errors
+
+| ld.lld: error: section type mismatch for .nozi.kdata_page
+| >>> /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
+| >>> output section .nozi: SHT_NOBITS
+|
+| ld.lld: error: section type mismatch for .nozi.mmu.l2
+| >>> /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
+| >>> output section .nozi: SHT_NOBITS
+
+These sections should be carrying SHT_NOBITS but so far it was not
+possible to do so, this patch tries to use clangs pragma to get this
+going and match the functionality with gcc.
+
+[1] https://intel.github.io/llvm-docs/clang/LanguageExtensions.html#specifying-section-names-for-global-objects-pragma-clang-section
+
+Upstream-Status: Pending
+Signed-off-by: Khem Raj <raj.khem@gmail.com>
+---
+ core/arch/arm/kernel/thread.c    | 19 +++++++++++++++--
+ core/arch/arm/mm/core_mmu_lpae.c | 35 ++++++++++++++++++++++++++++----
+ core/arch/arm/mm/pgt_cache.c     | 12 ++++++++++-
+ core/kernel/thread.c             | 13 +++++++++++-
+ 4 files changed, 71 insertions(+), 8 deletions(-)
+
+diff --git a/core/arch/arm/kernel/thread.c b/core/arch/arm/kernel/thread.c
+index f083b159e..432983c86 100644
+--- a/core/arch/arm/kernel/thread.c
++++ b/core/arch/arm/kernel/thread.c
+@@ -44,15 +44,30 @@ static size_t thread_user_kcode_size __nex_bss;
+ #if defined(CFG_CORE_UNMAP_CORE_AT_EL0) && \
+ 	defined(CFG_CORE_WORKAROUND_SPECTRE_BP_SEC) && defined(ARM64)
+ long thread_user_kdata_sp_offset __nex_bss;
++#ifdef __clang__
++#ifndef CFG_VIRTUALIZATION
++#pragma clang section bss=".nozi.kdata_page"
++#else
++#pragma clang section bss=".nex_nozi.kdata_page"
++#endif
++#endif
+ static uint8_t thread_user_kdata_page[
+ 	ROUNDUP(sizeof(struct thread_core_local) * CFG_TEE_CORE_NB_CORE,
+ 		SMALL_PAGE_SIZE)]
+ 	__aligned(SMALL_PAGE_SIZE)
++#ifndef __clang__
+ #ifndef CFG_VIRTUALIZATION
+-	__section(".nozi.kdata_page");
++	__section(".nozi.kdata_page")
+ #else
+-	__section(".nex_nozi.kdata_page");
++	__section(".nex_nozi.kdata_page")
+ #endif
++#endif
++    ;
++#endif
++
++/* reset BSS section to default ( .bss ) */
++#ifdef __clang__
++#pragma clang section bss=""
+ #endif
+ 
+ #ifdef ARM32
+diff --git a/core/arch/arm/mm/core_mmu_lpae.c b/core/arch/arm/mm/core_mmu_lpae.c
+index 19cd7b61b..78f5910c5 100644
+--- a/core/arch/arm/mm/core_mmu_lpae.c
++++ b/core/arch/arm/mm/core_mmu_lpae.c
+@@ -230,19 +230,46 @@ typedef uint16_t l1_idx_t;
+ typedef uint64_t base_xlat_tbls_t[CFG_TEE_CORE_NB_CORE][NUM_BASE_LEVEL_ENTRIES];
+ typedef uint64_t xlat_tbl_t[XLAT_TABLE_ENTRIES];
+ 
++#ifdef __clang__
++#pragma clang section bss=".nozi.mmu.base_table"
++#endif
+ static base_xlat_tbls_t base_xlation_table[NUM_BASE_TABLES]
+ 	__aligned(NUM_BASE_LEVEL_ENTRIES * XLAT_ENTRY_SIZE)
+-	__section(".nozi.mmu.base_table");
++#ifndef __clang__
++	__section(".nozi.mmu.base_table")
++#endif
++;
++#ifdef __clang__
++#pragma clang section bss=""
++#endif
+ 
++#ifdef __clang__
++#pragma clang section bss=".nozi.mmu.l2"
++#endif
+ static xlat_tbl_t xlat_tables[MAX_XLAT_TABLES]
+-	__aligned(XLAT_TABLE_SIZE) __section(".nozi.mmu.l2");
++	__aligned(XLAT_TABLE_SIZE)
++#ifndef __clang__
++	__section(".nozi.mmu.l2")
++#endif
++;
++#ifdef __clang__
++#pragma clang section bss=""
++#endif
+ 
+ #define XLAT_TABLES_SIZE	(sizeof(xlat_tbl_t) * MAX_XLAT_TABLES)
+ 
++#ifdef __clang__
++#pragma clang section bss=".nozi.mmu.l2"
++#endif
+ /* MMU L2 table for TAs, one for each thread */
+ static xlat_tbl_t xlat_tables_ul1[CFG_NUM_THREADS]
+-	__aligned(XLAT_TABLE_SIZE) __section(".nozi.mmu.l2");
+-
++#ifndef __clang__
++	__aligned(XLAT_TABLE_SIZE) __section(".nozi.mmu.l2")
++#endif
++;
++#ifdef __clang__
++#pragma clang section bss=""
++#endif
+ /*
+  * TAs page table entry inside a level 1 page table.
+  *
+diff --git a/core/arch/arm/mm/pgt_cache.c b/core/arch/arm/mm/pgt_cache.c
+index d658b3e68..6c36706c0 100644
+--- a/core/arch/arm/mm/pgt_cache.c
++++ b/core/arch/arm/mm/pgt_cache.c
+@@ -104,8 +104,18 @@ void pgt_init(void)
+ 	 * has a large alignment, while .bss has a small alignment. The current
+ 	 * link script is optimized for small alignment in .bss
+ 	 */
++#ifdef __clang__
++#pragma clang section bss=".nozi.mmu.l2"
++#endif
+ 	static uint8_t pgt_tables[PGT_CACHE_SIZE][PGT_SIZE]
+-			__aligned(PGT_SIZE) __section(".nozi.pgt_cache");
++			__aligned(PGT_SIZE)
++#ifndef __clang__
++			__section(".nozi.pgt_cache")
++#endif
++			;
++#ifdef __clang__
++#pragma clang section bss=""
++#endif
+ 	size_t n;
+ 
+ 	for (n = 0; n < ARRAY_SIZE(pgt_tables); n++) {
+diff --git a/core/kernel/thread.c b/core/kernel/thread.c
+index 18d34e6ad..086129e28 100644
+--- a/core/kernel/thread.c
++++ b/core/kernel/thread.c
+@@ -37,13 +37,24 @@ struct thread_core_local thread_core_local[CFG_TEE_CORE_NB_CORE] __nex_bss;
+ 	name[stack_num][sizeof(name[stack_num]) / sizeof(uint32_t) - 1]
+ #endif
+ 
++#define DO_PRAGMA(x) _Pragma (#x)
++
++#ifdef __clang__
++#define DECLARE_STACK(name, num_stacks, stack_size, linkage) \
++DO_PRAGMA (clang section bss=".nozi_stack." #name) \
++linkage uint32_t name[num_stacks] \
++		[ROUNDUP(stack_size + STACK_CANARY_SIZE + STACK_CHECK_EXTRA, \
++			 STACK_ALIGNMENT) / sizeof(uint32_t)] \
++		__attribute__((aligned(STACK_ALIGNMENT))); \
++DO_PRAGMA(clang section bss="")
++#else
+ #define DECLARE_STACK(name, num_stacks, stack_size, linkage) \
+ linkage uint32_t name[num_stacks] \
+ 		[ROUNDUP(stack_size + STACK_CANARY_SIZE + STACK_CHECK_EXTRA, \
+ 			 STACK_ALIGNMENT) / sizeof(uint32_t)] \
+ 		__attribute__((section(".nozi_stack." # name), \
+ 			       aligned(STACK_ALIGNMENT)))
+-
++#endif
+ #define GET_STACK(stack) ((vaddr_t)(stack) + STACK_SIZE(stack))
+ 
+ DECLARE_STACK(stack_tmp, CFG_TEE_CORE_NB_CORE,
+-- 
+2.37.2
+
-- 
2.37.2



^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] optee-os: Add section attribute parameters when clang is used
  2022-08-14  2:51 ` [PATCH 2/2] optee-os: Add section attribute parameters when clang is used Khem Raj
@ 2022-08-15 18:25   ` Jon Mason
  2022-08-15 18:48     ` Khem Raj
  0 siblings, 1 reply; 5+ messages in thread
From: Jon Mason @ 2022-08-15 18:25 UTC (permalink / raw)
  To: Khem Raj; +Cc: meta-arm

On Sat, Aug 13, 2022 at 07:51:24PM -0700, Khem Raj wrote:
> Signed-off-by: Khem Raj <raj.khem@gmail.com>
> ---
>  meta-arm/recipes-security/optee/optee-os.inc  |   1 +
>  ...-Define-section-attributes-for-clang.patch | 188 ++++++++++++++++++
>  2 files changed, 189 insertions(+)
>  create mode 100644 meta-arm/recipes-security/optee/optee-os/0001-core-Define-section-attributes-for-clang.patch
> 
> diff --git a/meta-arm/recipes-security/optee/optee-os.inc b/meta-arm/recipes-security/optee/optee-os.inc
> index 11193dc..7834aae 100644
> --- a/meta-arm/recipes-security/optee/optee-os.inc
> +++ b/meta-arm/recipes-security/optee/optee-os.inc
> @@ -19,6 +19,7 @@ SRC_URI = "git://github.com/OP-TEE/optee_os.git;branch=master;protocol=https"
>  SRC_URI:append = " \
>      file://0006-allow-setting-sysroot-for-libgcc-lookup.patch \
>      file://0007-allow-setting-sysroot-for-clang.patch \
> +    file://0001-core-Define-section-attributes-for-clang.patch \
>     "

This breaks the 3.14 recipe.  So, I'm modifying the patch to only
apply it to 3.18.  Hopefully that is acceptable.  

Also, I'll have a patch shortly that will update all of the 3.17
recipes to 3.18 (assuming it passes cI), which should close any
exposure there.

Thanks,
Jon

>  
>  S = "${WORKDIR}/git"
> diff --git a/meta-arm/recipes-security/optee/optee-os/0001-core-Define-section-attributes-for-clang.patch b/meta-arm/recipes-security/optee/optee-os/0001-core-Define-section-attributes-for-clang.patch
> new file mode 100644
> index 0000000..db88e7f
> --- /dev/null
> +++ b/meta-arm/recipes-security/optee/optee-os/0001-core-Define-section-attributes-for-clang.patch
> @@ -0,0 +1,188 @@
> +From f189457b79989543f65b8a4e8729eff2cdf9a758 Mon Sep 17 00:00:00 2001
> +From: Khem Raj <raj.khem@gmail.com>
> +Date: Sat, 13 Aug 2022 19:24:55 -0700
> +Subject: [PATCH] core: Define section attributes for clang
> +
> +Clang's attribute section is not same as gcc, here we need to add flags
> +to sections so they can be eventually collected by linker into final
> +output segments. Only way to do so with clang is to use
> +
> +pragma clang section ...
> +
> +The behavious is described here [1], this allows us to define names bss
> +sections. This was not an issue until clang-15 where LLD linker starts
> +to detect the section flags before merging them and throws the following
> +errors
> +
> +| ld.lld: error: section type mismatch for .nozi.kdata_page
> +| >>> /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
> +| >>> output section .nozi: SHT_NOBITS
> +|
> +| ld.lld: error: section type mismatch for .nozi.mmu.l2
> +| >>> /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
> +| >>> output section .nozi: SHT_NOBITS
> +
> +These sections should be carrying SHT_NOBITS but so far it was not
> +possible to do so, this patch tries to use clangs pragma to get this
> +going and match the functionality with gcc.
> +
> +[1] https://intel.github.io/llvm-docs/clang/LanguageExtensions.html#specifying-section-names-for-global-objects-pragma-clang-section
> +
> +Upstream-Status: Pending
> +Signed-off-by: Khem Raj <raj.khem@gmail.com>
> +---
> + core/arch/arm/kernel/thread.c    | 19 +++++++++++++++--
> + core/arch/arm/mm/core_mmu_lpae.c | 35 ++++++++++++++++++++++++++++----
> + core/arch/arm/mm/pgt_cache.c     | 12 ++++++++++-
> + core/kernel/thread.c             | 13 +++++++++++-
> + 4 files changed, 71 insertions(+), 8 deletions(-)
> +
> +diff --git a/core/arch/arm/kernel/thread.c b/core/arch/arm/kernel/thread.c
> +index f083b159e..432983c86 100644
> +--- a/core/arch/arm/kernel/thread.c
> ++++ b/core/arch/arm/kernel/thread.c
> +@@ -44,15 +44,30 @@ static size_t thread_user_kcode_size __nex_bss;
> + #if defined(CFG_CORE_UNMAP_CORE_AT_EL0) && \
> + 	defined(CFG_CORE_WORKAROUND_SPECTRE_BP_SEC) && defined(ARM64)
> + long thread_user_kdata_sp_offset __nex_bss;
> ++#ifdef __clang__
> ++#ifndef CFG_VIRTUALIZATION
> ++#pragma clang section bss=".nozi.kdata_page"
> ++#else
> ++#pragma clang section bss=".nex_nozi.kdata_page"
> ++#endif
> ++#endif
> + static uint8_t thread_user_kdata_page[
> + 	ROUNDUP(sizeof(struct thread_core_local) * CFG_TEE_CORE_NB_CORE,
> + 		SMALL_PAGE_SIZE)]
> + 	__aligned(SMALL_PAGE_SIZE)
> ++#ifndef __clang__
> + #ifndef CFG_VIRTUALIZATION
> +-	__section(".nozi.kdata_page");
> ++	__section(".nozi.kdata_page")
> + #else
> +-	__section(".nex_nozi.kdata_page");
> ++	__section(".nex_nozi.kdata_page")
> + #endif
> ++#endif
> ++    ;
> ++#endif
> ++
> ++/* reset BSS section to default ( .bss ) */
> ++#ifdef __clang__
> ++#pragma clang section bss=""
> + #endif
> + 
> + #ifdef ARM32
> +diff --git a/core/arch/arm/mm/core_mmu_lpae.c b/core/arch/arm/mm/core_mmu_lpae.c
> +index 19cd7b61b..78f5910c5 100644
> +--- a/core/arch/arm/mm/core_mmu_lpae.c
> ++++ b/core/arch/arm/mm/core_mmu_lpae.c
> +@@ -230,19 +230,46 @@ typedef uint16_t l1_idx_t;
> + typedef uint64_t base_xlat_tbls_t[CFG_TEE_CORE_NB_CORE][NUM_BASE_LEVEL_ENTRIES];
> + typedef uint64_t xlat_tbl_t[XLAT_TABLE_ENTRIES];
> + 
> ++#ifdef __clang__
> ++#pragma clang section bss=".nozi.mmu.base_table"
> ++#endif
> + static base_xlat_tbls_t base_xlation_table[NUM_BASE_TABLES]
> + 	__aligned(NUM_BASE_LEVEL_ENTRIES * XLAT_ENTRY_SIZE)
> +-	__section(".nozi.mmu.base_table");
> ++#ifndef __clang__
> ++	__section(".nozi.mmu.base_table")
> ++#endif
> ++;
> ++#ifdef __clang__
> ++#pragma clang section bss=""
> ++#endif
> + 
> ++#ifdef __clang__
> ++#pragma clang section bss=".nozi.mmu.l2"
> ++#endif
> + static xlat_tbl_t xlat_tables[MAX_XLAT_TABLES]
> +-	__aligned(XLAT_TABLE_SIZE) __section(".nozi.mmu.l2");
> ++	__aligned(XLAT_TABLE_SIZE)
> ++#ifndef __clang__
> ++	__section(".nozi.mmu.l2")
> ++#endif
> ++;
> ++#ifdef __clang__
> ++#pragma clang section bss=""
> ++#endif
> + 
> + #define XLAT_TABLES_SIZE	(sizeof(xlat_tbl_t) * MAX_XLAT_TABLES)
> + 
> ++#ifdef __clang__
> ++#pragma clang section bss=".nozi.mmu.l2"
> ++#endif
> + /* MMU L2 table for TAs, one for each thread */
> + static xlat_tbl_t xlat_tables_ul1[CFG_NUM_THREADS]
> +-	__aligned(XLAT_TABLE_SIZE) __section(".nozi.mmu.l2");
> +-
> ++#ifndef __clang__
> ++	__aligned(XLAT_TABLE_SIZE) __section(".nozi.mmu.l2")
> ++#endif
> ++;
> ++#ifdef __clang__
> ++#pragma clang section bss=""
> ++#endif
> + /*
> +  * TAs page table entry inside a level 1 page table.
> +  *
> +diff --git a/core/arch/arm/mm/pgt_cache.c b/core/arch/arm/mm/pgt_cache.c
> +index d658b3e68..6c36706c0 100644
> +--- a/core/arch/arm/mm/pgt_cache.c
> ++++ b/core/arch/arm/mm/pgt_cache.c
> +@@ -104,8 +104,18 @@ void pgt_init(void)
> + 	 * has a large alignment, while .bss has a small alignment. The current
> + 	 * link script is optimized for small alignment in .bss
> + 	 */
> ++#ifdef __clang__
> ++#pragma clang section bss=".nozi.mmu.l2"
> ++#endif
> + 	static uint8_t pgt_tables[PGT_CACHE_SIZE][PGT_SIZE]
> +-			__aligned(PGT_SIZE) __section(".nozi.pgt_cache");
> ++			__aligned(PGT_SIZE)
> ++#ifndef __clang__
> ++			__section(".nozi.pgt_cache")
> ++#endif
> ++			;
> ++#ifdef __clang__
> ++#pragma clang section bss=""
> ++#endif
> + 	size_t n;
> + 
> + 	for (n = 0; n < ARRAY_SIZE(pgt_tables); n++) {
> +diff --git a/core/kernel/thread.c b/core/kernel/thread.c
> +index 18d34e6ad..086129e28 100644
> +--- a/core/kernel/thread.c
> ++++ b/core/kernel/thread.c
> +@@ -37,13 +37,24 @@ struct thread_core_local thread_core_local[CFG_TEE_CORE_NB_CORE] __nex_bss;
> + 	name[stack_num][sizeof(name[stack_num]) / sizeof(uint32_t) - 1]
> + #endif
> + 
> ++#define DO_PRAGMA(x) _Pragma (#x)
> ++
> ++#ifdef __clang__
> ++#define DECLARE_STACK(name, num_stacks, stack_size, linkage) \
> ++DO_PRAGMA (clang section bss=".nozi_stack." #name) \
> ++linkage uint32_t name[num_stacks] \
> ++		[ROUNDUP(stack_size + STACK_CANARY_SIZE + STACK_CHECK_EXTRA, \
> ++			 STACK_ALIGNMENT) / sizeof(uint32_t)] \
> ++		__attribute__((aligned(STACK_ALIGNMENT))); \
> ++DO_PRAGMA(clang section bss="")
> ++#else
> + #define DECLARE_STACK(name, num_stacks, stack_size, linkage) \
> + linkage uint32_t name[num_stacks] \
> + 		[ROUNDUP(stack_size + STACK_CANARY_SIZE + STACK_CHECK_EXTRA, \
> + 			 STACK_ALIGNMENT) / sizeof(uint32_t)] \
> + 		__attribute__((section(".nozi_stack." # name), \
> + 			       aligned(STACK_ALIGNMENT)))
> +-
> ++#endif
> + #define GET_STACK(stack) ((vaddr_t)(stack) + STACK_SIZE(stack))
> + 
> + DECLARE_STACK(stack_tmp, CFG_TEE_CORE_NB_CORE,
> +-- 
> +2.37.2
> +
> -- 
> 2.37.2
> 
> 


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 2/2] optee-os: Add section attribute parameters when clang is used
  2022-08-15 18:25   ` Jon Mason
@ 2022-08-15 18:48     ` Khem Raj
  0 siblings, 0 replies; 5+ messages in thread
From: Khem Raj @ 2022-08-15 18:48 UTC (permalink / raw)
  To: Jon Mason; +Cc: meta-arm

On Mon, Aug 15, 2022 at 11:25 AM Jon Mason <jdmason@kudzu.us> wrote:
>
> On Sat, Aug 13, 2022 at 07:51:24PM -0700, Khem Raj wrote:
> > Signed-off-by: Khem Raj <raj.khem@gmail.com>
> > ---
> >  meta-arm/recipes-security/optee/optee-os.inc  |   1 +
> >  ...-Define-section-attributes-for-clang.patch | 188 ++++++++++++++++++
> >  2 files changed, 189 insertions(+)
> >  create mode 100644 meta-arm/recipes-security/optee/optee-os/0001-core-Define-section-attributes-for-clang.patch
> >
> > diff --git a/meta-arm/recipes-security/optee/optee-os.inc b/meta-arm/recipes-security/optee/optee-os.inc
> > index 11193dc..7834aae 100644
> > --- a/meta-arm/recipes-security/optee/optee-os.inc
> > +++ b/meta-arm/recipes-security/optee/optee-os.inc
> > @@ -19,6 +19,7 @@ SRC_URI = "git://github.com/OP-TEE/optee_os.git;branch=master;protocol=https"
> >  SRC_URI:append = " \
> >      file://0006-allow-setting-sysroot-for-libgcc-lookup.patch \
> >      file://0007-allow-setting-sysroot-for-clang.patch \
> > +    file://0001-core-Define-section-attributes-for-clang.patch \
> >     "
>
> This breaks the 3.14 recipe.  So, I'm modifying the patch to only
> apply it to 3.18.  Hopefully that is acceptable.
>
> Also, I'll have a patch shortly that will update all of the 3.17
> recipes to 3.18 (assuming it passes cI), which should close any
> exposure there.

Thanks Jon, I have done builds for 3.18 and 3.17 but not for 3.14

>
> Thanks,
> Jon
>
> >
> >  S = "${WORKDIR}/git"
> > diff --git a/meta-arm/recipes-security/optee/optee-os/0001-core-Define-section-attributes-for-clang.patch b/meta-arm/recipes-security/optee/optee-os/0001-core-Define-section-attributes-for-clang.patch
> > new file mode 100644
> > index 0000000..db88e7f
> > --- /dev/null
> > +++ b/meta-arm/recipes-security/optee/optee-os/0001-core-Define-section-attributes-for-clang.patch
> > @@ -0,0 +1,188 @@
> > +From f189457b79989543f65b8a4e8729eff2cdf9a758 Mon Sep 17 00:00:00 2001
> > +From: Khem Raj <raj.khem@gmail.com>
> > +Date: Sat, 13 Aug 2022 19:24:55 -0700
> > +Subject: [PATCH] core: Define section attributes for clang
> > +
> > +Clang's attribute section is not same as gcc, here we need to add flags
> > +to sections so they can be eventually collected by linker into final
> > +output segments. Only way to do so with clang is to use
> > +
> > +pragma clang section ...
> > +
> > +The behavious is described here [1], this allows us to define names bss
> > +sections. This was not an issue until clang-15 where LLD linker starts
> > +to detect the section flags before merging them and throws the following
> > +errors
> > +
> > +| ld.lld: error: section type mismatch for .nozi.kdata_page
> > +| >>> /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
> > +| >>> output section .nozi: SHT_NOBITS
> > +|
> > +| ld.lld: error: section type mismatch for .nozi.mmu.l2
> > +| >>> /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
> > +| >>> output section .nozi: SHT_NOBITS
> > +
> > +These sections should be carrying SHT_NOBITS but so far it was not
> > +possible to do so, this patch tries to use clangs pragma to get this
> > +going and match the functionality with gcc.
> > +
> > +[1] https://intel.github.io/llvm-docs/clang/LanguageExtensions.html#specifying-section-names-for-global-objects-pragma-clang-section
> > +
> > +Upstream-Status: Pending
> > +Signed-off-by: Khem Raj <raj.khem@gmail.com>
> > +---
> > + core/arch/arm/kernel/thread.c    | 19 +++++++++++++++--
> > + core/arch/arm/mm/core_mmu_lpae.c | 35 ++++++++++++++++++++++++++++----
> > + core/arch/arm/mm/pgt_cache.c     | 12 ++++++++++-
> > + core/kernel/thread.c             | 13 +++++++++++-
> > + 4 files changed, 71 insertions(+), 8 deletions(-)
> > +
> > +diff --git a/core/arch/arm/kernel/thread.c b/core/arch/arm/kernel/thread.c
> > +index f083b159e..432983c86 100644
> > +--- a/core/arch/arm/kernel/thread.c
> > ++++ b/core/arch/arm/kernel/thread.c
> > +@@ -44,15 +44,30 @@ static size_t thread_user_kcode_size __nex_bss;
> > + #if defined(CFG_CORE_UNMAP_CORE_AT_EL0) && \
> > +     defined(CFG_CORE_WORKAROUND_SPECTRE_BP_SEC) && defined(ARM64)
> > + long thread_user_kdata_sp_offset __nex_bss;
> > ++#ifdef __clang__
> > ++#ifndef CFG_VIRTUALIZATION
> > ++#pragma clang section bss=".nozi.kdata_page"
> > ++#else
> > ++#pragma clang section bss=".nex_nozi.kdata_page"
> > ++#endif
> > ++#endif
> > + static uint8_t thread_user_kdata_page[
> > +     ROUNDUP(sizeof(struct thread_core_local) * CFG_TEE_CORE_NB_CORE,
> > +             SMALL_PAGE_SIZE)]
> > +     __aligned(SMALL_PAGE_SIZE)
> > ++#ifndef __clang__
> > + #ifndef CFG_VIRTUALIZATION
> > +-    __section(".nozi.kdata_page");
> > ++    __section(".nozi.kdata_page")
> > + #else
> > +-    __section(".nex_nozi.kdata_page");
> > ++    __section(".nex_nozi.kdata_page")
> > + #endif
> > ++#endif
> > ++    ;
> > ++#endif
> > ++
> > ++/* reset BSS section to default ( .bss ) */
> > ++#ifdef __clang__
> > ++#pragma clang section bss=""
> > + #endif
> > +
> > + #ifdef ARM32
> > +diff --git a/core/arch/arm/mm/core_mmu_lpae.c b/core/arch/arm/mm/core_mmu_lpae.c
> > +index 19cd7b61b..78f5910c5 100644
> > +--- a/core/arch/arm/mm/core_mmu_lpae.c
> > ++++ b/core/arch/arm/mm/core_mmu_lpae.c
> > +@@ -230,19 +230,46 @@ typedef uint16_t l1_idx_t;
> > + typedef uint64_t base_xlat_tbls_t[CFG_TEE_CORE_NB_CORE][NUM_BASE_LEVEL_ENTRIES];
> > + typedef uint64_t xlat_tbl_t[XLAT_TABLE_ENTRIES];
> > +
> > ++#ifdef __clang__
> > ++#pragma clang section bss=".nozi.mmu.base_table"
> > ++#endif
> > + static base_xlat_tbls_t base_xlation_table[NUM_BASE_TABLES]
> > +     __aligned(NUM_BASE_LEVEL_ENTRIES * XLAT_ENTRY_SIZE)
> > +-    __section(".nozi.mmu.base_table");
> > ++#ifndef __clang__
> > ++    __section(".nozi.mmu.base_table")
> > ++#endif
> > ++;
> > ++#ifdef __clang__
> > ++#pragma clang section bss=""
> > ++#endif
> > +
> > ++#ifdef __clang__
> > ++#pragma clang section bss=".nozi.mmu.l2"
> > ++#endif
> > + static xlat_tbl_t xlat_tables[MAX_XLAT_TABLES]
> > +-    __aligned(XLAT_TABLE_SIZE) __section(".nozi.mmu.l2");
> > ++    __aligned(XLAT_TABLE_SIZE)
> > ++#ifndef __clang__
> > ++    __section(".nozi.mmu.l2")
> > ++#endif
> > ++;
> > ++#ifdef __clang__
> > ++#pragma clang section bss=""
> > ++#endif
> > +
> > + #define XLAT_TABLES_SIZE    (sizeof(xlat_tbl_t) * MAX_XLAT_TABLES)
> > +
> > ++#ifdef __clang__
> > ++#pragma clang section bss=".nozi.mmu.l2"
> > ++#endif
> > + /* MMU L2 table for TAs, one for each thread */
> > + static xlat_tbl_t xlat_tables_ul1[CFG_NUM_THREADS]
> > +-    __aligned(XLAT_TABLE_SIZE) __section(".nozi.mmu.l2");
> > +-
> > ++#ifndef __clang__
> > ++    __aligned(XLAT_TABLE_SIZE) __section(".nozi.mmu.l2")
> > ++#endif
> > ++;
> > ++#ifdef __clang__
> > ++#pragma clang section bss=""
> > ++#endif
> > + /*
> > +  * TAs page table entry inside a level 1 page table.
> > +  *
> > +diff --git a/core/arch/arm/mm/pgt_cache.c b/core/arch/arm/mm/pgt_cache.c
> > +index d658b3e68..6c36706c0 100644
> > +--- a/core/arch/arm/mm/pgt_cache.c
> > ++++ b/core/arch/arm/mm/pgt_cache.c
> > +@@ -104,8 +104,18 @@ void pgt_init(void)
> > +      * has a large alignment, while .bss has a small alignment. The current
> > +      * link script is optimized for small alignment in .bss
> > +      */
> > ++#ifdef __clang__
> > ++#pragma clang section bss=".nozi.mmu.l2"
> > ++#endif
> > +     static uint8_t pgt_tables[PGT_CACHE_SIZE][PGT_SIZE]
> > +-                    __aligned(PGT_SIZE) __section(".nozi.pgt_cache");
> > ++                    __aligned(PGT_SIZE)
> > ++#ifndef __clang__
> > ++                    __section(".nozi.pgt_cache")
> > ++#endif
> > ++                    ;
> > ++#ifdef __clang__
> > ++#pragma clang section bss=""
> > ++#endif
> > +     size_t n;
> > +
> > +     for (n = 0; n < ARRAY_SIZE(pgt_tables); n++) {
> > +diff --git a/core/kernel/thread.c b/core/kernel/thread.c
> > +index 18d34e6ad..086129e28 100644
> > +--- a/core/kernel/thread.c
> > ++++ b/core/kernel/thread.c
> > +@@ -37,13 +37,24 @@ struct thread_core_local thread_core_local[CFG_TEE_CORE_NB_CORE] __nex_bss;
> > +     name[stack_num][sizeof(name[stack_num]) / sizeof(uint32_t) - 1]
> > + #endif
> > +
> > ++#define DO_PRAGMA(x) _Pragma (#x)
> > ++
> > ++#ifdef __clang__
> > ++#define DECLARE_STACK(name, num_stacks, stack_size, linkage) \
> > ++DO_PRAGMA (clang section bss=".nozi_stack." #name) \
> > ++linkage uint32_t name[num_stacks] \
> > ++            [ROUNDUP(stack_size + STACK_CANARY_SIZE + STACK_CHECK_EXTRA, \
> > ++                     STACK_ALIGNMENT) / sizeof(uint32_t)] \
> > ++            __attribute__((aligned(STACK_ALIGNMENT))); \
> > ++DO_PRAGMA(clang section bss="")
> > ++#else
> > + #define DECLARE_STACK(name, num_stacks, stack_size, linkage) \
> > + linkage uint32_t name[num_stacks] \
> > +             [ROUNDUP(stack_size + STACK_CANARY_SIZE + STACK_CHECK_EXTRA, \
> > +                      STACK_ALIGNMENT) / sizeof(uint32_t)] \
> > +             __attribute__((section(".nozi_stack." # name), \
> > +                            aligned(STACK_ALIGNMENT)))
> > +-
> > ++#endif
> > + #define GET_STACK(stack) ((vaddr_t)(stack) + STACK_SIZE(stack))
> > +
> > + DECLARE_STACK(stack_tmp, CFG_TEE_CORE_NB_CORE,
> > +--
> > +2.37.2
> > +
> > --
> > 2.37.2
> >
> >


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] gator-daemon: Define _GNU_SOURCE feature test macro
  2022-08-14  2:51 [PATCH 1/2] gator-daemon: Define _GNU_SOURCE feature test macro Khem Raj
  2022-08-14  2:51 ` [PATCH 2/2] optee-os: Add section attribute parameters when clang is used Khem Raj
@ 2022-08-16  2:08 ` Jon Mason
  1 sibling, 0 replies; 5+ messages in thread
From: Jon Mason @ 2022-08-16  2:08 UTC (permalink / raw)
  To: meta-arm, Khem Raj

On Sat, 13 Aug 2022 19:51:23 -0700, Khem Raj wrote:
> Needed for getting vasprintf API from libc

Applied, thanks!

[1/2] gator-daemon: Define _GNU_SOURCE feature test macro
      commit: ee73c352ccb8347bb705023af031b6f9c49a9ce4
[2/2] optee-os: Add section attribute parameters when clang is used
      commit: 74cab68b96a3bc8f5b4523e29351e902d26ab158

Best regards,
-- 
Jon Mason <jon.mason@arm.com>


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-08-16  2:08 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-14  2:51 [PATCH 1/2] gator-daemon: Define _GNU_SOURCE feature test macro Khem Raj
2022-08-14  2:51 ` [PATCH 2/2] optee-os: Add section attribute parameters when clang is used Khem Raj
2022-08-15 18:25   ` Jon Mason
2022-08-15 18:48     ` Khem Raj
2022-08-16  2:08 ` [PATCH 1/2] gator-daemon: Define _GNU_SOURCE feature test macro Jon Mason

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.