Fix the compact patterns for crt0.s and entry.s. #417
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi Guys,
There are two problems here that cause testcases to runtime fail for freedom-e-sdk,
1:
auipc a0, %pcrel_hi(global_pointer)
addi a0, a0, %pcrel_lo(1b)
ld gp, 0(a0)
add gp, gp, a0
la gp, __global_pointer$
.option pop
/* Stack pointer is expected to be initialized before _start */
/* If we're not hart 0, skip the initialization work */
la t0, __metal_boot_hart
bne a0, t0, _skip_init
Obviously my code is wrong here, a0 usually used for function parameters, so if I use it to do anything special, then the value of a0 will be changed. Maybe t0/t1 is more suitable.
When rodata is placed nearly to text, then we can use la to access metal_segment_data_source_start
directly; When the rodata is placed nearly to rwdata, then use the lla.gprel is more suitable. But once the rodata is placed far away from both text and rwdata, generally we should use la.got.gprel to access it. Unfortunately, la.got.gprel cannot work for metal_segment_data_source_start, if LMA and VMA are different in the linker script. Since we need to move the data, including GOT sections, from the LMA to VMA, then we can get the right values of got entries. Therefore, use la.got.gprel to access the metal_segment_data_source_start will get the uninitilaize value.
One of the solution is that - use compact stub to access the metal_segment_data_source_start, just like what we did above, to initialize gp. But we need four instructions and one 8 bytes stub, so the code size will be slightly larger (4 * 4 + 8 = 24 bytes, originally, the la.got.gprel may be relaxed to a 4 bytes ld, so it will be 20 bytes more).