[Bug 1739392] [NEW] [aarch64] wrong symbol address

goto 1739392 at bugs.launchpad.net
Wed Dec 20 09:43:44 UTC 2017


Public bug reported:

gcc-aarch64-linux-gnu package in bionic has gcc version 7.2.0.

I have a bug with relocation symbols in this version.
It seems to be fixed in gcc version 7.2.1 (tested with gcc-linaro-7.2.1-2017.11 toolchain). Could you please update the package?

Thank you!

Test case:
``` test.c
struct ld_symbol;
extern struct ld_symbol _test_start, _test_end;

unsigned long long test(void)
{
    unsigned long long test_start = (unsigned long long)&_test_start;
    unsigned long long test_end = (unsigned long long)&_test_end;
    return test_end - test_start;
}
```

``` script.ld
OUTPUT_ARCH(aarch64)
OUTPUT_FORMAT(elf64-littleaarch64)
SECTIONS
{
    _test_start = .;
    .text :
    {
        *(.text)
    }
    _test_end = .;
    . += 0xFFFF0000;
}
```

Compile with:
```
aarch64-linux-gnu-gcc -O1 -c test.c -o test.o
aarch64-linux-gnu-objdump -ld test.o
aarch64-linux-gnu-ld -o test.elf -nostdlib --script script.ld --entry test test.o
aarch64-linux-gnu-objdump -ld test.elf
```

Bad (current):
```
test.o:
test():
   0:	90000001 	adrp	x1, 0 <_test_end>
   4:	f9400021 	ldr	x1, [x1]
   8:	90000000 	adrp	x0, 0 <_test_start>
   c:	f9400000 	ldr	x0, [x0]
  10:	cb000020 	sub	x0, x1, x0
  14:	d65f03c0 	ret

test.elf:
test(): 
   0:	907fff81 	adrp	x1, ffff0000 <_test_end+0xfffeffe8> 
   4:	f9401421 	ldr	x1, [x1, #40] 
   8:	907fff80 	adrp	x0, ffff0000 <_test_end+0xfffeffe8> 
   c:	f9401000 	ldr	x0, [x0, #32] 
  10:	cb000020 	sub	x0, x1, x0 
  14:	d65f03c0 	ret
```

Good:
```
test():
   0:	90000001 	adrp	x1, 0 <_test_end>
   4:	91000021 	add	x1, x1, #0x0
   8:	90000000 	adrp	x0, 0 <_test_start>
   c:	91000000 	add	x0, x0, #0x0
  10:	cb000020 	sub	x0, x1, x0
  14:	d65f03c0 	ret
```

** Affects: gcc-defaults (Ubuntu)
     Importance: Undecided
         Status: New

-- 
You received this bug notification because you are a member of Ubuntu
Foundations Bugs, which is subscribed to gcc-defaults in Ubuntu.
https://bugs.launchpad.net/bugs/1739392

Title:
  [aarch64] wrong symbol address

Status in gcc-defaults package in Ubuntu:
  New

Bug description:
  gcc-aarch64-linux-gnu package in bionic has gcc version 7.2.0.

  I have a bug with relocation symbols in this version.
  It seems to be fixed in gcc version 7.2.1 (tested with gcc-linaro-7.2.1-2017.11 toolchain). Could you please update the package?

  Thank you!

  Test case:
  ``` test.c
  struct ld_symbol;
  extern struct ld_symbol _test_start, _test_end;

  unsigned long long test(void)
  {
      unsigned long long test_start = (unsigned long long)&_test_start;
      unsigned long long test_end = (unsigned long long)&_test_end;
      return test_end - test_start;
  }
  ```

  ``` script.ld
  OUTPUT_ARCH(aarch64)
  OUTPUT_FORMAT(elf64-littleaarch64)
  SECTIONS
  {
      _test_start = .;
      .text :
      {
          *(.text)
      }
      _test_end = .;
      . += 0xFFFF0000;
  }
  ```

  Compile with:
  ```
  aarch64-linux-gnu-gcc -O1 -c test.c -o test.o
  aarch64-linux-gnu-objdump -ld test.o
  aarch64-linux-gnu-ld -o test.elf -nostdlib --script script.ld --entry test test.o
  aarch64-linux-gnu-objdump -ld test.elf
  ```

  Bad (current):
  ```
  test.o:
  test():
     0:	90000001 	adrp	x1, 0 <_test_end>
     4:	f9400021 	ldr	x1, [x1]
     8:	90000000 	adrp	x0, 0 <_test_start>
     c:	f9400000 	ldr	x0, [x0]
    10:	cb000020 	sub	x0, x1, x0
    14:	d65f03c0 	ret

  test.elf:
  test(): 
     0:	907fff81 	adrp	x1, ffff0000 <_test_end+0xfffeffe8> 
     4:	f9401421 	ldr	x1, [x1, #40] 
     8:	907fff80 	adrp	x0, ffff0000 <_test_end+0xfffeffe8> 
     c:	f9401000 	ldr	x0, [x0, #32] 
    10:	cb000020 	sub	x0, x1, x0 
    14:	d65f03c0 	ret
  ```

  Good:
  ```
  test():
     0:	90000001 	adrp	x1, 0 <_test_end>
     4:	91000021 	add	x1, x1, #0x0
     8:	90000000 	adrp	x0, 0 <_test_start>
     c:	91000000 	add	x0, x0, #0x0
    10:	cb000020 	sub	x0, x1, x0
    14:	d65f03c0 	ret
  ```

To manage notifications about this bug go to:
https://bugs.launchpad.net/ubuntu/+source/gcc-defaults/+bug/1739392/+subscriptions



More information about the foundations-bugs mailing list