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

Output labels when disassembling code #8897

Merged
merged 13 commits into from
Nov 10, 2014

Conversation

eschnett
Copy link
Contributor

@eschnett eschnett commented Nov 4, 2014

This addresses #6589.

This handles only the LLVM33 non-MCJIT case. Addressing the other cases seems straightforward, but I currently can't test them locally.

@ihnorton
Copy link
Member

ihnorton commented Nov 4, 2014

👍

}
const char *SymbolTable::lookupSymbol(uint64_t addr)
{
std::cout << "lookupSymbol(" << addr << ")\n";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching this, that's just leftover debug output. Since the actual disassembled output is cached, cout output appears above, making it easy to miss.

@vtjnash
Copy link
Sponsor Member

vtjnash commented Nov 5, 2014

would this allow us to also start generating better labels for call instructions and variable assignments? or is this just for labels (which is alone very awesome)?

@eschnett
Copy link
Contributor Author

eschnett commented Nov 5, 2014

This is at the moment only for branch labels, where the new code maintains a symbol table.

If Julia already has a symbol table (I guess it does) for call targets, then it should be just a few additional lines to convert those into meaningful names as well. Any pointers?

(What's up with Travis? I always get gfortran errors for the OS X tests, and I don't think it's related to my changes.)

The labels are still output with the wrong offset (as if they had the value 0), and debug info is enabled.
@eschnett
Copy link
Contributor Author

eschnett commented Nov 6, 2014

Call labels are now resolved as well.

@JeffBezanson
Copy link
Sponsor Member

Wow, this is impressive. Can you show some example output?

@eschnett
Copy link
Contributor Author

eschnett commented Nov 6, 2014

Example output with labels. Local (branch) labels use L as prefix, global (call) labels use the respective routine names (thanks, backtrace mechanism!).

julia> code_native(Burgers.u_initial, (Int,))
    .section    __TEXT,__text,regular,pure_instructions
Filename: /Users/eschnett/src/jl/Burgers.jl
Source line: 7
    push    RBP
    mov RBP, RSP
    push    R14
    push    RBX
    sub RSP, 32
    mov RBX, RDI
    mov QWORD PTR [RBP - 48], 4
Source line: 7
    movabs  R14, jl_pgcstack
    mov RAX, QWORD PTR [R14]
    mov QWORD PTR [RBP - 40], RAX
    lea RAX, QWORD PTR [RBP - 48]
    mov QWORD PTR [R14], RAX
    mov QWORD PTR [RBP - 32], 0
    movabs  RAX, 140225061117248
Source line: 8
    mov QWORD PTR [RBP - 24], RAX
    movabs  RAX, jl_new_array
    movabs  RDI, 140225061117248
    mov RSI, RBX
    call    RAX
    test    RBX, RBX
    mov QWORD PTR [RBP - 32], RAX
    jle L240
Source line: 7
    lea RCX, QWORD PTR [RBX - 1]
    vcvtsi2sd   XMM0, XMM0, RCX
    movabs  RCX, 4568076320
    vmovsd  XMM1, QWORD PTR [RCX]
    vdivsd  XMM0, XMM1, XMM0
Source line: 11
    mov RCX, QWORD PTR [RAX + 16]
    xor EDX, EDX
    vxorps  XMM1, XMM1, XMM1
    movabs  RSI, 4568076328
    vmovsd  XMM2, QWORD PTR [RSI]
    movabs  RSI, 4568076336
    vmovsd  XMM3, QWORD PTR [RSI]
    xor ESI, ESI
Source line: 10
L173:   vcvtsi2sd   XMM4, XMM0, RSI
    vmulsd  XMM4, XMM0, XMM4
    vaddsd  XMM4, XMM4, XMM1
    vucomisd    XMM3, XMM4
    vmovaps XMM4, XMM2
    ja  L204
    vxorps  XMM4, XMM4, XMM4
Source line: 11
L204:   cmp RSI, RCX
    jae L256
    mov RDI, QWORD PTR [RAX + 8]
    sub RDI, RDX
    vmovsd  QWORD PTR [RDI], XMM4
    add RDX, -8
    inc RSI
    cmp RBX, RSI
    jne L173
Source line: 13
L240:   mov RCX, QWORD PTR [RBP - 40]
    mov QWORD PTR [R14], RCX
    add RSP, 32
    pop RBX
    pop R14
    pop RBP
    ret
Source line: 11
L256:   movabs  RAX, jl_bounds_exception
    mov RDI, QWORD PTR [RAX]
    movabs  RAX, jl_throw_with_superfluous_argument
    mov ESI, 11
    call    RAX

@eschnett
Copy link
Contributor Author

eschnett commented Nov 6, 2014

It seems the code is missing some symbols. I think this may be related to functions that have not yet been compiled, and where the code presumably is pointing to a wrapper or trampoline. Where is the data structure defined in Julia that holds the mapping between functions and addresses? I found Function and jl_codectx_t in codegen.cpp, but I didn't find any global data structure that holds pointers to these.

@StefanKarpinski
Copy link
Sponsor Member

Nice. This makes the native code dumps actually somewhat decipherable when there are branches.

JeffBezanson added a commit that referenced this pull request Nov 10, 2014
Output labels when disassembling code
@JeffBezanson JeffBezanson merged commit 03d7b15 into JuliaLang:master Nov 10, 2014
ihnorton added a commit that referenced this pull request Nov 11, 2014
@eschnett eschnett deleted the asm-labels branch November 19, 2014 15:17
waTeim pushed a commit to waTeim/julia that referenced this pull request Nov 23, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants