Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[homebrew] Default install environment gives linker errors #2417

Closed
mathiasbynens opened this issue Jan 26, 2017 · 13 comments
Closed

[homebrew] Default install environment gives linker errors #2417

mathiasbynens opened this issue Jan 26, 2017 · 13 comments

Comments

@mathiasbynens
Copy link
Contributor

mathiasbynens commented Jan 26, 2017

While working on a Homebrew formula for ChakraCore, I ran into an issue when running ./build.sh --static --test-build --no-icu. Running that command on its own (outside of the Homebrew sandbox) works fine, but within the sandbox, the linking step fails with the following error:

[100%] Linking CXX executable ch
Undefined symbols for architecture x86_64:
  "void Js::ByteCodeWriter::Data::EncodeOpCode<(Js::LayoutSize)1>(unsigned short, Js::ByteCodeWriter*)", referenced from:
      bool Js::AsmJsByteCodeWriter::TryWriteAsmReg2<Js::LayoutSizePolicy<(Js::LayoutSize)1> >(Js::OpCodeAsmJs, unsigned int, unsigned int) in libChakra.Jsrt.a(AsmJsByteCodeWriter.cpp.o)
      bool Js::AsmJsByteCodeWriter::TryWriteInt1Const1<Js::LayoutSizePolicy<(Js::LayoutSize)1> >(Js::OpCodeAsmJs, unsigned int, int) in libChakra.Jsrt.a(AsmJsByteCodeWriter.cpp.o)
      bool Js::AsmJsByteCodeWriter::TryWriteReg1IntConst1<Js::LayoutSizePolicy<(Js::LayoutSize)1> >(Js::OpCodeAsmJs, unsigned int, int) in libChakra.Jsrt.a(AsmJsByteCodeWriter.cpp.o)
      bool Js::AsmJsByteCodeWriter::TryWriteLong1Const1<Js::LayoutSizePolicy<(Js::LayoutSize)1> >(Js::OpCodeAsmJs, unsigned int, long) in libChakra.Jsrt.a(AsmJsByteCodeWriter.cpp.o)
      bool Js::AsmJsByteCodeWriter::TryWriteFloat1Const1<Js::LayoutSizePolicy<(Js::LayoutSize)1> >(Js::OpCodeAsmJs, unsigned int, float) in libChakra.Jsrt.a(AsmJsByteCodeWriter.cpp.o)
      bool Js::AsmJsByteCodeWriter::TryWriteDouble1Const1<Js::LayoutSizePolicy<(Js::LayoutSize)1> >(Js::OpCodeAsmJs, unsigned int, double) in libChakra.Jsrt.a(AsmJsByteCodeWriter.cpp.o)
      Js::AsmJsByteCodeWriter::AsmReg1(Js::OpCodeAsmJs, unsigned int) in libChakra.Jsrt.a(AsmJsByteCodeWriter.cpp.o)
      ...
  "void Js::ByteCodeWriter::Data::EncodeOpCode<(Js::LayoutSize)2>(unsigned short, Js::ByteCodeWriter*)", referenced from:
      bool Js::AsmJsByteCodeWriter::TryWriteAsmReg2<Js::LayoutSizePolicy<(Js::LayoutSize)2> >(Js::OpCodeAsmJs, unsigned int, unsigned int) in libChakra.Jsrt.a(AsmJsByteCodeWriter.cpp.o)
      Js::AsmJsByteCodeWriter::AsmInt1Const1(Js::OpCodeAsmJs, unsigned int, int) in libChakra.Jsrt.a(AsmJsByteCodeWriter.cpp.o)
      Js::AsmJsByteCodeWriter::AsmReg1IntConst1(Js::OpCodeAsmJs, unsigned int, int) in libChakra.Jsrt.a(AsmJsByteCodeWriter.cpp.o)
      Js::AsmJsByteCodeWriter::AsmLong1Const1(Js::OpCodeAsmJs, unsigned int, long) in libChakra.Jsrt.a(AsmJsByteCodeWriter.cpp.o)
      Js::AsmJsByteCodeWriter::AsmFloat1Const1(Js::OpCodeAsmJs, unsigned int, float) in libChakra.Jsrt.a(AsmJsByteCodeWriter.cpp.o)
      Js::AsmJsByteCodeWriter::AsmDouble1Const1(Js::OpCodeAsmJs, unsigned int, double) in libChakra.Jsrt.a(AsmJsByteCodeWriter.cpp.o)
      Js::AsmJsByteCodeWriter::AsmReg1(Js::OpCodeAsmJs, unsigned int) in libChakra.Jsrt.a(AsmJsByteCodeWriter.cpp.o)
      ...
  "Js::JavascriptString::Concat(Js::JavascriptString*, Js::JavascriptString*)", referenced from:
      Js::JavascriptError::EntryToString(Js::RecyclableObject*, Js::CallInfo, ...) in libChakra.Jsrt.a(JavascriptError.cpp.o)
      Js::JavascriptLibrary::CreateGetterFunction(int, Js::FunctionInfo*) in libChakra.Jsrt.a(JavascriptLibrary.cpp.o)
      Js::JavascriptLibrary::CreateSetterFunction(int, Js::FunctionInfo*) in libChakra.Jsrt.a(JavascriptLibrary.cpp.o)
      Js::JavascriptFunction::NewInstanceHelper(Js::ScriptContext*, Js::RecyclableObject*, Js::CallInfo, Js::ArgumentReader&, Js::JavascriptFunction::FunctionKind) in libChakra.Jsrt.a(JavascriptFunction.cpp.o)
      Js::JavascriptString* Js::JavascriptFunction::GetNativeFunctionDisplayStringCommon<Js::JavascriptString, Js::JavascriptString*, Js::ScriptContext>(Js::ScriptContext*, Js::JavascriptString*) in libChakra.Jsrt.a(JavascriptFunction.cpp.o)
      Js::JavascriptFunction::DisplayNameHelper(char16_t const*, unsigned int) const in libChakra.Jsrt.a(JavascriptFunction.cpp.o)
      Js::RecyclableObjectDisplay::Value(int) in libChakra.Jsrt.a(DiagObjectModel.cpp.o)
      ...
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [bin/ch/ch] Error 1
make[1]: *** [bin/ch/CMakeFiles/ch.dir/all] Error 2
make: *** [all] Error 2
See error details above. Exit code was 2

Since the command works outside of the sandbox, I figure I’m doing something wrong here. Any ideas what to look for? Here’s some more info about the sandbox environment in which the linking fails:

Compile Target : amd64
Generating Test makefiles
-- The C compiler identification is AppleClang 8.0.0.8000042
-- The CXX compiler identification is AppleClang 8.0.0.8000042
-- Check for working C compiler: /usr/local/Homebrew/Library/Homebrew/shims/super/clang
-- Check for working C compiler: /usr/local/Homebrew/Library/Homebrew/shims/super/clang -- works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: /usr/local/Homebrew/Library/Homebrew/shims/super/clang++
-- Check for working CXX compiler: /usr/local/Homebrew/Library/Homebrew/shims/super/clang++ -- works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test CLANG_HAS_DISABLE_TAIL_CALLS_CFG
-- Performing Test CLANG_HAS_DISABLE_TAIL_CALLS_CFG - Success
-- The ASM compiler identification is AppleClang
-- Found assembler: /usr/local/Homebrew/Library/Homebrew/shims/super/clang
-- Looking for include file ieeefp.h
-- Looking for include file ieeefp.h - not found
-- Looking for include file alloca.h
-- Looking for include file alloca.h - found
-- Looking for include file sys/vmparam.h
-- Looking for include file sys/vmparam.h - found
-- Looking for include file mach/vm_types.h
-- Looking for include file mach/vm_types.h - found
-- Looking for include file mach/vm_param.h
-- Looking for include file mach/vm_param.h - found
-- Looking for include file procfs.h
-- Looking for include file procfs.h - not found
-- Looking for include file crt_externs.h
-- Looking for include file crt_externs.h - found
-- Looking for include file sys/time.h
-- Looking for include file sys/time.h - found
-- Looking for include file pthread_np.h
-- Looking for include file pthread_np.h - not found
-- Looking for include file sys/lwp.h
-- Looking for include file sys/lwp.h - not found
-- Looking for include file libunwind.h
-- Looking for include file libunwind.h - found
-- Looking for include file runetype.h
-- Looking for include file runetype.h - found
-- Looking for include file unicode/uchar.h
-- Looking for include file unicode/uchar.h - not found
-- Looking for kqueue
-- Looking for kqueue - found
-- Looking for getpwuid_r
-- Looking for getpwuid_r - found
-- Looking for pthread_suspend in pthread
-- Looking for pthread_suspend in pthread - not found
-- Looking for pthread_suspend_np in pthread
-- Looking for pthread_suspend_np in pthread - not found
-- Looking for pthread_continue in pthread
-- Looking for pthread_continue in pthread - not found
-- Looking for pthread_continue_np in pthread
-- Looking for pthread_continue_np in pthread - not found
-- Looking for pthread_resume_np in pthread
-- Looking for pthread_resume_np in pthread - not found
-- Looking for pthread_attr_get_np in pthread
-- Looking for pthread_attr_get_np in pthread - not found
-- Looking for pthread_getattr_np in pthread
-- Looking for pthread_getattr_np in pthread - not found
-- Looking for pthread_sigqueue in pthread
-- Looking for pthread_sigqueue in pthread - not found
-- Looking for sigreturn
-- Looking for sigreturn - not found
-- Looking for _thread_sys_sigreturn
-- Looking for _thread_sys_sigreturn - not found
-- Looking for copysign
-- Looking for copysign - found
-- Looking for fsync
-- Looking for fsync - found
-- Looking for futimes
-- Looking for futimes - found
-- Looking for utimes
-- Looking for utimes - found
-- Looking for sysctl
-- Looking for sysctl - found
-- Looking for sysconf
-- Looking for sysconf - found
-- Looking for localtime_r
-- Looking for localtime_r - found
-- Looking for gmtime_r
-- Looking for gmtime_r - found
-- Looking for timegm
-- Looking for timegm - found
-- Looking for _snwprintf
-- Looking for _snwprintf - not found
-- Looking for poll
-- Looking for poll - found
-- Looking for statvfs
-- Looking for statvfs - found
-- Looking for thread_self
-- Looking for thread_self - not found
-- Looking for _lwp_self
-- Looking for _lwp_self - not found
-- Looking for pthread_mach_thread_np
-- Looking for pthread_mach_thread_np - found
-- Looking for thread_set_exception_ports
-- Looking for thread_set_exception_ports - found
-- Looking for vm_allocate
-- Looking for vm_allocate - found
-- Looking for vm_read
-- Looking for vm_read - found
-- Looking for directio
-- Looking for directio - not found
-- Looking for semget
-- Looking for semget - found
-- Looking for pthread_mutex_init
-- Looking for pthread_mutex_init - found
-- Looking for ttrace
-- Looking for ttrace - not found
-- Performing Test HAVE_STAT_TIMESPEC
-- Performing Test HAVE_STAT_TIMESPEC - Success
-- Performing Test HAVE_STAT_NSEC
-- Performing Test HAVE_STAT_NSEC - Failed
-- Performing Test HAVE_TM_GMTOFF
-- Performing Test HAVE_TM_GMTOFF - Success
-- Performing Test HAVE_GREGSET_T
-- Performing Test HAVE_GREGSET_T - Failed
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of struct reg
-- Check size of struct reg - failed
-- Check size of struct pt_regs
-- Check size of struct pt_regs - failed
-- Check size of siginfo_t
-- Check size of siginfo_t - done
-- Check size of ucontext_t
-- Check size of ucontext_t - failed
-- Check size of pthread_rwlock_t
-- Check size of pthread_rwlock_t - done
-- Check size of prwatch_t
-- Check size of prwatch_t - failed
-- Check size of off_t
-- Check size of off_t - done
-- Looking for SYS_yield
-- Looking for SYS_yield - not found
-- Looking for INFTIM
-- Looking for INFTIM - not found
-- Looking for CHAR_BIT
-- Looking for CHAR_BIT - not found
-- Looking for _DEBUG
-- Looking for _DEBUG - not found
-- Looking for _SC_PHYS_PAGES
-- Looking for _SC_PHYS_PAGES - found
-- Looking for _SC_AVPHYS_PAGES
-- Looking for _SC_AVPHYS_PAGES - not found
-- Performing Test PLATFORM_ACCEPTS_ABS_OVERLOAD
-- Performing Test PLATFORM_ACCEPTS_ABS_OVERLOAD - Success
-- Performing Test REALPATH_SUPPORTS_NONEXISTENT_FILES
-- Performing Test REALPATH_SUPPORTS_NONEXISTENT_FILES - Failed
-- Performing Test SSCANF_SUPPORT_ll
-- Performing Test SSCANF_SUPPORT_ll - Success
-- Performing Test SSCANF_CANNOT_HANDLE_MISSING_EXPONENT
-- Performing Test SSCANF_CANNOT_HANDLE_MISSING_EXPONENT - Failed
-- Performing Test HAVE_LARGE_SNPRINTF_SUPPORT
-- Performing Test HAVE_LARGE_SNPRINTF_SUPPORT - Success
-- Performing Test HAVE_BROKEN_FIFO_SELECT
-- Performing Test HAVE_BROKEN_FIFO_SELECT - Failed
-- Performing Test HAVE_BROKEN_FIFO_KEVENT
-- Performing Test HAVE_BROKEN_FIFO_KEVENT - Failed
-- Performing Test HAVE_SCHED_GET_PRIORITY
-- Performing Test HAVE_SCHED_GET_PRIORITY - Success
-- Performing Test HAVE_SCHED_GETCPU
-- Performing Test HAVE_SCHED_GETCPU - Failed
-- Performing Test HAVE_WORKING_GETTIMEOFDAY
-- Performing Test HAVE_WORKING_GETTIMEOFDAY - Success
-- Performing Test HAVE_WORKING_CLOCK_GETTIME
-- Performing Test HAVE_WORKING_CLOCK_GETTIME - Success
-- Performing Test HAVE_CLOCK_MONOTONIC
-- Performing Test HAVE_CLOCK_MONOTONIC - Success
-- Performing Test HAVE_CLOCK_MONOTONIC_COARSE
-- Performing Test HAVE_CLOCK_MONOTONIC_COARSE - Failed
-- Performing Test HAVE_MACH_ABSOLUTE_TIME
-- Performing Test HAVE_MACH_ABSOLUTE_TIME - Success
-- Performing Test HAVE_CLOCK_THREAD_CPUTIME
-- Performing Test HAVE_CLOCK_THREAD_CPUTIME - Success
-- Performing Test HAVE_MMAP_DEV_ZERO
-- Performing Test HAVE_MMAP_DEV_ZERO - Failed
-- Performing Test MMAP_IGNORES_HINT
-- Performing Test MMAP_IGNORES_HINT - Failed
-- Performing Test MMAP_ANON_IGNORES_PROTECTION
-- Performing Test MMAP_ANON_IGNORES_PROTECTION - Failed
-- Performing Test MMAP_DOESNOT_ALLOW_REMAP
-- Performing Test MMAP_DOESNOT_ALLOW_REMAP - Failed
-- Performing Test ONE_SHARED_MAPPING_PER_FILEREGION_PER_PROCESS
-- Performing Test ONE_SHARED_MAPPING_PER_FILEREGION_PER_PROCESS - Failed
-- Performing Test PTHREAD_CREATE_MODIFIES_ERRNO
-- Performing Test PTHREAD_CREATE_MODIFIES_ERRNO - Failed
-- Performing Test SEM_INIT_MODIFIES_ERRNO
-- Performing Test SEM_INIT_MODIFIES_ERRNO - Failed
-- Performing Test HAVE_PROCFS_CTL
-- Performing Test HAVE_PROCFS_CTL - Failed
-- Performing Test HAVE_COMPATIBLE_ACOS
-- Performing Test HAVE_COMPATIBLE_ACOS - Success
-- Performing Test HAVE_COMPATIBLE_ASIN
-- Performing Test HAVE_COMPATIBLE_ASIN - Success
-- Performing Test HAVE_COMPATIBLE_ATAN2
-- Performing Test HAVE_COMPATIBLE_ATAN2 - Success
-- Performing Test HAVE_COMPATIBLE_EXP
-- Performing Test HAVE_COMPATIBLE_EXP - Failed
-- Performing Test HAVE_COMPATIBLE_LOG
-- Performing Test HAVE_COMPATIBLE_LOG - Success
-- Performing Test HAVE_COMPATIBLE_LOG10
-- Performing Test HAVE_COMPATIBLE_LOG10 - Success
-- Performing Test UNGETC_NOT_RETURN_EOF
-- Performing Test UNGETC_NOT_RETURN_EOF - Failed
-- Performing Test HAS_POSIX_SEMAPHORES
-- Performing Test HAS_POSIX_SEMAPHORES - Failed
-- Performing Test GETPWUID_R_SETS_ERRNO
-- Performing Test GETPWUID_R_SETS_ERRNO - Failed
-- Performing Test FILE_OPS_CHECK_FERROR_OF_PREVIOUS_CALL
-- Performing Test FILE_OPS_CHECK_FERROR_OF_PREVIOUS_CALL - Failed
-- Performing Test UNWIND_CONTEXT_IS_UCONTEXT_T
-- Performing Test UNWIND_CONTEXT_IS_UCONTEXT_T - Failed
-- Configuring done
-- Generating done
[…]

Here’s the full log: https://bot.brew.sh/job/Homebrew%20Core/15413/version=el_capitan/testReport/junit/brew-test-bot/el_capitan/install_chakra/

@obastemur
Copy link
Collaborator

IIRC Homebrew pushes for recent libc++ for osx 10.9+..

While installing with homebrew, you should use --env=std argument with brew install ... command. The rest should be just fine.

@obastemur obastemur changed the title [Question] Undefined symbols for architecture x86_64 [homebrew] Default install environment gives linker errors Jan 27, 2017
@MikeMcQuaid
Copy link

IIRC Homebrew pushes for recent libc++ for osx 10.9+..

Homebrew lead maintainer here: can you elaborate on what this means as I'm not sure I understand.

While installing with homebrew, you should use --env=std argument with brew install ... command. The rest should be just fine.

We consider env :std to be deprecated and anything that requires it to either be a env :super or upstream build system bug.

@mathiasbynens
Copy link
Contributor Author

@ilovezfs figured it out:

The problem is not the c++ library; it's the optimization. Adding ENV.O3 to the install method should fix it for you.

@ilovezfs
Copy link

ilovezfs commented Jan 27, 2017

Incidentally, the fact that -Os doesn't work "should" be considered a bug worth fixing by upstream IMO.

@ilovezfs
Copy link

ilovezfs commented Jan 27, 2017

Also, it's a bit sketchy a new formula is using libstdc++ and that c++11 kills it.

@obastemur
Copy link
Collaborator

Homebrew lead maintainer here: can you elaborate on what this means as I'm not sure I understand.

IIRC Homebrew pushes for recent libc++ for osx 10.9+..

I might remember this wrong but Homebrew build sets mmacosx-version-min explicitly to latest. No?

@ilovezfs
Copy link

We set the environment variable MACOSX_DEPLOYMENT_TARGET to the same as the host.

obastemur added a commit to obastemur/ChakraCore that referenced this issue Jan 27, 2017
@obastemur
Copy link
Collaborator

CC build script sets macos deployment target to 10.7 in order not to introduce libc++/libstdc++ mix into ChakraCore dependent solutions. These solutions similarly target 10.7 SDK. Apart from that, there is no particular reason for us to pick libstdc++ over libc++ at the moment. At least, I'm not aware any other reason.

We set the environment variable MACOSX_DEPLOYMENT_TARGET to the same as the host.

In that case;

Upcoming change to our build script; if 'MACOSX_DEPLOYMENT_TARGET' environment variable was already set, do not force 10.7.

164cda7

@ilovezfs
Copy link

@obastemur cool. It would be great if we could build with ENV.cxx11 set, which passes -std=c++11 -stdlib=libc++ because we've been considering turning that on as a default at some point.

Any idea why ChakraCore isn't happy with -Os? That's pretty unusual. In Homebrew, only eleven of the 3,804 formulae have to specify their own optimization setting to override the default -Os.

@obastemur
Copy link
Collaborator

Any idea why ChakraCore isn't happy with -Os?

No particular reason, just a bug. Fixed on CC end. Suspicious behavior though.

All these changes will be part of upcoming xplat release.

@ilovezfs
Copy link

@obastemur nice work! With the patch, -Os succeeded.

However, if I (on macOS 10.11)

    inreplace "CMakeLists.txt", "mmacosx-version-min=10.7",
                                "mmacosx-version-min=#{MacOS.version}"

I get

[100%] Linking CXX executable ch
Undefined symbols for architecture x86_64:
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::__init(char const*, unsigned long)", referenced from:
      WScriptJsrt::FetchImportedModule(void*, void*, void**) in WScriptJsrt.cpp.o
      WScriptJsrt::LoadModuleFromString(char const*, char const*) in WScriptJsrt.cpp.o
  "std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >::~basic_string()", referenced from:
      WScriptJsrt::FetchImportedModule(void*, void*, void**) in WScriptJsrt.cpp.o
      WScriptJsrt::LoadModuleFromString(char const*, char const*) in WScriptJsrt.cpp.o
      std::__1::__tree<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void*>, std::__1::__map_value_compare<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void*>, std::__1::less<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >, true>, std::__1::allocator<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void*> > >::destroy(std::__1::__tree_node<std::__1::__value_type<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, void*>, void*>*) in WScriptJsrt.cpp.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [bin/ch/ch] Error 1
make[1]: *** [bin/ch/CMakeFiles/ch.dir/all] Error 2
make: *** [all] Error 2

@obastemur
Copy link
Collaborator

@ilovezfs you don't need to replace anything. Right now, on the master branch, if MACOSX_DEPLOYMENT_TARGET is set, we don't set mmacosx-version-min at all.

@obastemur
Copy link
Collaborator

@mathiasbynens Thanks for opening this up! @ilovezfs @MikeMcQuaid Thanks for all the help to figure out the issues.

Merging the PR closed this issue automatically. Both -Os and osx sdk target issues should be fixed on the master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants