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

Move the gp register, to allow the compiler to leverage gp to access … #533

Merged
merged 1 commit into from
Feb 25, 2025

Conversation

cnlohr
Copy link
Owner

@cnlohr cnlohr commented Feb 23, 2025

…the first part of ram. This produces smaller executables in general. I don't know why the original startup code pointed at 0x20000800. You can reach all of the first part of ram by setting it to 0x200003fc

…the first part of ram. This produces smaller executables in general. I don't know why the original startup code pointed at 0x20000800. You can reach all of the first part of ram by setting it to 0x200003fc
@TommyMurphyTM1234
Copy link
Contributor

I don't know why the original startup code pointed at 0x20000800.

I don't know if this is discussion about $gp might help at all?

@monte-monte
Copy link
Contributor

Yeah, it seems they just copepasted it from the chips with bigger ram. But if gp is used as described here https://gnu-mcu-eclipse.github.io/arch/riscv/programmer/#the-gp-global-pointer-register why does this change produces effect? If all 2K fit in negative region of 12bit offset?

@cnlohr
Copy link
Owner Author

cnlohr commented Feb 23, 2025

It looks like it might be primarily a GCC bug. It SHOULD be able to leverage 0x20000800 But, in practice, even with GCC v14.2.0-3 it still doesn't know how to use it appropriately.

@TommyMurphyTM1234
Copy link
Contributor

It looks like it might be primarily a GCC bug. It SHOULD be able to leverage 0x20000800 But, in practice, even with GCC v14.2.0-3 it still doesn't know how to use it appropriately.

Do you happen to have a reproducible test case? If this is a bug in GCC then it should ideally be logged upstream. Although isn't the $gp primarily used for linker relaxation so any issue in this context may actually be with the Binutils linker rather than GCC per se?

@monte-monte
Copy link
Contributor

monte-monte commented Feb 24, 2025

@TommyMurphyTM1234 I compiled a project with different values for gp. Only when offset is a big negative number gcc seems to ignore the existence of gp. If you set gp = 0 then it works (the positive portion of 12bit)
I was building a rv003usb bootloader (for reference).

@cnlohr
Copy link
Owner Author

cnlohr commented Feb 24, 2025

Before submitting this, I also want to try adding -ffunction-sections - there seems to be some situations where GCC will not strip unused functions.

Also, as we discussed on the Discord. We cannot find a reason why GCC can't use the full +/- 2k Range, but, it does seem to effectively use the +/- 1k range.

@cnlohr
Copy link
Owner Author

cnlohr commented Feb 25, 2025

We already use -ffunction-sections it turned out, and I was just misusing the cflags in my test. All is well. Still need to make this change so I am submitting it.

@cnlohr cnlohr merged commit 565bc54 into master Feb 25, 2025
166 checks passed
@cnlohr cnlohr deleted the move_gp branch February 25, 2025 23:11
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