[llvm] r193498 - MCJIT-remote: __main should be resolved in child context.

NAKAMURA Takumi geek4civic at gmail.com
Mon Oct 28 17:16:48 PDT 2013


Andy,

Thanks for working. Unfortunately, It didn't resolve the issue.
__main is inserted at codegen (X86ISelDAGToDAG) and is not found in IR level.
I guess it requires to resolve symbols, like runtime libraries, in
child context.

...Takumi

2013/10/29 Kaylor, Andrew <andrew.kaylor at intel.com>:
> After sending the reply below I took a closer look at the code that was generating the "__main" function call and the code in RTDyldMemoryManager that resolves it in the local case.  That made it clear that what I suggested below is not going to work and that the problem shouldn't be addressed in MCJIT/RuntimeDyld anyway.  However, I think I understand what's going on now and how we can handle it.
>
> The attached patch creates an extra module containing an empty "__main" function and adds it to the ExecutionEngine if the target is Cygwin or MinGW and lli is generating for remote MCJIT execution.  This should handle/hide the linking problem you are seeing.  It may also be possible to just add the "__main" function directly to the main module.  Obviously this isn't what a client would want to do in most cases, but I don't think it's realistic to try to generalize the lli remote implementation to real world usage anyway.
>
> I don't have a system set up for MinGW or Cygwin use, so I haven't tested the attached patch beyond just building it.  Could you give it a try and let me know what you think of it?
>
> Thanks,
> Andy
>
> -----Original Message-----
> From: llvm-commits-bounces at cs.uiuc.edu [mailto:llvm-commits-bounces at cs.uiuc.edu] On Behalf Of Kaylor, Andrew
> Sent: Monday, October 28, 2013 10:24 AM
> To: NAKAMURA Takumi; llvm-commits at cs.uiuc.edu
> Subject: RE: [llvm] r193498 - MCJIT-remote: __main should be resolved in child context.
>
> Would it be possible to fix this problem at the MCJIT level?  MCJIT now has a linking memory manager (which wraps the client memory manager to enable multiple module handling).  If there is another generated symbol ('main' without the underscores?) which it would be appropriate to use in place of '__main' the LinkingMemoryManager could do that when the target is Cyg/Ming.
>
> -Andy
>
> -----Original Message-----
> From: llvm-commits-bounces at cs.uiuc.edu [mailto:llvm-commits-bounces at cs.uiuc.edu] On Behalf Of NAKAMURA Takumi
> Sent: Sunday, October 27, 2013 3:23 AM
> To: llvm-commits at cs.uiuc.edu
> Subject: [llvm] r193498 - MCJIT-remote: __main should be resolved in child context.
>
> Author: chapuni
> Date: Sun Oct 27 05:22:52 2013
> New Revision: 193498
>
> URL: http://llvm.org/viewvc/llvm-project?rev=193498&view=rev
> Log:
> MCJIT-remote: __main should be resolved in child context.
>
>   - Mark tests as XFAIL:cygming in test/ExecutionEngine/MCJIT/remote.
>     Rather to suppress them, I'd like to leave them running as XFAIL.
>   - Revert r193472. RecordMemoryManager no longer resolves __main on cygming.
>
> There are a couple of issues.
>
>   - X86 Codegen emits "call __main" in @main for targeting cygming.
>     It is useless in JIT. FYI, tests are passing when emitting __main is disabled.
>   - Current remote JIT does not resolve any symbols in child context.
>
> FIXME: __main should be disabled, or remote JIT should resolve __main.
>
> Modified:
>     llvm/trunk/test/ExecutionEngine/MCJIT/remote/cross-module-a.ll
>     llvm/trunk/test/ExecutionEngine/MCJIT/remote/multi-module-a.ll
>     llvm/trunk/test/ExecutionEngine/MCJIT/remote/simpletest-remote.ll
>     llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-common-symbols-remote.ll
>     llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-data-align-remote.ll
>     llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-fp-no-external-funcs-remote.ll
>     llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-global-init-nonzero-remote.ll
>     llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-ptr-reloc-remote.ll
>     llvm/trunk/tools/lli/RemoteMemoryManager.cpp
>     llvm/trunk/tools/lli/RemoteMemoryManager.h
>
> Modified: llvm/trunk/test/ExecutionEngine/MCJIT/remote/cross-module-a.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/MCJIT/remote/cross-module-a.ll?rev=193498&r1=193497&r2=193498&view=diff
> ==============================================================================
> --- llvm/trunk/test/ExecutionEngine/MCJIT/remote/cross-module-a.ll (original)
> +++ llvm/trunk/test/ExecutionEngine/MCJIT/remote/cross-module-a.ll Sun
> +++ Oct 27 05:22:52 2013
> @@ -1,5 +1,8 @@
>  ; RUN: %lli_mcjit -extra-modules=%p/cross-module-b.ir  -disable-lazy-compilation=true -remote-mcjit -mcjit-remote-process=lli-child-target %s > /dev/null
>
> +; This fails because __main is not resolved in remote mcjit.
> +; XFAIL: cygwin,mingw32
> +
>  declare i32 @FB()
>
>  define i32 @FA() {
>
> Modified: llvm/trunk/test/ExecutionEngine/MCJIT/remote/multi-module-a.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/MCJIT/remote/multi-module-a.ll?rev=193498&r1=193497&r2=193498&view=diff
> ==============================================================================
> --- llvm/trunk/test/ExecutionEngine/MCJIT/remote/multi-module-a.ll (original)
> +++ llvm/trunk/test/ExecutionEngine/MCJIT/remote/multi-module-a.ll Sun
> +++ Oct 27 05:22:52 2013
> @@ -1,5 +1,8 @@
>  ; RUN: %lli_mcjit -extra-modules=%p/multi-module-b.ir,%p/multi-module-c.ir  -disable-lazy-compilation=true -remote-mcjit -mcjit-remote-process=lli-child-target %s > /dev/null
>
> +; This fails because __main is not resolved in remote mcjit.
> +; XFAIL: cygwin,mingw32
> +
>  declare i32 @FB()
>
>  define i32 @main() {
>
> Modified: llvm/trunk/test/ExecutionEngine/MCJIT/remote/simpletest-remote.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/MCJIT/remote/simpletest-remote.ll?rev=193498&r1=193497&r2=193498&view=diff
> ==============================================================================
> --- llvm/trunk/test/ExecutionEngine/MCJIT/remote/simpletest-remote.ll (original)
> +++ llvm/trunk/test/ExecutionEngine/MCJIT/remote/simpletest-remote.ll
> +++ Sun Oct 27 05:22:52 2013
> @@ -1,5 +1,7 @@
>  ; RUN: %lli_mcjit -remote-mcjit -mcjit-remote-process=lli-child-target %s > /dev/null -; XFAIL:  mips
> +
> +; This fails because __main is not resolved in remote mcjit on cygming.
> +; XFAIL: cygwin,mingw32,mips
>
>  define i32 @bar() {
>         ret i32 0
>
> Modified: llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-common-symbols-remote.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-common-symbols-remote.ll?rev=193498&r1=193497&r2=193498&view=diff
> ==============================================================================
> --- llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-common-symbols-remote.ll (original)
> +++ llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-common-symbols-rem
> +++ ote.ll Sun Oct 27 05:22:52 2013
> @@ -1,5 +1,7 @@
>  ; RUN: %lli_mcjit -remote-mcjit -O0 -disable-lazy-compilation=false -mcjit-remote-process=lli-child-target %s -; XFAIL: mips
> +
> +; This fails because __main is not resolved in remote mcjit on cygming.
> +; XFAIL: cygwin,mingw32,mips
>
>  ; The intention of this test is to verify that symbols mapped to COMMON in ELF  ; work as expected.
>
> Modified: llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-data-align-remote.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-data-align-remote.ll?rev=193498&r1=193497&r2=193498&view=diff
> ==============================================================================
> --- llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-data-align-remote.ll (original)
> +++ llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-data-align-remote.
> +++ ll Sun Oct 27 05:22:52 2013
> @@ -1,5 +1,7 @@
>  ; RUN:  %lli_mcjit -remote-mcjit -O0 -mcjit-remote-process=lli-child-target %s -; XFAIL: mips
> +
> +; This fails because __main is not resolved in remote mcjit on cygming.
> +; XFAIL: cygwin,mingw32,mips
>
>  ; Check that a variable is always aligned as specified.
>
>
> Modified: llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-fp-no-external-funcs-remote.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-fp-no-external-funcs-remote.ll?rev=193498&r1=193497&r2=193498&view=diff
> ==============================================================================
> --- llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-fp-no-external-funcs-remote.ll (original)
> +++ llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-fp-no-external-fun
> +++ cs-remote.ll Sun Oct 27 05:22:52 2013
> @@ -1,5 +1,7 @@
>  ; RUN: %lli_mcjit -remote-mcjit -mcjit-remote-process=lli-child-target %s > /dev/null -; XFAIL:  mips
> +
> +; This fails because __main is not resolved in remote mcjit on cygming.
> +; XFAIL: cygwin,mingw32,mips
>
>  define double @test(double* %DP, double %Arg) {
>         %D = load double* %DP           ; <double> [#uses=1]
>
> Modified: llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-global-init-nonzero-remote.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-global-init-nonzero-remote.ll?rev=193498&r1=193497&r2=193498&view=diff
> ==============================================================================
> --- llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-global-init-nonzero-remote.ll (original)
> +++ llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-global-init-nonzer
> +++ o-remote.ll Sun Oct 27 05:22:52 2013
> @@ -1,5 +1,7 @@
>  ; RUN: %lli_mcjit -remote-mcjit -mcjit-remote-process=lli-child-target %s > /dev/null -; XFAIL: mips
> +
> +; This fails because __main is not resolved in remote mcjit on cygming.
> +; XFAIL: cygwin,mingw32,mips
>
>  @count = global i32 1, align 4
>
>
> Modified: llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-ptr-reloc-remote.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-ptr-reloc-remote.ll?rev=193498&r1=193497&r2=193498&view=diff
> ==============================================================================
> --- llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-ptr-reloc-remote.ll (original)
> +++ llvm/trunk/test/ExecutionEngine/MCJIT/remote/test-ptr-reloc-remote.l
> +++ l Sun Oct 27 05:22:52 2013
> @@ -1,5 +1,8 @@
>  ; RUN: %lli_mcjit -remote-mcjit -O0 -mcjit-remote-process=lli-child-target %s
>
> +; This fails because __main is not resolved in remote mcjit.
> +; XFAIL: cygwin,mingw32
> +
>  @.str = private unnamed_addr constant [6 x i8] c"data1\00", align 1  @ptr = global i8* getelementptr inbounds ([6 x i8]* @.str, i32 0, i32 0), align 4
>  @.str1 = private unnamed_addr constant [6 x i8] c"data2\00", align 1
>
> Modified: llvm/trunk/tools/lli/RemoteMemoryManager.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lli/RemoteMemoryManager.cpp?rev=193498&r1=193497&r2=193498&view=diff
> ==============================================================================
> --- llvm/trunk/tools/lli/RemoteMemoryManager.cpp (original)
> +++ llvm/trunk/tools/lli/RemoteMemoryManager.cpp Sun Oct 27 05:22:52
> +++ 2013
> @@ -204,19 +204,3 @@ uint8_t *RemoteMemoryManager::allocateGl  void RemoteMemoryManager::deallocateFunctionBody(void *Body) {
>    llvm_unreachable("Unexpected!");
>  }
> -
> -static int jit_noop() {
> -  return 0;
> -}
> -
> -uint64_t RemoteMemoryManager::getSymbolAddress(const std::string &Name) {
> -  // We should not invoke parent's ctors/dtors from generated main()!
> -  // On Mingw and Cygwin, the symbol __main is resolved to
> -  // callee's(eg. tools/lli) one, to invoke wrong duplicated ctors
> -  // (and register wrong callee's dtors with atexit(3)).
> -  // We expect ExecutionEngine::runStaticConstructorsDestructors()
> -  // is called before ExecutionEngine::runFunctionAsMain() is called.
> -  if (Name == "__main") return (uintptr_t)&jit_noop;
> -
> -  return 0;
> -}
>
> Modified: llvm/trunk/tools/lli/RemoteMemoryManager.h
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lli/RemoteMemoryManager.h?rev=193498&r1=193497&r2=193498&view=diff
> ==============================================================================
> --- llvm/trunk/tools/lli/RemoteMemoryManager.h (original)
> +++ llvm/trunk/tools/lli/RemoteMemoryManager.h Sun Oct 27 05:22:52 2013
> @@ -78,7 +78,7 @@ public:
>    // interface does support this, but clients must provide their own
>    // mechanism for finding remote symbol addresses.  MCJIT will resolve
>    // symbols from Modules it contains.
> -  uint64_t getSymbolAddress(const std::string &Name);
> +  uint64_t getSymbolAddress(const std::string &Name) { return 0; }
>
>    void notifyObjectLoaded(ExecutionEngine *EE, const ObjectImage *Obj);
>
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits




More information about the llvm-commits mailing list