[Bug c/67265] New: [x86] 'asm' operand has impossible constraints with -fstack-check

2015-08-18 Thread gnu at JonnyJD dot net
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67265

Bug ID: 67265
   Summary: [x86] 'asm' operand has impossible constraints with
-fstack-check
   Product: gcc
   Version: 5.2.0
Status: UNCONFIRMED
  Severity: normal
  Priority: P3
 Component: c
  Assignee: unassigned at gcc dot gnu.org
  Reporter: gnu at JonnyJD dot net
  Target Milestone: ---
  Host: i686-linux-gnu

Created attachment 36209
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36209&action=edit
minimal working example (C file)

When compiling a 32 bit build of libx264 (on a 64 bit machine) it works in
general, even with PIC.
However the build breaks when I add -fstack-check to CFLAGS.

The failing code is:

int a, b, c, d, e;
int fn1() {
  __asm__("" : "+r"(c), "+r"(e), "+r"(d), "+r"(a) : ""(b), "mg"(fn1), "mm"(c));
}

(attached as me.c)

This works:
 gcc -O3 -m32 -fPIC -c me.c

This fails (and should work)
 gcc -O3 -m32 -fstack-check -fPIC -c me.c

This also works (as a workaround):
 gcc -O3 -m32 -fstack-check -c me.c


The error message is:
me.c: In function ‘fn1’:
me.c:3:3: error: ‘asm’ operand has impossible constraints
   __asm__("" : "+r"(c), "+r"(e), "+r"(d), "+r"(a) : ""(b), "mg"(fn1),
"mm"(c));
   ^


The related discussion for x264 is here:
https://mailman.videolan.org/pipermail/x264-devel/2015-August/011246.html

The flag -fstack-check is added by default on Arch Linux when building
packages, but also additionally using hardened wrapper, where I also mentioned
the problem:
https://github.com/thestinger/hardening-wrapper/issues/6

I am the maintainer of lib32-libx264 on Arch Linux where the problem came up
originally:
https://aur.archlinux.org/packages/lib32-libx264/

[Bug c/67265] [x86] 'asm' operand has impossible constraints with -fstack-check

2015-08-18 Thread gnu at JonnyJD dot net
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67265

--- Comment #1 from Johannes Dewender  ---
Created attachment 36210
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=36210&action=edit
Makefile with failing, working and workaround flags

I found the bug using gcc 5.2.0 (Arch Linux), but I also tested gcc 5.1.0 and
gcc 4.9.2.
So this is not a brand new bug. Not sure if it did work as expected in versions
before that.