This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: [PATCH: PR gas/11323] Add R_ARM_GOT_PREL relocation to arm assembler
- From: Richard Earnshaw <rearnsha at arm dot com>
- To: Carrot Wei <carrot at google dot com>
- Cc: binutils at sourceware dot org
- Date: Mon, 15 Mar 2010 08:51:35 +0000
- Subject: Re: [PATCH: PR gas/11323] Add R_ARM_GOT_PREL relocation to arm assembler
- References: <7587b291003150137x3f5a3efqdbe1149c15d8ff2f@mail.gmail.com>
On Mon, 2010-03-15 at 16:37 +0800, Carrot Wei wrote:
> Hi
>
> As described in http://sourceware.org/bugzilla/show_bug.cgi?id=11323, this
> patch processes following expression
>
> .word var(GOTABS)-(.LPIC0+4)
>
> And produces a relocation of type R_ARM_GOT_PREL.
>
> This patch has been tested by "make check-gas".
>
I understand why you've done it this way, but I don't like the fact that
the (GOTABS) annotation leads to a GOT_PREL relocation. I think the
correct way of expressing this is to have a GOT_PREL annotation itself,
and then to factor compensation for the addend into the remainder of the
expression:
So, mathematically
var(GOT_PREL) = &GOT_SLOT(var) - .
and the expression that should then be used in the assembly should
compensate for this:
.word var(GOT_PREL) - (.LPIC0+4 - .)
The advantage of this way of expressing things is that we've now got two
parts to the expression: a var (with relocation type) and and addend
(that's constant). Further, if the addend is zero, then the expression
collapses naturally to '.word var(GOT_PREL)' and we still get exactly
the right output.
R.
> thanks
> Wei Guozhi
>
> bfd/
> 2010-03-15 Wei Guozhi <carrot@google.com>
>
> PR gas/11323
> * bfd-in2.h (enum bfd_reloc_code_real): New BFD_RELOC_* types.
> * elf32-arm.c (elf32_arm_reloc_map): New BFD_RELOC_* to R_ARM_* maps.
> * libbfd.h (bfd_reloc_code_real_names): New BFD_RELOC_* names.
> * reloc.c (comments): Document the new relocations.
>
> gas/
> 2010-03-15 Wei Guozhi <carrot@google.com>
>
> PR gas/11323
> * config/tc-arm.c (reloc_names): New relocation names.
> (md_apply_fix): New case for BFD_RELOC_ARM_GOT_ABS.
> (tc_gen_reloc): New case for BFD_RELOC_ARM_GOT_PREL.
> * doc/c-arm.texi (ARM-Relocations): Document the new relocation.
>
> gas/testsuite
> 2010-03-15 Wei Guozhi <carrot@google.com>
>
> PR gas/11323
> * gas/arm/got_prel.s: New test case.
> * gas/arm/got_prel.d: Likewise.
>
>
> Index: bfd-in2.h
> ===================================================================
> RCS file: /cvs/src/src/bfd/bfd-in2.h,v
> retrieving revision 1.507
> diff -u -r1.507 bfd-in2.h
> --- bfd-in2.h 8 Feb 2010 20:28:43 -0000 1.507
> +++ bfd-in2.h 15 Mar 2010 08:07:00 -0000
> @@ -3114,6 +3114,8 @@
> BFD_RELOC_ARM_RELATIVE,
> BFD_RELOC_ARM_GOTOFF,
> BFD_RELOC_ARM_GOTPC,
> + BFD_RELOC_ARM_GOT_ABS,
> + BFD_RELOC_ARM_GOT_PREL,
>
> /* ARM thread-local storage relocations. */
> BFD_RELOC_ARM_TLS_GD32,
>
>
> Index: elf32-arm.c
> ===================================================================
> RCS file: /cvs/src/src/bfd/elf32-arm.c,v
> retrieving revision 1.227
> diff -u -r1.227 elf32-arm.c
> --- elf32-arm.c 4 Mar 2010 17:16:08 -0000 1.227
> +++ elf32-arm.c 15 Mar 2010 08:07:02 -0000
> @@ -1721,6 +1721,8 @@
> {BFD_RELOC_ARM_RELATIVE, R_ARM_RELATIVE},
> {BFD_RELOC_ARM_GOTOFF, R_ARM_GOTOFF32},
> {BFD_RELOC_ARM_GOTPC, R_ARM_GOTPC},
> + {BFD_RELOC_ARM_GOT_ABS, R_ARM_GOT_ABS},
> + {BFD_RELOC_ARM_GOT_PREL, R_ARM_GOT_PREL},
> {BFD_RELOC_ARM_GOT32, R_ARM_GOT32},
> {BFD_RELOC_ARM_PLT32, R_ARM_PLT32},
> {BFD_RELOC_ARM_TARGET1, R_ARM_TARGET1},
>
>
> Index: libbfd.h
> ===================================================================
> RCS file: /cvs/src/src/bfd/libbfd.h,v
> retrieving revision 1.227
> diff -u -r1.227 libbfd.h
> --- libbfd.h 8 Feb 2010 20:28:43 -0000 1.227
> +++ libbfd.h 15 Mar 2010 08:07:02 -0000
> @@ -1330,6 +1330,8 @@
> "BFD_RELOC_ARM_RELATIVE",
> "BFD_RELOC_ARM_GOTOFF",
> "BFD_RELOC_ARM_GOTPC",
> + "BFD_RELOC_ARM_GOT_ABS",
> + "BFD_RELOC_ARM_GOT_PREL",
> "BFD_RELOC_ARM_TLS_GD32",
> "BFD_RELOC_ARM_TLS_LDO32",
> "BFD_RELOC_ARM_TLS_LDM32",
>
>
> Index: reloc.c
> ===================================================================
> RCS file: /cvs/src/src/bfd/reloc.c,v
> retrieving revision 1.198
> diff -u -r1.198 reloc.c
> --- reloc.c 21 Feb 2010 22:24:03 -0000 1.198
> +++ reloc.c 15 Mar 2010 08:07:03 -0000
> @@ -2940,6 +2940,10 @@
> BFD_RELOC_ARM_GOTOFF
> ENUMX
> BFD_RELOC_ARM_GOTPC
> +ENUMX
> + BFD_RELOC_ARM_GOT_ABS
> +ENUMX
> + BFD_RELOC_ARM_GOT_PREL
> ENUMDOC
> Relocations for setting up GOTs and PLTs for shared libraries.
>
>
> Index: config/tc-arm.c
> ===================================================================
> RCS file: /cvs/src/src/gas/config/tc-arm.c,v
> retrieving revision 1.437
> diff -u -r1.437 tc-arm.c
> --- config/tc-arm.c 5 Mar 2010 10:41:04 -0000 1.437
> +++ config/tc-arm.c 15 Mar 2010 08:19:41 -0000
> @@ -16191,7 +16191,8 @@
> { "tlsldm", BFD_RELOC_ARM_TLS_LDM32}, { "TLSLDM", BFD_RELOC_ARM_TLS_LDM32},
> { "tlsldo", BFD_RELOC_ARM_TLS_LDO32}, { "TLSLDO", BFD_RELOC_ARM_TLS_LDO32},
> { "gottpoff",BFD_RELOC_ARM_TLS_IE32}, { "GOTTPOFF",BFD_RELOC_ARM_TLS_IE32},
> - { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32}
> + { "tpoff", BFD_RELOC_ARM_TLS_LE32}, { "TPOFF", BFD_RELOC_ARM_TLS_LE32},
> + { "gotabs", BFD_RELOC_ARM_GOT_ABS}, { "GOTABS", BFD_RELOC_ARM_GOT_ABS }
> };
> #endif
>
> @@ -20477,7 +20478,13 @@
> if (fixP->fx_done || !seg->use_rela_p)
> md_number_to_chars (buf, 0, 4);
> break;
> -
> +
> + case BFD_RELOC_ARM_GOT_ABS:
> + fixP->fx_r_type = BFD_RELOC_ARM_GOT_PREL;
> + if (fixP->fx_done || !seg->use_rela_p)
> + md_number_to_chars (buf, value, 4);
> + break;
> +
> case BFD_RELOC_ARM_TARGET2:
> /* TARGET2 is not partial-inplace, so we need to write the
> addend here for REL targets, because it won't be written out
> @@ -21062,6 +21069,7 @@
> #ifdef OBJ_ELF
> case BFD_RELOC_ARM_GOT32:
> case BFD_RELOC_ARM_GOTOFF:
> + case BFD_RELOC_ARM_GOT_PREL:
> case BFD_RELOC_ARM_PLT32:
> case BFD_RELOC_ARM_TARGET1:
> case BFD_RELOC_ARM_ROSEGREL32:
>
>
> Index: doc/c-arm.texi
> ===================================================================
> RCS file: /cvs/src/src/gas/doc/c-arm.texi,v
> retrieving revision 1.68
> diff -u -r1.68 c-arm.texi
> --- doc/c-arm.texi 18 Feb 2010 10:56:27 -0000 1.68
> +++ doc/c-arm.texi 15 Mar 2010 08:19:42 -0000
> @@ -452,7 +452,8 @@
> @code{TLSGD},
> @code{TLSLDM},
> @code{TLSLDO},
> -@code{GOTTPOFF}
> +@code{GOTTPOFF},
> +@code{GOTABS}
> and
> @code{TPOFF}.
>
> gas/arm/got_prel.s
> ======================================================
> .code 16
> .text
> .Ltext0:
> .section .text.foo,"ax",%progbits
> .align 2
> .global foo
> .code 16
> .thumb_func
> .type foo, %function
> foo:
> .fnstart
> ldr r3, .L3
> .LPIC0:
> add r3, pc
> ldr r3, [r3]
> ldr r2, [r3]
> str r0, [r3]
> mov r0, r2
> bx lr
> .align 2
> .L3:
> .word i(GOTABS) - (.LPIC0+4)
> .fnend
>
>
> gas/arm/got_prel.d
> ======================================================
> # name: R_ARM_GOT_PREL relocation
> # source: got_prel.s
> # as: -march=armv5te -meabi=5
> # readelf: -x 4 -r
>
> Relocation section '.rel.text.foo' at offset 0x3f0 contains 1 entries:
> Offset Info Type Sym.Value Sym. Name
> 00000010 00000c60 R_ARM_GOT_PREL 00000000 i
>
> Relocation section '.rel.ARM.exidx.text.foo' at offset 0x3f8 contains 2 entries:
> Offset Info Type Sym.Value Sym. Name
> 00000000 0000042a R_ARM_PREL31 00000000 .text.foo
> 00000000 00000d00 R_ARM_NONE 00000000 __aeabi_unwind_cpp_pr0
>
> Hex dump of section '.text.foo':
> NOTE: This section has relocations against it, but these have NOT
> been applied to this dump.
> 0x00000000 034b7b44 1b681a68 1860101c 7047c046 .K{D.h.h.`..pG.F
> 0x00000010 0a000000 ....