[LLVMbugs] [Bug 6144] New: GP is used before restored after a library call

bugzilla-daemon at cs.uiuc.edu bugzilla-daemon at cs.uiuc.edu
Tue Jan 26 00:25:09 PST 2010


           Summary: GP is used before restored after a library call
           Product: new-bugs
           Version: unspecified
          Platform: PC
        OS/Version: Linux
            Status: ASSIGNED
          Keywords: ABI
          Severity: normal
          Priority: P2
         Component: new bugs
        AssignedTo: bruno.cardoso at gmail.com
        ReportedBy: joe_shuchang_zhou at yahoo.com
                CC: llvmbugs at cs.uiuc.edu

; ModuleID = 'gp.c'
target datalayout =
target triple = "i386-pc-linux-gnu"

@.str = private constant [3 x i8] c"hi\00", align 1 ; <[3 x i8]*> [#uses=1]
@i = common global i32 0                          ; <i32*> [#uses=1]

define i32 @main() nounwind {
  %0 = tail call i32 @puts(i8* getelementptr inbounds ([3 x i8]* @.str, i32 0,
i32 0)) nounwind ; <i32> [#uses=0]
  store i32 3, i32* @i, align 4
  ret i32 0

declare i32 @puts(i8* nocapture) nounwind

Code above segfaults after following commands.
llc -O0 -mcpu=r6000 -march=mips -mattr=+o32 gp.ll -o gp.s
mipsel-unknown-linux-gnu-gcc -mips3 gp.s -o gp

By GDB, it is because in assembly we have
        lw      $25, %call16(puts)($gp)
        jalr    $25
        lw      $2, %got(i)($gp)
                           ~~~~~$gp is used before restored
        lw      $3, 16($sp)
        addiu   $4, $zero, 3
        addu    $gp, $zero, $3
        sw      $4, 0($2)

Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.

More information about the llvm-bugs mailing list