LLVM-RL78 clang ld.lld’s incorrect relocation address problem
LLVM-RL78 clang ld.lld’s incorrect relocation address problem
Hello support team,
Thank you for your replies.
The our shared RL78/G14 project has the following source line. LLVM-RL78 clang ld.lld generates correct relocation address. But if I remove the line, LLVM-RL78 clang generates incorrect relocation address.
This problem might be caused in the following condition A & B & C.
(A) Variable is defined in C source file.
(B) The variable isn’t used in C source file.
(C) The variable is used in assembly source file.
Screen copies:
CORRECT
INCORRECT
Best regards,
NoMaY
[Added]
At first post, I mistakenly used -O0 optimization option. Now -Os is used in the screen copies.
Best regards,
NoMaY
Dear NoMaY-san,
Upon investigating further, the issue seems to be that the assembly code that references the variables is placed in a section which has some missing flags.
To instruct the linker that the custom section should be checked for references, the sections should be specified like this:
https://github.com/NoMaY-jp/FreeRTOS-Kernel/blob/main/portable/Renesas/LLVMRL78/portasm.S:
.section .lowtext.vPortStartFirstTask, "ax"
_vPortStartFirstTask:
<rest of the code…>
Clang accepts the following syntax too:
.section .lowtext.vPortStartFirstTask,#alloc,#execinstr
_vPortStartFirstTask:
<rest of the code…>
Adding these flags will result in the linker detecting the references to the variables, making their re-initialization in the C source code unnecessary.
A detailed description of the syntax may be found here https://sourceware.org/binutils/docs/as/Section.html#ELF-Version.
Please let us know if we can be of any further assistance.
__
Best regards,
The Open Source Tools Team
Dear NoMaY-san,
We have managed to reproduce the issue, thank you for bringing it to our attention.
While we are working on a fix, a possible workaround could be changing the output sections for the functions present in portasm.S (and for any other in similar situation) from .lowtext.* to .text.* This change resulted in the correct detection of symbol reference in the assembly files, preventing their removal by the –gc-sections option.
Please let us know if this workaround works for you.
__
Best regards,
The Open Source Tools Team