Re: Setting up alpha stack frames

"Peter \"Firefly\" Lund" <firefly@diku.dk>
14 May 2003 00:45:10 -0400

          From comp.compilers

Related articles
Setting up alpha stack frames tim.jones@mail.com (2003-05-06)
Re: Setting up alpha stack frames Len.Lattanzi@Migration.com (2003-05-14)
Re: Setting up alpha stack frames firefly@diku.dk (Peter \Firefly\Lund) (2003-05-14)
Re: Setting up alpha stack frames anton@mips.complang.tuwien.ac.at (2003-05-14)
| List of all articles for this month |
From: "Peter \"Firefly\" Lund" <firefly@diku.dk>
Newsgroups: comp.compilers,comp.arch
Date: 14 May 2003 00:45:10 -0400
Organization: Department of Computer Science, University of Copenhagen
References: 03-05-046
Keywords: architecture
Posted-Date: 14 May 2003 00:45:09 EDT

On Wed, 6 May 2003, Timothy Jones wrote:


> The first problem I had was with alignment. I started with the


Nope. With not knowing the ABI.


> hello:
> nop
> ldgp $gp,0($27)


Read up on the ldgp pseudo-instruction. The expression on the right
is supposed to evaluate at run-time to the address of the instruction
but $27 is the PV register (Procedure Value, I guess... memory is
getting rusty), which is setup to point to the subroutine to jump to
just before the jump is performed (see how printf is called a few
instructions later in the snippet). In other words: 0($27) points to
the nop.


The consequences are that the program doesn't load the correct address
of the GOT (Global Offset Table) which means that everytime your
program needs an immediate longer than 8 bits, it will fetch an
incorrect value from the GOT. It is probably the lda $16,
__tmp_string_0 pseudo instruction that either segfaults (due to use of
an illegal pointer for the GOT start address) or fetches an illegal
address which is then passed to printf.


Always, Always, Always read the ABI before doing low-level stuff like
compiler writing or direct massaging of machine code.


-Peter


PS: Mind the ldgp's after function calls, too.


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.