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

Linking and linker relaxation fixes #200

Merged
merged 3 commits into from
May 22, 2024
Merged

Conversation

DNedic
Copy link
Contributor

@DNedic DNedic commented May 20, 2024

This PR fixes the following issues:

  1. Accounts for the possibility of the .sdata* sections being generated. These sections are created by compilers in order to optimize access for small data on some architectures. Right now this breaks the espressif/esp example the .sdata output section is being automatically placed at the wrong place, creating an incorrect and enormous binary.
  2. Properly provide the __global_pointer$ used in the RISC-V architecture CPUs to initialize the GP register. This register is then used in order to improve access times to frequently used data, as long as it is +-2048 bytes away by fitting the offset in the immideate part of the instruction.
  3. Disables relaxation when initializing the GP register on espressif-riscv

References:
https://www.sifive.com/blog/all-aboard-part-3-linker-relaxation-in-riscv-toolchain
https://five-embeddev.com/quickref/global_pointer.html
https://d3s.mff.cuni.cz/files/teaching/nswi200/202324/doc/riscv-abi.pdf

DNedic added 3 commits May 21, 2024 01:23
The .sdata section is used for small initialized data by LLVM in order
to optimize access to it on some architectures like RISC-V.
The global pointer should be set to cover a range of +-2048 inside
frequently accessed data in order to accommodate linker relaxations and
improve performance.
@DNedic DNedic changed the title Linker relaxation fixes and improvements Linking fixes and improvements May 20, 2024
@DNedic DNedic changed the title Linking fixes and improvements Linking and relaxation fixes and improvements May 20, 2024
@DNedic DNedic changed the title Linking and relaxation fixes and improvements Linking and linker relaxation fixes and improvements May 20, 2024
@DNedic DNedic changed the title Linking and linker relaxation fixes and improvements Linking and linker relaxation fixes May 20, 2024
@DNedic
Copy link
Contributor Author

DNedic commented May 21, 2024

The toolchain does not appear to generate gp relative loads still, does zig utilize this feature?

@DNedic
Copy link
Contributor Author

DNedic commented May 22, 2024

It does appear that relaxation is not enabled in zig: ziglang/zig#3451, I believe this should still be merged now as espressif/esp example (and other projects utilizing espressif-riscv) are broken.

@mattnite
Copy link
Contributor

@DNedic thank you!

@mattnite mattnite merged commit 1b1e3e6 into ZigEmbeddedGroup:main May 22, 2024
3 checks passed
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.

2 participants