Fix MIPS __start linker error with default relocation model#171
Open
walruscraft wants to merge 1 commit intosunfishcode:mainfrom
Open
Fix MIPS __start linker error with default relocation model#171walruscraft wants to merge 1 commit intosunfishcode:mainfrom
walruscraft wants to merge 1 commit intosunfishcode:mainfrom
Conversation
Turns out `la $t9, {entry}` generates a CALL16 relocation in PIC
mode, and CALL16 needs the target to be a global symbol. Since
`entry` is pub(super), the linker rightfully complains. Swapped
to lui/addiu which use HI16/LO16 and don't care about visibility.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Embarrassing follow-up to #170 - I introduced a bug in the MIPS startup code.
The
la $t9, {entry}instruction in__startgenerates a CALL16 relocation when compiled with PIC (which is the default relocation model formipsel-unknown-linux-gnu). CALL16 requires the target to be a global symbol, butentryispub(super)so the linker rejects it:I missed this because my test setup happened to use
-C relocation-model=static, which avoids PIC entirely. So it linked fine on my end and I never saw the issue. Anyone using the default relocation model would hit this on their first MIPS build.The fix is to use
lui/addiuinstead ofla. These generate HI16/LO16 relocations which work with local symbols. Still loads the address into$t9for PIC convention, just without going through the GOT.Tested by building a real application (kv) for
mipsel-unknown-linux-gnuwithout the relocation-model workaround. Links and runs correctly under QEMU.Sorry about the mess.