gcc 4.8: "invalid expression as operand" in aarch64 inline asm

Bug #1270789 reported by Will Newton
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Linaro GCC
Fix Released
Undecided
Kugan Vivekanandarajah
gcc
Fix Released
Medium
gcc-4.8 (Ubuntu)
Fix Released
Undecided
Unassigned

Bug Description

The attached pre-processed source fails with:

# aarch64-linux-gnu-gcc -std=gnu99 -fgnu89-inline -O -Wall -Winline -Wwrite-strings -fmerge-all-constants -frounding-math -g -Wstrict-prototypes malloc.i
malloc.c: In function ‘__libc_mallopt’:
malloc.c:4761:16: error: invalid 'asm': invalid expression as operand

Splitting this inline asm out into a smaller testcase does not seem to reproduce the issue. It's possible this is a bug in the source file, but it's not clear from gcc's output what the problem is.

Related branches

Revision history for this message
Will Newton (will-newton) wrote :
Changed in gcc-linaro:
assignee: nobody → Kugan Vivekanandarajah (kugan-vivekanandarajah)
Changed in gcc-linaro:
status: New → In Progress
Revision history for this message
Kugan Vivekanandarajah (kugan-vivekanandarajah) wrote :

Seems to be an issue with alignment calculation in
aarch64_classify_address.

for rtl of the form (lo_sum:DI (reg/f:DI 132)
    (symbol_ref:DI ("*.LANCHOR4") [flags 0x182])) we are currently
calculating align of 8bits and due to this the following statement
returns false. This causes output_addr_const (in gcc/final.c) to fail.

 return ((INTVAL (offs) & (ref_size - 1)) == 0
                      && ((align / BITS_PER_UNIT) & (ref_size - 1)) == 0);

AFIK, align of 8bits is not correct here.

Revision history for this message
In , Kuganv (kuganv) wrote :

Created attachment 32017
pre processed source

This issue is originally reported in https://bugs.launchpad.net/gcc-linaro/+bug/1270789

The attached pre-processed source fails with:

# aarch64-linux-gnu-gcc -std=gnu99 -fgnu89-inline -O -Wall -Winline -Wwrite-strings -fmerge-all-constants -frounding-math -g -Wstrict-prototypes malloc.i
malloc.c: In function ‘__libc_mallopt’:
malloc.c:4761:16: error: invalid 'asm': invalid expression as operand

Splitting this inline asm out into a smaller testcase does not seem to reproduce the issue. It's possible this is a bug in the source file, but it's not clear from gcc's output what the problem is.

Seems to be an issue with alignment calculation in
aarch64_classify_address.

for rtl of the form (lo_sum:DI (reg/f:DI 132)
    (symbol_ref:DI ("*.LANCHOR4") [flags 0x182])) we are currently
calculating align of 8bits and due to this the following statement
returns false. This causes output_addr_const (in gcc/final.c) to fail.

 return ((INTVAL (offs) & (ref_size - 1)) == 0
                      && ((align / BITS_PER_UNIT) & (ref_size - 1)) == 0);

AFIK, align of 8bits is not correct here.

GCC version and config:
arm-none-linux-gnueabi-gcc -v
Using built-in specs.
COLLECT_GCC=/home/kugan/work/builds/gcc-fsf-trunk/tools/bin/arm-none-linux-gnueabi-gcc
COLLECT_LTO_WRAPPER=/home/kugan/work/builds/gcc-fsf-trunk/tools/libexec/gcc/arm-none-linux-gnueabi/4.9.0/lto-wrapper
Target: arm-none-linux-gnueabi
Configured with: /home/kugan/work/sources/gcc-fsf/trunk/configure --target=arm-none-linux-gnueabi --prefix=/home/kugan/work/builds/gcc-fsf-trunk/tools --with-sysroot=/home/kugan/work/builds/gcc-fsf-trunk/sysroot-arm-none-linux-gnueabi --disable-libssp --disable-libgomp --disable-libmudflap --enable-languages=c,c++ --with-arch=armv7-a --with-fpu=vfpv3-d16 --with-float=softfp --with-thumb
Thread model: posix
gcc version 4.9.0 20130922 (experimental) (GCC)

Revision history for this message
In , Kuganv (kuganv) wrote :

Created attachment 32018
Proposed patch

Revision history for this message
In , Kuganv (kuganv) wrote :

I am sorry that I entered wrong gcc -v (cut and paste error). It is an aarch64 issue and the correct gcc -v is below:

aarch64-none-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=/home/kugan/work/builds/gcc-fsf-trunk/tools/bin/aarch64-none-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/home/kugan/work/builds/gcc-fsf-trunk/tools/libexec/gcc/aarch64-none-linux-gnu/4.9.0/lto-wrapper
Target: aarch64-none-linux-gnu
Configured with: /home/kugan/work/sources/gcc-fsf/trunk/configure --target=aarch64-none-linux-gnu --prefix=/home/kugan/work/builds/gcc-fsf-trunk/tools --without-headers --with-newlib --disable-shared --disable-threads --disable-libssp --disable-libgomp --disable-libmudflap --disable-libatomic --without-libquadmath --disable-libquadmath --enable-languages=c
Thread model: single
gcc version 4.9.0 20130922 (experimental) (GCC)

Revision history for this message
In , Pinskia (pinskia) wrote :

Here is a reduced testcase:
static unsigned long global_max_fast;
int __libc_mallopt (int param_number, int value)
{
 __asm__ __volatile__ ("# %[_SDT_A2]" :: [_SDT_A2] "nor" ((global_max_fast)));
 global_max_fast = 1;
}

Revision history for this message
In , Ramana-gcc (ramana-gcc) wrote :

(In reply to Kugan from comment #1)
> Created attachment 32018 [details]
> Proposed patch

Please submit patches on <email address hidden>

Revision history for this message
In , Kuganv (kuganv) wrote :

There is a rgression with this patch in qemu aarch64-none-linux-gnu for pr38151.c.

pr38151.c:(.text+0x10c): relocation truncated to fit:
R_AARCH64_LDST64_ABS_LO12_NC against `.rodata'
collect2: error: ld returned 1 exit status

asm diff is as shown below.

< add x0, x0, :lo12:.LANCHOR0
< ldr x0, [x0]
---
> ldr x0, [x0,#:lo12:.LANCHOR0]

If I however increase the alignment of .rodata where .LANCHOR0 is
defined, this passes. Is alignment of BITS_PER_UNIT valid for
SYMBOL_REF? If I change it as I am doing this attached patch, is there
anything else I need to do. Any tips?

Revision history for this message
In , Kugan (kugan) wrote :

Author: kugan
Date: Sun Mar 30 22:41:59 2014
New Revision: 208949

URL: http://gcc.gnu.org/viewcvs?rev=208949&root=gcc&view=rev
Log:
PR target/60034
* aarch64/aarch64.c (aarch64_classify_address): Fix alignment for
section anchor.

PR target/60034
* gcc.target/aarch64/pr60034.c: New file.

Added:
    trunk/gcc/testsuite/gcc.target/aarch64/pr60034.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/config/aarch64/aarch64.c
    trunk/gcc/testsuite/ChangeLog

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package gcc-4.8 - 4.8.2-19ubuntu1

---------------
gcc-4.8 (4.8.2-19ubuntu1) trusty; urgency=medium

  * Merge with Debian; remaining changes:
    - Build from the upstream source.
    - Don't build the libgcc packages, now built from gcc-4.9.

gcc-4.8 (4.8.2-19) unstable; urgency=medium

  * Update to SVN 20140404 (r209122) from the gcc-4_8-branch.
    - Fix PR rtl-optimization/60700 (wrong code on x86),
      PR rtl-optimization/57637 (wrong code on ARM in SPEC2000),
      PR target/60039 (SH), PR ada/60703.

  [ Matthias Klose ]
  * Include include and include-fixed header files into the stage1
    gcc-4.8 package.
  * Explicitly configure with --disable-multilib on sparc64 when no
    multilibs are requested (Helmut Grohne). Closes: #743342.
  * Fix PR target/60034 (AArch64), taken from the trunk. LP: #1270789.
  * Update ada-ppc64.diff from the gnat-4.9 package, fixing the gnat build
    on powerpc.
  * Fix PR target/60609 (ARM), proposed patch (Charles Baylis). LP: #1295653.
  * Build libphobos for armel and armhf.
  * Include the gnu triplet prefixed gcov and gcc-{ar,nm,ranlib} binaries.
  * Stop building ppc64el from the ibm branch, now integrated in the fsf
    branch.

  [ Iain Buclaw ]
  * Update the GDC frontend (20140401).
 -- Matthias Klose <email address hidden> Fri, 04 Apr 2014 19:36:41 +0200

Changed in gcc-4.8 (Ubuntu):
status: New → Fix Released
Revision history for this message
In , Ramana-gcc (ramana-gcc) wrote :

Fixed on trunk for 4.9.0.

Revision history for this message
Kugan Vivekanandarajah (kugan-vivekanandarajah) wrote :
Changed in gcc-linaro:
status: In Progress → Fix Released
Changed in gcc:
importance: Unknown → Medium
status: Unknown → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

Bug watches keep track of this bug in other bug trackers.