Bug 4079 - Errors in @GOT
Summary: Errors in @GOT
Status: RESOLVED FIXED
Alias: None
Product: binutils
Classification: Unclassified
Component: gas (show other bugs)
Version: 2.17
: P2 enhancement
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2007-02-19 19:40 UTC by Mikulas Patocka
Modified: 2007-08-17 14:13 UTC (History)
1 user (show)

See Also:
Host: i686-pc-linux-gnu
Target: i686-pc-linux-gnu
Build: i686-pc-linux-gnu
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mikulas Patocka 2007-02-19 19:40:49 UTC
There are errors with expressions with @GOT suffix. They can be
manifested in this example:

#include <stdio.h>
__asm__ (".global number; number = 0x12345678");
extern void number;
int main()
{
        printf("%p\n", &number);
        return 0;
}

--- when this program is compiled with -fPIC, it crashes, without -fPIC it
prints 12345678. Note that if you split program to two files, one containing
__asm__ line and the other file containing the rest, compile with -fPIC and
link files statically or dynamically, it succeeds and prints correct value ---
12345678. Static and dynamic linker can process this relocation fine, but
that gas corrupts it if both definition and @GOT reference are in one file.

The error is caused by bad processing of @GOT suffix:

movl $constant@GOT, %eax is assembled as movl $constant, %eax --- which is
wrong. It should move offset in GOT, where pointer to constant is.

movl $symbol+constant@GOT, %eax will ignore the constant.

Gas should at least write error messages and not generate incorrect code when
encountering these constructs. With more work, some of these cases can be
assembled correctly:
movl $.@GOT, %eax is assembled correctly --- special symbol with name "L0\001"
is created and GOT relocation against this symbol is generated. movl
$constant@GOT, %eax could do exactly the same trick, setting the symbol to
constant.

movl $defined_symbol+constant@GOT, %eax could be assembled corectly too by
creating special symbol --- but I don't see any use for such construct.
movl $extern_symbol+constant@GOT, %eax cannot be correctly assembled and error
should be reported (current implementation just forgets the constant).