Re: "-flto -O2" shouln't opt out "undefined reference" error

2017-01-20 Thread Jim Wilson
On Tue, Jan 17, 2017 at 7:27 PM, Xuefer  wrote:
> volatile: i tried already with clang/llvm it worked.
>
> i'm using gentoo linux, trying to emerge everything with -flto. i'm not sure
> if i understand linker/compiler bug or not a bug, i wonder how many script
> is affected by this issue.

OK, if you want everything compiled with -flto then you may need to
fix some package configure scripts to make this work, and you may need
autoconf fixes too.  This may not be well tested.

Exactly how lto integrates into a package build system may vary from
package to package.  For GCC, you can do
--with-build-config=bootstrap-lto and it will bootstrap itself with
LTO enabled.  For most other packages though putting -flto in CFLAGS
before configure/make is probably good enough.

Jim

___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


Re: "-flto -O2" shouln't opt out "undefined reference" error

2017-01-17 Thread Xuefer
volatile: i tried already with clang/llvm it worked.

i'm using gentoo linux, trying to emerge everything with -flto. i'm not
sure if i understand linker/compiler bug or not a bug, i wonder how many
script is affected by this issue.

On Wed, Jan 18, 2017 at 7:53 AM Jim Wilson  wrote:

On 01/16/2017 10:32 AM, Xuefer wrote:
> without -flto or without -O2 produce good (expected) result:
> 
> configure:5332: checking for dlsym
> ...

It isn't the linker that is the problem here.  It is the compiler.  But
it isn't a compiler bug.  An optimizing compiler is supposed to optimize
code like this.

I'd say the main problem is trying to use -flto at configure time.  This
is likely to break lots of configure scripts.

how could -lfto be not used with configure yet with make? pass another
CFLAGS to make as argument?
IIRC, we tends to assume configure use same CFLAGS as Makefile (which
generated by configure anyway)



> char (*f) ();

However, this particular problem I can fix with gcc by changing this line to

char (* volatile f) ();

and now gcc won't optimize away the store, even with -flto.
Unfortunately, I can't check LLVM at the moment, as I don't have LLVM
-flto support set up on any of my machines at the moment.

So this can be fixed by not using -flto at configure time, or by
modifying configure scripts to use volatile.  There is no linker or
compiler fix to make here.

Jim
___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


Re: "-flto -O2" shouln't opt out "undefined reference" error

2017-01-17 Thread Jim Wilson

On 01/16/2017 10:32 AM, Xuefer wrote:

without -flto or without -O2 produce good (expected) result:

configure:5332: checking for dlsym
...


It isn't the linker that is the problem here.  It is the compiler.  But 
it isn't a compiler bug.  An optimizing compiler is supposed to optimize 
code like this.


I'd say the main problem is trying to use -flto at configure time.  This 
is likely to break lots of configure scripts.



char (*f) ();


However, this particular problem I can fix with gcc by changing this line to

char (* volatile f) ();

and now gcc won't optimize away the store, even with -flto. 
Unfortunately, I can't check LLVM at the moment, as I don't have LLVM 
-flto support set up on any of my machines at the moment.


So this can be fixed by not using -flto at configure time, or by 
modifying configure scripts to use volatile.  There is no linker or 
compiler fix to make here.


Jim


___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils


"-flto -O2" shouln't opt out "undefined reference" error

2017-01-16 Thread Xuefer
without -flto or without -O2 produce good (expected) result:

configure:5332: checking for dlsym
configure:5369: clang -o conftest -O2 -pipe -march=ivybridge -O2 -pipe
  conftest.c  >&5
/tmp/conftest-597c62.o:conftest.c:function main: error: undefined
reference to 'dlsym'
clang-3.9: error: linker command failed with exit code 1 (use -v to
see invocation)
configure:5372: $? = 1
configure: failed program was:
#line 5338 "configure"
#include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes,
which can conflict with char dlsym (); below.  */
#include 
/* Override any gcc2 internal prototype to avoid an error.  */
#ifdef __cplusplus
extern "C"
#endif
/* We use char because int might match the return type of a gcc2
   builtin and then its argument prototype would still apply.  */
char dlsym ();
char (*f) ();

int
main ()
{
/* The GNU C library defines this for functions which it implements
to always fail with ENOSYS.  Some functions are actually named
something starting with __ and the normal name is an alias.  */
#if defined (__stub_dlsym) || defined (__stub___dlsym)
choke me
#else
f = dlsym; /* workaround for ICC 12.0.3 */ if (f == 0) return 1;
#endif

  ;
  return 0;
}


 with both -flto and -O2 produce bad result (tested with clang and
gcc), this is reproduced when i build ncurses which have strange
configure script built with many workaround, unlike other configure
script


configure:5332: checking for dlsym
configure:5369: clang -o conftest -flto -O2 -pipe -march=ivybridge -O2
-pipe   conftest.c  >&5
configure:5372: $? = 0
configure:5375: test -s conftest
configure:5378: $? = 0
configure:5388: result: yes


___
bug-binutils mailing list
bug-binutils@gnu.org
https://lists.gnu.org/mailman/listinfo/bug-binutils