bug-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

problem with -q


From: Robert Cohn
Subject: problem with -q
Date: Mon, 22 Jul 2002 11:04:52 -0400

I am using the 020719 snapshot of binutils to link on ia64 and linux.

When I use -q,  ld produces an incorrect program.

The symptom of the bug is that there is an address in the data section that
should point to a string, but the address is invalid. Here is what I think is
happening:

There is a reference to the same string in the text section and the data
section. The text section is processed first in elf_link_input_bfd (elflink.h).
Since -q is used, emit_relocs is on and after processing the text section, it
emits the relocation. As part of this processing, it updates st_value in the
symbol by replacing the section relative offset with the absolute address. Next
the data section is processed. When it processes the relocation that refers to
the same symbol, it computes the value by adding in the section beginning, even
though this is already an absolute address (_bfd_elf_rela_local_sym). Is there a
way to make _bfd_elf_rela_local_sym recognize that the symbol is absolute and
not add in the section beginning?

Here is the C source, asm source, and gdb session:
You must compile it cc -O to get the symbol sharing.

char * string = "abc";
main()
{
    printf("%s\n",string);
    return strcmp(string,"abc");

}

Asm code:

 .file "test.c"
 .pred.safe_across_calls p1-p5,p16-p63
 .global string#
 .section .rodata.str1.8,"ams",@progbits,1
 .align 8
.LC0:
 stringz "abc"
.sdata
 .align 8
 .type  string#,@object
 .size  string#,8
string:
 data8 .LC0
 .section .rodata.str1.8,"ams",@progbits,1
 .align 8
.LC1:
 stringz "%s\n"
.text
 .align 16
 .global main#
 .proc main#
main:
 .prologue 12, 34
 .save ar.pfs, r35
 alloc r35 = ar.pfs, 0, 4, 2, 0
 .save rp, r34
 mov r34 = b0
 .body
 addl r32 = @gprel(string#), gp
 addl r36 = @ltoff(.LC1), gp
 ;;
 ld8 r36 = [r36]
 ld8 r37 = [r32]
 mov r33 = r1
 br.call.sptk.many b0 = printf#
 ;;
 mov r1 = r33
 ld8 r36 = [r32]
 ;;
 addl r37 = @ltoff(.LC0), gp
 ;;
 ld8 r37 = [r37]
 br.call.sptk.many b0 = strcmp#
 ;;
 mov ar.pfs = r35
 mov b0 = r34
 br.ret.sptk.many b0
 .endp main#
 .ident "GCC: (GNU) 2.96 20000731 (Red Hat Linux 7.1 2.96-101)"

Here is what happens in gdb:

address@hidden bug]$ cc -O -g -Wl,-q test.c -o test
address@hidden bug]$ ./test
Segmentation fault
address@hidden bug]$ gdb test
GNU gdb Red Hat Linux (5.1-1)
Copyright 2001 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "ia64-redhat-linux"...
(gdb) print string
$1 = 0x80000000000011c0 <Address 0x80000000000011c0 out of bounds>
(gdb)





reply via email to

[Prev in Thread] Current Thread [Next in Thread]