[Bug lto/59626] [4.8/4.9 Regression] /usr/include/bits/unistd.h:173:1: error: inlining failed in call to always_inline 'readlinkat': recursive inlining

2014-04-04 Thread hubicka at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59626

--- Comment #21 from Jan Hubicka hubicka at gcc dot gnu.org ---
Author: hubicka
Date: Fri Apr  4 18:02:31 2014
New Revision: 209123

URL: http://gcc.gnu.org/viewcvs?rev=209123root=gccview=rev
Log:

PR ipa/59626
* lto-cgraph.c (input_overwrite_node): Check that partitioning
flags are set only during streaming.
* ipa.c (process_references, walk_polymorphic_call_targets,
symtab_remove_unreachable_nodes): Drop bodies of always inline
after early inlining.
(symtab_remove_unreachable_nodes): Remove always_inline attribute.
* gcc.dg/lto/pr59626_0.c: New testcase.
* gcc.dg/lto/pr59626_1.c: New testcase.

Added:
trunk/gcc/testsuite/gcc.dg/lto/pr59626_0.c
trunk/gcc/testsuite/gcc.dg/lto/pr59626_1.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/ipa.c
trunk/gcc/lto-cgraph.c
trunk/gcc/testsuite/ChangeLog


[Bug lto/59626] [4.8/4.9 Regression] /usr/include/bits/unistd.h:173:1: error: inlining failed in call to always_inline 'readlinkat': recursive inlining

2014-03-24 Thread rguenth at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59626

--- Comment #20 from Richard Biener rguenth at gcc dot gnu.org ---
Testcase:

int __atoi  (const char *) __asm__(atoi);
extern inline __attribute__((always_inline,gnu_inline))
int atoi (const char *x)
{
  return __atoi (x);
}

int bar (int (*)(const char *));

int main()
{
  return bar (atoi);
}



int bar (int (*fn)(const char *))
{
  return fn (0);
}



[Bug lto/59626] [4.8/4.9 Regression] /usr/include/bits/unistd.h:173:1: error: inlining failed in call to always_inline 'readlinkat': recursive inlining

2014-03-21 Thread rguenth at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59626

--- Comment #17 from Richard Biener rguenth at gcc dot gnu.org ---
Seems to happen quite often when building packages with LTO (see PR51744 for
another major annoyance there).


[Bug lto/59626] [4.8/4.9 Regression] /usr/include/bits/unistd.h:173:1: error: inlining failed in call to always_inline 'readlinkat': recursive inlining

2014-03-21 Thread rguenth at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59626

--- Comment #18 from Richard Biener rguenth at gcc dot gnu.org ---
(In reply to Jakub Jelinek from comment #5)
 But the function doesn't inline itself, that is why it uses the asm alias
 and GCC shouldn't be looking through that and merging the two decls because
 of that.
 
 Breaking this breaks pretty much all of glibc -D_FORTIFY_SOURCE, and there
 really isn't any other way how to write it.
 
 To show the reason for the inline:
 __fortify_function __nonnull ((1, 2)) __wur ssize_t
 __NTH (readlink (const char *__restrict __path, char *__restrict __buf,
  size_t __len))
 {
   if (__bos (__buf) != (size_t) -1)
 {
   if (!__builtin_constant_p (__len))
 return __readlink_chk (__path, __buf, __len, __bos (__buf));
 
   if ( __len  __bos (__buf))
 return __readlink_chk_warn (__path, __buf, __len, __bos (__buf));
 }
   return __readlink_alias (__path, __buf, __len);
 }
 
 The inline must be always_inline, because it is a security matter if it is
 inlined or not, and we want it to expand as a call to __readlink_chk if
 it needs runtime verification, otherwise as a call to the original function,
 not inlined.  So, this is really a LTO/IPA bug.

Note that __readlink_alias was _not_ declared always-inline and thus at least
the call edge (even if eventually re-directing to readlink itself) should
not be considered always-inline.  But we always check the always-inline flag
on the callee decl, even if it was substituted from an alias.  As we throw
away the callgraph edges it's also hard to maintain this edge property there.


[Bug lto/59626] [4.8/4.9 Regression] /usr/include/bits/unistd.h:173:1: error: inlining failed in call to always_inline 'readlinkat': recursive inlining

2014-03-09 Thread nheghathivhistha at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59626

--- Comment #16 from David Kredba nheghathivhistha at gmail dot com ---
Todays Gentoo to tree pushed flac-1.3.0 with gcc-4.9 rev. 208429. The flac
package is still broken in ABI=32 but this should go anyway I think.

/usr/include/bits/stdio2.h: In function
'FLAC__metadata_simple_iterator_get_application_id':
/usr/include/bits/stdio2.h:282:1: error: inlining failed in call to
always_inline 'fread': recursive inlining
 fread (void *__restrict __ptr, size_t __size, size_t __n,
 ^
/usr/include/bits/stdio2.h:295:3: error: called from here
   return __fread_alias (__ptr, __size, __n, __stream);
   ^
make[5]: ***
[/var/tmp/portage/media-libs/flac-1.3.0/temp/ccp3QvqG.ltrans4.ltrans.o] Error 1
make[5]: *** Waiting for unfinished jobs


Called this way:

libtool: link: x86_64-pc-linux-gnu-gcc -m32 -std=gnu99 -shared  -fPIC -DPIC 
.libs/bitmath.o .libs/bitreader.o .libs/bitwriter.o .libs/cpu.o .libs/crc.o
.libs/fixed.o .libs/float.o .libs/format.o .libs/lpc.o .libs/md5.o
.libs/memory.o .libs/metadata_iterators.o .libs/metadata_object.o
.libs/stream_decoder.o .libs/stream_encoder.o .libs/stream_encoder_framing.o
.libs/window.o .libs/ogg_decoder_aspect.o .libs/ogg_encoder_aspect.o
.libs/ogg_helper.o .libs/ogg_mapping.o  -Wl,--whole-archive
ia32/.libs/libFLAC-asm.a -Wl,--no-whole-archive  -Wl,--as-needed -L/usr/lib
-logg -lm  -m32 -flto=4 -fuse-linker-plugin -O2 -march=native -mtune=native
-mno-3dnow -mno-sse4.2 -mno-avx -flto=4 -fuse-linker-plugin -Wl,-O2 -Wl,-flto
-O2 -march=native -mtune=native -mno-3dnow -mno-sse4.2 -mno-avx   -Wl,-soname
-Wl,libFLAC.so.8 -o .libs/libFLAC.so.8.3.0

Binutils are patched by Markus's slim-lto patch.


[Bug lto/59626] [4.8/4.9 Regression] /usr/include/bits/unistd.h:173:1: error: inlining failed in call to always_inline 'readlinkat': recursive inlining

2014-02-25 Thread rguenth at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59626

Richard Biener rguenth at gcc dot gnu.org changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
   Assignee|unassigned at gcc dot gnu.org  |rguenth at gcc dot 
gnu.org

--- Comment #8 from Richard Biener rguenth at gcc dot gnu.org ---
I will have a look.


[Bug lto/59626] [4.8/4.9 Regression] /usr/include/bits/unistd.h:173:1: error: inlining failed in call to always_inline 'readlinkat': recursive inlining

2014-02-25 Thread rguenth at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59626

Richard Biener rguenth at gcc dot gnu.org changed:

   What|Removed |Added

   Priority|P1  |P2
 CC||rguenth at gcc dot gnu.org


[Bug lto/59626] [4.8/4.9 Regression] /usr/include/bits/unistd.h:173:1: error: inlining failed in call to always_inline 'readlinkat': recursive inlining

2014-02-25 Thread rguenth at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59626

Richard Biener rguenth at gcc dot gnu.org changed:

   What|Removed |Added

   Keywords||wrong-code
 Status|ASSIGNED|WAITING

--- Comment #9 from Richard Biener rguenth at gcc dot gnu.org ---
We are merging the cgraph nodes for the function and the alias:

Merging nodes for readlinkat. Candidates:
readlinkat/0 (readlinkat) @0x766ba6f0
  Type: function
  Visibility: prevailing_def_ironly public
  next sharing asm name: 2
  References:
  Referring:
  Read from file: t.o
  Function flags: analyzed finalized
  Called by:
  Calls: *readlinkat/2 (1.00 per call)
*readlinkat/2 (__readlinkat_alias) @0x766ba940
  Type: function
  Visibility: external public
  previous sharing asm name: 0
  References:
  Referring:
  Read from file: t.o
  Function flags:
  Called by: main/1 (1.00 per call) readlinkat/0 (1.00 per call)
  Calls:
After resolution:
readlinkat/0 (readlinkat) @0x766ba6f0
  Type: function
  Visibility: prevailing_def_ironly public
  next sharing asm name: 2
  References:
  Referring:
  Read from file: t.o
  Function flags: analyzed finalized
  Called by:
  Calls: *readlinkat/2 (1.00 per call)
*readlinkat/2 (__readlinkat_alias) @0x766ba940
  Type: function
  Visibility: external public
  previous sharing asm name: 0
  References:
  Referring:
  Read from file: t.o
  Function flags:
  Called by: main/1 (1.00 per call) readlinkat/0 (1.00 per call)
  Calls:
...

Replacing cgraph node __readlinkat_alias/2 by readlinkat/0 for symbol
readlinkat
callgraph:

main/1 (main) @0x766ba818
  Type: function
  Visibility: force_output prevailing_def public
  References:
  Referring:
  Read from file: t.o
  Availability: available
  Function flags: analyzed finalized
  Called by:
  Calls: readlinkat/0 (1.00 per call)
readlinkat/0 (readlinkat) @0x766ba6f0
  Type: function
  Visibility: prevailing_def_ironly public
  References:
  Referring:
  Read from file: t.o
  Availability: available
  Function flags: analyzed finalized
  Called by: readlinkat/0 (1.00 per call) main/1 (1.00 per call)
  Calls: readlinkat/0 (1.00 per call)


And there is the optimization issue that we already get rid of the need
for the inline body during early inlining and thus we'd need to keep the
extern decl only.  And always-inline body never prevails (even though
we emit them eventually if inlining failed or somebody took its address -
something we maybe should change ...).  It works when using
extern inline __attribute__((always_inline,gnu_inline)) or extern inline
and not -std=c99.  So maybe that inline int readlinkat() {} _can_ prevail?

The glibc fortify wrappers use

extern __inline __attribute__ ((__always_inline__)) __attribute__
((__gnu_inline__)) __attribute__ ((__artificial__)) void *
__attribute__ ((__nothrow__ , __leaf__)) memcpy (void *__restrict __dest, const
void *__restrict __src, size_t __len)

{
  return __builtin___memcpy_chk (__dest, __src, __len, __builtin_object_size
(__dest, 0));
}

and thus extern gnu inline always-inline which works fine.  So IMHO this
bug doesn't warrant P1 status.

Btw, it fails with 4.8 even with -O0 (with 4.9 -O0 works!?  Ah, because
we massaged the condition guarding the error ...).

Still the callgraph is wrong and we miscompile the testcase in 4.9 with -O0
(to an endless recursion).

In the testcase from comment #2 'readlinkat' is

 function_decl 0x76d4a800 readlinkat
...
addressable used public static autoinline decl_5 QI file t.c line 4 col 10
align 8 context translation_unit_decl 0x76d6a000 D.1748 attributes
tree_list 0x76d45938 initial block 0x76d55910

which makes it go to the LTO symbol table (where the linker plugin then
decides it prevails - which is already wrong).  When adding 'extern' to
the declaration we do _not_ output it in the LTO symbol table because
it isn't even in the symtab encoder (it's reclaimed).

So I'm not sure if the testcase is even valid (without -flto we behave
the same as gcc 4.9 with -O0 and -flto - we compile this to endless
recursion - and a self-recursive always-inline function is ok to being
diagnosed IMHO).

So - I'm inclined to close this as INVALID?  My glibc version always has
'extern' on the inlines.

So - please provide preprocessed source of the file that uses readlinkat
or provide complete compile options.


[Bug lto/59626] [4.8/4.9 Regression] /usr/include/bits/unistd.h:173:1: error: inlining failed in call to always_inline 'readlinkat': recursive inlining

2014-02-25 Thread nheghathivhistha at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59626

--- Comment #10 from David Kredba nheghathivhistha at gmail dot com ---
There is preprocessed source in closed as duplicate of this error:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56088.

I will attach one from program cp.


[Bug lto/59626] [4.8/4.9 Regression] /usr/include/bits/unistd.h:173:1: error: inlining failed in call to always_inline 'readlinkat': recursive inlining

2014-02-25 Thread rguenth at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59626

--- Comment #11 from Richard Biener rguenth at gcc dot gnu.org ---
(In reply to David Kredba from comment #10)
 There is preprocessed source in closed as duplicate of this error:
 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=56088.
 
 I will attach one from program cp.

The duplicate preprocessed source has correct wrappers:

extern int __vswprintf_alias (wchar_t *__restrict __s, size_t __n, __const
wchar_t *__restrict __fmt, __gnuc_va_list __ap) throw () __asm__ (
vswprintf)


 ;

extern __inline __attribute__ ((__always_inline__)) __attribute__
((__gnu_inline__, __artificial__)) int
__attribute__ ((__leaf__)) vswprintf (wchar_t *__restrict __s, size_t __n,
__const wchar_t *__restrict __fmt, __gnuc_va_list __ap) throw ()

{
  if (__builtin_object_size (__s, 1  1) != (size_t) -1 || 1  1)
return __vswprintf_chk (__s, __n, 1 - 1,
   __builtin_object_size (__s, 1  1) / sizeof (wchar_t), __fmt, __ap);
  return __vswprintf_alias (__s, __n, __fmt, __ap);
}

and it works for me.


[Bug lto/59626] [4.8/4.9 Regression] /usr/include/bits/unistd.h:173:1: error: inlining failed in call to always_inline 'readlinkat': recursive inlining

2014-02-25 Thread trippels at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59626

--- Comment #12 from Markus Trippelsdorf trippels at gcc dot gnu.org ---
Created attachment 32210
  -- http://gcc.gnu.org/bugzilla/attachment.cgi?id=32210action=edit
Unreduced testcase

Here's the unreduced testcase:

markus@x4 coreutils % gcc -std=gnu99 -flto -O2 cp.i copy.i areadlinkat.i
careadlinkat.i linkat.i
/usr/include/bits/unistd.h: In function ‘careadlinkat.constprop’:
/usr/include/bits/unistd.h:173:42: error: inlining failed in call to
always_inline ‘readlinkat’: recursive inlining
 __NTH (readlinkat (int __fd, const char *__restrict __path,
  ^
/usr/include/bits/unistd.h:185:3: error: called from here
   return __readlinkat_alias (__fd, __path, __buf, __len);
   ^
lto-wrapper: /usr/x86_64-pc-linux-gnu/gcc-bin/4.9.0/gcc returned 1 exit status
/usr/lib/gcc/x86_64-pc-linux-gnu/4.9.0/../../../../x86_64-pc-linux-gnu/bin/ld:
fatal error: lto-wrapper failed
collect2: error: ld returned 1 exit status

[Bug lto/59626] [4.8/4.9 Regression] /usr/include/bits/unistd.h:173:1: error: inlining failed in call to always_inline 'readlinkat': recursive inlining

2014-02-25 Thread rguenth at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59626

--- Comment #13 from Richard Biener rguenth at gcc dot gnu.org ---
(In reply to Markus Trippelsdorf from comment #12)
 Created attachment 32210 [details]
 Unreduced testcase
 
 Here's the unreduced testcase:
 
 markus@x4 coreutils % gcc -std=gnu99 -flto -O2 cp.i copy.i areadlinkat.i
 careadlinkat.i linkat.i
 /usr/include/bits/unistd.h: In function ‘careadlinkat.constprop’:
 /usr/include/bits/unistd.h:173:42: error: inlining failed in call to
 always_inline ‘readlinkat’: recursive inlining
  __NTH (readlinkat (int __fd, const char *__restrict __path,
   ^
 /usr/include/bits/unistd.h:185:3: error: called from here
return __readlinkat_alias (__fd, __path, __buf, __len);
^
 lto-wrapper: /usr/x86_64-pc-linux-gnu/gcc-bin/4.9.0/gcc returned 1 exit
 status
 /usr/lib/gcc/x86_64-pc-linux-gnu/4.9.0/../../../../x86_64-pc-linux-gnu/bin/
 ld: fatal error: lto-wrapper failed
 collect2: error: ld returned 1 exit status

Confirmed with that testcase.  (it doesn't link though - files are missing?)

cgraph merging does

Replacing cgraph node __readlinkat_alias/183 by readlinkat/181 for symbol
readlinkat

I think it's caused by IPA-CP which does

Evaluating opportunities for careadlinkat/187.
 - Creating a specialized node of careadlinkat/187 for all known contexts.
replacing param fd with const -100
replacing param buffer with const 0B
replacing param buffer_size with const 0
replacing param alloc with const 0B
replacing param preadlinkat with const readlinkat
Accounting size:45.00, time:231.11 on predicate:(true)
Accounting size:3.00, time:2.00 on new predicate:(not inlined)
 the new node is careadlinkat.constprop.5/106.
ipa-prop: Discovered an indirect call to a known target
(careadlinkat.constprop.5/106 - readlinkat/181), for stmt with uid 2

and then IPA inlining decides

Considering readlinkat with 27 size
   Estimating body: readlinkat/181
   Known to be false: not inlined
   size:24 time:19
 to be inlined into careadlinkat.constprop.5 in unknown:-1
 Estimated growth after inlined into all is +36 insns.
 Estimated badness is -2147483648, frequency 16.39.
Accounting size:4.00, time:55.21 on predicate:(true)
Processing frequency readlinkat
  Called by careadlinkat.constprop.5 that is normal or hot
  enqueuing call readlinkat/130 - readlinkat/181, badness -2147483648

(!)

So it is IPA inlining that follows aliases bogously.  The alias target
is _not_ the non-prevailing extern inline function.

OTOH coreutils is walking on shaking grounds (or glibc is) as it takes
the address of an always-inline function.  That address-taking should
probably refer to an extern decl instead (and we are wrong to identify
it with the readlinkat variant with body at LTO time).

Btw, the LTO symbol table looks good to me.  Still somehow the inline
body prevails ... :/

  /* If there's not a prevailing symbol yet it's an external reference.
 Happens a lot during ltrans.  Choose the first symbol with a
 cgraph or a varpool node.  */
  if (!prevailing)
{
...
  /* For variables prefer the non-builtin if one is available.  */
  else if (TREE_CODE (prevailing-decl) == FUNCTION_DECL)
{
  for (e = first; e; e = e-next_sharing_asm_name)
if (TREE_CODE (e-decl) == FUNCTION_DECL
 !DECL_BUILT_IN (e-decl)
 lto_symtab_symbol_p (e))
  {
prevailing = e;
break;
  }

Now it is readlinkat

$22 = {type = SYMTAB_FUNCTION, resolution = LDPR_RESOLVED_DYN, definition = 1, 
  alias = 0, weakref = 0, cpp_implicit_alias = 0, analyzed = 1, 
  externally_visible = 0, force_output = 0, forced_by_abi = 0, 
  unique_name = 0, used_from_other_partition = 0, in_other_partition = 0, 
  address_taken = 1, order = 777, decl = 0x76dfc300, 
  next = 0x76e19668, previous = 0x76e19a40, 
  next_sharing_asm_name = 0x76e19b88, previous_sharing_asm_name = 0x0, 
  same_comdat_group = 0x0, ref_list = {references = 0x0, referring = {
  m_vec = 0x1ddfe00}}, alias_target = 0x0, lto_file_data = 0x77fe1000, 
  aux = 0x0}

that prevails, not the alias

$23 = {type = SYMTAB_FUNCTION, resolution = LDPR_UNKNOWN, definition = 0, 
  alias = 0, weakref = 0, cpp_implicit_alias = 0, analyzed = 0, 
  externally_visible = 0, force_output = 0, forced_by_abi = 0, 
  unique_name = 0, used_from_other_partition = 0, in_other_partition = 0, 
  address_taken = 0, order = 792, decl = 0x76dfc500, 
  next = 0x76e19a40, previous = 0x76e19cd0, 
  next_sharing_asm_name = 0x0, previous_sharing_asm_name = 0x76e198f8, 
  same_comdat_group = 0x0, ref_list = {references = 0x0, referring = {
  m_vec = 0x0}}, alias_target = 0x0, lto_file_data = 0x77fe1000, 
  aux = 0x0}

and we replace its cgraph node

*readlinkat/792 (__readlinkat_alias) @0x76e19b88
  Type: function
  

[Bug lto/59626] [4.8/4.9 Regression] /usr/include/bits/unistd.h:173:1: error: inlining failed in call to always_inline 'readlinkat': recursive inlining

2014-02-25 Thread nheghathivhistha at gmail dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59626

--- Comment #14 from David Kredba nheghathivhistha at gmail dot com ---
For me it is fixed too, tested it by reveision 207938, cp compiles fine with
-flto=4 -fuse-linker-plugin. It crashes later at link time but that is
something completely different.


[Bug lto/59626] [4.8/4.9 Regression] /usr/include/bits/unistd.h:173:1: error: inlining failed in call to always_inline 'readlinkat': recursive inlining

2014-02-25 Thread rguenth at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59626

Richard Biener rguenth at gcc dot gnu.org changed:

   What|Removed |Added

 Status|WAITING |ASSIGNED
   Assignee|rguenth at gcc dot gnu.org |hubicka at gcc dot 
gnu.org

--- Comment #15 from Richard Biener rguenth at gcc dot gnu.org ---
Honza?  Does the patch make sense?  Basically the alias following breaks

int __readlinkat_alias(void) __asm__(readlinkat);
extern inline int readlinkat()
{
return __readlinkat_alias();
}
int main() {
  return readlinkat();
}

because it replaces __readlinkat_alias () (in main) with readlinkat.


[Bug lto/59626] [4.8/4.9 Regression] /usr/include/bits/unistd.h:173:1: error: inlining failed in call to always_inline 'readlinkat': recursive inlining

2014-02-16 Thread trippels at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59626

Markus Trippelsdorf trippels at gcc dot gnu.org changed:

   What|Removed |Added

 CC||vhaisman at gmail dot com

--- Comment #7 from Markus Trippelsdorf trippels at gcc dot gnu.org ---
*** Bug 56088 has been marked as a duplicate of this bug. ***


[Bug lto/59626] [4.8/4.9 Regression] /usr/include/bits/unistd.h:173:1: error: inlining failed in call to always_inline 'readlinkat': recursive inlining

2014-01-31 Thread rguenth at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=59626

Richard Biener rguenth at gcc dot gnu.org changed:

   What|Removed |Added

   Keywords||lto
   Priority|P3  |P1
   Target Milestone|4.9.0   |4.8.3
Summary|[4.9 lto]   |[4.8/4.9 Regression]
   |/usr/include/bits/unistd.h: |/usr/include/bits/unistd.h:
   |173:1: error: inlining  |173:1: error: inlining
   |failed in call to   |failed in call to
   |always_inline 'readlinkat': |always_inline 'readlinkat':
   |recursive inlining  |recursive inlining