bug-binutils
[Top][All Lists]
Advanced

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

[Bug ld/10858] New: ld generate broken PIE binaries on MIPS


From: aurelien at aurel32 dot net
Subject: [Bug ld/10858] New: ld generate broken PIE binaries on MIPS
Date: 28 Oct 2009 13:45:05 -0000

Most PIE binaries generated on MIPS are broken. Here is a small testcase to 
demonstrate the problem:

/* compile with cc -pie -fPIE -o fpie fpie.c */

#include <stdio.h>
#include <string.h>

int val0 = 3;
int val1 = 4;

int *vals[2] = {
    &val0,
    &val1
};

int main(void)
{
    printf("val0 is %i\n", *vals[0]);
    printf("val1 is %i\n", *vals[1]);

    return 0;/* compile with cc -pie -fPIE -o fpie fpie.c */

#include <stdio.h>
#include <string.h>

int val0 = 3;
int val1 = 4;

int *vals[2] = {
    &val0,
    &val1
};

int main(void)
{
    printf("val0 is %i\n", *vals[0]);
    printf("val1 is %i\n", *vals[1]);

    return 0;
}

Note that for an unknown reason, gcc 4.3 does not generate a pie binary 
with -pie (not specific to MIPS), so you may want to try it with gcc 4.1.

Such a code crashes on startup during the relocation phase. This is due to a 
wrong ELF header. Compared to a working binutils, val0 and val1 do not appear 
in '.dynsym'. As a consequence '.rel.dyn' is filled with bad entries, causing 
the crash:

Relocation section '.rel.dyn' at offset 0x594 contains 5 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
00000000  00000000 R_MIPS_NONE
00010ab0  00000003 R_MIPS_REL32
00010ab4  00000003 R_MIPS_REL32
00010ad0  ffffff03 R_MIPS_REL32      bad symbol index: 00ffffff
00010ad4  ffffff03 R_MIPS_REL32      bad symbol index: 00ffffff

Manually editing '.rel.dyn' with an hex editor to point the entries to another 
symbol cause the crash to disappear. Of course the value is then wrong.

-- 
           Summary: ld generate broken PIE binaries on MIPS
           Product: binutils
           Version: 2.20
            Status: NEW
          Severity: normal
          Priority: P2
         Component: ld
        AssignedTo: unassigned at sources dot redhat dot com
        ReportedBy: aurelien at aurel32 dot net
                CC: bug-binutils at gnu dot org
 GCC build triplet: mipsel-unknown-linux-gnu
  GCC host triplet: mipsel-unknown-linux-gnu
GCC target triplet: mipsel-unknown-linux-gnu


http://sourceware.org/bugzilla/show_bug.cgi?id=10858

------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.




reply via email to

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