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

Zcmt relaxation of single *.S-source bare metal code #88

Open
silabs-hfegran opened this issue May 5, 2023 · 3 comments
Open

Zcmt relaxation of single *.S-source bare metal code #88

silabs-hfegran opened this issue May 5, 2023 · 3 comments
Labels
documentation Improvements or additions to documentation

Comments

@silabs-hfegran
Copy link

There are cases where compilation of a single, bare-metal .S-file with the zcmt-flag march-flag enabled causes the linker to replace jumps inside the assembly with table jump instructions - this creates several issues and does not really make sense to me:

  1. The program and linker has no way of knowing the initial value of the jvt-register (jvt is not necessarily read-only), thus the address of the table is unknown. To make sense, the code also needs to initialize this register with the address of the table it wants to use.
  2. The table itself is not created (I believe this is the case - in a previous version of binutils, the content at address 0 would be overwritten)
  3. Will break manually crafted assembly files that uses manually written table(s) and cm.jalt/cm.jt instructions.
  4. Will break assembly tests that do not explicitly use zcmt (but leaves the march flag enabled), as the program jumps will get corrupted due to lack of a functional jump table.
  5. Will break assembly tests that use multiple jump tables whose locations (jvt) are updated based on the state of the program
  6. If the jvt CSR is updated, as per bullet 1, then it would cause additional new instructions (e.g. csrrw) to be inserted into a manually crafted asm file, which is usually not what one would want.

Technically, this can be avoided with -mno-relax-flag to the linker, but I would not expect this to be necessary, as that also leads to an impact of potentially blocking other relaxations.
That leads me to the question of what kind of scenario with tablejump-relaxation of a manually crafted assembly file would actually be useful?

I do not currently have an example on hand to reproduce this, but I will try to add that here as soon as possible. Posting this now to raise awareness of this issue.

@fanghuaqi
Copy link

Hi @silabs-hfegran , I met similar issues with you, hope there will some way to not enable table jump for certain code

such as

  1. using the asm .option arch, -zcmt to disable cmt option
  2. allow a gcc option to not replace jump instruction to certain symbols not be replaced by table jump

Maybe @pz9115 @linsinan1995 can help with this issue.

Thanks

@linsinan1995
Copy link
Contributor

linsinan1995 commented May 19, 2023

Hi, @fanghuaqi

Hi @silabs-hfegran , I met similar issues with you, hope there will some way to not enable table jump for certain code

such as

  1. using the asm .option arch, -zcmt to disable cmt option

Not sure if this works or not. IIRC, the current relaxation phrase treat symbols from different object files equally, so this won't work unless we record the arch info of each object file and skip relaxing symbols from object files without zcmt arch option.

  1. allow a gcc option to not replace jump instruction to certain symbols not be replaced by table jump

I could imagine this option will be useful in some other scenarios, and better to have it. CC @pz9115

@fanghuaqi
Copy link

Hi, @fanghuaqi

Hi @silabs-hfegran , I met similar issues with you, hope there will some way to not enable table jump for certain code
such as

  1. using the asm .option arch, -zcmt to disable cmt option

Not sure if this works or not. IIRC, the current relaxation phrase treat symbols from different object files equally, so this won't work unless we record the arch info of each object file and skip relaxing symbols from object files without zcmt arch option.

  1. allow a gcc option to not replace jump instruction to certain symbols not be replaced by table jump

I could imagine this option will be useful in some other scenarios, and better to have it. CC @pz9115

Thanks @linsinan1995 , option 1 is not working, I have tried it, currently didn't find a good way to achive it.

@MaryBennett MaryBennett added the documentation Improvements or additions to documentation label Aug 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation
Projects
None yet
Development

No branches or pull requests

4 participants