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

codegen assertion failure, problem with code_native #15971

Closed
yuyichao opened this issue Apr 20, 2016 · 14 comments
Closed

codegen assertion failure, problem with code_native #15971

yuyichao opened this issue Apr 20, 2016 · 14 comments
Labels
regression Regression in behavior compared to a previous version

Comments

@yuyichao
Copy link
Contributor

yuyichao commented Apr 20, 2016

The actual output is too long to post here but it looks like

yuyichao% ./julia -f -e '@code_native 1 + 1' | wc
 129249  344502 2470759

Piping to tail suggest that the end is always the same so it seems that the disassembler works until it reaches the end of the file.

Bisect result. ad37021

ad370215297c3d78efd9b1135f7731b115c2ccc7 is the first bad commit
commit ad370215297c3d78efd9b1135f7731b115c2ccc7
Author: Jameson Nash <[email protected]>
Date:   Mon Apr 18 21:00:08 2016 -0400

    do a better job at generating code for known functions

    closes #15048

:040000 040000 2440f97408e9d97b3ab126ed69fc3483bd4d57b8 bd297c38e4c1fb7c8868e58d20e143682093c1df M      base
:040000 040000 c68c27e351cf0b24d74e6b52e5f041538d2051d8 df3434506f7936808c8baa292c92828d70bda7e9 M      src


git bisect start
# good: [b0e098aab77335c0b100c4515e5d63d07ac69c9a] Merge pull request #15921 from JuliaLang/teh/concat
git bisect good b0e098aab77335c0b100c4515e5d63d07ac69c9a
# bad: [637ac97def4d86ab2f7e6b65a40557ccc161a217] Merge pull request #15934 from JuliaLang/jn/precompile_plus
git bisect bad 637ac97def4d86ab2f7e6b65a40557ccc161a217
# good: [57a0c72ef66aba1acf05ff663d06ade6a3164afd] Merge pull request #15925 from JuliaLang/jn/no-stage0
git bisect good 57a0c72ef66aba1acf05ff663d06ade6a3164afd
# bad: [ad370215297c3d78efd9b1135f7731b115c2ccc7] do a better job at generating code for known functions
git bisect bad ad370215297c3d78efd9b1135f7731b115c2ccc7
# first bad commit: [ad370215297c3d78efd9b1135f7731b115c2ccc7] do a better job at generating code for known functions

@vtjnash

@JeffBezanson JeffBezanson added the regression Regression in behavior compared to a previous version label Apr 20, 2016
@JeffBezanson
Copy link
Member

I get

julia: /home/jeff/src/julia-master/julia/src/codegen.cpp:1330: uint64_t compute_obj_symsize(const llvm::object::ObjectFile*, uint64_t): Assertion `hi == 0' failed.

@ivarne ivarne added the needs tests Unit tests are required for this change label Apr 21, 2016
@vtjnash
Copy link
Member

vtjnash commented Apr 21, 2016

perhaps an effect of #15617?

@JeffBezanson JeffBezanson added the compiler:codegen Generation of LLVM IR and native code label Apr 25, 2016
@JeffBezanson JeffBezanson changed the title code_native returns the code for almost the entire sysimg on linux codegen assertion failure, problem with code_native Apr 25, 2016
@Ismael-VC
Copy link
Contributor

Do you think it's a good idea to add a test here, something kinda like this?

On v0.4.5:

julia> function test_native()
           orig = STDOUT
           temp = redirect_stdout()[1]
           @code_native 1 + 1
           println("END")
           lines = []
           while true
               line = readline(temp)
               if line == "END\n"
                   break
               end
               push!(lines, line)
           end
           redirect_stdout(orig)
           join(lines, "")
       end
test_native (generic function with 1 method)

julia> native_test = "\t.text\nFilename: int.jl\nSource line: 8\n\tpushq\t%rbp\n\tmovq\t%rsp, %rbp\nSource line: 8\n\taddq\t%rsi, %rdi\n\tmovq\t%rdi, %rax\n\tpopq\t%rbp\n\tret\n"
"\t.text\nFilename: int.jl\nSource line: 8\n\tpushq\t%rbp\n\tmovq\t%rsp, %rbp\nSource line: 8\n\taddq\t%rsi, %rdi\n\tmovq\t%rdi, %rax\n\tpopq\t%rbp\n\tret\n"

julia> using Base.Test

julia> @test test_native() == native_test

The expected output seems to be consistent except on ARM, but could be tailored, I don't know if it's a good idea, but I allways show off the @code_native 1 + 1 snippet, which is why I noticed.

@yuyichao
Copy link
Contributor Author

That is the meaning of the needs-tests label. Adding a test for this is easy when this is fixed.

@Ismael-VC
Copy link
Contributor

@yuyichao I understand that, but I mean is the way I'm testing is a good idea, that's the only way of testing this that came up to me, if it is I can send PR for review, thanks!

@yuyichao
Copy link
Contributor Author

is the way I'm testing is a good idea

No, every optimization, debug option, line number change, different architecture, available instructions set is going to break this badly. Just test for the length should be good enough to notice the difference. code_native also accept io argument and we already have tests for it. It's a matter of adding a upper limit on the output in additional to the !isempty test.

I can send PR for review

I don't see the point of sending a PR with a failing test while there's already an open issue to track the problem.

@Ismael-VC
Copy link
Contributor

Ismael-VC commented Apr 28, 2016

No, every optimization, debug option, line number change, different architecture, available instructions set is going to break this badly.

That's what I wanted to know. I had the impression that the expected native output for 1 + 1 was somewhat consistent. It may seem obvious to you, but it's not for me, thanks for your input and your time!

I don't see the point of sending a PR with a failing test while there's already an open issue to track the problem.

Me neither, of course was I meant to send a PR with a working test (since there are any for this yet, even when there is an issue), not the snippet above (I just said something like that), which is why I'm asking.

code_native also accept io argument and we already have tests for it.

Oh, I didn't know that, it's not documented, except for methods(code_native) and the tests.

I'm still not good enough to help you here, so I'll go document that stuff.

@yuyichao
Copy link
Contributor Author

Oh, I didn't know that, it's not documented
I'll go document that stuff.

I didn't realize it wasn't..... FYI both code_native and code_llvm accept that, would be nice to have that added to the doc.

@yuyichao
Copy link
Contributor Author

It may seem obvious to you, but it's not for me

Try @code_native with debug build.

@Ismael-VC
Copy link
Contributor

Ismael-VC commented Apr 28, 2016

Adding a test for this is easy when this is fixed.

ade5a90 doesn't address the testing part of this issue.

function test_bin_reflection(freflect, f, types, n)
    iob = IOBuffer()                               
    freflect(iob, f, types)                        
    str = takebuf_string(iob)
    @test !isempty(str)                        
    lines = length(split(str, "\n"))                                         
    @test lines  n                               
end                                                                                                                                    

@vtjnash
Copy link
Member

vtjnash commented Apr 28, 2016

that looks fine too. there's an assertion failure that it was 50-50 likely to hit also, depending on how various functions got placed in the object file.

@vtjnash vtjnash removed compiler:codegen Generation of LLVM IR and native code needs tests Unit tests are required for this change labels Apr 28, 2016
@tkelman
Copy link
Contributor

tkelman commented Apr 28, 2016

and yet the assertion failure never seemed to happen on CI?

@vtjnash
Copy link
Member

vtjnash commented Apr 28, 2016

the assertion isn't enabled on CI

@tkelman
Copy link
Contributor

tkelman commented Apr 28, 2016

FORCE_ASSERTIONS=1 doesn't cover this?

BUILDOPTS="-j3 VERBOSE=1 FORCE_ASSERTIONS=1";

We should build LLVM with assertions enabled on CI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
regression Regression in behavior compared to a previous version
Projects
None yet
Development

No branches or pull requests

6 participants