thlorenz / v8-perf

⏱️ Notes and resources related to v8 and thus Node.js performance
2.2k stars 112 forks source link

Is Mach-O JIT info generated correctly #10

Closed thlorenz closed 6 years ago

thlorenz commented 9 years ago

Trying to gain information here WRT to a bug I filed with lldb originally.

Basically I just want to make sure I understand the problem correctly in order to file a helpful bug report with the v8 team. I created a step by step guide to help reproduce the problem.

The latest from the mentioned bug report is that some information seems to be missing from the DWARF that is generated by v8 (I wrote the memory indicated to contain the JIT info to disk to be able to dwarfdump it).

Quoting Greg Clayton from the lldb team:

There is just a TEXT.text segment and a __TEXT.eh_frame section:

% dwarfdump -R /Volumes/work/gclayton/Downloads/jit.o 
----------------------------------------------------------------------
 File: /Volumes/work/gclayton/Downloads/jit.o (x86_64)
----------------------------------------------------------------------
Header
magic:      0xfeedfacf
cputype:    0x01000007
cpusubtype: 0x00000003
filetype:   0x00000001
ncmds:      0x00000001
sizeofcmds: 0x000000e8
flags:      0x00000000

Segments
Segment Name     vmaddr           vmsize           fileoff          filesize         maxprot  initprot nsects   flags
---------------- ---------------- ---------------- ---------------- ---------------- -------- -------- -------- --------
                 000008c6762a0760 00000000000003d4 0000000000000108 0000000000000068 00000007 00000007 00000002 00000000

Sections
Section Name     Segment Name     addr             size             offset   align    reloff   nreloc   flags    reserv1  reserv2  reserv3  size     size %
---------------- ---------------- ---------------- ---------------- -------- -------- -------- -------- -------- -------- -------- -------- ======== ======
__text           __TEXT           000008c6762a0760 00000000000003d4 00000000 00000005 00000000 00000000 80000400 00000000 00000000 cdcdcdcd  980       nan%
__eh_frame       __TEXT           0000000000000000 0000000000000068 00000108 00000003 00000000 00000000 00000000 00000000 00000000 cdcdcdcd  104       nan%

You might need to tell the JIT memory manager to load the DWARF somehow. It doesn't seem like the DWARF is making it into the final memory mach-o where it probably is for ELF.


@mraleph gave some pointers on twitter

if it does - debug section should be called __debug_info not .debug_info

In the above dwarfdump I see neither of those mentioned debug sections. So seems like it's just missing completely?

Greg Clayton from the lldb team suggested:

get the JIT team to help you to be able to get a the DWARF into the __DWARF segment

indicating that a huge portion of the information is missing.

I personally just started diving into the land of dwarfs, elfs and machos so any help to clarify things or pointers where to look, what to read up on, etc. to figure this out is greatly appreciated.

I also have a feeling that @indutny may know a lot more about this than I do at this point ;)

mraleph commented 9 years ago

If at the same V8 version you have line info on Linux and not on Mac OS X that probably means Mach-O is potentially malformed. I'd just throw some printf's into https://github.com/v8/v8-git-mirror/blob/master/src/gdb-jit.cc#L1791and see if it tries to generate it at all. Then see what it generates and what it registers.

There is also FLAG_gdbjit_dump (in DEBUG build) that would force V8 to dump all object files it generates in memory (to verify that they reach LLDB untruncated)

thlorenz commented 9 years ago

I did try FLAG_gdbjit_dump which resulted in lots of elfs in my /tmp folder. I wasn't sure what to do with those since after all I'm on OSX. Dumping symbols out of them lead to nothing useful.

I'll try to look at more details by logging inside gdb-jit.cc, thanks.

mraleph commented 9 years ago

@thlorenz I doubt they are elf's, they are just called this way. I suggest dumping them just to check the size it should match the size you are seeing in the LLDB.

mraleph commented 9 years ago

[if they actually are elf's and not MachO that means V8 does not understand it needs to generate Mach-O files]

thlorenz commented 9 years ago

Ok, makes sense, as i said I was able to dwarfdump them, so most likely not really elfs. However as I mentioned no useful info was contained in them.

I'll dig more in that direction and possibly attach some generated object files somewhere to figure this out.