This is an archive of the discontinued LLVM Phabricator instance.

Make i386-*-freebsd expression work on JIT path
ClosedPublic

Authored by karnajitw on Jun 28 2017, 2:05 PM.

Details

Summary

Expression evaluation which takes the non IRInterpreter::Interpret path fails on i386-*-freebsd. Following changes are done to enable it.

  1. Enable i386 ABI creation for freebsd
  2. Added an extra argument in ABISysV_i386::PrepareTrivialCall for mmap syscall
  3. Unlike linux, the last argument of mmap is actually 64-bit(off_t). This requires us to push an additional word for the higher order bits.
  4. Prior to this change, ktrace dump will show mmap failures due to invalid argument coming from the 6th mmap argument.

Prior Fix:
(lldb) expression printf("%d", d1)
error: Can't run the expression locally: Interpreter doesn't handle one of the expression's opcodes
(lldb) expression d1 + 5 << IRInterpreter path
(int) $0 = 10
(lldb) expression d1 + 5.0
error: Can't run the expression locally: Interpreter doesn't handle one of the expression's opcodes
(lldb) expression f1 * 5
error: Can't run the expression locally: Interpreter doesn't handle one of the expression's opcodes
(lldb) expression f1 / 5
error: Can't run the expression locally: Interpreter doesn't handle one of the expression's opcodes

With Fix:
(lldb) expression printf("%d", d1)
(int) $0 = 1
(lldb) expression printf("%2.3f", f1)
(int) $2 = 5
(lldb) expression d1 + 5
(int) $3 = 10
(lldb) expression d1 + 5.0
(double) $4 = 10
(lldb) expression f1 * 5
(float) $7 = 25.5
(lldb) expression f1 / 5
(float) $8 = 1.01999998

NOTE: Expression involving floating point arithmetic will result in NaN on i386-*-freebsd11.0. Patch https://svnweb.freebsd.org/base?view=revision&revision=320051 is required to make it work.

Diff Detail

Repository
rL LLVM

Event Timeline

karnajitw created this revision.Jun 28 2017, 2:05 PM
labath added a subscriber: labath.Jun 29 2017, 2:41 AM
labath added inline comments.
source/Plugins/Process/Utility/InferiorCallPOSIX.cpp
92 ↗(On Diff #104495)

It would be great if we could avoid OS-specific code in this file. That's what we have tried to do with the Platform::ConvertMmapFlagsToPlatform call (line 82), but it looks like it may not have been the right abstraction.

How about we replace the ConvertMmapFlagsToPlatform function (it's only used in this place) with a more generic GetMmapArguments call (returning a vector of args)? It can still do the MAP_ANON dance as before, but in the freebsd case it will do this additional append.

What do you think?

Looks like the right thing to do. I will make the changes accordingly.

karnajitw updated this revision to Diff 104984.Jul 1 2017, 2:55 AM

Done the changes. Please verify. Tried with RefArray but looks like they don't work well with copy.

+ed as freebsd owner

ArrayRef cannot be returned from a function as they don't own the underlying data. The more traditional way of using SmallVector is to "return" it as a by-ref SmallVectorImpl<T> argument, as that avoids the need to hardcode the size in the function prototypes, but I suppose this will work as well...

karnajitw marked an inline comment as done.Jul 4 2017, 11:13 AM

With my test setup on i386-*-freebsd-11.0 (freebsd patched).. There seems to be quite a good improvement in the number of test failures.

[BEFORE lldb patch]

Test Result Summary

Test Methods: 1276
Reruns: 2
Success: 490
Expected Failure: 57
Failure: 61
Error: 2
Exceptional Exit: 1
Unexpected Success: 5
Skip: 658
Timeout: 2
Expected Timeout: 0

[After lldb patch]

Test Result Summary

Test Methods: 1276
Reruns: 0
Success: 545
Expected Failure: 55
Failure: 6
Error: 2
Exceptional Exit: 1
Unexpected Success: 7
Skip: 658
Timeout: 2
Expected Timeout: 0

emaste edited edge metadata.Aug 7 2017, 5:23 AM

Sorry I missed this when first uploaded, I will look at it shortly.

For future uploads can you kindly include full context, as described in https://llvm.org/docs/Phabricator.html?

The change in PlatformOpenBSD.cpp failed to apply for me (although it was trivial to manually apply it).

emaste added a comment.Aug 7 2017, 6:27 PM

With this patch i386 test results are comparable to amd64, and I'm happy with it from a FreeBSD perspective (modulo the PlatformOpenBSD patch conflict).

emaste accepted this revision.Aug 8 2017, 11:52 AM
emaste added a reviewer: labath.
This revision is now accepted and ready to land.Aug 8 2017, 11:53 AM

I've committed this to FreeBSD's copy of lldb in r322326. @labath if you're happy with this patch I will commit to lldb for @karnajitw. I'm not sure how the patch ended up with a conflict, but it's just a whitespace issue.

labath accepted this revision.Aug 16 2017, 2:20 AM

lgtm

This revision was automatically updated to reflect the committed changes.