bug-binutils
[Top][All Lists]
Advanced

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

Linker does not support R_ARM_GOT_BREL with -fdpic


From: Dmitrii Rodionov
Subject: Linker does not support R_ARM_GOT_BREL with -fdpic
Date: Tue, 9 Oct 2018 18:33:00 +0300
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0

Hello!

What do I need:
I have MMU-less ARM CPU with XIP (eXecution In Place). I need ELF file with .text and .plt sections into FLASH. It means that @plt entries must be _NOT_ pc-relative.

commit a0c3048e3f397a595a14208e82e21399131f782b
Author: Tom Tromey <address@hidden>
Date:   Mon Oct 8 16:39:29 2018 -0600



I have configured binutils as follows (with default target=arm-linux-gnueabi):

./configure --enable-fdpic --enable-lto --enable-plugins --disable-werror CPPFLAGS=-UFORTIFY_SOURCE --disable-gdb --disable-sim --disable-libdecnumber --disable-readline --prefix=/home/rodionov/gnu/install/ --target=arm-none-eabi
$make
$make install


I have test.c file:
$ cat test.c 
extern void external_func(int a);

volatile int global = 4;

void test(void)
{
         external_func(global);
}

Obtain object file:
$ arm-none-eabi-gcc --version
arm-none-eabi-gcc (GNU Tools for Arm Embedded Processors 7-2018-q2-update) 7.3.1 20180622 (release) [ARM/embedded-7-branch revision 261907]

$ arm-none-eabi-gcc -fpic -c -mno-pic-data-is-text-relative test.c -o test.o

Try to link:
$ ./arm-none-eabi-ld --version
GNU ld (GNU Binutils) 2.31.51.20181008

$ ./arm-none-eabi-ld -fdpic -shared -no-pic-data-is-text-relative test.o -o test.so
But resulting @plt is pc-relative and cannot be used with XIP:
000081d4 <address@hidden>:
    81d4:       e28fc600        add     ip, pc, #0, 12
    81d8:       e28cca10        add     ip, ip, #16, 20 ; 0x10000
    81dc:       e5bcf0d8        ldr     pc, [ip, #216]! ; 0xd8



I have found into code (binutils-gdb/bfd/elf32-arm.c) plt that I want:
 2288 /* ARM FDPIC PLT entry.  */                                                     
 2289 /* The last 5 words contain PLT lazy fragment code and data.  */                
 2290 static const bfd_vma elf32_arm_fdpic_plt_entry [] =                             
 2291   {                                                                             
 2292     0xe59fc008,    /* ldr     r12, .L1 */                                       
 2293     0xe08cc009,    /* add     r12, r12, r9 */                                   
 2294     0xe59c9004,    /* ldr     r9, [r12, #4] */                                  
 2295     0xe59cf000,    /* ldr     pc, [r12] */                                      
 2296     0x00000000,    /* L1.     .word   foo(GOTOFFFUNCDESC) */                    
 2297     0x00000000,    /* L1.     .word   foo(funcdesc_value_reloc_offset) */       
 2298     0xe51fc00c,    /* ldr     r12, [pc, #-12] */                                
 2299     0xe92d1000,    /* push    {r12} */                                          
 2300     0xe599c004,    /* ldr     r12, [r9, #4] */                                  
 2301     0xe599f000,    /* ldr     pc, [r9] */                                       
 2302   };


 So, as I can see, I need to reconfigure binutils with --target=arm-linux-uclinuxfdpiceabi to enable -m armelf_linux_fdpiceabi emulation and r9-relative @plt (as above) entry: 

~$ ./configure --enable-fdpic --enable-lto --enable-plugins --disable-werror CPPFLAGS=-UFORTIFY_SOURCE --disable-gdb --disable-sim --disable-libdecnumber --disable-readline --prefix=/home/rodionov/gnu/install/ --target=arm-linux-uclinuxfdpiceabi


Try to link object file with just built linker:
~$ ./arm-linux-uclinuxfdpiceabi-ld -fdpic -shared -m armelf_linux_fdpiceabi test.o -o test.so
./arm-linux-uclinuxfdpiceabi-ld: test.o: in function `test':
test.c:(.text+0x18): dangerous relocation: unsupported relocation

$ readelf -a test.o
...
Relocation section '.rel.text' at offset 0x200 contains 2 entries:
 Offset     Info    Type            Sym.Value  Sym. Name
0000000e  00000d0a R_ARM_THM_CALL    00000000   external_func
00000018  00000b1a R_ARM_GOT_BREL    00000000   global
...

As I can see, the second relocation causes the error: unsupported relocation.


Could anyone help with this situation? Is there a bug into binutils or am I doing something wrong?

Thanks.
Dmitrii Rodionov

 

  


reply via email to

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