You wrote:
>If I run `go build test.go`, when does llvm-goc executable start to run?
Does go build command replace its' existing compiler with llvm-goc?

The "go" command, the program that orchestrates the building of Go
programs, runs 'llvm-goc' at each point where it needs to compile a Go
package, and then at the point where it needs to do a final link step to
create an executable.

You can learn more about how the compiler is invoked by the Go command
(what is happening "under the hood" so to speak) by using the "-x" option
with go build. E.g.

  $ go clean -cache
  $ go build -x myprogram.go 1> transcript.txt 2>&1
  $

then inspect "transcript.txt" to see how the compiler is being invoked.

If your program "myprogram.go" imports packages P1 and P2, then in the
transcript
you would expect to see (at minimum) an invocation of llvm-goc for P1, for
P2, then for the main package,  and for the final link.

Also:
>Does go build command replace its' existing compiler with llvm-goc?

More or less. The set of command line flags supported by the two compilers
is completely different (and there are many other implementation
differences), so there will be some differences in the build steps.

Than




On Sat, Jun 26, 2021 at 1:10 PM Kavindu Gimhan Zoysa <kavindu...@gmail.com>
wrote:

> Hi,
>
> Thank you for your detailed explanation. I will try your suggestions and
> let you know.
>
> I used this cmake command.
> `cmake -DCMAKE_INSTALL_PREFIX=/my/install/dir -DCMAKE_BUILD_TYPE=Release
> -DLLVM_USE_LINKER=gold -G Ninja ../llvm-project/llvm`
>
> Then I used, `ninja gollvm`, and it was successful.
>
> Also, I used, `ninja install-gollvm`, but nothing happens.
>
> I have a couple of unclear points. As I know, llvm-goc is a tool that
> generates llvm IR for a go source code.
> If I run `go build test.go`, when does llvm-goc executable start to run?
> Does go build command replace its' existing compiler with llvm-goc?
>
> Thank you,
> Kavindu
> On Friday, 25 June 2021 at 19:52:16 UTC+5:30 th...@google.com wrote:
>
>> Hello again,
>>
>> Couple of things.
>>
>> First, it is important to keep in mind that the "llvm-goc" binary is not
>> intended to be used as a top level go compiler, in the same way that the
>> "gcc" or "clang" commands are used as top-level C/C++ compilers. The normal
>> use case is to use "go build" as opposed to invoking llvm-goc directly.
>> Just to recap: build the 'install-gollvm' ninja target (as described in
>> https://go.googlesource.com/gollvm/#installing), prepend the install dir
>> "bin" directory in your path, and then run "go build".
>>
>> It's also problematic to run llvm-goc directly out of the build area
>> instead of doing and install and using the copy in the install dir. For
>> example, if I do a build of llvm-goc in my LLVM build area, then invoke it
>> directly on a small Go program, this is what I see:
>>
>> $ ./bin/llvm-goc smallmain.go
>> /usr/bin/ld.gold: error: cannot find -lgobegin
>> /usr/bin/ld.gold: error: cannot find -lgo
>> /usr/lib/gcc/x86_64-linux-gnu/10/../../../x86_64-linux-gnu/crt1.o:function
>> _start: error: undefined reference to 'main'
>> <built-in>:1: error: undefined reference to
>> 'runtime.registerTypeDescriptors'
>> smallmain.go:4: error: undefined reference to 'runtime.printlock'
>> smallmain.go:4: error: undefined reference to 'runtime.printint'
>> smallmain.go:4: error: undefined reference to 'runtime.printnl'
>> smallmain.go:4: error: undefined reference to 'runtime.printunlock'
>> $
>>
>> Here the compiler is unable to find the right runtime libraries. I'll see
>> if I can update the documentation to make this a little clearer.
>>
>> Regarding the crash you're seeing when building from
>>
>>  LLVM: 43ff75f2c3feef64f9d73328230d34dac8832a91
>> gollvm: 44a7a475cfd3b871b7a5a0941b8ab1ea9d489adc
>> gofrontend: be0d2cc2df9f98d967c242594838f86362dae2e7
>> libbacktrace: 5a99ff7fed66b8ea8f09c9805c138524a7035ece
>> libffi: 737d4faa00d681b4c758057f67e1a02d813d01c2
>>
>>
>> Sorry, but I can't reproduce your crash (I did another build using the
>> config above and it seems to work ok). What is the exact cmake command
>> you're using to set up your build area?
>>
>> You might also try this: in your LLVM build area, run "ninja
>> llvm-symbolizer" and then set
>>
>> export LLVM_SYMBOLIZER=${HERE}/bin/llvm-symbolizer
>>
>> then rerun the failing "llvm-goc" invocation, that might give you a
>> better stack trace.
>>
>> Thanks, Than
>>
>>
>>
>> On Thu, Jun 24, 2021 at 2:53 PM Kavindu Gimhan Zoysa <kavin...@gmail.com>
>> wrote:
>>
>>> I did not use any *go build* command. Sorry if I missed anything. These
>>> are the steps I followed.
>>>
>>> 1. Build gollvm referring to the official documentation. I followed the
>>> steps until https://go.googlesource.com/gollvm/#cmakeninja.
>>> 2. I was able to see the *llvm-goc *in the bin folder.  I export the
>>> path using '*export
>>> LD_LIBRARY_PATH=<HOME>/build-debug/libgo/x86_64-unknown-linux-gnu' *
>>> command.
>>> 3. Then I tried to dump the llvm IR using '*../bin/llvm-goc -S test.go
>>> -dump-ir', *and it was successful.
>>> 4. Then I ran this command '*./bin/llvm-goc test.go'*. I got the above
>>> error.
>>>
>>> Did i miss anything?
>>>
>>> Thank you,
>>> Kavindu
>>> On Friday, 25 June 2021 at 00:01:41 UTC+5:30 th...@google.com wrote:
>>>
>>>> Could you please post the complete "go build" command?
>>>>
>>>> Thanks, Than
>>>>
>>>> On Thu, Jun 24, 2021 at 2:05 PM Kavindu Gimhan Zoysa <
>>>> kavin...@gmail.com> wrote:
>>>>
>>>>> Hi all,
>>>>>
>>>>> Still, I was unable to figure out the reason for the above error.
>>>>> Really appreciate your help.
>>>>>
>>>>> Thank you,
>>>>> Kavindu
>>>>>
>>>>> On Thursday, 24 June 2021 at 12:06:32 UTC+5:30 Kavindu Gimhan Zoysa
>>>>> wrote:
>>>>>
>>>>>> Hi all,
>>>>>>
>>>>>> I have build the gollvm and now I am trying to run it. So I run
>>>>>> follwing command against a simple go source code. I am getting below 
>>>>>> error.
>>>>>> Really appreciate your input to solve this issue.
>>>>>>
>>>>>> command :
>>>>>> *./bin/llvm-goc test.go*
>>>>>>
>>>>>> error:
>>>>>> *llvm-goc:
>>>>>> /home/kavindu/GIT/llvm-project/llvm/tools/gollvm/driver/Action.cpp:51:
>>>>>> const char* gollvm::driver::Action::resultFileSuffix() const: Assertion
>>>>>> `false' failed.*
>>>>>> *../bin/llvm-goc(+0x2c46a3f)[0x55a113e42a3f]*
>>>>>> *../bin/llvm-goc(+0x2c46ad6)[0x55a113e42ad6]*
>>>>>> *../bin/llvm-goc(+0x2c44829)[0x55a113e40829]*
>>>>>> *../bin/llvm-goc(+0x2c46387)[0x55a113e42387]*
>>>>>> */lib/x86_64-linux-gnu/libpthread.so.0(+0x153c0)[0x7f67e0aad3c0]*
>>>>>> */lib/x86_64-linux-gnu/libc.so.6(gsignal+0xcb)[0x7f67e056818b]*
>>>>>> */lib/x86_64-linux-gnu/libc.so.6(abort+0x12b)[0x7f67e0547859]*
>>>>>> */lib/x86_64-linux-gnu/libc.so.6(+0x25729)[0x7f67e0547729]*
>>>>>> */lib/x86_64-linux-gnu/libc.so.6(+0x36f36)[0x7f67e0558f36]*
>>>>>> *../bin/llvm-goc(+0x827e69)[0x55a111a23e69]*
>>>>>> *../bin/llvm-goc(+0x8167d5)[0x55a111a127d5]*
>>>>>> *../bin/llvm-goc(+0x81db02)[0x55a111a19b02]*
>>>>>> *../bin/llvm-goc(+0x81ddfb)[0x55a111a19dfb]*
>>>>>> *../bin/llvm-goc(+0x811cb9)[0x55a111a0dcb9]*
>>>>>>
>>>>>> */lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf3)[0x7f67e05490b3]*
>>>>>> *../bin/llvm-goc(+0x81112e)[0x55a111a0d12e]*
>>>>>> *PLEASE submit a bug report to https://bugs.llvm.org/
>>>>>> <https://bugs.llvm.org/> and include the crash backtrace.*
>>>>>> *Stack dump:*
>>>>>> *0. Program arguments: ../bin/llvm-goc test.go *
>>>>>> *Aborted (core dumped)*
>>>>>>
>>>>>> I have build gollvm using exact commits as shown here.
>>>>>> https://groups.google.com/g/golang-nuts/c/E770QGuKkpU/m/sJFuarbrBQAJ
>>>>>>
>>>>>> Thank you,
>>>>>> Kavindu
>>>>>>
>>>>> --
>>>>> You received this message because you are subscribed to the Google
>>>>> Groups "golang-nuts" group.
>>>>> To unsubscribe from this group and stop receiving emails from it, send
>>>>> an email to golang-nuts...@googlegroups.com.
>>>>> To view this discussion on the web visit
>>>>> https://groups.google.com/d/msgid/golang-nuts/5a73b285-1252-400a-9259-20b2d7f68e5cn%40googlegroups.com
>>>>> <https://groups.google.com/d/msgid/golang-nuts/5a73b285-1252-400a-9259-20b2d7f68e5cn%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "golang-nuts" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to golang-nuts...@googlegroups.com.
>>>
>> To view this discussion on the web visit
>>> https://groups.google.com/d/msgid/golang-nuts/834df407-71f3-48d4-8d93-0f1e3c6ab714n%40googlegroups.com
>>> <https://groups.google.com/d/msgid/golang-nuts/834df407-71f3-48d4-8d93-0f1e3c6ab714n%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/golang-nuts/b3d9d30c-2ff2-48fe-aee4-01be7551609an%40googlegroups.com
> <https://groups.google.com/d/msgid/golang-nuts/b3d9d30c-2ff2-48fe-aee4-01be7551609an%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CA%2BUr55HdtJ8CCO5wqOwww-vAs1Cr0b1bPrjefQSMc6F0V%3Dh2xQ%40mail.gmail.com.

Reply via email to