<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <p>Hi David<br>
    </p>
    <div class="moz-cite-prefix">On 25/01/19 4:12 AM, David Blaikie
      wrote:<br>
    </div>
    <blockquote type="cite"
cite="mid:CAENS6Eu8u0kHxNucZ5hyC54-8kjQSsFb7sskfDJhwiHW_NtGKA@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">Still haven't had much luck reproducing this<br>
        <div class="gmail_quote">
          <div dir="ltr" class="m_181879325336469943gmail_attr">On Thu,
            Jan 24, 2019 at 1:19 PM preejackie <<a
              href="mailto:praveenvelliengiri@gmail.com" target="_blank"
              moz-do-not-send="true">praveenvelliengiri@gmail.com</a>>
            wrote:<br>
          </div>
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div bgcolor="#FFFFFF" text="#000000">
              <p>Hi David!</p>
              <p>Thanks for reaching out, the codegen part of the
                tutorial is fine, but when I try to generate the object
                code file, it throws segfault. Also please note that I'm
                using release build of llvm, actually I don't know
                whether that is the root cause or not.</p>
              <p>I also run through valgrind, it seems like a invalid
                read from stack.</p>
              <p><code><samp></samp></code><code><samp>Error Summary:<br>
                  </samp></code></p>
              <p><code><samp>1 errors in context 1 of 1:<br>
                    ==4153== Invalid read of size 1<br>
                    ==4153==    at 0x4AFEE0:
                    llvm::optional_detail::OptionalStorage<llvm::Reloc::Model,
true>::OptionalStorage(llvm::optional_detail::OptionalStorage<llvm::Reloc::Model,
                    true> const&) (in /home/preejackie/kld/toy)<br>
                    ==4153==    by 0x4B098D:
llvm::RegisterTargetMachine<llvm::X86TargetMachine>::Allocator(llvm::Target
                    const&, llvm::Triple const&,
                    llvm::StringRef, llvm::StringRef,
                    llvm::TargetOptions const&,
                    llvm::Optional<llvm::Reloc::Model>,
                    llvm::Optional<llvm::CodeModel::Model>,
                    llvm::CodeGenOpt::Level, bool) (in
                    /home/preejackie/kld/toy)<br>
                    ==4153==    by 0x46CE5B: createTargetMachine
                    (TargetRegistry.h:397)<br>
                    ==4153==    by 0x46CE5B: main (kjit.cpp:1337)<br>
                    ==4153==  Address 0x4 is not stack'd, malloc'd or
                    (recently) free'd<br>
                  </samp></code></p>
              <p>Source compile command : clang++ -g -O3 kjit.cpp
                `llvm-config --cxxflags --ldflags --system-libs --libs
                all` -o toy</p>
              <p>Please, let me know that if you need some additional
                information :)</p>
              <p>Thanks a lot <br>
              </p>
            </div>
          </blockquote>
          <div><br>
            Oh, hmm, this might be that ABI problem <a
              href="https://bugs.llvm.org/show_bug.cgi?id=39427"
              moz-do-not-send="true">https://bugs.llvm.org/show_bug.cgi?id=39427</a> -
            if the release you're using was built with GCC and you're
            building your code with Clang, that could be it.<br>
            <br>
            Maybe try building with GCC?<br>
            <br>
          </div>
        </div>
      </div>
    </blockquote>
    <p>  Yes, I tried to compile with GCC it works fine. <br>
    </p>
    <p>  Thanks a lot <br>
    </p>
    <blockquote type="cite"
cite="mid:CAENS6Eu8u0kHxNucZ5hyC54-8kjQSsFb7sskfDJhwiHW_NtGKA@mail.gmail.com">
      <div dir="ltr">
        <div class="gmail_quote">
          <blockquote class="gmail_quote" style="margin:0 0 0
            .8ex;border-left:1px #ccc solid;padding-left:1ex">
            <div bgcolor="#FFFFFF" text="#000000">
              <p> </p>
            </div>
            <div bgcolor="#FFFFFF" text="#000000">
              <div
                class="m_181879325336469943m_1417450841655898947moz-cite-prefix">On
                25/01/19 1:47 AM, David Blaikie wrote:<br>
              </div>
              <blockquote type="cite">
                <div dir="ltr">Hi there!<br>
                  <br>
                  Sorry to hear you're having trouble with the examples
                  & thanks for reaching out.<br>
                  <br>
                  I'm having some difficulty reproducing the failure
                  mode you described. From the code sample, it sounds
                  like you're in Chapter 8 and I just took a look at
                  Chapter 8 in my debug build and got this result:<br>
                  <br>
                  <div>$ ./bin/Kaleidoscope-Ch8 </div>
                  <div>ready> def average(x y) (x + y) * 0.5;</div>
                  <div>Read function definition:</div>
                  <div>define double @average(double %x, double %y) {</div>
                  <div>entry:</div>
                  <div>  %y2 = alloca double</div>
                  <div>  %x1 = alloca double</div>
                  <div>  store double %x, double* %x1</div>
                  <div>  store double %y, double* %y2</div>
                  <div>  %x3 = load double, double* %x1</div>
                  <div>  %y4 = load double, double* %y2</div>
                  <div>  %addtmp = fadd double %x3, %y4</div>
                  <div>  %multmp = fmul double %addtmp, 5.000000e-01</div>
                  <div>  ret double %multmp</div>
                  <div>}</div>
                  <div><br>
                    <br>
                    Any  ideas what you might be doing differently that
                    I could do to try to reproduce the failure you're
                    seeing?</div>
                  <br>
                  <div class="gmail_quote">
                    <div dir="ltr"
                      class="m_181879325336469943m_1417450841655898947gmail_attr">On
                      Thu, Jan 24, 2019 at 9:36 AM preejackie via
                      llvm-dev <<a
                        href="mailto:llvm-dev@lists.llvm.org"
                        target="_blank" moz-do-not-send="true">llvm-dev@lists.llvm.org</a>>
                      wrote:<br>
                    </div>
                    <blockquote class="gmail_quote" style="margin:0 0 0
                      .8ex;border-left:1px #ccc solid;padding-left:1ex">
                      <div bgcolor="#FFFFFF" text="#000000">
                        <p>Hi all :)</p>
                        <p>I'm new to llvm!<br>
                        </p>
                        <p>I'm going through the kaleidoscope :
                          compiling llvm IR to object code tutorial,
                          code in the listings breaks and causes a
                          segmentation fault. After some investigation
                          through gdb, probably this constructor call,
                          causing the segfault.<br>
                        </p>
                        <p><code>Program received signal SIGSEGV,
                            Segmentation fault.</code><code><br>
                          </code><code>0x00000000004afee0 in
                            llvm::optional_detail::OptionalStorage<llvm::Reloc::Model,
true>::OptionalStorage(llvm::optional_detail::OptionalStorage<llvm::Reloc::Model,
                            true> const&) ()</code></p>
                        <p><code>Source code: </code><br>
                        </p>
                        <div style="color:#f8f8f2;background-color:#272822;font-family:'Droid Sans Mono','monospace',monospace,'Droid Sans Fallback';font-weight:normal;font-size:14px;line-height:19px;white-space:pre-wrap"><div><span style="color:#f8f8f2">TargetOptions opt;</span></div><div><font face="Courier New, Courier, monospace"><span style="color:#f8f8f2">  </span><span style="color:#66d9ef;font-style:italic">auto</span><span style="color:#f8f8f2"> RM </span><span style="color:#f92672">=</span><span style="color:#f8f8f2"> Optional</span><span style="color:#f92672"><</span><span style="color:#f8f8f2">Reloc::Model</span><span style="color:#f92672">></span><span style="color:#f8f8f2">();</span></font></div><div><span style="color:#f8f8f2">  </span><span style="color:#66d9ef;font-style:italic">auto</span><span style="color:#f8f8f2"> TheTargetMachine </span><span style="color:#f92672">=</span></div><div><span style="color:#f8f8f2">      Target-></span><span style="color:#a6e22e">createTargetMachine</span><span style="color:#f8f8f2">(TargetTriple, CPU, Features, opt, RM);</span></div></div>
                        <p>Whether this behavior is already notified and
                          is there any workaround available for it ? I
                          would be great to know the root cause for this
                          behavior.<br>
                        </p>
                        <p>Of course, the kaleidoscope is friendly and
                          good introduction to llvm for beginners, thank
                          you very much for developing :) <br>
                        </p>
                        <p>Thanks for your kind help <br>
                        </p>
                      </div>
                      _______________________________________________<br>
                      LLVM Developers mailing list<br>
                      <a href="mailto:llvm-dev@lists.llvm.org"
                        target="_blank" moz-do-not-send="true">llvm-dev@lists.llvm.org</a><br>
                      <a
                        href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev"
                        rel="noreferrer" target="_blank"
                        moz-do-not-send="true">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
                    </blockquote>
                  </div>
                </div>
              </blockquote>
            </div>
          </blockquote>
        </div>
      </div>
    </blockquote>
  </body>
</html>