Hi Bohdan,

For reference, this is due to armlink being strict on following the ELF specification for which the region alignment is derived as the maximum alignment of the input sections. You can relax this requirement with armlink by either using the --legacyalign option (although it's being deprecated) or suppressing the diagnostic --diag_suppress=6244. In the future, we could try to reorganize the scatter file for the armclang toolchain to avoid using directly ALIGN attributes and align the base address of the execution regions using AlignExpr() instead, but even with this strategy, any alignment requirement which stems from using .aligned directive in assembly or attribute __ ((aligned)) attributes will influence the input sections alignment, hence it will require a deeper restructuring of the scatter file, possibly moving sections with increased alignment in a separate load region just after LR​_CODE which must have a base address that forces a natural alignment.

Hope this helps.

Thanks, Antonio


From: Bohdan.Hunko--- via TF-M <tf-m@lists.trustedfirmware.org>
Sent: Monday, December 11, 2023 13:39
To: Anton Komlev <Anton.Komlev@arm.com>; tf-m@lists.trustedfirmware.org <tf-m@lists.trustedfirmware.org>
Subject: [TF-M] Re: Weird behavior of Clang linker
 

Hi Anton,

 

Here is the version I am using:

 

$ armclang --version

Product: Arm Development Studio Gold Edition 2020.1

Component: Arm Compiler for Embedded 6.19

Tool: armclang [5e73cb00]

 

Target: unspecified-arm-none-unspecified

 

 

Regards,

Bohdan Hunko

 

Cypress Semiconductor Ukraine

Engineer

CSUKR CSS ICW SW FW

Mobile: +38099 50 19 714
Bohdan.Hunko@infineon.com

 

 

From: Anton Komlev <Anton.Komlev@arm.com>
Sent: Monday, December 11, 2023 15:34
To: Hunko Bohdan (CSS ICW SW FW 3) <Bohdan.Hunko@infineon.com>; tf-m@lists.trustedfirmware.org
Subject: RE: Weird behavior of Clang linker

 

Caution: This e-mail originated outside Infineon Technologies. Do not click on links or open attachments unless you validate it is safe.

 

Hi Bohdan,

What is Clang version you are using?

 

Thanks,

Anton

 

From: Bohdan.Hunko--- via TF-M <tf-m@lists.trustedfirmware.org>
Sent: Monday, December 11, 2023 12:58 PM
To: tf-m@lists.trustedfirmware.org
Subject: [TF-M] Weird behavior of Clang linker

 

Hi all,

 

Our platform uses 4KBs alignment in linker files (as this is the requirement of our protection HW).

 

For this reasons I have introduced tfm_s_linker_alignments.h.

 

Everything works fine with GCC but we have a problem with Clang. The problem is that Clang requires LR_CODE to have same alignment as other sections inside of it.

 

Following are the steps to reproduce the issue:

  1. Set TFM_LINKER_DEFAULT_ALIGNMENT to 0x1000 in tfm_s_linker_alignments.h
  2. Build AN521 with following command line
    cmake -S . -B build_an521 -DTFM_PLATFORM=arm/mps2/an521 -DTFM_TOOLCHAIN_FILE=./toolchain_ARMCLANG.cmake

 

 

Expected result:

Everything works fine

 

Actual result:

                Error: L6244E: Load region LR_CODE address (0x10080400) not aligned on a 4096 byte boundary.

 

This error is weird because there is no explicit alignment assigned to LR_CODE region.

 

Would appreciate a help on this as it is a blocking issue for us.

 

Regards,

Bohdan Hunko

 

Cypress Semiconductor Ukraine

Engineer

CSUKR CSS ICW SW FW

Mobile: +38099 50 19 714
Bohdan.Hunko@infineon.com