Skip to content

MIPS: .cpsetup broken for n32 #52785

@chmeeedalf

Description

@chmeeedalf
Contributor

MIPS n32 ABI requires '.cpsetup , <off | reg>, ' to generate the following sequence:

sd $gp, off ($sp)
lui $gp, label    // top half
addiu $gp, label  // bottom half
addu $gp, $gp, r

The MIPS code generator currently does not include the final addu, leading to crashes in n32 ABI position independent code.

Activity

chmeeedalf

chmeeedalf commented on Dec 18, 2021

@chmeeedalf
ContributorAuthor

Looking at it more, n32 is supposed to use whatever label, not fixed at __gnu_local_gp

atanasyan

atanasyan commented on Dec 18, 2021

@atanasyan
Collaborator

Could you check that this patch fixes the issue? The patch adds the addu instruction only. __gnu_local_gp is a separate problem.
pr52785.patch.txt

rasul247

rasul247 commented on Dec 18, 2021

@rasul247
chmeeedalf

chmeeedalf commented on Dec 20, 2021

@chmeeedalf
ContributorAuthor

Unfortunately that's incomplete. It's adding the "absolute" address of __gnu_local_gp, which won't work to get a relative address. It really should be doing what is done for N64 below in the function, from what I can tell.

wzssyqa

wzssyqa commented on Feb 3, 2024

@wzssyqa
Contributor

It's due to a typo in MipsTargetELFStreamer::emitDirectiveCpsetup
This patch should work:

-  if (getABI().IsN32()) {
+#if 0
+  // We haven't support -mabicalls -mno-shared yet.
+  if (-mno-shared) {
     MCSymbol *GPSym = MCA.getContext().getOrCreateSymbol("__gnu_local_gp");
     const MipsMCExpr *HiExpr = MipsMCExpr::create(
         MipsMCExpr::MEK_HI, MCSymbolRefExpr::create(GPSym, MCA.getContext()),
@@ -1273,6 +1275,7 @@ void MipsTargetELFStreamer::emitDirectiveCpsetup(unsigned RegNo,
 
     return;
   }
+#endif
added a commit that references this issue on Feb 3, 2024
46bc99d
added a commit that references this issue on Feb 3, 2024
f71a0e8
added a commit that references this issue on Feb 22, 2024
0e9ab65
added a commit that references this issue on Feb 26, 2024
860b6ed
added a commit that references this issue on Feb 27, 2024
3e22471
added a commit that references this issue on Mar 11, 2024
340ba45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @wzssyqa@chmeeedalf@RKSimon@atanasyan@rasul247

      Issue actions

        MIPS: .cpsetup broken for n32 · Issue #52785 · llvm/llvm-project