bug-ncurses
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

configure 'ncurses' when it is set '-flto' in CFLAGS, CXXFLAGS and LDFLA


From: Denis Pronin
Subject: configure 'ncurses' when it is set '-flto' in CFLAGS, CXXFLAGS and LDFLAGS
Date: Wed, 03 Oct 2018 23:20:15 +0300

Hi,

I work on gentoo linux, where CC, CXX, CFLAGS, CXXFLAGS, LDFLAGS are
exposed to ./configure script of ncurses library. As 'configure' goes
it checks whether it is supported linkage to dl*() functions. CFLAGS,
CXXFLAGS and LDFLAGS contains '-flto' flag standing for 'link time
optimization' taking place when compiling and linking against libraries
and object files

./configure verifies support of dl*() functions by compiling the FIRST
conftest.c looking like:

__________________

#include <assert.h>
/* 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 (void)
{
/* 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;
} 


_____________

If we compile this without '-flto' flag provided to a compiler and a
linker we get failed since 'dlsym' is required to exist since no
optimization is taken and applied. This definitely leads the configure
script to checking if the symbols are available in libdl library and
./configure tries to compile the other conftest.c by calling a compiler
and a linker with the same flags appended by -ldl, the SECOND
conftest.c looks like:

____

#include "confdefs.h"
#include <dlfcn.h>
int
main (void)
{

                void *obj;
                if ((obj = dlopen("filename", 0)) != 0) {
                        if (dlsym(obj, "symbolname") == 0) {
                        dlclose(obj);
                        }
                }
  ;
  return 0;
}

___________

And it gets succeeded in comping this program having been linked
against -ldl


The issue is: if we compile the FIRST conftest.c with supplemented flag
'-flto' the conftest.c passes fairly because when 'lto' is enabled it
erases all the symbols not participating in any invocations. Since
'dlsym' is not used, only is assigned, it is deleted from binary upon
linking. As you might see in contrast to the version, where 'lto' is
disabled, it gets successfully compiled and afterwards fails to compile
some tests being deceived that 'dlsym' is available without -ldl linked

The reason is '-flto' that makes a compiler behave wisely with unused
and prone-to-optimized-out variables and calls 

What I could suggest you is adding one single line with usage of
'dlsym' by calling it in the FIRST conftest.c to prevent '-flto' from
displacing 'dlsym' from the object file when it is a linker's state of
preparing a binary

Just make the FIRST conftest.c be:

__________________

#include <assert.h>
/* 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 (void)
{
/* 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;
f(NULL, NULL);
#endif
  ;
  return 0;
} 


_____________

It is the most simple fix I could advise

Thank you



reply via email to

[Prev in Thread] Current Thread [Next in Thread]