emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.91k stars 3.32k forks source link

emcc links with system libraries during './configure' #2242

Closed nick7ikin closed 5 years ago

nick7ikin commented 10 years ago

Hi

I've met an issue when './configure' script determine system functions available.

Trying to build assuan library. Running configure script as:

emconfigure ./configure --with-libgpg-error-prefix=/home/user/work/gnupg/gnupg/build --disable-shared --enable-static

Somehow it finds 'fopencookie' function that actually exists in system header /usr/include/stdio.h:

configure:14245: checking for fopencookie... yes
configure:14245: $? = 0
configure:14245: result: yes

I'm a bit confused, cause I thought that emconfigure sets up include search path to emscripten folder and not to system one.

I tried to find fopencookie at ~/emscripten path:

grep -r fopencookie ~/emscripten/*

but there is no such a function.

I added -v option in order to get verbose output from compiler during ./configure:


user@Inspiron-3520:~/work/.../build/libassuan-2.1.1$ /home/user/emscripten/emcc -v -o conftest  -Wall -Wcast-align -Wshadow -Wstrict-prototypes -Wpointer-arith -fPIC -DPIC   conftest.c
clang version 3.2 (tags/RELEASE_32/final 203112)
Target: x86_64-unknown-linux-gnu
Thread model: posix
 "/home/user/llvm32build/bin/clang-3.2" -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -main-file-name conftest.c -mrelocation-model pic -pic-level 2 -mdisable-fp-elim -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -momit-leaf-frame-pointer -v -nostdsysteminc -nobuiltininc -resource-dir /home/user/llvm32build/bin/../lib/clang/3.2 -D PIC -U __i386__ -U __i386 -U i386 -U __STRICT_ANSI__ -D __IEEE_LITTLE_ENDIAN -U __SSE__ -U __SSE_MATH__ -U __SSE2__ -U __SSE2_MATH__ -U __MMX__ -U __APPLE__ -U __linux__ -D EMSCRIPTEN -fmodule-cache-path /var/tmp/clang-module-cache -Wall -Wcast-align -Wshadow -Wstrict-prototypes -Wpointer-arith -fdebug-compilation-dir /home/user/work/gnupg/gnupg/build/libassuan-2.1.1 -ferror-limit 19 -fmessage-length 239 -mstackrealign -fobjc-runtime=gcc -fdiagnostics-show-option -fcolor-diagnostics -nobuiltininc -nostdsysteminc -isystem/home/user/emscripten/system/local/include -isystem/home/user/emscripten/system/include/compat -isystem/home/user/emscripten/system/include/libcxx -isystem/home/user/emscripten/system/include -isystem/home/user/emscripten/system/include/emscripten -isystem/home/user/emscripten/system/include/bsd -isystem/home/user/emscripten/system/include/libc -isystem/home/user/emscripten/system/include/gfx -isystem/home/user/emscripten/system/include/net -isystem/home/user/emscripten/system/include/SDL -o /tmp/conftest-Qdc3Fz.o -x c conftest.c
clang -cc1 version 3.2 based upon LLVM 3.2svn default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/home/user/emscripten/system/local/include"
ignoring nonexistent directory "/home/user/emscripten/system/include/bsd"
ignoring nonexistent directory "/home/user/emscripten/system/include/net"
#include "..." search starts here:
#include <...> search starts here:
 /home/user/emscripten/system/include/compat
 /home/user/emscripten/system/include/libcxx
 /home/user/emscripten/system/include
 /home/user/emscripten/system/include/emscripten
 /home/user/emscripten/system/include/libc
 /home/user/emscripten/system/include/gfx
 /home/user/emscripten/system/include/SDL
End of search list.
 "/usr/bin/ld" -z relro --hash-style=gnu --build-id --eh-frame-hdr -m elf_x86_64 -dynamic-linker /lib64/ld-linux-x86-64.so.2 -o conftest /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crt1.o /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crti.o /usr/lib/gcc/x86_64-linux-gnu/4.7/crtbegin.o -L/usr/lib/gcc/x86_64-linux-gnu/4.7 -L/usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu -L/lib/x86_64-linux-gnu -L/lib/../lib64 -L/usr/lib/x86_64-linux-gnu -L/usr/lib/gcc/x86_64-linux-gnu/4.7/../../.. -L/lib -L/usr/lib /tmp/conftest-Qdc3Fz.o -lgcc --as-needed -lgcc_s --no-as-needed -lc -lgcc --as-needed -lgcc_s --no-as-needed /usr/lib/gcc/x86_64-linux-gnu/4.7/crtend.o /usr/lib/gcc/x86_64-linux-gnu/4.7/../../../x86_64-linux-gnu/crtn.o

As I see clang is provided non-system include paths - that is expected. But after that /usr/bin/ld linker is called and it is linked with system libraries.

In my Makefile LD is defined as

192 LD = /home/user/emscripten/emcc
193 LDFLAGS =

Please tell me what I'm doing wrong. Why does emscripten link with system libraries?

kripken commented 10 years ago

I'm a bit confused, cause I thought that emconfigure sets up include search path to emscripten folder and not to system one.

It will. However, if configure does something like -I/usr/include then it will look in the system location. You may need to look at what commands configure is issuing (config.log) to see what is going on, then try to run them yourself manually etc.

nick7ikin commented 10 years ago

I don't think that configure is related to this output. The first line

emcc -v -o conftest  -Wall -Wcast-align -Wshadow -Wstrict-prototypes -Wpointer-arith -fPIC -DPIC   conftest.c

I run manually in command line and got the output from the previous message (I added conftest.c file content at the bottom of the message)

I suspected environment variables could be a reason, but emconfigure printenv shows:

user@Inspiron-3520:~/work/.../crypto-emscripten$ emconfigure printenv
rvm_version=1.25.17 (stable)
LDSHARED=/home/user/emscripten/emcc
LC_PAPER=ru_UA.UTF-8
SHELL=/bin/bash
XDG_DATA_DIRS=/usr/share/ubuntu:/usr/share/gnome:/usr/local/share/:/usr/share/
MANDATORY_PATH=/usr/share/gconf/ubuntu.mandatory.path
DESKTOP_AUTOSTART_ID=10a3dbb2f35f467c18139522414013652100000047780019
XDG_RUNTIME_DIR=/run/user/user
LC_ADDRESS=ru_UA.UTF-8
RANLIB=/home/user/emscripten/emranlib
_system_type=Linux
MY_RUBY_HOME=/home/user/.rvm/rubies/ruby-2.0.0-p353
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-nSb78SDIYe,guid=853da6c62deaa4c84681f2f453296e4b
GNOME_KEYRING_PID=4767
TERMCAP=SC|screen|VT 100/ANSI X3.64 virtual terminal:\
        :DO=\E[%dB:LE=\E[%dD:RI=\E[%dC:UP=\E[%dA:bs:bt=\E[Z:\
        :cd=\E[J:ce=\E[K:cl=\E[H\E[J:cm=\E[%i%d;%dH:ct=\E[3g:\
        :do=^J:nd=\E[C:pt:rc=\E8:rs=\Ec:sc=\E7:st=\EH:up=\EM:\
        :le=^H:bl=^G:cr=^M:it#8:ho=\E[H:nw=\EE:ta=^I:is=\E)0:\
        :li#35:co#233:am:xn:xv:LP:sr=\EM:al=\E[L:AL=\E[%dL:\
        :cs=\E[%i%d;%dr:dl=\E[M:DL=\E[%dM:dc=\E[P:DC=\E[%dP:\
        :im=\E[4h:ei=\E[4l:mi:IC=\E[%d@:ks=\E[?1h\E=:\
        :ke=\E[?1l\E>:vi=\E[?25l:ve=\E[34h\E[?25h:vs=\E[34l:\
        :ti=\E[?1049h:te=\E[?1049l:us=\E[4m:ue=\E[24m:so=\E[3m:\
        :se=\E[23m:mb=\E[5m:md=\E[1m:mr=\E[7m:me=\E[m:ms:\
        :Co#8:pa#64:AF=\E[3%dm:AB=\E[4%dm:op=\E[39;49m:AX:\
        :vb=\Eg:G0:as=\E(0:ae=\E(B:\
        :ac=\140\140aaffggjjkkllmmnnooppqqrrssttuuvvwwxxyyzz{{||}}~~..--++,,hhII00:\
        :po=\E[5i:pf=\E[4i:k0=\E[10~:k1=\EOP:k2=\EOQ:k3=\EOR:\
        :k4=\EOS:k5=\E[15~:k6=\E[17~:k7=\E[18~:k8=\E[19~:\
        :k9=\E[20~:k;=\E[21~:F1=\E[23~:F2=\E[24~:F3=\E[1;2P:\
        :F4=\E[1;2Q:F5=\E[1;2R:F6=\E[1;2S:F7=\E[15;2~:\
        :F8=\E[17;2~:F9=\E[18;2~:FA=\E[19;2~:kb=:K2=\EOE:\
        :kB=\E[Z:kF=\E[1;2B:kR=\E[1;2A:*4=\E[3;2~:*7=\E[1;2F:\
        :#2=\E[1;2H:#3=\E[2;2~:#4=\E[1;2D:%c=\E[6;2~:%e=\E[5;2~:\
        :%i=\E[1;2C:kh=\E[1~:@1=\E[1~:kH=\E[4~:@7=\E[4~:\
        :kN=\E[6~:kP=\E[5~:kI=\E[2~:kD=\E[3~:ku=\EOA:kd=\EOB:\
        :kr=\EOC:kl=\EOD:km:
DESKTOP_SESSION=ubuntu
GTK_MODULES=overlay-scrollbar
CXX=/home/user/emscripten/em++
_system_version=12.10
EMMAKEN_CFLAGS=
LC_NAME=ru_UA.UTF-8
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*
.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;
31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=
01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.f
lc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.m
ka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:
LC_NUMERIC=ru_UA.UTF-8
GNOME_DESKTOP_SESSION_ID=this-is-deprecated
rvm_path=/home/user/.rvm
LESSOPEN=| /usr/bin/lesspipe %s
USER=user
PS4=+ $(__rvm_date "+%s.%N" 2>/dev/null) ${BASH_SOURCE##${rvm_path:-}} : ${FUNCNAME[0]:+${FUNCNAME[0]}()}  ${LINENO} >
EMSCRIPTEN=/home/user/emscripten
XAUTHORITY=/home/user/.Xauthority
LANGUAGE=en
SESSION_MANAGER=local/Inspiron-3520:@/tmp/.ICE-unix/4778,unix/Inspiron-3520:/tmp/.ICE-unix/4778
LC_MEASUREMENT=ru_UA.UTF-8
MYPS=$(echo -n "${PWD/#$HOME/~}" | awk -F "/" '{if (length($0) > 20) { if (NF>4) print $1 "/" $2 "/.../" $(NF-1) "/" $NF; else if (NF>3) print $1 "/" $2 "/.../" $NF; else print $1 "/.../" $NF; } else print $0;}')
EMMAKEN_COMPILER=/home/user/llvm32build/bin/clang++
ANDROID_SDK=/home/user/dev/android/adt-bundle-linux/sdk
COMPIZ_CONFIG_PROFILE=ubuntu
GPG_AGENT_INFO=/run/user/user/keyring-yUa944/gpg:0:1
GEM_PATH=/home/user/.rvm/gems/ruby-2.0.0-p353:/home/user/.rvm/gems/ruby-2.0.0-p353@global
GDMSESSION=ubuntu
PKG_CONFIG_PATH=
_=/home/user/emscripten/emconfigure
LC_IDENTIFICATION=ru_UA.UTF-8
XDG_CONFIG_DIRS=/etc/xdg/xdg-ubuntu:/etc/xdg
UBUNTU_MENUPROXY=libappmenu.so
HOST_CXXFLAGS=-W
_system_name=Ubuntu
HOST_CC=/home/user/llvm32build/bin/clang
LC_TIME=ru_UA.UTF-8
HOST_CFLAGS=-W
XDG_SEAT_PATH=/org/freedesktop/DisplayManager/Seat0
HOME=/home/user
DISPLAY=:0
LANG=en_US.UTF-8
LC_MONETARY=ru_UA.UTF-8
_system_arch=x86_64
rvm_prefix=/home/user
CC=/home/user/emscripten/emcc
COMP_WORDBREAKS=
"'><;|&(:
IRBRC=/home/user/.rvm/rubies/ruby-2.0.0-p353/.irbrc
XDG_CURRENT_DESKTOP=Unity
LESSCLOSE=/usr/bin/lesspipe %s %s
DEFAULTS_PATH=/usr/share/gconf/ubuntu.default.path
GEM_HOME=/home/user/.rvm/gems/ruby-2.0.0-p353
LOGNAME=user
GNOME_KEYRING_CONTROL=/run/user/user/keyring-yUa944
PATH=/home/user/.rvm/gems/ruby-2.0.0-p353/bin:/home/user/.rvm/gems/ruby-2.0.0-p353@global/bin:/home/user/.rvm/rubies/ruby-2.0.0-p353/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/lib/jvm/jdk/bin:/home/user/.rvm/bin:/home/user/llvm32build/bin:/home/user/emscripten:/home/user/llvm32build/bin:/home/user/emscripten
SSH_AGENT_PID=4817
TERM=screen
XDG_SESSION_PATH=/org/freedesktop/DisplayManager/Session0
XDG_SESSION_COOKIE=39473177d9255b9ef38080ca516f97d2-1395224137.819123-863647279
WINDOW=3
EMMAKEN_JUST_CONFIGURE=1
rvm_bin_path=/home/user/.rvm/bin
PKG_CONFIG_LIBDIR=/home/user/emscripten/system/local/lib/pkgconfig:/home/user/emscripten/system/lib/pkgconfig
SSH_AUTH_SOCK=/run/user/user/keyring-yUa944/ssh
LD=/home/user/emscripten/emcc
AR=/home/user/emscripten/emar
LC_ALL=en_US.UTF-8
STY=26783.pts-5.Inspiron-3520
OLDPWD=/home/user/work/gnupg/gnupg/build
LC_TELEPHONE=ru_UA.UTF-8
NODE_PATH=/usr/lib/nodejs:/usr/lib/node_modules:/usr/share/javascript
SHLVL=2
PWD=/home/user/work/gnupg/crypto-emscripten
CFLAGS=
HOST_CXX=/home/user/llvm32build/bin/clang++
EMSCRIPTEN_TOOLS=/home/user/emscripten/tools

But I do not see variables pointing to system include folders. It is very strange, cause I don't known where to look any more.

conftest.c file content - checking for fopencookie function existance:

/* confdefs.h */
#define PACKAGE_NAME "libassuan"
#define PACKAGE_TARNAME "libassuan"
#define PACKAGE_VERSION "2.1.1"
#define PACKAGE_STRING "libassuan 2.1.1"
#define PACKAGE_BUGREPORT "http://bugs.gnupg.org"
#define PACKAGE_URL ""
#define PACKAGE "libassuan"
#define VERSION "2.1.1"
#define STDC_HEADERS 1
#define HAVE_SYS_TYPES_H 1
#define HAVE_SYS_STAT_H 1
#define HAVE_STDLIB_H 1
#define HAVE_STRING_H 1
#define HAVE_MEMORY_H 1
#define HAVE_STRINGS_H 1
#define HAVE_INTTYPES_H 1
#define HAVE_STDINT_H 1
#define HAVE_UNISTD_H 1
#define __EXTENSIONS__ 1
#define _ALL_SOURCE 1
#define _GNU_SOURCE 1
#define _POSIX_PTHREAD_SEMANTICS 1
#define _TANDEM_SOURCE 1
#define PACKAGE "libassuan"
#define VERSION "2.1.1"
#define PACKAGE_BUGREPORT "http://bugs.gnupg.org"
#define HAVE_DLFCN_H 1
#define LT_OBJDIR ".libs/"
#define BUILD_REVISION "cf1e6f6"
#define BUILD_TIMESTAMP "2014-03-18T18:05+0000"
#define STDC_HEADERS 1
#define HAVE_STRING_H 1
#define HAVE_LOCALE_H 1
#define HAVE_SYS_UIO_H 1
#define HAVE_STDINT_H 1
#define HAVE_INTTYPES_H 1
#define HAVE_SYS_TYPES_H 1
#define HAVE_SYS_STAT_H 1
#define HAVE_UNISTD_H 1
#define HAVE_SYS_TIME_H 1
#define HAVE_FCNTL_H 1
#define HAVE_SYS_SELECT_H 1
#define HAVE_UINTPTR_T 1
#define RETSIGTYPE void
#define HAVE_DECL_SYS_SIGLIST 0
#define HAVE_SYS_SOCKET_H 1
#define USE_DESCRIPTOR_PASSING 1
#define HAVE_FLOCKFILE 1
#define HAVE_FUNLOCKFILE 1
#define HAVE_INET_PTON 1
#define HAVE_NANOSLEEP 1
/* end confdefs.h.  */
/* Define fopencookie to an innocuous variant, in case <limits.h> declares fopencookie.
   For example, HP-UX 11i <limits.h> declares gettimeofday.  */
#define fopencookie innocuous_fopencookie

/* System header to define __stub macros and hopefully few prototypes,
    which can conflict with char fopencookie (); 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 fopencookie

/* Override any GCC internal prototype to avoid an error.
   Use char because int might match the return type of a GCC
   builtin and then its argument prototype would still apply.  */
#ifdef __cplusplus
extern "C"
#endif
char fopencookie ();
/* 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_fopencookie || defined __stub___fopencookie
choke me
#endif

int
main ()
{
return fopencookie ();
  ;
  return 0;
}
kripken commented 10 years ago

Can you reduce this to a standalone testcase I can reproduce with? Not sure if that is what the above is or is not.

stale[bot] commented 5 years ago

This issue has been automatically marked as stale because there has been no activity in the past 2 years. It will be closed automatically if no further activity occurs in the next 7 days. Feel free to re-open at any time if this issue is still relevant.