https://gcc.gnu.org/bugzilla/show_bug.cgi?id=98618

            Bug ID: 98618
           Summary: aarch64: oob adrp offset causes relocation truncated
                    to fit: R_AARCH64_ADR_PREL_PG_HI21
           Product: gcc
           Version: 8.4.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nsz at gcc dot gnu.org
  Target Milestone: ---

gcc-8 and earlier can generate adrp with out of bounds offset
for hidden and local symbols.

i haven't yet found the change that fixed this in gcc-9.

this affects glibc since
https://sourceware.org/git/?p=glibc.git;a=commit;h=2f056e8a5dd4dc0f075413f931e82cede37d1057

$ cat bug.c
long n;
struct s { long a[100]; };
extern struct s obj __attribute__((visibility("hidden")));
void foo()
{
  long *a = obj.a;
  a[n - 0x70000000 + 35] = n;
  a[0x6ffffdff - n + 35 + 6 + 16 + 3] = n;
}

$ gcc -fPIC -O2 -c bug.c
$ objdump -rd bug.o

bug.o:     file format elf64-littleaarch64


Disassembly of section .text:

0000000000000000 <foo>:
   0:   90000000        adrp    x0, 8 <foo+0x8>
                        0: R_AARCH64_ADR_GOT_PAGE       n
   4:   90000002        adrp    x2, 0 <obj>
                        4: R_AARCH64_ADR_PREL_PG_HI21   obj-0x37ffffee8
   8:   91000042        add     x2, x2, #0x0
                        8: R_AARCH64_ADD_ABS_LO12_NC    obj-0x37ffffee8
   c:   90000001        adrp    x1, 0 <obj>
                        c: R_AARCH64_ADR_PREL_PG_HI21   obj+0x37ffff1d8
  10:   f9400000        ldr     x0, [x0]
                        10: R_AARCH64_LD64_GOT_LO12_NC  n
  14:   91000021        add     x1, x1, #0x0
                        14: R_AARCH64_ADD_ABS_LO12_NC   obj+0x37ffff1d8
  18:   f9400000        ldr     x0, [x0]
  1c:   cb000fe3        neg     x3, x0, lsl #3
  20:   f8207840        str     x0, [x2, x0, lsl #3]
  24:   f8216860        str     x0, [x3, x1]
  28:   d65f03c0        ret
$ gcc -shared bug.o obj.o
bug.o: In function `foo':
bug.c:(.text+0x4): relocation truncated to fit: R_AARCH64_ADR_PREL_PG_HI21
against symbol `obj' defined in .data section in obj.o
bug.c:(.text+0xc): relocation truncated to fit: R_AARCH64_ADR_PREL_PG_HI21
against symbol `obj' defined in .data section in obj.o
collect2: error: ld returned 1 exit status

Reply via email to