Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GCC: ARM_CM0: Fix L6286E error on Keil MDK #1131

Merged

Conversation

TomasGalbickaNXP
Copy link
Contributor

@TomasGalbickaNXP TomasGalbickaNXP commented Aug 27, 2024

Keil MDK Compilation for CM0 core reports L6286E: Relocation #REL:0 in portasm.o

Description

Change the .b instruction to .bl with higher range to solve error reported by MDK descibed bellow.

Fix:
Error: L6286E: Relocation #REL:0 in portasm.o(.text.SVC_Handler) with respect to vPortSVCHandler_C. Value(0x1a04) out of range(-0x800 - 0x7fe) for (R_ARM_THM_JUMP11)

Compiler: Keil MDK ARMClang 6.22.0

https://developer.arm.com/documentation/ka002847/latest/ https://developer.arm.com/documentation/dui0496/m/Linker-Errors-and-Warnings/List-of-the-armlink-error-and-warning-messages

See the issue #1130

Test Steps

See the issue #1130

To Reproduce
git clone https://github.com/TomasGalbickaNXP/freertos-port-cm0-core-issue.git
Checkout the Example with added CM0 MPU port.
git checkout 40af92d06408450e11ca10ad17cd578760fd861a
Open MDK Project and build. It will fail with error reported above.
Checkout fix
git checkout 72a9d6246277ae32594bab69fef66c6e13af3cd1
Open MDK Project and build.
The build reports no Errors.

Checklist:

  • [ x ] I have tested my changes. No regression in existing tests.
  • [ ] I have modified and/or added unit-tests to cover the code changes in this Pull Request.

Related Issue

#1130

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@TomasGalbickaNXP TomasGalbickaNXP requested a review from a team as a code owner August 27, 2024 14:33
portable/GCC/ARM_CM0/portasm.c Outdated Show resolved Hide resolved
@aggarg
Copy link
Member

aggarg commented Aug 27, 2024

Can you share the project that we can use to repro the problem?

@TomasGalbickaNXP
Copy link
Contributor Author

Hi @aggarg Please refer to the Issue there is To Reproduce with the link to git repo with the example project. I will also update this PR.
#1130

@aggarg
Copy link
Member

aggarg commented Aug 28, 2024

Hi @aggarg Please refer to the Issue there is To Reproduce with the link to git repo with the example project. I will also update this PR. #1130

Thank you. I will give it a try and get back.

@TomasGalbickaNXP TomasGalbickaNXP force-pushed the fix/L6286E-error-on-GCC-CM0-port branch from 53ec2eb to 6b7a5fc Compare August 28, 2024 07:19
@aggarg
Copy link
Member

aggarg commented Aug 28, 2024

Branch and Link (bl) instruction changes the value of Link Register (LR) which needs to be preserved. There are 2 ways to solve this problem -

  1. Push and pop the Link Register (LR) in the way we do for system_call_enter and system_call_exit:

    push {lr}
    bl vPortSVCHandler_C
    pop {pc}
    

    This has a drawback - the system call to start the scheduler (portSVC_START_SCHEDULER) never returns and therefore, the corresponding pop is never executed. As a result, we end up wasting 4 bytes on MSP.

  2. Alternative is to use Branch and Exchange (BX) instruction which does not have the range restriction. The following patch implements this solution - use_bx.patch. I have tested this solution on a Cortex-M0+ platform and I have checked that your project builds too with this change. I suggest that we go with this solution. If you agree, would you please apply this patch in this PR.

Thanks.

@TomasGalbickaNXP TomasGalbickaNXP force-pushed the fix/L6286E-error-on-GCC-CM0-port branch from 6b7a5fc to 6abb4df Compare August 28, 2024 12:13
@TomasGalbickaNXP
Copy link
Contributor Author

TomasGalbickaNXP commented Aug 28, 2024

Great! Thanks for your fix.
Yes agreed bx instruction will be better here.

I have applied your provided patch.

" ldr r3, =%1 \n"
" cmp r2, r3 \n"
" beq system_call_exit \n"
" ldr r3, vPortSVCHandler_C_Address \n"
Copy link
Contributor

@urutva urutva Aug 28, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
" ldr r3, vPortSVCHandler_C_Address \n"
" ldr r3, =vPortSVCHandler_C \n"

@TomasGalbickaNXP @aggarg Apologies for the nit. With this style, we can avoid the constant pool defined at the end of the function and let the linker handle the needed alignement.

@aggarg
Copy link
Member

aggarg commented Aug 28, 2024

Thanks @urutva for pointing that out. Here is the updated patch - use_bx_updated.patch. I have tested it on M0+ for both MPU enable and disable.

@TomasGalbickaNXP please use this patch instead. Apologies for back and forth.

@TomasGalbickaNXP TomasGalbickaNXP force-pushed the fix/L6286E-error-on-GCC-CM0-port branch from 6abb4df to 57744d9 Compare August 29, 2024 06:14
Change the .b instruction to .bx with higher range to solve error
reported by MDK descibed bellow.

Fix:
Error: L6286E: Relocation #REL:0 in portasm.o(.text.SVC_Handler) with respect to vPortSVCHandler_C. Value(0x1a04) out of range(-0x800 - 0x7fe) for (R_ARM_THM_JUMP11)

Compiler: Keil MDK ARMClang 6.22.0

https://developer.arm.com/documentation/ka002847/latest/
https://developer.arm.com/documentation/dui0496/m/Linker-Errors-and-Warnings/List-of-the-armlink-error-and-warning-messages

Signed-off-by: Tomas Galbicka <[email protected]>
@TomasGalbickaNXP TomasGalbickaNXP force-pushed the fix/L6286E-error-on-GCC-CM0-port branch from 57744d9 to 74b50e4 Compare August 29, 2024 06:16
Copy link

@TomasGalbickaNXP
Copy link
Contributor Author

OK patch applied.

@aggarg aggarg merged commit e6d8308 into FreeRTOS:main Aug 29, 2024
16 checks passed
@aggarg
Copy link
Member

aggarg commented Aug 29, 2024

Thank you for your contribution!

@TomasGalbickaNXP TomasGalbickaNXP deleted the fix/L6286E-error-on-GCC-CM0-port branch August 29, 2024 11:54
@TomasGalbickaNXP
Copy link
Contributor Author

Thank you for great assistance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants