This repository has been archived by the owner on Apr 11, 2024. It is now read-only.
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.
With "medium" code model, we call a function with a pair of PCALAU12I
and JIRL instructions. Currently the assembler produces something like:
This is problematic:
(1) If we just apply the R_LARCH_PCALA_LO12 relocation following its
definition, we'll got wrong result: jirl is 2RI16-type but
R_LARCH_PCALA_LO12 is for 2RI12-type.
(2) The linker need to produce a PLT entry if
g
is an externalfunction. Currently ld.bfd assumes if there is an R_LARCH_PCALA_HI20
against an external symbol,
g
"should be" an external function. Butthis assumption is only true if the programmers (and the compiler) do
not make any error. Consider if a programmer moved
data
(which is nota function) from one shared object into another, but forgot to update
in the code. Now the linker generates a "PLT entry" for data without
any diagnostic, and
ld.d
instruction loads two instructions in thePLT. The programmer can only notice something wrong (as a mysterious
crash or bad output) at runtime.
To avoid those issues, we may add extra semantics to R_LARCH_PCALA_LO12
like "if it's applied to a jirl instruction, blah blah..." but it's too
tricky and introduces extra complexity into the linker: ld.bfd is
designed to process the linking in multiple passes, and if we load the
actual content of text segment to inspect if there is a jirl
instruction, the memory footprint of linker will be increased
significantly. So it's better to use a new relocation type for function
call in medium code model.