WeHack BBS
LTO导致configure时的conftest失败 - 可打印的版本

+- WeHack BBS (https://bbs.wehack.space)
+-- 版块: 计算机技术 (https://bbs.wehack.space/forum-5.html)
+--- 版块: 程序设计讨论区 (https://bbs.wehack.space/forum-14.html)
+--- 主题: LTO导致configure时的conftest失败 (/thread-237.html)



LTO导致configure时的conftest失败 - vimacs - 03-29-2021

今天试着打开链接时优化(LTO)选项构建一些包,发现它会导致configure时的一些测试出错。下面是来自tcl 8.5.19的一个测试。

代码:
/* end confdefs.h.  */
/* Define pthread_attr_get_np to an innocuous variant, in case <limits.h> declares pthread_attr_get_np.
   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
#define pthread_attr_get_np innocuous_pthread_attr_get_np

/* System header to define __stub macros and hopefully few prototypes,
    which can conflict with char pthread_attr_get_np (); below.
    Prefer <limits.h> to <assert.h> if __STDC__ is defined, since
    <limits.h> exists even on freestanding compilers.  */

#ifdef __STDC__
# include <limits.h>
#else
# include <assert.h>
#endif

#undef pthread_attr_get_np

/* 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 pthread_attr_get_np ();
/* 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_pthread_attr_get_np) || defined (__stub___pthread_attr_get_np)
choke me
#else
char (*f) () = pthread_attr_get_np;
#endif
#ifdef __cplusplus
}
#endif

int
main ()
{
return f != pthread_attr_get_np;
  ;
  return 0;
}

上面这段程序用于测试 pthread_attr_get_np 这个符号是否存在,没开LTO的时候,这段程序在我的系统下是链接失败的,但是开了LTO之后,就会链接成功,main()会被直接优化为一个return 0.